1 Index: linux-2.6.21.7/arch/arm/Kconfig
2 ===================================================================
3 --- linux-2.6.21.7.orig/arch/arm/Kconfig
4 +++ linux-2.6.21.7/arch/arm/Kconfig
5 @@ -505,6 +505,8 @@ config PCI_HOST_VIA82C505
6 depends on PCI && ARCH_SHARK
9 +source "drivers/gpio/Kconfig"
11 source "drivers/pci/Kconfig"
13 source "drivers/pcmcia/Kconfig"
14 Index: linux-2.6.21.7/drivers/Makefile
15 ===================================================================
16 --- linux-2.6.21.7.orig/drivers/Makefile
17 +++ linux-2.6.21.7/drivers/Makefile
18 @@ -81,3 +81,4 @@ obj-$(CONFIG_GENERIC_TIME) += clocksourc
19 obj-$(CONFIG_DMA_ENGINE) += dma/
20 obj-$(CONFIG_HID) += hid/
21 obj-$(CONFIG_PPC_PS3) += ps3/
22 +obj-$(CONFIG_PROC_GPIO) += gpio/
23 Index: linux-2.6.21.7/drivers/gpio/Kconfig
24 ===================================================================
25 --- linux-2.6.21.7.orig/drivers/gpio/Kconfig
26 +++ linux-2.6.21.7/drivers/gpio/Kconfig
27 @@ -2,14 +2,27 @@ menuconfig NEW_GPIO
29 depends on GENERIC_GPIO
31 - Say Y to enable Linux GPIO device support. This allows control of
32 - GPIO pins using a character device
33 + Say Y to enable Linux GPIO device support. This allows control of
34 + GPIO pins using a character device
39 tristate "GPIO device support"
41 - This option enables the gpio character device
42 + This option enables the gpio character device
47 + tristate "GPIO /proc interface"
48 + depends on PXA25x || PXA27x
50 + This enables an interface under /proc/gpio which allows reading or setting
51 + of any GPIO, and also changing the GPIO alt function mode of any line.
53 +config PROC_GPIO_DEBUG
54 + boolean "Enable /proc/gpio debug logging"
55 + depends on PROC_GPIO
57 + This enables printk logging of activity done through /proc/gpio
58 Index: linux-2.6.21.7/drivers/gpio/Makefile
59 ===================================================================
60 --- linux-2.6.21.7.orig/drivers/gpio/Makefile
61 +++ linux-2.6.21.7/drivers/gpio/Makefile
63 obj-$(CONFIG_GPIO_DEVICE) += gpio_dev.o
65 +# Expose GPIOs under /proc
66 +obj-$(CONFIG_PROC_GPIO) += proc_gpio.o
67 Index: linux-2.6.21.7/drivers/gpio/proc_gpio.c
68 ===================================================================
70 +++ linux-2.6.21.7/drivers/gpio/proc_gpio.c
74 + * PXA25x GPIOs exposed under /proc for reading and writing
75 + * They will show up under /proc/gpio/NN
77 + * Based on patch 1773/1 in the arm kernel patch repository at arm.linux.co.uk
81 +#include <linux/module.h>
82 +#include <linux/init.h>
83 +#include <linux/proc_fs.h>
84 +#include <linux/string.h>
85 +#include <linux/ctype.h>
87 +#include <asm/hardware.h>
88 +#include <asm/arch/pxa-regs.h>
89 +#include <asm/uaccess.h>
91 +static struct proc_dir_entry *proc_gpio_parent;
92 +static struct proc_dir_entry *proc_gpios[PXA_LAST_GPIO + 1];
100 +static gpio_summary_type gpio_summaries[PXA_LAST_GPIO + 1];
102 +static int proc_gpio_write(struct file *file, const char __user *buf,
103 + unsigned long count, void *data)
105 + char *cur, lbuf[count + 1];
106 + gpio_summary_type *summary = data;
107 + u32 altfn, direction, setclear, gafr;
109 + if (!capable(CAP_SYS_ADMIN))
112 + memset(lbuf, 0, count + 1);
114 + if (copy_from_user(lbuf, buf, count))
119 + // Initialize to current state
120 + altfn = ((GAFR(summary->gpio) >> ((summary->gpio & 0x0f) << 0x01)) & 0x03);
121 + direction = GPDR(summary->gpio) & GPIO_bit(summary->gpio);
122 + setclear = GPLR(summary->gpio) & GPIO_bit(summary->gpio);
125 + // We accept options: {GPIO|AF1|AF2|AF3}, {set|clear}, {in|out}
126 + // Anything else is an error
127 + while(cur[0] && (isspace(cur[0]) || ispunct(cur[0]))) cur = &(cur[1]);
129 + if('\0' == cur[0]) break;
131 + // Ok, so now we're pointing at the start of something
135 + // Check that next is "PIO" -- '\0' will cause safe short-circuit if end of buf
136 + if(!(cur[1] == 'P' && cur[2] == 'I' && cur[3] == 'O')) goto parse_error;
137 + // Ok, so set this GPIO to GPIO (non-ALT) function
142 + if(!(cur[1] == 'F' && cur[2] >= '1' && cur[2] <= '3')) goto parse_error;
143 + altfn = cur[2] - '0';
147 + if(!(cur[1] == 'e' && cur[2] == 't')) goto parse_error;
152 + if(!(cur[1] == 'l' && cur[2] == 'e' && cur[3] == 'a' && cur[4] == 'r')) goto parse_error;
157 + if(!(cur[1] == 'n')) goto parse_error;
162 + if(!(cur[1] == 'u' && cur[2] == 't')) goto parse_error;
166 + default: goto parse_error;
169 + // Ok, now set gpio mode and value
171 + GPDR(summary->gpio) |= GPIO_bit(summary->gpio);
173 + GPDR(summary->gpio) &= ~GPIO_bit(summary->gpio);
175 + gafr = GAFR(summary->gpio) & ~(0x3 << (((summary->gpio) & 0xf)*2));
176 + GAFR(summary->gpio) = gafr | (altfn << (((summary->gpio) & 0xf)*2));
178 + if(direction && !altfn)
180 + if(setclear) GPSR(summary->gpio) = GPIO_bit(summary->gpio);
181 + else GPCR(summary->gpio) = GPIO_bit(summary->gpio);
184 +#ifdef CONFIG_PROC_GPIO_DEBUG
185 + printk(KERN_INFO "Set (%s,%s,%s) via /proc/gpio/%s\n",altfn ? (altfn == 1 ? "AF1" : (altfn == 2 ? "AF2" : "AF3")) : "GPIO",
186 + direction ? "out" : "in",
187 + setclear ? "set" : "clear",
194 + printk(KERN_CRIT "Parse error: Expect \"[GPIO|AF1|AF2|AF3]|[set|clear]|[in|out] ...\"\n");
198 +static int proc_gpio_read(char *page, char **start, off_t off,
199 + int count, int *eof, void *data)
202 + gpio_summary_type *summary = data;
206 + p += sprintf(p, "%d\t%s\t%s\t%s\n", i,
207 + (af = ((GAFR(i) >> ((i & 0x0f) << 0x01)) & 0x03)) ? (af == 1 ? "AF1" : (af == 2 ? "AF2" : "AF3")) : "GPIO",
208 + (GPDR(i) & GPIO_bit(i)) ? "out" : "in",
209 + (GPLR(i) & GPIO_bit(i)) ? "set" : "clear");
211 + len = (p - page) - off;
218 + *eof = (len <= count) ? 1 : 0;
219 + *start = page + off;
225 +#ifdef CONFIG_PXA25x
226 +static const char const *GAFR_DESC[] = { "GAFR0_L", "GAFR0_U", "GAFR1_L", "GAFR1_U", "GAFR2_L", "GAFR2_U" };
227 +#elif defined(CONFIG_PXA27x)
228 +static const char const *GAFR_DESC[] = { "GAFR0_L", "GAFR0_U", "GAFR1_L", "GAFR1_U", "GAFR2_L", "GAFR2_U", "GAFR3_L", "GAFR3_U" };
231 +static int proc_gafr_read(char *page, char **start, off_t off,
232 + int count, int *eof, void *data)
237 + for(i=0; i<ARRAY_SIZE(GAFR_DESC); i++)
239 + p += sprintf(p, "%s: %08x\n", GAFR_DESC[i], GAFR(i*16));
242 + len = (p - page) - off;
249 + *eof = (len <= count) ? 1 : 0;
250 + *start = page + off;
255 +static int proc_gpdr_read(char *page, char **start, off_t off,
256 + int count, int *eof, void *data)
261 + for(i=0; i<=2; i++)
263 + p += sprintf(p, "GPDR%d: %08x\n", i, GPDR(i * 32));
266 + len = (p - page) - off;
273 + *eof = (len <= count) ? 1 : 0;
274 + *start = page + off;
279 +static int proc_gplr_read(char *page, char **start, off_t off,
280 + int count, int *eof, void *data)
285 + for(i=0; i<=2; i++)
287 + p += sprintf(p, "GPLR%d: %08x\n", i, GPLR(i * 32));
290 + len = (p - page) - off;
297 + *eof = (len <= count) ? 1 : 0;
298 + *start = page + off;
303 +static int __init gpio_init(void)
307 + proc_gpio_parent = create_proc_entry("gpio", S_IFDIR | S_IRUGO | S_IXUGO, NULL);
308 + if(!proc_gpio_parent) return 0;
310 + for(i=0; i < (PXA_LAST_GPIO+1); i++)
312 + gpio_summaries[i].gpio = i;
313 + sprintf(gpio_summaries[i].name, "GPIO%d", i);
314 + proc_gpios[i] = create_proc_entry(gpio_summaries[i].name, 0644, proc_gpio_parent);
317 + proc_gpios[i]->data = &gpio_summaries[i];
318 + proc_gpios[i]->read_proc = proc_gpio_read;
319 + proc_gpios[i]->write_proc = proc_gpio_write;
323 + create_proc_read_entry("GAFR", 0444, proc_gpio_parent, proc_gafr_read, NULL);
324 + create_proc_read_entry("GPDR", 0444, proc_gpio_parent, proc_gpdr_read, NULL);
325 + create_proc_read_entry("GPLR", 0444, proc_gpio_parent, proc_gplr_read, NULL);
330 +static void gpio_exit(void)
334 + remove_proc_entry("GAFR", proc_gpio_parent);
335 + remove_proc_entry("GPDR", proc_gpio_parent);
336 + remove_proc_entry("GPLR", proc_gpio_parent);
338 + for(i=0; i < (PXA_LAST_GPIO+1); i++)
340 + if(proc_gpios[i]) remove_proc_entry(gpio_summaries[i].name, proc_gpio_parent);
342 + if(proc_gpio_parent) remove_proc_entry("gpio", NULL);
345 +module_init(gpio_init);
346 +module_exit(gpio_exit);
347 +MODULE_LICENSE("GPL");