patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / arch / i386 / kernel / scx200.c
1 /* linux/arch/i386/kernel/scx200.c 
2
3    Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com>
4
5    National Semiconductor SCx200 support. */
6
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>
13
14 #include <linux/scx200.h>
15 #include <linux/scx200.h>
16
17 #define NAME "scx200"
18
19 MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>");
20 MODULE_DESCRIPTION("NatSemi SCx200 Driver");
21 MODULE_LICENSE("GPL");
22
23 unsigned scx200_gpio_base = 0;
24 long scx200_gpio_shadow[2];
25
26 spinlock_t scx200_gpio_lock = SPIN_LOCK_UNLOCKED;
27 static spinlock_t scx200_gpio_config_lock = SPIN_LOCK_UNLOCKED;
28
29 u32 scx200_gpio_configure(int index, u32 mask, u32 bits)
30 {
31         u32 config, new_config;
32         unsigned long flags;
33
34         spin_lock_irqsave(&scx200_gpio_config_lock, flags);
35
36         outl(index, scx200_gpio_base + 0x20);
37         config = inl(scx200_gpio_base + 0x24);
38
39         new_config = (config & mask) | bits;
40         outl(new_config, scx200_gpio_base + 0x24);
41
42         spin_unlock_irqrestore(&scx200_gpio_config_lock, flags);
43
44         return config;
45 }
46
47 void scx200_gpio_dump(unsigned index)
48 {
49         u32 config = scx200_gpio_configure(index, ~0, 0);
50         printk(KERN_DEBUG "GPIO%02u: 0x%08lx", index, (unsigned long)config);
51         
52         if (config & 1) 
53                 printk(" OE"); /* output enabled */
54         else
55                 printk(" TS"); /* tristate */
56         if (config & 2) 
57                 printk(" PP"); /* push pull */
58         else
59                 printk(" OD"); /* open drain */
60         if (config & 4) 
61                 printk(" PUE"); /* pull up enabled */
62         else
63                 printk(" PUD"); /* pull up disabled */
64         if (config & 8) 
65                 printk(" LOCKED"); /* locked */
66         if (config & 16) 
67                 printk(" LEVEL"); /* level input */
68         else
69                 printk(" EDGE"); /* edge input */
70         if (config & 32) 
71                 printk(" HI"); /* trigger on rising edge */
72         else
73                 printk(" LO"); /* trigger on falling edge */
74         if (config & 64) 
75                 printk(" DEBOUNCE"); /* debounce */
76         printk("\n");
77 }
78
79 int __init scx200_init(void)
80 {
81         struct pci_dev *bridge;
82         int bank;
83         unsigned base;
84
85         printk(KERN_INFO NAME ": NatSemi SCx200 Driver\n");
86
87         if ((bridge = pci_find_device(PCI_VENDOR_ID_NS, 
88                                       PCI_DEVICE_ID_NS_SCx200_BRIDGE,
89                                       NULL)) == NULL
90             && (bridge = pci_find_device(PCI_VENDOR_ID_NS,
91                                          PCI_DEVICE_ID_NS_SC1100_BRIDGE,
92                                          NULL)) == NULL)
93                 return -ENODEV;
94
95         base = pci_resource_start(bridge, 0);
96         printk(KERN_INFO NAME ": GPIO base 0x%x\n", base);
97
98         if (request_region(base, SCx200_GPIO_SIZE, "NatSemi SCx200 GPIO") == 0) {
99                 printk(KERN_ERR NAME ": can't allocate I/O for GPIOs\n");
100                 return -EBUSY;
101         }
102
103         scx200_gpio_base = base;
104
105         /* read the current values driven on the GPIO signals */
106         for (bank = 0; bank < 2; ++bank)
107                 scx200_gpio_shadow[bank] = inl(scx200_gpio_base + 0x10 * bank);
108
109         return 0;
110 }
111
112 void __exit scx200_cleanup(void)
113 {
114         release_region(scx200_gpio_base, SCx200_GPIO_SIZE);
115 }
116
117 module_init(scx200_init);
118 module_exit(scx200_cleanup);
119
120 EXPORT_SYMBOL(scx200_gpio_base);
121 EXPORT_SYMBOL(scx200_gpio_shadow);
122 EXPORT_SYMBOL(scx200_gpio_lock);
123 EXPORT_SYMBOL(scx200_gpio_configure);
124 EXPORT_SYMBOL(scx200_gpio_dump);
125
126 /*
127     Local variables:
128         compile-command: "make -k -C ../../.. SUBDIRS=arch/i386/kernel modules"
129         c-basic-offset: 8
130     End:
131 */