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
;
125 BUFFALO_UNKNOWN_4710
,
170 /* Western Digital */
189 static void __init
bcm4780_init(void) {
192 /* Enables GPIO 3 that controls HDD and led power on ASUS WL-700gE */
193 printk(MODULE_NAME
": Spinning up HDD and enabling leds\n");
194 bcm47xx_gpio_outen(pin
, pin
);
195 bcm47xx_gpio_control(pin
, 0);
196 bcm47xx_gpio_out(pin
, pin
);
198 /* Wait 5s, so the HDD can spin up */
199 set_current_state(TASK_INTERRUPTIBLE
);
200 schedule_timeout(HZ
* 5);
203 static void __init
NetCenter_init(void) {
204 /* unset pin 6 (+12V) */
206 bcm47xx_gpio_outen(pin
, pin
);
207 bcm47xx_gpio_control(pin
, 0);
208 bcm47xx_gpio_out(pin
, pin
);
209 /* unset pin 1 (turn off red led, blue will light alone if +5V comes up) */
211 bcm47xx_gpio_outen(pin
, pin
);
212 bcm47xx_gpio_control(pin
, 0);
213 bcm47xx_gpio_out(pin
, pin
);
214 /* unset pin 3 (+5V) and wait 5 seconds (harddisk spin up) */
218 static void __init
bcm57xx_init(void) {
221 /* FIXME: switch comes up, but port mappings/vlans not right */
222 bcm47xx_gpio_outen(pin
, pin
);
223 bcm47xx_gpio_control(pin
, 0);
224 bcm47xx_gpio_out(pin
, pin
);
227 static struct platform_t __initdata platforms
[] = {
230 .name
= "Linksys WAP54G V1",
232 { .name
= "reset", .gpio
= 1 << 0 },
235 { .name
= "diag", .gpio
= 1 << 3 },
236 { .name
= "wlan", .gpio
= 1 << 4 },
240 .name
= "Linksys WAP54G V2",
242 { .name
= "reset", .gpio
= 1 << 0 },
245 { .name
= "wlan", .gpio
= 1 << 5, .polarity
= REVERSE
},
246 /* GPIO 6 is b44 (eth0, LAN) PHY power */
250 .name
= "Linksys WAP54G V3",
252 /* FIXME: verify this */
253 { .name
= "reset", .gpio
= 1 << 7 },
254 { .name
= "ses", .gpio
= 1 << 0 },
258 { .name
= "ses", .gpio
= 1 << 1 },
262 .name
= "Linksys WRT54G V1.x",
264 { .name
= "reset", .gpio
= 1 << 6 },
267 { .name
= "diag", .gpio
= 0x13 | GPIO_TYPE_EXTIF
, .polarity
= NORMAL
},
268 { .name
= "dmz", .gpio
= 0x12 | GPIO_TYPE_EXTIF
, .polarity
= NORMAL
},
272 .name
= "Linksys WRT54G/GS/GL",
274 { .name
= "reset", .gpio
= 1 << 6 },
275 { .name
= "ses", .gpio
= 1 << 4 },
278 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
279 { .name
= "dmz", .gpio
= 1 << 7, .polarity
= REVERSE
},
280 { .name
= "ses_white", .gpio
= 1 << 2, .polarity
= REVERSE
},
281 { .name
= "ses_orange", .gpio
= 1 << 3, .polarity
= REVERSE
},
282 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
286 .name
= "Linksys WRTSL54GS",
288 { .name
= "reset", .gpio
= 1 << 6 },
289 { .name
= "ses", .gpio
= 1 << 4 },
292 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
293 { .name
= "dmz", .gpio
= 1 << 0, .polarity
= REVERSE
},
294 { .name
= "ses_white", .gpio
= 1 << 5, .polarity
= REVERSE
},
295 { .name
= "ses_orange", .gpio
= 1 << 7, .polarity
= REVERSE
},
299 .name
= "Linksys WRT54G3G",
301 { .name
= "reset", .gpio
= 1 << 6 },
302 { .name
= "3g", .gpio
= 1 << 4 },
305 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
306 { .name
= "dmz", .gpio
= 1 << 7, .polarity
= REVERSE
},
307 { .name
= "3g_green", .gpio
= 1 << 2, .polarity
= NORMAL
},
308 { .name
= "3g_blue", .gpio
= 1 << 3, .polarity
= NORMAL
},
309 { .name
= "3g_blink", .gpio
= 1 << 5, .polarity
= NORMAL
},
313 .name
= "Linksys WRT54G3GV2-VF",
315 { .name
= "reset", .gpio
= 1 << 6 },
316 { .name
= "3g", .gpio
= 1 << 5 },
319 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
320 { .name
= "3g_green", .gpio
= 1 << 2, .polarity
= NORMAL
},
321 { .name
= "3g_blue", .gpio
= 1 << 3, .polarity
= NORMAL
},
325 .name
= "Linksys WRT150N V1",
327 { .name
= "reset", .gpio
= 1 << 6 },
328 { .name
= "ses", .gpio
= 1 << 4 },
331 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
332 { .name
= "ses_green", .gpio
= 1 << 5, .polarity
= REVERSE
},
333 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
337 .name
= "Linksys WRT150N V1.1",
339 { .name
= "reset", .gpio
= 1 << 6 },
340 { .name
= "ses", .gpio
= 1 << 4 },
343 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
344 { .name
= "ses_green", .gpio
= 1 << 5, .polarity
= REVERSE
},
345 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
349 .name
= "Linksys WRT160N v1.x",
351 { .name
= "reset", .gpio
= 1 << 6 },
352 { .name
= "ses", .gpio
= 1 << 4 },
355 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
356 { .name
= "ses_blue", .gpio
= 1 << 5, .polarity
= REVERSE
},
357 { .name
= "ses_orange", .gpio
= 1 << 3, .polarity
= REVERSE
},
361 .name
= "Linksys WRT160N V3",
363 { .name
= "reset", .gpio
= 1 << 6 },
364 { .name
= "ses", .gpio
= 1 << 5 },
367 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
368 { .name
= "ses_blue", .gpio
= 1 << 4, .polarity
= REVERSE
},
369 { .name
= "ses_orange", .gpio
= 1 << 2, .polarity
= REVERSE
},
373 .name
= "Linksys WRT300N V1.1",
375 { .name
= "reset", .gpio
= 1 << 6 }, // "Reset" on back panel
376 { .name
= "ses", .gpio
= 1 << 4 }, // "Reserved" on top panel
379 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
}, // "Power"
380 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
}, // "Security" Amber
381 { .name
= "ses_green", .gpio
= 1 << 5, .polarity
= REVERSE
}, // "Security" Green
383 .platform_init
= bcm57xx_init
,
386 .name
= "Linksys WRT350N",
388 { .name
= "reset", .gpio
= 1 << 6 },
389 { .name
= "ses", .gpio
= 1 << 8 },
392 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
393 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
394 { .name
= "ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
},
395 { .name
= "usb_blink", .gpio
= 1 << 10, .polarity
= REVERSE
},
396 { .name
= "usb", .gpio
= 1 << 11, .polarity
= REVERSE
},
398 .platform_init
= bcm57xx_init
,
401 .name
= "Linksys WRT600N",
403 { .name
= "reset", .gpio
= 1 << 6 },
404 { .name
= "ses", .gpio
= 1 << 7 },
407 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
}, // Power LED
408 { .name
= "usb", .gpio
= 1 << 3, .polarity
= REVERSE
}, // USB LED
409 { .name
= "wl0_ses_amber", .gpio
= 1 << 8, .polarity
= REVERSE
}, // 2.4Ghz LED Amber
410 { .name
= "wl0_ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
}, // 2.4Ghz LED Green
411 { .name
= "wl1_ses_amber", .gpio
= 1 << 10, .polarity
= REVERSE
}, // 5.6Ghz LED Amber
412 { .name
= "wl1_ses_green", .gpio
= 1 << 11, .polarity
= REVERSE
}, // 5.6Ghz LED Green
414 .platform_init
= bcm57xx_init
,
417 .name
= "Linksys WRT600N V1.1",
419 { .name
= "reset", .gpio
= 1 << 6 },
420 { .name
= "ses", .gpio
= 1 << 7 },
423 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
}, // Power LED
424 { .name
= "usb", .gpio
= 1 << 3, .polarity
= REVERSE
}, // USB LED
425 { .name
= "wl0_ses_amber", .gpio
= 1 << 8, .polarity
= REVERSE
}, // 2.4Ghz LED Amber
426 { .name
= "wl0_ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
}, // 2.4Ghz LED Green
427 { .name
= "wl1_ses_amber", .gpio
= 1 << 10, .polarity
= REVERSE
}, // 5.6Ghz LED Amber
428 { .name
= "wl1_ses_green", .gpio
= 1 << 11, .polarity
= REVERSE
}, // 5.6Ghz LED Green
430 .platform_init
= bcm57xx_init
,
433 .name
= "Linksys WRT610N",
435 { .name
= "reset", .gpio
= 1 << 6 },
436 { .name
= "ses", .gpio
= 1 << 8 },
439 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
}, // Power LED
440 { .name
= "usb", .gpio
= 1 << 0, .polarity
= REVERSE
}, // USB LED
441 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
}, // WiFi protected setup LED amber
442 { .name
= "ses_blue", .gpio
= 1 << 9, .polarity
= REVERSE
}, // WiFi protected setup LED blue
446 .name
= "Linksys WRT610N V2",
448 { .name
= "reset", .gpio
= 1 << 6 },
449 { .name
= "ses", .gpio
= 1 << 4 },
452 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
}, // Power LED
453 { .name
= "usb", .gpio
= 1 << 7, .polarity
= NORMAL
}, // USB LED
454 { .name
= "ses_amber", .gpio
= 1 << 0, .polarity
= REVERSE
}, // WiFi protected setup LED amber
455 { .name
= "ses_blue", .gpio
= 1 << 3, .polarity
= REVERSE
}, // WiFi protected setup LED blue
456 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
}, // Wireless LED
459 /* same hardware as WRT160NV3 and Cisco Valet M10V1, but different board detection, combine? */
461 .name
= "Linksys E1000 V1",
463 { .name
= "reset", .gpio
= 1 << 6 },
464 { .name
= "wps", .gpio
= 1 << 5 }, /* nvram get gpio5=wps_button */
467 /** turns on leds for all ethernet ports (wan too)
468 * this also disconnects some, or maybe all, ethernet ports
469 * 1: leds work normally
470 * 0: all lit all the time */
471 /* nvram get gpio3=robo_reset */
472 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
473 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
474 { .name
= "ses_blue", .gpio
= 1 << 4, .polarity
= REVERSE
}, /* nvram get gpio4=wps_led */
475 { .name
= "ses_orange", .gpio
= 1 << 2, .polarity
= REVERSE
}, /* nvram get gpio2=wps_status_led */
479 .name
= "Linksys E1000 V2.1",
481 { .name
= "reset", .gpio
= 1 << 10 }, /* nvram get reset_gpio=10 */
482 { .name
= "wps", .gpio
= 1 << 9 }, /* nvram get gpio9=wps_button */
485 { .name
= "power", .gpio
= 1 << 6, .polarity
= REVERSE
},
486 { .name
= "wlan", .gpio
= 1 << 5, .polarity
= NORMAL
},
487 { .name
= "ses_blue", .gpio
= 1 << 8, .polarity
= NORMAL
}, /* nvram get gpio8=wps_led */
488 { .name
= "ses_orange", .gpio
= 1 << 7, .polarity
= NORMAL
}, /* nvram get gpio7=wps_status_led */
492 .name
= "Linksys E3000 V1",
494 { .name
= "reset", .gpio
= 1 << 6 },
495 { .name
= "ses", .gpio
= 1 << 4 },
498 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
}, // Power LED
499 { .name
= "usb", .gpio
= 1 << 7, .polarity
= NORMAL
}, // USB LED
500 { .name
= "ses_amber", .gpio
= 1 << 0, .polarity
= REVERSE
}, // WiFi protected setup LED amber
501 { .name
= "ses_blue", .gpio
= 1 << 3, .polarity
= REVERSE
}, // WiFi protected setup LED blue
502 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
}, // Wireless LED
506 .name
= "Linksys E3200 V1",
508 /* { .name = "switch", .gpio = 1 << 4 },*/ /* nvram get gpio4=robo_reset */
509 { .name
= "reset", .gpio
= 1 << 5 }, /* nvram get reset_gpio=5 */
510 { .name
= "wps", .gpio
= 1 << 8 }, /* nvram get gpio8=wps_button */
511 /* { .name = "wombo", .gpio = 1 << 23 },*/ /* nvram get gpio23=wombo_reset - wireless on motherboard */
514 { .name
= "power", .gpio
= 1 << 3, .polarity
= REVERSE
}, /* Power LED */
518 .name
= "Linksys E4200 V1",
520 { .name
= "reset", .gpio
= 1 << 6 },
521 { .name
= "wps", .gpio
= 1 << 4 },
524 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
529 .name
= "ASUS WL-HDD",
531 { .name
= "reset", .gpio
= 1 << 6 },
534 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
535 { .name
= "usb", .gpio
= 1 << 2, .polarity
= REVERSE
},
539 .name
= "ASUS WL-300g",
541 { .name
= "reset", .gpio
= 1 << 6 },
544 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
548 .name
= "ASUS WL-320gE/WL-320gP",
550 { .name
= "reset", .gpio
= 1 << 6 },
553 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
554 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
},
555 { .name
= "link", .gpio
= 1 << 11, .polarity
= REVERSE
},
559 .name
= "ASUS WL-330gE",
561 { .name
= "reset", .gpio
= 1 << 2 },
564 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
568 .name
= "ASUS WL-500g",
570 { .name
= "reset", .gpio
= 1 << 6 },
573 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
577 .name
= "ASUS WL-500g Deluxe",
579 { .name
= "reset", .gpio
= 1 << 6 },
582 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
586 .name
= "ASUS WL-500g Premium",
588 { .name
= "reset", .gpio
= 1 << 0 },
589 { .name
= "ses", .gpio
= 1 << 4 },
592 { .name
= "power", .gpio
= 1 << 1, .polarity
= REVERSE
},
596 .name
= "ASUS WL-500g Premium V2",
598 { .name
= "reset", .gpio
= 1 << 2 },
599 { .name
= "ses", .gpio
= 1 << 3 },
602 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
603 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
607 .name
= "ASUS WL-500W",
609 { .name
= "reset", .gpio
= 1 << 6 },
610 { .name
= "ses", .gpio
= 1 << 7 },
613 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
617 .name
= "ASUS WL-520GC",
619 { .name
= "reset", .gpio
= 1 << 2 },
620 { .name
= "ses", .gpio
= 1 << 3 },
623 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
624 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
628 .name
= "ASUS WL-520gU",
630 { .name
= "reset", .gpio
= 1 << 2 },
631 { .name
= "ses", .gpio
= 1 << 3 },
634 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
635 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
639 .name
= "ASUS (unknown, BCM4702)",
641 { .name
= "reset", .gpio
= 1 << 6 },
644 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
648 .name
= "ASUS WL-700gE",
650 { .name
= "reset", .gpio
= 1 << 7 }, // on back, hardwired, always resets device regardless OS state
651 { .name
= "ses", .gpio
= 1 << 4 }, // on back, actual name ezsetup
652 { .name
= "power", .gpio
= 1 << 0 }, // on front
653 { .name
= "copy", .gpio
= 1 << 6 }, // on front
657 // GPIO that controls power led also enables/disables some essential functions
660 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
}, // actual name power
662 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
664 .platform_init
= bcm4780_init
,
667 .name
= "ASUS RT-N12",
669 { .name
= "wps", .gpio
= 1 << 0 },
670 { .name
= "reset", .gpio
= 1 << 1 },
671 // this is the router/repeater/ap switch
672 { .name
= "sw1", .gpio
= 1 << 4 },
673 { .name
= "sw2", .gpio
= 1 << 5 },
674 { .name
= "sw3", .gpio
= 1 << 6 },
677 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
},
678 { .name
= "wlan", .gpio
= 1 << 7, .polarity
= NORMAL
},
679 // gpio3 forces WAN and LAN1-4 all on
680 //{ .name = "eth", .gpio = 1 << 3, .polarity = REVERSE },
684 .name
= "ASUS RT-N16",
686 { .name
= "reset", .gpio
= 1 << 8 },
687 { .name
= "ses", .gpio
= 1 << 5 },
690 { .name
= "power", .gpio
= 1 << 1, .polarity
= REVERSE
},
691 { .name
= "wlan", .gpio
= 1 << 7, .polarity
= NORMAL
},
695 .name
= "ASUS RT-N66U",
697 { .name
= "reset", .gpio
= 1 << 9 },
698 { .name
= "wps", .gpio
= 1 << 4 },
701 { .name
= "power", .gpio
= 1 << 12, .polarity
= REVERSE
},
702 { .name
= "usb", .gpio
= 1 << 15, .polarity
= REVERSE
},
707 .name
= "Buffalo WHR-G54S",
709 { .name
= "reset", .gpio
= 1 << 4 },
710 { .name
= "bridge", .gpio
= 1 << 5 },
711 { .name
= "ses", .gpio
= 1 << 0 },
714 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
715 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
716 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
717 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
718 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
722 .name
= "Buffalo WBR2-G54",
725 { .name
= "reset", .gpio
= 1 << 7 },
728 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
732 .name
= "Buffalo WHR-HP-G54",
734 { .name
= "reset", .gpio
= 1 << 4 },
735 { .name
= "bridge", .gpio
= 1 << 5 },
736 { .name
= "ses", .gpio
= 1 << 0 },
739 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
740 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
741 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
742 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
743 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
747 .name
= "Buffalo WHR-G125",
749 { .name
= "reset", .gpio
= 1 << 4 },
750 { .name
= "bridge", .gpio
= 1 << 5 },
751 { .name
= "ses", .gpio
= 1 << 0 },
754 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
755 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
756 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
757 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
758 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
762 .name
= "Buffalo WHR2-A54G54",
764 { .name
= "reset", .gpio
= 1 << 4 },
767 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
771 .name
= "Buffalo WLA2-G54L",
774 { .name
= "reset", .gpio
= 1 << 7 },
777 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
781 .name
= "Buffalo WZR-G300N",
783 { .name
= "reset", .gpio
= 1 << 4 },
786 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
787 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
788 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
792 .name
= "Buffalo WZR-RS-G54",
794 { .name
= "ses", .gpio
= 1 << 0 },
795 { .name
= "reset", .gpio
= 1 << 4 },
798 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
799 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
800 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
804 .name
= "Buffalo WZR-RS-G54HP",
806 { .name
= "ses", .gpio
= 1 << 0 },
807 { .name
= "reset", .gpio
= 1 << 4 },
810 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
811 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
812 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
815 [BUFFALO_UNKNOWN_4710
] = {
816 .name
= "Buffalo (unknown, BCM4710)",
818 { .name
= "reset", .gpio
= 1 << 4 },
821 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
826 .name
= "Siemens SE505 V1",
828 /* No usable buttons */
831 // { .name = "power", .gpio = 1 << 0 .polarity = REVERSE }, // Usable when retrofitting D26 (?)
832 { .name
= "dmz", .gpio
= 1 << 4, .polarity
= REVERSE
}, // actual name WWW
833 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
837 .name
= "Siemens SE505 V2",
839 /* No usable buttons */
842 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
843 { .name
= "dmz", .gpio
= 1 << 0, .polarity
= REVERSE
}, // actual name WWW
844 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
849 .name
= "U.S. Robotics USR5461",
851 /* No usable buttons */
854 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
855 { .name
= "printer", .gpio
= 1 << 1, .polarity
= REVERSE
},
860 .name
= "Dell TrueMobile 2300",
862 { .name
= "reset", .gpio
= 1 << 0 },
865 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
866 { .name
= "power", .gpio
= 1 << 7, .polarity
= REVERSE
},
870 .name
= "Dell TrueMobile 2300 v2",
872 { .name
= "reset", .gpio
= 1 << 0 },
875 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
876 { .name
= "power", .gpio
= 1 << 7, .polarity
= REVERSE
},
881 .name
= "Motorola WE800G",
883 { .name
= "reset", .gpio
= 1 << 0 },
886 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
887 { .name
= "diag", .gpio
= 1 << 2, .polarity
= REVERSE
},
888 { .name
= "wlan_amber", .gpio
= 1 << 1, .polarity
= NORMAL
},
892 .name
= "Motorola WR850G V1",
894 { .name
= "reset", .gpio
= 1 << 0 },
897 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
898 { .name
= "diag", .gpio
= 1 << 3, .polarity
= REVERSE
},
899 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= NORMAL
},
900 { .name
= "wlan_red", .gpio
= 1 << 5, .polarity
= REVERSE
},
901 { .name
= "wlan_green", .gpio
= 1 << 7, .polarity
= REVERSE
},
905 .name
= "Motorola WR850G V2/V3",
907 { .name
= "reset", .gpio
= 1 << 5 },
910 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
911 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
912 { .name
= "wan", .gpio
= 1 << 6, .polarity
= INPUT
},
913 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
917 .name
= "Motorola WR850GP",
919 { .name
= "reset", .gpio
= 1 << 5 },
922 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
923 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
924 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= REVERSE
},
925 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
931 .name
= "Belkin (unknown)",
932 /* FIXME: verify & add detection */
934 { .name
= "reset", .gpio
= 1 << 7 },
937 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
},
938 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= NORMAL
},
939 { .name
= "connected", .gpio
= 1 << 0, .polarity
= NORMAL
},
943 .name
= "Belkin PlayMax F7D4301",
945 { .name
= "reset", .gpio
= 1 << 6 },
946 { .name
= "wps", .gpio
= 1 << 8 },
949 { .name
= "power", .gpio
= 1 << 11, .polarity
= REVERSE
},
950 { .name
= "wlan", .gpio
= 1 << 13, .polarity
= REVERSE
},
951 { .name
= "led0", .gpio
= 1 << 14, .polarity
= REVERSE
},
952 { .name
= "led1", .gpio
= 1 << 15, .polarity
= REVERSE
},
957 .name
= "Netgear WGT634U",
959 { .name
= "reset", .gpio
= 1 << 2 },
962 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
},
967 .name
= "Netgear WNR834B V1",
968 .buttons
= { /* TODO: add reset button and confirm LEDs - GPIO from dd-wrt */ },
970 { .name
= "power", .gpio
= 1 << 4, .polarity
= REVERSE
},
971 { .name
= "diag", .gpio
= 1 << 5, .polarity
= REVERSE
},
972 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
977 .name
= "Netgear WNR834B V2",
979 { .name
= "reset", .gpio
= 1 << 6 },
982 { .name
= "power", .gpio
= 1 << 2, .polarity
= NORMAL
},
983 { .name
= "diag", .gpio
= 1 << 3, .polarity
= NORMAL
},
984 { .name
= "connected", .gpio
= 1 << 7, .polarity
= NORMAL
},
988 .name
= "Netgear WNDR3400 V1",
990 /* nvram get gpio5=robo_reset */
991 { .name
= "reset", .gpio
= 1 << 4 },
992 { .name
= "wps", .gpio
= 1 << 6 },
993 { .name
= "wlan", .gpio
= 1 << 8 },
996 { .name
= "wlan", .gpio
= 0 << 0, .polarity
= NORMAL
},
997 { .name
= "connected", .gpio
= 1 << 0, .polarity
= NORMAL
},
998 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
},
999 { .name
= "diag", .gpio
= 1 << 7, .polarity
= NORMAL
},
1000 { .name
= "usb", .gpio
= 1 << 2, .polarity
= REVERSE
},
1004 .name
= "Netgear WNDR3700 V3",
1006 /* { .name = "usb", .gpio = 1 << 1 }, */ /* this button doesn't seem to exist. */
1007 { .name
= "wlan", .gpio
= 1 << 2 },
1008 { .name
= "reset", .gpio
= 1 << 3 },
1009 { .name
= "wps", .gpio
= 1 << 4 },
1010 /* { .name = "switch", .gpio = 1 << 5 },*/ /* nvram get gpio5=robo_reset */
1013 { .name
= "power", .gpio
= (1 << 0) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1014 { .name
= "diag", .gpio
= (1 << 1) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1015 /* WAN LED doesn't respond to GPIO control. The switch is probably driving it.
1016 * { .name = "wan", .gpio = (1 << 2) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1018 { .name
= "wlan2g", .gpio
= (1 << 3) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1019 { .name
= "wlan5g", .gpio
= (1 << 4) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1020 { .name
= "usb", .gpio
= (1 << 5) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1021 { .name
= "wps", .gpio
= (1 << 6) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1022 { .name
= "wlan", .gpio
= (1 << 7) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1027 .name
= "Trendware TEW411BRP+",
1029 { /* No usable buttons */ },
1032 { .name
= "power", .gpio
= 1 << 7, .polarity
= NORMAL
},
1033 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
},
1034 { .name
= "bridge", .gpio
= 1 << 6, .polarity
= NORMAL
},
1039 .name
= "SimpleTech SimpleShare NAS",
1041 { .name
= "reset", .gpio
= 1 << 0 }, // Power button on back, named reset to enable failsafe.
1044 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
1046 .platform_init
= bcm4780_init
,
1050 .name
= "D-Link DIR-130",
1052 { .name
= "reset", .gpio
= 1 << 3},
1053 { .name
= "reserved", .gpio
= 1 << 7},
1056 { .name
= "diag", .gpio
= 1 << 0},
1057 { .name
= "blue", .gpio
= 1 << 6},
1061 .name
= "D-Link DIR-320",
1063 { .name
= "reserved", .gpio
= 1 << 6},
1064 { .name
= "reset", .gpio
= 1 << 7},
1067 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
1068 { .name
= "diag", .gpio
= 1 << 1, .polarity
= NORMAL
}, /* "status led */
1069 { .name
= "red", .gpio
= 1 << 3, .polarity
= REVERSE
},
1070 { .name
= "blue", .gpio
= 1 << 4, .polarity
= REVERSE
},
1071 { .name
= "usb", .gpio
= 1 << 5, .polarity
= NORMAL
},
1075 .name
= "D-Link DIR-330",
1077 { .name
= "reset", .gpio
= 1 << 3},
1078 { .name
= "reserved", .gpio
= 1 << 7},
1081 { .name
= "diag", .gpio
= 1 << 0},
1082 { .name
= "usb", .gpio
= 1 << 4},
1083 { .name
= "blue", .gpio
= 1 << 6},
1087 .name
= "D-Link DWL-3150",
1089 { .name
= "reset", .gpio
= 1 << 7},
1092 { .name
= "diag", .gpio
= 1 << 2},
1093 { .name
= "status", .gpio
= 1 << 1},
1098 .name
= "Sitecom WL-105b",
1100 { .name
= "reset", .gpio
= 1 << 10},
1103 { .name
= "wlan", .gpio
= 1 << 4},
1104 { .name
= "power", .gpio
= 1 << 3},
1107 /* Western Digital Net Center */
1109 .name
= "Western Digital NetCenter",
1111 { .name
= "power", .gpio
= 1 << 0},
1112 { .name
= "reset", .gpio
= 1 << 7},
1114 .platform_init
= NetCenter_init
,
1116 /* Askey (and clones) */
1118 .name
= "Askey RT210W",
1120 /* Power button is hard-wired to hardware reset */
1121 /* but is also connected to GPIO 7 (probably for bootloader recovery) */
1122 { .name
= "power", .gpio
= 1 << 7},
1125 /* These were verified and named based on Belkin F5D4230-4 v1112 */
1126 { .name
= "connected", .gpio
= 1 << 0, .polarity
= REVERSE
},
1127 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
1128 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
1132 .name
= "OvisLink WL-1600GL",
1134 { .name
= "reset", .gpio
= 1 << 3 },
1135 { .name
= "ses", .gpio
= 1 << 4 },
1138 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
1139 { .name
= "wps", .gpio
= 1 << 2, .polarity
= REVERSE
},
1140 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
1141 { .name
= "connected", .gpio
= 1 << 0, .polarity
= REVERSE
},
1146 .name
= "Microsoft MN-700",
1148 { .name
= "reset", .gpio
= 1 << 7 },
1151 { .name
= "power", .gpio
= 1 << 6, .polarity
= NORMAL
},
1156 .name
= "Edimax PS-1208MFG",
1158 { .name
= "reset", .gpio
= 1 << 4 },
1161 { .name
= "status", .gpio
= 1 << 1, .polarity
= NORMAL
},
1162 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
1167 .name
= "Huawei E970",
1169 { .name
= "reset", .gpio
= 1 << 6 },
1172 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
1177 static struct platform_t __init
*platform_detect_legacy(void)
1179 char *boardnum
, *boardtype
;
1181 if (strcmp(getvar("nvram_type"), "cfe") == 0)
1182 return &platforms
[WGT634U
];
1185 /* no easy model number, attempt to guess */
1186 boardnum
= getvar("boardnum");
1187 boardtype
= getvar("boardtype");
1189 if (!strcmp(boardnum
, "20070615")) { /* Linksys WRT600N v1/V1.1 */
1190 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "0") && !strcmp(getvar("switch_type"),"BCM5395"))
1191 return &platforms
[WRT600NV11
];
1193 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "0"))
1194 return &platforms
[WRT600N
];
1197 if (startswith(getvar("pmon_ver"), "CFE")) {
1198 /* CFE based - newer hardware */
1199 if (!strcmp(boardnum
, "42")) { /* Linksys */
1200 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "1"))
1201 return &platforms
[WRT350N
];
1203 if (!strcmp(boardtype
, "0x0101") && !strcmp(getvar("boot_ver"), "v3.6"))
1204 return &platforms
[WRT54G3G
];
1206 /* default to WRT54G if no boot_hw_model is set */
1207 if (nvram_get("boot_hw_model") == NULL
)
1208 return &platforms
[WRT54G
];
1210 if (!strcmp(boardnum
, "1024") && !strcmp(boardtype
, "0x0446"))
1211 return &platforms
[WAP54GV2
];
1213 if (!strcmp(boardnum
, "8") && !strcmp(boardtype
, "0x048e"))
1214 return &platforms
[WL1600GL
];
1217 if (!strcmp(boardnum
, "44") || !strcmp(boardnum
, "44\r")) {
1218 if (!strcmp(boardtype
,"0x0101") || !strcmp(boardtype
, "0x0101\r"))
1219 return &platforms
[TM2300V2
]; /* Dell TrueMobile 2300 v2 */
1222 if (!strcmp(boardnum
, "10496"))
1223 return &platforms
[USR5461
];
1225 if (!strcmp(getvar("boardtype"), "0x0101") && !strcmp(getvar("boardrev"), "0x10")) /* SE505V2 With Modified CFE */
1226 return &platforms
[SE505V2
];
1228 if (!strcmp(boardtype
, "0x048e") && !strcmp(getvar("boardrev"),"0x35") &&
1229 !strcmp(getvar("boardflags"), "0x750")) /* D-Link DIR-320 */
1230 return &platforms
[DIR320
];
1232 if (!strncmp(boardnum
, "TH",2) && !strcmp(boardtype
,"0x042f")) {
1233 return &platforms
[WDNetCenter
];
1236 if (!strcmp(boardtype
,"0x0472") && !strcmp(getvar("cardbus"), "1")) { /* Netgear WNR834B V1 and V2*/
1237 if (!strcmp(boardnum
, "08") || !strcmp(boardnum
, "8"))
1238 return &platforms
[WNR834BV1
];
1239 if (!strcmp(boardnum
, "01") || !strcmp(boardnum
, "1"))
1240 return &platforms
[WNR834BV2
];
1243 } else { /* PMON based - old stuff */
1244 if ((simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 9) &&
1245 (simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 30)) {
1246 return &platforms
[WR850GV1
];
1248 if (startswith(boardtype
, "bcm94710dev")) {
1249 if (!strcmp(boardnum
, "42"))
1250 return &platforms
[WRT54GV1
];
1251 if (simple_strtoul(boardnum
, NULL
, 0) == 2)
1252 return &platforms
[WAP54GV1
];
1254 /* MN-700 has also hardware_version 'WL500-...', so use boardnum */
1255 if (startswith(getvar("hardware_version"), "WL500-")) {
1256 if (!strcmp(getvar("boardnum"), "mn700"))
1257 return &platforms
[MN700
];
1259 return &platforms
[WL500G
];
1261 /* Sitecom WL-105b */
1262 if (startswith(boardnum
, "2") && simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 1)
1263 return &platforms
[WL105B
];
1265 /* unknown asus stuff, probably bcm4702 */
1266 if (startswith(boardnum
, "asusX"))
1267 return &platforms
[ASUS_4702
];
1269 /* bcm4702 based Askey RT210W clones, Including:
1270 * Askey RT210W (duh?)
1272 * Belkin F5D7230-4 before version v1444 (MiniPCI slot, not integrated)
1274 if (!strcmp(boardtype
,"bcm94710r4")
1275 && !strcmp(boardnum
,"100")
1276 && !strcmp(getvar("pmon_ver"),"v1.03.12.bk")
1278 return &platforms
[RT210W
];
1282 if (boardnum
|| !strcmp(boardnum
, "00")) {/* probably buffalo */
1283 if (startswith(boardtype
, "bcm94710ap"))
1284 return &platforms
[BUFFALO_UNKNOWN_4710
];
1287 if (startswith(getvar("CFEver"), "MotoWRv2") ||
1288 startswith(getvar("CFEver"), "MotoWRv3") ||
1289 !strcmp(getvar("MOTO_BOARD_TYPE"), "WR_FEM1")) {
1291 return &platforms
[WR850GV2V3
];
1294 if (!strcmp(boardnum
, "44") && !strcmp(getvar("boardflags"),"0x0388")) { /* Trendware TEW-411BRP+ */
1295 return &platforms
[TEW411BRPP
];
1298 if (startswith(boardnum
, "04FN")) /* SimpleTech SimpleShare */
1299 return &platforms
[STI_NAS
];
1301 if (!strcmp(boardnum
, "10") && !strcmp(getvar("boardrev"), "0x13")) /* D-Link DWL-3150 */
1302 return &platforms
[DWL3150
];
1304 if (!strcmp(boardnum
, "01") && !strcmp(boardtype
, "0x048e") && /* Edimax PS1208MFG */
1305 !strcmp(getvar("status_gpio"), "1")) /* gpio based detection */
1306 return &platforms
[PS1208MFG
];
1312 static struct platform_t __init
*platform_detect(void)
1314 enum bcm47xx_board board
;
1315 const char *board_name
;
1318 board
= bcm47xx_board_get();
1319 board_name
= bcm47xx_board_get_name();
1320 if (board
!= BCM47XX_BOARD_UNKNOWN
&& board
!= BCM47XX_BOARD_NON
)
1321 printk(MODULE_NAME
": kernel found a \"%s\"\n", board_name
);
1324 case BCM47XX_BOARD_ASUS_RTN12
:
1325 return &platforms
[RTN12
];
1326 case BCM47XX_BOARD_ASUS_RTN16
:
1327 return &platforms
[RTN16
];
1328 case BCM47XX_BOARD_ASUS_RTN66U
:
1329 return &platforms
[RTN66U
];
1330 case BCM47XX_BOARD_ASUS_WL300G
:
1331 return &platforms
[WL300G
];
1332 case BCM47XX_BOARD_ASUS_WL320GE
:
1333 return &platforms
[WL320GE
];
1334 case BCM47XX_BOARD_ASUS_WL330GE
:
1335 return &platforms
[WL330GE
];
1336 case BCM47XX_BOARD_ASUS_WL500GD
:
1337 return &platforms
[WL500GD
];
1338 case BCM47XX_BOARD_ASUS_WL500GPV1
:
1339 return &platforms
[WL500GP
];
1340 case BCM47XX_BOARD_ASUS_WL500GPV2
:
1341 return &platforms
[WL500GPV2
];
1342 case BCM47XX_BOARD_ASUS_WL500W
:
1343 return &platforms
[WL500W
];
1344 case BCM47XX_BOARD_ASUS_WL520GC
:
1345 return &platforms
[WL520GC
];
1346 case BCM47XX_BOARD_ASUS_WL520GU
:
1347 return &platforms
[WL520GU
];
1348 case BCM47XX_BOARD_ASUS_WL700GE
:
1349 return &platforms
[WL700GE
];
1350 case BCM47XX_BOARD_ASUS_WLHDD
:
1351 return &platforms
[WLHDD
];
1352 case BCM47XX_BOARD_BELKIN_F7D4301
:
1353 return &platforms
[BELKIN_F7D4301
];
1354 case BCM47XX_BOARD_BUFFALO_WBR2_G54
:
1355 return &platforms
[WBR2_G54
];
1356 case BCM47XX_BOARD_BUFFALO_WHR2_A54G54
:
1357 return &platforms
[WHR2_A54G54
];
1358 case BCM47XX_BOARD_BUFFALO_WHR_G125
:
1359 return &platforms
[WHR_G125
];
1360 case BCM47XX_BOARD_BUFFALO_WHR_G54S
:
1361 return &platforms
[WHR_G54S
];
1362 case BCM47XX_BOARD_BUFFALO_WHR_HP_G54
:
1363 return &platforms
[WHR_HP_G54
];
1364 case BCM47XX_BOARD_BUFFALO_WLA2_G54L
:
1365 return &platforms
[WLA2_G54L
];
1366 case BCM47XX_BOARD_BUFFALO_WZR_G300N
:
1367 return &platforms
[WZR_G300N
];
1368 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54
:
1369 return &platforms
[WZR_RS_G54
];
1370 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54HP
:
1371 return &platforms
[WZR_RS_G54HP
];
1372 case BCM47XX_BOARD_DELL_TM2300
:
1373 return &platforms
[TM2300
];
1374 case BCM47XX_BOARD_DLINK_DIR130
:
1375 return &platforms
[DIR130
];
1376 case BCM47XX_BOARD_DLINK_DIR330
:
1377 return &platforms
[DIR330
];
1378 case BCM47XX_BOARD_HUAWEI_E970
:
1379 return &platforms
[HUAWEI_E970
];
1380 case BCM47XX_BOARD_LINKSYS_E1000V1
:
1381 return &platforms
[E1000V1
];
1382 case BCM47XX_BOARD_LINKSYS_E1000V21
:
1383 return &platforms
[E1000V21
];
1384 case BCM47XX_BOARD_LINKSYS_E3000V1
:
1385 return &platforms
[E3000V1
];
1386 case BCM47XX_BOARD_LINKSYS_E3200V1
:
1387 return &platforms
[E3200V1
];
1388 case BCM47XX_BOARD_LINKSYS_E4200V1
:
1389 return &platforms
[E4200V1
];
1390 case BCM47XX_BOARD_LINKSYS_WRT150NV1
:
1391 return &platforms
[WRT150NV1
];
1392 case BCM47XX_BOARD_LINKSYS_WRT150NV11
:
1393 return &platforms
[WRT150NV11
];
1394 case BCM47XX_BOARD_LINKSYS_WRT160NV1
:
1395 return &platforms
[WRT160NV1
];
1396 case BCM47XX_BOARD_LINKSYS_WRT160NV3
:
1397 return &platforms
[WRT160NV3
];
1398 case BCM47XX_BOARD_LINKSYS_WRT300NV11
:
1399 return &platforms
[WRT300NV11
];
1400 case BCM47XX_BOARD_LINKSYS_WRT54G3GV2
:
1401 return &platforms
[WRT54G3GV2_VF
];
1402 case BCM47XX_BOARD_LINKSYS_WRT610NV1
:
1403 return &platforms
[WRT610N
];
1404 case BCM47XX_BOARD_LINKSYS_WRT610NV2
:
1405 return &platforms
[WRT610NV2
];
1406 case BCM47XX_BOARD_LINKSYS_WRTSL54GS
:
1407 return &platforms
[WRTSL54GS
];
1408 case BCM47XX_BOARD_MOTOROLA_WE800G
:
1409 return &platforms
[WE800G
];
1410 case BCM47XX_BOARD_MOTOROLA_WR850GP
:
1411 return &platforms
[WR850GP
];
1412 case BCM47XX_BOARD_MOTOROLA_WR850GV2V3
:
1413 return &platforms
[WR850GV2V3
];
1414 case BCM47XX_BOARD_NETGEAR_WNDR3400V1
:
1415 return &platforms
[WNDR3400V1
];
1416 case BCM47XX_BOARD_NETGEAR_WNDR3700V3
:
1417 return &platforms
[WNDR3700V3
];
1418 case BCM47XX_BOARD_UNKNOWN
:
1419 case BCM47XX_BOARD_NON
:
1420 printk(MODULE_NAME
": unknown board found, try legacy detect\n");
1421 printk(MODULE_NAME
": please open a ticket at https://dev.openwrt.org and attach the complete nvram\n");
1422 return platform_detect_legacy();
1424 printk(MODULE_NAME
": board was detected as \"%s\", but not gpio configuration available\n", board_name
);
1425 printk(MODULE_NAME
": now trying legacy detect\n");
1426 return platform_detect_legacy();
1430 static inline void ssb_maskset32(struct ssb_device
*dev
,
1431 u16 offset
, u32 mask
, u32 set
)
1433 ssb_write32(dev
, offset
, (ssb_read32(dev
, offset
) & mask
) | set
);
1436 static void gpio_set_irqenable(int enabled
, irqreturn_t (*handler
)(int, void *))
1441 irq
= gpio_to_irq(0);
1443 pr_err("no irq for gpio available\n");
1448 err
= request_irq(irq
, handler
, IRQF_SHARED
, "gpio", handler
);
1450 pr_err("can not reqeust irq\n");
1454 free_irq(irq
, handler
);
1457 switch (bcm47xx_bus_type
) {
1458 #ifdef CONFIG_BCM47XX_SSB
1459 case BCM47XX_BUS_TYPE_SSB
:
1460 if (bcm47xx_bus
.ssb
.chipco
.dev
)
1461 ssb_maskset32(bcm47xx_bus
.ssb
.chipco
.dev
, SSB_CHIPCO_IRQMASK
, ~SSB_CHIPCO_IRQ_GPIO
, (enabled
? SSB_CHIPCO_IRQ_GPIO
: 0));
1464 #ifdef CONFIG_BCM47XX_BCMA
1465 case BCM47XX_BUS_TYPE_BCMA
:
1466 if (bcm47xx_bus
.bcma
.bus
.drv_cc
.core
)
1467 bcma_maskset32(bcm47xx_bus
.bcma
.bus
.drv_cc
.core
, BCMA_CC_IRQMASK
, ~BCMA_CC_IRQ_GPIO
, (enabled
? BCMA_CC_IRQ_GPIO
: 0));
1473 static void hotplug_button(struct work_struct
*work
)
1475 struct event_t
*event
= container_of(work
, struct event_t
, wq
);
1478 event
->skb
= alloc_skb(2048, GFP_KERNEL
);
1480 s
= skb_put(event
->skb
, strlen(event
->action
) + 2);
1481 sprintf(s
, "%s@", event
->action
);
1484 NETLINK_CB(event
->skb
).dst_group
= 1;
1485 broadcast_uevent(event
->skb
, 0, 1, GFP_KERNEL
);
1490 static irqreturn_t
button_handler(int irq
, void *dev_id
)
1495 in
= bcm47xx_gpio_in(~0) & platform
.button_mask
;
1496 bcm47xx_gpio_polarity(platform
.button_mask
, in
);
1497 changed
= platform
.button_polarity
^ in
;
1498 platform
.button_polarity
= in
;
1500 changed
&= ~bcm47xx_gpio_outen(0, 0);
1502 for (b
= platform
.buttons
; b
->name
; b
++) {
1503 struct event_t
*event
;
1505 if (!(b
->gpio
& changed
)) continue;
1509 if ((event
= (struct event_t
*)kzalloc (sizeof(struct event_t
), GFP_ATOMIC
))) {
1510 event
->seen
= (jiffies
- b
->seen
)/HZ
;
1511 event
->name
= b
->name
;
1512 event
->action
= b
->pressed
? "pressed" : "released";
1513 INIT_WORK(&event
->wq
, (void *)(void *)hotplug_button
);
1514 schedule_work(&event
->wq
);
1522 static void register_buttons(struct button_t
*b
)
1524 for (; b
->name
; b
++)
1525 platform
.button_mask
|= b
->gpio
;
1527 platform
.button_mask
&= ~gpiomask
;
1529 bcm47xx_gpio_outen(platform
.button_mask
, 0);
1530 bcm47xx_gpio_control(platform
.button_mask
, 0);
1531 platform
.button_polarity
= bcm47xx_gpio_in(~0) & platform
.button_mask
;
1532 bcm47xx_gpio_polarity(platform
.button_mask
, platform
.button_polarity
);
1533 bcm47xx_gpio_intmask(platform
.button_mask
, platform
.button_mask
);
1535 gpio_set_irqenable(1, button_handler
);
1538 static void unregister_buttons(struct button_t
*b
)
1540 bcm47xx_gpio_intmask(platform
.button_mask
, 0);
1542 gpio_set_irqenable(0, button_handler
);
1546 static void add_msg(struct event_t
*event
, char *msg
, int argv
)
1553 s
= skb_put(event
->skb
, strlen(msg
) + 1);
1557 static int fill_event (struct event_t
*event
)
1559 static char buf
[128];
1561 add_msg(event
, "HOME=/", 0);
1562 add_msg(event
, "PATH=/sbin:/bin:/usr/sbin:/usr/bin", 0);
1563 add_msg(event
, "SUBSYSTEM=button", 0);
1564 snprintf(buf
, 128, "ACTION=%s", event
->action
);
1565 add_msg(event
, buf
, 0);
1566 snprintf(buf
, 128, "BUTTON=%s", event
->name
);
1567 add_msg(event
, buf
, 0);
1568 snprintf(buf
, 128, "SEEN=%ld", event
->seen
);
1569 add_msg(event
, buf
, 0);
1570 snprintf(buf
, 128, "SEQNUM=%llu", uevent_next_seqnum());
1571 add_msg(event
, buf
, 0);
1577 * This should be extended to allow the platform to specify the pins and width
1578 * of the shift register. They're hardcoded for now because only the WNDR3700v3
1581 static void shiftreg_output(unsigned int val
)
1585 bcm47xx_gpio_out(SHIFTREG_DATA
, SHIFTREG_DATA
); /* init off, pull high */
1586 bcm47xx_gpio_out(SHIFTREG_CLK
, 0); /* init reset */
1589 for(mask
= 1 << (SHIFTREG_MAX_BITS
-1); mask
; mask
>>= 1)
1591 bcm47xx_gpio_out(SHIFTREG_DATA
, (val
& mask
) ? SHIFTREG_DATA
: 0);
1592 bcm47xx_gpio_out(SHIFTREG_CLK
, SHIFTREG_CLK
); /* pull high to trigger */
1593 bcm47xx_gpio_out(SHIFTREG_CLK
, 0); /* reset to low */
1597 static void set_led_shift(struct led_t
*led
)
1599 static u32 shiftreg
= 0;
1601 u32 pin
= (led
->gpio
& ~GPIO_TYPE_MASK
);
1609 /* Clock the bits out. */
1610 if (shiftreg
!= old
) {
1611 shiftreg_output(shiftreg
);
1615 static void set_led_extif(struct led_t
*led
)
1617 volatile u8
*addr
= (volatile u8
*) KSEG1ADDR(EXTIF_UART
) + (led
->gpio
& ~GPIO_TYPE_MASK
);
1625 static void led_flash(unsigned long dummy
) {
1630 for (l
= platform
.leds
; l
->name
; l
++) {
1631 if (!l
->flash
) continue;
1632 switch (l
->gpio
& GPIO_TYPE_MASK
) {
1633 case GPIO_TYPE_EXTIF
:
1635 l
->state
= !l
->state
;
1638 case GPIO_TYPE_SHIFT
:
1640 l
->state
= !l
->state
;
1643 case GPIO_TYPE_NORMAL
:
1652 u32 val
= ~bcm47xx_gpio_in(~0);
1654 bcm47xx_gpio_outen(mask
, mask
);
1655 bcm47xx_gpio_control(mask
, 0);
1656 bcm47xx_gpio_out(mask
, val
);
1658 if (mask
|| extif_blink
) {
1659 mod_timer(&led_timer
, jiffies
+ FLASH_TIME
);
1663 static int diag_led_show(struct seq_file
*m
, void *v
)
1665 struct led_t
* led
= m
->private;
1667 u8 p
= (led
->polarity
== NORMAL
? 0 : 1);
1669 return seq_printf(m
, "f\n");
1670 } else if ((led
->gpio
& GPIO_TYPE_MASK
) != GPIO_TYPE_NORMAL
) {
1671 return seq_printf(m
, "%d\n", ((led
->state
^ p
) ? 1 : 0));
1673 u32 in
= (bcm47xx_gpio_in(~0) & led
->gpio
? 1 : 0);
1674 return seq_printf(m
, "%d\n", ((in
^ p
) ? 1 : 0));
1678 static int diag_led_open(struct inode
*inode
, struct file
*file
)
1680 return single_open(file
, diag_led_show
, PDE_DATA(inode
));
1683 static ssize_t
diag_led_write(struct file
*file
, const char __user
*buf
, size_t count
, loff_t
*ppos
)
1685 struct led_t
*led
= PDE_DATA(file_inode(file
));
1690 len
= min(count
, sizeof(cmd
) - 1);
1691 if (copy_from_user(cmd
, buf
, len
))
1696 p
= (led
->polarity
== NORMAL
? 0 : 1);
1697 if (cmd
[0] == 'f') {
1702 if ((led
->gpio
& GPIO_TYPE_MASK
) == GPIO_TYPE_EXTIF
) {
1703 led
->state
= p
^ ((cmd
[0] == '1') ? 1 : 0);
1705 } else if ((led
->gpio
& GPIO_TYPE_MASK
) == GPIO_TYPE_SHIFT
) {
1706 led
->state
= p
^ ((cmd
[0] == '1') ? 1 : 0);
1709 bcm47xx_gpio_outen(led
->gpio
, led
->gpio
);
1710 bcm47xx_gpio_control(led
->gpio
, 0);
1711 bcm47xx_gpio_out(led
->gpio
, ((p
^ (cmd
[0] == '1')) ? led
->gpio
: 0));
1717 static const struct file_operations diag_led_fops
= {
1718 .open
= diag_led_open
,
1720 .llseek
= seq_lseek
,
1721 .write
= diag_led_write
1724 static void register_leds(struct led_t
*l
)
1726 struct proc_dir_entry
*p
;
1731 leds
= proc_mkdir("led", diag
);
1735 for(; l
->name
; l
++) {
1736 if (l
->gpio
& gpiomask
)
1739 switch (l
->gpio
& GPIO_TYPE_MASK
) {
1740 case GPIO_TYPE_EXTIF
:
1744 case GPIO_TYPE_SHIFT
:
1745 mask
|= (SHIFTREG_DATA
| SHIFTREG_CLK
);
1746 oe_mask
|= (SHIFTREG_DATA
| SHIFTREG_CLK
);
1747 l
->state
= (l
->polarity
!= NORMAL
);
1750 case GPIO_TYPE_NORMAL
:
1752 if (l
->polarity
!= INPUT
) oe_mask
|= l
->gpio
;
1754 val
|= (l
->polarity
== NORMAL
)?0:l
->gpio
;
1758 if (l
->polarity
== INPUT
) continue;
1760 p
= proc_create_data(l
->name
, S_IRUSR
, leds
, &diag_led_fops
, l
);
1763 bcm47xx_gpio_outen(mask
, oe_mask
);
1764 bcm47xx_gpio_control(mask
, 0);
1765 bcm47xx_gpio_out(mask
, val
);
1766 bcm47xx_gpio_intmask(mask
, 0);
1769 static void unregister_leds(struct led_t
*l
)
1772 remove_proc_entry(l
->name
, leds
);
1774 remove_proc_entry("led", diag
);
1777 static int diag_model_show(struct seq_file
*m
, void *v
)
1779 return seq_printf(m
, "%s\n", platform
.name
);
1782 static int diag_model_open(struct inode
*inode
, struct file
*file
)
1784 return single_open(file
, diag_model_show
, PDE_DATA(inode
));
1787 static const struct file_operations diag_model_fops
= {
1788 .open
= diag_model_open
,
1793 static int diag_gpiomask_show(struct seq_file
*m
, void *v
)
1795 return seq_printf(m
, "0x%04x\n", gpiomask
);
1798 static int diag_gpiomask_open(struct inode
*inode
, struct file
*file
)
1800 return single_open(file
, diag_gpiomask_show
, PDE_DATA(inode
));
1803 static ssize_t
diag_gpiomask_write(struct file
*file
, const char __user
*buf
, size_t count
, loff_t
*ppos
)
1805 int err
= kstrtouint_from_user(buf
, count
, 0, &gpiomask
);
1809 if (platform
.buttons
) {
1810 unregister_buttons(platform
.buttons
);
1811 register_buttons(platform
.buttons
);
1814 if (platform
.leds
) {
1815 unregister_leds(platform
.leds
);
1816 register_leds(platform
.leds
);
1822 static const struct file_operations diag_gpiomask_fops
= {
1823 .open
= diag_gpiomask_open
,
1825 .llseek
= seq_lseek
,
1826 .write
= diag_gpiomask_write
1829 static int __init
diag_init(void)
1831 static struct proc_dir_entry
*p
;
1832 static struct platform_t
*detected
;
1834 detected
= platform_detect();
1836 printk(MODULE_NAME
": Router model not detected.\n");
1839 memcpy(&platform
, detected
, sizeof(struct platform_t
));
1841 printk(MODULE_NAME
": Detected '%s'\n", platform
.name
);
1842 if (platform
.platform_init
!= NULL
) {
1843 platform
.platform_init();
1846 if (!(diag
= proc_mkdir("diag", NULL
))) {
1847 printk(MODULE_NAME
": proc_mkdir on /proc/diag failed\n");
1851 p
= proc_create("model", S_IRUSR
, diag
, &diag_model_fops
);
1853 remove_proc_entry("diag", NULL
);
1857 p
= proc_create("gpiomask", S_IRUSR
| S_IWUSR
, diag
, &diag_gpiomask_fops
);
1859 remove_proc_entry("model", diag
);
1860 remove_proc_entry("diag", NULL
);
1864 if (platform
.buttons
)
1865 register_buttons(platform
.buttons
);
1868 register_leds(platform
.leds
);
1873 static void __exit
diag_exit(void)
1875 del_timer(&led_timer
);
1877 if (platform
.buttons
)
1878 unregister_buttons(platform
.buttons
);
1881 unregister_leds(platform
.leds
);
1883 remove_proc_entry("model", diag
);
1884 remove_proc_entry("gpiomask", diag
);
1885 remove_proc_entry("diag", NULL
);
1888 module_init(diag_init
);
1889 module_exit(diag_exit
);
1891 MODULE_AUTHOR("Mike Baker, Felix Fietkau / OpenWrt.org");
1892 MODULE_LICENSE("GPL");