1 diff -urN linux-2.6.22.1.old/arch/arm/mach-at91/gpio.c linux-2.6.22.1/arch/arm/mach-at91/gpio.c
2 --- linux-2.6.22.1.old/arch/arm/mach-at91/gpio.c 2007-07-10 20:56:30.000000000 +0200
3 +++ linux-2.6.22.1/arch/arm/mach-at91/gpio.c 2007-07-29 07:03:30.000000000 +0200
6 static struct at91_gpio_bank *gpio;
8 +static u32 pio_gpio_pin[4] = { 0, 0, 0, 0 };
11 static inline void __iomem *pin_to_controller(unsigned pin)
14 void __iomem *pio = pin_to_controller(pin);
15 unsigned mask = pin_to_mask(pin);
16 + int bank = (pin - PIN_BASE) / 32;
21 + pio_gpio_pin[bank] |= mask;
23 __raw_writel(mask, pio + PIO_IDR);
24 __raw_writel(mask, pio + (use_pullup ? PIO_PUER : PIO_PUDR));
25 __raw_writel(mask, pio + PIO_PER);
28 void __iomem *pio = pin_to_controller(pin);
29 unsigned mask = pin_to_mask(pin);
30 + int bank = (pin - PIN_BASE) / 32;
35 + pio_gpio_pin[bank] |= mask;
37 __raw_writel(mask, pio + PIO_IDR);
38 __raw_writel(mask, pio + (use_pullup ? PIO_PUER : PIO_PUDR));
39 __raw_writel(mask, pio + PIO_ODR);
42 void __iomem *pio = pin_to_controller(pin);
43 unsigned mask = pin_to_mask(pin);
44 + int bank = (pin - PIN_BASE) / 32;
49 + pio_gpio_pin[bank] |= mask;
51 __raw_writel(mask, pio + PIO_IDR);
52 __raw_writel(mask, pio + PIO_PUDR);
53 __raw_writel(mask, pio + (value ? PIO_SODR : PIO_CODR));
56 EXPORT_SYMBOL(at91_get_gpio_value);
58 +int at91_is_pin_gpio(unsigned pin)
60 + void __iomem *pio = pin_to_controller(pin);
61 + unsigned mask = pin_to_mask(pin);
62 + int bank = (pin - PIN_BASE) / 32;
66 + return (pio_gpio_pin[bank] & mask) != 0;
68 +EXPORT_SYMBOL(at91_is_pin_gpio);
70 /*--------------------------------------------------------------------------*/
73 diff -urN linux-2.6.22.1.old/drivers/char/Kconfig linux-2.6.22.1/drivers/char/Kconfig
74 --- linux-2.6.22.1.old/drivers/char/Kconfig 2007-07-29 06:46:13.000000000 +0200
75 +++ linux-2.6.22.1/drivers/char/Kconfig 2007-07-29 07:05:30.000000000 +0200
76 @@ -1099,5 +1099,12 @@
77 The SPI driver gives user mode access to this serial
78 bus on the AT91RM9200 processor.
81 + tristate "Versalink LED and GPIO interface"
82 + depends on ARCH_AT91RM9200 && MACH_VLINK
85 + Provides a handler GPIO's in userspace
89 diff -urN linux-2.6.22.1.old/drivers/char/Makefile linux-2.6.22.1/drivers/char/Makefile
90 --- linux-2.6.22.1.old/drivers/char/Makefile 2007-07-29 06:46:13.000000000 +0200
91 +++ linux-2.6.22.1/drivers/char/Makefile 2007-07-29 07:06:06.000000000 +0200
93 obj-$(CONFIG_TELCLOCK) += tlclk.o
94 obj-$(CONFIG_AT91_SPI) += at91_spi.o
95 obj-$(CONFIG_AT91_SPIDEV) += at91_spidev.o
96 +obj-$(CONFIG_AT91_VLIO) += vlink_giu.o
98 obj-$(CONFIG_WATCHDOG) += watchdog/
99 obj-$(CONFIG_MWAVE) += mwave/
100 diff -urN linux-2.6.22.1.old/drivers/char/vlink_giu.c linux-2.6.22.1/drivers/char/vlink_giu.c
101 --- linux-2.6.22.1.old/drivers/char/vlink_giu.c 1970-01-01 01:00:00.000000000 +0100
102 +++ linux-2.6.22.1/drivers/char/vlink_giu.c 2007-07-29 07:06:33.000000000 +0200
105 + * Driver for FDL Versalink GPIO
107 + * Copyright (C) 2005 Guthrie Consulting
108 + * Author: Hamish Guthrie <hamish@prodigi.ch>
110 + * This program is free software; you can redistribute it and/or modify
111 + * it under the terms of the GNU General Public License as published by
112 + * the Free Software Foundation; either version 2 of the License, or
113 + * (at your option) any later version.
115 + * This program is distributed in the hope that it will be useful,
116 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
117 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
118 + * GNU General Public License for more details.
120 + * You should have received a copy of the GNU General Public License
121 + * along with this program; if not, write to the Free Software
122 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
125 +#include <linux/module.h>
126 +#include <linux/moduleparam.h>
127 +#include <linux/init.h>
128 +#include <linux/platform_device.h>
130 +#include <linux/kernel.h>
131 +#include <linux/slab.h>
132 +#include <linux/fs.h>
133 +#include <linux/errno.h>
134 +#include <linux/init.h>
135 +#include <linux/types.h>
136 +#include <linux/proc_fs.h>
137 +#include <linux/fcntl.h>
138 +#include <linux/seq_file.h>
139 +#include <linux/cdev.h>
140 +#include <asm/arch/gpio.h>
141 +#include <asm/uaccess.h>
143 +static int major; /* default is dynamic major device number */
144 +module_param(major, int, 0);
145 +MODULE_PARM_DESC(major, "Major device number");
147 +#define VIO_NR_DEVS 96
153 +struct vio_dev *vio_devices;
154 +static struct class *vio_class;
156 +static ssize_t gpio_read(struct file *file, char __user *buf, size_t len,
163 + pin = iminor(file->f_dentry->d_inode);
165 + retval = at91_get_gpio_value(PIN_BASE + pin);
169 + value = retval + 0x30;
170 + if (put_user(value, buf))
176 +static ssize_t gpio_write(struct file *file, const char __user *data,
177 + size_t len, loff_t *ppos)
184 + pin = iminor(file->f_dentry->d_inode);
186 + for (i = 0; i < len; i++) {
187 + if (get_user(c, data + i))
193 + retval = at91_set_gpio_value(PIN_BASE + pin, (int)c - 0x30);
208 +static int gpio_open(struct inode *inode, struct file *file)
210 + return nonseekable_open(inode, file);
213 +static int gpio_release(struct inode *inode, struct file *file)
218 +static struct file_operations vio_fops = {
219 + .owner = THIS_MODULE,
221 + .write = gpio_write,
223 + .release = gpio_release,
226 +static void vio_setup_cdev(struct vio_dev *dev, int index)
228 + int err, devno = MKDEV(major, index);
230 + cdev_init(&dev->cdev, &vio_fops);
231 + dev->cdev.owner = THIS_MODULE;
232 + dev->cdev.ops = &vio_fops;
233 + err = cdev_add (&dev->cdev, devno, 1);
235 + printk(KERN_NOTICE "vio: Error %d adding vio%d", err, index);
238 +static int vio_remove(struct platform_device *dev)
241 + dev_t devno = MKDEV(major, 0);
244 + for(i=0; i<VIO_NR_DEVS; i++) {
245 + int iodev = at91_is_pin_gpio(PIN_BASE + i);
247 + cdev_del(&vio_devices[i].cdev);
248 + class_device_destroy(vio_class, MKDEV(major, i));
251 + kfree(vio_devices);
254 + class_destroy(vio_class);
255 + unregister_chrdev_region(devno, VIO_NR_DEVS);
257 + platform_set_drvdata(dev, NULL);
262 +static int vio_probe(struct platform_device *dev)
268 + vdev = MKDEV(major, 0);
269 + retval = register_chrdev_region(vdev, VIO_NR_DEVS, "vio");
271 + retval = alloc_chrdev_region(&vdev, 0, VIO_NR_DEVS, "vio");
272 + major = MAJOR(vdev);
275 + printk(KERN_WARNING "vio: can't get major %d\n", major);
281 + printk(KERN_INFO "vio: major number %d\n", major);
284 + vio_class = class_create(THIS_MODULE, "vio");
286 + if (IS_ERR(vio_class)) {
287 + printk(KERN_ERR "vio: Error creating vio class\n");
289 + return PTR_ERR(vio_class);
292 + vio_devices = kmalloc(VIO_NR_DEVS * sizeof(struct vio_dev), GFP_KERNEL);
293 + if (!vio_devices) {
297 + memset(vio_devices, 0, VIO_NR_DEVS * sizeof(struct vio_dev));
299 + for (i=0; i<VIO_NR_DEVS/32; i++)
300 + for(j=0; j<32; j++) {
301 + int iodev = at91_is_pin_gpio(PIN_BASE + i*32 + j);
303 + vio_setup_cdev(&vio_devices[i*32 + j], i*32 + j);
304 + class_device_create(vio_class, NULL, MKDEV(major, i*32 + j), NULL,
305 + "vio%c%d", i + 'A', j);
309 + platform_set_drvdata(dev, vio_devices);
318 +static struct platform_device *vio_platform_device;
320 +static struct platform_driver vio_driver = {
321 + .probe = vio_probe,
322 + .remove = vio_remove,
325 + .owner = THIS_MODULE,
329 +static int __init vio_init(void)
333 + vio_platform_device = platform_device_register_simple("vio", -1, NULL, 0);
334 + if (IS_ERR(vio_platform_device)) {
335 + printk(KERN_WARNING "vio: device registration failed\n");
336 + return PTR_ERR(vio_platform_device);
339 + retval = platform_driver_register(&vio_driver);
341 + printk(KERN_WARNING "vio: driver registration failed\n");
342 + platform_device_unregister(vio_platform_device);
348 +static void __exit vio_exit(void)
350 + platform_driver_unregister(&vio_driver);
351 + platform_device_unregister(vio_platform_device);
354 +module_init(vio_init);
355 +module_exit(vio_exit);
357 +MODULE_AUTHOR("Hamish Guthrie <hamish@prodigi.ch>");
358 +MODULE_DESCRIPTION("FDL Versalink GPIO Driver");
359 +MODULE_LICENSE("GPL");