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