1 diff -urN linux-2.6.19.2.old/arch/arm/mach-at91rm9200/gpio.c linux-2.6.19.2/arch/arm/mach-at91rm9200/gpio.c
2 --- linux-2.6.19.2.old/arch/arm/mach-at91rm9200/gpio.c 2007-03-06 22:49:37.000000000 +0100
3 +++ linux-2.6.19.2/arch/arm/mach-at91rm9200/gpio.c 2007-03-07 10:25:41.000000000 +0100
6 static struct at91_gpio_bank *gpio;
9 +static u32 pio_gpio_pin[4] = { 0, 0, 0, 0 };
11 static inline void __iomem *pin_to_controller(unsigned pin)
15 void __iomem *pio = pin_to_controller(pin);
16 unsigned mask = pin_to_mask(pin);
17 + int bank = (pin - PIN_BASE) / 32;
22 + pio_gpio_pin[bank] |= mask;
24 __raw_writel(mask, pio + PIO_IDR);
25 __raw_writel(mask, pio + (use_pullup ? PIO_PUER : PIO_PUDR));
26 __raw_writel(mask, pio + PIO_ODR);
29 void __iomem *pio = pin_to_controller(pin);
30 unsigned mask = pin_to_mask(pin);
31 + int bank = (pin - PIN_BASE) / 32;
36 + pio_gpio_pin[bank] |= mask;
38 __raw_writel(mask, pio + PIO_IDR);
39 __raw_writel(mask, pio + PIO_PUDR);
40 __raw_writel(mask, pio + (value ? PIO_SODR : PIO_CODR));
43 EXPORT_SYMBOL(at91_get_gpio_value);
45 +int at91_is_pin_gpio(unsigned pin)
47 + void __iomem *pio = pin_to_controller(pin);
48 + unsigned mask = pin_to_mask(pin);
49 + int bank = (pin - PIN_BASE) / 32;
53 + return (pio_gpio_pin[bank] & mask) != 0;
55 +EXPORT_SYMBOL(at91_is_pin_gpio);
57 /*--------------------------------------------------------------------------*/
60 diff -urN linux-2.6.19.2.old/drivers/char/Kconfig linux-2.6.19.2/drivers/char/Kconfig
61 --- linux-2.6.19.2.old/drivers/char/Kconfig 2007-03-06 22:49:37.000000000 +0100
62 +++ linux-2.6.19.2/drivers/char/Kconfig 2007-03-07 01:08:57.000000000 +0100
63 @@ -1064,5 +1064,12 @@
64 The SPI driver gives user mode access to this serial
65 bus on the AT91RM9200 processor.
68 + tristate "Versalink LED and GPIO interface"
69 + depends on ARCH_AT91RM9200 && MACH_VLINK
72 + Provides a handler for LED and GPIO in userspace
76 diff -urN linux-2.6.19.2.old/drivers/char/Makefile linux-2.6.19.2/drivers/char/Makefile
77 --- linux-2.6.19.2.old/drivers/char/Makefile 2007-03-06 22:49:37.000000000 +0100
78 +++ linux-2.6.19.2/drivers/char/Makefile 2007-03-07 01:08:05.000000000 +0100
80 obj-$(CONFIG_TELCLOCK) += tlclk.o
81 obj-$(CONFIG_AT91_SPI) += at91_spi.o
82 obj-$(CONFIG_AT91_SPIDEV) += at91_spidev.o
83 +obj-$(CONFIG_AT91_VLIO) += vlink_giu.o
85 obj-$(CONFIG_WATCHDOG) += watchdog/
86 obj-$(CONFIG_MWAVE) += mwave/
87 diff -urN linux-2.6.19.2.old/drivers/char/vlink_giu.c linux-2.6.19.2/drivers/char/vlink_giu.c
88 --- linux-2.6.19.2.old/drivers/char/vlink_giu.c 1970-01-01 01:00:00.000000000 +0100
89 +++ linux-2.6.19.2/drivers/char/vlink_giu.c 2007-03-07 01:21:21.000000000 +0100
92 + * Driver for FDL Versalink GPIO
94 + * Copyright (C) 2005 Guthrie Consulting
95 + * Author: Hamish Guthrie <hamish@prodigi.ch>
97 + * This program is free software; you can redistribute it and/or modify
98 + * it under the terms of the GNU General Public License as published by
99 + * the Free Software Foundation; either version 2 of the License, or
100 + * (at your option) any later version.
102 + * This program is distributed in the hope that it will be useful,
103 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
104 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
105 + * GNU General Public License for more details.
107 + * You should have received a copy of the GNU General Public License
108 + * along with this program; if not, write to the Free Software
109 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
112 +#include <linux/module.h>
113 +#include <linux/moduleparam.h>
114 +#include <linux/init.h>
115 +#include <linux/platform_device.h>
117 +#include <linux/kernel.h>
118 +#include <linux/slab.h>
119 +#include <linux/fs.h>
120 +#include <linux/errno.h>
121 +#include <linux/init.h>
122 +#include <linux/types.h>
123 +#include <linux/proc_fs.h>
124 +#include <linux/fcntl.h>
125 +#include <linux/seq_file.h>
126 +#include <linux/cdev.h>
127 +#include <asm/arch/gpio.h>
128 +#include <asm/uaccess.h>
130 +static int major; /* default is dynamic major device number */
131 +module_param(major, int, 0);
132 +MODULE_PARM_DESC(major, "Major device number");
134 +#define VIO_NR_DEVS 96
140 +struct vio_dev *vio_devices;
141 +static struct class *vio_class;
143 +static ssize_t gpio_read(struct file *file, char __user *buf, size_t len,
150 + pin = iminor(file->f_dentry->d_inode);
152 + retval = at91_get_gpio_value(PIN_BASE + pin);
156 + value = retval + 0x30;
157 + if (put_user(value, buf))
163 +static ssize_t gpio_write(struct file *file, const char __user *data,
164 + size_t len, loff_t *ppos)
171 + pin = iminor(file->f_dentry->d_inode);
173 + for (i = 0; i < len; i++) {
174 + if (get_user(c, data + i))
180 + retval = at91_set_gpio_value(PIN_BASE + pin, (int)c - 0x30);
195 +static int gpio_open(struct inode *inode, struct file *file)
197 + return nonseekable_open(inode, file);
200 +static int gpio_release(struct inode *inode, struct file *file)
205 +static struct file_operations vio_fops = {
206 + .owner = THIS_MODULE,
208 + .write = gpio_write,
210 + .release = gpio_release,
213 +static void vio_setup_cdev(struct vio_dev *dev, int index)
215 + int err, devno = MKDEV(major, index);
217 + cdev_init(&dev->cdev, &vio_fops);
218 + dev->cdev.owner = THIS_MODULE;
219 + dev->cdev.ops = &vio_fops;
220 + err = cdev_add (&dev->cdev, devno, 1);
222 + printk(KERN_NOTICE "vio: Error %d adding vio%d", err, index);
225 +static int vio_remove(struct platform_device *dev)
228 + dev_t devno = MKDEV(major, 0);
231 + for(i=0; i<VIO_NR_DEVS; i++) {
232 + int iodev = at91_is_pin_gpio(PIN_BASE + i);
234 + cdev_del(&vio_devices[i].cdev);
235 + class_device_destroy(vio_class, MKDEV(major, i));
238 + kfree(vio_devices);
241 + class_destroy(vio_class);
242 + unregister_chrdev_region(devno, VIO_NR_DEVS);
244 + platform_set_drvdata(dev, NULL);
249 +static int vio_probe(struct platform_device *dev)
255 + vdev = MKDEV(major, 0);
256 + retval = register_chrdev_region(vdev, VIO_NR_DEVS, "vio");
258 + retval = alloc_chrdev_region(&vdev, 0, VIO_NR_DEVS, "vio");
259 + major = MAJOR(vdev);
262 + printk(KERN_WARNING "vio: can't get major %d\n", major);
268 + printk(KERN_INFO "vio: major number %d\n", major);
271 + vio_class = class_create(THIS_MODULE, "vio");
273 + if (IS_ERR(vio_class)) {
274 + printk(KERN_ERR "vio: Error creating vio class\n");
276 + return PTR_ERR(vio_class);
279 + vio_devices = kmalloc(VIO_NR_DEVS * sizeof(struct vio_dev), GFP_KERNEL);
280 + if (!vio_devices) {
284 + memset(vio_devices, 0, VIO_NR_DEVS * sizeof(struct vio_dev));
286 + for (i=0; i<VIO_NR_DEVS/32; i++)
287 + for(j=0; j<32; j++) {
288 + int iodev = at91_is_pin_gpio(PIN_BASE + i*32 + j);
290 + vio_setup_cdev(&vio_devices[i*32 + j], i*32 + j);
291 + class_device_create(vio_class, NULL, MKDEV(major, i*32 + j), NULL,
292 + "vio%c%d", i + 'A', j);
296 + platform_set_drvdata(dev, vio_devices);
305 +static struct platform_device *vio_platform_device;
307 +static struct platform_driver vio_driver = {
308 + .probe = vio_probe,
309 + .remove = vio_remove,
312 + .owner = THIS_MODULE,
316 +static int __init vio_init(void)
320 + vio_platform_device = platform_device_register_simple("vio", -1, NULL, 0);
321 + if (IS_ERR(vio_platform_device)) {
322 + printk(KERN_WARNING "vio: device registration failed\n");
323 + return PTR_ERR(vio_platform_device);
326 + retval = platform_driver_register(&vio_driver);
328 + printk(KERN_WARNING "vio: driver registration failed\n");
329 + platform_device_unregister(vio_platform_device);
335 +static void __exit vio_exit(void)
337 + platform_driver_unregister(&vio_driver);
338 + platform_device_unregister(vio_platform_device);
341 +module_init(vio_init);
342 +module_exit(vio_exit);
344 +MODULE_AUTHOR("Hamish Guthrie <hamish@prodigi.ch>");
345 +MODULE_DESCRIPTION("FDL Versalink GPIO Driver");
346 +MODULE_LICENSE("GPL");
347 diff -urN linux-2.6.19.2.old/include/asm-arm/arch-at91rm9200/gpio.h linux-2.6.19.2/include/asm-arm/arch-at91rm9200/gpio.h
348 --- linux-2.6.19.2.old/include/asm-arm/arch-at91rm9200/gpio.h 2007-01-10 20:10:37.000000000 +0100
349 +++ linux-2.6.19.2/include/asm-arm/arch-at91rm9200/gpio.h 2007-03-07 01:17:23.000000000 +0100
351 /* callable at any time */
352 extern int at91_set_gpio_value(unsigned pin, int value);
353 extern int at91_get_gpio_value(unsigned pin);
354 +extern int at91_is_pin_gpio(unsigned pin);
356 /* callable only from core power-management code */
357 extern void at91_gpio_suspend(void);