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,
172 /* Western Digital */
191 static void __init bcm4780_init(void) {
194 /* Enables GPIO 3 that controls HDD and led power on ASUS WL-700gE */
195 printk(MODULE_NAME ": Spinning up HDD and enabling leds\n");
196 bcm47xx_gpio_outen(pin, pin);
197 bcm47xx_gpio_control(pin, 0);
198 bcm47xx_gpio_out(pin, pin);
200 /* Wait 5s, so the HDD can spin up */
201 set_current_state(TASK_INTERRUPTIBLE);
202 schedule_timeout(HZ * 5);
205 static void __init NetCenter_init(void) {
206 /* unset pin 6 (+12V) */
208 bcm47xx_gpio_outen(pin, pin);
209 bcm47xx_gpio_control(pin, 0);
210 bcm47xx_gpio_out(pin, pin);
211 /* unset pin 1 (turn off red led, blue will light alone if +5V comes up) */
213 bcm47xx_gpio_outen(pin, pin);
214 bcm47xx_gpio_control(pin, 0);
215 bcm47xx_gpio_out(pin, pin);
216 /* unset pin 3 (+5V) and wait 5 seconds (harddisk spin up) */
220 static void __init bcm57xx_init(void) {
223 /* FIXME: switch comes up, but port mappings/vlans not right */
224 bcm47xx_gpio_outen(pin, pin);
225 bcm47xx_gpio_control(pin, 0);
226 bcm47xx_gpio_out(pin, pin);
229 static struct platform_t __initdata platforms[] = {
232 .name = "Linksys WAP54G V1",
234 { .name = "reset", .gpio = 1 << 0 },
237 { .name = "diag", .gpio = 1 << 3 },
238 { .name = "wlan", .gpio = 1 << 4 },
242 .name = "Linksys WAP54G V2",
244 { .name = "reset", .gpio = 1 << 0 },
247 { .name = "wlan", .gpio = 1 << 5, .polarity = REVERSE },
248 /* GPIO 6 is b44 (eth0, LAN) PHY power */
252 .name = "Linksys WAP54G V3",
254 /* FIXME: verify this */
255 { .name = "reset", .gpio = 1 << 7 },
256 { .name = "ses", .gpio = 1 << 0 },
260 { .name = "ses", .gpio = 1 << 1 },
264 .name = "Linksys WRT54G V1.x",
266 { .name = "reset", .gpio = 1 << 6 },
269 { .name = "diag", .gpio = 0x13 | GPIO_TYPE_EXTIF, .polarity = NORMAL },
270 { .name = "dmz", .gpio = 0x12 | GPIO_TYPE_EXTIF, .polarity = NORMAL },
274 .name = "Linksys WRT54G/GS/GL",
276 { .name = "reset", .gpio = 1 << 6 },
277 { .name = "ses", .gpio = 1 << 4 },
280 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
281 { .name = "dmz", .gpio = 1 << 7, .polarity = REVERSE },
282 { .name = "ses_white", .gpio = 1 << 2, .polarity = REVERSE },
283 { .name = "ses_orange", .gpio = 1 << 3, .polarity = REVERSE },
284 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
288 .name = "Linksys WRTSL54GS",
290 { .name = "reset", .gpio = 1 << 6 },
291 { .name = "ses", .gpio = 1 << 4 },
294 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
295 { .name = "dmz", .gpio = 1 << 0, .polarity = REVERSE },
296 { .name = "ses_white", .gpio = 1 << 5, .polarity = REVERSE },
297 { .name = "ses_orange", .gpio = 1 << 7, .polarity = REVERSE },
301 .name = "Linksys WRT54G3G",
303 { .name = "reset", .gpio = 1 << 6 },
304 { .name = "3g", .gpio = 1 << 4 },
307 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
308 { .name = "dmz", .gpio = 1 << 7, .polarity = REVERSE },
309 { .name = "3g_green", .gpio = 1 << 2, .polarity = NORMAL },
310 { .name = "3g_blue", .gpio = 1 << 3, .polarity = NORMAL },
311 { .name = "3g_blink", .gpio = 1 << 5, .polarity = NORMAL },
315 .name = "Linksys WRT54G3GV2-VF",
317 { .name = "reset", .gpio = 1 << 6 },
318 { .name = "3g", .gpio = 1 << 5 },
321 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
322 { .name = "3g_green", .gpio = 1 << 2, .polarity = NORMAL },
323 { .name = "3g_blue", .gpio = 1 << 3, .polarity = NORMAL },
327 .name = "Linksys WRT150N V1",
329 { .name = "reset", .gpio = 1 << 6 },
330 { .name = "ses", .gpio = 1 << 4 },
333 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
334 { .name = "ses_green", .gpio = 1 << 5, .polarity = REVERSE },
335 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE },
339 .name = "Linksys WRT150N V1.1",
341 { .name = "reset", .gpio = 1 << 6 },
342 { .name = "ses", .gpio = 1 << 4 },
345 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
346 { .name = "ses_green", .gpio = 1 << 5, .polarity = REVERSE },
347 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE },
351 .name = "Linksys WRT160N v1.x",
353 { .name = "reset", .gpio = 1 << 6 },
354 { .name = "ses", .gpio = 1 << 4 },
357 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
358 { .name = "ses_blue", .gpio = 1 << 5, .polarity = REVERSE },
359 { .name = "ses_orange", .gpio = 1 << 3, .polarity = REVERSE },
363 .name = "Linksys WRT160N V3",
365 { .name = "reset", .gpio = 1 << 6 },
366 { .name = "ses", .gpio = 1 << 5 },
369 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
370 { .name = "ses_blue", .gpio = 1 << 4, .polarity = REVERSE },
371 { .name = "ses_orange", .gpio = 1 << 2, .polarity = REVERSE },
375 .name = "Linksys WRT300N V1.1",
377 { .name = "reset", .gpio = 1 << 6 }, // "Reset" on back panel
378 { .name = "ses", .gpio = 1 << 4 }, // "Reserved" on top panel
381 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL }, // "Power"
382 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE }, // "Security" Amber
383 { .name = "ses_green", .gpio = 1 << 5, .polarity = REVERSE }, // "Security" Green
385 .platform_init = bcm57xx_init,
388 .name = "Linksys WRT310N V1",
390 { .name = "reset", .gpio = 1 << 6 }, // "Reset" on back panel
391 { .name = "ses", .gpio = 1 << 8 }, // "Reserved" on top panel
394 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL }, // Power LED
395 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE }, // "Security" Amber
396 { .name = "ses_blue", .gpio = 1 << 9, .polarity = REVERSE }, // "Security" Blue
400 .name = "Linksys WRT350N",
402 { .name = "reset", .gpio = 1 << 6 },
403 { .name = "ses", .gpio = 1 << 8 },
406 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
407 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE },
408 { .name = "ses_green", .gpio = 1 << 9, .polarity = REVERSE },
409 { .name = "usb_blink", .gpio = 1 << 10, .polarity = REVERSE },
410 { .name = "usb", .gpio = 1 << 11, .polarity = REVERSE },
412 .platform_init = bcm57xx_init,
415 .name = "Linksys WRT600N",
417 { .name = "reset", .gpio = 1 << 6 },
418 { .name = "ses", .gpio = 1 << 7 },
421 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE }, // Power LED
422 { .name = "usb", .gpio = 1 << 3, .polarity = REVERSE }, // USB LED
423 { .name = "wl0_ses_amber", .gpio = 1 << 8, .polarity = REVERSE }, // 2.4Ghz LED Amber
424 { .name = "wl0_ses_green", .gpio = 1 << 9, .polarity = REVERSE }, // 2.4Ghz LED Green
425 { .name = "wl1_ses_amber", .gpio = 1 << 10, .polarity = REVERSE }, // 5.6Ghz LED Amber
426 { .name = "wl1_ses_green", .gpio = 1 << 11, .polarity = REVERSE }, // 5.6Ghz LED Green
428 .platform_init = bcm57xx_init,
431 .name = "Linksys WRT600N V1.1",
433 { .name = "reset", .gpio = 1 << 6 },
434 { .name = "ses", .gpio = 1 << 7 },
437 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE }, // Power LED
438 { .name = "usb", .gpio = 1 << 3, .polarity = REVERSE }, // USB LED
439 { .name = "wl0_ses_amber", .gpio = 1 << 8, .polarity = REVERSE }, // 2.4Ghz LED Amber
440 { .name = "wl0_ses_green", .gpio = 1 << 9, .polarity = REVERSE }, // 2.4Ghz LED Green
441 { .name = "wl1_ses_amber", .gpio = 1 << 10, .polarity = REVERSE }, // 5.6Ghz LED Amber
442 { .name = "wl1_ses_green", .gpio = 1 << 11, .polarity = REVERSE }, // 5.6Ghz LED Green
444 .platform_init = bcm57xx_init,
447 .name = "Linksys WRT610N",
449 { .name = "reset", .gpio = 1 << 6 },
450 { .name = "ses", .gpio = 1 << 8 },
453 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL }, // Power LED
454 { .name = "usb", .gpio = 1 << 0, .polarity = REVERSE }, // USB LED
455 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE }, // WiFi protected setup LED amber
456 { .name = "ses_blue", .gpio = 1 << 9, .polarity = REVERSE }, // WiFi protected setup LED blue
460 .name = "Linksys WRT610N V2",
462 { .name = "reset", .gpio = 1 << 6 },
463 { .name = "ses", .gpio = 1 << 4 },
466 { .name = "power", .gpio = 1 << 5, .polarity = NORMAL }, // Power LED
467 { .name = "usb", .gpio = 1 << 7, .polarity = NORMAL }, // USB LED
468 { .name = "ses_amber", .gpio = 1 << 0, .polarity = REVERSE }, // WiFi protected setup LED amber
469 { .name = "ses_blue", .gpio = 1 << 3, .polarity = REVERSE }, // WiFi protected setup LED blue
470 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL }, // Wireless LED
473 /* same hardware as WRT160NV3 and Cisco Valet M10V1, but different board detection, combine? */
475 .name = "Linksys E1000 V1",
477 { .name = "reset", .gpio = 1 << 6 },
478 { .name = "wps", .gpio = 1 << 5 }, /* nvram get gpio5=wps_button */
481 /** turns on leds for all ethernet ports (wan too)
482 * this also disconnects some, or maybe all, ethernet ports
483 * 1: leds work normally
484 * 0: all lit all the time */
485 /* nvram get gpio3=robo_reset */
486 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
487 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
488 { .name = "ses_blue", .gpio = 1 << 4, .polarity = REVERSE }, /* nvram get gpio4=wps_led */
489 { .name = "ses_orange", .gpio = 1 << 2, .polarity = REVERSE }, /* nvram get gpio2=wps_status_led */
493 .name = "Linksys E1000 V2.1",
495 { .name = "reset", .gpio = 1 << 10 }, /* nvram get reset_gpio=10 */
496 { .name = "wps", .gpio = 1 << 9 }, /* nvram get gpio9=wps_button */
499 { .name = "power", .gpio = 1 << 6, .polarity = REVERSE },
500 { .name = "wlan", .gpio = 1 << 5, .polarity = NORMAL },
501 { .name = "ses_blue", .gpio = 1 << 8, .polarity = NORMAL }, /* nvram get gpio8=wps_led */
502 { .name = "ses_orange", .gpio = 1 << 7, .polarity = NORMAL }, /* nvram get gpio7=wps_status_led */
506 .name = "Linksys E2000 V1",
508 { .name = "reset", .gpio = 1 << 8 },
509 { .name = "ses", .gpio = 1 << 5 },
512 { .name = "power", .gpio = 1 << 2, .polarity = NORMAL },
513 { .name = "ses_amber", .gpio = 1 << 4, .polarity = REVERSE },
514 { .name = "ses_blue", .gpio = 1 << 3, .polarity = REVERSE },
515 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL },
519 .name = "Linksys E3000 V1",
521 { .name = "reset", .gpio = 1 << 6 },
522 { .name = "ses", .gpio = 1 << 4 },
525 { .name = "power", .gpio = 1 << 5, .polarity = NORMAL }, // Power LED
526 { .name = "usb", .gpio = 1 << 7, .polarity = NORMAL }, // USB LED
527 { .name = "ses_amber", .gpio = 1 << 0, .polarity = REVERSE }, // WiFi protected setup LED amber
528 { .name = "ses_blue", .gpio = 1 << 3, .polarity = REVERSE }, // WiFi protected setup LED blue
529 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL }, // Wireless LED
533 .name = "Linksys E3200 V1",
535 /* { .name = "switch", .gpio = 1 << 4 },*/ /* nvram get gpio4=robo_reset */
536 { .name = "reset", .gpio = 1 << 5 }, /* nvram get reset_gpio=5 */
537 { .name = "wps", .gpio = 1 << 8 }, /* nvram get gpio8=wps_button */
538 /* { .name = "wombo", .gpio = 1 << 23 },*/ /* nvram get gpio23=wombo_reset - wireless on motherboard */
541 { .name = "power", .gpio = 1 << 3, .polarity = REVERSE }, /* Power LED */
545 .name = "Linksys E4200 V1",
547 { .name = "reset", .gpio = 1 << 6 },
548 { .name = "wps", .gpio = 1 << 4 },
551 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
556 .name = "ASUS WL-HDD",
558 { .name = "reset", .gpio = 1 << 6 },
561 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
562 { .name = "usb", .gpio = 1 << 2, .polarity = REVERSE },
566 .name = "ASUS WL-300g",
568 { .name = "reset", .gpio = 1 << 6 },
571 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
575 .name = "ASUS WL-320gE/WL-320gP",
577 { .name = "reset", .gpio = 1 << 6 },
580 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
581 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE },
582 { .name = "link", .gpio = 1 << 11, .polarity = REVERSE },
586 .name = "ASUS WL-330gE",
588 { .name = "reset", .gpio = 1 << 2 },
591 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
595 .name = "ASUS WL-500g",
597 { .name = "reset", .gpio = 1 << 6 },
600 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
604 .name = "ASUS WL-500g Deluxe",
606 { .name = "reset", .gpio = 1 << 6 },
609 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
613 .name = "ASUS WL-500g Premium",
615 { .name = "reset", .gpio = 1 << 0 },
616 { .name = "ses", .gpio = 1 << 4 },
619 { .name = "power", .gpio = 1 << 1, .polarity = REVERSE },
623 .name = "ASUS WL-500g Premium V2",
625 { .name = "reset", .gpio = 1 << 2 },
626 { .name = "ses", .gpio = 1 << 3 },
629 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
630 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
634 .name = "ASUS WL-500W",
636 { .name = "reset", .gpio = 1 << 6 },
637 { .name = "ses", .gpio = 1 << 7 },
640 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
644 .name = "ASUS WL-520GC",
646 { .name = "reset", .gpio = 1 << 2 },
647 { .name = "ses", .gpio = 1 << 3 },
650 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
651 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
655 .name = "ASUS WL-520gU",
657 { .name = "reset", .gpio = 1 << 2 },
658 { .name = "ses", .gpio = 1 << 3 },
661 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
662 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
666 .name = "ASUS (unknown, BCM4702)",
668 { .name = "reset", .gpio = 1 << 6 },
671 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
675 .name = "ASUS WL-700gE",
677 { .name = "reset", .gpio = 1 << 7 }, // on back, hardwired, always resets device regardless OS state
678 { .name = "ses", .gpio = 1 << 4 }, // on back, actual name ezsetup
679 { .name = "power", .gpio = 1 << 0 }, // on front
680 { .name = "copy", .gpio = 1 << 6 }, // on front
684 // GPIO that controls power led also enables/disables some essential functions
687 { .name = "power", .gpio = 1 << 3, .polarity = NORMAL }, // actual name power
689 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE }, // actual name ready
691 .platform_init = bcm4780_init,
694 .name = "ASUS RT-N12",
696 { .name = "wps", .gpio = 1 << 0 },
697 { .name = "reset", .gpio = 1 << 1 },
698 // this is the router/repeater/ap switch
699 { .name = "sw1", .gpio = 1 << 4 },
700 { .name = "sw2", .gpio = 1 << 5 },
701 { .name = "sw3", .gpio = 1 << 6 },
704 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE },
705 { .name = "wlan", .gpio = 1 << 7, .polarity = NORMAL },
706 // gpio3 forces WAN and LAN1-4 all on
707 //{ .name = "eth", .gpio = 1 << 3, .polarity = REVERSE },
711 .name = "ASUS RT-N16",
713 { .name = "reset", .gpio = 1 << 8 },
714 { .name = "ses", .gpio = 1 << 6 },
717 { .name = "power", .gpio = 1 << 1, .polarity = REVERSE },
718 { .name = "wlan", .gpio = 1 << 7, .polarity = NORMAL },
722 .name = "ASUS RT-N66U",
724 { .name = "reset", .gpio = 1 << 9 },
725 { .name = "wps", .gpio = 1 << 4 },
728 { .name = "power", .gpio = 1 << 12, .polarity = REVERSE },
729 { .name = "usb", .gpio = 1 << 15, .polarity = REVERSE },
734 .name = "Buffalo WHR-G54S",
736 { .name = "reset", .gpio = 1 << 4 },
737 { .name = "bridge", .gpio = 1 << 5 },
738 { .name = "ses", .gpio = 1 << 0 },
741 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
742 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
743 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
744 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
745 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
749 .name = "Buffalo WBR2-G54",
752 { .name = "reset", .gpio = 1 << 7 },
755 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
759 .name = "Buffalo WHR-HP-G54",
761 { .name = "reset", .gpio = 1 << 4 },
762 { .name = "bridge", .gpio = 1 << 5 },
763 { .name = "ses", .gpio = 1 << 0 },
766 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
767 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
768 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
769 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
770 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
774 .name = "Buffalo WHR-G125",
776 { .name = "reset", .gpio = 1 << 4 },
777 { .name = "bridge", .gpio = 1 << 5 },
778 { .name = "ses", .gpio = 1 << 0 },
781 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
782 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
783 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
784 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
785 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
789 .name = "Buffalo WHR2-A54G54",
791 { .name = "reset", .gpio = 1 << 4 },
794 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
798 .name = "Buffalo WLA2-G54L",
801 { .name = "reset", .gpio = 1 << 7 },
804 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
808 .name = "Buffalo WZR-G300N",
810 { .name = "reset", .gpio = 1 << 4 },
813 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
814 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
815 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
819 .name = "Buffalo WZR-RS-G54",
821 { .name = "ses", .gpio = 1 << 0 },
822 { .name = "reset", .gpio = 1 << 4 },
825 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
826 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
827 { .name = "vpn", .gpio = 1 << 1, .polarity = REVERSE },
831 .name = "Buffalo WZR-RS-G54HP",
833 { .name = "ses", .gpio = 1 << 0 },
834 { .name = "reset", .gpio = 1 << 4 },
837 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
838 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
839 { .name = "vpn", .gpio = 1 << 1, .polarity = REVERSE },
842 [BUFFALO_UNKNOWN_4710] = {
843 .name = "Buffalo (unknown, BCM4710)",
845 { .name = "reset", .gpio = 1 << 4 },
848 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
853 .name = "Siemens SE505 V1",
855 /* No usable buttons */
858 // { .name = "power", .gpio = 1 << 0 .polarity = REVERSE }, // Usable when retrofitting D26 (?)
859 { .name = "dmz", .gpio = 1 << 4, .polarity = REVERSE }, // actual name WWW
860 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
864 .name = "Siemens SE505 V2",
866 /* No usable buttons */
869 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
870 { .name = "dmz", .gpio = 1 << 0, .polarity = REVERSE }, // actual name WWW
871 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
876 .name = "U.S. Robotics USR5461",
878 /* No usable buttons */
881 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
882 { .name = "printer", .gpio = 1 << 1, .polarity = REVERSE },
887 .name = "Dell TrueMobile 2300",
889 { .name = "reset", .gpio = 1 << 0 },
892 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
893 { .name = "power", .gpio = 1 << 7, .polarity = REVERSE },
897 .name = "Dell TrueMobile 2300 v2",
899 { .name = "reset", .gpio = 1 << 0 },
902 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
903 { .name = "power", .gpio = 1 << 7, .polarity = REVERSE },
908 .name = "Motorola WE800G",
910 { .name = "reset", .gpio = 1 << 0 },
913 { .name = "power", .gpio = 1 << 4, .polarity = NORMAL },
914 { .name = "diag", .gpio = 1 << 2, .polarity = REVERSE },
915 { .name = "wlan_amber", .gpio = 1 << 1, .polarity = NORMAL },
919 .name = "Motorola WR850G V1",
921 { .name = "reset", .gpio = 1 << 0 },
924 { .name = "power", .gpio = 1 << 4, .polarity = NORMAL },
925 { .name = "diag", .gpio = 1 << 3, .polarity = REVERSE },
926 { .name = "dmz", .gpio = 1 << 6, .polarity = NORMAL },
927 { .name = "wlan_red", .gpio = 1 << 5, .polarity = REVERSE },
928 { .name = "wlan_green", .gpio = 1 << 7, .polarity = REVERSE },
932 .name = "Motorola WR850G V2/V3",
934 { .name = "reset", .gpio = 1 << 5 },
937 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
938 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
939 { .name = "wan", .gpio = 1 << 6, .polarity = INPUT },
940 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
944 .name = "Motorola WR850GP",
946 { .name = "reset", .gpio = 1 << 5 },
949 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
950 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
951 { .name = "dmz", .gpio = 1 << 6, .polarity = REVERSE },
952 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
958 .name = "Belkin (unknown)",
959 /* FIXME: verify & add detection */
961 { .name = "reset", .gpio = 1 << 7 },
964 { .name = "power", .gpio = 1 << 5, .polarity = NORMAL },
965 { .name = "wlan", .gpio = 1 << 3, .polarity = NORMAL },
966 { .name = "connected", .gpio = 1 << 0, .polarity = NORMAL },
970 .name = "Belkin PlayMax F7D4301",
972 { .name = "reset", .gpio = 1 << 6 },
973 { .name = "wps", .gpio = 1 << 8 },
976 { .name = "power", .gpio = 1 << 11, .polarity = REVERSE },
977 { .name = "wlan", .gpio = 1 << 13, .polarity = REVERSE },
978 { .name = "led0", .gpio = 1 << 14, .polarity = REVERSE },
979 { .name = "led1", .gpio = 1 << 15, .polarity = REVERSE },
984 .name = "Netgear WGT634U",
986 { .name = "reset", .gpio = 1 << 2 },
989 { .name = "power", .gpio = 1 << 3, .polarity = NORMAL },
994 .name = "Netgear WNR834B V1",
995 .buttons = { /* TODO: add reset button and confirm LEDs - GPIO from dd-wrt */ },
997 { .name = "power", .gpio = 1 << 4, .polarity = REVERSE },
998 { .name = "diag", .gpio = 1 << 5, .polarity = REVERSE },
999 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
1004 .name = "Netgear WNR834B V2",
1006 { .name = "reset", .gpio = 1 << 6 },
1009 { .name = "power", .gpio = 1 << 2, .polarity = NORMAL },
1010 { .name = "diag", .gpio = 1 << 3, .polarity = NORMAL },
1011 { .name = "connected", .gpio = 1 << 7, .polarity = NORMAL },
1015 .name = "Netgear WNDR3400 V1",
1017 /* nvram get gpio5=robo_reset */
1018 { .name = "reset", .gpio = 1 << 4 },
1019 { .name = "wps", .gpio = 1 << 6 },
1020 { .name = "wlan", .gpio = 1 << 8 },
1023 { .name = "wlan", .gpio = 0 << 0, .polarity = NORMAL },
1024 { .name = "connected", .gpio = 1 << 0, .polarity = NORMAL },
1025 { .name = "power", .gpio = 1 << 3, .polarity = NORMAL },
1026 { .name = "diag", .gpio = 1 << 7, .polarity = NORMAL },
1027 { .name = "usb", .gpio = 1 << 2, .polarity = REVERSE },
1031 .name = "Netgear WNDR3700 V3",
1033 /* { .name = "usb", .gpio = 1 << 1 }, */ /* this button doesn't seem to exist. */
1034 { .name = "wlan", .gpio = 1 << 2 },
1035 { .name = "reset", .gpio = 1 << 3 },
1036 { .name = "wps", .gpio = 1 << 4 },
1037 /* { .name = "switch", .gpio = 1 << 5 },*/ /* nvram get gpio5=robo_reset */
1040 { .name = "power", .gpio = (1 << 0) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1041 { .name = "diag", .gpio = (1 << 1) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1042 /* WAN LED doesn't respond to GPIO control. The switch is probably driving it.
1043 * { .name = "wan", .gpio = (1 << 2) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1045 { .name = "wlan2g", .gpio = (1 << 3) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1046 { .name = "wlan5g", .gpio = (1 << 4) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1047 { .name = "usb", .gpio = (1 << 5) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1048 { .name = "wps", .gpio = (1 << 6) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1049 { .name = "wlan", .gpio = (1 << 7) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1054 .name = "Trendware TEW411BRP+",
1056 { /* No usable buttons */ },
1059 { .name = "power", .gpio = 1 << 7, .polarity = NORMAL },
1060 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL },
1061 { .name = "bridge", .gpio = 1 << 6, .polarity = NORMAL },
1066 .name = "SimpleTech SimpleShare NAS",
1068 { .name = "reset", .gpio = 1 << 0 }, // Power button on back, named reset to enable failsafe.
1071 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE }, // actual name ready
1073 .platform_init = bcm4780_init,
1077 .name = "D-Link DIR-130",
1079 { .name = "reset", .gpio = 1 << 3},
1080 { .name = "reserved", .gpio = 1 << 7},
1083 { .name = "diag", .gpio = 1 << 0},
1084 { .name = "blue", .gpio = 1 << 6},
1088 .name = "D-Link DIR-320",
1090 { .name = "reserved", .gpio = 1 << 6},
1091 { .name = "reset", .gpio = 1 << 7},
1094 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
1095 { .name = "diag", .gpio = 1 << 1, .polarity = NORMAL }, /* "status led */
1096 { .name = "red", .gpio = 1 << 3, .polarity = REVERSE },
1097 { .name = "blue", .gpio = 1 << 4, .polarity = REVERSE },
1098 { .name = "usb", .gpio = 1 << 5, .polarity = NORMAL },
1102 .name = "D-Link DIR-330",
1104 { .name = "reset", .gpio = 1 << 3},
1105 { .name = "reserved", .gpio = 1 << 7},
1108 { .name = "diag", .gpio = 1 << 0},
1109 { .name = "usb", .gpio = 1 << 4},
1110 { .name = "blue", .gpio = 1 << 6},
1114 .name = "D-Link DWL-3150",
1116 { .name = "reset", .gpio = 1 << 7},
1119 { .name = "diag", .gpio = 1 << 2},
1120 { .name = "status", .gpio = 1 << 1},
1125 .name = "Sitecom WL-105b",
1127 { .name = "reset", .gpio = 1 << 10},
1130 { .name = "wlan", .gpio = 1 << 4},
1131 { .name = "power", .gpio = 1 << 3},
1134 /* Western Digital Net Center */
1136 .name = "Western Digital NetCenter",
1138 { .name = "power", .gpio = 1 << 0},
1139 { .name = "reset", .gpio = 1 << 7},
1141 .platform_init = NetCenter_init,
1143 /* Askey (and clones) */
1145 .name = "Askey RT210W",
1147 /* Power button is hard-wired to hardware reset */
1148 /* but is also connected to GPIO 7 (probably for bootloader recovery) */
1149 { .name = "power", .gpio = 1 << 7},
1152 /* These were verified and named based on Belkin F5D4230-4 v1112 */
1153 { .name = "connected", .gpio = 1 << 0, .polarity = REVERSE },
1154 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
1155 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
1159 .name = "OvisLink WL-1600GL",
1161 { .name = "reset", .gpio = 1 << 3 },
1162 { .name = "ses", .gpio = 1 << 4 },
1165 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
1166 { .name = "wps", .gpio = 1 << 2, .polarity = REVERSE },
1167 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
1168 { .name = "connected", .gpio = 1 << 0, .polarity = REVERSE },
1173 .name = "Microsoft MN-700",
1175 { .name = "reset", .gpio = 1 << 7 },
1178 { .name = "power", .gpio = 1 << 6, .polarity = NORMAL },
1183 .name = "Edimax PS-1208MFG",
1185 { .name = "reset", .gpio = 1 << 4 },
1188 { .name = "status", .gpio = 1 << 1, .polarity = NORMAL },
1189 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
1194 .name = "Huawei E970",
1196 { .name = "reset", .gpio = 1 << 6 },
1199 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
1204 static struct platform_t __init *platform_detect_legacy(void)
1206 char *boardnum, *boardtype;
1208 if (strcmp(getvar("nvram_type"), "cfe") == 0)
1209 return &platforms[WGT634U];
1212 /* no easy model number, attempt to guess */
1213 boardnum = getvar("boardnum");
1214 boardtype = getvar("boardtype");
1216 if (!strcmp(boardnum, "20070615")) { /* Linksys WRT600N v1/V1.1 */
1217 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "0") && !strcmp(getvar("switch_type"),"BCM5395"))
1218 return &platforms[WRT600NV11];
1220 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "0"))
1221 return &platforms[WRT600N];
1224 if (startswith(getvar("pmon_ver"), "CFE")) {
1225 /* CFE based - newer hardware */
1226 if (!strcmp(boardnum, "42")) { /* Linksys */
1227 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "1"))
1228 return &platforms[WRT350N];
1230 if (!strcmp(boardtype, "0x0101") && !strcmp(getvar("boot_ver"), "v3.6"))
1231 return &platforms[WRT54G3G];
1233 /* default to WRT54G if no boot_hw_model is set */
1234 if (nvram_get("boot_hw_model") == NULL)
1235 return &platforms[WRT54G];
1237 if (!strcmp(boardnum, "1024") && !strcmp(boardtype, "0x0446"))
1238 return &platforms[WAP54GV2];
1240 if (!strcmp(boardnum, "8") && !strcmp(boardtype, "0x048e"))
1241 return &platforms[WL1600GL];
1244 if (!strcmp(boardnum, "44") || !strcmp(boardnum, "44\r")) {
1245 if (!strcmp(boardtype,"0x0101") || !strcmp(boardtype, "0x0101\r"))
1246 return &platforms[TM2300V2]; /* Dell TrueMobile 2300 v2 */
1249 if (!strcmp(boardnum, "10496"))
1250 return &platforms[USR5461];
1252 if (!strcmp(getvar("boardtype"), "0x0101") && !strcmp(getvar("boardrev"), "0x10")) /* SE505V2 With Modified CFE */
1253 return &platforms[SE505V2];
1255 if (!strcmp(boardtype, "0x048e") && !strcmp(getvar("boardrev"),"0x35") &&
1256 !strcmp(getvar("boardflags"), "0x750")) /* D-Link DIR-320 */
1257 return &platforms[DIR320];
1259 if (!strncmp(boardnum, "TH",2) && !strcmp(boardtype,"0x042f")) {
1260 return &platforms[WDNetCenter];
1263 if (!strcmp(boardtype,"0x0472") && !strcmp(getvar("cardbus"), "1")) { /* Netgear WNR834B V1 and V2*/
1264 if (!strcmp(boardnum, "08") || !strcmp(boardnum, "8"))
1265 return &platforms[WNR834BV1];
1266 if (!strcmp(boardnum, "01") || !strcmp(boardnum, "1"))
1267 return &platforms[WNR834BV2];
1270 } else { /* PMON based - old stuff */
1271 if ((simple_strtoul(getvar("GemtekPmonVer"), NULL, 0) == 9) &&
1272 (simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 30)) {
1273 return &platforms[WR850GV1];
1275 if (startswith(boardtype, "bcm94710dev")) {
1276 if (!strcmp(boardnum, "42"))
1277 return &platforms[WRT54GV1];
1278 if (simple_strtoul(boardnum, NULL, 0) == 2)
1279 return &platforms[WAP54GV1];
1281 /* MN-700 has also hardware_version 'WL500-...', so use boardnum */
1282 if (startswith(getvar("hardware_version"), "WL500-")) {
1283 if (!strcmp(getvar("boardnum"), "mn700"))
1284 return &platforms[MN700];
1286 return &platforms[WL500G];
1288 /* Sitecom WL-105b */
1289 if (startswith(boardnum, "2") && simple_strtoul(getvar("GemtekPmonVer"), NULL, 0) == 1)
1290 return &platforms[WL105B];
1292 /* unknown asus stuff, probably bcm4702 */
1293 if (startswith(boardnum, "asusX"))
1294 return &platforms[ASUS_4702];
1296 /* bcm4702 based Askey RT210W clones, Including:
1297 * Askey RT210W (duh?)
1299 * Belkin F5D7230-4 before version v1444 (MiniPCI slot, not integrated)
1301 if (!strcmp(boardtype,"bcm94710r4")
1302 && !strcmp(boardnum ,"100")
1303 && !strcmp(getvar("pmon_ver"),"v1.03.12.bk")
1305 return &platforms[RT210W];
1309 if (boardnum || !strcmp(boardnum, "00")) {/* probably buffalo */
1310 if (startswith(boardtype, "bcm94710ap"))
1311 return &platforms[BUFFALO_UNKNOWN_4710];
1314 if (startswith(getvar("CFEver"), "MotoWRv2") ||
1315 startswith(getvar("CFEver"), "MotoWRv3") ||
1316 !strcmp(getvar("MOTO_BOARD_TYPE"), "WR_FEM1")) {
1318 return &platforms[WR850GV2V3];
1321 if (!strcmp(boardnum, "44") && !strcmp(getvar("boardflags"),"0x0388")) { /* Trendware TEW-411BRP+ */
1322 return &platforms[TEW411BRPP];
1325 if (startswith(boardnum, "04FN")) /* SimpleTech SimpleShare */
1326 return &platforms[STI_NAS];
1328 if (!strcmp(boardnum, "10") && !strcmp(getvar("boardrev"), "0x13")) /* D-Link DWL-3150 */
1329 return &platforms[DWL3150];
1331 if (!strcmp(boardnum, "01") && !strcmp(boardtype, "0x048e") && /* Edimax PS1208MFG */
1332 !strcmp(getvar("status_gpio"), "1")) /* gpio based detection */
1333 return &platforms[PS1208MFG];
1339 static struct platform_t __init *platform_detect(void)
1341 enum bcm47xx_board board;
1342 const char *board_name;
1345 board = bcm47xx_board_get();
1346 board_name = bcm47xx_board_get_name();
1347 if (board != BCM47XX_BOARD_UNKNOWN && board != BCM47XX_BOARD_NO)
1348 printk(MODULE_NAME ": kernel found a \"%s\"\n", board_name);
1351 case BCM47XX_BOARD_ASUS_RTN12:
1352 return &platforms[RTN12];
1353 case BCM47XX_BOARD_ASUS_RTN16:
1354 return &platforms[RTN16];
1355 case BCM47XX_BOARD_ASUS_RTN66U:
1356 return &platforms[RTN66U];
1357 case BCM47XX_BOARD_ASUS_WL300G:
1358 return &platforms[WL300G];
1359 case BCM47XX_BOARD_ASUS_WL320GE:
1360 return &platforms[WL320GE];
1361 case BCM47XX_BOARD_ASUS_WL330GE:
1362 return &platforms[WL330GE];
1363 case BCM47XX_BOARD_ASUS_WL500GD:
1364 return &platforms[WL500GD];
1365 case BCM47XX_BOARD_ASUS_WL500GPV1:
1366 return &platforms[WL500GP];
1367 case BCM47XX_BOARD_ASUS_WL500GPV2:
1368 return &platforms[WL500GPV2];
1369 case BCM47XX_BOARD_ASUS_WL500W:
1370 return &platforms[WL500W];
1371 case BCM47XX_BOARD_ASUS_WL520GC:
1372 return &platforms[WL520GC];
1373 case BCM47XX_BOARD_ASUS_WL520GU:
1374 return &platforms[WL520GU];
1375 case BCM47XX_BOARD_ASUS_WL700GE:
1376 return &platforms[WL700GE];
1377 case BCM47XX_BOARD_ASUS_WLHDD:
1378 return &platforms[WLHDD];
1379 case BCM47XX_BOARD_BELKIN_F7D4301:
1380 return &platforms[BELKIN_F7D4301];
1381 case BCM47XX_BOARD_BUFFALO_WBR2_G54:
1382 return &platforms[WBR2_G54];
1383 case BCM47XX_BOARD_BUFFALO_WHR2_A54G54:
1384 return &platforms[WHR2_A54G54];
1385 case BCM47XX_BOARD_BUFFALO_WHR_G125:
1386 return &platforms[WHR_G125];
1387 case BCM47XX_BOARD_BUFFALO_WHR_G54S:
1388 return &platforms[WHR_G54S];
1389 case BCM47XX_BOARD_BUFFALO_WHR_HP_G54:
1390 return &platforms[WHR_HP_G54];
1391 case BCM47XX_BOARD_BUFFALO_WLA2_G54L:
1392 return &platforms[WLA2_G54L];
1393 case BCM47XX_BOARD_BUFFALO_WZR_G300N:
1394 return &platforms[WZR_G300N];
1395 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54:
1396 return &platforms[WZR_RS_G54];
1397 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54HP:
1398 return &platforms[WZR_RS_G54HP];
1399 case BCM47XX_BOARD_DELL_TM2300:
1400 return &platforms[TM2300];
1401 case BCM47XX_BOARD_DLINK_DIR130:
1402 return &platforms[DIR130];
1403 case BCM47XX_BOARD_DLINK_DIR330:
1404 return &platforms[DIR330];
1405 case BCM47XX_BOARD_HUAWEI_E970:
1406 return &platforms[HUAWEI_E970];
1407 case BCM47XX_BOARD_LINKSYS_E1000V1:
1408 return &platforms[E1000V1];
1409 case BCM47XX_BOARD_LINKSYS_E1000V21:
1410 return &platforms[E1000V21];
1411 case BCM47XX_BOARD_LINKSYS_E2000V1:
1412 return &platforms[E2000V1];
1413 case BCM47XX_BOARD_LINKSYS_E3000V1:
1414 return &platforms[E3000V1];
1415 case BCM47XX_BOARD_LINKSYS_E3200V1:
1416 return &platforms[E3200V1];
1417 case BCM47XX_BOARD_LINKSYS_E4200V1:
1418 return &platforms[E4200V1];
1419 case BCM47XX_BOARD_LINKSYS_WRT150NV1:
1420 return &platforms[WRT150NV1];
1421 case BCM47XX_BOARD_LINKSYS_WRT150NV11:
1422 return &platforms[WRT150NV11];
1423 case BCM47XX_BOARD_LINKSYS_WRT160NV1:
1424 return &platforms[WRT160NV1];
1425 case BCM47XX_BOARD_LINKSYS_WRT160NV3:
1426 return &platforms[WRT160NV3];
1427 case BCM47XX_BOARD_LINKSYS_WRT300NV11:
1428 return &platforms[WRT300NV11];
1429 case BCM47XX_BOARD_LINKSYS_WRT310NV1:
1430 return &platforms[WRT310NV1];
1431 case BCM47XX_BOARD_LINKSYS_WRT54GSV1:
1432 return &platforms[WRT54G];
1433 case BCM47XX_BOARD_LINKSYS_WRT54G3GV2:
1434 return &platforms[WRT54G3GV2_VF];
1435 case BCM47XX_BOARD_LINKSYS_WRT610NV1:
1436 return &platforms[WRT610N];
1437 case BCM47XX_BOARD_LINKSYS_WRT610NV2:
1438 return &platforms[WRT610NV2];
1439 case BCM47XX_BOARD_LINKSYS_WRTSL54GS:
1440 return &platforms[WRTSL54GS];
1441 case BCM47XX_BOARD_MOTOROLA_WE800G:
1442 return &platforms[WE800G];
1443 case BCM47XX_BOARD_MOTOROLA_WR850GP:
1444 return &platforms[WR850GP];
1445 case BCM47XX_BOARD_MOTOROLA_WR850GV2V3:
1446 return &platforms[WR850GV2V3];
1447 case BCM47XX_BOARD_NETGEAR_WNDR3400V1:
1448 return &platforms[WNDR3400V1];
1449 case BCM47XX_BOARD_NETGEAR_WNDR3700V3:
1450 return &platforms[WNDR3700V3];
1451 case BCM47XX_BOARD_UNKNOWN:
1452 case BCM47XX_BOARD_NO:
1453 printk(MODULE_NAME ": unknown board found, try legacy detect\n");
1454 printk(MODULE_NAME ": please open a ticket at https://dev.openwrt.org and attach the complete nvram\n");
1455 return platform_detect_legacy();
1457 printk(MODULE_NAME ": board was detected as \"%s\", but not gpio configuration available\n", board_name);
1458 printk(MODULE_NAME ": now trying legacy detect\n");
1459 return platform_detect_legacy();
1463 static inline void ssb_maskset32(struct ssb_device *dev,
1464 u16 offset, u32 mask, u32 set)
1466 ssb_write32(dev, offset, (ssb_read32(dev, offset) & mask) | set);
1469 static void gpio_set_irqenable(int enabled, irqreturn_t (*handler)(int, void *))
1474 irq = gpio_to_irq(0);
1476 pr_err("no irq for gpio available\n");
1481 err = request_irq(irq, handler, IRQF_SHARED, "gpio", handler);
1483 pr_err("can not reqeust irq\n");
1487 free_irq(irq, handler);
1490 switch (bcm47xx_bus_type) {
1491 #ifdef CONFIG_BCM47XX_SSB
1492 case BCM47XX_BUS_TYPE_SSB:
1493 if (bcm47xx_bus.ssb.chipco.dev)
1494 ssb_maskset32(bcm47xx_bus.ssb.chipco.dev, SSB_CHIPCO_IRQMASK, ~SSB_CHIPCO_IRQ_GPIO, (enabled ? SSB_CHIPCO_IRQ_GPIO : 0));
1497 #ifdef CONFIG_BCM47XX_BCMA
1498 case BCM47XX_BUS_TYPE_BCMA:
1499 if (bcm47xx_bus.bcma.bus.drv_cc.core)
1500 bcma_maskset32(bcm47xx_bus.bcma.bus.drv_cc.core, BCMA_CC_IRQMASK, ~BCMA_CC_IRQ_GPIO, (enabled ? BCMA_CC_IRQ_GPIO : 0));
1506 static void hotplug_button(struct work_struct *work)
1508 struct event_t *event = container_of(work, struct event_t, wq);
1511 event->skb = alloc_skb(2048, GFP_KERNEL);
1513 s = skb_put(event->skb, strlen(event->action) + 2);
1514 sprintf(s, "%s@", event->action);
1517 NETLINK_CB(event->skb).dst_group = 1;
1518 broadcast_uevent(event->skb, 0, 1, GFP_KERNEL);
1523 static irqreturn_t button_handler(int irq, void *dev_id)
1528 in = bcm47xx_gpio_in(~0) & platform.button_mask;
1529 bcm47xx_gpio_polarity(platform.button_mask, in);
1530 changed = platform.button_polarity ^ in;
1531 platform.button_polarity = in;
1533 changed &= ~bcm47xx_gpio_outen(0, 0);
1535 for (b = platform.buttons; b->name; b++) {
1536 struct event_t *event;
1538 if (!(b->gpio & changed)) continue;
1542 if ((event = (struct event_t *)kzalloc (sizeof(struct event_t), GFP_ATOMIC))) {
1543 event->seen = (jiffies - b->seen)/HZ;
1544 event->name = b->name;
1545 event->action = b->pressed ? "pressed" : "released";
1546 INIT_WORK(&event->wq, (void *)(void *)hotplug_button);
1547 schedule_work(&event->wq);
1555 static void register_buttons(struct button_t *b)
1557 for (; b->name; b++)
1558 platform.button_mask |= b->gpio;
1560 platform.button_mask &= ~gpiomask;
1562 bcm47xx_gpio_outen(platform.button_mask, 0);
1563 bcm47xx_gpio_control(platform.button_mask, 0);
1564 platform.button_polarity = bcm47xx_gpio_in(~0) & platform.button_mask;
1565 bcm47xx_gpio_polarity(platform.button_mask, platform.button_polarity);
1566 bcm47xx_gpio_intmask(platform.button_mask, platform.button_mask);
1568 gpio_set_irqenable(1, button_handler);
1571 static void unregister_buttons(struct button_t *b)
1573 bcm47xx_gpio_intmask(platform.button_mask, 0);
1575 gpio_set_irqenable(0, button_handler);
1579 static void add_msg(struct event_t *event, char *msg, int argv)
1586 s = skb_put(event->skb, strlen(msg) + 1);
1590 static int fill_event (struct event_t *event)
1592 static char buf[128];
1594 add_msg(event, "HOME=/", 0);
1595 add_msg(event, "PATH=/sbin:/bin:/usr/sbin:/usr/bin", 0);
1596 add_msg(event, "SUBSYSTEM=button", 0);
1597 snprintf(buf, 128, "ACTION=%s", event->action);
1598 add_msg(event, buf, 0);
1599 snprintf(buf, 128, "BUTTON=%s", event->name);
1600 add_msg(event, buf, 0);
1601 snprintf(buf, 128, "SEEN=%ld", event->seen);
1602 add_msg(event, buf, 0);
1603 snprintf(buf, 128, "SEQNUM=%llu", uevent_next_seqnum());
1604 add_msg(event, buf, 0);
1610 * This should be extended to allow the platform to specify the pins and width
1611 * of the shift register. They're hardcoded for now because only the WNDR3700v3
1614 static void shiftreg_output(unsigned int val)
1618 bcm47xx_gpio_out(SHIFTREG_DATA, SHIFTREG_DATA); /* init off, pull high */
1619 bcm47xx_gpio_out(SHIFTREG_CLK, 0); /* init reset */
1622 for(mask = 1 << (SHIFTREG_MAX_BITS-1); mask; mask >>= 1)
1624 bcm47xx_gpio_out(SHIFTREG_DATA, (val & mask) ? SHIFTREG_DATA : 0);
1625 bcm47xx_gpio_out(SHIFTREG_CLK, SHIFTREG_CLK); /* pull high to trigger */
1626 bcm47xx_gpio_out(SHIFTREG_CLK, 0); /* reset to low */
1630 static void set_led_shift(struct led_t *led)
1632 static u32 shiftreg = 0;
1634 u32 pin = (led->gpio & ~GPIO_TYPE_MASK);
1642 /* Clock the bits out. */
1643 if (shiftreg != old) {
1644 shiftreg_output(shiftreg);
1648 static void set_led_extif(struct led_t *led)
1650 volatile u8 *addr = (volatile u8 *) KSEG1ADDR(EXTIF_UART) + (led->gpio & ~GPIO_TYPE_MASK);
1658 static void led_flash(unsigned long dummy) {
1663 for (l = platform.leds; l->name; l++) {
1664 if (!l->flash) continue;
1665 switch (l->gpio & GPIO_TYPE_MASK) {
1666 case GPIO_TYPE_EXTIF:
1668 l->state = !l->state;
1671 case GPIO_TYPE_SHIFT:
1673 l->state = !l->state;
1676 case GPIO_TYPE_NORMAL:
1685 u32 val = ~bcm47xx_gpio_in(~0);
1687 bcm47xx_gpio_outen(mask, mask);
1688 bcm47xx_gpio_control(mask, 0);
1689 bcm47xx_gpio_out(mask, val);
1691 if (mask || extif_blink) {
1692 mod_timer(&led_timer, jiffies + FLASH_TIME);
1696 static int diag_led_show(struct seq_file *m, void *v)
1698 struct led_t * led = m->private;
1700 u8 p = (led->polarity == NORMAL ? 0 : 1);
1702 return seq_printf(m, "f\n");
1703 } else if ((led->gpio & GPIO_TYPE_MASK) != GPIO_TYPE_NORMAL) {
1704 return seq_printf(m, "%d\n", ((led->state ^ p) ? 1 : 0));
1706 u32 in = (bcm47xx_gpio_in(~0) & led->gpio ? 1 : 0);
1707 return seq_printf(m, "%d\n", ((in ^ p) ? 1 : 0));
1711 static int diag_led_open(struct inode *inode, struct file *file)
1713 return single_open(file, diag_led_show, PDE_DATA(inode));
1716 static ssize_t diag_led_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
1718 struct led_t *led = PDE_DATA(file_inode(file));
1723 len = min(count, sizeof(cmd) - 1);
1724 if (copy_from_user(cmd, buf, len))
1729 p = (led->polarity == NORMAL ? 0 : 1);
1730 if (cmd[0] == 'f') {
1735 if ((led->gpio & GPIO_TYPE_MASK) == GPIO_TYPE_EXTIF) {
1736 led->state = p ^ ((cmd[0] == '1') ? 1 : 0);
1738 } else if ((led->gpio & GPIO_TYPE_MASK) == GPIO_TYPE_SHIFT) {
1739 led->state = p ^ ((cmd[0] == '1') ? 1 : 0);
1742 bcm47xx_gpio_outen(led->gpio, led->gpio);
1743 bcm47xx_gpio_control(led->gpio, 0);
1744 bcm47xx_gpio_out(led->gpio, ((p ^ (cmd[0] == '1')) ? led->gpio : 0));
1750 static const struct file_operations diag_led_fops = {
1751 .open = diag_led_open,
1753 .llseek = seq_lseek,
1754 .write = diag_led_write
1757 static void register_leds(struct led_t *l)
1759 struct proc_dir_entry *p;
1764 leds = proc_mkdir("led", diag);
1768 for(; l->name; l++) {
1769 if (l->gpio & gpiomask)
1772 switch (l->gpio & GPIO_TYPE_MASK) {
1773 case GPIO_TYPE_EXTIF:
1777 case GPIO_TYPE_SHIFT:
1778 mask |= (SHIFTREG_DATA | SHIFTREG_CLK);
1779 oe_mask |= (SHIFTREG_DATA | SHIFTREG_CLK);
1780 l->state = (l->polarity != NORMAL);
1783 case GPIO_TYPE_NORMAL:
1785 if (l->polarity != INPUT) oe_mask |= l->gpio;
1787 val |= (l->polarity == NORMAL)?0:l->gpio;
1791 if (l->polarity == INPUT) continue;
1793 p = proc_create_data(l->name, S_IRUSR, leds, &diag_led_fops, l);
1796 bcm47xx_gpio_outen(mask, oe_mask);
1797 bcm47xx_gpio_control(mask, 0);
1798 bcm47xx_gpio_out(mask, val);
1799 bcm47xx_gpio_intmask(mask, 0);
1802 static void unregister_leds(struct led_t *l)
1805 remove_proc_entry(l->name, leds);
1807 remove_proc_entry("led", diag);
1810 static int diag_model_show(struct seq_file *m, void *v)
1812 return seq_printf(m, "%s\n", platform.name);
1815 static int diag_model_open(struct inode *inode, struct file *file)
1817 return single_open(file, diag_model_show, PDE_DATA(inode));
1820 static const struct file_operations diag_model_fops = {
1821 .open = diag_model_open,
1826 static int diag_gpiomask_show(struct seq_file *m, void *v)
1828 return seq_printf(m, "0x%04x\n", gpiomask);
1831 static int diag_gpiomask_open(struct inode *inode, struct file *file)
1833 return single_open(file, diag_gpiomask_show, PDE_DATA(inode));
1836 static ssize_t diag_gpiomask_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
1838 int err = kstrtouint_from_user(buf, count, 0, &gpiomask);
1842 if (platform.buttons) {
1843 unregister_buttons(platform.buttons);
1844 register_buttons(platform.buttons);
1847 if (platform.leds) {
1848 unregister_leds(platform.leds);
1849 register_leds(platform.leds);
1855 static const struct file_operations diag_gpiomask_fops = {
1856 .open = diag_gpiomask_open,
1858 .llseek = seq_lseek,
1859 .write = diag_gpiomask_write
1862 static int __init diag_init(void)
1864 static struct proc_dir_entry *p;
1865 static struct platform_t *detected;
1867 detected = platform_detect();
1869 printk(MODULE_NAME ": Router model not detected.\n");
1872 memcpy(&platform, detected, sizeof(struct platform_t));
1874 printk(MODULE_NAME ": Detected '%s'\n", platform.name);
1875 if (platform.platform_init != NULL) {
1876 platform.platform_init();
1879 if (!(diag = proc_mkdir("diag", NULL))) {
1880 printk(MODULE_NAME ": proc_mkdir on /proc/diag failed\n");
1884 p = proc_create("model", S_IRUSR, diag, &diag_model_fops);
1886 remove_proc_entry("diag", NULL);
1890 p = proc_create("gpiomask", S_IRUSR | S_IWUSR, diag, &diag_gpiomask_fops);
1892 remove_proc_entry("model", diag);
1893 remove_proc_entry("diag", NULL);
1897 if (platform.buttons)
1898 register_buttons(platform.buttons);
1901 register_leds(platform.leds);
1906 static void __exit diag_exit(void)
1908 del_timer(&led_timer);
1910 if (platform.buttons)
1911 unregister_buttons(platform.buttons);
1914 unregister_leds(platform.leds);
1916 remove_proc_entry("model", diag);
1917 remove_proc_entry("gpiomask", diag);
1918 remove_proc_entry("diag", NULL);
1921 module_init(diag_init);
1922 module_exit(diag_exit);
1924 MODULE_AUTHOR("Mike Baker, Felix Fietkau / OpenWrt.org");
1925 MODULE_LICENSE("GPL");