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);
140 /* Western Digital */
156 static void __init bcm4780_init(void) {
159 /* Enables GPIO 3 that controls HDD and led power on ASUS WL-700gE */
160 printk(MODULE_NAME ": Spinning up HDD and enabling leds\n");
161 bcm47xx_gpio_outen(pin, pin);
162 bcm47xx_gpio_control(pin, 0);
163 bcm47xx_gpio_out(pin, pin);
165 /* Wait 5s, so the HDD can spin up */
166 set_current_state(TASK_INTERRUPTIBLE);
167 schedule_timeout(HZ * 5);
170 static void __init NetCenter_init(void) {
171 /* unset pin 6 (+12V) */
173 bcm47xx_gpio_outen(pin, pin);
174 bcm47xx_gpio_control(pin, 0);
175 bcm47xx_gpio_out(pin, pin);
176 /* unset pin 1 (turn off red led, blue will light alone if +5V comes up) */
178 bcm47xx_gpio_outen(pin, pin);
179 bcm47xx_gpio_control(pin, 0);
180 bcm47xx_gpio_out(pin, pin);
181 /* unset pin 3 (+5V) and wait 5 seconds (harddisk spin up) */
185 static void __init bcm57xx_init(void) {
188 /* FIXME: switch comes up, but port mappings/vlans not right */
189 bcm47xx_gpio_outen(pin, pin);
190 bcm47xx_gpio_control(pin, 0);
191 bcm47xx_gpio_out(pin, pin);
194 static struct platform_t __initdata platforms[] = {
197 .name = "Linksys WAP54G V1",
199 { .name = "reset", .gpio = 1 << 0 },
202 { .name = "diag", .gpio = 1 << 3 },
203 { .name = "wlan", .gpio = 1 << 4 },
207 .name = "Linksys WAP54G V2",
209 { .name = "reset", .gpio = 1 << 0 },
212 { .name = "wlan", .gpio = 1 << 5, .polarity = REVERSE },
213 /* GPIO 6 is b44 (eth0, LAN) PHY power */
217 .name = "Linksys WAP54G V3",
219 /* FIXME: verify this */
220 { .name = "reset", .gpio = 1 << 7 },
221 { .name = "ses", .gpio = 1 << 0 },
225 { .name = "ses", .gpio = 1 << 1 },
229 .name = "Linksys WRT54G V1.x",
231 { .name = "reset", .gpio = 1 << 6 },
234 { .name = "diag", .gpio = 0x13 | GPIO_TYPE_EXTIF, .polarity = NORMAL },
235 { .name = "dmz", .gpio = 0x12 | GPIO_TYPE_EXTIF, .polarity = NORMAL },
239 .name = "Linksys WRT54G/GS/GL",
241 { .name = "reset", .gpio = 1 << 6 },
242 { .name = "ses", .gpio = 1 << 4 },
245 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
246 { .name = "dmz", .gpio = 1 << 7, .polarity = REVERSE },
247 { .name = "ses_white", .gpio = 1 << 2, .polarity = REVERSE },
248 { .name = "ses_orange", .gpio = 1 << 3, .polarity = REVERSE },
249 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
253 .name = "Linksys WRTSL54GS",
255 { .name = "reset", .gpio = 1 << 6 },
256 { .name = "ses", .gpio = 1 << 4 },
259 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
260 { .name = "dmz", .gpio = 1 << 0, .polarity = REVERSE },
261 { .name = "ses_white", .gpio = 1 << 5, .polarity = REVERSE },
262 { .name = "ses_orange", .gpio = 1 << 7, .polarity = REVERSE },
266 .name = "Linksys WRT54G3G",
268 { .name = "reset", .gpio = 1 << 6 },
269 { .name = "3g", .gpio = 1 << 4 },
272 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
273 { .name = "dmz", .gpio = 1 << 7, .polarity = REVERSE },
274 { .name = "3g_green", .gpio = 1 << 2, .polarity = NORMAL },
275 { .name = "3g_blue", .gpio = 1 << 3, .polarity = NORMAL },
276 { .name = "3g_blink", .gpio = 1 << 5, .polarity = NORMAL },
280 .name = "Linksys WRT54G3GV2-VF",
282 { .name = "reset", .gpio = 1 << 6 },
283 { .name = "3g", .gpio = 1 << 5 },
286 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
287 { .name = "3g_green", .gpio = 1 << 2, .polarity = NORMAL },
288 { .name = "3g_blue", .gpio = 1 << 3, .polarity = NORMAL },
292 .name = "Linksys WRT150N V1",
294 { .name = "reset", .gpio = 1 << 6 },
295 { .name = "ses", .gpio = 1 << 4 },
298 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
299 { .name = "ses_green", .gpio = 1 << 5, .polarity = REVERSE },
300 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE },
304 .name = "Linksys WRT150N V1.1",
306 { .name = "reset", .gpio = 1 << 6 },
307 { .name = "ses", .gpio = 1 << 4 },
310 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
311 { .name = "ses_green", .gpio = 1 << 5, .polarity = REVERSE },
312 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE },
316 .name = "Linksys WRT160N v1.x",
318 { .name = "reset", .gpio = 1 << 6 },
319 { .name = "ses", .gpio = 1 << 4 },
322 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
323 { .name = "ses_blue", .gpio = 1 << 5, .polarity = REVERSE },
324 { .name = "ses_orange", .gpio = 1 << 3, .polarity = REVERSE },
328 .name = "Linksys WRT160N V3",
330 { .name = "reset", .gpio = 1 << 6 },
331 { .name = "ses", .gpio = 1 << 5 },
334 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
335 { .name = "ses_blue", .gpio = 1 << 4, .polarity = REVERSE },
336 { .name = "ses_orange", .gpio = 1 << 2, .polarity = REVERSE },
340 .name = "Linksys WRT300N V1.1",
342 { .name = "reset", .gpio = 1 << 6 }, // "Reset" on back panel
343 { .name = "ses", .gpio = 1 << 4 }, // "Reserved" on top panel
346 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL }, // "Power"
347 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE }, // "Security" Amber
348 { .name = "ses_green", .gpio = 1 << 5, .polarity = REVERSE }, // "Security" Green
350 .platform_init = bcm57xx_init,
353 .name = "Linksys WRT350N",
355 { .name = "reset", .gpio = 1 << 6 },
356 { .name = "ses", .gpio = 1 << 8 },
359 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
360 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE },
361 { .name = "ses_green", .gpio = 1 << 9, .polarity = REVERSE },
362 { .name = "usb_blink", .gpio = 1 << 10, .polarity = REVERSE },
363 { .name = "usb", .gpio = 1 << 11, .polarity = REVERSE },
365 .platform_init = bcm57xx_init,
368 .name = "Linksys WRT600N",
370 { .name = "reset", .gpio = 1 << 6 },
371 { .name = "ses", .gpio = 1 << 7 },
374 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE }, // Power LED
375 { .name = "usb", .gpio = 1 << 3, .polarity = REVERSE }, // USB LED
376 { .name = "wl0_ses_amber", .gpio = 1 << 8, .polarity = REVERSE }, // 2.4Ghz LED Amber
377 { .name = "wl0_ses_green", .gpio = 1 << 9, .polarity = REVERSE }, // 2.4Ghz LED Green
378 { .name = "wl1_ses_amber", .gpio = 1 << 10, .polarity = REVERSE }, // 5.6Ghz LED Amber
379 { .name = "wl1_ses_green", .gpio = 1 << 11, .polarity = REVERSE }, // 5.6Ghz LED Green
381 .platform_init = bcm57xx_init,
384 .name = "Linksys WRT600N V1.1",
386 { .name = "reset", .gpio = 1 << 6 },
387 { .name = "ses", .gpio = 1 << 7 },
390 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE }, // Power LED
391 { .name = "usb", .gpio = 1 << 3, .polarity = REVERSE }, // USB LED
392 { .name = "wl0_ses_amber", .gpio = 1 << 8, .polarity = REVERSE }, // 2.4Ghz LED Amber
393 { .name = "wl0_ses_green", .gpio = 1 << 9, .polarity = REVERSE }, // 2.4Ghz LED Green
394 { .name = "wl1_ses_amber", .gpio = 1 << 10, .polarity = REVERSE }, // 5.6Ghz LED Amber
395 { .name = "wl1_ses_green", .gpio = 1 << 11, .polarity = REVERSE }, // 5.6Ghz LED Green
397 .platform_init = bcm57xx_init,
400 .name = "Linksys WRT610N",
402 { .name = "reset", .gpio = 1 << 6 },
403 { .name = "ses", .gpio = 1 << 8 },
406 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL }, // Power LED
407 { .name = "usb", .gpio = 1 << 0, .polarity = REVERSE }, // USB LED
408 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE }, // WiFi protected setup LED amber
409 { .name = "ses_blue", .gpio = 1 << 9, .polarity = REVERSE }, // WiFi protected setup LED blue
413 .name = "Linksys WRT610N V2",
415 { .name = "reset", .gpio = 1 << 6 },
416 { .name = "ses", .gpio = 1 << 4 },
419 { .name = "power", .gpio = 1 << 5, .polarity = NORMAL }, // Power LED
420 { .name = "usb", .gpio = 1 << 7, .polarity = NORMAL }, // USB LED
421 { .name = "ses_amber", .gpio = 1 << 0, .polarity = REVERSE }, // WiFi protected setup LED amber
422 { .name = "ses_blue", .gpio = 1 << 3, .polarity = REVERSE }, // WiFi protected setup LED blue
423 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL }, // Wireless LED
426 /* same hardware as WRT160NV3 and Cisco Valet M10V1, but different board detection, combine? */
428 .name = "Linksys E1000 V1",
430 { .name = "reset", .gpio = 1 << 6 },
431 { .name = "wps", .gpio = 1 << 5 }, /* nvram get gpio5=wps_button */
434 /** turns on leds for all ethernet ports (wan too)
435 * this also disconnects some, or maybe all, ethernet ports
436 * 1: leds work normally
437 * 0: all lit all the time */
438 /* nvram get gpio3=robo_reset */
439 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
440 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
441 { .name = "ses_blue", .gpio = 1 << 4, .polarity = REVERSE }, /* nvram get gpio4=wps_led */
442 { .name = "ses_orange", .gpio = 1 << 2, .polarity = REVERSE }, /* nvram get gpio2=wps_status_led */
446 .name = "Linksys E3000 V1",
448 { .name = "reset", .gpio = 1 << 6 },
449 { .name = "ses", .gpio = 1 << 4 },
452 { .name = "power", .gpio = 1 << 5, .polarity = NORMAL }, // Power LED
453 { .name = "usb", .gpio = 1 << 7, .polarity = NORMAL }, // USB LED
454 { .name = "ses_amber", .gpio = 1 << 0, .polarity = REVERSE }, // WiFi protected setup LED amber
455 { .name = "ses_blue", .gpio = 1 << 3, .polarity = REVERSE }, // WiFi protected setup LED blue
456 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL }, // Wireless LED
461 .name = "ASUS WL-HDD",
463 { .name = "reset", .gpio = 1 << 6 },
466 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
467 { .name = "usb", .gpio = 1 << 2, .polarity = REVERSE },
471 .name = "ASUS WL-300g",
473 { .name = "reset", .gpio = 1 << 6 },
476 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
480 .name = "ASUS WL-320gE/WL-320gP",
482 { .name = "reset", .gpio = 1 << 6 },
485 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
486 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE },
487 { .name = "link", .gpio = 1 << 11, .polarity = REVERSE },
491 .name = "ASUS WL-330gE",
493 { .name = "reset", .gpio = 1 << 2 },
496 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
500 .name = "ASUS WL-500g",
502 { .name = "reset", .gpio = 1 << 6 },
505 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
509 .name = "ASUS WL-500g Deluxe",
511 { .name = "reset", .gpio = 1 << 6 },
514 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
518 .name = "ASUS WL-500g Premium",
520 { .name = "reset", .gpio = 1 << 0 },
521 { .name = "ses", .gpio = 1 << 4 },
524 { .name = "power", .gpio = 1 << 1, .polarity = REVERSE },
528 .name = "ASUS WL-500g Premium V2",
530 { .name = "reset", .gpio = 1 << 2 },
531 { .name = "ses", .gpio = 1 << 3 },
534 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
535 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
539 .name = "ASUS WL-500W",
541 { .name = "reset", .gpio = 1 << 6 },
542 { .name = "ses", .gpio = 1 << 7 },
545 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
549 .name = "ASUS WL-520GC",
551 { .name = "reset", .gpio = 1 << 2 },
552 { .name = "ses", .gpio = 1 << 3 },
555 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
556 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
560 .name = "ASUS WL-520gU",
562 { .name = "reset", .gpio = 1 << 2 },
563 { .name = "ses", .gpio = 1 << 3 },
566 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
567 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
571 .name = "ASUS (unknown, BCM4702)",
573 { .name = "reset", .gpio = 1 << 6 },
576 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
580 .name = "ASUS WL-700gE",
582 { .name = "reset", .gpio = 1 << 7 }, // on back, hardwired, always resets device regardless OS state
583 { .name = "ses", .gpio = 1 << 4 }, // on back, actual name ezsetup
584 { .name = "power", .gpio = 1 << 0 }, // on front
585 { .name = "copy", .gpio = 1 << 6 }, // on front
589 // GPIO that controls power led also enables/disables some essential functions
592 { .name = "power", .gpio = 1 << 3, .polarity = NORMAL }, // actual name power
594 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE }, // actual name ready
596 .platform_init = bcm4780_init,
599 .name = "ASUS RT-N16",
601 { .name = "reset", .gpio = 1 << 8 },
602 { .name = "ses", .gpio = 1 << 5 },
605 { .name = "power", .gpio = 1 << 1, .polarity = REVERSE },
606 { .name = "wlan", .gpio = 1 << 7, .polarity = NORMAL },
611 .name = "Buffalo WHR-G54S",
613 { .name = "reset", .gpio = 1 << 4 },
614 { .name = "bridge", .gpio = 1 << 5 },
615 { .name = "ses", .gpio = 1 << 0 },
618 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
619 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
620 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
621 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
622 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
626 .name = "Buffalo WBR2-G54",
629 { .name = "reset", .gpio = 1 << 7 },
632 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
636 .name = "Buffalo WHR-HP-G54",
638 { .name = "reset", .gpio = 1 << 4 },
639 { .name = "bridge", .gpio = 1 << 5 },
640 { .name = "ses", .gpio = 1 << 0 },
643 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
644 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
645 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
646 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
647 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
651 .name = "Buffalo WHR-G125",
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 WHR2-A54G54",
668 { .name = "reset", .gpio = 1 << 4 },
671 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
675 .name = "Buffalo WLA2-G54L",
678 { .name = "reset", .gpio = 1 << 7 },
681 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
685 .name = "Buffalo WZR-G300N",
687 { .name = "reset", .gpio = 1 << 4 },
690 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
691 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
692 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
696 .name = "Buffalo WZR-RS-G54",
698 { .name = "ses", .gpio = 1 << 0 },
699 { .name = "reset", .gpio = 1 << 4 },
702 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
703 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
704 { .name = "vpn", .gpio = 1 << 1, .polarity = REVERSE },
708 .name = "Buffalo WZR-RS-G54HP",
710 { .name = "ses", .gpio = 1 << 0 },
711 { .name = "reset", .gpio = 1 << 4 },
714 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
715 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
716 { .name = "vpn", .gpio = 1 << 1, .polarity = REVERSE },
719 [BUFFALO_UNKNOWN] = {
720 .name = "Buffalo (unknown)",
722 { .name = "reset", .gpio = 1 << 7 },
725 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
728 [BUFFALO_UNKNOWN_4710] = {
729 .name = "Buffalo (unknown, BCM4710)",
731 { .name = "reset", .gpio = 1 << 4 },
734 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
739 .name = "Siemens SE505 V1",
741 /* No usable buttons */
744 // { .name = "power", .gpio = 1 << 0 .polarity = REVERSE }, // Usable when retrofitting D26 (?)
745 { .name = "dmz", .gpio = 1 << 4, .polarity = REVERSE }, // actual name WWW
746 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
750 .name = "Siemens SE505 V2",
752 /* No usable buttons */
755 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
756 { .name = "dmz", .gpio = 1 << 0, .polarity = REVERSE }, // actual name WWW
757 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
762 .name = "U.S. Robotics USR5461",
764 /* No usable buttons */
767 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
768 { .name = "printer", .gpio = 1 << 1, .polarity = REVERSE },
773 .name = "Dell TrueMobile 2300",
775 { .name = "reset", .gpio = 1 << 0 },
778 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
779 { .name = "power", .gpio = 1 << 7, .polarity = REVERSE },
783 .name = "Dell TrueMobile 2300 v2",
785 { .name = "reset", .gpio = 1 << 0 },
788 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
789 { .name = "power", .gpio = 1 << 7, .polarity = REVERSE },
794 .name = "Motorola WE800G",
796 { .name = "reset", .gpio = 1 << 0 },
799 { .name = "power", .gpio = 1 << 4, .polarity = NORMAL },
800 { .name = "diag", .gpio = 1 << 2, .polarity = REVERSE },
801 { .name = "wlan_amber", .gpio = 1 << 1, .polarity = NORMAL },
805 .name = "Motorola WR850G V1",
807 { .name = "reset", .gpio = 1 << 0 },
810 { .name = "power", .gpio = 1 << 4, .polarity = NORMAL },
811 { .name = "diag", .gpio = 1 << 3, .polarity = REVERSE },
812 { .name = "dmz", .gpio = 1 << 6, .polarity = NORMAL },
813 { .name = "wlan_red", .gpio = 1 << 5, .polarity = REVERSE },
814 { .name = "wlan_green", .gpio = 1 << 7, .polarity = REVERSE },
818 .name = "Motorola WR850G V2/V3",
820 { .name = "reset", .gpio = 1 << 5 },
823 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
824 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
825 { .name = "wan", .gpio = 1 << 6, .polarity = INPUT },
826 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
830 .name = "Motorola WR850GP",
832 { .name = "reset", .gpio = 1 << 5 },
835 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
836 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
837 { .name = "dmz", .gpio = 1 << 6, .polarity = REVERSE },
838 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
844 .name = "Belkin (unknown)",
845 /* FIXME: verify & add detection */
847 { .name = "reset", .gpio = 1 << 7 },
850 { .name = "power", .gpio = 1 << 5, .polarity = NORMAL },
851 { .name = "wlan", .gpio = 1 << 3, .polarity = NORMAL },
852 { .name = "connected", .gpio = 1 << 0, .polarity = NORMAL },
856 .name = "Belkin PlayMax F7D4301",
858 { .name = "reset", .gpio = 1 << 6 },
859 { .name = "wps", .gpio = 1 << 8 },
862 { .name = "power", .gpio = 1 << 11, .polarity = REVERSE },
863 { .name = "wlan", .gpio = 1 << 13, .polarity = REVERSE },
864 { .name = "led0", .gpio = 1 << 14, .polarity = REVERSE },
865 { .name = "led1", .gpio = 1 << 15, .polarity = REVERSE },
870 .name = "Netgear WGT634U",
872 { .name = "reset", .gpio = 1 << 2 },
875 { .name = "power", .gpio = 1 << 3, .polarity = NORMAL },
880 .name = "Netgear WNR834B V1",
881 .buttons = { /* TODO: add reset button and confirm LEDs - GPIO from dd-wrt */ },
883 { .name = "power", .gpio = 1 << 4, .polarity = REVERSE },
884 { .name = "diag", .gpio = 1 << 5, .polarity = REVERSE },
885 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
890 .name = "Netgear WNR834B V2",
892 { .name = "reset", .gpio = 1 << 6 },
895 { .name = "power", .gpio = 1 << 2, .polarity = NORMAL },
896 { .name = "diag", .gpio = 1 << 3, .polarity = NORMAL },
897 { .name = "connected", .gpio = 1 << 7, .polarity = NORMAL },
902 .name = "Trendware TEW411BRP+",
904 { /* No usable buttons */ },
907 { .name = "power", .gpio = 1 << 7, .polarity = NORMAL },
908 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL },
909 { .name = "bridge", .gpio = 1 << 6, .polarity = NORMAL },
914 .name = "SimpleTech SimpleShare NAS",
916 { .name = "reset", .gpio = 1 << 0 }, // Power button on back, named reset to enable failsafe.
919 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE }, // actual name ready
921 .platform_init = bcm4780_init,
925 .name = "D-Link DIR-130",
927 { .name = "reset", .gpio = 1 << 3},
928 { .name = "reserved", .gpio = 1 << 7},
931 { .name = "diag", .gpio = 1 << 0},
932 { .name = "blue", .gpio = 1 << 6},
936 .name = "D-Link DIR-320",
938 { .name = "reserved", .gpio = 1 << 6},
939 { .name = "reset", .gpio = 1 << 7},
942 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
943 { .name = "diag", .gpio = 1 << 1, .polarity = NORMAL }, /* "status led */
944 { .name = "red", .gpio = 1 << 3, .polarity = REVERSE },
945 { .name = "blue", .gpio = 1 << 4, .polarity = REVERSE },
946 { .name = "usb", .gpio = 1 << 5, .polarity = NORMAL },
950 .name = "D-Link DIR-330",
952 { .name = "reset", .gpio = 1 << 3},
953 { .name = "reserved", .gpio = 1 << 7},
956 { .name = "diag", .gpio = 1 << 0},
957 { .name = "usb", .gpio = 1 << 4},
958 { .name = "blue", .gpio = 1 << 6},
962 .name = "D-Link DWL-3150",
964 { .name = "reset", .gpio = 1 << 7},
967 { .name = "diag", .gpio = 1 << 2},
968 { .name = "status", .gpio = 1 << 1},
973 .name = "Sitecom WL-105b",
975 { .name = "reset", .gpio = 1 << 10},
978 { .name = "wlan", .gpio = 1 << 4},
979 { .name = "power", .gpio = 1 << 3},
982 /* Western Digital Net Center */
984 .name = "Western Digital NetCenter",
986 { .name = "power", .gpio = 1 << 0},
987 { .name = "reset", .gpio = 1 << 7},
989 .platform_init = NetCenter_init,
991 /* Askey (and clones) */
993 .name = "Askey RT210W",
995 /* Power button is hard-wired to hardware reset */
996 /* but is also connected to GPIO 7 (probably for bootloader recovery) */
997 { .name = "power", .gpio = 1 << 7},
1000 /* These were verified and named based on Belkin F5D4230-4 v1112 */
1001 { .name = "connected", .gpio = 1 << 0, .polarity = REVERSE },
1002 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
1003 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
1007 .name = "OvisLink WL-1600GL",
1009 { .name = "reset", .gpio = 1 << 3 },
1010 { .name = "ses", .gpio = 1 << 4 },
1013 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
1014 { .name = "wps", .gpio = 1 << 2, .polarity = REVERSE },
1015 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
1016 { .name = "connected", .gpio = 1 << 0, .polarity = REVERSE },
1021 .name = "Microsoft MN-700",
1023 { .name = "reset", .gpio = 1 << 7 },
1026 { .name = "power", .gpio = 1 << 6, .polarity = NORMAL },
1031 .name = "Edimax PS-1208MFG",
1033 { .name = "reset", .gpio = 1 << 4 },
1036 { .name = "status", .gpio = 1 << 1, .polarity = NORMAL },
1037 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
1042 static struct platform_t __init *platform_detect_legacy(void)
1044 char *boardnum, *boardtype, *buf;
1046 if (strcmp(getvar("nvram_type"), "cfe") == 0)
1047 return &platforms[WGT634U];
1050 /* no easy model number, attempt to guess */
1051 boardnum = getvar("boardnum");
1052 boardtype = getvar("boardtype");
1054 if (!strcmp(boardnum, "20070615")) { /* Linksys WRT600N v1/V1.1 */
1055 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "0") && !strcmp(getvar("switch_type"),"BCM5395"))
1056 return &platforms[WRT600NV11];
1058 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "0"))
1059 return &platforms[WRT600N];
1062 if (startswith(getvar("pmon_ver"), "CFE")) {
1063 /* CFE based - newer hardware */
1064 if (!strcmp(boardnum, "42")) { /* Linksys */
1065 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "1"))
1066 return &platforms[WRT350N];
1068 if (!strcmp(boardtype, "0x0101") && !strcmp(getvar("boot_ver"), "v3.6"))
1069 return &platforms[WRT54G3G];
1071 if (!strcmp(getvar("et1phyaddr"),"5") && !strcmp(getvar("et1mdcport"), "1"))
1072 return &platforms[WRTSL54GS];
1074 /* default to WRT54G */
1075 return &platforms[WRT54G];
1077 if (!strcmp(boardnum, "1024") && !strcmp(boardtype, "0x0446"))
1078 return &platforms[WAP54GV2];
1080 if (!strcmp(boardnum, "8") && !strcmp(boardtype, "0x048e"))
1081 return &platforms[WL1600GL];
1084 if (!strcmp(boardnum, "44") || !strcmp(boardnum, "44\r")) {
1085 if (!strcmp(boardtype,"0x0101") || !strcmp(boardtype, "0x0101\r"))
1086 return &platforms[TM2300V2]; /* Dell TrueMobile 2300 v2 */
1089 if (!strcmp(boardnum, "45")) { /* ASUS */
1090 if (!strcmp(boardtype,"0x0472"))
1091 return &platforms[WL500W];
1092 else if (!strcmp(boardtype,"0x467"))
1093 return &platforms[WL320GE];
1095 return &platforms[WL500GD];
1098 if (!strcmp(boardnum, "10496"))
1099 return &platforms[USR5461];
1101 if (!strcmp(getvar("boardtype"), "0x0101") && !strcmp(getvar("boardrev"), "0x10")) /* SE505V2 With Modified CFE */
1102 return &platforms[SE505V2];
1104 if (!strcmp(boardtype, "0x048e") && !strcmp(getvar("boardrev"),"0x35") &&
1105 !strcmp(getvar("boardflags"), "0x750")) /* D-Link DIR-320 */
1106 return &platforms[DIR320];
1108 if (!strncmp(boardnum, "TH",2) && !strcmp(boardtype,"0x042f")) {
1109 return &platforms[WDNetCenter];
1112 if (!strcmp(boardtype,"0x0472") && !strcmp(getvar("cardbus"), "1")) { /* Netgear WNR834B V1 and V2*/
1113 if (!strcmp(boardnum, "08") || !strcmp(boardnum, "8"))
1114 return &platforms[WNR834BV1];
1115 if (!strcmp(boardnum, "01") || !strcmp(boardnum, "1"))
1116 return &platforms[WNR834BV2];
1119 } else { /* PMON based - old stuff */
1120 if ((simple_strtoul(getvar("GemtekPmonVer"), NULL, 0) == 9) &&
1121 (simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 30)) {
1122 return &platforms[WR850GV1];
1124 if (startswith(boardtype, "bcm94710dev")) {
1125 if (!strcmp(boardnum, "42"))
1126 return &platforms[WRT54GV1];
1127 if (simple_strtoul(boardnum, NULL, 0) == 2)
1128 return &platforms[WAP54GV1];
1130 /* MN-700 has also hardware_version 'WL500-...', so use boardnum */
1131 if (startswith(getvar("hardware_version"), "WL500-")) {
1132 if (!strcmp(getvar("boardnum"), "mn700"))
1133 return &platforms[MN700];
1135 return &platforms[WL500G];
1137 if (startswith(getvar("hardware_version"), "WL300-")) {
1138 /* Either WL-300g or WL-HDD, do more extensive checks */
1139 if ((simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 0) &&
1140 (simple_strtoul(getvar("et1phyaddr"), NULL, 0) == 1))
1141 return &platforms[WLHDD];
1142 if ((simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 0) &&
1143 (simple_strtoul(getvar("et1phyaddr"), NULL, 0) == 10))
1144 return &platforms[WL300G];
1146 /* Sitecom WL-105b */
1147 if (startswith(boardnum, "2") && simple_strtoul(getvar("GemtekPmonVer"), NULL, 0) == 1)
1148 return &platforms[WL105B];
1150 /* unknown asus stuff, probably bcm4702 */
1151 if (startswith(boardnum, "asusX"))
1152 return &platforms[ASUS_4702];
1154 /* bcm4702 based Askey RT210W clones, Including:
1155 * Askey RT210W (duh?)
1157 * Belkin F5D7230-4 before version v1444 (MiniPCI slot, not integrated)
1159 if (!strcmp(boardtype,"bcm94710r4")
1160 && !strcmp(boardnum ,"100")
1161 && !strcmp(getvar("pmon_ver"),"v1.03.12.bk")
1163 return &platforms[RT210W];
1167 if (buf || !strcmp(boardnum, "00")) {/* probably buffalo */
1168 if (startswith(boardtype, "bcm94710ap"))
1169 return &platforms[BUFFALO_UNKNOWN_4710];
1171 return &platforms[BUFFALO_UNKNOWN];
1174 if (startswith(getvar("CFEver"), "MotoWRv2") ||
1175 startswith(getvar("CFEver"), "MotoWRv3") ||
1176 !strcmp(getvar("MOTO_BOARD_TYPE"), "WR_FEM1")) {
1178 return &platforms[WR850GV2V3];
1181 if (!strcmp(boardnum, "44") && !strcmp(getvar("boardflags"),"0x0388")) { /* Trendware TEW-411BRP+ */
1182 return &platforms[TEW411BRPP];
1185 if (startswith(boardnum, "04FN")) /* SimpleTech SimpleShare */
1186 return &platforms[STI_NAS];
1188 if (!strcmp(boardnum, "10") && !strcmp(getvar("boardrev"), "0x13")) /* D-Link DWL-3150 */
1189 return &platforms[DWL3150];
1191 if (!strcmp(boardnum, "01") && !strcmp(boardtype, "0x048e") && /* Edimax PS1208MFG */
1192 !strcmp(getvar("status_gpio"), "1")) /* gpio based detection */
1193 return &platforms[PS1208MFG];
1199 static struct platform_t __init *platform_detect(void)
1201 enum bcm47xx_board board;
1202 const char *board_name;
1205 board = bcm47xx_board_get();
1206 board_name = bcm47xx_board_get_name();
1207 if (board != BCM47XX_BOARD_UNKNOWN && board != BCM47XX_BOARD_NON)
1208 printk(MODULE_NAME ": kernel found a \"%s\"\n", board_name);
1211 case BCM47XX_BOARD_ASUS_RTN16:
1212 return &platforms[RTN16];
1213 case BCM47XX_BOARD_ASUS_WL330GE:
1214 return &platforms[WL330GE];
1215 case BCM47XX_BOARD_ASUS_WL500GPV1:
1216 return &platforms[WL500GP];
1217 case BCM47XX_BOARD_ASUS_WL500GPV2:
1218 return &platforms[WL500GPV2];
1219 case BCM47XX_BOARD_ASUS_WL520GC:
1220 return &platforms[WL520GC];
1221 case BCM47XX_BOARD_ASUS_WL520GU:
1222 return &platforms[WL520GU];
1223 case BCM47XX_BOARD_ASUS_WL700GE:
1224 return &platforms[WL700GE];
1225 case BCM47XX_BOARD_BELKIN_F7D4301:
1226 return &platforms[BELKIN_F7D4301];
1227 case BCM47XX_BOARD_BUFFALO_WBR2_G54:
1228 return &platforms[WBR2_G54];
1229 case BCM47XX_BOARD_BUFFALO_WHR2_A54G54:
1230 return &platforms[WHR2_A54G54];
1231 case BCM47XX_BOARD_BUFFALO_WHR_G125:
1232 return &platforms[WHR_G125];
1233 case BCM47XX_BOARD_BUFFALO_WHR_G54S:
1234 return &platforms[WHR_G54S];
1235 case BCM47XX_BOARD_BUFFALO_WHR_HP_G54:
1236 return &platforms[WHR_HP_G54];
1237 case BCM47XX_BOARD_BUFFALO_WLA2_G54L:
1238 return &platforms[WLA2_G54L];
1239 case BCM47XX_BOARD_BUFFALO_WZR_G300N:
1240 return &platforms[WZR_G300N];
1241 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54:
1242 return &platforms[WZR_RS_G54];
1243 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54HP:
1244 return &platforms[WZR_RS_G54HP];
1245 case BCM47XX_BOARD_DELL_TM2300:
1246 return &platforms[TM2300];
1247 case BCM47XX_BOARD_DLINK_DIR130:
1248 return &platforms[DIR130];
1249 case BCM47XX_BOARD_DLINK_DIR330:
1250 return &platforms[DIR330];
1251 case BCM47XX_BOARD_LINKSYS_E1000V1:
1252 return &platforms[E1000V1];
1253 case BCM47XX_BOARD_LINKSYS_E3000V1:
1254 return &platforms[E3000V1];
1255 case BCM47XX_BOARD_LINKSYS_WRT150NV1:
1256 return &platforms[WRT150NV1];
1257 case BCM47XX_BOARD_LINKSYS_WRT150NV11:
1258 return &platforms[WRT150NV11];
1259 case BCM47XX_BOARD_LINKSYS_WRT160NV1:
1260 return &platforms[WRT160NV1];
1261 case BCM47XX_BOARD_LINKSYS_WRT160NV3:
1262 return &platforms[WRT160NV3];
1263 case BCM47XX_BOARD_LINKSYS_WRT300NV11:
1264 return &platforms[WRT300NV11];
1265 case BCM47XX_BOARD_LINKSYS_WRT54G3GV2:
1266 return &platforms[WRT54G3GV2_VF];
1267 case BCM47XX_BOARD_LINKSYS_WRT610NV1:
1268 return &platforms[WRT610N];
1269 case BCM47XX_BOARD_LINKSYS_WRT610NV2:
1270 return &platforms[WRT610NV2];
1271 case BCM47XX_BOARD_MOTOROLA_WE800G:
1272 return &platforms[WE800G];
1273 case BCM47XX_BOARD_MOTOROLA_WR850GP:
1274 return &platforms[WR850GP];
1275 case BCM47XX_BOARD_MOTOROLA_WR850GV2V3:
1276 return &platforms[WR850GV2V3];
1277 case BCM47XX_BOARD_UNKNOWN:
1278 case BCM47XX_BOARD_NON:
1279 printk(MODULE_NAME ": unknown board found, try legacy detect\n");
1280 printk(MODULE_NAME ": please open a ticket at https://dev.openwrt.org and attach the complete nvram\n");
1281 return platform_detect_legacy();
1283 printk(MODULE_NAME ": board was detected as \"%s\", but not gpio configuration available\n", board_name);
1284 printk(MODULE_NAME ": now trying legacy detect\n");
1285 return platform_detect_legacy();
1289 static inline void ssb_maskset32(struct ssb_device *dev,
1290 u16 offset, u32 mask, u32 set)
1292 ssb_write32(dev, offset, (ssb_read32(dev, offset) & mask) | set);
1295 static void gpio_set_irqenable(int enabled, irqreturn_t (*handler)(int, void *))
1299 irq = gpio_to_irq(0);
1300 if (irq == -EINVAL) return;
1303 if (request_irq(irq, handler, IRQF_SHARED, "gpio", handler))
1306 free_irq(irq, handler);
1309 switch (bcm47xx_bus_type) {
1310 #ifdef CONFIG_BCM47XX_SSB
1311 case BCM47XX_BUS_TYPE_SSB:
1312 if (bcm47xx_bus.ssb.chipco.dev)
1313 ssb_maskset32(bcm47xx_bus.ssb.chipco.dev, SSB_CHIPCO_IRQMASK, ~SSB_CHIPCO_IRQ_GPIO, (enabled ? SSB_CHIPCO_IRQ_GPIO : 0));
1316 #ifdef CONFIG_BCM47XX_BCMA
1317 case BCM47XX_BUS_TYPE_BCMA:
1318 if (bcm47xx_bus.bcma.bus.drv_cc.core)
1319 bcma_maskset32(bcm47xx_bus.bcma.bus.drv_cc.core, BCMA_CC_IRQMASK, ~BCMA_CC_IRQ_GPIO, (enabled ? BCMA_CC_IRQ_GPIO : 0));
1325 static void register_buttons(struct button_t *b)
1327 for (; b->name; b++)
1328 platform.button_mask |= b->gpio;
1330 platform.button_mask &= ~gpiomask;
1332 bcm47xx_gpio_outen(platform.button_mask, 0);
1333 bcm47xx_gpio_control(platform.button_mask, 0);
1334 platform.button_polarity = bcm47xx_gpio_in(~0) & platform.button_mask;
1335 bcm47xx_gpio_polarity(platform.button_mask, platform.button_polarity);
1336 bcm47xx_gpio_intmask(platform.button_mask, platform.button_mask);
1338 gpio_set_irqenable(1, button_handler);
1341 static void unregister_buttons(struct button_t *b)
1343 bcm47xx_gpio_intmask(platform.button_mask, 0);
1345 gpio_set_irqenable(0, button_handler);
1349 static void add_msg(struct event_t *event, char *msg, int argv)
1356 s = skb_put(event->skb, strlen(msg) + 1);
1360 static void hotplug_button(struct work_struct *work)
1362 struct event_t *event = container_of(work, struct event_t, wq);
1365 event->skb = alloc_skb(2048, GFP_KERNEL);
1367 s = skb_put(event->skb, strlen(event->action) + 2);
1368 sprintf(s, "%s@", event->action);
1371 NETLINK_CB(event->skb).dst_group = 1;
1372 broadcast_uevent(event->skb, 0, 1, GFP_KERNEL);
1378 static int fill_event (struct event_t *event)
1380 static char buf[128];
1382 add_msg(event, "HOME=/", 0);
1383 add_msg(event, "PATH=/sbin:/bin:/usr/sbin:/usr/bin", 0);
1384 add_msg(event, "SUBSYSTEM=button", 0);
1385 snprintf(buf, 128, "ACTION=%s", event->action);
1386 add_msg(event, buf, 0);
1387 snprintf(buf, 128, "BUTTON=%s", event->name);
1388 add_msg(event, buf, 0);
1389 snprintf(buf, 128, "SEEN=%ld", event->seen);
1390 add_msg(event, buf, 0);
1391 snprintf(buf, 128, "SEQNUM=%llu", uevent_next_seqnum());
1392 add_msg(event, buf, 0);
1398 static irqreturn_t button_handler(int irq, void *dev_id)
1403 in = bcm47xx_gpio_in(~0) & platform.button_mask;
1404 bcm47xx_gpio_polarity(platform.button_mask, in);
1405 changed = platform.button_polarity ^ in;
1406 platform.button_polarity = in;
1408 changed &= ~bcm47xx_gpio_outen(0, 0);
1410 for (b = platform.buttons; b->name; b++) {
1411 struct event_t *event;
1413 if (!(b->gpio & changed)) continue;
1417 if ((event = (struct event_t *)kzalloc (sizeof(struct event_t), GFP_ATOMIC))) {
1418 event->seen = (jiffies - b->seen)/HZ;
1419 event->name = b->name;
1420 event->action = b->pressed ? "pressed" : "released";
1421 INIT_WORK(&event->wq, (void *)(void *)hotplug_button);
1422 schedule_work(&event->wq);
1430 static void register_leds(struct led_t *l)
1432 struct proc_dir_entry *p;
1437 leds = proc_mkdir("led", diag);
1441 for(; l->name; l++) {
1442 if (l->gpio & gpiomask)
1445 if (l->gpio & GPIO_TYPE_EXTIF) {
1449 if (l->polarity != INPUT) oe_mask |= l->gpio;
1451 val |= (l->polarity == NORMAL)?0:l->gpio;
1454 if (l->polarity == INPUT) continue;
1456 if ((p = create_proc_entry(l->name, S_IRUSR, leds))) {
1457 l->proc.type = PROC_LED;
1459 p->data = (void *) &l->proc;
1460 p->proc_fops = &diag_proc_fops;
1464 bcm47xx_gpio_outen(mask, oe_mask);
1465 bcm47xx_gpio_control(mask, 0);
1466 bcm47xx_gpio_out(mask, val);
1467 bcm47xx_gpio_intmask(mask, 0);
1470 static void unregister_leds(struct led_t *l)
1473 remove_proc_entry(l->name, leds);
1475 remove_proc_entry("led", diag);
1478 static void set_led_extif(struct led_t *led)
1480 volatile u8 *addr = (volatile u8 *) KSEG1ADDR(EXTIF_UART) + (led->gpio & ~GPIO_TYPE_MASK);
1487 static void led_flash(unsigned long dummy) {
1492 for (l = platform.leds; l->name; l++) {
1494 if (l->gpio & GPIO_TYPE_EXTIF) {
1496 l->state = !l->state;
1506 u32 val = ~bcm47xx_gpio_in(~0);
1508 bcm47xx_gpio_outen(mask, mask);
1509 bcm47xx_gpio_control(mask, 0);
1510 bcm47xx_gpio_out(mask, val);
1512 if (mask || extif_blink) {
1513 mod_timer(&led_timer, jiffies + FLASH_TIME);
1517 static ssize_t diag_proc_read(struct file *file, char *buf, size_t count, loff_t *ppos)
1519 struct proc_dir_entry *dent = PDE(file->f_dentry->d_inode);
1523 if ((page = kmalloc(1024, GFP_KERNEL)) == NULL)
1526 if (dent->data != NULL) {
1527 struct prochandler_t *handler = (struct prochandler_t *) dent->data;
1528 switch (handler->type) {
1530 struct led_t * led = (struct led_t *) handler->ptr;
1532 len = sprintf(page, "f\n");
1534 if (led->gpio & GPIO_TYPE_EXTIF) {
1535 len = sprintf(page, "%d\n", led->state);
1537 u32 in = (bcm47xx_gpio_in(~0) & led->gpio ? 1 : 0);
1538 u8 p = (led->polarity == NORMAL ? 0 : 1);
1539 len = sprintf(page, "%d\n", ((in ^ p) ? 1 : 0));
1545 len = sprintf(page, "%s\n", platform.name);
1548 len = sprintf(page, "0x%04x\n", gpiomask);
1555 len = min_t(int, len - *ppos, count);
1556 if (copy_to_user(buf, (page + *ppos), len)) {
1570 static ssize_t diag_proc_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
1572 struct proc_dir_entry *dent = PDE(file->f_dentry->d_inode);
1576 if ((page = kmalloc(count + 1, GFP_KERNEL)) == NULL)
1579 if (copy_from_user(page, buf, count)) {
1585 if (dent->data != NULL) {
1586 struct prochandler_t *handler = (struct prochandler_t *) dent->data;
1587 switch (handler->type) {
1589 struct led_t *led = (struct led_t *) handler->ptr;
1590 int p = (led->polarity == NORMAL ? 0 : 1);
1592 if (page[0] == 'f') {
1597 if (led->gpio & GPIO_TYPE_EXTIF) {
1598 led->state = p ^ ((page[0] == '1') ? 1 : 0);
1601 bcm47xx_gpio_outen(led->gpio, led->gpio);
1602 bcm47xx_gpio_control(led->gpio, 0);
1603 bcm47xx_gpio_out(led->gpio, ((p ^ (page[0] == '1')) ? led->gpio : 0));
1609 gpiomask = simple_strtoul(page, NULL, 0);
1611 if (platform.buttons) {
1612 unregister_buttons(platform.buttons);
1613 register_buttons(platform.buttons);
1616 if (platform.leds) {
1617 unregister_leds(platform.leds);
1618 register_leds(platform.leds);
1629 static int __init diag_init(void)
1631 static struct proc_dir_entry *p;
1632 static struct platform_t *detected;
1634 detected = platform_detect();
1636 printk(MODULE_NAME ": Router model not detected.\n");
1639 memcpy(&platform, detected, sizeof(struct platform_t));
1641 printk(MODULE_NAME ": Detected '%s'\n", platform.name);
1642 if (platform.platform_init != NULL) {
1643 platform.platform_init();
1646 if (!(diag = proc_mkdir("diag", NULL))) {
1647 printk(MODULE_NAME ": proc_mkdir on /proc/diag failed\n");
1651 if ((p = create_proc_entry("model", S_IRUSR, diag))) {
1652 p->data = (void *) &proc_model;
1653 p->proc_fops = &diag_proc_fops;
1656 if ((p = create_proc_entry("gpiomask", S_IRUSR | S_IWUSR, diag))) {
1657 p->data = (void *) &proc_gpiomask;
1658 p->proc_fops = &diag_proc_fops;
1661 if (platform.buttons)
1662 register_buttons(platform.buttons);
1665 register_leds(platform.leds);
1670 static void __exit diag_exit(void)
1672 del_timer(&led_timer);
1674 if (platform.buttons)
1675 unregister_buttons(platform.buttons);
1678 unregister_leds(platform.leds);
1680 remove_proc_entry("model", diag);
1681 remove_proc_entry("gpiomask", diag);
1682 remove_proc_entry("diag", NULL);
1685 module_init(diag_init);
1686 module_exit(diag_exit);
1688 MODULE_AUTHOR("Mike Baker, Felix Fietkau / OpenWrt.org");
1689 MODULE_LICENSE("GPL");