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