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
;
126 BUFFALO_UNKNOWN_4710
,
171 /* Western Digital */
190 static void __init
bcm4780_init(void) {
193 /* Enables GPIO 3 that controls HDD and led power on ASUS WL-700gE */
194 printk(MODULE_NAME
": Spinning up HDD and enabling leds\n");
195 bcm47xx_gpio_outen(pin
, pin
);
196 bcm47xx_gpio_control(pin
, 0);
197 bcm47xx_gpio_out(pin
, pin
);
199 /* Wait 5s, so the HDD can spin up */
200 set_current_state(TASK_INTERRUPTIBLE
);
201 schedule_timeout(HZ
* 5);
204 static void __init
NetCenter_init(void) {
205 /* unset pin 6 (+12V) */
207 bcm47xx_gpio_outen(pin
, pin
);
208 bcm47xx_gpio_control(pin
, 0);
209 bcm47xx_gpio_out(pin
, pin
);
210 /* unset pin 1 (turn off red led, blue will light alone if +5V comes up) */
212 bcm47xx_gpio_outen(pin
, pin
);
213 bcm47xx_gpio_control(pin
, 0);
214 bcm47xx_gpio_out(pin
, pin
);
215 /* unset pin 3 (+5V) and wait 5 seconds (harddisk spin up) */
219 static void __init
bcm57xx_init(void) {
222 /* FIXME: switch comes up, but port mappings/vlans not right */
223 bcm47xx_gpio_outen(pin
, pin
);
224 bcm47xx_gpio_control(pin
, 0);
225 bcm47xx_gpio_out(pin
, pin
);
228 static struct platform_t __initdata platforms
[] = {
231 .name
= "Linksys WAP54G V1",
233 { .name
= "reset", .gpio
= 1 << 0 },
236 { .name
= "diag", .gpio
= 1 << 3 },
237 { .name
= "wlan", .gpio
= 1 << 4 },
241 .name
= "Linksys WAP54G V2",
243 { .name
= "reset", .gpio
= 1 << 0 },
246 { .name
= "wlan", .gpio
= 1 << 5, .polarity
= REVERSE
},
247 /* GPIO 6 is b44 (eth0, LAN) PHY power */
251 .name
= "Linksys WAP54G V3",
253 /* FIXME: verify this */
254 { .name
= "reset", .gpio
= 1 << 7 },
255 { .name
= "ses", .gpio
= 1 << 0 },
259 { .name
= "ses", .gpio
= 1 << 1 },
263 .name
= "Linksys WRT54G V1.x",
265 { .name
= "reset", .gpio
= 1 << 6 },
268 { .name
= "diag", .gpio
= 0x13 | GPIO_TYPE_EXTIF
, .polarity
= NORMAL
},
269 { .name
= "dmz", .gpio
= 0x12 | GPIO_TYPE_EXTIF
, .polarity
= NORMAL
},
273 .name
= "Linksys WRT54G/GS/GL",
275 { .name
= "reset", .gpio
= 1 << 6 },
276 { .name
= "ses", .gpio
= 1 << 4 },
279 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
280 { .name
= "dmz", .gpio
= 1 << 7, .polarity
= REVERSE
},
281 { .name
= "ses_white", .gpio
= 1 << 2, .polarity
= REVERSE
},
282 { .name
= "ses_orange", .gpio
= 1 << 3, .polarity
= REVERSE
},
283 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
287 .name
= "Linksys WRTSL54GS",
289 { .name
= "reset", .gpio
= 1 << 6 },
290 { .name
= "ses", .gpio
= 1 << 4 },
293 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
294 { .name
= "dmz", .gpio
= 1 << 0, .polarity
= REVERSE
},
295 { .name
= "ses_white", .gpio
= 1 << 5, .polarity
= REVERSE
},
296 { .name
= "ses_orange", .gpio
= 1 << 7, .polarity
= REVERSE
},
300 .name
= "Linksys WRT54G3G",
302 { .name
= "reset", .gpio
= 1 << 6 },
303 { .name
= "3g", .gpio
= 1 << 4 },
306 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
307 { .name
= "dmz", .gpio
= 1 << 7, .polarity
= REVERSE
},
308 { .name
= "3g_green", .gpio
= 1 << 2, .polarity
= NORMAL
},
309 { .name
= "3g_blue", .gpio
= 1 << 3, .polarity
= NORMAL
},
310 { .name
= "3g_blink", .gpio
= 1 << 5, .polarity
= NORMAL
},
314 .name
= "Linksys WRT54G3GV2-VF",
316 { .name
= "reset", .gpio
= 1 << 6 },
317 { .name
= "3g", .gpio
= 1 << 5 },
320 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
321 { .name
= "3g_green", .gpio
= 1 << 2, .polarity
= NORMAL
},
322 { .name
= "3g_blue", .gpio
= 1 << 3, .polarity
= NORMAL
},
326 .name
= "Linksys WRT150N V1",
328 { .name
= "reset", .gpio
= 1 << 6 },
329 { .name
= "ses", .gpio
= 1 << 4 },
332 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
333 { .name
= "ses_green", .gpio
= 1 << 5, .polarity
= REVERSE
},
334 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
338 .name
= "Linksys WRT150N V1.1",
340 { .name
= "reset", .gpio
= 1 << 6 },
341 { .name
= "ses", .gpio
= 1 << 4 },
344 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
345 { .name
= "ses_green", .gpio
= 1 << 5, .polarity
= REVERSE
},
346 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
350 .name
= "Linksys WRT160N v1.x",
352 { .name
= "reset", .gpio
= 1 << 6 },
353 { .name
= "ses", .gpio
= 1 << 4 },
356 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
357 { .name
= "ses_blue", .gpio
= 1 << 5, .polarity
= REVERSE
},
358 { .name
= "ses_orange", .gpio
= 1 << 3, .polarity
= REVERSE
},
362 .name
= "Linksys WRT160N V3",
364 { .name
= "reset", .gpio
= 1 << 6 },
365 { .name
= "ses", .gpio
= 1 << 5 },
368 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
369 { .name
= "ses_blue", .gpio
= 1 << 4, .polarity
= REVERSE
},
370 { .name
= "ses_orange", .gpio
= 1 << 2, .polarity
= REVERSE
},
374 .name
= "Linksys WRT300N V1.1",
376 { .name
= "reset", .gpio
= 1 << 6 }, // "Reset" on back panel
377 { .name
= "ses", .gpio
= 1 << 4 }, // "Reserved" on top panel
380 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
}, // "Power"
381 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
}, // "Security" Amber
382 { .name
= "ses_green", .gpio
= 1 << 5, .polarity
= REVERSE
}, // "Security" Green
384 .platform_init
= bcm57xx_init
,
387 .name
= "Linksys WRT310N V1",
389 { .name
= "reset", .gpio
= 1 << 6 }, // "Reset" on back panel
390 { .name
= "ses", .gpio
= 1 << 8 }, // "Reserved" on top panel
393 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
}, // Power LED
394 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
}, // "Security" Amber
395 { .name
= "ses_blue", .gpio
= 1 << 9, .polarity
= REVERSE
}, // "Security" Blue
399 .name
= "Linksys WRT350N",
401 { .name
= "reset", .gpio
= 1 << 6 },
402 { .name
= "ses", .gpio
= 1 << 8 },
405 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
406 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
407 { .name
= "ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
},
408 { .name
= "usb_blink", .gpio
= 1 << 10, .polarity
= REVERSE
},
409 { .name
= "usb", .gpio
= 1 << 11, .polarity
= REVERSE
},
411 .platform_init
= bcm57xx_init
,
414 .name
= "Linksys WRT600N",
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 WRT600N V1.1",
432 { .name
= "reset", .gpio
= 1 << 6 },
433 { .name
= "ses", .gpio
= 1 << 7 },
436 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
}, // Power LED
437 { .name
= "usb", .gpio
= 1 << 3, .polarity
= REVERSE
}, // USB LED
438 { .name
= "wl0_ses_amber", .gpio
= 1 << 8, .polarity
= REVERSE
}, // 2.4Ghz LED Amber
439 { .name
= "wl0_ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
}, // 2.4Ghz LED Green
440 { .name
= "wl1_ses_amber", .gpio
= 1 << 10, .polarity
= REVERSE
}, // 5.6Ghz LED Amber
441 { .name
= "wl1_ses_green", .gpio
= 1 << 11, .polarity
= REVERSE
}, // 5.6Ghz LED Green
443 .platform_init
= bcm57xx_init
,
446 .name
= "Linksys WRT610N",
448 { .name
= "reset", .gpio
= 1 << 6 },
449 { .name
= "ses", .gpio
= 1 << 8 },
452 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
}, // Power LED
453 { .name
= "usb", .gpio
= 1 << 0, .polarity
= REVERSE
}, // USB LED
454 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
}, // WiFi protected setup LED amber
455 { .name
= "ses_blue", .gpio
= 1 << 9, .polarity
= REVERSE
}, // WiFi protected setup LED blue
459 .name
= "Linksys WRT610N V2",
461 { .name
= "reset", .gpio
= 1 << 6 },
462 { .name
= "ses", .gpio
= 1 << 4 },
465 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
}, // Power LED
466 { .name
= "usb", .gpio
= 1 << 7, .polarity
= NORMAL
}, // USB LED
467 { .name
= "ses_amber", .gpio
= 1 << 0, .polarity
= REVERSE
}, // WiFi protected setup LED amber
468 { .name
= "ses_blue", .gpio
= 1 << 3, .polarity
= REVERSE
}, // WiFi protected setup LED blue
469 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
}, // Wireless LED
472 /* same hardware as WRT160NV3 and Cisco Valet M10V1, but different board detection, combine? */
474 .name
= "Linksys E1000 V1",
476 { .name
= "reset", .gpio
= 1 << 6 },
477 { .name
= "wps", .gpio
= 1 << 5 }, /* nvram get gpio5=wps_button */
480 /** turns on leds for all ethernet ports (wan too)
481 * this also disconnects some, or maybe all, ethernet ports
482 * 1: leds work normally
483 * 0: all lit all the time */
484 /* nvram get gpio3=robo_reset */
485 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
486 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
487 { .name
= "ses_blue", .gpio
= 1 << 4, .polarity
= REVERSE
}, /* nvram get gpio4=wps_led */
488 { .name
= "ses_orange", .gpio
= 1 << 2, .polarity
= REVERSE
}, /* nvram get gpio2=wps_status_led */
492 .name
= "Linksys E1000 V2.1",
494 { .name
= "reset", .gpio
= 1 << 10 }, /* nvram get reset_gpio=10 */
495 { .name
= "wps", .gpio
= 1 << 9 }, /* nvram get gpio9=wps_button */
498 { .name
= "power", .gpio
= 1 << 6, .polarity
= REVERSE
},
499 { .name
= "wlan", .gpio
= 1 << 5, .polarity
= NORMAL
},
500 { .name
= "ses_blue", .gpio
= 1 << 8, .polarity
= NORMAL
}, /* nvram get gpio8=wps_led */
501 { .name
= "ses_orange", .gpio
= 1 << 7, .polarity
= NORMAL
}, /* nvram get gpio7=wps_status_led */
505 .name
= "Linksys E3000 V1",
507 { .name
= "reset", .gpio
= 1 << 6 },
508 { .name
= "ses", .gpio
= 1 << 4 },
511 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
}, // Power LED
512 { .name
= "usb", .gpio
= 1 << 7, .polarity
= NORMAL
}, // USB LED
513 { .name
= "ses_amber", .gpio
= 1 << 0, .polarity
= REVERSE
}, // WiFi protected setup LED amber
514 { .name
= "ses_blue", .gpio
= 1 << 3, .polarity
= REVERSE
}, // WiFi protected setup LED blue
515 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
}, // Wireless LED
519 .name
= "Linksys E3200 V1",
521 /* { .name = "switch", .gpio = 1 << 4 },*/ /* nvram get gpio4=robo_reset */
522 { .name
= "reset", .gpio
= 1 << 5 }, /* nvram get reset_gpio=5 */
523 { .name
= "wps", .gpio
= 1 << 8 }, /* nvram get gpio8=wps_button */
524 /* { .name = "wombo", .gpio = 1 << 23 },*/ /* nvram get gpio23=wombo_reset - wireless on motherboard */
527 { .name
= "power", .gpio
= 1 << 3, .polarity
= REVERSE
}, /* Power LED */
531 .name
= "Linksys E4200 V1",
533 { .name
= "reset", .gpio
= 1 << 6 },
534 { .name
= "wps", .gpio
= 1 << 4 },
537 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
542 .name
= "ASUS WL-HDD",
544 { .name
= "reset", .gpio
= 1 << 6 },
547 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
548 { .name
= "usb", .gpio
= 1 << 2, .polarity
= REVERSE
},
552 .name
= "ASUS WL-300g",
554 { .name
= "reset", .gpio
= 1 << 6 },
557 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
561 .name
= "ASUS WL-320gE/WL-320gP",
563 { .name
= "reset", .gpio
= 1 << 6 },
566 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
567 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
},
568 { .name
= "link", .gpio
= 1 << 11, .polarity
= REVERSE
},
572 .name
= "ASUS WL-330gE",
574 { .name
= "reset", .gpio
= 1 << 2 },
577 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
581 .name
= "ASUS WL-500g",
583 { .name
= "reset", .gpio
= 1 << 6 },
586 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
590 .name
= "ASUS WL-500g Deluxe",
592 { .name
= "reset", .gpio
= 1 << 6 },
595 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
599 .name
= "ASUS WL-500g Premium",
601 { .name
= "reset", .gpio
= 1 << 0 },
602 { .name
= "ses", .gpio
= 1 << 4 },
605 { .name
= "power", .gpio
= 1 << 1, .polarity
= REVERSE
},
609 .name
= "ASUS WL-500g Premium V2",
611 { .name
= "reset", .gpio
= 1 << 2 },
612 { .name
= "ses", .gpio
= 1 << 3 },
615 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
616 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
620 .name
= "ASUS WL-500W",
622 { .name
= "reset", .gpio
= 1 << 6 },
623 { .name
= "ses", .gpio
= 1 << 7 },
626 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
630 .name
= "ASUS WL-520GC",
632 { .name
= "reset", .gpio
= 1 << 2 },
633 { .name
= "ses", .gpio
= 1 << 3 },
636 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
637 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
641 .name
= "ASUS WL-520gU",
643 { .name
= "reset", .gpio
= 1 << 2 },
644 { .name
= "ses", .gpio
= 1 << 3 },
647 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
648 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
652 .name
= "ASUS (unknown, BCM4702)",
654 { .name
= "reset", .gpio
= 1 << 6 },
657 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
661 .name
= "ASUS WL-700gE",
663 { .name
= "reset", .gpio
= 1 << 7 }, // on back, hardwired, always resets device regardless OS state
664 { .name
= "ses", .gpio
= 1 << 4 }, // on back, actual name ezsetup
665 { .name
= "power", .gpio
= 1 << 0 }, // on front
666 { .name
= "copy", .gpio
= 1 << 6 }, // on front
670 // GPIO that controls power led also enables/disables some essential functions
673 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
}, // actual name power
675 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
677 .platform_init
= bcm4780_init
,
680 .name
= "ASUS RT-N12",
682 { .name
= "wps", .gpio
= 1 << 0 },
683 { .name
= "reset", .gpio
= 1 << 1 },
684 // this is the router/repeater/ap switch
685 { .name
= "sw1", .gpio
= 1 << 4 },
686 { .name
= "sw2", .gpio
= 1 << 5 },
687 { .name
= "sw3", .gpio
= 1 << 6 },
690 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
},
691 { .name
= "wlan", .gpio
= 1 << 7, .polarity
= NORMAL
},
692 // gpio3 forces WAN and LAN1-4 all on
693 //{ .name = "eth", .gpio = 1 << 3, .polarity = REVERSE },
697 .name
= "ASUS RT-N16",
699 { .name
= "reset", .gpio
= 1 << 8 },
700 { .name
= "ses", .gpio
= 1 << 5 },
703 { .name
= "power", .gpio
= 1 << 1, .polarity
= REVERSE
},
704 { .name
= "wlan", .gpio
= 1 << 7, .polarity
= NORMAL
},
708 .name
= "ASUS RT-N66U",
710 { .name
= "reset", .gpio
= 1 << 9 },
711 { .name
= "wps", .gpio
= 1 << 4 },
714 { .name
= "power", .gpio
= 1 << 12, .polarity
= REVERSE
},
715 { .name
= "usb", .gpio
= 1 << 15, .polarity
= REVERSE
},
720 .name
= "Buffalo WHR-G54S",
722 { .name
= "reset", .gpio
= 1 << 4 },
723 { .name
= "bridge", .gpio
= 1 << 5 },
724 { .name
= "ses", .gpio
= 1 << 0 },
727 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
728 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
729 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
730 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
731 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
735 .name
= "Buffalo WBR2-G54",
738 { .name
= "reset", .gpio
= 1 << 7 },
741 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
745 .name
= "Buffalo WHR-HP-G54",
747 { .name
= "reset", .gpio
= 1 << 4 },
748 { .name
= "bridge", .gpio
= 1 << 5 },
749 { .name
= "ses", .gpio
= 1 << 0 },
752 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
753 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
754 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
755 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
756 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
760 .name
= "Buffalo WHR-G125",
762 { .name
= "reset", .gpio
= 1 << 4 },
763 { .name
= "bridge", .gpio
= 1 << 5 },
764 { .name
= "ses", .gpio
= 1 << 0 },
767 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
768 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
769 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
770 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
771 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
775 .name
= "Buffalo WHR2-A54G54",
777 { .name
= "reset", .gpio
= 1 << 4 },
780 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
784 .name
= "Buffalo WLA2-G54L",
787 { .name
= "reset", .gpio
= 1 << 7 },
790 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
794 .name
= "Buffalo WZR-G300N",
796 { .name
= "reset", .gpio
= 1 << 4 },
799 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
800 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
801 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
805 .name
= "Buffalo WZR-RS-G54",
807 { .name
= "ses", .gpio
= 1 << 0 },
808 { .name
= "reset", .gpio
= 1 << 4 },
811 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
812 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
813 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
817 .name
= "Buffalo WZR-RS-G54HP",
819 { .name
= "ses", .gpio
= 1 << 0 },
820 { .name
= "reset", .gpio
= 1 << 4 },
823 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
824 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
825 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
828 [BUFFALO_UNKNOWN_4710
] = {
829 .name
= "Buffalo (unknown, BCM4710)",
831 { .name
= "reset", .gpio
= 1 << 4 },
834 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
839 .name
= "Siemens SE505 V1",
841 /* No usable buttons */
844 // { .name = "power", .gpio = 1 << 0 .polarity = REVERSE }, // Usable when retrofitting D26 (?)
845 { .name
= "dmz", .gpio
= 1 << 4, .polarity
= REVERSE
}, // actual name WWW
846 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
850 .name
= "Siemens SE505 V2",
852 /* No usable buttons */
855 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
856 { .name
= "dmz", .gpio
= 1 << 0, .polarity
= REVERSE
}, // actual name WWW
857 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
862 .name
= "U.S. Robotics USR5461",
864 /* No usable buttons */
867 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
868 { .name
= "printer", .gpio
= 1 << 1, .polarity
= REVERSE
},
873 .name
= "Dell TrueMobile 2300",
875 { .name
= "reset", .gpio
= 1 << 0 },
878 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
879 { .name
= "power", .gpio
= 1 << 7, .polarity
= REVERSE
},
883 .name
= "Dell TrueMobile 2300 v2",
885 { .name
= "reset", .gpio
= 1 << 0 },
888 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
889 { .name
= "power", .gpio
= 1 << 7, .polarity
= REVERSE
},
894 .name
= "Motorola WE800G",
896 { .name
= "reset", .gpio
= 1 << 0 },
899 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
900 { .name
= "diag", .gpio
= 1 << 2, .polarity
= REVERSE
},
901 { .name
= "wlan_amber", .gpio
= 1 << 1, .polarity
= NORMAL
},
905 .name
= "Motorola WR850G V1",
907 { .name
= "reset", .gpio
= 1 << 0 },
910 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
911 { .name
= "diag", .gpio
= 1 << 3, .polarity
= REVERSE
},
912 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= NORMAL
},
913 { .name
= "wlan_red", .gpio
= 1 << 5, .polarity
= REVERSE
},
914 { .name
= "wlan_green", .gpio
= 1 << 7, .polarity
= REVERSE
},
918 .name
= "Motorola WR850G V2/V3",
920 { .name
= "reset", .gpio
= 1 << 5 },
923 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
924 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
925 { .name
= "wan", .gpio
= 1 << 6, .polarity
= INPUT
},
926 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
930 .name
= "Motorola WR850GP",
932 { .name
= "reset", .gpio
= 1 << 5 },
935 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
936 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
937 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= REVERSE
},
938 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
944 .name
= "Belkin (unknown)",
945 /* FIXME: verify & add detection */
947 { .name
= "reset", .gpio
= 1 << 7 },
950 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
},
951 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= NORMAL
},
952 { .name
= "connected", .gpio
= 1 << 0, .polarity
= NORMAL
},
956 .name
= "Belkin PlayMax F7D4301",
958 { .name
= "reset", .gpio
= 1 << 6 },
959 { .name
= "wps", .gpio
= 1 << 8 },
962 { .name
= "power", .gpio
= 1 << 11, .polarity
= REVERSE
},
963 { .name
= "wlan", .gpio
= 1 << 13, .polarity
= REVERSE
},
964 { .name
= "led0", .gpio
= 1 << 14, .polarity
= REVERSE
},
965 { .name
= "led1", .gpio
= 1 << 15, .polarity
= REVERSE
},
970 .name
= "Netgear WGT634U",
972 { .name
= "reset", .gpio
= 1 << 2 },
975 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
},
980 .name
= "Netgear WNR834B V1",
981 .buttons
= { /* TODO: add reset button and confirm LEDs - GPIO from dd-wrt */ },
983 { .name
= "power", .gpio
= 1 << 4, .polarity
= REVERSE
},
984 { .name
= "diag", .gpio
= 1 << 5, .polarity
= REVERSE
},
985 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
990 .name
= "Netgear WNR834B V2",
992 { .name
= "reset", .gpio
= 1 << 6 },
995 { .name
= "power", .gpio
= 1 << 2, .polarity
= NORMAL
},
996 { .name
= "diag", .gpio
= 1 << 3, .polarity
= NORMAL
},
997 { .name
= "connected", .gpio
= 1 << 7, .polarity
= NORMAL
},
1001 .name
= "Netgear WNDR3400 V1",
1003 /* nvram get gpio5=robo_reset */
1004 { .name
= "reset", .gpio
= 1 << 4 },
1005 { .name
= "wps", .gpio
= 1 << 6 },
1006 { .name
= "wlan", .gpio
= 1 << 8 },
1009 { .name
= "wlan", .gpio
= 0 << 0, .polarity
= NORMAL
},
1010 { .name
= "connected", .gpio
= 1 << 0, .polarity
= NORMAL
},
1011 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
},
1012 { .name
= "diag", .gpio
= 1 << 7, .polarity
= NORMAL
},
1013 { .name
= "usb", .gpio
= 1 << 2, .polarity
= REVERSE
},
1017 .name
= "Netgear WNDR3700 V3",
1019 /* { .name = "usb", .gpio = 1 << 1 }, */ /* this button doesn't seem to exist. */
1020 { .name
= "wlan", .gpio
= 1 << 2 },
1021 { .name
= "reset", .gpio
= 1 << 3 },
1022 { .name
= "wps", .gpio
= 1 << 4 },
1023 /* { .name = "switch", .gpio = 1 << 5 },*/ /* nvram get gpio5=robo_reset */
1026 { .name
= "power", .gpio
= (1 << 0) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1027 { .name
= "diag", .gpio
= (1 << 1) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1028 /* WAN LED doesn't respond to GPIO control. The switch is probably driving it.
1029 * { .name = "wan", .gpio = (1 << 2) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1031 { .name
= "wlan2g", .gpio
= (1 << 3) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1032 { .name
= "wlan5g", .gpio
= (1 << 4) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1033 { .name
= "usb", .gpio
= (1 << 5) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1034 { .name
= "wps", .gpio
= (1 << 6) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1035 { .name
= "wlan", .gpio
= (1 << 7) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1040 .name
= "Trendware TEW411BRP+",
1042 { /* No usable buttons */ },
1045 { .name
= "power", .gpio
= 1 << 7, .polarity
= NORMAL
},
1046 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
},
1047 { .name
= "bridge", .gpio
= 1 << 6, .polarity
= NORMAL
},
1052 .name
= "SimpleTech SimpleShare NAS",
1054 { .name
= "reset", .gpio
= 1 << 0 }, // Power button on back, named reset to enable failsafe.
1057 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
1059 .platform_init
= bcm4780_init
,
1063 .name
= "D-Link DIR-130",
1065 { .name
= "reset", .gpio
= 1 << 3},
1066 { .name
= "reserved", .gpio
= 1 << 7},
1069 { .name
= "diag", .gpio
= 1 << 0},
1070 { .name
= "blue", .gpio
= 1 << 6},
1074 .name
= "D-Link DIR-320",
1076 { .name
= "reserved", .gpio
= 1 << 6},
1077 { .name
= "reset", .gpio
= 1 << 7},
1080 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
1081 { .name
= "diag", .gpio
= 1 << 1, .polarity
= NORMAL
}, /* "status led */
1082 { .name
= "red", .gpio
= 1 << 3, .polarity
= REVERSE
},
1083 { .name
= "blue", .gpio
= 1 << 4, .polarity
= REVERSE
},
1084 { .name
= "usb", .gpio
= 1 << 5, .polarity
= NORMAL
},
1088 .name
= "D-Link DIR-330",
1090 { .name
= "reset", .gpio
= 1 << 3},
1091 { .name
= "reserved", .gpio
= 1 << 7},
1094 { .name
= "diag", .gpio
= 1 << 0},
1095 { .name
= "usb", .gpio
= 1 << 4},
1096 { .name
= "blue", .gpio
= 1 << 6},
1100 .name
= "D-Link DWL-3150",
1102 { .name
= "reset", .gpio
= 1 << 7},
1105 { .name
= "diag", .gpio
= 1 << 2},
1106 { .name
= "status", .gpio
= 1 << 1},
1111 .name
= "Sitecom WL-105b",
1113 { .name
= "reset", .gpio
= 1 << 10},
1116 { .name
= "wlan", .gpio
= 1 << 4},
1117 { .name
= "power", .gpio
= 1 << 3},
1120 /* Western Digital Net Center */
1122 .name
= "Western Digital NetCenter",
1124 { .name
= "power", .gpio
= 1 << 0},
1125 { .name
= "reset", .gpio
= 1 << 7},
1127 .platform_init
= NetCenter_init
,
1129 /* Askey (and clones) */
1131 .name
= "Askey RT210W",
1133 /* Power button is hard-wired to hardware reset */
1134 /* but is also connected to GPIO 7 (probably for bootloader recovery) */
1135 { .name
= "power", .gpio
= 1 << 7},
1138 /* These were verified and named based on Belkin F5D4230-4 v1112 */
1139 { .name
= "connected", .gpio
= 1 << 0, .polarity
= REVERSE
},
1140 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
1141 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
1145 .name
= "OvisLink WL-1600GL",
1147 { .name
= "reset", .gpio
= 1 << 3 },
1148 { .name
= "ses", .gpio
= 1 << 4 },
1151 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
1152 { .name
= "wps", .gpio
= 1 << 2, .polarity
= REVERSE
},
1153 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
1154 { .name
= "connected", .gpio
= 1 << 0, .polarity
= REVERSE
},
1159 .name
= "Microsoft MN-700",
1161 { .name
= "reset", .gpio
= 1 << 7 },
1164 { .name
= "power", .gpio
= 1 << 6, .polarity
= NORMAL
},
1169 .name
= "Edimax PS-1208MFG",
1171 { .name
= "reset", .gpio
= 1 << 4 },
1174 { .name
= "status", .gpio
= 1 << 1, .polarity
= NORMAL
},
1175 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
1180 .name
= "Huawei E970",
1182 { .name
= "reset", .gpio
= 1 << 6 },
1185 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
1190 static struct platform_t __init
*platform_detect_legacy(void)
1192 char *boardnum
, *boardtype
;
1194 if (strcmp(getvar("nvram_type"), "cfe") == 0)
1195 return &platforms
[WGT634U
];
1198 /* no easy model number, attempt to guess */
1199 boardnum
= getvar("boardnum");
1200 boardtype
= getvar("boardtype");
1202 if (!strcmp(boardnum
, "20070615")) { /* Linksys WRT600N v1/V1.1 */
1203 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "0") && !strcmp(getvar("switch_type"),"BCM5395"))
1204 return &platforms
[WRT600NV11
];
1206 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "0"))
1207 return &platforms
[WRT600N
];
1210 if (startswith(getvar("pmon_ver"), "CFE")) {
1211 /* CFE based - newer hardware */
1212 if (!strcmp(boardnum
, "42")) { /* Linksys */
1213 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "1"))
1214 return &platforms
[WRT350N
];
1216 if (!strcmp(boardtype
, "0x0101") && !strcmp(getvar("boot_ver"), "v3.6"))
1217 return &platforms
[WRT54G3G
];
1219 /* default to WRT54G if no boot_hw_model is set */
1220 if (nvram_get("boot_hw_model") == NULL
)
1221 return &platforms
[WRT54G
];
1223 if (!strcmp(boardnum
, "1024") && !strcmp(boardtype
, "0x0446"))
1224 return &platforms
[WAP54GV2
];
1226 if (!strcmp(boardnum
, "8") && !strcmp(boardtype
, "0x048e"))
1227 return &platforms
[WL1600GL
];
1230 if (!strcmp(boardnum
, "44") || !strcmp(boardnum
, "44\r")) {
1231 if (!strcmp(boardtype
,"0x0101") || !strcmp(boardtype
, "0x0101\r"))
1232 return &platforms
[TM2300V2
]; /* Dell TrueMobile 2300 v2 */
1235 if (!strcmp(boardnum
, "10496"))
1236 return &platforms
[USR5461
];
1238 if (!strcmp(getvar("boardtype"), "0x0101") && !strcmp(getvar("boardrev"), "0x10")) /* SE505V2 With Modified CFE */
1239 return &platforms
[SE505V2
];
1241 if (!strcmp(boardtype
, "0x048e") && !strcmp(getvar("boardrev"),"0x35") &&
1242 !strcmp(getvar("boardflags"), "0x750")) /* D-Link DIR-320 */
1243 return &platforms
[DIR320
];
1245 if (!strncmp(boardnum
, "TH",2) && !strcmp(boardtype
,"0x042f")) {
1246 return &platforms
[WDNetCenter
];
1249 if (!strcmp(boardtype
,"0x0472") && !strcmp(getvar("cardbus"), "1")) { /* Netgear WNR834B V1 and V2*/
1250 if (!strcmp(boardnum
, "08") || !strcmp(boardnum
, "8"))
1251 return &platforms
[WNR834BV1
];
1252 if (!strcmp(boardnum
, "01") || !strcmp(boardnum
, "1"))
1253 return &platforms
[WNR834BV2
];
1256 } else { /* PMON based - old stuff */
1257 if ((simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 9) &&
1258 (simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 30)) {
1259 return &platforms
[WR850GV1
];
1261 if (startswith(boardtype
, "bcm94710dev")) {
1262 if (!strcmp(boardnum
, "42"))
1263 return &platforms
[WRT54GV1
];
1264 if (simple_strtoul(boardnum
, NULL
, 0) == 2)
1265 return &platforms
[WAP54GV1
];
1267 /* MN-700 has also hardware_version 'WL500-...', so use boardnum */
1268 if (startswith(getvar("hardware_version"), "WL500-")) {
1269 if (!strcmp(getvar("boardnum"), "mn700"))
1270 return &platforms
[MN700
];
1272 return &platforms
[WL500G
];
1274 /* Sitecom WL-105b */
1275 if (startswith(boardnum
, "2") && simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 1)
1276 return &platforms
[WL105B
];
1278 /* unknown asus stuff, probably bcm4702 */
1279 if (startswith(boardnum
, "asusX"))
1280 return &platforms
[ASUS_4702
];
1282 /* bcm4702 based Askey RT210W clones, Including:
1283 * Askey RT210W (duh?)
1285 * Belkin F5D7230-4 before version v1444 (MiniPCI slot, not integrated)
1287 if (!strcmp(boardtype
,"bcm94710r4")
1288 && !strcmp(boardnum
,"100")
1289 && !strcmp(getvar("pmon_ver"),"v1.03.12.bk")
1291 return &platforms
[RT210W
];
1295 if (boardnum
|| !strcmp(boardnum
, "00")) {/* probably buffalo */
1296 if (startswith(boardtype
, "bcm94710ap"))
1297 return &platforms
[BUFFALO_UNKNOWN_4710
];
1300 if (startswith(getvar("CFEver"), "MotoWRv2") ||
1301 startswith(getvar("CFEver"), "MotoWRv3") ||
1302 !strcmp(getvar("MOTO_BOARD_TYPE"), "WR_FEM1")) {
1304 return &platforms
[WR850GV2V3
];
1307 if (!strcmp(boardnum
, "44") && !strcmp(getvar("boardflags"),"0x0388")) { /* Trendware TEW-411BRP+ */
1308 return &platforms
[TEW411BRPP
];
1311 if (startswith(boardnum
, "04FN")) /* SimpleTech SimpleShare */
1312 return &platforms
[STI_NAS
];
1314 if (!strcmp(boardnum
, "10") && !strcmp(getvar("boardrev"), "0x13")) /* D-Link DWL-3150 */
1315 return &platforms
[DWL3150
];
1317 if (!strcmp(boardnum
, "01") && !strcmp(boardtype
, "0x048e") && /* Edimax PS1208MFG */
1318 !strcmp(getvar("status_gpio"), "1")) /* gpio based detection */
1319 return &platforms
[PS1208MFG
];
1325 static struct platform_t __init
*platform_detect(void)
1327 enum bcm47xx_board board
;
1328 const char *board_name
;
1331 board
= bcm47xx_board_get();
1332 board_name
= bcm47xx_board_get_name();
1333 if (board
!= BCM47XX_BOARD_UNKNOWN
&& board
!= BCM47XX_BOARD_NON
)
1334 printk(MODULE_NAME
": kernel found a \"%s\"\n", board_name
);
1337 case BCM47XX_BOARD_ASUS_RTN12
:
1338 return &platforms
[RTN12
];
1339 case BCM47XX_BOARD_ASUS_RTN16
:
1340 return &platforms
[RTN16
];
1341 case BCM47XX_BOARD_ASUS_RTN66U
:
1342 return &platforms
[RTN66U
];
1343 case BCM47XX_BOARD_ASUS_WL300G
:
1344 return &platforms
[WL300G
];
1345 case BCM47XX_BOARD_ASUS_WL320GE
:
1346 return &platforms
[WL320GE
];
1347 case BCM47XX_BOARD_ASUS_WL330GE
:
1348 return &platforms
[WL330GE
];
1349 case BCM47XX_BOARD_ASUS_WL500GD
:
1350 return &platforms
[WL500GD
];
1351 case BCM47XX_BOARD_ASUS_WL500GPV1
:
1352 return &platforms
[WL500GP
];
1353 case BCM47XX_BOARD_ASUS_WL500GPV2
:
1354 return &platforms
[WL500GPV2
];
1355 case BCM47XX_BOARD_ASUS_WL500W
:
1356 return &platforms
[WL500W
];
1357 case BCM47XX_BOARD_ASUS_WL520GC
:
1358 return &platforms
[WL520GC
];
1359 case BCM47XX_BOARD_ASUS_WL520GU
:
1360 return &platforms
[WL520GU
];
1361 case BCM47XX_BOARD_ASUS_WL700GE
:
1362 return &platforms
[WL700GE
];
1363 case BCM47XX_BOARD_ASUS_WLHDD
:
1364 return &platforms
[WLHDD
];
1365 case BCM47XX_BOARD_BELKIN_F7D4301
:
1366 return &platforms
[BELKIN_F7D4301
];
1367 case BCM47XX_BOARD_BUFFALO_WBR2_G54
:
1368 return &platforms
[WBR2_G54
];
1369 case BCM47XX_BOARD_BUFFALO_WHR2_A54G54
:
1370 return &platforms
[WHR2_A54G54
];
1371 case BCM47XX_BOARD_BUFFALO_WHR_G125
:
1372 return &platforms
[WHR_G125
];
1373 case BCM47XX_BOARD_BUFFALO_WHR_G54S
:
1374 return &platforms
[WHR_G54S
];
1375 case BCM47XX_BOARD_BUFFALO_WHR_HP_G54
:
1376 return &platforms
[WHR_HP_G54
];
1377 case BCM47XX_BOARD_BUFFALO_WLA2_G54L
:
1378 return &platforms
[WLA2_G54L
];
1379 case BCM47XX_BOARD_BUFFALO_WZR_G300N
:
1380 return &platforms
[WZR_G300N
];
1381 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54
:
1382 return &platforms
[WZR_RS_G54
];
1383 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54HP
:
1384 return &platforms
[WZR_RS_G54HP
];
1385 case BCM47XX_BOARD_DELL_TM2300
:
1386 return &platforms
[TM2300
];
1387 case BCM47XX_BOARD_DLINK_DIR130
:
1388 return &platforms
[DIR130
];
1389 case BCM47XX_BOARD_DLINK_DIR330
:
1390 return &platforms
[DIR330
];
1391 case BCM47XX_BOARD_HUAWEI_E970
:
1392 return &platforms
[HUAWEI_E970
];
1393 case BCM47XX_BOARD_LINKSYS_E1000V1
:
1394 return &platforms
[E1000V1
];
1395 case BCM47XX_BOARD_LINKSYS_E1000V21
:
1396 return &platforms
[E1000V21
];
1397 case BCM47XX_BOARD_LINKSYS_E3000V1
:
1398 return &platforms
[E3000V1
];
1399 case BCM47XX_BOARD_LINKSYS_E3200V1
:
1400 return &platforms
[E3200V1
];
1401 case BCM47XX_BOARD_LINKSYS_E4200V1
:
1402 return &platforms
[E4200V1
];
1403 case BCM47XX_BOARD_LINKSYS_WRT150NV1
:
1404 return &platforms
[WRT150NV1
];
1405 case BCM47XX_BOARD_LINKSYS_WRT150NV11
:
1406 return &platforms
[WRT150NV11
];
1407 case BCM47XX_BOARD_LINKSYS_WRT160NV1
:
1408 return &platforms
[WRT160NV1
];
1409 case BCM47XX_BOARD_LINKSYS_WRT160NV3
:
1410 return &platforms
[WRT160NV3
];
1411 case BCM47XX_BOARD_LINKSYS_WRT300NV11
:
1412 return &platforms
[WRT300NV11
];
1413 case BCM47XX_BOARD_LINKSYS_WRT310NV1
:
1414 return &platforms
[WRT310NV1
];
1415 case BCM47XX_BOARD_LINKSYS_WRT54G3GV2
:
1416 return &platforms
[WRT54G3GV2_VF
];
1417 case BCM47XX_BOARD_LINKSYS_WRT610NV1
:
1418 return &platforms
[WRT610N
];
1419 case BCM47XX_BOARD_LINKSYS_WRT610NV2
:
1420 return &platforms
[WRT610NV2
];
1421 case BCM47XX_BOARD_LINKSYS_WRTSL54GS
:
1422 return &platforms
[WRTSL54GS
];
1423 case BCM47XX_BOARD_MOTOROLA_WE800G
:
1424 return &platforms
[WE800G
];
1425 case BCM47XX_BOARD_MOTOROLA_WR850GP
:
1426 return &platforms
[WR850GP
];
1427 case BCM47XX_BOARD_MOTOROLA_WR850GV2V3
:
1428 return &platforms
[WR850GV2V3
];
1429 case BCM47XX_BOARD_NETGEAR_WNDR3400V1
:
1430 return &platforms
[WNDR3400V1
];
1431 case BCM47XX_BOARD_NETGEAR_WNDR3700V3
:
1432 return &platforms
[WNDR3700V3
];
1433 case BCM47XX_BOARD_UNKNOWN
:
1434 case BCM47XX_BOARD_NON
:
1435 printk(MODULE_NAME
": unknown board found, try legacy detect\n");
1436 printk(MODULE_NAME
": please open a ticket at https://dev.openwrt.org and attach the complete nvram\n");
1437 return platform_detect_legacy();
1439 printk(MODULE_NAME
": board was detected as \"%s\", but not gpio configuration available\n", board_name
);
1440 printk(MODULE_NAME
": now trying legacy detect\n");
1441 return platform_detect_legacy();
1445 static inline void ssb_maskset32(struct ssb_device
*dev
,
1446 u16 offset
, u32 mask
, u32 set
)
1448 ssb_write32(dev
, offset
, (ssb_read32(dev
, offset
) & mask
) | set
);
1451 static void gpio_set_irqenable(int enabled
, irqreturn_t (*handler
)(int, void *))
1456 irq
= gpio_to_irq(0);
1458 pr_err("no irq for gpio available\n");
1463 err
= request_irq(irq
, handler
, IRQF_SHARED
, "gpio", handler
);
1465 pr_err("can not reqeust irq\n");
1469 free_irq(irq
, handler
);
1472 switch (bcm47xx_bus_type
) {
1473 #ifdef CONFIG_BCM47XX_SSB
1474 case BCM47XX_BUS_TYPE_SSB
:
1475 if (bcm47xx_bus
.ssb
.chipco
.dev
)
1476 ssb_maskset32(bcm47xx_bus
.ssb
.chipco
.dev
, SSB_CHIPCO_IRQMASK
, ~SSB_CHIPCO_IRQ_GPIO
, (enabled
? SSB_CHIPCO_IRQ_GPIO
: 0));
1479 #ifdef CONFIG_BCM47XX_BCMA
1480 case BCM47XX_BUS_TYPE_BCMA
:
1481 if (bcm47xx_bus
.bcma
.bus
.drv_cc
.core
)
1482 bcma_maskset32(bcm47xx_bus
.bcma
.bus
.drv_cc
.core
, BCMA_CC_IRQMASK
, ~BCMA_CC_IRQ_GPIO
, (enabled
? BCMA_CC_IRQ_GPIO
: 0));
1488 static void hotplug_button(struct work_struct
*work
)
1490 struct event_t
*event
= container_of(work
, struct event_t
, wq
);
1493 event
->skb
= alloc_skb(2048, GFP_KERNEL
);
1495 s
= skb_put(event
->skb
, strlen(event
->action
) + 2);
1496 sprintf(s
, "%s@", event
->action
);
1499 NETLINK_CB(event
->skb
).dst_group
= 1;
1500 broadcast_uevent(event
->skb
, 0, 1, GFP_KERNEL
);
1505 static irqreturn_t
button_handler(int irq
, void *dev_id
)
1510 in
= bcm47xx_gpio_in(~0) & platform
.button_mask
;
1511 bcm47xx_gpio_polarity(platform
.button_mask
, in
);
1512 changed
= platform
.button_polarity
^ in
;
1513 platform
.button_polarity
= in
;
1515 changed
&= ~bcm47xx_gpio_outen(0, 0);
1517 for (b
= platform
.buttons
; b
->name
; b
++) {
1518 struct event_t
*event
;
1520 if (!(b
->gpio
& changed
)) continue;
1524 if ((event
= (struct event_t
*)kzalloc (sizeof(struct event_t
), GFP_ATOMIC
))) {
1525 event
->seen
= (jiffies
- b
->seen
)/HZ
;
1526 event
->name
= b
->name
;
1527 event
->action
= b
->pressed
? "pressed" : "released";
1528 INIT_WORK(&event
->wq
, (void *)(void *)hotplug_button
);
1529 schedule_work(&event
->wq
);
1537 static void register_buttons(struct button_t
*b
)
1539 for (; b
->name
; b
++)
1540 platform
.button_mask
|= b
->gpio
;
1542 platform
.button_mask
&= ~gpiomask
;
1544 bcm47xx_gpio_outen(platform
.button_mask
, 0);
1545 bcm47xx_gpio_control(platform
.button_mask
, 0);
1546 platform
.button_polarity
= bcm47xx_gpio_in(~0) & platform
.button_mask
;
1547 bcm47xx_gpio_polarity(platform
.button_mask
, platform
.button_polarity
);
1548 bcm47xx_gpio_intmask(platform
.button_mask
, platform
.button_mask
);
1550 gpio_set_irqenable(1, button_handler
);
1553 static void unregister_buttons(struct button_t
*b
)
1555 bcm47xx_gpio_intmask(platform
.button_mask
, 0);
1557 gpio_set_irqenable(0, button_handler
);
1561 static void add_msg(struct event_t
*event
, char *msg
, int argv
)
1568 s
= skb_put(event
->skb
, strlen(msg
) + 1);
1572 static int fill_event (struct event_t
*event
)
1574 static char buf
[128];
1576 add_msg(event
, "HOME=/", 0);
1577 add_msg(event
, "PATH=/sbin:/bin:/usr/sbin:/usr/bin", 0);
1578 add_msg(event
, "SUBSYSTEM=button", 0);
1579 snprintf(buf
, 128, "ACTION=%s", event
->action
);
1580 add_msg(event
, buf
, 0);
1581 snprintf(buf
, 128, "BUTTON=%s", event
->name
);
1582 add_msg(event
, buf
, 0);
1583 snprintf(buf
, 128, "SEEN=%ld", event
->seen
);
1584 add_msg(event
, buf
, 0);
1585 snprintf(buf
, 128, "SEQNUM=%llu", uevent_next_seqnum());
1586 add_msg(event
, buf
, 0);
1592 * This should be extended to allow the platform to specify the pins and width
1593 * of the shift register. They're hardcoded for now because only the WNDR3700v3
1596 static void shiftreg_output(unsigned int val
)
1600 bcm47xx_gpio_out(SHIFTREG_DATA
, SHIFTREG_DATA
); /* init off, pull high */
1601 bcm47xx_gpio_out(SHIFTREG_CLK
, 0); /* init reset */
1604 for(mask
= 1 << (SHIFTREG_MAX_BITS
-1); mask
; mask
>>= 1)
1606 bcm47xx_gpio_out(SHIFTREG_DATA
, (val
& mask
) ? SHIFTREG_DATA
: 0);
1607 bcm47xx_gpio_out(SHIFTREG_CLK
, SHIFTREG_CLK
); /* pull high to trigger */
1608 bcm47xx_gpio_out(SHIFTREG_CLK
, 0); /* reset to low */
1612 static void set_led_shift(struct led_t
*led
)
1614 static u32 shiftreg
= 0;
1616 u32 pin
= (led
->gpio
& ~GPIO_TYPE_MASK
);
1624 /* Clock the bits out. */
1625 if (shiftreg
!= old
) {
1626 shiftreg_output(shiftreg
);
1630 static void set_led_extif(struct led_t
*led
)
1632 volatile u8
*addr
= (volatile u8
*) KSEG1ADDR(EXTIF_UART
) + (led
->gpio
& ~GPIO_TYPE_MASK
);
1640 static void led_flash(unsigned long dummy
) {
1645 for (l
= platform
.leds
; l
->name
; l
++) {
1646 if (!l
->flash
) continue;
1647 switch (l
->gpio
& GPIO_TYPE_MASK
) {
1648 case GPIO_TYPE_EXTIF
:
1650 l
->state
= !l
->state
;
1653 case GPIO_TYPE_SHIFT
:
1655 l
->state
= !l
->state
;
1658 case GPIO_TYPE_NORMAL
:
1667 u32 val
= ~bcm47xx_gpio_in(~0);
1669 bcm47xx_gpio_outen(mask
, mask
);
1670 bcm47xx_gpio_control(mask
, 0);
1671 bcm47xx_gpio_out(mask
, val
);
1673 if (mask
|| extif_blink
) {
1674 mod_timer(&led_timer
, jiffies
+ FLASH_TIME
);
1678 static int diag_led_show(struct seq_file
*m
, void *v
)
1680 struct led_t
* led
= m
->private;
1682 u8 p
= (led
->polarity
== NORMAL
? 0 : 1);
1684 return seq_printf(m
, "f\n");
1685 } else if ((led
->gpio
& GPIO_TYPE_MASK
) != GPIO_TYPE_NORMAL
) {
1686 return seq_printf(m
, "%d\n", ((led
->state
^ p
) ? 1 : 0));
1688 u32 in
= (bcm47xx_gpio_in(~0) & led
->gpio
? 1 : 0);
1689 return seq_printf(m
, "%d\n", ((in
^ p
) ? 1 : 0));
1693 static int diag_led_open(struct inode
*inode
, struct file
*file
)
1695 return single_open(file
, diag_led_show
, PDE_DATA(inode
));
1698 static ssize_t
diag_led_write(struct file
*file
, const char __user
*buf
, size_t count
, loff_t
*ppos
)
1700 struct led_t
*led
= PDE_DATA(file_inode(file
));
1705 len
= min(count
, sizeof(cmd
) - 1);
1706 if (copy_from_user(cmd
, buf
, len
))
1711 p
= (led
->polarity
== NORMAL
? 0 : 1);
1712 if (cmd
[0] == 'f') {
1717 if ((led
->gpio
& GPIO_TYPE_MASK
) == GPIO_TYPE_EXTIF
) {
1718 led
->state
= p
^ ((cmd
[0] == '1') ? 1 : 0);
1720 } else if ((led
->gpio
& GPIO_TYPE_MASK
) == GPIO_TYPE_SHIFT
) {
1721 led
->state
= p
^ ((cmd
[0] == '1') ? 1 : 0);
1724 bcm47xx_gpio_outen(led
->gpio
, led
->gpio
);
1725 bcm47xx_gpio_control(led
->gpio
, 0);
1726 bcm47xx_gpio_out(led
->gpio
, ((p
^ (cmd
[0] == '1')) ? led
->gpio
: 0));
1732 static const struct file_operations diag_led_fops
= {
1733 .open
= diag_led_open
,
1735 .llseek
= seq_lseek
,
1736 .write
= diag_led_write
1739 static void register_leds(struct led_t
*l
)
1741 struct proc_dir_entry
*p
;
1746 leds
= proc_mkdir("led", diag
);
1750 for(; l
->name
; l
++) {
1751 if (l
->gpio
& gpiomask
)
1754 switch (l
->gpio
& GPIO_TYPE_MASK
) {
1755 case GPIO_TYPE_EXTIF
:
1759 case GPIO_TYPE_SHIFT
:
1760 mask
|= (SHIFTREG_DATA
| SHIFTREG_CLK
);
1761 oe_mask
|= (SHIFTREG_DATA
| SHIFTREG_CLK
);
1762 l
->state
= (l
->polarity
!= NORMAL
);
1765 case GPIO_TYPE_NORMAL
:
1767 if (l
->polarity
!= INPUT
) oe_mask
|= l
->gpio
;
1769 val
|= (l
->polarity
== NORMAL
)?0:l
->gpio
;
1773 if (l
->polarity
== INPUT
) continue;
1775 p
= proc_create_data(l
->name
, S_IRUSR
, leds
, &diag_led_fops
, l
);
1778 bcm47xx_gpio_outen(mask
, oe_mask
);
1779 bcm47xx_gpio_control(mask
, 0);
1780 bcm47xx_gpio_out(mask
, val
);
1781 bcm47xx_gpio_intmask(mask
, 0);
1784 static void unregister_leds(struct led_t
*l
)
1787 remove_proc_entry(l
->name
, leds
);
1789 remove_proc_entry("led", diag
);
1792 static int diag_model_show(struct seq_file
*m
, void *v
)
1794 return seq_printf(m
, "%s\n", platform
.name
);
1797 static int diag_model_open(struct inode
*inode
, struct file
*file
)
1799 return single_open(file
, diag_model_show
, PDE_DATA(inode
));
1802 static const struct file_operations diag_model_fops
= {
1803 .open
= diag_model_open
,
1808 static int diag_gpiomask_show(struct seq_file
*m
, void *v
)
1810 return seq_printf(m
, "0x%04x\n", gpiomask
);
1813 static int diag_gpiomask_open(struct inode
*inode
, struct file
*file
)
1815 return single_open(file
, diag_gpiomask_show
, PDE_DATA(inode
));
1818 static ssize_t
diag_gpiomask_write(struct file
*file
, const char __user
*buf
, size_t count
, loff_t
*ppos
)
1820 int err
= kstrtouint_from_user(buf
, count
, 0, &gpiomask
);
1824 if (platform
.buttons
) {
1825 unregister_buttons(platform
.buttons
);
1826 register_buttons(platform
.buttons
);
1829 if (platform
.leds
) {
1830 unregister_leds(platform
.leds
);
1831 register_leds(platform
.leds
);
1837 static const struct file_operations diag_gpiomask_fops
= {
1838 .open
= diag_gpiomask_open
,
1840 .llseek
= seq_lseek
,
1841 .write
= diag_gpiomask_write
1844 static int __init
diag_init(void)
1846 static struct proc_dir_entry
*p
;
1847 static struct platform_t
*detected
;
1849 detected
= platform_detect();
1851 printk(MODULE_NAME
": Router model not detected.\n");
1854 memcpy(&platform
, detected
, sizeof(struct platform_t
));
1856 printk(MODULE_NAME
": Detected '%s'\n", platform
.name
);
1857 if (platform
.platform_init
!= NULL
) {
1858 platform
.platform_init();
1861 if (!(diag
= proc_mkdir("diag", NULL
))) {
1862 printk(MODULE_NAME
": proc_mkdir on /proc/diag failed\n");
1866 p
= proc_create("model", S_IRUSR
, diag
, &diag_model_fops
);
1868 remove_proc_entry("diag", NULL
);
1872 p
= proc_create("gpiomask", S_IRUSR
| S_IWUSR
, diag
, &diag_gpiomask_fops
);
1874 remove_proc_entry("model", diag
);
1875 remove_proc_entry("diag", NULL
);
1879 if (platform
.buttons
)
1880 register_buttons(platform
.buttons
);
1883 register_leds(platform
.leds
);
1888 static void __exit
diag_exit(void)
1890 del_timer(&led_timer
);
1892 if (platform
.buttons
)
1893 unregister_buttons(platform
.buttons
);
1896 unregister_leds(platform
.leds
);
1898 remove_proc_entry("model", diag
);
1899 remove_proc_entry("gpiomask", diag
);
1900 remove_proc_entry("diag", NULL
);
1903 module_init(diag_init
);
1904 module_exit(diag_exit
);
1906 MODULE_AUTHOR("Mike Baker, Felix Fietkau / OpenWrt.org");
1907 MODULE_LICENSE("GPL");