1 /* linux/arch/i386/kernel/scx200.c
3 Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com>
5 National Semiconductor SCx200 support. */
7 #include <linux/config.h>
8 #include <linux/module.h>
9 #include <linux/errno.h>
10 #include <linux/kernel.h>
11 #include <linux/init.h>
12 #include <linux/pci.h>
14 #include <linux/scx200.h>
18 MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>");
19 MODULE_DESCRIPTION("NatSemi SCx200 Driver");
20 MODULE_LICENSE("GPL");
22 unsigned scx200_gpio_base = 0;
23 long scx200_gpio_shadow[2];
25 spinlock_t scx200_gpio_lock = SPIN_LOCK_UNLOCKED;
26 static spinlock_t scx200_gpio_config_lock = SPIN_LOCK_UNLOCKED;
28 u32 scx200_gpio_configure(int index, u32 mask, u32 bits)
30 u32 config, new_config;
33 spin_lock_irqsave(&scx200_gpio_config_lock, flags);
35 outl(index, scx200_gpio_base + 0x20);
36 config = inl(scx200_gpio_base + 0x24);
38 new_config = (config & mask) | bits;
39 outl(new_config, scx200_gpio_base + 0x24);
41 spin_unlock_irqrestore(&scx200_gpio_config_lock, flags);
46 void scx200_gpio_dump(unsigned index)
48 u32 config = scx200_gpio_configure(index, ~0, 0);
49 printk(KERN_DEBUG "GPIO%02u: 0x%08lx", index, (unsigned long)config);
52 printk(" OE"); /* output enabled */
54 printk(" TS"); /* tristate */
56 printk(" PP"); /* push pull */
58 printk(" OD"); /* open drain */
60 printk(" PUE"); /* pull up enabled */
62 printk(" PUD"); /* pull up disabled */
64 printk(" LOCKED"); /* locked */
66 printk(" LEVEL"); /* level input */
68 printk(" EDGE"); /* edge input */
70 printk(" HI"); /* trigger on rising edge */
72 printk(" LO"); /* trigger on falling edge */
74 printk(" DEBOUNCE"); /* debounce */
78 int __init scx200_init(void)
80 struct pci_dev *bridge;
84 printk(KERN_INFO NAME ": NatSemi SCx200 Driver\n");
86 if ((bridge = pci_find_device(PCI_VENDOR_ID_NS,
87 PCI_DEVICE_ID_NS_SCx200_BRIDGE,
89 && (bridge = pci_find_device(PCI_VENDOR_ID_NS,
90 PCI_DEVICE_ID_NS_SC1100_BRIDGE,
94 base = pci_resource_start(bridge, 0);
95 printk(KERN_INFO NAME ": GPIO base 0x%x\n", base);
97 if (request_region(base, SCx200_GPIO_SIZE, "NatSemi SCx200 GPIO") == 0) {
98 printk(KERN_ERR NAME ": can't allocate I/O for GPIOs\n");
102 scx200_gpio_base = base;
104 /* read the current values driven on the GPIO signals */
105 for (bank = 0; bank < 2; ++bank)
106 scx200_gpio_shadow[bank] = inl(scx200_gpio_base + 0x10 * bank);
111 void __exit scx200_cleanup(void)
113 release_region(scx200_gpio_base, SCx200_GPIO_SIZE);
116 module_init(scx200_init);
117 module_exit(scx200_cleanup);
119 EXPORT_SYMBOL(scx200_gpio_base);
120 EXPORT_SYMBOL(scx200_gpio_shadow);
121 EXPORT_SYMBOL(scx200_gpio_lock);
122 EXPORT_SYMBOL(scx200_gpio_configure);
123 EXPORT_SYMBOL(scx200_gpio_dump);
127 compile-command: "make -k -C ../../.. SUBDIRS=arch/i386/kernel modules"