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 /* default to WRT54G */
1149 return &platforms
[WRT54G
];
1151 if (!strcmp(boardnum
, "1024") && !strcmp(boardtype
, "0x0446"))
1152 return &platforms
[WAP54GV2
];
1154 if (!strcmp(boardnum
, "8") && !strcmp(boardtype
, "0x048e"))
1155 return &platforms
[WL1600GL
];
1158 if (!strcmp(boardnum
, "44") || !strcmp(boardnum
, "44\r")) {
1159 if (!strcmp(boardtype
,"0x0101") || !strcmp(boardtype
, "0x0101\r"))
1160 return &platforms
[TM2300V2
]; /* Dell TrueMobile 2300 v2 */
1163 if (!strcmp(boardnum
, "45")) { /* ASUS */
1164 if (!strcmp(boardtype
,"0x0472"))
1165 return &platforms
[WL500W
];
1166 else if (!strcmp(boardtype
,"0x467"))
1167 return &platforms
[WL320GE
];
1169 return &platforms
[WL500GD
];
1172 if (!strcmp(boardnum
, "10496"))
1173 return &platforms
[USR5461
];
1175 if (!strcmp(getvar("boardtype"), "0x0101") && !strcmp(getvar("boardrev"), "0x10")) /* SE505V2 With Modified CFE */
1176 return &platforms
[SE505V2
];
1178 if (!strcmp(boardtype
, "0x048e") && !strcmp(getvar("boardrev"),"0x35") &&
1179 !strcmp(getvar("boardflags"), "0x750")) /* D-Link DIR-320 */
1180 return &platforms
[DIR320
];
1182 if (!strncmp(boardnum
, "TH",2) && !strcmp(boardtype
,"0x042f")) {
1183 return &platforms
[WDNetCenter
];
1186 if (!strcmp(boardtype
,"0x0472") && !strcmp(getvar("cardbus"), "1")) { /* Netgear WNR834B V1 and V2*/
1187 if (!strcmp(boardnum
, "08") || !strcmp(boardnum
, "8"))
1188 return &platforms
[WNR834BV1
];
1189 if (!strcmp(boardnum
, "01") || !strcmp(boardnum
, "1"))
1190 return &platforms
[WNR834BV2
];
1193 } else { /* PMON based - old stuff */
1194 if ((simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 9) &&
1195 (simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 30)) {
1196 return &platforms
[WR850GV1
];
1198 if (startswith(boardtype
, "bcm94710dev")) {
1199 if (!strcmp(boardnum
, "42"))
1200 return &platforms
[WRT54GV1
];
1201 if (simple_strtoul(boardnum
, NULL
, 0) == 2)
1202 return &platforms
[WAP54GV1
];
1204 /* MN-700 has also hardware_version 'WL500-...', so use boardnum */
1205 if (startswith(getvar("hardware_version"), "WL500-")) {
1206 if (!strcmp(getvar("boardnum"), "mn700"))
1207 return &platforms
[MN700
];
1209 return &platforms
[WL500G
];
1211 if (startswith(getvar("hardware_version"), "WL300-")) {
1212 /* Either WL-300g or WL-HDD, do more extensive checks */
1213 if ((simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 0) &&
1214 (simple_strtoul(getvar("et1phyaddr"), NULL
, 0) == 1))
1215 return &platforms
[WLHDD
];
1216 if ((simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 0) &&
1217 (simple_strtoul(getvar("et1phyaddr"), NULL
, 0) == 10))
1218 return &platforms
[WL300G
];
1220 /* Sitecom WL-105b */
1221 if (startswith(boardnum
, "2") && simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 1)
1222 return &platforms
[WL105B
];
1224 /* unknown asus stuff, probably bcm4702 */
1225 if (startswith(boardnum
, "asusX"))
1226 return &platforms
[ASUS_4702
];
1228 /* bcm4702 based Askey RT210W clones, Including:
1229 * Askey RT210W (duh?)
1231 * Belkin F5D7230-4 before version v1444 (MiniPCI slot, not integrated)
1233 if (!strcmp(boardtype
,"bcm94710r4")
1234 && !strcmp(boardnum
,"100")
1235 && !strcmp(getvar("pmon_ver"),"v1.03.12.bk")
1237 return &platforms
[RT210W
];
1241 if (boardnum
|| !strcmp(boardnum
, "00")) {/* probably buffalo */
1242 if (startswith(boardtype
, "bcm94710ap"))
1243 return &platforms
[BUFFALO_UNKNOWN_4710
];
1245 return &platforms
[BUFFALO_UNKNOWN
];
1248 if (startswith(getvar("CFEver"), "MotoWRv2") ||
1249 startswith(getvar("CFEver"), "MotoWRv3") ||
1250 !strcmp(getvar("MOTO_BOARD_TYPE"), "WR_FEM1")) {
1252 return &platforms
[WR850GV2V3
];
1255 if (!strcmp(boardnum
, "44") && !strcmp(getvar("boardflags"),"0x0388")) { /* Trendware TEW-411BRP+ */
1256 return &platforms
[TEW411BRPP
];
1259 if (startswith(boardnum
, "04FN")) /* SimpleTech SimpleShare */
1260 return &platforms
[STI_NAS
];
1262 if (!strcmp(boardnum
, "10") && !strcmp(getvar("boardrev"), "0x13")) /* D-Link DWL-3150 */
1263 return &platforms
[DWL3150
];
1265 if (!strcmp(boardnum
, "01") && !strcmp(boardtype
, "0x048e") && /* Edimax PS1208MFG */
1266 !strcmp(getvar("status_gpio"), "1")) /* gpio based detection */
1267 return &platforms
[PS1208MFG
];
1273 static struct platform_t __init
*platform_detect(void)
1275 enum bcm47xx_board board
;
1276 const char *board_name
;
1279 board
= bcm47xx_board_get();
1280 board_name
= bcm47xx_board_get_name();
1281 if (board
!= BCM47XX_BOARD_UNKNOWN
&& board
!= BCM47XX_BOARD_NON
)
1282 printk(MODULE_NAME
": kernel found a \"%s\"\n", board_name
);
1285 case BCM47XX_BOARD_ASUS_RTN16
:
1286 return &platforms
[RTN16
];
1287 case BCM47XX_BOARD_ASUS_WL330GE
:
1288 return &platforms
[WL330GE
];
1289 case BCM47XX_BOARD_ASUS_WL500GPV1
:
1290 return &platforms
[WL500GP
];
1291 case BCM47XX_BOARD_ASUS_WL500GPV2
:
1292 return &platforms
[WL500GPV2
];
1293 case BCM47XX_BOARD_ASUS_WL520GC
:
1294 return &platforms
[WL520GC
];
1295 case BCM47XX_BOARD_ASUS_WL520GU
:
1296 return &platforms
[WL520GU
];
1297 case BCM47XX_BOARD_ASUS_WL700GE
:
1298 return &platforms
[WL700GE
];
1299 case BCM47XX_BOARD_BELKIN_F7D4301
:
1300 return &platforms
[BELKIN_F7D4301
];
1301 case BCM47XX_BOARD_BUFFALO_WBR2_G54
:
1302 return &platforms
[WBR2_G54
];
1303 case BCM47XX_BOARD_BUFFALO_WHR2_A54G54
:
1304 return &platforms
[WHR2_A54G54
];
1305 case BCM47XX_BOARD_BUFFALO_WHR_G125
:
1306 return &platforms
[WHR_G125
];
1307 case BCM47XX_BOARD_BUFFALO_WHR_G54S
:
1308 return &platforms
[WHR_G54S
];
1309 case BCM47XX_BOARD_BUFFALO_WHR_HP_G54
:
1310 return &platforms
[WHR_HP_G54
];
1311 case BCM47XX_BOARD_BUFFALO_WLA2_G54L
:
1312 return &platforms
[WLA2_G54L
];
1313 case BCM47XX_BOARD_BUFFALO_WZR_G300N
:
1314 return &platforms
[WZR_G300N
];
1315 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54
:
1316 return &platforms
[WZR_RS_G54
];
1317 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54HP
:
1318 return &platforms
[WZR_RS_G54HP
];
1319 case BCM47XX_BOARD_DELL_TM2300
:
1320 return &platforms
[TM2300
];
1321 case BCM47XX_BOARD_DLINK_DIR130
:
1322 return &platforms
[DIR130
];
1323 case BCM47XX_BOARD_DLINK_DIR330
:
1324 return &platforms
[DIR330
];
1325 case BCM47XX_BOARD_LINKSYS_E1000V1
:
1326 return &platforms
[E1000V1
];
1327 case BCM47XX_BOARD_LINKSYS_E3000V1
:
1328 return &platforms
[E3000V1
];
1329 case BCM47XX_BOARD_LINKSYS_E3200V1
:
1330 return &platforms
[E3200V1
];
1331 case BCM47XX_BOARD_LINKSYS_WRT150NV1
:
1332 return &platforms
[WRT150NV1
];
1333 case BCM47XX_BOARD_LINKSYS_WRT150NV11
:
1334 return &platforms
[WRT150NV11
];
1335 case BCM47XX_BOARD_LINKSYS_WRT160NV1
:
1336 return &platforms
[WRT160NV1
];
1337 case BCM47XX_BOARD_LINKSYS_WRT160NV3
:
1338 return &platforms
[WRT160NV3
];
1339 case BCM47XX_BOARD_LINKSYS_WRT300NV11
:
1340 return &platforms
[WRT300NV11
];
1341 case BCM47XX_BOARD_LINKSYS_WRT54G3GV2
:
1342 return &platforms
[WRT54G3GV2_VF
];
1343 case BCM47XX_BOARD_LINKSYS_WRT610NV1
:
1344 return &platforms
[WRT610N
];
1345 case BCM47XX_BOARD_LINKSYS_WRT610NV2
:
1346 return &platforms
[WRT610NV2
];
1347 case BCM47XX_BOARD_LINKSYS_WRTSL54GS
:
1348 return &platforms
[WRTSL54GS
];
1349 case BCM47XX_BOARD_MOTOROLA_WE800G
:
1350 return &platforms
[WE800G
];
1351 case BCM47XX_BOARD_MOTOROLA_WR850GP
:
1352 return &platforms
[WR850GP
];
1353 case BCM47XX_BOARD_MOTOROLA_WR850GV2V3
:
1354 return &platforms
[WR850GV2V3
];
1355 case BCM47XX_BOARD_NETGEAR_WNDR3400V1
:
1356 return &platforms
[WNDR3400V1
];
1357 case BCM47XX_BOARD_NETGEAR_WNDR3700V3
:
1358 return &platforms
[WNDR3700V3
];
1359 case BCM47XX_BOARD_UNKNOWN
:
1360 case BCM47XX_BOARD_NON
:
1361 printk(MODULE_NAME
": unknown board found, try legacy detect\n");
1362 printk(MODULE_NAME
": please open a ticket at https://dev.openwrt.org and attach the complete nvram\n");
1363 return platform_detect_legacy();
1365 printk(MODULE_NAME
": board was detected as \"%s\", but not gpio configuration available\n", board_name
);
1366 printk(MODULE_NAME
": now trying legacy detect\n");
1367 return platform_detect_legacy();
1371 static inline void ssb_maskset32(struct ssb_device
*dev
,
1372 u16 offset
, u32 mask
, u32 set
)
1374 ssb_write32(dev
, offset
, (ssb_read32(dev
, offset
) & mask
) | set
);
1377 static void gpio_set_irqenable(int enabled
, irqreturn_t (*handler
)(int, void *))
1381 irq
= gpio_to_irq(0);
1382 if (irq
== -EINVAL
) return;
1385 if (request_irq(irq
, handler
, IRQF_SHARED
, "gpio", handler
))
1388 free_irq(irq
, handler
);
1391 switch (bcm47xx_bus_type
) {
1392 #ifdef CONFIG_BCM47XX_SSB
1393 case BCM47XX_BUS_TYPE_SSB
:
1394 if (bcm47xx_bus
.ssb
.chipco
.dev
)
1395 ssb_maskset32(bcm47xx_bus
.ssb
.chipco
.dev
, SSB_CHIPCO_IRQMASK
, ~SSB_CHIPCO_IRQ_GPIO
, (enabled
? SSB_CHIPCO_IRQ_GPIO
: 0));
1398 #ifdef CONFIG_BCM47XX_BCMA
1399 case BCM47XX_BUS_TYPE_BCMA
:
1400 if (bcm47xx_bus
.bcma
.bus
.drv_cc
.core
)
1401 bcma_maskset32(bcm47xx_bus
.bcma
.bus
.drv_cc
.core
, BCMA_CC_IRQMASK
, ~BCMA_CC_IRQ_GPIO
, (enabled
? BCMA_CC_IRQ_GPIO
: 0));
1407 static void hotplug_button(struct work_struct
*work
)
1409 struct event_t
*event
= container_of(work
, struct event_t
, wq
);
1412 event
->skb
= alloc_skb(2048, GFP_KERNEL
);
1414 s
= skb_put(event
->skb
, strlen(event
->action
) + 2);
1415 sprintf(s
, "%s@", event
->action
);
1418 NETLINK_CB(event
->skb
).dst_group
= 1;
1419 broadcast_uevent(event
->skb
, 0, 1, GFP_KERNEL
);
1424 static irqreturn_t
button_handler(int irq
, void *dev_id
)
1429 in
= bcm47xx_gpio_in(~0) & platform
.button_mask
;
1430 bcm47xx_gpio_polarity(platform
.button_mask
, in
);
1431 changed
= platform
.button_polarity
^ in
;
1432 platform
.button_polarity
= in
;
1434 changed
&= ~bcm47xx_gpio_outen(0, 0);
1436 for (b
= platform
.buttons
; b
->name
; b
++) {
1437 struct event_t
*event
;
1439 if (!(b
->gpio
& changed
)) continue;
1443 if ((event
= (struct event_t
*)kzalloc (sizeof(struct event_t
), GFP_ATOMIC
))) {
1444 event
->seen
= (jiffies
- b
->seen
)/HZ
;
1445 event
->name
= b
->name
;
1446 event
->action
= b
->pressed
? "pressed" : "released";
1447 INIT_WORK(&event
->wq
, (void *)(void *)hotplug_button
);
1448 schedule_work(&event
->wq
);
1456 static void register_buttons(struct button_t
*b
)
1458 for (; b
->name
; b
++)
1459 platform
.button_mask
|= b
->gpio
;
1461 platform
.button_mask
&= ~gpiomask
;
1463 bcm47xx_gpio_outen(platform
.button_mask
, 0);
1464 bcm47xx_gpio_control(platform
.button_mask
, 0);
1465 platform
.button_polarity
= bcm47xx_gpio_in(~0) & platform
.button_mask
;
1466 bcm47xx_gpio_polarity(platform
.button_mask
, platform
.button_polarity
);
1467 bcm47xx_gpio_intmask(platform
.button_mask
, platform
.button_mask
);
1469 gpio_set_irqenable(1, button_handler
);
1472 static void unregister_buttons(struct button_t
*b
)
1474 bcm47xx_gpio_intmask(platform
.button_mask
, 0);
1476 gpio_set_irqenable(0, button_handler
);
1480 static void add_msg(struct event_t
*event
, char *msg
, int argv
)
1487 s
= skb_put(event
->skb
, strlen(msg
) + 1);
1491 static int fill_event (struct event_t
*event
)
1493 static char buf
[128];
1495 add_msg(event
, "HOME=/", 0);
1496 add_msg(event
, "PATH=/sbin:/bin:/usr/sbin:/usr/bin", 0);
1497 add_msg(event
, "SUBSYSTEM=button", 0);
1498 snprintf(buf
, 128, "ACTION=%s", event
->action
);
1499 add_msg(event
, buf
, 0);
1500 snprintf(buf
, 128, "BUTTON=%s", event
->name
);
1501 add_msg(event
, buf
, 0);
1502 snprintf(buf
, 128, "SEEN=%ld", event
->seen
);
1503 add_msg(event
, buf
, 0);
1504 snprintf(buf
, 128, "SEQNUM=%llu", uevent_next_seqnum());
1505 add_msg(event
, buf
, 0);
1511 * This should be extended to allow the platform to specify the pins and width
1512 * of the shift register. They're hardcoded for now because only the WNDR3700v3
1515 static void shiftreg_output(unsigned int val
)
1519 bcm47xx_gpio_out(SHIFTREG_DATA
, SHIFTREG_DATA
); /* init off, pull high */
1520 bcm47xx_gpio_out(SHIFTREG_CLK
, 0); /* init reset */
1523 for(mask
= 1 << (SHIFTREG_MAX_BITS
-1); mask
; mask
>>= 1)
1525 bcm47xx_gpio_out(SHIFTREG_DATA
, (val
& mask
) ? SHIFTREG_DATA
: 0);
1526 bcm47xx_gpio_out(SHIFTREG_CLK
, SHIFTREG_CLK
); /* pull high to trigger */
1527 bcm47xx_gpio_out(SHIFTREG_CLK
, 0); /* reset to low */
1531 static void set_led_shift(struct led_t
*led
)
1533 static u32 shiftreg
= 0;
1535 u32 pin
= (led
->gpio
& ~GPIO_TYPE_MASK
);
1543 /* Clock the bits out. */
1544 if (shiftreg
!= old
) {
1545 shiftreg_output(shiftreg
);
1549 static void set_led_extif(struct led_t
*led
)
1551 volatile u8
*addr
= (volatile u8
*) KSEG1ADDR(EXTIF_UART
) + (led
->gpio
& ~GPIO_TYPE_MASK
);
1559 static void led_flash(unsigned long dummy
) {
1564 for (l
= platform
.leds
; l
->name
; l
++) {
1565 if (!l
->flash
) continue;
1566 switch (l
->gpio
& GPIO_TYPE_MASK
) {
1567 case GPIO_TYPE_EXTIF
:
1569 l
->state
= !l
->state
;
1572 case GPIO_TYPE_SHIFT
:
1574 l
->state
= !l
->state
;
1577 case GPIO_TYPE_NORMAL
:
1586 u32 val
= ~bcm47xx_gpio_in(~0);
1588 bcm47xx_gpio_outen(mask
, mask
);
1589 bcm47xx_gpio_control(mask
, 0);
1590 bcm47xx_gpio_out(mask
, val
);
1592 if (mask
|| extif_blink
) {
1593 mod_timer(&led_timer
, jiffies
+ FLASH_TIME
);
1597 static int diag_led_show(struct seq_file
*m
, void *v
)
1599 struct led_t
* led
= m
->private;
1601 u8 p
= (led
->polarity
== NORMAL
? 0 : 1);
1603 return seq_printf(m
, "f\n");
1604 } else if ((led
->gpio
& GPIO_TYPE_MASK
) != GPIO_TYPE_NORMAL
) {
1605 return seq_printf(m
, "%d\n", ((led
->state
^ p
) ? 1 : 0));
1607 u32 in
= (bcm47xx_gpio_in(~0) & led
->gpio
? 1 : 0);
1608 return seq_printf(m
, "%d\n", ((in
^ p
) ? 1 : 0));
1612 static int diag_led_open(struct inode
*inode
, struct file
*file
)
1614 return single_open(file
, diag_led_show
, PDE_DATA(inode
));
1617 static ssize_t
diag_led_write(struct file
*file
, const char __user
*buf
, size_t count
, loff_t
*ppos
)
1619 struct led_t
*led
= PDE_DATA(file_inode(file
));
1624 len
= min(count
, sizeof(cmd
) - 1);
1625 if (copy_from_user(cmd
, buf
, len
))
1630 p
= (led
->polarity
== NORMAL
? 0 : 1);
1631 if (cmd
[0] == 'f') {
1636 if ((led
->gpio
& GPIO_TYPE_MASK
) == GPIO_TYPE_EXTIF
) {
1637 led
->state
= p
^ ((cmd
[0] == '1') ? 1 : 0);
1639 } else if ((led
->gpio
& GPIO_TYPE_MASK
) == GPIO_TYPE_SHIFT
) {
1640 led
->state
= p
^ ((cmd
[0] == '1') ? 1 : 0);
1643 bcm47xx_gpio_outen(led
->gpio
, led
->gpio
);
1644 bcm47xx_gpio_control(led
->gpio
, 0);
1645 bcm47xx_gpio_out(led
->gpio
, ((p
^ (cmd
[0] == '1')) ? led
->gpio
: 0));
1651 static const struct file_operations diag_led_fops
= {
1652 .open
= diag_led_open
,
1654 .llseek
= seq_lseek
,
1655 .write
= diag_led_write
1658 static void register_leds(struct led_t
*l
)
1660 struct proc_dir_entry
*p
;
1665 leds
= proc_mkdir("led", diag
);
1669 for(; l
->name
; l
++) {
1670 if (l
->gpio
& gpiomask
)
1673 switch (l
->gpio
& GPIO_TYPE_MASK
) {
1674 case GPIO_TYPE_EXTIF
:
1678 case GPIO_TYPE_SHIFT
:
1679 mask
|= (SHIFTREG_DATA
| SHIFTREG_CLK
);
1680 oe_mask
|= (SHIFTREG_DATA
| SHIFTREG_CLK
);
1681 l
->state
= (l
->polarity
!= NORMAL
);
1684 case GPIO_TYPE_NORMAL
:
1686 if (l
->polarity
!= INPUT
) oe_mask
|= l
->gpio
;
1688 val
|= (l
->polarity
== NORMAL
)?0:l
->gpio
;
1692 if (l
->polarity
== INPUT
) continue;
1694 p
= proc_create_data(l
->name
, S_IRUSR
, leds
, &diag_led_fops
, l
);
1697 bcm47xx_gpio_outen(mask
, oe_mask
);
1698 bcm47xx_gpio_control(mask
, 0);
1699 bcm47xx_gpio_out(mask
, val
);
1700 bcm47xx_gpio_intmask(mask
, 0);
1703 static void unregister_leds(struct led_t
*l
)
1706 remove_proc_entry(l
->name
, leds
);
1708 remove_proc_entry("led", diag
);
1711 static int diag_model_show(struct seq_file
*m
, void *v
)
1713 return seq_printf(m
, "%s\n", platform
.name
);
1716 static int diag_model_open(struct inode
*inode
, struct file
*file
)
1718 return single_open(file
, diag_model_show
, PDE_DATA(inode
));
1721 static const struct file_operations diag_model_fops
= {
1722 .open
= diag_model_open
,
1727 static int diag_gpiomask_show(struct seq_file
*m
, void *v
)
1729 return seq_printf(m
, "0x%04x\n", gpiomask
);
1732 static int diag_gpiomask_open(struct inode
*inode
, struct file
*file
)
1734 return single_open(file
, diag_gpiomask_show
, PDE_DATA(inode
));
1737 static ssize_t
diag_gpiomask_write(struct file
*file
, const char __user
*buf
, size_t count
, loff_t
*ppos
)
1739 int err
= kstrtouint_from_user(buf
, count
, 0, &gpiomask
);
1743 if (platform
.buttons
) {
1744 unregister_buttons(platform
.buttons
);
1745 register_buttons(platform
.buttons
);
1748 if (platform
.leds
) {
1749 unregister_leds(platform
.leds
);
1750 register_leds(platform
.leds
);
1756 static const struct file_operations diag_gpiomask_fops
= {
1757 .open
= diag_gpiomask_open
,
1759 .llseek
= seq_lseek
,
1760 .write
= diag_gpiomask_write
1763 static int __init
diag_init(void)
1765 static struct proc_dir_entry
*p
;
1766 static struct platform_t
*detected
;
1768 detected
= platform_detect();
1770 printk(MODULE_NAME
": Router model not detected.\n");
1773 memcpy(&platform
, detected
, sizeof(struct platform_t
));
1775 printk(MODULE_NAME
": Detected '%s'\n", platform
.name
);
1776 if (platform
.platform_init
!= NULL
) {
1777 platform
.platform_init();
1780 if (!(diag
= proc_mkdir("diag", NULL
))) {
1781 printk(MODULE_NAME
": proc_mkdir on /proc/diag failed\n");
1785 p
= proc_create("model", S_IRUSR
, diag
, &diag_model_fops
);
1787 remove_proc_entry("diag", NULL
);
1791 p
= proc_create("gpiomask", S_IRUSR
| S_IWUSR
, diag
, &diag_gpiomask_fops
);
1793 remove_proc_entry("model", diag
);
1794 remove_proc_entry("diag", NULL
);
1798 if (platform
.buttons
)
1799 register_buttons(platform
.buttons
);
1802 register_leds(platform
.leds
);
1807 static void __exit
diag_exit(void)
1809 del_timer(&led_timer
);
1811 if (platform
.buttons
)
1812 unregister_buttons(platform
.buttons
);
1815 unregister_leds(platform
.leds
);
1817 remove_proc_entry("model", diag
);
1818 remove_proc_entry("gpiomask", diag
);
1819 remove_proc_entry("diag", NULL
);
1822 module_init(diag_init
);
1823 module_exit(diag_exit
);
1825 MODULE_AUTHOR("Mike Baker, Felix Fietkau / OpenWrt.org");
1826 MODULE_LICENSE("GPL");