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 extern u64 uevent_next_seqnum(void);
39 #define getvar(str) (nvram_get(str)?:"")
41 static inline int startswith (char *source, char *cmp) { return !strncmp(source,cmp,strlen(cmp)); }
42 static int fill_event(struct event_t *);
43 static unsigned int gpiomask = 0;
44 module_param(gpiomask, int, 0644);
131 /* Western Digital */
147 static void __init bcm4780_init(void) {
150 /* Enables GPIO 3 that controls HDD and led power on ASUS WL-700gE */
151 printk(MODULE_NAME ": Spinning up HDD and enabling leds\n");
152 gpio_outen(pin, pin);
153 gpio_control(pin, 0);
156 /* Wait 5s, so the HDD can spin up */
157 set_current_state(TASK_INTERRUPTIBLE);
158 schedule_timeout(HZ * 5);
161 static void __init NetCenter_init(void) {
162 /* unset pin 6 (+12V) */
164 gpio_outen(pin, pin);
165 gpio_control(pin, 0);
167 /* unset pin 1 (turn off red led, blue will light alone if +5V comes up) */
169 gpio_outen(pin, pin);
170 gpio_control(pin, 0);
172 /* unset pin 3 (+5V) and wait 5 seconds (harddisk spin up) */
176 static void __init bcm57xx_init(void) {
179 /* FIXME: switch comes up, but port mappings/vlans not right */
180 gpio_outen(pin, pin);
181 gpio_control(pin, 0);
185 static struct platform_t __initdata platforms[] = {
188 .name = "Linksys WAP54G V1",
190 { .name = "reset", .gpio = 1 << 0 },
193 { .name = "diag", .gpio = 1 << 3 },
194 { .name = "wlan", .gpio = 1 << 4 },
198 .name = "Linksys WAP54G V2",
200 { .name = "reset", .gpio = 1 << 0 },
203 { .name = "wlan", .gpio = 1 << 5, .polarity = REVERSE },
204 /* GPIO 6 is b44 (eth0, LAN) PHY power */
208 .name = "Linksys WAP54G V3",
210 /* FIXME: verify this */
211 { .name = "reset", .gpio = 1 << 7 },
212 { .name = "ses", .gpio = 1 << 0 },
216 { .name = "ses", .gpio = 1 << 1 },
220 .name = "Linksys WRT54G V1.x",
222 { .name = "reset", .gpio = 1 << 6 },
225 { .name = "diag", .gpio = 0x13 | GPIO_TYPE_EXTIF, .polarity = NORMAL },
226 { .name = "dmz", .gpio = 0x12 | GPIO_TYPE_EXTIF, .polarity = NORMAL },
230 .name = "Linksys WRT54G/GS/GL",
232 { .name = "reset", .gpio = 1 << 6 },
233 { .name = "ses", .gpio = 1 << 4 },
236 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
237 { .name = "dmz", .gpio = 1 << 7, .polarity = REVERSE },
238 { .name = "ses_white", .gpio = 1 << 2, .polarity = REVERSE },
239 { .name = "ses_orange", .gpio = 1 << 3, .polarity = REVERSE },
240 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
244 .name = "Linksys WRTSL54GS",
246 { .name = "reset", .gpio = 1 << 6 },
247 { .name = "ses", .gpio = 1 << 4 },
250 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
251 { .name = "dmz", .gpio = 1 << 0, .polarity = REVERSE },
252 { .name = "ses_white", .gpio = 1 << 5, .polarity = REVERSE },
253 { .name = "ses_orange", .gpio = 1 << 7, .polarity = REVERSE },
257 .name = "Linksys WRT54G3G",
259 { .name = "reset", .gpio = 1 << 6 },
260 { .name = "3g", .gpio = 1 << 4 },
263 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
264 { .name = "dmz", .gpio = 1 << 7, .polarity = REVERSE },
265 { .name = "3g_green", .gpio = 1 << 2, .polarity = NORMAL },
266 { .name = "3g_blue", .gpio = 1 << 3, .polarity = NORMAL },
267 { .name = "3g_blink", .gpio = 1 << 5, .polarity = NORMAL },
271 .name = "Linksys WRT54G3GV2-VF",
273 { .name = "reset", .gpio = 1 << 6 },
274 { .name = "3g", .gpio = 1 << 5 },
277 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
278 { .name = "3g_green", .gpio = 1 << 2, .polarity = NORMAL },
279 { .name = "3g_blue", .gpio = 1 << 3, .polarity = NORMAL },
283 .name = "Linksys WRT160N",
285 { .name = "reset", .gpio = 1 << 6 },
286 { .name = "ses", .gpio = 1 << 4 },
289 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
290 { .name = "ses_blue", .gpio = 1 << 5, .polarity = REVERSE },
291 { .name = "ses_orange", .gpio = 1 << 3, .polarity = REVERSE },
295 .name = "Linksys WRT300N V1.1",
297 { .name = "reset", .gpio = 1 << 6 }, // "Reset" on back panel
298 { .name = "ses", .gpio = 1 << 4 }, // "Reserved" on top panel
301 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL }, // "Power"
302 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE }, // "Security" Amber
303 { .name = "ses_green", .gpio = 1 << 5, .polarity = REVERSE }, // "Security" Green
305 .platform_init = bcm57xx_init,
308 .name = "Linksys WRT350N",
310 { .name = "reset", .gpio = 1 << 6 },
311 { .name = "ses", .gpio = 1 << 8 },
314 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
315 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE },
316 { .name = "ses_green", .gpio = 1 << 9, .polarity = REVERSE },
317 { .name = "usb_blink", .gpio = 1 << 10, .polarity = REVERSE },
318 { .name = "usb", .gpio = 1 << 11, .polarity = REVERSE },
320 .platform_init = bcm57xx_init,
323 .name = "Linksys WRT600N",
325 { .name = "reset", .gpio = 1 << 6 },
326 { .name = "ses", .gpio = 1 << 7 },
329 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE }, // Power LED
330 { .name = "usb", .gpio = 1 << 3, .polarity = REVERSE }, // USB LED
331 { .name = "wl0_ses_amber", .gpio = 1 << 8, .polarity = REVERSE }, // 2.4Ghz LED Amber
332 { .name = "wl0_ses_green", .gpio = 1 << 9, .polarity = REVERSE }, // 2.4Ghz LED Green
333 { .name = "wl1_ses_amber", .gpio = 1 << 10, .polarity = REVERSE }, // 5.6Ghz LED Amber
334 { .name = "wl1_ses_green", .gpio = 1 << 11, .polarity = REVERSE }, // 5.6Ghz LED Green
336 .platform_init = bcm57xx_init,
339 .name = "Linksys WRT600N V1.1",
341 { .name = "reset", .gpio = 1 << 6 },
342 { .name = "ses", .gpio = 1 << 7 },
345 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE }, // Power LED
346 { .name = "usb", .gpio = 1 << 3, .polarity = REVERSE }, // USB LED
347 { .name = "wl0_ses_amber", .gpio = 1 << 8, .polarity = REVERSE }, // 2.4Ghz LED Amber
348 { .name = "wl0_ses_green", .gpio = 1 << 9, .polarity = REVERSE }, // 2.4Ghz LED Green
349 { .name = "wl1_ses_amber", .gpio = 1 << 10, .polarity = REVERSE }, // 5.6Ghz LED Amber
350 { .name = "wl1_ses_green", .gpio = 1 << 11, .polarity = REVERSE }, // 5.6Ghz LED Green
352 .platform_init = bcm57xx_init,
355 .name = "Linksys WRT610N",
357 { .name = "reset", .gpio = 1 << 6 },
358 { .name = "ses", .gpio = 1 << 8 },
361 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL }, // Power LED
362 { .name = "usb", .gpio = 1 << 0, .polarity = REVERSE }, // USB LED
363 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE }, // WiFi protected setup LED amber
364 { .name = "ses_blue", .gpio = 1 << 9, .polarity = REVERSE }, // WiFi protected setup LED blue
369 .name = "ASUS WL-HDD",
371 { .name = "reset", .gpio = 1 << 6 },
374 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
375 { .name = "usb", .gpio = 1 << 2, .polarity = REVERSE },
379 .name = "ASUS WL-300g",
381 { .name = "reset", .gpio = 1 << 6 },
384 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
388 .name = "ASUS WL-320gE/WL-320gP",
390 { .name = "reset", .gpio = 1 << 6 },
393 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
394 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE },
395 { .name = "link", .gpio = 1 << 11, .polarity = REVERSE },
399 .name = "ASUS WL-330gE",
401 { .name = "reset", .gpio = 1 << 2 },
404 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
408 .name = "ASUS WL-500g",
410 { .name = "reset", .gpio = 1 << 6 },
413 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
417 .name = "ASUS WL-500g Deluxe",
419 { .name = "reset", .gpio = 1 << 6 },
422 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
426 .name = "ASUS WL-500g Premium",
428 { .name = "reset", .gpio = 1 << 0 },
429 { .name = "ses", .gpio = 1 << 4 },
432 { .name = "power", .gpio = 1 << 1, .polarity = REVERSE },
436 .name = "ASUS WL-500g Premium V2",
438 { .name = "reset", .gpio = 1 << 2 },
439 { .name = "ses", .gpio = 1 << 3 },
442 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
443 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
447 .name = "ASUS WL-500W",
449 { .name = "reset", .gpio = 1 << 6 },
450 { .name = "ses", .gpio = 1 << 7 },
453 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
457 .name = "ASUS WL-520GC",
459 { .name = "reset", .gpio = 1 << 2 },
460 { .name = "ses", .gpio = 1 << 3 },
463 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
464 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
468 .name = "ASUS WL-520gU",
470 { .name = "reset", .gpio = 1 << 2 },
471 { .name = "ses", .gpio = 1 << 3 },
474 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
475 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
479 .name = "ASUS (unknown, BCM4702)",
481 { .name = "reset", .gpio = 1 << 6 },
484 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
488 .name = "ASUS WL-700gE",
490 { .name = "reset", .gpio = 1 << 7 }, // on back, hardwired, always resets device regardless OS state
491 { .name = "ses", .gpio = 1 << 4 }, // on back, actual name ezsetup
492 { .name = "power", .gpio = 1 << 0 }, // on front
493 { .name = "copy", .gpio = 1 << 6 }, // on front
497 // GPIO that controls power led also enables/disables some essential functions
500 { .name = "power", .gpio = 1 << 3, .polarity = NORMAL }, // actual name power
502 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE }, // actual name ready
504 .platform_init = bcm4780_init,
508 .name = "Buffalo WHR-G54S",
510 { .name = "reset", .gpio = 1 << 4 },
511 { .name = "bridge", .gpio = 1 << 5 },
512 { .name = "ses", .gpio = 1 << 0 },
515 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
516 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
517 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
518 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
519 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
523 .name = "Buffalo WBR2-G54",
526 { .name = "reset", .gpio = 1 << 7 },
529 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
533 .name = "Buffalo WHR-HP-G54",
535 { .name = "reset", .gpio = 1 << 4 },
536 { .name = "bridge", .gpio = 1 << 5 },
537 { .name = "ses", .gpio = 1 << 0 },
540 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
541 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
542 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
543 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
544 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
548 .name = "Buffalo WHR-G125",
550 { .name = "reset", .gpio = 1 << 4 },
551 { .name = "bridge", .gpio = 1 << 5 },
552 { .name = "ses", .gpio = 1 << 0 },
555 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
556 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
557 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
558 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
559 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
563 .name = "Buffalo WHR2-A54G54",
565 { .name = "reset", .gpio = 1 << 4 },
568 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
572 .name = "Buffalo WLA2-G54L",
575 { .name = "reset", .gpio = 1 << 7 },
578 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
582 .name = "Buffalo WZR-G300N",
584 { .name = "reset", .gpio = 1 << 4 },
587 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
588 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
589 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
593 .name = "Buffalo WZR-RS-G54",
595 { .name = "ses", .gpio = 1 << 0 },
596 { .name = "reset", .gpio = 1 << 4 },
599 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
600 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
601 { .name = "vpn", .gpio = 1 << 1, .polarity = REVERSE },
605 .name = "Buffalo WZR-RS-G54HP",
607 { .name = "ses", .gpio = 1 << 0 },
608 { .name = "reset", .gpio = 1 << 4 },
611 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
612 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
613 { .name = "vpn", .gpio = 1 << 1, .polarity = REVERSE },
616 [BUFFALO_UNKNOWN] = {
617 .name = "Buffalo (unknown)",
619 { .name = "reset", .gpio = 1 << 7 },
622 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
625 [BUFFALO_UNKNOWN_4710] = {
626 .name = "Buffalo (unknown, BCM4710)",
628 { .name = "reset", .gpio = 1 << 4 },
631 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
636 .name = "Siemens SE505 V1",
638 /* No usable buttons */
641 // { .name = "power", .gpio = 1 << 0 .polarity = REVERSE }, // Usable when retrofitting D26 (?)
642 { .name = "dmz", .gpio = 1 << 4, .polarity = REVERSE }, // actual name WWW
643 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
647 .name = "Siemens SE505 V2",
649 /* No usable buttons */
652 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
653 { .name = "dmz", .gpio = 1 << 0, .polarity = REVERSE }, // actual name WWW
654 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
659 .name = "U.S. Robotics USR5461",
661 /* No usable buttons */
664 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
665 { .name = "printer", .gpio = 1 << 1, .polarity = REVERSE },
670 .name = "Dell TrueMobile 2300",
672 { .name = "reset", .gpio = 1 << 0 },
675 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
676 { .name = "power", .gpio = 1 << 7, .polarity = REVERSE },
680 .name = "Dell TrueMobile 2300 v2",
682 { .name = "reset", .gpio = 1 << 0 },
685 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
686 { .name = "power", .gpio = 1 << 7, .polarity = REVERSE },
691 .name = "Motorola WE800G",
693 { .name = "reset", .gpio = 1 << 0 },
696 { .name = "power", .gpio = 1 << 4, .polarity = NORMAL },
697 { .name = "diag", .gpio = 1 << 2, .polarity = REVERSE },
698 { .name = "wlan_amber", .gpio = 1 << 1, .polarity = NORMAL },
702 .name = "Motorola WR850G V1",
704 { .name = "reset", .gpio = 1 << 0 },
707 { .name = "power", .gpio = 1 << 4, .polarity = NORMAL },
708 { .name = "diag", .gpio = 1 << 3, .polarity = REVERSE },
709 { .name = "dmz", .gpio = 1 << 6, .polarity = NORMAL },
710 { .name = "wlan_red", .gpio = 1 << 5, .polarity = REVERSE },
711 { .name = "wlan_green", .gpio = 1 << 7, .polarity = REVERSE },
715 .name = "Motorola WR850G V2/V3",
717 { .name = "reset", .gpio = 1 << 5 },
720 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
721 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
722 { .name = "wan", .gpio = 1 << 6, .polarity = INPUT },
723 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
727 .name = "Motorola WR850GP",
729 { .name = "reset", .gpio = 1 << 5 },
732 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
733 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
734 { .name = "dmz", .gpio = 1 << 6, .polarity = REVERSE },
735 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
741 .name = "Belkin (unknown)",
742 /* FIXME: verify & add detection */
744 { .name = "reset", .gpio = 1 << 7 },
747 { .name = "power", .gpio = 1 << 5, .polarity = NORMAL },
748 { .name = "wlan", .gpio = 1 << 3, .polarity = NORMAL },
749 { .name = "connected", .gpio = 1 << 0, .polarity = NORMAL },
754 .name = "Netgear WGT634U",
756 { .name = "reset", .gpio = 1 << 2 },
759 { .name = "power", .gpio = 1 << 3, .polarity = NORMAL },
764 .name = "Netgear WNR834B V1",
765 .buttons = { /* TODO: add reset button and confirm LEDs - GPIO from dd-wrt */ },
767 { .name = "power", .gpio = 1 << 4, .polarity = REVERSE },
768 { .name = "diag", .gpio = 1 << 5, .polarity = REVERSE },
769 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
774 .name = "Netgear WNR834B V2",
776 { .name = "reset", .gpio = 1 << 6 },
779 { .name = "power", .gpio = 1 << 2, .polarity = NORMAL },
780 { .name = "diag", .gpio = 1 << 3, .polarity = NORMAL },
781 { .name = "connected", .gpio = 1 << 7, .polarity = NORMAL },
786 .name = "Trendware TEW411BRP+",
788 { /* No usable buttons */ },
791 { .name = "power", .gpio = 1 << 7, .polarity = NORMAL },
792 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL },
793 { .name = "bridge", .gpio = 1 << 6, .polarity = NORMAL },
798 .name = "SimpleTech SimpleShare NAS",
800 { .name = "reset", .gpio = 1 << 0 }, // Power button on back, named reset to enable failsafe.
803 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE }, // actual name ready
805 .platform_init = bcm4780_init,
809 .name = "D-Link DIR-130",
811 { .name = "reset", .gpio = 1 << 3},
812 { .name = "reserved", .gpio = 1 << 7},
815 { .name = "diag", .gpio = 1 << 0},
816 { .name = "blue", .gpio = 1 << 6},
820 .name = "D-Link DIR-320",
822 { .name = "reserved", .gpio = 1 << 6},
823 { .name = "reset", .gpio = 1 << 7},
826 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
827 { .name = "diag", .gpio = 1 << 1, .polarity = NORMAL }, /* "status led */
828 { .name = "red", .gpio = 1 << 3, .polarity = REVERSE },
829 { .name = "blue", .gpio = 1 << 4, .polarity = REVERSE },
830 { .name = "usb", .gpio = 1 << 5, .polarity = NORMAL },
834 .name = "D-Link DIR-330",
836 { .name = "reset", .gpio = 1 << 3},
837 { .name = "reserved", .gpio = 1 << 7},
840 { .name = "diag", .gpio = 1 << 0},
841 { .name = "usb", .gpio = 1 << 4},
842 { .name = "blue", .gpio = 1 << 6},
846 .name = "D-Link DWL-3150",
848 { .name = "reset", .gpio = 1 << 7},
851 { .name = "diag", .gpio = 1 << 2},
852 { .name = "status", .gpio = 1 << 1},
857 .name = "Sitecom WL-105b",
859 { .name = "reset", .gpio = 1 << 10},
862 { .name = "wlan", .gpio = 1 << 4},
863 { .name = "power", .gpio = 1 << 3},
866 /* Western Digital Net Center */
868 .name = "Western Digital NetCenter",
870 { .name = "power", .gpio = 1 << 0},
871 { .name = "reset", .gpio = 1 << 7},
873 .platform_init = NetCenter_init,
875 /* Askey (and clones) */
877 .name = "Askey RT210W",
879 /* Power button is hard-wired to hardware reset */
880 /* but is also connected to GPIO 7 (probably for bootloader recovery) */
881 { .name = "power", .gpio = 1 << 7},
884 /* These were verified and named based on Belkin F5D4230-4 v1112 */
885 { .name = "connected", .gpio = 1 << 0, .polarity = REVERSE },
886 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
887 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
891 .name = "OvisLink WL-1600GL",
893 { .name = "reset", .gpio = 1 << 3 },
894 { .name = "ses", .gpio = 1 << 4 },
897 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
898 { .name = "wps", .gpio = 1 << 2, .polarity = REVERSE },
899 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
900 { .name = "connected", .gpio = 1 << 0, .polarity = REVERSE },
905 .name = "Microsoft MN-700",
907 { .name = "reset", .gpio = 1 << 7 },
910 { .name = "power", .gpio = 1 << 6, .polarity = NORMAL },
915 .name = "Edimax PS-1208MFG",
917 { .name = "reset", .gpio = 1 << 4 },
920 { .name = "status", .gpio = 1 << 1, .polarity = NORMAL },
921 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
926 static struct platform_t __init *platform_detect(void)
928 char *boardnum, *boardtype, *buf;
930 if (strcmp(getvar("nvram_type"), "cfe") == 0)
931 return &platforms[WGT634U];
933 /* Look for a model identifier */
935 /* Based on "model_name" */
936 if ((buf = nvram_get("model_name"))) {
937 if (!strcmp(buf, "DIR-130"))
938 return &platforms[DIR130];
939 if (!strcmp(buf, "DIR-330"))
940 return &platforms[DIR330];
943 /* Based on "wsc_modelname */
944 if ((buf = nvram_get("wsc_modelname"))) {
945 if (!strcmp(buf, "WRT610N"))
946 return &platforms[WRT610N];
949 /* Based on "model_no" */
950 if ((buf = nvram_get("model_no"))) {
951 if (startswith(buf,"WL700")) /* WL700* */
952 return &platforms[WL700GE];
955 /* Based on "hardware_version" */
956 if ((buf = nvram_get("hardware_version"))) {
957 if (startswith(buf,"WL500GPV2-")) /* WL500GPV2-* */
958 return &platforms[WL500GPV2];
959 if (startswith(buf,"WL520GC-")) /* WL520GU-* */
960 return &platforms[WL520GC];
961 if (startswith(buf,"WL520GU-")) /* WL520GU-* */
962 return &platforms[WL520GU];
963 if (startswith(buf,"WL330GE-")) /* WL330GE-* */
964 return &platforms[WL330GE];
967 /* Based on "ModelId" */
968 if ((buf = nvram_get("ModelId"))) {
969 if (!strcmp(buf, "WR850GP"))
970 return &platforms[WR850GP];
971 if (!strcmp(buf, "WR850G"))
972 return &platforms[WR850GV2V3];
973 if (!strcmp(buf, "WX-5565") && !strcmp(getvar("boardtype"),"bcm94710ap"))
974 return &platforms[TM2300]; /* Dell TrueMobile 2300 */
975 if (startswith(buf,"WE800G")) /* WE800G* */
976 return &platforms[WE800G];
980 if ((buf = (nvram_get("melco_id") ?: nvram_get("buffalo_id")))) {
981 /* Buffalo hardware, check id for specific hardware matches */
982 if (!strcmp(buf, "29bb0332"))
983 return &platforms[WBR2_G54];
984 if (!strcmp(buf, "29129"))
985 return &platforms[WLA2_G54L];
986 if (!strcmp(buf, "30189"))
987 return &platforms[WHR_HP_G54];
988 if (!strcmp(buf, "32093"))
989 return &platforms[WHR_G125];
990 if (!strcmp(buf, "30182"))
991 return &platforms[WHR_G54S];
992 if (!strcmp(buf, "290441dd"))
993 return &platforms[WHR2_A54G54];
994 if (!strcmp(buf, "31120"))
995 return &platforms[WZR_G300N];
996 if (!strcmp(buf, "30083"))
997 return &platforms[WZR_RS_G54];
998 if (!strcmp(buf, "30103"))
999 return &platforms[WZR_RS_G54HP];
1002 /* no easy model number, attempt to guess */
1003 boardnum = getvar("boardnum");
1004 boardtype = getvar("boardtype");
1006 if (!strcmp(boardnum, "20070615")) { /* Linksys WRT600N v1/V1.1 */
1007 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "0") && !strcmp(getvar("switch_type"),"BCM5395"))
1008 return &platforms[WRT600NV11];
1010 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "0"))
1011 return &platforms[WRT600N];
1014 if (startswith(getvar("pmon_ver"), "CFE")) {
1015 /* CFE based - newer hardware */
1016 if (!strcmp(boardnum, "42")) { /* Linksys */
1017 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("boot_hw_model"), "WRT300N") && !strcmp(getvar("boot_hw_ver"), "1.1"))
1018 return &platforms[WRT300NV11];
1020 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "1"))
1021 return &platforms[WRT350N];
1023 if (!strcmp(boardtype, "0x0101") && !strcmp(getvar("boot_ver"), "v3.6"))
1024 return &platforms[WRT54G3G];
1026 if (!strcmp(boardtype, "0x042f") && !strcmp(getvar("model_name"), "WRT54G3GV2-VF"))
1027 return &platforms[WRT54G3GV2_VF];
1029 if (!strcmp(getvar("et1phyaddr"),"5") && !strcmp(getvar("et1mdcport"), "1"))
1030 return &platforms[WRTSL54GS];
1032 if (!strcmp(boardtype, "0x0472"))
1033 return &platforms[WRT160N];
1035 /* default to WRT54G */
1036 return &platforms[WRT54G];
1038 if (!strcmp(boardnum, "1024") && !strcmp(boardtype, "0x0446"))
1039 return &platforms[WAP54GV2];
1041 if (!strcmp(boardnum, "8") && !strcmp(boardtype, "0x048e"))
1042 return &platforms[WL1600GL];
1045 if (!strcmp(boardnum, "44") || !strcmp(boardnum, "44\r")) {
1046 if (!strcmp(boardtype,"0x0101") || !strcmp(boardtype, "0x0101\r"))
1047 return &platforms[TM2300V2]; /* Dell TrueMobile 2300 v2 */
1050 if (!strcmp(boardnum, "45")) { /* ASUS */
1051 if (!strcmp(boardtype,"0x042f"))
1052 return &platforms[WL500GP];
1053 else if (!strcmp(boardtype,"0x0472"))
1054 return &platforms[WL500W];
1055 else if (!strcmp(boardtype,"0x467"))
1056 return &platforms[WL320GE];
1058 return &platforms[WL500GD];
1061 if (!strcmp(boardnum, "10496"))
1062 return &platforms[USR5461];
1064 if (!strcmp(getvar("boardtype"), "0x0101") && !strcmp(getvar("boardrev"), "0x10")) /* SE505V2 With Modified CFE */
1065 return &platforms[SE505V2];
1067 if (!strcmp(boardtype, "0x048e") && !strcmp(getvar("boardrev"),"0x35") &&
1068 !strcmp(getvar("boardflags"), "0x750")) /* D-Link DIR-320 */
1069 return &platforms[DIR320];
1071 if (!strncmp(boardnum, "TH",2) && !strcmp(boardtype,"0x042f")) {
1072 return &platforms[WDNetCenter];
1075 if (!strcmp(boardtype,"0x0472") && !strcmp(getvar("cardbus"), "1")) { /* Netgear WNR834B V1 and V2*/
1076 if (!strcmp(boardnum, "08") || !strcmp(boardnum, "8"))
1077 return &platforms[WNR834BV1];
1078 if (!strcmp(boardnum, "01") || !strcmp(boardnum, "1"))
1079 return &platforms[WNR834BV2];
1082 } else { /* PMON based - old stuff */
1083 if ((simple_strtoul(getvar("GemtekPmonVer"), NULL, 0) == 9) &&
1084 (simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 30)) {
1085 return &platforms[WR850GV1];
1087 if (startswith(boardtype, "bcm94710dev")) {
1088 if (!strcmp(boardnum, "42"))
1089 return &platforms[WRT54GV1];
1090 if (simple_strtoul(boardnum, NULL, 0) == 2)
1091 return &platforms[WAP54GV1];
1093 /* MN-700 has also hardware_version 'WL500-...', so use boardnum */
1094 if (startswith(getvar("hardware_version"), "WL500-")) {
1095 if (!strcmp(getvar("boardnum"), "mn700"))
1096 return &platforms[MN700];
1098 return &platforms[WL500G];
1100 if (startswith(getvar("hardware_version"), "WL300-")) {
1101 /* Either WL-300g or WL-HDD, do more extensive checks */
1102 if ((simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 0) &&
1103 (simple_strtoul(getvar("et1phyaddr"), NULL, 0) == 1))
1104 return &platforms[WLHDD];
1105 if ((simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 0) &&
1106 (simple_strtoul(getvar("et1phyaddr"), NULL, 0) == 10))
1107 return &platforms[WL300G];
1109 /* Sitecom WL-105b */
1110 if (startswith(boardnum, "2") && simple_strtoul(getvar("GemtekPmonVer"), NULL, 0) == 1)
1111 return &platforms[WL105B];
1113 /* unknown asus stuff, probably bcm4702 */
1114 if (startswith(boardnum, "asusX"))
1115 return &platforms[ASUS_4702];
1117 /* bcm4702 based Askey RT210W clones, Including:
1118 * Askey RT210W (duh?)
1120 * Belkin F5D7230-4 before version v1444 (MiniPCI slot, not integrated)
1122 if (!strcmp(boardtype,"bcm94710r4")
1123 && !strcmp(boardnum ,"100")
1124 && !strcmp(getvar("pmon_ver"),"v1.03.12.bk")
1126 return &platforms[RT210W];
1130 if (buf || !strcmp(boardnum, "00")) {/* probably buffalo */
1131 if (startswith(boardtype, "bcm94710ap"))
1132 return &platforms[BUFFALO_UNKNOWN_4710];
1134 return &platforms[BUFFALO_UNKNOWN];
1137 if (startswith(getvar("CFEver"), "MotoWRv2") ||
1138 startswith(getvar("CFEver"), "MotoWRv3") ||
1139 !strcmp(getvar("MOTO_BOARD_TYPE"), "WR_FEM1")) {
1141 return &platforms[WR850GV2V3];
1144 if (!strcmp(boardnum, "44") && !strcmp(getvar("boardflags"),"0x0388")) { /* Trendware TEW-411BRP+ */
1145 return &platforms[TEW411BRPP];
1148 if (startswith(boardnum, "04FN")) /* SimpleTech SimpleShare */
1149 return &platforms[STI_NAS];
1151 if (!strcmp(boardnum, "10") && !strcmp(getvar("boardrev"), "0x13")) /* D-Link DWL-3150 */
1152 return &platforms[DWL3150];
1154 if (!strcmp(boardnum, "01") && !strcmp(boardtype, "0x048e") && /* Edimax PS1208MFG */
1155 !strcmp(getvar("status_gpio"), "1")) /* gpio based detection */
1156 return &platforms[PS1208MFG];
1162 static void register_buttons(struct button_t *b)
1164 for (; b->name; b++)
1165 platform.button_mask |= b->gpio;
1167 platform.button_mask &= ~gpiomask;
1169 gpio_outen(platform.button_mask, 0);
1170 gpio_control(platform.button_mask, 0);
1171 platform.button_polarity = gpio_in() & platform.button_mask;
1172 gpio_intpolarity(platform.button_mask, platform.button_polarity);
1173 gpio_setintmask(platform.button_mask, platform.button_mask);
1175 gpio_set_irqenable(1, button_handler);
1178 static void unregister_buttons(struct button_t *b)
1180 gpio_setintmask(platform.button_mask, 0);
1182 gpio_set_irqenable(0, button_handler);
1186 static void add_msg(struct event_t *event, char *msg, int argv)
1193 s = skb_put(event->skb, strlen(msg) + 1);
1197 static void hotplug_button(struct work_struct *work)
1199 struct event_t *event = container_of(work, struct event_t, wq);
1202 event->skb = alloc_skb(2048, GFP_KERNEL);
1204 s = skb_put(event->skb, strlen(event->action) + 2);
1205 sprintf(s, "%s@", event->action);
1208 NETLINK_CB(event->skb).dst_group = 1;
1209 broadcast_uevent(event->skb, 0, 1, GFP_KERNEL);
1215 static int fill_event (struct event_t *event)
1217 static char buf[128];
1219 add_msg(event, "HOME=/", 0);
1220 add_msg(event, "PATH=/sbin:/bin:/usr/sbin:/usr/bin", 0);
1221 add_msg(event, "SUBSYSTEM=button", 0);
1222 snprintf(buf, 128, "ACTION=%s", event->action);
1223 add_msg(event, buf, 0);
1224 snprintf(buf, 128, "BUTTON=%s", event->name);
1225 add_msg(event, buf, 0);
1226 snprintf(buf, 128, "SEEN=%ld", event->seen);
1227 add_msg(event, buf, 0);
1228 snprintf(buf, 128, "SEQNUM=%llu", uevent_next_seqnum());
1229 add_msg(event, buf, 0);
1235 static irqreturn_t button_handler(int irq, void *dev_id)
1240 in = gpio_in() & platform.button_mask;
1241 gpio_intpolarity(platform.button_mask, in);
1242 changed = platform.button_polarity ^ in;
1243 platform.button_polarity = in;
1245 changed &= ~gpio_outen(0, 0);
1247 for (b = platform.buttons; b->name; b++) {
1248 struct event_t *event;
1250 if (!(b->gpio & changed)) continue;
1254 if ((event = (struct event_t *)kzalloc (sizeof(struct event_t), GFP_ATOMIC))) {
1255 event->seen = (jiffies - b->seen)/HZ;
1256 event->name = b->name;
1257 event->action = b->pressed ? "pressed" : "released";
1258 INIT_WORK(&event->wq, (void *)(void *)hotplug_button);
1259 schedule_work(&event->wq);
1267 static void register_leds(struct led_t *l)
1269 struct proc_dir_entry *p;
1274 leds = proc_mkdir("led", diag);
1278 for(; l->name; l++) {
1279 if (l->gpio & gpiomask)
1282 if (l->gpio & GPIO_TYPE_EXTIF) {
1286 if (l->polarity != INPUT) oe_mask |= l->gpio;
1288 val |= (l->polarity == NORMAL)?0:l->gpio;
1291 if (l->polarity == INPUT) continue;
1293 if ((p = create_proc_entry(l->name, S_IRUSR, leds))) {
1294 l->proc.type = PROC_LED;
1296 p->data = (void *) &l->proc;
1297 p->proc_fops = &diag_proc_fops;
1301 gpio_outen(mask, oe_mask);
1302 gpio_control(mask, 0);
1303 gpio_out(mask, val);
1304 gpio_setintmask(mask, 0);
1307 static void unregister_leds(struct led_t *l)
1310 remove_proc_entry(l->name, leds);
1312 remove_proc_entry("led", diag);
1315 static void set_led_extif(struct led_t *led)
1317 gpio_set_extif(led->gpio, led->state);
1320 static void led_flash(unsigned long dummy) {
1325 for (l = platform.leds; l->name; l++) {
1327 if (l->gpio & GPIO_TYPE_EXTIF) {
1329 l->state = !l->state;
1339 u32 val = ~gpio_in();
1341 gpio_outen(mask, mask);
1342 gpio_control(mask, 0);
1343 gpio_out(mask, val);
1345 if (mask || extif_blink) {
1346 mod_timer(&led_timer, jiffies + FLASH_TIME);
1350 static ssize_t diag_proc_read(struct file *file, char *buf, size_t count, loff_t *ppos)
1352 struct proc_dir_entry *dent = PDE(file->f_dentry->d_inode);
1356 if ((page = kmalloc(1024, GFP_KERNEL)) == NULL)
1359 if (dent->data != NULL) {
1360 struct prochandler_t *handler = (struct prochandler_t *) dent->data;
1361 switch (handler->type) {
1363 struct led_t * led = (struct led_t *) handler->ptr;
1365 len = sprintf(page, "f\n");
1367 if (led->gpio & GPIO_TYPE_EXTIF) {
1368 len = sprintf(page, "%d\n", led->state);
1370 u32 in = (gpio_in() & led->gpio ? 1 : 0);
1371 u8 p = (led->polarity == NORMAL ? 0 : 1);
1372 len = sprintf(page, "%d\n", ((in ^ p) ? 1 : 0));
1378 len = sprintf(page, "%s\n", platform.name);
1381 len = sprintf(page, "0x%04x\n", gpiomask);
1388 len = min_t(int, len - *ppos, count);
1389 if (copy_to_user(buf, (page + *ppos), len)) {
1403 static ssize_t diag_proc_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
1405 struct proc_dir_entry *dent = PDE(file->f_dentry->d_inode);
1409 if ((page = kmalloc(count + 1, GFP_KERNEL)) == NULL)
1412 if (copy_from_user(page, buf, count)) {
1418 if (dent->data != NULL) {
1419 struct prochandler_t *handler = (struct prochandler_t *) dent->data;
1420 switch (handler->type) {
1422 struct led_t *led = (struct led_t *) handler->ptr;
1423 int p = (led->polarity == NORMAL ? 0 : 1);
1425 if (page[0] == 'f') {
1430 if (led->gpio & GPIO_TYPE_EXTIF) {
1431 led->state = p ^ ((page[0] == '1') ? 1 : 0);
1434 gpio_outen(led->gpio, led->gpio);
1435 gpio_control(led->gpio, 0);
1436 gpio_out(led->gpio, ((p ^ (page[0] == '1')) ? led->gpio : 0));
1442 gpiomask = simple_strtoul(page, NULL, 0);
1444 if (platform.buttons) {
1445 unregister_buttons(platform.buttons);
1446 register_buttons(platform.buttons);
1449 if (platform.leds) {
1450 unregister_leds(platform.leds);
1451 register_leds(platform.leds);
1462 static int __init diag_init(void)
1464 static struct proc_dir_entry *p;
1465 static struct platform_t *detected;
1467 detected = platform_detect();
1469 printk(MODULE_NAME ": Router model not detected.\n");
1472 memcpy(&platform, detected, sizeof(struct platform_t));
1474 printk(MODULE_NAME ": Detected '%s'\n", platform.name);
1475 if (platform.platform_init != NULL) {
1476 platform.platform_init();
1479 if (!(diag = proc_mkdir("diag", NULL))) {
1480 printk(MODULE_NAME ": proc_mkdir on /proc/diag failed\n");
1484 if ((p = create_proc_entry("model", S_IRUSR, diag))) {
1485 p->data = (void *) &proc_model;
1486 p->proc_fops = &diag_proc_fops;
1489 if ((p = create_proc_entry("gpiomask", S_IRUSR | S_IWUSR, diag))) {
1490 p->data = (void *) &proc_gpiomask;
1491 p->proc_fops = &diag_proc_fops;
1494 if (platform.buttons)
1495 register_buttons(platform.buttons);
1498 register_leds(platform.leds);
1503 static void __exit diag_exit(void)
1505 del_timer(&led_timer);
1507 if (platform.buttons)
1508 unregister_buttons(platform.buttons);
1511 unregister_leds(platform.leds);
1513 remove_proc_entry("model", diag);
1514 remove_proc_entry("gpiomask", diag);
1515 remove_proc_entry("diag", NULL);
1518 module_init(diag_init);
1519 module_exit(diag_exit);
1521 MODULE_AUTHOR("Mike Baker, Felix Fietkau / OpenWrt.org");
1522 MODULE_LICENSE("GPL");