blob: 9e96a785dd058f3c9447b49c47dfa5bb6b00e8e8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* 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>
Adrian Bunkcc658cf2005-11-07 00:58:37 -080015#include <linux/scx200_gpio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17/* Verify that the configuration block really is there */
18#define scx200_cb_probe(base) (inw((base) + SCx200_CBA) == (base))
19
20#define NAME "scx200"
21
22MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>");
23MODULE_DESCRIPTION("NatSemi SCx200 Driver");
24MODULE_LICENSE("GPL");
25
26unsigned scx200_gpio_base = 0;
27long scx200_gpio_shadow[2];
28
29unsigned scx200_cb_base = 0;
30
31static struct pci_device_id scx200_tbl[] = {
32 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SCx200_BRIDGE) },
33 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SC1100_BRIDGE) },
34 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SCx200_XBUS) },
35 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SC1100_XBUS) },
36 { },
37};
38MODULE_DEVICE_TABLE(pci,scx200_tbl);
39
40static int __devinit scx200_probe(struct pci_dev *, const struct pci_device_id *);
41
42static struct pci_driver scx200_pci_driver = {
43 .name = "scx200",
44 .id_table = scx200_tbl,
45 .probe = scx200_probe,
46};
47
48static DEFINE_SPINLOCK(scx200_gpio_config_lock);
49
50static int __devinit scx200_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
51{
52 int bank;
53 unsigned base;
54
55 if (pdev->device == PCI_DEVICE_ID_NS_SCx200_BRIDGE ||
56 pdev->device == PCI_DEVICE_ID_NS_SC1100_BRIDGE) {
57 base = pci_resource_start(pdev, 0);
58 printk(KERN_INFO NAME ": GPIO base 0x%x\n", base);
59
60 if (request_region(base, SCx200_GPIO_SIZE, "NatSemi SCx200 GPIO") == 0) {
61 printk(KERN_ERR NAME ": can't allocate I/O for GPIOs\n");
62 return -EBUSY;
63 }
64
65 scx200_gpio_base = base;
66
67 /* read the current values driven on the GPIO signals */
68 for (bank = 0; bank < 2; ++bank)
69 scx200_gpio_shadow[bank] = inl(scx200_gpio_base + 0x10 * bank);
70
71 } else {
72 /* find the base of the Configuration Block */
73 if (scx200_cb_probe(SCx200_CB_BASE_FIXED)) {
74 scx200_cb_base = SCx200_CB_BASE_FIXED;
75 } else {
76 pci_read_config_dword(pdev, SCx200_CBA_SCRATCH, &base);
77 if (scx200_cb_probe(base)) {
78 scx200_cb_base = base;
79 } else {
80 printk(KERN_WARNING NAME ": Configuration Block not found\n");
81 return -ENODEV;
82 }
83 }
84 printk(KERN_INFO NAME ": Configuration Block base 0x%x\n", scx200_cb_base);
85 }
86
87 return 0;
88}
89
Jim Cromie55b8c042006-06-27 02:54:15 -070090u32 scx200_gpio_configure(unsigned index, u32 mask, u32 bits)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091{
92 u32 config, new_config;
93 unsigned long flags;
94
95 spin_lock_irqsave(&scx200_gpio_config_lock, flags);
96
97 outl(index, scx200_gpio_base + 0x20);
98 config = inl(scx200_gpio_base + 0x24);
99
100 new_config = (config & mask) | bits;
101 outl(new_config, scx200_gpio_base + 0x24);
102
103 spin_unlock_irqrestore(&scx200_gpio_config_lock, flags);
104
105 return config;
106}
107
108#if 0
109void scx200_gpio_dump(unsigned index)
110{
Jim Cromied424aa82006-06-27 02:54:16 -0700111 u32 config = scx200_gpio_configure(index, ~0, 0);
112
113 printk(KERN_INFO NAME ": GPIO-%02u: 0x%08lx %s %s %s %s %s %s %s\n",
114 index, (unsigned long) config,
115 (config & 1) ? "OE" : "TS", /* output enabled / tristate */
116 (config & 2) ? "PP" : "OD", /* push pull / open drain */
117 (config & 4) ? "PUE" : "PUD", /* pull up enabled/disabled */
118 (config & 8) ? "LOCKED" : "", /* locked / unlocked */
119 (config & 16) ? "LEVEL" : "EDGE", /* level/edge input */
120 (config & 32) ? "HI" : "LO", /* trigger on rising/falling edge */
121 (config & 64) ? "DEBOUNCE" : ""); /* debounce */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122}
123#endif /* 0 */
124
125static int __init scx200_init(void)
126{
127 printk(KERN_INFO NAME ": NatSemi SCx200 Driver\n");
128
Richard Knutssond1d6da82005-11-30 00:59:14 +0100129 return pci_register_driver(&scx200_pci_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130}
131
132static void __exit scx200_cleanup(void)
133{
134 pci_unregister_driver(&scx200_pci_driver);
135 release_region(scx200_gpio_base, SCx200_GPIO_SIZE);
136}
137
138module_init(scx200_init);
139module_exit(scx200_cleanup);
140
141EXPORT_SYMBOL(scx200_gpio_base);
142EXPORT_SYMBOL(scx200_gpio_shadow);
143EXPORT_SYMBOL(scx200_gpio_configure);
144EXPORT_SYMBOL(scx200_cb_base);