initial commit with v2.6.9
[linux-2.6.9-moxart.git] / arch / i386 / kernel / scx200.c
blob1cde4145ce558ccfbc2f4d39d10432fb50be09a0
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>
16 #define NAME "scx200"
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;
31 unsigned long flags;
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);
43 return config;
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);
51 if (config & 1)
52 printk(" OE"); /* output enabled */
53 else
54 printk(" TS"); /* tristate */
55 if (config & 2)
56 printk(" PP"); /* push pull */
57 else
58 printk(" OD"); /* open drain */
59 if (config & 4)
60 printk(" PUE"); /* pull up enabled */
61 else
62 printk(" PUD"); /* pull up disabled */
63 if (config & 8)
64 printk(" LOCKED"); /* locked */
65 if (config & 16)
66 printk(" LEVEL"); /* level input */
67 else
68 printk(" EDGE"); /* edge input */
69 if (config & 32)
70 printk(" HI"); /* trigger on rising edge */
71 else
72 printk(" LO"); /* trigger on falling edge */
73 if (config & 64)
74 printk(" DEBOUNCE"); /* debounce */
75 printk("\n");
78 int __init scx200_init(void)
80 struct pci_dev *bridge;
81 int bank;
82 unsigned base;
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,
88 NULL)) == NULL
89 && (bridge = pci_find_device(PCI_VENDOR_ID_NS,
90 PCI_DEVICE_ID_NS_SC1100_BRIDGE,
91 NULL)) == NULL)
92 return -ENODEV;
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");
99 return -EBUSY;
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);
108 return 0;
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);
126 Local variables:
127 compile-command: "make -k -C ../../.. SUBDIRS=arch/i386/kernel modules"
128 c-basic-offset: 8
129 End: