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
;
127 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 E2000 V1",
507 { .name
= "reset", .gpio
= 1 << 8 },
508 { .name
= "ses", .gpio
= 1 << 5 },
511 { .name
= "power", .gpio
= 1 << 2, .polarity
= NORMAL
},
512 { .name
= "ses_amber", .gpio
= 1 << 4, .polarity
= REVERSE
},
513 { .name
= "ses_blue", .gpio
= 1 << 3, .polarity
= REVERSE
},
514 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
},
518 .name
= "Linksys E3000 V1",
520 { .name
= "reset", .gpio
= 1 << 6 },
521 { .name
= "ses", .gpio
= 1 << 4 },
524 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
}, // Power LED
525 { .name
= "usb", .gpio
= 1 << 7, .polarity
= NORMAL
}, // USB LED
526 { .name
= "ses_amber", .gpio
= 1 << 0, .polarity
= REVERSE
}, // WiFi protected setup LED amber
527 { .name
= "ses_blue", .gpio
= 1 << 3, .polarity
= REVERSE
}, // WiFi protected setup LED blue
528 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
}, // Wireless LED
532 .name
= "Linksys E3200 V1",
534 /* { .name = "switch", .gpio = 1 << 4 },*/ /* nvram get gpio4=robo_reset */
535 { .name
= "reset", .gpio
= 1 << 5 }, /* nvram get reset_gpio=5 */
536 { .name
= "wps", .gpio
= 1 << 8 }, /* nvram get gpio8=wps_button */
537 /* { .name = "wombo", .gpio = 1 << 23 },*/ /* nvram get gpio23=wombo_reset - wireless on motherboard */
540 { .name
= "power", .gpio
= 1 << 3, .polarity
= REVERSE
}, /* Power LED */
544 .name
= "Linksys E4200 V1",
546 { .name
= "reset", .gpio
= 1 << 6 },
547 { .name
= "wps", .gpio
= 1 << 4 },
550 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
555 .name
= "ASUS WL-HDD",
557 { .name
= "reset", .gpio
= 1 << 6 },
560 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
561 { .name
= "usb", .gpio
= 1 << 2, .polarity
= REVERSE
},
565 .name
= "ASUS WL-300g",
567 { .name
= "reset", .gpio
= 1 << 6 },
570 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
574 .name
= "ASUS WL-320gE/WL-320gP",
576 { .name
= "reset", .gpio
= 1 << 6 },
579 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
580 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
},
581 { .name
= "link", .gpio
= 1 << 11, .polarity
= REVERSE
},
585 .name
= "ASUS WL-330gE",
587 { .name
= "reset", .gpio
= 1 << 2 },
590 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
594 .name
= "ASUS WL-500g",
596 { .name
= "reset", .gpio
= 1 << 6 },
599 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
603 .name
= "ASUS WL-500g Deluxe",
605 { .name
= "reset", .gpio
= 1 << 6 },
608 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
612 .name
= "ASUS WL-500g Premium",
614 { .name
= "reset", .gpio
= 1 << 0 },
615 { .name
= "ses", .gpio
= 1 << 4 },
618 { .name
= "power", .gpio
= 1 << 1, .polarity
= REVERSE
},
622 .name
= "ASUS WL-500g Premium V2",
624 { .name
= "reset", .gpio
= 1 << 2 },
625 { .name
= "ses", .gpio
= 1 << 3 },
628 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
629 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
633 .name
= "ASUS WL-500W",
635 { .name
= "reset", .gpio
= 1 << 6 },
636 { .name
= "ses", .gpio
= 1 << 7 },
639 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
643 .name
= "ASUS WL-520GC",
645 { .name
= "reset", .gpio
= 1 << 2 },
646 { .name
= "ses", .gpio
= 1 << 3 },
649 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
650 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
654 .name
= "ASUS WL-520gU",
656 { .name
= "reset", .gpio
= 1 << 2 },
657 { .name
= "ses", .gpio
= 1 << 3 },
660 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
661 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
665 .name
= "ASUS (unknown, BCM4702)",
667 { .name
= "reset", .gpio
= 1 << 6 },
670 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
674 .name
= "ASUS WL-700gE",
676 { .name
= "reset", .gpio
= 1 << 7 }, // on back, hardwired, always resets device regardless OS state
677 { .name
= "ses", .gpio
= 1 << 4 }, // on back, actual name ezsetup
678 { .name
= "power", .gpio
= 1 << 0 }, // on front
679 { .name
= "copy", .gpio
= 1 << 6 }, // on front
683 // GPIO that controls power led also enables/disables some essential functions
686 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
}, // actual name power
688 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
690 .platform_init
= bcm4780_init
,
693 .name
= "ASUS RT-N12",
695 { .name
= "wps", .gpio
= 1 << 0 },
696 { .name
= "reset", .gpio
= 1 << 1 },
697 // this is the router/repeater/ap switch
698 { .name
= "sw1", .gpio
= 1 << 4 },
699 { .name
= "sw2", .gpio
= 1 << 5 },
700 { .name
= "sw3", .gpio
= 1 << 6 },
703 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
},
704 { .name
= "wlan", .gpio
= 1 << 7, .polarity
= NORMAL
},
705 // gpio3 forces WAN and LAN1-4 all on
706 //{ .name = "eth", .gpio = 1 << 3, .polarity = REVERSE },
710 .name
= "ASUS RT-N16",
712 { .name
= "reset", .gpio
= 1 << 8 },
713 { .name
= "ses", .gpio
= 1 << 6 },
716 { .name
= "power", .gpio
= 1 << 1, .polarity
= REVERSE
},
717 { .name
= "wlan", .gpio
= 1 << 7, .polarity
= NORMAL
},
721 .name
= "ASUS RT-N66U",
723 { .name
= "reset", .gpio
= 1 << 9 },
724 { .name
= "wps", .gpio
= 1 << 4 },
727 { .name
= "power", .gpio
= 1 << 12, .polarity
= REVERSE
},
728 { .name
= "usb", .gpio
= 1 << 15, .polarity
= REVERSE
},
733 .name
= "Buffalo WHR-G54S",
735 { .name
= "reset", .gpio
= 1 << 4 },
736 { .name
= "bridge", .gpio
= 1 << 5 },
737 { .name
= "ses", .gpio
= 1 << 0 },
740 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
741 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
742 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
743 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
744 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
748 .name
= "Buffalo WBR2-G54",
751 { .name
= "reset", .gpio
= 1 << 7 },
754 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
758 .name
= "Buffalo WHR-HP-G54",
760 { .name
= "reset", .gpio
= 1 << 4 },
761 { .name
= "bridge", .gpio
= 1 << 5 },
762 { .name
= "ses", .gpio
= 1 << 0 },
765 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
766 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
767 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
768 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
769 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
773 .name
= "Buffalo WHR-G125",
775 { .name
= "reset", .gpio
= 1 << 4 },
776 { .name
= "bridge", .gpio
= 1 << 5 },
777 { .name
= "ses", .gpio
= 1 << 0 },
780 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
781 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
782 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
783 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
784 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
788 .name
= "Buffalo WHR2-A54G54",
790 { .name
= "reset", .gpio
= 1 << 4 },
793 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
797 .name
= "Buffalo WLA2-G54L",
800 { .name
= "reset", .gpio
= 1 << 7 },
803 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
807 .name
= "Buffalo WZR-G300N",
809 { .name
= "reset", .gpio
= 1 << 4 },
812 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
813 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
814 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
818 .name
= "Buffalo WZR-RS-G54",
820 { .name
= "ses", .gpio
= 1 << 0 },
821 { .name
= "reset", .gpio
= 1 << 4 },
824 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
825 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
826 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
830 .name
= "Buffalo WZR-RS-G54HP",
832 { .name
= "ses", .gpio
= 1 << 0 },
833 { .name
= "reset", .gpio
= 1 << 4 },
836 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
837 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
838 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
841 [BUFFALO_UNKNOWN_4710
] = {
842 .name
= "Buffalo (unknown, BCM4710)",
844 { .name
= "reset", .gpio
= 1 << 4 },
847 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
852 .name
= "Siemens SE505 V1",
854 /* No usable buttons */
857 // { .name = "power", .gpio = 1 << 0 .polarity = REVERSE }, // Usable when retrofitting D26 (?)
858 { .name
= "dmz", .gpio
= 1 << 4, .polarity
= REVERSE
}, // actual name WWW
859 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
863 .name
= "Siemens SE505 V2",
865 /* No usable buttons */
868 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
869 { .name
= "dmz", .gpio
= 1 << 0, .polarity
= REVERSE
}, // actual name WWW
870 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
875 .name
= "U.S. Robotics USR5461",
877 /* No usable buttons */
880 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
881 { .name
= "printer", .gpio
= 1 << 1, .polarity
= REVERSE
},
886 .name
= "Dell TrueMobile 2300",
888 { .name
= "reset", .gpio
= 1 << 0 },
891 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
892 { .name
= "power", .gpio
= 1 << 7, .polarity
= REVERSE
},
896 .name
= "Dell TrueMobile 2300 v2",
898 { .name
= "reset", .gpio
= 1 << 0 },
901 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
902 { .name
= "power", .gpio
= 1 << 7, .polarity
= REVERSE
},
907 .name
= "Motorola WE800G",
909 { .name
= "reset", .gpio
= 1 << 0 },
912 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
913 { .name
= "diag", .gpio
= 1 << 2, .polarity
= REVERSE
},
914 { .name
= "wlan_amber", .gpio
= 1 << 1, .polarity
= NORMAL
},
918 .name
= "Motorola WR850G V1",
920 { .name
= "reset", .gpio
= 1 << 0 },
923 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
924 { .name
= "diag", .gpio
= 1 << 3, .polarity
= REVERSE
},
925 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= NORMAL
},
926 { .name
= "wlan_red", .gpio
= 1 << 5, .polarity
= REVERSE
},
927 { .name
= "wlan_green", .gpio
= 1 << 7, .polarity
= REVERSE
},
931 .name
= "Motorola WR850G V2/V3",
933 { .name
= "reset", .gpio
= 1 << 5 },
936 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
937 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
938 { .name
= "wan", .gpio
= 1 << 6, .polarity
= INPUT
},
939 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
943 .name
= "Motorola WR850GP",
945 { .name
= "reset", .gpio
= 1 << 5 },
948 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
949 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
950 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= REVERSE
},
951 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
957 .name
= "Belkin PlayMax F7D4301",
959 { .name
= "reset", .gpio
= 1 << 6 },
960 { .name
= "wps", .gpio
= 1 << 8 },
963 { .name
= "power", .gpio
= 1 << 10, .polarity
= REVERSE
},
964 { .name
= "warn", .gpio
= 1 << 11, .polarity
= REVERSE
},
965 { .name
= "wps", .gpio
= 1 << 12, .polarity
= REVERSE
},
966 { .name
= "wlan", .gpio
= 1 << 13, .polarity
= REVERSE
},
967 { .name
= "usb0", .gpio
= 1 << 14, .polarity
= REVERSE
},
968 { .name
= "usb1", .gpio
= 1 << 15, .polarity
= REVERSE
},
973 .name
= "Netgear WGT634U",
975 { .name
= "reset", .gpio
= 1 << 2 },
978 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
},
983 .name
= "Netgear WNR834B V1",
984 .buttons
= { /* TODO: add reset button and confirm LEDs - GPIO from dd-wrt */ },
986 { .name
= "power", .gpio
= 1 << 4, .polarity
= REVERSE
},
987 { .name
= "diag", .gpio
= 1 << 5, .polarity
= REVERSE
},
988 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
993 .name
= "Netgear WNR834B V2",
995 { .name
= "reset", .gpio
= 1 << 6 },
998 { .name
= "power", .gpio
= 1 << 2, .polarity
= NORMAL
},
999 { .name
= "diag", .gpio
= 1 << 3, .polarity
= NORMAL
},
1000 { .name
= "connected", .gpio
= 1 << 7, .polarity
= NORMAL
},
1004 .name
= "Netgear WNDR3400 V1",
1006 /* nvram get gpio5=robo_reset */
1007 { .name
= "reset", .gpio
= 1 << 4 },
1008 { .name
= "wps", .gpio
= 1 << 6 },
1009 { .name
= "wlan", .gpio
= 1 << 8 },
1012 { .name
= "wlan", .gpio
= 0 << 0, .polarity
= NORMAL
},
1013 { .name
= "connected", .gpio
= 1 << 0, .polarity
= NORMAL
},
1014 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
},
1015 { .name
= "diag", .gpio
= 1 << 7, .polarity
= NORMAL
},
1016 { .name
= "usb", .gpio
= 1 << 2, .polarity
= REVERSE
},
1020 .name
= "Netgear WNDR3700 V3",
1022 /* { .name = "usb", .gpio = 1 << 1 }, */ /* this button doesn't seem to exist. */
1023 { .name
= "wlan", .gpio
= 1 << 2 },
1024 { .name
= "reset", .gpio
= 1 << 3 },
1025 { .name
= "wps", .gpio
= 1 << 4 },
1026 /* { .name = "switch", .gpio = 1 << 5 },*/ /* nvram get gpio5=robo_reset */
1029 { .name
= "power", .gpio
= (1 << 0) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1030 { .name
= "diag", .gpio
= (1 << 1) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1031 /* WAN LED doesn't respond to GPIO control. The switch is probably driving it.
1032 * { .name = "wan", .gpio = (1 << 2) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1034 { .name
= "wlan2g", .gpio
= (1 << 3) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1035 { .name
= "wlan5g", .gpio
= (1 << 4) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1036 { .name
= "usb", .gpio
= (1 << 5) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1037 { .name
= "wps", .gpio
= (1 << 6) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1038 { .name
= "wlan", .gpio
= (1 << 7) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
1043 .name
= "Trendware TEW411BRP+",
1045 { /* No usable buttons */ },
1048 { .name
= "power", .gpio
= 1 << 7, .polarity
= NORMAL
},
1049 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
},
1050 { .name
= "bridge", .gpio
= 1 << 6, .polarity
= NORMAL
},
1055 .name
= "SimpleTech SimpleShare NAS",
1057 { .name
= "reset", .gpio
= 1 << 0 }, // Power button on back, named reset to enable failsafe.
1060 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
1062 .platform_init
= bcm4780_init
,
1066 .name
= "D-Link DIR-130",
1068 { .name
= "reset", .gpio
= 1 << 3},
1069 { .name
= "reserved", .gpio
= 1 << 7},
1072 { .name
= "diag", .gpio
= 1 << 0},
1073 { .name
= "blue", .gpio
= 1 << 6},
1077 .name
= "D-Link DIR-320",
1079 { .name
= "reserved", .gpio
= 1 << 6},
1080 { .name
= "reset", .gpio
= 1 << 7},
1083 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
1084 { .name
= "diag", .gpio
= 1 << 1, .polarity
= NORMAL
}, /* "status led */
1085 { .name
= "red", .gpio
= 1 << 3, .polarity
= REVERSE
},
1086 { .name
= "blue", .gpio
= 1 << 4, .polarity
= REVERSE
},
1087 { .name
= "usb", .gpio
= 1 << 5, .polarity
= NORMAL
},
1091 .name
= "D-Link DIR-330",
1093 { .name
= "reset", .gpio
= 1 << 3},
1094 { .name
= "reserved", .gpio
= 1 << 7},
1097 { .name
= "diag", .gpio
= 1 << 0},
1098 { .name
= "usb", .gpio
= 1 << 4},
1099 { .name
= "blue", .gpio
= 1 << 6},
1103 .name
= "D-Link DWL-3150",
1105 { .name
= "reset", .gpio
= 1 << 7},
1108 { .name
= "diag", .gpio
= 1 << 2},
1109 { .name
= "status", .gpio
= 1 << 1},
1114 .name
= "Sitecom WL-105b",
1116 { .name
= "reset", .gpio
= 1 << 10},
1119 { .name
= "wlan", .gpio
= 1 << 4},
1120 { .name
= "power", .gpio
= 1 << 3},
1123 /* Western Digital Net Center */
1125 .name
= "Western Digital NetCenter",
1127 { .name
= "power", .gpio
= 1 << 0},
1128 { .name
= "reset", .gpio
= 1 << 7},
1130 .platform_init
= NetCenter_init
,
1132 /* Askey (and clones) */
1134 .name
= "Askey RT210W",
1136 /* Power button is hard-wired to hardware reset */
1137 /* but is also connected to GPIO 7 (probably for bootloader recovery) */
1138 { .name
= "power", .gpio
= 1 << 7},
1141 /* These were verified and named based on Belkin F5D4230-4 v1112 */
1142 { .name
= "connected", .gpio
= 1 << 0, .polarity
= REVERSE
},
1143 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
1144 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
1148 .name
= "OvisLink WL-1600GL",
1150 { .name
= "reset", .gpio
= 1 << 3 },
1151 { .name
= "ses", .gpio
= 1 << 4 },
1154 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
1155 { .name
= "wps", .gpio
= 1 << 2, .polarity
= REVERSE
},
1156 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
1157 { .name
= "connected", .gpio
= 1 << 0, .polarity
= REVERSE
},
1162 .name
= "Microsoft MN-700",
1164 { .name
= "reset", .gpio
= 1 << 7 },
1167 { .name
= "power", .gpio
= 1 << 6, .polarity
= NORMAL
},
1172 .name
= "Edimax PS-1208MFG",
1174 { .name
= "reset", .gpio
= 1 << 4 },
1177 { .name
= "status", .gpio
= 1 << 1, .polarity
= NORMAL
},
1178 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
1183 .name
= "Huawei E970",
1185 { .name
= "reset", .gpio
= 1 << 6 },
1188 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
1193 static struct platform_t __init
*platform_detect_legacy(void)
1195 char *boardnum
, *boardtype
;
1197 if (strcmp(getvar("nvram_type"), "cfe") == 0)
1198 return &platforms
[WGT634U
];
1201 /* no easy model number, attempt to guess */
1202 boardnum
= getvar("boardnum");
1203 boardtype
= getvar("boardtype");
1205 if (!strcmp(boardnum
, "20070615")) { /* Linksys WRT600N v1/V1.1 */
1206 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "0") && !strcmp(getvar("switch_type"),"BCM5395"))
1207 return &platforms
[WRT600NV11
];
1209 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "0"))
1210 return &platforms
[WRT600N
];
1213 if (startswith(getvar("pmon_ver"), "CFE")) {
1214 /* CFE based - newer hardware */
1215 if (!strcmp(boardnum
, "42")) { /* Linksys */
1216 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "1"))
1217 return &platforms
[WRT350N
];
1219 if (!strcmp(boardtype
, "0x0101") && !strcmp(getvar("boot_ver"), "v3.6"))
1220 return &platforms
[WRT54G3G
];
1222 /* default to WRT54G if no boot_hw_model is set */
1223 if (nvram_get("boot_hw_model") == NULL
)
1224 return &platforms
[WRT54G
];
1226 if (!strcmp(boardnum
, "1024") && !strcmp(boardtype
, "0x0446"))
1227 return &platforms
[WAP54GV2
];
1229 if (!strcmp(boardnum
, "8") && !strcmp(boardtype
, "0x048e"))
1230 return &platforms
[WL1600GL
];
1233 if (!strcmp(boardnum
, "44") || !strcmp(boardnum
, "44\r")) {
1234 if (!strcmp(boardtype
,"0x0101") || !strcmp(boardtype
, "0x0101\r"))
1235 return &platforms
[TM2300V2
]; /* Dell TrueMobile 2300 v2 */
1238 if (!strcmp(boardnum
, "10496"))
1239 return &platforms
[USR5461
];
1241 if (!strcmp(getvar("boardtype"), "0x0101") && !strcmp(getvar("boardrev"), "0x10")) /* SE505V2 With Modified CFE */
1242 return &platforms
[SE505V2
];
1244 if (!strcmp(boardtype
, "0x048e") && !strcmp(getvar("boardrev"),"0x35") &&
1245 !strcmp(getvar("boardflags"), "0x750")) /* D-Link DIR-320 */
1246 return &platforms
[DIR320
];
1248 if (!strncmp(boardnum
, "TH",2) && !strcmp(boardtype
,"0x042f")) {
1249 return &platforms
[WDNetCenter
];
1252 if (!strcmp(boardtype
,"0x0472") && !strcmp(getvar("cardbus"), "1")) { /* Netgear WNR834B V1 and V2*/
1253 if (!strcmp(boardnum
, "08") || !strcmp(boardnum
, "8"))
1254 return &platforms
[WNR834BV1
];
1255 if (!strcmp(boardnum
, "01") || !strcmp(boardnum
, "1"))
1256 return &platforms
[WNR834BV2
];
1259 } else { /* PMON based - old stuff */
1260 if ((simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 9) &&
1261 (simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 30)) {
1262 return &platforms
[WR850GV1
];
1264 if (startswith(boardtype
, "bcm94710dev")) {
1265 if (!strcmp(boardnum
, "42"))
1266 return &platforms
[WRT54GV1
];
1267 if (simple_strtoul(boardnum
, NULL
, 0) == 2)
1268 return &platforms
[WAP54GV1
];
1270 /* MN-700 has also hardware_version 'WL500-...', so use boardnum */
1271 if (startswith(getvar("hardware_version"), "WL500-")) {
1272 if (!strcmp(getvar("boardnum"), "mn700"))
1273 return &platforms
[MN700
];
1275 return &platforms
[WL500G
];
1277 /* Sitecom WL-105b */
1278 if (startswith(boardnum
, "2") && simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 1)
1279 return &platforms
[WL105B
];
1281 /* unknown asus stuff, probably bcm4702 */
1282 if (startswith(boardnum
, "asusX"))
1283 return &platforms
[ASUS_4702
];
1285 /* bcm4702 based Askey RT210W clones, Including:
1286 * Askey RT210W (duh?)
1288 * Belkin F5D7230-4 before version v1444 (MiniPCI slot, not integrated)
1290 if (!strcmp(boardtype
,"bcm94710r4")
1291 && !strcmp(boardnum
,"100")
1292 && !strcmp(getvar("pmon_ver"),"v1.03.12.bk")
1294 return &platforms
[RT210W
];
1298 if (boardnum
|| !strcmp(boardnum
, "00")) {/* probably buffalo */
1299 if (startswith(boardtype
, "bcm94710ap"))
1300 return &platforms
[BUFFALO_UNKNOWN_4710
];
1303 if (startswith(getvar("CFEver"), "MotoWRv2") ||
1304 startswith(getvar("CFEver"), "MotoWRv3") ||
1305 !strcmp(getvar("MOTO_BOARD_TYPE"), "WR_FEM1")) {
1307 return &platforms
[WR850GV2V3
];
1310 if (!strcmp(boardnum
, "44") && !strcmp(getvar("boardflags"),"0x0388")) { /* Trendware TEW-411BRP+ */
1311 return &platforms
[TEW411BRPP
];
1314 if (startswith(boardnum
, "04FN")) /* SimpleTech SimpleShare */
1315 return &platforms
[STI_NAS
];
1317 if (!strcmp(boardnum
, "10") && !strcmp(getvar("boardrev"), "0x13")) /* D-Link DWL-3150 */
1318 return &platforms
[DWL3150
];
1320 if (!strcmp(boardnum
, "01") && !strcmp(boardtype
, "0x048e") && /* Edimax PS1208MFG */
1321 !strcmp(getvar("status_gpio"), "1")) /* gpio based detection */
1322 return &platforms
[PS1208MFG
];
1328 static struct platform_t __init
*platform_detect(void)
1330 enum bcm47xx_board board
;
1331 const char *board_name
;
1334 board
= bcm47xx_board_get();
1335 board_name
= bcm47xx_board_get_name();
1336 if (board
!= BCM47XX_BOARD_UNKNOWN
&& board
!= BCM47XX_BOARD_NO
)
1337 printk(MODULE_NAME
": kernel found a \"%s\"\n", board_name
);
1340 case BCM47XX_BOARD_ASUS_RTN12
:
1341 return &platforms
[RTN12
];
1342 case BCM47XX_BOARD_ASUS_RTN16
:
1343 return &platforms
[RTN16
];
1344 case BCM47XX_BOARD_ASUS_RTN66U
:
1345 return &platforms
[RTN66U
];
1346 case BCM47XX_BOARD_ASUS_WL300G
:
1347 return &platforms
[WL300G
];
1348 case BCM47XX_BOARD_ASUS_WL320GE
:
1349 return &platforms
[WL320GE
];
1350 case BCM47XX_BOARD_ASUS_WL330GE
:
1351 return &platforms
[WL330GE
];
1352 case BCM47XX_BOARD_ASUS_WL500GD
:
1353 return &platforms
[WL500GD
];
1354 case BCM47XX_BOARD_ASUS_WL500GPV1
:
1355 return &platforms
[WL500GP
];
1356 case BCM47XX_BOARD_ASUS_WL500GPV2
:
1357 return &platforms
[WL500GPV2
];
1358 case BCM47XX_BOARD_ASUS_WL500W
:
1359 return &platforms
[WL500W
];
1360 case BCM47XX_BOARD_ASUS_WL520GC
:
1361 return &platforms
[WL520GC
];
1362 case BCM47XX_BOARD_ASUS_WL520GU
:
1363 return &platforms
[WL520GU
];
1364 case BCM47XX_BOARD_ASUS_WL700GE
:
1365 return &platforms
[WL700GE
];
1366 case BCM47XX_BOARD_ASUS_WLHDD
:
1367 return &platforms
[WLHDD
];
1368 case BCM47XX_BOARD_BELKIN_F7D4301
:
1369 return &platforms
[BELKIN_F7D4301
];
1370 case BCM47XX_BOARD_BUFFALO_WBR2_G54
:
1371 return &platforms
[WBR2_G54
];
1372 case BCM47XX_BOARD_BUFFALO_WHR2_A54G54
:
1373 return &platforms
[WHR2_A54G54
];
1374 case BCM47XX_BOARD_BUFFALO_WHR_G125
:
1375 return &platforms
[WHR_G125
];
1376 case BCM47XX_BOARD_BUFFALO_WHR_G54S
:
1377 return &platforms
[WHR_G54S
];
1378 case BCM47XX_BOARD_BUFFALO_WHR_HP_G54
:
1379 return &platforms
[WHR_HP_G54
];
1380 case BCM47XX_BOARD_BUFFALO_WLA2_G54L
:
1381 return &platforms
[WLA2_G54L
];
1382 case BCM47XX_BOARD_BUFFALO_WZR_G300N
:
1383 return &platforms
[WZR_G300N
];
1384 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54
:
1385 return &platforms
[WZR_RS_G54
];
1386 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54HP
:
1387 return &platforms
[WZR_RS_G54HP
];
1388 case BCM47XX_BOARD_DELL_TM2300
:
1389 return &platforms
[TM2300
];
1390 case BCM47XX_BOARD_DLINK_DIR130
:
1391 return &platforms
[DIR130
];
1392 case BCM47XX_BOARD_DLINK_DIR330
:
1393 return &platforms
[DIR330
];
1394 case BCM47XX_BOARD_HUAWEI_E970
:
1395 return &platforms
[HUAWEI_E970
];
1396 case BCM47XX_BOARD_LINKSYS_E1000V1
:
1397 return &platforms
[E1000V1
];
1398 case BCM47XX_BOARD_LINKSYS_E1000V21
:
1399 return &platforms
[E1000V21
];
1400 case BCM47XX_BOARD_LINKSYS_E2000V1
:
1401 return &platforms
[E2000V1
];
1402 case BCM47XX_BOARD_LINKSYS_E3000V1
:
1403 return &platforms
[E3000V1
];
1404 case BCM47XX_BOARD_LINKSYS_E3200V1
:
1405 return &platforms
[E3200V1
];
1406 case BCM47XX_BOARD_LINKSYS_E4200V1
:
1407 return &platforms
[E4200V1
];
1408 case BCM47XX_BOARD_LINKSYS_WRT150NV1
:
1409 return &platforms
[WRT150NV1
];
1410 case BCM47XX_BOARD_LINKSYS_WRT150NV11
:
1411 return &platforms
[WRT150NV11
];
1412 case BCM47XX_BOARD_LINKSYS_WRT160NV1
:
1413 return &platforms
[WRT160NV1
];
1414 case BCM47XX_BOARD_LINKSYS_WRT160NV3
:
1415 return &platforms
[WRT160NV3
];
1416 case BCM47XX_BOARD_LINKSYS_WRT300NV11
:
1417 return &platforms
[WRT300NV11
];
1418 case BCM47XX_BOARD_LINKSYS_WRT310NV1
:
1419 return &platforms
[WRT310NV1
];
1420 case BCM47XX_BOARD_LINKSYS_WRT54GSV1
:
1421 return &platforms
[WRT54G
];
1422 case BCM47XX_BOARD_LINKSYS_WRT54G3GV2
:
1423 return &platforms
[WRT54G3GV2_VF
];
1424 case BCM47XX_BOARD_LINKSYS_WRT610NV1
:
1425 return &platforms
[WRT610N
];
1426 case BCM47XX_BOARD_LINKSYS_WRT610NV2
:
1427 return &platforms
[WRT610NV2
];
1428 case BCM47XX_BOARD_LINKSYS_WRTSL54GS
:
1429 return &platforms
[WRTSL54GS
];
1430 case BCM47XX_BOARD_MOTOROLA_WE800G
:
1431 return &platforms
[WE800G
];
1432 case BCM47XX_BOARD_MOTOROLA_WR850GP
:
1433 return &platforms
[WR850GP
];
1434 case BCM47XX_BOARD_MOTOROLA_WR850GV2V3
:
1435 return &platforms
[WR850GV2V3
];
1436 case BCM47XX_BOARD_NETGEAR_WNDR3400V1
:
1437 return &platforms
[WNDR3400V1
];
1438 case BCM47XX_BOARD_NETGEAR_WNDR3700V3
:
1439 return &platforms
[WNDR3700V3
];
1440 case BCM47XX_BOARD_UNKNOWN
:
1441 case BCM47XX_BOARD_NO
:
1442 printk(MODULE_NAME
": unknown board found, try legacy detect\n");
1443 printk(MODULE_NAME
": please open a ticket at https://dev.openwrt.org and attach the complete nvram\n");
1444 return platform_detect_legacy();
1446 printk(MODULE_NAME
": board was detected as \"%s\", but not gpio configuration available\n", board_name
);
1447 printk(MODULE_NAME
": now trying legacy detect\n");
1448 return platform_detect_legacy();
1452 static inline void ssb_maskset32(struct ssb_device
*dev
,
1453 u16 offset
, u32 mask
, u32 set
)
1455 ssb_write32(dev
, offset
, (ssb_read32(dev
, offset
) & mask
) | set
);
1458 static void gpio_set_irqenable(int enabled
, irqreturn_t (*handler
)(int, void *))
1463 irq
= gpio_to_irq(0);
1465 pr_err("no irq for gpio available\n");
1470 err
= request_irq(irq
, handler
, IRQF_SHARED
, "gpio", handler
);
1472 pr_err("can not reqeust irq\n");
1476 free_irq(irq
, handler
);
1479 switch (bcm47xx_bus_type
) {
1480 #ifdef CONFIG_BCM47XX_SSB
1481 case BCM47XX_BUS_TYPE_SSB
:
1482 if (bcm47xx_bus
.ssb
.chipco
.dev
)
1483 ssb_maskset32(bcm47xx_bus
.ssb
.chipco
.dev
, SSB_CHIPCO_IRQMASK
, ~SSB_CHIPCO_IRQ_GPIO
, (enabled
? SSB_CHIPCO_IRQ_GPIO
: 0));
1486 #ifdef CONFIG_BCM47XX_BCMA
1487 case BCM47XX_BUS_TYPE_BCMA
:
1488 if (bcm47xx_bus
.bcma
.bus
.drv_cc
.core
)
1489 bcma_maskset32(bcm47xx_bus
.bcma
.bus
.drv_cc
.core
, BCMA_CC_IRQMASK
, ~BCMA_CC_IRQ_GPIO
, (enabled
? BCMA_CC_IRQ_GPIO
: 0));
1495 static void hotplug_button(struct work_struct
*work
)
1497 struct event_t
*event
= container_of(work
, struct event_t
, wq
);
1500 event
->skb
= alloc_skb(2048, GFP_KERNEL
);
1502 s
= skb_put(event
->skb
, strlen(event
->action
) + 2);
1503 sprintf(s
, "%s@", event
->action
);
1506 NETLINK_CB(event
->skb
).dst_group
= 1;
1507 broadcast_uevent(event
->skb
, 0, 1, GFP_KERNEL
);
1512 static irqreturn_t
button_handler(int irq
, void *dev_id
)
1517 in
= bcm47xx_gpio_in(~0) & platform
.button_mask
;
1518 bcm47xx_gpio_polarity(platform
.button_mask
, in
);
1519 changed
= platform
.button_polarity
^ in
;
1520 platform
.button_polarity
= in
;
1522 changed
&= ~bcm47xx_gpio_outen(0, 0);
1524 for (b
= platform
.buttons
; b
->name
; b
++) {
1525 struct event_t
*event
;
1527 if (!(b
->gpio
& changed
)) continue;
1531 if ((event
= (struct event_t
*)kzalloc (sizeof(struct event_t
), GFP_ATOMIC
))) {
1532 event
->seen
= (jiffies
- b
->seen
)/HZ
;
1533 event
->name
= b
->name
;
1534 event
->action
= b
->pressed
? "pressed" : "released";
1535 INIT_WORK(&event
->wq
, (void *)(void *)hotplug_button
);
1536 schedule_work(&event
->wq
);
1544 static void register_buttons(struct button_t
*b
)
1546 for (; b
->name
; b
++)
1547 platform
.button_mask
|= b
->gpio
;
1549 platform
.button_mask
&= ~gpiomask
;
1551 bcm47xx_gpio_outen(platform
.button_mask
, 0);
1552 bcm47xx_gpio_control(platform
.button_mask
, 0);
1553 platform
.button_polarity
= bcm47xx_gpio_in(~0) & platform
.button_mask
;
1554 bcm47xx_gpio_polarity(platform
.button_mask
, platform
.button_polarity
);
1555 bcm47xx_gpio_intmask(platform
.button_mask
, platform
.button_mask
);
1557 gpio_set_irqenable(1, button_handler
);
1560 static void unregister_buttons(struct button_t
*b
)
1562 bcm47xx_gpio_intmask(platform
.button_mask
, 0);
1564 gpio_set_irqenable(0, button_handler
);
1568 static void add_msg(struct event_t
*event
, char *msg
, int argv
)
1575 s
= skb_put(event
->skb
, strlen(msg
) + 1);
1579 static int fill_event (struct event_t
*event
)
1581 static char buf
[128];
1583 add_msg(event
, "HOME=/", 0);
1584 add_msg(event
, "PATH=/sbin:/bin:/usr/sbin:/usr/bin", 0);
1585 add_msg(event
, "SUBSYSTEM=button", 0);
1586 snprintf(buf
, 128, "ACTION=%s", event
->action
);
1587 add_msg(event
, buf
, 0);
1588 snprintf(buf
, 128, "BUTTON=%s", event
->name
);
1589 add_msg(event
, buf
, 0);
1590 snprintf(buf
, 128, "SEEN=%ld", event
->seen
);
1591 add_msg(event
, buf
, 0);
1592 snprintf(buf
, 128, "SEQNUM=%llu", uevent_next_seqnum());
1593 add_msg(event
, buf
, 0);
1599 * This should be extended to allow the platform to specify the pins and width
1600 * of the shift register. They're hardcoded for now because only the WNDR3700v3
1603 static void shiftreg_output(unsigned int val
)
1607 bcm47xx_gpio_out(SHIFTREG_DATA
, SHIFTREG_DATA
); /* init off, pull high */
1608 bcm47xx_gpio_out(SHIFTREG_CLK
, 0); /* init reset */
1611 for(mask
= 1 << (SHIFTREG_MAX_BITS
-1); mask
; mask
>>= 1)
1613 bcm47xx_gpio_out(SHIFTREG_DATA
, (val
& mask
) ? SHIFTREG_DATA
: 0);
1614 bcm47xx_gpio_out(SHIFTREG_CLK
, SHIFTREG_CLK
); /* pull high to trigger */
1615 bcm47xx_gpio_out(SHIFTREG_CLK
, 0); /* reset to low */
1619 static void set_led_shift(struct led_t
*led
)
1621 static u32 shiftreg
= 0;
1623 u32 pin
= (led
->gpio
& ~GPIO_TYPE_MASK
);
1631 /* Clock the bits out. */
1632 if (shiftreg
!= old
) {
1633 shiftreg_output(shiftreg
);
1637 static void set_led_extif(struct led_t
*led
)
1639 volatile u8
*addr
= (volatile u8
*) KSEG1ADDR(EXTIF_UART
) + (led
->gpio
& ~GPIO_TYPE_MASK
);
1647 static void led_flash(unsigned long dummy
) {
1652 for (l
= platform
.leds
; l
->name
; l
++) {
1653 if (!l
->flash
) continue;
1654 switch (l
->gpio
& GPIO_TYPE_MASK
) {
1655 case GPIO_TYPE_EXTIF
:
1657 l
->state
= !l
->state
;
1660 case GPIO_TYPE_SHIFT
:
1662 l
->state
= !l
->state
;
1665 case GPIO_TYPE_NORMAL
:
1674 u32 val
= ~bcm47xx_gpio_in(~0);
1676 bcm47xx_gpio_outen(mask
, mask
);
1677 bcm47xx_gpio_control(mask
, 0);
1678 bcm47xx_gpio_out(mask
, val
);
1680 if (mask
|| extif_blink
) {
1681 mod_timer(&led_timer
, jiffies
+ FLASH_TIME
);
1685 static int diag_led_show(struct seq_file
*m
, void *v
)
1687 struct led_t
* led
= m
->private;
1689 u8 p
= (led
->polarity
== NORMAL
? 0 : 1);
1691 return seq_printf(m
, "f\n");
1692 } else if ((led
->gpio
& GPIO_TYPE_MASK
) != GPIO_TYPE_NORMAL
) {
1693 return seq_printf(m
, "%d\n", ((led
->state
^ p
) ? 1 : 0));
1695 u32 in
= (bcm47xx_gpio_in(~0) & led
->gpio
? 1 : 0);
1696 return seq_printf(m
, "%d\n", ((in
^ p
) ? 1 : 0));
1700 static int diag_led_open(struct inode
*inode
, struct file
*file
)
1702 return single_open(file
, diag_led_show
, PDE_DATA(inode
));
1705 static ssize_t
diag_led_write(struct file
*file
, const char __user
*buf
, size_t count
, loff_t
*ppos
)
1707 struct led_t
*led
= PDE_DATA(file_inode(file
));
1712 len
= min(count
, sizeof(cmd
) - 1);
1713 if (copy_from_user(cmd
, buf
, len
))
1718 p
= (led
->polarity
== NORMAL
? 0 : 1);
1719 if (cmd
[0] == 'f') {
1724 if ((led
->gpio
& GPIO_TYPE_MASK
) == GPIO_TYPE_EXTIF
) {
1725 led
->state
= p
^ ((cmd
[0] == '1') ? 1 : 0);
1727 } else if ((led
->gpio
& GPIO_TYPE_MASK
) == GPIO_TYPE_SHIFT
) {
1728 led
->state
= p
^ ((cmd
[0] == '1') ? 1 : 0);
1731 bcm47xx_gpio_outen(led
->gpio
, led
->gpio
);
1732 bcm47xx_gpio_control(led
->gpio
, 0);
1733 bcm47xx_gpio_out(led
->gpio
, ((p
^ (cmd
[0] == '1')) ? led
->gpio
: 0));
1739 static const struct file_operations diag_led_fops
= {
1740 .open
= diag_led_open
,
1742 .llseek
= seq_lseek
,
1743 .write
= diag_led_write
1746 static void register_leds(struct led_t
*l
)
1748 struct proc_dir_entry
*p
;
1753 leds
= proc_mkdir("led", diag
);
1757 for(; l
->name
; l
++) {
1758 if (l
->gpio
& gpiomask
)
1761 switch (l
->gpio
& GPIO_TYPE_MASK
) {
1762 case GPIO_TYPE_EXTIF
:
1766 case GPIO_TYPE_SHIFT
:
1767 mask
|= (SHIFTREG_DATA
| SHIFTREG_CLK
);
1768 oe_mask
|= (SHIFTREG_DATA
| SHIFTREG_CLK
);
1769 l
->state
= (l
->polarity
!= NORMAL
);
1772 case GPIO_TYPE_NORMAL
:
1774 if (l
->polarity
!= INPUT
) oe_mask
|= l
->gpio
;
1776 val
|= (l
->polarity
== NORMAL
)?0:l
->gpio
;
1780 if (l
->polarity
== INPUT
) continue;
1782 p
= proc_create_data(l
->name
, S_IRUSR
, leds
, &diag_led_fops
, l
);
1785 bcm47xx_gpio_outen(mask
, oe_mask
);
1786 bcm47xx_gpio_control(mask
, 0);
1787 bcm47xx_gpio_out(mask
, val
);
1788 bcm47xx_gpio_intmask(mask
, 0);
1791 static void unregister_leds(struct led_t
*l
)
1794 remove_proc_entry(l
->name
, leds
);
1796 remove_proc_entry("led", diag
);
1799 static int diag_model_show(struct seq_file
*m
, void *v
)
1801 return seq_printf(m
, "%s\n", platform
.name
);
1804 static int diag_model_open(struct inode
*inode
, struct file
*file
)
1806 return single_open(file
, diag_model_show
, PDE_DATA(inode
));
1809 static const struct file_operations diag_model_fops
= {
1810 .open
= diag_model_open
,
1815 static int diag_gpiomask_show(struct seq_file
*m
, void *v
)
1817 return seq_printf(m
, "0x%04x\n", gpiomask
);
1820 static int diag_gpiomask_open(struct inode
*inode
, struct file
*file
)
1822 return single_open(file
, diag_gpiomask_show
, PDE_DATA(inode
));
1825 static ssize_t
diag_gpiomask_write(struct file
*file
, const char __user
*buf
, size_t count
, loff_t
*ppos
)
1827 int err
= kstrtouint_from_user(buf
, count
, 0, &gpiomask
);
1831 if (platform
.buttons
) {
1832 unregister_buttons(platform
.buttons
);
1833 register_buttons(platform
.buttons
);
1836 if (platform
.leds
) {
1837 unregister_leds(platform
.leds
);
1838 register_leds(platform
.leds
);
1844 static const struct file_operations diag_gpiomask_fops
= {
1845 .open
= diag_gpiomask_open
,
1847 .llseek
= seq_lseek
,
1848 .write
= diag_gpiomask_write
1851 static int __init
diag_init(void)
1853 static struct proc_dir_entry
*p
;
1854 static struct platform_t
*detected
;
1856 detected
= platform_detect();
1858 printk(MODULE_NAME
": Router model not detected.\n");
1861 memcpy(&platform
, detected
, sizeof(struct platform_t
));
1863 printk(MODULE_NAME
": Detected '%s'\n", platform
.name
);
1864 if (platform
.platform_init
!= NULL
) {
1865 platform
.platform_init();
1868 if (!(diag
= proc_mkdir("diag", NULL
))) {
1869 printk(MODULE_NAME
": proc_mkdir on /proc/diag failed\n");
1873 p
= proc_create("model", S_IRUSR
, diag
, &diag_model_fops
);
1875 remove_proc_entry("diag", NULL
);
1879 p
= proc_create("gpiomask", S_IRUSR
| S_IWUSR
, diag
, &diag_gpiomask_fops
);
1881 remove_proc_entry("model", diag
);
1882 remove_proc_entry("diag", NULL
);
1886 if (platform
.buttons
)
1887 register_buttons(platform
.buttons
);
1890 register_leds(platform
.leds
);
1895 static void __exit
diag_exit(void)
1897 del_timer(&led_timer
);
1899 if (platform
.buttons
)
1900 unregister_buttons(platform
.buttons
);
1903 unregister_leds(platform
.leds
);
1905 remove_proc_entry("model", diag
);
1906 remove_proc_entry("gpiomask", diag
);
1907 remove_proc_entry("diag", NULL
);
1910 module_init(diag_init
);
1911 module_exit(diag_exit
);
1913 MODULE_AUTHOR("Mike Baker, Felix Fietkau / OpenWrt.org");
1914 MODULE_LICENSE("GPL");