aboutsummaryrefslogtreecommitdiffstats
path: root/arch/i386/kernel/scx200.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/i386/kernel/scx200.c')
-rw-r--r--arch/i386/kernel/scx200.c167
1 files changed, 167 insertions, 0 deletions
diff --git a/arch/i386/kernel/scx200.c b/arch/i386/kernel/scx200.c
new file mode 100644
index 000000000000..69e203a0d330
--- /dev/null
+++ b/arch/i386/kernel/scx200.c
@@ -0,0 +1,167 @@
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/* Verify that the configuration block really is there */
17#define scx200_cb_probe(base) (inw((base) + SCx200_CBA) == (base))
18
19#define NAME "scx200"
20
21MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>");
22MODULE_DESCRIPTION("NatSemi SCx200 Driver");
23MODULE_LICENSE("GPL");
24
25unsigned scx200_gpio_base = 0;
26long scx200_gpio_shadow[2];
27
28unsigned scx200_cb_base = 0;
29
30static struct pci_device_id scx200_tbl[] = {
31 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SCx200_BRIDGE) },
32 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SC1100_BRIDGE) },
33 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SCx200_XBUS) },
34 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SC1100_XBUS) },
35 { },
36};
37MODULE_DEVICE_TABLE(pci,scx200_tbl);
38
39static int __devinit scx200_probe(struct pci_dev *, const struct pci_device_id *);
40
41static struct pci_driver scx200_pci_driver = {
42 .name = "scx200",
43 .id_table = scx200_tbl,
44 .probe = scx200_probe,
45};
46
47static DEFINE_SPINLOCK(scx200_gpio_config_lock);
48
49static int __devinit scx200_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
50{
51 int bank;
52 unsigned base;
53
54 if (pdev->device == PCI_DEVICE_ID_NS_SCx200_BRIDGE ||
55 pdev->device == PCI_DEVICE_ID_NS_SC1100_BRIDGE) {
56 base = pci_resource_start(pdev, 0);
57 printk(KERN_INFO NAME ": GPIO base 0x%x\n", base);
58
59 if (request_region(base, SCx200_GPIO_SIZE, "NatSemi SCx200 GPIO") == 0) {
60 printk(KERN_ERR NAME ": can't allocate I/O for GPIOs\n");
61 return -EBUSY;
62 }
63
64 scx200_gpio_base = base;
65
66 /* read the current values driven on the GPIO signals */
67 for (bank = 0; bank < 2; ++bank)
68 scx200_gpio_shadow[bank] = inl(scx200_gpio_base + 0x10 * bank);
69
70 } else {
71 /* find the base of the Configuration Block */
72 if (scx200_cb_probe(SCx200_CB_BASE_FIXED)) {
73 scx200_cb_base = SCx200_CB_BASE_FIXED;
74 } else {
75 pci_read_config_dword(pdev, SCx200_CBA_SCRATCH, &base);
76 if (scx200_cb_probe(base)) {
77 scx200_cb_base = base;
78 } else {
79 printk(KERN_WARNING NAME ": Configuration Block not found\n");
80 return -ENODEV;
81 }
82 }
83 printk(KERN_INFO NAME ": Configuration Block base 0x%x\n", scx200_cb_base);
84 }
85
86 return 0;
87}
88
89u32 scx200_gpio_configure(int index, u32 mask, u32 bits)
90{
91 u32 config, new_config;
92 unsigned long flags;
93
94 spin_lock_irqsave(&scx200_gpio_config_lock, flags);
95
96 outl(index, scx200_gpio_base + 0x20);
97 config = inl(scx200_gpio_base + 0x24);
98
99 new_config = (config & mask) | bits;
100 outl(new_config, scx200_gpio_base + 0x24);
101
102 spin_unlock_irqrestore(&scx200_gpio_config_lock, flags);
103
104 return config;
105}
106
107#if 0
108void scx200_gpio_dump(unsigned index)
109{
110 u32 config = scx200_gpio_configure(index, ~0, 0);
111 printk(KERN_DEBUG "GPIO%02u: 0x%08lx", index, (unsigned long)config);
112
113 if (config & 1)
114 printk(" OE"); /* output enabled */
115 else
116 printk(" TS"); /* tristate */
117 if (config & 2)
118 printk(" PP"); /* push pull */
119 else
120 printk(" OD"); /* open drain */
121 if (config & 4)
122 printk(" PUE"); /* pull up enabled */
123 else
124 printk(" PUD"); /* pull up disabled */
125 if (config & 8)
126 printk(" LOCKED"); /* locked */
127 if (config & 16)
128 printk(" LEVEL"); /* level input */
129 else
130 printk(" EDGE"); /* edge input */
131 if (config & 32)
132 printk(" HI"); /* trigger on rising edge */
133 else
134 printk(" LO"); /* trigger on falling edge */
135 if (config & 64)
136 printk(" DEBOUNCE"); /* debounce */
137 printk("\n");
138}
139#endif /* 0 */
140
141static int __init scx200_init(void)
142{
143 printk(KERN_INFO NAME ": NatSemi SCx200 Driver\n");
144
145 return pci_module_init(&scx200_pci_driver);
146}
147
148static void __exit scx200_cleanup(void)
149{
150 pci_unregister_driver(&scx200_pci_driver);
151 release_region(scx200_gpio_base, SCx200_GPIO_SIZE);
152}
153
154module_init(scx200_init);
155module_exit(scx200_cleanup);
156
157EXPORT_SYMBOL(scx200_gpio_base);
158EXPORT_SYMBOL(scx200_gpio_shadow);
159EXPORT_SYMBOL(scx200_gpio_configure);
160EXPORT_SYMBOL(scx200_cb_base);
161
162/*
163 Local variables:
164 compile-command: "make -k -C ../../.. SUBDIRS=arch/i386/kernel modules"
165 c-basic-offset: 8
166 End:
167*/