1 --- a/arch/arm/mach-at91/board-vlink.c
2 +++ b/arch/arm/mach-at91/board-vlink.c
6 static struct at91_mmc_data __initdata vlink_mmc_data = {
7 -// .det_pin = AT91_PIN_PB27,
8 +// .det_pin = AT91_PIN_PC10,
11 // .wp_pin = AT91_PIN_PA17,
14 static void __init vlink_board_init(void)
18 at91_add_device_serial();
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);
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);
30 // at91_gpio_leds(vlink_leds, ARRAY_SIZE(vlink_leds));
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
46 +/* Test jig presence detection */
47 + at91_set_gpio_input(AT91_PIN_PB8, 1); // JIGPRESENT
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);
56 + at91_set_gpio_output(AT91_PIN_PB9, 1);
58 + at91_set_gpio_output(AT91_PIN_PC13, 1);
60 + at91_set_gpio_output(AT91_PIN_PB11, 1);
62 + at91_set_gpio_output(AT91_PIN_PB9, 0);
64 + at91_set_gpio_output(AT91_PIN_PC13, 0);
67 -/* GSM Module Control */
68 - at91_set_gpio_output(AT91_PIN_PB12, 1); // GSMONOFF
69 + at91_set_gpio_output(AT91_PIN_PB10, 1); // ENBSC2
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
77 - at91_set_gpio_input(AT91_PIN_PB22, 1); // PWR_IND
78 + at91_set_gpio_input(AT91_PIN_PB22, 1); // PWR_IND
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
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
89 +/* USB Power controls */
93 + at91_set_gpio_input (AT91_PIN_PC12, 1); // SD Card present
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
104 MACHINE_START(VLINK, "FDL VersaLink")
105 --- a/arch/arm/mach-at91/gpio.c
106 +++ b/arch/arm/mach-at91/gpio.c
109 static struct at91_gpio_bank *gpio;
110 static int gpio_banks;
111 +static u32 pio_gpio_pin[4] = { 0, 0, 0, 0 };
114 static inline void __iomem *pin_to_controller(unsigned pin)
117 void __iomem *pio = pin_to_controller(pin);
118 unsigned mask = pin_to_mask(pin);
119 + int bank = (pin - PIN_BASE) / 32;
124 + pio_gpio_pin[bank] |= mask;
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 @@
131 void __iomem *pio = pin_to_controller(pin);
132 unsigned mask = pin_to_mask(pin);
133 + int bank = (pin - PIN_BASE) / 32;
138 + pio_gpio_pin[bank] |= mask;
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 @@
145 void __iomem *pio = pin_to_controller(pin);
146 unsigned mask = pin_to_mask(pin);
147 + int bank = (pin - PIN_BASE) / 32;
152 + pio_gpio_pin[bank] |= mask;
154 __raw_writel(mask, pio + PIO_IDR);
155 __raw_writel(mask, pio + PIO_PUDR);
156 __raw_writel(mask, pio + (value ? PIO_SODR : PIO_CODR));
159 EXPORT_SYMBOL(at91_get_gpio_value);
161 +int at91_is_pin_gpio(unsigned pin)
163 + void __iomem *pio = pin_to_controller(pin);
164 + unsigned mask = pin_to_mask(pin);
165 + int bank = (pin - PIN_BASE) / 32;
169 + return (pio_gpio_pin[bank] & mask) != 0;
171 +EXPORT_SYMBOL(at91_is_pin_gpio);
173 /*--------------------------------------------------------------------------*/
176 --- a/drivers/char/Kconfig
177 +++ b/drivers/char/Kconfig
178 @@ -1072,5 +1072,12 @@
179 The SPI driver gives user mode access to this serial
180 bus on the AT91RM9200 processor.
183 + tristate "Versalink LED and GPIO interface"
184 + depends on ARCH_AT91RM9200 && MACH_VLINK
187 + Provides a handler GPIO's in userspace
191 --- a/drivers/char/Makefile
192 +++ b/drivers/char/Makefile
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
199 obj-$(CONFIG_MWAVE) += mwave/
200 obj-$(CONFIG_AGP) += agp/
202 +++ b/drivers/char/vlink_giu.c
205 + * Driver for FDL Versalink GPIO
207 + * Copyright (C) 2005 Guthrie Consulting
208 + * Author: Hamish Guthrie <hamish@prodigi.ch>
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.
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.
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
225 +#include <linux/module.h>
226 +#include <linux/moduleparam.h>
227 +#include <linux/init.h>
228 +#include <linux/platform_device.h>
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>
243 +static int major; /* default is dynamic major device number */
244 +module_param(major, int, 0);
245 +MODULE_PARM_DESC(major, "Major device number");
247 +#define VIO_NR_DEVS 96
253 +struct vio_dev *vio_devices;
254 +static struct class *vio_class;
256 +#define MAX_VIO_NAMES 24
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"},
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"},
303 +static void lookupPINName(char version100, char *devName, char port, char pin);
306 +static ssize_t gpio_read(struct file *file, char __user *buf, size_t len,
313 + pin = iminor(file->f_dentry->d_inode);
315 + retval = at91_get_gpio_value(PIN_BASE + pin);
319 + value = retval + 0x30;
320 + if (put_user(value, buf))
326 +static ssize_t gpio_write(struct file *file, const char __user *data,
327 + size_t len, loff_t *ppos)
334 + pin = iminor(file->f_dentry->d_inode);
336 + for (i = 0; i < len; i++) {
337 + if (get_user(c, data + i))
343 + retval = at91_set_gpio_value(PIN_BASE + pin, (int)c - 0x30);
358 +static int gpio_open(struct inode *inode, struct file *file)
360 + return nonseekable_open(inode, file);
363 +static int gpio_release(struct inode *inode, struct file *file)
368 +static struct file_operations vio_fops = {
369 + .owner = THIS_MODULE,
371 + .write = gpio_write,
373 + .release = gpio_release,
376 +static void vio_setup_cdev(struct vio_dev *dev, int index)
378 + int err, devno = MKDEV(major, index);
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);
385 + printk(KERN_NOTICE "vio: Error %d adding vio%d", err, index);
388 +static int vio_remove(struct platform_device *dev)
391 + dev_t devno = MKDEV(major, 0);
394 + for(i=0; i<VIO_NR_DEVS; i++) {
395 + int iodev = at91_is_pin_gpio(PIN_BASE + i);
397 + cdev_del(&vio_devices[i].cdev);
398 + class_device_destroy(vio_class, MKDEV(major, i));
401 + kfree(vio_devices);
404 + class_destroy(vio_class);
405 + unregister_chrdev_region(devno, VIO_NR_DEVS);
407 + platform_set_drvdata(dev, NULL);
412 +static int vio_probe(struct platform_device *dev)
420 + vdev = MKDEV(major, 0);
421 + retval = register_chrdev_region(vdev, VIO_NR_DEVS, "vio");
423 + retval = alloc_chrdev_region(&vdev, 0, VIO_NR_DEVS, "vio");
424 + major = MAJOR(vdev);
427 + printk(KERN_WARNING "vio: can't get major %d\n", major);
433 + printk(KERN_INFO "vio: major number %d\n", major);
436 + vio_class = class_create(THIS_MODULE, "vio");
438 + if (IS_ERR(vio_class)) {
439 + printk(KERN_ERR "vio: Error creating vio class\n");
441 + return PTR_ERR(vio_class);
444 + vlinkV100 = at91_get_gpio_value(AT91_PIN_PC2); // Denotes V1.5 if GND
446 + vio_devices = kmalloc(VIO_NR_DEVS * sizeof(struct vio_dev), GFP_KERNEL);
447 + if (!vio_devices) {
451 + memset(vio_devices, 0, VIO_NR_DEVS * sizeof(struct vio_dev));
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);
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);
464 + platform_set_drvdata(dev, vio_devices);
473 +static void lookupPINName(char version100, char *devName, char port, char pin)
480 + if (i >= MAX_VIO_NAMES)
482 + if (VioName[i].port == port+'A' && VioName[i].pin == pin)
484 + printk(KERN_ERR "vio++: %c%d=%s\n",VioName[i].port,VioName[i].pin,VioName[i].name150);
486 + strcpy(devName, VioName[i].name100);
488 + strcpy(devName, VioName[i].name150);
493 + sprintf(devName, "vio%c%d", port + 'A', pin);
496 +static struct platform_device *vio_platform_device;
498 +static struct platform_driver vio_driver = {
499 + .probe = vio_probe,
500 + .remove = vio_remove,
503 + .owner = THIS_MODULE,
507 +static int __init vio_init(void)
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);
517 + retval = platform_driver_register(&vio_driver);
519 + printk(KERN_WARNING "vio: driver registration failed\n");
520 + platform_device_unregister(vio_platform_device);
526 +static void __exit vio_exit(void)
528 + platform_driver_unregister(&vio_driver);
529 + platform_device_unregister(vio_platform_device);
532 +module_init(vio_init);
533 +module_exit(vio_exit);
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
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);
545 /* callable only from core power-management code */
546 extern void at91_gpio_suspend(void);