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 <mach/hardware.h>
25 static short __iomem
*latch_address
;
26 static unsigned short latch_value
;
29 static void fsg_led_wlan_set(struct led_classdev
*led_cdev
,
30 enum led_brightness value
)
33 latch_value
&= ~(1 << FSG_LED_WLAN_BIT
);
34 *latch_address
= latch_value
;
36 latch_value
|= (1 << FSG_LED_WLAN_BIT
);
37 *latch_address
= latch_value
;
41 static void fsg_led_wan_set(struct led_classdev
*led_cdev
,
42 enum led_brightness value
)
45 latch_value
&= ~(1 << FSG_LED_WAN_BIT
);
46 *latch_address
= latch_value
;
48 latch_value
|= (1 << FSG_LED_WAN_BIT
);
49 *latch_address
= latch_value
;
53 static void fsg_led_sata_set(struct led_classdev
*led_cdev
,
54 enum led_brightness value
)
57 latch_value
&= ~(1 << FSG_LED_SATA_BIT
);
58 *latch_address
= latch_value
;
60 latch_value
|= (1 << FSG_LED_SATA_BIT
);
61 *latch_address
= latch_value
;
65 static void fsg_led_usb_set(struct led_classdev
*led_cdev
,
66 enum led_brightness value
)
69 latch_value
&= ~(1 << FSG_LED_USB_BIT
);
70 *latch_address
= latch_value
;
72 latch_value
|= (1 << FSG_LED_USB_BIT
);
73 *latch_address
= latch_value
;
77 static void fsg_led_sync_set(struct led_classdev
*led_cdev
,
78 enum led_brightness value
)
81 latch_value
&= ~(1 << FSG_LED_SYNC_BIT
);
82 *latch_address
= latch_value
;
84 latch_value
|= (1 << FSG_LED_SYNC_BIT
);
85 *latch_address
= latch_value
;
89 static void fsg_led_ring_set(struct led_classdev
*led_cdev
,
90 enum led_brightness value
)
93 latch_value
&= ~(1 << FSG_LED_RING_BIT
);
94 *latch_address
= latch_value
;
96 latch_value
|= (1 << FSG_LED_RING_BIT
);
97 *latch_address
= latch_value
;
102 static struct led_classdev fsg_wlan_led
= {
103 .name
= "fsg:blue:wlan",
104 .brightness_set
= fsg_led_wlan_set
,
105 .flags
= LED_CORE_SUSPENDRESUME
,
108 static struct led_classdev fsg_wan_led
= {
109 .name
= "fsg:blue:wan",
110 .brightness_set
= fsg_led_wan_set
,
111 .flags
= LED_CORE_SUSPENDRESUME
,
114 static struct led_classdev fsg_sata_led
= {
115 .name
= "fsg:blue:sata",
116 .brightness_set
= fsg_led_sata_set
,
117 .flags
= LED_CORE_SUSPENDRESUME
,
120 static struct led_classdev fsg_usb_led
= {
121 .name
= "fsg:blue:usb",
122 .brightness_set
= fsg_led_usb_set
,
123 .flags
= LED_CORE_SUSPENDRESUME
,
126 static struct led_classdev fsg_sync_led
= {
127 .name
= "fsg:blue:sync",
128 .brightness_set
= fsg_led_sync_set
,
129 .flags
= LED_CORE_SUSPENDRESUME
,
132 static struct led_classdev fsg_ring_led
= {
133 .name
= "fsg:blue:ring",
134 .brightness_set
= fsg_led_ring_set
,
135 .flags
= LED_CORE_SUSPENDRESUME
,
139 static int fsg_led_probe(struct platform_device
*pdev
)
143 /* Map the LED chip select address space */
144 latch_address
= (unsigned short *) ioremap(IXP4XX_EXP_BUS_BASE(2), 512);
145 if (!latch_address
) {
150 latch_value
= 0xffff;
151 *latch_address
= latch_value
;
153 ret
= led_classdev_register(&pdev
->dev
, &fsg_wlan_led
);
157 ret
= led_classdev_register(&pdev
->dev
, &fsg_wan_led
);
161 ret
= led_classdev_register(&pdev
->dev
, &fsg_sata_led
);
165 ret
= led_classdev_register(&pdev
->dev
, &fsg_usb_led
);
169 ret
= led_classdev_register(&pdev
->dev
, &fsg_sync_led
);
173 ret
= led_classdev_register(&pdev
->dev
, &fsg_ring_led
);
180 led_classdev_unregister(&fsg_sync_led
);
182 led_classdev_unregister(&fsg_usb_led
);
184 led_classdev_unregister(&fsg_sata_led
);
186 led_classdev_unregister(&fsg_wan_led
);
188 led_classdev_unregister(&fsg_wlan_led
);
190 iounmap(latch_address
);
196 static int fsg_led_remove(struct platform_device
*pdev
)
198 led_classdev_unregister(&fsg_wlan_led
);
199 led_classdev_unregister(&fsg_wan_led
);
200 led_classdev_unregister(&fsg_sata_led
);
201 led_classdev_unregister(&fsg_usb_led
);
202 led_classdev_unregister(&fsg_sync_led
);
203 led_classdev_unregister(&fsg_ring_led
);
205 iounmap(latch_address
);
211 static struct platform_driver fsg_led_driver
= {
212 .probe
= fsg_led_probe
,
213 .remove
= fsg_led_remove
,
220 static int __init
fsg_led_init(void)
222 return platform_driver_register(&fsg_led_driver
);
225 static void __exit
fsg_led_exit(void)
227 platform_driver_unregister(&fsg_led_driver
);
231 module_init(fsg_led_init
);
232 module_exit(fsg_led_exit
);
234 MODULE_AUTHOR("Rod Whitby <rod@whitby.id.au>");
235 MODULE_DESCRIPTION("Freecom FSG-3 LED driver");
236 MODULE_LICENSE("GPL");