[PATCH] powerpc: udbg_printf() formatting attribute
[linux-2.6/sactl.git] / arch / i386 / kernel / scx200.c
blob321f5fd26e75062ef2119710e9ce1b7047ac662c
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>
15 #include <linux/scx200_gpio.h>
17 /* Verify that the configuration block really is there */
18 #define scx200_cb_probe(base) (inw((base) + SCx200_CBA) == (base))
20 #define NAME "scx200"
22 MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>");
23 MODULE_DESCRIPTION("NatSemi SCx200 Driver");
24 MODULE_LICENSE("GPL");
26 unsigned scx200_gpio_base = 0;
27 long scx200_gpio_shadow[2];
29 unsigned scx200_cb_base = 0;
31 static 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 { },
38 MODULE_DEVICE_TABLE(pci,scx200_tbl);
40 static int __devinit scx200_probe(struct pci_dev *, const struct pci_device_id *);
42 static struct pci_driver scx200_pci_driver = {
43 .name = "scx200",
44 .id_table = scx200_tbl,
45 .probe = scx200_probe,
48 static DEFINE_SPINLOCK(scx200_gpio_config_lock);
50 static int __devinit scx200_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
52 int bank;
53 unsigned base;
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);
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;
65 scx200_gpio_base = base;
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);
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;
84 printk(KERN_INFO NAME ": Configuration Block base 0x%x\n", scx200_cb_base);
87 return 0;
90 u32 scx200_gpio_configure(int index, u32 mask, u32 bits)
92 u32 config, new_config;
93 unsigned long flags;
95 spin_lock_irqsave(&scx200_gpio_config_lock, flags);
97 outl(index, scx200_gpio_base + 0x20);
98 config = inl(scx200_gpio_base + 0x24);
100 new_config = (config & mask) | bits;
101 outl(new_config, scx200_gpio_base + 0x24);
103 spin_unlock_irqrestore(&scx200_gpio_config_lock, flags);
105 return config;
108 #if 0
109 void scx200_gpio_dump(unsigned index)
111 u32 config = scx200_gpio_configure(index, ~0, 0);
112 printk(KERN_DEBUG "GPIO%02u: 0x%08lx", index, (unsigned long)config);
114 if (config & 1)
115 printk(" OE"); /* output enabled */
116 else
117 printk(" TS"); /* tristate */
118 if (config & 2)
119 printk(" PP"); /* push pull */
120 else
121 printk(" OD"); /* open drain */
122 if (config & 4)
123 printk(" PUE"); /* pull up enabled */
124 else
125 printk(" PUD"); /* pull up disabled */
126 if (config & 8)
127 printk(" LOCKED"); /* locked */
128 if (config & 16)
129 printk(" LEVEL"); /* level input */
130 else
131 printk(" EDGE"); /* edge input */
132 if (config & 32)
133 printk(" HI"); /* trigger on rising edge */
134 else
135 printk(" LO"); /* trigger on falling edge */
136 if (config & 64)
137 printk(" DEBOUNCE"); /* debounce */
138 printk("\n");
140 #endif /* 0 */
142 static int __init scx200_init(void)
144 printk(KERN_INFO NAME ": NatSemi SCx200 Driver\n");
146 return pci_register_driver(&scx200_pci_driver);
149 static void __exit scx200_cleanup(void)
151 pci_unregister_driver(&scx200_pci_driver);
152 release_region(scx200_gpio_base, SCx200_GPIO_SIZE);
155 module_init(scx200_init);
156 module_exit(scx200_cleanup);
158 EXPORT_SYMBOL(scx200_gpio_base);
159 EXPORT_SYMBOL(scx200_gpio_shadow);
160 EXPORT_SYMBOL(scx200_gpio_configure);
161 EXPORT_SYMBOL(scx200_cb_base);
164 Local variables:
165 compile-command: "make -k -C ../../.. SUBDIRS=arch/i386/kernel modules"
166 c-basic-offset: 8
167 End: