add ixp4xx 2.6.25 patchset
[openwrt.git] / target / linux / ixp4xx / patches-2.6.25 / 031-ixp4xx_fsg_led_driver.patch
1 From a66e34fefb3f8142d7f16808563eb610225f6e77 Mon Sep 17 00:00:00 2001
2 From: Rod Whitby <rod@whitby.id.au>
3 Date: Tue, 29 Jan 2008 23:17:42 +1030
4 Subject: [PATCH] leds: Add new driver for the LEDs on the Freecom FSG-3
5
6 The LEDs on the Freecom FSG-3 are connected to an external
7 memory-mapped latch on the ixp4xx expansion bus, and therefore cannot
8 be supported by any of the existing LEDs drivers.
9
10 Signed-off-by: Rod Whitby <rod@whitby.id.au>
11 --
12 PATCH FOLLOWS
13 KernelVersion: v2.6.25-rc6-117-g457fb60
14 ---
15 drivers/leds/Kconfig | 6 +
16 drivers/leds/Makefile | 1 +
17 drivers/leds/leds-fsg.c | 261 +++++++++++++++++++++++++++++++++++++++++++++++
18 3 files changed, 268 insertions(+), 0 deletions(-)
19 create mode 100644 drivers/leds/leds-fsg.c
20
21 diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
22 index 859814f..aefbe04 100644
23 --- a/drivers/leds/Kconfig
24 +++ b/drivers/leds/Kconfig
25 @@ -46,6 +46,12 @@ config LEDS_SPITZ
26 This option enables support for the LEDs on Sharp Zaurus
27 SL-Cxx00 series (C1000, C3000, C3100).
28
29 +config LEDS_FSG
30 + tristate "LED Support for the Freecom FSG-3"
31 + depends on LEDS_CLASS && MACH_FSG
32 + help
33 + This option enables support for the LEDs on the Freecom FSG-3.
34 +
35 config LEDS_TOSA
36 tristate "LED Support for the Sharp SL-6000 series"
37 depends on LEDS_CLASS && PXA_SHARPSL
38 diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
39 index 84ced3b..b17bd91 100644
40 --- a/drivers/leds/Makefile
41 +++ b/drivers/leds/Makefile
42 @@ -21,6 +21,7 @@ obj-$(CONFIG_LEDS_GPIO) += leds-gpio.o
43 obj-$(CONFIG_LEDS_CM_X270) += leds-cm-x270.o
44 obj-$(CONFIG_LEDS_CLEVO_MAIL) += leds-clevo-mail.o
45 obj-$(CONFIG_LEDS_HP6XX) += leds-hp6xx.o
46 +obj-$(CONFIG_LEDS_FSG) += leds-fsg.o
47
48 # LED Triggers
49 obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o
50 diff --git a/drivers/leds/leds-fsg.c b/drivers/leds/leds-fsg.c
51 new file mode 100644
52 index 0000000..a7421b8
53 --- /dev/null
54 +++ b/drivers/leds/leds-fsg.c
55 @@ -0,0 +1,261 @@
56 +/*
57 + * LED Driver for the Freecom FSG-3
58 + *
59 + * Copyright (c) 2008 Rod Whitby <rod@whitby.id.au>
60 + *
61 + * Author: Rod Whitby <rod@whitby.id.au>
62 + *
63 + * Based on leds-spitz.c
64 + * Copyright 2005-2006 Openedhand Ltd.
65 + * Author: Richard Purdie <rpurdie@openedhand.com>
66 + *
67 + * This program is free software; you can redistribute it and/or modify
68 + * it under the terms of the GNU General Public License version 2 as
69 + * published by the Free Software Foundation.
70 + *
71 + */
72 +
73 +#include <linux/kernel.h>
74 +#include <linux/init.h>
75 +#include <linux/platform_device.h>
76 +#include <linux/leds.h>
77 +#include <asm/arch/hardware.h>
78 +#include <asm/io.h>
79 +
80 +static short __iomem *latch_address;
81 +static unsigned short latch_value;
82 +
83 +
84 +static void fsg_led_wlan_set(struct led_classdev *led_cdev,
85 + enum led_brightness value)
86 +{
87 + if (value) {
88 + latch_value &= ~(1 << FSG_LED_WLAN_BIT);
89 + *latch_address = latch_value;
90 + } else {
91 + latch_value |= (1 << FSG_LED_WLAN_BIT);
92 + *latch_address = latch_value;
93 + }
94 +}
95 +
96 +static void fsg_led_wan_set(struct led_classdev *led_cdev,
97 + enum led_brightness value)
98 +{
99 + if (value) {
100 + latch_value &= ~(1 << FSG_LED_WAN_BIT);
101 + *latch_address = latch_value;
102 + } else {
103 + latch_value |= (1 << FSG_LED_WAN_BIT);
104 + *latch_address = latch_value;
105 + }
106 +}
107 +
108 +static void fsg_led_sata_set(struct led_classdev *led_cdev,
109 + enum led_brightness value)
110 +{
111 + if (value) {
112 + latch_value &= ~(1 << FSG_LED_SATA_BIT);
113 + *latch_address = latch_value;
114 + } else {
115 + latch_value |= (1 << FSG_LED_SATA_BIT);
116 + *latch_address = latch_value;
117 + }
118 +}
119 +
120 +static void fsg_led_usb_set(struct led_classdev *led_cdev,
121 + enum led_brightness value)
122 +{
123 + if (value) {
124 + latch_value &= ~(1 << FSG_LED_USB_BIT);
125 + *latch_address = latch_value;
126 + } else {
127 + latch_value |= (1 << FSG_LED_USB_BIT);
128 + *latch_address = latch_value;
129 + }
130 +}
131 +
132 +static void fsg_led_sync_set(struct led_classdev *led_cdev,
133 + enum led_brightness value)
134 +{
135 + if (value) {
136 + latch_value &= ~(1 << FSG_LED_SYNC_BIT);
137 + *latch_address = latch_value;
138 + } else {
139 + latch_value |= (1 << FSG_LED_SYNC_BIT);
140 + *latch_address = latch_value;
141 + }
142 +}
143 +
144 +static void fsg_led_ring_set(struct led_classdev *led_cdev,
145 + enum led_brightness value)
146 +{
147 + if (value) {
148 + latch_value &= ~(1 << FSG_LED_RING_BIT);
149 + *latch_address = latch_value;
150 + } else {
151 + latch_value |= (1 << FSG_LED_RING_BIT);
152 + *latch_address = latch_value;
153 + }
154 +}
155 +
156 +
157 +
158 +static struct led_classdev fsg_wlan_led = {
159 + .name = "fsg:blue:wlan",
160 + .brightness_set = fsg_led_wlan_set,
161 +};
162 +
163 +static struct led_classdev fsg_wan_led = {
164 + .name = "fsg:blue:wan",
165 + .brightness_set = fsg_led_wan_set,
166 +};
167 +
168 +static struct led_classdev fsg_sata_led = {
169 + .name = "fsg:blue:sata",
170 + .brightness_set = fsg_led_sata_set,
171 +};
172 +
173 +static struct led_classdev fsg_usb_led = {
174 + .name = "fsg:blue:usb",
175 + .brightness_set = fsg_led_usb_set,
176 +};
177 +
178 +static struct led_classdev fsg_sync_led = {
179 + .name = "fsg:blue:sync",
180 + .brightness_set = fsg_led_sync_set,
181 +};
182 +
183 +static struct led_classdev fsg_ring_led = {
184 + .name = "fsg:blue:ring",
185 + .brightness_set = fsg_led_ring_set,
186 +};
187 +
188 +
189 +
190 +#ifdef CONFIG_PM
191 +static int fsg_led_suspend(struct platform_device *dev, pm_message_t state)
192 +{
193 + led_classdev_suspend(&fsg_wlan_led);
194 + led_classdev_suspend(&fsg_wan_led);
195 + led_classdev_suspend(&fsg_sata_led);
196 + led_classdev_suspend(&fsg_usb_led);
197 + led_classdev_suspend(&fsg_sync_led);
198 + led_classdev_suspend(&fsg_ring_led);
199 + return 0;
200 +}
201 +
202 +static int fsg_led_resume(struct platform_device *dev)
203 +{
204 + led_classdev_resume(&fsg_wlan_led);
205 + led_classdev_resume(&fsg_wan_led);
206 + led_classdev_resume(&fsg_sata_led);
207 + led_classdev_resume(&fsg_usb_led);
208 + led_classdev_resume(&fsg_sync_led);
209 + led_classdev_resume(&fsg_ring_led);
210 + return 0;
211 +}
212 +#endif
213 +
214 +
215 +static int fsg_led_probe(struct platform_device *pdev)
216 +{
217 + int ret;
218 +
219 + ret = led_classdev_register(&pdev->dev, &fsg_wlan_led);
220 + if (ret < 0)
221 + goto failwlan;
222 +
223 + ret = led_classdev_register(&pdev->dev, &fsg_wan_led);
224 + if (ret < 0)
225 + goto failwan;
226 +
227 + ret = led_classdev_register(&pdev->dev, &fsg_sata_led);
228 + if (ret < 0)
229 + goto failsata;
230 +
231 + ret = led_classdev_register(&pdev->dev, &fsg_usb_led);
232 + if (ret < 0)
233 + goto failusb;
234 +
235 + ret = led_classdev_register(&pdev->dev, &fsg_sync_led);
236 + if (ret < 0)
237 + goto failsync;
238 +
239 + ret = led_classdev_register(&pdev->dev, &fsg_ring_led);
240 + if (ret < 0)
241 + goto failring;
242 +
243 + /* Map the LED chip select address space */
244 + latch_address = (unsigned short *) ioremap(IXP4XX_EXP_BUS_BASE(2), 512);
245 + if (!latch_address) {
246 + ret = -ENOMEM;
247 + goto failremap;
248 + }
249 +
250 + latch_value = 0xffff;
251 + *latch_address = latch_value;
252 +
253 + return ret;
254 +
255 + failremap:
256 + led_classdev_unregister(&fsg_ring_led);
257 + failring:
258 + led_classdev_unregister(&fsg_sync_led);
259 + failsync:
260 + led_classdev_unregister(&fsg_usb_led);
261 + failusb:
262 + led_classdev_unregister(&fsg_sata_led);
263 + failsata:
264 + led_classdev_unregister(&fsg_wan_led);
265 + failwan:
266 + led_classdev_unregister(&fsg_wlan_led);
267 + failwlan:
268 +
269 + return ret;
270 +}
271 +
272 +static int fsg_led_remove(struct platform_device *pdev)
273 +{
274 + iounmap(latch_address);
275 +
276 + led_classdev_unregister(&fsg_wlan_led);
277 + led_classdev_unregister(&fsg_wan_led);
278 + led_classdev_unregister(&fsg_sata_led);
279 + led_classdev_unregister(&fsg_usb_led);
280 + led_classdev_unregister(&fsg_sync_led);
281 + led_classdev_unregister(&fsg_ring_led);
282 +
283 + return 0;
284 +}
285 +
286 +
287 +static struct platform_driver fsg_led_driver = {
288 + .probe = fsg_led_probe,
289 + .remove = fsg_led_remove,
290 +#ifdef CONFIG_PM
291 + .suspend = fsg_led_suspend,
292 + .resume = fsg_led_resume,
293 +#endif
294 + .driver = {
295 + .name = "fsg-led",
296 + },
297 +};
298 +
299 +
300 +static int __init fsg_led_init(void)
301 +{
302 + return platform_driver_register(&fsg_led_driver);
303 +}
304 +
305 +static void __exit fsg_led_exit(void)
306 +{
307 + platform_driver_unregister(&fsg_led_driver);
308 +}
309 +
310 +
311 +module_init(fsg_led_init);
312 +module_exit(fsg_led_exit);
313 +
314 +MODULE_AUTHOR("Rod Whitby <rod@whitby.id.au>");
315 +MODULE_DESCRIPTION("Freecom FSG-3 LED driver");
316 +MODULE_LICENSE("GPL");
317 --
318 1.5.2.5
319
This page took 0.051563 seconds and 5 git commands to generate.