4 * ADM5120 GPIO LED devices
6 * Copyright (C) 2007,2008 OpenWrt.org
7 * Copyright (C) 2007,2008 Gabor Juhos <juhosg at openwrt.org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 as published
11 * by the Free Software Foundation.
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/platform_device.h>
18 #include <linux/leds.h>
19 #include <linux/err.h>
22 #include <linux/leds.h>
24 #include <asm/bootinfo.h>
27 #include <adm5120_info.h>
29 #define NUM_LEDS_MAX 23
30 #define DRV_DESC "LED driver for the ADM5120 based boards"
32 #define ADM5120_GPIO_xxxx 0x100 /* an unknown pin */
35 unsigned long machtype
;
37 struct gpio_led
*leds
;
40 struct adm5120_leddev
{
41 struct platform_device pdev
;
43 struct gpio_led_platform_data pdata
;
47 static struct adm5120_leddev
*led_devs
[NUM_LEDS_MAX
];
49 #define LED_ARRAY(n) \
50 static struct gpio_led n ## _leds [] __initdata =
52 #define LED_DATA(n, t, g, a) { \
54 .default_trigger = (t), \
59 #define LED_STD(g, n, t) LED_DATA((n), (t), (g), 0)
60 #define LED_INV(g, n, t) LED_DATA((n), (t), (g), 1)
65 #if defined(CONFIG_LEDS_ADM5120_EXPERIMENTAL)
66 LED_ARRAY(np27g
) { /* FIXME: untested */
67 LED_STD(ADM5120_GPIO_xxxx
, "lan1", NULL
),
68 LED_STD(ADM5120_GPIO_xxxx
, "lan2", NULL
),
69 LED_STD(ADM5120_GPIO_xxxx
, "lan3", NULL
),
70 LED_STD(ADM5120_GPIO_xxxx
, "lan4", NULL
),
71 LED_STD(ADM5120_GPIO_xxxx
, "wan_cond", NULL
),
72 LED_STD(ADM5120_GPIO_xxxx
, "wlan", NULL
),
73 LED_STD(ADM5120_GPIO_xxxx
, "wan_act", NULL
),
74 LED_STD(ADM5120_GPIO_xxxx
, "usb1", NULL
),
75 LED_STD(ADM5120_GPIO_xxxx
, "usb2", NULL
),
76 LED_INV(ADM5120_GPIO_PIN2
, "power", NULL
),
77 LED_STD(ADM5120_GPIO_xxxx
, "diag", NULL
),
82 LED_INV(ADM5120_GPIO_PIN2
, "diag", NULL
),
83 LED_INV(ADM5120_GPIO_PIN3
, "power", NULL
),
84 LED_INV(ADM5120_GPIO_PIN6
, "wan_cond", NULL
),
85 LED_INV(ADM5120_GPIO_PIN7
, "wifi", NULL
),
86 LED_INV(ADM5120_GPIO_P0L2
, "usb1", NULL
),
87 LED_INV(ADM5120_GPIO_P1L0
, "lan1", NULL
),
88 LED_INV(ADM5120_GPIO_P1L2
, "usb2", NULL
),
89 LED_INV(ADM5120_GPIO_P2L0
, "lan2", NULL
),
90 LED_INV(ADM5120_GPIO_P2L2
, "usb3", NULL
),
91 LED_INV(ADM5120_GPIO_P3L0
, "lan3", NULL
),
92 LED_INV(ADM5120_GPIO_P3L2
, "usb4", NULL
),
93 LED_INV(ADM5120_GPIO_P4L0
, "wan", NULL
),
97 LED_INV(ADM5120_GPIO_PIN2
, "diag", NULL
),
98 LED_INV(ADM5120_GPIO_PIN6
, "wlan", NULL
),
99 LED_INV(ADM5120_GPIO_PIN7
, "wan", NULL
),
100 LED_INV(ADM5120_GPIO_P0L0
, "lan1", NULL
),
101 LED_INV(ADM5120_GPIO_P1L0
, "lan2", NULL
),
108 LED_STD(ADM5120_GPIO_PIN0
, "power", NULL
),
109 LED_INV(ADM5120_GPIO_P0L1
, "wan_speed", NULL
),
110 LED_INV(ADM5120_GPIO_P0L0
, "wan_lnkact", NULL
),
111 LED_INV(ADM5120_GPIO_P1L1
, "lan1_speed", NULL
),
112 LED_INV(ADM5120_GPIO_P1L0
, "lan1_lnkact", NULL
),
113 LED_INV(ADM5120_GPIO_P2L1
, "lan2_speed", NULL
),
114 LED_INV(ADM5120_GPIO_P2L0
, "lan2_lnkact", NULL
),
115 LED_INV(ADM5120_GPIO_P3L1
, "lan3_speed", NULL
),
116 LED_INV(ADM5120_GPIO_P3L0
, "lan3_lnkact", NULL
),
117 LED_INV(ADM5120_GPIO_P4L1
, "lan4_speed", NULL
),
118 LED_INV(ADM5120_GPIO_P4L0
, "lan4_lnkact", NULL
),
121 LED_ARRAY(br61x4wg
) {
122 LED_STD(ADM5120_GPIO_PIN0
, "power", NULL
),
123 LED_STD(ADM5120_GPIO_PIN5
, "wlan", NULL
),
124 LED_INV(ADM5120_GPIO_P0L1
, "wan_speed", NULL
),
125 LED_INV(ADM5120_GPIO_P0L0
, "wan_lnkact", NULL
),
126 LED_INV(ADM5120_GPIO_P1L1
, "lan1_speed", NULL
),
127 LED_INV(ADM5120_GPIO_P1L0
, "lan1_lnkact", NULL
),
128 LED_INV(ADM5120_GPIO_P2L1
, "lan2_speed", NULL
),
129 LED_INV(ADM5120_GPIO_P2L0
, "lan2_lnkact", NULL
),
130 LED_INV(ADM5120_GPIO_P3L1
, "lan3_speed", NULL
),
131 LED_INV(ADM5120_GPIO_P3L0
, "lan3_lnkact", NULL
),
132 LED_INV(ADM5120_GPIO_P4L1
, "lan4_speed", NULL
),
133 LED_INV(ADM5120_GPIO_P4L0
, "lan4_lnkact", NULL
),
140 LED_STD(ADM5120_GPIO_PIN3
, "user", NULL
),
141 LED_INV(ADM5120_GPIO_P0L1
, "lan_speed", NULL
),
142 LED_INV(ADM5120_GPIO_P0L0
, "lan_lnkact", NULL
),
146 LED_STD(ADM5120_GPIO_PIN6
, "power", NULL
),
147 LED_STD(ADM5120_GPIO_PIN5
, "user", NULL
),
148 LED_INV(ADM5120_GPIO_P2L1
, "lan1_speed", NULL
), /* untested */
149 LED_INV(ADM5120_GPIO_P2L0
, "lan1_lnkact", NULL
), /* untested */
153 LED_STD(ADM5120_GPIO_PIN6
, "power", NULL
),
154 LED_STD(ADM5120_GPIO_PIN5
, "user", NULL
),
155 LED_INV(ADM5120_GPIO_P2L1
, "lan1_speed", NULL
), /* untested */
156 LED_INV(ADM5120_GPIO_P2L0
, "lan1_lnkact", NULL
), /* untested */
157 LED_INV(ADM5120_GPIO_P1L1
, "lan2_speed", NULL
), /* untested */
158 LED_INV(ADM5120_GPIO_P1L0
, "lan2_lnkact", NULL
), /* untested */
159 LED_INV(ADM5120_GPIO_P0L1
, "lan3_speed", NULL
), /* untested */
160 LED_INV(ADM5120_GPIO_P0L0
, "lan3_lnkact", NULL
), /* untested */
164 LED_STD(ADM5120_GPIO_PIN5
, "user", NULL
),
165 LED_INV(ADM5120_GPIO_P0L1
, "lan1_speed", NULL
),
166 LED_INV(ADM5120_GPIO_P0L0
, "lan1_lnkact", NULL
),
167 LED_INV(ADM5120_GPIO_P1L1
, "lan5_speed", NULL
),
168 LED_INV(ADM5120_GPIO_P1L0
, "lan5_lnkact", NULL
),
169 LED_INV(ADM5120_GPIO_P2L1
, "lan4_speed", NULL
),
170 LED_INV(ADM5120_GPIO_P2L0
, "lan4_lnkact", NULL
),
171 LED_INV(ADM5120_GPIO_P3L1
, "lan3_speed", NULL
),
172 LED_INV(ADM5120_GPIO_P3L0
, "lan3_lnkact", NULL
),
173 LED_INV(ADM5120_GPIO_P4L1
, "lan2_speed", NULL
),
174 LED_INV(ADM5120_GPIO_P4L0
, "lan2_lnkact", NULL
),
180 #if defined(CONFIG_LEDS_ADM5120_EXPERIMENTAL)
181 LED_ARRAY(p334
) { /* FIXME: untested */
182 LED_INV(ADM5120_GPIO_xxxx
, "power", NULL
),
183 LED_INV(ADM5120_GPIO_xxxx
, "lan1", NULL
),
184 LED_INV(ADM5120_GPIO_xxxx
, "lan2", NULL
),
185 LED_INV(ADM5120_GPIO_xxxx
, "lan3", NULL
),
186 LED_INV(ADM5120_GPIO_xxxx
, "lan4", NULL
),
187 LED_INV(ADM5120_GPIO_xxxx
, "wan", NULL
),
192 LED_INV(ADM5120_GPIO_PIN2
, "power", NULL
),
193 LED_INV(ADM5120_GPIO_P3L0
, "lan1", NULL
),
194 LED_INV(ADM5120_GPIO_P2L0
, "lan2", NULL
),
195 LED_INV(ADM5120_GPIO_P1L0
, "lan3", NULL
),
196 LED_INV(ADM5120_GPIO_P0L0
, "lan4", NULL
),
197 LED_INV(ADM5120_GPIO_P4L0
, "wan", NULL
),
198 LED_INV(ADM5120_GPIO_P4L2
, "wlan", NULL
),
199 LED_INV(ADM5120_GPIO_P2L2
, "otist", NULL
),
200 LED_INV(ADM5120_GPIO_P1L2
, "hidden", NULL
),
203 #if defined(CONFIG_LEDS_ADM5120_EXPERIMENTAL)
204 LED_ARRAY(p335
) { /* FIXME: untested */
205 LED_INV(ADM5120_GPIO_PIN2
, "power", NULL
),
206 LED_INV(ADM5120_GPIO_P3L0
, "lan1", NULL
),
207 LED_INV(ADM5120_GPIO_P2L0
, "lan2", NULL
),
208 LED_INV(ADM5120_GPIO_P1L0
, "lan3", NULL
),
209 LED_INV(ADM5120_GPIO_P0L0
, "lan4", NULL
),
210 LED_INV(ADM5120_GPIO_P4L0
, "wan", NULL
),
211 LED_INV(ADM5120_GPIO_P4L2
, "wlan", NULL
),
212 LED_INV(ADM5120_GPIO_P2L2
, "otist", NULL
),
213 LED_INV(ADM5120_GPIO_xxxx
, "usb", NULL
),
221 #if defined(CONFIG_LEDS_ADM5120_DIAG)
222 LED_STD(ADM5120_GPIO_PIN0
, "gpio0", NULL
),
223 LED_STD(ADM5120_GPIO_PIN1
, "gpio1", NULL
),
224 LED_STD(ADM5120_GPIO_PIN2
, "gpio2", NULL
),
225 LED_STD(ADM5120_GPIO_PIN3
, "gpio3", NULL
),
226 LED_STD(ADM5120_GPIO_PIN4
, "gpio4", NULL
),
227 LED_STD(ADM5120_GPIO_PIN5
, "gpio5", NULL
),
228 LED_STD(ADM5120_GPIO_PIN6
, "gpio6", NULL
),
229 LED_STD(ADM5120_GPIO_PIN7
, "gpio7", NULL
),
230 LED_STD(ADM5120_GPIO_P0L0
, "port0led0", NULL
),
231 LED_STD(ADM5120_GPIO_P0L1
, "port0led1", NULL
),
232 LED_STD(ADM5120_GPIO_P0L2
, "port0led2", NULL
),
233 LED_STD(ADM5120_GPIO_P1L0
, "port1led0", NULL
),
234 LED_STD(ADM5120_GPIO_P1L1
, "port1led1", NULL
),
235 LED_STD(ADM5120_GPIO_P1L2
, "port1led2", NULL
),
236 LED_STD(ADM5120_GPIO_P2L0
, "port2led0", NULL
),
237 LED_STD(ADM5120_GPIO_P2L1
, "port2led1", NULL
),
238 LED_STD(ADM5120_GPIO_P2L2
, "port2led2", NULL
),
239 LED_STD(ADM5120_GPIO_P3L0
, "port3led0", NULL
),
240 LED_STD(ADM5120_GPIO_P3L1
, "port3led1", NULL
),
241 LED_STD(ADM5120_GPIO_P3L2
, "port3led2", NULL
),
242 LED_STD(ADM5120_GPIO_P4L0
, "port4led0", NULL
),
243 LED_STD(ADM5120_GPIO_P4L1
, "port4led1", NULL
),
244 LED_STD(ADM5120_GPIO_P4L2
, "port4led2", NULL
),
248 #define MACH_DATA(m, n) { \
250 .nr_leds = ARRAY_SIZE(n ## _leds), \
254 static struct mach_data machines
[] __initdata
= {
255 MACH_DATA(MACH_ADM5120_GENERIC
, generic
),
257 MACH_DATA(MACH_ADM5120_NP28G
, np28g
),
258 MACH_DATA(MACH_ADM5120_NP28GHS
, np28g
),
259 MACH_DATA(MACH_ADM5120_WP54AG
, wp54g
),
260 MACH_DATA(MACH_ADM5120_WP54G
, wp54g
),
261 MACH_DATA(MACH_ADM5120_WP54G_WRT
, wp54g
),
262 MACH_DATA(MACH_ADM5120_WPP54AG
, wp54g
),
263 MACH_DATA(MACH_ADM5120_WPP54G
, wp54g
),
265 MACH_DATA(MACH_ADM5120_BR6104K
, br6104k
),
266 MACH_DATA(MACH_ADM5120_BR61x4WG
, br61x4wg
),
268 MACH_DATA(MACH_ADM5120_RB_111
, rb100
),
269 MACH_DATA(MACH_ADM5120_RB_112
, rb100
),
270 MACH_DATA(MACH_ADM5120_RB_133
, rb133
),
271 MACH_DATA(MACH_ADM5120_RB_133C
, rb133c
),
272 MACH_DATA(MACH_ADM5120_RB_153
, rb153
),
274 MACH_DATA(MACH_ADM5120_P334WT
, p334wt
),
275 #if defined(CONFIG_LEDS_ADM5120_EXPERIMENTAL)
277 MACH_DATA(MACH_ADM5120_P334
, p334
),
278 MACH_DATA(MACH_ADM5120_P335
, p335
),
279 MACH_DATA(MACH_ADM5120_NP27G
, np27g
),
283 static struct adm5120_leddev
* __init
284 create_leddev(int id
, struct gpio_led
*led
)
286 struct adm5120_leddev
*p
;
288 p
= kzalloc(sizeof(*p
), GFP_KERNEL
);
292 memcpy(&p
->led
, led
, sizeof(p
->led
));
293 p
->pdev
.name
= "leds-gpio";
295 p
->pdev
.dev
.platform_data
= &p
->pdata
;
296 p
->pdata
.num_leds
= 1;
297 p
->pdata
.leds
= &p
->led
;
302 static struct mach_data
* __init
303 adm5120_leds_findmach(unsigned long machtype
)
305 struct mach_data
*mach
;
309 for (i
= 0; i
< ARRAY_SIZE(machines
); i
++) {
310 if (machines
[i
].machtype
== machtype
) {
316 #if defined(CONFIG_LEDS_ADM5120_DIAG)
325 adm5120_leds_init(void)
327 struct mach_data
*mach
;
330 mach
= adm5120_leds_findmach(mips_machtype
);
332 printk(KERN_ERR
"leds-adm5120: unsupported board\n");
337 for (i
= 0; i
< mach
->nr_leds
; i
++) {
338 led_devs
[i
] = create_leddev(i
, &mach
->leds
[i
]);
339 if (led_devs
[i
] == NULL
) {
345 for (i
= 0; i
< mach
->nr_leds
; i
++) {
346 ret
= platform_device_register(&led_devs
[i
]->pdev
);
351 led_count
= mach
->nr_leds
;
355 for (i
--; i
>= 0; i
--)
356 platform_device_unregister(&led_devs
[i
]->pdev
);
359 for (i
= 0; i
< led_count
; i
++)
366 adm5120_leds_exit(void)
370 for (i
= 0; i
< led_count
; i
++) {
371 platform_device_unregister(&led_devs
[i
]->pdev
);
376 module_init(adm5120_leds_init
);
377 module_exit(adm5120_leds_exit
);
379 MODULE_AUTHOR("Gabor Juhos <juhosg at openwrt.org>");
380 MODULE_DESCRIPTION(DRV_DESC
);
381 MODULE_LICENSE("GPL v2");