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;
123 BUFFALO_UNKNOWN_4710,
168 /* Western Digital */
184 static void __init bcm4780_init(void) {
187 /* Enables GPIO 3 that controls HDD and led power on ASUS WL-700gE */
188 printk(MODULE_NAME ": Spinning up HDD and enabling leds\n");
189 bcm47xx_gpio_outen(pin, pin);
190 bcm47xx_gpio_control(pin, 0);
191 bcm47xx_gpio_out(pin, pin);
193 /* Wait 5s, so the HDD can spin up */
194 set_current_state(TASK_INTERRUPTIBLE);
195 schedule_timeout(HZ * 5);
198 static void __init NetCenter_init(void) {
199 /* unset pin 6 (+12V) */
201 bcm47xx_gpio_outen(pin, pin);
202 bcm47xx_gpio_control(pin, 0);
203 bcm47xx_gpio_out(pin, pin);
204 /* unset pin 1 (turn off red led, blue will light alone if +5V comes up) */
206 bcm47xx_gpio_outen(pin, pin);
207 bcm47xx_gpio_control(pin, 0);
208 bcm47xx_gpio_out(pin, pin);
209 /* unset pin 3 (+5V) and wait 5 seconds (harddisk spin up) */
213 static void __init bcm57xx_init(void) {
216 /* FIXME: switch comes up, but port mappings/vlans not right */
217 bcm47xx_gpio_outen(pin, pin);
218 bcm47xx_gpio_control(pin, 0);
219 bcm47xx_gpio_out(pin, pin);
222 static struct platform_t __initdata platforms[] = {
225 .name = "Linksys WAP54G V1",
227 { .name = "reset", .gpio = 1 << 0 },
230 { .name = "diag", .gpio = 1 << 3 },
231 { .name = "wlan", .gpio = 1 << 4 },
235 .name = "Linksys WAP54G V2",
237 { .name = "reset", .gpio = 1 << 0 },
240 { .name = "wlan", .gpio = 1 << 5, .polarity = REVERSE },
241 /* GPIO 6 is b44 (eth0, LAN) PHY power */
245 .name = "Linksys WAP54G V3",
247 /* FIXME: verify this */
248 { .name = "reset", .gpio = 1 << 7 },
249 { .name = "ses", .gpio = 1 << 0 },
253 { .name = "ses", .gpio = 1 << 1 },
257 .name = "Linksys WRT54G V1.x",
259 { .name = "reset", .gpio = 1 << 6 },
262 { .name = "diag", .gpio = 0x13 | GPIO_TYPE_EXTIF, .polarity = NORMAL },
263 { .name = "dmz", .gpio = 0x12 | GPIO_TYPE_EXTIF, .polarity = NORMAL },
267 .name = "Linksys WRT54G/GS/GL",
269 { .name = "reset", .gpio = 1 << 6 },
270 { .name = "ses", .gpio = 1 << 4 },
273 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
274 { .name = "dmz", .gpio = 1 << 7, .polarity = REVERSE },
275 { .name = "ses_white", .gpio = 1 << 2, .polarity = REVERSE },
276 { .name = "ses_orange", .gpio = 1 << 3, .polarity = REVERSE },
277 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
281 .name = "Linksys WRTSL54GS",
283 { .name = "reset", .gpio = 1 << 6 },
284 { .name = "ses", .gpio = 1 << 4 },
287 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
288 { .name = "dmz", .gpio = 1 << 0, .polarity = REVERSE },
289 { .name = "ses_white", .gpio = 1 << 5, .polarity = REVERSE },
290 { .name = "ses_orange", .gpio = 1 << 7, .polarity = REVERSE },
294 .name = "Linksys WRT54G3G",
296 { .name = "reset", .gpio = 1 << 6 },
297 { .name = "3g", .gpio = 1 << 4 },
300 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
301 { .name = "dmz", .gpio = 1 << 7, .polarity = REVERSE },
302 { .name = "3g_green", .gpio = 1 << 2, .polarity = NORMAL },
303 { .name = "3g_blue", .gpio = 1 << 3, .polarity = NORMAL },
304 { .name = "3g_blink", .gpio = 1 << 5, .polarity = NORMAL },
308 .name = "Linksys WRT54G3GV2-VF",
310 { .name = "reset", .gpio = 1 << 6 },
311 { .name = "3g", .gpio = 1 << 5 },
314 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
315 { .name = "3g_green", .gpio = 1 << 2, .polarity = NORMAL },
316 { .name = "3g_blue", .gpio = 1 << 3, .polarity = NORMAL },
320 .name = "Linksys WRT150N V1",
322 { .name = "reset", .gpio = 1 << 6 },
323 { .name = "ses", .gpio = 1 << 4 },
326 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
327 { .name = "ses_green", .gpio = 1 << 5, .polarity = REVERSE },
328 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE },
332 .name = "Linksys WRT150N V1.1",
334 { .name = "reset", .gpio = 1 << 6 },
335 { .name = "ses", .gpio = 1 << 4 },
338 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
339 { .name = "ses_green", .gpio = 1 << 5, .polarity = REVERSE },
340 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE },
344 .name = "Linksys WRT160N v1.x",
346 { .name = "reset", .gpio = 1 << 6 },
347 { .name = "ses", .gpio = 1 << 4 },
350 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
351 { .name = "ses_blue", .gpio = 1 << 5, .polarity = REVERSE },
352 { .name = "ses_orange", .gpio = 1 << 3, .polarity = REVERSE },
356 .name = "Linksys WRT160N V3",
358 { .name = "reset", .gpio = 1 << 6 },
359 { .name = "ses", .gpio = 1 << 5 },
362 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
363 { .name = "ses_blue", .gpio = 1 << 4, .polarity = REVERSE },
364 { .name = "ses_orange", .gpio = 1 << 2, .polarity = REVERSE },
368 .name = "Linksys WRT300N V1.1",
370 { .name = "reset", .gpio = 1 << 6 }, // "Reset" on back panel
371 { .name = "ses", .gpio = 1 << 4 }, // "Reserved" on top panel
374 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL }, // "Power"
375 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE }, // "Security" Amber
376 { .name = "ses_green", .gpio = 1 << 5, .polarity = REVERSE }, // "Security" Green
378 .platform_init = bcm57xx_init,
381 .name = "Linksys WRT350N",
383 { .name = "reset", .gpio = 1 << 6 },
384 { .name = "ses", .gpio = 1 << 8 },
387 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
388 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE },
389 { .name = "ses_green", .gpio = 1 << 9, .polarity = REVERSE },
390 { .name = "usb_blink", .gpio = 1 << 10, .polarity = REVERSE },
391 { .name = "usb", .gpio = 1 << 11, .polarity = REVERSE },
393 .platform_init = bcm57xx_init,
396 .name = "Linksys WRT600N",
398 { .name = "reset", .gpio = 1 << 6 },
399 { .name = "ses", .gpio = 1 << 7 },
402 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE }, // Power LED
403 { .name = "usb", .gpio = 1 << 3, .polarity = REVERSE }, // USB LED
404 { .name = "wl0_ses_amber", .gpio = 1 << 8, .polarity = REVERSE }, // 2.4Ghz LED Amber
405 { .name = "wl0_ses_green", .gpio = 1 << 9, .polarity = REVERSE }, // 2.4Ghz LED Green
406 { .name = "wl1_ses_amber", .gpio = 1 << 10, .polarity = REVERSE }, // 5.6Ghz LED Amber
407 { .name = "wl1_ses_green", .gpio = 1 << 11, .polarity = REVERSE }, // 5.6Ghz LED Green
409 .platform_init = bcm57xx_init,
412 .name = "Linksys WRT600N V1.1",
414 { .name = "reset", .gpio = 1 << 6 },
415 { .name = "ses", .gpio = 1 << 7 },
418 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE }, // Power LED
419 { .name = "usb", .gpio = 1 << 3, .polarity = REVERSE }, // USB LED
420 { .name = "wl0_ses_amber", .gpio = 1 << 8, .polarity = REVERSE }, // 2.4Ghz LED Amber
421 { .name = "wl0_ses_green", .gpio = 1 << 9, .polarity = REVERSE }, // 2.4Ghz LED Green
422 { .name = "wl1_ses_amber", .gpio = 1 << 10, .polarity = REVERSE }, // 5.6Ghz LED Amber
423 { .name = "wl1_ses_green", .gpio = 1 << 11, .polarity = REVERSE }, // 5.6Ghz LED Green
425 .platform_init = bcm57xx_init,
428 .name = "Linksys WRT610N",
430 { .name = "reset", .gpio = 1 << 6 },
431 { .name = "ses", .gpio = 1 << 8 },
434 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL }, // Power LED
435 { .name = "usb", .gpio = 1 << 0, .polarity = REVERSE }, // USB LED
436 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE }, // WiFi protected setup LED amber
437 { .name = "ses_blue", .gpio = 1 << 9, .polarity = REVERSE }, // WiFi protected setup LED blue
441 .name = "Linksys WRT610N V2",
443 { .name = "reset", .gpio = 1 << 6 },
444 { .name = "ses", .gpio = 1 << 4 },
447 { .name = "power", .gpio = 1 << 5, .polarity = NORMAL }, // Power LED
448 { .name = "usb", .gpio = 1 << 7, .polarity = NORMAL }, // USB LED
449 { .name = "ses_amber", .gpio = 1 << 0, .polarity = REVERSE }, // WiFi protected setup LED amber
450 { .name = "ses_blue", .gpio = 1 << 3, .polarity = REVERSE }, // WiFi protected setup LED blue
451 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL }, // Wireless LED
454 /* same hardware as WRT160NV3 and Cisco Valet M10V1, but different board detection, combine? */
456 .name = "Linksys E1000 V1",
458 { .name = "reset", .gpio = 1 << 6 },
459 { .name = "wps", .gpio = 1 << 5 }, /* nvram get gpio5=wps_button */
462 /** turns on leds for all ethernet ports (wan too)
463 * this also disconnects some, or maybe all, ethernet ports
464 * 1: leds work normally
465 * 0: all lit all the time */
466 /* nvram get gpio3=robo_reset */
467 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
468 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
469 { .name = "ses_blue", .gpio = 1 << 4, .polarity = REVERSE }, /* nvram get gpio4=wps_led */
470 { .name = "ses_orange", .gpio = 1 << 2, .polarity = REVERSE }, /* nvram get gpio2=wps_status_led */
474 .name = "Linksys E3000 V1",
476 { .name = "reset", .gpio = 1 << 6 },
477 { .name = "ses", .gpio = 1 << 4 },
480 { .name = "power", .gpio = 1 << 5, .polarity = NORMAL }, // Power LED
481 { .name = "usb", .gpio = 1 << 7, .polarity = NORMAL }, // USB LED
482 { .name = "ses_amber", .gpio = 1 << 0, .polarity = REVERSE }, // WiFi protected setup LED amber
483 { .name = "ses_blue", .gpio = 1 << 3, .polarity = REVERSE }, // WiFi protected setup LED blue
484 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL }, // Wireless LED
488 .name = "Linksys E3200 V1",
490 /* { .name = "switch", .gpio = 1 << 4 },*/ /* nvram get gpio4=robo_reset */
491 { .name = "reset", .gpio = 1 << 5 }, /* nvram get reset_gpio=5 */
492 { .name = "wps", .gpio = 1 << 8 }, /* nvram get gpio8=wps_button */
493 /* { .name = "wombo", .gpio = 1 << 23 },*/ /* nvram get gpio23=wombo_reset - wireless on motherboard */
496 { .name = "power", .gpio = 1 << 3, .polarity = REVERSE }, /* Power LED */
501 .name = "ASUS WL-HDD",
503 { .name = "reset", .gpio = 1 << 6 },
506 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
507 { .name = "usb", .gpio = 1 << 2, .polarity = REVERSE },
511 .name = "ASUS WL-300g",
513 { .name = "reset", .gpio = 1 << 6 },
516 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
520 .name = "ASUS WL-320gE/WL-320gP",
522 { .name = "reset", .gpio = 1 << 6 },
525 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
526 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE },
527 { .name = "link", .gpio = 1 << 11, .polarity = REVERSE },
531 .name = "ASUS WL-330gE",
533 { .name = "reset", .gpio = 1 << 2 },
536 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
540 .name = "ASUS WL-500g",
542 { .name = "reset", .gpio = 1 << 6 },
545 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
549 .name = "ASUS WL-500g Deluxe",
551 { .name = "reset", .gpio = 1 << 6 },
554 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
558 .name = "ASUS WL-500g Premium",
560 { .name = "reset", .gpio = 1 << 0 },
561 { .name = "ses", .gpio = 1 << 4 },
564 { .name = "power", .gpio = 1 << 1, .polarity = REVERSE },
568 .name = "ASUS WL-500g Premium V2",
570 { .name = "reset", .gpio = 1 << 2 },
571 { .name = "ses", .gpio = 1 << 3 },
574 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
575 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
579 .name = "ASUS WL-500W",
581 { .name = "reset", .gpio = 1 << 6 },
582 { .name = "ses", .gpio = 1 << 7 },
585 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
589 .name = "ASUS WL-520GC",
591 { .name = "reset", .gpio = 1 << 2 },
592 { .name = "ses", .gpio = 1 << 3 },
595 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
596 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
600 .name = "ASUS WL-520gU",
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 (unknown, BCM4702)",
613 { .name = "reset", .gpio = 1 << 6 },
616 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
620 .name = "ASUS WL-700gE",
622 { .name = "reset", .gpio = 1 << 7 }, // on back, hardwired, always resets device regardless OS state
623 { .name = "ses", .gpio = 1 << 4 }, // on back, actual name ezsetup
624 { .name = "power", .gpio = 1 << 0 }, // on front
625 { .name = "copy", .gpio = 1 << 6 }, // on front
629 // GPIO that controls power led also enables/disables some essential functions
632 { .name = "power", .gpio = 1 << 3, .polarity = NORMAL }, // actual name power
634 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE }, // actual name ready
636 .platform_init = bcm4780_init,
639 .name = "ASUS RT-N12",
641 { .name = "wps", .gpio = 1 << 0 },
642 { .name = "reset", .gpio = 1 << 1 },
643 // this is the router/repeater/ap switch
644 { .name = "sw1", .gpio = 1 << 4 },
645 { .name = "sw2", .gpio = 1 << 5 },
646 { .name = "sw3", .gpio = 1 << 6 },
649 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE },
650 { .name = "wlan", .gpio = 1 << 7, .polarity = NORMAL },
651 // gpio3 forces WAN and LAN1-4 all on
652 //{ .name = "eth", .gpio = 1 << 3, .polarity = REVERSE },
656 .name = "ASUS RT-N16",
658 { .name = "reset", .gpio = 1 << 8 },
659 { .name = "ses", .gpio = 1 << 5 },
662 { .name = "power", .gpio = 1 << 1, .polarity = REVERSE },
663 { .name = "wlan", .gpio = 1 << 7, .polarity = NORMAL },
668 .name = "Buffalo WHR-G54S",
670 { .name = "reset", .gpio = 1 << 4 },
671 { .name = "bridge", .gpio = 1 << 5 },
672 { .name = "ses", .gpio = 1 << 0 },
675 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
676 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
677 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
678 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
679 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
683 .name = "Buffalo WBR2-G54",
686 { .name = "reset", .gpio = 1 << 7 },
689 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
693 .name = "Buffalo WHR-HP-G54",
695 { .name = "reset", .gpio = 1 << 4 },
696 { .name = "bridge", .gpio = 1 << 5 },
697 { .name = "ses", .gpio = 1 << 0 },
700 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
701 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
702 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
703 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
704 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
708 .name = "Buffalo WHR-G125",
710 { .name = "reset", .gpio = 1 << 4 },
711 { .name = "bridge", .gpio = 1 << 5 },
712 { .name = "ses", .gpio = 1 << 0 },
715 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
716 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
717 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
718 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
719 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
723 .name = "Buffalo WHR2-A54G54",
725 { .name = "reset", .gpio = 1 << 4 },
728 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
732 .name = "Buffalo WLA2-G54L",
735 { .name = "reset", .gpio = 1 << 7 },
738 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
742 .name = "Buffalo WZR-G300N",
744 { .name = "reset", .gpio = 1 << 4 },
747 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
748 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
749 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
753 .name = "Buffalo WZR-RS-G54",
755 { .name = "ses", .gpio = 1 << 0 },
756 { .name = "reset", .gpio = 1 << 4 },
759 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
760 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
761 { .name = "vpn", .gpio = 1 << 1, .polarity = REVERSE },
765 .name = "Buffalo WZR-RS-G54HP",
767 { .name = "ses", .gpio = 1 << 0 },
768 { .name = "reset", .gpio = 1 << 4 },
771 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
772 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
773 { .name = "vpn", .gpio = 1 << 1, .polarity = REVERSE },
776 [BUFFALO_UNKNOWN] = {
777 .name = "Buffalo (unknown)",
779 { .name = "reset", .gpio = 1 << 7 },
782 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
785 [BUFFALO_UNKNOWN_4710] = {
786 .name = "Buffalo (unknown, BCM4710)",
788 { .name = "reset", .gpio = 1 << 4 },
791 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
796 .name = "Siemens SE505 V1",
798 /* No usable buttons */
801 // { .name = "power", .gpio = 1 << 0 .polarity = REVERSE }, // Usable when retrofitting D26 (?)
802 { .name = "dmz", .gpio = 1 << 4, .polarity = REVERSE }, // actual name WWW
803 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
807 .name = "Siemens SE505 V2",
809 /* No usable buttons */
812 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
813 { .name = "dmz", .gpio = 1 << 0, .polarity = REVERSE }, // actual name WWW
814 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
819 .name = "U.S. Robotics USR5461",
821 /* No usable buttons */
824 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
825 { .name = "printer", .gpio = 1 << 1, .polarity = REVERSE },
830 .name = "Dell TrueMobile 2300",
832 { .name = "reset", .gpio = 1 << 0 },
835 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
836 { .name = "power", .gpio = 1 << 7, .polarity = REVERSE },
840 .name = "Dell TrueMobile 2300 v2",
842 { .name = "reset", .gpio = 1 << 0 },
845 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
846 { .name = "power", .gpio = 1 << 7, .polarity = REVERSE },
851 .name = "Motorola WE800G",
853 { .name = "reset", .gpio = 1 << 0 },
856 { .name = "power", .gpio = 1 << 4, .polarity = NORMAL },
857 { .name = "diag", .gpio = 1 << 2, .polarity = REVERSE },
858 { .name = "wlan_amber", .gpio = 1 << 1, .polarity = NORMAL },
862 .name = "Motorola WR850G V1",
864 { .name = "reset", .gpio = 1 << 0 },
867 { .name = "power", .gpio = 1 << 4, .polarity = NORMAL },
868 { .name = "diag", .gpio = 1 << 3, .polarity = REVERSE },
869 { .name = "dmz", .gpio = 1 << 6, .polarity = NORMAL },
870 { .name = "wlan_red", .gpio = 1 << 5, .polarity = REVERSE },
871 { .name = "wlan_green", .gpio = 1 << 7, .polarity = REVERSE },
875 .name = "Motorola WR850G V2/V3",
877 { .name = "reset", .gpio = 1 << 5 },
880 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
881 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
882 { .name = "wan", .gpio = 1 << 6, .polarity = INPUT },
883 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
887 .name = "Motorola WR850GP",
889 { .name = "reset", .gpio = 1 << 5 },
892 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
893 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
894 { .name = "dmz", .gpio = 1 << 6, .polarity = REVERSE },
895 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
901 .name = "Belkin (unknown)",
902 /* FIXME: verify & add detection */
904 { .name = "reset", .gpio = 1 << 7 },
907 { .name = "power", .gpio = 1 << 5, .polarity = NORMAL },
908 { .name = "wlan", .gpio = 1 << 3, .polarity = NORMAL },
909 { .name = "connected", .gpio = 1 << 0, .polarity = NORMAL },
913 .name = "Belkin PlayMax F7D4301",
915 { .name = "reset", .gpio = 1 << 6 },
916 { .name = "wps", .gpio = 1 << 8 },
919 { .name = "power", .gpio = 1 << 11, .polarity = REVERSE },
920 { .name = "wlan", .gpio = 1 << 13, .polarity = REVERSE },
921 { .name = "led0", .gpio = 1 << 14, .polarity = REVERSE },
922 { .name = "led1", .gpio = 1 << 15, .polarity = REVERSE },
927 .name = "Netgear WGT634U",
929 { .name = "reset", .gpio = 1 << 2 },
932 { .name = "power", .gpio = 1 << 3, .polarity = NORMAL },
937 .name = "Netgear WNR834B V1",
938 .buttons = { /* TODO: add reset button and confirm LEDs - GPIO from dd-wrt */ },
940 { .name = "power", .gpio = 1 << 4, .polarity = REVERSE },
941 { .name = "diag", .gpio = 1 << 5, .polarity = REVERSE },
942 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
947 .name = "Netgear WNR834B V2",
949 { .name = "reset", .gpio = 1 << 6 },
952 { .name = "power", .gpio = 1 << 2, .polarity = NORMAL },
953 { .name = "diag", .gpio = 1 << 3, .polarity = NORMAL },
954 { .name = "connected", .gpio = 1 << 7, .polarity = NORMAL },
958 .name = "Netgear WNDR3400 V1",
960 /* nvram get gpio5=robo_reset */
961 { .name = "reset", .gpio = 1 << 4 },
962 { .name = "wps", .gpio = 1 << 6 },
963 { .name = "wlan", .gpio = 1 << 8 },
966 { .name = "wlan", .gpio = 0 << 0, .polarity = NORMAL },
967 { .name = "connected", .gpio = 1 << 0, .polarity = NORMAL },
968 { .name = "power", .gpio = 1 << 3, .polarity = NORMAL },
969 { .name = "diag", .gpio = 1 << 7, .polarity = NORMAL },
970 { .name = "usb", .gpio = 1 << 2, .polarity = REVERSE },
974 .name = "Netgear WNDR3700 V3",
976 /* { .name = "usb", .gpio = 1 << 1 }, */ /* this button doesn't seem to exist. */
977 { .name = "wlan", .gpio = 1 << 2 },
978 { .name = "reset", .gpio = 1 << 3 },
979 { .name = "wps", .gpio = 1 << 4 },
980 /* { .name = "switch", .gpio = 1 << 5 },*/ /* nvram get gpio5=robo_reset */
983 { .name = "power", .gpio = (1 << 0) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
984 { .name = "diag", .gpio = (1 << 1) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
985 /* WAN LED doesn't respond to GPIO control. The switch is probably driving it.
986 * { .name = "wan", .gpio = (1 << 2) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
988 { .name = "wlan2g", .gpio = (1 << 3) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
989 { .name = "wlan5g", .gpio = (1 << 4) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
990 { .name = "usb", .gpio = (1 << 5) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
991 { .name = "wps", .gpio = (1 << 6) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
992 { .name = "wlan", .gpio = (1 << 7) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
997 .name = "Trendware TEW411BRP+",
999 { /* No usable buttons */ },
1002 { .name = "power", .gpio = 1 << 7, .polarity = NORMAL },
1003 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL },
1004 { .name = "bridge", .gpio = 1 << 6, .polarity = NORMAL },
1009 .name = "SimpleTech SimpleShare NAS",
1011 { .name = "reset", .gpio = 1 << 0 }, // Power button on back, named reset to enable failsafe.
1014 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE }, // actual name ready
1016 .platform_init = bcm4780_init,
1020 .name = "D-Link DIR-130",
1022 { .name = "reset", .gpio = 1 << 3},
1023 { .name = "reserved", .gpio = 1 << 7},
1026 { .name = "diag", .gpio = 1 << 0},
1027 { .name = "blue", .gpio = 1 << 6},
1031 .name = "D-Link DIR-320",
1033 { .name = "reserved", .gpio = 1 << 6},
1034 { .name = "reset", .gpio = 1 << 7},
1037 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
1038 { .name = "diag", .gpio = 1 << 1, .polarity = NORMAL }, /* "status led */
1039 { .name = "red", .gpio = 1 << 3, .polarity = REVERSE },
1040 { .name = "blue", .gpio = 1 << 4, .polarity = REVERSE },
1041 { .name = "usb", .gpio = 1 << 5, .polarity = NORMAL },
1045 .name = "D-Link DIR-330",
1047 { .name = "reset", .gpio = 1 << 3},
1048 { .name = "reserved", .gpio = 1 << 7},
1051 { .name = "diag", .gpio = 1 << 0},
1052 { .name = "usb", .gpio = 1 << 4},
1053 { .name = "blue", .gpio = 1 << 6},
1057 .name = "D-Link DWL-3150",
1059 { .name = "reset", .gpio = 1 << 7},
1062 { .name = "diag", .gpio = 1 << 2},
1063 { .name = "status", .gpio = 1 << 1},
1068 .name = "Sitecom WL-105b",
1070 { .name = "reset", .gpio = 1 << 10},
1073 { .name = "wlan", .gpio = 1 << 4},
1074 { .name = "power", .gpio = 1 << 3},
1077 /* Western Digital Net Center */
1079 .name = "Western Digital NetCenter",
1081 { .name = "power", .gpio = 1 << 0},
1082 { .name = "reset", .gpio = 1 << 7},
1084 .platform_init = NetCenter_init,
1086 /* Askey (and clones) */
1088 .name = "Askey RT210W",
1090 /* Power button is hard-wired to hardware reset */
1091 /* but is also connected to GPIO 7 (probably for bootloader recovery) */
1092 { .name = "power", .gpio = 1 << 7},
1095 /* These were verified and named based on Belkin F5D4230-4 v1112 */
1096 { .name = "connected", .gpio = 1 << 0, .polarity = REVERSE },
1097 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
1098 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
1102 .name = "OvisLink WL-1600GL",
1104 { .name = "reset", .gpio = 1 << 3 },
1105 { .name = "ses", .gpio = 1 << 4 },
1108 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
1109 { .name = "wps", .gpio = 1 << 2, .polarity = REVERSE },
1110 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
1111 { .name = "connected", .gpio = 1 << 0, .polarity = REVERSE },
1116 .name = "Microsoft MN-700",
1118 { .name = "reset", .gpio = 1 << 7 },
1121 { .name = "power", .gpio = 1 << 6, .polarity = NORMAL },
1126 .name = "Edimax PS-1208MFG",
1128 { .name = "reset", .gpio = 1 << 4 },
1131 { .name = "status", .gpio = 1 << 1, .polarity = NORMAL },
1132 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
1137 static struct platform_t __init *platform_detect_legacy(void)
1139 char *boardnum, *boardtype;
1141 if (strcmp(getvar("nvram_type"), "cfe") == 0)
1142 return &platforms[WGT634U];
1145 /* no easy model number, attempt to guess */
1146 boardnum = getvar("boardnum");
1147 boardtype = getvar("boardtype");
1149 if (!strcmp(boardnum, "20070615")) { /* Linksys WRT600N v1/V1.1 */
1150 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "0") && !strcmp(getvar("switch_type"),"BCM5395"))
1151 return &platforms[WRT600NV11];
1153 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "0"))
1154 return &platforms[WRT600N];
1157 if (startswith(getvar("pmon_ver"), "CFE")) {
1158 /* CFE based - newer hardware */
1159 if (!strcmp(boardnum, "42")) { /* Linksys */
1160 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "1"))
1161 return &platforms[WRT350N];
1163 if (!strcmp(boardtype, "0x0101") && !strcmp(getvar("boot_ver"), "v3.6"))
1164 return &platforms[WRT54G3G];
1166 /* default to WRT54G */
1167 return &platforms[WRT54G];
1169 if (!strcmp(boardnum, "1024") && !strcmp(boardtype, "0x0446"))
1170 return &platforms[WAP54GV2];
1172 if (!strcmp(boardnum, "8") && !strcmp(boardtype, "0x048e"))
1173 return &platforms[WL1600GL];
1176 if (!strcmp(boardnum, "44") || !strcmp(boardnum, "44\r")) {
1177 if (!strcmp(boardtype,"0x0101") || !strcmp(boardtype, "0x0101\r"))
1178 return &platforms[TM2300V2]; /* Dell TrueMobile 2300 v2 */
1181 if (!strcmp(boardnum, "45")) { /* ASUS */
1182 if (!strcmp(boardtype,"0x0472"))
1183 return &platforms[WL500W];
1184 else if (!strcmp(boardtype,"0x467"))
1185 return &platforms[WL320GE];
1187 return &platforms[WL500GD];
1190 if (!strcmp(boardnum, "10496"))
1191 return &platforms[USR5461];
1193 if (!strcmp(getvar("boardtype"), "0x0101") && !strcmp(getvar("boardrev"), "0x10")) /* SE505V2 With Modified CFE */
1194 return &platforms[SE505V2];
1196 if (!strcmp(boardtype, "0x048e") && !strcmp(getvar("boardrev"),"0x35") &&
1197 !strcmp(getvar("boardflags"), "0x750")) /* D-Link DIR-320 */
1198 return &platforms[DIR320];
1200 if (!strncmp(boardnum, "TH",2) && !strcmp(boardtype,"0x042f")) {
1201 return &platforms[WDNetCenter];
1204 if (!strcmp(boardtype,"0x0472") && !strcmp(getvar("cardbus"), "1")) { /* Netgear WNR834B V1 and V2*/
1205 if (!strcmp(boardnum, "08") || !strcmp(boardnum, "8"))
1206 return &platforms[WNR834BV1];
1207 if (!strcmp(boardnum, "01") || !strcmp(boardnum, "1"))
1208 return &platforms[WNR834BV2];
1211 } else { /* PMON based - old stuff */
1212 if ((simple_strtoul(getvar("GemtekPmonVer"), NULL, 0) == 9) &&
1213 (simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 30)) {
1214 return &platforms[WR850GV1];
1216 if (startswith(boardtype, "bcm94710dev")) {
1217 if (!strcmp(boardnum, "42"))
1218 return &platforms[WRT54GV1];
1219 if (simple_strtoul(boardnum, NULL, 0) == 2)
1220 return &platforms[WAP54GV1];
1222 /* MN-700 has also hardware_version 'WL500-...', so use boardnum */
1223 if (startswith(getvar("hardware_version"), "WL500-")) {
1224 if (!strcmp(getvar("boardnum"), "mn700"))
1225 return &platforms[MN700];
1227 return &platforms[WL500G];
1229 if (startswith(getvar("hardware_version"), "WL300-")) {
1230 /* Either WL-300g or WL-HDD, do more extensive checks */
1231 if ((simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 0) &&
1232 (simple_strtoul(getvar("et1phyaddr"), NULL, 0) == 1))
1233 return &platforms[WLHDD];
1234 if ((simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 0) &&
1235 (simple_strtoul(getvar("et1phyaddr"), NULL, 0) == 10))
1236 return &platforms[WL300G];
1238 /* Sitecom WL-105b */
1239 if (startswith(boardnum, "2") && simple_strtoul(getvar("GemtekPmonVer"), NULL, 0) == 1)
1240 return &platforms[WL105B];
1242 /* unknown asus stuff, probably bcm4702 */
1243 if (startswith(boardnum, "asusX"))
1244 return &platforms[ASUS_4702];
1246 /* bcm4702 based Askey RT210W clones, Including:
1247 * Askey RT210W (duh?)
1249 * Belkin F5D7230-4 before version v1444 (MiniPCI slot, not integrated)
1251 if (!strcmp(boardtype,"bcm94710r4")
1252 && !strcmp(boardnum ,"100")
1253 && !strcmp(getvar("pmon_ver"),"v1.03.12.bk")
1255 return &platforms[RT210W];
1259 if (boardnum || !strcmp(boardnum, "00")) {/* probably buffalo */
1260 if (startswith(boardtype, "bcm94710ap"))
1261 return &platforms[BUFFALO_UNKNOWN_4710];
1263 return &platforms[BUFFALO_UNKNOWN];
1266 if (startswith(getvar("CFEver"), "MotoWRv2") ||
1267 startswith(getvar("CFEver"), "MotoWRv3") ||
1268 !strcmp(getvar("MOTO_BOARD_TYPE"), "WR_FEM1")) {
1270 return &platforms[WR850GV2V3];
1273 if (!strcmp(boardnum, "44") && !strcmp(getvar("boardflags"),"0x0388")) { /* Trendware TEW-411BRP+ */
1274 return &platforms[TEW411BRPP];
1277 if (startswith(boardnum, "04FN")) /* SimpleTech SimpleShare */
1278 return &platforms[STI_NAS];
1280 if (!strcmp(boardnum, "10") && !strcmp(getvar("boardrev"), "0x13")) /* D-Link DWL-3150 */
1281 return &platforms[DWL3150];
1283 if (!strcmp(boardnum, "01") && !strcmp(boardtype, "0x048e") && /* Edimax PS1208MFG */
1284 !strcmp(getvar("status_gpio"), "1")) /* gpio based detection */
1285 return &platforms[PS1208MFG];
1291 static struct platform_t __init *platform_detect(void)
1293 enum bcm47xx_board board;
1294 const char *board_name;
1297 board = bcm47xx_board_get();
1298 board_name = bcm47xx_board_get_name();
1299 if (board != BCM47XX_BOARD_UNKNOWN && board != BCM47XX_BOARD_NON)
1300 printk(MODULE_NAME ": kernel found a \"%s\"\n", board_name);
1303 case BCM47XX_BOARD_ASUS_RTN12:
1304 return &platforms[RTN12];
1305 case BCM47XX_BOARD_ASUS_RTN16:
1306 return &platforms[RTN16];
1307 case BCM47XX_BOARD_ASUS_WL330GE:
1308 return &platforms[WL330GE];
1309 case BCM47XX_BOARD_ASUS_WL500GPV1:
1310 return &platforms[WL500GP];
1311 case BCM47XX_BOARD_ASUS_WL500GPV2:
1312 return &platforms[WL500GPV2];
1313 case BCM47XX_BOARD_ASUS_WL520GC:
1314 return &platforms[WL520GC];
1315 case BCM47XX_BOARD_ASUS_WL520GU:
1316 return &platforms[WL520GU];
1317 case BCM47XX_BOARD_ASUS_WL700GE:
1318 return &platforms[WL700GE];
1319 case BCM47XX_BOARD_BELKIN_F7D4301:
1320 return &platforms[BELKIN_F7D4301];
1321 case BCM47XX_BOARD_BUFFALO_WBR2_G54:
1322 return &platforms[WBR2_G54];
1323 case BCM47XX_BOARD_BUFFALO_WHR2_A54G54:
1324 return &platforms[WHR2_A54G54];
1325 case BCM47XX_BOARD_BUFFALO_WHR_G125:
1326 return &platforms[WHR_G125];
1327 case BCM47XX_BOARD_BUFFALO_WHR_G54S:
1328 return &platforms[WHR_G54S];
1329 case BCM47XX_BOARD_BUFFALO_WHR_HP_G54:
1330 return &platforms[WHR_HP_G54];
1331 case BCM47XX_BOARD_BUFFALO_WLA2_G54L:
1332 return &platforms[WLA2_G54L];
1333 case BCM47XX_BOARD_BUFFALO_WZR_G300N:
1334 return &platforms[WZR_G300N];
1335 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54:
1336 return &platforms[WZR_RS_G54];
1337 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54HP:
1338 return &platforms[WZR_RS_G54HP];
1339 case BCM47XX_BOARD_DELL_TM2300:
1340 return &platforms[TM2300];
1341 case BCM47XX_BOARD_DLINK_DIR130:
1342 return &platforms[DIR130];
1343 case BCM47XX_BOARD_DLINK_DIR330:
1344 return &platforms[DIR330];
1345 case BCM47XX_BOARD_LINKSYS_E1000V1:
1346 return &platforms[E1000V1];
1347 case BCM47XX_BOARD_LINKSYS_E3000V1:
1348 return &platforms[E3000V1];
1349 case BCM47XX_BOARD_LINKSYS_E3200V1:
1350 return &platforms[E3200V1];
1351 case BCM47XX_BOARD_LINKSYS_WRT150NV1:
1352 return &platforms[WRT150NV1];
1353 case BCM47XX_BOARD_LINKSYS_WRT150NV11:
1354 return &platforms[WRT150NV11];
1355 case BCM47XX_BOARD_LINKSYS_WRT160NV1:
1356 return &platforms[WRT160NV1];
1357 case BCM47XX_BOARD_LINKSYS_WRT160NV3:
1358 return &platforms[WRT160NV3];
1359 case BCM47XX_BOARD_LINKSYS_WRT300NV11:
1360 return &platforms[WRT300NV11];
1361 case BCM47XX_BOARD_LINKSYS_WRT54G3GV2:
1362 return &platforms[WRT54G3GV2_VF];
1363 case BCM47XX_BOARD_LINKSYS_WRT610NV1:
1364 return &platforms[WRT610N];
1365 case BCM47XX_BOARD_LINKSYS_WRT610NV2:
1366 return &platforms[WRT610NV2];
1367 case BCM47XX_BOARD_LINKSYS_WRTSL54GS:
1368 return &platforms[WRTSL54GS];
1369 case BCM47XX_BOARD_MOTOROLA_WE800G:
1370 return &platforms[WE800G];
1371 case BCM47XX_BOARD_MOTOROLA_WR850GP:
1372 return &platforms[WR850GP];
1373 case BCM47XX_BOARD_MOTOROLA_WR850GV2V3:
1374 return &platforms[WR850GV2V3];
1375 case BCM47XX_BOARD_NETGEAR_WNDR3400V1:
1376 return &platforms[WNDR3400V1];
1377 case BCM47XX_BOARD_NETGEAR_WNDR3700V3:
1378 return &platforms[WNDR3700V3];
1379 case BCM47XX_BOARD_UNKNOWN:
1380 case BCM47XX_BOARD_NON:
1381 printk(MODULE_NAME ": unknown board found, try legacy detect\n");
1382 printk(MODULE_NAME ": please open a ticket at https://dev.openwrt.org and attach the complete nvram\n");
1383 return platform_detect_legacy();
1385 printk(MODULE_NAME ": board was detected as \"%s\", but not gpio configuration available\n", board_name);
1386 printk(MODULE_NAME ": now trying legacy detect\n");
1387 return platform_detect_legacy();
1391 static inline void ssb_maskset32(struct ssb_device *dev,
1392 u16 offset, u32 mask, u32 set)
1394 ssb_write32(dev, offset, (ssb_read32(dev, offset) & mask) | set);
1397 static void gpio_set_irqenable(int enabled, irqreturn_t (*handler)(int, void *))
1401 irq = gpio_to_irq(0);
1402 if (irq == -EINVAL) return;
1405 if (request_irq(irq, handler, IRQF_SHARED, "gpio", handler))
1408 free_irq(irq, handler);
1411 switch (bcm47xx_bus_type) {
1412 #ifdef CONFIG_BCM47XX_SSB
1413 case BCM47XX_BUS_TYPE_SSB:
1414 if (bcm47xx_bus.ssb.chipco.dev)
1415 ssb_maskset32(bcm47xx_bus.ssb.chipco.dev, SSB_CHIPCO_IRQMASK, ~SSB_CHIPCO_IRQ_GPIO, (enabled ? SSB_CHIPCO_IRQ_GPIO : 0));
1418 #ifdef CONFIG_BCM47XX_BCMA
1419 case BCM47XX_BUS_TYPE_BCMA:
1420 if (bcm47xx_bus.bcma.bus.drv_cc.core)
1421 bcma_maskset32(bcm47xx_bus.bcma.bus.drv_cc.core, BCMA_CC_IRQMASK, ~BCMA_CC_IRQ_GPIO, (enabled ? BCMA_CC_IRQ_GPIO : 0));
1427 static void hotplug_button(struct work_struct *work)
1429 struct event_t *event = container_of(work, struct event_t, wq);
1432 event->skb = alloc_skb(2048, GFP_KERNEL);
1434 s = skb_put(event->skb, strlen(event->action) + 2);
1435 sprintf(s, "%s@", event->action);
1438 NETLINK_CB(event->skb).dst_group = 1;
1439 broadcast_uevent(event->skb, 0, 1, GFP_KERNEL);
1444 static irqreturn_t button_handler(int irq, void *dev_id)
1449 in = bcm47xx_gpio_in(~0) & platform.button_mask;
1450 bcm47xx_gpio_polarity(platform.button_mask, in);
1451 changed = platform.button_polarity ^ in;
1452 platform.button_polarity = in;
1454 changed &= ~bcm47xx_gpio_outen(0, 0);
1456 for (b = platform.buttons; b->name; b++) {
1457 struct event_t *event;
1459 if (!(b->gpio & changed)) continue;
1463 if ((event = (struct event_t *)kzalloc (sizeof(struct event_t), GFP_ATOMIC))) {
1464 event->seen = (jiffies - b->seen)/HZ;
1465 event->name = b->name;
1466 event->action = b->pressed ? "pressed" : "released";
1467 INIT_WORK(&event->wq, (void *)(void *)hotplug_button);
1468 schedule_work(&event->wq);
1476 static void register_buttons(struct button_t *b)
1478 for (; b->name; b++)
1479 platform.button_mask |= b->gpio;
1481 platform.button_mask &= ~gpiomask;
1483 bcm47xx_gpio_outen(platform.button_mask, 0);
1484 bcm47xx_gpio_control(platform.button_mask, 0);
1485 platform.button_polarity = bcm47xx_gpio_in(~0) & platform.button_mask;
1486 bcm47xx_gpio_polarity(platform.button_mask, platform.button_polarity);
1487 bcm47xx_gpio_intmask(platform.button_mask, platform.button_mask);
1489 gpio_set_irqenable(1, button_handler);
1492 static void unregister_buttons(struct button_t *b)
1494 bcm47xx_gpio_intmask(platform.button_mask, 0);
1496 gpio_set_irqenable(0, button_handler);
1500 static void add_msg(struct event_t *event, char *msg, int argv)
1507 s = skb_put(event->skb, strlen(msg) + 1);
1511 static int fill_event (struct event_t *event)
1513 static char buf[128];
1515 add_msg(event, "HOME=/", 0);
1516 add_msg(event, "PATH=/sbin:/bin:/usr/sbin:/usr/bin", 0);
1517 add_msg(event, "SUBSYSTEM=button", 0);
1518 snprintf(buf, 128, "ACTION=%s", event->action);
1519 add_msg(event, buf, 0);
1520 snprintf(buf, 128, "BUTTON=%s", event->name);
1521 add_msg(event, buf, 0);
1522 snprintf(buf, 128, "SEEN=%ld", event->seen);
1523 add_msg(event, buf, 0);
1524 snprintf(buf, 128, "SEQNUM=%llu", uevent_next_seqnum());
1525 add_msg(event, buf, 0);
1531 * This should be extended to allow the platform to specify the pins and width
1532 * of the shift register. They're hardcoded for now because only the WNDR3700v3
1535 static void shiftreg_output(unsigned int val)
1539 bcm47xx_gpio_out(SHIFTREG_DATA, SHIFTREG_DATA); /* init off, pull high */
1540 bcm47xx_gpio_out(SHIFTREG_CLK, 0); /* init reset */
1543 for(mask = 1 << (SHIFTREG_MAX_BITS-1); mask; mask >>= 1)
1545 bcm47xx_gpio_out(SHIFTREG_DATA, (val & mask) ? SHIFTREG_DATA : 0);
1546 bcm47xx_gpio_out(SHIFTREG_CLK, SHIFTREG_CLK); /* pull high to trigger */
1547 bcm47xx_gpio_out(SHIFTREG_CLK, 0); /* reset to low */
1551 static void set_led_shift(struct led_t *led)
1553 static u32 shiftreg = 0;
1555 u32 pin = (led->gpio & ~GPIO_TYPE_MASK);
1563 /* Clock the bits out. */
1564 if (shiftreg != old) {
1565 shiftreg_output(shiftreg);
1569 static void set_led_extif(struct led_t *led)
1571 volatile u8 *addr = (volatile u8 *) KSEG1ADDR(EXTIF_UART) + (led->gpio & ~GPIO_TYPE_MASK);
1579 static void led_flash(unsigned long dummy) {
1584 for (l = platform.leds; l->name; l++) {
1585 if (!l->flash) continue;
1586 switch (l->gpio & GPIO_TYPE_MASK) {
1587 case GPIO_TYPE_EXTIF:
1589 l->state = !l->state;
1592 case GPIO_TYPE_SHIFT:
1594 l->state = !l->state;
1597 case GPIO_TYPE_NORMAL:
1606 u32 val = ~bcm47xx_gpio_in(~0);
1608 bcm47xx_gpio_outen(mask, mask);
1609 bcm47xx_gpio_control(mask, 0);
1610 bcm47xx_gpio_out(mask, val);
1612 if (mask || extif_blink) {
1613 mod_timer(&led_timer, jiffies + FLASH_TIME);
1617 static int diag_led_show(struct seq_file *m, void *v)
1619 struct led_t * led = m->private;
1621 u8 p = (led->polarity == NORMAL ? 0 : 1);
1623 return seq_printf(m, "f\n");
1624 } else if ((led->gpio & GPIO_TYPE_MASK) != GPIO_TYPE_NORMAL) {
1625 return seq_printf(m, "%d\n", ((led->state ^ p) ? 1 : 0));
1627 u32 in = (bcm47xx_gpio_in(~0) & led->gpio ? 1 : 0);
1628 return seq_printf(m, "%d\n", ((in ^ p) ? 1 : 0));
1632 static int diag_led_open(struct inode *inode, struct file *file)
1634 return single_open(file, diag_led_show, PDE_DATA(inode));
1637 static ssize_t diag_led_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
1639 struct led_t *led = PDE_DATA(file_inode(file));
1644 len = min(count, sizeof(cmd) - 1);
1645 if (copy_from_user(cmd, buf, len))
1650 p = (led->polarity == NORMAL ? 0 : 1);
1651 if (cmd[0] == 'f') {
1656 if ((led->gpio & GPIO_TYPE_MASK) == GPIO_TYPE_EXTIF) {
1657 led->state = p ^ ((cmd[0] == '1') ? 1 : 0);
1659 } else if ((led->gpio & GPIO_TYPE_MASK) == GPIO_TYPE_SHIFT) {
1660 led->state = p ^ ((cmd[0] == '1') ? 1 : 0);
1663 bcm47xx_gpio_outen(led->gpio, led->gpio);
1664 bcm47xx_gpio_control(led->gpio, 0);
1665 bcm47xx_gpio_out(led->gpio, ((p ^ (cmd[0] == '1')) ? led->gpio : 0));
1671 static const struct file_operations diag_led_fops = {
1672 .open = diag_led_open,
1674 .llseek = seq_lseek,
1675 .write = diag_led_write
1678 static void register_leds(struct led_t *l)
1680 struct proc_dir_entry *p;
1685 leds = proc_mkdir("led", diag);
1689 for(; l->name; l++) {
1690 if (l->gpio & gpiomask)
1693 switch (l->gpio & GPIO_TYPE_MASK) {
1694 case GPIO_TYPE_EXTIF:
1698 case GPIO_TYPE_SHIFT:
1699 mask |= (SHIFTREG_DATA | SHIFTREG_CLK);
1700 oe_mask |= (SHIFTREG_DATA | SHIFTREG_CLK);
1701 l->state = (l->polarity != NORMAL);
1704 case GPIO_TYPE_NORMAL:
1706 if (l->polarity != INPUT) oe_mask |= l->gpio;
1708 val |= (l->polarity == NORMAL)?0:l->gpio;
1712 if (l->polarity == INPUT) continue;
1714 p = proc_create_data(l->name, S_IRUSR, leds, &diag_led_fops, l);
1717 bcm47xx_gpio_outen(mask, oe_mask);
1718 bcm47xx_gpio_control(mask, 0);
1719 bcm47xx_gpio_out(mask, val);
1720 bcm47xx_gpio_intmask(mask, 0);
1723 static void unregister_leds(struct led_t *l)
1726 remove_proc_entry(l->name, leds);
1728 remove_proc_entry("led", diag);
1731 static int diag_model_show(struct seq_file *m, void *v)
1733 return seq_printf(m, "%s\n", platform.name);
1736 static int diag_model_open(struct inode *inode, struct file *file)
1738 return single_open(file, diag_model_show, PDE_DATA(inode));
1741 static const struct file_operations diag_model_fops = {
1742 .open = diag_model_open,
1747 static int diag_gpiomask_show(struct seq_file *m, void *v)
1749 return seq_printf(m, "0x%04x\n", gpiomask);
1752 static int diag_gpiomask_open(struct inode *inode, struct file *file)
1754 return single_open(file, diag_gpiomask_show, PDE_DATA(inode));
1757 static ssize_t diag_gpiomask_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
1759 int err = kstrtouint_from_user(buf, count, 0, &gpiomask);
1763 if (platform.buttons) {
1764 unregister_buttons(platform.buttons);
1765 register_buttons(platform.buttons);
1768 if (platform.leds) {
1769 unregister_leds(platform.leds);
1770 register_leds(platform.leds);
1776 static const struct file_operations diag_gpiomask_fops = {
1777 .open = diag_gpiomask_open,
1779 .llseek = seq_lseek,
1780 .write = diag_gpiomask_write
1783 static int __init diag_init(void)
1785 static struct proc_dir_entry *p;
1786 static struct platform_t *detected;
1788 detected = platform_detect();
1790 printk(MODULE_NAME ": Router model not detected.\n");
1793 memcpy(&platform, detected, sizeof(struct platform_t));
1795 printk(MODULE_NAME ": Detected '%s'\n", platform.name);
1796 if (platform.platform_init != NULL) {
1797 platform.platform_init();
1800 if (!(diag = proc_mkdir("diag", NULL))) {
1801 printk(MODULE_NAME ": proc_mkdir on /proc/diag failed\n");
1805 p = proc_create("model", S_IRUSR, diag, &diag_model_fops);
1807 remove_proc_entry("diag", NULL);
1811 p = proc_create("gpiomask", S_IRUSR | S_IWUSR, diag, &diag_gpiomask_fops);
1813 remove_proc_entry("model", diag);
1814 remove_proc_entry("diag", NULL);
1818 if (platform.buttons)
1819 register_buttons(platform.buttons);
1822 register_leds(platform.leds);
1827 static void __exit diag_exit(void)
1829 del_timer(&led_timer);
1831 if (platform.buttons)
1832 unregister_buttons(platform.buttons);
1835 unregister_leds(platform.leds);
1837 remove_proc_entry("model", diag);
1838 remove_proc_entry("gpiomask", diag);
1839 remove_proc_entry("diag", NULL);
1842 module_init(diag_init);
1843 module_exit(diag_exit);
1845 MODULE_AUTHOR("Mike Baker, Felix Fietkau / OpenWrt.org");
1846 MODULE_LICENSE("GPL");