2 * diag.c - GPIO interface driver for Broadcom boards
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>
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.
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.
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.
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>
35 #include <bcm47xx_board.h>
36 extern u64
uevent_next_seqnum(void);
40 #define getvar(str) (nvram_get(str)?:"")
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);
47 extern char *nvram_get(char *str
);
48 static void led_flash(unsigned long dummy
);
50 static struct platform_t platform
;
52 static struct timer_list led_timer
= TIMER_INITIALIZER(&led_flash
, 0, 0);
54 static struct proc_dir_entry
*diag
, *leds
;
56 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,9,0)
57 static inline struct inode
*file_inode(struct file
*f
)
59 return f
->f_path
.dentry
->d_inode
;
63 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)
64 static inline void *PDE_DATA(const struct inode
*inode
)
66 return PDE(inode
)->data
;
127 BUFFALO_UNKNOWN_4710
,
148 BELKIN_F7D330X
, /* covers F7D7302,F7D3302,F7D3301, and F7D7301 */
173 /* Western Digital */
192 static void __init
bcm4780_init(void) {
195 /* Enables GPIO 3 that controls HDD and led power on ASUS WL-700gE */
196 printk(MODULE_NAME
": Spinning up HDD and enabling leds\n");
197 bcm47xx_gpio_outen(pin
, pin
);
198 bcm47xx_gpio_control(pin
, 0);
199 bcm47xx_gpio_out(pin
, pin
);
201 /* Wait 5s, so the HDD can spin up */
202 set_current_state(TASK_INTERRUPTIBLE
);
203 schedule_timeout(HZ
* 5);
206 static void __init
NetCenter_init(void) {
207 /* unset pin 6 (+12V) */
209 bcm47xx_gpio_outen(pin
, pin
);
210 bcm47xx_gpio_control(pin
, 0);
211 bcm47xx_gpio_out(pin
, pin
);
212 /* unset pin 1 (turn off red led, blue will light alone if +5V comes up) */
214 bcm47xx_gpio_outen(pin
, pin
);
215 bcm47xx_gpio_control(pin
, 0);
216 bcm47xx_gpio_out(pin
, pin
);
217 /* unset pin 3 (+5V) and wait 5 seconds (harddisk spin up) */
221 static void __init
bcm57xx_init(void) {
224 /* FIXME: switch comes up, but port mappings/vlans not right */
225 bcm47xx_gpio_outen(pin
, pin
);
226 bcm47xx_gpio_control(pin
, 0);
227 bcm47xx_gpio_out(pin
, pin
);
230 static struct platform_t __initdata platforms
[] = {
233 .name
= "Linksys WAP54G V1",
235 { .name
= "reset", .gpio
= 1 << 0 },
238 { .name
= "diag", .gpio
= 1 << 3 },
239 { .name
= "wlan", .gpio
= 1 << 4 },
243 .name
= "Linksys WAP54G V2",
245 { .name
= "reset", .gpio
= 1 << 0 },
248 { .name
= "wlan", .gpio
= 1 << 5, .polarity
= REVERSE
},
249 /* GPIO 6 is b44 (eth0, LAN) PHY power */
253 .name
= "Linksys WAP54G V3",
255 /* FIXME: verify this */
256 { .name
= "reset", .gpio
= 1 << 7 },
257 { .name
= "ses", .gpio
= 1 << 0 },
261 { .name
= "ses", .gpio
= 1 << 1 },
265 .name
= "Linksys WRT54G V1.x",
267 { .name
= "reset", .gpio
= 1 << 6 },
270 { .name
= "diag", .gpio
= 0x13 | GPIO_TYPE_EXTIF
, .polarity
= NORMAL
},
271 { .name
= "dmz", .gpio
= 0x12 | GPIO_TYPE_EXTIF
, .polarity
= NORMAL
},
275 .name
= "Linksys WRT54G/GS/GL",
277 { .name
= "reset", .gpio
= 1 << 6 },
278 { .name
= "ses", .gpio
= 1 << 4 },
281 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
282 { .name
= "dmz", .gpio
= 1 << 7, .polarity
= REVERSE
},
283 { .name
= "ses_white", .gpio
= 1 << 2, .polarity
= REVERSE
},
284 { .name
= "ses_orange", .gpio
= 1 << 3, .polarity
= REVERSE
},
285 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
289 .name
= "Linksys WRTSL54GS",
291 { .name
= "reset", .gpio
= 1 << 6 },
292 { .name
= "ses", .gpio
= 1 << 4 },
295 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
296 { .name
= "dmz", .gpio
= 1 << 0, .polarity
= REVERSE
},
297 { .name
= "ses_white", .gpio
= 1 << 5, .polarity
= REVERSE
},
298 { .name
= "ses_orange", .gpio
= 1 << 7, .polarity
= REVERSE
},
302 .name
= "Linksys WRT54G3G",
304 { .name
= "reset", .gpio
= 1 << 6 },
305 { .name
= "3g", .gpio
= 1 << 4 },
308 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
309 { .name
= "dmz", .gpio
= 1 << 7, .polarity
= REVERSE
},
310 { .name
= "3g_green", .gpio
= 1 << 2, .polarity
= NORMAL
},
311 { .name
= "3g_blue", .gpio
= 1 << 3, .polarity
= NORMAL
},
312 { .name
= "3g_blink", .gpio
= 1 << 5, .polarity
= NORMAL
},
316 .name
= "Linksys WRT54G3GV2-VF",
318 { .name
= "reset", .gpio
= 1 << 6 },
319 { .name
= "3g", .gpio
= 1 << 5 },
322 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
323 { .name
= "3g_green", .gpio
= 1 << 2, .polarity
= NORMAL
},
324 { .name
= "3g_blue", .gpio
= 1 << 3, .polarity
= NORMAL
},
328 .name
= "Linksys WRT150N V1",
330 { .name
= "reset", .gpio
= 1 << 6 },
331 { .name
= "ses", .gpio
= 1 << 4 },
334 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
335 { .name
= "ses_green", .gpio
= 1 << 5, .polarity
= REVERSE
},
336 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
340 .name
= "Linksys WRT150N V1.1",
342 { .name
= "reset", .gpio
= 1 << 6 },
343 { .name
= "ses", .gpio
= 1 << 4 },
346 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
347 { .name
= "ses_green", .gpio
= 1 << 5, .polarity
= REVERSE
},
348 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
352 .name
= "Linksys WRT160N v1.x",
354 { .name
= "reset", .gpio
= 1 << 6 },
355 { .name
= "ses", .gpio
= 1 << 4 },
358 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
359 { .name
= "ses_blue", .gpio
= 1 << 5, .polarity
= REVERSE
},
360 { .name
= "ses_orange", .gpio
= 1 << 3, .polarity
= REVERSE
},
364 .name
= "Linksys WRT160N V3",
366 { .name
= "reset", .gpio
= 1 << 6 },
367 { .name
= "ses", .gpio
= 1 << 5 },
370 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
371 { .name
= "ses_blue", .gpio
= 1 << 4, .polarity
= REVERSE
},
372 { .name
= "ses_orange", .gpio
= 1 << 2, .polarity
= REVERSE
},
376 .name
= "Linksys WRT300N V1.1",
378 { .name
= "reset", .gpio
= 1 << 6 }, // "Reset" on back panel
379 { .name
= "ses", .gpio
= 1 << 4 }, // "Reserved" on top panel
382 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
}, // "Power"
383 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
}, // "Security" Amber
384 { .name
= "ses_green", .gpio
= 1 << 5, .polarity
= REVERSE
}, // "Security" Green
386 .platform_init
= bcm57xx_init
,
389 .name
= "Linksys WRT310N V1",
391 { .name
= "reset", .gpio
= 1 << 6 }, // "Reset" on back panel
392 { .name
= "ses", .gpio
= 1 << 8 }, // "Reserved" on top panel
395 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
}, // Power LED
396 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
}, // "Security" Amber
397 { .name
= "ses_blue", .gpio
= 1 << 9, .polarity
= REVERSE
}, // "Security" Blue
401 .name
= "Linksys WRT350N",
403 { .name
= "reset", .gpio
= 1 << 6 },
404 { .name
= "ses", .gpio
= 1 << 8 },
407 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
408 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
409 { .name
= "ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
},
410 { .name
= "usb_blink", .gpio
= 1 << 10, .polarity
= REVERSE
},
411 { .name
= "usb", .gpio
= 1 << 11, .polarity
= REVERSE
},
413 .platform_init
= bcm57xx_init
,
416 .name
= "Linksys WRT600N",
418 { .name
= "reset", .gpio
= 1 << 6 },
419 { .name
= "ses", .gpio
= 1 << 7 },
422 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
}, // Power LED
423 { .name
= "usb", .gpio
= 1 << 3, .polarity
= REVERSE
}, // USB LED
424 { .name
= "wl0_ses_amber", .gpio
= 1 << 8, .polarity
= REVERSE
}, // 2.4Ghz LED Amber
425 { .name
= "wl0_ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
}, // 2.4Ghz LED Green
426 { .name
= "wl1_ses_amber", .gpio
= 1 << 10, .polarity
= REVERSE
}, // 5.6Ghz LED Amber
427 { .name
= "wl1_ses_green", .gpio
= 1 << 11, .polarity
= REVERSE
}, // 5.6Ghz LED Green
429 .platform_init
= bcm57xx_init
,
432 .name
= "Linksys WRT600N V1.1",
434 { .name
= "reset", .gpio
= 1 << 6 },
435 { .name
= "ses", .gpio
= 1 << 7 },
438 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
}, // Power LED
439 { .name
= "usb", .gpio
= 1 << 3, .polarity
= REVERSE
}, // USB LED
440 { .name
= "wl0_ses_amber", .gpio
= 1 << 8, .polarity
= REVERSE
}, // 2.4Ghz LED Amber
441 { .name
= "wl0_ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
}, // 2.4Ghz LED Green
442 { .name
= "wl1_ses_amber", .gpio
= 1 << 10, .polarity
= REVERSE
}, // 5.6Ghz LED Amber
443 { .name
= "wl1_ses_green", .gpio
= 1 << 11, .polarity
= REVERSE
}, // 5.6Ghz LED Green
445 .platform_init
= bcm57xx_init
,
448 .name
= "Linksys WRT610N",
450 { .name
= "reset", .gpio
= 1 << 6 },
451 { .name
= "ses", .gpio
= 1 << 8 },
454 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
}, // Power LED
455 { .name
= "usb", .gpio
= 1 << 0, .polarity
= REVERSE
}, // USB LED
456 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
}, // WiFi protected setup LED amber
457 { .name
= "ses_blue", .gpio
= 1 << 9, .polarity
= REVERSE
}, // WiFi protected setup LED blue
461 .name
= "Linksys WRT610N V2",
463 { .name
= "reset", .gpio
= 1 << 6 },
464 { .name
= "ses", .gpio
= 1 << 4 },
467 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
}, // Power LED
468 { .name
= "usb", .gpio
= 1 << 7, .polarity
= NORMAL
}, // USB LED
469 { .name
= "ses_amber", .gpio
= 1 << 0, .polarity
= REVERSE
}, // WiFi protected setup LED amber
470 { .name
= "ses_blue", .gpio
= 1 << 3, .polarity
= REVERSE
}, // WiFi protected setup LED blue
471 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
}, // Wireless LED
474 /* same hardware as WRT160NV3 and Cisco Valet M10V1, but different board detection, combine? */
476 .name
= "Linksys E1000 V1",
478 { .name
= "reset", .gpio
= 1 << 6 },
479 { .name
= "wps", .gpio
= 1 << 5 }, /* nvram get gpio5=wps_button */
482 /** turns on leds for all ethernet ports (wan too)
483 * this also disconnects some, or maybe all, ethernet ports
484 * 1: leds work normally
485 * 0: all lit all the time */
486 /* nvram get gpio3=robo_reset */
487 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
488 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
489 { .name
= "ses_blue", .gpio
= 1 << 4, .polarity
= REVERSE
}, /* nvram get gpio4=wps_led */
490 { .name
= "ses_orange", .gpio
= 1 << 2, .polarity
= REVERSE
}, /* nvram get gpio2=wps_status_led */
494 .name
= "Linksys E1000 V2.1",
496 { .name
= "reset", .gpio
= 1 << 10 }, /* nvram get reset_gpio=10 */
497 { .name
= "wps", .gpio
= 1 << 9 }, /* nvram get gpio9=wps_button */
500 { .name
= "power", .gpio
= 1 << 6, .polarity
= REVERSE
},
501 { .name
= "wlan", .gpio
= 1 << 5, .polarity
= NORMAL
},
502 { .name
= "ses_blue", .gpio
= 1 << 8, .polarity
= NORMAL
}, /* nvram get gpio8=wps_led */
503 { .name
= "ses_orange", .gpio
= 1 << 7, .polarity
= NORMAL
}, /* nvram get gpio7=wps_status_led */
507 .name
= "Linksys E2000 V1",
509 { .name
= "reset", .gpio
= 1 << 8 },
510 { .name
= "ses", .gpio
= 1 << 5 },
513 { .name
= "power", .gpio
= 1 << 2, .polarity
= NORMAL
},
514 { .name
= "ses_amber", .gpio
= 1 << 4, .polarity
= REVERSE
},
515 { .name
= "ses_blue", .gpio
= 1 << 3, .polarity
= REVERSE
},
516 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
},
520 .name
= "Linksys E3000 V1",
522 { .name
= "reset", .gpio
= 1 << 6 },
523 { .name
= "ses", .gpio
= 1 << 4 },
526 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
}, // Power LED
527 { .name
= "usb", .gpio
= 1 << 7, .polarity
= NORMAL
}, // USB LED
528 { .name
= "ses_amber", .gpio
= 1 << 0, .polarity
= REVERSE
}, // WiFi protected setup LED amber
529 { .name
= "ses_blue", .gpio
= 1 << 3, .polarity
= REVERSE
}, // WiFi protected setup LED blue
530 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
}, // Wireless LED
534 .name
= "Linksys E3200 V1",
536 /* { .name = "switch", .gpio = 1 << 4 },*/ /* nvram get gpio4=robo_reset */
537 { .name
= "reset", .gpio
= 1 << 5 }, /* nvram get reset_gpio=5 */
538 { .name
= "wps", .gpio
= 1 << 8 }, /* nvram get gpio8=wps_button */
539 /* { .name = "wombo", .gpio = 1 << 23 },*/ /* nvram get gpio23=wombo_reset - wireless on motherboard */
542 { .name
= "power", .gpio
= 1 << 3, .polarity
= REVERSE
}, /* Power LED */
546 .name
= "Linksys E4200 V1",
548 { .name
= "reset", .gpio
= 1 << 6 },
549 { .name
= "wps", .gpio
= 1 << 4 },
552 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
557 .name
= "ASUS WL-HDD",
559 { .name
= "reset", .gpio
= 1 << 6 },
562 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
563 { .name
= "usb", .gpio
= 1 << 2, .polarity
= REVERSE
},
567 .name
= "ASUS WL-300g",
569 { .name
= "reset", .gpio
= 1 << 6 },
572 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
576 .name
= "ASUS WL-320gE/WL-320gP",
578 { .name
= "reset", .gpio
= 1 << 6 },
581 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
582 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
},
583 { .name
= "link", .gpio
= 1 << 11, .polarity
= REVERSE
},
587 .name
= "ASUS WL-330gE",
589 { .name
= "reset", .gpio
= 1 << 2 },
592 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
596 .name
= "ASUS WL-500g",
598 { .name
= "reset", .gpio
= 1 << 6 },
601 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
605 .name
= "ASUS WL-500g Deluxe",
607 { .name
= "reset", .gpio
= 1 << 6 },
610 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
614 .name
= "ASUS WL-500g Premium",
616 { .name
= "reset", .gpio
= 1 << 0 },
617 { .name
= "ses", .gpio
= 1 << 4 },
620 { .name
= "power", .gpio
= 1 << 1, .polarity
= REVERSE
},
624 .name
= "ASUS WL-500g Premium V2",
626 { .name
= "reset", .gpio
= 1 << 2 },
627 { .name
= "ses", .gpio
= 1 << 3 },
630 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
631 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
635 .name
= "ASUS WL-500W",
637 { .name
= "reset", .gpio
= 1 << 6 },
638 { .name
= "ses", .gpio
= 1 << 7 },
641 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
645 .name
= "ASUS WL-520GC",
647 { .name
= "reset", .gpio
= 1 << 2 },
648 { .name
= "ses", .gpio
= 1 << 3 },
651 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
652 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
656 .name
= "ASUS WL-520gU",
658 { .name
= "reset", .gpio
= 1 << 2 },
659 { .name
= "ses", .gpio
= 1 << 3 },
662 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
663 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
667 .name
= "ASUS (unknown, BCM4702)",
669 { .name
= "reset", .gpio
= 1 << 6 },
672 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
676 .name
= "ASUS WL-700gE",
678 { .name
= "reset", .gpio
= 1 << 7 }, // on back, hardwired, always resets device regardless OS state
679 { .name
= "ses", .gpio
= 1 << 4 }, // on back, actual name ezsetup
680 { .name
= "power", .gpio
= 1 << 0 }, // on front
681 { .name
= "copy", .gpio
= 1 << 6 }, // on front
685 // GPIO that controls power led also enables/disables some essential functions
688 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
}, // actual name power
690 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
692 .platform_init
= bcm4780_init
,
695 .name
= "ASUS RT-N12",
697 { .name
= "wps", .gpio
= 1 << 0 },
698 { .name
= "reset", .gpio
= 1 << 1 },
699 // this is the router/repeater/ap switch
700 { .name
= "sw1", .gpio
= 1 << 4 },
701 { .name
= "sw2", .gpio
= 1 << 5 },
702 { .name
= "sw3", .gpio
= 1 << 6 },
705 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
},
706 { .name
= "wlan", .gpio
= 1 << 7, .polarity
= NORMAL
},
707 // gpio3 forces WAN and LAN1-4 all on
708 //{ .name = "eth", .gpio = 1 << 3, .polarity = REVERSE },
712 .name
= "ASUS RT-N16",
714 { .name
= "reset", .gpio
= 1 << 8 },
715 { .name
= "ses", .gpio
= 1 << 6 },
718 { .name
= "power", .gpio
= 1 << 1, .polarity
= REVERSE
},
719 { .name
= "wlan", .gpio
= 1 << 7, .polarity
= NORMAL
},
723 .name
= "ASUS RT-N66U",
725 { .name
= "reset", .gpio
= 1 << 9 },
726 { .name
= "wps", .gpio
= 1 << 4 },
729 { .name
= "power", .gpio
= 1 << 12, .polarity
= REVERSE
},
730 { .name
= "usb", .gpio
= 1 << 15, .polarity
= REVERSE
},
735 .name
= "Buffalo WHR-G54S",
737 { .name
= "reset", .gpio
= 1 << 4 },
738 { .name
= "bridge", .gpio
= 1 << 5 },
739 { .name
= "ses", .gpio
= 1 << 0 },
742 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
743 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
744 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
745 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
746 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
750 .name
= "Buffalo WBR2-G54",
753 { .name
= "reset", .gpio
= 1 << 7 },
756 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
760 .name
= "Buffalo WHR-HP-G54",
762 { .name
= "reset", .gpio
= 1 << 4 },
763 { .name
= "bridge", .gpio
= 1 << 5 },
764 { .name
= "ses", .gpio
= 1 << 0 },
767 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
768 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
769 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
770 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
771 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
775 .name
= "Buffalo WHR-G125",
777 { .name
= "reset", .gpio
= 1 << 4 },
778 { .name
= "bridge", .gpio
= 1 << 5 },
779 { .name
= "ses", .gpio
= 1 << 0 },
782 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
783 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
784 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
785 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
786 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
790 .name
= "Buffalo WHR2-A54G54",
792 { .name
= "reset", .gpio
= 1 << 4 },
795 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
799 .name
= "Buffalo WLA2-G54L",
802 { .name
= "reset", .gpio
= 1 << 7 },
805 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
809 .name
= "Buffalo WZR-G300N",
811 { .name
= "reset", .gpio
= 1 << 4 },
814 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
815 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
816 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
820 .name
= "Buffalo WZR-RS-G54",
822 { .name
= "ses", .gpio
= 1 << 0 },
823 { .name
= "reset", .gpio
= 1 << 4 },
826 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
827 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
828 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
832 .name
= "Buffalo WZR-RS-G54HP",
834 { .name
= "ses", .gpio
= 1 << 0 },
835 { .name
= "reset", .gpio
= 1 << 4 },
838 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
839 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
840 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
843 [BUFFALO_UNKNOWN_4710
] = {
844 .name
= "Buffalo (unknown, BCM4710)",
846 { .name
= "reset", .gpio
= 1 << 4 },
849 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
854 .name
= "Siemens SE505 V1",
856 /* No usable buttons */
859 // { .name = "power", .gpio = 1 << 0 .polarity = REVERSE }, // Usable when retrofitting D26 (?)
860 { .name
= "dmz", .gpio
= 1 << 4, .polarity
= REVERSE
}, // actual name WWW
861 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
865 .name
= "Siemens SE505 V2",
867 /* No usable buttons */
870 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
871 { .name
= "dmz", .gpio
= 1 << 0, .polarity
= REVERSE
}, // actual name WWW
872 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
877 .name
= "U.S. Robotics USR5461",
879 /* No usable buttons */
882 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
883 { .name
= "printer", .gpio
= 1 << 1, .polarity
= REVERSE
},
888 .name
= "Dell TrueMobile 2300",
890 { .name
= "reset", .gpio
= 1 << 0 },
893 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
894 { .name
= "power", .gpio
= 1 << 7, .polarity
= REVERSE
},
898 .name
= "Dell TrueMobile 2300 v2",
900 { .name
= "reset", .gpio
= 1 << 0 },
903 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
904 { .name
= "power", .gpio
= 1 << 7, .polarity
= REVERSE
},
909 .name
= "Motorola WE800G",
911 { .name
= "reset", .gpio
= 1 << 0 },
914 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
915 { .name
= "diag", .gpio
= 1 << 2, .polarity
= REVERSE
},
916 { .name
= "wlan_amber", .gpio
= 1 << 1, .polarity
= NORMAL
},
920 .name
= "Motorola WR850G V1",
922 { .name
= "reset", .gpio
= 1 << 0 },
925 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
926 { .name
= "diag", .gpio
= 1 << 3, .polarity
= REVERSE
},
927 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= NORMAL
},
928 { .name
= "wlan_red", .gpio
= 1 << 5, .polarity
= REVERSE
},
929 { .name
= "wlan_green", .gpio
= 1 << 7, .polarity
= REVERSE
},
933 .name
= "Motorola WR850G V2/V3",
935 { .name
= "reset", .gpio
= 1 << 5 },
938 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
939 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
940 { .name
= "wan", .gpio
= 1 << 6, .polarity
= INPUT
},
941 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
945 .name
= "Motorola WR850GP",
947 { .name
= "reset", .gpio
= 1 << 5 },
950 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
951 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
952 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= REVERSE
},
953 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
959 .name
= "Belkin (unknown)",
960 /* FIXME: verify & add detection */
962 { .name
= "reset", .gpio
= 1 << 7 },
965 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
},
966 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= NORMAL
},
967 { .name
= "connected", .gpio
= 1 << 0, .polarity
= NORMAL
},
971 .name
= "Belkin F7D330X",
973 { .name
= "reset", .gpio
= 1 << 6 },
974 { .name
= "wps", .gpio
= 1 << 8 },
978 { .name
= "power", .gpio
= 1 << 10, .polarity
= REVERSE
},
980 { .name
= "warn", .gpio
= 1 << 11, .polarity
= REVERSE
},
982 { .name
= "wps", .gpio
= 1 << 12, .polarity
= REVERSE
},
984 { .name
= "wlan", .gpio
= 1 << 13, .polarity
= REVERSE
},
985 { .name
= "usb0", .gpio
= 1 << 14, .polarity
= REVERSE
},
986 /* shipped unconnected in the F7D3302 */
987 { .name
= "usb1", .gpio
= 1 << 15, .polarity
= REVERSE
},
991 .name
= "Belkin PlayMax F7D4301",
993 { .name
= "reset", .gpio
= 1 << 6 },
994 { .name
= "wps", .gpio
= 1 << 8 },
997 { .name
= "power", .gpio
= 1 << 10, .polarity
= REVERSE
},
998 { .name
= "warn", .gpio
= 1 << 11, .polarity
= REVERSE
},
999 { .name
= "wps", .gpio
= 1 << 12, .polarity
= REVERSE
},
1000 { .name
= "wlan", .gpio
= 1 << 13, .polarity
= REVERSE
},
1001 { .name
= "usb0", .gpio
= 1 << 14, .polarity
= REVERSE
},
1002 { .name
= "usb1", .gpio
= 1 << 15, .polarity
= REVERSE
},
1007 .name
= "Netgear WGT634U",
1009 { .name
= "reset", .gpio
= 1 << 2 },
1012 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
},
1017 .name
= "Netgear WNR834B V1",
1018 .buttons
= { /* TODO: add reset button and confirm LEDs - GPIO from dd-wrt */ },
1020 { .name
= "power", .gpio
= 1 << 4, .polarity
= REVERSE
},
1021 { .name
= "diag", .gpio
= 1 << 5, .polarity
= REVERSE
},
1022 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
1027 .name
= "Netgear WNR834B V2",
1029 { .name
= "reset", .gpio
= 1 << 6 },
1032 { .name
= "power", .gpio
= 1 << 2, .polarity
= NORMAL
},
1033 { .name
= "diag", .gpio
= 1 << 3, .polarity
= NORMAL
},
1034 { .name
= "connected", .gpio
= 1 << 7, .polarity
= NORMAL
},
1038 .name
= "Netgear WNDR3400 V1",
1040 /* nvram get gpio5=robo_reset */
1041 { .name
= "reset", .gpio
= 1 << 4 },
1042 { .name
= "wps", .gpio
= 1 << 6 },
1043 { .name
= "wlan", .gpio
= 1 << 8 },
1046 { .name
= "wlan", .gpio
= 0 << 0, .polarity
= NORMAL
},
1047 { .name
= "connected", .gpio
= 1 << 0, .polarity
= NORMAL
},
1048 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
},
1049 { .name
= "diag", .gpio
= 1 << 7, .polarity
= NORMAL
},
1050 { .name
= "usb", .gpio
= 1 << 2, .polarity
= REVERSE
},
1054 .name
= "Netgear WNDR3700 V3",
1056 /* { .name = "usb", .gpio = 1 << 1 }, */ /* this button doesn't seem to exist. */
1057 { .name
= "wlan", .gpio
= 1 << 2 },
1058 { .name
= "reset", .gpio
= 1 << 3 },
1059 { .name
= "wps", .gpio
= 1 << 4 },
1060 /* { .name = "switch", .gpio = 1 << 5 },*/ /* nvram get gpio5=robo_reset */
1063 { .name
= "power", .gpio
= (1 << 0) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1064 { .name
= "diag", .gpio
= (1 << 1) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1065 /* WAN LED doesn't respond to GPIO control. The switch is probably driving it.
1066 * { .name = "wan", .gpio = (1 << 2) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1068 { .name
= "wlan2g", .gpio
= (1 << 3) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1069 { .name
= "wlan5g", .gpio
= (1 << 4) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1070 { .name
= "usb", .gpio
= (1 << 5) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1071 { .name
= "wps", .gpio
= (1 << 6) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1072 { .name
= "wlan", .gpio
= (1 << 7) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1077 .name
= "Trendware TEW411BRP+",
1079 { /* No usable buttons */ },
1082 { .name
= "power", .gpio
= 1 << 7, .polarity
= NORMAL
},
1083 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
},
1084 { .name
= "bridge", .gpio
= 1 << 6, .polarity
= NORMAL
},
1089 .name
= "SimpleTech SimpleShare NAS",
1091 { .name
= "reset", .gpio
= 1 << 0 }, // Power button on back, named reset to enable failsafe.
1094 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
1096 .platform_init
= bcm4780_init
,
1100 .name
= "D-Link DIR-130",
1102 { .name
= "reset", .gpio
= 1 << 3},
1103 { .name
= "reserved", .gpio
= 1 << 7},
1106 { .name
= "diag", .gpio
= 1 << 0},
1107 { .name
= "blue", .gpio
= 1 << 6},
1111 .name
= "D-Link DIR-320",
1113 { .name
= "reserved", .gpio
= 1 << 6},
1114 { .name
= "reset", .gpio
= 1 << 7},
1117 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
1118 { .name
= "diag", .gpio
= 1 << 1, .polarity
= NORMAL
}, /* "status led */
1119 { .name
= "red", .gpio
= 1 << 3, .polarity
= REVERSE
},
1120 { .name
= "blue", .gpio
= 1 << 4, .polarity
= REVERSE
},
1121 { .name
= "usb", .gpio
= 1 << 5, .polarity
= NORMAL
},
1125 .name
= "D-Link DIR-330",
1127 { .name
= "reset", .gpio
= 1 << 3},
1128 { .name
= "reserved", .gpio
= 1 << 7},
1131 { .name
= "diag", .gpio
= 1 << 0},
1132 { .name
= "usb", .gpio
= 1 << 4},
1133 { .name
= "blue", .gpio
= 1 << 6},
1137 .name
= "D-Link DWL-3150",
1139 { .name
= "reset", .gpio
= 1 << 7},
1142 { .name
= "diag", .gpio
= 1 << 2},
1143 { .name
= "status", .gpio
= 1 << 1},
1148 .name
= "Sitecom WL-105b",
1150 { .name
= "reset", .gpio
= 1 << 10},
1153 { .name
= "wlan", .gpio
= 1 << 4},
1154 { .name
= "power", .gpio
= 1 << 3},
1157 /* Western Digital Net Center */
1159 .name
= "Western Digital NetCenter",
1161 { .name
= "power", .gpio
= 1 << 0},
1162 { .name
= "reset", .gpio
= 1 << 7},
1164 .platform_init
= NetCenter_init
,
1166 /* Askey (and clones) */
1168 .name
= "Askey RT210W",
1170 /* Power button is hard-wired to hardware reset */
1171 /* but is also connected to GPIO 7 (probably for bootloader recovery) */
1172 { .name
= "power", .gpio
= 1 << 7},
1175 /* These were verified and named based on Belkin F5D4230-4 v1112 */
1176 { .name
= "connected", .gpio
= 1 << 0, .polarity
= REVERSE
},
1177 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
1178 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
1182 .name
= "OvisLink WL-1600GL",
1184 { .name
= "reset", .gpio
= 1 << 3 },
1185 { .name
= "ses", .gpio
= 1 << 4 },
1188 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
1189 { .name
= "wps", .gpio
= 1 << 2, .polarity
= REVERSE
},
1190 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
1191 { .name
= "connected", .gpio
= 1 << 0, .polarity
= REVERSE
},
1196 .name
= "Microsoft MN-700",
1198 { .name
= "reset", .gpio
= 1 << 7 },
1201 { .name
= "power", .gpio
= 1 << 6, .polarity
= NORMAL
},
1206 .name
= "Edimax PS-1208MFG",
1208 { .name
= "reset", .gpio
= 1 << 4 },
1211 { .name
= "status", .gpio
= 1 << 1, .polarity
= NORMAL
},
1212 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
1217 .name
= "Huawei E970",
1219 { .name
= "reset", .gpio
= 1 << 6 },
1222 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
1227 static struct platform_t __init
*platform_detect_legacy(void)
1229 char *boardnum
, *boardtype
;
1231 if (strcmp(getvar("nvram_type"), "cfe") == 0)
1232 return &platforms
[WGT634U
];
1235 /* no easy model number, attempt to guess */
1236 boardnum
= getvar("boardnum");
1237 boardtype
= getvar("boardtype");
1239 if (!strcmp(boardnum
, "20070615")) { /* Linksys WRT600N v1/V1.1 */
1240 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "0") && !strcmp(getvar("switch_type"),"BCM5395"))
1241 return &platforms
[WRT600NV11
];
1243 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "0"))
1244 return &platforms
[WRT600N
];
1247 if (startswith(getvar("pmon_ver"), "CFE")) {
1248 /* CFE based - newer hardware */
1249 if (!strcmp(boardnum
, "42")) { /* Linksys */
1250 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "1"))
1251 return &platforms
[WRT350N
];
1253 if (!strcmp(boardtype
, "0x0101") && !strcmp(getvar("boot_ver"), "v3.6"))
1254 return &platforms
[WRT54G3G
];
1256 /* default to WRT54G if no boot_hw_model is set */
1257 if (nvram_get("boot_hw_model") == NULL
)
1258 return &platforms
[WRT54G
];
1260 if (!strcmp(boardnum
, "1024") && !strcmp(boardtype
, "0x0446"))
1261 return &platforms
[WAP54GV2
];
1263 if (!strcmp(boardnum
, "8") && !strcmp(boardtype
, "0x048e"))
1264 return &platforms
[WL1600GL
];
1267 if (!strcmp(boardnum
, "44") || !strcmp(boardnum
, "44\r")) {
1268 if (!strcmp(boardtype
,"0x0101") || !strcmp(boardtype
, "0x0101\r"))
1269 return &platforms
[TM2300V2
]; /* Dell TrueMobile 2300 v2 */
1272 if (!strcmp(boardnum
, "10496"))
1273 return &platforms
[USR5461
];
1275 if (!strcmp(getvar("boardtype"), "0x0101") && !strcmp(getvar("boardrev"), "0x10")) /* SE505V2 With Modified CFE */
1276 return &platforms
[SE505V2
];
1278 if (!strcmp(boardtype
, "0x048e") && !strcmp(getvar("boardrev"),"0x35") &&
1279 !strcmp(getvar("boardflags"), "0x750")) /* D-Link DIR-320 */
1280 return &platforms
[DIR320
];
1282 if (!strncmp(boardnum
, "TH",2) && !strcmp(boardtype
,"0x042f")) {
1283 return &platforms
[WDNetCenter
];
1286 if (!strcmp(boardtype
,"0x0472") && !strcmp(getvar("cardbus"), "1")) { /* Netgear WNR834B V1 and V2*/
1287 if (!strcmp(boardnum
, "08") || !strcmp(boardnum
, "8"))
1288 return &platforms
[WNR834BV1
];
1289 if (!strcmp(boardnum
, "01") || !strcmp(boardnum
, "1"))
1290 return &platforms
[WNR834BV2
];
1293 } else { /* PMON based - old stuff */
1294 if ((simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 9) &&
1295 (simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 30)) {
1296 return &platforms
[WR850GV1
];
1298 if (startswith(boardtype
, "bcm94710dev")) {
1299 if (!strcmp(boardnum
, "42"))
1300 return &platforms
[WRT54GV1
];
1301 if (simple_strtoul(boardnum
, NULL
, 0) == 2)
1302 return &platforms
[WAP54GV1
];
1304 /* MN-700 has also hardware_version 'WL500-...', so use boardnum */
1305 if (startswith(getvar("hardware_version"), "WL500-")) {
1306 if (!strcmp(getvar("boardnum"), "mn700"))
1307 return &platforms
[MN700
];
1309 return &platforms
[WL500G
];
1311 /* Sitecom WL-105b */
1312 if (startswith(boardnum
, "2") && simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 1)
1313 return &platforms
[WL105B
];
1315 /* unknown asus stuff, probably bcm4702 */
1316 if (startswith(boardnum
, "asusX"))
1317 return &platforms
[ASUS_4702
];
1319 /* bcm4702 based Askey RT210W clones, Including:
1320 * Askey RT210W (duh?)
1322 * Belkin F5D7230-4 before version v1444 (MiniPCI slot, not integrated)
1324 if (!strcmp(boardtype
,"bcm94710r4")
1325 && !strcmp(boardnum
,"100")
1326 && !strcmp(getvar("pmon_ver"),"v1.03.12.bk")
1328 return &platforms
[RT210W
];
1332 if (boardnum
|| !strcmp(boardnum
, "00")) {/* probably buffalo */
1333 if (startswith(boardtype
, "bcm94710ap"))
1334 return &platforms
[BUFFALO_UNKNOWN_4710
];
1337 if (startswith(getvar("CFEver"), "MotoWRv2") ||
1338 startswith(getvar("CFEver"), "MotoWRv3") ||
1339 !strcmp(getvar("MOTO_BOARD_TYPE"), "WR_FEM1")) {
1341 return &platforms
[WR850GV2V3
];
1344 if (!strcmp(boardnum
, "44") && !strcmp(getvar("boardflags"),"0x0388")) { /* Trendware TEW-411BRP+ */
1345 return &platforms
[TEW411BRPP
];
1348 if (startswith(boardnum
, "04FN")) /* SimpleTech SimpleShare */
1349 return &platforms
[STI_NAS
];
1351 if (!strcmp(boardnum
, "10") && !strcmp(getvar("boardrev"), "0x13")) /* D-Link DWL-3150 */
1352 return &platforms
[DWL3150
];
1354 if (!strcmp(boardnum
, "01") && !strcmp(boardtype
, "0x048e") && /* Edimax PS1208MFG */
1355 !strcmp(getvar("status_gpio"), "1")) /* gpio based detection */
1356 return &platforms
[PS1208MFG
];
1362 static struct platform_t __init
*platform_detect(void)
1364 enum bcm47xx_board board
;
1365 const char *board_name
;
1368 board
= bcm47xx_board_get();
1369 board_name
= bcm47xx_board_get_name();
1370 if (board
!= BCM47XX_BOARD_UNKNOWN
&& board
!= BCM47XX_BOARD_NO
)
1371 printk(MODULE_NAME
": kernel found a \"%s\"\n", board_name
);
1374 case BCM47XX_BOARD_ASUS_RTN12
:
1375 return &platforms
[RTN12
];
1376 case BCM47XX_BOARD_ASUS_RTN16
:
1377 return &platforms
[RTN16
];
1378 case BCM47XX_BOARD_ASUS_RTN66U
:
1379 return &platforms
[RTN66U
];
1380 case BCM47XX_BOARD_ASUS_WL300G
:
1381 return &platforms
[WL300G
];
1382 case BCM47XX_BOARD_ASUS_WL320GE
:
1383 return &platforms
[WL320GE
];
1384 case BCM47XX_BOARD_ASUS_WL330GE
:
1385 return &platforms
[WL330GE
];
1386 case BCM47XX_BOARD_ASUS_WL500GD
:
1387 return &platforms
[WL500GD
];
1388 case BCM47XX_BOARD_ASUS_WL500GPV1
:
1389 return &platforms
[WL500GP
];
1390 case BCM47XX_BOARD_ASUS_WL500GPV2
:
1391 return &platforms
[WL500GPV2
];
1392 case BCM47XX_BOARD_ASUS_WL500W
:
1393 return &platforms
[WL500W
];
1394 case BCM47XX_BOARD_ASUS_WL520GC
:
1395 return &platforms
[WL520GC
];
1396 case BCM47XX_BOARD_ASUS_WL520GU
:
1397 return &platforms
[WL520GU
];
1398 case BCM47XX_BOARD_ASUS_WL700GE
:
1399 return &platforms
[WL700GE
];
1400 case BCM47XX_BOARD_ASUS_WLHDD
:
1401 return &platforms
[WLHDD
];
1402 case BCM47XX_BOARD_BELKIN_F7D4301
:
1403 return &platforms
[BELKIN_F7D4301
];
1404 case BCM47XX_BOARD_BELKIN_F7D330X
:
1405 return &platforms
[BELKIN_F7D330X
];
1406 case BCM47XX_BOARD_BUFFALO_WBR2_G54
:
1407 return &platforms
[WBR2_G54
];
1408 case BCM47XX_BOARD_BUFFALO_WHR2_A54G54
:
1409 return &platforms
[WHR2_A54G54
];
1410 case BCM47XX_BOARD_BUFFALO_WHR_G125
:
1411 return &platforms
[WHR_G125
];
1412 case BCM47XX_BOARD_BUFFALO_WHR_G54S
:
1413 return &platforms
[WHR_G54S
];
1414 case BCM47XX_BOARD_BUFFALO_WHR_HP_G54
:
1415 return &platforms
[WHR_HP_G54
];
1416 case BCM47XX_BOARD_BUFFALO_WLA2_G54L
:
1417 return &platforms
[WLA2_G54L
];
1418 case BCM47XX_BOARD_BUFFALO_WZR_G300N
:
1419 return &platforms
[WZR_G300N
];
1420 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54
:
1421 return &platforms
[WZR_RS_G54
];
1422 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54HP
:
1423 return &platforms
[WZR_RS_G54HP
];
1424 case BCM47XX_BOARD_DELL_TM2300
:
1425 return &platforms
[TM2300
];
1426 case BCM47XX_BOARD_DLINK_DIR130
:
1427 return &platforms
[DIR130
];
1428 case BCM47XX_BOARD_DLINK_DIR330
:
1429 return &platforms
[DIR330
];
1430 case BCM47XX_BOARD_HUAWEI_E970
:
1431 return &platforms
[HUAWEI_E970
];
1432 case BCM47XX_BOARD_LINKSYS_E1000V1
:
1433 return &platforms
[E1000V1
];
1434 case BCM47XX_BOARD_LINKSYS_E1000V21
:
1435 return &platforms
[E1000V21
];
1436 case BCM47XX_BOARD_LINKSYS_E2000V1
:
1437 return &platforms
[E2000V1
];
1438 case BCM47XX_BOARD_LINKSYS_E3000V1
:
1439 return &platforms
[E3000V1
];
1440 case BCM47XX_BOARD_LINKSYS_E3200V1
:
1441 return &platforms
[E3200V1
];
1442 case BCM47XX_BOARD_LINKSYS_E4200V1
:
1443 return &platforms
[E4200V1
];
1444 case BCM47XX_BOARD_LINKSYS_WRT150NV1
:
1445 return &platforms
[WRT150NV1
];
1446 case BCM47XX_BOARD_LINKSYS_WRT150NV11
:
1447 return &platforms
[WRT150NV11
];
1448 case BCM47XX_BOARD_LINKSYS_WRT160NV1
:
1449 return &platforms
[WRT160NV1
];
1450 case BCM47XX_BOARD_LINKSYS_WRT160NV3
:
1451 return &platforms
[WRT160NV3
];
1452 case BCM47XX_BOARD_LINKSYS_WRT300NV11
:
1453 return &platforms
[WRT300NV11
];
1454 case BCM47XX_BOARD_LINKSYS_WRT310NV1
:
1455 return &platforms
[WRT310NV1
];
1456 case BCM47XX_BOARD_LINKSYS_WRT54GSV1
:
1457 return &platforms
[WRT54G
];
1458 case BCM47XX_BOARD_LINKSYS_WRT54G3GV2
:
1459 return &platforms
[WRT54G3GV2_VF
];
1460 case BCM47XX_BOARD_LINKSYS_WRT610NV1
:
1461 return &platforms
[WRT610N
];
1462 case BCM47XX_BOARD_LINKSYS_WRT610NV2
:
1463 return &platforms
[WRT610NV2
];
1464 case BCM47XX_BOARD_LINKSYS_WRTSL54GS
:
1465 return &platforms
[WRTSL54GS
];
1466 case BCM47XX_BOARD_MOTOROLA_WE800G
:
1467 return &platforms
[WE800G
];
1468 case BCM47XX_BOARD_MOTOROLA_WR850GP
:
1469 return &platforms
[WR850GP
];
1470 case BCM47XX_BOARD_MOTOROLA_WR850GV2V3
:
1471 return &platforms
[WR850GV2V3
];
1472 case BCM47XX_BOARD_NETGEAR_WNDR3400V1
:
1473 return &platforms
[WNDR3400V1
];
1474 case BCM47XX_BOARD_NETGEAR_WNDR3700V3
:
1475 return &platforms
[WNDR3700V3
];
1476 case BCM47XX_BOARD_UNKNOWN
:
1477 case BCM47XX_BOARD_NO
:
1478 printk(MODULE_NAME
": unknown board found, try legacy detect\n");
1479 printk(MODULE_NAME
": please open a ticket at https://dev.openwrt.org and attach the complete nvram\n");
1480 return platform_detect_legacy();
1482 printk(MODULE_NAME
": board was detected as \"%s\", but not gpio configuration available\n", board_name
);
1483 printk(MODULE_NAME
": now trying legacy detect\n");
1484 return platform_detect_legacy();
1488 static inline void ssb_maskset32(struct ssb_device
*dev
,
1489 u16 offset
, u32 mask
, u32 set
)
1491 ssb_write32(dev
, offset
, (ssb_read32(dev
, offset
) & mask
) | set
);
1494 static void gpio_set_irqenable(int enabled
, irqreturn_t (*handler
)(int, void *))
1499 irq
= gpio_to_irq(0);
1501 pr_err("no irq for gpio available\n");
1506 err
= request_irq(irq
, handler
, IRQF_SHARED
, "gpio", handler
);
1508 pr_err("can not reqeust irq\n");
1512 free_irq(irq
, handler
);
1515 switch (bcm47xx_bus_type
) {
1516 #ifdef CONFIG_BCM47XX_SSB
1517 case BCM47XX_BUS_TYPE_SSB
:
1518 if (bcm47xx_bus
.ssb
.chipco
.dev
)
1519 ssb_maskset32(bcm47xx_bus
.ssb
.chipco
.dev
, SSB_CHIPCO_IRQMASK
, ~SSB_CHIPCO_IRQ_GPIO
, (enabled
? SSB_CHIPCO_IRQ_GPIO
: 0));
1522 #ifdef CONFIG_BCM47XX_BCMA
1523 case BCM47XX_BUS_TYPE_BCMA
:
1524 if (bcm47xx_bus
.bcma
.bus
.drv_cc
.core
)
1525 bcma_maskset32(bcm47xx_bus
.bcma
.bus
.drv_cc
.core
, BCMA_CC_IRQMASK
, ~BCMA_CC_IRQ_GPIO
, (enabled
? BCMA_CC_IRQ_GPIO
: 0));
1531 static void hotplug_button(struct work_struct
*work
)
1533 struct event_t
*event
= container_of(work
, struct event_t
, wq
);
1536 event
->skb
= alloc_skb(2048, GFP_KERNEL
);
1538 s
= skb_put(event
->skb
, strlen(event
->action
) + 2);
1539 sprintf(s
, "%s@", event
->action
);
1542 NETLINK_CB(event
->skb
).dst_group
= 1;
1543 broadcast_uevent(event
->skb
, 0, 1, GFP_KERNEL
);
1548 static irqreturn_t
button_handler(int irq
, void *dev_id
)
1553 in
= bcm47xx_gpio_in(~0) & platform
.button_mask
;
1554 bcm47xx_gpio_polarity(platform
.button_mask
, in
);
1555 changed
= platform
.button_polarity
^ in
;
1556 platform
.button_polarity
= in
;
1558 changed
&= ~bcm47xx_gpio_outen(0, 0);
1560 for (b
= platform
.buttons
; b
->name
; b
++) {
1561 struct event_t
*event
;
1563 if (!(b
->gpio
& changed
)) continue;
1567 if ((event
= (struct event_t
*)kzalloc (sizeof(struct event_t
), GFP_ATOMIC
))) {
1568 event
->seen
= (jiffies
- b
->seen
)/HZ
;
1569 event
->name
= b
->name
;
1570 event
->action
= b
->pressed
? "pressed" : "released";
1571 INIT_WORK(&event
->wq
, (void *)(void *)hotplug_button
);
1572 schedule_work(&event
->wq
);
1580 static void register_buttons(struct button_t
*b
)
1582 for (; b
->name
; b
++)
1583 platform
.button_mask
|= b
->gpio
;
1585 platform
.button_mask
&= ~gpiomask
;
1587 bcm47xx_gpio_outen(platform
.button_mask
, 0);
1588 bcm47xx_gpio_control(platform
.button_mask
, 0);
1589 platform
.button_polarity
= bcm47xx_gpio_in(~0) & platform
.button_mask
;
1590 bcm47xx_gpio_polarity(platform
.button_mask
, platform
.button_polarity
);
1591 bcm47xx_gpio_intmask(platform
.button_mask
, platform
.button_mask
);
1593 gpio_set_irqenable(1, button_handler
);
1596 static void unregister_buttons(struct button_t
*b
)
1598 bcm47xx_gpio_intmask(platform
.button_mask
, 0);
1600 gpio_set_irqenable(0, button_handler
);
1604 static void add_msg(struct event_t
*event
, char *msg
, int argv
)
1611 s
= skb_put(event
->skb
, strlen(msg
) + 1);
1615 static int fill_event (struct event_t
*event
)
1617 static char buf
[128];
1619 add_msg(event
, "HOME=/", 0);
1620 add_msg(event
, "PATH=/sbin:/bin:/usr/sbin:/usr/bin", 0);
1621 add_msg(event
, "SUBSYSTEM=button", 0);
1622 snprintf(buf
, 128, "ACTION=%s", event
->action
);
1623 add_msg(event
, buf
, 0);
1624 snprintf(buf
, 128, "BUTTON=%s", event
->name
);
1625 add_msg(event
, buf
, 0);
1626 snprintf(buf
, 128, "SEEN=%ld", event
->seen
);
1627 add_msg(event
, buf
, 0);
1628 snprintf(buf
, 128, "SEQNUM=%llu", uevent_next_seqnum());
1629 add_msg(event
, buf
, 0);
1635 * This should be extended to allow the platform to specify the pins and width
1636 * of the shift register. They're hardcoded for now because only the WNDR3700v3
1639 static void shiftreg_output(unsigned int val
)
1643 bcm47xx_gpio_out(SHIFTREG_DATA
, SHIFTREG_DATA
); /* init off, pull high */
1644 bcm47xx_gpio_out(SHIFTREG_CLK
, 0); /* init reset */
1647 for(mask
= 1 << (SHIFTREG_MAX_BITS
-1); mask
; mask
>>= 1)
1649 bcm47xx_gpio_out(SHIFTREG_DATA
, (val
& mask
) ? SHIFTREG_DATA
: 0);
1650 bcm47xx_gpio_out(SHIFTREG_CLK
, SHIFTREG_CLK
); /* pull high to trigger */
1651 bcm47xx_gpio_out(SHIFTREG_CLK
, 0); /* reset to low */
1655 static void set_led_shift(struct led_t
*led
)
1657 static u32 shiftreg
= 0;
1659 u32 pin
= (led
->gpio
& ~GPIO_TYPE_MASK
);
1667 /* Clock the bits out. */
1668 if (shiftreg
!= old
) {
1669 shiftreg_output(shiftreg
);
1673 static void set_led_extif(struct led_t
*led
)
1675 volatile u8
*addr
= (volatile u8
*) KSEG1ADDR(EXTIF_UART
) + (led
->gpio
& ~GPIO_TYPE_MASK
);
1683 static void led_flash(unsigned long dummy
) {
1688 for (l
= platform
.leds
; l
->name
; l
++) {
1689 if (!l
->flash
) continue;
1690 switch (l
->gpio
& GPIO_TYPE_MASK
) {
1691 case GPIO_TYPE_EXTIF
:
1693 l
->state
= !l
->state
;
1696 case GPIO_TYPE_SHIFT
:
1698 l
->state
= !l
->state
;
1701 case GPIO_TYPE_NORMAL
:
1710 u32 val
= ~bcm47xx_gpio_in(~0);
1712 bcm47xx_gpio_outen(mask
, mask
);
1713 bcm47xx_gpio_control(mask
, 0);
1714 bcm47xx_gpio_out(mask
, val
);
1716 if (mask
|| extif_blink
) {
1717 mod_timer(&led_timer
, jiffies
+ FLASH_TIME
);
1721 static int diag_led_show(struct seq_file
*m
, void *v
)
1723 struct led_t
* led
= m
->private;
1725 u8 p
= (led
->polarity
== NORMAL
? 0 : 1);
1727 return seq_printf(m
, "f\n");
1728 } else if ((led
->gpio
& GPIO_TYPE_MASK
) != GPIO_TYPE_NORMAL
) {
1729 return seq_printf(m
, "%d\n", ((led
->state
^ p
) ? 1 : 0));
1731 u32 in
= (bcm47xx_gpio_in(~0) & led
->gpio
? 1 : 0);
1732 return seq_printf(m
, "%d\n", ((in
^ p
) ? 1 : 0));
1736 static int diag_led_open(struct inode
*inode
, struct file
*file
)
1738 return single_open(file
, diag_led_show
, PDE_DATA(inode
));
1741 static ssize_t
diag_led_write(struct file
*file
, const char __user
*buf
, size_t count
, loff_t
*ppos
)
1743 struct led_t
*led
= PDE_DATA(file_inode(file
));
1748 len
= min(count
, sizeof(cmd
) - 1);
1749 if (copy_from_user(cmd
, buf
, len
))
1754 p
= (led
->polarity
== NORMAL
? 0 : 1);
1755 if (cmd
[0] == 'f') {
1760 if ((led
->gpio
& GPIO_TYPE_MASK
) == GPIO_TYPE_EXTIF
) {
1761 led
->state
= p
^ ((cmd
[0] == '1') ? 1 : 0);
1763 } else if ((led
->gpio
& GPIO_TYPE_MASK
) == GPIO_TYPE_SHIFT
) {
1764 led
->state
= p
^ ((cmd
[0] == '1') ? 1 : 0);
1767 bcm47xx_gpio_outen(led
->gpio
, led
->gpio
);
1768 bcm47xx_gpio_control(led
->gpio
, 0);
1769 bcm47xx_gpio_out(led
->gpio
, ((p
^ (cmd
[0] == '1')) ? led
->gpio
: 0));
1775 static const struct file_operations diag_led_fops
= {
1776 .open
= diag_led_open
,
1778 .llseek
= seq_lseek
,
1779 .write
= diag_led_write
1782 static void register_leds(struct led_t
*l
)
1784 struct proc_dir_entry
*p
;
1789 leds
= proc_mkdir("led", diag
);
1793 for(; l
->name
; l
++) {
1794 if (l
->gpio
& gpiomask
)
1797 switch (l
->gpio
& GPIO_TYPE_MASK
) {
1798 case GPIO_TYPE_EXTIF
:
1802 case GPIO_TYPE_SHIFT
:
1803 mask
|= (SHIFTREG_DATA
| SHIFTREG_CLK
);
1804 oe_mask
|= (SHIFTREG_DATA
| SHIFTREG_CLK
);
1805 l
->state
= (l
->polarity
!= NORMAL
);
1808 case GPIO_TYPE_NORMAL
:
1810 if (l
->polarity
!= INPUT
) oe_mask
|= l
->gpio
;
1812 val
|= (l
->polarity
== NORMAL
)?0:l
->gpio
;
1816 if (l
->polarity
== INPUT
) continue;
1818 p
= proc_create_data(l
->name
, S_IRUSR
, leds
, &diag_led_fops
, l
);
1821 bcm47xx_gpio_outen(mask
, oe_mask
);
1822 bcm47xx_gpio_control(mask
, 0);
1823 bcm47xx_gpio_out(mask
, val
);
1824 bcm47xx_gpio_intmask(mask
, 0);
1827 static void unregister_leds(struct led_t
*l
)
1830 remove_proc_entry(l
->name
, leds
);
1832 remove_proc_entry("led", diag
);
1835 static int diag_model_show(struct seq_file
*m
, void *v
)
1837 return seq_printf(m
, "%s\n", platform
.name
);
1840 static int diag_model_open(struct inode
*inode
, struct file
*file
)
1842 return single_open(file
, diag_model_show
, PDE_DATA(inode
));
1845 static const struct file_operations diag_model_fops
= {
1846 .open
= diag_model_open
,
1851 static int diag_gpiomask_show(struct seq_file
*m
, void *v
)
1853 return seq_printf(m
, "0x%04x\n", gpiomask
);
1856 static int diag_gpiomask_open(struct inode
*inode
, struct file
*file
)
1858 return single_open(file
, diag_gpiomask_show
, PDE_DATA(inode
));
1861 static ssize_t
diag_gpiomask_write(struct file
*file
, const char __user
*buf
, size_t count
, loff_t
*ppos
)
1863 int err
= kstrtouint_from_user(buf
, count
, 0, &gpiomask
);
1867 if (platform
.buttons
) {
1868 unregister_buttons(platform
.buttons
);
1869 register_buttons(platform
.buttons
);
1872 if (platform
.leds
) {
1873 unregister_leds(platform
.leds
);
1874 register_leds(platform
.leds
);
1880 static const struct file_operations diag_gpiomask_fops
= {
1881 .open
= diag_gpiomask_open
,
1883 .llseek
= seq_lseek
,
1884 .write
= diag_gpiomask_write
1887 static int __init
diag_init(void)
1889 static struct proc_dir_entry
*p
;
1890 static struct platform_t
*detected
;
1892 detected
= platform_detect();
1894 printk(MODULE_NAME
": Router model not detected.\n");
1897 memcpy(&platform
, detected
, sizeof(struct platform_t
));
1899 printk(MODULE_NAME
": Detected '%s'\n", platform
.name
);
1900 if (platform
.platform_init
!= NULL
) {
1901 platform
.platform_init();
1904 if (!(diag
= proc_mkdir("diag", NULL
))) {
1905 printk(MODULE_NAME
": proc_mkdir on /proc/diag failed\n");
1909 p
= proc_create("model", S_IRUSR
, diag
, &diag_model_fops
);
1911 remove_proc_entry("diag", NULL
);
1915 p
= proc_create("gpiomask", S_IRUSR
| S_IWUSR
, diag
, &diag_gpiomask_fops
);
1917 remove_proc_entry("model", diag
);
1918 remove_proc_entry("diag", NULL
);
1922 if (platform
.buttons
)
1923 register_buttons(platform
.buttons
);
1926 register_leds(platform
.leds
);
1931 static void __exit
diag_exit(void)
1933 del_timer(&led_timer
);
1935 if (platform
.buttons
)
1936 unregister_buttons(platform
.buttons
);
1939 unregister_leds(platform
.leds
);
1941 remove_proc_entry("model", diag
);
1942 remove_proc_entry("gpiomask", diag
);
1943 remove_proc_entry("diag", NULL
);
1946 module_init(diag_init
);
1947 module_exit(diag_exit
);
1949 MODULE_AUTHOR("Mike Baker, Felix Fietkau / OpenWrt.org");
1950 MODULE_LICENSE("GPL");