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);
130 /* Western Digital */
146 static void __init
bcm4780_init(void) {
149 /* Enables GPIO 3 that controls HDD and led power on ASUS WL-700gE */
150 printk(MODULE_NAME
": Spinning up HDD and enabling leds\n");
151 gpio_outen(pin
, pin
);
152 gpio_control(pin
, 0);
155 /* Wait 5s, so the HDD can spin up */
156 set_current_state(TASK_INTERRUPTIBLE
);
157 schedule_timeout(HZ
* 5);
160 static void __init
NetCenter_init(void) {
161 /* unset pin 6 (+12V) */
163 gpio_outen(pin
, pin
);
164 gpio_control(pin
, 0);
166 /* unset pin 1 (turn off red led, blue will light alone if +5V comes up) */
168 gpio_outen(pin
, pin
);
169 gpio_control(pin
, 0);
171 /* unset pin 3 (+5V) and wait 5 seconds (harddisk spin up) */
175 static void __init
bcm57xx_init(void) {
178 /* FIXME: switch comes up, but port mappings/vlans not right */
179 gpio_outen(pin
, pin
);
180 gpio_control(pin
, 0);
184 static struct platform_t __initdata platforms
[] = {
187 .name
= "Linksys WAP54G V1",
189 { .name
= "reset", .gpio
= 1 << 0 },
192 { .name
= "diag", .gpio
= 1 << 3 },
193 { .name
= "wlan", .gpio
= 1 << 4 },
197 .name
= "Linksys WAP54G V2",
199 { .name
= "reset", .gpio
= 1 << 0 },
202 { .name
= "wlan", .gpio
= 1 << 5, .polarity
= REVERSE
},
203 /* GPIO 6 is b44 (eth0, LAN) PHY power */
207 .name
= "Linksys WAP54G V3",
209 /* FIXME: verify this */
210 { .name
= "reset", .gpio
= 1 << 7 },
211 { .name
= "ses", .gpio
= 1 << 0 },
215 { .name
= "ses", .gpio
= 1 << 1 },
219 .name
= "Linksys WRT54G V1.x",
221 { .name
= "reset", .gpio
= 1 << 6 },
224 { .name
= "diag", .gpio
= 0x13 | GPIO_TYPE_EXTIF
, .polarity
= NORMAL
},
225 { .name
= "dmz", .gpio
= 0x12 | GPIO_TYPE_EXTIF
, .polarity
= NORMAL
},
229 .name
= "Linksys WRT54G/GS/GL",
231 { .name
= "reset", .gpio
= 1 << 6 },
232 { .name
= "ses", .gpio
= 1 << 4 },
235 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
236 { .name
= "dmz", .gpio
= 1 << 7, .polarity
= REVERSE
},
237 { .name
= "ses_white", .gpio
= 1 << 2, .polarity
= REVERSE
},
238 { .name
= "ses_orange", .gpio
= 1 << 3, .polarity
= REVERSE
},
239 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
243 .name
= "Linksys WRTSL54GS",
245 { .name
= "reset", .gpio
= 1 << 6 },
246 { .name
= "ses", .gpio
= 1 << 4 },
249 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
250 { .name
= "dmz", .gpio
= 1 << 0, .polarity
= REVERSE
},
251 { .name
= "ses_white", .gpio
= 1 << 5, .polarity
= REVERSE
},
252 { .name
= "ses_orange", .gpio
= 1 << 7, .polarity
= REVERSE
},
256 .name
= "Linksys WRT54G3G",
258 { .name
= "reset", .gpio
= 1 << 6 },
259 { .name
= "3g", .gpio
= 1 << 4 },
262 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
263 { .name
= "dmz", .gpio
= 1 << 7, .polarity
= REVERSE
},
264 { .name
= "3g_green", .gpio
= 1 << 2, .polarity
= NORMAL
},
265 { .name
= "3g_blue", .gpio
= 1 << 3, .polarity
= NORMAL
},
266 { .name
= "3g_blink", .gpio
= 1 << 5, .polarity
= NORMAL
},
270 .name
= "Linksys WRT54G3GV2-VF",
272 { .name
= "reset", .gpio
= 1 << 6 },
273 { .name
= "3g", .gpio
= 1 << 5 },
276 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
277 { .name
= "3g_green", .gpio
= 1 << 2, .polarity
= NORMAL
},
278 { .name
= "3g_blue", .gpio
= 1 << 3, .polarity
= NORMAL
},
282 .name
= "Linksys WRT160N",
284 { .name
= "reset", .gpio
= 1 << 6 },
285 { .name
= "ses", .gpio
= 1 << 4 },
288 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
289 { .name
= "ses_blue", .gpio
= 1 << 5, .polarity
= REVERSE
},
290 { .name
= "ses_orange", .gpio
= 1 << 3, .polarity
= REVERSE
},
294 .name
= "Linksys WRT300N V1.1",
296 { .name
= "reset", .gpio
= 1 << 6 }, // "Reset" on back panel
297 { .name
= "ses", .gpio
= 1 << 4 }, // "Reserved" on top panel
300 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
}, // "Power"
301 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
}, // "Security" Amber
302 { .name
= "ses_green", .gpio
= 1 << 5, .polarity
= REVERSE
}, // "Security" Green
304 .platform_init
= bcm57xx_init
,
307 .name
= "Linksys WRT350N",
309 { .name
= "reset", .gpio
= 1 << 6 },
310 { .name
= "ses", .gpio
= 1 << 8 },
313 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
314 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
315 { .name
= "ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
},
316 { .name
= "usb_blink", .gpio
= 1 << 10, .polarity
= REVERSE
},
317 { .name
= "usb", .gpio
= 1 << 11, .polarity
= REVERSE
},
319 .platform_init
= bcm57xx_init
,
322 .name
= "Linksys WRT600N",
324 { .name
= "reset", .gpio
= 1 << 6 },
325 { .name
= "ses", .gpio
= 1 << 7 },
328 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
}, // Power LED
329 { .name
= "usb", .gpio
= 1 << 3, .polarity
= REVERSE
}, // USB LED
330 { .name
= "wl0_ses_amber", .gpio
= 1 << 8, .polarity
= REVERSE
}, // 2.4Ghz LED Amber
331 { .name
= "wl0_ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
}, // 2.4Ghz LED Green
332 { .name
= "wl1_ses_amber", .gpio
= 1 << 10, .polarity
= REVERSE
}, // 5.6Ghz LED Amber
333 { .name
= "wl1_ses_green", .gpio
= 1 << 11, .polarity
= REVERSE
}, // 5.6Ghz LED Green
335 .platform_init
= bcm57xx_init
,
338 .name
= "Linksys WRT600N V1.1",
340 { .name
= "reset", .gpio
= 1 << 6 },
341 { .name
= "ses", .gpio
= 1 << 7 },
344 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
}, // Power LED
345 { .name
= "usb", .gpio
= 1 << 3, .polarity
= REVERSE
}, // USB LED
346 { .name
= "wl0_ses_amber", .gpio
= 1 << 8, .polarity
= REVERSE
}, // 2.4Ghz LED Amber
347 { .name
= "wl0_ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
}, // 2.4Ghz LED Green
348 { .name
= "wl1_ses_amber", .gpio
= 1 << 10, .polarity
= REVERSE
}, // 5.6Ghz LED Amber
349 { .name
= "wl1_ses_green", .gpio
= 1 << 11, .polarity
= REVERSE
}, // 5.6Ghz LED Green
351 .platform_init
= bcm57xx_init
,
354 .name
= "Linksys WRT610N",
356 { .name
= "reset", .gpio
= 1 << 6 },
357 { .name
= "ses", .gpio
= 1 << 8 },
360 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
}, // Power LED
361 { .name
= "usb", .gpio
= 1 << 0, .polarity
= REVERSE
}, // USB LED
362 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
}, // WiFi protected setup LED amber
363 { .name
= "ses_blue", .gpio
= 1 << 9, .polarity
= REVERSE
}, // WiFi protected setup LED blue
368 .name
= "ASUS WL-HDD",
370 { .name
= "reset", .gpio
= 1 << 6 },
373 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
374 { .name
= "usb", .gpio
= 1 << 2, .polarity
= REVERSE
},
378 .name
= "ASUS WL-300g",
380 { .name
= "reset", .gpio
= 1 << 6 },
383 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
387 .name
= "ASUS WL-320gE/WL-320gP",
389 { .name
= "reset", .gpio
= 1 << 6 },
392 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
393 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
},
394 { .name
= "link", .gpio
= 1 << 11, .polarity
= REVERSE
},
398 .name
= "ASUS WL-330gE",
400 { .name
= "reset", .gpio
= 1 << 2 },
403 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
407 .name
= "ASUS WL-500g",
409 { .name
= "reset", .gpio
= 1 << 6 },
412 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
416 .name
= "ASUS WL-500g Deluxe",
418 { .name
= "reset", .gpio
= 1 << 6 },
421 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
425 .name
= "ASUS WL-500g Premium",
427 { .name
= "reset", .gpio
= 1 << 0 },
428 { .name
= "ses", .gpio
= 1 << 4 },
431 { .name
= "power", .gpio
= 1 << 1, .polarity
= REVERSE
},
435 .name
= "ASUS WL-500g Premium V2",
437 { .name
= "reset", .gpio
= 1 << 2 },
438 { .name
= "ses", .gpio
= 1 << 3 },
441 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
442 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
446 .name
= "ASUS WL-500W",
448 { .name
= "reset", .gpio
= 1 << 6 },
449 { .name
= "ses", .gpio
= 1 << 7 },
452 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
456 .name
= "ASUS WL-520GC",
458 { .name
= "reset", .gpio
= 1 << 2 },
459 { .name
= "ses", .gpio
= 1 << 3 },
462 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
463 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
467 .name
= "ASUS WL-520gU",
469 { .name
= "reset", .gpio
= 1 << 2 },
470 { .name
= "ses", .gpio
= 1 << 3 },
473 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
474 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
478 .name
= "ASUS (unknown, BCM4702)",
480 { .name
= "reset", .gpio
= 1 << 6 },
483 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
487 .name
= "ASUS WL-700gE",
489 { .name
= "reset", .gpio
= 1 << 7 }, // on back, hardwired, always resets device regardless OS state
490 { .name
= "ses", .gpio
= 1 << 4 }, // on back, actual name ezsetup
491 { .name
= "power", .gpio
= 1 << 0 }, // on front
492 { .name
= "copy", .gpio
= 1 << 6 }, // on front
496 // GPIO that controls power led also enables/disables some essential functions
499 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
}, // actual name power
501 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
503 .platform_init
= bcm4780_init
,
507 .name
= "Buffalo WHR-G54S",
509 { .name
= "reset", .gpio
= 1 << 4 },
510 { .name
= "bridge", .gpio
= 1 << 5 },
511 { .name
= "ses", .gpio
= 1 << 0 },
514 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
515 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
516 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
517 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
518 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
522 .name
= "Buffalo WBR2-G54",
525 { .name
= "reset", .gpio
= 1 << 7 },
528 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
532 .name
= "Buffalo WHR-HP-G54",
534 { .name
= "reset", .gpio
= 1 << 4 },
535 { .name
= "bridge", .gpio
= 1 << 5 },
536 { .name
= "ses", .gpio
= 1 << 0 },
539 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
540 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
541 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
542 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
543 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
547 .name
= "Buffalo WHR-G125",
549 { .name
= "reset", .gpio
= 1 << 4 },
550 { .name
= "bridge", .gpio
= 1 << 5 },
551 { .name
= "ses", .gpio
= 1 << 0 },
554 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
555 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
556 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
557 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
558 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
562 .name
= "Buffalo WHR2-A54G54",
564 { .name
= "reset", .gpio
= 1 << 4 },
567 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
571 .name
= "Buffalo WLA2-G54L",
574 { .name
= "reset", .gpio
= 1 << 7 },
577 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
581 .name
= "Buffalo WZR-G300N",
583 { .name
= "reset", .gpio
= 1 << 4 },
586 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
587 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
588 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
592 .name
= "Buffalo WZR-RS-G54",
594 { .name
= "ses", .gpio
= 1 << 0 },
595 { .name
= "reset", .gpio
= 1 << 4 },
598 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
599 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
600 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
604 .name
= "Buffalo WZR-RS-G54HP",
606 { .name
= "ses", .gpio
= 1 << 0 },
607 { .name
= "reset", .gpio
= 1 << 4 },
610 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
611 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
612 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
615 [BUFFALO_UNKNOWN
] = {
616 .name
= "Buffalo (unknown)",
618 { .name
= "reset", .gpio
= 1 << 7 },
621 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
624 [BUFFALO_UNKNOWN_4710
] = {
625 .name
= "Buffalo (unknown, BCM4710)",
627 { .name
= "reset", .gpio
= 1 << 4 },
630 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
635 .name
= "Siemens SE505 V1",
637 /* No usable buttons */
640 // { .name = "power", .gpio = 1 << 0 .polarity = REVERSE }, // Usable when retrofitting D26 (?)
641 { .name
= "dmz", .gpio
= 1 << 4, .polarity
= REVERSE
}, // actual name WWW
642 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
646 .name
= "Siemens SE505 V2",
648 /* No usable buttons */
651 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
652 { .name
= "dmz", .gpio
= 1 << 0, .polarity
= REVERSE
}, // actual name WWW
653 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
658 .name
= "U.S. Robotics USR5461",
660 /* No usable buttons */
663 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
664 { .name
= "printer", .gpio
= 1 << 1, .polarity
= REVERSE
},
669 .name
= "Dell TrueMobile 2300",
671 { .name
= "reset", .gpio
= 1 << 0 },
674 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
675 { .name
= "power", .gpio
= 1 << 7, .polarity
= REVERSE
},
679 .name
= "Dell TrueMobile 2300 v2",
681 { .name
= "reset", .gpio
= 1 << 0 },
684 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
685 { .name
= "power", .gpio
= 1 << 7, .polarity
= REVERSE
},
690 .name
= "Motorola WE800G",
692 { .name
= "reset", .gpio
= 1 << 0 },
695 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
696 { .name
= "diag", .gpio
= 1 << 2, .polarity
= REVERSE
},
697 { .name
= "wlan_amber", .gpio
= 1 << 1, .polarity
= NORMAL
},
701 .name
= "Motorola WR850G V1",
703 { .name
= "reset", .gpio
= 1 << 0 },
706 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
707 { .name
= "diag", .gpio
= 1 << 3, .polarity
= REVERSE
},
708 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= NORMAL
},
709 { .name
= "wlan_red", .gpio
= 1 << 5, .polarity
= REVERSE
},
710 { .name
= "wlan_green", .gpio
= 1 << 7, .polarity
= REVERSE
},
714 .name
= "Motorola WR850G V2/V3",
716 { .name
= "reset", .gpio
= 1 << 5 },
719 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
720 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
721 { .name
= "wan", .gpio
= 1 << 6, .polarity
= INPUT
},
722 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
726 .name
= "Motorola WR850GP",
728 { .name
= "reset", .gpio
= 1 << 5 },
731 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
732 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
733 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= REVERSE
},
734 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
740 .name
= "Belkin (unknown)",
741 /* FIXME: verify & add detection */
743 { .name
= "reset", .gpio
= 1 << 7 },
746 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
},
747 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= NORMAL
},
748 { .name
= "connected", .gpio
= 1 << 0, .polarity
= NORMAL
},
753 .name
= "Netgear WGT634U",
755 { .name
= "reset", .gpio
= 1 << 2 },
758 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
},
762 .name
= "Netgear WNR834B V2",
764 { .name
= "reset", .gpio
= 1 << 6 },
767 { .name
= "power", .gpio
= 1 << 2, .polarity
= NORMAL
},
768 { .name
= "diag", .gpio
= 1 << 3, .polarity
= NORMAL
},
769 { .name
= "connected", .gpio
= 1 << 7, .polarity
= NORMAL
},
774 .name
= "Trendware TEW411BRP+",
776 { /* No usable buttons */ },
779 { .name
= "power", .gpio
= 1 << 7, .polarity
= NORMAL
},
780 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
},
781 { .name
= "bridge", .gpio
= 1 << 6, .polarity
= NORMAL
},
786 .name
= "SimpleTech SimpleShare NAS",
788 { .name
= "reset", .gpio
= 1 << 0 }, // Power button on back, named reset to enable failsafe.
791 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
793 .platform_init
= bcm4780_init
,
797 .name
= "D-Link DIR-130",
799 { .name
= "reset", .gpio
= 1 << 3},
800 { .name
= "reserved", .gpio
= 1 << 7},
803 { .name
= "diag", .gpio
= 1 << 0},
804 { .name
= "blue", .gpio
= 1 << 6},
808 .name
= "D-Link DIR-320",
810 { .name
= "reserved", .gpio
= 1 << 6},
811 { .name
= "reset", .gpio
= 1 << 7},
814 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
815 { .name
= "diag", .gpio
= 1 << 1, .polarity
= NORMAL
}, /* "status led */
816 { .name
= "red", .gpio
= 1 << 3, .polarity
= REVERSE
},
817 { .name
= "blue", .gpio
= 1 << 4, .polarity
= REVERSE
},
818 { .name
= "usb", .gpio
= 1 << 5, .polarity
= NORMAL
},
822 .name
= "D-Link DIR-330",
824 { .name
= "reset", .gpio
= 1 << 3},
825 { .name
= "reserved", .gpio
= 1 << 7},
828 { .name
= "diag", .gpio
= 1 << 0},
829 { .name
= "usb", .gpio
= 1 << 4},
830 { .name
= "blue", .gpio
= 1 << 6},
834 .name
= "D-Link DWL-3150",
836 { .name
= "reset", .gpio
= 1 << 7},
839 { .name
= "diag", .gpio
= 1 << 2},
840 { .name
= "status", .gpio
= 1 << 1},
845 .name
= "Sitecom WL-105b",
847 { .name
= "reset", .gpio
= 1 << 10},
850 { .name
= "wlan", .gpio
= 1 << 4},
851 { .name
= "power", .gpio
= 1 << 3},
854 /* Western Digital Net Center */
856 .name
= "Western Digital NetCenter",
858 { .name
= "power", .gpio
= 1 << 0},
859 { .name
= "reset", .gpio
= 1 << 7},
861 .platform_init
= NetCenter_init
,
863 /* Askey (and clones) */
865 .name
= "Askey RT210W",
867 /* Power button is hard-wired to hardware reset */
868 /* but is also connected to GPIO 7 (probably for bootloader recovery) */
869 { .name
= "power", .gpio
= 1 << 7},
872 /* These were verified and named based on Belkin F5D4230-4 v1112 */
873 { .name
= "connected", .gpio
= 1 << 0, .polarity
= REVERSE
},
874 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
875 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
879 .name
= "OvisLink WL-1600GL",
881 { .name
= "reset", .gpio
= 1 << 3 },
882 { .name
= "ses", .gpio
= 1 << 4 },
885 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
886 { .name
= "wps", .gpio
= 1 << 2, .polarity
= REVERSE
},
887 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
888 { .name
= "connected", .gpio
= 1 << 0, .polarity
= REVERSE
},
893 .name
= "Microsoft MN-700",
895 { .name
= "reset", .gpio
= 1 << 7 },
898 { .name
= "power", .gpio
= 1 << 6, .polarity
= NORMAL
},
903 .name
= "Edimax PS-1208MFG",
905 { .name
= "reset", .gpio
= 1 << 4 },
908 { .name
= "status", .gpio
= 1 << 1, .polarity
= NORMAL
},
909 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
914 static struct platform_t __init
*platform_detect(void)
916 char *boardnum
, *boardtype
, *buf
;
918 if (strcmp(getvar("nvram_type"), "cfe") == 0)
919 return &platforms
[WGT634U
];
921 /* Look for a model identifier */
923 /* Based on "model_name" */
924 if ((buf
= nvram_get("model_name"))) {
925 if (!strcmp(buf
, "DIR-130"))
926 return &platforms
[DIR130
];
927 if (!strcmp(buf
, "DIR-330"))
928 return &platforms
[DIR330
];
931 /* Based on "wsc_modelname */
932 if ((buf
= nvram_get("wsc_modelname"))) {
933 if (!strcmp(buf
, "WRT610N"))
934 return &platforms
[WRT610N
];
937 /* Based on "model_no" */
938 if ((buf
= nvram_get("model_no"))) {
939 if (startswith(buf
,"WL700")) /* WL700* */
940 return &platforms
[WL700GE
];
943 /* Based on "hardware_version" */
944 if ((buf
= nvram_get("hardware_version"))) {
945 if (startswith(buf
,"WL500GPV2-")) /* WL500GPV2-* */
946 return &platforms
[WL500GPV2
];
947 if (startswith(buf
,"WL520GC-")) /* WL520GU-* */
948 return &platforms
[WL520GC
];
949 if (startswith(buf
,"WL520GU-")) /* WL520GU-* */
950 return &platforms
[WL520GU
];
951 if (startswith(buf
,"WL330GE-")) /* WL330GE-* */
952 return &platforms
[WL330GE
];
955 /* Based on "ModelId" */
956 if ((buf
= nvram_get("ModelId"))) {
957 if (!strcmp(buf
, "WR850GP"))
958 return &platforms
[WR850GP
];
959 if (!strcmp(buf
, "WR850G"))
960 return &platforms
[WR850GV2V3
];
961 if (!strcmp(buf
, "WX-5565") && !strcmp(getvar("boardtype"),"bcm94710ap"))
962 return &platforms
[TM2300
]; /* Dell TrueMobile 2300 */
963 if (startswith(buf
,"WE800G")) /* WE800G* */
964 return &platforms
[WE800G
];
968 if ((buf
= (nvram_get("melco_id") ?: nvram_get("buffalo_id")))) {
969 /* Buffalo hardware, check id for specific hardware matches */
970 if (!strcmp(buf
, "29bb0332"))
971 return &platforms
[WBR2_G54
];
972 if (!strcmp(buf
, "29129"))
973 return &platforms
[WLA2_G54L
];
974 if (!strcmp(buf
, "30189"))
975 return &platforms
[WHR_HP_G54
];
976 if (!strcmp(buf
, "32093"))
977 return &platforms
[WHR_G125
];
978 if (!strcmp(buf
, "30182"))
979 return &platforms
[WHR_G54S
];
980 if (!strcmp(buf
, "290441dd"))
981 return &platforms
[WHR2_A54G54
];
982 if (!strcmp(buf
, "31120"))
983 return &platforms
[WZR_G300N
];
984 if (!strcmp(buf
, "30083"))
985 return &platforms
[WZR_RS_G54
];
986 if (!strcmp(buf
, "30103"))
987 return &platforms
[WZR_RS_G54HP
];
990 /* no easy model number, attempt to guess */
991 boardnum
= getvar("boardnum");
992 boardtype
= getvar("boardtype");
994 if (!strcmp(boardnum
, "20070615")) { /* Linksys WRT600N v1/V1.1 */
995 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "0") && !strcmp(getvar("switch_type"),"BCM5395"))
996 return &platforms
[WRT600NV11
];
998 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "0"))
999 return &platforms
[WRT600N
];
1002 if (startswith(getvar("pmon_ver"), "CFE")) {
1003 /* CFE based - newer hardware */
1004 if (!strcmp(boardnum
, "42")) { /* Linksys */
1005 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("boot_hw_model"), "WRT300N") && !strcmp(getvar("boot_hw_ver"), "1.1"))
1006 return &platforms
[WRT300NV11
];
1008 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "1"))
1009 return &platforms
[WRT350N
];
1011 if (!strcmp(boardtype
, "0x0101") && !strcmp(getvar("boot_ver"), "v3.6"))
1012 return &platforms
[WRT54G3G
];
1014 if (!strcmp(boardtype
, "0x042f") && !strcmp(getvar("model_name"), "WRT54G3GV2-VF"))
1015 return &platforms
[WRT54G3GV2_VF
];
1017 if (!strcmp(getvar("et1phyaddr"),"5") && !strcmp(getvar("et1mdcport"), "1"))
1018 return &platforms
[WRTSL54GS
];
1020 if (!strcmp(boardtype
, "0x0472"))
1021 return &platforms
[WRT160N
];
1023 /* default to WRT54G */
1024 return &platforms
[WRT54G
];
1026 if (!strcmp(boardnum
, "1024") && !strcmp(boardtype
, "0x0446"))
1027 return &platforms
[WAP54GV2
];
1029 if (!strcmp(boardnum
, "8") && !strcmp(boardtype
, "0x048e"))
1030 return &platforms
[WL1600GL
];
1033 if (!strcmp(boardnum
, "44") || !strcmp(boardnum
, "44\r")) {
1034 if (!strcmp(boardtype
,"0x0101") || !strcmp(boardtype
, "0x0101\r"))
1035 return &platforms
[TM2300V2
]; /* Dell TrueMobile 2300 v2 */
1038 if (!strcmp(boardnum
, "45")) { /* ASUS */
1039 if (!strcmp(boardtype
,"0x042f"))
1040 return &platforms
[WL500GP
];
1041 else if (!strcmp(boardtype
,"0x0472"))
1042 return &platforms
[WL500W
];
1043 else if (!strcmp(boardtype
,"0x467"))
1044 return &platforms
[WL320GE
];
1046 return &platforms
[WL500GD
];
1049 if (!strcmp(boardnum
, "10496"))
1050 return &platforms
[USR5461
];
1052 if (!strcmp(getvar("boardtype"), "0x0101") && !strcmp(getvar("boardrev"), "0x10")) /* SE505V2 With Modified CFE */
1053 return &platforms
[SE505V2
];
1055 if (!strcmp(boardtype
, "0x048e") && !strcmp(getvar("boardrev"),"0x35") &&
1056 !strcmp(getvar("boardflags"), "0x750")) /* D-Link DIR-320 */
1057 return &platforms
[DIR320
];
1059 if (!strncmp(boardnum
, "TH",2) && !strcmp(boardtype
,"0x042f")) {
1060 return &platforms
[WDNetCenter
];
1063 if ((!strcmp(boardnum
, "08") || !strcmp(boardnum
, "01")) &&
1064 !strcmp(boardtype
,"0x0472") && !strcmp(getvar("cardbus"), "1")) { /* Netgear WNR834B V1 and V2*/
1065 /* TODO: Check for version. Default platform is V2 for now. */
1066 return &platforms
[WNR834BV2
];
1069 } else { /* PMON based - old stuff */
1070 if ((simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 9) &&
1071 (simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 30)) {
1072 return &platforms
[WR850GV1
];
1074 if (startswith(boardtype
, "bcm94710dev")) {
1075 if (!strcmp(boardnum
, "42"))
1076 return &platforms
[WRT54GV1
];
1077 if (simple_strtoul(boardnum
, NULL
, 0) == 2)
1078 return &platforms
[WAP54GV1
];
1080 /* MN-700 has also hardware_version 'WL500-...', so use boardnum */
1081 if (startswith(getvar("hardware_version"), "WL500-")) {
1082 if (!strcmp(getvar("boardnum"), "mn700"))
1083 return &platforms
[MN700
];
1085 return &platforms
[WL500G
];
1087 if (startswith(getvar("hardware_version"), "WL300-")) {
1088 /* Either WL-300g or WL-HDD, do more extensive checks */
1089 if ((simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 0) &&
1090 (simple_strtoul(getvar("et1phyaddr"), NULL
, 0) == 1))
1091 return &platforms
[WLHDD
];
1092 if ((simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 0) &&
1093 (simple_strtoul(getvar("et1phyaddr"), NULL
, 0) == 10))
1094 return &platforms
[WL300G
];
1096 /* Sitecom WL-105b */
1097 if (startswith(boardnum
, "2") && simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 1)
1098 return &platforms
[WL105B
];
1100 /* unknown asus stuff, probably bcm4702 */
1101 if (startswith(boardnum
, "asusX"))
1102 return &platforms
[ASUS_4702
];
1104 /* bcm4702 based Askey RT210W clones, Including:
1105 * Askey RT210W (duh?)
1107 * Belkin F5D7230-4 before version v1444 (MiniPCI slot, not integrated)
1109 if (!strcmp(boardtype
,"bcm94710r4")
1110 && !strcmp(boardnum
,"100")
1111 && !strcmp(getvar("pmon_ver"),"v1.03.12.bk")
1113 return &platforms
[RT210W
];
1117 if (buf
|| !strcmp(boardnum
, "00")) {/* probably buffalo */
1118 if (startswith(boardtype
, "bcm94710ap"))
1119 return &platforms
[BUFFALO_UNKNOWN_4710
];
1121 return &platforms
[BUFFALO_UNKNOWN
];
1124 if (startswith(getvar("CFEver"), "MotoWRv2") ||
1125 startswith(getvar("CFEver"), "MotoWRv3") ||
1126 !strcmp(getvar("MOTO_BOARD_TYPE"), "WR_FEM1")) {
1128 return &platforms
[WR850GV2V3
];
1131 if (!strcmp(boardnum
, "44") && !strcmp(getvar("boardflags"),"0x0388")) { /* Trendware TEW-411BRP+ */
1132 return &platforms
[TEW411BRPP
];
1135 if (startswith(boardnum
, "04FN")) /* SimpleTech SimpleShare */
1136 return &platforms
[STI_NAS
];
1138 if (!strcmp(boardnum
, "10") && !strcmp(getvar("boardrev"), "0x13")) /* D-Link DWL-3150 */
1139 return &platforms
[DWL3150
];
1141 if (!strcmp(boardnum
, "01") && !strcmp(boardtype
, "0x048e") && /* Edimax PS1208MFG */
1142 !strcmp(getvar("status_gpio"), "1")) /* gpio based detection */
1143 return &platforms
[PS1208MFG
];
1149 static void register_buttons(struct button_t
*b
)
1151 for (; b
->name
; b
++)
1152 platform
.button_mask
|= b
->gpio
;
1154 platform
.button_mask
&= ~gpiomask
;
1156 gpio_outen(platform
.button_mask
, 0);
1157 gpio_control(platform
.button_mask
, 0);
1158 platform
.button_polarity
= gpio_in() & platform
.button_mask
;
1159 gpio_intpolarity(platform
.button_mask
, platform
.button_polarity
);
1160 gpio_setintmask(platform
.button_mask
, platform
.button_mask
);
1162 gpio_set_irqenable(1, button_handler
);
1165 static void unregister_buttons(struct button_t
*b
)
1167 gpio_setintmask(platform
.button_mask
, 0);
1169 gpio_set_irqenable(0, button_handler
);
1173 static void add_msg(struct event_t
*event
, char *msg
, int argv
)
1180 s
= skb_put(event
->skb
, strlen(msg
) + 1);
1184 static void hotplug_button(struct work_struct
*work
)
1186 struct event_t
*event
= container_of(work
, struct event_t
, wq
);
1189 event
->skb
= alloc_skb(2048, GFP_KERNEL
);
1191 s
= skb_put(event
->skb
, strlen(event
->action
) + 2);
1192 sprintf(s
, "%s@", event
->action
);
1195 NETLINK_CB(event
->skb
).dst_group
= 1;
1196 broadcast_uevent(event
->skb
, 0, 1, GFP_KERNEL
);
1202 static int fill_event (struct event_t
*event
)
1204 static char buf
[128];
1206 add_msg(event
, "HOME=/", 0);
1207 add_msg(event
, "PATH=/sbin:/bin:/usr/sbin:/usr/bin", 0);
1208 add_msg(event
, "SUBSYSTEM=button", 0);
1209 snprintf(buf
, 128, "ACTION=%s", event
->action
);
1210 add_msg(event
, buf
, 0);
1211 snprintf(buf
, 128, "BUTTON=%s", event
->name
);
1212 add_msg(event
, buf
, 0);
1213 snprintf(buf
, 128, "SEEN=%ld", event
->seen
);
1214 add_msg(event
, buf
, 0);
1215 snprintf(buf
, 128, "SEQNUM=%llu", uevent_next_seqnum());
1216 add_msg(event
, buf
, 0);
1222 static irqreturn_t
button_handler(int irq
, void *dev_id
)
1227 in
= gpio_in() & platform
.button_mask
;
1228 gpio_intpolarity(platform
.button_mask
, in
);
1229 changed
= platform
.button_polarity
^ in
;
1230 platform
.button_polarity
= in
;
1232 changed
&= ~gpio_outen(0, 0);
1234 for (b
= platform
.buttons
; b
->name
; b
++) {
1235 struct event_t
*event
;
1237 if (!(b
->gpio
& changed
)) continue;
1241 if ((event
= (struct event_t
*)kzalloc (sizeof(struct event_t
), GFP_ATOMIC
))) {
1242 event
->seen
= (jiffies
- b
->seen
)/HZ
;
1243 event
->name
= b
->name
;
1244 event
->action
= b
->pressed
? "pressed" : "released";
1245 INIT_WORK(&event
->wq
, (void *)(void *)hotplug_button
);
1246 schedule_work(&event
->wq
);
1254 static void register_leds(struct led_t
*l
)
1256 struct proc_dir_entry
*p
;
1261 leds
= proc_mkdir("led", diag
);
1265 for(; l
->name
; l
++) {
1266 if (l
->gpio
& gpiomask
)
1269 if (l
->gpio
& GPIO_TYPE_EXTIF
) {
1273 if (l
->polarity
!= INPUT
) oe_mask
|= l
->gpio
;
1275 val
|= (l
->polarity
== NORMAL
)?0:l
->gpio
;
1278 if (l
->polarity
== INPUT
) continue;
1280 if ((p
= create_proc_entry(l
->name
, S_IRUSR
, leds
))) {
1281 l
->proc
.type
= PROC_LED
;
1283 p
->data
= (void *) &l
->proc
;
1284 p
->proc_fops
= &diag_proc_fops
;
1288 gpio_outen(mask
, oe_mask
);
1289 gpio_control(mask
, 0);
1290 gpio_out(mask
, val
);
1291 gpio_setintmask(mask
, 0);
1294 static void unregister_leds(struct led_t
*l
)
1297 remove_proc_entry(l
->name
, leds
);
1299 remove_proc_entry("led", diag
);
1302 static void set_led_extif(struct led_t
*led
)
1304 gpio_set_extif(led
->gpio
, led
->state
);
1307 static void led_flash(unsigned long dummy
) {
1312 for (l
= platform
.leds
; l
->name
; l
++) {
1314 if (l
->gpio
& GPIO_TYPE_EXTIF
) {
1316 l
->state
= !l
->state
;
1326 u32 val
= ~gpio_in();
1328 gpio_outen(mask
, mask
);
1329 gpio_control(mask
, 0);
1330 gpio_out(mask
, val
);
1332 if (mask
|| extif_blink
) {
1333 mod_timer(&led_timer
, jiffies
+ FLASH_TIME
);
1337 static ssize_t
diag_proc_read(struct file
*file
, char *buf
, size_t count
, loff_t
*ppos
)
1339 struct proc_dir_entry
*dent
= PDE(file
->f_dentry
->d_inode
);
1343 if ((page
= kmalloc(1024, GFP_KERNEL
)) == NULL
)
1346 if (dent
->data
!= NULL
) {
1347 struct prochandler_t
*handler
= (struct prochandler_t
*) dent
->data
;
1348 switch (handler
->type
) {
1350 struct led_t
* led
= (struct led_t
*) handler
->ptr
;
1352 len
= sprintf(page
, "f\n");
1354 if (led
->gpio
& GPIO_TYPE_EXTIF
) {
1355 len
= sprintf(page
, "%d\n", led
->state
);
1357 u32 in
= (gpio_in() & led
->gpio
? 1 : 0);
1358 u8 p
= (led
->polarity
== NORMAL
? 0 : 1);
1359 len
= sprintf(page
, "%d\n", ((in
^ p
) ? 1 : 0));
1365 len
= sprintf(page
, "%s\n", platform
.name
);
1368 len
= sprintf(page
, "0x%04x\n", gpiomask
);
1375 len
= min_t(int, len
- *ppos
, count
);
1376 if (copy_to_user(buf
, (page
+ *ppos
), len
)) {
1390 static ssize_t
diag_proc_write(struct file
*file
, const char *buf
, size_t count
, loff_t
*ppos
)
1392 struct proc_dir_entry
*dent
= PDE(file
->f_dentry
->d_inode
);
1396 if ((page
= kmalloc(count
+ 1, GFP_KERNEL
)) == NULL
)
1399 if (copy_from_user(page
, buf
, count
)) {
1405 if (dent
->data
!= NULL
) {
1406 struct prochandler_t
*handler
= (struct prochandler_t
*) dent
->data
;
1407 switch (handler
->type
) {
1409 struct led_t
*led
= (struct led_t
*) handler
->ptr
;
1410 int p
= (led
->polarity
== NORMAL
? 0 : 1);
1412 if (page
[0] == 'f') {
1417 if (led
->gpio
& GPIO_TYPE_EXTIF
) {
1418 led
->state
= p
^ ((page
[0] == '1') ? 1 : 0);
1421 gpio_outen(led
->gpio
, led
->gpio
);
1422 gpio_control(led
->gpio
, 0);
1423 gpio_out(led
->gpio
, ((p
^ (page
[0] == '1')) ? led
->gpio
: 0));
1429 gpiomask
= simple_strtoul(page
, NULL
, 0);
1431 if (platform
.buttons
) {
1432 unregister_buttons(platform
.buttons
);
1433 register_buttons(platform
.buttons
);
1436 if (platform
.leds
) {
1437 unregister_leds(platform
.leds
);
1438 register_leds(platform
.leds
);
1449 static int __init
diag_init(void)
1451 static struct proc_dir_entry
*p
;
1452 static struct platform_t
*detected
;
1454 detected
= platform_detect();
1456 printk(MODULE_NAME
": Router model not detected.\n");
1459 memcpy(&platform
, detected
, sizeof(struct platform_t
));
1461 printk(MODULE_NAME
": Detected '%s'\n", platform
.name
);
1462 if (platform
.platform_init
!= NULL
) {
1463 platform
.platform_init();
1466 if (!(diag
= proc_mkdir("diag", NULL
))) {
1467 printk(MODULE_NAME
": proc_mkdir on /proc/diag failed\n");
1471 if ((p
= create_proc_entry("model", S_IRUSR
, diag
))) {
1472 p
->data
= (void *) &proc_model
;
1473 p
->proc_fops
= &diag_proc_fops
;
1476 if ((p
= create_proc_entry("gpiomask", S_IRUSR
| S_IWUSR
, diag
))) {
1477 p
->data
= (void *) &proc_gpiomask
;
1478 p
->proc_fops
= &diag_proc_fops
;
1481 if (platform
.buttons
)
1482 register_buttons(platform
.buttons
);
1485 register_leds(platform
.leds
);
1490 static void __exit
diag_exit(void)
1492 del_timer(&led_timer
);
1494 if (platform
.buttons
)
1495 unregister_buttons(platform
.buttons
);
1498 unregister_leds(platform
.leds
);
1500 remove_proc_entry("model", diag
);
1501 remove_proc_entry("gpiomask", diag
);
1502 remove_proc_entry("diag", NULL
);
1505 module_init(diag_init
);
1506 module_exit(diag_exit
);
1508 MODULE_AUTHOR("Mike Baker, Felix Fietkau / OpenWrt.org");
1509 MODULE_LICENSE("GPL");