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
;
122 BUFFALO_UNKNOWN_4710
,
167 /* Western Digital */
183 static void __init
bcm4780_init(void) {
186 /* Enables GPIO 3 that controls HDD and led power on ASUS WL-700gE */
187 printk(MODULE_NAME
": Spinning up HDD and enabling leds\n");
188 bcm47xx_gpio_outen(pin
, pin
);
189 bcm47xx_gpio_control(pin
, 0);
190 bcm47xx_gpio_out(pin
, pin
);
192 /* Wait 5s, so the HDD can spin up */
193 set_current_state(TASK_INTERRUPTIBLE
);
194 schedule_timeout(HZ
* 5);
197 static void __init
NetCenter_init(void) {
198 /* unset pin 6 (+12V) */
200 bcm47xx_gpio_outen(pin
, pin
);
201 bcm47xx_gpio_control(pin
, 0);
202 bcm47xx_gpio_out(pin
, pin
);
203 /* unset pin 1 (turn off red led, blue will light alone if +5V comes up) */
205 bcm47xx_gpio_outen(pin
, pin
);
206 bcm47xx_gpio_control(pin
, 0);
207 bcm47xx_gpio_out(pin
, pin
);
208 /* unset pin 3 (+5V) and wait 5 seconds (harddisk spin up) */
212 static void __init
bcm57xx_init(void) {
215 /* FIXME: switch comes up, but port mappings/vlans not right */
216 bcm47xx_gpio_outen(pin
, pin
);
217 bcm47xx_gpio_control(pin
, 0);
218 bcm47xx_gpio_out(pin
, pin
);
221 static struct platform_t __initdata platforms
[] = {
224 .name
= "Linksys WAP54G V1",
226 { .name
= "reset", .gpio
= 1 << 0 },
229 { .name
= "diag", .gpio
= 1 << 3 },
230 { .name
= "wlan", .gpio
= 1 << 4 },
234 .name
= "Linksys WAP54G V2",
236 { .name
= "reset", .gpio
= 1 << 0 },
239 { .name
= "wlan", .gpio
= 1 << 5, .polarity
= REVERSE
},
240 /* GPIO 6 is b44 (eth0, LAN) PHY power */
244 .name
= "Linksys WAP54G V3",
246 /* FIXME: verify this */
247 { .name
= "reset", .gpio
= 1 << 7 },
248 { .name
= "ses", .gpio
= 1 << 0 },
252 { .name
= "ses", .gpio
= 1 << 1 },
256 .name
= "Linksys WRT54G V1.x",
258 { .name
= "reset", .gpio
= 1 << 6 },
261 { .name
= "diag", .gpio
= 0x13 | GPIO_TYPE_EXTIF
, .polarity
= NORMAL
},
262 { .name
= "dmz", .gpio
= 0x12 | GPIO_TYPE_EXTIF
, .polarity
= NORMAL
},
266 .name
= "Linksys WRT54G/GS/GL",
268 { .name
= "reset", .gpio
= 1 << 6 },
269 { .name
= "ses", .gpio
= 1 << 4 },
272 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
273 { .name
= "dmz", .gpio
= 1 << 7, .polarity
= REVERSE
},
274 { .name
= "ses_white", .gpio
= 1 << 2, .polarity
= REVERSE
},
275 { .name
= "ses_orange", .gpio
= 1 << 3, .polarity
= REVERSE
},
276 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
280 .name
= "Linksys WRTSL54GS",
282 { .name
= "reset", .gpio
= 1 << 6 },
283 { .name
= "ses", .gpio
= 1 << 4 },
286 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
287 { .name
= "dmz", .gpio
= 1 << 0, .polarity
= REVERSE
},
288 { .name
= "ses_white", .gpio
= 1 << 5, .polarity
= REVERSE
},
289 { .name
= "ses_orange", .gpio
= 1 << 7, .polarity
= REVERSE
},
293 .name
= "Linksys WRT54G3G",
295 { .name
= "reset", .gpio
= 1 << 6 },
296 { .name
= "3g", .gpio
= 1 << 4 },
299 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
300 { .name
= "dmz", .gpio
= 1 << 7, .polarity
= REVERSE
},
301 { .name
= "3g_green", .gpio
= 1 << 2, .polarity
= NORMAL
},
302 { .name
= "3g_blue", .gpio
= 1 << 3, .polarity
= NORMAL
},
303 { .name
= "3g_blink", .gpio
= 1 << 5, .polarity
= NORMAL
},
307 .name
= "Linksys WRT54G3GV2-VF",
309 { .name
= "reset", .gpio
= 1 << 6 },
310 { .name
= "3g", .gpio
= 1 << 5 },
313 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
314 { .name
= "3g_green", .gpio
= 1 << 2, .polarity
= NORMAL
},
315 { .name
= "3g_blue", .gpio
= 1 << 3, .polarity
= NORMAL
},
319 .name
= "Linksys WRT150N V1",
321 { .name
= "reset", .gpio
= 1 << 6 },
322 { .name
= "ses", .gpio
= 1 << 4 },
325 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
326 { .name
= "ses_green", .gpio
= 1 << 5, .polarity
= REVERSE
},
327 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
331 .name
= "Linksys WRT150N V1.1",
333 { .name
= "reset", .gpio
= 1 << 6 },
334 { .name
= "ses", .gpio
= 1 << 4 },
337 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
338 { .name
= "ses_green", .gpio
= 1 << 5, .polarity
= REVERSE
},
339 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
343 .name
= "Linksys WRT160N v1.x",
345 { .name
= "reset", .gpio
= 1 << 6 },
346 { .name
= "ses", .gpio
= 1 << 4 },
349 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
350 { .name
= "ses_blue", .gpio
= 1 << 5, .polarity
= REVERSE
},
351 { .name
= "ses_orange", .gpio
= 1 << 3, .polarity
= REVERSE
},
355 .name
= "Linksys WRT160N V3",
357 { .name
= "reset", .gpio
= 1 << 6 },
358 { .name
= "ses", .gpio
= 1 << 5 },
361 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
362 { .name
= "ses_blue", .gpio
= 1 << 4, .polarity
= REVERSE
},
363 { .name
= "ses_orange", .gpio
= 1 << 2, .polarity
= REVERSE
},
367 .name
= "Linksys WRT300N V1.1",
369 { .name
= "reset", .gpio
= 1 << 6 }, // "Reset" on back panel
370 { .name
= "ses", .gpio
= 1 << 4 }, // "Reserved" on top panel
373 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
}, // "Power"
374 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
}, // "Security" Amber
375 { .name
= "ses_green", .gpio
= 1 << 5, .polarity
= REVERSE
}, // "Security" Green
377 .platform_init
= bcm57xx_init
,
380 .name
= "Linksys WRT350N",
382 { .name
= "reset", .gpio
= 1 << 6 },
383 { .name
= "ses", .gpio
= 1 << 8 },
386 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
387 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
388 { .name
= "ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
},
389 { .name
= "usb_blink", .gpio
= 1 << 10, .polarity
= REVERSE
},
390 { .name
= "usb", .gpio
= 1 << 11, .polarity
= REVERSE
},
392 .platform_init
= bcm57xx_init
,
395 .name
= "Linksys WRT600N",
397 { .name
= "reset", .gpio
= 1 << 6 },
398 { .name
= "ses", .gpio
= 1 << 7 },
401 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
}, // Power LED
402 { .name
= "usb", .gpio
= 1 << 3, .polarity
= REVERSE
}, // USB LED
403 { .name
= "wl0_ses_amber", .gpio
= 1 << 8, .polarity
= REVERSE
}, // 2.4Ghz LED Amber
404 { .name
= "wl0_ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
}, // 2.4Ghz LED Green
405 { .name
= "wl1_ses_amber", .gpio
= 1 << 10, .polarity
= REVERSE
}, // 5.6Ghz LED Amber
406 { .name
= "wl1_ses_green", .gpio
= 1 << 11, .polarity
= REVERSE
}, // 5.6Ghz LED Green
408 .platform_init
= bcm57xx_init
,
411 .name
= "Linksys WRT600N V1.1",
413 { .name
= "reset", .gpio
= 1 << 6 },
414 { .name
= "ses", .gpio
= 1 << 7 },
417 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
}, // Power LED
418 { .name
= "usb", .gpio
= 1 << 3, .polarity
= REVERSE
}, // USB LED
419 { .name
= "wl0_ses_amber", .gpio
= 1 << 8, .polarity
= REVERSE
}, // 2.4Ghz LED Amber
420 { .name
= "wl0_ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
}, // 2.4Ghz LED Green
421 { .name
= "wl1_ses_amber", .gpio
= 1 << 10, .polarity
= REVERSE
}, // 5.6Ghz LED Amber
422 { .name
= "wl1_ses_green", .gpio
= 1 << 11, .polarity
= REVERSE
}, // 5.6Ghz LED Green
424 .platform_init
= bcm57xx_init
,
427 .name
= "Linksys WRT610N",
429 { .name
= "reset", .gpio
= 1 << 6 },
430 { .name
= "ses", .gpio
= 1 << 8 },
433 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
}, // Power LED
434 { .name
= "usb", .gpio
= 1 << 0, .polarity
= REVERSE
}, // USB LED
435 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
}, // WiFi protected setup LED amber
436 { .name
= "ses_blue", .gpio
= 1 << 9, .polarity
= REVERSE
}, // WiFi protected setup LED blue
440 .name
= "Linksys WRT610N V2",
442 { .name
= "reset", .gpio
= 1 << 6 },
443 { .name
= "ses", .gpio
= 1 << 4 },
446 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
}, // Power LED
447 { .name
= "usb", .gpio
= 1 << 7, .polarity
= NORMAL
}, // USB LED
448 { .name
= "ses_amber", .gpio
= 1 << 0, .polarity
= REVERSE
}, // WiFi protected setup LED amber
449 { .name
= "ses_blue", .gpio
= 1 << 3, .polarity
= REVERSE
}, // WiFi protected setup LED blue
450 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
}, // Wireless LED
453 /* same hardware as WRT160NV3 and Cisco Valet M10V1, but different board detection, combine? */
455 .name
= "Linksys E1000 V1",
457 { .name
= "reset", .gpio
= 1 << 6 },
458 { .name
= "wps", .gpio
= 1 << 5 }, /* nvram get gpio5=wps_button */
461 /** turns on leds for all ethernet ports (wan too)
462 * this also disconnects some, or maybe all, ethernet ports
463 * 1: leds work normally
464 * 0: all lit all the time */
465 /* nvram get gpio3=robo_reset */
466 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
467 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
468 { .name
= "ses_blue", .gpio
= 1 << 4, .polarity
= REVERSE
}, /* nvram get gpio4=wps_led */
469 { .name
= "ses_orange", .gpio
= 1 << 2, .polarity
= REVERSE
}, /* nvram get gpio2=wps_status_led */
473 .name
= "Linksys E3000 V1",
475 { .name
= "reset", .gpio
= 1 << 6 },
476 { .name
= "ses", .gpio
= 1 << 4 },
479 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
}, // Power LED
480 { .name
= "usb", .gpio
= 1 << 7, .polarity
= NORMAL
}, // USB LED
481 { .name
= "ses_amber", .gpio
= 1 << 0, .polarity
= REVERSE
}, // WiFi protected setup LED amber
482 { .name
= "ses_blue", .gpio
= 1 << 3, .polarity
= REVERSE
}, // WiFi protected setup LED blue
483 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
}, // Wireless LED
487 .name
= "Linksys E3200 V1",
489 /* { .name = "switch", .gpio = 1 << 4 },*/ /* nvram get gpio4=robo_reset */
490 { .name
= "reset", .gpio
= 1 << 5 }, /* nvram get reset_gpio=5 */
491 { .name
= "wps", .gpio
= 1 << 8 }, /* nvram get gpio8=wps_button */
492 /* { .name = "wombo", .gpio = 1 << 23 },*/ /* nvram get gpio23=wombo_reset - wireless on motherboard */
495 { .name
= "power", .gpio
= 1 << 3, .polarity
= REVERSE
}, /* Power LED */
500 .name
= "ASUS WL-HDD",
502 { .name
= "reset", .gpio
= 1 << 6 },
505 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
506 { .name
= "usb", .gpio
= 1 << 2, .polarity
= REVERSE
},
510 .name
= "ASUS WL-300g",
512 { .name
= "reset", .gpio
= 1 << 6 },
515 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
519 .name
= "ASUS WL-320gE/WL-320gP",
521 { .name
= "reset", .gpio
= 1 << 6 },
524 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
525 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
},
526 { .name
= "link", .gpio
= 1 << 11, .polarity
= REVERSE
},
530 .name
= "ASUS WL-330gE",
532 { .name
= "reset", .gpio
= 1 << 2 },
535 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
539 .name
= "ASUS WL-500g",
541 { .name
= "reset", .gpio
= 1 << 6 },
544 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
548 .name
= "ASUS WL-500g Deluxe",
550 { .name
= "reset", .gpio
= 1 << 6 },
553 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
557 .name
= "ASUS WL-500g Premium",
559 { .name
= "reset", .gpio
= 1 << 0 },
560 { .name
= "ses", .gpio
= 1 << 4 },
563 { .name
= "power", .gpio
= 1 << 1, .polarity
= REVERSE
},
567 .name
= "ASUS WL-500g Premium V2",
569 { .name
= "reset", .gpio
= 1 << 2 },
570 { .name
= "ses", .gpio
= 1 << 3 },
573 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
574 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
578 .name
= "ASUS WL-500W",
580 { .name
= "reset", .gpio
= 1 << 6 },
581 { .name
= "ses", .gpio
= 1 << 7 },
584 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
588 .name
= "ASUS WL-520GC",
590 { .name
= "reset", .gpio
= 1 << 2 },
591 { .name
= "ses", .gpio
= 1 << 3 },
594 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
595 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
599 .name
= "ASUS WL-520gU",
601 { .name
= "reset", .gpio
= 1 << 2 },
602 { .name
= "ses", .gpio
= 1 << 3 },
605 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
606 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
610 .name
= "ASUS (unknown, BCM4702)",
612 { .name
= "reset", .gpio
= 1 << 6 },
615 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
619 .name
= "ASUS WL-700gE",
621 { .name
= "reset", .gpio
= 1 << 7 }, // on back, hardwired, always resets device regardless OS state
622 { .name
= "ses", .gpio
= 1 << 4 }, // on back, actual name ezsetup
623 { .name
= "power", .gpio
= 1 << 0 }, // on front
624 { .name
= "copy", .gpio
= 1 << 6 }, // on front
628 // GPIO that controls power led also enables/disables some essential functions
631 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
}, // actual name power
633 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
635 .platform_init
= bcm4780_init
,
638 .name
= "ASUS RT-N16",
640 { .name
= "reset", .gpio
= 1 << 8 },
641 { .name
= "ses", .gpio
= 1 << 5 },
644 { .name
= "power", .gpio
= 1 << 1, .polarity
= REVERSE
},
645 { .name
= "wlan", .gpio
= 1 << 7, .polarity
= NORMAL
},
650 .name
= "Buffalo WHR-G54S",
652 { .name
= "reset", .gpio
= 1 << 4 },
653 { .name
= "bridge", .gpio
= 1 << 5 },
654 { .name
= "ses", .gpio
= 1 << 0 },
657 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
658 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
659 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
660 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
661 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
665 .name
= "Buffalo WBR2-G54",
668 { .name
= "reset", .gpio
= 1 << 7 },
671 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
675 .name
= "Buffalo WHR-HP-G54",
677 { .name
= "reset", .gpio
= 1 << 4 },
678 { .name
= "bridge", .gpio
= 1 << 5 },
679 { .name
= "ses", .gpio
= 1 << 0 },
682 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
683 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
684 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
685 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
686 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
690 .name
= "Buffalo WHR-G125",
692 { .name
= "reset", .gpio
= 1 << 4 },
693 { .name
= "bridge", .gpio
= 1 << 5 },
694 { .name
= "ses", .gpio
= 1 << 0 },
697 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
698 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
699 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
700 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
701 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
705 .name
= "Buffalo WHR2-A54G54",
707 { .name
= "reset", .gpio
= 1 << 4 },
710 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
714 .name
= "Buffalo WLA2-G54L",
717 { .name
= "reset", .gpio
= 1 << 7 },
720 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
724 .name
= "Buffalo WZR-G300N",
726 { .name
= "reset", .gpio
= 1 << 4 },
729 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
730 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
731 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
735 .name
= "Buffalo WZR-RS-G54",
737 { .name
= "ses", .gpio
= 1 << 0 },
738 { .name
= "reset", .gpio
= 1 << 4 },
741 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
742 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
743 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
747 .name
= "Buffalo WZR-RS-G54HP",
749 { .name
= "ses", .gpio
= 1 << 0 },
750 { .name
= "reset", .gpio
= 1 << 4 },
753 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
754 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
755 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
758 [BUFFALO_UNKNOWN
] = {
759 .name
= "Buffalo (unknown)",
761 { .name
= "reset", .gpio
= 1 << 7 },
764 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
767 [BUFFALO_UNKNOWN_4710
] = {
768 .name
= "Buffalo (unknown, BCM4710)",
770 { .name
= "reset", .gpio
= 1 << 4 },
773 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
778 .name
= "Siemens SE505 V1",
780 /* No usable buttons */
783 // { .name = "power", .gpio = 1 << 0 .polarity = REVERSE }, // Usable when retrofitting D26 (?)
784 { .name
= "dmz", .gpio
= 1 << 4, .polarity
= REVERSE
}, // actual name WWW
785 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
789 .name
= "Siemens SE505 V2",
791 /* No usable buttons */
794 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
795 { .name
= "dmz", .gpio
= 1 << 0, .polarity
= REVERSE
}, // actual name WWW
796 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
801 .name
= "U.S. Robotics USR5461",
803 /* No usable buttons */
806 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
807 { .name
= "printer", .gpio
= 1 << 1, .polarity
= REVERSE
},
812 .name
= "Dell TrueMobile 2300",
814 { .name
= "reset", .gpio
= 1 << 0 },
817 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
818 { .name
= "power", .gpio
= 1 << 7, .polarity
= REVERSE
},
822 .name
= "Dell TrueMobile 2300 v2",
824 { .name
= "reset", .gpio
= 1 << 0 },
827 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
828 { .name
= "power", .gpio
= 1 << 7, .polarity
= REVERSE
},
833 .name
= "Motorola WE800G",
835 { .name
= "reset", .gpio
= 1 << 0 },
838 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
839 { .name
= "diag", .gpio
= 1 << 2, .polarity
= REVERSE
},
840 { .name
= "wlan_amber", .gpio
= 1 << 1, .polarity
= NORMAL
},
844 .name
= "Motorola WR850G V1",
846 { .name
= "reset", .gpio
= 1 << 0 },
849 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
850 { .name
= "diag", .gpio
= 1 << 3, .polarity
= REVERSE
},
851 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= NORMAL
},
852 { .name
= "wlan_red", .gpio
= 1 << 5, .polarity
= REVERSE
},
853 { .name
= "wlan_green", .gpio
= 1 << 7, .polarity
= REVERSE
},
857 .name
= "Motorola WR850G V2/V3",
859 { .name
= "reset", .gpio
= 1 << 5 },
862 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
863 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
864 { .name
= "wan", .gpio
= 1 << 6, .polarity
= INPUT
},
865 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
869 .name
= "Motorola WR850GP",
871 { .name
= "reset", .gpio
= 1 << 5 },
874 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
875 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
876 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= REVERSE
},
877 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
883 .name
= "Belkin (unknown)",
884 /* FIXME: verify & add detection */
886 { .name
= "reset", .gpio
= 1 << 7 },
889 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
},
890 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= NORMAL
},
891 { .name
= "connected", .gpio
= 1 << 0, .polarity
= NORMAL
},
895 .name
= "Belkin PlayMax F7D4301",
897 { .name
= "reset", .gpio
= 1 << 6 },
898 { .name
= "wps", .gpio
= 1 << 8 },
901 { .name
= "power", .gpio
= 1 << 11, .polarity
= REVERSE
},
902 { .name
= "wlan", .gpio
= 1 << 13, .polarity
= REVERSE
},
903 { .name
= "led0", .gpio
= 1 << 14, .polarity
= REVERSE
},
904 { .name
= "led1", .gpio
= 1 << 15, .polarity
= REVERSE
},
909 .name
= "Netgear WGT634U",
911 { .name
= "reset", .gpio
= 1 << 2 },
914 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
},
919 .name
= "Netgear WNR834B V1",
920 .buttons
= { /* TODO: add reset button and confirm LEDs - GPIO from dd-wrt */ },
922 { .name
= "power", .gpio
= 1 << 4, .polarity
= REVERSE
},
923 { .name
= "diag", .gpio
= 1 << 5, .polarity
= REVERSE
},
924 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
929 .name
= "Netgear WNR834B V2",
931 { .name
= "reset", .gpio
= 1 << 6 },
934 { .name
= "power", .gpio
= 1 << 2, .polarity
= NORMAL
},
935 { .name
= "diag", .gpio
= 1 << 3, .polarity
= NORMAL
},
936 { .name
= "connected", .gpio
= 1 << 7, .polarity
= NORMAL
},
940 .name
= "Netgear WNDR3400 V1",
942 /* nvram get gpio5=robo_reset */
943 { .name
= "reset", .gpio
= 1 << 4 },
944 { .name
= "wps", .gpio
= 1 << 6 },
945 { .name
= "wlan", .gpio
= 1 << 8 },
948 { .name
= "wlan", .gpio
= 0 << 0, .polarity
= NORMAL
},
949 { .name
= "connected", .gpio
= 1 << 0, .polarity
= NORMAL
},
950 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
},
951 { .name
= "diag", .gpio
= 1 << 7, .polarity
= NORMAL
},
952 { .name
= "usb", .gpio
= 1 << 2, .polarity
= REVERSE
},
956 .name
= "Netgear WNDR3700 V3",
958 /* { .name = "usb", .gpio = 1 << 1 }, */ /* this button doesn't seem to exist. */
959 { .name
= "wlan", .gpio
= 1 << 2 },
960 { .name
= "reset", .gpio
= 1 << 3 },
961 { .name
= "wps", .gpio
= 1 << 4 },
962 /* { .name = "switch", .gpio = 1 << 5 },*/ /* nvram get gpio5=robo_reset */
965 { .name
= "power", .gpio
= (1 << 0) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
966 { .name
= "diag", .gpio
= (1 << 1) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
967 /* WAN LED doesn't respond to GPIO control. The switch is probably driving it.
968 * { .name = "wan", .gpio = (1 << 2) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
970 { .name
= "wlan2g", .gpio
= (1 << 3) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
971 { .name
= "wlan5g", .gpio
= (1 << 4) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
972 { .name
= "usb", .gpio
= (1 << 5) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
973 { .name
= "wps", .gpio
= (1 << 6) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
974 { .name
= "wlan", .gpio
= (1 << 7) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
979 .name
= "Trendware TEW411BRP+",
981 { /* No usable buttons */ },
984 { .name
= "power", .gpio
= 1 << 7, .polarity
= NORMAL
},
985 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
},
986 { .name
= "bridge", .gpio
= 1 << 6, .polarity
= NORMAL
},
991 .name
= "SimpleTech SimpleShare NAS",
993 { .name
= "reset", .gpio
= 1 << 0 }, // Power button on back, named reset to enable failsafe.
996 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
998 .platform_init
= bcm4780_init
,
1002 .name
= "D-Link DIR-130",
1004 { .name
= "reset", .gpio
= 1 << 3},
1005 { .name
= "reserved", .gpio
= 1 << 7},
1008 { .name
= "diag", .gpio
= 1 << 0},
1009 { .name
= "blue", .gpio
= 1 << 6},
1013 .name
= "D-Link DIR-320",
1015 { .name
= "reserved", .gpio
= 1 << 6},
1016 { .name
= "reset", .gpio
= 1 << 7},
1019 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
1020 { .name
= "diag", .gpio
= 1 << 1, .polarity
= NORMAL
}, /* "status led */
1021 { .name
= "red", .gpio
= 1 << 3, .polarity
= REVERSE
},
1022 { .name
= "blue", .gpio
= 1 << 4, .polarity
= REVERSE
},
1023 { .name
= "usb", .gpio
= 1 << 5, .polarity
= NORMAL
},
1027 .name
= "D-Link DIR-330",
1029 { .name
= "reset", .gpio
= 1 << 3},
1030 { .name
= "reserved", .gpio
= 1 << 7},
1033 { .name
= "diag", .gpio
= 1 << 0},
1034 { .name
= "usb", .gpio
= 1 << 4},
1035 { .name
= "blue", .gpio
= 1 << 6},
1039 .name
= "D-Link DWL-3150",
1041 { .name
= "reset", .gpio
= 1 << 7},
1044 { .name
= "diag", .gpio
= 1 << 2},
1045 { .name
= "status", .gpio
= 1 << 1},
1050 .name
= "Sitecom WL-105b",
1052 { .name
= "reset", .gpio
= 1 << 10},
1055 { .name
= "wlan", .gpio
= 1 << 4},
1056 { .name
= "power", .gpio
= 1 << 3},
1059 /* Western Digital Net Center */
1061 .name
= "Western Digital NetCenter",
1063 { .name
= "power", .gpio
= 1 << 0},
1064 { .name
= "reset", .gpio
= 1 << 7},
1066 .platform_init
= NetCenter_init
,
1068 /* Askey (and clones) */
1070 .name
= "Askey RT210W",
1072 /* Power button is hard-wired to hardware reset */
1073 /* but is also connected to GPIO 7 (probably for bootloader recovery) */
1074 { .name
= "power", .gpio
= 1 << 7},
1077 /* These were verified and named based on Belkin F5D4230-4 v1112 */
1078 { .name
= "connected", .gpio
= 1 << 0, .polarity
= REVERSE
},
1079 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
1080 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
1084 .name
= "OvisLink WL-1600GL",
1086 { .name
= "reset", .gpio
= 1 << 3 },
1087 { .name
= "ses", .gpio
= 1 << 4 },
1090 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
1091 { .name
= "wps", .gpio
= 1 << 2, .polarity
= REVERSE
},
1092 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
1093 { .name
= "connected", .gpio
= 1 << 0, .polarity
= REVERSE
},
1098 .name
= "Microsoft MN-700",
1100 { .name
= "reset", .gpio
= 1 << 7 },
1103 { .name
= "power", .gpio
= 1 << 6, .polarity
= NORMAL
},
1108 .name
= "Edimax PS-1208MFG",
1110 { .name
= "reset", .gpio
= 1 << 4 },
1113 { .name
= "status", .gpio
= 1 << 1, .polarity
= NORMAL
},
1114 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
1119 static struct platform_t __init
*platform_detect_legacy(void)
1121 char *boardnum
, *boardtype
;
1123 if (strcmp(getvar("nvram_type"), "cfe") == 0)
1124 return &platforms
[WGT634U
];
1127 /* no easy model number, attempt to guess */
1128 boardnum
= getvar("boardnum");
1129 boardtype
= getvar("boardtype");
1131 if (!strcmp(boardnum
, "20070615")) { /* Linksys WRT600N v1/V1.1 */
1132 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "0") && !strcmp(getvar("switch_type"),"BCM5395"))
1133 return &platforms
[WRT600NV11
];
1135 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "0"))
1136 return &platforms
[WRT600N
];
1139 if (startswith(getvar("pmon_ver"), "CFE")) {
1140 /* CFE based - newer hardware */
1141 if (!strcmp(boardnum
, "42")) { /* Linksys */
1142 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "1"))
1143 return &platforms
[WRT350N
];
1145 if (!strcmp(boardtype
, "0x0101") && !strcmp(getvar("boot_ver"), "v3.6"))
1146 return &platforms
[WRT54G3G
];
1148 if (!strcmp(getvar("et1phyaddr"),"5") && !strcmp(getvar("et1mdcport"), "1"))
1149 return &platforms
[WRTSL54GS
];
1151 /* default to WRT54G */
1152 return &platforms
[WRT54G
];
1154 if (!strcmp(boardnum
, "1024") && !strcmp(boardtype
, "0x0446"))
1155 return &platforms
[WAP54GV2
];
1157 if (!strcmp(boardnum
, "8") && !strcmp(boardtype
, "0x048e"))
1158 return &platforms
[WL1600GL
];
1161 if (!strcmp(boardnum
, "44") || !strcmp(boardnum
, "44\r")) {
1162 if (!strcmp(boardtype
,"0x0101") || !strcmp(boardtype
, "0x0101\r"))
1163 return &platforms
[TM2300V2
]; /* Dell TrueMobile 2300 v2 */
1166 if (!strcmp(boardnum
, "45")) { /* ASUS */
1167 if (!strcmp(boardtype
,"0x0472"))
1168 return &platforms
[WL500W
];
1169 else if (!strcmp(boardtype
,"0x467"))
1170 return &platforms
[WL320GE
];
1172 return &platforms
[WL500GD
];
1175 if (!strcmp(boardnum
, "10496"))
1176 return &platforms
[USR5461
];
1178 if (!strcmp(getvar("boardtype"), "0x0101") && !strcmp(getvar("boardrev"), "0x10")) /* SE505V2 With Modified CFE */
1179 return &platforms
[SE505V2
];
1181 if (!strcmp(boardtype
, "0x048e") && !strcmp(getvar("boardrev"),"0x35") &&
1182 !strcmp(getvar("boardflags"), "0x750")) /* D-Link DIR-320 */
1183 return &platforms
[DIR320
];
1185 if (!strncmp(boardnum
, "TH",2) && !strcmp(boardtype
,"0x042f")) {
1186 return &platforms
[WDNetCenter
];
1189 if (!strcmp(boardtype
,"0x0472") && !strcmp(getvar("cardbus"), "1")) { /* Netgear WNR834B V1 and V2*/
1190 if (!strcmp(boardnum
, "08") || !strcmp(boardnum
, "8"))
1191 return &platforms
[WNR834BV1
];
1192 if (!strcmp(boardnum
, "01") || !strcmp(boardnum
, "1"))
1193 return &platforms
[WNR834BV2
];
1196 } else { /* PMON based - old stuff */
1197 if ((simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 9) &&
1198 (simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 30)) {
1199 return &platforms
[WR850GV1
];
1201 if (startswith(boardtype
, "bcm94710dev")) {
1202 if (!strcmp(boardnum
, "42"))
1203 return &platforms
[WRT54GV1
];
1204 if (simple_strtoul(boardnum
, NULL
, 0) == 2)
1205 return &platforms
[WAP54GV1
];
1207 /* MN-700 has also hardware_version 'WL500-...', so use boardnum */
1208 if (startswith(getvar("hardware_version"), "WL500-")) {
1209 if (!strcmp(getvar("boardnum"), "mn700"))
1210 return &platforms
[MN700
];
1212 return &platforms
[WL500G
];
1214 if (startswith(getvar("hardware_version"), "WL300-")) {
1215 /* Either WL-300g or WL-HDD, do more extensive checks */
1216 if ((simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 0) &&
1217 (simple_strtoul(getvar("et1phyaddr"), NULL
, 0) == 1))
1218 return &platforms
[WLHDD
];
1219 if ((simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 0) &&
1220 (simple_strtoul(getvar("et1phyaddr"), NULL
, 0) == 10))
1221 return &platforms
[WL300G
];
1223 /* Sitecom WL-105b */
1224 if (startswith(boardnum
, "2") && simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 1)
1225 return &platforms
[WL105B
];
1227 /* unknown asus stuff, probably bcm4702 */
1228 if (startswith(boardnum
, "asusX"))
1229 return &platforms
[ASUS_4702
];
1231 /* bcm4702 based Askey RT210W clones, Including:
1232 * Askey RT210W (duh?)
1234 * Belkin F5D7230-4 before version v1444 (MiniPCI slot, not integrated)
1236 if (!strcmp(boardtype
,"bcm94710r4")
1237 && !strcmp(boardnum
,"100")
1238 && !strcmp(getvar("pmon_ver"),"v1.03.12.bk")
1240 return &platforms
[RT210W
];
1244 if (boardnum
|| !strcmp(boardnum
, "00")) {/* probably buffalo */
1245 if (startswith(boardtype
, "bcm94710ap"))
1246 return &platforms
[BUFFALO_UNKNOWN_4710
];
1248 return &platforms
[BUFFALO_UNKNOWN
];
1251 if (startswith(getvar("CFEver"), "MotoWRv2") ||
1252 startswith(getvar("CFEver"), "MotoWRv3") ||
1253 !strcmp(getvar("MOTO_BOARD_TYPE"), "WR_FEM1")) {
1255 return &platforms
[WR850GV2V3
];
1258 if (!strcmp(boardnum
, "44") && !strcmp(getvar("boardflags"),"0x0388")) { /* Trendware TEW-411BRP+ */
1259 return &platforms
[TEW411BRPP
];
1262 if (startswith(boardnum
, "04FN")) /* SimpleTech SimpleShare */
1263 return &platforms
[STI_NAS
];
1265 if (!strcmp(boardnum
, "10") && !strcmp(getvar("boardrev"), "0x13")) /* D-Link DWL-3150 */
1266 return &platforms
[DWL3150
];
1268 if (!strcmp(boardnum
, "01") && !strcmp(boardtype
, "0x048e") && /* Edimax PS1208MFG */
1269 !strcmp(getvar("status_gpio"), "1")) /* gpio based detection */
1270 return &platforms
[PS1208MFG
];
1276 static struct platform_t __init
*platform_detect(void)
1278 enum bcm47xx_board board
;
1279 const char *board_name
;
1282 board
= bcm47xx_board_get();
1283 board_name
= bcm47xx_board_get_name();
1284 if (board
!= BCM47XX_BOARD_UNKNOWN
&& board
!= BCM47XX_BOARD_NON
)
1285 printk(MODULE_NAME
": kernel found a \"%s\"\n", board_name
);
1288 case BCM47XX_BOARD_ASUS_RTN16
:
1289 return &platforms
[RTN16
];
1290 case BCM47XX_BOARD_ASUS_WL330GE
:
1291 return &platforms
[WL330GE
];
1292 case BCM47XX_BOARD_ASUS_WL500GPV1
:
1293 return &platforms
[WL500GP
];
1294 case BCM47XX_BOARD_ASUS_WL500GPV2
:
1295 return &platforms
[WL500GPV2
];
1296 case BCM47XX_BOARD_ASUS_WL520GC
:
1297 return &platforms
[WL520GC
];
1298 case BCM47XX_BOARD_ASUS_WL520GU
:
1299 return &platforms
[WL520GU
];
1300 case BCM47XX_BOARD_ASUS_WL700GE
:
1301 return &platforms
[WL700GE
];
1302 case BCM47XX_BOARD_BELKIN_F7D4301
:
1303 return &platforms
[BELKIN_F7D4301
];
1304 case BCM47XX_BOARD_BUFFALO_WBR2_G54
:
1305 return &platforms
[WBR2_G54
];
1306 case BCM47XX_BOARD_BUFFALO_WHR2_A54G54
:
1307 return &platforms
[WHR2_A54G54
];
1308 case BCM47XX_BOARD_BUFFALO_WHR_G125
:
1309 return &platforms
[WHR_G125
];
1310 case BCM47XX_BOARD_BUFFALO_WHR_G54S
:
1311 return &platforms
[WHR_G54S
];
1312 case BCM47XX_BOARD_BUFFALO_WHR_HP_G54
:
1313 return &platforms
[WHR_HP_G54
];
1314 case BCM47XX_BOARD_BUFFALO_WLA2_G54L
:
1315 return &platforms
[WLA2_G54L
];
1316 case BCM47XX_BOARD_BUFFALO_WZR_G300N
:
1317 return &platforms
[WZR_G300N
];
1318 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54
:
1319 return &platforms
[WZR_RS_G54
];
1320 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54HP
:
1321 return &platforms
[WZR_RS_G54HP
];
1322 case BCM47XX_BOARD_DELL_TM2300
:
1323 return &platforms
[TM2300
];
1324 case BCM47XX_BOARD_DLINK_DIR130
:
1325 return &platforms
[DIR130
];
1326 case BCM47XX_BOARD_DLINK_DIR330
:
1327 return &platforms
[DIR330
];
1328 case BCM47XX_BOARD_LINKSYS_E1000V1
:
1329 return &platforms
[E1000V1
];
1330 case BCM47XX_BOARD_LINKSYS_E3000V1
:
1331 return &platforms
[E3000V1
];
1332 case BCM47XX_BOARD_LINKSYS_E3200V1
:
1333 return &platforms
[E3200V1
];
1334 case BCM47XX_BOARD_LINKSYS_WRT150NV1
:
1335 return &platforms
[WRT150NV1
];
1336 case BCM47XX_BOARD_LINKSYS_WRT150NV11
:
1337 return &platforms
[WRT150NV11
];
1338 case BCM47XX_BOARD_LINKSYS_WRT160NV1
:
1339 return &platforms
[WRT160NV1
];
1340 case BCM47XX_BOARD_LINKSYS_WRT160NV3
:
1341 return &platforms
[WRT160NV3
];
1342 case BCM47XX_BOARD_LINKSYS_WRT300NV11
:
1343 return &platforms
[WRT300NV11
];
1344 case BCM47XX_BOARD_LINKSYS_WRT54G3GV2
:
1345 return &platforms
[WRT54G3GV2_VF
];
1346 case BCM47XX_BOARD_LINKSYS_WRT610NV1
:
1347 return &platforms
[WRT610N
];
1348 case BCM47XX_BOARD_LINKSYS_WRT610NV2
:
1349 return &platforms
[WRT610NV2
];
1350 case BCM47XX_BOARD_MOTOROLA_WE800G
:
1351 return &platforms
[WE800G
];
1352 case BCM47XX_BOARD_MOTOROLA_WR850GP
:
1353 return &platforms
[WR850GP
];
1354 case BCM47XX_BOARD_MOTOROLA_WR850GV2V3
:
1355 return &platforms
[WR850GV2V3
];
1356 case BCM47XX_BOARD_NETGEAR_WNDR3400V1
:
1357 return &platforms
[WNDR3400V1
];
1358 case BCM47XX_BOARD_NETGEAR_WNDR3700V3
:
1359 return &platforms
[WNDR3700V3
];
1360 case BCM47XX_BOARD_UNKNOWN
:
1361 case BCM47XX_BOARD_NON
:
1362 printk(MODULE_NAME
": unknown board found, try legacy detect\n");
1363 printk(MODULE_NAME
": please open a ticket at https://dev.openwrt.org and attach the complete nvram\n");
1364 return platform_detect_legacy();
1366 printk(MODULE_NAME
": board was detected as \"%s\", but not gpio configuration available\n", board_name
);
1367 printk(MODULE_NAME
": now trying legacy detect\n");
1368 return platform_detect_legacy();
1372 static inline void ssb_maskset32(struct ssb_device
*dev
,
1373 u16 offset
, u32 mask
, u32 set
)
1375 ssb_write32(dev
, offset
, (ssb_read32(dev
, offset
) & mask
) | set
);
1378 static void gpio_set_irqenable(int enabled
, irqreturn_t (*handler
)(int, void *))
1382 irq
= gpio_to_irq(0);
1383 if (irq
== -EINVAL
) return;
1386 if (request_irq(irq
, handler
, IRQF_SHARED
, "gpio", handler
))
1389 free_irq(irq
, handler
);
1392 switch (bcm47xx_bus_type
) {
1393 #ifdef CONFIG_BCM47XX_SSB
1394 case BCM47XX_BUS_TYPE_SSB
:
1395 if (bcm47xx_bus
.ssb
.chipco
.dev
)
1396 ssb_maskset32(bcm47xx_bus
.ssb
.chipco
.dev
, SSB_CHIPCO_IRQMASK
, ~SSB_CHIPCO_IRQ_GPIO
, (enabled
? SSB_CHIPCO_IRQ_GPIO
: 0));
1399 #ifdef CONFIG_BCM47XX_BCMA
1400 case BCM47XX_BUS_TYPE_BCMA
:
1401 if (bcm47xx_bus
.bcma
.bus
.drv_cc
.core
)
1402 bcma_maskset32(bcm47xx_bus
.bcma
.bus
.drv_cc
.core
, BCMA_CC_IRQMASK
, ~BCMA_CC_IRQ_GPIO
, (enabled
? BCMA_CC_IRQ_GPIO
: 0));
1408 static void hotplug_button(struct work_struct
*work
)
1410 struct event_t
*event
= container_of(work
, struct event_t
, wq
);
1413 event
->skb
= alloc_skb(2048, GFP_KERNEL
);
1415 s
= skb_put(event
->skb
, strlen(event
->action
) + 2);
1416 sprintf(s
, "%s@", event
->action
);
1419 NETLINK_CB(event
->skb
).dst_group
= 1;
1420 broadcast_uevent(event
->skb
, 0, 1, GFP_KERNEL
);
1425 static irqreturn_t
button_handler(int irq
, void *dev_id
)
1430 in
= bcm47xx_gpio_in(~0) & platform
.button_mask
;
1431 bcm47xx_gpio_polarity(platform
.button_mask
, in
);
1432 changed
= platform
.button_polarity
^ in
;
1433 platform
.button_polarity
= in
;
1435 changed
&= ~bcm47xx_gpio_outen(0, 0);
1437 for (b
= platform
.buttons
; b
->name
; b
++) {
1438 struct event_t
*event
;
1440 if (!(b
->gpio
& changed
)) continue;
1444 if ((event
= (struct event_t
*)kzalloc (sizeof(struct event_t
), GFP_ATOMIC
))) {
1445 event
->seen
= (jiffies
- b
->seen
)/HZ
;
1446 event
->name
= b
->name
;
1447 event
->action
= b
->pressed
? "pressed" : "released";
1448 INIT_WORK(&event
->wq
, (void *)(void *)hotplug_button
);
1449 schedule_work(&event
->wq
);
1457 static void register_buttons(struct button_t
*b
)
1459 for (; b
->name
; b
++)
1460 platform
.button_mask
|= b
->gpio
;
1462 platform
.button_mask
&= ~gpiomask
;
1464 bcm47xx_gpio_outen(platform
.button_mask
, 0);
1465 bcm47xx_gpio_control(platform
.button_mask
, 0);
1466 platform
.button_polarity
= bcm47xx_gpio_in(~0) & platform
.button_mask
;
1467 bcm47xx_gpio_polarity(platform
.button_mask
, platform
.button_polarity
);
1468 bcm47xx_gpio_intmask(platform
.button_mask
, platform
.button_mask
);
1470 gpio_set_irqenable(1, button_handler
);
1473 static void unregister_buttons(struct button_t
*b
)
1475 bcm47xx_gpio_intmask(platform
.button_mask
, 0);
1477 gpio_set_irqenable(0, button_handler
);
1481 static void add_msg(struct event_t
*event
, char *msg
, int argv
)
1488 s
= skb_put(event
->skb
, strlen(msg
) + 1);
1492 static int fill_event (struct event_t
*event
)
1494 static char buf
[128];
1496 add_msg(event
, "HOME=/", 0);
1497 add_msg(event
, "PATH=/sbin:/bin:/usr/sbin:/usr/bin", 0);
1498 add_msg(event
, "SUBSYSTEM=button", 0);
1499 snprintf(buf
, 128, "ACTION=%s", event
->action
);
1500 add_msg(event
, buf
, 0);
1501 snprintf(buf
, 128, "BUTTON=%s", event
->name
);
1502 add_msg(event
, buf
, 0);
1503 snprintf(buf
, 128, "SEEN=%ld", event
->seen
);
1504 add_msg(event
, buf
, 0);
1505 snprintf(buf
, 128, "SEQNUM=%llu", uevent_next_seqnum());
1506 add_msg(event
, buf
, 0);
1512 * This should be extended to allow the platform to specify the pins and width
1513 * of the shift register. They're hardcoded for now because only the WNDR3700v3
1516 static void shiftreg_output(unsigned int val
)
1520 bcm47xx_gpio_out(SHIFTREG_DATA
, SHIFTREG_DATA
); /* init off, pull high */
1521 bcm47xx_gpio_out(SHIFTREG_CLK
, 0); /* init reset */
1524 for(mask
= 1 << (SHIFTREG_MAX_BITS
-1); mask
; mask
>>= 1)
1526 bcm47xx_gpio_out(SHIFTREG_DATA
, (val
& mask
) ? SHIFTREG_DATA
: 0);
1527 bcm47xx_gpio_out(SHIFTREG_CLK
, SHIFTREG_CLK
); /* pull high to trigger */
1528 bcm47xx_gpio_out(SHIFTREG_CLK
, 0); /* reset to low */
1532 static void set_led_shift(struct led_t
*led
)
1534 static u32 shiftreg
= 0;
1536 u32 pin
= (led
->gpio
& ~GPIO_TYPE_MASK
);
1544 /* Clock the bits out. */
1545 if (shiftreg
!= old
) {
1546 shiftreg_output(shiftreg
);
1550 static void set_led_extif(struct led_t
*led
)
1552 volatile u8
*addr
= (volatile u8
*) KSEG1ADDR(EXTIF_UART
) + (led
->gpio
& ~GPIO_TYPE_MASK
);
1560 static void led_flash(unsigned long dummy
) {
1565 for (l
= platform
.leds
; l
->name
; l
++) {
1566 if (!l
->flash
) continue;
1567 switch (l
->gpio
& GPIO_TYPE_MASK
) {
1568 case GPIO_TYPE_EXTIF
:
1570 l
->state
= !l
->state
;
1573 case GPIO_TYPE_SHIFT
:
1575 l
->state
= !l
->state
;
1578 case GPIO_TYPE_NORMAL
:
1587 u32 val
= ~bcm47xx_gpio_in(~0);
1589 bcm47xx_gpio_outen(mask
, mask
);
1590 bcm47xx_gpio_control(mask
, 0);
1591 bcm47xx_gpio_out(mask
, val
);
1593 if (mask
|| extif_blink
) {
1594 mod_timer(&led_timer
, jiffies
+ FLASH_TIME
);
1598 static int diag_led_show(struct seq_file
*m
, void *v
)
1600 struct led_t
* led
= m
->private;
1602 u8 p
= (led
->polarity
== NORMAL
? 0 : 1);
1604 return seq_printf(m
, "f\n");
1605 } else if ((led
->gpio
& GPIO_TYPE_MASK
) != GPIO_TYPE_NORMAL
) {
1606 return seq_printf(m
, "%d\n", ((led
->state
^ p
) ? 1 : 0));
1608 u32 in
= (bcm47xx_gpio_in(~0) & led
->gpio
? 1 : 0);
1609 return seq_printf(m
, "%d\n", ((in
^ p
) ? 1 : 0));
1613 static int diag_led_open(struct inode
*inode
, struct file
*file
)
1615 return single_open(file
, diag_led_show
, PDE_DATA(inode
));
1618 static ssize_t
diag_led_write(struct file
*file
, const char __user
*buf
, size_t count
, loff_t
*ppos
)
1620 struct led_t
*led
= PDE_DATA(file_inode(file
));
1625 len
= min(count
, sizeof(cmd
) - 1);
1626 if (copy_from_user(cmd
, buf
, len
))
1631 p
= (led
->polarity
== NORMAL
? 0 : 1);
1632 if (cmd
[0] == 'f') {
1637 if ((led
->gpio
& GPIO_TYPE_MASK
) == GPIO_TYPE_EXTIF
) {
1638 led
->state
= p
^ ((cmd
[0] == '1') ? 1 : 0);
1640 } else if ((led
->gpio
& GPIO_TYPE_MASK
) == GPIO_TYPE_SHIFT
) {
1641 led
->state
= p
^ ((cmd
[0] == '1') ? 1 : 0);
1644 bcm47xx_gpio_outen(led
->gpio
, led
->gpio
);
1645 bcm47xx_gpio_control(led
->gpio
, 0);
1646 bcm47xx_gpio_out(led
->gpio
, ((p
^ (cmd
[0] == '1')) ? led
->gpio
: 0));
1652 static const struct file_operations diag_led_fops
= {
1653 .open
= diag_led_open
,
1655 .llseek
= seq_lseek
,
1656 .write
= diag_led_write
1659 static void register_leds(struct led_t
*l
)
1661 struct proc_dir_entry
*p
;
1666 leds
= proc_mkdir("led", diag
);
1670 for(; l
->name
; l
++) {
1671 if (l
->gpio
& gpiomask
)
1674 switch (l
->gpio
& GPIO_TYPE_MASK
) {
1675 case GPIO_TYPE_EXTIF
:
1679 case GPIO_TYPE_SHIFT
:
1680 mask
|= (SHIFTREG_DATA
| SHIFTREG_CLK
);
1681 oe_mask
|= (SHIFTREG_DATA
| SHIFTREG_CLK
);
1682 l
->state
= (l
->polarity
!= NORMAL
);
1685 case GPIO_TYPE_NORMAL
:
1687 if (l
->polarity
!= INPUT
) oe_mask
|= l
->gpio
;
1689 val
|= (l
->polarity
== NORMAL
)?0:l
->gpio
;
1693 if (l
->polarity
== INPUT
) continue;
1695 p
= proc_create_data(l
->name
, S_IRUSR
, leds
, &diag_led_fops
, l
);
1698 bcm47xx_gpio_outen(mask
, oe_mask
);
1699 bcm47xx_gpio_control(mask
, 0);
1700 bcm47xx_gpio_out(mask
, val
);
1701 bcm47xx_gpio_intmask(mask
, 0);
1704 static void unregister_leds(struct led_t
*l
)
1707 remove_proc_entry(l
->name
, leds
);
1709 remove_proc_entry("led", diag
);
1712 static int diag_model_show(struct seq_file
*m
, void *v
)
1714 return seq_printf(m
, "%s\n", platform
.name
);
1717 static int diag_model_open(struct inode
*inode
, struct file
*file
)
1719 return single_open(file
, diag_model_show
, PDE_DATA(inode
));
1722 static const struct file_operations diag_model_fops
= {
1723 .open
= diag_model_open
,
1728 static int diag_gpiomask_show(struct seq_file
*m
, void *v
)
1730 return seq_printf(m
, "0x%04x\n", gpiomask
);
1733 static int diag_gpiomask_open(struct inode
*inode
, struct file
*file
)
1735 return single_open(file
, diag_gpiomask_show
, PDE_DATA(inode
));
1738 static ssize_t
diag_gpiomask_write(struct file
*file
, const char __user
*buf
, size_t count
, loff_t
*ppos
)
1740 int err
= kstrtouint_from_user(buf
, count
, 0, &gpiomask
);
1744 if (platform
.buttons
) {
1745 unregister_buttons(platform
.buttons
);
1746 register_buttons(platform
.buttons
);
1749 if (platform
.leds
) {
1750 unregister_leds(platform
.leds
);
1751 register_leds(platform
.leds
);
1757 static const struct file_operations diag_gpiomask_fops
= {
1758 .open
= diag_gpiomask_open
,
1760 .llseek
= seq_lseek
,
1761 .write
= diag_gpiomask_write
1764 static int __init
diag_init(void)
1766 static struct proc_dir_entry
*p
;
1767 static struct platform_t
*detected
;
1769 detected
= platform_detect();
1771 printk(MODULE_NAME
": Router model not detected.\n");
1774 memcpy(&platform
, detected
, sizeof(struct platform_t
));
1776 printk(MODULE_NAME
": Detected '%s'\n", platform
.name
);
1777 if (platform
.platform_init
!= NULL
) {
1778 platform
.platform_init();
1781 if (!(diag
= proc_mkdir("diag", NULL
))) {
1782 printk(MODULE_NAME
": proc_mkdir on /proc/diag failed\n");
1786 p
= proc_create("model", S_IRUSR
, diag
, &diag_model_fops
);
1788 remove_proc_entry("diag", NULL
);
1792 p
= proc_create("gpiomask", S_IRUSR
| S_IWUSR
, diag
, &diag_gpiomask_fops
);
1794 remove_proc_entry("model", diag
);
1795 remove_proc_entry("diag", NULL
);
1799 if (platform
.buttons
)
1800 register_buttons(platform
.buttons
);
1803 register_leds(platform
.leds
);
1808 static void __exit
diag_exit(void)
1810 del_timer(&led_timer
);
1812 if (platform
.buttons
)
1813 unregister_buttons(platform
.buttons
);
1816 unregister_leds(platform
.leds
);
1818 remove_proc_entry("model", diag
);
1819 remove_proc_entry("gpiomask", diag
);
1820 remove_proc_entry("diag", NULL
);
1823 module_init(diag_init
);
1824 module_exit(diag_exit
);
1826 MODULE_AUTHOR("Mike Baker, Felix Fietkau / OpenWrt.org");
1827 MODULE_LICENSE("GPL");