2 * diag.c - GPIO interface driver for Broadcom boards
4 * Copyright (C) 2006 Mike Baker <mbm@openwrt.org>,
5 * Copyright (C) 2006-2007 Felix Fietkau <nbd@openwrt.org>
6 * Copyright (C) 2008 Andy Boyett <agb@openwrt.org>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include <linux/module.h>
24 #include <linux/pci.h>
25 #include <linux/kmod.h>
26 #include <linux/proc_fs.h>
27 #include <linux/timer.h>
28 #include <linux/version.h>
29 #include <asm/uaccess.h>
30 #include <linux/workqueue.h>
31 #include <linux/skbuff.h>
32 #include <linux/netlink.h>
33 #include <linux/kobject.h>
35 #include <bcm47xx_board.h>
36 extern u64 uevent_next_seqnum(void);
40 #define getvar(str) (nvram_get(str)?:"")
42 static inline int startswith (char *source, char *cmp) { return !strncmp(source,cmp,strlen(cmp)); }
43 static int fill_event(struct event_t *);
44 static unsigned int gpiomask = 0;
45 module_param(gpiomask, int, 0644);
47 extern char *nvram_get(char *str);
48 static void led_flash(unsigned long dummy);
50 static struct platform_t platform;
52 static struct timer_list led_timer = TIMER_INITIALIZER(&led_flash, 0, 0);
54 static struct proc_dir_entry *diag, *leds;
56 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,9,0)
57 static inline struct inode *file_inode(struct file *f)
59 return f->f_path.dentry->d_inode;
63 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)
64 static inline void *PDE_DATA(const struct inode *inode)
66 return PDE(inode)->data;
125 BUFFALO_UNKNOWN_4710,
170 /* Western Digital */
186 static void __init bcm4780_init(void) {
189 /* Enables GPIO 3 that controls HDD and led power on ASUS WL-700gE */
190 printk(MODULE_NAME ": Spinning up HDD and enabling leds\n");
191 bcm47xx_gpio_outen(pin, pin);
192 bcm47xx_gpio_control(pin, 0);
193 bcm47xx_gpio_out(pin, pin);
195 /* Wait 5s, so the HDD can spin up */
196 set_current_state(TASK_INTERRUPTIBLE);
197 schedule_timeout(HZ * 5);
200 static void __init NetCenter_init(void) {
201 /* unset pin 6 (+12V) */
203 bcm47xx_gpio_outen(pin, pin);
204 bcm47xx_gpio_control(pin, 0);
205 bcm47xx_gpio_out(pin, pin);
206 /* unset pin 1 (turn off red led, blue will light alone if +5V comes up) */
208 bcm47xx_gpio_outen(pin, pin);
209 bcm47xx_gpio_control(pin, 0);
210 bcm47xx_gpio_out(pin, pin);
211 /* unset pin 3 (+5V) and wait 5 seconds (harddisk spin up) */
215 static void __init bcm57xx_init(void) {
218 /* FIXME: switch comes up, but port mappings/vlans not right */
219 bcm47xx_gpio_outen(pin, pin);
220 bcm47xx_gpio_control(pin, 0);
221 bcm47xx_gpio_out(pin, pin);
224 static struct platform_t __initdata platforms[] = {
227 .name = "Linksys WAP54G V1",
229 { .name = "reset", .gpio = 1 << 0 },
232 { .name = "diag", .gpio = 1 << 3 },
233 { .name = "wlan", .gpio = 1 << 4 },
237 .name = "Linksys WAP54G V2",
239 { .name = "reset", .gpio = 1 << 0 },
242 { .name = "wlan", .gpio = 1 << 5, .polarity = REVERSE },
243 /* GPIO 6 is b44 (eth0, LAN) PHY power */
247 .name = "Linksys WAP54G V3",
249 /* FIXME: verify this */
250 { .name = "reset", .gpio = 1 << 7 },
251 { .name = "ses", .gpio = 1 << 0 },
255 { .name = "ses", .gpio = 1 << 1 },
259 .name = "Linksys WRT54G V1.x",
261 { .name = "reset", .gpio = 1 << 6 },
264 { .name = "diag", .gpio = 0x13 | GPIO_TYPE_EXTIF, .polarity = NORMAL },
265 { .name = "dmz", .gpio = 0x12 | GPIO_TYPE_EXTIF, .polarity = NORMAL },
269 .name = "Linksys WRT54G/GS/GL",
271 { .name = "reset", .gpio = 1 << 6 },
272 { .name = "ses", .gpio = 1 << 4 },
275 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
276 { .name = "dmz", .gpio = 1 << 7, .polarity = REVERSE },
277 { .name = "ses_white", .gpio = 1 << 2, .polarity = REVERSE },
278 { .name = "ses_orange", .gpio = 1 << 3, .polarity = REVERSE },
279 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
283 .name = "Linksys WRTSL54GS",
285 { .name = "reset", .gpio = 1 << 6 },
286 { .name = "ses", .gpio = 1 << 4 },
289 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
290 { .name = "dmz", .gpio = 1 << 0, .polarity = REVERSE },
291 { .name = "ses_white", .gpio = 1 << 5, .polarity = REVERSE },
292 { .name = "ses_orange", .gpio = 1 << 7, .polarity = REVERSE },
296 .name = "Linksys WRT54G3G",
298 { .name = "reset", .gpio = 1 << 6 },
299 { .name = "3g", .gpio = 1 << 4 },
302 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
303 { .name = "dmz", .gpio = 1 << 7, .polarity = REVERSE },
304 { .name = "3g_green", .gpio = 1 << 2, .polarity = NORMAL },
305 { .name = "3g_blue", .gpio = 1 << 3, .polarity = NORMAL },
306 { .name = "3g_blink", .gpio = 1 << 5, .polarity = NORMAL },
310 .name = "Linksys WRT54G3GV2-VF",
312 { .name = "reset", .gpio = 1 << 6 },
313 { .name = "3g", .gpio = 1 << 5 },
316 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
317 { .name = "3g_green", .gpio = 1 << 2, .polarity = NORMAL },
318 { .name = "3g_blue", .gpio = 1 << 3, .polarity = NORMAL },
322 .name = "Linksys WRT150N V1",
324 { .name = "reset", .gpio = 1 << 6 },
325 { .name = "ses", .gpio = 1 << 4 },
328 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
329 { .name = "ses_green", .gpio = 1 << 5, .polarity = REVERSE },
330 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE },
334 .name = "Linksys WRT150N V1.1",
336 { .name = "reset", .gpio = 1 << 6 },
337 { .name = "ses", .gpio = 1 << 4 },
340 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
341 { .name = "ses_green", .gpio = 1 << 5, .polarity = REVERSE },
342 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE },
346 .name = "Linksys WRT160N v1.x",
348 { .name = "reset", .gpio = 1 << 6 },
349 { .name = "ses", .gpio = 1 << 4 },
352 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
353 { .name = "ses_blue", .gpio = 1 << 5, .polarity = REVERSE },
354 { .name = "ses_orange", .gpio = 1 << 3, .polarity = REVERSE },
358 .name = "Linksys WRT160N V3",
360 { .name = "reset", .gpio = 1 << 6 },
361 { .name = "ses", .gpio = 1 << 5 },
364 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
365 { .name = "ses_blue", .gpio = 1 << 4, .polarity = REVERSE },
366 { .name = "ses_orange", .gpio = 1 << 2, .polarity = REVERSE },
370 .name = "Linksys WRT300N V1.1",
372 { .name = "reset", .gpio = 1 << 6 }, // "Reset" on back panel
373 { .name = "ses", .gpio = 1 << 4 }, // "Reserved" on top panel
376 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL }, // "Power"
377 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE }, // "Security" Amber
378 { .name = "ses_green", .gpio = 1 << 5, .polarity = REVERSE }, // "Security" Green
380 .platform_init = bcm57xx_init,
383 .name = "Linksys WRT350N",
385 { .name = "reset", .gpio = 1 << 6 },
386 { .name = "ses", .gpio = 1 << 8 },
389 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
390 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE },
391 { .name = "ses_green", .gpio = 1 << 9, .polarity = REVERSE },
392 { .name = "usb_blink", .gpio = 1 << 10, .polarity = REVERSE },
393 { .name = "usb", .gpio = 1 << 11, .polarity = REVERSE },
395 .platform_init = bcm57xx_init,
398 .name = "Linksys WRT600N",
400 { .name = "reset", .gpio = 1 << 6 },
401 { .name = "ses", .gpio = 1 << 7 },
404 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE }, // Power LED
405 { .name = "usb", .gpio = 1 << 3, .polarity = REVERSE }, // USB LED
406 { .name = "wl0_ses_amber", .gpio = 1 << 8, .polarity = REVERSE }, // 2.4Ghz LED Amber
407 { .name = "wl0_ses_green", .gpio = 1 << 9, .polarity = REVERSE }, // 2.4Ghz LED Green
408 { .name = "wl1_ses_amber", .gpio = 1 << 10, .polarity = REVERSE }, // 5.6Ghz LED Amber
409 { .name = "wl1_ses_green", .gpio = 1 << 11, .polarity = REVERSE }, // 5.6Ghz LED Green
411 .platform_init = bcm57xx_init,
414 .name = "Linksys WRT600N V1.1",
416 { .name = "reset", .gpio = 1 << 6 },
417 { .name = "ses", .gpio = 1 << 7 },
420 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE }, // Power LED
421 { .name = "usb", .gpio = 1 << 3, .polarity = REVERSE }, // USB LED
422 { .name = "wl0_ses_amber", .gpio = 1 << 8, .polarity = REVERSE }, // 2.4Ghz LED Amber
423 { .name = "wl0_ses_green", .gpio = 1 << 9, .polarity = REVERSE }, // 2.4Ghz LED Green
424 { .name = "wl1_ses_amber", .gpio = 1 << 10, .polarity = REVERSE }, // 5.6Ghz LED Amber
425 { .name = "wl1_ses_green", .gpio = 1 << 11, .polarity = REVERSE }, // 5.6Ghz LED Green
427 .platform_init = bcm57xx_init,
430 .name = "Linksys WRT610N",
432 { .name = "reset", .gpio = 1 << 6 },
433 { .name = "ses", .gpio = 1 << 8 },
436 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL }, // Power LED
437 { .name = "usb", .gpio = 1 << 0, .polarity = REVERSE }, // USB LED
438 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE }, // WiFi protected setup LED amber
439 { .name = "ses_blue", .gpio = 1 << 9, .polarity = REVERSE }, // WiFi protected setup LED blue
443 .name = "Linksys WRT610N V2",
445 { .name = "reset", .gpio = 1 << 6 },
446 { .name = "ses", .gpio = 1 << 4 },
449 { .name = "power", .gpio = 1 << 5, .polarity = NORMAL }, // Power LED
450 { .name = "usb", .gpio = 1 << 7, .polarity = NORMAL }, // USB LED
451 { .name = "ses_amber", .gpio = 1 << 0, .polarity = REVERSE }, // WiFi protected setup LED amber
452 { .name = "ses_blue", .gpio = 1 << 3, .polarity = REVERSE }, // WiFi protected setup LED blue
453 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL }, // Wireless LED
456 /* same hardware as WRT160NV3 and Cisco Valet M10V1, but different board detection, combine? */
458 .name = "Linksys E1000 V1",
460 { .name = "reset", .gpio = 1 << 6 },
461 { .name = "wps", .gpio = 1 << 5 }, /* nvram get gpio5=wps_button */
464 /** turns on leds for all ethernet ports (wan too)
465 * this also disconnects some, or maybe all, ethernet ports
466 * 1: leds work normally
467 * 0: all lit all the time */
468 /* nvram get gpio3=robo_reset */
469 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
470 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
471 { .name = "ses_blue", .gpio = 1 << 4, .polarity = REVERSE }, /* nvram get gpio4=wps_led */
472 { .name = "ses_orange", .gpio = 1 << 2, .polarity = REVERSE }, /* nvram get gpio2=wps_status_led */
476 .name = "Linksys E3000 V1",
478 { .name = "reset", .gpio = 1 << 6 },
479 { .name = "ses", .gpio = 1 << 4 },
482 { .name = "power", .gpio = 1 << 5, .polarity = NORMAL }, // Power LED
483 { .name = "usb", .gpio = 1 << 7, .polarity = NORMAL }, // USB LED
484 { .name = "ses_amber", .gpio = 1 << 0, .polarity = REVERSE }, // WiFi protected setup LED amber
485 { .name = "ses_blue", .gpio = 1 << 3, .polarity = REVERSE }, // WiFi protected setup LED blue
486 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL }, // Wireless LED
490 .name = "Linksys E3200 V1",
492 /* { .name = "switch", .gpio = 1 << 4 },*/ /* nvram get gpio4=robo_reset */
493 { .name = "reset", .gpio = 1 << 5 }, /* nvram get reset_gpio=5 */
494 { .name = "wps", .gpio = 1 << 8 }, /* nvram get gpio8=wps_button */
495 /* { .name = "wombo", .gpio = 1 << 23 },*/ /* nvram get gpio23=wombo_reset - wireless on motherboard */
498 { .name = "power", .gpio = 1 << 3, .polarity = REVERSE }, /* Power LED */
502 .name = "Linksys E4200 V1",
504 { .name = "reset", .gpio = 1 << 6 },
505 { .name = "wps", .gpio = 1 << 4 },
508 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
513 .name = "ASUS WL-HDD",
515 { .name = "reset", .gpio = 1 << 6 },
518 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
519 { .name = "usb", .gpio = 1 << 2, .polarity = REVERSE },
523 .name = "ASUS WL-300g",
525 { .name = "reset", .gpio = 1 << 6 },
528 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
532 .name = "ASUS WL-320gE/WL-320gP",
534 { .name = "reset", .gpio = 1 << 6 },
537 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
538 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE },
539 { .name = "link", .gpio = 1 << 11, .polarity = REVERSE },
543 .name = "ASUS WL-330gE",
545 { .name = "reset", .gpio = 1 << 2 },
548 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
552 .name = "ASUS WL-500g",
554 { .name = "reset", .gpio = 1 << 6 },
557 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
561 .name = "ASUS WL-500g Deluxe",
563 { .name = "reset", .gpio = 1 << 6 },
566 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
570 .name = "ASUS WL-500g Premium",
572 { .name = "reset", .gpio = 1 << 0 },
573 { .name = "ses", .gpio = 1 << 4 },
576 { .name = "power", .gpio = 1 << 1, .polarity = REVERSE },
580 .name = "ASUS WL-500g Premium V2",
582 { .name = "reset", .gpio = 1 << 2 },
583 { .name = "ses", .gpio = 1 << 3 },
586 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
587 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
591 .name = "ASUS WL-500W",
593 { .name = "reset", .gpio = 1 << 6 },
594 { .name = "ses", .gpio = 1 << 7 },
597 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
601 .name = "ASUS WL-520GC",
603 { .name = "reset", .gpio = 1 << 2 },
604 { .name = "ses", .gpio = 1 << 3 },
607 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
608 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
612 .name = "ASUS WL-520gU",
614 { .name = "reset", .gpio = 1 << 2 },
615 { .name = "ses", .gpio = 1 << 3 },
618 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
619 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
623 .name = "ASUS (unknown, BCM4702)",
625 { .name = "reset", .gpio = 1 << 6 },
628 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
632 .name = "ASUS WL-700gE",
634 { .name = "reset", .gpio = 1 << 7 }, // on back, hardwired, always resets device regardless OS state
635 { .name = "ses", .gpio = 1 << 4 }, // on back, actual name ezsetup
636 { .name = "power", .gpio = 1 << 0 }, // on front
637 { .name = "copy", .gpio = 1 << 6 }, // on front
641 // GPIO that controls power led also enables/disables some essential functions
644 { .name = "power", .gpio = 1 << 3, .polarity = NORMAL }, // actual name power
646 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE }, // actual name ready
648 .platform_init = bcm4780_init,
651 .name = "ASUS RT-N12",
653 { .name = "wps", .gpio = 1 << 0 },
654 { .name = "reset", .gpio = 1 << 1 },
655 // this is the router/repeater/ap switch
656 { .name = "sw1", .gpio = 1 << 4 },
657 { .name = "sw2", .gpio = 1 << 5 },
658 { .name = "sw3", .gpio = 1 << 6 },
661 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE },
662 { .name = "wlan", .gpio = 1 << 7, .polarity = NORMAL },
663 // gpio3 forces WAN and LAN1-4 all on
664 //{ .name = "eth", .gpio = 1 << 3, .polarity = REVERSE },
668 .name = "ASUS RT-N16",
670 { .name = "reset", .gpio = 1 << 8 },
671 { .name = "ses", .gpio = 1 << 5 },
674 { .name = "power", .gpio = 1 << 1, .polarity = REVERSE },
675 { .name = "wlan", .gpio = 1 << 7, .polarity = NORMAL },
679 .name = "ASUS RT-N66U",
681 { .name = "reset", .gpio = 1 << 9 },
682 { .name = "wps", .gpio = 1 << 4 },
685 { .name = "power", .gpio = 1 << 12, .polarity = REVERSE },
686 { .name = "usb", .gpio = 1 << 15, .polarity = REVERSE },
691 .name = "Buffalo WHR-G54S",
693 { .name = "reset", .gpio = 1 << 4 },
694 { .name = "bridge", .gpio = 1 << 5 },
695 { .name = "ses", .gpio = 1 << 0 },
698 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
699 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
700 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
701 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
702 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
706 .name = "Buffalo WBR2-G54",
709 { .name = "reset", .gpio = 1 << 7 },
712 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
716 .name = "Buffalo WHR-HP-G54",
718 { .name = "reset", .gpio = 1 << 4 },
719 { .name = "bridge", .gpio = 1 << 5 },
720 { .name = "ses", .gpio = 1 << 0 },
723 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
724 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
725 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
726 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
727 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
731 .name = "Buffalo WHR-G125",
733 { .name = "reset", .gpio = 1 << 4 },
734 { .name = "bridge", .gpio = 1 << 5 },
735 { .name = "ses", .gpio = 1 << 0 },
738 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
739 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
740 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
741 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
742 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
746 .name = "Buffalo WHR2-A54G54",
748 { .name = "reset", .gpio = 1 << 4 },
751 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
755 .name = "Buffalo WLA2-G54L",
758 { .name = "reset", .gpio = 1 << 7 },
761 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
765 .name = "Buffalo WZR-G300N",
767 { .name = "reset", .gpio = 1 << 4 },
770 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
771 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
772 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
776 .name = "Buffalo WZR-RS-G54",
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 },
788 .name = "Buffalo WZR-RS-G54HP",
790 { .name = "ses", .gpio = 1 << 0 },
791 { .name = "reset", .gpio = 1 << 4 },
794 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
795 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
796 { .name = "vpn", .gpio = 1 << 1, .polarity = REVERSE },
799 [BUFFALO_UNKNOWN] = {
800 .name = "Buffalo (unknown)",
802 { .name = "reset", .gpio = 1 << 7 },
805 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
808 [BUFFALO_UNKNOWN_4710] = {
809 .name = "Buffalo (unknown, BCM4710)",
811 { .name = "reset", .gpio = 1 << 4 },
814 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
819 .name = "Siemens SE505 V1",
821 /* No usable buttons */
824 // { .name = "power", .gpio = 1 << 0 .polarity = REVERSE }, // Usable when retrofitting D26 (?)
825 { .name = "dmz", .gpio = 1 << 4, .polarity = REVERSE }, // actual name WWW
826 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
830 .name = "Siemens SE505 V2",
832 /* No usable buttons */
835 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
836 { .name = "dmz", .gpio = 1 << 0, .polarity = REVERSE }, // actual name WWW
837 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
842 .name = "U.S. Robotics USR5461",
844 /* No usable buttons */
847 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
848 { .name = "printer", .gpio = 1 << 1, .polarity = REVERSE },
853 .name = "Dell TrueMobile 2300",
855 { .name = "reset", .gpio = 1 << 0 },
858 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
859 { .name = "power", .gpio = 1 << 7, .polarity = REVERSE },
863 .name = "Dell TrueMobile 2300 v2",
865 { .name = "reset", .gpio = 1 << 0 },
868 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
869 { .name = "power", .gpio = 1 << 7, .polarity = REVERSE },
874 .name = "Motorola WE800G",
876 { .name = "reset", .gpio = 1 << 0 },
879 { .name = "power", .gpio = 1 << 4, .polarity = NORMAL },
880 { .name = "diag", .gpio = 1 << 2, .polarity = REVERSE },
881 { .name = "wlan_amber", .gpio = 1 << 1, .polarity = NORMAL },
885 .name = "Motorola WR850G V1",
887 { .name = "reset", .gpio = 1 << 0 },
890 { .name = "power", .gpio = 1 << 4, .polarity = NORMAL },
891 { .name = "diag", .gpio = 1 << 3, .polarity = REVERSE },
892 { .name = "dmz", .gpio = 1 << 6, .polarity = NORMAL },
893 { .name = "wlan_red", .gpio = 1 << 5, .polarity = REVERSE },
894 { .name = "wlan_green", .gpio = 1 << 7, .polarity = REVERSE },
898 .name = "Motorola WR850G V2/V3",
900 { .name = "reset", .gpio = 1 << 5 },
903 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
904 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
905 { .name = "wan", .gpio = 1 << 6, .polarity = INPUT },
906 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
910 .name = "Motorola WR850GP",
912 { .name = "reset", .gpio = 1 << 5 },
915 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
916 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
917 { .name = "dmz", .gpio = 1 << 6, .polarity = REVERSE },
918 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
924 .name = "Belkin (unknown)",
925 /* FIXME: verify & add detection */
927 { .name = "reset", .gpio = 1 << 7 },
930 { .name = "power", .gpio = 1 << 5, .polarity = NORMAL },
931 { .name = "wlan", .gpio = 1 << 3, .polarity = NORMAL },
932 { .name = "connected", .gpio = 1 << 0, .polarity = NORMAL },
936 .name = "Belkin PlayMax F7D4301",
938 { .name = "reset", .gpio = 1 << 6 },
939 { .name = "wps", .gpio = 1 << 8 },
942 { .name = "power", .gpio = 1 << 11, .polarity = REVERSE },
943 { .name = "wlan", .gpio = 1 << 13, .polarity = REVERSE },
944 { .name = "led0", .gpio = 1 << 14, .polarity = REVERSE },
945 { .name = "led1", .gpio = 1 << 15, .polarity = REVERSE },
950 .name = "Netgear WGT634U",
952 { .name = "reset", .gpio = 1 << 2 },
955 { .name = "power", .gpio = 1 << 3, .polarity = NORMAL },
960 .name = "Netgear WNR834B V1",
961 .buttons = { /* TODO: add reset button and confirm LEDs - GPIO from dd-wrt */ },
963 { .name = "power", .gpio = 1 << 4, .polarity = REVERSE },
964 { .name = "diag", .gpio = 1 << 5, .polarity = REVERSE },
965 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
970 .name = "Netgear WNR834B V2",
972 { .name = "reset", .gpio = 1 << 6 },
975 { .name = "power", .gpio = 1 << 2, .polarity = NORMAL },
976 { .name = "diag", .gpio = 1 << 3, .polarity = NORMAL },
977 { .name = "connected", .gpio = 1 << 7, .polarity = NORMAL },
981 .name = "Netgear WNDR3400 V1",
983 /* nvram get gpio5=robo_reset */
984 { .name = "reset", .gpio = 1 << 4 },
985 { .name = "wps", .gpio = 1 << 6 },
986 { .name = "wlan", .gpio = 1 << 8 },
989 { .name = "wlan", .gpio = 0 << 0, .polarity = NORMAL },
990 { .name = "connected", .gpio = 1 << 0, .polarity = NORMAL },
991 { .name = "power", .gpio = 1 << 3, .polarity = NORMAL },
992 { .name = "diag", .gpio = 1 << 7, .polarity = NORMAL },
993 { .name = "usb", .gpio = 1 << 2, .polarity = REVERSE },
997 .name = "Netgear WNDR3700 V3",
999 /* { .name = "usb", .gpio = 1 << 1 }, */ /* this button doesn't seem to exist. */
1000 { .name = "wlan", .gpio = 1 << 2 },
1001 { .name = "reset", .gpio = 1 << 3 },
1002 { .name = "wps", .gpio = 1 << 4 },
1003 /* { .name = "switch", .gpio = 1 << 5 },*/ /* nvram get gpio5=robo_reset */
1006 { .name = "power", .gpio = (1 << 0) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1007 { .name = "diag", .gpio = (1 << 1) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1008 /* WAN LED doesn't respond to GPIO control. The switch is probably driving it.
1009 * { .name = "wan", .gpio = (1 << 2) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1011 { .name = "wlan2g", .gpio = (1 << 3) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1012 { .name = "wlan5g", .gpio = (1 << 4) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1013 { .name = "usb", .gpio = (1 << 5) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1014 { .name = "wps", .gpio = (1 << 6) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1015 { .name = "wlan", .gpio = (1 << 7) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1020 .name = "Trendware TEW411BRP+",
1022 { /* No usable buttons */ },
1025 { .name = "power", .gpio = 1 << 7, .polarity = NORMAL },
1026 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL },
1027 { .name = "bridge", .gpio = 1 << 6, .polarity = NORMAL },
1032 .name = "SimpleTech SimpleShare NAS",
1034 { .name = "reset", .gpio = 1 << 0 }, // Power button on back, named reset to enable failsafe.
1037 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE }, // actual name ready
1039 .platform_init = bcm4780_init,
1043 .name = "D-Link DIR-130",
1045 { .name = "reset", .gpio = 1 << 3},
1046 { .name = "reserved", .gpio = 1 << 7},
1049 { .name = "diag", .gpio = 1 << 0},
1050 { .name = "blue", .gpio = 1 << 6},
1054 .name = "D-Link DIR-320",
1056 { .name = "reserved", .gpio = 1 << 6},
1057 { .name = "reset", .gpio = 1 << 7},
1060 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
1061 { .name = "diag", .gpio = 1 << 1, .polarity = NORMAL }, /* "status led */
1062 { .name = "red", .gpio = 1 << 3, .polarity = REVERSE },
1063 { .name = "blue", .gpio = 1 << 4, .polarity = REVERSE },
1064 { .name = "usb", .gpio = 1 << 5, .polarity = NORMAL },
1068 .name = "D-Link DIR-330",
1070 { .name = "reset", .gpio = 1 << 3},
1071 { .name = "reserved", .gpio = 1 << 7},
1074 { .name = "diag", .gpio = 1 << 0},
1075 { .name = "usb", .gpio = 1 << 4},
1076 { .name = "blue", .gpio = 1 << 6},
1080 .name = "D-Link DWL-3150",
1082 { .name = "reset", .gpio = 1 << 7},
1085 { .name = "diag", .gpio = 1 << 2},
1086 { .name = "status", .gpio = 1 << 1},
1091 .name = "Sitecom WL-105b",
1093 { .name = "reset", .gpio = 1 << 10},
1096 { .name = "wlan", .gpio = 1 << 4},
1097 { .name = "power", .gpio = 1 << 3},
1100 /* Western Digital Net Center */
1102 .name = "Western Digital NetCenter",
1104 { .name = "power", .gpio = 1 << 0},
1105 { .name = "reset", .gpio = 1 << 7},
1107 .platform_init = NetCenter_init,
1109 /* Askey (and clones) */
1111 .name = "Askey RT210W",
1113 /* Power button is hard-wired to hardware reset */
1114 /* but is also connected to GPIO 7 (probably for bootloader recovery) */
1115 { .name = "power", .gpio = 1 << 7},
1118 /* These were verified and named based on Belkin F5D4230-4 v1112 */
1119 { .name = "connected", .gpio = 1 << 0, .polarity = REVERSE },
1120 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
1121 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
1125 .name = "OvisLink WL-1600GL",
1127 { .name = "reset", .gpio = 1 << 3 },
1128 { .name = "ses", .gpio = 1 << 4 },
1131 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
1132 { .name = "wps", .gpio = 1 << 2, .polarity = REVERSE },
1133 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
1134 { .name = "connected", .gpio = 1 << 0, .polarity = REVERSE },
1139 .name = "Microsoft MN-700",
1141 { .name = "reset", .gpio = 1 << 7 },
1144 { .name = "power", .gpio = 1 << 6, .polarity = NORMAL },
1149 .name = "Edimax PS-1208MFG",
1151 { .name = "reset", .gpio = 1 << 4 },
1154 { .name = "status", .gpio = 1 << 1, .polarity = NORMAL },
1155 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
1160 static struct platform_t __init *platform_detect_legacy(void)
1162 char *boardnum, *boardtype;
1164 if (strcmp(getvar("nvram_type"), "cfe") == 0)
1165 return &platforms[WGT634U];
1168 /* no easy model number, attempt to guess */
1169 boardnum = getvar("boardnum");
1170 boardtype = getvar("boardtype");
1172 if (!strcmp(boardnum, "20070615")) { /* Linksys WRT600N v1/V1.1 */
1173 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "0") && !strcmp(getvar("switch_type"),"BCM5395"))
1174 return &platforms[WRT600NV11];
1176 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "0"))
1177 return &platforms[WRT600N];
1180 if (startswith(getvar("pmon_ver"), "CFE")) {
1181 /* CFE based - newer hardware */
1182 if (!strcmp(boardnum, "42")) { /* Linksys */
1183 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "1"))
1184 return &platforms[WRT350N];
1186 if (!strcmp(boardtype, "0x0101") && !strcmp(getvar("boot_ver"), "v3.6"))
1187 return &platforms[WRT54G3G];
1189 /* default to WRT54G */
1190 return &platforms[WRT54G];
1192 if (!strcmp(boardnum, "1024") && !strcmp(boardtype, "0x0446"))
1193 return &platforms[WAP54GV2];
1195 if (!strcmp(boardnum, "8") && !strcmp(boardtype, "0x048e"))
1196 return &platforms[WL1600GL];
1199 if (!strcmp(boardnum, "44") || !strcmp(boardnum, "44\r")) {
1200 if (!strcmp(boardtype,"0x0101") || !strcmp(boardtype, "0x0101\r"))
1201 return &platforms[TM2300V2]; /* Dell TrueMobile 2300 v2 */
1204 if (!strcmp(boardnum, "45")) { /* ASUS */
1205 if (!strcmp(boardtype,"0x0472"))
1206 return &platforms[WL500W];
1207 else if (!strcmp(boardtype,"0x467"))
1208 return &platforms[WL320GE];
1210 return &platforms[WL500GD];
1213 if (!strcmp(boardnum, "10496"))
1214 return &platforms[USR5461];
1216 if (!strcmp(getvar("boardtype"), "0x0101") && !strcmp(getvar("boardrev"), "0x10")) /* SE505V2 With Modified CFE */
1217 return &platforms[SE505V2];
1219 if (!strcmp(boardtype, "0x048e") && !strcmp(getvar("boardrev"),"0x35") &&
1220 !strcmp(getvar("boardflags"), "0x750")) /* D-Link DIR-320 */
1221 return &platforms[DIR320];
1223 if (!strncmp(boardnum, "TH",2) && !strcmp(boardtype,"0x042f")) {
1224 return &platforms[WDNetCenter];
1227 if (!strcmp(boardtype,"0x0472") && !strcmp(getvar("cardbus"), "1")) { /* Netgear WNR834B V1 and V2*/
1228 if (!strcmp(boardnum, "08") || !strcmp(boardnum, "8"))
1229 return &platforms[WNR834BV1];
1230 if (!strcmp(boardnum, "01") || !strcmp(boardnum, "1"))
1231 return &platforms[WNR834BV2];
1234 } else { /* PMON based - old stuff */
1235 if ((simple_strtoul(getvar("GemtekPmonVer"), NULL, 0) == 9) &&
1236 (simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 30)) {
1237 return &platforms[WR850GV1];
1239 if (startswith(boardtype, "bcm94710dev")) {
1240 if (!strcmp(boardnum, "42"))
1241 return &platforms[WRT54GV1];
1242 if (simple_strtoul(boardnum, NULL, 0) == 2)
1243 return &platforms[WAP54GV1];
1245 /* MN-700 has also hardware_version 'WL500-...', so use boardnum */
1246 if (startswith(getvar("hardware_version"), "WL500-")) {
1247 if (!strcmp(getvar("boardnum"), "mn700"))
1248 return &platforms[MN700];
1250 return &platforms[WL500G];
1252 if (startswith(getvar("hardware_version"), "WL300-")) {
1253 /* Either WL-300g or WL-HDD, do more extensive checks */
1254 if ((simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 0) &&
1255 (simple_strtoul(getvar("et1phyaddr"), NULL, 0) == 1))
1256 return &platforms[WLHDD];
1257 if ((simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 0) &&
1258 (simple_strtoul(getvar("et1phyaddr"), NULL, 0) == 10))
1259 return &platforms[WL300G];
1261 /* Sitecom WL-105b */
1262 if (startswith(boardnum, "2") && simple_strtoul(getvar("GemtekPmonVer"), NULL, 0) == 1)
1263 return &platforms[WL105B];
1265 /* unknown asus stuff, probably bcm4702 */
1266 if (startswith(boardnum, "asusX"))
1267 return &platforms[ASUS_4702];
1269 /* bcm4702 based Askey RT210W clones, Including:
1270 * Askey RT210W (duh?)
1272 * Belkin F5D7230-4 before version v1444 (MiniPCI slot, not integrated)
1274 if (!strcmp(boardtype,"bcm94710r4")
1275 && !strcmp(boardnum ,"100")
1276 && !strcmp(getvar("pmon_ver"),"v1.03.12.bk")
1278 return &platforms[RT210W];
1282 if (boardnum || !strcmp(boardnum, "00")) {/* probably buffalo */
1283 if (startswith(boardtype, "bcm94710ap"))
1284 return &platforms[BUFFALO_UNKNOWN_4710];
1286 return &platforms[BUFFALO_UNKNOWN];
1289 if (startswith(getvar("CFEver"), "MotoWRv2") ||
1290 startswith(getvar("CFEver"), "MotoWRv3") ||
1291 !strcmp(getvar("MOTO_BOARD_TYPE"), "WR_FEM1")) {
1293 return &platforms[WR850GV2V3];
1296 if (!strcmp(boardnum, "44") && !strcmp(getvar("boardflags"),"0x0388")) { /* Trendware TEW-411BRP+ */
1297 return &platforms[TEW411BRPP];
1300 if (startswith(boardnum, "04FN")) /* SimpleTech SimpleShare */
1301 return &platforms[STI_NAS];
1303 if (!strcmp(boardnum, "10") && !strcmp(getvar("boardrev"), "0x13")) /* D-Link DWL-3150 */
1304 return &platforms[DWL3150];
1306 if (!strcmp(boardnum, "01") && !strcmp(boardtype, "0x048e") && /* Edimax PS1208MFG */
1307 !strcmp(getvar("status_gpio"), "1")) /* gpio based detection */
1308 return &platforms[PS1208MFG];
1314 static struct platform_t __init *platform_detect(void)
1316 enum bcm47xx_board board;
1317 const char *board_name;
1320 board = bcm47xx_board_get();
1321 board_name = bcm47xx_board_get_name();
1322 if (board != BCM47XX_BOARD_UNKNOWN && board != BCM47XX_BOARD_NON)
1323 printk(MODULE_NAME ": kernel found a \"%s\"\n", board_name);
1326 case BCM47XX_BOARD_ASUS_RTN12:
1327 return &platforms[RTN12];
1328 case BCM47XX_BOARD_ASUS_RTN16:
1329 return &platforms[RTN16];
1330 case BCM47XX_BOARD_ASUS_RTN66U:
1331 return &platforms[RTN66U];
1332 case BCM47XX_BOARD_ASUS_WL330GE:
1333 return &platforms[WL330GE];
1334 case BCM47XX_BOARD_ASUS_WL500GPV1:
1335 return &platforms[WL500GP];
1336 case BCM47XX_BOARD_ASUS_WL500GPV2:
1337 return &platforms[WL500GPV2];
1338 case BCM47XX_BOARD_ASUS_WL520GC:
1339 return &platforms[WL520GC];
1340 case BCM47XX_BOARD_ASUS_WL520GU:
1341 return &platforms[WL520GU];
1342 case BCM47XX_BOARD_ASUS_WL700GE:
1343 return &platforms[WL700GE];
1344 case BCM47XX_BOARD_BELKIN_F7D4301:
1345 return &platforms[BELKIN_F7D4301];
1346 case BCM47XX_BOARD_BUFFALO_WBR2_G54:
1347 return &platforms[WBR2_G54];
1348 case BCM47XX_BOARD_BUFFALO_WHR2_A54G54:
1349 return &platforms[WHR2_A54G54];
1350 case BCM47XX_BOARD_BUFFALO_WHR_G125:
1351 return &platforms[WHR_G125];
1352 case BCM47XX_BOARD_BUFFALO_WHR_G54S:
1353 return &platforms[WHR_G54S];
1354 case BCM47XX_BOARD_BUFFALO_WHR_HP_G54:
1355 return &platforms[WHR_HP_G54];
1356 case BCM47XX_BOARD_BUFFALO_WLA2_G54L:
1357 return &platforms[WLA2_G54L];
1358 case BCM47XX_BOARD_BUFFALO_WZR_G300N:
1359 return &platforms[WZR_G300N];
1360 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54:
1361 return &platforms[WZR_RS_G54];
1362 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54HP:
1363 return &platforms[WZR_RS_G54HP];
1364 case BCM47XX_BOARD_DELL_TM2300:
1365 return &platforms[TM2300];
1366 case BCM47XX_BOARD_DLINK_DIR130:
1367 return &platforms[DIR130];
1368 case BCM47XX_BOARD_DLINK_DIR330:
1369 return &platforms[DIR330];
1370 case BCM47XX_BOARD_LINKSYS_E1000V1:
1371 return &platforms[E1000V1];
1372 case BCM47XX_BOARD_LINKSYS_E3000V1:
1373 return &platforms[E3000V1];
1374 case BCM47XX_BOARD_LINKSYS_E3200V1:
1375 return &platforms[E3200V1];
1376 case BCM47XX_BOARD_LINKSYS_E4200V1:
1377 return &platforms[E4200V1];
1378 case BCM47XX_BOARD_LINKSYS_WRT150NV1:
1379 return &platforms[WRT150NV1];
1380 case BCM47XX_BOARD_LINKSYS_WRT150NV11:
1381 return &platforms[WRT150NV11];
1382 case BCM47XX_BOARD_LINKSYS_WRT160NV1:
1383 return &platforms[WRT160NV1];
1384 case BCM47XX_BOARD_LINKSYS_WRT160NV3:
1385 return &platforms[WRT160NV3];
1386 case BCM47XX_BOARD_LINKSYS_WRT300NV11:
1387 return &platforms[WRT300NV11];
1388 case BCM47XX_BOARD_LINKSYS_WRT54G3GV2:
1389 return &platforms[WRT54G3GV2_VF];
1390 case BCM47XX_BOARD_LINKSYS_WRT610NV1:
1391 return &platforms[WRT610N];
1392 case BCM47XX_BOARD_LINKSYS_WRT610NV2:
1393 return &platforms[WRT610NV2];
1394 case BCM47XX_BOARD_LINKSYS_WRTSL54GS:
1395 return &platforms[WRTSL54GS];
1396 case BCM47XX_BOARD_MOTOROLA_WE800G:
1397 return &platforms[WE800G];
1398 case BCM47XX_BOARD_MOTOROLA_WR850GP:
1399 return &platforms[WR850GP];
1400 case BCM47XX_BOARD_MOTOROLA_WR850GV2V3:
1401 return &platforms[WR850GV2V3];
1402 case BCM47XX_BOARD_NETGEAR_WNDR3400V1:
1403 return &platforms[WNDR3400V1];
1404 case BCM47XX_BOARD_NETGEAR_WNDR3700V3:
1405 return &platforms[WNDR3700V3];
1406 case BCM47XX_BOARD_UNKNOWN:
1407 case BCM47XX_BOARD_NON:
1408 printk(MODULE_NAME ": unknown board found, try legacy detect\n");
1409 printk(MODULE_NAME ": please open a ticket at https://dev.openwrt.org and attach the complete nvram\n");
1410 return platform_detect_legacy();
1412 printk(MODULE_NAME ": board was detected as \"%s\", but not gpio configuration available\n", board_name);
1413 printk(MODULE_NAME ": now trying legacy detect\n");
1414 return platform_detect_legacy();
1418 static inline void ssb_maskset32(struct ssb_device *dev,
1419 u16 offset, u32 mask, u32 set)
1421 ssb_write32(dev, offset, (ssb_read32(dev, offset) & mask) | set);
1424 static void gpio_set_irqenable(int enabled, irqreturn_t (*handler)(int, void *))
1429 irq = gpio_to_irq(0);
1431 pr_err("no irq for gpio available\n");
1436 err = request_irq(irq, handler, IRQF_SHARED, "gpio", handler);
1438 pr_err("can not reqeust irq\n");
1442 free_irq(irq, handler);
1445 switch (bcm47xx_bus_type) {
1446 #ifdef CONFIG_BCM47XX_SSB
1447 case BCM47XX_BUS_TYPE_SSB:
1448 if (bcm47xx_bus.ssb.chipco.dev)
1449 ssb_maskset32(bcm47xx_bus.ssb.chipco.dev, SSB_CHIPCO_IRQMASK, ~SSB_CHIPCO_IRQ_GPIO, (enabled ? SSB_CHIPCO_IRQ_GPIO : 0));
1452 #ifdef CONFIG_BCM47XX_BCMA
1453 case BCM47XX_BUS_TYPE_BCMA:
1454 if (bcm47xx_bus.bcma.bus.drv_cc.core)
1455 bcma_maskset32(bcm47xx_bus.bcma.bus.drv_cc.core, BCMA_CC_IRQMASK, ~BCMA_CC_IRQ_GPIO, (enabled ? BCMA_CC_IRQ_GPIO : 0));
1461 static void hotplug_button(struct work_struct *work)
1463 struct event_t *event = container_of(work, struct event_t, wq);
1466 event->skb = alloc_skb(2048, GFP_KERNEL);
1468 s = skb_put(event->skb, strlen(event->action) + 2);
1469 sprintf(s, "%s@", event->action);
1472 NETLINK_CB(event->skb).dst_group = 1;
1473 broadcast_uevent(event->skb, 0, 1, GFP_KERNEL);
1478 static irqreturn_t button_handler(int irq, void *dev_id)
1483 in = bcm47xx_gpio_in(~0) & platform.button_mask;
1484 bcm47xx_gpio_polarity(platform.button_mask, in);
1485 changed = platform.button_polarity ^ in;
1486 platform.button_polarity = in;
1488 changed &= ~bcm47xx_gpio_outen(0, 0);
1490 for (b = platform.buttons; b->name; b++) {
1491 struct event_t *event;
1493 if (!(b->gpio & changed)) continue;
1497 if ((event = (struct event_t *)kzalloc (sizeof(struct event_t), GFP_ATOMIC))) {
1498 event->seen = (jiffies - b->seen)/HZ;
1499 event->name = b->name;
1500 event->action = b->pressed ? "pressed" : "released";
1501 INIT_WORK(&event->wq, (void *)(void *)hotplug_button);
1502 schedule_work(&event->wq);
1510 static void register_buttons(struct button_t *b)
1512 for (; b->name; b++)
1513 platform.button_mask |= b->gpio;
1515 platform.button_mask &= ~gpiomask;
1517 bcm47xx_gpio_outen(platform.button_mask, 0);
1518 bcm47xx_gpio_control(platform.button_mask, 0);
1519 platform.button_polarity = bcm47xx_gpio_in(~0) & platform.button_mask;
1520 bcm47xx_gpio_polarity(platform.button_mask, platform.button_polarity);
1521 bcm47xx_gpio_intmask(platform.button_mask, platform.button_mask);
1523 gpio_set_irqenable(1, button_handler);
1526 static void unregister_buttons(struct button_t *b)
1528 bcm47xx_gpio_intmask(platform.button_mask, 0);
1530 gpio_set_irqenable(0, button_handler);
1534 static void add_msg(struct event_t *event, char *msg, int argv)
1541 s = skb_put(event->skb, strlen(msg) + 1);
1545 static int fill_event (struct event_t *event)
1547 static char buf[128];
1549 add_msg(event, "HOME=/", 0);
1550 add_msg(event, "PATH=/sbin:/bin:/usr/sbin:/usr/bin", 0);
1551 add_msg(event, "SUBSYSTEM=button", 0);
1552 snprintf(buf, 128, "ACTION=%s", event->action);
1553 add_msg(event, buf, 0);
1554 snprintf(buf, 128, "BUTTON=%s", event->name);
1555 add_msg(event, buf, 0);
1556 snprintf(buf, 128, "SEEN=%ld", event->seen);
1557 add_msg(event, buf, 0);
1558 snprintf(buf, 128, "SEQNUM=%llu", uevent_next_seqnum());
1559 add_msg(event, buf, 0);
1565 * This should be extended to allow the platform to specify the pins and width
1566 * of the shift register. They're hardcoded for now because only the WNDR3700v3
1569 static void shiftreg_output(unsigned int val)
1573 bcm47xx_gpio_out(SHIFTREG_DATA, SHIFTREG_DATA); /* init off, pull high */
1574 bcm47xx_gpio_out(SHIFTREG_CLK, 0); /* init reset */
1577 for(mask = 1 << (SHIFTREG_MAX_BITS-1); mask; mask >>= 1)
1579 bcm47xx_gpio_out(SHIFTREG_DATA, (val & mask) ? SHIFTREG_DATA : 0);
1580 bcm47xx_gpio_out(SHIFTREG_CLK, SHIFTREG_CLK); /* pull high to trigger */
1581 bcm47xx_gpio_out(SHIFTREG_CLK, 0); /* reset to low */
1585 static void set_led_shift(struct led_t *led)
1587 static u32 shiftreg = 0;
1589 u32 pin = (led->gpio & ~GPIO_TYPE_MASK);
1597 /* Clock the bits out. */
1598 if (shiftreg != old) {
1599 shiftreg_output(shiftreg);
1603 static void set_led_extif(struct led_t *led)
1605 volatile u8 *addr = (volatile u8 *) KSEG1ADDR(EXTIF_UART) + (led->gpio & ~GPIO_TYPE_MASK);
1613 static void led_flash(unsigned long dummy) {
1618 for (l = platform.leds; l->name; l++) {
1619 if (!l->flash) continue;
1620 switch (l->gpio & GPIO_TYPE_MASK) {
1621 case GPIO_TYPE_EXTIF:
1623 l->state = !l->state;
1626 case GPIO_TYPE_SHIFT:
1628 l->state = !l->state;
1631 case GPIO_TYPE_NORMAL:
1640 u32 val = ~bcm47xx_gpio_in(~0);
1642 bcm47xx_gpio_outen(mask, mask);
1643 bcm47xx_gpio_control(mask, 0);
1644 bcm47xx_gpio_out(mask, val);
1646 if (mask || extif_blink) {
1647 mod_timer(&led_timer, jiffies + FLASH_TIME);
1651 static int diag_led_show(struct seq_file *m, void *v)
1653 struct led_t * led = m->private;
1655 u8 p = (led->polarity == NORMAL ? 0 : 1);
1657 return seq_printf(m, "f\n");
1658 } else if ((led->gpio & GPIO_TYPE_MASK) != GPIO_TYPE_NORMAL) {
1659 return seq_printf(m, "%d\n", ((led->state ^ p) ? 1 : 0));
1661 u32 in = (bcm47xx_gpio_in(~0) & led->gpio ? 1 : 0);
1662 return seq_printf(m, "%d\n", ((in ^ p) ? 1 : 0));
1666 static int diag_led_open(struct inode *inode, struct file *file)
1668 return single_open(file, diag_led_show, PDE_DATA(inode));
1671 static ssize_t diag_led_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
1673 struct led_t *led = PDE_DATA(file_inode(file));
1678 len = min(count, sizeof(cmd) - 1);
1679 if (copy_from_user(cmd, buf, len))
1684 p = (led->polarity == NORMAL ? 0 : 1);
1685 if (cmd[0] == 'f') {
1690 if ((led->gpio & GPIO_TYPE_MASK) == GPIO_TYPE_EXTIF) {
1691 led->state = p ^ ((cmd[0] == '1') ? 1 : 0);
1693 } else if ((led->gpio & GPIO_TYPE_MASK) == GPIO_TYPE_SHIFT) {
1694 led->state = p ^ ((cmd[0] == '1') ? 1 : 0);
1697 bcm47xx_gpio_outen(led->gpio, led->gpio);
1698 bcm47xx_gpio_control(led->gpio, 0);
1699 bcm47xx_gpio_out(led->gpio, ((p ^ (cmd[0] == '1')) ? led->gpio : 0));
1705 static const struct file_operations diag_led_fops = {
1706 .open = diag_led_open,
1708 .llseek = seq_lseek,
1709 .write = diag_led_write
1712 static void register_leds(struct led_t *l)
1714 struct proc_dir_entry *p;
1719 leds = proc_mkdir("led", diag);
1723 for(; l->name; l++) {
1724 if (l->gpio & gpiomask)
1727 switch (l->gpio & GPIO_TYPE_MASK) {
1728 case GPIO_TYPE_EXTIF:
1732 case GPIO_TYPE_SHIFT:
1733 mask |= (SHIFTREG_DATA | SHIFTREG_CLK);
1734 oe_mask |= (SHIFTREG_DATA | SHIFTREG_CLK);
1735 l->state = (l->polarity != NORMAL);
1738 case GPIO_TYPE_NORMAL:
1740 if (l->polarity != INPUT) oe_mask |= l->gpio;
1742 val |= (l->polarity == NORMAL)?0:l->gpio;
1746 if (l->polarity == INPUT) continue;
1748 p = proc_create_data(l->name, S_IRUSR, leds, &diag_led_fops, l);
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 diag_model_show(struct seq_file *m, void *v)
1767 return seq_printf(m, "%s\n", platform.name);
1770 static int diag_model_open(struct inode *inode, struct file *file)
1772 return single_open(file, diag_model_show, PDE_DATA(inode));
1775 static const struct file_operations diag_model_fops = {
1776 .open = diag_model_open,
1781 static int diag_gpiomask_show(struct seq_file *m, void *v)
1783 return seq_printf(m, "0x%04x\n", gpiomask);
1786 static int diag_gpiomask_open(struct inode *inode, struct file *file)
1788 return single_open(file, diag_gpiomask_show, PDE_DATA(inode));
1791 static ssize_t diag_gpiomask_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
1793 int err = kstrtouint_from_user(buf, count, 0, &gpiomask);
1797 if (platform.buttons) {
1798 unregister_buttons(platform.buttons);
1799 register_buttons(platform.buttons);
1802 if (platform.leds) {
1803 unregister_leds(platform.leds);
1804 register_leds(platform.leds);
1810 static const struct file_operations diag_gpiomask_fops = {
1811 .open = diag_gpiomask_open,
1813 .llseek = seq_lseek,
1814 .write = diag_gpiomask_write
1817 static int __init diag_init(void)
1819 static struct proc_dir_entry *p;
1820 static struct platform_t *detected;
1822 detected = platform_detect();
1824 printk(MODULE_NAME ": Router model not detected.\n");
1827 memcpy(&platform, detected, sizeof(struct platform_t));
1829 printk(MODULE_NAME ": Detected '%s'\n", platform.name);
1830 if (platform.platform_init != NULL) {
1831 platform.platform_init();
1834 if (!(diag = proc_mkdir("diag", NULL))) {
1835 printk(MODULE_NAME ": proc_mkdir on /proc/diag failed\n");
1839 p = proc_create("model", S_IRUSR, diag, &diag_model_fops);
1841 remove_proc_entry("diag", NULL);
1845 p = proc_create("gpiomask", S_IRUSR | S_IWUSR, diag, &diag_gpiomask_fops);
1847 remove_proc_entry("model", diag);
1848 remove_proc_entry("diag", NULL);
1852 if (platform.buttons)
1853 register_buttons(platform.buttons);
1856 register_leds(platform.leds);
1861 static void __exit diag_exit(void)
1863 del_timer(&led_timer);
1865 if (platform.buttons)
1866 unregister_buttons(platform.buttons);
1869 unregister_leds(platform.leds);
1871 remove_proc_entry("model", diag);
1872 remove_proc_entry("gpiomask", diag);
1873 remove_proc_entry("diag", NULL);
1876 module_init(diag_init);
1877 module_exit(diag_exit);
1879 MODULE_AUTHOR("Mike Baker, Felix Fietkau / OpenWrt.org");
1880 MODULE_LICENSE("GPL");