4 * ADM5120 GPIO LED devices
6 * Copyright (C) 2007 OpenWrt.org
7 * Copyright (C) 2007 Gabor Juhos <juhosg at openwrt.org>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the
21 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
26 #include <linux/kernel.h>
27 #include <linux/init.h>
28 #include <linux/platform_device.h>
29 #include <linux/leds.h>
30 #include <linux/err.h>
33 #include <linux/leds.h>
35 #include <asm/bootinfo.h>
38 #include <adm5120_info.h>
40 #define NUM_LEDS_MAX 23
41 #define DRV_DESC "LED driver for the ADM5120 based boards"
43 #define ADM5120_GPIO_xxxx 0x100 /* an unknown pin */
46 unsigned long machtype
;
48 struct gpio_led
*leds
;
51 struct adm5120_leddev
{
52 struct platform_device pdev
;
54 struct gpio_led_platform_data pdata
;
58 static struct adm5120_leddev
*led_devs
[NUM_LEDS_MAX
];
60 #define LED_ARRAY(n) \
61 static struct gpio_led n ## _leds [] __initdata =
63 #define LED_DATA(n, t, g, a) { \
65 .default_trigger = (t), \
70 #define LED_STD(g, n, t) LED_DATA((n), (t), (g), 0)
71 #define LED_INV(g, n, t) LED_DATA((n), (t), (g), 1)
76 #if defined(CONFIG_LEDS_ADM5120_EXPERIMENTAL)
77 LED_ARRAY(np27g
) { /* FIXME: untested */
78 LED_STD(ADM5120_GPIO_xxxx
, "lan1", NULL
),
79 LED_STD(ADM5120_GPIO_xxxx
, "lan2", NULL
),
80 LED_STD(ADM5120_GPIO_xxxx
, "lan3", NULL
),
81 LED_STD(ADM5120_GPIO_xxxx
, "lan4", NULL
),
82 LED_STD(ADM5120_GPIO_xxxx
, "wan_cond", NULL
),
83 LED_STD(ADM5120_GPIO_xxxx
, "wlan", NULL
),
84 LED_STD(ADM5120_GPIO_xxxx
, "wan_act", NULL
),
85 LED_STD(ADM5120_GPIO_xxxx
, "usb1", NULL
),
86 LED_STD(ADM5120_GPIO_xxxx
, "usb2", NULL
),
87 LED_INV(ADM5120_GPIO_PIN2
, "power", NULL
),
88 LED_STD(ADM5120_GPIO_xxxx
, "diag", NULL
),
93 LED_INV(ADM5120_GPIO_PIN2
, "diag", NULL
),
94 LED_INV(ADM5120_GPIO_PIN3
, "power", NULL
),
95 LED_INV(ADM5120_GPIO_PIN6
, "wan_cond", NULL
),
96 LED_INV(ADM5120_GPIO_PIN7
, "wifi", NULL
),
97 LED_INV(ADM5120_GPIO_P0L2
, "usb1", NULL
),
98 LED_INV(ADM5120_GPIO_P1L0
, "lan1", NULL
),
99 LED_INV(ADM5120_GPIO_P1L2
, "usb2", NULL
),
100 LED_INV(ADM5120_GPIO_P2L0
, "lan2", NULL
),
101 LED_INV(ADM5120_GPIO_P2L2
, "usb3", NULL
),
102 LED_INV(ADM5120_GPIO_P3L0
, "lan3", NULL
),
103 LED_INV(ADM5120_GPIO_P3L2
, "usb4", NULL
),
104 LED_INV(ADM5120_GPIO_P4L0
, "wan", NULL
),
108 LED_INV(ADM5120_GPIO_PIN2
, "diag", NULL
),
109 LED_INV(ADM5120_GPIO_PIN6
, "wlan", NULL
),
110 LED_INV(ADM5120_GPIO_PIN7
, "wan", NULL
),
111 LED_INV(ADM5120_GPIO_P0L0
, "lan1", NULL
),
112 LED_INV(ADM5120_GPIO_P1L0
, "lan2", NULL
),
119 LED_STD(ADM5120_GPIO_PIN0
, "power", NULL
),
120 LED_INV(ADM5120_GPIO_P0L1
, "wan_speed", NULL
),
121 LED_INV(ADM5120_GPIO_P0L0
, "wan_lnkact", NULL
),
122 LED_INV(ADM5120_GPIO_P1L1
, "lan1_speed", NULL
),
123 LED_INV(ADM5120_GPIO_P1L0
, "lan1_lnkact", NULL
),
124 LED_INV(ADM5120_GPIO_P2L1
, "lan2_speed", NULL
),
125 LED_INV(ADM5120_GPIO_P2L0
, "lan2_lnkact", NULL
),
126 LED_INV(ADM5120_GPIO_P3L1
, "lan3_speed", NULL
),
127 LED_INV(ADM5120_GPIO_P3L0
, "lan3_lnkact", NULL
),
128 LED_INV(ADM5120_GPIO_P4L1
, "lan4_speed", NULL
),
129 LED_INV(ADM5120_GPIO_P4L0
, "lan4_lnkact", NULL
),
132 LED_ARRAY(br61x4wg
) {
133 LED_STD(ADM5120_GPIO_PIN0
, "power", NULL
),
134 LED_STD(ADM5120_GPIO_PIN5
, "wlan", NULL
),
135 LED_INV(ADM5120_GPIO_P0L1
, "wan_speed", NULL
),
136 LED_INV(ADM5120_GPIO_P0L0
, "wan_lnkact", NULL
),
137 LED_INV(ADM5120_GPIO_P1L1
, "lan1_speed", NULL
),
138 LED_INV(ADM5120_GPIO_P1L0
, "lan1_lnkact", NULL
),
139 LED_INV(ADM5120_GPIO_P2L1
, "lan2_speed", NULL
),
140 LED_INV(ADM5120_GPIO_P2L0
, "lan2_lnkact", NULL
),
141 LED_INV(ADM5120_GPIO_P3L1
, "lan3_speed", NULL
),
142 LED_INV(ADM5120_GPIO_P3L0
, "lan3_lnkact", NULL
),
143 LED_INV(ADM5120_GPIO_P4L1
, "lan4_speed", NULL
),
144 LED_INV(ADM5120_GPIO_P4L0
, "lan4_lnkact", NULL
),
150 #if defined(CONFIG_LEDS_ADM5120_EXPERIMENTAL)
151 LED_ARRAY(rb100
) { /* FIXME: untested */
152 LED_STD(ADM5120_GPIO_PIN6
, "power", NULL
),
153 LED_STD(ADM5120_GPIO_PIN3
, "user", NULL
),
158 LED_STD(ADM5120_GPIO_PIN6
, "power", NULL
),
159 LED_STD(ADM5120_GPIO_PIN5
, "user", NULL
),
165 #if defined(CONFIG_LEDS_ADM5120_EXPERIMENTAL)
166 LED_ARRAY(p334
) { /* FIXME: untested */
167 LED_INV(ADM5120_GPIO_xxxx
, "power", NULL
),
168 LED_INV(ADM5120_GPIO_xxxx
, "lan1", NULL
),
169 LED_INV(ADM5120_GPIO_xxxx
, "lan2", NULL
),
170 LED_INV(ADM5120_GPIO_xxxx
, "lan3", NULL
),
171 LED_INV(ADM5120_GPIO_xxxx
, "lan4", NULL
),
172 LED_INV(ADM5120_GPIO_xxxx
, "wan", NULL
),
177 LED_INV(ADM5120_GPIO_PIN2
, "power", NULL
),
178 LED_INV(ADM5120_GPIO_P3L0
, "lan1", NULL
),
179 LED_INV(ADM5120_GPIO_P2L0
, "lan2", NULL
),
180 LED_INV(ADM5120_GPIO_P1L0
, "lan3", NULL
),
181 LED_INV(ADM5120_GPIO_P0L0
, "lan4", NULL
),
182 LED_INV(ADM5120_GPIO_P4L0
, "wan", NULL
),
183 LED_INV(ADM5120_GPIO_P4L2
, "wlan", NULL
),
184 LED_INV(ADM5120_GPIO_P2L2
, "otist", NULL
),
185 LED_INV(ADM5120_GPIO_P1L2
, "hidden", NULL
),
188 #if defined(CONFIG_LEDS_ADM5120_EXPERIMENTAL)
189 LED_ARRAY(p335
) { /* FIXME: untested */
190 LED_INV(ADM5120_GPIO_PIN2
, "power", NULL
),
191 LED_INV(ADM5120_GPIO_P3L0
, "lan1", NULL
),
192 LED_INV(ADM5120_GPIO_P2L0
, "lan2", NULL
),
193 LED_INV(ADM5120_GPIO_P1L0
, "lan3", NULL
),
194 LED_INV(ADM5120_GPIO_P0L0
, "lan4", NULL
),
195 LED_INV(ADM5120_GPIO_P4L0
, "wan", NULL
),
196 LED_INV(ADM5120_GPIO_P4L2
, "wlan", NULL
),
197 LED_INV(ADM5120_GPIO_P2L2
, "otist", NULL
),
198 LED_INV(ADM5120_GPIO_xxxx
, "usb", NULL
),
206 #if defined(CONFIG_LEDS_ADM5120_DIAG)
207 LED_STD(ADM5120_GPIO_PIN0
, "gpio0", NULL
),
208 LED_STD(ADM5120_GPIO_PIN1
, "gpio1", NULL
),
209 LED_STD(ADM5120_GPIO_PIN2
, "gpio2", NULL
),
210 LED_STD(ADM5120_GPIO_PIN3
, "gpio3", NULL
),
211 LED_STD(ADM5120_GPIO_PIN4
, "gpio4", NULL
),
212 LED_STD(ADM5120_GPIO_PIN5
, "gpio5", NULL
),
213 LED_STD(ADM5120_GPIO_PIN6
, "gpio6", NULL
),
214 LED_STD(ADM5120_GPIO_PIN7
, "gpio7", NULL
),
215 LED_STD(ADM5120_GPIO_P0L0
, "port0led0", NULL
),
216 LED_STD(ADM5120_GPIO_P0L1
, "port0led1", NULL
),
217 LED_STD(ADM5120_GPIO_P0L2
, "port0led2", NULL
),
218 LED_STD(ADM5120_GPIO_P1L0
, "port1led0", NULL
),
219 LED_STD(ADM5120_GPIO_P1L1
, "port1led1", NULL
),
220 LED_STD(ADM5120_GPIO_P1L2
, "port1led2", NULL
),
221 LED_STD(ADM5120_GPIO_P2L0
, "port2led0", NULL
),
222 LED_STD(ADM5120_GPIO_P2L1
, "port2led1", NULL
),
223 LED_STD(ADM5120_GPIO_P2L2
, "port2led2", NULL
),
224 LED_STD(ADM5120_GPIO_P3L0
, "port3led0", NULL
),
225 LED_STD(ADM5120_GPIO_P3L1
, "port3led1", NULL
),
226 LED_STD(ADM5120_GPIO_P3L2
, "port3led2", NULL
),
227 LED_STD(ADM5120_GPIO_P4L0
, "port4led0", NULL
),
228 LED_STD(ADM5120_GPIO_P4L1
, "port4led1", NULL
),
229 LED_STD(ADM5120_GPIO_P4L2
, "port4led2", NULL
),
233 #define MACH_DATA(m, n) { \
235 .nr_leds = ARRAY_SIZE(n ## _leds), \
239 static struct mach_data machines
[] __initdata
= {
240 MACH_DATA(MACH_ADM5120_GENERIC
, generic
),
242 MACH_DATA(MACH_ADM5120_NP28G
, np28g
),
243 MACH_DATA(MACH_ADM5120_NP28GHS
, np28g
),
244 MACH_DATA(MACH_ADM5120_WP54AG
, wp54g
),
245 MACH_DATA(MACH_ADM5120_WP54G
, wp54g
),
246 MACH_DATA(MACH_ADM5120_WP54G_WRT
, wp54g
),
247 MACH_DATA(MACH_ADM5120_WPP54AG
, wp54g
),
248 MACH_DATA(MACH_ADM5120_WPP54G
, wp54g
),
250 MACH_DATA(MACH_ADM5120_BR6104K
, br6104k
),
251 MACH_DATA(MACH_ADM5120_BR61x4WG
, br61x4wg
),
253 MACH_DATA(MACH_ADM5120_RB_133
, rb133
),
254 MACH_DATA(MACH_ADM5120_RB_133C
, rb133
),
256 MACH_DATA(MACH_ADM5120_P334WT
, p334wt
),
257 #if defined(CONFIG_LEDS_ADM5120_EXPERIMENTAL)
259 MACH_DATA(MACH_ADM5120_P334
, p334
),
260 MACH_DATA(MACH_ADM5120_P335
, p335
),
261 MACH_DATA(MACH_ADM5120_RB_111
, rb100
),
262 MACH_DATA(MACH_ADM5120_RB_112
, rb100
),
263 MACH_DATA(MACH_ADM5120_NP27G
, np27g
),
267 static struct adm5120_leddev
* __init
268 create_leddev(int id
, struct gpio_led
*led
)
270 struct adm5120_leddev
*p
;
272 p
= kzalloc(sizeof(*p
), GFP_KERNEL
);
276 memcpy(&p
->led
, led
, sizeof(p
->led
));
277 p
->pdev
.name
= "leds-gpio";
279 p
->pdev
.dev
.platform_data
= &p
->pdata
;
280 p
->pdata
.num_leds
= 1;
281 p
->pdata
.leds
= &p
->led
;
286 static struct mach_data
* __init
287 adm5120_leds_findmach(unsigned long machtype
)
289 struct mach_data
*mach
;
293 for (i
= 0; i
< ARRAY_SIZE(machines
); i
++) {
294 if (machines
[i
].machtype
== machtype
) {
300 #if defined(CONFIG_LEDS_ADM5120_DIAG)
309 adm5120_leds_init(void)
311 struct mach_data
*mach
;
314 if (mips_machgroup
!= MACH_GROUP_ADM5120
) {
319 mach
= adm5120_leds_findmach(mips_machtype
);
321 printk(KERN_ERR
"leds-adm5120: unsupported board\n");
326 for (i
= 0; i
< mach
->nr_leds
; i
++) {
327 led_devs
[i
] = create_leddev(i
, &mach
->leds
[i
]);
328 if (led_devs
[i
] == NULL
) {
334 for (i
= 0; i
< mach
->nr_leds
; i
++) {
335 ret
= platform_device_register(&led_devs
[i
]->pdev
);
340 led_count
= mach
->nr_leds
;
344 for (i
--; i
>= 0; i
--)
345 platform_device_unregister(&led_devs
[i
]->pdev
);
348 for (i
= 0; i
< led_count
; i
++)
355 adm5120_leds_exit(void)
359 for (i
= 0; i
< led_count
; i
++) {
360 platform_device_unregister(&led_devs
[i
]->pdev
);
365 module_init(adm5120_leds_init
);
366 module_exit(adm5120_leds_exit
);
368 MODULE_AUTHOR("Gabor Juhos <juhosg at openwrt.org>");
369 MODULE_DESCRIPTION(DRV_DESC
);
370 MODULE_LICENSE("GPL");