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);
141 /* Western Digital */
157 static void __init bcm4780_init(void) {
160 /* Enables GPIO 3 that controls HDD and led power on ASUS WL-700gE */
161 printk(MODULE_NAME ": Spinning up HDD and enabling leds\n");
162 bcm47xx_gpio_outen(pin, pin);
163 bcm47xx_gpio_control(pin, 0);
164 bcm47xx_gpio_out(pin, pin);
166 /* Wait 5s, so the HDD can spin up */
167 set_current_state(TASK_INTERRUPTIBLE);
168 schedule_timeout(HZ * 5);
171 static void __init NetCenter_init(void) {
172 /* unset pin 6 (+12V) */
174 bcm47xx_gpio_outen(pin, pin);
175 bcm47xx_gpio_control(pin, 0);
176 bcm47xx_gpio_out(pin, pin);
177 /* unset pin 1 (turn off red led, blue will light alone if +5V comes up) */
179 bcm47xx_gpio_outen(pin, pin);
180 bcm47xx_gpio_control(pin, 0);
181 bcm47xx_gpio_out(pin, pin);
182 /* unset pin 3 (+5V) and wait 5 seconds (harddisk spin up) */
186 static void __init bcm57xx_init(void) {
189 /* FIXME: switch comes up, but port mappings/vlans not right */
190 bcm47xx_gpio_outen(pin, pin);
191 bcm47xx_gpio_control(pin, 0);
192 bcm47xx_gpio_out(pin, pin);
195 static struct platform_t __initdata platforms[] = {
198 .name = "Linksys WAP54G V1",
200 { .name = "reset", .gpio = 1 << 0 },
203 { .name = "diag", .gpio = 1 << 3 },
204 { .name = "wlan", .gpio = 1 << 4 },
208 .name = "Linksys WAP54G V2",
210 { .name = "reset", .gpio = 1 << 0 },
213 { .name = "wlan", .gpio = 1 << 5, .polarity = REVERSE },
214 /* GPIO 6 is b44 (eth0, LAN) PHY power */
218 .name = "Linksys WAP54G V3",
220 /* FIXME: verify this */
221 { .name = "reset", .gpio = 1 << 7 },
222 { .name = "ses", .gpio = 1 << 0 },
226 { .name = "ses", .gpio = 1 << 1 },
230 .name = "Linksys WRT54G V1.x",
232 { .name = "reset", .gpio = 1 << 6 },
235 { .name = "diag", .gpio = 0x13 | GPIO_TYPE_EXTIF, .polarity = NORMAL },
236 { .name = "dmz", .gpio = 0x12 | GPIO_TYPE_EXTIF, .polarity = NORMAL },
240 .name = "Linksys WRT54G/GS/GL",
242 { .name = "reset", .gpio = 1 << 6 },
243 { .name = "ses", .gpio = 1 << 4 },
246 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
247 { .name = "dmz", .gpio = 1 << 7, .polarity = REVERSE },
248 { .name = "ses_white", .gpio = 1 << 2, .polarity = REVERSE },
249 { .name = "ses_orange", .gpio = 1 << 3, .polarity = REVERSE },
250 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
254 .name = "Linksys WRTSL54GS",
256 { .name = "reset", .gpio = 1 << 6 },
257 { .name = "ses", .gpio = 1 << 4 },
260 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
261 { .name = "dmz", .gpio = 1 << 0, .polarity = REVERSE },
262 { .name = "ses_white", .gpio = 1 << 5, .polarity = REVERSE },
263 { .name = "ses_orange", .gpio = 1 << 7, .polarity = REVERSE },
267 .name = "Linksys WRT54G3G",
269 { .name = "reset", .gpio = 1 << 6 },
270 { .name = "3g", .gpio = 1 << 4 },
273 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
274 { .name = "dmz", .gpio = 1 << 7, .polarity = REVERSE },
275 { .name = "3g_green", .gpio = 1 << 2, .polarity = NORMAL },
276 { .name = "3g_blue", .gpio = 1 << 3, .polarity = NORMAL },
277 { .name = "3g_blink", .gpio = 1 << 5, .polarity = NORMAL },
281 .name = "Linksys WRT54G3GV2-VF",
283 { .name = "reset", .gpio = 1 << 6 },
284 { .name = "3g", .gpio = 1 << 5 },
287 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
288 { .name = "3g_green", .gpio = 1 << 2, .polarity = NORMAL },
289 { .name = "3g_blue", .gpio = 1 << 3, .polarity = NORMAL },
293 .name = "Linksys WRT150N V1",
295 { .name = "reset", .gpio = 1 << 6 },
296 { .name = "ses", .gpio = 1 << 4 },
299 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
300 { .name = "ses_green", .gpio = 1 << 5, .polarity = REVERSE },
301 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE },
305 .name = "Linksys WRT150N V1.1",
307 { .name = "reset", .gpio = 1 << 6 },
308 { .name = "ses", .gpio = 1 << 4 },
311 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
312 { .name = "ses_green", .gpio = 1 << 5, .polarity = REVERSE },
313 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE },
317 .name = "Linksys WRT160N v1.x",
319 { .name = "reset", .gpio = 1 << 6 },
320 { .name = "ses", .gpio = 1 << 4 },
323 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
324 { .name = "ses_blue", .gpio = 1 << 5, .polarity = REVERSE },
325 { .name = "ses_orange", .gpio = 1 << 3, .polarity = REVERSE },
329 .name = "Linksys WRT160N V3",
331 { .name = "reset", .gpio = 1 << 6 },
332 { .name = "ses", .gpio = 1 << 5 },
335 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
336 { .name = "ses_blue", .gpio = 1 << 4, .polarity = REVERSE },
337 { .name = "ses_orange", .gpio = 1 << 2, .polarity = REVERSE },
341 .name = "Linksys WRT300N V1.1",
343 { .name = "reset", .gpio = 1 << 6 }, // "Reset" on back panel
344 { .name = "ses", .gpio = 1 << 4 }, // "Reserved" on top panel
347 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL }, // "Power"
348 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE }, // "Security" Amber
349 { .name = "ses_green", .gpio = 1 << 5, .polarity = REVERSE }, // "Security" Green
351 .platform_init = bcm57xx_init,
354 .name = "Linksys WRT350N",
356 { .name = "reset", .gpio = 1 << 6 },
357 { .name = "ses", .gpio = 1 << 8 },
360 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
361 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE },
362 { .name = "ses_green", .gpio = 1 << 9, .polarity = REVERSE },
363 { .name = "usb_blink", .gpio = 1 << 10, .polarity = REVERSE },
364 { .name = "usb", .gpio = 1 << 11, .polarity = REVERSE },
366 .platform_init = bcm57xx_init,
369 .name = "Linksys WRT600N",
371 { .name = "reset", .gpio = 1 << 6 },
372 { .name = "ses", .gpio = 1 << 7 },
375 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE }, // Power LED
376 { .name = "usb", .gpio = 1 << 3, .polarity = REVERSE }, // USB LED
377 { .name = "wl0_ses_amber", .gpio = 1 << 8, .polarity = REVERSE }, // 2.4Ghz LED Amber
378 { .name = "wl0_ses_green", .gpio = 1 << 9, .polarity = REVERSE }, // 2.4Ghz LED Green
379 { .name = "wl1_ses_amber", .gpio = 1 << 10, .polarity = REVERSE }, // 5.6Ghz LED Amber
380 { .name = "wl1_ses_green", .gpio = 1 << 11, .polarity = REVERSE }, // 5.6Ghz LED Green
382 .platform_init = bcm57xx_init,
385 .name = "Linksys WRT600N V1.1",
387 { .name = "reset", .gpio = 1 << 6 },
388 { .name = "ses", .gpio = 1 << 7 },
391 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE }, // Power LED
392 { .name = "usb", .gpio = 1 << 3, .polarity = REVERSE }, // USB LED
393 { .name = "wl0_ses_amber", .gpio = 1 << 8, .polarity = REVERSE }, // 2.4Ghz LED Amber
394 { .name = "wl0_ses_green", .gpio = 1 << 9, .polarity = REVERSE }, // 2.4Ghz LED Green
395 { .name = "wl1_ses_amber", .gpio = 1 << 10, .polarity = REVERSE }, // 5.6Ghz LED Amber
396 { .name = "wl1_ses_green", .gpio = 1 << 11, .polarity = REVERSE }, // 5.6Ghz LED Green
398 .platform_init = bcm57xx_init,
401 .name = "Linksys WRT610N",
403 { .name = "reset", .gpio = 1 << 6 },
404 { .name = "ses", .gpio = 1 << 8 },
407 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL }, // Power LED
408 { .name = "usb", .gpio = 1 << 0, .polarity = REVERSE }, // USB LED
409 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE }, // WiFi protected setup LED amber
410 { .name = "ses_blue", .gpio = 1 << 9, .polarity = REVERSE }, // WiFi protected setup LED blue
414 .name = "Linksys WRT610N V2",
416 { .name = "reset", .gpio = 1 << 6 },
417 { .name = "ses", .gpio = 1 << 4 },
420 { .name = "power", .gpio = 1 << 5, .polarity = NORMAL }, // Power LED
421 { .name = "usb", .gpio = 1 << 7, .polarity = NORMAL }, // USB LED
422 { .name = "ses_amber", .gpio = 1 << 0, .polarity = REVERSE }, // WiFi protected setup LED amber
423 { .name = "ses_blue", .gpio = 1 << 3, .polarity = REVERSE }, // WiFi protected setup LED blue
424 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL }, // Wireless LED
427 /* same hardware as WRT160NV3 and Cisco Valet M10V1, but different board detection, combine? */
429 .name = "Linksys E1000 V1",
431 { .name = "reset", .gpio = 1 << 6 },
432 { .name = "wps", .gpio = 1 << 5 }, /* nvram get gpio5=wps_button */
435 /** turns on leds for all ethernet ports (wan too)
436 * this also disconnects some, or maybe all, ethernet ports
437 * 1: leds work normally
438 * 0: all lit all the time */
439 /* nvram get gpio3=robo_reset */
440 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
441 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
442 { .name = "ses_blue", .gpio = 1 << 4, .polarity = REVERSE }, /* nvram get gpio4=wps_led */
443 { .name = "ses_orange", .gpio = 1 << 2, .polarity = REVERSE }, /* nvram get gpio2=wps_status_led */
447 .name = "Linksys E3000 V1",
449 { .name = "reset", .gpio = 1 << 6 },
450 { .name = "ses", .gpio = 1 << 4 },
453 { .name = "power", .gpio = 1 << 5, .polarity = NORMAL }, // Power LED
454 { .name = "usb", .gpio = 1 << 7, .polarity = NORMAL }, // USB LED
455 { .name = "ses_amber", .gpio = 1 << 0, .polarity = REVERSE }, // WiFi protected setup LED amber
456 { .name = "ses_blue", .gpio = 1 << 3, .polarity = REVERSE }, // WiFi protected setup LED blue
457 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL }, // Wireless LED
462 .name = "ASUS WL-HDD",
464 { .name = "reset", .gpio = 1 << 6 },
467 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
468 { .name = "usb", .gpio = 1 << 2, .polarity = REVERSE },
472 .name = "ASUS WL-300g",
474 { .name = "reset", .gpio = 1 << 6 },
477 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
481 .name = "ASUS WL-320gE/WL-320gP",
483 { .name = "reset", .gpio = 1 << 6 },
486 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
487 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE },
488 { .name = "link", .gpio = 1 << 11, .polarity = REVERSE },
492 .name = "ASUS WL-330gE",
494 { .name = "reset", .gpio = 1 << 2 },
497 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
501 .name = "ASUS WL-500g",
503 { .name = "reset", .gpio = 1 << 6 },
506 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
510 .name = "ASUS WL-500g Deluxe",
512 { .name = "reset", .gpio = 1 << 6 },
515 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
519 .name = "ASUS WL-500g Premium",
521 { .name = "reset", .gpio = 1 << 0 },
522 { .name = "ses", .gpio = 1 << 4 },
525 { .name = "power", .gpio = 1 << 1, .polarity = REVERSE },
529 .name = "ASUS WL-500g Premium V2",
531 { .name = "reset", .gpio = 1 << 2 },
532 { .name = "ses", .gpio = 1 << 3 },
535 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
536 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
540 .name = "ASUS WL-500W",
542 { .name = "reset", .gpio = 1 << 6 },
543 { .name = "ses", .gpio = 1 << 7 },
546 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
550 .name = "ASUS WL-520GC",
552 { .name = "reset", .gpio = 1 << 2 },
553 { .name = "ses", .gpio = 1 << 3 },
556 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
557 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
561 .name = "ASUS WL-520gU",
563 { .name = "reset", .gpio = 1 << 2 },
564 { .name = "ses", .gpio = 1 << 3 },
567 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
568 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
572 .name = "ASUS (unknown, BCM4702)",
574 { .name = "reset", .gpio = 1 << 6 },
577 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
581 .name = "ASUS WL-700gE",
583 { .name = "reset", .gpio = 1 << 7 }, // on back, hardwired, always resets device regardless OS state
584 { .name = "ses", .gpio = 1 << 4 }, // on back, actual name ezsetup
585 { .name = "power", .gpio = 1 << 0 }, // on front
586 { .name = "copy", .gpio = 1 << 6 }, // on front
590 // GPIO that controls power led also enables/disables some essential functions
593 { .name = "power", .gpio = 1 << 3, .polarity = NORMAL }, // actual name power
595 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE }, // actual name ready
597 .platform_init = bcm4780_init,
600 .name = "ASUS RT-N16",
602 { .name = "reset", .gpio = 1 << 8 },
603 { .name = "ses", .gpio = 1 << 5 },
606 { .name = "power", .gpio = 1 << 1, .polarity = REVERSE },
607 { .name = "wlan", .gpio = 1 << 7, .polarity = NORMAL },
612 .name = "Buffalo WHR-G54S",
614 { .name = "reset", .gpio = 1 << 4 },
615 { .name = "bridge", .gpio = 1 << 5 },
616 { .name = "ses", .gpio = 1 << 0 },
619 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
620 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
621 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
622 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
623 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
627 .name = "Buffalo WBR2-G54",
630 { .name = "reset", .gpio = 1 << 7 },
633 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
637 .name = "Buffalo WHR-HP-G54",
639 { .name = "reset", .gpio = 1 << 4 },
640 { .name = "bridge", .gpio = 1 << 5 },
641 { .name = "ses", .gpio = 1 << 0 },
644 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
645 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
646 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
647 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
648 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
652 .name = "Buffalo WHR-G125",
654 { .name = "reset", .gpio = 1 << 4 },
655 { .name = "bridge", .gpio = 1 << 5 },
656 { .name = "ses", .gpio = 1 << 0 },
659 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
660 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
661 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
662 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
663 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
667 .name = "Buffalo WHR2-A54G54",
669 { .name = "reset", .gpio = 1 << 4 },
672 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
676 .name = "Buffalo WLA2-G54L",
679 { .name = "reset", .gpio = 1 << 7 },
682 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
686 .name = "Buffalo WZR-G300N",
688 { .name = "reset", .gpio = 1 << 4 },
691 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
692 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
693 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
697 .name = "Buffalo WZR-RS-G54",
699 { .name = "ses", .gpio = 1 << 0 },
700 { .name = "reset", .gpio = 1 << 4 },
703 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
704 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
705 { .name = "vpn", .gpio = 1 << 1, .polarity = REVERSE },
709 .name = "Buffalo WZR-RS-G54HP",
711 { .name = "ses", .gpio = 1 << 0 },
712 { .name = "reset", .gpio = 1 << 4 },
715 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
716 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
717 { .name = "vpn", .gpio = 1 << 1, .polarity = REVERSE },
720 [BUFFALO_UNKNOWN] = {
721 .name = "Buffalo (unknown)",
723 { .name = "reset", .gpio = 1 << 7 },
726 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
729 [BUFFALO_UNKNOWN_4710] = {
730 .name = "Buffalo (unknown, BCM4710)",
732 { .name = "reset", .gpio = 1 << 4 },
735 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
740 .name = "Siemens SE505 V1",
742 /* No usable buttons */
745 // { .name = "power", .gpio = 1 << 0 .polarity = REVERSE }, // Usable when retrofitting D26 (?)
746 { .name = "dmz", .gpio = 1 << 4, .polarity = REVERSE }, // actual name WWW
747 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
751 .name = "Siemens SE505 V2",
753 /* No usable buttons */
756 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
757 { .name = "dmz", .gpio = 1 << 0, .polarity = REVERSE }, // actual name WWW
758 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
763 .name = "U.S. Robotics USR5461",
765 /* No usable buttons */
768 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
769 { .name = "printer", .gpio = 1 << 1, .polarity = REVERSE },
774 .name = "Dell TrueMobile 2300",
776 { .name = "reset", .gpio = 1 << 0 },
779 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
780 { .name = "power", .gpio = 1 << 7, .polarity = REVERSE },
784 .name = "Dell TrueMobile 2300 v2",
786 { .name = "reset", .gpio = 1 << 0 },
789 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
790 { .name = "power", .gpio = 1 << 7, .polarity = REVERSE },
795 .name = "Motorola WE800G",
797 { .name = "reset", .gpio = 1 << 0 },
800 { .name = "power", .gpio = 1 << 4, .polarity = NORMAL },
801 { .name = "diag", .gpio = 1 << 2, .polarity = REVERSE },
802 { .name = "wlan_amber", .gpio = 1 << 1, .polarity = NORMAL },
806 .name = "Motorola WR850G V1",
808 { .name = "reset", .gpio = 1 << 0 },
811 { .name = "power", .gpio = 1 << 4, .polarity = NORMAL },
812 { .name = "diag", .gpio = 1 << 3, .polarity = REVERSE },
813 { .name = "dmz", .gpio = 1 << 6, .polarity = NORMAL },
814 { .name = "wlan_red", .gpio = 1 << 5, .polarity = REVERSE },
815 { .name = "wlan_green", .gpio = 1 << 7, .polarity = REVERSE },
819 .name = "Motorola WR850G V2/V3",
821 { .name = "reset", .gpio = 1 << 5 },
824 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
825 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
826 { .name = "wan", .gpio = 1 << 6, .polarity = INPUT },
827 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
831 .name = "Motorola WR850GP",
833 { .name = "reset", .gpio = 1 << 5 },
836 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
837 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
838 { .name = "dmz", .gpio = 1 << 6, .polarity = REVERSE },
839 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
845 .name = "Belkin (unknown)",
846 /* FIXME: verify & add detection */
848 { .name = "reset", .gpio = 1 << 7 },
851 { .name = "power", .gpio = 1 << 5, .polarity = NORMAL },
852 { .name = "wlan", .gpio = 1 << 3, .polarity = NORMAL },
853 { .name = "connected", .gpio = 1 << 0, .polarity = NORMAL },
857 .name = "Belkin PlayMax F7D4301",
859 { .name = "reset", .gpio = 1 << 6 },
860 { .name = "wps", .gpio = 1 << 8 },
863 { .name = "power", .gpio = 1 << 11, .polarity = REVERSE },
864 { .name = "wlan", .gpio = 1 << 13, .polarity = REVERSE },
865 { .name = "led0", .gpio = 1 << 14, .polarity = REVERSE },
866 { .name = "led1", .gpio = 1 << 15, .polarity = REVERSE },
871 .name = "Netgear WGT634U",
873 { .name = "reset", .gpio = 1 << 2 },
876 { .name = "power", .gpio = 1 << 3, .polarity = NORMAL },
881 .name = "Netgear WNR834B V1",
882 .buttons = { /* TODO: add reset button and confirm LEDs - GPIO from dd-wrt */ },
884 { .name = "power", .gpio = 1 << 4, .polarity = REVERSE },
885 { .name = "diag", .gpio = 1 << 5, .polarity = REVERSE },
886 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
891 .name = "Netgear WNR834B V2",
893 { .name = "reset", .gpio = 1 << 6 },
896 { .name = "power", .gpio = 1 << 2, .polarity = NORMAL },
897 { .name = "diag", .gpio = 1 << 3, .polarity = NORMAL },
898 { .name = "connected", .gpio = 1 << 7, .polarity = NORMAL },
902 .name = "Netgear WNDR3400 V1",
904 /* nvram get gpio5=robo_reset */
905 { .name = "reset", .gpio = 1 << 4 },
906 { .name = "wps", .gpio = 1 << 6 },
907 { .name = "wlan", .gpio = 1 << 8 },
910 { .name = "wlan", .gpio = 0 << 0, .polarity = NORMAL },
911 { .name = "connected", .gpio = 1 << 0, .polarity = NORMAL },
912 { .name = "power", .gpio = 1 << 3, .polarity = NORMAL },
913 { .name = "diag", .gpio = 1 << 7, .polarity = NORMAL },
914 { .name = "usb", .gpio = 1 << 2, .polarity = REVERSE },
919 .name = "Trendware TEW411BRP+",
921 { /* No usable buttons */ },
924 { .name = "power", .gpio = 1 << 7, .polarity = NORMAL },
925 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL },
926 { .name = "bridge", .gpio = 1 << 6, .polarity = NORMAL },
931 .name = "SimpleTech SimpleShare NAS",
933 { .name = "reset", .gpio = 1 << 0 }, // Power button on back, named reset to enable failsafe.
936 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE }, // actual name ready
938 .platform_init = bcm4780_init,
942 .name = "D-Link DIR-130",
944 { .name = "reset", .gpio = 1 << 3},
945 { .name = "reserved", .gpio = 1 << 7},
948 { .name = "diag", .gpio = 1 << 0},
949 { .name = "blue", .gpio = 1 << 6},
953 .name = "D-Link DIR-320",
955 { .name = "reserved", .gpio = 1 << 6},
956 { .name = "reset", .gpio = 1 << 7},
959 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
960 { .name = "diag", .gpio = 1 << 1, .polarity = NORMAL }, /* "status led */
961 { .name = "red", .gpio = 1 << 3, .polarity = REVERSE },
962 { .name = "blue", .gpio = 1 << 4, .polarity = REVERSE },
963 { .name = "usb", .gpio = 1 << 5, .polarity = NORMAL },
967 .name = "D-Link DIR-330",
969 { .name = "reset", .gpio = 1 << 3},
970 { .name = "reserved", .gpio = 1 << 7},
973 { .name = "diag", .gpio = 1 << 0},
974 { .name = "usb", .gpio = 1 << 4},
975 { .name = "blue", .gpio = 1 << 6},
979 .name = "D-Link DWL-3150",
981 { .name = "reset", .gpio = 1 << 7},
984 { .name = "diag", .gpio = 1 << 2},
985 { .name = "status", .gpio = 1 << 1},
990 .name = "Sitecom WL-105b",
992 { .name = "reset", .gpio = 1 << 10},
995 { .name = "wlan", .gpio = 1 << 4},
996 { .name = "power", .gpio = 1 << 3},
999 /* Western Digital Net Center */
1001 .name = "Western Digital NetCenter",
1003 { .name = "power", .gpio = 1 << 0},
1004 { .name = "reset", .gpio = 1 << 7},
1006 .platform_init = NetCenter_init,
1008 /* Askey (and clones) */
1010 .name = "Askey RT210W",
1012 /* Power button is hard-wired to hardware reset */
1013 /* but is also connected to GPIO 7 (probably for bootloader recovery) */
1014 { .name = "power", .gpio = 1 << 7},
1017 /* These were verified and named based on Belkin F5D4230-4 v1112 */
1018 { .name = "connected", .gpio = 1 << 0, .polarity = REVERSE },
1019 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
1020 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
1024 .name = "OvisLink WL-1600GL",
1026 { .name = "reset", .gpio = 1 << 3 },
1027 { .name = "ses", .gpio = 1 << 4 },
1030 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
1031 { .name = "wps", .gpio = 1 << 2, .polarity = REVERSE },
1032 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
1033 { .name = "connected", .gpio = 1 << 0, .polarity = REVERSE },
1038 .name = "Microsoft MN-700",
1040 { .name = "reset", .gpio = 1 << 7 },
1043 { .name = "power", .gpio = 1 << 6, .polarity = NORMAL },
1048 .name = "Edimax PS-1208MFG",
1050 { .name = "reset", .gpio = 1 << 4 },
1053 { .name = "status", .gpio = 1 << 1, .polarity = NORMAL },
1054 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
1059 static struct platform_t __init *platform_detect_legacy(void)
1061 char *boardnum, *boardtype, *buf;
1063 if (strcmp(getvar("nvram_type"), "cfe") == 0)
1064 return &platforms[WGT634U];
1067 /* no easy model number, attempt to guess */
1068 boardnum = getvar("boardnum");
1069 boardtype = getvar("boardtype");
1071 if (!strcmp(boardnum, "20070615")) { /* Linksys WRT600N v1/V1.1 */
1072 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "0") && !strcmp(getvar("switch_type"),"BCM5395"))
1073 return &platforms[WRT600NV11];
1075 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "0"))
1076 return &platforms[WRT600N];
1079 if (startswith(getvar("pmon_ver"), "CFE")) {
1080 /* CFE based - newer hardware */
1081 if (!strcmp(boardnum, "42")) { /* Linksys */
1082 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "1"))
1083 return &platforms[WRT350N];
1085 if (!strcmp(boardtype, "0x0101") && !strcmp(getvar("boot_ver"), "v3.6"))
1086 return &platforms[WRT54G3G];
1088 if (!strcmp(getvar("et1phyaddr"),"5") && !strcmp(getvar("et1mdcport"), "1"))
1089 return &platforms[WRTSL54GS];
1091 /* default to WRT54G */
1092 return &platforms[WRT54G];
1094 if (!strcmp(boardnum, "1024") && !strcmp(boardtype, "0x0446"))
1095 return &platforms[WAP54GV2];
1097 if (!strcmp(boardnum, "8") && !strcmp(boardtype, "0x048e"))
1098 return &platforms[WL1600GL];
1101 if (!strcmp(boardnum, "44") || !strcmp(boardnum, "44\r")) {
1102 if (!strcmp(boardtype,"0x0101") || !strcmp(boardtype, "0x0101\r"))
1103 return &platforms[TM2300V2]; /* Dell TrueMobile 2300 v2 */
1106 if (!strcmp(boardnum, "45")) { /* ASUS */
1107 if (!strcmp(boardtype,"0x0472"))
1108 return &platforms[WL500W];
1109 else if (!strcmp(boardtype,"0x467"))
1110 return &platforms[WL320GE];
1112 return &platforms[WL500GD];
1115 if (!strcmp(boardnum, "10496"))
1116 return &platforms[USR5461];
1118 if (!strcmp(getvar("boardtype"), "0x0101") && !strcmp(getvar("boardrev"), "0x10")) /* SE505V2 With Modified CFE */
1119 return &platforms[SE505V2];
1121 if (!strcmp(boardtype, "0x048e") && !strcmp(getvar("boardrev"),"0x35") &&
1122 !strcmp(getvar("boardflags"), "0x750")) /* D-Link DIR-320 */
1123 return &platforms[DIR320];
1125 if (!strncmp(boardnum, "TH",2) && !strcmp(boardtype,"0x042f")) {
1126 return &platforms[WDNetCenter];
1129 if (!strcmp(boardtype,"0x0472") && !strcmp(getvar("cardbus"), "1")) { /* Netgear WNR834B V1 and V2*/
1130 if (!strcmp(boardnum, "08") || !strcmp(boardnum, "8"))
1131 return &platforms[WNR834BV1];
1132 if (!strcmp(boardnum, "01") || !strcmp(boardnum, "1"))
1133 return &platforms[WNR834BV2];
1136 } else { /* PMON based - old stuff */
1137 if ((simple_strtoul(getvar("GemtekPmonVer"), NULL, 0) == 9) &&
1138 (simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 30)) {
1139 return &platforms[WR850GV1];
1141 if (startswith(boardtype, "bcm94710dev")) {
1142 if (!strcmp(boardnum, "42"))
1143 return &platforms[WRT54GV1];
1144 if (simple_strtoul(boardnum, NULL, 0) == 2)
1145 return &platforms[WAP54GV1];
1147 /* MN-700 has also hardware_version 'WL500-...', so use boardnum */
1148 if (startswith(getvar("hardware_version"), "WL500-")) {
1149 if (!strcmp(getvar("boardnum"), "mn700"))
1150 return &platforms[MN700];
1152 return &platforms[WL500G];
1154 if (startswith(getvar("hardware_version"), "WL300-")) {
1155 /* Either WL-300g or WL-HDD, do more extensive checks */
1156 if ((simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 0) &&
1157 (simple_strtoul(getvar("et1phyaddr"), NULL, 0) == 1))
1158 return &platforms[WLHDD];
1159 if ((simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 0) &&
1160 (simple_strtoul(getvar("et1phyaddr"), NULL, 0) == 10))
1161 return &platforms[WL300G];
1163 /* Sitecom WL-105b */
1164 if (startswith(boardnum, "2") && simple_strtoul(getvar("GemtekPmonVer"), NULL, 0) == 1)
1165 return &platforms[WL105B];
1167 /* unknown asus stuff, probably bcm4702 */
1168 if (startswith(boardnum, "asusX"))
1169 return &platforms[ASUS_4702];
1171 /* bcm4702 based Askey RT210W clones, Including:
1172 * Askey RT210W (duh?)
1174 * Belkin F5D7230-4 before version v1444 (MiniPCI slot, not integrated)
1176 if (!strcmp(boardtype,"bcm94710r4")
1177 && !strcmp(boardnum ,"100")
1178 && !strcmp(getvar("pmon_ver"),"v1.03.12.bk")
1180 return &platforms[RT210W];
1184 if (buf || !strcmp(boardnum, "00")) {/* probably buffalo */
1185 if (startswith(boardtype, "bcm94710ap"))
1186 return &platforms[BUFFALO_UNKNOWN_4710];
1188 return &platforms[BUFFALO_UNKNOWN];
1191 if (startswith(getvar("CFEver"), "MotoWRv2") ||
1192 startswith(getvar("CFEver"), "MotoWRv3") ||
1193 !strcmp(getvar("MOTO_BOARD_TYPE"), "WR_FEM1")) {
1195 return &platforms[WR850GV2V3];
1198 if (!strcmp(boardnum, "44") && !strcmp(getvar("boardflags"),"0x0388")) { /* Trendware TEW-411BRP+ */
1199 return &platforms[TEW411BRPP];
1202 if (startswith(boardnum, "04FN")) /* SimpleTech SimpleShare */
1203 return &platforms[STI_NAS];
1205 if (!strcmp(boardnum, "10") && !strcmp(getvar("boardrev"), "0x13")) /* D-Link DWL-3150 */
1206 return &platforms[DWL3150];
1208 if (!strcmp(boardnum, "01") && !strcmp(boardtype, "0x048e") && /* Edimax PS1208MFG */
1209 !strcmp(getvar("status_gpio"), "1")) /* gpio based detection */
1210 return &platforms[PS1208MFG];
1216 static struct platform_t __init *platform_detect(void)
1218 enum bcm47xx_board board;
1219 const char *board_name;
1222 board = bcm47xx_board_get();
1223 board_name = bcm47xx_board_get_name();
1224 if (board != BCM47XX_BOARD_UNKNOWN && board != BCM47XX_BOARD_NON)
1225 printk(MODULE_NAME ": kernel found a \"%s\"\n", board_name);
1228 case BCM47XX_BOARD_ASUS_RTN16:
1229 return &platforms[RTN16];
1230 case BCM47XX_BOARD_ASUS_WL330GE:
1231 return &platforms[WL330GE];
1232 case BCM47XX_BOARD_ASUS_WL500GPV1:
1233 return &platforms[WL500GP];
1234 case BCM47XX_BOARD_ASUS_WL500GPV2:
1235 return &platforms[WL500GPV2];
1236 case BCM47XX_BOARD_ASUS_WL520GC:
1237 return &platforms[WL520GC];
1238 case BCM47XX_BOARD_ASUS_WL520GU:
1239 return &platforms[WL520GU];
1240 case BCM47XX_BOARD_ASUS_WL700GE:
1241 return &platforms[WL700GE];
1242 case BCM47XX_BOARD_BELKIN_F7D4301:
1243 return &platforms[BELKIN_F7D4301];
1244 case BCM47XX_BOARD_BUFFALO_WBR2_G54:
1245 return &platforms[WBR2_G54];
1246 case BCM47XX_BOARD_BUFFALO_WHR2_A54G54:
1247 return &platforms[WHR2_A54G54];
1248 case BCM47XX_BOARD_BUFFALO_WHR_G125:
1249 return &platforms[WHR_G125];
1250 case BCM47XX_BOARD_BUFFALO_WHR_G54S:
1251 return &platforms[WHR_G54S];
1252 case BCM47XX_BOARD_BUFFALO_WHR_HP_G54:
1253 return &platforms[WHR_HP_G54];
1254 case BCM47XX_BOARD_BUFFALO_WLA2_G54L:
1255 return &platforms[WLA2_G54L];
1256 case BCM47XX_BOARD_BUFFALO_WZR_G300N:
1257 return &platforms[WZR_G300N];
1258 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54:
1259 return &platforms[WZR_RS_G54];
1260 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54HP:
1261 return &platforms[WZR_RS_G54HP];
1262 case BCM47XX_BOARD_DELL_TM2300:
1263 return &platforms[TM2300];
1264 case BCM47XX_BOARD_DLINK_DIR130:
1265 return &platforms[DIR130];
1266 case BCM47XX_BOARD_DLINK_DIR330:
1267 return &platforms[DIR330];
1268 case BCM47XX_BOARD_LINKSYS_E1000V1:
1269 return &platforms[E1000V1];
1270 case BCM47XX_BOARD_LINKSYS_E3000V1:
1271 return &platforms[E3000V1];
1272 case BCM47XX_BOARD_LINKSYS_WRT150NV1:
1273 return &platforms[WRT150NV1];
1274 case BCM47XX_BOARD_LINKSYS_WRT150NV11:
1275 return &platforms[WRT150NV11];
1276 case BCM47XX_BOARD_LINKSYS_WRT160NV1:
1277 return &platforms[WRT160NV1];
1278 case BCM47XX_BOARD_LINKSYS_WRT160NV3:
1279 return &platforms[WRT160NV3];
1280 case BCM47XX_BOARD_LINKSYS_WRT300NV11:
1281 return &platforms[WRT300NV11];
1282 case BCM47XX_BOARD_LINKSYS_WRT54G3GV2:
1283 return &platforms[WRT54G3GV2_VF];
1284 case BCM47XX_BOARD_LINKSYS_WRT610NV1:
1285 return &platforms[WRT610N];
1286 case BCM47XX_BOARD_LINKSYS_WRT610NV2:
1287 return &platforms[WRT610NV2];
1288 case BCM47XX_BOARD_MOTOROLA_WE800G:
1289 return &platforms[WE800G];
1290 case BCM47XX_BOARD_MOTOROLA_WR850GP:
1291 return &platforms[WR850GP];
1292 case BCM47XX_BOARD_MOTOROLA_WR850GV2V3:
1293 return &platforms[WR850GV2V3];
1294 case BCM47XX_BOARD_NETGEAR_WNDR3400V1:
1295 return &platforms[WNDR3400V1];
1296 case BCM47XX_BOARD_UNKNOWN:
1297 case BCM47XX_BOARD_NON:
1298 printk(MODULE_NAME ": unknown board found, try legacy detect\n");
1299 printk(MODULE_NAME ": please open a ticket at https://dev.openwrt.org and attach the complete nvram\n");
1300 return platform_detect_legacy();
1302 printk(MODULE_NAME ": board was detected as \"%s\", but not gpio configuration available\n", board_name);
1303 printk(MODULE_NAME ": now trying legacy detect\n");
1304 return platform_detect_legacy();
1308 static inline void ssb_maskset32(struct ssb_device *dev,
1309 u16 offset, u32 mask, u32 set)
1311 ssb_write32(dev, offset, (ssb_read32(dev, offset) & mask) | set);
1314 static void gpio_set_irqenable(int enabled, irqreturn_t (*handler)(int, void *))
1318 irq = gpio_to_irq(0);
1319 if (irq == -EINVAL) return;
1322 if (request_irq(irq, handler, IRQF_SHARED, "gpio", handler))
1325 free_irq(irq, handler);
1328 switch (bcm47xx_bus_type) {
1329 #ifdef CONFIG_BCM47XX_SSB
1330 case BCM47XX_BUS_TYPE_SSB:
1331 if (bcm47xx_bus.ssb.chipco.dev)
1332 ssb_maskset32(bcm47xx_bus.ssb.chipco.dev, SSB_CHIPCO_IRQMASK, ~SSB_CHIPCO_IRQ_GPIO, (enabled ? SSB_CHIPCO_IRQ_GPIO : 0));
1335 #ifdef CONFIG_BCM47XX_BCMA
1336 case BCM47XX_BUS_TYPE_BCMA:
1337 if (bcm47xx_bus.bcma.bus.drv_cc.core)
1338 bcma_maskset32(bcm47xx_bus.bcma.bus.drv_cc.core, BCMA_CC_IRQMASK, ~BCMA_CC_IRQ_GPIO, (enabled ? BCMA_CC_IRQ_GPIO : 0));
1344 static void register_buttons(struct button_t *b)
1346 for (; b->name; b++)
1347 platform.button_mask |= b->gpio;
1349 platform.button_mask &= ~gpiomask;
1351 bcm47xx_gpio_outen(platform.button_mask, 0);
1352 bcm47xx_gpio_control(platform.button_mask, 0);
1353 platform.button_polarity = bcm47xx_gpio_in(~0) & platform.button_mask;
1354 bcm47xx_gpio_polarity(platform.button_mask, platform.button_polarity);
1355 bcm47xx_gpio_intmask(platform.button_mask, platform.button_mask);
1357 gpio_set_irqenable(1, button_handler);
1360 static void unregister_buttons(struct button_t *b)
1362 bcm47xx_gpio_intmask(platform.button_mask, 0);
1364 gpio_set_irqenable(0, button_handler);
1368 static void add_msg(struct event_t *event, char *msg, int argv)
1375 s = skb_put(event->skb, strlen(msg) + 1);
1379 static void hotplug_button(struct work_struct *work)
1381 struct event_t *event = container_of(work, struct event_t, wq);
1384 event->skb = alloc_skb(2048, GFP_KERNEL);
1386 s = skb_put(event->skb, strlen(event->action) + 2);
1387 sprintf(s, "%s@", event->action);
1390 NETLINK_CB(event->skb).dst_group = 1;
1391 broadcast_uevent(event->skb, 0, 1, GFP_KERNEL);
1397 static int fill_event (struct event_t *event)
1399 static char buf[128];
1401 add_msg(event, "HOME=/", 0);
1402 add_msg(event, "PATH=/sbin:/bin:/usr/sbin:/usr/bin", 0);
1403 add_msg(event, "SUBSYSTEM=button", 0);
1404 snprintf(buf, 128, "ACTION=%s", event->action);
1405 add_msg(event, buf, 0);
1406 snprintf(buf, 128, "BUTTON=%s", event->name);
1407 add_msg(event, buf, 0);
1408 snprintf(buf, 128, "SEEN=%ld", event->seen);
1409 add_msg(event, buf, 0);
1410 snprintf(buf, 128, "SEQNUM=%llu", uevent_next_seqnum());
1411 add_msg(event, buf, 0);
1417 static irqreturn_t button_handler(int irq, void *dev_id)
1422 in = bcm47xx_gpio_in(~0) & platform.button_mask;
1423 bcm47xx_gpio_polarity(platform.button_mask, in);
1424 changed = platform.button_polarity ^ in;
1425 platform.button_polarity = in;
1427 changed &= ~bcm47xx_gpio_outen(0, 0);
1429 for (b = platform.buttons; b->name; b++) {
1430 struct event_t *event;
1432 if (!(b->gpio & changed)) continue;
1436 if ((event = (struct event_t *)kzalloc (sizeof(struct event_t), GFP_ATOMIC))) {
1437 event->seen = (jiffies - b->seen)/HZ;
1438 event->name = b->name;
1439 event->action = b->pressed ? "pressed" : "released";
1440 INIT_WORK(&event->wq, (void *)(void *)hotplug_button);
1441 schedule_work(&event->wq);
1449 static void register_leds(struct led_t *l)
1451 struct proc_dir_entry *p;
1456 leds = proc_mkdir("led", diag);
1460 for(; l->name; l++) {
1461 if (l->gpio & gpiomask)
1464 if (l->gpio & GPIO_TYPE_EXTIF) {
1468 if (l->polarity != INPUT) oe_mask |= l->gpio;
1470 val |= (l->polarity == NORMAL)?0:l->gpio;
1473 if (l->polarity == INPUT) continue;
1475 if ((p = create_proc_entry(l->name, S_IRUSR, leds))) {
1476 l->proc.type = PROC_LED;
1478 p->data = (void *) &l->proc;
1479 p->proc_fops = &diag_proc_fops;
1483 bcm47xx_gpio_outen(mask, oe_mask);
1484 bcm47xx_gpio_control(mask, 0);
1485 bcm47xx_gpio_out(mask, val);
1486 bcm47xx_gpio_intmask(mask, 0);
1489 static void unregister_leds(struct led_t *l)
1492 remove_proc_entry(l->name, leds);
1494 remove_proc_entry("led", diag);
1497 static void set_led_extif(struct led_t *led)
1499 volatile u8 *addr = (volatile u8 *) KSEG1ADDR(EXTIF_UART) + (led->gpio & ~GPIO_TYPE_MASK);
1506 static void led_flash(unsigned long dummy) {
1511 for (l = platform.leds; l->name; l++) {
1513 if (l->gpio & GPIO_TYPE_EXTIF) {
1515 l->state = !l->state;
1525 u32 val = ~bcm47xx_gpio_in(~0);
1527 bcm47xx_gpio_outen(mask, mask);
1528 bcm47xx_gpio_control(mask, 0);
1529 bcm47xx_gpio_out(mask, val);
1531 if (mask || extif_blink) {
1532 mod_timer(&led_timer, jiffies + FLASH_TIME);
1536 static ssize_t diag_proc_read(struct file *file, char *buf, size_t count, loff_t *ppos)
1538 struct proc_dir_entry *dent = PDE(file->f_dentry->d_inode);
1542 if ((page = kmalloc(1024, GFP_KERNEL)) == NULL)
1545 if (dent->data != NULL) {
1546 struct prochandler_t *handler = (struct prochandler_t *) dent->data;
1547 switch (handler->type) {
1549 struct led_t * led = (struct led_t *) handler->ptr;
1551 len = sprintf(page, "f\n");
1553 if (led->gpio & GPIO_TYPE_EXTIF) {
1554 len = sprintf(page, "%d\n", led->state);
1556 u32 in = (bcm47xx_gpio_in(~0) & led->gpio ? 1 : 0);
1557 u8 p = (led->polarity == NORMAL ? 0 : 1);
1558 len = sprintf(page, "%d\n", ((in ^ p) ? 1 : 0));
1564 len = sprintf(page, "%s\n", platform.name);
1567 len = sprintf(page, "0x%04x\n", gpiomask);
1574 len = min_t(int, len - *ppos, count);
1575 if (copy_to_user(buf, (page + *ppos), len)) {
1589 static ssize_t diag_proc_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
1591 struct proc_dir_entry *dent = PDE(file->f_dentry->d_inode);
1595 if ((page = kmalloc(count + 1, GFP_KERNEL)) == NULL)
1598 if (copy_from_user(page, buf, count)) {
1604 if (dent->data != NULL) {
1605 struct prochandler_t *handler = (struct prochandler_t *) dent->data;
1606 switch (handler->type) {
1608 struct led_t *led = (struct led_t *) handler->ptr;
1609 int p = (led->polarity == NORMAL ? 0 : 1);
1611 if (page[0] == 'f') {
1616 if (led->gpio & GPIO_TYPE_EXTIF) {
1617 led->state = p ^ ((page[0] == '1') ? 1 : 0);
1620 bcm47xx_gpio_outen(led->gpio, led->gpio);
1621 bcm47xx_gpio_control(led->gpio, 0);
1622 bcm47xx_gpio_out(led->gpio, ((p ^ (page[0] == '1')) ? led->gpio : 0));
1628 gpiomask = simple_strtoul(page, NULL, 0);
1630 if (platform.buttons) {
1631 unregister_buttons(platform.buttons);
1632 register_buttons(platform.buttons);
1635 if (platform.leds) {
1636 unregister_leds(platform.leds);
1637 register_leds(platform.leds);
1648 static int __init diag_init(void)
1650 static struct proc_dir_entry *p;
1651 static struct platform_t *detected;
1653 detected = platform_detect();
1655 printk(MODULE_NAME ": Router model not detected.\n");
1658 memcpy(&platform, detected, sizeof(struct platform_t));
1660 printk(MODULE_NAME ": Detected '%s'\n", platform.name);
1661 if (platform.platform_init != NULL) {
1662 platform.platform_init();
1665 if (!(diag = proc_mkdir("diag", NULL))) {
1666 printk(MODULE_NAME ": proc_mkdir on /proc/diag failed\n");
1670 if ((p = create_proc_entry("model", S_IRUSR, diag))) {
1671 p->data = (void *) &proc_model;
1672 p->proc_fops = &diag_proc_fops;
1675 if ((p = create_proc_entry("gpiomask", S_IRUSR | S_IWUSR, diag))) {
1676 p->data = (void *) &proc_gpiomask;
1677 p->proc_fops = &diag_proc_fops;
1680 if (platform.buttons)
1681 register_buttons(platform.buttons);
1684 register_leds(platform.leds);
1689 static void __exit diag_exit(void)
1691 del_timer(&led_timer);
1693 if (platform.buttons)
1694 unregister_buttons(platform.buttons);
1697 unregister_leds(platform.leds);
1699 remove_proc_entry("model", diag);
1700 remove_proc_entry("gpiomask", diag);
1701 remove_proc_entry("diag", NULL);
1704 module_init(diag_init);
1705 module_exit(diag_exit);
1707 MODULE_AUTHOR("Mike Baker, Felix Fietkau / OpenWrt.org");
1708 MODULE_LICENSE("GPL");