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.h>
19 MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>");
20 MODULE_DESCRIPTION("NatSemi SCx200 Driver");
21 MODULE_LICENSE("GPL");
23 unsigned scx200_gpio_base = 0;
24 long scx200_gpio_shadow[2];
26 spinlock_t scx200_gpio_lock = SPIN_LOCK_UNLOCKED;
27 static spinlock_t scx200_gpio_config_lock = SPIN_LOCK_UNLOCKED;
29 u32 scx200_gpio_configure(int index, u32 mask, u32 bits)
31 u32 config, new_config;
34 spin_lock_irqsave(&scx200_gpio_config_lock, flags);
36 outl(index, scx200_gpio_base + 0x20);
37 config = inl(scx200_gpio_base + 0x24);
39 new_config = (config & mask) | bits;
40 outl(new_config, scx200_gpio_base + 0x24);
42 spin_unlock_irqrestore(&scx200_gpio_config_lock, flags);
47 void scx200_gpio_dump(unsigned index)
49 u32 config = scx200_gpio_configure(index, ~0, 0);
50 printk(KERN_DEBUG "GPIO%02u: 0x%08lx", index, (unsigned long)config);
53 printk(" OE"); /* output enabled */
55 printk(" TS"); /* tristate */
57 printk(" PP"); /* push pull */
59 printk(" OD"); /* open drain */
61 printk(" PUE"); /* pull up enabled */
63 printk(" PUD"); /* pull up disabled */
65 printk(" LOCKED"); /* locked */
67 printk(" LEVEL"); /* level input */
69 printk(" EDGE"); /* edge input */
71 printk(" HI"); /* trigger on rising edge */
73 printk(" LO"); /* trigger on falling edge */
75 printk(" DEBOUNCE"); /* debounce */
79 int __init scx200_init(void)
81 struct pci_dev *bridge;
85 printk(KERN_INFO NAME ": NatSemi SCx200 Driver\n");
87 if ((bridge = pci_find_device(PCI_VENDOR_ID_NS,
88 PCI_DEVICE_ID_NS_SCx200_BRIDGE,
90 && (bridge = pci_find_device(PCI_VENDOR_ID_NS,
91 PCI_DEVICE_ID_NS_SC1100_BRIDGE,
95 base = pci_resource_start(bridge, 0);
96 printk(KERN_INFO NAME ": GPIO base 0x%x\n", base);
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");
103 scx200_gpio_base = base;
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);
112 void __exit scx200_cleanup(void)
114 release_region(scx200_gpio_base, SCx200_GPIO_SIZE);
117 module_init(scx200_init);
118 module_exit(scx200_cleanup);
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);
128 compile-command: "make -k -C ../../.. SUBDIRS=arch/i386/kernel modules"