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);
143 /* Western Digital */
159 static void __init
bcm4780_init(void) {
162 /* Enables GPIO 3 that controls HDD and led power on ASUS WL-700gE */
163 printk(MODULE_NAME
": Spinning up HDD and enabling leds\n");
164 bcm47xx_gpio_outen(pin
, pin
);
165 bcm47xx_gpio_control(pin
, 0);
166 bcm47xx_gpio_out(pin
, pin
);
168 /* Wait 5s, so the HDD can spin up */
169 set_current_state(TASK_INTERRUPTIBLE
);
170 schedule_timeout(HZ
* 5);
173 static void __init
NetCenter_init(void) {
174 /* unset pin 6 (+12V) */
176 bcm47xx_gpio_outen(pin
, pin
);
177 bcm47xx_gpio_control(pin
, 0);
178 bcm47xx_gpio_out(pin
, pin
);
179 /* unset pin 1 (turn off red led, blue will light alone if +5V comes up) */
181 bcm47xx_gpio_outen(pin
, pin
);
182 bcm47xx_gpio_control(pin
, 0);
183 bcm47xx_gpio_out(pin
, pin
);
184 /* unset pin 3 (+5V) and wait 5 seconds (harddisk spin up) */
188 static void __init
bcm57xx_init(void) {
191 /* FIXME: switch comes up, but port mappings/vlans not right */
192 bcm47xx_gpio_outen(pin
, pin
);
193 bcm47xx_gpio_control(pin
, 0);
194 bcm47xx_gpio_out(pin
, pin
);
197 static struct platform_t __initdata platforms
[] = {
200 .name
= "Linksys WAP54G V1",
202 { .name
= "reset", .gpio
= 1 << 0 },
205 { .name
= "diag", .gpio
= 1 << 3 },
206 { .name
= "wlan", .gpio
= 1 << 4 },
210 .name
= "Linksys WAP54G V2",
212 { .name
= "reset", .gpio
= 1 << 0 },
215 { .name
= "wlan", .gpio
= 1 << 5, .polarity
= REVERSE
},
216 /* GPIO 6 is b44 (eth0, LAN) PHY power */
220 .name
= "Linksys WAP54G V3",
222 /* FIXME: verify this */
223 { .name
= "reset", .gpio
= 1 << 7 },
224 { .name
= "ses", .gpio
= 1 << 0 },
228 { .name
= "ses", .gpio
= 1 << 1 },
232 .name
= "Linksys WRT54G V1.x",
234 { .name
= "reset", .gpio
= 1 << 6 },
237 { .name
= "diag", .gpio
= 0x13 | GPIO_TYPE_EXTIF
, .polarity
= NORMAL
},
238 { .name
= "dmz", .gpio
= 0x12 | GPIO_TYPE_EXTIF
, .polarity
= NORMAL
},
242 .name
= "Linksys WRT54G/GS/GL",
244 { .name
= "reset", .gpio
= 1 << 6 },
245 { .name
= "ses", .gpio
= 1 << 4 },
248 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
249 { .name
= "dmz", .gpio
= 1 << 7, .polarity
= REVERSE
},
250 { .name
= "ses_white", .gpio
= 1 << 2, .polarity
= REVERSE
},
251 { .name
= "ses_orange", .gpio
= 1 << 3, .polarity
= REVERSE
},
252 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
256 .name
= "Linksys WRTSL54GS",
258 { .name
= "reset", .gpio
= 1 << 6 },
259 { .name
= "ses", .gpio
= 1 << 4 },
262 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
263 { .name
= "dmz", .gpio
= 1 << 0, .polarity
= REVERSE
},
264 { .name
= "ses_white", .gpio
= 1 << 5, .polarity
= REVERSE
},
265 { .name
= "ses_orange", .gpio
= 1 << 7, .polarity
= REVERSE
},
269 .name
= "Linksys WRT54G3G",
271 { .name
= "reset", .gpio
= 1 << 6 },
272 { .name
= "3g", .gpio
= 1 << 4 },
275 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
276 { .name
= "dmz", .gpio
= 1 << 7, .polarity
= REVERSE
},
277 { .name
= "3g_green", .gpio
= 1 << 2, .polarity
= NORMAL
},
278 { .name
= "3g_blue", .gpio
= 1 << 3, .polarity
= NORMAL
},
279 { .name
= "3g_blink", .gpio
= 1 << 5, .polarity
= NORMAL
},
283 .name
= "Linksys WRT54G3GV2-VF",
285 { .name
= "reset", .gpio
= 1 << 6 },
286 { .name
= "3g", .gpio
= 1 << 5 },
289 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
290 { .name
= "3g_green", .gpio
= 1 << 2, .polarity
= NORMAL
},
291 { .name
= "3g_blue", .gpio
= 1 << 3, .polarity
= NORMAL
},
295 .name
= "Linksys WRT150N V1",
297 { .name
= "reset", .gpio
= 1 << 6 },
298 { .name
= "ses", .gpio
= 1 << 4 },
301 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
302 { .name
= "ses_green", .gpio
= 1 << 5, .polarity
= REVERSE
},
303 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
307 .name
= "Linksys WRT150N V1.1",
309 { .name
= "reset", .gpio
= 1 << 6 },
310 { .name
= "ses", .gpio
= 1 << 4 },
313 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
314 { .name
= "ses_green", .gpio
= 1 << 5, .polarity
= REVERSE
},
315 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
319 .name
= "Linksys WRT160N v1.x",
321 { .name
= "reset", .gpio
= 1 << 6 },
322 { .name
= "ses", .gpio
= 1 << 4 },
325 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
326 { .name
= "ses_blue", .gpio
= 1 << 5, .polarity
= REVERSE
},
327 { .name
= "ses_orange", .gpio
= 1 << 3, .polarity
= REVERSE
},
331 .name
= "Linksys WRT160N V3",
333 { .name
= "reset", .gpio
= 1 << 6 },
334 { .name
= "ses", .gpio
= 1 << 5 },
337 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
338 { .name
= "ses_blue", .gpio
= 1 << 4, .polarity
= REVERSE
},
339 { .name
= "ses_orange", .gpio
= 1 << 2, .polarity
= REVERSE
},
343 .name
= "Linksys WRT300N V1.1",
345 { .name
= "reset", .gpio
= 1 << 6 }, // "Reset" on back panel
346 { .name
= "ses", .gpio
= 1 << 4 }, // "Reserved" on top panel
349 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
}, // "Power"
350 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
}, // "Security" Amber
351 { .name
= "ses_green", .gpio
= 1 << 5, .polarity
= REVERSE
}, // "Security" Green
353 .platform_init
= bcm57xx_init
,
356 .name
= "Linksys WRT350N",
358 { .name
= "reset", .gpio
= 1 << 6 },
359 { .name
= "ses", .gpio
= 1 << 8 },
362 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
363 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
364 { .name
= "ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
},
365 { .name
= "usb_blink", .gpio
= 1 << 10, .polarity
= REVERSE
},
366 { .name
= "usb", .gpio
= 1 << 11, .polarity
= REVERSE
},
368 .platform_init
= bcm57xx_init
,
371 .name
= "Linksys WRT600N",
373 { .name
= "reset", .gpio
= 1 << 6 },
374 { .name
= "ses", .gpio
= 1 << 7 },
377 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
}, // Power LED
378 { .name
= "usb", .gpio
= 1 << 3, .polarity
= REVERSE
}, // USB LED
379 { .name
= "wl0_ses_amber", .gpio
= 1 << 8, .polarity
= REVERSE
}, // 2.4Ghz LED Amber
380 { .name
= "wl0_ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
}, // 2.4Ghz LED Green
381 { .name
= "wl1_ses_amber", .gpio
= 1 << 10, .polarity
= REVERSE
}, // 5.6Ghz LED Amber
382 { .name
= "wl1_ses_green", .gpio
= 1 << 11, .polarity
= REVERSE
}, // 5.6Ghz LED Green
384 .platform_init
= bcm57xx_init
,
387 .name
= "Linksys WRT600N V1.1",
389 { .name
= "reset", .gpio
= 1 << 6 },
390 { .name
= "ses", .gpio
= 1 << 7 },
393 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
}, // Power LED
394 { .name
= "usb", .gpio
= 1 << 3, .polarity
= REVERSE
}, // USB LED
395 { .name
= "wl0_ses_amber", .gpio
= 1 << 8, .polarity
= REVERSE
}, // 2.4Ghz LED Amber
396 { .name
= "wl0_ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
}, // 2.4Ghz LED Green
397 { .name
= "wl1_ses_amber", .gpio
= 1 << 10, .polarity
= REVERSE
}, // 5.6Ghz LED Amber
398 { .name
= "wl1_ses_green", .gpio
= 1 << 11, .polarity
= REVERSE
}, // 5.6Ghz LED Green
400 .platform_init
= bcm57xx_init
,
403 .name
= "Linksys WRT610N",
405 { .name
= "reset", .gpio
= 1 << 6 },
406 { .name
= "ses", .gpio
= 1 << 8 },
409 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
}, // Power LED
410 { .name
= "usb", .gpio
= 1 << 0, .polarity
= REVERSE
}, // USB LED
411 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
}, // WiFi protected setup LED amber
412 { .name
= "ses_blue", .gpio
= 1 << 9, .polarity
= REVERSE
}, // WiFi protected setup LED blue
416 .name
= "Linksys WRT610N V2",
418 { .name
= "reset", .gpio
= 1 << 6 },
419 { .name
= "ses", .gpio
= 1 << 4 },
422 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
}, // Power LED
423 { .name
= "usb", .gpio
= 1 << 7, .polarity
= NORMAL
}, // USB LED
424 { .name
= "ses_amber", .gpio
= 1 << 0, .polarity
= REVERSE
}, // WiFi protected setup LED amber
425 { .name
= "ses_blue", .gpio
= 1 << 3, .polarity
= REVERSE
}, // WiFi protected setup LED blue
426 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
}, // Wireless LED
429 /* same hardware as WRT160NV3 and Cisco Valet M10V1, but different board detection, combine? */
431 .name
= "Linksys E1000 V1",
433 { .name
= "reset", .gpio
= 1 << 6 },
434 { .name
= "wps", .gpio
= 1 << 5 }, /* nvram get gpio5=wps_button */
437 /** turns on leds for all ethernet ports (wan too)
438 * this also disconnects some, or maybe all, ethernet ports
439 * 1: leds work normally
440 * 0: all lit all the time */
441 /* nvram get gpio3=robo_reset */
442 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
443 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
444 { .name
= "ses_blue", .gpio
= 1 << 4, .polarity
= REVERSE
}, /* nvram get gpio4=wps_led */
445 { .name
= "ses_orange", .gpio
= 1 << 2, .polarity
= REVERSE
}, /* nvram get gpio2=wps_status_led */
449 .name
= "Linksys E3000 V1",
451 { .name
= "reset", .gpio
= 1 << 6 },
452 { .name
= "ses", .gpio
= 1 << 4 },
455 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
}, // Power LED
456 { .name
= "usb", .gpio
= 1 << 7, .polarity
= NORMAL
}, // USB LED
457 { .name
= "ses_amber", .gpio
= 1 << 0, .polarity
= REVERSE
}, // WiFi protected setup LED amber
458 { .name
= "ses_blue", .gpio
= 1 << 3, .polarity
= REVERSE
}, // WiFi protected setup LED blue
459 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
}, // Wireless LED
463 .name
= "Linksys E3200 V1",
465 /* { .name = "switch", .gpio = 1 << 4 },*/ /* nvram get gpio4=robo_reset */
466 { .name
= "reset", .gpio
= 1 << 5 }, /* nvram get reset_gpio=5 */
467 { .name
= "wps", .gpio
= 1 << 8 }, /* nvram get gpio8=wps_button */
468 /* { .name = "wombo", .gpio = 1 << 23 },*/ /* nvram get gpio23=wombo_reset - wireless on motherboard */
471 { .name
= "power", .gpio
= 1 << 3, .polarity
= REVERSE
}, /* Power LED */
476 .name
= "ASUS WL-HDD",
478 { .name
= "reset", .gpio
= 1 << 6 },
481 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
482 { .name
= "usb", .gpio
= 1 << 2, .polarity
= REVERSE
},
486 .name
= "ASUS WL-300g",
488 { .name
= "reset", .gpio
= 1 << 6 },
491 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
495 .name
= "ASUS WL-320gE/WL-320gP",
497 { .name
= "reset", .gpio
= 1 << 6 },
500 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
501 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
},
502 { .name
= "link", .gpio
= 1 << 11, .polarity
= REVERSE
},
506 .name
= "ASUS WL-330gE",
508 { .name
= "reset", .gpio
= 1 << 2 },
511 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
515 .name
= "ASUS WL-500g",
517 { .name
= "reset", .gpio
= 1 << 6 },
520 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
524 .name
= "ASUS WL-500g Deluxe",
526 { .name
= "reset", .gpio
= 1 << 6 },
529 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
533 .name
= "ASUS WL-500g Premium",
535 { .name
= "reset", .gpio
= 1 << 0 },
536 { .name
= "ses", .gpio
= 1 << 4 },
539 { .name
= "power", .gpio
= 1 << 1, .polarity
= REVERSE
},
543 .name
= "ASUS WL-500g Premium V2",
545 { .name
= "reset", .gpio
= 1 << 2 },
546 { .name
= "ses", .gpio
= 1 << 3 },
549 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
550 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
554 .name
= "ASUS WL-500W",
556 { .name
= "reset", .gpio
= 1 << 6 },
557 { .name
= "ses", .gpio
= 1 << 7 },
560 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
564 .name
= "ASUS WL-520GC",
566 { .name
= "reset", .gpio
= 1 << 2 },
567 { .name
= "ses", .gpio
= 1 << 3 },
570 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
571 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
575 .name
= "ASUS WL-520gU",
577 { .name
= "reset", .gpio
= 1 << 2 },
578 { .name
= "ses", .gpio
= 1 << 3 },
581 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
582 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
586 .name
= "ASUS (unknown, BCM4702)",
588 { .name
= "reset", .gpio
= 1 << 6 },
591 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
595 .name
= "ASUS WL-700gE",
597 { .name
= "reset", .gpio
= 1 << 7 }, // on back, hardwired, always resets device regardless OS state
598 { .name
= "ses", .gpio
= 1 << 4 }, // on back, actual name ezsetup
599 { .name
= "power", .gpio
= 1 << 0 }, // on front
600 { .name
= "copy", .gpio
= 1 << 6 }, // on front
604 // GPIO that controls power led also enables/disables some essential functions
607 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
}, // actual name power
609 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
611 .platform_init
= bcm4780_init
,
614 .name
= "ASUS RT-N16",
616 { .name
= "reset", .gpio
= 1 << 8 },
617 { .name
= "ses", .gpio
= 1 << 5 },
620 { .name
= "power", .gpio
= 1 << 1, .polarity
= REVERSE
},
621 { .name
= "wlan", .gpio
= 1 << 7, .polarity
= NORMAL
},
626 .name
= "Buffalo WHR-G54S",
628 { .name
= "reset", .gpio
= 1 << 4 },
629 { .name
= "bridge", .gpio
= 1 << 5 },
630 { .name
= "ses", .gpio
= 1 << 0 },
633 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
634 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
635 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
636 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
637 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
641 .name
= "Buffalo WBR2-G54",
644 { .name
= "reset", .gpio
= 1 << 7 },
647 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
651 .name
= "Buffalo WHR-HP-G54",
653 { .name
= "reset", .gpio
= 1 << 4 },
654 { .name
= "bridge", .gpio
= 1 << 5 },
655 { .name
= "ses", .gpio
= 1 << 0 },
658 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
659 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
660 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
661 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
662 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
666 .name
= "Buffalo WHR-G125",
668 { .name
= "reset", .gpio
= 1 << 4 },
669 { .name
= "bridge", .gpio
= 1 << 5 },
670 { .name
= "ses", .gpio
= 1 << 0 },
673 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
674 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
675 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
676 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
677 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
681 .name
= "Buffalo WHR2-A54G54",
683 { .name
= "reset", .gpio
= 1 << 4 },
686 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
690 .name
= "Buffalo WLA2-G54L",
693 { .name
= "reset", .gpio
= 1 << 7 },
696 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
700 .name
= "Buffalo WZR-G300N",
702 { .name
= "reset", .gpio
= 1 << 4 },
705 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
706 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
707 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
711 .name
= "Buffalo WZR-RS-G54",
713 { .name
= "ses", .gpio
= 1 << 0 },
714 { .name
= "reset", .gpio
= 1 << 4 },
717 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
718 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
719 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
723 .name
= "Buffalo WZR-RS-G54HP",
725 { .name
= "ses", .gpio
= 1 << 0 },
726 { .name
= "reset", .gpio
= 1 << 4 },
729 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
730 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
731 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
734 [BUFFALO_UNKNOWN
] = {
735 .name
= "Buffalo (unknown)",
737 { .name
= "reset", .gpio
= 1 << 7 },
740 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
743 [BUFFALO_UNKNOWN_4710
] = {
744 .name
= "Buffalo (unknown, BCM4710)",
746 { .name
= "reset", .gpio
= 1 << 4 },
749 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
754 .name
= "Siemens SE505 V1",
756 /* No usable buttons */
759 // { .name = "power", .gpio = 1 << 0 .polarity = REVERSE }, // Usable when retrofitting D26 (?)
760 { .name
= "dmz", .gpio
= 1 << 4, .polarity
= REVERSE
}, // actual name WWW
761 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
765 .name
= "Siemens SE505 V2",
767 /* No usable buttons */
770 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
771 { .name
= "dmz", .gpio
= 1 << 0, .polarity
= REVERSE
}, // actual name WWW
772 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
777 .name
= "U.S. Robotics USR5461",
779 /* No usable buttons */
782 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
783 { .name
= "printer", .gpio
= 1 << 1, .polarity
= REVERSE
},
788 .name
= "Dell TrueMobile 2300",
790 { .name
= "reset", .gpio
= 1 << 0 },
793 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
794 { .name
= "power", .gpio
= 1 << 7, .polarity
= REVERSE
},
798 .name
= "Dell TrueMobile 2300 v2",
800 { .name
= "reset", .gpio
= 1 << 0 },
803 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
804 { .name
= "power", .gpio
= 1 << 7, .polarity
= REVERSE
},
809 .name
= "Motorola WE800G",
811 { .name
= "reset", .gpio
= 1 << 0 },
814 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
815 { .name
= "diag", .gpio
= 1 << 2, .polarity
= REVERSE
},
816 { .name
= "wlan_amber", .gpio
= 1 << 1, .polarity
= NORMAL
},
820 .name
= "Motorola WR850G V1",
822 { .name
= "reset", .gpio
= 1 << 0 },
825 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
826 { .name
= "diag", .gpio
= 1 << 3, .polarity
= REVERSE
},
827 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= NORMAL
},
828 { .name
= "wlan_red", .gpio
= 1 << 5, .polarity
= REVERSE
},
829 { .name
= "wlan_green", .gpio
= 1 << 7, .polarity
= REVERSE
},
833 .name
= "Motorola WR850G V2/V3",
835 { .name
= "reset", .gpio
= 1 << 5 },
838 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
839 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
840 { .name
= "wan", .gpio
= 1 << 6, .polarity
= INPUT
},
841 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
845 .name
= "Motorola WR850GP",
847 { .name
= "reset", .gpio
= 1 << 5 },
850 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
851 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
852 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= REVERSE
},
853 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
859 .name
= "Belkin (unknown)",
860 /* FIXME: verify & add detection */
862 { .name
= "reset", .gpio
= 1 << 7 },
865 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
},
866 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= NORMAL
},
867 { .name
= "connected", .gpio
= 1 << 0, .polarity
= NORMAL
},
871 .name
= "Belkin PlayMax F7D4301",
873 { .name
= "reset", .gpio
= 1 << 6 },
874 { .name
= "wps", .gpio
= 1 << 8 },
877 { .name
= "power", .gpio
= 1 << 11, .polarity
= REVERSE
},
878 { .name
= "wlan", .gpio
= 1 << 13, .polarity
= REVERSE
},
879 { .name
= "led0", .gpio
= 1 << 14, .polarity
= REVERSE
},
880 { .name
= "led1", .gpio
= 1 << 15, .polarity
= REVERSE
},
885 .name
= "Netgear WGT634U",
887 { .name
= "reset", .gpio
= 1 << 2 },
890 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
},
895 .name
= "Netgear WNR834B V1",
896 .buttons
= { /* TODO: add reset button and confirm LEDs - GPIO from dd-wrt */ },
898 { .name
= "power", .gpio
= 1 << 4, .polarity
= REVERSE
},
899 { .name
= "diag", .gpio
= 1 << 5, .polarity
= REVERSE
},
900 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
905 .name
= "Netgear WNR834B V2",
907 { .name
= "reset", .gpio
= 1 << 6 },
910 { .name
= "power", .gpio
= 1 << 2, .polarity
= NORMAL
},
911 { .name
= "diag", .gpio
= 1 << 3, .polarity
= NORMAL
},
912 { .name
= "connected", .gpio
= 1 << 7, .polarity
= NORMAL
},
916 .name
= "Netgear WNDR3400 V1",
918 /* nvram get gpio5=robo_reset */
919 { .name
= "reset", .gpio
= 1 << 4 },
920 { .name
= "wps", .gpio
= 1 << 6 },
921 { .name
= "wlan", .gpio
= 1 << 8 },
924 { .name
= "wlan", .gpio
= 0 << 0, .polarity
= NORMAL
},
925 { .name
= "connected", .gpio
= 1 << 0, .polarity
= NORMAL
},
926 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
},
927 { .name
= "diag", .gpio
= 1 << 7, .polarity
= NORMAL
},
928 { .name
= "usb", .gpio
= 1 << 2, .polarity
= REVERSE
},
932 .name
= "Netgear WNDR3700 V3",
934 /* { .name = "usb", .gpio = 1 << 1 }, */ /* this button doesn't seem to exist. */
935 { .name
= "wlan", .gpio
= 1 << 2 },
936 { .name
= "reset", .gpio
= 1 << 3 },
937 { .name
= "wps", .gpio
= 1 << 4 },
938 /* { .name = "switch", .gpio = 1 << 5 },*/ /* nvram get gpio5=robo_reset */
941 { .name
= "power", .gpio
= (1 << 0) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
942 { .name
= "diag", .gpio
= (1 << 1) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
943 /* WAN LED doesn't respond to GPIO control. The switch is probably driving it.
944 * { .name = "wan", .gpio = (1 << 2) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
946 { .name
= "wlan2g", .gpio
= (1 << 3) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
947 { .name
= "wlan5g", .gpio
= (1 << 4) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
948 { .name
= "usb", .gpio
= (1 << 5) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
949 { .name
= "wps", .gpio
= (1 << 6) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
950 { .name
= "wlan", .gpio
= (1 << 7) | GPIO_TYPE_SHIFT
, .polarity
= REVERSE
},
955 .name
= "Trendware TEW411BRP+",
957 { /* No usable buttons */ },
960 { .name
= "power", .gpio
= 1 << 7, .polarity
= NORMAL
},
961 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
},
962 { .name
= "bridge", .gpio
= 1 << 6, .polarity
= NORMAL
},
967 .name
= "SimpleTech SimpleShare NAS",
969 { .name
= "reset", .gpio
= 1 << 0 }, // Power button on back, named reset to enable failsafe.
972 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
974 .platform_init
= bcm4780_init
,
978 .name
= "D-Link DIR-130",
980 { .name
= "reset", .gpio
= 1 << 3},
981 { .name
= "reserved", .gpio
= 1 << 7},
984 { .name
= "diag", .gpio
= 1 << 0},
985 { .name
= "blue", .gpio
= 1 << 6},
989 .name
= "D-Link DIR-320",
991 { .name
= "reserved", .gpio
= 1 << 6},
992 { .name
= "reset", .gpio
= 1 << 7},
995 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
996 { .name
= "diag", .gpio
= 1 << 1, .polarity
= NORMAL
}, /* "status led */
997 { .name
= "red", .gpio
= 1 << 3, .polarity
= REVERSE
},
998 { .name
= "blue", .gpio
= 1 << 4, .polarity
= REVERSE
},
999 { .name
= "usb", .gpio
= 1 << 5, .polarity
= NORMAL
},
1003 .name
= "D-Link DIR-330",
1005 { .name
= "reset", .gpio
= 1 << 3},
1006 { .name
= "reserved", .gpio
= 1 << 7},
1009 { .name
= "diag", .gpio
= 1 << 0},
1010 { .name
= "usb", .gpio
= 1 << 4},
1011 { .name
= "blue", .gpio
= 1 << 6},
1015 .name
= "D-Link DWL-3150",
1017 { .name
= "reset", .gpio
= 1 << 7},
1020 { .name
= "diag", .gpio
= 1 << 2},
1021 { .name
= "status", .gpio
= 1 << 1},
1026 .name
= "Sitecom WL-105b",
1028 { .name
= "reset", .gpio
= 1 << 10},
1031 { .name
= "wlan", .gpio
= 1 << 4},
1032 { .name
= "power", .gpio
= 1 << 3},
1035 /* Western Digital Net Center */
1037 .name
= "Western Digital NetCenter",
1039 { .name
= "power", .gpio
= 1 << 0},
1040 { .name
= "reset", .gpio
= 1 << 7},
1042 .platform_init
= NetCenter_init
,
1044 /* Askey (and clones) */
1046 .name
= "Askey RT210W",
1048 /* Power button is hard-wired to hardware reset */
1049 /* but is also connected to GPIO 7 (probably for bootloader recovery) */
1050 { .name
= "power", .gpio
= 1 << 7},
1053 /* These were verified and named based on Belkin F5D4230-4 v1112 */
1054 { .name
= "connected", .gpio
= 1 << 0, .polarity
= REVERSE
},
1055 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
1056 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
1060 .name
= "OvisLink WL-1600GL",
1062 { .name
= "reset", .gpio
= 1 << 3 },
1063 { .name
= "ses", .gpio
= 1 << 4 },
1066 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
1067 { .name
= "wps", .gpio
= 1 << 2, .polarity
= REVERSE
},
1068 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
1069 { .name
= "connected", .gpio
= 1 << 0, .polarity
= REVERSE
},
1074 .name
= "Microsoft MN-700",
1076 { .name
= "reset", .gpio
= 1 << 7 },
1079 { .name
= "power", .gpio
= 1 << 6, .polarity
= NORMAL
},
1084 .name
= "Edimax PS-1208MFG",
1086 { .name
= "reset", .gpio
= 1 << 4 },
1089 { .name
= "status", .gpio
= 1 << 1, .polarity
= NORMAL
},
1090 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
1095 static struct platform_t __init
*platform_detect_legacy(void)
1097 char *boardnum
, *boardtype
, *buf
;
1099 if (strcmp(getvar("nvram_type"), "cfe") == 0)
1100 return &platforms
[WGT634U
];
1103 /* no easy model number, attempt to guess */
1104 boardnum
= getvar("boardnum");
1105 boardtype
= getvar("boardtype");
1107 if (!strcmp(boardnum
, "20070615")) { /* Linksys WRT600N v1/V1.1 */
1108 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "0") && !strcmp(getvar("switch_type"),"BCM5395"))
1109 return &platforms
[WRT600NV11
];
1111 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "0"))
1112 return &platforms
[WRT600N
];
1115 if (startswith(getvar("pmon_ver"), "CFE")) {
1116 /* CFE based - newer hardware */
1117 if (!strcmp(boardnum
, "42")) { /* Linksys */
1118 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "1"))
1119 return &platforms
[WRT350N
];
1121 if (!strcmp(boardtype
, "0x0101") && !strcmp(getvar("boot_ver"), "v3.6"))
1122 return &platforms
[WRT54G3G
];
1124 if (!strcmp(getvar("et1phyaddr"),"5") && !strcmp(getvar("et1mdcport"), "1"))
1125 return &platforms
[WRTSL54GS
];
1127 /* default to WRT54G */
1128 return &platforms
[WRT54G
];
1130 if (!strcmp(boardnum
, "1024") && !strcmp(boardtype
, "0x0446"))
1131 return &platforms
[WAP54GV2
];
1133 if (!strcmp(boardnum
, "8") && !strcmp(boardtype
, "0x048e"))
1134 return &platforms
[WL1600GL
];
1137 if (!strcmp(boardnum
, "44") || !strcmp(boardnum
, "44\r")) {
1138 if (!strcmp(boardtype
,"0x0101") || !strcmp(boardtype
, "0x0101\r"))
1139 return &platforms
[TM2300V2
]; /* Dell TrueMobile 2300 v2 */
1142 if (!strcmp(boardnum
, "45")) { /* ASUS */
1143 if (!strcmp(boardtype
,"0x0472"))
1144 return &platforms
[WL500W
];
1145 else if (!strcmp(boardtype
,"0x467"))
1146 return &platforms
[WL320GE
];
1148 return &platforms
[WL500GD
];
1151 if (!strcmp(boardnum
, "10496"))
1152 return &platforms
[USR5461
];
1154 if (!strcmp(getvar("boardtype"), "0x0101") && !strcmp(getvar("boardrev"), "0x10")) /* SE505V2 With Modified CFE */
1155 return &platforms
[SE505V2
];
1157 if (!strcmp(boardtype
, "0x048e") && !strcmp(getvar("boardrev"),"0x35") &&
1158 !strcmp(getvar("boardflags"), "0x750")) /* D-Link DIR-320 */
1159 return &platforms
[DIR320
];
1161 if (!strncmp(boardnum
, "TH",2) && !strcmp(boardtype
,"0x042f")) {
1162 return &platforms
[WDNetCenter
];
1165 if (!strcmp(boardtype
,"0x0472") && !strcmp(getvar("cardbus"), "1")) { /* Netgear WNR834B V1 and V2*/
1166 if (!strcmp(boardnum
, "08") || !strcmp(boardnum
, "8"))
1167 return &platforms
[WNR834BV1
];
1168 if (!strcmp(boardnum
, "01") || !strcmp(boardnum
, "1"))
1169 return &platforms
[WNR834BV2
];
1172 } else { /* PMON based - old stuff */
1173 if ((simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 9) &&
1174 (simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 30)) {
1175 return &platforms
[WR850GV1
];
1177 if (startswith(boardtype
, "bcm94710dev")) {
1178 if (!strcmp(boardnum
, "42"))
1179 return &platforms
[WRT54GV1
];
1180 if (simple_strtoul(boardnum
, NULL
, 0) == 2)
1181 return &platforms
[WAP54GV1
];
1183 /* MN-700 has also hardware_version 'WL500-...', so use boardnum */
1184 if (startswith(getvar("hardware_version"), "WL500-")) {
1185 if (!strcmp(getvar("boardnum"), "mn700"))
1186 return &platforms
[MN700
];
1188 return &platforms
[WL500G
];
1190 if (startswith(getvar("hardware_version"), "WL300-")) {
1191 /* Either WL-300g or WL-HDD, do more extensive checks */
1192 if ((simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 0) &&
1193 (simple_strtoul(getvar("et1phyaddr"), NULL
, 0) == 1))
1194 return &platforms
[WLHDD
];
1195 if ((simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 0) &&
1196 (simple_strtoul(getvar("et1phyaddr"), NULL
, 0) == 10))
1197 return &platforms
[WL300G
];
1199 /* Sitecom WL-105b */
1200 if (startswith(boardnum
, "2") && simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 1)
1201 return &platforms
[WL105B
];
1203 /* unknown asus stuff, probably bcm4702 */
1204 if (startswith(boardnum
, "asusX"))
1205 return &platforms
[ASUS_4702
];
1207 /* bcm4702 based Askey RT210W clones, Including:
1208 * Askey RT210W (duh?)
1210 * Belkin F5D7230-4 before version v1444 (MiniPCI slot, not integrated)
1212 if (!strcmp(boardtype
,"bcm94710r4")
1213 && !strcmp(boardnum
,"100")
1214 && !strcmp(getvar("pmon_ver"),"v1.03.12.bk")
1216 return &platforms
[RT210W
];
1220 if (buf
|| !strcmp(boardnum
, "00")) {/* probably buffalo */
1221 if (startswith(boardtype
, "bcm94710ap"))
1222 return &platforms
[BUFFALO_UNKNOWN_4710
];
1224 return &platforms
[BUFFALO_UNKNOWN
];
1227 if (startswith(getvar("CFEver"), "MotoWRv2") ||
1228 startswith(getvar("CFEver"), "MotoWRv3") ||
1229 !strcmp(getvar("MOTO_BOARD_TYPE"), "WR_FEM1")) {
1231 return &platforms
[WR850GV2V3
];
1234 if (!strcmp(boardnum
, "44") && !strcmp(getvar("boardflags"),"0x0388")) { /* Trendware TEW-411BRP+ */
1235 return &platforms
[TEW411BRPP
];
1238 if (startswith(boardnum
, "04FN")) /* SimpleTech SimpleShare */
1239 return &platforms
[STI_NAS
];
1241 if (!strcmp(boardnum
, "10") && !strcmp(getvar("boardrev"), "0x13")) /* D-Link DWL-3150 */
1242 return &platforms
[DWL3150
];
1244 if (!strcmp(boardnum
, "01") && !strcmp(boardtype
, "0x048e") && /* Edimax PS1208MFG */
1245 !strcmp(getvar("status_gpio"), "1")) /* gpio based detection */
1246 return &platforms
[PS1208MFG
];
1252 static struct platform_t __init
*platform_detect(void)
1254 enum bcm47xx_board board
;
1255 const char *board_name
;
1258 board
= bcm47xx_board_get();
1259 board_name
= bcm47xx_board_get_name();
1260 if (board
!= BCM47XX_BOARD_UNKNOWN
&& board
!= BCM47XX_BOARD_NON
)
1261 printk(MODULE_NAME
": kernel found a \"%s\"\n", board_name
);
1264 case BCM47XX_BOARD_ASUS_RTN16
:
1265 return &platforms
[RTN16
];
1266 case BCM47XX_BOARD_ASUS_WL330GE
:
1267 return &platforms
[WL330GE
];
1268 case BCM47XX_BOARD_ASUS_WL500GPV1
:
1269 return &platforms
[WL500GP
];
1270 case BCM47XX_BOARD_ASUS_WL500GPV2
:
1271 return &platforms
[WL500GPV2
];
1272 case BCM47XX_BOARD_ASUS_WL520GC
:
1273 return &platforms
[WL520GC
];
1274 case BCM47XX_BOARD_ASUS_WL520GU
:
1275 return &platforms
[WL520GU
];
1276 case BCM47XX_BOARD_ASUS_WL700GE
:
1277 return &platforms
[WL700GE
];
1278 case BCM47XX_BOARD_BELKIN_F7D4301
:
1279 return &platforms
[BELKIN_F7D4301
];
1280 case BCM47XX_BOARD_BUFFALO_WBR2_G54
:
1281 return &platforms
[WBR2_G54
];
1282 case BCM47XX_BOARD_BUFFALO_WHR2_A54G54
:
1283 return &platforms
[WHR2_A54G54
];
1284 case BCM47XX_BOARD_BUFFALO_WHR_G125
:
1285 return &platforms
[WHR_G125
];
1286 case BCM47XX_BOARD_BUFFALO_WHR_G54S
:
1287 return &platforms
[WHR_G54S
];
1288 case BCM47XX_BOARD_BUFFALO_WHR_HP_G54
:
1289 return &platforms
[WHR_HP_G54
];
1290 case BCM47XX_BOARD_BUFFALO_WLA2_G54L
:
1291 return &platforms
[WLA2_G54L
];
1292 case BCM47XX_BOARD_BUFFALO_WZR_G300N
:
1293 return &platforms
[WZR_G300N
];
1294 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54
:
1295 return &platforms
[WZR_RS_G54
];
1296 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54HP
:
1297 return &platforms
[WZR_RS_G54HP
];
1298 case BCM47XX_BOARD_DELL_TM2300
:
1299 return &platforms
[TM2300
];
1300 case BCM47XX_BOARD_DLINK_DIR130
:
1301 return &platforms
[DIR130
];
1302 case BCM47XX_BOARD_DLINK_DIR330
:
1303 return &platforms
[DIR330
];
1304 case BCM47XX_BOARD_LINKSYS_E1000V1
:
1305 return &platforms
[E1000V1
];
1306 case BCM47XX_BOARD_LINKSYS_E3000V1
:
1307 return &platforms
[E3000V1
];
1308 case BCM47XX_BOARD_LINKSYS_E3200V1
:
1309 return &platforms
[E3200V1
];
1310 case BCM47XX_BOARD_LINKSYS_WRT150NV1
:
1311 return &platforms
[WRT150NV1
];
1312 case BCM47XX_BOARD_LINKSYS_WRT150NV11
:
1313 return &platforms
[WRT150NV11
];
1314 case BCM47XX_BOARD_LINKSYS_WRT160NV1
:
1315 return &platforms
[WRT160NV1
];
1316 case BCM47XX_BOARD_LINKSYS_WRT160NV3
:
1317 return &platforms
[WRT160NV3
];
1318 case BCM47XX_BOARD_LINKSYS_WRT300NV11
:
1319 return &platforms
[WRT300NV11
];
1320 case BCM47XX_BOARD_LINKSYS_WRT54G3GV2
:
1321 return &platforms
[WRT54G3GV2_VF
];
1322 case BCM47XX_BOARD_LINKSYS_WRT610NV1
:
1323 return &platforms
[WRT610N
];
1324 case BCM47XX_BOARD_LINKSYS_WRT610NV2
:
1325 return &platforms
[WRT610NV2
];
1326 case BCM47XX_BOARD_MOTOROLA_WE800G
:
1327 return &platforms
[WE800G
];
1328 case BCM47XX_BOARD_MOTOROLA_WR850GP
:
1329 return &platforms
[WR850GP
];
1330 case BCM47XX_BOARD_MOTOROLA_WR850GV2V3
:
1331 return &platforms
[WR850GV2V3
];
1332 case BCM47XX_BOARD_NETGEAR_WNDR3400V1
:
1333 return &platforms
[WNDR3400V1
];
1334 case BCM47XX_BOARD_NETGEAR_WNDR3700V3
:
1335 return &platforms
[WNDR3700V3
];
1336 case BCM47XX_BOARD_UNKNOWN
:
1337 case BCM47XX_BOARD_NON
:
1338 printk(MODULE_NAME
": unknown board found, try legacy detect\n");
1339 printk(MODULE_NAME
": please open a ticket at https://dev.openwrt.org and attach the complete nvram\n");
1340 return platform_detect_legacy();
1342 printk(MODULE_NAME
": board was detected as \"%s\", but not gpio configuration available\n", board_name
);
1343 printk(MODULE_NAME
": now trying legacy detect\n");
1344 return platform_detect_legacy();
1348 static inline void ssb_maskset32(struct ssb_device
*dev
,
1349 u16 offset
, u32 mask
, u32 set
)
1351 ssb_write32(dev
, offset
, (ssb_read32(dev
, offset
) & mask
) | set
);
1354 static void gpio_set_irqenable(int enabled
, irqreturn_t (*handler
)(int, void *))
1358 irq
= gpio_to_irq(0);
1359 if (irq
== -EINVAL
) return;
1362 if (request_irq(irq
, handler
, IRQF_SHARED
, "gpio", handler
))
1365 free_irq(irq
, handler
);
1368 switch (bcm47xx_bus_type
) {
1369 #ifdef CONFIG_BCM47XX_SSB
1370 case BCM47XX_BUS_TYPE_SSB
:
1371 if (bcm47xx_bus
.ssb
.chipco
.dev
)
1372 ssb_maskset32(bcm47xx_bus
.ssb
.chipco
.dev
, SSB_CHIPCO_IRQMASK
, ~SSB_CHIPCO_IRQ_GPIO
, (enabled
? SSB_CHIPCO_IRQ_GPIO
: 0));
1375 #ifdef CONFIG_BCM47XX_BCMA
1376 case BCM47XX_BUS_TYPE_BCMA
:
1377 if (bcm47xx_bus
.bcma
.bus
.drv_cc
.core
)
1378 bcma_maskset32(bcm47xx_bus
.bcma
.bus
.drv_cc
.core
, BCMA_CC_IRQMASK
, ~BCMA_CC_IRQ_GPIO
, (enabled
? BCMA_CC_IRQ_GPIO
: 0));
1384 static void register_buttons(struct button_t
*b
)
1386 for (; b
->name
; b
++)
1387 platform
.button_mask
|= b
->gpio
;
1389 platform
.button_mask
&= ~gpiomask
;
1391 bcm47xx_gpio_outen(platform
.button_mask
, 0);
1392 bcm47xx_gpio_control(platform
.button_mask
, 0);
1393 platform
.button_polarity
= bcm47xx_gpio_in(~0) & platform
.button_mask
;
1394 bcm47xx_gpio_polarity(platform
.button_mask
, platform
.button_polarity
);
1395 bcm47xx_gpio_intmask(platform
.button_mask
, platform
.button_mask
);
1397 gpio_set_irqenable(1, button_handler
);
1400 static void unregister_buttons(struct button_t
*b
)
1402 bcm47xx_gpio_intmask(platform
.button_mask
, 0);
1404 gpio_set_irqenable(0, button_handler
);
1408 static void add_msg(struct event_t
*event
, char *msg
, int argv
)
1415 s
= skb_put(event
->skb
, strlen(msg
) + 1);
1419 static void hotplug_button(struct work_struct
*work
)
1421 struct event_t
*event
= container_of(work
, struct event_t
, wq
);
1424 event
->skb
= alloc_skb(2048, GFP_KERNEL
);
1426 s
= skb_put(event
->skb
, strlen(event
->action
) + 2);
1427 sprintf(s
, "%s@", event
->action
);
1430 NETLINK_CB(event
->skb
).dst_group
= 1;
1431 broadcast_uevent(event
->skb
, 0, 1, GFP_KERNEL
);
1437 static int fill_event (struct event_t
*event
)
1439 static char buf
[128];
1441 add_msg(event
, "HOME=/", 0);
1442 add_msg(event
, "PATH=/sbin:/bin:/usr/sbin:/usr/bin", 0);
1443 add_msg(event
, "SUBSYSTEM=button", 0);
1444 snprintf(buf
, 128, "ACTION=%s", event
->action
);
1445 add_msg(event
, buf
, 0);
1446 snprintf(buf
, 128, "BUTTON=%s", event
->name
);
1447 add_msg(event
, buf
, 0);
1448 snprintf(buf
, 128, "SEEN=%ld", event
->seen
);
1449 add_msg(event
, buf
, 0);
1450 snprintf(buf
, 128, "SEQNUM=%llu", uevent_next_seqnum());
1451 add_msg(event
, buf
, 0);
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_leds(struct led_t
*l
)
1491 struct proc_dir_entry
*p
;
1496 leds
= proc_mkdir("led", diag
);
1500 for(; l
->name
; l
++) {
1501 if (l
->gpio
& gpiomask
)
1504 switch (l
->gpio
& GPIO_TYPE_MASK
) {
1505 case GPIO_TYPE_EXTIF
:
1509 case GPIO_TYPE_SHIFT
:
1510 mask
|= (SHIFTREG_DATA
| SHIFTREG_CLK
);
1511 oe_mask
|= (SHIFTREG_DATA
| SHIFTREG_CLK
);
1512 l
->state
= (l
->polarity
!= NORMAL
);
1515 case GPIO_TYPE_NORMAL
:
1517 if (l
->polarity
!= INPUT
) oe_mask
|= l
->gpio
;
1519 val
|= (l
->polarity
== NORMAL
)?0:l
->gpio
;
1523 if (l
->polarity
== INPUT
) continue;
1525 if ((p
= create_proc_entry(l
->name
, S_IRUSR
, leds
))) {
1526 l
->proc
.type
= PROC_LED
;
1528 p
->data
= (void *) &l
->proc
;
1529 p
->proc_fops
= &diag_proc_fops
;
1533 bcm47xx_gpio_outen(mask
, oe_mask
);
1534 bcm47xx_gpio_control(mask
, 0);
1535 bcm47xx_gpio_out(mask
, val
);
1536 bcm47xx_gpio_intmask(mask
, 0);
1539 static void unregister_leds(struct led_t
*l
)
1542 remove_proc_entry(l
->name
, leds
);
1544 remove_proc_entry("led", diag
);
1547 static void set_led_extif(struct led_t
*led
)
1549 volatile u8
*addr
= (volatile u8
*) KSEG1ADDR(EXTIF_UART
) + (led
->gpio
& ~GPIO_TYPE_MASK
);
1557 * This should be extended to allow the platform to specify the pins and width
1558 * of the shift register. They're hardcoded for now because only the WNDR3700v3
1561 static void shiftreg_output(unsigned int val
)
1565 bcm47xx_gpio_out(SHIFTREG_DATA
, SHIFTREG_DATA
); /* init off, pull high */
1566 bcm47xx_gpio_out(SHIFTREG_CLK
, 0); /* init reset */
1569 for(mask
= 1 << (SHIFTREG_MAX_BITS
-1); mask
; mask
>>= 1)
1571 bcm47xx_gpio_out(SHIFTREG_DATA
, (val
& mask
) ? SHIFTREG_DATA
: 0);
1572 bcm47xx_gpio_out(SHIFTREG_CLK
, SHIFTREG_CLK
); /* pull high to trigger */
1573 bcm47xx_gpio_out(SHIFTREG_CLK
, 0); /* reset to low */
1577 static void set_led_shift(struct led_t
*led
)
1579 static u32 shiftreg
= 0;
1581 u32 pin
= (led
->gpio
& ~GPIO_TYPE_MASK
);
1589 /* Clock the bits out. */
1590 if (shiftreg
!= old
) {
1591 shiftreg_output(shiftreg
);
1596 static void led_flash(unsigned long dummy
) {
1601 for (l
= platform
.leds
; l
->name
; l
++) {
1602 if (!l
->flash
) continue;
1603 switch (l
->gpio
& GPIO_TYPE_MASK
) {
1604 case GPIO_TYPE_EXTIF
:
1606 l
->state
= !l
->state
;
1609 case GPIO_TYPE_SHIFT
:
1611 l
->state
= !l
->state
;
1614 case GPIO_TYPE_NORMAL
:
1623 u32 val
= ~bcm47xx_gpio_in(~0);
1625 bcm47xx_gpio_outen(mask
, mask
);
1626 bcm47xx_gpio_control(mask
, 0);
1627 bcm47xx_gpio_out(mask
, val
);
1629 if (mask
|| extif_blink
) {
1630 mod_timer(&led_timer
, jiffies
+ FLASH_TIME
);
1634 static ssize_t
diag_proc_read(struct file
*file
, char *buf
, size_t count
, loff_t
*ppos
)
1636 struct proc_dir_entry
*dent
= PDE(file
->f_dentry
->d_inode
);
1640 if ((page
= kmalloc(1024, GFP_KERNEL
)) == NULL
)
1643 if (dent
->data
!= NULL
) {
1644 struct prochandler_t
*handler
= (struct prochandler_t
*) dent
->data
;
1645 switch (handler
->type
) {
1647 struct led_t
* led
= (struct led_t
*) handler
->ptr
;
1648 u8 p
= (led
->polarity
== NORMAL
? 0 : 1);
1650 len
= sprintf(page
, "f\n");
1651 } else if ((led
->gpio
& GPIO_TYPE_MASK
) != GPIO_TYPE_NORMAL
) {
1652 len
= sprintf(page
, "%d\n", ((led
->state
^ p
) ? 1 : 0));
1654 u32 in
= (bcm47xx_gpio_in(~0) & led
->gpio
? 1 : 0);
1655 len
= sprintf(page
, "%d\n", ((in
^ p
) ? 1 : 0));
1660 len
= sprintf(page
, "%s\n", platform
.name
);
1663 len
= sprintf(page
, "0x%04x\n", gpiomask
);
1670 len
= min_t(int, len
- *ppos
, count
);
1671 if (copy_to_user(buf
, (page
+ *ppos
), len
)) {
1685 static ssize_t
diag_proc_write(struct file
*file
, const char *buf
, size_t count
, loff_t
*ppos
)
1687 struct proc_dir_entry
*dent
= PDE(file
->f_dentry
->d_inode
);
1691 if ((page
= kmalloc(count
+ 1, GFP_KERNEL
)) == NULL
)
1694 if (copy_from_user(page
, buf
, count
)) {
1700 if (dent
->data
!= NULL
) {
1701 struct prochandler_t
*handler
= (struct prochandler_t
*) dent
->data
;
1702 switch (handler
->type
) {
1704 struct led_t
*led
= (struct led_t
*) handler
->ptr
;
1705 int p
= (led
->polarity
== NORMAL
? 0 : 1);
1707 if (page
[0] == 'f') {
1712 if ((led
->gpio
& GPIO_TYPE_MASK
) == GPIO_TYPE_EXTIF
) {
1713 led
->state
= p
^ ((page
[0] == '1') ? 1 : 0);
1715 } else if ((led
->gpio
& GPIO_TYPE_MASK
) == GPIO_TYPE_SHIFT
) {
1716 led
->state
= p
^ ((page
[0] == '1') ? 1 : 0);
1719 bcm47xx_gpio_outen(led
->gpio
, led
->gpio
);
1720 bcm47xx_gpio_control(led
->gpio
, 0);
1721 bcm47xx_gpio_out(led
->gpio
, ((p
^ (page
[0] == '1')) ? led
->gpio
: 0));
1727 gpiomask
= simple_strtoul(page
, NULL
, 0);
1729 if (platform
.buttons
) {
1730 unregister_buttons(platform
.buttons
);
1731 register_buttons(platform
.buttons
);
1734 if (platform
.leds
) {
1735 unregister_leds(platform
.leds
);
1736 register_leds(platform
.leds
);
1747 static int __init
diag_init(void)
1749 static struct proc_dir_entry
*p
;
1750 static struct platform_t
*detected
;
1752 detected
= platform_detect();
1754 printk(MODULE_NAME
": Router model not detected.\n");
1757 memcpy(&platform
, detected
, sizeof(struct platform_t
));
1759 printk(MODULE_NAME
": Detected '%s'\n", platform
.name
);
1760 if (platform
.platform_init
!= NULL
) {
1761 platform
.platform_init();
1764 if (!(diag
= proc_mkdir("diag", NULL
))) {
1765 printk(MODULE_NAME
": proc_mkdir on /proc/diag failed\n");
1769 if ((p
= create_proc_entry("model", S_IRUSR
, diag
))) {
1770 p
->data
= (void *) &proc_model
;
1771 p
->proc_fops
= &diag_proc_fops
;
1774 if ((p
= create_proc_entry("gpiomask", S_IRUSR
| S_IWUSR
, diag
))) {
1775 p
->data
= (void *) &proc_gpiomask
;
1776 p
->proc_fops
= &diag_proc_fops
;
1779 if (platform
.buttons
)
1780 register_buttons(platform
.buttons
);
1783 register_leds(platform
.leds
);
1788 static void __exit
diag_exit(void)
1790 del_timer(&led_timer
);
1792 if (platform
.buttons
)
1793 unregister_buttons(platform
.buttons
);
1796 unregister_leds(platform
.leds
);
1798 remove_proc_entry("model", diag
);
1799 remove_proc_entry("gpiomask", diag
);
1800 remove_proc_entry("diag", NULL
);
1803 module_init(diag_init
);
1804 module_exit(diag_exit
);
1806 MODULE_AUTHOR("Mike Baker, Felix Fietkau / OpenWrt.org");
1807 MODULE_LICENSE("GPL");