broadcom-diag: support for the WNDR3700v3
[openwrt/openwrt.git] / package / broadcom-diag / src / diag.c
1 /*
2 * diag.c - GPIO interface driver for Broadcom boards
3 *
4 * Copyright (C) 2006 Mike Baker <mbm@openwrt.org>,
5 * Copyright (C) 2006-2007 Felix Fietkau <nbd@openwrt.org>
6 * Copyright (C) 2008 Andy Boyett <agb@openwrt.org>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 *
22 */
23 #include <linux/module.h>
24 #include <linux/pci.h>
25 #include <linux/kmod.h>
26 #include <linux/proc_fs.h>
27 #include <linux/timer.h>
28 #include <linux/version.h>
29 #include <asm/uaccess.h>
30 #include <linux/workqueue.h>
31 #include <linux/skbuff.h>
32 #include <linux/netlink.h>
33 #include <linux/kobject.h>
34 #include <net/sock.h>
35 #include <bcm47xx_board.h>
36 extern u64 uevent_next_seqnum(void);
37
38 #include "gpio.h"
39 #include "diag.h"
40 #define getvar(str) (nvram_get(str)?:"")
41
42 static inline int startswith (char *source, char *cmp) { return !strncmp(source,cmp,strlen(cmp)); }
43 static int fill_event(struct event_t *);
44 static unsigned int gpiomask = 0;
45 module_param(gpiomask, int, 0644);
46
47 enum {
48 /* Linksys */
49 WAP54GV1,
50 WAP54GV2,
51 WAP54GV3,
52 WRT54GV1,
53 WRT54G,
54 WRTSL54GS,
55 WRT54G3G,
56 WRT54G3GV2_VF,
57 WRT150NV1,
58 WRT150NV11,
59 WRT160NV1,
60 WRT160NV3,
61 WRT300NV11,
62 WRT350N,
63 WRT600N,
64 WRT600NV11,
65 WRT610N,
66 WRT610NV2,
67 E1000V1,
68 E3000V1,
69 E3200V1,
70
71 /* ASUS */
72 WLHDD,
73 WL300G,
74 WL320GE,
75 WL330GE,
76 WL500G,
77 WL500GD,
78 WL500GP,
79 WL500GPV2,
80 WL500W,
81 WL520GC,
82 WL520GU,
83 ASUS_4702,
84 WL700GE,
85 RTN16,
86
87 /* Buffalo */
88 WBR2_G54,
89 WHR_G54S,
90 WHR_HP_G54,
91 WHR_G125,
92 WHR2_A54G54,
93 WLA2_G54L,
94 WZR_G300N,
95 WZR_RS_G54,
96 WZR_RS_G54HP,
97 BUFFALO_UNKNOWN,
98 BUFFALO_UNKNOWN_4710,
99
100 /* Siemens */
101 SE505V1,
102 SE505V2,
103
104 /* US Robotics */
105 USR5461,
106
107 /* Dell */
108 TM2300,
109 TM2300V2,
110
111 /* Motorola */
112 WE800G,
113 WR850GV1,
114 WR850GV2V3,
115 WR850GP,
116
117 /* Belkin */
118 BELKIN_UNKNOWN,
119 BELKIN_F7D4301,
120
121 /* Netgear */
122 WGT634U,
123 WNR834BV1,
124 WNR834BV2,
125 WNDR3400V1,
126 WNDR3700V3,
127
128 /* Trendware */
129 TEW411BRPP,
130
131 /* SimpleTech */
132 STI_NAS,
133
134 /* D-Link */
135 DIR130,
136 DIR320,
137 DIR330,
138 DWL3150,
139
140 /* Sitecom */
141 WL105B,
142
143 /* Western Digital */
144 WDNetCenter,
145
146 /* Askey */
147 RT210W,
148
149 /* OvisLink */
150 WL1600GL,
151
152 /* Microsoft */
153 MN700,
154
155 /* Edimax */
156 PS1208MFG,
157 };
158
159 static void __init bcm4780_init(void) {
160 int pin = 1 << 3;
161
162 /* Enables GPIO 3 that controls HDD and led power on ASUS WL-700gE */
163 printk(MODULE_NAME ": Spinning up HDD and enabling leds\n");
164 bcm47xx_gpio_outen(pin, pin);
165 bcm47xx_gpio_control(pin, 0);
166 bcm47xx_gpio_out(pin, pin);
167
168 /* Wait 5s, so the HDD can spin up */
169 set_current_state(TASK_INTERRUPTIBLE);
170 schedule_timeout(HZ * 5);
171 }
172
173 static void __init NetCenter_init(void) {
174 /* unset pin 6 (+12V) */
175 int pin = 1 << 6;
176 bcm47xx_gpio_outen(pin, pin);
177 bcm47xx_gpio_control(pin, 0);
178 bcm47xx_gpio_out(pin, pin);
179 /* unset pin 1 (turn off red led, blue will light alone if +5V comes up) */
180 pin = 1 << 1;
181 bcm47xx_gpio_outen(pin, pin);
182 bcm47xx_gpio_control(pin, 0);
183 bcm47xx_gpio_out(pin, pin);
184 /* unset pin 3 (+5V) and wait 5 seconds (harddisk spin up) */
185 bcm4780_init();
186 }
187
188 static void __init bcm57xx_init(void) {
189 int pin = 1 << 2;
190
191 /* FIXME: switch comes up, but port mappings/vlans not right */
192 bcm47xx_gpio_outen(pin, pin);
193 bcm47xx_gpio_control(pin, 0);
194 bcm47xx_gpio_out(pin, pin);
195 }
196
197 static struct platform_t __initdata platforms[] = {
198 /* Linksys */
199 [WAP54GV1] = {
200 .name = "Linksys WAP54G V1",
201 .buttons = {
202 { .name = "reset", .gpio = 1 << 0 },
203 },
204 .leds = {
205 { .name = "diag", .gpio = 1 << 3 },
206 { .name = "wlan", .gpio = 1 << 4 },
207 },
208 },
209 [WAP54GV2] = {
210 .name = "Linksys WAP54G V2",
211 .buttons = {
212 { .name = "reset", .gpio = 1 << 0 },
213 },
214 .leds = {
215 { .name = "wlan", .gpio = 1 << 5, .polarity = REVERSE },
216 /* GPIO 6 is b44 (eth0, LAN) PHY power */
217 },
218 },
219 [WAP54GV3] = {
220 .name = "Linksys WAP54G V3",
221 .buttons = {
222 /* FIXME: verify this */
223 { .name = "reset", .gpio = 1 << 7 },
224 { .name = "ses", .gpio = 1 << 0 },
225 },
226 .leds = {
227 /* FIXME: diag? */
228 { .name = "ses", .gpio = 1 << 1 },
229 },
230 },
231 [WRT54GV1] = {
232 .name = "Linksys WRT54G V1.x",
233 .buttons = {
234 { .name = "reset", .gpio = 1 << 6 },
235 },
236 .leds = {
237 { .name = "diag", .gpio = 0x13 | GPIO_TYPE_EXTIF, .polarity = NORMAL },
238 { .name = "dmz", .gpio = 0x12 | GPIO_TYPE_EXTIF, .polarity = NORMAL },
239 },
240 },
241 [WRT54G] = {
242 .name = "Linksys WRT54G/GS/GL",
243 .buttons = {
244 { .name = "reset", .gpio = 1 << 6 },
245 { .name = "ses", .gpio = 1 << 4 },
246 },
247 .leds = {
248 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
249 { .name = "dmz", .gpio = 1 << 7, .polarity = REVERSE },
250 { .name = "ses_white", .gpio = 1 << 2, .polarity = REVERSE },
251 { .name = "ses_orange", .gpio = 1 << 3, .polarity = REVERSE },
252 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
253 },
254 },
255 [WRTSL54GS] = {
256 .name = "Linksys WRTSL54GS",
257 .buttons = {
258 { .name = "reset", .gpio = 1 << 6 },
259 { .name = "ses", .gpio = 1 << 4 },
260 },
261 .leds = {
262 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
263 { .name = "dmz", .gpio = 1 << 0, .polarity = REVERSE },
264 { .name = "ses_white", .gpio = 1 << 5, .polarity = REVERSE },
265 { .name = "ses_orange", .gpio = 1 << 7, .polarity = REVERSE },
266 },
267 },
268 [WRT54G3G] = {
269 .name = "Linksys WRT54G3G",
270 .buttons = {
271 { .name = "reset", .gpio = 1 << 6 },
272 { .name = "3g", .gpio = 1 << 4 },
273 },
274 .leds = {
275 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
276 { .name = "dmz", .gpio = 1 << 7, .polarity = REVERSE },
277 { .name = "3g_green", .gpio = 1 << 2, .polarity = NORMAL },
278 { .name = "3g_blue", .gpio = 1 << 3, .polarity = NORMAL },
279 { .name = "3g_blink", .gpio = 1 << 5, .polarity = NORMAL },
280 },
281 },
282 [WRT54G3GV2_VF] = {
283 .name = "Linksys WRT54G3GV2-VF",
284 .buttons = {
285 { .name = "reset", .gpio = 1 << 6 },
286 { .name = "3g", .gpio = 1 << 5 },
287 },
288 .leds = {
289 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
290 { .name = "3g_green", .gpio = 1 << 2, .polarity = NORMAL },
291 { .name = "3g_blue", .gpio = 1 << 3, .polarity = NORMAL },
292 },
293 },
294 [WRT150NV1] = {
295 .name = "Linksys WRT150N V1",
296 .buttons = {
297 { .name = "reset", .gpio = 1 << 6 },
298 { .name = "ses", .gpio = 1 << 4 },
299 },
300 .leds = {
301 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
302 { .name = "ses_green", .gpio = 1 << 5, .polarity = REVERSE },
303 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE },
304 },
305 },
306 [WRT150NV11] = {
307 .name = "Linksys WRT150N V1.1",
308 .buttons = {
309 { .name = "reset", .gpio = 1 << 6 },
310 { .name = "ses", .gpio = 1 << 4 },
311 },
312 .leds = {
313 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
314 { .name = "ses_green", .gpio = 1 << 5, .polarity = REVERSE },
315 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE },
316 },
317 },
318 [WRT160NV1] = {
319 .name = "Linksys WRT160N v1.x",
320 .buttons = {
321 { .name = "reset", .gpio = 1 << 6 },
322 { .name = "ses", .gpio = 1 << 4 },
323 },
324 .leds = {
325 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
326 { .name = "ses_blue", .gpio = 1 << 5, .polarity = REVERSE },
327 { .name = "ses_orange", .gpio = 1 << 3, .polarity = REVERSE },
328 },
329 },
330 [WRT160NV3] = {
331 .name = "Linksys WRT160N V3",
332 .buttons = {
333 { .name = "reset", .gpio = 1 << 6 },
334 { .name = "ses", .gpio = 1 << 5 },
335 },
336 .leds = {
337 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
338 { .name = "ses_blue", .gpio = 1 << 4, .polarity = REVERSE },
339 { .name = "ses_orange", .gpio = 1 << 2, .polarity = REVERSE },
340 },
341 },
342 [WRT300NV11] = {
343 .name = "Linksys WRT300N V1.1",
344 .buttons = {
345 { .name = "reset", .gpio = 1 << 6 }, // "Reset" on back panel
346 { .name = "ses", .gpio = 1 << 4 }, // "Reserved" on top panel
347 },
348 .leds = {
349 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL }, // "Power"
350 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE }, // "Security" Amber
351 { .name = "ses_green", .gpio = 1 << 5, .polarity = REVERSE }, // "Security" Green
352 },
353 .platform_init = bcm57xx_init,
354 },
355 [WRT350N] = {
356 .name = "Linksys WRT350N",
357 .buttons = {
358 { .name = "reset", .gpio = 1 << 6 },
359 { .name = "ses", .gpio = 1 << 8 },
360 },
361 .leds = {
362 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
363 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE },
364 { .name = "ses_green", .gpio = 1 << 9, .polarity = REVERSE },
365 { .name = "usb_blink", .gpio = 1 << 10, .polarity = REVERSE },
366 { .name = "usb", .gpio = 1 << 11, .polarity = REVERSE },
367 },
368 .platform_init = bcm57xx_init,
369 },
370 [WRT600N] = {
371 .name = "Linksys WRT600N",
372 .buttons = {
373 { .name = "reset", .gpio = 1 << 6 },
374 { .name = "ses", .gpio = 1 << 7 },
375 },
376 .leds = {
377 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE }, // Power LED
378 { .name = "usb", .gpio = 1 << 3, .polarity = REVERSE }, // USB LED
379 { .name = "wl0_ses_amber", .gpio = 1 << 8, .polarity = REVERSE }, // 2.4Ghz LED Amber
380 { .name = "wl0_ses_green", .gpio = 1 << 9, .polarity = REVERSE }, // 2.4Ghz LED Green
381 { .name = "wl1_ses_amber", .gpio = 1 << 10, .polarity = REVERSE }, // 5.6Ghz LED Amber
382 { .name = "wl1_ses_green", .gpio = 1 << 11, .polarity = REVERSE }, // 5.6Ghz LED Green
383 },
384 .platform_init = bcm57xx_init,
385 },
386 [WRT600NV11] = {
387 .name = "Linksys WRT600N V1.1",
388 .buttons = {
389 { .name = "reset", .gpio = 1 << 6 },
390 { .name = "ses", .gpio = 1 << 7 },
391 },
392 .leds = {
393 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE }, // Power LED
394 { .name = "usb", .gpio = 1 << 3, .polarity = REVERSE }, // USB LED
395 { .name = "wl0_ses_amber", .gpio = 1 << 8, .polarity = REVERSE }, // 2.4Ghz LED Amber
396 { .name = "wl0_ses_green", .gpio = 1 << 9, .polarity = REVERSE }, // 2.4Ghz LED Green
397 { .name = "wl1_ses_amber", .gpio = 1 << 10, .polarity = REVERSE }, // 5.6Ghz LED Amber
398 { .name = "wl1_ses_green", .gpio = 1 << 11, .polarity = REVERSE }, // 5.6Ghz LED Green
399 },
400 .platform_init = bcm57xx_init,
401 },
402 [WRT610N] = {
403 .name = "Linksys WRT610N",
404 .buttons = {
405 { .name = "reset", .gpio = 1 << 6 },
406 { .name = "ses", .gpio = 1 << 8 },
407 },
408 .leds = {
409 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL }, // Power LED
410 { .name = "usb", .gpio = 1 << 0, .polarity = REVERSE }, // USB LED
411 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE }, // WiFi protected setup LED amber
412 { .name = "ses_blue", .gpio = 1 << 9, .polarity = REVERSE }, // WiFi protected setup LED blue
413 },
414 },
415 [WRT610NV2] = {
416 .name = "Linksys WRT610N V2",
417 .buttons = {
418 { .name = "reset", .gpio = 1 << 6 },
419 { .name = "ses", .gpio = 1 << 4 },
420 },
421 .leds = {
422 { .name = "power", .gpio = 1 << 5, .polarity = NORMAL }, // Power LED
423 { .name = "usb", .gpio = 1 << 7, .polarity = NORMAL }, // USB LED
424 { .name = "ses_amber", .gpio = 1 << 0, .polarity = REVERSE }, // WiFi protected setup LED amber
425 { .name = "ses_blue", .gpio = 1 << 3, .polarity = REVERSE }, // WiFi protected setup LED blue
426 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL }, // Wireless LED
427 },
428 },
429 /* same hardware as WRT160NV3 and Cisco Valet M10V1, but different board detection, combine? */
430 [E1000V1] = {
431 .name = "Linksys E1000 V1",
432 .buttons = {
433 { .name = "reset", .gpio = 1 << 6 },
434 { .name = "wps", .gpio = 1 << 5 }, /* nvram get gpio5=wps_button */
435 },
436 .leds = {
437 /** turns on leds for all ethernet ports (wan too)
438 * this also disconnects some, or maybe all, ethernet ports
439 * 1: leds work normally
440 * 0: all lit all the time */
441 /* nvram get gpio3=robo_reset */
442 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
443 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
444 { .name = "ses_blue", .gpio = 1 << 4, .polarity = REVERSE }, /* nvram get gpio4=wps_led */
445 { .name = "ses_orange", .gpio = 1 << 2, .polarity = REVERSE }, /* nvram get gpio2=wps_status_led */
446 },
447 },
448 [E3000V1] = {
449 .name = "Linksys E3000 V1",
450 .buttons = {
451 { .name = "reset", .gpio = 1 << 6 },
452 { .name = "ses", .gpio = 1 << 4 },
453 },
454 .leds = {
455 { .name = "power", .gpio = 1 << 5, .polarity = NORMAL }, // Power LED
456 { .name = "usb", .gpio = 1 << 7, .polarity = NORMAL }, // USB LED
457 { .name = "ses_amber", .gpio = 1 << 0, .polarity = REVERSE }, // WiFi protected setup LED amber
458 { .name = "ses_blue", .gpio = 1 << 3, .polarity = REVERSE }, // WiFi protected setup LED blue
459 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL }, // Wireless LED
460 },
461 },
462 [E3200V1] = {
463 .name = "Linksys E3200 V1",
464 .buttons = {
465 /* { .name = "switch", .gpio = 1 << 4 },*/ /* nvram get gpio4=robo_reset */
466 { .name = "reset", .gpio = 1 << 5 }, /* nvram get reset_gpio=5 */
467 { .name = "wps", .gpio = 1 << 8 }, /* nvram get gpio8=wps_button */
468 /* { .name = "wombo", .gpio = 1 << 23 },*/ /* nvram get gpio23=wombo_reset - wireless on motherboard */
469 },
470 .leds = {
471 { .name = "power", .gpio = 1 << 3, .polarity = REVERSE }, /* Power LED */
472 },
473 },
474 /* Asus */
475 [WLHDD] = {
476 .name = "ASUS WL-HDD",
477 .buttons = {
478 { .name = "reset", .gpio = 1 << 6 },
479 },
480 .leds = {
481 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
482 { .name = "usb", .gpio = 1 << 2, .polarity = REVERSE },
483 },
484 },
485 [WL300G] = {
486 .name = "ASUS WL-300g",
487 .buttons = {
488 { .name = "reset", .gpio = 1 << 6 },
489 },
490 .leds = {
491 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
492 },
493 },
494 [WL320GE] = {
495 .name = "ASUS WL-320gE/WL-320gP",
496 .buttons = {
497 { .name = "reset", .gpio = 1 << 6 },
498 },
499 .leds = {
500 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
501 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE },
502 { .name = "link", .gpio = 1 << 11, .polarity = REVERSE },
503 },
504 },
505 [WL330GE] = {
506 .name = "ASUS WL-330gE",
507 .buttons = {
508 { .name = "reset", .gpio = 1 << 2 },
509 },
510 .leds = {
511 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
512 },
513 },
514 [WL500G] = {
515 .name = "ASUS WL-500g",
516 .buttons = {
517 { .name = "reset", .gpio = 1 << 6 },
518 },
519 .leds = {
520 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
521 },
522 },
523 [WL500GD] = {
524 .name = "ASUS WL-500g Deluxe",
525 .buttons = {
526 { .name = "reset", .gpio = 1 << 6 },
527 },
528 .leds = {
529 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
530 },
531 },
532 [WL500GP] = {
533 .name = "ASUS WL-500g Premium",
534 .buttons = {
535 { .name = "reset", .gpio = 1 << 0 },
536 { .name = "ses", .gpio = 1 << 4 },
537 },
538 .leds = {
539 { .name = "power", .gpio = 1 << 1, .polarity = REVERSE },
540 },
541 },
542 [WL500GPV2] = {
543 .name = "ASUS WL-500g Premium V2",
544 .buttons = {
545 { .name = "reset", .gpio = 1 << 2 },
546 { .name = "ses", .gpio = 1 << 3 },
547 },
548 .leds = {
549 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
550 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
551 },
552 },
553 [WL500W] = {
554 .name = "ASUS WL-500W",
555 .buttons = {
556 { .name = "reset", .gpio = 1 << 6 },
557 { .name = "ses", .gpio = 1 << 7 },
558 },
559 .leds = {
560 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
561 },
562 },
563 [WL520GC] = {
564 .name = "ASUS WL-520GC",
565 .buttons = {
566 { .name = "reset", .gpio = 1 << 2 },
567 { .name = "ses", .gpio = 1 << 3 },
568 },
569 .leds = {
570 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
571 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
572 },
573 },
574 [WL520GU] = {
575 .name = "ASUS WL-520gU",
576 .buttons = {
577 { .name = "reset", .gpio = 1 << 2 },
578 { .name = "ses", .gpio = 1 << 3 },
579 },
580 .leds = {
581 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
582 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
583 },
584 },
585 [ASUS_4702] = {
586 .name = "ASUS (unknown, BCM4702)",
587 .buttons = {
588 { .name = "reset", .gpio = 1 << 6 },
589 },
590 .leds = {
591 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
592 },
593 },
594 [WL700GE] = {
595 .name = "ASUS WL-700gE",
596 .buttons = {
597 { .name = "reset", .gpio = 1 << 7 }, // on back, hardwired, always resets device regardless OS state
598 { .name = "ses", .gpio = 1 << 4 }, // on back, actual name ezsetup
599 { .name = "power", .gpio = 1 << 0 }, // on front
600 { .name = "copy", .gpio = 1 << 6 }, // on front
601 },
602 .leds = {
603 #if 0
604 // GPIO that controls power led also enables/disables some essential functions
605 // - power to HDD
606 // - switch leds
607 { .name = "power", .gpio = 1 << 3, .polarity = NORMAL }, // actual name power
608 #endif
609 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE }, // actual name ready
610 },
611 .platform_init = bcm4780_init,
612 },
613 [RTN16] = {
614 .name = "ASUS RT-N16",
615 .buttons = {
616 { .name = "reset", .gpio = 1 << 8 },
617 { .name = "ses", .gpio = 1 << 5 },
618 },
619 .leds = {
620 { .name = "power", .gpio = 1 << 1, .polarity = REVERSE },
621 { .name = "wlan", .gpio = 1 << 7, .polarity = NORMAL },
622 },
623 },
624 /* Buffalo */
625 [WHR_G54S] = {
626 .name = "Buffalo WHR-G54S",
627 .buttons = {
628 { .name = "reset", .gpio = 1 << 4 },
629 { .name = "bridge", .gpio = 1 << 5 },
630 { .name = "ses", .gpio = 1 << 0 },
631 },
632 .leds = {
633 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
634 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
635 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
636 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
637 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
638 },
639 },
640 [WBR2_G54] = {
641 .name = "Buffalo WBR2-G54",
642 /* FIXME: verify */
643 .buttons = {
644 { .name = "reset", .gpio = 1 << 7 },
645 },
646 .leds = {
647 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
648 },
649 },
650 [WHR_HP_G54] = {
651 .name = "Buffalo WHR-HP-G54",
652 .buttons = {
653 { .name = "reset", .gpio = 1 << 4 },
654 { .name = "bridge", .gpio = 1 << 5 },
655 { .name = "ses", .gpio = 1 << 0 },
656 },
657 .leds = {
658 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
659 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
660 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
661 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
662 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
663 },
664 },
665 [WHR_G125] = {
666 .name = "Buffalo WHR-G125",
667 .buttons = {
668 { .name = "reset", .gpio = 1 << 4 },
669 { .name = "bridge", .gpio = 1 << 5 },
670 { .name = "ses", .gpio = 1 << 0 },
671 },
672 .leds = {
673 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
674 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
675 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
676 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
677 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
678 },
679 },
680 [WHR2_A54G54] = {
681 .name = "Buffalo WHR2-A54G54",
682 .buttons = {
683 { .name = "reset", .gpio = 1 << 4 },
684 },
685 .leds = {
686 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
687 },
688 },
689 [WLA2_G54L] = {
690 .name = "Buffalo WLA2-G54L",
691 /* FIXME: verify */
692 .buttons = {
693 { .name = "reset", .gpio = 1 << 7 },
694 },
695 .leds = {
696 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
697 },
698 },
699 [WZR_G300N] = {
700 .name = "Buffalo WZR-G300N",
701 .buttons = {
702 { .name = "reset", .gpio = 1 << 4 },
703 },
704 .leds = {
705 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
706 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
707 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
708 },
709 },
710 [WZR_RS_G54] = {
711 .name = "Buffalo WZR-RS-G54",
712 .buttons = {
713 { .name = "ses", .gpio = 1 << 0 },
714 { .name = "reset", .gpio = 1 << 4 },
715 },
716 .leds = {
717 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
718 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
719 { .name = "vpn", .gpio = 1 << 1, .polarity = REVERSE },
720 },
721 },
722 [WZR_RS_G54HP] = {
723 .name = "Buffalo WZR-RS-G54HP",
724 .buttons = {
725 { .name = "ses", .gpio = 1 << 0 },
726 { .name = "reset", .gpio = 1 << 4 },
727 },
728 .leds = {
729 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
730 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
731 { .name = "vpn", .gpio = 1 << 1, .polarity = REVERSE },
732 },
733 },
734 [BUFFALO_UNKNOWN] = {
735 .name = "Buffalo (unknown)",
736 .buttons = {
737 { .name = "reset", .gpio = 1 << 7 },
738 },
739 .leds = {
740 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
741 },
742 },
743 [BUFFALO_UNKNOWN_4710] = {
744 .name = "Buffalo (unknown, BCM4710)",
745 .buttons = {
746 { .name = "reset", .gpio = 1 << 4 },
747 },
748 .leds = {
749 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
750 },
751 },
752 /* Siemens */
753 [SE505V1] = {
754 .name = "Siemens SE505 V1",
755 .buttons = {
756 /* No usable buttons */
757 },
758 .leds = {
759 // { .name = "power", .gpio = 1 << 0 .polarity = REVERSE }, // Usable when retrofitting D26 (?)
760 { .name = "dmz", .gpio = 1 << 4, .polarity = REVERSE }, // actual name WWW
761 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
762 },
763 },
764 [SE505V2] = {
765 .name = "Siemens SE505 V2",
766 .buttons = {
767 /* No usable buttons */
768 },
769 .leds = {
770 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
771 { .name = "dmz", .gpio = 1 << 0, .polarity = REVERSE }, // actual name WWW
772 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
773 },
774 },
775 /* US Robotics */
776 [USR5461] = {
777 .name = "U.S. Robotics USR5461",
778 .buttons = {
779 /* No usable buttons */
780 },
781 .leds = {
782 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
783 { .name = "printer", .gpio = 1 << 1, .polarity = REVERSE },
784 },
785 },
786 /* Dell */
787 [TM2300] = {
788 .name = "Dell TrueMobile 2300",
789 .buttons = {
790 { .name = "reset", .gpio = 1 << 0 },
791 },
792 .leds = {
793 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
794 { .name = "power", .gpio = 1 << 7, .polarity = REVERSE },
795 },
796 },
797 [TM2300V2] = {
798 .name = "Dell TrueMobile 2300 v2",
799 .buttons = {
800 { .name = "reset", .gpio = 1 << 0 },
801 },
802 .leds = {
803 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
804 { .name = "power", .gpio = 1 << 7, .polarity = REVERSE },
805 },
806 },
807 /* Motorola */
808 [WE800G] = {
809 .name = "Motorola WE800G",
810 .buttons = {
811 { .name = "reset", .gpio = 1 << 0 },
812 },
813 .leds = {
814 { .name = "power", .gpio = 1 << 4, .polarity = NORMAL },
815 { .name = "diag", .gpio = 1 << 2, .polarity = REVERSE },
816 { .name = "wlan_amber", .gpio = 1 << 1, .polarity = NORMAL },
817 },
818 },
819 [WR850GV1] = {
820 .name = "Motorola WR850G V1",
821 .buttons = {
822 { .name = "reset", .gpio = 1 << 0 },
823 },
824 .leds = {
825 { .name = "power", .gpio = 1 << 4, .polarity = NORMAL },
826 { .name = "diag", .gpio = 1 << 3, .polarity = REVERSE },
827 { .name = "dmz", .gpio = 1 << 6, .polarity = NORMAL },
828 { .name = "wlan_red", .gpio = 1 << 5, .polarity = REVERSE },
829 { .name = "wlan_green", .gpio = 1 << 7, .polarity = REVERSE },
830 },
831 },
832 [WR850GV2V3] = {
833 .name = "Motorola WR850G V2/V3",
834 .buttons = {
835 { .name = "reset", .gpio = 1 << 5 },
836 },
837 .leds = {
838 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
839 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
840 { .name = "wan", .gpio = 1 << 6, .polarity = INPUT },
841 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
842 },
843 },
844 [WR850GP] = {
845 .name = "Motorola WR850GP",
846 .buttons = {
847 { .name = "reset", .gpio = 1 << 5 },
848 },
849 .leds = {
850 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
851 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
852 { .name = "dmz", .gpio = 1 << 6, .polarity = REVERSE },
853 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
854 },
855 },
856
857 /* Belkin */
858 [BELKIN_UNKNOWN] = {
859 .name = "Belkin (unknown)",
860 /* FIXME: verify & add detection */
861 .buttons = {
862 { .name = "reset", .gpio = 1 << 7 },
863 },
864 .leds = {
865 { .name = "power", .gpio = 1 << 5, .polarity = NORMAL },
866 { .name = "wlan", .gpio = 1 << 3, .polarity = NORMAL },
867 { .name = "connected", .gpio = 1 << 0, .polarity = NORMAL },
868 },
869 },
870 [BELKIN_F7D4301] = {
871 .name = "Belkin PlayMax F7D4301",
872 .buttons = {
873 { .name = "reset", .gpio = 1 << 6 },
874 { .name = "wps", .gpio = 1 << 8 },
875 },
876 .leds = {
877 { .name = "power", .gpio = 1 << 11, .polarity = REVERSE },
878 { .name = "wlan", .gpio = 1 << 13, .polarity = REVERSE },
879 { .name = "led0", .gpio = 1 << 14, .polarity = REVERSE },
880 { .name = "led1", .gpio = 1 << 15, .polarity = REVERSE },
881 },
882 },
883 /* Netgear */
884 [WGT634U] = {
885 .name = "Netgear WGT634U",
886 .buttons = {
887 { .name = "reset", .gpio = 1 << 2 },
888 },
889 .leds = {
890 { .name = "power", .gpio = 1 << 3, .polarity = NORMAL },
891 },
892 },
893 /* Netgear */
894 [WNR834BV1] = {
895 .name = "Netgear WNR834B V1",
896 .buttons = { /* TODO: add reset button and confirm LEDs - GPIO from dd-wrt */ },
897 .leds = {
898 { .name = "power", .gpio = 1 << 4, .polarity = REVERSE },
899 { .name = "diag", .gpio = 1 << 5, .polarity = REVERSE },
900 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
901 },
902 },
903 /* Netgear */
904 [WNR834BV2] = {
905 .name = "Netgear WNR834B V2",
906 .buttons = {
907 { .name = "reset", .gpio = 1 << 6 },
908 },
909 .leds = {
910 { .name = "power", .gpio = 1 << 2, .polarity = NORMAL },
911 { .name = "diag", .gpio = 1 << 3, .polarity = NORMAL },
912 { .name = "connected", .gpio = 1 << 7, .polarity = NORMAL },
913 },
914 },
915 [WNDR3400V1] = {
916 .name = "Netgear WNDR3400 V1",
917 .buttons = {
918 /* nvram get gpio5=robo_reset */
919 { .name = "reset", .gpio = 1 << 4 },
920 { .name = "wps", .gpio = 1 << 6 },
921 { .name = "wlan", .gpio = 1 << 8 },
922 },
923 .leds = {
924 { .name = "wlan", .gpio = 0 << 0, .polarity = NORMAL },
925 { .name = "connected", .gpio = 1 << 0, .polarity = NORMAL },
926 { .name = "power", .gpio = 1 << 3, .polarity = NORMAL },
927 { .name = "diag", .gpio = 1 << 7, .polarity = NORMAL },
928 { .name = "usb", .gpio = 1 << 2, .polarity = REVERSE },
929 },
930 },
931 [WNDR3700V3] = {
932 .name = "Netgear WNDR3700 V3",
933 .buttons = {
934 /* { .name = "usb", .gpio = 1 << 1 }, */ /* this button doesn't seem to exist. */
935 { .name = "wlan", .gpio = 1 << 2 },
936 { .name = "reset", .gpio = 1 << 3 },
937 { .name = "wps", .gpio = 1 << 4 },
938 /* { .name = "switch", .gpio = 1 << 5 },*/ /* nvram get gpio5=robo_reset */
939 },
940 .leds = {
941 { .name = "power", .gpio = (1 << 0) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
942 { .name = "diag", .gpio = (1 << 1) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
943 /* WAN LED doesn't respond to GPIO control. The switch is probably driving it.
944 * { .name = "wan", .gpio = (1 << 2) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
945 */
946 { .name = "wlan2g", .gpio = (1 << 3) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
947 { .name = "wlan5g", .gpio = (1 << 4) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
948 { .name = "usb", .gpio = (1 << 5) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
949 { .name = "wps", .gpio = (1 << 6) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
950 { .name = "wlan", .gpio = (1 << 7) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
951 },
952 },
953 /* Trendware */
954 [TEW411BRPP] = {
955 .name = "Trendware TEW411BRP+",
956 .buttons = {
957 { /* No usable buttons */ },
958 },
959 .leds = {
960 { .name = "power", .gpio = 1 << 7, .polarity = NORMAL },
961 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL },
962 { .name = "bridge", .gpio = 1 << 6, .polarity = NORMAL },
963 },
964 },
965 /* SimpleTech */
966 [STI_NAS] = {
967 .name = "SimpleTech SimpleShare NAS",
968 .buttons = {
969 { .name = "reset", .gpio = 1 << 0 }, // Power button on back, named reset to enable failsafe.
970 },
971 .leds = {
972 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE }, // actual name ready
973 },
974 .platform_init = bcm4780_init,
975 },
976 /* D-Link */
977 [DIR130] = {
978 .name = "D-Link DIR-130",
979 .buttons = {
980 { .name = "reset", .gpio = 1 << 3},
981 { .name = "reserved", .gpio = 1 << 7},
982 },
983 .leds = {
984 { .name = "diag", .gpio = 1 << 0},
985 { .name = "blue", .gpio = 1 << 6},
986 },
987 },
988 [DIR320] = {
989 .name = "D-Link DIR-320",
990 .buttons = {
991 { .name = "reserved", .gpio = 1 << 6},
992 { .name = "reset", .gpio = 1 << 7},
993 },
994 .leds = {
995 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
996 { .name = "diag", .gpio = 1 << 1, .polarity = NORMAL }, /* "status led */
997 { .name = "red", .gpio = 1 << 3, .polarity = REVERSE },
998 { .name = "blue", .gpio = 1 << 4, .polarity = REVERSE },
999 { .name = "usb", .gpio = 1 << 5, .polarity = NORMAL },
1000 },
1001 },
1002 [DIR330] = {
1003 .name = "D-Link DIR-330",
1004 .buttons = {
1005 { .name = "reset", .gpio = 1 << 3},
1006 { .name = "reserved", .gpio = 1 << 7},
1007 },
1008 .leds = {
1009 { .name = "diag", .gpio = 1 << 0},
1010 { .name = "usb", .gpio = 1 << 4},
1011 { .name = "blue", .gpio = 1 << 6},
1012 },
1013 },
1014 [DWL3150] = {
1015 .name = "D-Link DWL-3150",
1016 .buttons = {
1017 { .name = "reset", .gpio = 1 << 7},
1018 },
1019 .leds = {
1020 { .name = "diag", .gpio = 1 << 2},
1021 { .name = "status", .gpio = 1 << 1},
1022 },
1023 },
1024 /* Double check */
1025 [WL105B] = {
1026 .name = "Sitecom WL-105b",
1027 .buttons = {
1028 { .name = "reset", .gpio = 1 << 10},
1029 },
1030 .leds = {
1031 { .name = "wlan", .gpio = 1 << 4},
1032 { .name = "power", .gpio = 1 << 3},
1033 },
1034 },
1035 /* Western Digital Net Center */
1036 [WDNetCenter] = {
1037 .name = "Western Digital NetCenter",
1038 .buttons = {
1039 { .name = "power", .gpio = 1 << 0},
1040 { .name = "reset", .gpio = 1 << 7},
1041 },
1042 .platform_init = NetCenter_init,
1043 },
1044 /* Askey (and clones) */
1045 [RT210W] = {
1046 .name = "Askey RT210W",
1047 .buttons = {
1048 /* Power button is hard-wired to hardware reset */
1049 /* but is also connected to GPIO 7 (probably for bootloader recovery) */
1050 { .name = "power", .gpio = 1 << 7},
1051 },
1052 .leds = {
1053 /* These were verified and named based on Belkin F5D4230-4 v1112 */
1054 { .name = "connected", .gpio = 1 << 0, .polarity = REVERSE },
1055 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
1056 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
1057 },
1058 },
1059 [WL1600GL] = {
1060 .name = "OvisLink WL-1600GL",
1061 .buttons = {
1062 { .name = "reset", .gpio = 1 << 3 },
1063 { .name = "ses", .gpio = 1 << 4 },
1064 },
1065 .leds = {
1066 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
1067 { .name = "wps", .gpio = 1 << 2, .polarity = REVERSE },
1068 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
1069 { .name = "connected", .gpio = 1 << 0, .polarity = REVERSE },
1070 },
1071 },
1072 /* Microsoft */
1073 [MN700] = {
1074 .name = "Microsoft MN-700",
1075 .buttons = {
1076 { .name = "reset", .gpio = 1 << 7 },
1077 },
1078 .leds = {
1079 { .name = "power", .gpio = 1 << 6, .polarity = NORMAL },
1080 },
1081 },
1082 /* Edimax */
1083 [PS1208MFG] = {
1084 .name = "Edimax PS-1208MFG",
1085 .buttons = {
1086 { .name = "reset", .gpio = 1 << 4 },
1087 },
1088 .leds = {
1089 { .name = "status", .gpio = 1 << 1, .polarity = NORMAL },
1090 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
1091 },
1092 },
1093 };
1094
1095 static struct platform_t __init *platform_detect_legacy(void)
1096 {
1097 char *boardnum, *boardtype, *buf;
1098
1099 if (strcmp(getvar("nvram_type"), "cfe") == 0)
1100 return &platforms[WGT634U];
1101
1102
1103 /* no easy model number, attempt to guess */
1104 boardnum = getvar("boardnum");
1105 boardtype = getvar("boardtype");
1106
1107 if (!strcmp(boardnum, "20070615")) { /* Linksys WRT600N v1/V1.1 */
1108 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "0") && !strcmp(getvar("switch_type"),"BCM5395"))
1109 return &platforms[WRT600NV11];
1110
1111 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "0"))
1112 return &platforms[WRT600N];
1113 }
1114
1115 if (startswith(getvar("pmon_ver"), "CFE")) {
1116 /* CFE based - newer hardware */
1117 if (!strcmp(boardnum, "42")) { /* Linksys */
1118 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "1"))
1119 return &platforms[WRT350N];
1120
1121 if (!strcmp(boardtype, "0x0101") && !strcmp(getvar("boot_ver"), "v3.6"))
1122 return &platforms[WRT54G3G];
1123
1124 if (!strcmp(getvar("et1phyaddr"),"5") && !strcmp(getvar("et1mdcport"), "1"))
1125 return &platforms[WRTSL54GS];
1126
1127 /* default to WRT54G */
1128 return &platforms[WRT54G];
1129 }
1130 if (!strcmp(boardnum, "1024") && !strcmp(boardtype, "0x0446"))
1131 return &platforms[WAP54GV2];
1132
1133 if (!strcmp(boardnum, "8") && !strcmp(boardtype, "0x048e"))
1134 return &platforms[WL1600GL];
1135
1136
1137 if (!strcmp(boardnum, "44") || !strcmp(boardnum, "44\r")) {
1138 if (!strcmp(boardtype,"0x0101") || !strcmp(boardtype, "0x0101\r"))
1139 return &platforms[TM2300V2]; /* Dell TrueMobile 2300 v2 */
1140 }
1141
1142 if (!strcmp(boardnum, "45")) { /* ASUS */
1143 if (!strcmp(boardtype,"0x0472"))
1144 return &platforms[WL500W];
1145 else if (!strcmp(boardtype,"0x467"))
1146 return &platforms[WL320GE];
1147 else
1148 return &platforms[WL500GD];
1149 }
1150
1151 if (!strcmp(boardnum, "10496"))
1152 return &platforms[USR5461];
1153
1154 if (!strcmp(getvar("boardtype"), "0x0101") && !strcmp(getvar("boardrev"), "0x10")) /* SE505V2 With Modified CFE */
1155 return &platforms[SE505V2];
1156
1157 if (!strcmp(boardtype, "0x048e") && !strcmp(getvar("boardrev"),"0x35") &&
1158 !strcmp(getvar("boardflags"), "0x750")) /* D-Link DIR-320 */
1159 return &platforms[DIR320];
1160
1161 if (!strncmp(boardnum, "TH",2) && !strcmp(boardtype,"0x042f")) {
1162 return &platforms[WDNetCenter];
1163 }
1164
1165 if (!strcmp(boardtype,"0x0472") && !strcmp(getvar("cardbus"), "1")) { /* Netgear WNR834B V1 and V2*/
1166 if (!strcmp(boardnum, "08") || !strcmp(boardnum, "8"))
1167 return &platforms[WNR834BV1];
1168 if (!strcmp(boardnum, "01") || !strcmp(boardnum, "1"))
1169 return &platforms[WNR834BV2];
1170 }
1171
1172 } else { /* PMON based - old stuff */
1173 if ((simple_strtoul(getvar("GemtekPmonVer"), NULL, 0) == 9) &&
1174 (simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 30)) {
1175 return &platforms[WR850GV1];
1176 }
1177 if (startswith(boardtype, "bcm94710dev")) {
1178 if (!strcmp(boardnum, "42"))
1179 return &platforms[WRT54GV1];
1180 if (simple_strtoul(boardnum, NULL, 0) == 2)
1181 return &platforms[WAP54GV1];
1182 }
1183 /* MN-700 has also hardware_version 'WL500-...', so use boardnum */
1184 if (startswith(getvar("hardware_version"), "WL500-")) {
1185 if (!strcmp(getvar("boardnum"), "mn700"))
1186 return &platforms[MN700];
1187 else
1188 return &platforms[WL500G];
1189 }
1190 if (startswith(getvar("hardware_version"), "WL300-")) {
1191 /* Either WL-300g or WL-HDD, do more extensive checks */
1192 if ((simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 0) &&
1193 (simple_strtoul(getvar("et1phyaddr"), NULL, 0) == 1))
1194 return &platforms[WLHDD];
1195 if ((simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 0) &&
1196 (simple_strtoul(getvar("et1phyaddr"), NULL, 0) == 10))
1197 return &platforms[WL300G];
1198 }
1199 /* Sitecom WL-105b */
1200 if (startswith(boardnum, "2") && simple_strtoul(getvar("GemtekPmonVer"), NULL, 0) == 1)
1201 return &platforms[WL105B];
1202
1203 /* unknown asus stuff, probably bcm4702 */
1204 if (startswith(boardnum, "asusX"))
1205 return &platforms[ASUS_4702];
1206
1207 /* bcm4702 based Askey RT210W clones, Including:
1208 * Askey RT210W (duh?)
1209 * Siemens SE505v1
1210 * Belkin F5D7230-4 before version v1444 (MiniPCI slot, not integrated)
1211 */
1212 if (!strcmp(boardtype,"bcm94710r4")
1213 && !strcmp(boardnum ,"100")
1214 && !strcmp(getvar("pmon_ver"),"v1.03.12.bk")
1215 ){
1216 return &platforms[RT210W];
1217 }
1218 }
1219
1220 if (buf || !strcmp(boardnum, "00")) {/* probably buffalo */
1221 if (startswith(boardtype, "bcm94710ap"))
1222 return &platforms[BUFFALO_UNKNOWN_4710];
1223 else
1224 return &platforms[BUFFALO_UNKNOWN];
1225 }
1226
1227 if (startswith(getvar("CFEver"), "MotoWRv2") ||
1228 startswith(getvar("CFEver"), "MotoWRv3") ||
1229 !strcmp(getvar("MOTO_BOARD_TYPE"), "WR_FEM1")) {
1230
1231 return &platforms[WR850GV2V3];
1232 }
1233
1234 if (!strcmp(boardnum, "44") && !strcmp(getvar("boardflags"),"0x0388")) { /* Trendware TEW-411BRP+ */
1235 return &platforms[TEW411BRPP];
1236 }
1237
1238 if (startswith(boardnum, "04FN")) /* SimpleTech SimpleShare */
1239 return &platforms[STI_NAS];
1240
1241 if (!strcmp(boardnum, "10") && !strcmp(getvar("boardrev"), "0x13")) /* D-Link DWL-3150 */
1242 return &platforms[DWL3150];
1243
1244 if (!strcmp(boardnum, "01") && !strcmp(boardtype, "0x048e") && /* Edimax PS1208MFG */
1245 !strcmp(getvar("status_gpio"), "1")) /* gpio based detection */
1246 return &platforms[PS1208MFG];
1247
1248 /* not found */
1249 return NULL;
1250 }
1251
1252 static struct platform_t __init *platform_detect(void)
1253 {
1254 enum bcm47xx_board board;
1255 const char *board_name;
1256
1257
1258 board = bcm47xx_board_get();
1259 board_name = bcm47xx_board_get_name();
1260 if (board != BCM47XX_BOARD_UNKNOWN && board != BCM47XX_BOARD_NON)
1261 printk(MODULE_NAME ": kernel found a \"%s\"\n", board_name);
1262
1263 switch(board) {
1264 case BCM47XX_BOARD_ASUS_RTN16:
1265 return &platforms[RTN16];
1266 case BCM47XX_BOARD_ASUS_WL330GE:
1267 return &platforms[WL330GE];
1268 case BCM47XX_BOARD_ASUS_WL500GPV1:
1269 return &platforms[WL500GP];
1270 case BCM47XX_BOARD_ASUS_WL500GPV2:
1271 return &platforms[WL500GPV2];
1272 case BCM47XX_BOARD_ASUS_WL520GC:
1273 return &platforms[WL520GC];
1274 case BCM47XX_BOARD_ASUS_WL520GU:
1275 return &platforms[WL520GU];
1276 case BCM47XX_BOARD_ASUS_WL700GE:
1277 return &platforms[WL700GE];
1278 case BCM47XX_BOARD_BELKIN_F7D4301:
1279 return &platforms[BELKIN_F7D4301];
1280 case BCM47XX_BOARD_BUFFALO_WBR2_G54:
1281 return &platforms[WBR2_G54];
1282 case BCM47XX_BOARD_BUFFALO_WHR2_A54G54:
1283 return &platforms[WHR2_A54G54];
1284 case BCM47XX_BOARD_BUFFALO_WHR_G125:
1285 return &platforms[WHR_G125];
1286 case BCM47XX_BOARD_BUFFALO_WHR_G54S:
1287 return &platforms[WHR_G54S];
1288 case BCM47XX_BOARD_BUFFALO_WHR_HP_G54:
1289 return &platforms[WHR_HP_G54];
1290 case BCM47XX_BOARD_BUFFALO_WLA2_G54L:
1291 return &platforms[WLA2_G54L];
1292 case BCM47XX_BOARD_BUFFALO_WZR_G300N:
1293 return &platforms[WZR_G300N];
1294 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54:
1295 return &platforms[WZR_RS_G54];
1296 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54HP:
1297 return &platforms[WZR_RS_G54HP];
1298 case BCM47XX_BOARD_DELL_TM2300:
1299 return &platforms[TM2300];
1300 case BCM47XX_BOARD_DLINK_DIR130:
1301 return &platforms[DIR130];
1302 case BCM47XX_BOARD_DLINK_DIR330:
1303 return &platforms[DIR330];
1304 case BCM47XX_BOARD_LINKSYS_E1000V1:
1305 return &platforms[E1000V1];
1306 case BCM47XX_BOARD_LINKSYS_E3000V1:
1307 return &platforms[E3000V1];
1308 case BCM47XX_BOARD_LINKSYS_E3200V1:
1309 return &platforms[E3200V1];
1310 case BCM47XX_BOARD_LINKSYS_WRT150NV1:
1311 return &platforms[WRT150NV1];
1312 case BCM47XX_BOARD_LINKSYS_WRT150NV11:
1313 return &platforms[WRT150NV11];
1314 case BCM47XX_BOARD_LINKSYS_WRT160NV1:
1315 return &platforms[WRT160NV1];
1316 case BCM47XX_BOARD_LINKSYS_WRT160NV3:
1317 return &platforms[WRT160NV3];
1318 case BCM47XX_BOARD_LINKSYS_WRT300NV11:
1319 return &platforms[WRT300NV11];
1320 case BCM47XX_BOARD_LINKSYS_WRT54G3GV2:
1321 return &platforms[WRT54G3GV2_VF];
1322 case BCM47XX_BOARD_LINKSYS_WRT610NV1:
1323 return &platforms[WRT610N];
1324 case BCM47XX_BOARD_LINKSYS_WRT610NV2:
1325 return &platforms[WRT610NV2];
1326 case BCM47XX_BOARD_MOTOROLA_WE800G:
1327 return &platforms[WE800G];
1328 case BCM47XX_BOARD_MOTOROLA_WR850GP:
1329 return &platforms[WR850GP];
1330 case BCM47XX_BOARD_MOTOROLA_WR850GV2V3:
1331 return &platforms[WR850GV2V3];
1332 case BCM47XX_BOARD_NETGEAR_WNDR3400V1:
1333 return &platforms[WNDR3400V1];
1334 case BCM47XX_BOARD_NETGEAR_WNDR3700V3:
1335 return &platforms[WNDR3700V3];
1336 case BCM47XX_BOARD_UNKNOWN:
1337 case BCM47XX_BOARD_NON:
1338 printk(MODULE_NAME ": unknown board found, try legacy detect\n");
1339 printk(MODULE_NAME ": please open a ticket at https://dev.openwrt.org and attach the complete nvram\n");
1340 return platform_detect_legacy();
1341 default:
1342 printk(MODULE_NAME ": board was detected as \"%s\", but not gpio configuration available\n", board_name);
1343 printk(MODULE_NAME ": now trying legacy detect\n");
1344 return platform_detect_legacy();
1345 }
1346 }
1347
1348 static inline void ssb_maskset32(struct ssb_device *dev,
1349 u16 offset, u32 mask, u32 set)
1350 {
1351 ssb_write32(dev, offset, (ssb_read32(dev, offset) & mask) | set);
1352 }
1353
1354 static void gpio_set_irqenable(int enabled, irqreturn_t (*handler)(int, void *))
1355 {
1356 int irq;
1357
1358 irq = gpio_to_irq(0);
1359 if (irq == -EINVAL) return;
1360
1361 if (enabled) {
1362 if (request_irq(irq, handler, IRQF_SHARED, "gpio", handler))
1363 return;
1364 } else {
1365 free_irq(irq, handler);
1366 }
1367
1368 switch (bcm47xx_bus_type) {
1369 #ifdef CONFIG_BCM47XX_SSB
1370 case BCM47XX_BUS_TYPE_SSB:
1371 if (bcm47xx_bus.ssb.chipco.dev)
1372 ssb_maskset32(bcm47xx_bus.ssb.chipco.dev, SSB_CHIPCO_IRQMASK, ~SSB_CHIPCO_IRQ_GPIO, (enabled ? SSB_CHIPCO_IRQ_GPIO : 0));
1373 break;
1374 #endif
1375 #ifdef CONFIG_BCM47XX_BCMA
1376 case BCM47XX_BUS_TYPE_BCMA:
1377 if (bcm47xx_bus.bcma.bus.drv_cc.core)
1378 bcma_maskset32(bcm47xx_bus.bcma.bus.drv_cc.core, BCMA_CC_IRQMASK, ~BCMA_CC_IRQ_GPIO, (enabled ? BCMA_CC_IRQ_GPIO : 0));
1379 break;
1380 #endif
1381 }
1382 }
1383
1384 static void register_buttons(struct button_t *b)
1385 {
1386 for (; b->name; b++)
1387 platform.button_mask |= b->gpio;
1388
1389 platform.button_mask &= ~gpiomask;
1390
1391 bcm47xx_gpio_outen(platform.button_mask, 0);
1392 bcm47xx_gpio_control(platform.button_mask, 0);
1393 platform.button_polarity = bcm47xx_gpio_in(~0) & platform.button_mask;
1394 bcm47xx_gpio_polarity(platform.button_mask, platform.button_polarity);
1395 bcm47xx_gpio_intmask(platform.button_mask, platform.button_mask);
1396
1397 gpio_set_irqenable(1, button_handler);
1398 }
1399
1400 static void unregister_buttons(struct button_t *b)
1401 {
1402 bcm47xx_gpio_intmask(platform.button_mask, 0);
1403
1404 gpio_set_irqenable(0, button_handler);
1405 }
1406
1407
1408 static void add_msg(struct event_t *event, char *msg, int argv)
1409 {
1410 char *s;
1411
1412 if (argv)
1413 return;
1414
1415 s = skb_put(event->skb, strlen(msg) + 1);
1416 strcpy(s, msg);
1417 }
1418
1419 static void hotplug_button(struct work_struct *work)
1420 {
1421 struct event_t *event = container_of(work, struct event_t, wq);
1422 char *s;
1423
1424 event->skb = alloc_skb(2048, GFP_KERNEL);
1425
1426 s = skb_put(event->skb, strlen(event->action) + 2);
1427 sprintf(s, "%s@", event->action);
1428 fill_event(event);
1429
1430 NETLINK_CB(event->skb).dst_group = 1;
1431 broadcast_uevent(event->skb, 0, 1, GFP_KERNEL);
1432
1433 kfree(event);
1434 }
1435
1436
1437 static int fill_event (struct event_t *event)
1438 {
1439 static char buf[128];
1440
1441 add_msg(event, "HOME=/", 0);
1442 add_msg(event, "PATH=/sbin:/bin:/usr/sbin:/usr/bin", 0);
1443 add_msg(event, "SUBSYSTEM=button", 0);
1444 snprintf(buf, 128, "ACTION=%s", event->action);
1445 add_msg(event, buf, 0);
1446 snprintf(buf, 128, "BUTTON=%s", event->name);
1447 add_msg(event, buf, 0);
1448 snprintf(buf, 128, "SEEN=%ld", event->seen);
1449 add_msg(event, buf, 0);
1450 snprintf(buf, 128, "SEQNUM=%llu", uevent_next_seqnum());
1451 add_msg(event, buf, 0);
1452
1453 return 0;
1454 }
1455
1456
1457 static irqreturn_t button_handler(int irq, void *dev_id)
1458 {
1459 struct button_t *b;
1460 u32 in, changed;
1461
1462 in = bcm47xx_gpio_in(~0) & platform.button_mask;
1463 bcm47xx_gpio_polarity(platform.button_mask, in);
1464 changed = platform.button_polarity ^ in;
1465 platform.button_polarity = in;
1466
1467 changed &= ~bcm47xx_gpio_outen(0, 0);
1468
1469 for (b = platform.buttons; b->name; b++) {
1470 struct event_t *event;
1471
1472 if (!(b->gpio & changed)) continue;
1473
1474 b->pressed ^= 1;
1475
1476 if ((event = (struct event_t *)kzalloc (sizeof(struct event_t), GFP_ATOMIC))) {
1477 event->seen = (jiffies - b->seen)/HZ;
1478 event->name = b->name;
1479 event->action = b->pressed ? "pressed" : "released";
1480 INIT_WORK(&event->wq, (void *)(void *)hotplug_button);
1481 schedule_work(&event->wq);
1482 }
1483
1484 b->seen = jiffies;
1485 }
1486 return IRQ_HANDLED;
1487 }
1488
1489 static void register_leds(struct led_t *l)
1490 {
1491 struct proc_dir_entry *p;
1492 u32 mask = 0;
1493 u32 oe_mask = 0;
1494 u32 val = 0;
1495
1496 leds = proc_mkdir("led", diag);
1497 if (!leds)
1498 return;
1499
1500 for(; l->name; l++) {
1501 if (l->gpio & gpiomask)
1502 continue;
1503
1504 switch (l->gpio & GPIO_TYPE_MASK) {
1505 case GPIO_TYPE_EXTIF:
1506 l->state = 0;
1507 set_led_extif(l);
1508 break;
1509 case GPIO_TYPE_SHIFT:
1510 mask |= (SHIFTREG_DATA | SHIFTREG_CLK);
1511 oe_mask |= (SHIFTREG_DATA | SHIFTREG_CLK);
1512 l->state = (l->polarity != NORMAL);
1513 set_led_shift(l);
1514 break;
1515 case GPIO_TYPE_NORMAL:
1516 default:
1517 if (l->polarity != INPUT) oe_mask |= l->gpio;
1518 mask |= l->gpio;
1519 val |= (l->polarity == NORMAL)?0:l->gpio;
1520 break;
1521 }
1522
1523 if (l->polarity == INPUT) continue;
1524
1525 if ((p = create_proc_entry(l->name, S_IRUSR, leds))) {
1526 l->proc.type = PROC_LED;
1527 l->proc.ptr = l;
1528 p->data = (void *) &l->proc;
1529 p->proc_fops = &diag_proc_fops;
1530 }
1531 }
1532
1533 bcm47xx_gpio_outen(mask, oe_mask);
1534 bcm47xx_gpio_control(mask, 0);
1535 bcm47xx_gpio_out(mask, val);
1536 bcm47xx_gpio_intmask(mask, 0);
1537 }
1538
1539 static void unregister_leds(struct led_t *l)
1540 {
1541 for(; l->name; l++)
1542 remove_proc_entry(l->name, leds);
1543
1544 remove_proc_entry("led", diag);
1545 }
1546
1547 static void set_led_extif(struct led_t *led)
1548 {
1549 volatile u8 *addr = (volatile u8 *) KSEG1ADDR(EXTIF_UART) + (led->gpio & ~GPIO_TYPE_MASK);
1550 if (led->state)
1551 *addr = 0xFF;
1552 else
1553 *addr;
1554 }
1555
1556 /*
1557 * This should be extended to allow the platform to specify the pins and width
1558 * of the shift register. They're hardcoded for now because only the WNDR3700v3
1559 * uses it.
1560 */
1561 static void shiftreg_output(unsigned int val)
1562 {
1563 unsigned int mask;
1564
1565 bcm47xx_gpio_out(SHIFTREG_DATA, SHIFTREG_DATA); /* init off, pull high */
1566 bcm47xx_gpio_out(SHIFTREG_CLK, 0); /* init reset */
1567
1568 /* shift 8 times */
1569 for(mask = 1 << (SHIFTREG_MAX_BITS-1); mask; mask >>= 1)
1570 {
1571 bcm47xx_gpio_out(SHIFTREG_DATA, (val & mask) ? SHIFTREG_DATA : 0);
1572 bcm47xx_gpio_out(SHIFTREG_CLK, SHIFTREG_CLK); /* pull high to trigger */
1573 bcm47xx_gpio_out(SHIFTREG_CLK, 0); /* reset to low */
1574 }
1575 }
1576
1577 static void set_led_shift(struct led_t *led)
1578 {
1579 static u32 shiftreg = 0;
1580 u32 old = shiftreg;
1581 u32 pin = (led->gpio & ~GPIO_TYPE_MASK);
1582
1583 if (led->state) {
1584 shiftreg |= pin;
1585 } else {
1586 shiftreg &= ~pin;
1587 }
1588
1589 /* Clock the bits out. */
1590 if (shiftreg != old) {
1591 shiftreg_output(shiftreg);
1592 }
1593 }
1594
1595
1596 static void led_flash(unsigned long dummy) {
1597 struct led_t *l;
1598 u32 mask = 0;
1599 u8 extif_blink = 0;
1600
1601 for (l = platform.leds; l->name; l++) {
1602 if (!l->flash) continue;
1603 switch (l->gpio & GPIO_TYPE_MASK) {
1604 case GPIO_TYPE_EXTIF:
1605 extif_blink = 1;
1606 l->state = !l->state;
1607 set_led_extif(l);
1608 break;
1609 case GPIO_TYPE_SHIFT:
1610 extif_blink = 1;
1611 l->state = !l->state;
1612 set_led_shift(l);
1613 break;
1614 case GPIO_TYPE_NORMAL:
1615 default:
1616 mask |= l->gpio;
1617 break;
1618 }
1619 }
1620
1621 mask &= ~gpiomask;
1622 if (mask) {
1623 u32 val = ~bcm47xx_gpio_in(~0);
1624
1625 bcm47xx_gpio_outen(mask, mask);
1626 bcm47xx_gpio_control(mask, 0);
1627 bcm47xx_gpio_out(mask, val);
1628 }
1629 if (mask || extif_blink) {
1630 mod_timer(&led_timer, jiffies + FLASH_TIME);
1631 }
1632 }
1633
1634 static ssize_t diag_proc_read(struct file *file, char *buf, size_t count, loff_t *ppos)
1635 {
1636 struct proc_dir_entry *dent = PDE(file->f_dentry->d_inode);
1637 char *page;
1638 int len = 0;
1639
1640 if ((page = kmalloc(1024, GFP_KERNEL)) == NULL)
1641 return -ENOBUFS;
1642
1643 if (dent->data != NULL) {
1644 struct prochandler_t *handler = (struct prochandler_t *) dent->data;
1645 switch (handler->type) {
1646 case PROC_LED: {
1647 struct led_t * led = (struct led_t *) handler->ptr;
1648 u8 p = (led->polarity == NORMAL ? 0 : 1);
1649 if (led->flash) {
1650 len = sprintf(page, "f\n");
1651 } else if ((led->gpio & GPIO_TYPE_MASK) != GPIO_TYPE_NORMAL) {
1652 len = sprintf(page, "%d\n", ((led->state ^ p) ? 1 : 0));
1653 } else {
1654 u32 in = (bcm47xx_gpio_in(~0) & led->gpio ? 1 : 0);
1655 len = sprintf(page, "%d\n", ((in ^ p) ? 1 : 0));
1656 }
1657 break;
1658 }
1659 case PROC_MODEL:
1660 len = sprintf(page, "%s\n", platform.name);
1661 break;
1662 case PROC_GPIOMASK:
1663 len = sprintf(page, "0x%04x\n", gpiomask);
1664 break;
1665 }
1666 }
1667 len += 1;
1668
1669 if (*ppos < len) {
1670 len = min_t(int, len - *ppos, count);
1671 if (copy_to_user(buf, (page + *ppos), len)) {
1672 kfree(page);
1673 return -EFAULT;
1674 }
1675 *ppos += len;
1676 } else {
1677 len = 0;
1678 }
1679
1680 kfree(page);
1681 return len;
1682 }
1683
1684
1685 static ssize_t diag_proc_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
1686 {
1687 struct proc_dir_entry *dent = PDE(file->f_dentry->d_inode);
1688 char *page;
1689 int ret = -EINVAL;
1690
1691 if ((page = kmalloc(count + 1, GFP_KERNEL)) == NULL)
1692 return -ENOBUFS;
1693
1694 if (copy_from_user(page, buf, count)) {
1695 kfree(page);
1696 return -EINVAL;
1697 }
1698 page[count] = 0;
1699
1700 if (dent->data != NULL) {
1701 struct prochandler_t *handler = (struct prochandler_t *) dent->data;
1702 switch (handler->type) {
1703 case PROC_LED: {
1704 struct led_t *led = (struct led_t *) handler->ptr;
1705 int p = (led->polarity == NORMAL ? 0 : 1);
1706
1707 if (page[0] == 'f') {
1708 led->flash = 1;
1709 led_flash(0);
1710 } else {
1711 led->flash = 0;
1712 if ((led->gpio & GPIO_TYPE_MASK) == GPIO_TYPE_EXTIF) {
1713 led->state = p ^ ((page[0] == '1') ? 1 : 0);
1714 set_led_extif(led);
1715 } else if ((led->gpio & GPIO_TYPE_MASK) == GPIO_TYPE_SHIFT) {
1716 led->state = p ^ ((page[0] == '1') ? 1 : 0);
1717 set_led_shift(led);
1718 } else {
1719 bcm47xx_gpio_outen(led->gpio, led->gpio);
1720 bcm47xx_gpio_control(led->gpio, 0);
1721 bcm47xx_gpio_out(led->gpio, ((p ^ (page[0] == '1')) ? led->gpio : 0));
1722 }
1723 }
1724 break;
1725 }
1726 case PROC_GPIOMASK:
1727 gpiomask = simple_strtoul(page, NULL, 0);
1728
1729 if (platform.buttons) {
1730 unregister_buttons(platform.buttons);
1731 register_buttons(platform.buttons);
1732 }
1733
1734 if (platform.leds) {
1735 unregister_leds(platform.leds);
1736 register_leds(platform.leds);
1737 }
1738 break;
1739 }
1740 ret = count;
1741 }
1742
1743 kfree(page);
1744 return ret;
1745 }
1746
1747 static int __init diag_init(void)
1748 {
1749 static struct proc_dir_entry *p;
1750 static struct platform_t *detected;
1751
1752 detected = platform_detect();
1753 if (!detected) {
1754 printk(MODULE_NAME ": Router model not detected.\n");
1755 return -ENODEV;
1756 }
1757 memcpy(&platform, detected, sizeof(struct platform_t));
1758
1759 printk(MODULE_NAME ": Detected '%s'\n", platform.name);
1760 if (platform.platform_init != NULL) {
1761 platform.platform_init();
1762 }
1763
1764 if (!(diag = proc_mkdir("diag", NULL))) {
1765 printk(MODULE_NAME ": proc_mkdir on /proc/diag failed\n");
1766 return -EINVAL;
1767 }
1768
1769 if ((p = create_proc_entry("model", S_IRUSR, diag))) {
1770 p->data = (void *) &proc_model;
1771 p->proc_fops = &diag_proc_fops;
1772 }
1773
1774 if ((p = create_proc_entry("gpiomask", S_IRUSR | S_IWUSR, diag))) {
1775 p->data = (void *) &proc_gpiomask;
1776 p->proc_fops = &diag_proc_fops;
1777 }
1778
1779 if (platform.buttons)
1780 register_buttons(platform.buttons);
1781
1782 if (platform.leds)
1783 register_leds(platform.leds);
1784
1785 return 0;
1786 }
1787
1788 static void __exit diag_exit(void)
1789 {
1790 del_timer(&led_timer);
1791
1792 if (platform.buttons)
1793 unregister_buttons(platform.buttons);
1794
1795 if (platform.leds)
1796 unregister_leds(platform.leds);
1797
1798 remove_proc_entry("model", diag);
1799 remove_proc_entry("gpiomask", diag);
1800 remove_proc_entry("diag", NULL);
1801 }
1802
1803 module_init(diag_init);
1804 module_exit(diag_exit);
1805
1806 MODULE_AUTHOR("Mike Baker, Felix Fietkau / OpenWrt.org");
1807 MODULE_LICENSE("GPL");