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 */
186 static void __init
bcm4780_init(void) {
189 /* Enables GPIO 3 that controls HDD and led power on ASUS WL-700gE */
190 printk(MODULE_NAME
": Spinning up HDD and enabling leds\n");
191 bcm47xx_gpio_outen(pin
, pin
);
192 bcm47xx_gpio_control(pin
, 0);
193 bcm47xx_gpio_out(pin
, pin
);
195 /* Wait 5s, so the HDD can spin up */
196 set_current_state(TASK_INTERRUPTIBLE
);
197 schedule_timeout(HZ
* 5);
200 static void __init
NetCenter_init(void) {
201 /* unset pin 6 (+12V) */
203 bcm47xx_gpio_outen(pin
, pin
);
204 bcm47xx_gpio_control(pin
, 0);
205 bcm47xx_gpio_out(pin
, pin
);
206 /* unset pin 1 (turn off red led, blue will light alone if +5V comes up) */
208 bcm47xx_gpio_outen(pin
, pin
);
209 bcm47xx_gpio_control(pin
, 0);
210 bcm47xx_gpio_out(pin
, pin
);
211 /* unset pin 3 (+5V) and wait 5 seconds (harddisk spin up) */
215 static void __init
bcm57xx_init(void) {
218 /* FIXME: switch comes up, but port mappings/vlans not right */
219 bcm47xx_gpio_outen(pin
, pin
);
220 bcm47xx_gpio_control(pin
, 0);
221 bcm47xx_gpio_out(pin
, pin
);
224 static struct platform_t __initdata platforms
[] = {
227 .name
= "Linksys WAP54G V1",
229 { .name
= "reset", .gpio
= 1 << 0 },
232 { .name
= "diag", .gpio
= 1 << 3 },
233 { .name
= "wlan", .gpio
= 1 << 4 },
237 .name
= "Linksys WAP54G V2",
239 { .name
= "reset", .gpio
= 1 << 0 },
242 { .name
= "wlan", .gpio
= 1 << 5, .polarity
= REVERSE
},
243 /* GPIO 6 is b44 (eth0, LAN) PHY power */
247 .name
= "Linksys WAP54G V3",
249 /* FIXME: verify this */
250 { .name
= "reset", .gpio
= 1 << 7 },
251 { .name
= "ses", .gpio
= 1 << 0 },
255 { .name
= "ses", .gpio
= 1 << 1 },
259 .name
= "Linksys WRT54G V1.x",
261 { .name
= "reset", .gpio
= 1 << 6 },
264 { .name
= "diag", .gpio
= 0x13 | GPIO_TYPE_EXTIF
, .polarity
= NORMAL
},
265 { .name
= "dmz", .gpio
= 0x12 | GPIO_TYPE_EXTIF
, .polarity
= NORMAL
},
269 .name
= "Linksys WRT54G/GS/GL",
271 { .name
= "reset", .gpio
= 1 << 6 },
272 { .name
= "ses", .gpio
= 1 << 4 },
275 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
276 { .name
= "dmz", .gpio
= 1 << 7, .polarity
= REVERSE
},
277 { .name
= "ses_white", .gpio
= 1 << 2, .polarity
= REVERSE
},
278 { .name
= "ses_orange", .gpio
= 1 << 3, .polarity
= REVERSE
},
279 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
283 .name
= "Linksys WRTSL54GS",
285 { .name
= "reset", .gpio
= 1 << 6 },
286 { .name
= "ses", .gpio
= 1 << 4 },
289 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
290 { .name
= "dmz", .gpio
= 1 << 0, .polarity
= REVERSE
},
291 { .name
= "ses_white", .gpio
= 1 << 5, .polarity
= REVERSE
},
292 { .name
= "ses_orange", .gpio
= 1 << 7, .polarity
= REVERSE
},
296 .name
= "Linksys WRT54G3G",
298 { .name
= "reset", .gpio
= 1 << 6 },
299 { .name
= "3g", .gpio
= 1 << 4 },
302 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
303 { .name
= "dmz", .gpio
= 1 << 7, .polarity
= REVERSE
},
304 { .name
= "3g_green", .gpio
= 1 << 2, .polarity
= NORMAL
},
305 { .name
= "3g_blue", .gpio
= 1 << 3, .polarity
= NORMAL
},
306 { .name
= "3g_blink", .gpio
= 1 << 5, .polarity
= NORMAL
},
310 .name
= "Linksys WRT54G3GV2-VF",
312 { .name
= "reset", .gpio
= 1 << 6 },
313 { .name
= "3g", .gpio
= 1 << 5 },
316 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
317 { .name
= "3g_green", .gpio
= 1 << 2, .polarity
= NORMAL
},
318 { .name
= "3g_blue", .gpio
= 1 << 3, .polarity
= NORMAL
},
322 .name
= "Linksys WRT150N V1",
324 { .name
= "reset", .gpio
= 1 << 6 },
325 { .name
= "ses", .gpio
= 1 << 4 },
328 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
329 { .name
= "ses_green", .gpio
= 1 << 5, .polarity
= REVERSE
},
330 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
334 .name
= "Linksys WRT150N V1.1",
336 { .name
= "reset", .gpio
= 1 << 6 },
337 { .name
= "ses", .gpio
= 1 << 4 },
340 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
341 { .name
= "ses_green", .gpio
= 1 << 5, .polarity
= REVERSE
},
342 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
346 .name
= "Linksys WRT160N v1.x",
348 { .name
= "reset", .gpio
= 1 << 6 },
349 { .name
= "ses", .gpio
= 1 << 4 },
352 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
353 { .name
= "ses_blue", .gpio
= 1 << 5, .polarity
= REVERSE
},
354 { .name
= "ses_orange", .gpio
= 1 << 3, .polarity
= REVERSE
},
358 .name
= "Linksys WRT160N V3",
360 { .name
= "reset", .gpio
= 1 << 6 },
361 { .name
= "ses", .gpio
= 1 << 5 },
364 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
365 { .name
= "ses_blue", .gpio
= 1 << 4, .polarity
= REVERSE
},
366 { .name
= "ses_orange", .gpio
= 1 << 2, .polarity
= REVERSE
},
370 .name
= "Linksys WRT300N V1.1",
372 { .name
= "reset", .gpio
= 1 << 6 }, // "Reset" on back panel
373 { .name
= "ses", .gpio
= 1 << 4 }, // "Reserved" on top panel
376 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
}, // "Power"
377 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
}, // "Security" Amber
378 { .name
= "ses_green", .gpio
= 1 << 5, .polarity
= REVERSE
}, // "Security" Green
380 .platform_init
= bcm57xx_init
,
383 .name
= "Linksys WRT350N",
385 { .name
= "reset", .gpio
= 1 << 6 },
386 { .name
= "ses", .gpio
= 1 << 8 },
389 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
390 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
391 { .name
= "ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
},
392 { .name
= "usb_blink", .gpio
= 1 << 10, .polarity
= REVERSE
},
393 { .name
= "usb", .gpio
= 1 << 11, .polarity
= REVERSE
},
395 .platform_init
= bcm57xx_init
,
398 .name
= "Linksys WRT600N",
400 { .name
= "reset", .gpio
= 1 << 6 },
401 { .name
= "ses", .gpio
= 1 << 7 },
404 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
}, // Power LED
405 { .name
= "usb", .gpio
= 1 << 3, .polarity
= REVERSE
}, // USB LED
406 { .name
= "wl0_ses_amber", .gpio
= 1 << 8, .polarity
= REVERSE
}, // 2.4Ghz LED Amber
407 { .name
= "wl0_ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
}, // 2.4Ghz LED Green
408 { .name
= "wl1_ses_amber", .gpio
= 1 << 10, .polarity
= REVERSE
}, // 5.6Ghz LED Amber
409 { .name
= "wl1_ses_green", .gpio
= 1 << 11, .polarity
= REVERSE
}, // 5.6Ghz LED Green
411 .platform_init
= bcm57xx_init
,
414 .name
= "Linksys WRT600N V1.1",
416 { .name
= "reset", .gpio
= 1 << 6 },
417 { .name
= "ses", .gpio
= 1 << 7 },
420 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
}, // Power LED
421 { .name
= "usb", .gpio
= 1 << 3, .polarity
= REVERSE
}, // USB LED
422 { .name
= "wl0_ses_amber", .gpio
= 1 << 8, .polarity
= REVERSE
}, // 2.4Ghz LED Amber
423 { .name
= "wl0_ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
}, // 2.4Ghz LED Green
424 { .name
= "wl1_ses_amber", .gpio
= 1 << 10, .polarity
= REVERSE
}, // 5.6Ghz LED Amber
425 { .name
= "wl1_ses_green", .gpio
= 1 << 11, .polarity
= REVERSE
}, // 5.6Ghz LED Green
427 .platform_init
= bcm57xx_init
,
430 .name
= "Linksys WRT610N",
432 { .name
= "reset", .gpio
= 1 << 6 },
433 { .name
= "ses", .gpio
= 1 << 8 },
436 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
}, // Power LED
437 { .name
= "usb", .gpio
= 1 << 0, .polarity
= REVERSE
}, // USB LED
438 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
}, // WiFi protected setup LED amber
439 { .name
= "ses_blue", .gpio
= 1 << 9, .polarity
= REVERSE
}, // WiFi protected setup LED blue
443 .name
= "Linksys WRT610N V2",
445 { .name
= "reset", .gpio
= 1 << 6 },
446 { .name
= "ses", .gpio
= 1 << 4 },
449 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
}, // Power LED
450 { .name
= "usb", .gpio
= 1 << 7, .polarity
= NORMAL
}, // USB LED
451 { .name
= "ses_amber", .gpio
= 1 << 0, .polarity
= REVERSE
}, // WiFi protected setup LED amber
452 { .name
= "ses_blue", .gpio
= 1 << 3, .polarity
= REVERSE
}, // WiFi protected setup LED blue
453 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
}, // Wireless LED
456 /* same hardware as WRT160NV3 and Cisco Valet M10V1, but different board detection, combine? */
458 .name
= "Linksys E1000 V1",
460 { .name
= "reset", .gpio
= 1 << 6 },
461 { .name
= "wps", .gpio
= 1 << 5 }, /* nvram get gpio5=wps_button */
464 /** turns on leds for all ethernet ports (wan too)
465 * this also disconnects some, or maybe all, ethernet ports
466 * 1: leds work normally
467 * 0: all lit all the time */
468 /* nvram get gpio3=robo_reset */
469 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
470 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
471 { .name
= "ses_blue", .gpio
= 1 << 4, .polarity
= REVERSE
}, /* nvram get gpio4=wps_led */
472 { .name
= "ses_orange", .gpio
= 1 << 2, .polarity
= REVERSE
}, /* nvram get gpio2=wps_status_led */
476 .name
= "Linksys E1000 V2.1",
478 { .name
= "reset", .gpio
= 1 << 10 }, /* nvram get reset_gpio=10 */
479 { .name
= "wps", .gpio
= 1 << 9 }, /* nvram get gpio9=wps_button */
482 { .name
= "power", .gpio
= 1 << 6, .polarity
= REVERSE
},
483 { .name
= "wlan", .gpio
= 1 << 5, .polarity
= NORMAL
},
484 { .name
= "ses_blue", .gpio
= 1 << 8, .polarity
= NORMAL
}, /* nvram get gpio8=wps_led */
485 { .name
= "ses_orange", .gpio
= 1 << 7, .polarity
= NORMAL
}, /* nvram get gpio7=wps_status_led */
489 .name
= "Linksys E3000 V1",
491 { .name
= "reset", .gpio
= 1 << 6 },
492 { .name
= "ses", .gpio
= 1 << 4 },
495 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
}, // Power LED
496 { .name
= "usb", .gpio
= 1 << 7, .polarity
= NORMAL
}, // USB LED
497 { .name
= "ses_amber", .gpio
= 1 << 0, .polarity
= REVERSE
}, // WiFi protected setup LED amber
498 { .name
= "ses_blue", .gpio
= 1 << 3, .polarity
= REVERSE
}, // WiFi protected setup LED blue
499 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
}, // Wireless LED
503 .name
= "Linksys E3200 V1",
505 /* { .name = "switch", .gpio = 1 << 4 },*/ /* nvram get gpio4=robo_reset */
506 { .name
= "reset", .gpio
= 1 << 5 }, /* nvram get reset_gpio=5 */
507 { .name
= "wps", .gpio
= 1 << 8 }, /* nvram get gpio8=wps_button */
508 /* { .name = "wombo", .gpio = 1 << 23 },*/ /* nvram get gpio23=wombo_reset - wireless on motherboard */
511 { .name
= "power", .gpio
= 1 << 3, .polarity
= REVERSE
}, /* Power LED */
515 .name
= "Linksys E4200 V1",
517 { .name
= "reset", .gpio
= 1 << 6 },
518 { .name
= "wps", .gpio
= 1 << 4 },
521 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
526 .name
= "ASUS WL-HDD",
528 { .name
= "reset", .gpio
= 1 << 6 },
531 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
532 { .name
= "usb", .gpio
= 1 << 2, .polarity
= REVERSE
},
536 .name
= "ASUS WL-300g",
538 { .name
= "reset", .gpio
= 1 << 6 },
541 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
545 .name
= "ASUS WL-320gE/WL-320gP",
547 { .name
= "reset", .gpio
= 1 << 6 },
550 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
551 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
},
552 { .name
= "link", .gpio
= 1 << 11, .polarity
= REVERSE
},
556 .name
= "ASUS WL-330gE",
558 { .name
= "reset", .gpio
= 1 << 2 },
561 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
565 .name
= "ASUS WL-500g",
567 { .name
= "reset", .gpio
= 1 << 6 },
570 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
574 .name
= "ASUS WL-500g Deluxe",
576 { .name
= "reset", .gpio
= 1 << 6 },
579 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
583 .name
= "ASUS WL-500g Premium",
585 { .name
= "reset", .gpio
= 1 << 0 },
586 { .name
= "ses", .gpio
= 1 << 4 },
589 { .name
= "power", .gpio
= 1 << 1, .polarity
= REVERSE
},
593 .name
= "ASUS WL-500g Premium V2",
595 { .name
= "reset", .gpio
= 1 << 2 },
596 { .name
= "ses", .gpio
= 1 << 3 },
599 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
600 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
604 .name
= "ASUS WL-500W",
606 { .name
= "reset", .gpio
= 1 << 6 },
607 { .name
= "ses", .gpio
= 1 << 7 },
610 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
614 .name
= "ASUS WL-520GC",
616 { .name
= "reset", .gpio
= 1 << 2 },
617 { .name
= "ses", .gpio
= 1 << 3 },
620 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
621 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
625 .name
= "ASUS WL-520gU",
627 { .name
= "reset", .gpio
= 1 << 2 },
628 { .name
= "ses", .gpio
= 1 << 3 },
631 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
632 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
636 .name
= "ASUS (unknown, BCM4702)",
638 { .name
= "reset", .gpio
= 1 << 6 },
641 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
645 .name
= "ASUS WL-700gE",
647 { .name
= "reset", .gpio
= 1 << 7 }, // on back, hardwired, always resets device regardless OS state
648 { .name
= "ses", .gpio
= 1 << 4 }, // on back, actual name ezsetup
649 { .name
= "power", .gpio
= 1 << 0 }, // on front
650 { .name
= "copy", .gpio
= 1 << 6 }, // on front
654 // GPIO that controls power led also enables/disables some essential functions
657 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
}, // actual name power
659 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
661 .platform_init
= bcm4780_init
,
664 .name
= "ASUS RT-N12",
666 { .name
= "wps", .gpio
= 1 << 0 },
667 { .name
= "reset", .gpio
= 1 << 1 },
668 // this is the router/repeater/ap switch
669 { .name
= "sw1", .gpio
= 1 << 4 },
670 { .name
= "sw2", .gpio
= 1 << 5 },
671 { .name
= "sw3", .gpio
= 1 << 6 },
674 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
},
675 { .name
= "wlan", .gpio
= 1 << 7, .polarity
= NORMAL
},
676 // gpio3 forces WAN and LAN1-4 all on
677 //{ .name = "eth", .gpio = 1 << 3, .polarity = REVERSE },
681 .name
= "ASUS RT-N16",
683 { .name
= "reset", .gpio
= 1 << 8 },
684 { .name
= "ses", .gpio
= 1 << 5 },
687 { .name
= "power", .gpio
= 1 << 1, .polarity
= REVERSE
},
688 { .name
= "wlan", .gpio
= 1 << 7, .polarity
= NORMAL
},
692 .name
= "ASUS RT-N66U",
694 { .name
= "reset", .gpio
= 1 << 9 },
695 { .name
= "wps", .gpio
= 1 << 4 },
698 { .name
= "power", .gpio
= 1 << 12, .polarity
= REVERSE
},
699 { .name
= "usb", .gpio
= 1 << 15, .polarity
= REVERSE
},
704 .name
= "Buffalo WHR-G54S",
706 { .name
= "reset", .gpio
= 1 << 4 },
707 { .name
= "bridge", .gpio
= 1 << 5 },
708 { .name
= "ses", .gpio
= 1 << 0 },
711 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
712 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
713 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
714 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
715 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
719 .name
= "Buffalo WBR2-G54",
722 { .name
= "reset", .gpio
= 1 << 7 },
725 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
729 .name
= "Buffalo WHR-HP-G54",
731 { .name
= "reset", .gpio
= 1 << 4 },
732 { .name
= "bridge", .gpio
= 1 << 5 },
733 { .name
= "ses", .gpio
= 1 << 0 },
736 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
737 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
738 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
739 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
740 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
744 .name
= "Buffalo WHR-G125",
746 { .name
= "reset", .gpio
= 1 << 4 },
747 { .name
= "bridge", .gpio
= 1 << 5 },
748 { .name
= "ses", .gpio
= 1 << 0 },
751 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
752 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
753 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
754 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
755 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
759 .name
= "Buffalo WHR2-A54G54",
761 { .name
= "reset", .gpio
= 1 << 4 },
764 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
768 .name
= "Buffalo WLA2-G54L",
771 { .name
= "reset", .gpio
= 1 << 7 },
774 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
778 .name
= "Buffalo WZR-G300N",
780 { .name
= "reset", .gpio
= 1 << 4 },
783 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
784 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
785 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
789 .name
= "Buffalo WZR-RS-G54",
791 { .name
= "ses", .gpio
= 1 << 0 },
792 { .name
= "reset", .gpio
= 1 << 4 },
795 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
796 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
797 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
801 .name
= "Buffalo WZR-RS-G54HP",
803 { .name
= "ses", .gpio
= 1 << 0 },
804 { .name
= "reset", .gpio
= 1 << 4 },
807 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
808 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
809 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
812 [BUFFALO_UNKNOWN_4710
] = {
813 .name
= "Buffalo (unknown, BCM4710)",
815 { .name
= "reset", .gpio
= 1 << 4 },
818 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
823 .name
= "Siemens SE505 V1",
825 /* No usable buttons */
828 // { .name = "power", .gpio = 1 << 0 .polarity = REVERSE }, // Usable when retrofitting D26 (?)
829 { .name
= "dmz", .gpio
= 1 << 4, .polarity
= REVERSE
}, // actual name WWW
830 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
834 .name
= "Siemens SE505 V2",
836 /* No usable buttons */
839 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
840 { .name
= "dmz", .gpio
= 1 << 0, .polarity
= REVERSE
}, // actual name WWW
841 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
846 .name
= "U.S. Robotics USR5461",
848 /* No usable buttons */
851 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
852 { .name
= "printer", .gpio
= 1 << 1, .polarity
= REVERSE
},
857 .name
= "Dell TrueMobile 2300",
859 { .name
= "reset", .gpio
= 1 << 0 },
862 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
863 { .name
= "power", .gpio
= 1 << 7, .polarity
= REVERSE
},
867 .name
= "Dell TrueMobile 2300 v2",
869 { .name
= "reset", .gpio
= 1 << 0 },
872 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
873 { .name
= "power", .gpio
= 1 << 7, .polarity
= REVERSE
},
878 .name
= "Motorola WE800G",
880 { .name
= "reset", .gpio
= 1 << 0 },
883 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
884 { .name
= "diag", .gpio
= 1 << 2, .polarity
= REVERSE
},
885 { .name
= "wlan_amber", .gpio
= 1 << 1, .polarity
= NORMAL
},
889 .name
= "Motorola WR850G V1",
891 { .name
= "reset", .gpio
= 1 << 0 },
894 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
895 { .name
= "diag", .gpio
= 1 << 3, .polarity
= REVERSE
},
896 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= NORMAL
},
897 { .name
= "wlan_red", .gpio
= 1 << 5, .polarity
= REVERSE
},
898 { .name
= "wlan_green", .gpio
= 1 << 7, .polarity
= REVERSE
},
902 .name
= "Motorola WR850G V2/V3",
904 { .name
= "reset", .gpio
= 1 << 5 },
907 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
908 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
909 { .name
= "wan", .gpio
= 1 << 6, .polarity
= INPUT
},
910 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
914 .name
= "Motorola WR850GP",
916 { .name
= "reset", .gpio
= 1 << 5 },
919 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
920 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
921 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= REVERSE
},
922 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
928 .name
= "Belkin (unknown)",
929 /* FIXME: verify & add detection */
931 { .name
= "reset", .gpio
= 1 << 7 },
934 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
},
935 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= NORMAL
},
936 { .name
= "connected", .gpio
= 1 << 0, .polarity
= NORMAL
},
940 .name
= "Belkin PlayMax F7D4301",
942 { .name
= "reset", .gpio
= 1 << 6 },
943 { .name
= "wps", .gpio
= 1 << 8 },
946 { .name
= "power", .gpio
= 1 << 11, .polarity
= REVERSE
},
947 { .name
= "wlan", .gpio
= 1 << 13, .polarity
= REVERSE
},
948 { .name
= "led0", .gpio
= 1 << 14, .polarity
= REVERSE
},
949 { .name
= "led1", .gpio
= 1 << 15, .polarity
= REVERSE
},
954 .name
= "Netgear WGT634U",
956 { .name
= "reset", .gpio
= 1 << 2 },
959 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
},
964 .name
= "Netgear WNR834B V1",
965 .buttons
= { /* TODO: add reset button and confirm LEDs - GPIO from dd-wrt */ },
967 { .name
= "power", .gpio
= 1 << 4, .polarity
= REVERSE
},
968 { .name
= "diag", .gpio
= 1 << 5, .polarity
= REVERSE
},
969 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
974 .name
= "Netgear WNR834B V2",
976 { .name
= "reset", .gpio
= 1 << 6 },
979 { .name
= "power", .gpio
= 1 << 2, .polarity
= NORMAL
},
980 { .name
= "diag", .gpio
= 1 << 3, .polarity
= NORMAL
},
981 { .name
= "connected", .gpio
= 1 << 7, .polarity
= NORMAL
},
985 .name
= "Netgear WNDR3400 V1",
987 /* nvram get gpio5=robo_reset */
988 { .name
= "reset", .gpio
= 1 << 4 },
989 { .name
= "wps", .gpio
= 1 << 6 },
990 { .name
= "wlan", .gpio
= 1 << 8 },
993 { .name
= "wlan", .gpio
= 0 << 0, .polarity
= NORMAL
},
994 { .name
= "connected", .gpio
= 1 << 0, .polarity
= NORMAL
},
995 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
},
996 { .name
= "diag", .gpio
= 1 << 7, .polarity
= NORMAL
},
997 { .name
= "usb", .gpio
= 1 << 2, .polarity
= REVERSE
},
1001 .name
= "Netgear WNDR3700 V3",
1003 /* { .name = "usb", .gpio = 1 << 1 }, */ /* this button doesn't seem to exist. */
1004 { .name
= "wlan", .gpio
= 1 << 2 },
1005 { .name
= "reset", .gpio
= 1 << 3 },
1006 { .name
= "wps", .gpio
= 1 << 4 },
1007 /* { .name = "switch", .gpio = 1 << 5 },*/ /* nvram get gpio5=robo_reset */
1010 { .name
= "power", .gpio
= (1 << 0) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1011 { .name
= "diag", .gpio
= (1 << 1) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1012 /* WAN LED doesn't respond to GPIO control. The switch is probably driving it.
1013 * { .name = "wan", .gpio = (1 << 2) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1015 { .name
= "wlan2g", .gpio
= (1 << 3) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1016 { .name
= "wlan5g", .gpio
= (1 << 4) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1017 { .name
= "usb", .gpio
= (1 << 5) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1018 { .name
= "wps", .gpio
= (1 << 6) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1019 { .name
= "wlan", .gpio
= (1 << 7) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1024 .name
= "Trendware TEW411BRP+",
1026 { /* No usable buttons */ },
1029 { .name
= "power", .gpio
= 1 << 7, .polarity
= NORMAL
},
1030 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
},
1031 { .name
= "bridge", .gpio
= 1 << 6, .polarity
= NORMAL
},
1036 .name
= "SimpleTech SimpleShare NAS",
1038 { .name
= "reset", .gpio
= 1 << 0 }, // Power button on back, named reset to enable failsafe.
1041 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
1043 .platform_init
= bcm4780_init
,
1047 .name
= "D-Link DIR-130",
1049 { .name
= "reset", .gpio
= 1 << 3},
1050 { .name
= "reserved", .gpio
= 1 << 7},
1053 { .name
= "diag", .gpio
= 1 << 0},
1054 { .name
= "blue", .gpio
= 1 << 6},
1058 .name
= "D-Link DIR-320",
1060 { .name
= "reserved", .gpio
= 1 << 6},
1061 { .name
= "reset", .gpio
= 1 << 7},
1064 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
1065 { .name
= "diag", .gpio
= 1 << 1, .polarity
= NORMAL
}, /* "status led */
1066 { .name
= "red", .gpio
= 1 << 3, .polarity
= REVERSE
},
1067 { .name
= "blue", .gpio
= 1 << 4, .polarity
= REVERSE
},
1068 { .name
= "usb", .gpio
= 1 << 5, .polarity
= NORMAL
},
1072 .name
= "D-Link DIR-330",
1074 { .name
= "reset", .gpio
= 1 << 3},
1075 { .name
= "reserved", .gpio
= 1 << 7},
1078 { .name
= "diag", .gpio
= 1 << 0},
1079 { .name
= "usb", .gpio
= 1 << 4},
1080 { .name
= "blue", .gpio
= 1 << 6},
1084 .name
= "D-Link DWL-3150",
1086 { .name
= "reset", .gpio
= 1 << 7},
1089 { .name
= "diag", .gpio
= 1 << 2},
1090 { .name
= "status", .gpio
= 1 << 1},
1095 .name
= "Sitecom WL-105b",
1097 { .name
= "reset", .gpio
= 1 << 10},
1100 { .name
= "wlan", .gpio
= 1 << 4},
1101 { .name
= "power", .gpio
= 1 << 3},
1104 /* Western Digital Net Center */
1106 .name
= "Western Digital NetCenter",
1108 { .name
= "power", .gpio
= 1 << 0},
1109 { .name
= "reset", .gpio
= 1 << 7},
1111 .platform_init
= NetCenter_init
,
1113 /* Askey (and clones) */
1115 .name
= "Askey RT210W",
1117 /* Power button is hard-wired to hardware reset */
1118 /* but is also connected to GPIO 7 (probably for bootloader recovery) */
1119 { .name
= "power", .gpio
= 1 << 7},
1122 /* These were verified and named based on Belkin F5D4230-4 v1112 */
1123 { .name
= "connected", .gpio
= 1 << 0, .polarity
= REVERSE
},
1124 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
1125 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
1129 .name
= "OvisLink WL-1600GL",
1131 { .name
= "reset", .gpio
= 1 << 3 },
1132 { .name
= "ses", .gpio
= 1 << 4 },
1135 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
1136 { .name
= "wps", .gpio
= 1 << 2, .polarity
= REVERSE
},
1137 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
1138 { .name
= "connected", .gpio
= 1 << 0, .polarity
= REVERSE
},
1143 .name
= "Microsoft MN-700",
1145 { .name
= "reset", .gpio
= 1 << 7 },
1148 { .name
= "power", .gpio
= 1 << 6, .polarity
= NORMAL
},
1153 .name
= "Edimax PS-1208MFG",
1155 { .name
= "reset", .gpio
= 1 << 4 },
1158 { .name
= "status", .gpio
= 1 << 1, .polarity
= NORMAL
},
1159 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
1164 static struct platform_t __init
*platform_detect_legacy(void)
1166 char *boardnum
, *boardtype
;
1168 if (strcmp(getvar("nvram_type"), "cfe") == 0)
1169 return &platforms
[WGT634U
];
1172 /* no easy model number, attempt to guess */
1173 boardnum
= getvar("boardnum");
1174 boardtype
= getvar("boardtype");
1176 if (!strcmp(boardnum
, "20070615")) { /* Linksys WRT600N v1/V1.1 */
1177 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "0") && !strcmp(getvar("switch_type"),"BCM5395"))
1178 return &platforms
[WRT600NV11
];
1180 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "0"))
1181 return &platforms
[WRT600N
];
1184 if (startswith(getvar("pmon_ver"), "CFE")) {
1185 /* CFE based - newer hardware */
1186 if (!strcmp(boardnum
, "42")) { /* Linksys */
1187 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "1"))
1188 return &platforms
[WRT350N
];
1190 if (!strcmp(boardtype
, "0x0101") && !strcmp(getvar("boot_ver"), "v3.6"))
1191 return &platforms
[WRT54G3G
];
1193 /* default to WRT54G if no boot_hw_model is set */
1194 if (nvram_get("boot_hw_model") == NULL
)
1195 return &platforms
[WRT54G
];
1197 if (!strcmp(boardnum
, "1024") && !strcmp(boardtype
, "0x0446"))
1198 return &platforms
[WAP54GV2
];
1200 if (!strcmp(boardnum
, "8") && !strcmp(boardtype
, "0x048e"))
1201 return &platforms
[WL1600GL
];
1204 if (!strcmp(boardnum
, "44") || !strcmp(boardnum
, "44\r")) {
1205 if (!strcmp(boardtype
,"0x0101") || !strcmp(boardtype
, "0x0101\r"))
1206 return &platforms
[TM2300V2
]; /* Dell TrueMobile 2300 v2 */
1209 if (!strcmp(boardnum
, "10496"))
1210 return &platforms
[USR5461
];
1212 if (!strcmp(getvar("boardtype"), "0x0101") && !strcmp(getvar("boardrev"), "0x10")) /* SE505V2 With Modified CFE */
1213 return &platforms
[SE505V2
];
1215 if (!strcmp(boardtype
, "0x048e") && !strcmp(getvar("boardrev"),"0x35") &&
1216 !strcmp(getvar("boardflags"), "0x750")) /* D-Link DIR-320 */
1217 return &platforms
[DIR320
];
1219 if (!strncmp(boardnum
, "TH",2) && !strcmp(boardtype
,"0x042f")) {
1220 return &platforms
[WDNetCenter
];
1223 if (!strcmp(boardtype
,"0x0472") && !strcmp(getvar("cardbus"), "1")) { /* Netgear WNR834B V1 and V2*/
1224 if (!strcmp(boardnum
, "08") || !strcmp(boardnum
, "8"))
1225 return &platforms
[WNR834BV1
];
1226 if (!strcmp(boardnum
, "01") || !strcmp(boardnum
, "1"))
1227 return &platforms
[WNR834BV2
];
1230 } else { /* PMON based - old stuff */
1231 if ((simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 9) &&
1232 (simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 30)) {
1233 return &platforms
[WR850GV1
];
1235 if (startswith(boardtype
, "bcm94710dev")) {
1236 if (!strcmp(boardnum
, "42"))
1237 return &platforms
[WRT54GV1
];
1238 if (simple_strtoul(boardnum
, NULL
, 0) == 2)
1239 return &platforms
[WAP54GV1
];
1241 /* MN-700 has also hardware_version 'WL500-...', so use boardnum */
1242 if (startswith(getvar("hardware_version"), "WL500-")) {
1243 if (!strcmp(getvar("boardnum"), "mn700"))
1244 return &platforms
[MN700
];
1246 return &platforms
[WL500G
];
1248 /* Sitecom WL-105b */
1249 if (startswith(boardnum
, "2") && simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 1)
1250 return &platforms
[WL105B
];
1252 /* unknown asus stuff, probably bcm4702 */
1253 if (startswith(boardnum
, "asusX"))
1254 return &platforms
[ASUS_4702
];
1256 /* bcm4702 based Askey RT210W clones, Including:
1257 * Askey RT210W (duh?)
1259 * Belkin F5D7230-4 before version v1444 (MiniPCI slot, not integrated)
1261 if (!strcmp(boardtype
,"bcm94710r4")
1262 && !strcmp(boardnum
,"100")
1263 && !strcmp(getvar("pmon_ver"),"v1.03.12.bk")
1265 return &platforms
[RT210W
];
1269 if (boardnum
|| !strcmp(boardnum
, "00")) {/* probably buffalo */
1270 if (startswith(boardtype
, "bcm94710ap"))
1271 return &platforms
[BUFFALO_UNKNOWN_4710
];
1274 if (startswith(getvar("CFEver"), "MotoWRv2") ||
1275 startswith(getvar("CFEver"), "MotoWRv3") ||
1276 !strcmp(getvar("MOTO_BOARD_TYPE"), "WR_FEM1")) {
1278 return &platforms
[WR850GV2V3
];
1281 if (!strcmp(boardnum
, "44") && !strcmp(getvar("boardflags"),"0x0388")) { /* Trendware TEW-411BRP+ */
1282 return &platforms
[TEW411BRPP
];
1285 if (startswith(boardnum
, "04FN")) /* SimpleTech SimpleShare */
1286 return &platforms
[STI_NAS
];
1288 if (!strcmp(boardnum
, "10") && !strcmp(getvar("boardrev"), "0x13")) /* D-Link DWL-3150 */
1289 return &platforms
[DWL3150
];
1291 if (!strcmp(boardnum
, "01") && !strcmp(boardtype
, "0x048e") && /* Edimax PS1208MFG */
1292 !strcmp(getvar("status_gpio"), "1")) /* gpio based detection */
1293 return &platforms
[PS1208MFG
];
1299 static struct platform_t __init
*platform_detect(void)
1301 enum bcm47xx_board board
;
1302 const char *board_name
;
1305 board
= bcm47xx_board_get();
1306 board_name
= bcm47xx_board_get_name();
1307 if (board
!= BCM47XX_BOARD_UNKNOWN
&& board
!= BCM47XX_BOARD_NON
)
1308 printk(MODULE_NAME
": kernel found a \"%s\"\n", board_name
);
1311 case BCM47XX_BOARD_ASUS_RTN12
:
1312 return &platforms
[RTN12
];
1313 case BCM47XX_BOARD_ASUS_RTN16
:
1314 return &platforms
[RTN16
];
1315 case BCM47XX_BOARD_ASUS_RTN66U
:
1316 return &platforms
[RTN66U
];
1317 case BCM47XX_BOARD_ASUS_WL300G
:
1318 return &platforms
[WL300G
];
1319 case BCM47XX_BOARD_ASUS_WL320GE
:
1320 return &platforms
[WL320GE
];
1321 case BCM47XX_BOARD_ASUS_WL330GE
:
1322 return &platforms
[WL330GE
];
1323 case BCM47XX_BOARD_ASUS_WL500GD
:
1324 return &platforms
[WL500GD
];
1325 case BCM47XX_BOARD_ASUS_WL500GPV1
:
1326 return &platforms
[WL500GP
];
1327 case BCM47XX_BOARD_ASUS_WL500GPV2
:
1328 return &platforms
[WL500GPV2
];
1329 case BCM47XX_BOARD_ASUS_WL500W
:
1330 return &platforms
[WL500W
];
1331 case BCM47XX_BOARD_ASUS_WL520GC
:
1332 return &platforms
[WL520GC
];
1333 case BCM47XX_BOARD_ASUS_WL520GU
:
1334 return &platforms
[WL520GU
];
1335 case BCM47XX_BOARD_ASUS_WL700GE
:
1336 return &platforms
[WL700GE
];
1337 case BCM47XX_BOARD_ASUS_WLHDD
:
1338 return &platforms
[WLHDD
];
1339 case BCM47XX_BOARD_BELKIN_F7D4301
:
1340 return &platforms
[BELKIN_F7D4301
];
1341 case BCM47XX_BOARD_BUFFALO_WBR2_G54
:
1342 return &platforms
[WBR2_G54
];
1343 case BCM47XX_BOARD_BUFFALO_WHR2_A54G54
:
1344 return &platforms
[WHR2_A54G54
];
1345 case BCM47XX_BOARD_BUFFALO_WHR_G125
:
1346 return &platforms
[WHR_G125
];
1347 case BCM47XX_BOARD_BUFFALO_WHR_G54S
:
1348 return &platforms
[WHR_G54S
];
1349 case BCM47XX_BOARD_BUFFALO_WHR_HP_G54
:
1350 return &platforms
[WHR_HP_G54
];
1351 case BCM47XX_BOARD_BUFFALO_WLA2_G54L
:
1352 return &platforms
[WLA2_G54L
];
1353 case BCM47XX_BOARD_BUFFALO_WZR_G300N
:
1354 return &platforms
[WZR_G300N
];
1355 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54
:
1356 return &platforms
[WZR_RS_G54
];
1357 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54HP
:
1358 return &platforms
[WZR_RS_G54HP
];
1359 case BCM47XX_BOARD_DELL_TM2300
:
1360 return &platforms
[TM2300
];
1361 case BCM47XX_BOARD_DLINK_DIR130
:
1362 return &platforms
[DIR130
];
1363 case BCM47XX_BOARD_DLINK_DIR330
:
1364 return &platforms
[DIR330
];
1365 case BCM47XX_BOARD_LINKSYS_E1000V1
:
1366 return &platforms
[E1000V1
];
1367 case BCM47XX_BOARD_LINKSYS_E1000V21
:
1368 return &platforms
[E1000V21
];
1369 case BCM47XX_BOARD_LINKSYS_E3000V1
:
1370 return &platforms
[E3000V1
];
1371 case BCM47XX_BOARD_LINKSYS_E3200V1
:
1372 return &platforms
[E3200V1
];
1373 case BCM47XX_BOARD_LINKSYS_E4200V1
:
1374 return &platforms
[E4200V1
];
1375 case BCM47XX_BOARD_LINKSYS_WRT150NV1
:
1376 return &platforms
[WRT150NV1
];
1377 case BCM47XX_BOARD_LINKSYS_WRT150NV11
:
1378 return &platforms
[WRT150NV11
];
1379 case BCM47XX_BOARD_LINKSYS_WRT160NV1
:
1380 return &platforms
[WRT160NV1
];
1381 case BCM47XX_BOARD_LINKSYS_WRT160NV3
:
1382 return &platforms
[WRT160NV3
];
1383 case BCM47XX_BOARD_LINKSYS_WRT300NV11
:
1384 return &platforms
[WRT300NV11
];
1385 case BCM47XX_BOARD_LINKSYS_WRT54G3GV2
:
1386 return &platforms
[WRT54G3GV2_VF
];
1387 case BCM47XX_BOARD_LINKSYS_WRT610NV1
:
1388 return &platforms
[WRT610N
];
1389 case BCM47XX_BOARD_LINKSYS_WRT610NV2
:
1390 return &platforms
[WRT610NV2
];
1391 case BCM47XX_BOARD_LINKSYS_WRTSL54GS
:
1392 return &platforms
[WRTSL54GS
];
1393 case BCM47XX_BOARD_MOTOROLA_WE800G
:
1394 return &platforms
[WE800G
];
1395 case BCM47XX_BOARD_MOTOROLA_WR850GP
:
1396 return &platforms
[WR850GP
];
1397 case BCM47XX_BOARD_MOTOROLA_WR850GV2V3
:
1398 return &platforms
[WR850GV2V3
];
1399 case BCM47XX_BOARD_NETGEAR_WNDR3400V1
:
1400 return &platforms
[WNDR3400V1
];
1401 case BCM47XX_BOARD_NETGEAR_WNDR3700V3
:
1402 return &platforms
[WNDR3700V3
];
1403 case BCM47XX_BOARD_UNKNOWN
:
1404 case BCM47XX_BOARD_NON
:
1405 printk(MODULE_NAME
": unknown board found, try legacy detect\n");
1406 printk(MODULE_NAME
": please open a ticket at https://dev.openwrt.org and attach the complete nvram\n");
1407 return platform_detect_legacy();
1409 printk(MODULE_NAME
": board was detected as \"%s\", but not gpio configuration available\n", board_name
);
1410 printk(MODULE_NAME
": now trying legacy detect\n");
1411 return platform_detect_legacy();
1415 static inline void ssb_maskset32(struct ssb_device
*dev
,
1416 u16 offset
, u32 mask
, u32 set
)
1418 ssb_write32(dev
, offset
, (ssb_read32(dev
, offset
) & mask
) | set
);
1421 static void gpio_set_irqenable(int enabled
, irqreturn_t (*handler
)(int, void *))
1426 irq
= gpio_to_irq(0);
1428 pr_err("no irq for gpio available\n");
1433 err
= request_irq(irq
, handler
, IRQF_SHARED
, "gpio", handler
);
1435 pr_err("can not reqeust irq\n");
1439 free_irq(irq
, handler
);
1442 switch (bcm47xx_bus_type
) {
1443 #ifdef CONFIG_BCM47XX_SSB
1444 case BCM47XX_BUS_TYPE_SSB
:
1445 if (bcm47xx_bus
.ssb
.chipco
.dev
)
1446 ssb_maskset32(bcm47xx_bus
.ssb
.chipco
.dev
, SSB_CHIPCO_IRQMASK
, ~SSB_CHIPCO_IRQ_GPIO
, (enabled
? SSB_CHIPCO_IRQ_GPIO
: 0));
1449 #ifdef CONFIG_BCM47XX_BCMA
1450 case BCM47XX_BUS_TYPE_BCMA
:
1451 if (bcm47xx_bus
.bcma
.bus
.drv_cc
.core
)
1452 bcma_maskset32(bcm47xx_bus
.bcma
.bus
.drv_cc
.core
, BCMA_CC_IRQMASK
, ~BCMA_CC_IRQ_GPIO
, (enabled
? BCMA_CC_IRQ_GPIO
: 0));
1458 static void hotplug_button(struct work_struct
*work
)
1460 struct event_t
*event
= container_of(work
, struct event_t
, wq
);
1463 event
->skb
= alloc_skb(2048, GFP_KERNEL
);
1465 s
= skb_put(event
->skb
, strlen(event
->action
) + 2);
1466 sprintf(s
, "%s@", event
->action
);
1469 NETLINK_CB(event
->skb
).dst_group
= 1;
1470 broadcast_uevent(event
->skb
, 0, 1, GFP_KERNEL
);
1475 static irqreturn_t
button_handler(int irq
, void *dev_id
)
1480 in
= bcm47xx_gpio_in(~0) & platform
.button_mask
;
1481 bcm47xx_gpio_polarity(platform
.button_mask
, in
);
1482 changed
= platform
.button_polarity
^ in
;
1483 platform
.button_polarity
= in
;
1485 changed
&= ~bcm47xx_gpio_outen(0, 0);
1487 for (b
= platform
.buttons
; b
->name
; b
++) {
1488 struct event_t
*event
;
1490 if (!(b
->gpio
& changed
)) continue;
1494 if ((event
= (struct event_t
*)kzalloc (sizeof(struct event_t
), GFP_ATOMIC
))) {
1495 event
->seen
= (jiffies
- b
->seen
)/HZ
;
1496 event
->name
= b
->name
;
1497 event
->action
= b
->pressed
? "pressed" : "released";
1498 INIT_WORK(&event
->wq
, (void *)(void *)hotplug_button
);
1499 schedule_work(&event
->wq
);
1507 static void register_buttons(struct button_t
*b
)
1509 for (; b
->name
; b
++)
1510 platform
.button_mask
|= b
->gpio
;
1512 platform
.button_mask
&= ~gpiomask
;
1514 bcm47xx_gpio_outen(platform
.button_mask
, 0);
1515 bcm47xx_gpio_control(platform
.button_mask
, 0);
1516 platform
.button_polarity
= bcm47xx_gpio_in(~0) & platform
.button_mask
;
1517 bcm47xx_gpio_polarity(platform
.button_mask
, platform
.button_polarity
);
1518 bcm47xx_gpio_intmask(platform
.button_mask
, platform
.button_mask
);
1520 gpio_set_irqenable(1, button_handler
);
1523 static void unregister_buttons(struct button_t
*b
)
1525 bcm47xx_gpio_intmask(platform
.button_mask
, 0);
1527 gpio_set_irqenable(0, button_handler
);
1531 static void add_msg(struct event_t
*event
, char *msg
, int argv
)
1538 s
= skb_put(event
->skb
, strlen(msg
) + 1);
1542 static int fill_event (struct event_t
*event
)
1544 static char buf
[128];
1546 add_msg(event
, "HOME=/", 0);
1547 add_msg(event
, "PATH=/sbin:/bin:/usr/sbin:/usr/bin", 0);
1548 add_msg(event
, "SUBSYSTEM=button", 0);
1549 snprintf(buf
, 128, "ACTION=%s", event
->action
);
1550 add_msg(event
, buf
, 0);
1551 snprintf(buf
, 128, "BUTTON=%s", event
->name
);
1552 add_msg(event
, buf
, 0);
1553 snprintf(buf
, 128, "SEEN=%ld", event
->seen
);
1554 add_msg(event
, buf
, 0);
1555 snprintf(buf
, 128, "SEQNUM=%llu", uevent_next_seqnum());
1556 add_msg(event
, buf
, 0);
1562 * This should be extended to allow the platform to specify the pins and width
1563 * of the shift register. They're hardcoded for now because only the WNDR3700v3
1566 static void shiftreg_output(unsigned int val
)
1570 bcm47xx_gpio_out(SHIFTREG_DATA
, SHIFTREG_DATA
); /* init off, pull high */
1571 bcm47xx_gpio_out(SHIFTREG_CLK
, 0); /* init reset */
1574 for(mask
= 1 << (SHIFTREG_MAX_BITS
-1); mask
; mask
>>= 1)
1576 bcm47xx_gpio_out(SHIFTREG_DATA
, (val
& mask
) ? SHIFTREG_DATA
: 0);
1577 bcm47xx_gpio_out(SHIFTREG_CLK
, SHIFTREG_CLK
); /* pull high to trigger */
1578 bcm47xx_gpio_out(SHIFTREG_CLK
, 0); /* reset to low */
1582 static void set_led_shift(struct led_t
*led
)
1584 static u32 shiftreg
= 0;
1586 u32 pin
= (led
->gpio
& ~GPIO_TYPE_MASK
);
1594 /* Clock the bits out. */
1595 if (shiftreg
!= old
) {
1596 shiftreg_output(shiftreg
);
1600 static void set_led_extif(struct led_t
*led
)
1602 volatile u8
*addr
= (volatile u8
*) KSEG1ADDR(EXTIF_UART
) + (led
->gpio
& ~GPIO_TYPE_MASK
);
1610 static void led_flash(unsigned long dummy
) {
1615 for (l
= platform
.leds
; l
->name
; l
++) {
1616 if (!l
->flash
) continue;
1617 switch (l
->gpio
& GPIO_TYPE_MASK
) {
1618 case GPIO_TYPE_EXTIF
:
1620 l
->state
= !l
->state
;
1623 case GPIO_TYPE_SHIFT
:
1625 l
->state
= !l
->state
;
1628 case GPIO_TYPE_NORMAL
:
1637 u32 val
= ~bcm47xx_gpio_in(~0);
1639 bcm47xx_gpio_outen(mask
, mask
);
1640 bcm47xx_gpio_control(mask
, 0);
1641 bcm47xx_gpio_out(mask
, val
);
1643 if (mask
|| extif_blink
) {
1644 mod_timer(&led_timer
, jiffies
+ FLASH_TIME
);
1648 static int diag_led_show(struct seq_file
*m
, void *v
)
1650 struct led_t
* led
= m
->private;
1652 u8 p
= (led
->polarity
== NORMAL
? 0 : 1);
1654 return seq_printf(m
, "f\n");
1655 } else if ((led
->gpio
& GPIO_TYPE_MASK
) != GPIO_TYPE_NORMAL
) {
1656 return seq_printf(m
, "%d\n", ((led
->state
^ p
) ? 1 : 0));
1658 u32 in
= (bcm47xx_gpio_in(~0) & led
->gpio
? 1 : 0);
1659 return seq_printf(m
, "%d\n", ((in
^ p
) ? 1 : 0));
1663 static int diag_led_open(struct inode
*inode
, struct file
*file
)
1665 return single_open(file
, diag_led_show
, PDE_DATA(inode
));
1668 static ssize_t
diag_led_write(struct file
*file
, const char __user
*buf
, size_t count
, loff_t
*ppos
)
1670 struct led_t
*led
= PDE_DATA(file_inode(file
));
1675 len
= min(count
, sizeof(cmd
) - 1);
1676 if (copy_from_user(cmd
, buf
, len
))
1681 p
= (led
->polarity
== NORMAL
? 0 : 1);
1682 if (cmd
[0] == 'f') {
1687 if ((led
->gpio
& GPIO_TYPE_MASK
) == GPIO_TYPE_EXTIF
) {
1688 led
->state
= p
^ ((cmd
[0] == '1') ? 1 : 0);
1690 } else if ((led
->gpio
& GPIO_TYPE_MASK
) == GPIO_TYPE_SHIFT
) {
1691 led
->state
= p
^ ((cmd
[0] == '1') ? 1 : 0);
1694 bcm47xx_gpio_outen(led
->gpio
, led
->gpio
);
1695 bcm47xx_gpio_control(led
->gpio
, 0);
1696 bcm47xx_gpio_out(led
->gpio
, ((p
^ (cmd
[0] == '1')) ? led
->gpio
: 0));
1702 static const struct file_operations diag_led_fops
= {
1703 .open
= diag_led_open
,
1705 .llseek
= seq_lseek
,
1706 .write
= diag_led_write
1709 static void register_leds(struct led_t
*l
)
1711 struct proc_dir_entry
*p
;
1716 leds
= proc_mkdir("led", diag
);
1720 for(; l
->name
; l
++) {
1721 if (l
->gpio
& gpiomask
)
1724 switch (l
->gpio
& GPIO_TYPE_MASK
) {
1725 case GPIO_TYPE_EXTIF
:
1729 case GPIO_TYPE_SHIFT
:
1730 mask
|= (SHIFTREG_DATA
| SHIFTREG_CLK
);
1731 oe_mask
|= (SHIFTREG_DATA
| SHIFTREG_CLK
);
1732 l
->state
= (l
->polarity
!= NORMAL
);
1735 case GPIO_TYPE_NORMAL
:
1737 if (l
->polarity
!= INPUT
) oe_mask
|= l
->gpio
;
1739 val
|= (l
->polarity
== NORMAL
)?0:l
->gpio
;
1743 if (l
->polarity
== INPUT
) continue;
1745 p
= proc_create_data(l
->name
, S_IRUSR
, leds
, &diag_led_fops
, l
);
1748 bcm47xx_gpio_outen(mask
, oe_mask
);
1749 bcm47xx_gpio_control(mask
, 0);
1750 bcm47xx_gpio_out(mask
, val
);
1751 bcm47xx_gpio_intmask(mask
, 0);
1754 static void unregister_leds(struct led_t
*l
)
1757 remove_proc_entry(l
->name
, leds
);
1759 remove_proc_entry("led", diag
);
1762 static int diag_model_show(struct seq_file
*m
, void *v
)
1764 return seq_printf(m
, "%s\n", platform
.name
);
1767 static int diag_model_open(struct inode
*inode
, struct file
*file
)
1769 return single_open(file
, diag_model_show
, PDE_DATA(inode
));
1772 static const struct file_operations diag_model_fops
= {
1773 .open
= diag_model_open
,
1778 static int diag_gpiomask_show(struct seq_file
*m
, void *v
)
1780 return seq_printf(m
, "0x%04x\n", gpiomask
);
1783 static int diag_gpiomask_open(struct inode
*inode
, struct file
*file
)
1785 return single_open(file
, diag_gpiomask_show
, PDE_DATA(inode
));
1788 static ssize_t
diag_gpiomask_write(struct file
*file
, const char __user
*buf
, size_t count
, loff_t
*ppos
)
1790 int err
= kstrtouint_from_user(buf
, count
, 0, &gpiomask
);
1794 if (platform
.buttons
) {
1795 unregister_buttons(platform
.buttons
);
1796 register_buttons(platform
.buttons
);
1799 if (platform
.leds
) {
1800 unregister_leds(platform
.leds
);
1801 register_leds(platform
.leds
);
1807 static const struct file_operations diag_gpiomask_fops
= {
1808 .open
= diag_gpiomask_open
,
1810 .llseek
= seq_lseek
,
1811 .write
= diag_gpiomask_write
1814 static int __init
diag_init(void)
1816 static struct proc_dir_entry
*p
;
1817 static struct platform_t
*detected
;
1819 detected
= platform_detect();
1821 printk(MODULE_NAME
": Router model not detected.\n");
1824 memcpy(&platform
, detected
, sizeof(struct platform_t
));
1826 printk(MODULE_NAME
": Detected '%s'\n", platform
.name
);
1827 if (platform
.platform_init
!= NULL
) {
1828 platform
.platform_init();
1831 if (!(diag
= proc_mkdir("diag", NULL
))) {
1832 printk(MODULE_NAME
": proc_mkdir on /proc/diag failed\n");
1836 p
= proc_create("model", S_IRUSR
, diag
, &diag_model_fops
);
1838 remove_proc_entry("diag", NULL
);
1842 p
= proc_create("gpiomask", S_IRUSR
| S_IWUSR
, diag
, &diag_gpiomask_fops
);
1844 remove_proc_entry("model", diag
);
1845 remove_proc_entry("diag", NULL
);
1849 if (platform
.buttons
)
1850 register_buttons(platform
.buttons
);
1853 register_leds(platform
.leds
);
1858 static void __exit
diag_exit(void)
1860 del_timer(&led_timer
);
1862 if (platform
.buttons
)
1863 unregister_buttons(platform
.buttons
);
1866 unregister_leds(platform
.leds
);
1868 remove_proc_entry("model", diag
);
1869 remove_proc_entry("gpiomask", diag
);
1870 remove_proc_entry("diag", NULL
);
1873 module_init(diag_init
);
1874 module_exit(diag_exit
);
1876 MODULE_AUTHOR("Mike Baker, Felix Fietkau / OpenWrt.org");
1877 MODULE_LICENSE("GPL");