blob: 5f7c9c5c09b1306c35211ed024aed989c1592b61 [file] [log] [blame]
Rod Whitby3b2e46f2008-04-24 23:43:09 +01001/*
2 * LED Driver for the Freecom FSG-3
3 *
4 * Copyright (c) 2008 Rod Whitby <rod@whitby.id.au>
5 *
6 * Author: Rod Whitby <rod@whitby.id.au>
7 *
8 * Based on leds-spitz.c
9 * Copyright 2005-2006 Openedhand Ltd.
10 * Author: Richard Purdie <rpurdie@openedhand.com>
11 *
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.
15 *
16 */
17
18#include <linux/kernel.h>
19#include <linux/init.h>
20#include <linux/platform_device.h>
21#include <linux/leds.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010022#include <mach/hardware.h>
Rod Whitby3b2e46f2008-04-24 23:43:09 +010023#include <asm/io.h>
24
25static short __iomem *latch_address;
26static unsigned short latch_value;
27
28
29static void fsg_led_wlan_set(struct led_classdev *led_cdev,
30 enum led_brightness value)
31{
32 if (value) {
33 latch_value &= ~(1 << FSG_LED_WLAN_BIT);
34 *latch_address = latch_value;
35 } else {
36 latch_value |= (1 << FSG_LED_WLAN_BIT);
37 *latch_address = latch_value;
38 }
39}
40
41static void fsg_led_wan_set(struct led_classdev *led_cdev,
42 enum led_brightness value)
43{
44 if (value) {
45 latch_value &= ~(1 << FSG_LED_WAN_BIT);
46 *latch_address = latch_value;
47 } else {
48 latch_value |= (1 << FSG_LED_WAN_BIT);
49 *latch_address = latch_value;
50 }
51}
52
53static void fsg_led_sata_set(struct led_classdev *led_cdev,
54 enum led_brightness value)
55{
56 if (value) {
57 latch_value &= ~(1 << FSG_LED_SATA_BIT);
58 *latch_address = latch_value;
59 } else {
60 latch_value |= (1 << FSG_LED_SATA_BIT);
61 *latch_address = latch_value;
62 }
63}
64
65static void fsg_led_usb_set(struct led_classdev *led_cdev,
66 enum led_brightness value)
67{
68 if (value) {
69 latch_value &= ~(1 << FSG_LED_USB_BIT);
70 *latch_address = latch_value;
71 } else {
72 latch_value |= (1 << FSG_LED_USB_BIT);
73 *latch_address = latch_value;
74 }
75}
76
77static void fsg_led_sync_set(struct led_classdev *led_cdev,
78 enum led_brightness value)
79{
80 if (value) {
81 latch_value &= ~(1 << FSG_LED_SYNC_BIT);
82 *latch_address = latch_value;
83 } else {
84 latch_value |= (1 << FSG_LED_SYNC_BIT);
85 *latch_address = latch_value;
86 }
87}
88
89static void fsg_led_ring_set(struct led_classdev *led_cdev,
90 enum led_brightness value)
91{
92 if (value) {
93 latch_value &= ~(1 << FSG_LED_RING_BIT);
94 *latch_address = latch_value;
95 } else {
96 latch_value |= (1 << FSG_LED_RING_BIT);
97 *latch_address = latch_value;
98 }
99}
100
101
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100102static struct led_classdev fsg_wlan_led = {
103 .name = "fsg:blue:wlan",
104 .brightness_set = fsg_led_wlan_set,
Richard Purdie859cb7f2009-01-08 17:55:03 +0000105 .flags = LED_CORE_SUSPENDRESUME,
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100106};
107
108static struct led_classdev fsg_wan_led = {
109 .name = "fsg:blue:wan",
110 .brightness_set = fsg_led_wan_set,
Richard Purdie859cb7f2009-01-08 17:55:03 +0000111 .flags = LED_CORE_SUSPENDRESUME,
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100112};
113
114static struct led_classdev fsg_sata_led = {
115 .name = "fsg:blue:sata",
116 .brightness_set = fsg_led_sata_set,
Richard Purdie859cb7f2009-01-08 17:55:03 +0000117 .flags = LED_CORE_SUSPENDRESUME,
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100118};
119
120static struct led_classdev fsg_usb_led = {
121 .name = "fsg:blue:usb",
122 .brightness_set = fsg_led_usb_set,
Richard Purdie859cb7f2009-01-08 17:55:03 +0000123 .flags = LED_CORE_SUSPENDRESUME,
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100124};
125
126static struct led_classdev fsg_sync_led = {
127 .name = "fsg:blue:sync",
128 .brightness_set = fsg_led_sync_set,
Richard Purdie859cb7f2009-01-08 17:55:03 +0000129 .flags = LED_CORE_SUSPENDRESUME,
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100130};
131
132static struct led_classdev fsg_ring_led = {
133 .name = "fsg:blue:ring",
134 .brightness_set = fsg_led_ring_set,
Richard Purdie859cb7f2009-01-08 17:55:03 +0000135 .flags = LED_CORE_SUSPENDRESUME,
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100136};
137
138
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100139static int fsg_led_probe(struct platform_device *pdev)
140{
141 int ret;
142
Sven Wegener07f696c2008-10-03 15:23:47 -0700143 /* Map the LED chip select address space */
144 latch_address = (unsigned short *) ioremap(IXP4XX_EXP_BUS_BASE(2), 512);
145 if (!latch_address) {
146 ret = -ENOMEM;
147 goto failremap;
148 }
149
150 latch_value = 0xffff;
151 *latch_address = latch_value;
152
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100153 ret = led_classdev_register(&pdev->dev, &fsg_wlan_led);
154 if (ret < 0)
155 goto failwlan;
156
157 ret = led_classdev_register(&pdev->dev, &fsg_wan_led);
158 if (ret < 0)
159 goto failwan;
160
161 ret = led_classdev_register(&pdev->dev, &fsg_sata_led);
162 if (ret < 0)
163 goto failsata;
164
165 ret = led_classdev_register(&pdev->dev, &fsg_usb_led);
166 if (ret < 0)
167 goto failusb;
168
169 ret = led_classdev_register(&pdev->dev, &fsg_sync_led);
170 if (ret < 0)
171 goto failsync;
172
173 ret = led_classdev_register(&pdev->dev, &fsg_ring_led);
174 if (ret < 0)
175 goto failring;
176
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100177 return ret;
178
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100179 failring:
180 led_classdev_unregister(&fsg_sync_led);
181 failsync:
182 led_classdev_unregister(&fsg_usb_led);
183 failusb:
184 led_classdev_unregister(&fsg_sata_led);
185 failsata:
186 led_classdev_unregister(&fsg_wan_led);
187 failwan:
188 led_classdev_unregister(&fsg_wlan_led);
189 failwlan:
Sven Wegener07f696c2008-10-03 15:23:47 -0700190 iounmap(latch_address);
191 failremap:
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100192
193 return ret;
194}
195
196static int fsg_led_remove(struct platform_device *pdev)
197{
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100198 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);
204
Sven Wegener07f696c2008-10-03 15:23:47 -0700205 iounmap(latch_address);
206
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100207 return 0;
208}
209
210
211static struct platform_driver fsg_led_driver = {
212 .probe = fsg_led_probe,
213 .remove = fsg_led_remove,
Rod Whitby3b2e46f2008-04-24 23:43:09 +0100214 .driver = {
215 .name = "fsg-led",
216 },
217};
218
219
220static int __init fsg_led_init(void)
221{
222 return platform_driver_register(&fsg_led_driver);
223}
224
225static void __exit fsg_led_exit(void)
226{
227 platform_driver_unregister(&fsg_led_driver);
228}
229
230
231module_init(fsg_led_init);
232module_exit(fsg_led_exit);
233
234MODULE_AUTHOR("Rod Whitby <rod@whitby.id.au>");
235MODULE_DESCRIPTION("Freecom FSG-3 LED driver");
236MODULE_LICENSE("GPL");