1 Index: linux-2.6.21.7/arch/arm/mach-at91/gpio.c
2 ===================================================================
3 --- linux-2.6.21.7.orig/arch/arm/mach-at91/gpio.c
4 +++ linux-2.6.21.7/arch/arm/mach-at91/gpio.c
7 static struct at91_gpio_bank *gpio;
9 +static u32 pio_gpio_pin[4] = { 0, 0, 0, 0 };
12 static inline void __iomem *pin_to_controller(unsigned pin)
13 @@ -71,9 +72,13 @@ int __init_or_module at91_set_GPIO_perip
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_PER);
27 @@ -130,10 +135,13 @@ int __init_or_module at91_set_gpio_input
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 + (use_pullup ? PIO_PUER : PIO_PUDR));
40 __raw_writel(mask, pio + PIO_ODR);
41 @@ -151,10 +159,13 @@ int __init_or_module at91_set_gpio_outpu
43 void __iomem *pio = pin_to_controller(pin);
44 unsigned mask = pin_to_mask(pin);
45 + int bank = (pin - PIN_BASE) / 32;
50 + pio_gpio_pin[bank] |= mask;
52 __raw_writel(mask, pio + PIO_IDR);
53 __raw_writel(mask, pio + PIO_PUDR);
54 __raw_writel(mask, pio + (value ? PIO_SODR : PIO_CODR));
55 @@ -262,6 +273,18 @@ int at91_get_gpio_value(unsigned pin)
57 EXPORT_SYMBOL(at91_get_gpio_value);
59 +int at91_is_pin_gpio(unsigned pin)
61 + void __iomem *pio = pin_to_controller(pin);
62 + unsigned mask = pin_to_mask(pin);
63 + int bank = (pin - PIN_BASE) / 32;
67 + return (pio_gpio_pin[bank] & mask) != 0;
69 +EXPORT_SYMBOL(at91_is_pin_gpio);
71 /*--------------------------------------------------------------------------*/
74 Index: linux-2.6.21.7/drivers/char/Kconfig
75 ===================================================================
76 --- linux-2.6.21.7.orig/drivers/char/Kconfig
77 +++ linux-2.6.21.7/drivers/char/Kconfig
78 @@ -1087,5 +1087,12 @@ config AT91_SPIDEV
79 The SPI driver gives user mode access to this serial
80 bus on the AT91RM9200 processor.
83 + tristate "Versalink LED and GPIO interface"
84 + depends on ARCH_AT91RM9200 && MACH_VLINK
87 + Provides a handler GPIO's in userspace
91 Index: linux-2.6.21.7/drivers/char/Makefile
92 ===================================================================
93 --- linux-2.6.21.7.orig/drivers/char/Makefile
94 +++ linux-2.6.21.7/drivers/char/Makefile
95 @@ -95,6 +95,7 @@ obj-$(CONFIG_TANBAC_TB0219) += tb0219.o
96 obj-$(CONFIG_TELCLOCK) += tlclk.o
97 obj-$(CONFIG_AT91_SPI) += at91_spi.o
98 obj-$(CONFIG_AT91_SPIDEV) += at91_spidev.o
99 +obj-$(CONFIG_AT91_VLIO) += vlink_giu.o
101 obj-$(CONFIG_WATCHDOG) += watchdog/
102 obj-$(CONFIG_MWAVE) += mwave/
103 Index: linux-2.6.21.7/drivers/char/vlink_giu.c
104 ===================================================================
106 +++ linux-2.6.21.7/drivers/char/vlink_giu.c
109 + * Driver for FDL Versalink GPIO
111 + * Copyright (C) 2005 Guthrie Consulting
112 + * Author: Hamish Guthrie <hamish@prodigi.ch>
114 + * This program is free software; you can redistribute it and/or modify
115 + * it under the terms of the GNU General Public License as published by
116 + * the Free Software Foundation; either version 2 of the License, or
117 + * (at your option) any later version.
119 + * This program is distributed in the hope that it will be useful,
120 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
121 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
122 + * GNU General Public License for more details.
124 + * You should have received a copy of the GNU General Public License
125 + * along with this program; if not, write to the Free Software
126 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
129 +#include <linux/module.h>
130 +#include <linux/moduleparam.h>
131 +#include <linux/init.h>
132 +#include <linux/platform_device.h>
134 +#include <linux/kernel.h>
135 +#include <linux/slab.h>
136 +#include <linux/fs.h>
137 +#include <linux/errno.h>
138 +#include <linux/init.h>
139 +#include <linux/types.h>
140 +#include <linux/proc_fs.h>
141 +#include <linux/fcntl.h>
142 +#include <linux/seq_file.h>
143 +#include <linux/cdev.h>
144 +#include <asm/arch/gpio.h>
145 +#include <asm/uaccess.h>
147 +static int major; /* default is dynamic major device number */
148 +module_param(major, int, 0);
149 +MODULE_PARM_DESC(major, "Major device number");
151 +#define VIO_NR_DEVS 96
157 +struct vio_dev *vio_devices;
158 +static struct class *vio_class;
160 +static ssize_t gpio_read(struct file *file, char __user *buf, size_t len,
167 + pin = iminor(file->f_dentry->d_inode);
169 + retval = at91_get_gpio_value(PIN_BASE + pin);
173 + value = retval + 0x30;
174 + if (put_user(value, buf))
180 +static ssize_t gpio_write(struct file *file, const char __user *data,
181 + size_t len, loff_t *ppos)
188 + pin = iminor(file->f_dentry->d_inode);
190 + for (i = 0; i < len; i++) {
191 + if (get_user(c, data + i))
197 + retval = at91_set_gpio_value(PIN_BASE + pin, (int)c - 0x30);
212 +static int gpio_open(struct inode *inode, struct file *file)
214 + return nonseekable_open(inode, file);
217 +static int gpio_release(struct inode *inode, struct file *file)
222 +static struct file_operations vio_fops = {
223 + .owner = THIS_MODULE,
225 + .write = gpio_write,
227 + .release = gpio_release,
230 +static void vio_setup_cdev(struct vio_dev *dev, int index)
232 + int err, devno = MKDEV(major, index);
234 + cdev_init(&dev->cdev, &vio_fops);
235 + dev->cdev.owner = THIS_MODULE;
236 + dev->cdev.ops = &vio_fops;
237 + err = cdev_add (&dev->cdev, devno, 1);
239 + printk(KERN_NOTICE "vio: Error %d adding vio%d", err, index);
242 +static int vio_remove(struct platform_device *dev)
245 + dev_t devno = MKDEV(major, 0);
248 + for(i=0; i<VIO_NR_DEVS; i++) {
249 + int iodev = at91_is_pin_gpio(PIN_BASE + i);
251 + cdev_del(&vio_devices[i].cdev);
252 + class_device_destroy(vio_class, MKDEV(major, i));
255 + kfree(vio_devices);
258 + class_destroy(vio_class);
259 + unregister_chrdev_region(devno, VIO_NR_DEVS);
261 + platform_set_drvdata(dev, NULL);
266 +static int vio_probe(struct platform_device *dev)
272 + vdev = MKDEV(major, 0);
273 + retval = register_chrdev_region(vdev, VIO_NR_DEVS, "vio");
275 + retval = alloc_chrdev_region(&vdev, 0, VIO_NR_DEVS, "vio");
276 + major = MAJOR(vdev);
279 + printk(KERN_WARNING "vio: can't get major %d\n", major);
285 + printk(KERN_INFO "vio: major number %d\n", major);
288 + vio_class = class_create(THIS_MODULE, "vio");
290 + if (IS_ERR(vio_class)) {
291 + printk(KERN_ERR "vio: Error creating vio class\n");
293 + return PTR_ERR(vio_class);
296 + vio_devices = kmalloc(VIO_NR_DEVS * sizeof(struct vio_dev), GFP_KERNEL);
297 + if (!vio_devices) {
301 + memset(vio_devices, 0, VIO_NR_DEVS * sizeof(struct vio_dev));
303 + for (i=0; i<VIO_NR_DEVS/32; i++)
304 + for(j=0; j<32; j++) {
305 + int iodev = at91_is_pin_gpio(PIN_BASE + i*32 + j);
307 + vio_setup_cdev(&vio_devices[i*32 + j], i*32 + j);
308 + class_device_create(vio_class, NULL, MKDEV(major, i*32 + j), NULL,
309 + "vio%c%d", i + 'A', j);
313 + platform_set_drvdata(dev, vio_devices);
322 +static struct platform_device *vio_platform_device;
324 +static struct platform_driver vio_driver = {
325 + .probe = vio_probe,
326 + .remove = vio_remove,
329 + .owner = THIS_MODULE,
333 +static int __init vio_init(void)
337 + vio_platform_device = platform_device_register_simple("vio", -1, NULL, 0);
338 + if (IS_ERR(vio_platform_device)) {
339 + printk(KERN_WARNING "vio: device registration failed\n");
340 + return PTR_ERR(vio_platform_device);
343 + retval = platform_driver_register(&vio_driver);
345 + printk(KERN_WARNING "vio: driver registration failed\n");
346 + platform_device_unregister(vio_platform_device);
352 +static void __exit vio_exit(void)
354 + platform_driver_unregister(&vio_driver);
355 + platform_device_unregister(vio_platform_device);
358 +module_init(vio_init);
359 +module_exit(vio_exit);
361 +MODULE_AUTHOR("Hamish Guthrie <hamish@prodigi.ch>");
362 +MODULE_DESCRIPTION("FDL Versalink GPIO Driver");
363 +MODULE_LICENSE("GPL");