VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[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
16 #define NAME "scx200"
17
18 MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>");
19 MODULE_DESCRIPTION("NatSemi SCx200 Driver");
20 MODULE_LICENSE("GPL");
21
22 unsigned scx200_gpio_base = 0;
23 long scx200_gpio_shadow[2];
24
25 spinlock_t scx200_gpio_lock = SPIN_LOCK_UNLOCKED;
26 static spinlock_t scx200_gpio_config_lock = SPIN_LOCK_UNLOCKED;
27
28 u32 scx200_gpio_configure(int index, u32 mask, u32 bits)
29 {
30         u32 config, new_config;
31         unsigned long flags;
32
33         spin_lock_irqsave(&scx200_gpio_config_lock, flags);
34
35         outl(index, scx200_gpio_base + 0x20);
36         config = inl(scx200_gpio_base + 0x24);
37
38         new_config = (config & mask) | bits;
39         outl(new_config, scx200_gpio_base + 0x24);
40
41         spin_unlock_irqrestore(&scx200_gpio_config_lock, flags);
42
43         return config;
44 }
45
46 void scx200_gpio_dump(unsigned index)
47 {
48         u32 config = scx200_gpio_configure(index, ~0, 0);
49         printk(KERN_DEBUG "GPIO%02u: 0x%08lx", index, (unsigned long)config);
50         
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");
76 }
77
78 int __init scx200_init(void)
79 {
80         struct pci_dev *bridge;
81         int bank;
82         unsigned base;
83
84         printk(KERN_INFO NAME ": NatSemi SCx200 Driver\n");
85
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;
93
94         base = pci_resource_start(bridge, 0);
95         printk(KERN_INFO NAME ": GPIO base 0x%x\n", base);
96
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;
100         }
101
102         scx200_gpio_base = base;
103
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);
107
108         return 0;
109 }
110
111 void __exit scx200_cleanup(void)
112 {
113         release_region(scx200_gpio_base, SCx200_GPIO_SIZE);
114 }
115
116 module_init(scx200_init);
117 module_exit(scx200_cleanup);
118
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);
124
125 /*
126     Local variables:
127         compile-command: "make -k -C ../../.. SUBDIRS=arch/i386/kernel modules"
128         c-basic-offset: 8
129     End:
130 */