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);
142 /* Western Digital */
158 static void __init bcm4780_init(void) {
161 /* Enables GPIO 3 that controls HDD and led power on ASUS WL-700gE */
162 printk(MODULE_NAME ": Spinning up HDD and enabling leds\n");
163 bcm47xx_gpio_outen(pin, pin);
164 bcm47xx_gpio_control(pin, 0);
165 bcm47xx_gpio_out(pin, pin);
167 /* Wait 5s, so the HDD can spin up */
168 set_current_state(TASK_INTERRUPTIBLE);
169 schedule_timeout(HZ * 5);
172 static void __init NetCenter_init(void) {
173 /* unset pin 6 (+12V) */
175 bcm47xx_gpio_outen(pin, pin);
176 bcm47xx_gpio_control(pin, 0);
177 bcm47xx_gpio_out(pin, pin);
178 /* unset pin 1 (turn off red led, blue will light alone if +5V comes up) */
180 bcm47xx_gpio_outen(pin, pin);
181 bcm47xx_gpio_control(pin, 0);
182 bcm47xx_gpio_out(pin, pin);
183 /* unset pin 3 (+5V) and wait 5 seconds (harddisk spin up) */
187 static void __init bcm57xx_init(void) {
190 /* FIXME: switch comes up, but port mappings/vlans not right */
191 bcm47xx_gpio_outen(pin, pin);
192 bcm47xx_gpio_control(pin, 0);
193 bcm47xx_gpio_out(pin, pin);
196 static struct platform_t __initdata platforms[] = {
199 .name = "Linksys WAP54G V1",
201 { .name = "reset", .gpio = 1 << 0 },
204 { .name = "diag", .gpio = 1 << 3 },
205 { .name = "wlan", .gpio = 1 << 4 },
209 .name = "Linksys WAP54G V2",
211 { .name = "reset", .gpio = 1 << 0 },
214 { .name = "wlan", .gpio = 1 << 5, .polarity = REVERSE },
215 /* GPIO 6 is b44 (eth0, LAN) PHY power */
219 .name = "Linksys WAP54G V3",
221 /* FIXME: verify this */
222 { .name = "reset", .gpio = 1 << 7 },
223 { .name = "ses", .gpio = 1 << 0 },
227 { .name = "ses", .gpio = 1 << 1 },
231 .name = "Linksys WRT54G V1.x",
233 { .name = "reset", .gpio = 1 << 6 },
236 { .name = "diag", .gpio = 0x13 | GPIO_TYPE_EXTIF, .polarity = NORMAL },
237 { .name = "dmz", .gpio = 0x12 | GPIO_TYPE_EXTIF, .polarity = NORMAL },
241 .name = "Linksys WRT54G/GS/GL",
243 { .name = "reset", .gpio = 1 << 6 },
244 { .name = "ses", .gpio = 1 << 4 },
247 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
248 { .name = "dmz", .gpio = 1 << 7, .polarity = REVERSE },
249 { .name = "ses_white", .gpio = 1 << 2, .polarity = REVERSE },
250 { .name = "ses_orange", .gpio = 1 << 3, .polarity = REVERSE },
251 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
255 .name = "Linksys WRTSL54GS",
257 { .name = "reset", .gpio = 1 << 6 },
258 { .name = "ses", .gpio = 1 << 4 },
261 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
262 { .name = "dmz", .gpio = 1 << 0, .polarity = REVERSE },
263 { .name = "ses_white", .gpio = 1 << 5, .polarity = REVERSE },
264 { .name = "ses_orange", .gpio = 1 << 7, .polarity = REVERSE },
268 .name = "Linksys WRT54G3G",
270 { .name = "reset", .gpio = 1 << 6 },
271 { .name = "3g", .gpio = 1 << 4 },
274 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
275 { .name = "dmz", .gpio = 1 << 7, .polarity = REVERSE },
276 { .name = "3g_green", .gpio = 1 << 2, .polarity = NORMAL },
277 { .name = "3g_blue", .gpio = 1 << 3, .polarity = NORMAL },
278 { .name = "3g_blink", .gpio = 1 << 5, .polarity = NORMAL },
282 .name = "Linksys WRT54G3GV2-VF",
284 { .name = "reset", .gpio = 1 << 6 },
285 { .name = "3g", .gpio = 1 << 5 },
288 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
289 { .name = "3g_green", .gpio = 1 << 2, .polarity = NORMAL },
290 { .name = "3g_blue", .gpio = 1 << 3, .polarity = NORMAL },
294 .name = "Linksys WRT150N V1",
296 { .name = "reset", .gpio = 1 << 6 },
297 { .name = "ses", .gpio = 1 << 4 },
300 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
301 { .name = "ses_green", .gpio = 1 << 5, .polarity = REVERSE },
302 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE },
306 .name = "Linksys WRT150N V1.1",
308 { .name = "reset", .gpio = 1 << 6 },
309 { .name = "ses", .gpio = 1 << 4 },
312 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
313 { .name = "ses_green", .gpio = 1 << 5, .polarity = REVERSE },
314 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE },
318 .name = "Linksys WRT160N v1.x",
320 { .name = "reset", .gpio = 1 << 6 },
321 { .name = "ses", .gpio = 1 << 4 },
324 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
325 { .name = "ses_blue", .gpio = 1 << 5, .polarity = REVERSE },
326 { .name = "ses_orange", .gpio = 1 << 3, .polarity = REVERSE },
330 .name = "Linksys WRT160N V3",
332 { .name = "reset", .gpio = 1 << 6 },
333 { .name = "ses", .gpio = 1 << 5 },
336 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
337 { .name = "ses_blue", .gpio = 1 << 4, .polarity = REVERSE },
338 { .name = "ses_orange", .gpio = 1 << 2, .polarity = REVERSE },
342 .name = "Linksys WRT300N V1.1",
344 { .name = "reset", .gpio = 1 << 6 }, // "Reset" on back panel
345 { .name = "ses", .gpio = 1 << 4 }, // "Reserved" on top panel
348 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL }, // "Power"
349 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE }, // "Security" Amber
350 { .name = "ses_green", .gpio = 1 << 5, .polarity = REVERSE }, // "Security" Green
352 .platform_init = bcm57xx_init,
355 .name = "Linksys WRT350N",
357 { .name = "reset", .gpio = 1 << 6 },
358 { .name = "ses", .gpio = 1 << 8 },
361 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
362 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE },
363 { .name = "ses_green", .gpio = 1 << 9, .polarity = REVERSE },
364 { .name = "usb_blink", .gpio = 1 << 10, .polarity = REVERSE },
365 { .name = "usb", .gpio = 1 << 11, .polarity = REVERSE },
367 .platform_init = bcm57xx_init,
370 .name = "Linksys WRT600N",
372 { .name = "reset", .gpio = 1 << 6 },
373 { .name = "ses", .gpio = 1 << 7 },
376 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE }, // Power LED
377 { .name = "usb", .gpio = 1 << 3, .polarity = REVERSE }, // USB LED
378 { .name = "wl0_ses_amber", .gpio = 1 << 8, .polarity = REVERSE }, // 2.4Ghz LED Amber
379 { .name = "wl0_ses_green", .gpio = 1 << 9, .polarity = REVERSE }, // 2.4Ghz LED Green
380 { .name = "wl1_ses_amber", .gpio = 1 << 10, .polarity = REVERSE }, // 5.6Ghz LED Amber
381 { .name = "wl1_ses_green", .gpio = 1 << 11, .polarity = REVERSE }, // 5.6Ghz LED Green
383 .platform_init = bcm57xx_init,
386 .name = "Linksys WRT600N V1.1",
388 { .name = "reset", .gpio = 1 << 6 },
389 { .name = "ses", .gpio = 1 << 7 },
392 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE }, // Power LED
393 { .name = "usb", .gpio = 1 << 3, .polarity = REVERSE }, // USB LED
394 { .name = "wl0_ses_amber", .gpio = 1 << 8, .polarity = REVERSE }, // 2.4Ghz LED Amber
395 { .name = "wl0_ses_green", .gpio = 1 << 9, .polarity = REVERSE }, // 2.4Ghz LED Green
396 { .name = "wl1_ses_amber", .gpio = 1 << 10, .polarity = REVERSE }, // 5.6Ghz LED Amber
397 { .name = "wl1_ses_green", .gpio = 1 << 11, .polarity = REVERSE }, // 5.6Ghz LED Green
399 .platform_init = bcm57xx_init,
402 .name = "Linksys WRT610N",
404 { .name = "reset", .gpio = 1 << 6 },
405 { .name = "ses", .gpio = 1 << 8 },
408 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL }, // Power LED
409 { .name = "usb", .gpio = 1 << 0, .polarity = REVERSE }, // USB LED
410 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE }, // WiFi protected setup LED amber
411 { .name = "ses_blue", .gpio = 1 << 9, .polarity = REVERSE }, // WiFi protected setup LED blue
415 .name = "Linksys WRT610N V2",
417 { .name = "reset", .gpio = 1 << 6 },
418 { .name = "ses", .gpio = 1 << 4 },
421 { .name = "power", .gpio = 1 << 5, .polarity = NORMAL }, // Power LED
422 { .name = "usb", .gpio = 1 << 7, .polarity = NORMAL }, // USB LED
423 { .name = "ses_amber", .gpio = 1 << 0, .polarity = REVERSE }, // WiFi protected setup LED amber
424 { .name = "ses_blue", .gpio = 1 << 3, .polarity = REVERSE }, // WiFi protected setup LED blue
425 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL }, // Wireless LED
428 /* same hardware as WRT160NV3 and Cisco Valet M10V1, but different board detection, combine? */
430 .name = "Linksys E1000 V1",
432 { .name = "reset", .gpio = 1 << 6 },
433 { .name = "wps", .gpio = 1 << 5 }, /* nvram get gpio5=wps_button */
436 /** turns on leds for all ethernet ports (wan too)
437 * this also disconnects some, or maybe all, ethernet ports
438 * 1: leds work normally
439 * 0: all lit all the time */
440 /* nvram get gpio3=robo_reset */
441 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
442 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
443 { .name = "ses_blue", .gpio = 1 << 4, .polarity = REVERSE }, /* nvram get gpio4=wps_led */
444 { .name = "ses_orange", .gpio = 1 << 2, .polarity = REVERSE }, /* nvram get gpio2=wps_status_led */
448 .name = "Linksys E3000 V1",
450 { .name = "reset", .gpio = 1 << 6 },
451 { .name = "ses", .gpio = 1 << 4 },
454 { .name = "power", .gpio = 1 << 5, .polarity = NORMAL }, // Power LED
455 { .name = "usb", .gpio = 1 << 7, .polarity = NORMAL }, // USB LED
456 { .name = "ses_amber", .gpio = 1 << 0, .polarity = REVERSE }, // WiFi protected setup LED amber
457 { .name = "ses_blue", .gpio = 1 << 3, .polarity = REVERSE }, // WiFi protected setup LED blue
458 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL }, // Wireless LED
462 .name = "Linksys E3200 V1",
464 /* { .name = "switch", .gpio = 1 << 4 },*/ /* nvram get gpio4=robo_reset */
465 { .name = "reset", .gpio = 1 << 5 }, /* nvram get reset_gpio=5 */
466 { .name = "wps", .gpio = 1 << 8 }, /* nvram get gpio8=wps_button */
467 /* { .name = "wombo", .gpio = 1 << 23 },*/ /* nvram get gpio23=wombo_reset - wireless on motherboard */
470 { .name = "power", .gpio = 1 << 3, .polarity = REVERSE }, /* Power LED */
475 .name = "ASUS WL-HDD",
477 { .name = "reset", .gpio = 1 << 6 },
480 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
481 { .name = "usb", .gpio = 1 << 2, .polarity = REVERSE },
485 .name = "ASUS WL-300g",
487 { .name = "reset", .gpio = 1 << 6 },
490 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
494 .name = "ASUS WL-320gE/WL-320gP",
496 { .name = "reset", .gpio = 1 << 6 },
499 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
500 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE },
501 { .name = "link", .gpio = 1 << 11, .polarity = REVERSE },
505 .name = "ASUS WL-330gE",
507 { .name = "reset", .gpio = 1 << 2 },
510 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
514 .name = "ASUS WL-500g",
516 { .name = "reset", .gpio = 1 << 6 },
519 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
523 .name = "ASUS WL-500g Deluxe",
525 { .name = "reset", .gpio = 1 << 6 },
528 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
532 .name = "ASUS WL-500g Premium",
534 { .name = "reset", .gpio = 1 << 0 },
535 { .name = "ses", .gpio = 1 << 4 },
538 { .name = "power", .gpio = 1 << 1, .polarity = REVERSE },
542 .name = "ASUS WL-500g Premium V2",
544 { .name = "reset", .gpio = 1 << 2 },
545 { .name = "ses", .gpio = 1 << 3 },
548 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
549 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
553 .name = "ASUS WL-500W",
555 { .name = "reset", .gpio = 1 << 6 },
556 { .name = "ses", .gpio = 1 << 7 },
559 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
563 .name = "ASUS WL-520GC",
565 { .name = "reset", .gpio = 1 << 2 },
566 { .name = "ses", .gpio = 1 << 3 },
569 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
570 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
574 .name = "ASUS WL-520gU",
576 { .name = "reset", .gpio = 1 << 2 },
577 { .name = "ses", .gpio = 1 << 3 },
580 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
581 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
585 .name = "ASUS (unknown, BCM4702)",
587 { .name = "reset", .gpio = 1 << 6 },
590 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
594 .name = "ASUS WL-700gE",
596 { .name = "reset", .gpio = 1 << 7 }, // on back, hardwired, always resets device regardless OS state
597 { .name = "ses", .gpio = 1 << 4 }, // on back, actual name ezsetup
598 { .name = "power", .gpio = 1 << 0 }, // on front
599 { .name = "copy", .gpio = 1 << 6 }, // on front
603 // GPIO that controls power led also enables/disables some essential functions
606 { .name = "power", .gpio = 1 << 3, .polarity = NORMAL }, // actual name power
608 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE }, // actual name ready
610 .platform_init = bcm4780_init,
613 .name = "ASUS RT-N16",
615 { .name = "reset", .gpio = 1 << 8 },
616 { .name = "ses", .gpio = 1 << 5 },
619 { .name = "power", .gpio = 1 << 1, .polarity = REVERSE },
620 { .name = "wlan", .gpio = 1 << 7, .polarity = NORMAL },
625 .name = "Buffalo WHR-G54S",
627 { .name = "reset", .gpio = 1 << 4 },
628 { .name = "bridge", .gpio = 1 << 5 },
629 { .name = "ses", .gpio = 1 << 0 },
632 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
633 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
634 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
635 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
636 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
640 .name = "Buffalo WBR2-G54",
643 { .name = "reset", .gpio = 1 << 7 },
646 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
650 .name = "Buffalo WHR-HP-G54",
652 { .name = "reset", .gpio = 1 << 4 },
653 { .name = "bridge", .gpio = 1 << 5 },
654 { .name = "ses", .gpio = 1 << 0 },
657 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
658 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
659 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
660 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
661 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
665 .name = "Buffalo WHR-G125",
667 { .name = "reset", .gpio = 1 << 4 },
668 { .name = "bridge", .gpio = 1 << 5 },
669 { .name = "ses", .gpio = 1 << 0 },
672 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
673 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
674 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
675 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
676 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
680 .name = "Buffalo WHR2-A54G54",
682 { .name = "reset", .gpio = 1 << 4 },
685 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
689 .name = "Buffalo WLA2-G54L",
692 { .name = "reset", .gpio = 1 << 7 },
695 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
699 .name = "Buffalo WZR-G300N",
701 { .name = "reset", .gpio = 1 << 4 },
704 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
705 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
706 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
710 .name = "Buffalo WZR-RS-G54",
712 { .name = "ses", .gpio = 1 << 0 },
713 { .name = "reset", .gpio = 1 << 4 },
716 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
717 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
718 { .name = "vpn", .gpio = 1 << 1, .polarity = REVERSE },
722 .name = "Buffalo WZR-RS-G54HP",
724 { .name = "ses", .gpio = 1 << 0 },
725 { .name = "reset", .gpio = 1 << 4 },
728 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
729 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
730 { .name = "vpn", .gpio = 1 << 1, .polarity = REVERSE },
733 [BUFFALO_UNKNOWN] = {
734 .name = "Buffalo (unknown)",
736 { .name = "reset", .gpio = 1 << 7 },
739 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
742 [BUFFALO_UNKNOWN_4710] = {
743 .name = "Buffalo (unknown, BCM4710)",
745 { .name = "reset", .gpio = 1 << 4 },
748 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
753 .name = "Siemens SE505 V1",
755 /* No usable buttons */
758 // { .name = "power", .gpio = 1 << 0 .polarity = REVERSE }, // Usable when retrofitting D26 (?)
759 { .name = "dmz", .gpio = 1 << 4, .polarity = REVERSE }, // actual name WWW
760 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
764 .name = "Siemens SE505 V2",
766 /* No usable buttons */
769 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
770 { .name = "dmz", .gpio = 1 << 0, .polarity = REVERSE }, // actual name WWW
771 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
776 .name = "U.S. Robotics USR5461",
778 /* No usable buttons */
781 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
782 { .name = "printer", .gpio = 1 << 1, .polarity = REVERSE },
787 .name = "Dell TrueMobile 2300",
789 { .name = "reset", .gpio = 1 << 0 },
792 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
793 { .name = "power", .gpio = 1 << 7, .polarity = REVERSE },
797 .name = "Dell TrueMobile 2300 v2",
799 { .name = "reset", .gpio = 1 << 0 },
802 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
803 { .name = "power", .gpio = 1 << 7, .polarity = REVERSE },
808 .name = "Motorola WE800G",
810 { .name = "reset", .gpio = 1 << 0 },
813 { .name = "power", .gpio = 1 << 4, .polarity = NORMAL },
814 { .name = "diag", .gpio = 1 << 2, .polarity = REVERSE },
815 { .name = "wlan_amber", .gpio = 1 << 1, .polarity = NORMAL },
819 .name = "Motorola WR850G V1",
821 { .name = "reset", .gpio = 1 << 0 },
824 { .name = "power", .gpio = 1 << 4, .polarity = NORMAL },
825 { .name = "diag", .gpio = 1 << 3, .polarity = REVERSE },
826 { .name = "dmz", .gpio = 1 << 6, .polarity = NORMAL },
827 { .name = "wlan_red", .gpio = 1 << 5, .polarity = REVERSE },
828 { .name = "wlan_green", .gpio = 1 << 7, .polarity = REVERSE },
832 .name = "Motorola WR850G V2/V3",
834 { .name = "reset", .gpio = 1 << 5 },
837 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
838 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
839 { .name = "wan", .gpio = 1 << 6, .polarity = INPUT },
840 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
844 .name = "Motorola WR850GP",
846 { .name = "reset", .gpio = 1 << 5 },
849 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
850 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
851 { .name = "dmz", .gpio = 1 << 6, .polarity = REVERSE },
852 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
858 .name = "Belkin (unknown)",
859 /* FIXME: verify & add detection */
861 { .name = "reset", .gpio = 1 << 7 },
864 { .name = "power", .gpio = 1 << 5, .polarity = NORMAL },
865 { .name = "wlan", .gpio = 1 << 3, .polarity = NORMAL },
866 { .name = "connected", .gpio = 1 << 0, .polarity = NORMAL },
870 .name = "Belkin PlayMax F7D4301",
872 { .name = "reset", .gpio = 1 << 6 },
873 { .name = "wps", .gpio = 1 << 8 },
876 { .name = "power", .gpio = 1 << 11, .polarity = REVERSE },
877 { .name = "wlan", .gpio = 1 << 13, .polarity = REVERSE },
878 { .name = "led0", .gpio = 1 << 14, .polarity = REVERSE },
879 { .name = "led1", .gpio = 1 << 15, .polarity = REVERSE },
884 .name = "Netgear WGT634U",
886 { .name = "reset", .gpio = 1 << 2 },
889 { .name = "power", .gpio = 1 << 3, .polarity = NORMAL },
894 .name = "Netgear WNR834B V1",
895 .buttons = { /* TODO: add reset button and confirm LEDs - GPIO from dd-wrt */ },
897 { .name = "power", .gpio = 1 << 4, .polarity = REVERSE },
898 { .name = "diag", .gpio = 1 << 5, .polarity = REVERSE },
899 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
904 .name = "Netgear WNR834B V2",
906 { .name = "reset", .gpio = 1 << 6 },
909 { .name = "power", .gpio = 1 << 2, .polarity = NORMAL },
910 { .name = "diag", .gpio = 1 << 3, .polarity = NORMAL },
911 { .name = "connected", .gpio = 1 << 7, .polarity = NORMAL },
915 .name = "Netgear WNDR3400 V1",
917 /* nvram get gpio5=robo_reset */
918 { .name = "reset", .gpio = 1 << 4 },
919 { .name = "wps", .gpio = 1 << 6 },
920 { .name = "wlan", .gpio = 1 << 8 },
923 { .name = "wlan", .gpio = 0 << 0, .polarity = NORMAL },
924 { .name = "connected", .gpio = 1 << 0, .polarity = NORMAL },
925 { .name = "power", .gpio = 1 << 3, .polarity = NORMAL },
926 { .name = "diag", .gpio = 1 << 7, .polarity = NORMAL },
927 { .name = "usb", .gpio = 1 << 2, .polarity = REVERSE },
932 .name = "Trendware TEW411BRP+",
934 { /* No usable buttons */ },
937 { .name = "power", .gpio = 1 << 7, .polarity = NORMAL },
938 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL },
939 { .name = "bridge", .gpio = 1 << 6, .polarity = NORMAL },
944 .name = "SimpleTech SimpleShare NAS",
946 { .name = "reset", .gpio = 1 << 0 }, // Power button on back, named reset to enable failsafe.
949 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE }, // actual name ready
951 .platform_init = bcm4780_init,
955 .name = "D-Link DIR-130",
957 { .name = "reset", .gpio = 1 << 3},
958 { .name = "reserved", .gpio = 1 << 7},
961 { .name = "diag", .gpio = 1 << 0},
962 { .name = "blue", .gpio = 1 << 6},
966 .name = "D-Link DIR-320",
968 { .name = "reserved", .gpio = 1 << 6},
969 { .name = "reset", .gpio = 1 << 7},
972 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
973 { .name = "diag", .gpio = 1 << 1, .polarity = NORMAL }, /* "status led */
974 { .name = "red", .gpio = 1 << 3, .polarity = REVERSE },
975 { .name = "blue", .gpio = 1 << 4, .polarity = REVERSE },
976 { .name = "usb", .gpio = 1 << 5, .polarity = NORMAL },
980 .name = "D-Link DIR-330",
982 { .name = "reset", .gpio = 1 << 3},
983 { .name = "reserved", .gpio = 1 << 7},
986 { .name = "diag", .gpio = 1 << 0},
987 { .name = "usb", .gpio = 1 << 4},
988 { .name = "blue", .gpio = 1 << 6},
992 .name = "D-Link DWL-3150",
994 { .name = "reset", .gpio = 1 << 7},
997 { .name = "diag", .gpio = 1 << 2},
998 { .name = "status", .gpio = 1 << 1},
1003 .name = "Sitecom WL-105b",
1005 { .name = "reset", .gpio = 1 << 10},
1008 { .name = "wlan", .gpio = 1 << 4},
1009 { .name = "power", .gpio = 1 << 3},
1012 /* Western Digital Net Center */
1014 .name = "Western Digital NetCenter",
1016 { .name = "power", .gpio = 1 << 0},
1017 { .name = "reset", .gpio = 1 << 7},
1019 .platform_init = NetCenter_init,
1021 /* Askey (and clones) */
1023 .name = "Askey RT210W",
1025 /* Power button is hard-wired to hardware reset */
1026 /* but is also connected to GPIO 7 (probably for bootloader recovery) */
1027 { .name = "power", .gpio = 1 << 7},
1030 /* These were verified and named based on Belkin F5D4230-4 v1112 */
1031 { .name = "connected", .gpio = 1 << 0, .polarity = REVERSE },
1032 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
1033 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
1037 .name = "OvisLink WL-1600GL",
1039 { .name = "reset", .gpio = 1 << 3 },
1040 { .name = "ses", .gpio = 1 << 4 },
1043 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
1044 { .name = "wps", .gpio = 1 << 2, .polarity = REVERSE },
1045 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
1046 { .name = "connected", .gpio = 1 << 0, .polarity = REVERSE },
1051 .name = "Microsoft MN-700",
1053 { .name = "reset", .gpio = 1 << 7 },
1056 { .name = "power", .gpio = 1 << 6, .polarity = NORMAL },
1061 .name = "Edimax PS-1208MFG",
1063 { .name = "reset", .gpio = 1 << 4 },
1066 { .name = "status", .gpio = 1 << 1, .polarity = NORMAL },
1067 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
1072 static struct platform_t __init *platform_detect_legacy(void)
1074 char *boardnum, *boardtype, *buf;
1076 if (strcmp(getvar("nvram_type"), "cfe") == 0)
1077 return &platforms[WGT634U];
1080 /* no easy model number, attempt to guess */
1081 boardnum = getvar("boardnum");
1082 boardtype = getvar("boardtype");
1084 if (!strcmp(boardnum, "20070615")) { /* Linksys WRT600N v1/V1.1 */
1085 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "0") && !strcmp(getvar("switch_type"),"BCM5395"))
1086 return &platforms[WRT600NV11];
1088 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "0"))
1089 return &platforms[WRT600N];
1092 if (startswith(getvar("pmon_ver"), "CFE")) {
1093 /* CFE based - newer hardware */
1094 if (!strcmp(boardnum, "42")) { /* Linksys */
1095 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "1"))
1096 return &platforms[WRT350N];
1098 if (!strcmp(boardtype, "0x0101") && !strcmp(getvar("boot_ver"), "v3.6"))
1099 return &platforms[WRT54G3G];
1101 if (!strcmp(getvar("et1phyaddr"),"5") && !strcmp(getvar("et1mdcport"), "1"))
1102 return &platforms[WRTSL54GS];
1104 /* default to WRT54G */
1105 return &platforms[WRT54G];
1107 if (!strcmp(boardnum, "1024") && !strcmp(boardtype, "0x0446"))
1108 return &platforms[WAP54GV2];
1110 if (!strcmp(boardnum, "8") && !strcmp(boardtype, "0x048e"))
1111 return &platforms[WL1600GL];
1114 if (!strcmp(boardnum, "44") || !strcmp(boardnum, "44\r")) {
1115 if (!strcmp(boardtype,"0x0101") || !strcmp(boardtype, "0x0101\r"))
1116 return &platforms[TM2300V2]; /* Dell TrueMobile 2300 v2 */
1119 if (!strcmp(boardnum, "45")) { /* ASUS */
1120 if (!strcmp(boardtype,"0x0472"))
1121 return &platforms[WL500W];
1122 else if (!strcmp(boardtype,"0x467"))
1123 return &platforms[WL320GE];
1125 return &platforms[WL500GD];
1128 if (!strcmp(boardnum, "10496"))
1129 return &platforms[USR5461];
1131 if (!strcmp(getvar("boardtype"), "0x0101") && !strcmp(getvar("boardrev"), "0x10")) /* SE505V2 With Modified CFE */
1132 return &platforms[SE505V2];
1134 if (!strcmp(boardtype, "0x048e") && !strcmp(getvar("boardrev"),"0x35") &&
1135 !strcmp(getvar("boardflags"), "0x750")) /* D-Link DIR-320 */
1136 return &platforms[DIR320];
1138 if (!strncmp(boardnum, "TH",2) && !strcmp(boardtype,"0x042f")) {
1139 return &platforms[WDNetCenter];
1142 if (!strcmp(boardtype,"0x0472") && !strcmp(getvar("cardbus"), "1")) { /* Netgear WNR834B V1 and V2*/
1143 if (!strcmp(boardnum, "08") || !strcmp(boardnum, "8"))
1144 return &platforms[WNR834BV1];
1145 if (!strcmp(boardnum, "01") || !strcmp(boardnum, "1"))
1146 return &platforms[WNR834BV2];
1149 } else { /* PMON based - old stuff */
1150 if ((simple_strtoul(getvar("GemtekPmonVer"), NULL, 0) == 9) &&
1151 (simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 30)) {
1152 return &platforms[WR850GV1];
1154 if (startswith(boardtype, "bcm94710dev")) {
1155 if (!strcmp(boardnum, "42"))
1156 return &platforms[WRT54GV1];
1157 if (simple_strtoul(boardnum, NULL, 0) == 2)
1158 return &platforms[WAP54GV1];
1160 /* MN-700 has also hardware_version 'WL500-...', so use boardnum */
1161 if (startswith(getvar("hardware_version"), "WL500-")) {
1162 if (!strcmp(getvar("boardnum"), "mn700"))
1163 return &platforms[MN700];
1165 return &platforms[WL500G];
1167 if (startswith(getvar("hardware_version"), "WL300-")) {
1168 /* Either WL-300g or WL-HDD, do more extensive checks */
1169 if ((simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 0) &&
1170 (simple_strtoul(getvar("et1phyaddr"), NULL, 0) == 1))
1171 return &platforms[WLHDD];
1172 if ((simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 0) &&
1173 (simple_strtoul(getvar("et1phyaddr"), NULL, 0) == 10))
1174 return &platforms[WL300G];
1176 /* Sitecom WL-105b */
1177 if (startswith(boardnum, "2") && simple_strtoul(getvar("GemtekPmonVer"), NULL, 0) == 1)
1178 return &platforms[WL105B];
1180 /* unknown asus stuff, probably bcm4702 */
1181 if (startswith(boardnum, "asusX"))
1182 return &platforms[ASUS_4702];
1184 /* bcm4702 based Askey RT210W clones, Including:
1185 * Askey RT210W (duh?)
1187 * Belkin F5D7230-4 before version v1444 (MiniPCI slot, not integrated)
1189 if (!strcmp(boardtype,"bcm94710r4")
1190 && !strcmp(boardnum ,"100")
1191 && !strcmp(getvar("pmon_ver"),"v1.03.12.bk")
1193 return &platforms[RT210W];
1197 if (buf || !strcmp(boardnum, "00")) {/* probably buffalo */
1198 if (startswith(boardtype, "bcm94710ap"))
1199 return &platforms[BUFFALO_UNKNOWN_4710];
1201 return &platforms[BUFFALO_UNKNOWN];
1204 if (startswith(getvar("CFEver"), "MotoWRv2") ||
1205 startswith(getvar("CFEver"), "MotoWRv3") ||
1206 !strcmp(getvar("MOTO_BOARD_TYPE"), "WR_FEM1")) {
1208 return &platforms[WR850GV2V3];
1211 if (!strcmp(boardnum, "44") && !strcmp(getvar("boardflags"),"0x0388")) { /* Trendware TEW-411BRP+ */
1212 return &platforms[TEW411BRPP];
1215 if (startswith(boardnum, "04FN")) /* SimpleTech SimpleShare */
1216 return &platforms[STI_NAS];
1218 if (!strcmp(boardnum, "10") && !strcmp(getvar("boardrev"), "0x13")) /* D-Link DWL-3150 */
1219 return &platforms[DWL3150];
1221 if (!strcmp(boardnum, "01") && !strcmp(boardtype, "0x048e") && /* Edimax PS1208MFG */
1222 !strcmp(getvar("status_gpio"), "1")) /* gpio based detection */
1223 return &platforms[PS1208MFG];
1229 static struct platform_t __init *platform_detect(void)
1231 enum bcm47xx_board board;
1232 const char *board_name;
1235 board = bcm47xx_board_get();
1236 board_name = bcm47xx_board_get_name();
1237 if (board != BCM47XX_BOARD_UNKNOWN && board != BCM47XX_BOARD_NON)
1238 printk(MODULE_NAME ": kernel found a \"%s\"\n", board_name);
1241 case BCM47XX_BOARD_ASUS_RTN16:
1242 return &platforms[RTN16];
1243 case BCM47XX_BOARD_ASUS_WL330GE:
1244 return &platforms[WL330GE];
1245 case BCM47XX_BOARD_ASUS_WL500GPV1:
1246 return &platforms[WL500GP];
1247 case BCM47XX_BOARD_ASUS_WL500GPV2:
1248 return &platforms[WL500GPV2];
1249 case BCM47XX_BOARD_ASUS_WL520GC:
1250 return &platforms[WL520GC];
1251 case BCM47XX_BOARD_ASUS_WL520GU:
1252 return &platforms[WL520GU];
1253 case BCM47XX_BOARD_ASUS_WL700GE:
1254 return &platforms[WL700GE];
1255 case BCM47XX_BOARD_BELKIN_F7D4301:
1256 return &platforms[BELKIN_F7D4301];
1257 case BCM47XX_BOARD_BUFFALO_WBR2_G54:
1258 return &platforms[WBR2_G54];
1259 case BCM47XX_BOARD_BUFFALO_WHR2_A54G54:
1260 return &platforms[WHR2_A54G54];
1261 case BCM47XX_BOARD_BUFFALO_WHR_G125:
1262 return &platforms[WHR_G125];
1263 case BCM47XX_BOARD_BUFFALO_WHR_G54S:
1264 return &platforms[WHR_G54S];
1265 case BCM47XX_BOARD_BUFFALO_WHR_HP_G54:
1266 return &platforms[WHR_HP_G54];
1267 case BCM47XX_BOARD_BUFFALO_WLA2_G54L:
1268 return &platforms[WLA2_G54L];
1269 case BCM47XX_BOARD_BUFFALO_WZR_G300N:
1270 return &platforms[WZR_G300N];
1271 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54:
1272 return &platforms[WZR_RS_G54];
1273 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54HP:
1274 return &platforms[WZR_RS_G54HP];
1275 case BCM47XX_BOARD_DELL_TM2300:
1276 return &platforms[TM2300];
1277 case BCM47XX_BOARD_DLINK_DIR130:
1278 return &platforms[DIR130];
1279 case BCM47XX_BOARD_DLINK_DIR330:
1280 return &platforms[DIR330];
1281 case BCM47XX_BOARD_LINKSYS_E1000V1:
1282 return &platforms[E1000V1];
1283 case BCM47XX_BOARD_LINKSYS_E3000V1:
1284 return &platforms[E3000V1];
1285 case BCM47XX_BOARD_LINKSYS_E3200V1:
1286 return &platforms[E3200V1];
1287 case BCM47XX_BOARD_LINKSYS_WRT150NV1:
1288 return &platforms[WRT150NV1];
1289 case BCM47XX_BOARD_LINKSYS_WRT150NV11:
1290 return &platforms[WRT150NV11];
1291 case BCM47XX_BOARD_LINKSYS_WRT160NV1:
1292 return &platforms[WRT160NV1];
1293 case BCM47XX_BOARD_LINKSYS_WRT160NV3:
1294 return &platforms[WRT160NV3];
1295 case BCM47XX_BOARD_LINKSYS_WRT300NV11:
1296 return &platforms[WRT300NV11];
1297 case BCM47XX_BOARD_LINKSYS_WRT54G3GV2:
1298 return &platforms[WRT54G3GV2_VF];
1299 case BCM47XX_BOARD_LINKSYS_WRT610NV1:
1300 return &platforms[WRT610N];
1301 case BCM47XX_BOARD_LINKSYS_WRT610NV2:
1302 return &platforms[WRT610NV2];
1303 case BCM47XX_BOARD_MOTOROLA_WE800G:
1304 return &platforms[WE800G];
1305 case BCM47XX_BOARD_MOTOROLA_WR850GP:
1306 return &platforms[WR850GP];
1307 case BCM47XX_BOARD_MOTOROLA_WR850GV2V3:
1308 return &platforms[WR850GV2V3];
1309 case BCM47XX_BOARD_NETGEAR_WNDR3400V1:
1310 return &platforms[WNDR3400V1];
1311 case BCM47XX_BOARD_UNKNOWN:
1312 case BCM47XX_BOARD_NON:
1313 printk(MODULE_NAME ": unknown board found, try legacy detect\n");
1314 printk(MODULE_NAME ": please open a ticket at https://dev.openwrt.org and attach the complete nvram\n");
1315 return platform_detect_legacy();
1317 printk(MODULE_NAME ": board was detected as \"%s\", but not gpio configuration available\n", board_name);
1318 printk(MODULE_NAME ": now trying legacy detect\n");
1319 return platform_detect_legacy();
1323 static inline void ssb_maskset32(struct ssb_device *dev,
1324 u16 offset, u32 mask, u32 set)
1326 ssb_write32(dev, offset, (ssb_read32(dev, offset) & mask) | set);
1329 static void gpio_set_irqenable(int enabled, irqreturn_t (*handler)(int, void *))
1333 irq = gpio_to_irq(0);
1334 if (irq == -EINVAL) return;
1337 if (request_irq(irq, handler, IRQF_SHARED, "gpio", handler))
1340 free_irq(irq, handler);
1343 switch (bcm47xx_bus_type) {
1344 #ifdef CONFIG_BCM47XX_SSB
1345 case BCM47XX_BUS_TYPE_SSB:
1346 if (bcm47xx_bus.ssb.chipco.dev)
1347 ssb_maskset32(bcm47xx_bus.ssb.chipco.dev, SSB_CHIPCO_IRQMASK, ~SSB_CHIPCO_IRQ_GPIO, (enabled ? SSB_CHIPCO_IRQ_GPIO : 0));
1350 #ifdef CONFIG_BCM47XX_BCMA
1351 case BCM47XX_BUS_TYPE_BCMA:
1352 if (bcm47xx_bus.bcma.bus.drv_cc.core)
1353 bcma_maskset32(bcm47xx_bus.bcma.bus.drv_cc.core, BCMA_CC_IRQMASK, ~BCMA_CC_IRQ_GPIO, (enabled ? BCMA_CC_IRQ_GPIO : 0));
1359 static void register_buttons(struct button_t *b)
1361 for (; b->name; b++)
1362 platform.button_mask |= b->gpio;
1364 platform.button_mask &= ~gpiomask;
1366 bcm47xx_gpio_outen(platform.button_mask, 0);
1367 bcm47xx_gpio_control(platform.button_mask, 0);
1368 platform.button_polarity = bcm47xx_gpio_in(~0) & platform.button_mask;
1369 bcm47xx_gpio_polarity(platform.button_mask, platform.button_polarity);
1370 bcm47xx_gpio_intmask(platform.button_mask, platform.button_mask);
1372 gpio_set_irqenable(1, button_handler);
1375 static void unregister_buttons(struct button_t *b)
1377 bcm47xx_gpio_intmask(platform.button_mask, 0);
1379 gpio_set_irqenable(0, button_handler);
1383 static void add_msg(struct event_t *event, char *msg, int argv)
1390 s = skb_put(event->skb, strlen(msg) + 1);
1394 static void hotplug_button(struct work_struct *work)
1396 struct event_t *event = container_of(work, struct event_t, wq);
1399 event->skb = alloc_skb(2048, GFP_KERNEL);
1401 s = skb_put(event->skb, strlen(event->action) + 2);
1402 sprintf(s, "%s@", event->action);
1405 NETLINK_CB(event->skb).dst_group = 1;
1406 broadcast_uevent(event->skb, 0, 1, GFP_KERNEL);
1412 static int fill_event (struct event_t *event)
1414 static char buf[128];
1416 add_msg(event, "HOME=/", 0);
1417 add_msg(event, "PATH=/sbin:/bin:/usr/sbin:/usr/bin", 0);
1418 add_msg(event, "SUBSYSTEM=button", 0);
1419 snprintf(buf, 128, "ACTION=%s", event->action);
1420 add_msg(event, buf, 0);
1421 snprintf(buf, 128, "BUTTON=%s", event->name);
1422 add_msg(event, buf, 0);
1423 snprintf(buf, 128, "SEEN=%ld", event->seen);
1424 add_msg(event, buf, 0);
1425 snprintf(buf, 128, "SEQNUM=%llu", uevent_next_seqnum());
1426 add_msg(event, buf, 0);
1432 static irqreturn_t button_handler(int irq, void *dev_id)
1437 in = bcm47xx_gpio_in(~0) & platform.button_mask;
1438 bcm47xx_gpio_polarity(platform.button_mask, in);
1439 changed = platform.button_polarity ^ in;
1440 platform.button_polarity = in;
1442 changed &= ~bcm47xx_gpio_outen(0, 0);
1444 for (b = platform.buttons; b->name; b++) {
1445 struct event_t *event;
1447 if (!(b->gpio & changed)) continue;
1451 if ((event = (struct event_t *)kzalloc (sizeof(struct event_t), GFP_ATOMIC))) {
1452 event->seen = (jiffies - b->seen)/HZ;
1453 event->name = b->name;
1454 event->action = b->pressed ? "pressed" : "released";
1455 INIT_WORK(&event->wq, (void *)(void *)hotplug_button);
1456 schedule_work(&event->wq);
1464 static void register_leds(struct led_t *l)
1466 struct proc_dir_entry *p;
1471 leds = proc_mkdir("led", diag);
1475 for(; l->name; l++) {
1476 if (l->gpio & gpiomask)
1479 if (l->gpio & GPIO_TYPE_EXTIF) {
1483 if (l->polarity != INPUT) oe_mask |= l->gpio;
1485 val |= (l->polarity == NORMAL)?0:l->gpio;
1488 if (l->polarity == INPUT) continue;
1490 if ((p = create_proc_entry(l->name, S_IRUSR, leds))) {
1491 l->proc.type = PROC_LED;
1493 p->data = (void *) &l->proc;
1494 p->proc_fops = &diag_proc_fops;
1498 bcm47xx_gpio_outen(mask, oe_mask);
1499 bcm47xx_gpio_control(mask, 0);
1500 bcm47xx_gpio_out(mask, val);
1501 bcm47xx_gpio_intmask(mask, 0);
1504 static void unregister_leds(struct led_t *l)
1507 remove_proc_entry(l->name, leds);
1509 remove_proc_entry("led", diag);
1512 static void set_led_extif(struct led_t *led)
1514 volatile u8 *addr = (volatile u8 *) KSEG1ADDR(EXTIF_UART) + (led->gpio & ~GPIO_TYPE_MASK);
1521 static void led_flash(unsigned long dummy) {
1526 for (l = platform.leds; l->name; l++) {
1528 if (l->gpio & GPIO_TYPE_EXTIF) {
1530 l->state = !l->state;
1540 u32 val = ~bcm47xx_gpio_in(~0);
1542 bcm47xx_gpio_outen(mask, mask);
1543 bcm47xx_gpio_control(mask, 0);
1544 bcm47xx_gpio_out(mask, val);
1546 if (mask || extif_blink) {
1547 mod_timer(&led_timer, jiffies + FLASH_TIME);
1551 static ssize_t diag_proc_read(struct file *file, char *buf, size_t count, loff_t *ppos)
1553 struct proc_dir_entry *dent = PDE(file->f_dentry->d_inode);
1557 if ((page = kmalloc(1024, GFP_KERNEL)) == NULL)
1560 if (dent->data != NULL) {
1561 struct prochandler_t *handler = (struct prochandler_t *) dent->data;
1562 switch (handler->type) {
1564 struct led_t * led = (struct led_t *) handler->ptr;
1566 len = sprintf(page, "f\n");
1568 if (led->gpio & GPIO_TYPE_EXTIF) {
1569 len = sprintf(page, "%d\n", led->state);
1571 u32 in = (bcm47xx_gpio_in(~0) & led->gpio ? 1 : 0);
1572 u8 p = (led->polarity == NORMAL ? 0 : 1);
1573 len = sprintf(page, "%d\n", ((in ^ p) ? 1 : 0));
1579 len = sprintf(page, "%s\n", platform.name);
1582 len = sprintf(page, "0x%04x\n", gpiomask);
1589 len = min_t(int, len - *ppos, count);
1590 if (copy_to_user(buf, (page + *ppos), len)) {
1604 static ssize_t diag_proc_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
1606 struct proc_dir_entry *dent = PDE(file->f_dentry->d_inode);
1610 if ((page = kmalloc(count + 1, GFP_KERNEL)) == NULL)
1613 if (copy_from_user(page, buf, count)) {
1619 if (dent->data != NULL) {
1620 struct prochandler_t *handler = (struct prochandler_t *) dent->data;
1621 switch (handler->type) {
1623 struct led_t *led = (struct led_t *) handler->ptr;
1624 int p = (led->polarity == NORMAL ? 0 : 1);
1626 if (page[0] == 'f') {
1631 if (led->gpio & GPIO_TYPE_EXTIF) {
1632 led->state = p ^ ((page[0] == '1') ? 1 : 0);
1635 bcm47xx_gpio_outen(led->gpio, led->gpio);
1636 bcm47xx_gpio_control(led->gpio, 0);
1637 bcm47xx_gpio_out(led->gpio, ((p ^ (page[0] == '1')) ? led->gpio : 0));
1643 gpiomask = simple_strtoul(page, NULL, 0);
1645 if (platform.buttons) {
1646 unregister_buttons(platform.buttons);
1647 register_buttons(platform.buttons);
1650 if (platform.leds) {
1651 unregister_leds(platform.leds);
1652 register_leds(platform.leds);
1663 static int __init diag_init(void)
1665 static struct proc_dir_entry *p;
1666 static struct platform_t *detected;
1668 detected = platform_detect();
1670 printk(MODULE_NAME ": Router model not detected.\n");
1673 memcpy(&platform, detected, sizeof(struct platform_t));
1675 printk(MODULE_NAME ": Detected '%s'\n", platform.name);
1676 if (platform.platform_init != NULL) {
1677 platform.platform_init();
1680 if (!(diag = proc_mkdir("diag", NULL))) {
1681 printk(MODULE_NAME ": proc_mkdir on /proc/diag failed\n");
1685 if ((p = create_proc_entry("model", S_IRUSR, diag))) {
1686 p->data = (void *) &proc_model;
1687 p->proc_fops = &diag_proc_fops;
1690 if ((p = create_proc_entry("gpiomask", S_IRUSR | S_IWUSR, diag))) {
1691 p->data = (void *) &proc_gpiomask;
1692 p->proc_fops = &diag_proc_fops;
1695 if (platform.buttons)
1696 register_buttons(platform.buttons);
1699 register_leds(platform.leds);
1704 static void __exit diag_exit(void)
1706 del_timer(&led_timer);
1708 if (platform.buttons)
1709 unregister_buttons(platform.buttons);
1712 unregister_leds(platform.leds);
1714 remove_proc_entry("model", diag);
1715 remove_proc_entry("gpiomask", diag);
1716 remove_proc_entry("diag", NULL);
1719 module_init(diag_init);
1720 module_exit(diag_exit);
1722 MODULE_AUTHOR("Mike Baker, Felix Fietkau / OpenWrt.org");
1723 MODULE_LICENSE("GPL");