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
);
49 static void register_leds(struct led_t
*l
);
50 static void unregister_leds(struct led_t
*l
);
51 static void led_flash(unsigned long dummy
);
53 static struct platform_t platform
;
55 static struct timer_list led_timer
= TIMER_INITIALIZER(&led_flash
, 0, 0);
57 static struct proc_dir_entry
*diag
, *leds
;
59 static struct prochandler_t proc_model
= { .type
= PROC_MODEL
};
60 static struct prochandler_t proc_gpiomask
= { .type
= PROC_GPIOMASK
};
113 BUFFALO_UNKNOWN_4710
,
158 /* Western Digital */
174 static void __init
bcm4780_init(void) {
177 /* Enables GPIO 3 that controls HDD and led power on ASUS WL-700gE */
178 printk(MODULE_NAME
": Spinning up HDD and enabling leds\n");
179 bcm47xx_gpio_outen(pin
, pin
);
180 bcm47xx_gpio_control(pin
, 0);
181 bcm47xx_gpio_out(pin
, pin
);
183 /* Wait 5s, so the HDD can spin up */
184 set_current_state(TASK_INTERRUPTIBLE
);
185 schedule_timeout(HZ
* 5);
188 static void __init
NetCenter_init(void) {
189 /* unset pin 6 (+12V) */
191 bcm47xx_gpio_outen(pin
, pin
);
192 bcm47xx_gpio_control(pin
, 0);
193 bcm47xx_gpio_out(pin
, pin
);
194 /* unset pin 1 (turn off red led, blue will light alone if +5V comes up) */
196 bcm47xx_gpio_outen(pin
, pin
);
197 bcm47xx_gpio_control(pin
, 0);
198 bcm47xx_gpio_out(pin
, pin
);
199 /* unset pin 3 (+5V) and wait 5 seconds (harddisk spin up) */
203 static void __init
bcm57xx_init(void) {
206 /* FIXME: switch comes up, but port mappings/vlans not right */
207 bcm47xx_gpio_outen(pin
, pin
);
208 bcm47xx_gpio_control(pin
, 0);
209 bcm47xx_gpio_out(pin
, pin
);
212 static struct platform_t __initdata platforms
[] = {
215 .name
= "Linksys WAP54G V1",
217 { .name
= "reset", .gpio
= 1 << 0 },
220 { .name
= "diag", .gpio
= 1 << 3 },
221 { .name
= "wlan", .gpio
= 1 << 4 },
225 .name
= "Linksys WAP54G V2",
227 { .name
= "reset", .gpio
= 1 << 0 },
230 { .name
= "wlan", .gpio
= 1 << 5, .polarity
= REVERSE
},
231 /* GPIO 6 is b44 (eth0, LAN) PHY power */
235 .name
= "Linksys WAP54G V3",
237 /* FIXME: verify this */
238 { .name
= "reset", .gpio
= 1 << 7 },
239 { .name
= "ses", .gpio
= 1 << 0 },
243 { .name
= "ses", .gpio
= 1 << 1 },
247 .name
= "Linksys WRT54G V1.x",
249 { .name
= "reset", .gpio
= 1 << 6 },
252 { .name
= "diag", .gpio
= 0x13 | GPIO_TYPE_EXTIF
, .polarity
= NORMAL
},
253 { .name
= "dmz", .gpio
= 0x12 | GPIO_TYPE_EXTIF
, .polarity
= NORMAL
},
257 .name
= "Linksys WRT54G/GS/GL",
259 { .name
= "reset", .gpio
= 1 << 6 },
260 { .name
= "ses", .gpio
= 1 << 4 },
263 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
264 { .name
= "dmz", .gpio
= 1 << 7, .polarity
= REVERSE
},
265 { .name
= "ses_white", .gpio
= 1 << 2, .polarity
= REVERSE
},
266 { .name
= "ses_orange", .gpio
= 1 << 3, .polarity
= REVERSE
},
267 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
271 .name
= "Linksys WRTSL54GS",
273 { .name
= "reset", .gpio
= 1 << 6 },
274 { .name
= "ses", .gpio
= 1 << 4 },
277 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
278 { .name
= "dmz", .gpio
= 1 << 0, .polarity
= REVERSE
},
279 { .name
= "ses_white", .gpio
= 1 << 5, .polarity
= REVERSE
},
280 { .name
= "ses_orange", .gpio
= 1 << 7, .polarity
= REVERSE
},
284 .name
= "Linksys WRT54G3G",
286 { .name
= "reset", .gpio
= 1 << 6 },
287 { .name
= "3g", .gpio
= 1 << 4 },
290 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
291 { .name
= "dmz", .gpio
= 1 << 7, .polarity
= REVERSE
},
292 { .name
= "3g_green", .gpio
= 1 << 2, .polarity
= NORMAL
},
293 { .name
= "3g_blue", .gpio
= 1 << 3, .polarity
= NORMAL
},
294 { .name
= "3g_blink", .gpio
= 1 << 5, .polarity
= NORMAL
},
298 .name
= "Linksys WRT54G3GV2-VF",
300 { .name
= "reset", .gpio
= 1 << 6 },
301 { .name
= "3g", .gpio
= 1 << 5 },
304 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
305 { .name
= "3g_green", .gpio
= 1 << 2, .polarity
= NORMAL
},
306 { .name
= "3g_blue", .gpio
= 1 << 3, .polarity
= NORMAL
},
310 .name
= "Linksys WRT150N V1",
312 { .name
= "reset", .gpio
= 1 << 6 },
313 { .name
= "ses", .gpio
= 1 << 4 },
316 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
317 { .name
= "ses_green", .gpio
= 1 << 5, .polarity
= REVERSE
},
318 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
322 .name
= "Linksys WRT150N V1.1",
324 { .name
= "reset", .gpio
= 1 << 6 },
325 { .name
= "ses", .gpio
= 1 << 4 },
328 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
329 { .name
= "ses_green", .gpio
= 1 << 5, .polarity
= REVERSE
},
330 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
334 .name
= "Linksys WRT160N v1.x",
336 { .name
= "reset", .gpio
= 1 << 6 },
337 { .name
= "ses", .gpio
= 1 << 4 },
340 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
341 { .name
= "ses_blue", .gpio
= 1 << 5, .polarity
= REVERSE
},
342 { .name
= "ses_orange", .gpio
= 1 << 3, .polarity
= REVERSE
},
346 .name
= "Linksys WRT160N V3",
348 { .name
= "reset", .gpio
= 1 << 6 },
349 { .name
= "ses", .gpio
= 1 << 5 },
352 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
353 { .name
= "ses_blue", .gpio
= 1 << 4, .polarity
= REVERSE
},
354 { .name
= "ses_orange", .gpio
= 1 << 2, .polarity
= REVERSE
},
358 .name
= "Linksys WRT300N V1.1",
360 { .name
= "reset", .gpio
= 1 << 6 }, // "Reset" on back panel
361 { .name
= "ses", .gpio
= 1 << 4 }, // "Reserved" on top panel
364 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
}, // "Power"
365 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
}, // "Security" Amber
366 { .name
= "ses_green", .gpio
= 1 << 5, .polarity
= REVERSE
}, // "Security" Green
368 .platform_init
= bcm57xx_init
,
371 .name
= "Linksys WRT350N",
373 { .name
= "reset", .gpio
= 1 << 6 },
374 { .name
= "ses", .gpio
= 1 << 8 },
377 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
378 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
379 { .name
= "ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
},
380 { .name
= "usb_blink", .gpio
= 1 << 10, .polarity
= REVERSE
},
381 { .name
= "usb", .gpio
= 1 << 11, .polarity
= REVERSE
},
383 .platform_init
= bcm57xx_init
,
386 .name
= "Linksys WRT600N",
388 { .name
= "reset", .gpio
= 1 << 6 },
389 { .name
= "ses", .gpio
= 1 << 7 },
392 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
}, // Power LED
393 { .name
= "usb", .gpio
= 1 << 3, .polarity
= REVERSE
}, // USB LED
394 { .name
= "wl0_ses_amber", .gpio
= 1 << 8, .polarity
= REVERSE
}, // 2.4Ghz LED Amber
395 { .name
= "wl0_ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
}, // 2.4Ghz LED Green
396 { .name
= "wl1_ses_amber", .gpio
= 1 << 10, .polarity
= REVERSE
}, // 5.6Ghz LED Amber
397 { .name
= "wl1_ses_green", .gpio
= 1 << 11, .polarity
= REVERSE
}, // 5.6Ghz LED Green
399 .platform_init
= bcm57xx_init
,
402 .name
= "Linksys WRT600N V1.1",
404 { .name
= "reset", .gpio
= 1 << 6 },
405 { .name
= "ses", .gpio
= 1 << 7 },
408 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
}, // Power LED
409 { .name
= "usb", .gpio
= 1 << 3, .polarity
= REVERSE
}, // USB LED
410 { .name
= "wl0_ses_amber", .gpio
= 1 << 8, .polarity
= REVERSE
}, // 2.4Ghz LED Amber
411 { .name
= "wl0_ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
}, // 2.4Ghz LED Green
412 { .name
= "wl1_ses_amber", .gpio
= 1 << 10, .polarity
= REVERSE
}, // 5.6Ghz LED Amber
413 { .name
= "wl1_ses_green", .gpio
= 1 << 11, .polarity
= REVERSE
}, // 5.6Ghz LED Green
415 .platform_init
= bcm57xx_init
,
418 .name
= "Linksys WRT610N",
420 { .name
= "reset", .gpio
= 1 << 6 },
421 { .name
= "ses", .gpio
= 1 << 8 },
424 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
}, // Power LED
425 { .name
= "usb", .gpio
= 1 << 0, .polarity
= REVERSE
}, // USB LED
426 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
}, // WiFi protected setup LED amber
427 { .name
= "ses_blue", .gpio
= 1 << 9, .polarity
= REVERSE
}, // WiFi protected setup LED blue
431 .name
= "Linksys WRT610N V2",
433 { .name
= "reset", .gpio
= 1 << 6 },
434 { .name
= "ses", .gpio
= 1 << 4 },
437 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
}, // Power LED
438 { .name
= "usb", .gpio
= 1 << 7, .polarity
= NORMAL
}, // USB LED
439 { .name
= "ses_amber", .gpio
= 1 << 0, .polarity
= REVERSE
}, // WiFi protected setup LED amber
440 { .name
= "ses_blue", .gpio
= 1 << 3, .polarity
= REVERSE
}, // WiFi protected setup LED blue
441 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
}, // Wireless LED
444 /* same hardware as WRT160NV3 and Cisco Valet M10V1, but different board detection, combine? */
446 .name
= "Linksys E1000 V1",
448 { .name
= "reset", .gpio
= 1 << 6 },
449 { .name
= "wps", .gpio
= 1 << 5 }, /* nvram get gpio5=wps_button */
452 /** turns on leds for all ethernet ports (wan too)
453 * this also disconnects some, or maybe all, ethernet ports
454 * 1: leds work normally
455 * 0: all lit all the time */
456 /* nvram get gpio3=robo_reset */
457 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
458 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
459 { .name
= "ses_blue", .gpio
= 1 << 4, .polarity
= REVERSE
}, /* nvram get gpio4=wps_led */
460 { .name
= "ses_orange", .gpio
= 1 << 2, .polarity
= REVERSE
}, /* nvram get gpio2=wps_status_led */
464 .name
= "Linksys E3000 V1",
466 { .name
= "reset", .gpio
= 1 << 6 },
467 { .name
= "ses", .gpio
= 1 << 4 },
470 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
}, // Power LED
471 { .name
= "usb", .gpio
= 1 << 7, .polarity
= NORMAL
}, // USB LED
472 { .name
= "ses_amber", .gpio
= 1 << 0, .polarity
= REVERSE
}, // WiFi protected setup LED amber
473 { .name
= "ses_blue", .gpio
= 1 << 3, .polarity
= REVERSE
}, // WiFi protected setup LED blue
474 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
}, // Wireless LED
478 .name
= "Linksys E3200 V1",
480 /* { .name = "switch", .gpio = 1 << 4 },*/ /* nvram get gpio4=robo_reset */
481 { .name
= "reset", .gpio
= 1 << 5 }, /* nvram get reset_gpio=5 */
482 { .name
= "wps", .gpio
= 1 << 8 }, /* nvram get gpio8=wps_button */
483 /* { .name = "wombo", .gpio = 1 << 23 },*/ /* nvram get gpio23=wombo_reset - wireless on motherboard */
486 { .name
= "power", .gpio
= 1 << 3, .polarity
= REVERSE
}, /* Power LED */
491 .name
= "ASUS WL-HDD",
493 { .name
= "reset", .gpio
= 1 << 6 },
496 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
497 { .name
= "usb", .gpio
= 1 << 2, .polarity
= REVERSE
},
501 .name
= "ASUS WL-300g",
503 { .name
= "reset", .gpio
= 1 << 6 },
506 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
510 .name
= "ASUS WL-320gE/WL-320gP",
512 { .name
= "reset", .gpio
= 1 << 6 },
515 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
516 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
},
517 { .name
= "link", .gpio
= 1 << 11, .polarity
= REVERSE
},
521 .name
= "ASUS WL-330gE",
523 { .name
= "reset", .gpio
= 1 << 2 },
526 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
530 .name
= "ASUS WL-500g",
532 { .name
= "reset", .gpio
= 1 << 6 },
535 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
539 .name
= "ASUS WL-500g Deluxe",
541 { .name
= "reset", .gpio
= 1 << 6 },
544 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
548 .name
= "ASUS WL-500g Premium",
550 { .name
= "reset", .gpio
= 1 << 0 },
551 { .name
= "ses", .gpio
= 1 << 4 },
554 { .name
= "power", .gpio
= 1 << 1, .polarity
= REVERSE
},
558 .name
= "ASUS WL-500g Premium V2",
560 { .name
= "reset", .gpio
= 1 << 2 },
561 { .name
= "ses", .gpio
= 1 << 3 },
564 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
565 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
569 .name
= "ASUS WL-500W",
571 { .name
= "reset", .gpio
= 1 << 6 },
572 { .name
= "ses", .gpio
= 1 << 7 },
575 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
579 .name
= "ASUS WL-520GC",
581 { .name
= "reset", .gpio
= 1 << 2 },
582 { .name
= "ses", .gpio
= 1 << 3 },
585 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
586 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
590 .name
= "ASUS WL-520gU",
592 { .name
= "reset", .gpio
= 1 << 2 },
593 { .name
= "ses", .gpio
= 1 << 3 },
596 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
597 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
601 .name
= "ASUS (unknown, BCM4702)",
603 { .name
= "reset", .gpio
= 1 << 6 },
606 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
610 .name
= "ASUS WL-700gE",
612 { .name
= "reset", .gpio
= 1 << 7 }, // on back, hardwired, always resets device regardless OS state
613 { .name
= "ses", .gpio
= 1 << 4 }, // on back, actual name ezsetup
614 { .name
= "power", .gpio
= 1 << 0 }, // on front
615 { .name
= "copy", .gpio
= 1 << 6 }, // on front
619 // GPIO that controls power led also enables/disables some essential functions
622 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
}, // actual name power
624 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
626 .platform_init
= bcm4780_init
,
629 .name
= "ASUS RT-N16",
631 { .name
= "reset", .gpio
= 1 << 8 },
632 { .name
= "ses", .gpio
= 1 << 5 },
635 { .name
= "power", .gpio
= 1 << 1, .polarity
= REVERSE
},
636 { .name
= "wlan", .gpio
= 1 << 7, .polarity
= NORMAL
},
641 .name
= "Buffalo WHR-G54S",
643 { .name
= "reset", .gpio
= 1 << 4 },
644 { .name
= "bridge", .gpio
= 1 << 5 },
645 { .name
= "ses", .gpio
= 1 << 0 },
648 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
649 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
650 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
651 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
652 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
656 .name
= "Buffalo WBR2-G54",
659 { .name
= "reset", .gpio
= 1 << 7 },
662 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
666 .name
= "Buffalo WHR-HP-G54",
668 { .name
= "reset", .gpio
= 1 << 4 },
669 { .name
= "bridge", .gpio
= 1 << 5 },
670 { .name
= "ses", .gpio
= 1 << 0 },
673 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
674 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
675 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
676 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
677 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
681 .name
= "Buffalo WHR-G125",
683 { .name
= "reset", .gpio
= 1 << 4 },
684 { .name
= "bridge", .gpio
= 1 << 5 },
685 { .name
= "ses", .gpio
= 1 << 0 },
688 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
689 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
690 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
691 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
692 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
696 .name
= "Buffalo WHR2-A54G54",
698 { .name
= "reset", .gpio
= 1 << 4 },
701 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
705 .name
= "Buffalo WLA2-G54L",
708 { .name
= "reset", .gpio
= 1 << 7 },
711 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
715 .name
= "Buffalo WZR-G300N",
717 { .name
= "reset", .gpio
= 1 << 4 },
720 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
721 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
722 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
726 .name
= "Buffalo WZR-RS-G54",
728 { .name
= "ses", .gpio
= 1 << 0 },
729 { .name
= "reset", .gpio
= 1 << 4 },
732 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
733 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
734 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
738 .name
= "Buffalo WZR-RS-G54HP",
740 { .name
= "ses", .gpio
= 1 << 0 },
741 { .name
= "reset", .gpio
= 1 << 4 },
744 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
745 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
746 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
749 [BUFFALO_UNKNOWN
] = {
750 .name
= "Buffalo (unknown)",
752 { .name
= "reset", .gpio
= 1 << 7 },
755 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
758 [BUFFALO_UNKNOWN_4710
] = {
759 .name
= "Buffalo (unknown, BCM4710)",
761 { .name
= "reset", .gpio
= 1 << 4 },
764 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
769 .name
= "Siemens SE505 V1",
771 /* No usable buttons */
774 // { .name = "power", .gpio = 1 << 0 .polarity = REVERSE }, // Usable when retrofitting D26 (?)
775 { .name
= "dmz", .gpio
= 1 << 4, .polarity
= REVERSE
}, // actual name WWW
776 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
780 .name
= "Siemens SE505 V2",
782 /* No usable buttons */
785 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
786 { .name
= "dmz", .gpio
= 1 << 0, .polarity
= REVERSE
}, // actual name WWW
787 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
792 .name
= "U.S. Robotics USR5461",
794 /* No usable buttons */
797 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
798 { .name
= "printer", .gpio
= 1 << 1, .polarity
= REVERSE
},
803 .name
= "Dell TrueMobile 2300",
805 { .name
= "reset", .gpio
= 1 << 0 },
808 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
809 { .name
= "power", .gpio
= 1 << 7, .polarity
= REVERSE
},
813 .name
= "Dell TrueMobile 2300 v2",
815 { .name
= "reset", .gpio
= 1 << 0 },
818 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
819 { .name
= "power", .gpio
= 1 << 7, .polarity
= REVERSE
},
824 .name
= "Motorola WE800G",
826 { .name
= "reset", .gpio
= 1 << 0 },
829 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
830 { .name
= "diag", .gpio
= 1 << 2, .polarity
= REVERSE
},
831 { .name
= "wlan_amber", .gpio
= 1 << 1, .polarity
= NORMAL
},
835 .name
= "Motorola WR850G V1",
837 { .name
= "reset", .gpio
= 1 << 0 },
840 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
841 { .name
= "diag", .gpio
= 1 << 3, .polarity
= REVERSE
},
842 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= NORMAL
},
843 { .name
= "wlan_red", .gpio
= 1 << 5, .polarity
= REVERSE
},
844 { .name
= "wlan_green", .gpio
= 1 << 7, .polarity
= REVERSE
},
848 .name
= "Motorola WR850G V2/V3",
850 { .name
= "reset", .gpio
= 1 << 5 },
853 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
854 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
855 { .name
= "wan", .gpio
= 1 << 6, .polarity
= INPUT
},
856 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
860 .name
= "Motorola WR850GP",
862 { .name
= "reset", .gpio
= 1 << 5 },
865 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
866 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
867 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= REVERSE
},
868 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
874 .name
= "Belkin (unknown)",
875 /* FIXME: verify & add detection */
877 { .name
= "reset", .gpio
= 1 << 7 },
880 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
},
881 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= NORMAL
},
882 { .name
= "connected", .gpio
= 1 << 0, .polarity
= NORMAL
},
886 .name
= "Belkin PlayMax F7D4301",
888 { .name
= "reset", .gpio
= 1 << 6 },
889 { .name
= "wps", .gpio
= 1 << 8 },
892 { .name
= "power", .gpio
= 1 << 11, .polarity
= REVERSE
},
893 { .name
= "wlan", .gpio
= 1 << 13, .polarity
= REVERSE
},
894 { .name
= "led0", .gpio
= 1 << 14, .polarity
= REVERSE
},
895 { .name
= "led1", .gpio
= 1 << 15, .polarity
= REVERSE
},
900 .name
= "Netgear WGT634U",
902 { .name
= "reset", .gpio
= 1 << 2 },
905 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
},
910 .name
= "Netgear WNR834B V1",
911 .buttons
= { /* TODO: add reset button and confirm LEDs - GPIO from dd-wrt */ },
913 { .name
= "power", .gpio
= 1 << 4, .polarity
= REVERSE
},
914 { .name
= "diag", .gpio
= 1 << 5, .polarity
= REVERSE
},
915 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
920 .name
= "Netgear WNR834B V2",
922 { .name
= "reset", .gpio
= 1 << 6 },
925 { .name
= "power", .gpio
= 1 << 2, .polarity
= NORMAL
},
926 { .name
= "diag", .gpio
= 1 << 3, .polarity
= NORMAL
},
927 { .name
= "connected", .gpio
= 1 << 7, .polarity
= NORMAL
},
931 .name
= "Netgear WNDR3400 V1",
933 /* nvram get gpio5=robo_reset */
934 { .name
= "reset", .gpio
= 1 << 4 },
935 { .name
= "wps", .gpio
= 1 << 6 },
936 { .name
= "wlan", .gpio
= 1 << 8 },
939 { .name
= "wlan", .gpio
= 0 << 0, .polarity
= NORMAL
},
940 { .name
= "connected", .gpio
= 1 << 0, .polarity
= NORMAL
},
941 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
},
942 { .name
= "diag", .gpio
= 1 << 7, .polarity
= NORMAL
},
943 { .name
= "usb", .gpio
= 1 << 2, .polarity
= REVERSE
},
947 .name
= "Netgear WNDR3700 V3",
949 /* { .name = "usb", .gpio = 1 << 1 }, */ /* this button doesn't seem to exist. */
950 { .name
= "wlan", .gpio
= 1 << 2 },
951 { .name
= "reset", .gpio
= 1 << 3 },
952 { .name
= "wps", .gpio
= 1 << 4 },
953 /* { .name = "switch", .gpio = 1 << 5 },*/ /* nvram get gpio5=robo_reset */
956 { .name
= "power", .gpio
= (1 << 0) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
957 { .name
= "diag", .gpio
= (1 << 1) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
958 /* WAN LED doesn't respond to GPIO control. The switch is probably driving it.
959 * { .name = "wan", .gpio = (1 << 2) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
961 { .name
= "wlan2g", .gpio
= (1 << 3) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
962 { .name
= "wlan5g", .gpio
= (1 << 4) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
963 { .name
= "usb", .gpio
= (1 << 5) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
964 { .name
= "wps", .gpio
= (1 << 6) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
965 { .name
= "wlan", .gpio
= (1 << 7) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
970 .name
= "Trendware TEW411BRP+",
972 { /* No usable buttons */ },
975 { .name
= "power", .gpio
= 1 << 7, .polarity
= NORMAL
},
976 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
},
977 { .name
= "bridge", .gpio
= 1 << 6, .polarity
= NORMAL
},
982 .name
= "SimpleTech SimpleShare NAS",
984 { .name
= "reset", .gpio
= 1 << 0 }, // Power button on back, named reset to enable failsafe.
987 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
989 .platform_init
= bcm4780_init
,
993 .name
= "D-Link DIR-130",
995 { .name
= "reset", .gpio
= 1 << 3},
996 { .name
= "reserved", .gpio
= 1 << 7},
999 { .name
= "diag", .gpio
= 1 << 0},
1000 { .name
= "blue", .gpio
= 1 << 6},
1004 .name
= "D-Link DIR-320",
1006 { .name
= "reserved", .gpio
= 1 << 6},
1007 { .name
= "reset", .gpio
= 1 << 7},
1010 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
1011 { .name
= "diag", .gpio
= 1 << 1, .polarity
= NORMAL
}, /* "status led */
1012 { .name
= "red", .gpio
= 1 << 3, .polarity
= REVERSE
},
1013 { .name
= "blue", .gpio
= 1 << 4, .polarity
= REVERSE
},
1014 { .name
= "usb", .gpio
= 1 << 5, .polarity
= NORMAL
},
1018 .name
= "D-Link DIR-330",
1020 { .name
= "reset", .gpio
= 1 << 3},
1021 { .name
= "reserved", .gpio
= 1 << 7},
1024 { .name
= "diag", .gpio
= 1 << 0},
1025 { .name
= "usb", .gpio
= 1 << 4},
1026 { .name
= "blue", .gpio
= 1 << 6},
1030 .name
= "D-Link DWL-3150",
1032 { .name
= "reset", .gpio
= 1 << 7},
1035 { .name
= "diag", .gpio
= 1 << 2},
1036 { .name
= "status", .gpio
= 1 << 1},
1041 .name
= "Sitecom WL-105b",
1043 { .name
= "reset", .gpio
= 1 << 10},
1046 { .name
= "wlan", .gpio
= 1 << 4},
1047 { .name
= "power", .gpio
= 1 << 3},
1050 /* Western Digital Net Center */
1052 .name
= "Western Digital NetCenter",
1054 { .name
= "power", .gpio
= 1 << 0},
1055 { .name
= "reset", .gpio
= 1 << 7},
1057 .platform_init
= NetCenter_init
,
1059 /* Askey (and clones) */
1061 .name
= "Askey RT210W",
1063 /* Power button is hard-wired to hardware reset */
1064 /* but is also connected to GPIO 7 (probably for bootloader recovery) */
1065 { .name
= "power", .gpio
= 1 << 7},
1068 /* These were verified and named based on Belkin F5D4230-4 v1112 */
1069 { .name
= "connected", .gpio
= 1 << 0, .polarity
= REVERSE
},
1070 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
1071 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
1075 .name
= "OvisLink WL-1600GL",
1077 { .name
= "reset", .gpio
= 1 << 3 },
1078 { .name
= "ses", .gpio
= 1 << 4 },
1081 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
1082 { .name
= "wps", .gpio
= 1 << 2, .polarity
= REVERSE
},
1083 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
1084 { .name
= "connected", .gpio
= 1 << 0, .polarity
= REVERSE
},
1089 .name
= "Microsoft MN-700",
1091 { .name
= "reset", .gpio
= 1 << 7 },
1094 { .name
= "power", .gpio
= 1 << 6, .polarity
= NORMAL
},
1099 .name
= "Edimax PS-1208MFG",
1101 { .name
= "reset", .gpio
= 1 << 4 },
1104 { .name
= "status", .gpio
= 1 << 1, .polarity
= NORMAL
},
1105 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
1110 static struct platform_t __init
*platform_detect_legacy(void)
1112 char *boardnum
, *boardtype
, *buf
;
1114 if (strcmp(getvar("nvram_type"), "cfe") == 0)
1115 return &platforms
[WGT634U
];
1118 /* no easy model number, attempt to guess */
1119 boardnum
= getvar("boardnum");
1120 boardtype
= getvar("boardtype");
1122 if (!strcmp(boardnum
, "20070615")) { /* Linksys WRT600N v1/V1.1 */
1123 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "0") && !strcmp(getvar("switch_type"),"BCM5395"))
1124 return &platforms
[WRT600NV11
];
1126 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "0"))
1127 return &platforms
[WRT600N
];
1130 if (startswith(getvar("pmon_ver"), "CFE")) {
1131 /* CFE based - newer hardware */
1132 if (!strcmp(boardnum
, "42")) { /* Linksys */
1133 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "1"))
1134 return &platforms
[WRT350N
];
1136 if (!strcmp(boardtype
, "0x0101") && !strcmp(getvar("boot_ver"), "v3.6"))
1137 return &platforms
[WRT54G3G
];
1139 if (!strcmp(getvar("et1phyaddr"),"5") && !strcmp(getvar("et1mdcport"), "1"))
1140 return &platforms
[WRTSL54GS
];
1142 /* default to WRT54G */
1143 return &platforms
[WRT54G
];
1145 if (!strcmp(boardnum
, "1024") && !strcmp(boardtype
, "0x0446"))
1146 return &platforms
[WAP54GV2
];
1148 if (!strcmp(boardnum
, "8") && !strcmp(boardtype
, "0x048e"))
1149 return &platforms
[WL1600GL
];
1152 if (!strcmp(boardnum
, "44") || !strcmp(boardnum
, "44\r")) {
1153 if (!strcmp(boardtype
,"0x0101") || !strcmp(boardtype
, "0x0101\r"))
1154 return &platforms
[TM2300V2
]; /* Dell TrueMobile 2300 v2 */
1157 if (!strcmp(boardnum
, "45")) { /* ASUS */
1158 if (!strcmp(boardtype
,"0x0472"))
1159 return &platforms
[WL500W
];
1160 else if (!strcmp(boardtype
,"0x467"))
1161 return &platforms
[WL320GE
];
1163 return &platforms
[WL500GD
];
1166 if (!strcmp(boardnum
, "10496"))
1167 return &platforms
[USR5461
];
1169 if (!strcmp(getvar("boardtype"), "0x0101") && !strcmp(getvar("boardrev"), "0x10")) /* SE505V2 With Modified CFE */
1170 return &platforms
[SE505V2
];
1172 if (!strcmp(boardtype
, "0x048e") && !strcmp(getvar("boardrev"),"0x35") &&
1173 !strcmp(getvar("boardflags"), "0x750")) /* D-Link DIR-320 */
1174 return &platforms
[DIR320
];
1176 if (!strncmp(boardnum
, "TH",2) && !strcmp(boardtype
,"0x042f")) {
1177 return &platforms
[WDNetCenter
];
1180 if (!strcmp(boardtype
,"0x0472") && !strcmp(getvar("cardbus"), "1")) { /* Netgear WNR834B V1 and V2*/
1181 if (!strcmp(boardnum
, "08") || !strcmp(boardnum
, "8"))
1182 return &platforms
[WNR834BV1
];
1183 if (!strcmp(boardnum
, "01") || !strcmp(boardnum
, "1"))
1184 return &platforms
[WNR834BV2
];
1187 } else { /* PMON based - old stuff */
1188 if ((simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 9) &&
1189 (simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 30)) {
1190 return &platforms
[WR850GV1
];
1192 if (startswith(boardtype
, "bcm94710dev")) {
1193 if (!strcmp(boardnum
, "42"))
1194 return &platforms
[WRT54GV1
];
1195 if (simple_strtoul(boardnum
, NULL
, 0) == 2)
1196 return &platforms
[WAP54GV1
];
1198 /* MN-700 has also hardware_version 'WL500-...', so use boardnum */
1199 if (startswith(getvar("hardware_version"), "WL500-")) {
1200 if (!strcmp(getvar("boardnum"), "mn700"))
1201 return &platforms
[MN700
];
1203 return &platforms
[WL500G
];
1205 if (startswith(getvar("hardware_version"), "WL300-")) {
1206 /* Either WL-300g or WL-HDD, do more extensive checks */
1207 if ((simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 0) &&
1208 (simple_strtoul(getvar("et1phyaddr"), NULL
, 0) == 1))
1209 return &platforms
[WLHDD
];
1210 if ((simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 0) &&
1211 (simple_strtoul(getvar("et1phyaddr"), NULL
, 0) == 10))
1212 return &platforms
[WL300G
];
1214 /* Sitecom WL-105b */
1215 if (startswith(boardnum
, "2") && simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 1)
1216 return &platforms
[WL105B
];
1218 /* unknown asus stuff, probably bcm4702 */
1219 if (startswith(boardnum
, "asusX"))
1220 return &platforms
[ASUS_4702
];
1222 /* bcm4702 based Askey RT210W clones, Including:
1223 * Askey RT210W (duh?)
1225 * Belkin F5D7230-4 before version v1444 (MiniPCI slot, not integrated)
1227 if (!strcmp(boardtype
,"bcm94710r4")
1228 && !strcmp(boardnum
,"100")
1229 && !strcmp(getvar("pmon_ver"),"v1.03.12.bk")
1231 return &platforms
[RT210W
];
1235 if (buf
|| !strcmp(boardnum
, "00")) {/* probably buffalo */
1236 if (startswith(boardtype
, "bcm94710ap"))
1237 return &platforms
[BUFFALO_UNKNOWN_4710
];
1239 return &platforms
[BUFFALO_UNKNOWN
];
1242 if (startswith(getvar("CFEver"), "MotoWRv2") ||
1243 startswith(getvar("CFEver"), "MotoWRv3") ||
1244 !strcmp(getvar("MOTO_BOARD_TYPE"), "WR_FEM1")) {
1246 return &platforms
[WR850GV2V3
];
1249 if (!strcmp(boardnum
, "44") && !strcmp(getvar("boardflags"),"0x0388")) { /* Trendware TEW-411BRP+ */
1250 return &platforms
[TEW411BRPP
];
1253 if (startswith(boardnum
, "04FN")) /* SimpleTech SimpleShare */
1254 return &platforms
[STI_NAS
];
1256 if (!strcmp(boardnum
, "10") && !strcmp(getvar("boardrev"), "0x13")) /* D-Link DWL-3150 */
1257 return &platforms
[DWL3150
];
1259 if (!strcmp(boardnum
, "01") && !strcmp(boardtype
, "0x048e") && /* Edimax PS1208MFG */
1260 !strcmp(getvar("status_gpio"), "1")) /* gpio based detection */
1261 return &platforms
[PS1208MFG
];
1267 static struct platform_t __init
*platform_detect(void)
1269 enum bcm47xx_board board
;
1270 const char *board_name
;
1273 board
= bcm47xx_board_get();
1274 board_name
= bcm47xx_board_get_name();
1275 if (board
!= BCM47XX_BOARD_UNKNOWN
&& board
!= BCM47XX_BOARD_NON
)
1276 printk(MODULE_NAME
": kernel found a \"%s\"\n", board_name
);
1279 case BCM47XX_BOARD_ASUS_RTN16
:
1280 return &platforms
[RTN16
];
1281 case BCM47XX_BOARD_ASUS_WL330GE
:
1282 return &platforms
[WL330GE
];
1283 case BCM47XX_BOARD_ASUS_WL500GPV1
:
1284 return &platforms
[WL500GP
];
1285 case BCM47XX_BOARD_ASUS_WL500GPV2
:
1286 return &platforms
[WL500GPV2
];
1287 case BCM47XX_BOARD_ASUS_WL520GC
:
1288 return &platforms
[WL520GC
];
1289 case BCM47XX_BOARD_ASUS_WL520GU
:
1290 return &platforms
[WL520GU
];
1291 case BCM47XX_BOARD_ASUS_WL700GE
:
1292 return &platforms
[WL700GE
];
1293 case BCM47XX_BOARD_BELKIN_F7D4301
:
1294 return &platforms
[BELKIN_F7D4301
];
1295 case BCM47XX_BOARD_BUFFALO_WBR2_G54
:
1296 return &platforms
[WBR2_G54
];
1297 case BCM47XX_BOARD_BUFFALO_WHR2_A54G54
:
1298 return &platforms
[WHR2_A54G54
];
1299 case BCM47XX_BOARD_BUFFALO_WHR_G125
:
1300 return &platforms
[WHR_G125
];
1301 case BCM47XX_BOARD_BUFFALO_WHR_G54S
:
1302 return &platforms
[WHR_G54S
];
1303 case BCM47XX_BOARD_BUFFALO_WHR_HP_G54
:
1304 return &platforms
[WHR_HP_G54
];
1305 case BCM47XX_BOARD_BUFFALO_WLA2_G54L
:
1306 return &platforms
[WLA2_G54L
];
1307 case BCM47XX_BOARD_BUFFALO_WZR_G300N
:
1308 return &platforms
[WZR_G300N
];
1309 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54
:
1310 return &platforms
[WZR_RS_G54
];
1311 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54HP
:
1312 return &platforms
[WZR_RS_G54HP
];
1313 case BCM47XX_BOARD_DELL_TM2300
:
1314 return &platforms
[TM2300
];
1315 case BCM47XX_BOARD_DLINK_DIR130
:
1316 return &platforms
[DIR130
];
1317 case BCM47XX_BOARD_DLINK_DIR330
:
1318 return &platforms
[DIR330
];
1319 case BCM47XX_BOARD_LINKSYS_E1000V1
:
1320 return &platforms
[E1000V1
];
1321 case BCM47XX_BOARD_LINKSYS_E3000V1
:
1322 return &platforms
[E3000V1
];
1323 case BCM47XX_BOARD_LINKSYS_E3200V1
:
1324 return &platforms
[E3200V1
];
1325 case BCM47XX_BOARD_LINKSYS_WRT150NV1
:
1326 return &platforms
[WRT150NV1
];
1327 case BCM47XX_BOARD_LINKSYS_WRT150NV11
:
1328 return &platforms
[WRT150NV11
];
1329 case BCM47XX_BOARD_LINKSYS_WRT160NV1
:
1330 return &platforms
[WRT160NV1
];
1331 case BCM47XX_BOARD_LINKSYS_WRT160NV3
:
1332 return &platforms
[WRT160NV3
];
1333 case BCM47XX_BOARD_LINKSYS_WRT300NV11
:
1334 return &platforms
[WRT300NV11
];
1335 case BCM47XX_BOARD_LINKSYS_WRT54G3GV2
:
1336 return &platforms
[WRT54G3GV2_VF
];
1337 case BCM47XX_BOARD_LINKSYS_WRT610NV1
:
1338 return &platforms
[WRT610N
];
1339 case BCM47XX_BOARD_LINKSYS_WRT610NV2
:
1340 return &platforms
[WRT610NV2
];
1341 case BCM47XX_BOARD_MOTOROLA_WE800G
:
1342 return &platforms
[WE800G
];
1343 case BCM47XX_BOARD_MOTOROLA_WR850GP
:
1344 return &platforms
[WR850GP
];
1345 case BCM47XX_BOARD_MOTOROLA_WR850GV2V3
:
1346 return &platforms
[WR850GV2V3
];
1347 case BCM47XX_BOARD_NETGEAR_WNDR3400V1
:
1348 return &platforms
[WNDR3400V1
];
1349 case BCM47XX_BOARD_NETGEAR_WNDR3700V3
:
1350 return &platforms
[WNDR3700V3
];
1351 case BCM47XX_BOARD_UNKNOWN
:
1352 case BCM47XX_BOARD_NON
:
1353 printk(MODULE_NAME
": unknown board found, try legacy detect\n");
1354 printk(MODULE_NAME
": please open a ticket at https://dev.openwrt.org and attach the complete nvram\n");
1355 return platform_detect_legacy();
1357 printk(MODULE_NAME
": board was detected as \"%s\", but not gpio configuration available\n", board_name
);
1358 printk(MODULE_NAME
": now trying legacy detect\n");
1359 return platform_detect_legacy();
1363 static inline void ssb_maskset32(struct ssb_device
*dev
,
1364 u16 offset
, u32 mask
, u32 set
)
1366 ssb_write32(dev
, offset
, (ssb_read32(dev
, offset
) & mask
) | set
);
1369 static void gpio_set_irqenable(int enabled
, irqreturn_t (*handler
)(int, void *))
1373 irq
= gpio_to_irq(0);
1374 if (irq
== -EINVAL
) return;
1377 if (request_irq(irq
, handler
, IRQF_SHARED
, "gpio", handler
))
1380 free_irq(irq
, handler
);
1383 switch (bcm47xx_bus_type
) {
1384 #ifdef CONFIG_BCM47XX_SSB
1385 case BCM47XX_BUS_TYPE_SSB
:
1386 if (bcm47xx_bus
.ssb
.chipco
.dev
)
1387 ssb_maskset32(bcm47xx_bus
.ssb
.chipco
.dev
, SSB_CHIPCO_IRQMASK
, ~SSB_CHIPCO_IRQ_GPIO
, (enabled
? SSB_CHIPCO_IRQ_GPIO
: 0));
1390 #ifdef CONFIG_BCM47XX_BCMA
1391 case BCM47XX_BUS_TYPE_BCMA
:
1392 if (bcm47xx_bus
.bcma
.bus
.drv_cc
.core
)
1393 bcma_maskset32(bcm47xx_bus
.bcma
.bus
.drv_cc
.core
, BCMA_CC_IRQMASK
, ~BCMA_CC_IRQ_GPIO
, (enabled
? BCMA_CC_IRQ_GPIO
: 0));
1399 static void hotplug_button(struct work_struct
*work
)
1401 struct event_t
*event
= container_of(work
, struct event_t
, wq
);
1404 event
->skb
= alloc_skb(2048, GFP_KERNEL
);
1406 s
= skb_put(event
->skb
, strlen(event
->action
) + 2);
1407 sprintf(s
, "%s@", event
->action
);
1410 NETLINK_CB(event
->skb
).dst_group
= 1;
1411 broadcast_uevent(event
->skb
, 0, 1, GFP_KERNEL
);
1416 static irqreturn_t
button_handler(int irq
, void *dev_id
)
1421 in
= bcm47xx_gpio_in(~0) & platform
.button_mask
;
1422 bcm47xx_gpio_polarity(platform
.button_mask
, in
);
1423 changed
= platform
.button_polarity
^ in
;
1424 platform
.button_polarity
= in
;
1426 changed
&= ~bcm47xx_gpio_outen(0, 0);
1428 for (b
= platform
.buttons
; b
->name
; b
++) {
1429 struct event_t
*event
;
1431 if (!(b
->gpio
& changed
)) continue;
1435 if ((event
= (struct event_t
*)kzalloc (sizeof(struct event_t
), GFP_ATOMIC
))) {
1436 event
->seen
= (jiffies
- b
->seen
)/HZ
;
1437 event
->name
= b
->name
;
1438 event
->action
= b
->pressed
? "pressed" : "released";
1439 INIT_WORK(&event
->wq
, (void *)(void *)hotplug_button
);
1440 schedule_work(&event
->wq
);
1448 static void register_buttons(struct button_t
*b
)
1450 for (; b
->name
; b
++)
1451 platform
.button_mask
|= b
->gpio
;
1453 platform
.button_mask
&= ~gpiomask
;
1455 bcm47xx_gpio_outen(platform
.button_mask
, 0);
1456 bcm47xx_gpio_control(platform
.button_mask
, 0);
1457 platform
.button_polarity
= bcm47xx_gpio_in(~0) & platform
.button_mask
;
1458 bcm47xx_gpio_polarity(platform
.button_mask
, platform
.button_polarity
);
1459 bcm47xx_gpio_intmask(platform
.button_mask
, platform
.button_mask
);
1461 gpio_set_irqenable(1, button_handler
);
1464 static void unregister_buttons(struct button_t
*b
)
1466 bcm47xx_gpio_intmask(platform
.button_mask
, 0);
1468 gpio_set_irqenable(0, button_handler
);
1472 static void add_msg(struct event_t
*event
, char *msg
, int argv
)
1479 s
= skb_put(event
->skb
, strlen(msg
) + 1);
1483 static int fill_event (struct event_t
*event
)
1485 static char buf
[128];
1487 add_msg(event
, "HOME=/", 0);
1488 add_msg(event
, "PATH=/sbin:/bin:/usr/sbin:/usr/bin", 0);
1489 add_msg(event
, "SUBSYSTEM=button", 0);
1490 snprintf(buf
, 128, "ACTION=%s", event
->action
);
1491 add_msg(event
, buf
, 0);
1492 snprintf(buf
, 128, "BUTTON=%s", event
->name
);
1493 add_msg(event
, buf
, 0);
1494 snprintf(buf
, 128, "SEEN=%ld", event
->seen
);
1495 add_msg(event
, buf
, 0);
1496 snprintf(buf
, 128, "SEQNUM=%llu", uevent_next_seqnum());
1497 add_msg(event
, buf
, 0);
1503 * This should be extended to allow the platform to specify the pins and width
1504 * of the shift register. They're hardcoded for now because only the WNDR3700v3
1507 static void shiftreg_output(unsigned int val
)
1511 bcm47xx_gpio_out(SHIFTREG_DATA
, SHIFTREG_DATA
); /* init off, pull high */
1512 bcm47xx_gpio_out(SHIFTREG_CLK
, 0); /* init reset */
1515 for(mask
= 1 << (SHIFTREG_MAX_BITS
-1); mask
; mask
>>= 1)
1517 bcm47xx_gpio_out(SHIFTREG_DATA
, (val
& mask
) ? SHIFTREG_DATA
: 0);
1518 bcm47xx_gpio_out(SHIFTREG_CLK
, SHIFTREG_CLK
); /* pull high to trigger */
1519 bcm47xx_gpio_out(SHIFTREG_CLK
, 0); /* reset to low */
1523 static void set_led_shift(struct led_t
*led
)
1525 static u32 shiftreg
= 0;
1527 u32 pin
= (led
->gpio
& ~GPIO_TYPE_MASK
);
1535 /* Clock the bits out. */
1536 if (shiftreg
!= old
) {
1537 shiftreg_output(shiftreg
);
1541 static void set_led_extif(struct led_t
*led
)
1543 volatile u8
*addr
= (volatile u8
*) KSEG1ADDR(EXTIF_UART
) + (led
->gpio
& ~GPIO_TYPE_MASK
);
1551 static void led_flash(unsigned long dummy
) {
1556 for (l
= platform
.leds
; l
->name
; l
++) {
1557 if (!l
->flash
) continue;
1558 switch (l
->gpio
& GPIO_TYPE_MASK
) {
1559 case GPIO_TYPE_EXTIF
:
1561 l
->state
= !l
->state
;
1564 case GPIO_TYPE_SHIFT
:
1566 l
->state
= !l
->state
;
1569 case GPIO_TYPE_NORMAL
:
1578 u32 val
= ~bcm47xx_gpio_in(~0);
1580 bcm47xx_gpio_outen(mask
, mask
);
1581 bcm47xx_gpio_control(mask
, 0);
1582 bcm47xx_gpio_out(mask
, val
);
1584 if (mask
|| extif_blink
) {
1585 mod_timer(&led_timer
, jiffies
+ FLASH_TIME
);
1589 static ssize_t
diag_proc_read(struct file
*file
, char *buf
, size_t count
, loff_t
*ppos
)
1591 struct proc_dir_entry
*dent
= PDE(file
->f_dentry
->d_inode
);
1595 if ((page
= kmalloc(1024, GFP_KERNEL
)) == NULL
)
1598 if (dent
->data
!= NULL
) {
1599 struct prochandler_t
*handler
= (struct prochandler_t
*) dent
->data
;
1600 switch (handler
->type
) {
1602 struct led_t
* led
= (struct led_t
*) handler
->ptr
;
1603 u8 p
= (led
->polarity
== NORMAL
? 0 : 1);
1605 len
= sprintf(page
, "f\n");
1606 } else if ((led
->gpio
& GPIO_TYPE_MASK
) != GPIO_TYPE_NORMAL
) {
1607 len
= sprintf(page
, "%d\n", ((led
->state
^ p
) ? 1 : 0));
1609 u32 in
= (bcm47xx_gpio_in(~0) & led
->gpio
? 1 : 0);
1610 len
= sprintf(page
, "%d\n", ((in
^ p
) ? 1 : 0));
1615 len
= sprintf(page
, "%s\n", platform
.name
);
1618 len
= sprintf(page
, "0x%04x\n", gpiomask
);
1625 len
= min_t(int, len
- *ppos
, count
);
1626 if (copy_to_user(buf
, (page
+ *ppos
), len
)) {
1640 static ssize_t
diag_proc_write(struct file
*file
, const char *buf
, size_t count
, loff_t
*ppos
)
1642 struct proc_dir_entry
*dent
= PDE(file
->f_dentry
->d_inode
);
1646 if ((page
= kmalloc(count
+ 1, GFP_KERNEL
)) == NULL
)
1649 if (copy_from_user(page
, buf
, count
)) {
1655 if (dent
->data
!= NULL
) {
1656 struct prochandler_t
*handler
= (struct prochandler_t
*) dent
->data
;
1657 switch (handler
->type
) {
1659 struct led_t
*led
= (struct led_t
*) handler
->ptr
;
1660 int p
= (led
->polarity
== NORMAL
? 0 : 1);
1662 if (page
[0] == 'f') {
1667 if ((led
->gpio
& GPIO_TYPE_MASK
) == GPIO_TYPE_EXTIF
) {
1668 led
->state
= p
^ ((page
[0] == '1') ? 1 : 0);
1670 } else if ((led
->gpio
& GPIO_TYPE_MASK
) == GPIO_TYPE_SHIFT
) {
1671 led
->state
= p
^ ((page
[0] == '1') ? 1 : 0);
1674 bcm47xx_gpio_outen(led
->gpio
, led
->gpio
);
1675 bcm47xx_gpio_control(led
->gpio
, 0);
1676 bcm47xx_gpio_out(led
->gpio
, ((p
^ (page
[0] == '1')) ? led
->gpio
: 0));
1682 gpiomask
= simple_strtoul(page
, NULL
, 0);
1684 if (platform
.buttons
) {
1685 unregister_buttons(platform
.buttons
);
1686 register_buttons(platform
.buttons
);
1689 if (platform
.leds
) {
1690 unregister_leds(platform
.leds
);
1691 register_leds(platform
.leds
);
1702 static struct file_operations diag_proc_fops
= {
1703 read
: diag_proc_read
,
1704 write
: diag_proc_write
1707 static void register_leds(struct led_t
*l
)
1709 struct proc_dir_entry
*p
;
1714 leds
= proc_mkdir("led", diag
);
1718 for(; l
->name
; l
++) {
1719 if (l
->gpio
& gpiomask
)
1722 switch (l
->gpio
& GPIO_TYPE_MASK
) {
1723 case GPIO_TYPE_EXTIF
:
1727 case GPIO_TYPE_SHIFT
:
1728 mask
|= (SHIFTREG_DATA
| SHIFTREG_CLK
);
1729 oe_mask
|= (SHIFTREG_DATA
| SHIFTREG_CLK
);
1730 l
->state
= (l
->polarity
!= NORMAL
);
1733 case GPIO_TYPE_NORMAL
:
1735 if (l
->polarity
!= INPUT
) oe_mask
|= l
->gpio
;
1737 val
|= (l
->polarity
== NORMAL
)?0:l
->gpio
;
1741 if (l
->polarity
== INPUT
) continue;
1743 if ((p
= create_proc_entry(l
->name
, S_IRUSR
, leds
))) {
1744 l
->proc
.type
= PROC_LED
;
1746 p
->data
= (void *) &l
->proc
;
1747 p
->proc_fops
= &diag_proc_fops
;
1751 bcm47xx_gpio_outen(mask
, oe_mask
);
1752 bcm47xx_gpio_control(mask
, 0);
1753 bcm47xx_gpio_out(mask
, val
);
1754 bcm47xx_gpio_intmask(mask
, 0);
1757 static void unregister_leds(struct led_t
*l
)
1760 remove_proc_entry(l
->name
, leds
);
1762 remove_proc_entry("led", diag
);
1765 static int __init
diag_init(void)
1767 static struct proc_dir_entry
*p
;
1768 static struct platform_t
*detected
;
1770 detected
= platform_detect();
1772 printk(MODULE_NAME
": Router model not detected.\n");
1775 memcpy(&platform
, detected
, sizeof(struct platform_t
));
1777 printk(MODULE_NAME
": Detected '%s'\n", platform
.name
);
1778 if (platform
.platform_init
!= NULL
) {
1779 platform
.platform_init();
1782 if (!(diag
= proc_mkdir("diag", NULL
))) {
1783 printk(MODULE_NAME
": proc_mkdir on /proc/diag failed\n");
1787 if ((p
= create_proc_entry("model", S_IRUSR
, diag
))) {
1788 p
->data
= (void *) &proc_model
;
1789 p
->proc_fops
= &diag_proc_fops
;
1792 if ((p
= create_proc_entry("gpiomask", S_IRUSR
| S_IWUSR
, diag
))) {
1793 p
->data
= (void *) &proc_gpiomask
;
1794 p
->proc_fops
= &diag_proc_fops
;
1797 if (platform
.buttons
)
1798 register_buttons(platform
.buttons
);
1801 register_leds(platform
.leds
);
1806 static void __exit
diag_exit(void)
1808 del_timer(&led_timer
);
1810 if (platform
.buttons
)
1811 unregister_buttons(platform
.buttons
);
1814 unregister_leds(platform
.leds
);
1816 remove_proc_entry("model", diag
);
1817 remove_proc_entry("gpiomask", diag
);
1818 remove_proc_entry("diag", NULL
);
1821 module_init(diag_init
);
1822 module_exit(diag_exit
);
1824 MODULE_AUTHOR("Mike Baker, Felix Fietkau / OpenWrt.org");
1825 MODULE_LICENSE("GPL");