4 depends on PCI && ARCH_SHARK
7 +source "drivers/gpio/Kconfig"
9 source "drivers/pci/Kconfig"
11 source "drivers/pcmcia/Kconfig"
12 --- a/drivers/Makefile
13 +++ b/drivers/Makefile
15 obj-$(CONFIG_DMA_ENGINE) += dma/
16 obj-$(CONFIG_HID) += hid/
17 obj-$(CONFIG_PPC_PS3) += ps3/
18 +obj-$(CONFIG_PROC_GPIO) += gpio/
20 +++ b/drivers/gpio/Kconfig
23 + tristate "GPIO /proc interface"
24 + depends on PXA25x || PXA27x
26 + This enables an interface under /proc/gpio which allows reading or setting
27 + of any GPIO, and also changing the GPIO alt function mode of any line.
29 +config PROC_GPIO_DEBUG
30 + boolean "Enable /proc/gpio debug logging"
31 + depends on PROC_GPIO
33 + This enables printk logging of activity done through /proc/gpio
36 +++ b/drivers/gpio/Makefile
38 +# Expose GPIOs under /proc
39 +obj-$(CONFIG_PROC_GPIO) += proc_gpio.o
41 +++ b/drivers/gpio/proc_gpio.c
45 + * PXA25x GPIOs exposed under /proc for reading and writing
46 + * They will show up under /proc/gpio/NN
48 + * Based on patch 1773/1 in the arm kernel patch repository at arm.linux.co.uk
52 +#include <linux/module.h>
53 +#include <linux/init.h>
54 +#include <linux/proc_fs.h>
55 +#include <linux/string.h>
56 +#include <linux/ctype.h>
58 +#include <asm/hardware.h>
59 +#include <asm/arch/pxa-regs.h>
60 +#include <asm/uaccess.h>
62 +static struct proc_dir_entry *proc_gpio_parent;
63 +static struct proc_dir_entry *proc_gpios[PXA_LAST_GPIO + 1];
71 +static gpio_summary_type gpio_summaries[PXA_LAST_GPIO + 1];
73 +static int proc_gpio_write(struct file *file, const char __user *buf,
74 + unsigned long count, void *data)
76 + char *cur, lbuf[count + 1];
77 + gpio_summary_type *summary = data;
78 + u32 altfn, direction, setclear, gafr;
80 + if (!capable(CAP_SYS_ADMIN))
83 + memset(lbuf, 0, count + 1);
85 + if (copy_from_user(lbuf, buf, count))
90 + // Initialize to current state
91 + altfn = ((GAFR(summary->gpio) >> ((summary->gpio & 0x0f) << 0x01)) & 0x03);
92 + direction = GPDR(summary->gpio) & GPIO_bit(summary->gpio);
93 + setclear = GPLR(summary->gpio) & GPIO_bit(summary->gpio);
96 + // We accept options: {GPIO|AF1|AF2|AF3}, {set|clear}, {in|out}
97 + // Anything else is an error
98 + while(cur[0] && (isspace(cur[0]) || ispunct(cur[0]))) cur = &(cur[1]);
100 + if('\0' == cur[0]) break;
102 + // Ok, so now we're pointing at the start of something
106 + // Check that next is "PIO" -- '\0' will cause safe short-circuit if end of buf
107 + if(!(cur[1] == 'P' && cur[2] == 'I' && cur[3] == 'O')) goto parse_error;
108 + // Ok, so set this GPIO to GPIO (non-ALT) function
113 + if(!(cur[1] == 'F' && cur[2] >= '1' && cur[2] <= '3')) goto parse_error;
114 + altfn = cur[2] - '0';
118 + if(!(cur[1] == 'e' && cur[2] == 't')) goto parse_error;
123 + if(!(cur[1] == 'l' && cur[2] == 'e' && cur[3] == 'a' && cur[4] == 'r')) goto parse_error;
128 + if(!(cur[1] == 'n')) goto parse_error;
133 + if(!(cur[1] == 'u' && cur[2] == 't')) goto parse_error;
137 + default: goto parse_error;
140 + // Ok, now set gpio mode and value
142 + GPDR(summary->gpio) |= GPIO_bit(summary->gpio);
144 + GPDR(summary->gpio) &= ~GPIO_bit(summary->gpio);
146 + gafr = GAFR(summary->gpio) & ~(0x3 << (((summary->gpio) & 0xf)*2));
147 + GAFR(summary->gpio) = gafr | (altfn << (((summary->gpio) & 0xf)*2));
149 + if(direction && !altfn)
151 + if(setclear) GPSR(summary->gpio) = GPIO_bit(summary->gpio);
152 + else GPCR(summary->gpio) = GPIO_bit(summary->gpio);
155 +#ifdef CONFIG_PROC_GPIO_DEBUG
156 + printk(KERN_INFO "Set (%s,%s,%s) via /proc/gpio/%s\n",altfn ? (altfn == 1 ? "AF1" : (altfn == 2 ? "AF2" : "AF3")) : "GPIO",
157 + direction ? "out" : "in",
158 + setclear ? "set" : "clear",
165 + printk(KERN_CRIT "Parse error: Expect \"[GPIO|AF1|AF2|AF3]|[set|clear]|[in|out] ...\"\n");
169 +static int proc_gpio_read(char *page, char **start, off_t off,
170 + int count, int *eof, void *data)
173 + gpio_summary_type *summary = data;
177 + p += sprintf(p, "%d\t%s\t%s\t%s\n", i,
178 + (af = ((GAFR(i) >> ((i & 0x0f) << 0x01)) & 0x03)) ? (af == 1 ? "AF1" : (af == 2 ? "AF2" : "AF3")) : "GPIO",
179 + (GPDR(i) & GPIO_bit(i)) ? "out" : "in",
180 + (GPLR(i) & GPIO_bit(i)) ? "set" : "clear");
182 + len = (p - page) - off;
189 + *eof = (len <= count) ? 1 : 0;
190 + *start = page + off;
196 +#ifdef CONFIG_PXA25x
197 +static const char const *GAFR_DESC[] = { "GAFR0_L", "GAFR0_U", "GAFR1_L", "GAFR1_U", "GAFR2_L", "GAFR2_U" };
198 +#elif defined(CONFIG_PXA27x)
199 +static const char const *GAFR_DESC[] = { "GAFR0_L", "GAFR0_U", "GAFR1_L", "GAFR1_U", "GAFR2_L", "GAFR2_U", "GAFR3_L", "GAFR3_U" };
202 +static int proc_gafr_read(char *page, char **start, off_t off,
203 + int count, int *eof, void *data)
208 + for(i=0; i<ARRAY_SIZE(GAFR_DESC); i++)
210 + p += sprintf(p, "%s: %08x\n", GAFR_DESC[i], GAFR(i*16));
213 + len = (p - page) - off;
220 + *eof = (len <= count) ? 1 : 0;
221 + *start = page + off;
226 +static int proc_gpdr_read(char *page, char **start, off_t off,
227 + int count, int *eof, void *data)
232 + for(i=0; i<=2; i++)
234 + p += sprintf(p, "GPDR%d: %08x\n", i, GPDR(i * 32));
237 + len = (p - page) - off;
244 + *eof = (len <= count) ? 1 : 0;
245 + *start = page + off;
250 +static int proc_gplr_read(char *page, char **start, off_t off,
251 + int count, int *eof, void *data)
256 + for(i=0; i<=2; i++)
258 + p += sprintf(p, "GPLR%d: %08x\n", i, GPLR(i * 32));
261 + len = (p - page) - off;
268 + *eof = (len <= count) ? 1 : 0;
269 + *start = page + off;
274 +static int __init gpio_init(void)
278 + proc_gpio_parent = create_proc_entry("gpio", S_IFDIR | S_IRUGO | S_IXUGO, NULL);
279 + if(!proc_gpio_parent) return 0;
281 + for(i=0; i < (PXA_LAST_GPIO+1); i++)
283 + gpio_summaries[i].gpio = i;
284 + sprintf(gpio_summaries[i].name, "GPIO%d", i);
285 + proc_gpios[i] = create_proc_entry(gpio_summaries[i].name, 0644, proc_gpio_parent);
288 + proc_gpios[i]->data = &gpio_summaries[i];
289 + proc_gpios[i]->read_proc = proc_gpio_read;
290 + proc_gpios[i]->write_proc = proc_gpio_write;
294 + create_proc_read_entry("GAFR", 0444, proc_gpio_parent, proc_gafr_read, NULL);
295 + create_proc_read_entry("GPDR", 0444, proc_gpio_parent, proc_gpdr_read, NULL);
296 + create_proc_read_entry("GPLR", 0444, proc_gpio_parent, proc_gplr_read, NULL);
301 +static void gpio_exit(void)
305 + remove_proc_entry("GAFR", proc_gpio_parent);
306 + remove_proc_entry("GPDR", proc_gpio_parent);
307 + remove_proc_entry("GPLR", proc_gpio_parent);
309 + for(i=0; i < (PXA_LAST_GPIO+1); i++)
311 + if(proc_gpios[i]) remove_proc_entry(gpio_summaries[i].name, proc_gpio_parent);
313 + if(proc_gpio_parent) remove_proc_entry("gpio", NULL);
316 +module_init(gpio_init);
317 +module_exit(gpio_exit);
318 +MODULE_LICENSE("GPL");