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;
124 BUFFALO_UNKNOWN_4710,
169 /* Western Digital */
185 static void __init bcm4780_init(void) {
188 /* Enables GPIO 3 that controls HDD and led power on ASUS WL-700gE */
189 printk(MODULE_NAME ": Spinning up HDD and enabling leds\n");
190 bcm47xx_gpio_outen(pin, pin);
191 bcm47xx_gpio_control(pin, 0);
192 bcm47xx_gpio_out(pin, pin);
194 /* Wait 5s, so the HDD can spin up */
195 set_current_state(TASK_INTERRUPTIBLE);
196 schedule_timeout(HZ * 5);
199 static void __init NetCenter_init(void) {
200 /* unset pin 6 (+12V) */
202 bcm47xx_gpio_outen(pin, pin);
203 bcm47xx_gpio_control(pin, 0);
204 bcm47xx_gpio_out(pin, pin);
205 /* unset pin 1 (turn off red led, blue will light alone if +5V comes up) */
207 bcm47xx_gpio_outen(pin, pin);
208 bcm47xx_gpio_control(pin, 0);
209 bcm47xx_gpio_out(pin, pin);
210 /* unset pin 3 (+5V) and wait 5 seconds (harddisk spin up) */
214 static void __init bcm57xx_init(void) {
217 /* FIXME: switch comes up, but port mappings/vlans not right */
218 bcm47xx_gpio_outen(pin, pin);
219 bcm47xx_gpio_control(pin, 0);
220 bcm47xx_gpio_out(pin, pin);
223 static struct platform_t __initdata platforms[] = {
226 .name = "Linksys WAP54G V1",
228 { .name = "reset", .gpio = 1 << 0 },
231 { .name = "diag", .gpio = 1 << 3 },
232 { .name = "wlan", .gpio = 1 << 4 },
236 .name = "Linksys WAP54G V2",
238 { .name = "reset", .gpio = 1 << 0 },
241 { .name = "wlan", .gpio = 1 << 5, .polarity = REVERSE },
242 /* GPIO 6 is b44 (eth0, LAN) PHY power */
246 .name = "Linksys WAP54G V3",
248 /* FIXME: verify this */
249 { .name = "reset", .gpio = 1 << 7 },
250 { .name = "ses", .gpio = 1 << 0 },
254 { .name = "ses", .gpio = 1 << 1 },
258 .name = "Linksys WRT54G V1.x",
260 { .name = "reset", .gpio = 1 << 6 },
263 { .name = "diag", .gpio = 0x13 | GPIO_TYPE_EXTIF, .polarity = NORMAL },
264 { .name = "dmz", .gpio = 0x12 | GPIO_TYPE_EXTIF, .polarity = NORMAL },
268 .name = "Linksys WRT54G/GS/GL",
270 { .name = "reset", .gpio = 1 << 6 },
271 { .name = "ses", .gpio = 1 << 4 },
274 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
275 { .name = "dmz", .gpio = 1 << 7, .polarity = REVERSE },
276 { .name = "ses_white", .gpio = 1 << 2, .polarity = REVERSE },
277 { .name = "ses_orange", .gpio = 1 << 3, .polarity = REVERSE },
278 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
282 .name = "Linksys WRTSL54GS",
284 { .name = "reset", .gpio = 1 << 6 },
285 { .name = "ses", .gpio = 1 << 4 },
288 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
289 { .name = "dmz", .gpio = 1 << 0, .polarity = REVERSE },
290 { .name = "ses_white", .gpio = 1 << 5, .polarity = REVERSE },
291 { .name = "ses_orange", .gpio = 1 << 7, .polarity = REVERSE },
295 .name = "Linksys WRT54G3G",
297 { .name = "reset", .gpio = 1 << 6 },
298 { .name = "3g", .gpio = 1 << 4 },
301 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
302 { .name = "dmz", .gpio = 1 << 7, .polarity = REVERSE },
303 { .name = "3g_green", .gpio = 1 << 2, .polarity = NORMAL },
304 { .name = "3g_blue", .gpio = 1 << 3, .polarity = NORMAL },
305 { .name = "3g_blink", .gpio = 1 << 5, .polarity = NORMAL },
309 .name = "Linksys WRT54G3GV2-VF",
311 { .name = "reset", .gpio = 1 << 6 },
312 { .name = "3g", .gpio = 1 << 5 },
315 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
316 { .name = "3g_green", .gpio = 1 << 2, .polarity = NORMAL },
317 { .name = "3g_blue", .gpio = 1 << 3, .polarity = NORMAL },
321 .name = "Linksys WRT150N V1",
323 { .name = "reset", .gpio = 1 << 6 },
324 { .name = "ses", .gpio = 1 << 4 },
327 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
328 { .name = "ses_green", .gpio = 1 << 5, .polarity = REVERSE },
329 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE },
333 .name = "Linksys WRT150N V1.1",
335 { .name = "reset", .gpio = 1 << 6 },
336 { .name = "ses", .gpio = 1 << 4 },
339 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
340 { .name = "ses_green", .gpio = 1 << 5, .polarity = REVERSE },
341 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE },
345 .name = "Linksys WRT160N v1.x",
347 { .name = "reset", .gpio = 1 << 6 },
348 { .name = "ses", .gpio = 1 << 4 },
351 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
352 { .name = "ses_blue", .gpio = 1 << 5, .polarity = REVERSE },
353 { .name = "ses_orange", .gpio = 1 << 3, .polarity = REVERSE },
357 .name = "Linksys WRT160N V3",
359 { .name = "reset", .gpio = 1 << 6 },
360 { .name = "ses", .gpio = 1 << 5 },
363 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
364 { .name = "ses_blue", .gpio = 1 << 4, .polarity = REVERSE },
365 { .name = "ses_orange", .gpio = 1 << 2, .polarity = REVERSE },
369 .name = "Linksys WRT300N V1.1",
371 { .name = "reset", .gpio = 1 << 6 }, // "Reset" on back panel
372 { .name = "ses", .gpio = 1 << 4 }, // "Reserved" on top panel
375 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL }, // "Power"
376 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE }, // "Security" Amber
377 { .name = "ses_green", .gpio = 1 << 5, .polarity = REVERSE }, // "Security" Green
379 .platform_init = bcm57xx_init,
382 .name = "Linksys WRT350N",
384 { .name = "reset", .gpio = 1 << 6 },
385 { .name = "ses", .gpio = 1 << 8 },
388 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
389 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE },
390 { .name = "ses_green", .gpio = 1 << 9, .polarity = REVERSE },
391 { .name = "usb_blink", .gpio = 1 << 10, .polarity = REVERSE },
392 { .name = "usb", .gpio = 1 << 11, .polarity = REVERSE },
394 .platform_init = bcm57xx_init,
397 .name = "Linksys WRT600N",
399 { .name = "reset", .gpio = 1 << 6 },
400 { .name = "ses", .gpio = 1 << 7 },
403 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE }, // Power LED
404 { .name = "usb", .gpio = 1 << 3, .polarity = REVERSE }, // USB LED
405 { .name = "wl0_ses_amber", .gpio = 1 << 8, .polarity = REVERSE }, // 2.4Ghz LED Amber
406 { .name = "wl0_ses_green", .gpio = 1 << 9, .polarity = REVERSE }, // 2.4Ghz LED Green
407 { .name = "wl1_ses_amber", .gpio = 1 << 10, .polarity = REVERSE }, // 5.6Ghz LED Amber
408 { .name = "wl1_ses_green", .gpio = 1 << 11, .polarity = REVERSE }, // 5.6Ghz LED Green
410 .platform_init = bcm57xx_init,
413 .name = "Linksys WRT600N V1.1",
415 { .name = "reset", .gpio = 1 << 6 },
416 { .name = "ses", .gpio = 1 << 7 },
419 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE }, // Power LED
420 { .name = "usb", .gpio = 1 << 3, .polarity = REVERSE }, // USB LED
421 { .name = "wl0_ses_amber", .gpio = 1 << 8, .polarity = REVERSE }, // 2.4Ghz LED Amber
422 { .name = "wl0_ses_green", .gpio = 1 << 9, .polarity = REVERSE }, // 2.4Ghz LED Green
423 { .name = "wl1_ses_amber", .gpio = 1 << 10, .polarity = REVERSE }, // 5.6Ghz LED Amber
424 { .name = "wl1_ses_green", .gpio = 1 << 11, .polarity = REVERSE }, // 5.6Ghz LED Green
426 .platform_init = bcm57xx_init,
429 .name = "Linksys WRT610N",
431 { .name = "reset", .gpio = 1 << 6 },
432 { .name = "ses", .gpio = 1 << 8 },
435 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL }, // Power LED
436 { .name = "usb", .gpio = 1 << 0, .polarity = REVERSE }, // USB LED
437 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE }, // WiFi protected setup LED amber
438 { .name = "ses_blue", .gpio = 1 << 9, .polarity = REVERSE }, // WiFi protected setup LED blue
442 .name = "Linksys WRT610N V2",
444 { .name = "reset", .gpio = 1 << 6 },
445 { .name = "ses", .gpio = 1 << 4 },
448 { .name = "power", .gpio = 1 << 5, .polarity = NORMAL }, // Power LED
449 { .name = "usb", .gpio = 1 << 7, .polarity = NORMAL }, // USB LED
450 { .name = "ses_amber", .gpio = 1 << 0, .polarity = REVERSE }, // WiFi protected setup LED amber
451 { .name = "ses_blue", .gpio = 1 << 3, .polarity = REVERSE }, // WiFi protected setup LED blue
452 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL }, // Wireless LED
455 /* same hardware as WRT160NV3 and Cisco Valet M10V1, but different board detection, combine? */
457 .name = "Linksys E1000 V1",
459 { .name = "reset", .gpio = 1 << 6 },
460 { .name = "wps", .gpio = 1 << 5 }, /* nvram get gpio5=wps_button */
463 /** turns on leds for all ethernet ports (wan too)
464 * this also disconnects some, or maybe all, ethernet ports
465 * 1: leds work normally
466 * 0: all lit all the time */
467 /* nvram get gpio3=robo_reset */
468 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
469 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
470 { .name = "ses_blue", .gpio = 1 << 4, .polarity = REVERSE }, /* nvram get gpio4=wps_led */
471 { .name = "ses_orange", .gpio = 1 << 2, .polarity = REVERSE }, /* nvram get gpio2=wps_status_led */
475 .name = "Linksys E3000 V1",
477 { .name = "reset", .gpio = 1 << 6 },
478 { .name = "ses", .gpio = 1 << 4 },
481 { .name = "power", .gpio = 1 << 5, .polarity = NORMAL }, // Power LED
482 { .name = "usb", .gpio = 1 << 7, .polarity = NORMAL }, // USB LED
483 { .name = "ses_amber", .gpio = 1 << 0, .polarity = REVERSE }, // WiFi protected setup LED amber
484 { .name = "ses_blue", .gpio = 1 << 3, .polarity = REVERSE }, // WiFi protected setup LED blue
485 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL }, // Wireless LED
489 .name = "Linksys E3200 V1",
491 /* { .name = "switch", .gpio = 1 << 4 },*/ /* nvram get gpio4=robo_reset */
492 { .name = "reset", .gpio = 1 << 5 }, /* nvram get reset_gpio=5 */
493 { .name = "wps", .gpio = 1 << 8 }, /* nvram get gpio8=wps_button */
494 /* { .name = "wombo", .gpio = 1 << 23 },*/ /* nvram get gpio23=wombo_reset - wireless on motherboard */
497 { .name = "power", .gpio = 1 << 3, .polarity = REVERSE }, /* Power LED */
501 .name = "Linksys E4200 V1",
503 { .name = "reset", .gpio = 1 << 6 },
504 { .name = "wps", .gpio = 1 << 4 },
507 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
512 .name = "ASUS WL-HDD",
514 { .name = "reset", .gpio = 1 << 6 },
517 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
518 { .name = "usb", .gpio = 1 << 2, .polarity = REVERSE },
522 .name = "ASUS WL-300g",
524 { .name = "reset", .gpio = 1 << 6 },
527 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
531 .name = "ASUS WL-320gE/WL-320gP",
533 { .name = "reset", .gpio = 1 << 6 },
536 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
537 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE },
538 { .name = "link", .gpio = 1 << 11, .polarity = REVERSE },
542 .name = "ASUS WL-330gE",
544 { .name = "reset", .gpio = 1 << 2 },
547 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
551 .name = "ASUS WL-500g",
553 { .name = "reset", .gpio = 1 << 6 },
556 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
560 .name = "ASUS WL-500g Deluxe",
562 { .name = "reset", .gpio = 1 << 6 },
565 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
569 .name = "ASUS WL-500g Premium",
571 { .name = "reset", .gpio = 1 << 0 },
572 { .name = "ses", .gpio = 1 << 4 },
575 { .name = "power", .gpio = 1 << 1, .polarity = REVERSE },
579 .name = "ASUS WL-500g Premium V2",
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-500W",
592 { .name = "reset", .gpio = 1 << 6 },
593 { .name = "ses", .gpio = 1 << 7 },
596 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
600 .name = "ASUS WL-520GC",
602 { .name = "reset", .gpio = 1 << 2 },
603 { .name = "ses", .gpio = 1 << 3 },
606 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
607 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
611 .name = "ASUS WL-520gU",
613 { .name = "reset", .gpio = 1 << 2 },
614 { .name = "ses", .gpio = 1 << 3 },
617 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
618 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
622 .name = "ASUS (unknown, BCM4702)",
624 { .name = "reset", .gpio = 1 << 6 },
627 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
631 .name = "ASUS WL-700gE",
633 { .name = "reset", .gpio = 1 << 7 }, // on back, hardwired, always resets device regardless OS state
634 { .name = "ses", .gpio = 1 << 4 }, // on back, actual name ezsetup
635 { .name = "power", .gpio = 1 << 0 }, // on front
636 { .name = "copy", .gpio = 1 << 6 }, // on front
640 // GPIO that controls power led also enables/disables some essential functions
643 { .name = "power", .gpio = 1 << 3, .polarity = NORMAL }, // actual name power
645 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE }, // actual name ready
647 .platform_init = bcm4780_init,
650 .name = "ASUS RT-N12",
652 { .name = "wps", .gpio = 1 << 0 },
653 { .name = "reset", .gpio = 1 << 1 },
654 // this is the router/repeater/ap switch
655 { .name = "sw1", .gpio = 1 << 4 },
656 { .name = "sw2", .gpio = 1 << 5 },
657 { .name = "sw3", .gpio = 1 << 6 },
660 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE },
661 { .name = "wlan", .gpio = 1 << 7, .polarity = NORMAL },
662 // gpio3 forces WAN and LAN1-4 all on
663 //{ .name = "eth", .gpio = 1 << 3, .polarity = REVERSE },
667 .name = "ASUS RT-N16",
669 { .name = "reset", .gpio = 1 << 8 },
670 { .name = "ses", .gpio = 1 << 5 },
673 { .name = "power", .gpio = 1 << 1, .polarity = REVERSE },
674 { .name = "wlan", .gpio = 1 << 7, .polarity = NORMAL },
679 .name = "Buffalo WHR-G54S",
681 { .name = "reset", .gpio = 1 << 4 },
682 { .name = "bridge", .gpio = 1 << 5 },
683 { .name = "ses", .gpio = 1 << 0 },
686 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
687 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
688 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
689 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
690 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
694 .name = "Buffalo WBR2-G54",
697 { .name = "reset", .gpio = 1 << 7 },
700 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
704 .name = "Buffalo WHR-HP-G54",
706 { .name = "reset", .gpio = 1 << 4 },
707 { .name = "bridge", .gpio = 1 << 5 },
708 { .name = "ses", .gpio = 1 << 0 },
711 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
712 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
713 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
714 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
715 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
719 .name = "Buffalo WHR-G125",
721 { .name = "reset", .gpio = 1 << 4 },
722 { .name = "bridge", .gpio = 1 << 5 },
723 { .name = "ses", .gpio = 1 << 0 },
726 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
727 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
728 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
729 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
730 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
734 .name = "Buffalo WHR2-A54G54",
736 { .name = "reset", .gpio = 1 << 4 },
739 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
743 .name = "Buffalo WLA2-G54L",
746 { .name = "reset", .gpio = 1 << 7 },
749 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
753 .name = "Buffalo WZR-G300N",
755 { .name = "reset", .gpio = 1 << 4 },
758 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
759 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
760 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
764 .name = "Buffalo WZR-RS-G54",
766 { .name = "ses", .gpio = 1 << 0 },
767 { .name = "reset", .gpio = 1 << 4 },
770 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
771 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
772 { .name = "vpn", .gpio = 1 << 1, .polarity = REVERSE },
776 .name = "Buffalo WZR-RS-G54HP",
778 { .name = "ses", .gpio = 1 << 0 },
779 { .name = "reset", .gpio = 1 << 4 },
782 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
783 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
784 { .name = "vpn", .gpio = 1 << 1, .polarity = REVERSE },
787 [BUFFALO_UNKNOWN] = {
788 .name = "Buffalo (unknown)",
790 { .name = "reset", .gpio = 1 << 7 },
793 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
796 [BUFFALO_UNKNOWN_4710] = {
797 .name = "Buffalo (unknown, BCM4710)",
799 { .name = "reset", .gpio = 1 << 4 },
802 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
807 .name = "Siemens SE505 V1",
809 /* No usable buttons */
812 // { .name = "power", .gpio = 1 << 0 .polarity = REVERSE }, // Usable when retrofitting D26 (?)
813 { .name = "dmz", .gpio = 1 << 4, .polarity = REVERSE }, // actual name WWW
814 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
818 .name = "Siemens SE505 V2",
820 /* No usable buttons */
823 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
824 { .name = "dmz", .gpio = 1 << 0, .polarity = REVERSE }, // actual name WWW
825 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
830 .name = "U.S. Robotics USR5461",
832 /* No usable buttons */
835 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
836 { .name = "printer", .gpio = 1 << 1, .polarity = REVERSE },
841 .name = "Dell TrueMobile 2300",
843 { .name = "reset", .gpio = 1 << 0 },
846 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
847 { .name = "power", .gpio = 1 << 7, .polarity = REVERSE },
851 .name = "Dell TrueMobile 2300 v2",
853 { .name = "reset", .gpio = 1 << 0 },
856 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
857 { .name = "power", .gpio = 1 << 7, .polarity = REVERSE },
862 .name = "Motorola WE800G",
864 { .name = "reset", .gpio = 1 << 0 },
867 { .name = "power", .gpio = 1 << 4, .polarity = NORMAL },
868 { .name = "diag", .gpio = 1 << 2, .polarity = REVERSE },
869 { .name = "wlan_amber", .gpio = 1 << 1, .polarity = NORMAL },
873 .name = "Motorola WR850G V1",
875 { .name = "reset", .gpio = 1 << 0 },
878 { .name = "power", .gpio = 1 << 4, .polarity = NORMAL },
879 { .name = "diag", .gpio = 1 << 3, .polarity = REVERSE },
880 { .name = "dmz", .gpio = 1 << 6, .polarity = NORMAL },
881 { .name = "wlan_red", .gpio = 1 << 5, .polarity = REVERSE },
882 { .name = "wlan_green", .gpio = 1 << 7, .polarity = REVERSE },
886 .name = "Motorola WR850G V2/V3",
888 { .name = "reset", .gpio = 1 << 5 },
891 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
892 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
893 { .name = "wan", .gpio = 1 << 6, .polarity = INPUT },
894 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
898 .name = "Motorola WR850GP",
900 { .name = "reset", .gpio = 1 << 5 },
903 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
904 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
905 { .name = "dmz", .gpio = 1 << 6, .polarity = REVERSE },
906 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
912 .name = "Belkin (unknown)",
913 /* FIXME: verify & add detection */
915 { .name = "reset", .gpio = 1 << 7 },
918 { .name = "power", .gpio = 1 << 5, .polarity = NORMAL },
919 { .name = "wlan", .gpio = 1 << 3, .polarity = NORMAL },
920 { .name = "connected", .gpio = 1 << 0, .polarity = NORMAL },
924 .name = "Belkin PlayMax F7D4301",
926 { .name = "reset", .gpio = 1 << 6 },
927 { .name = "wps", .gpio = 1 << 8 },
930 { .name = "power", .gpio = 1 << 11, .polarity = REVERSE },
931 { .name = "wlan", .gpio = 1 << 13, .polarity = REVERSE },
932 { .name = "led0", .gpio = 1 << 14, .polarity = REVERSE },
933 { .name = "led1", .gpio = 1 << 15, .polarity = REVERSE },
938 .name = "Netgear WGT634U",
940 { .name = "reset", .gpio = 1 << 2 },
943 { .name = "power", .gpio = 1 << 3, .polarity = NORMAL },
948 .name = "Netgear WNR834B V1",
949 .buttons = { /* TODO: add reset button and confirm LEDs - GPIO from dd-wrt */ },
951 { .name = "power", .gpio = 1 << 4, .polarity = REVERSE },
952 { .name = "diag", .gpio = 1 << 5, .polarity = REVERSE },
953 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
958 .name = "Netgear WNR834B V2",
960 { .name = "reset", .gpio = 1 << 6 },
963 { .name = "power", .gpio = 1 << 2, .polarity = NORMAL },
964 { .name = "diag", .gpio = 1 << 3, .polarity = NORMAL },
965 { .name = "connected", .gpio = 1 << 7, .polarity = NORMAL },
969 .name = "Netgear WNDR3400 V1",
971 /* nvram get gpio5=robo_reset */
972 { .name = "reset", .gpio = 1 << 4 },
973 { .name = "wps", .gpio = 1 << 6 },
974 { .name = "wlan", .gpio = 1 << 8 },
977 { .name = "wlan", .gpio = 0 << 0, .polarity = NORMAL },
978 { .name = "connected", .gpio = 1 << 0, .polarity = NORMAL },
979 { .name = "power", .gpio = 1 << 3, .polarity = NORMAL },
980 { .name = "diag", .gpio = 1 << 7, .polarity = NORMAL },
981 { .name = "usb", .gpio = 1 << 2, .polarity = REVERSE },
985 .name = "Netgear WNDR3700 V3",
987 /* { .name = "usb", .gpio = 1 << 1 }, */ /* this button doesn't seem to exist. */
988 { .name = "wlan", .gpio = 1 << 2 },
989 { .name = "reset", .gpio = 1 << 3 },
990 { .name = "wps", .gpio = 1 << 4 },
991 /* { .name = "switch", .gpio = 1 << 5 },*/ /* nvram get gpio5=robo_reset */
994 { .name = "power", .gpio = (1 << 0) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
995 { .name = "diag", .gpio = (1 << 1) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
996 /* WAN LED doesn't respond to GPIO control. The switch is probably driving it.
997 * { .name = "wan", .gpio = (1 << 2) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
999 { .name = "wlan2g", .gpio = (1 << 3) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1000 { .name = "wlan5g", .gpio = (1 << 4) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1001 { .name = "usb", .gpio = (1 << 5) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1002 { .name = "wps", .gpio = (1 << 6) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1003 { .name = "wlan", .gpio = (1 << 7) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1008 .name = "Trendware TEW411BRP+",
1010 { /* No usable buttons */ },
1013 { .name = "power", .gpio = 1 << 7, .polarity = NORMAL },
1014 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL },
1015 { .name = "bridge", .gpio = 1 << 6, .polarity = NORMAL },
1020 .name = "SimpleTech SimpleShare NAS",
1022 { .name = "reset", .gpio = 1 << 0 }, // Power button on back, named reset to enable failsafe.
1025 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE }, // actual name ready
1027 .platform_init = bcm4780_init,
1031 .name = "D-Link DIR-130",
1033 { .name = "reset", .gpio = 1 << 3},
1034 { .name = "reserved", .gpio = 1 << 7},
1037 { .name = "diag", .gpio = 1 << 0},
1038 { .name = "blue", .gpio = 1 << 6},
1042 .name = "D-Link DIR-320",
1044 { .name = "reserved", .gpio = 1 << 6},
1045 { .name = "reset", .gpio = 1 << 7},
1048 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
1049 { .name = "diag", .gpio = 1 << 1, .polarity = NORMAL }, /* "status led */
1050 { .name = "red", .gpio = 1 << 3, .polarity = REVERSE },
1051 { .name = "blue", .gpio = 1 << 4, .polarity = REVERSE },
1052 { .name = "usb", .gpio = 1 << 5, .polarity = NORMAL },
1056 .name = "D-Link DIR-330",
1058 { .name = "reset", .gpio = 1 << 3},
1059 { .name = "reserved", .gpio = 1 << 7},
1062 { .name = "diag", .gpio = 1 << 0},
1063 { .name = "usb", .gpio = 1 << 4},
1064 { .name = "blue", .gpio = 1 << 6},
1068 .name = "D-Link DWL-3150",
1070 { .name = "reset", .gpio = 1 << 7},
1073 { .name = "diag", .gpio = 1 << 2},
1074 { .name = "status", .gpio = 1 << 1},
1079 .name = "Sitecom WL-105b",
1081 { .name = "reset", .gpio = 1 << 10},
1084 { .name = "wlan", .gpio = 1 << 4},
1085 { .name = "power", .gpio = 1 << 3},
1088 /* Western Digital Net Center */
1090 .name = "Western Digital NetCenter",
1092 { .name = "power", .gpio = 1 << 0},
1093 { .name = "reset", .gpio = 1 << 7},
1095 .platform_init = NetCenter_init,
1097 /* Askey (and clones) */
1099 .name = "Askey RT210W",
1101 /* Power button is hard-wired to hardware reset */
1102 /* but is also connected to GPIO 7 (probably for bootloader recovery) */
1103 { .name = "power", .gpio = 1 << 7},
1106 /* These were verified and named based on Belkin F5D4230-4 v1112 */
1107 { .name = "connected", .gpio = 1 << 0, .polarity = REVERSE },
1108 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
1109 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
1113 .name = "OvisLink WL-1600GL",
1115 { .name = "reset", .gpio = 1 << 3 },
1116 { .name = "ses", .gpio = 1 << 4 },
1119 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
1120 { .name = "wps", .gpio = 1 << 2, .polarity = REVERSE },
1121 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
1122 { .name = "connected", .gpio = 1 << 0, .polarity = REVERSE },
1127 .name = "Microsoft MN-700",
1129 { .name = "reset", .gpio = 1 << 7 },
1132 { .name = "power", .gpio = 1 << 6, .polarity = NORMAL },
1137 .name = "Edimax PS-1208MFG",
1139 { .name = "reset", .gpio = 1 << 4 },
1142 { .name = "status", .gpio = 1 << 1, .polarity = NORMAL },
1143 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
1148 static struct platform_t __init *platform_detect_legacy(void)
1150 char *boardnum, *boardtype;
1152 if (strcmp(getvar("nvram_type"), "cfe") == 0)
1153 return &platforms[WGT634U];
1156 /* no easy model number, attempt to guess */
1157 boardnum = getvar("boardnum");
1158 boardtype = getvar("boardtype");
1160 if (!strcmp(boardnum, "20070615")) { /* Linksys WRT600N v1/V1.1 */
1161 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "0") && !strcmp(getvar("switch_type"),"BCM5395"))
1162 return &platforms[WRT600NV11];
1164 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "0"))
1165 return &platforms[WRT600N];
1168 if (startswith(getvar("pmon_ver"), "CFE")) {
1169 /* CFE based - newer hardware */
1170 if (!strcmp(boardnum, "42")) { /* Linksys */
1171 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "1"))
1172 return &platforms[WRT350N];
1174 if (!strcmp(boardtype, "0x0101") && !strcmp(getvar("boot_ver"), "v3.6"))
1175 return &platforms[WRT54G3G];
1177 /* default to WRT54G */
1178 return &platforms[WRT54G];
1180 if (!strcmp(boardnum, "1024") && !strcmp(boardtype, "0x0446"))
1181 return &platforms[WAP54GV2];
1183 if (!strcmp(boardnum, "8") && !strcmp(boardtype, "0x048e"))
1184 return &platforms[WL1600GL];
1187 if (!strcmp(boardnum, "44") || !strcmp(boardnum, "44\r")) {
1188 if (!strcmp(boardtype,"0x0101") || !strcmp(boardtype, "0x0101\r"))
1189 return &platforms[TM2300V2]; /* Dell TrueMobile 2300 v2 */
1192 if (!strcmp(boardnum, "45")) { /* ASUS */
1193 if (!strcmp(boardtype,"0x0472"))
1194 return &platforms[WL500W];
1195 else if (!strcmp(boardtype,"0x467"))
1196 return &platforms[WL320GE];
1198 return &platforms[WL500GD];
1201 if (!strcmp(boardnum, "10496"))
1202 return &platforms[USR5461];
1204 if (!strcmp(getvar("boardtype"), "0x0101") && !strcmp(getvar("boardrev"), "0x10")) /* SE505V2 With Modified CFE */
1205 return &platforms[SE505V2];
1207 if (!strcmp(boardtype, "0x048e") && !strcmp(getvar("boardrev"),"0x35") &&
1208 !strcmp(getvar("boardflags"), "0x750")) /* D-Link DIR-320 */
1209 return &platforms[DIR320];
1211 if (!strncmp(boardnum, "TH",2) && !strcmp(boardtype,"0x042f")) {
1212 return &platforms[WDNetCenter];
1215 if (!strcmp(boardtype,"0x0472") && !strcmp(getvar("cardbus"), "1")) { /* Netgear WNR834B V1 and V2*/
1216 if (!strcmp(boardnum, "08") || !strcmp(boardnum, "8"))
1217 return &platforms[WNR834BV1];
1218 if (!strcmp(boardnum, "01") || !strcmp(boardnum, "1"))
1219 return &platforms[WNR834BV2];
1222 } else { /* PMON based - old stuff */
1223 if ((simple_strtoul(getvar("GemtekPmonVer"), NULL, 0) == 9) &&
1224 (simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 30)) {
1225 return &platforms[WR850GV1];
1227 if (startswith(boardtype, "bcm94710dev")) {
1228 if (!strcmp(boardnum, "42"))
1229 return &platforms[WRT54GV1];
1230 if (simple_strtoul(boardnum, NULL, 0) == 2)
1231 return &platforms[WAP54GV1];
1233 /* MN-700 has also hardware_version 'WL500-...', so use boardnum */
1234 if (startswith(getvar("hardware_version"), "WL500-")) {
1235 if (!strcmp(getvar("boardnum"), "mn700"))
1236 return &platforms[MN700];
1238 return &platforms[WL500G];
1240 if (startswith(getvar("hardware_version"), "WL300-")) {
1241 /* Either WL-300g or WL-HDD, do more extensive checks */
1242 if ((simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 0) &&
1243 (simple_strtoul(getvar("et1phyaddr"), NULL, 0) == 1))
1244 return &platforms[WLHDD];
1245 if ((simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 0) &&
1246 (simple_strtoul(getvar("et1phyaddr"), NULL, 0) == 10))
1247 return &platforms[WL300G];
1249 /* Sitecom WL-105b */
1250 if (startswith(boardnum, "2") && simple_strtoul(getvar("GemtekPmonVer"), NULL, 0) == 1)
1251 return &platforms[WL105B];
1253 /* unknown asus stuff, probably bcm4702 */
1254 if (startswith(boardnum, "asusX"))
1255 return &platforms[ASUS_4702];
1257 /* bcm4702 based Askey RT210W clones, Including:
1258 * Askey RT210W (duh?)
1260 * Belkin F5D7230-4 before version v1444 (MiniPCI slot, not integrated)
1262 if (!strcmp(boardtype,"bcm94710r4")
1263 && !strcmp(boardnum ,"100")
1264 && !strcmp(getvar("pmon_ver"),"v1.03.12.bk")
1266 return &platforms[RT210W];
1270 if (boardnum || !strcmp(boardnum, "00")) {/* probably buffalo */
1271 if (startswith(boardtype, "bcm94710ap"))
1272 return &platforms[BUFFALO_UNKNOWN_4710];
1274 return &platforms[BUFFALO_UNKNOWN];
1277 if (startswith(getvar("CFEver"), "MotoWRv2") ||
1278 startswith(getvar("CFEver"), "MotoWRv3") ||
1279 !strcmp(getvar("MOTO_BOARD_TYPE"), "WR_FEM1")) {
1281 return &platforms[WR850GV2V3];
1284 if (!strcmp(boardnum, "44") && !strcmp(getvar("boardflags"),"0x0388")) { /* Trendware TEW-411BRP+ */
1285 return &platforms[TEW411BRPP];
1288 if (startswith(boardnum, "04FN")) /* SimpleTech SimpleShare */
1289 return &platforms[STI_NAS];
1291 if (!strcmp(boardnum, "10") && !strcmp(getvar("boardrev"), "0x13")) /* D-Link DWL-3150 */
1292 return &platforms[DWL3150];
1294 if (!strcmp(boardnum, "01") && !strcmp(boardtype, "0x048e") && /* Edimax PS1208MFG */
1295 !strcmp(getvar("status_gpio"), "1")) /* gpio based detection */
1296 return &platforms[PS1208MFG];
1302 static struct platform_t __init *platform_detect(void)
1304 enum bcm47xx_board board;
1305 const char *board_name;
1308 board = bcm47xx_board_get();
1309 board_name = bcm47xx_board_get_name();
1310 if (board != BCM47XX_BOARD_UNKNOWN && board != BCM47XX_BOARD_NON)
1311 printk(MODULE_NAME ": kernel found a \"%s\"\n", board_name);
1314 case BCM47XX_BOARD_ASUS_RTN12:
1315 return &platforms[RTN12];
1316 case BCM47XX_BOARD_ASUS_RTN16:
1317 return &platforms[RTN16];
1318 case BCM47XX_BOARD_ASUS_WL330GE:
1319 return &platforms[WL330GE];
1320 case BCM47XX_BOARD_ASUS_WL500GPV1:
1321 return &platforms[WL500GP];
1322 case BCM47XX_BOARD_ASUS_WL500GPV2:
1323 return &platforms[WL500GPV2];
1324 case BCM47XX_BOARD_ASUS_WL520GC:
1325 return &platforms[WL520GC];
1326 case BCM47XX_BOARD_ASUS_WL520GU:
1327 return &platforms[WL520GU];
1328 case BCM47XX_BOARD_ASUS_WL700GE:
1329 return &platforms[WL700GE];
1330 case BCM47XX_BOARD_BELKIN_F7D4301:
1331 return &platforms[BELKIN_F7D4301];
1332 case BCM47XX_BOARD_BUFFALO_WBR2_G54:
1333 return &platforms[WBR2_G54];
1334 case BCM47XX_BOARD_BUFFALO_WHR2_A54G54:
1335 return &platforms[WHR2_A54G54];
1336 case BCM47XX_BOARD_BUFFALO_WHR_G125:
1337 return &platforms[WHR_G125];
1338 case BCM47XX_BOARD_BUFFALO_WHR_G54S:
1339 return &platforms[WHR_G54S];
1340 case BCM47XX_BOARD_BUFFALO_WHR_HP_G54:
1341 return &platforms[WHR_HP_G54];
1342 case BCM47XX_BOARD_BUFFALO_WLA2_G54L:
1343 return &platforms[WLA2_G54L];
1344 case BCM47XX_BOARD_BUFFALO_WZR_G300N:
1345 return &platforms[WZR_G300N];
1346 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54:
1347 return &platforms[WZR_RS_G54];
1348 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54HP:
1349 return &platforms[WZR_RS_G54HP];
1350 case BCM47XX_BOARD_DELL_TM2300:
1351 return &platforms[TM2300];
1352 case BCM47XX_BOARD_DLINK_DIR130:
1353 return &platforms[DIR130];
1354 case BCM47XX_BOARD_DLINK_DIR330:
1355 return &platforms[DIR330];
1356 case BCM47XX_BOARD_LINKSYS_E1000V1:
1357 return &platforms[E1000V1];
1358 case BCM47XX_BOARD_LINKSYS_E3000V1:
1359 return &platforms[E3000V1];
1360 case BCM47XX_BOARD_LINKSYS_E3200V1:
1361 return &platforms[E3200V1];
1362 case BCM47XX_BOARD_LINKSYS_E4200V1:
1363 return &platforms[E4200V1];
1364 case BCM47XX_BOARD_LINKSYS_WRT150NV1:
1365 return &platforms[WRT150NV1];
1366 case BCM47XX_BOARD_LINKSYS_WRT150NV11:
1367 return &platforms[WRT150NV11];
1368 case BCM47XX_BOARD_LINKSYS_WRT160NV1:
1369 return &platforms[WRT160NV1];
1370 case BCM47XX_BOARD_LINKSYS_WRT160NV3:
1371 return &platforms[WRT160NV3];
1372 case BCM47XX_BOARD_LINKSYS_WRT300NV11:
1373 return &platforms[WRT300NV11];
1374 case BCM47XX_BOARD_LINKSYS_WRT54G3GV2:
1375 return &platforms[WRT54G3GV2_VF];
1376 case BCM47XX_BOARD_LINKSYS_WRT610NV1:
1377 return &platforms[WRT610N];
1378 case BCM47XX_BOARD_LINKSYS_WRT610NV2:
1379 return &platforms[WRT610NV2];
1380 case BCM47XX_BOARD_LINKSYS_WRTSL54GS:
1381 return &platforms[WRTSL54GS];
1382 case BCM47XX_BOARD_MOTOROLA_WE800G:
1383 return &platforms[WE800G];
1384 case BCM47XX_BOARD_MOTOROLA_WR850GP:
1385 return &platforms[WR850GP];
1386 case BCM47XX_BOARD_MOTOROLA_WR850GV2V3:
1387 return &platforms[WR850GV2V3];
1388 case BCM47XX_BOARD_NETGEAR_WNDR3400V1:
1389 return &platforms[WNDR3400V1];
1390 case BCM47XX_BOARD_NETGEAR_WNDR3700V3:
1391 return &platforms[WNDR3700V3];
1392 case BCM47XX_BOARD_UNKNOWN:
1393 case BCM47XX_BOARD_NON:
1394 printk(MODULE_NAME ": unknown board found, try legacy detect\n");
1395 printk(MODULE_NAME ": please open a ticket at https://dev.openwrt.org and attach the complete nvram\n");
1396 return platform_detect_legacy();
1398 printk(MODULE_NAME ": board was detected as \"%s\", but not gpio configuration available\n", board_name);
1399 printk(MODULE_NAME ": now trying legacy detect\n");
1400 return platform_detect_legacy();
1404 static inline void ssb_maskset32(struct ssb_device *dev,
1405 u16 offset, u32 mask, u32 set)
1407 ssb_write32(dev, offset, (ssb_read32(dev, offset) & mask) | set);
1410 static void gpio_set_irqenable(int enabled, irqreturn_t (*handler)(int, void *))
1414 irq = gpio_to_irq(0);
1415 if (irq == -EINVAL) return;
1418 if (request_irq(irq, handler, IRQF_SHARED, "gpio", handler))
1421 free_irq(irq, handler);
1424 switch (bcm47xx_bus_type) {
1425 #ifdef CONFIG_BCM47XX_SSB
1426 case BCM47XX_BUS_TYPE_SSB:
1427 if (bcm47xx_bus.ssb.chipco.dev)
1428 ssb_maskset32(bcm47xx_bus.ssb.chipco.dev, SSB_CHIPCO_IRQMASK, ~SSB_CHIPCO_IRQ_GPIO, (enabled ? SSB_CHIPCO_IRQ_GPIO : 0));
1431 #ifdef CONFIG_BCM47XX_BCMA
1432 case BCM47XX_BUS_TYPE_BCMA:
1433 if (bcm47xx_bus.bcma.bus.drv_cc.core)
1434 bcma_maskset32(bcm47xx_bus.bcma.bus.drv_cc.core, BCMA_CC_IRQMASK, ~BCMA_CC_IRQ_GPIO, (enabled ? BCMA_CC_IRQ_GPIO : 0));
1440 static void hotplug_button(struct work_struct *work)
1442 struct event_t *event = container_of(work, struct event_t, wq);
1445 event->skb = alloc_skb(2048, GFP_KERNEL);
1447 s = skb_put(event->skb, strlen(event->action) + 2);
1448 sprintf(s, "%s@", event->action);
1451 NETLINK_CB(event->skb).dst_group = 1;
1452 broadcast_uevent(event->skb, 0, 1, GFP_KERNEL);
1457 static irqreturn_t button_handler(int irq, void *dev_id)
1462 in = bcm47xx_gpio_in(~0) & platform.button_mask;
1463 bcm47xx_gpio_polarity(platform.button_mask, in);
1464 changed = platform.button_polarity ^ in;
1465 platform.button_polarity = in;
1467 changed &= ~bcm47xx_gpio_outen(0, 0);
1469 for (b = platform.buttons; b->name; b++) {
1470 struct event_t *event;
1472 if (!(b->gpio & changed)) continue;
1476 if ((event = (struct event_t *)kzalloc (sizeof(struct event_t), GFP_ATOMIC))) {
1477 event->seen = (jiffies - b->seen)/HZ;
1478 event->name = b->name;
1479 event->action = b->pressed ? "pressed" : "released";
1480 INIT_WORK(&event->wq, (void *)(void *)hotplug_button);
1481 schedule_work(&event->wq);
1489 static void register_buttons(struct button_t *b)
1491 for (; b->name; b++)
1492 platform.button_mask |= b->gpio;
1494 platform.button_mask &= ~gpiomask;
1496 bcm47xx_gpio_outen(platform.button_mask, 0);
1497 bcm47xx_gpio_control(platform.button_mask, 0);
1498 platform.button_polarity = bcm47xx_gpio_in(~0) & platform.button_mask;
1499 bcm47xx_gpio_polarity(platform.button_mask, platform.button_polarity);
1500 bcm47xx_gpio_intmask(platform.button_mask, platform.button_mask);
1502 gpio_set_irqenable(1, button_handler);
1505 static void unregister_buttons(struct button_t *b)
1507 bcm47xx_gpio_intmask(platform.button_mask, 0);
1509 gpio_set_irqenable(0, button_handler);
1513 static void add_msg(struct event_t *event, char *msg, int argv)
1520 s = skb_put(event->skb, strlen(msg) + 1);
1524 static int fill_event (struct event_t *event)
1526 static char buf[128];
1528 add_msg(event, "HOME=/", 0);
1529 add_msg(event, "PATH=/sbin:/bin:/usr/sbin:/usr/bin", 0);
1530 add_msg(event, "SUBSYSTEM=button", 0);
1531 snprintf(buf, 128, "ACTION=%s", event->action);
1532 add_msg(event, buf, 0);
1533 snprintf(buf, 128, "BUTTON=%s", event->name);
1534 add_msg(event, buf, 0);
1535 snprintf(buf, 128, "SEEN=%ld", event->seen);
1536 add_msg(event, buf, 0);
1537 snprintf(buf, 128, "SEQNUM=%llu", uevent_next_seqnum());
1538 add_msg(event, buf, 0);
1544 * This should be extended to allow the platform to specify the pins and width
1545 * of the shift register. They're hardcoded for now because only the WNDR3700v3
1548 static void shiftreg_output(unsigned int val)
1552 bcm47xx_gpio_out(SHIFTREG_DATA, SHIFTREG_DATA); /* init off, pull high */
1553 bcm47xx_gpio_out(SHIFTREG_CLK, 0); /* init reset */
1556 for(mask = 1 << (SHIFTREG_MAX_BITS-1); mask; mask >>= 1)
1558 bcm47xx_gpio_out(SHIFTREG_DATA, (val & mask) ? SHIFTREG_DATA : 0);
1559 bcm47xx_gpio_out(SHIFTREG_CLK, SHIFTREG_CLK); /* pull high to trigger */
1560 bcm47xx_gpio_out(SHIFTREG_CLK, 0); /* reset to low */
1564 static void set_led_shift(struct led_t *led)
1566 static u32 shiftreg = 0;
1568 u32 pin = (led->gpio & ~GPIO_TYPE_MASK);
1576 /* Clock the bits out. */
1577 if (shiftreg != old) {
1578 shiftreg_output(shiftreg);
1582 static void set_led_extif(struct led_t *led)
1584 volatile u8 *addr = (volatile u8 *) KSEG1ADDR(EXTIF_UART) + (led->gpio & ~GPIO_TYPE_MASK);
1592 static void led_flash(unsigned long dummy) {
1597 for (l = platform.leds; l->name; l++) {
1598 if (!l->flash) continue;
1599 switch (l->gpio & GPIO_TYPE_MASK) {
1600 case GPIO_TYPE_EXTIF:
1602 l->state = !l->state;
1605 case GPIO_TYPE_SHIFT:
1607 l->state = !l->state;
1610 case GPIO_TYPE_NORMAL:
1619 u32 val = ~bcm47xx_gpio_in(~0);
1621 bcm47xx_gpio_outen(mask, mask);
1622 bcm47xx_gpio_control(mask, 0);
1623 bcm47xx_gpio_out(mask, val);
1625 if (mask || extif_blink) {
1626 mod_timer(&led_timer, jiffies + FLASH_TIME);
1630 static int diag_led_show(struct seq_file *m, void *v)
1632 struct led_t * led = m->private;
1634 u8 p = (led->polarity == NORMAL ? 0 : 1);
1636 return seq_printf(m, "f\n");
1637 } else if ((led->gpio & GPIO_TYPE_MASK) != GPIO_TYPE_NORMAL) {
1638 return seq_printf(m, "%d\n", ((led->state ^ p) ? 1 : 0));
1640 u32 in = (bcm47xx_gpio_in(~0) & led->gpio ? 1 : 0);
1641 return seq_printf(m, "%d\n", ((in ^ p) ? 1 : 0));
1645 static int diag_led_open(struct inode *inode, struct file *file)
1647 return single_open(file, diag_led_show, PDE_DATA(inode));
1650 static ssize_t diag_led_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
1652 struct led_t *led = PDE_DATA(file_inode(file));
1657 len = min(count, sizeof(cmd) - 1);
1658 if (copy_from_user(cmd, buf, len))
1663 p = (led->polarity == NORMAL ? 0 : 1);
1664 if (cmd[0] == 'f') {
1669 if ((led->gpio & GPIO_TYPE_MASK) == GPIO_TYPE_EXTIF) {
1670 led->state = p ^ ((cmd[0] == '1') ? 1 : 0);
1672 } else if ((led->gpio & GPIO_TYPE_MASK) == GPIO_TYPE_SHIFT) {
1673 led->state = p ^ ((cmd[0] == '1') ? 1 : 0);
1676 bcm47xx_gpio_outen(led->gpio, led->gpio);
1677 bcm47xx_gpio_control(led->gpio, 0);
1678 bcm47xx_gpio_out(led->gpio, ((p ^ (cmd[0] == '1')) ? led->gpio : 0));
1684 static const struct file_operations diag_led_fops = {
1685 .open = diag_led_open,
1687 .llseek = seq_lseek,
1688 .write = diag_led_write
1691 static void register_leds(struct led_t *l)
1693 struct proc_dir_entry *p;
1698 leds = proc_mkdir("led", diag);
1702 for(; l->name; l++) {
1703 if (l->gpio & gpiomask)
1706 switch (l->gpio & GPIO_TYPE_MASK) {
1707 case GPIO_TYPE_EXTIF:
1711 case GPIO_TYPE_SHIFT:
1712 mask |= (SHIFTREG_DATA | SHIFTREG_CLK);
1713 oe_mask |= (SHIFTREG_DATA | SHIFTREG_CLK);
1714 l->state = (l->polarity != NORMAL);
1717 case GPIO_TYPE_NORMAL:
1719 if (l->polarity != INPUT) oe_mask |= l->gpio;
1721 val |= (l->polarity == NORMAL)?0:l->gpio;
1725 if (l->polarity == INPUT) continue;
1727 p = proc_create_data(l->name, S_IRUSR, leds, &diag_led_fops, l);
1730 bcm47xx_gpio_outen(mask, oe_mask);
1731 bcm47xx_gpio_control(mask, 0);
1732 bcm47xx_gpio_out(mask, val);
1733 bcm47xx_gpio_intmask(mask, 0);
1736 static void unregister_leds(struct led_t *l)
1739 remove_proc_entry(l->name, leds);
1741 remove_proc_entry("led", diag);
1744 static int diag_model_show(struct seq_file *m, void *v)
1746 return seq_printf(m, "%s\n", platform.name);
1749 static int diag_model_open(struct inode *inode, struct file *file)
1751 return single_open(file, diag_model_show, PDE_DATA(inode));
1754 static const struct file_operations diag_model_fops = {
1755 .open = diag_model_open,
1760 static int diag_gpiomask_show(struct seq_file *m, void *v)
1762 return seq_printf(m, "0x%04x\n", gpiomask);
1765 static int diag_gpiomask_open(struct inode *inode, struct file *file)
1767 return single_open(file, diag_gpiomask_show, PDE_DATA(inode));
1770 static ssize_t diag_gpiomask_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
1772 int err = kstrtouint_from_user(buf, count, 0, &gpiomask);
1776 if (platform.buttons) {
1777 unregister_buttons(platform.buttons);
1778 register_buttons(platform.buttons);
1781 if (platform.leds) {
1782 unregister_leds(platform.leds);
1783 register_leds(platform.leds);
1789 static const struct file_operations diag_gpiomask_fops = {
1790 .open = diag_gpiomask_open,
1792 .llseek = seq_lseek,
1793 .write = diag_gpiomask_write
1796 static int __init diag_init(void)
1798 static struct proc_dir_entry *p;
1799 static struct platform_t *detected;
1801 detected = platform_detect();
1803 printk(MODULE_NAME ": Router model not detected.\n");
1806 memcpy(&platform, detected, sizeof(struct platform_t));
1808 printk(MODULE_NAME ": Detected '%s'\n", platform.name);
1809 if (platform.platform_init != NULL) {
1810 platform.platform_init();
1813 if (!(diag = proc_mkdir("diag", NULL))) {
1814 printk(MODULE_NAME ": proc_mkdir on /proc/diag failed\n");
1818 p = proc_create("model", S_IRUSR, diag, &diag_model_fops);
1820 remove_proc_entry("diag", NULL);
1824 p = proc_create("gpiomask", S_IRUSR | S_IWUSR, diag, &diag_gpiomask_fops);
1826 remove_proc_entry("model", diag);
1827 remove_proc_entry("diag", NULL);
1831 if (platform.buttons)
1832 register_buttons(platform.buttons);
1835 register_leds(platform.leds);
1840 static void __exit diag_exit(void)
1842 del_timer(&led_timer);
1844 if (platform.buttons)
1845 unregister_buttons(platform.buttons);
1848 unregister_leds(platform.leds);
1850 remove_proc_entry("model", diag);
1851 remove_proc_entry("gpiomask", diag);
1852 remove_proc_entry("diag", NULL);
1855 module_init(diag_init);
1856 module_exit(diag_exit);
1858 MODULE_AUTHOR("Mike Baker, Felix Fietkau / OpenWrt.org");
1859 MODULE_LICENSE("GPL");