2 * LED Driver for the Freecom FSG-3
4 * Copyright (c) 2008 Rod Whitby <rod@whitby.id.au>
6 * Author: Rod Whitby <rod@whitby.id.au>
8 * Based on leds-spitz.c
9 * Copyright 2005-2006 Openedhand Ltd.
10 * Author: Richard Purdie <rpurdie@openedhand.com>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
18 #include <linux/kernel.h>
19 #include <linux/init.h>
20 #include <linux/platform_device.h>
21 #include <linux/leds.h>
22 #include <linux/module.h>
23 #include <mach/hardware.h>
26 #define FSG_LED_WLAN_BIT 0
27 #define FSG_LED_WAN_BIT 1
28 #define FSG_LED_SATA_BIT 2
29 #define FSG_LED_USB_BIT 4
30 #define FSG_LED_RING_BIT 5
31 #define FSG_LED_SYNC_BIT 7
33 static short __iomem
*latch_address
;
34 static unsigned short latch_value
;
37 static void fsg_led_wlan_set(struct led_classdev
*led_cdev
,
38 enum led_brightness value
)
41 latch_value
&= ~(1 << FSG_LED_WLAN_BIT
);
42 *latch_address
= latch_value
;
44 latch_value
|= (1 << FSG_LED_WLAN_BIT
);
45 *latch_address
= latch_value
;
49 static void fsg_led_wan_set(struct led_classdev
*led_cdev
,
50 enum led_brightness value
)
53 latch_value
&= ~(1 << FSG_LED_WAN_BIT
);
54 *latch_address
= latch_value
;
56 latch_value
|= (1 << FSG_LED_WAN_BIT
);
57 *latch_address
= latch_value
;
61 static void fsg_led_sata_set(struct led_classdev
*led_cdev
,
62 enum led_brightness value
)
65 latch_value
&= ~(1 << FSG_LED_SATA_BIT
);
66 *latch_address
= latch_value
;
68 latch_value
|= (1 << FSG_LED_SATA_BIT
);
69 *latch_address
= latch_value
;
73 static void fsg_led_usb_set(struct led_classdev
*led_cdev
,
74 enum led_brightness value
)
77 latch_value
&= ~(1 << FSG_LED_USB_BIT
);
78 *latch_address
= latch_value
;
80 latch_value
|= (1 << FSG_LED_USB_BIT
);
81 *latch_address
= latch_value
;
85 static void fsg_led_sync_set(struct led_classdev
*led_cdev
,
86 enum led_brightness value
)
89 latch_value
&= ~(1 << FSG_LED_SYNC_BIT
);
90 *latch_address
= latch_value
;
92 latch_value
|= (1 << FSG_LED_SYNC_BIT
);
93 *latch_address
= latch_value
;
97 static void fsg_led_ring_set(struct led_classdev
*led_cdev
,
98 enum led_brightness value
)
101 latch_value
&= ~(1 << FSG_LED_RING_BIT
);
102 *latch_address
= latch_value
;
104 latch_value
|= (1 << FSG_LED_RING_BIT
);
105 *latch_address
= latch_value
;
110 static struct led_classdev fsg_wlan_led
= {
111 .name
= "fsg:blue:wlan",
112 .brightness_set
= fsg_led_wlan_set
,
113 .flags
= LED_CORE_SUSPENDRESUME
,
116 static struct led_classdev fsg_wan_led
= {
117 .name
= "fsg:blue:wan",
118 .brightness_set
= fsg_led_wan_set
,
119 .flags
= LED_CORE_SUSPENDRESUME
,
122 static struct led_classdev fsg_sata_led
= {
123 .name
= "fsg:blue:sata",
124 .brightness_set
= fsg_led_sata_set
,
125 .flags
= LED_CORE_SUSPENDRESUME
,
128 static struct led_classdev fsg_usb_led
= {
129 .name
= "fsg:blue:usb",
130 .brightness_set
= fsg_led_usb_set
,
131 .flags
= LED_CORE_SUSPENDRESUME
,
134 static struct led_classdev fsg_sync_led
= {
135 .name
= "fsg:blue:sync",
136 .brightness_set
= fsg_led_sync_set
,
137 .flags
= LED_CORE_SUSPENDRESUME
,
140 static struct led_classdev fsg_ring_led
= {
141 .name
= "fsg:blue:ring",
142 .brightness_set
= fsg_led_ring_set
,
143 .flags
= LED_CORE_SUSPENDRESUME
,
147 static int fsg_led_probe(struct platform_device
*pdev
)
151 /* Map the LED chip select address space */
152 latch_address
= (unsigned short *) ioremap(IXP4XX_EXP_BUS_BASE(2), 512);
153 if (!latch_address
) {
158 latch_value
= 0xffff;
159 *latch_address
= latch_value
;
161 ret
= led_classdev_register(&pdev
->dev
, &fsg_wlan_led
);
165 ret
= led_classdev_register(&pdev
->dev
, &fsg_wan_led
);
169 ret
= led_classdev_register(&pdev
->dev
, &fsg_sata_led
);
173 ret
= led_classdev_register(&pdev
->dev
, &fsg_usb_led
);
177 ret
= led_classdev_register(&pdev
->dev
, &fsg_sync_led
);
181 ret
= led_classdev_register(&pdev
->dev
, &fsg_ring_led
);
188 led_classdev_unregister(&fsg_sync_led
);
190 led_classdev_unregister(&fsg_usb_led
);
192 led_classdev_unregister(&fsg_sata_led
);
194 led_classdev_unregister(&fsg_wan_led
);
196 led_classdev_unregister(&fsg_wlan_led
);
198 iounmap(latch_address
);
204 static int fsg_led_remove(struct platform_device
*pdev
)
206 led_classdev_unregister(&fsg_wlan_led
);
207 led_classdev_unregister(&fsg_wan_led
);
208 led_classdev_unregister(&fsg_sata_led
);
209 led_classdev_unregister(&fsg_usb_led
);
210 led_classdev_unregister(&fsg_sync_led
);
211 led_classdev_unregister(&fsg_ring_led
);
213 iounmap(latch_address
);
219 static struct platform_driver fsg_led_driver
= {
220 .probe
= fsg_led_probe
,
221 .remove
= fsg_led_remove
,
228 static int __init
fsg_led_init(void)
230 return platform_driver_register(&fsg_led_driver
);
233 static void __exit
fsg_led_exit(void)
235 platform_driver_unregister(&fsg_led_driver
);
239 module_init(fsg_led_init
);
240 module_exit(fsg_led_exit
);
242 MODULE_AUTHOR("Rod Whitby <rod@whitby.id.au>");
243 MODULE_DESCRIPTION("Freecom FSG-3 LED driver");
244 MODULE_LICENSE("GPL");