strip the kernel version suffix from target directories, except for brcm-2.4 (the...
[15.05/openwrt.git] / target / linux / at91 / patches-2.6.22 / 003-gpio-driver.patch
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
4 @@ -27,6 +27,7 @@
5  
6  static struct at91_gpio_bank *gpio;
7  static int gpio_banks;
8 +static u32 pio_gpio_pin[4] = { 0, 0, 0, 0 };
9  
10  
11  static inline void __iomem *pin_to_controller(unsigned pin)
12 @@ -71,9 +72,13 @@
13  {
14         void __iomem    *pio = pin_to_controller(pin);
15         unsigned        mask = pin_to_mask(pin);
16 +       int bank = (pin - PIN_BASE) / 32;
17  
18         if (!pio)
19                 return -EINVAL;
20 +
21 +       pio_gpio_pin[bank] |= mask;
22 +
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);
26 @@ -130,10 +135,13 @@
27  {
28         void __iomem    *pio = pin_to_controller(pin);
29         unsigned        mask = pin_to_mask(pin);
30 +       int bank = (pin - PIN_BASE) / 32;
31  
32         if (!pio)
33                 return -EINVAL;
34  
35 +       pio_gpio_pin[bank] |= mask;
36 +
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);
40 @@ -151,10 +159,13 @@
41  {
42         void __iomem    *pio = pin_to_controller(pin);
43         unsigned        mask = pin_to_mask(pin);
44 +       int bank = (pin - PIN_BASE) / 32;
45  
46         if (!pio)
47                 return -EINVAL;
48  
49 +       pio_gpio_pin[bank] |= mask;
50 +
51         __raw_writel(mask, pio + PIO_IDR);
52         __raw_writel(mask, pio + PIO_PUDR);
53         __raw_writel(mask, pio + (value ? PIO_SODR : PIO_CODR));
54 @@ -262,6 +273,18 @@
55  }
56  EXPORT_SYMBOL(at91_get_gpio_value);
57  
58 +int at91_is_pin_gpio(unsigned pin)
59 +{
60 +       void __iomem  *pio = pin_to_controller(pin);
61 +       unsigned  mask = pin_to_mask(pin);
62 +       int     bank = (pin - PIN_BASE) / 32;
63 +
64 +       if (!pio)
65 +               return -EINVAL;
66 +       return (pio_gpio_pin[bank] & mask) != 0;
67 +}
68 +EXPORT_SYMBOL(at91_is_pin_gpio);
69 +
70  /*--------------------------------------------------------------------------*/
71  
72  #ifdef CONFIG_PM
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.
79  
80 +config AT91_VLIO
81 +       tristate "Versalink LED and GPIO interface"
82 +       depends on ARCH_AT91RM9200 && MACH_VLINK
83 +       default n
84 +       help
85 +         Provides a handler GPIO's in userspace
86 +
87  endmenu
88  
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
92 @@ -95,6 +95,7 @@
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
97  
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
103 @@ -0,0 +1,256 @@
104 +/*
105 + *  Driver for FDL Versalink GPIO
106 + *
107 + *  Copyright (C) 2005 Guthrie Consulting
108 + *     Author: Hamish Guthrie <hamish@prodigi.ch>
109 + *
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.
114 + *
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.
119 + *
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
123 + */
124 +
125 +#include <linux/module.h>
126 +#include <linux/moduleparam.h>
127 +#include <linux/init.h>
128 +#include <linux/platform_device.h>
129 +
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>
142 +
143 +static int major;      /* default is dynamic major device number */
144 +module_param(major, int, 0);
145 +MODULE_PARM_DESC(major, "Major device number");
146 +
147 +#define VIO_NR_DEVS 96
148 +
149 +struct vio_dev {
150 +       struct cdev cdev;
151 +};
152 +
153 +struct vio_dev *vio_devices;
154 +static struct class *vio_class;
155 +
156 +static ssize_t gpio_read(struct file *file, char __user *buf, size_t len,
157 +                         loff_t *ppos)
158 +{
159 +       unsigned int pin;
160 +       int retval;
161 +       char value = '0';
162 +
163 +       pin = iminor(file->f_dentry->d_inode);
164 +
165 +       retval = at91_get_gpio_value(PIN_BASE + pin);
166 +       if (retval < 0)
167 +               return -EFAULT;
168 +
169 +       value = retval + 0x30;
170 +       if (put_user(value, buf))
171 +               return -EFAULT;
172 +
173 +       return 1;
174 +}
175 +
176 +static ssize_t gpio_write(struct file *file, const char __user *data,
177 +                          size_t len, loff_t *ppos)
178 +{
179 +       unsigned int pin;
180 +       size_t i;
181 +       char c;
182 +       int retval = 0;
183 +
184 +       pin = iminor(file->f_dentry->d_inode);
185 +
186 +       for (i = 0; i < len; i++) {
187 +               if (get_user(c, data + i))
188 +                       return -EFAULT;
189 +
190 +               switch (c) {
191 +               case '0':
192 +               case '1':
193 +                       retval = at91_set_gpio_value(PIN_BASE + pin, (int)c - 0x30);
194 +                       if (retval < 0)
195 +                               return -EFAULT;
196 +                       break;
197 +               default:
198 +                       break;
199 +               }
200 +
201 +               if (retval < 0)
202 +                       break;
203 +       }
204 +
205 +       return i;
206 +}
207 +
208 +static int gpio_open(struct inode *inode, struct file *file)
209 +{
210 +       return nonseekable_open(inode, file);
211 +}
212 +
213 +static int gpio_release(struct inode *inode, struct file *file)
214 +{
215 +       return 0;
216 +}
217 +
218 +static struct file_operations vio_fops = {
219 +       .owner          = THIS_MODULE,
220 +       .read           = gpio_read,
221 +       .write          = gpio_write,
222 +       .open           = gpio_open,
223 +       .release        = gpio_release,
224 +};
225 +
226 +static void vio_setup_cdev(struct vio_dev *dev, int index)
227 +{
228 +       int err, devno = MKDEV(major, index);
229 +
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);
234 +       if (err)
235 +               printk(KERN_NOTICE "vio: Error %d adding vio%d", err, index);
236 +}
237 +
238 +static int vio_remove(struct platform_device *dev)
239 +{
240 +       int i;
241 +       dev_t devno = MKDEV(major, 0);
242 +
243 +       if (vio_devices) {
244 +               for(i=0; i<VIO_NR_DEVS; i++) {
245 +                       int iodev = at91_is_pin_gpio(PIN_BASE + i);
246 +                       if (iodev) {
247 +                               cdev_del(&vio_devices[i].cdev);
248 +                               class_device_destroy(vio_class, MKDEV(major, i));
249 +                       }
250 +               }
251 +               kfree(vio_devices);
252 +       }
253 +
254 +       class_destroy(vio_class);
255 +       unregister_chrdev_region(devno, VIO_NR_DEVS);
256 +
257 +       platform_set_drvdata(dev, NULL);
258 +
259 +       return 0;
260 +}
261 +
262 +static int vio_probe(struct platform_device *dev)
263 +{
264 +       int retval, i, j;
265 +       dev_t vdev = 0;
266 +
267 +       if (major) {
268 +               vdev = MKDEV(major, 0);
269 +               retval = register_chrdev_region(vdev, VIO_NR_DEVS, "vio");
270 +       } else {
271 +               retval = alloc_chrdev_region(&vdev, 0, VIO_NR_DEVS, "vio");
272 +               major = MAJOR(vdev);
273 +       }
274 +       if (retval < 0) {
275 +               printk(KERN_WARNING "vio: can't get major %d\n", major);
276 +               return retval;
277 +       }
278 +
279 +       if (major == 0) {
280 +               major = retval;
281 +               printk(KERN_INFO "vio: major number %d\n", major);
282 +       }
283 +
284 +       vio_class = class_create(THIS_MODULE, "vio");
285 +
286 +       if (IS_ERR(vio_class)) {
287 +               printk(KERN_ERR "vio: Error creating vio class\n");
288 +               vio_remove(dev);
289 +               return PTR_ERR(vio_class);
290 +       }
291 +
292 +       vio_devices = kmalloc(VIO_NR_DEVS * sizeof(struct vio_dev), GFP_KERNEL);
293 +       if (!vio_devices) {
294 +               retval = -ENOMEM;
295 +               goto fail;
296 +       }
297 +       memset(vio_devices, 0, VIO_NR_DEVS * sizeof(struct vio_dev));
298 +
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);
302 +                       if (iodev) {
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);
306 +                       }
307 +               }
308 +
309 +       platform_set_drvdata(dev, vio_devices);
310 +
311 +       return 0;
312 +
313 +fail:
314 +       vio_remove(dev);
315 +       return retval;
316 +}
317 +
318 +static struct platform_device *vio_platform_device;
319 +
320 +static struct platform_driver vio_driver = {
321 +       .probe          = vio_probe,
322 +       .remove         = vio_remove,
323 +       .driver         = {
324 +               .name   = "vio",
325 +               .owner  = THIS_MODULE,
326 +       },
327 +};
328 +
329 +static int __init vio_init(void)
330 +{
331 +       int retval;
332 +
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);
337 +       }
338 +
339 +       retval = platform_driver_register(&vio_driver);
340 +       if (retval < 0) {
341 +               printk(KERN_WARNING "vio: driver registration failed\n");
342 +               platform_device_unregister(vio_platform_device);
343 +       }
344 +       
345 +       return retval;
346 +}
347 +
348 +static void __exit vio_exit(void)
349 +{
350 +       platform_driver_unregister(&vio_driver);
351 +       platform_device_unregister(vio_platform_device);
352 +}
353 +
354 +module_init(vio_init);
355 +module_exit(vio_exit);
356 +
357 +MODULE_AUTHOR("Hamish Guthrie <hamish@prodigi.ch>");
358 +MODULE_DESCRIPTION("FDL Versalink GPIO Driver");
359 +MODULE_LICENSE("GPL");