aba62841f5f784edb5335b63f109cd692c4aa7ce
[openwrt.git] / target / linux / ixp4xx / patches-2.6.25 / 301-avila_led.patch
1 diff -ruN clean/linux-2.6.25.4/arch/arm/mach-ixp4xx/avila-setup.c linux-2.6.25.4/arch/arm/mach-ixp4xx/avila-setup.c
2 --- clean/linux-2.6.25.4/arch/arm/mach-ixp4xx/avila-setup.c 2008-05-20 09:18:21.000000000 -0700
3 +++ linux-2.6.25.4/arch/arm/mach-ixp4xx/avila-setup.c 2008-05-20 09:31:55.000000000 -0700
4 @@ -26,6 +26,7 @@
5 # include <linux/eeprom.h>
6 #endif
7
8 +#include <linux/leds.h>
9 #include <linux/i2c-gpio.h>
10
11 #include <asm/types.h>
12 @@ -172,6 +173,72 @@
13 .dev.platform_data = &avila_npec_data,
14 };
15
16 +static struct gpio_led avila_gpio_leds[] = {
17 + {
18 + .name = "user", /* green led */
19 + .gpio = AVILA_GW23XX_LED_USER_GPIO,
20 + .active_low = 1,
21 + }
22 +};
23 +
24 +static struct gpio_led_platform_data avila_gpio_leds_data = {
25 + .num_leds = 1,
26 + .leds = avila_gpio_leds,
27 +};
28 +
29 +static struct platform_device avila_gpio_leds_device = {
30 + .name = "leds-gpio",
31 + .id = -1,
32 + .dev.platform_data = &avila_gpio_leds_data,
33 +};
34 +
35 +static struct latch_led avila_latch_leds[] = {
36 + {
37 + .name = "led0", /* green led */
38 + .bit = 0,
39 + },
40 + {
41 + .name = "led1", /* green led */
42 + .bit = 1,
43 + },
44 + {
45 + .name = "led2", /* green led */
46 + .bit = 2,
47 + },
48 + {
49 + .name = "led3", /* green led */
50 + .bit = 3,
51 + },
52 + {
53 + .name = "led4", /* green led */
54 + .bit = 4,
55 + },
56 + {
57 + .name = "led5", /* green led */
58 + .bit = 5,
59 + },
60 + {
61 + .name = "led6", /* green led */
62 + .bit = 6,
63 + },
64 + {
65 + .name = "led7", /* green led */
66 + .bit = 7,
67 + }
68 +};
69 +
70 +static struct latch_led_platform_data avila_latch_leds_data = {
71 + .num_leds = 8,
72 + .leds = avila_latch_leds,
73 + .mem = 0x51000000,
74 +};
75 +
76 +static struct platform_device avila_latch_leds_device = {
77 + .name = "leds-latch",
78 + .id = -1,
79 + .dev.platform_data = &avila_latch_leds_data,
80 +};
81 +
82 static struct platform_device *avila_devices[] __initdata = {
83 &avila_i2c_gpio,
84 &avila_flash,
85 @@ -182,6 +249,8 @@
86 {
87 platform_device_register(&avila_npeb_device);
88 platform_device_register(&avila_npec_device);
89 +
90 + platform_device_register(&avila_gpio_leds_device);
91 }
92
93 #ifdef CONFIG_SENSORS_EEPROM
94 @@ -189,6 +258,8 @@
95 {
96 platform_device_register(&avila_npeb_device);
97 platform_device_register(&avila_npec_device);
98 +
99 + platform_device_register(&avila_gpio_leds_device);
100 }
101
102 static void __init avila_gw2345_setup(void)
103 @@ -199,22 +270,30 @@
104
105 avila_npec_data.phy = 5; /* port 5 of the KS8995 switch */
106 platform_device_register(&avila_npec_device);
107 +
108 + platform_device_register(&avila_gpio_leds_device);
109 }
110
111 static void __init avila_gw2347_setup(void)
112 {
113 platform_device_register(&avila_npeb_device);
114 +
115 + avila_gpio_leds[0].gpio = AVILA_GW23X7_LED_USER_GPIO;
116 + platform_device_register(&avila_gpio_leds_device);
117 }
118
119 static void __init avila_gw2348_setup(void)
120 {
121 platform_device_register(&avila_npeb_device);
122 platform_device_register(&avila_npec_device);
123 +
124 + platform_device_register(&avila_gpio_leds_device);
125 }
126
127 static void __init avila_gw2353_setup(void)
128 {
129 platform_device_register(&avila_npeb_device);
130 + platform_device_register(&avila_gpio_leds_device);
131 }
132
133 static void __init avila_gw2355_setup(void)
134 @@ -225,11 +304,29 @@
135
136 avila_npec_data.phy = 16;
137 platform_device_register(&avila_npec_device);
138 +
139 + platform_device_register(&avila_gpio_leds_device);
140 +
141 + *IXP4XX_EXP_CS4 |= 0xbfff3c03;
142 + avila_latch_leds[0].name = "RXD";
143 + avila_latch_leds[1].name = "TXD";
144 + avila_latch_leds[2].name = "POL";
145 + avila_latch_leds[3].name = "LNK";
146 + avila_latch_leds[4].name = "ERR";
147 + avila_latch_leds_data.num_leds = 5;
148 + avila_latch_leds_data.mem = 0x54000000;
149 + platform_device_register(&avila_latch_leds_device);
150 }
151
152 static void __init avila_gw2357_setup(void)
153 {
154 platform_device_register(&avila_npeb_device);
155 +
156 + avila_gpio_leds[0].gpio = AVILA_GW23X7_LED_USER_GPIO;
157 + platform_device_register(&avila_gpio_leds_device);
158 +
159 + *IXP4XX_EXP_CS1 |= 0xbfff3c03;
160 + platform_device_register(&avila_latch_leds_device);
161 }
162
163 static struct avila_board_info avila_boards[] __initdata = {
164 diff -ruN clean/linux-2.6.25.4/drivers/leds/Kconfig linux-2.6.25.4/drivers/leds/Kconfig
165 --- clean/linux-2.6.25.4/drivers/leds/Kconfig 2008-05-15 08:00:12.000000000 -0700
166 +++ linux-2.6.25.4/drivers/leds/Kconfig 2008-05-20 09:25:15.000000000 -0700
167 @@ -113,6 +113,12 @@
168 outputs. To be useful the particular board must have LEDs
169 and they must be connected to the GPIO lines.
170
171 +config LEDS_LATCH
172 + tristate "LED Support for Memory Latched LEDs"
173 + depends on LEDS_CLASS
174 + help
175 + -- To Do --
176 +
177 config LEDS_CM_X270
178 tristate "LED Support for the CM-X270 LEDs"
179 depends on LEDS_CLASS && MACH_ARMCORE
180 diff -ruN clean/linux-2.6.25.4/drivers/leds/leds-latch.c linux-2.6.25.4/drivers/leds/leds-latch.c
181 --- clean/linux-2.6.25.4/drivers/leds/leds-latch.c 1969-12-31 16:00:00.000000000 -0800
182 +++ linux-2.6.25.4/drivers/leds/leds-latch.c 2008-04-30 14:03:21.000000000 -0700
183 @@ -0,0 +1,141 @@
184 +/*
185 + * LEDs driver for Memory Latched Devices
186 + *
187 + * Copyright (C) 2008 Gateworks Corp.
188 + * Chris Lang <clang@gateworks.com>
189 + *
190 + * This program is free software; you can redistribute it and/or modify
191 + * it under the terms of the GNU General Public License version 2 as
192 + * published by the Free Software Foundation.
193 + *
194 + */
195 +#include <linux/kernel.h>
196 +#include <linux/init.h>
197 +#include <linux/platform_device.h>
198 +#include <linux/leds.h>
199 +#include <linux/workqueue.h>
200 +#include <asm/io.h>
201 +#include <linux/spinlock.h>
202 +
203 +static unsigned int mem_keep = 0xFF;
204 +static spinlock_t mem_lock;
205 +static unsigned char *iobase;
206 +
207 +struct latch_led_data {
208 + struct led_classdev cdev;
209 + struct work_struct work;
210 + u8 new_level;
211 + u8 bit;
212 +};
213 +
214 +static void latch_led_set(struct led_classdev *led_cdev,
215 + enum led_brightness value)
216 +{
217 + struct latch_led_data *led_dat =
218 + container_of(led_cdev, struct latch_led_data, cdev);
219 +
220 + spin_lock(mem_lock);
221 +
222 + if (value == LED_OFF)
223 + mem_keep |= (0x1 << led_dat->bit);
224 + else
225 + mem_keep &= ~(0x1 << led_dat->bit);
226 +
227 + writeb(mem_keep, iobase);
228 +
229 + spin_unlock(mem_lock);
230 +}
231 +
232 +static int latch_led_probe(struct platform_device *pdev)
233 +{
234 + struct latch_led_platform_data *pdata = pdev->dev.platform_data;
235 + struct latch_led *cur_led;
236 + struct latch_led_data *leds_data, *led_dat;
237 + int i, ret = 0;
238 +
239 + if (!pdata)
240 + return -EBUSY;
241 +
242 + leds_data = kzalloc(sizeof(struct latch_led_data) * pdata->num_leds,
243 + GFP_KERNEL);
244 + if (!leds_data)
245 + return -ENOMEM;
246 +
247 + iobase = ioremap_nocache(pdata->mem, 0x1000);
248 + writeb(0xFF, iobase);
249 +
250 + for (i = 0; i < pdata->num_leds; i++) {
251 + cur_led = &pdata->leds[i];
252 + led_dat = &leds_data[i];
253 +
254 + led_dat->cdev.name = cur_led->name;
255 + led_dat->cdev.default_trigger = cur_led->default_trigger;
256 + led_dat->cdev.brightness_set = latch_led_set;
257 + led_dat->cdev.brightness = LED_OFF;
258 + led_dat->bit = cur_led->bit;
259 +
260 + ret = led_classdev_register(&pdev->dev, &led_dat->cdev);
261 + if (ret < 0) {
262 + goto err;
263 + }
264 + }
265 +
266 + platform_set_drvdata(pdev, leds_data);
267 +
268 + return 0;
269 +
270 +err:
271 + if (i > 0) {
272 + for (i = i - 1; i >= 0; i--) {
273 + led_classdev_unregister(&leds_data[i].cdev);
274 + }
275 + }
276 +
277 + kfree(leds_data);
278 +
279 + return ret;
280 +}
281 +
282 +static int __devexit latch_led_remove(struct platform_device *pdev)
283 +{
284 + int i;
285 + struct latch_led_platform_data *pdata = pdev->dev.platform_data;
286 + struct latch_led_data *leds_data;
287 +
288 + leds_data = platform_get_drvdata(pdev);
289 +
290 + for (i = 0; i < pdata->num_leds; i++) {
291 + led_classdev_unregister(&leds_data[i].cdev);
292 + cancel_work_sync(&leds_data[i].work);
293 + }
294 +
295 + kfree(leds_data);
296 +
297 + return 0;
298 +}
299 +
300 +static struct platform_driver latch_led_driver = {
301 + .probe = latch_led_probe,
302 + .remove = __devexit_p(latch_led_remove),
303 + .driver = {
304 + .name = "leds-latch",
305 + .owner = THIS_MODULE,
306 + },
307 +};
308 +
309 +static int __init latch_led_init(void)
310 +{
311 + return platform_driver_register(&latch_led_driver);
312 +}
313 +
314 +static void __exit latch_led_exit(void)
315 +{
316 + platform_driver_unregister(&latch_led_driver);
317 +}
318 +
319 +module_init(latch_led_init);
320 +module_exit(latch_led_exit);
321 +
322 +MODULE_AUTHOR("Chris Lang <clang@gateworks.com>");
323 +MODULE_DESCRIPTION("Latch LED driver");
324 +MODULE_LICENSE("GPL");
325 diff -ruN clean/linux-2.6.25.4/drivers/leds/Makefile linux-2.6.25.4/drivers/leds/Makefile
326 --- clean/linux-2.6.25.4/drivers/leds/Makefile 2008-05-15 08:00:12.000000000 -0700
327 +++ linux-2.6.25.4/drivers/leds/Makefile 2008-05-20 09:26:14.000000000 -0700
328 @@ -18,6 +18,7 @@
329 obj-$(CONFIG_LEDS_COBALT_QUBE) += leds-cobalt-qube.o
330 obj-$(CONFIG_LEDS_COBALT_RAQ) += leds-cobalt-raq.o
331 obj-$(CONFIG_LEDS_GPIO) += leds-gpio.o
332 +obj-$(CONFIG_LEDS_LATCH) += leds-latch.o
333 obj-$(CONFIG_LEDS_CM_X270) += leds-cm-x270.o
334 obj-$(CONFIG_LEDS_CLEVO_MAIL) += leds-clevo-mail.o
335 obj-$(CONFIG_LEDS_HP6XX) += leds-hp6xx.o
336 diff -ruN clean/linux-2.6.25.4/include/asm-arm/arch-ixp4xx/avila.h linux-2.6.25.4/include/asm-arm/arch-ixp4xx/avila.h
337 --- clean/linux-2.6.25.4/include/asm-arm/arch-ixp4xx/avila.h 2008-05-15 08:00:12.000000000 -0700
338 +++ linux-2.6.25.4/include/asm-arm/arch-ixp4xx/avila.h 2008-05-20 09:22:28.000000000 -0700
339 @@ -36,4 +36,6 @@
340 #define AVILA_PCI_INTC_PIN 9
341 #define AVILA_PCI_INTD_PIN 8
342
343 -
344 +/* User LEDs */
345 +#define AVILA_GW23XX_LED_USER_GPIO 3
346 +#define AVILA_GW23X7_LED_USER_GPIO 4
347 diff -ruN clean/linux-2.6.25.4/include/linux/leds.h linux-2.6.25.4/include/linux/leds.h
348 --- clean/linux-2.6.25.4/include/linux/leds.h 2008-05-15 08:00:12.000000000 -0700
349 +++ linux-2.6.25.4/include/linux/leds.h 2008-05-20 09:32:35.000000000 -0700
350 @@ -136,5 +136,18 @@
351 struct gpio_led *leds;
352 };
353
354 +/* For the leds-latch driver */
355 +struct latch_led {
356 + const char *name;
357 + char *default_trigger;
358 + unsigned bit;
359 +};
360 +
361 +struct latch_led_platform_data {
362 + int num_leds;
363 + u32 mem;
364 + struct latch_led *leds;
365 +};
366 +
367
368 #endif /* __LINUX_LEDS_H_INCLUDED */
This page took 0.050497 seconds and 3 git commands to generate.