Added gpio and led drivers for 2.6.25.10 kernel
[openwrt/staging/dedeckeh.git] / target / linux / at91 / patches-2.6.25 / 003-gpio-driver.patch
1 diff -urN linux-2.6.25.10.old/arch/arm/mach-at91/board-vlink.c linux-2.6.25.10/arch/arm/mach-at91/board-vlink.c
2 --- linux-2.6.25.10.old/arch/arm/mach-at91/board-vlink.c 2008-07-07 11:20:21.000000000 +0200
3 +++ linux-2.6.25.10/arch/arm/mach-at91/board-vlink.c 2008-07-07 12:11:40.000000000 +0200
4 @@ -99,7 +99,7 @@
5 */
6
7 static struct at91_mmc_data __initdata vlink_mmc_data = {
8 -// .det_pin = AT91_PIN_PB27,
9 +// .det_pin = AT91_PIN_PC10,
10 .slot_b = 0,
11 .wire4 = 1,
12 // .wp_pin = AT91_PIN_PA17,
13 @@ -136,6 +136,7 @@
14
15 static void __init vlink_board_init(void)
16 {
17 + int v100;
18 /* Serial */
19 at91_add_device_serial();
20 /* Ethernet */
21 @@ -157,36 +158,66 @@
22 // at91_set_gpio_output(AT91_PIN_PB22, 1); /* this MMC card slot can optionally use SPI signaling (CS3). */
23 at91_add_device_mmc(0, &vlink_mmc_data);
24 #endif
25 +
26 +// Set VLink version PIN as an input with pull-up (V1.5 = GND)
27 + at91_set_gpio_input(AT91_PIN_PC2, 1);
28 + v100 = at91_get_gpio_value(AT91_PIN_PC2);
29 +
30 /* LEDs */
31 // at91_gpio_leds(vlink_leds, ARRAY_SIZE(vlink_leds));
32
33 /* Other LED's */
34 - at91_set_gpio_output(AT91_PIN_PC7, 1); // LED FRONT AP1
35 - at91_set_gpio_output(AT91_PIN_PC8, 1); // LED FRONT BP1
36 - at91_set_gpio_output(AT91_PIN_PB14, 1); // LED BACK AP1
37 - at91_set_gpio_output(AT91_PIN_PB15, 1); // LED BACK BP1
38 - at91_set_gpio_output(AT91_PIN_PB16, 1); // LED BACK AP2
39 - at91_set_gpio_output(AT91_PIN_PB17, 1); // LED BACK BP2
40 + at91_set_gpio_output(AT91_PIN_PC7, 1); // LED FRONT AP1
41 + at91_set_gpio_output(AT91_PIN_PC8, 1); // LED FRONT BP1
42 + at91_set_gpio_output(AT91_PIN_PB14, 1); // LED BACK AP1
43 + at91_set_gpio_output(AT91_PIN_PB15, 1); // LED BACK BP1
44 + at91_set_gpio_output(AT91_PIN_PB16, 1); // LED BACK AP2
45 + at91_set_gpio_output(AT91_PIN_PB17, 1); // LED BACK BP2
46 +
47 +/* Test jig presence detection */
48 + at91_set_gpio_input(AT91_PIN_PB8, 1); // JIGPRESENT
49
50 /* SIM Cards */
51 - at91_set_gpio_output(AT91_PIN_PB9, 1); // ENBSC3
52 - at91_set_gpio_output(AT91_PIN_PB10, 1); // ENBSC2
53 - at91_set_gpio_output(AT91_PIN_PB11, 1); // ENBSC1
54 + if (at91_get_gpio_value(AT91_PIN_PB8)) {
55 + at91_set_gpio_output(AT91_PIN_PB11, 0);
56 + if (v100)
57 + at91_set_gpio_output(AT91_PIN_PB9, 1);
58 + else
59 + at91_set_gpio_output(AT91_PIN_PC13, 1);
60 + } else {
61 + at91_set_gpio_output(AT91_PIN_PB11, 1);
62 + if (v100)
63 + at91_set_gpio_output(AT91_PIN_PB9, 0);
64 + else
65 + at91_set_gpio_output(AT91_PIN_PC13, 0);
66 + }
67
68 -/* GSM Module Control */
69 - at91_set_gpio_output(AT91_PIN_PB12, 1); // GSMONOFF
70 + at91_set_gpio_output(AT91_PIN_PB10, 1); // ENBSC2
71
72 -/* Test jig presence detection */
73 - at91_set_gpio_input(AT91_PIN_PB8, 1); // JIGPRESENT
74 +/* GSM Module Control */
75 + at91_set_gpio_output(AT91_PIN_PB12, 1); // GSMONOFF
76
77 /* Power indicator */
78 - at91_set_gpio_input(AT91_PIN_PB22, 1); // PWR_IND
79 + at91_set_gpio_input(AT91_PIN_PB22, 1); // PWR_IND
80
81 /* USB Device control */
82 - at91_set_gpio_input(AT91_PIN_PB27, 1); // UDB_CNX
83 - at91_set_gpio_output(AT91_PIN_PB28, 1); // UDB_PUP
84 - at91_set_multi_drive(AT91_PIN_PB28, 1); // Set to multi-drive
85 -
86 + at91_set_gpio_input(AT91_PIN_PB27, 1); // UDB_CNX
87 + at91_set_gpio_output(AT91_PIN_PB28, 1); // UDB_PUP
88 + at91_set_multi_drive(AT91_PIN_PB28, 1); // Set to multi-drive
89 +
90 +/* USB Power controls */
91 +
92 + if (v100)
93 + { // V100
94 + at91_set_gpio_input (AT91_PIN_PC12, 1); // SD Card present
95 + }
96 + else
97 + { // DO special things for V1.5
98 + at91_set_gpio_output(AT91_PIN_PB9 , 0); // USB suspend
99 + at91_set_gpio_input (AT91_PIN_PC10, 1); // SD Card present
100 + at91_set_gpio_output(AT91_PIN_PC11, 0); // USB Vin CTRL for modules onboard
101 + at91_set_gpio_output(AT91_PIN_PC12, 0); // SIM control
102 + }
103 }
104
105 MACHINE_START(VLINK, "FDL VersaLink")
106 diff -urN linux-2.6.25.10.old/arch/arm/mach-at91/gpio.c linux-2.6.25.10/arch/arm/mach-at91/gpio.c
107 --- linux-2.6.25.10.old/arch/arm/mach-at91/gpio.c 2008-07-07 11:20:21.000000000 +0200
108 +++ linux-2.6.25.10/arch/arm/mach-at91/gpio.c 2008-07-07 11:42:33.000000000 +0200
109 @@ -29,6 +29,7 @@
110
111 static struct at91_gpio_bank *gpio;
112 static int gpio_banks;
113 +static u32 pio_gpio_pin[4] = { 0, 0, 0, 0 };
114
115
116 static inline void __iomem *pin_to_controller(unsigned pin)
117 @@ -71,9 +72,13 @@
118 {
119 void __iomem *pio = pin_to_controller(pin);
120 unsigned mask = pin_to_mask(pin);
121 + int bank = (pin - PIN_BASE) / 32;
122
123 if (!pio)
124 return -EINVAL;
125 +
126 + pio_gpio_pin[bank] |= mask;
127 +
128 __raw_writel(mask, pio + PIO_IDR);
129 __raw_writel(mask, pio + (use_pullup ? PIO_PUER : PIO_PUDR));
130 __raw_writel(mask, pio + PIO_PER);
131 @@ -130,10 +135,13 @@
132 {
133 void __iomem *pio = pin_to_controller(pin);
134 unsigned mask = pin_to_mask(pin);
135 + int bank = (pin - PIN_BASE) / 32;
136
137 if (!pio)
138 return -EINVAL;
139
140 + pio_gpio_pin[bank] |= mask;
141 +
142 __raw_writel(mask, pio + PIO_IDR);
143 __raw_writel(mask, pio + (use_pullup ? PIO_PUER : PIO_PUDR));
144 __raw_writel(mask, pio + PIO_ODR);
145 @@ -151,10 +159,13 @@
146 {
147 void __iomem *pio = pin_to_controller(pin);
148 unsigned mask = pin_to_mask(pin);
149 + int bank = (pin - PIN_BASE) / 32;
150
151 if (!pio)
152 return -EINVAL;
153
154 + pio_gpio_pin[bank] |= mask;
155 +
156 __raw_writel(mask, pio + PIO_IDR);
157 __raw_writel(mask, pio + PIO_PUDR);
158 __raw_writel(mask, pio + (value ? PIO_SODR : PIO_CODR));
159 @@ -262,6 +273,18 @@
160 }
161 EXPORT_SYMBOL(at91_get_gpio_value);
162
163 +int at91_is_pin_gpio(unsigned pin)
164 +{
165 + void __iomem *pio = pin_to_controller(pin);
166 + unsigned mask = pin_to_mask(pin);
167 + int bank = (pin - PIN_BASE) / 32;
168 +
169 + if (!pio)
170 + return -EINVAL;
171 + return (pio_gpio_pin[bank] & mask) != 0;
172 +}
173 +EXPORT_SYMBOL(at91_is_pin_gpio);
174 +
175 /*--------------------------------------------------------------------------*/
176
177 #ifdef CONFIG_PM
178 diff -urN linux-2.6.25.10.old/drivers/char/Kconfig linux-2.6.25.10/drivers/char/Kconfig
179 --- linux-2.6.25.10.old/drivers/char/Kconfig 2008-07-07 11:20:21.000000000 +0200
180 +++ linux-2.6.25.10/drivers/char/Kconfig 2008-07-07 11:42:33.000000000 +0200
181 @@ -1072,5 +1072,12 @@
182 The SPI driver gives user mode access to this serial
183 bus on the AT91RM9200 processor.
184
185 +config AT91_VLIO
186 + tristate "Versalink LED and GPIO interface"
187 + depends on ARCH_AT91RM9200 && MACH_VLINK
188 + default n
189 + help
190 + Provides a handler GPIO's in userspace
191 +
192 endmenu
193
194 diff -urN linux-2.6.25.10.old/drivers/char/Makefile linux-2.6.25.10/drivers/char/Makefile
195 --- linux-2.6.25.10.old/drivers/char/Makefile 2008-07-07 11:20:21.000000000 +0200
196 +++ linux-2.6.25.10/drivers/char/Makefile 2008-07-07 11:42:33.000000000 +0200
197 @@ -100,6 +100,7 @@
198 obj-$(CONFIG_TELCLOCK) += tlclk.o
199 obj-$(CONFIG_AT91_SPI) += at91_spi.o
200 obj-$(CONFIG_AT91_SPIDEV) += at91_spidev.o
201 +obj-$(CONFIG_AT91_VLIO) += vlink_giu.o
202
203 obj-$(CONFIG_MWAVE) += mwave/
204 obj-$(CONFIG_AGP) += agp/
205 diff -urN linux-2.6.25.10.old/drivers/char/vlink_giu.c linux-2.6.25.10/drivers/char/vlink_giu.c
206 --- linux-2.6.25.10.old/drivers/char/vlink_giu.c 1970-01-01 01:00:00.000000000 +0100
207 +++ linux-2.6.25.10/drivers/char/vlink_giu.c 2008-07-07 13:41:51.000000000 +0200
208 @@ -0,0 +1,333 @@
209 +/*
210 + * Driver for FDL Versalink GPIO
211 + *
212 + * Copyright (C) 2005 Guthrie Consulting
213 + * Author: Hamish Guthrie <hamish@prodigi.ch>
214 + *
215 + * This program is free software; you can redistribute it and/or modify
216 + * it under the terms of the GNU General Public License as published by
217 + * the Free Software Foundation; either version 2 of the License, or
218 + * (at your option) any later version.
219 + *
220 + * This program is distributed in the hope that it will be useful,
221 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
222 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
223 + * GNU General Public License for more details.
224 + *
225 + * You should have received a copy of the GNU General Public License
226 + * along with this program; if not, write to the Free Software
227 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
228 + */
229 +
230 +#include <linux/module.h>
231 +#include <linux/moduleparam.h>
232 +#include <linux/init.h>
233 +#include <linux/platform_device.h>
234 +
235 +#include <linux/kernel.h>
236 +#include <linux/slab.h>
237 +#include <linux/fs.h>
238 +#include <linux/errno.h>
239 +#include <linux/init.h>
240 +#include <linux/types.h>
241 +#include <linux/proc_fs.h>
242 +#include <linux/fcntl.h>
243 +#include <linux/seq_file.h>
244 +#include <linux/cdev.h>
245 +#include <asm/arch/gpio.h>
246 +#include <asm/uaccess.h>
247 +
248 +static int major; /* default is dynamic major device number */
249 +module_param(major, int, 0);
250 +MODULE_PARM_DESC(major, "Major device number");
251 +
252 +#define VIO_NR_DEVS 96
253 +
254 +struct vio_dev {
255 + struct cdev cdev;
256 +};
257 +
258 +struct vio_dev *vio_devices;
259 +static struct class *vio_class;
260 +
261 +#define MAX_VIO_NAMES 24
262 +typedef struct
263 +{
264 + char port;
265 + char pin;
266 + char name100[10];
267 + char name150[10];
268 +} VIO_NAMES;
269 +
270 +VIO_NAMES VioName[MAX_VIO_NAMES] =
271 +{ // Port, Pin, V100, V150
272 + {'A',19,"port1DTR" ,"port1DTR"},
273 + {'A',24,"port2DTR" ,"port2DTR"},
274 + {'B',8, "jigOn" ,"jigOn"} ,
275 + {'B',9, "enbSC3" ,"usbSUSPND"},
276 + {'B',10,"enbSC2" ,"enbSC2"},
277 + {'B',11,"enbSC1" ,"enbSC1"},
278 + {'B',12,"gsmONOFF" ,"gsmONOFF"},
279 + {'B',14,"ledBAP1" ,"ledBAP1"},
280 + {'B',15,"ledBBP1" ,"ledBBP1"},
281 + {'B',16,"ledBAP2" ,"ledBAP2"},
282 + {'B',17,"ledBBP2" ,"ledBBP2"},
283 + {'B',27,"udpCNX" ,"udpCNX"},
284 + {'B',28,"udpPUP" ,"udpPUP"},
285 + {'B',29,"port2DCD" ,"port2DCD"},
286 + {'C',2, "vlVer100" ,"vlVer150"},
287 + {'C',7, "ledFAP1" ,"ledFAP1"},
288 + {'C',8, "ledFBP1" ,"ledFBP1"},
289 + {'C',10,"vioC10" ,"sdCardON"},
290 + {'C',11,"vioC11" ,"vusbCTRL"},
291 + {'C',12,"sdCardON" ,"simCTRL"},
292 + {'C',13,"vioC13" ,"enbSC3"},
293 + {'C',14,"ledFBP2" ,"ledFBP2"},
294 + {'C',15,"ledFAP2" ,"ledFAP2"},
295 + {0,0,"",""}
296 +};
297 +
298 +/*
299 +{'B',18,"gsmRIO" ,"gsmRIO"},
300 +{'B',20,"gsmTX" ,"gsmTX"},
301 +{'B',21,"gsmRX" ,"gsmRX"},
302 +{'B',22,"gsmPIND" ,"gsmPIND"},
303 +{'B',23,"gsmDCD" ,"gsmDCD"},
304 +{'B',24,"gsmCTS" ,"gsmCTS"},
305 +{'B',25,"gsmDSR" ,"gsmDSR"},
306 +{'B',26,"gsmRTS" ,"gsmRTS"},
307 +*/
308 +static void lookupPINName(char version100, char *devName, char port, char pin);
309 +// EOF KWJ + AJE
310 +
311 +static ssize_t gpio_read(struct file *file, char __user *buf, size_t len,
312 + loff_t *ppos)
313 +{
314 + unsigned int pin;
315 + int retval;
316 + char value = '0';
317 +
318 + pin = iminor(file->f_dentry->d_inode);
319 +
320 + retval = at91_get_gpio_value(PIN_BASE + pin);
321 + if (retval < 0)
322 + return -EFAULT;
323 +
324 + value = retval + 0x30;
325 + if (put_user(value, buf))
326 + return -EFAULT;
327 +
328 + return 1;
329 +}
330 +
331 +static ssize_t gpio_write(struct file *file, const char __user *data,
332 + size_t len, loff_t *ppos)
333 +{
334 + unsigned int pin;
335 + size_t i;
336 + char c;
337 + int retval = 0;
338 +
339 + pin = iminor(file->f_dentry->d_inode);
340 +
341 + for (i = 0; i < len; i++) {
342 + if (get_user(c, data + i))
343 + return -EFAULT;
344 +
345 + switch (c) {
346 + case '0':
347 + case '1':
348 + retval = at91_set_gpio_value(PIN_BASE + pin, (int)c - 0x30);
349 + if (retval < 0)
350 + return -EFAULT;
351 + break;
352 + default:
353 + break;
354 + }
355 +
356 + if (retval < 0)
357 + break;
358 + }
359 +
360 + return i;
361 +}
362 +
363 +static int gpio_open(struct inode *inode, struct file *file)
364 +{
365 + return nonseekable_open(inode, file);
366 +}
367 +
368 +static int gpio_release(struct inode *inode, struct file *file)
369 +{
370 + return 0;
371 +}
372 +
373 +static struct file_operations vio_fops = {
374 + .owner = THIS_MODULE,
375 + .read = gpio_read,
376 + .write = gpio_write,
377 + .open = gpio_open,
378 + .release = gpio_release,
379 +};
380 +
381 +static void vio_setup_cdev(struct vio_dev *dev, int index)
382 +{
383 + int err, devno = MKDEV(major, index);
384 +
385 + cdev_init(&dev->cdev, &vio_fops);
386 + dev->cdev.owner = THIS_MODULE;
387 + dev->cdev.ops = &vio_fops;
388 + err = cdev_add (&dev->cdev, devno, 1);
389 + if (err)
390 + printk(KERN_NOTICE "vio: Error %d adding vio%d", err, index);
391 +}
392 +
393 +static int vio_remove(struct platform_device *dev)
394 +{
395 + int i;
396 + dev_t devno = MKDEV(major, 0);
397 +
398 + if (vio_devices) {
399 + for(i=0; i<VIO_NR_DEVS; i++) {
400 + int iodev = at91_is_pin_gpio(PIN_BASE + i);
401 + if (iodev) {
402 + cdev_del(&vio_devices[i].cdev);
403 + class_device_destroy(vio_class, MKDEV(major, i));
404 + }
405 + }
406 + kfree(vio_devices);
407 + }
408 +
409 + class_destroy(vio_class);
410 + unregister_chrdev_region(devno, VIO_NR_DEVS);
411 +
412 + platform_set_drvdata(dev, NULL);
413 +
414 + return 0;
415 +}
416 +
417 +static int vio_probe(struct platform_device *dev)
418 +{
419 + int retval, i, j;
420 + dev_t vdev = 0;
421 + char devName[30];
422 + int vlinkV100;
423 +
424 + if (major) {
425 + vdev = MKDEV(major, 0);
426 + retval = register_chrdev_region(vdev, VIO_NR_DEVS, "vio");
427 + } else {
428 + retval = alloc_chrdev_region(&vdev, 0, VIO_NR_DEVS, "vio");
429 + major = MAJOR(vdev);
430 + }
431 + if (retval < 0) {
432 + printk(KERN_WARNING "vio: can't get major %d\n", major);
433 + return retval;
434 + }
435 +
436 + if (major == 0) {
437 + major = retval;
438 + printk(KERN_INFO "vio: major number %d\n", major);
439 + }
440 +
441 + vio_class = class_create(THIS_MODULE, "vio");
442 +
443 + if (IS_ERR(vio_class)) {
444 + printk(KERN_ERR "vio: Error creating vio class\n");
445 + vio_remove(dev);
446 + return PTR_ERR(vio_class);
447 + }
448 +
449 + vlinkV100 = at91_get_gpio_value(AT91_PIN_PC2); // Denotes V1.5 if GND
450 +
451 + vio_devices = kmalloc(VIO_NR_DEVS * sizeof(struct vio_dev), GFP_KERNEL);
452 + if (!vio_devices) {
453 + retval = -ENOMEM;
454 + goto fail;
455 + }
456 + memset(vio_devices, 0, VIO_NR_DEVS * sizeof(struct vio_dev));
457 +
458 + for (i=0; i<VIO_NR_DEVS/32; i++)
459 + for(j=0; j<32; j++) {
460 + int iodev = at91_is_pin_gpio(PIN_BASE + i*32 + j);
461 + if (iodev) {
462 + vio_setup_cdev(&vio_devices[i*32 + j], i*32 + j);
463 + // Lookup name of vio to create
464 + lookupPINName(vlinkV100, devName, i, j);
465 + class_device_create(vio_class, NULL, MKDEV(major, i*32 + j), NULL, devName);
466 + }
467 + }
468 +
469 + platform_set_drvdata(dev, vio_devices);
470 +
471 + return 0;
472 +
473 +fail:
474 + vio_remove(dev);
475 + return retval;
476 +}
477 +
478 +static void lookupPINName(char version100, char *devName, char port, char pin)
479 +{
480 + int i = -1;
481 + char found = 0;
482 + while (!found)
483 + {
484 + i++;
485 + if (i >= MAX_VIO_NAMES)
486 + break;
487 + if (VioName[i].port == port+'A' && VioName[i].pin == pin)
488 + {
489 + printk(KERN_ERR "vio++: %c%d=%s\n",VioName[i].port,VioName[i].pin,VioName[i].name150);
490 + if (version100)
491 + strcpy(devName, VioName[i].name100);
492 + else
493 + strcpy(devName, VioName[i].name150);
494 + found = 1;
495 + }
496 + }
497 + if (!found)
498 + sprintf(devName, "vio%c%d", port + 'A', pin);
499 +}
500 +
501 +static struct platform_device *vio_platform_device;
502 +
503 +static struct platform_driver vio_driver = {
504 + .probe = vio_probe,
505 + .remove = vio_remove,
506 + .driver = {
507 + .name = "vio",
508 + .owner = THIS_MODULE,
509 + },
510 +};
511 +
512 +static int __init vio_init(void)
513 +{
514 + int retval;
515 +
516 + vio_platform_device = platform_device_register_simple("vio", -1, NULL, 0);
517 + if (IS_ERR(vio_platform_device)) {
518 + printk(KERN_WARNING "vio: device registration failed\n");
519 + return PTR_ERR(vio_platform_device);
520 + }
521 +
522 + retval = platform_driver_register(&vio_driver);
523 + if (retval < 0) {
524 + printk(KERN_WARNING "vio: driver registration failed\n");
525 + platform_device_unregister(vio_platform_device);
526 + }
527 +
528 + return retval;
529 +}
530 +
531 +static void __exit vio_exit(void)
532 +{
533 + platform_driver_unregister(&vio_driver);
534 + platform_device_unregister(vio_platform_device);
535 +}
536 +
537 +module_init(vio_init);
538 +module_exit(vio_exit);
539 +
540 +MODULE_AUTHOR("Hamish Guthrie <hamish@prodigi.ch>");
541 +MODULE_DESCRIPTION("FDL Versalink GPIO Driver");
542 +MODULE_LICENSE("GPL");
543 --- linux-2.6.25.10.old/include/asm-arm/arch-at91/gpio.h 2008-07-03 05:46:47.000000000 +0200
544 +++ linux-2.6.25.10/include/asm-arm/arch-at91/gpio.h 2008-07-07 17:03:03.000000000 +0200
545 @@ -199,6 +199,7 @@
546 /* callable at any time */
547 extern int at91_set_gpio_value(unsigned pin, int value);
548 extern int at91_get_gpio_value(unsigned pin);
549 +extern int at91_is_pin_gpio(unsigned pin);
550
551 /* callable only from core power-management code */
552 extern void at91_gpio_suspend(void);