1 /* linux/drivers/char/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 #include <linux/scx200.h>
16
17 #define NAME "scx200"
18
19 MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>");
20 MODULE_DESCRIPTION("NatSemi SCx200 Driver");
21 MODULE_LICENSE("GPL");
22
23 unsigned scx200_gpio_base = 0;
24 long scx200_gpio_shadow[2];
25
26 spinlock_t scx200_gpio_lock = SPIN_LOCK_UNLOCKED;
27 static spinlock_t scx200_gpio_config_lock = SPIN_LOCK_UNLOCKED;
28
scx200_gpio_configure(int index,u32 mask,u32 bits)29 u32 scx200_gpio_configure(int index, u32 mask, u32 bits)
30 {
31 u32 config, new_config;
32 unsigned long flags;
33
34 spin_lock_irqsave(&scx200_gpio_config_lock, flags);
35
36 outl(index, scx200_gpio_base + 0x20);
37 config = inl(scx200_gpio_base + 0x24);
38
39 new_config = (config & mask) | bits;
40 outl(new_config, scx200_gpio_base + 0x24);
41
42 spin_unlock_irqrestore(&scx200_gpio_config_lock, flags);
43
44 return config;
45 }
46
scx200_gpio_dump(unsigned index)47 void scx200_gpio_dump(unsigned index)
48 {
49 u32 config = scx200_gpio_configure(index, ~0, 0);
50 printk(KERN_DEBUG "GPIO%02u: 0x%08lx", index, (unsigned long)config);
51
52 if (config & 1)
53 printk(" OE"); /* output enabled */
54 else
55 printk(" TS"); /* tristate */
56 if (config & 2)
57 printk(" PP"); /* push pull */
58 else
59 printk(" OD"); /* open drain */
60 if (config & 4)
61 printk(" PUE"); /* pull up enabled */
62 else
63 printk(" PUD"); /* pull up disabled */
64 if (config & 8)
65 printk(" LOCKED"); /* locked */
66 if (config & 16)
67 printk(" LEVEL"); /* level input */
68 else
69 printk(" EDGE"); /* edge input */
70 if (config & 32)
71 printk(" HI"); /* trigger on rising edge */
72 else
73 printk(" LO"); /* trigger on falling edge */
74 if (config & 64)
75 printk(" DEBOUNCE"); /* debounce */
76 printk("\n");
77 }
78
scx200_init(void)79 int __init scx200_init(void)
80 {
81 struct pci_dev *bridge;
82 int bank;
83 unsigned base;
84
85 printk(KERN_INFO NAME ": NatSemi SCx200 Driver\n");
86
87 if ((bridge = pci_find_device(PCI_VENDOR_ID_NS,
88 PCI_DEVICE_ID_NS_SCx200_BRIDGE,
89 NULL)) == NULL)
90 return -ENODEV;
91
92 base = pci_resource_start(bridge, 0);
93 printk(KERN_INFO NAME ": GPIO base 0x%x\n", base);
94
95 if (request_region(base, SCx200_GPIO_SIZE, "NatSemi SCx200 GPIO") == 0) {
96 printk(KERN_ERR NAME ": can't allocate I/O for GPIOs\n");
97 return -EBUSY;
98 }
99
100 scx200_gpio_base = base;
101
102 /* read the current values driven on the GPIO signals */
103 for (bank = 0; bank < 2; ++bank)
104 scx200_gpio_shadow[bank] = inl(scx200_gpio_base + 0x10 * bank);
105
106 return 0;
107 }
108
scx200_cleanup(void)109 void __exit scx200_cleanup(void)
110 {
111 release_region(scx200_gpio_base, SCx200_GPIO_SIZE);
112 }
113
114 module_init(scx200_init);
115 module_exit(scx200_cleanup);
116
117 EXPORT_SYMBOL(scx200_gpio_base);
118 EXPORT_SYMBOL(scx200_gpio_shadow);
119 EXPORT_SYMBOL(scx200_gpio_lock);
120 EXPORT_SYMBOL(scx200_gpio_configure);
121 EXPORT_SYMBOL(scx200_gpio_dump);
122
123 /*
124 Local variables:
125 compile-command: "make -k -C ../../.. SUBDIRS=arch/i386/kernel modules"
126 c-basic-offset: 8
127 End:
128 */
129