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