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>
32 #include <linux/workqueue.h>
33 #include <linux/skbuff.h>
34 #include <linux/netlink.h>
36 extern struct sock
*uevent_sock
;
37 extern u64
uevent_next_seqnum(void);
39 #include <linux/tqueue.h>
40 #define INIT_WORK INIT_TQUEUE
41 #define schedule_work schedule_task
42 #define work_struct tq_struct
47 #define getvar(str) (nvram_get(str)?:"")
49 static inline int startswith (char *source
, char *cmp
) { return !strncmp(source
,cmp
,strlen(cmp
)); }
50 static int fill_event(struct event_t
*);
51 static unsigned int gpiomask
= 0;
52 module_param(gpiomask
, int, 0644);
135 static void __init
bcm4780_init(void) {
138 /* Enables GPIO 3 that controls HDD and led power on ASUS WL-700gE */
139 printk(MODULE_NAME
": Spinning up HDD and enabling leds\n");
140 gpio_outen(pin
, pin
);
141 gpio_control(pin
, 0);
144 /* Wait 5s, so the HDD can spin up */
145 set_current_state(TASK_INTERRUPTIBLE
);
146 schedule_timeout(HZ
* 5);
149 static void __init
bcm57xx_init(void) {
153 /* FIXME: switch comes up, but port mappings/vlans not right */
154 gpio_outen(pin
, pin
);
155 gpio_control(pin
, 0);
160 static struct platform_t __initdata platforms
[] = {
163 .name
= "Linksys WAP54G V1",
165 { .name
= "reset", .gpio
= 1 << 0 },
168 { .name
= "diag", .gpio
= 1 << 3 },
169 { .name
= "wlan", .gpio
= 1 << 4 },
173 .name
= "Linksys WAP54G V2",
175 { .name
= "reset", .gpio
= 1 << 0 },
178 { .name
= "wlan", .gpio
= 1 << 5, .polarity
= REVERSE
},
179 /* GPIO 6 is b44 (eth0, LAN) PHY power */
183 .name
= "Linksys WAP54G V3",
185 /* FIXME: verify this */
186 { .name
= "reset", .gpio
= 1 << 7 },
187 { .name
= "ses", .gpio
= 1 << 0 },
191 { .name
= "ses", .gpio
= 1 << 1 },
195 .name
= "Linksys WRT54G V1.x",
197 { .name
= "reset", .gpio
= 1 << 6 },
200 { .name
= "diag", .gpio
= 0x13 | GPIO_TYPE_EXTIF
, .polarity
= NORMAL
},
201 { .name
= "dmz", .gpio
= 0x12 | GPIO_TYPE_EXTIF
, .polarity
= NORMAL
},
205 .name
= "Linksys WRT54G/GS/GL",
207 { .name
= "reset", .gpio
= 1 << 6 },
208 { .name
= "ses", .gpio
= 1 << 4 },
211 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
212 { .name
= "dmz", .gpio
= 1 << 7, .polarity
= REVERSE
},
213 { .name
= "ses_white", .gpio
= 1 << 2, .polarity
= REVERSE
},
214 { .name
= "ses_orange", .gpio
= 1 << 3, .polarity
= REVERSE
},
215 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
219 .name
= "Linksys WRTSL54GS",
221 { .name
= "reset", .gpio
= 1 << 6 },
222 { .name
= "ses", .gpio
= 1 << 4 },
225 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
226 { .name
= "dmz", .gpio
= 1 << 0, .polarity
= REVERSE
},
227 { .name
= "ses_white", .gpio
= 1 << 5, .polarity
= REVERSE
},
228 { .name
= "ses_orange", .gpio
= 1 << 7, .polarity
= REVERSE
},
232 .name
= "Linksys WRT54G3G",
234 { .name
= "reset", .gpio
= 1 << 6 },
235 { .name
= "3g", .gpio
= 1 << 4 },
238 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
239 { .name
= "dmz", .gpio
= 1 << 7, .polarity
= REVERSE
},
240 { .name
= "3g_green", .gpio
= 1 << 2, .polarity
= NORMAL
},
241 { .name
= "3g_blue", .gpio
= 1 << 3, .polarity
= NORMAL
},
242 { .name
= "3g_blink", .gpio
= 1 << 5, .polarity
= NORMAL
},
246 .name
= "Linksys WRT160N",
248 { .name
= "reset", .gpio
= 1 << 6 },
249 { .name
= "ses", .gpio
= 1 << 4 },
252 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
253 { .name
= "ses_blue", .gpio
= 1 << 5, .polarity
= REVERSE
},
254 { .name
= "ses_orange", .gpio
= 1 << 3, .polarity
= REVERSE
},
258 .name
= "Linksys WRT350N",
260 { .name
= "reset", .gpio
= 1 << 6 },
261 { .name
= "ses", .gpio
= 1 << 8 },
264 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
265 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
266 { .name
= "ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
},
267 { .name
= "usb_blink", .gpio
= 1 << 10, .polarity
= REVERSE
},
268 { .name
= "usb", .gpio
= 1 << 11, .polarity
= REVERSE
},
270 .platform_init
= bcm57xx_init
,
273 .name
= "Linksys WRT600N",
275 { .name
= "reset", .gpio
= 1 << 6 },
276 { .name
= "ses", .gpio
= 1 << 7 },
279 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
}, // Power LED
280 { .name
= "usb", .gpio
= 1 << 3, .polarity
= REVERSE
}, // USB LED
281 { .name
= "wl0_ses_amber", .gpio
= 1 << 8, .polarity
= REVERSE
}, // 2.4Ghz LED Amber
282 { .name
= "wl0_ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
}, // 2.4Ghz LED Green
283 { .name
= "wl1_ses_amber", .gpio
= 1 << 10, .polarity
= REVERSE
}, // 5.6Ghz LED Amber
284 { .name
= "wl1_ses_green", .gpio
= 1 << 11, .polarity
= REVERSE
}, // 5.6Ghz LED Green
286 .platform_init
= bcm57xx_init
,
289 .name
= "Linksys WRT600N V1.1",
291 { .name
= "reset", .gpio
= 1 << 6 },
292 { .name
= "ses", .gpio
= 1 << 7 },
295 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
}, // Power LED
296 { .name
= "usb", .gpio
= 1 << 3, .polarity
= REVERSE
}, // USB LED
297 { .name
= "wl0_ses_amber", .gpio
= 1 << 8, .polarity
= REVERSE
}, // 2.4Ghz LED Amber
298 { .name
= "wl0_ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
}, // 2.4Ghz LED Green
299 { .name
= "wl1_ses_amber", .gpio
= 1 << 10, .polarity
= REVERSE
}, // 5.6Ghz LED Amber
300 { .name
= "wl1_ses_green", .gpio
= 1 << 11, .polarity
= REVERSE
}, // 5.6Ghz LED Green
302 .platform_init
= bcm57xx_init
,
306 .name
= "ASUS WL-HDD",
308 { .name
= "reset", .gpio
= 1 << 6 },
311 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
312 { .name
= "usb", .gpio
= 1 << 2, .polarity
= NORMAL
},
316 .name
= "ASUS WL-300g",
318 { .name
= "reset", .gpio
= 1 << 6 },
321 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
325 .name
= "ASUS WL-320gE/WL-320gP",
327 { .name
= "reset", .gpio
= 1 << 6 },
330 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
331 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
},
332 { .name
= "link", .gpio
= 1 << 11, .polarity
= REVERSE
},
336 .name
= "ASUS WL-330gE",
338 { .name
= "reset", .gpio
= 1 << 2 },
341 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
345 .name
= "ASUS WL-500g",
347 { .name
= "reset", .gpio
= 1 << 6 },
350 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
354 .name
= "ASUS WL-500g Deluxe",
356 { .name
= "reset", .gpio
= 1 << 6 },
359 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
363 .name
= "ASUS WL-500g Premium",
365 { .name
= "reset", .gpio
= 1 << 0 },
366 { .name
= "ses", .gpio
= 1 << 4 },
369 { .name
= "power", .gpio
= 1 << 1, .polarity
= REVERSE
},
373 .name
= "ASUS WL-500g Premium V2",
375 { .name
= "reset", .gpio
= 1 << 2 },
376 { .name
= "ses", .gpio
= 1 << 3 },
379 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
380 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
384 .name
= "ASUS WL-500W",
386 { .name
= "reset", .gpio
= 1 << 6 },
387 { .name
= "ses", .gpio
= 1 << 7 },
390 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
394 .name
= "ASUS WL-520GC",
396 { .name
= "reset", .gpio
= 1 << 2 },
397 { .name
= "ses", .gpio
= 1 << 3 },
400 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
401 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
405 .name
= "ASUS WL-520gU",
407 { .name
= "reset", .gpio
= 1 << 2 },
408 { .name
= "ses", .gpio
= 1 << 3 },
411 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
412 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
416 .name
= "ASUS (unknown, BCM4702)",
418 { .name
= "reset", .gpio
= 1 << 6 },
421 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
425 .name
= "ASUS WL-700gE",
427 { .name
= "reset", .gpio
= 1 << 7 }, // on back, hardwired, always resets device regardless OS state
428 { .name
= "ses", .gpio
= 1 << 4 }, // on back, actual name ezsetup
429 { .name
= "power", .gpio
= 1 << 0 }, // on front
430 { .name
= "copy", .gpio
= 1 << 6 }, // on front
434 // GPIO that controls power led also enables/disables some essential functions
437 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
}, // actual name power
439 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
441 .platform_init
= bcm4780_init
,
445 .name
= "Buffalo WHR-G54S",
447 { .name
= "reset", .gpio
= 1 << 4 },
448 { .name
= "bridge", .gpio
= 1 << 5 },
449 { .name
= "ses", .gpio
= 1 << 0 },
452 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
453 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
454 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
455 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
456 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
460 .name
= "Buffalo WBR2-G54",
463 { .name
= "reset", .gpio
= 1 << 7 },
466 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
470 .name
= "Buffalo WHR-HP-G54",
472 { .name
= "reset", .gpio
= 1 << 4 },
473 { .name
= "bridge", .gpio
= 1 << 5 },
474 { .name
= "ses", .gpio
= 1 << 0 },
477 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
478 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
479 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
480 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
481 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
485 .name
= "Buffalo WHR-G125",
487 { .name
= "reset", .gpio
= 1 << 4 },
488 { .name
= "bridge", .gpio
= 1 << 5 },
489 { .name
= "ses", .gpio
= 1 << 0 },
492 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
493 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
494 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
495 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
496 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
500 .name
= "Buffalo WHR2-A54G54",
502 { .name
= "reset", .gpio
= 1 << 4 },
505 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
509 .name
= "Buffalo WLA2-G54L",
512 { .name
= "reset", .gpio
= 1 << 7 },
515 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
519 .name
= "Buffalo WZR-G300N",
521 { .name
= "reset", .gpio
= 1 << 4 },
524 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
525 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
526 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
530 .name
= "Buffalo WZR-RS-G54",
532 { .name
= "ses", .gpio
= 1 << 0 },
533 { .name
= "reset", .gpio
= 1 << 4 },
536 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
537 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
538 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
542 .name
= "Buffalo WZR-RS-G54HP",
544 { .name
= "ses", .gpio
= 1 << 0 },
545 { .name
= "reset", .gpio
= 1 << 4 },
548 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
549 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
550 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
553 [BUFFALO_UNKNOWN
] = {
554 .name
= "Buffalo (unknown)",
556 { .name
= "reset", .gpio
= 1 << 7 },
559 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
562 [BUFFALO_UNKNOWN_4710
] = {
563 .name
= "Buffalo (unknown, BCM4710)",
565 { .name
= "reset", .gpio
= 1 << 4 },
568 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
573 .name
= "Siemens SE505 V1",
575 /* No usable buttons */
578 // { .name = "power", .gpio = 1 << 0 .polarity = REVERSE }, // Usable when retrofitting D26 (?)
579 { .name
= "dmz", .gpio
= 1 << 4, .polarity
= REVERSE
}, // actual name WWW
580 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
584 .name
= "Siemens SE505 V2",
586 /* No usable buttons */
589 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
590 { .name
= "dmz", .gpio
= 1 << 0, .polarity
= REVERSE
}, // actual name WWW
591 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
596 .name
= "U.S. Robotics USR5461",
598 /* No usable buttons */
601 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
602 { .name
= "printer", .gpio
= 1 << 1, .polarity
= REVERSE
},
607 .name
= "Dell TrueMobile 2300",
609 { .name
= "reset", .gpio
= 1 << 0 },
612 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
613 { .name
= "power", .gpio
= 1 << 7, .polarity
= REVERSE
},
617 .name
= "Dell TrueMobile 2300 v2",
619 { .name
= "reset", .gpio
= 1 << 0 },
622 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
623 { .name
= "power", .gpio
= 1 << 7, .polarity
= REVERSE
},
628 .name
= "Motorola WE800G",
630 { .name
= "reset", .gpio
= 1 << 0 },
633 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
634 { .name
= "diag", .gpio
= 1 << 2, .polarity
= REVERSE
},
635 { .name
= "wlan_amber", .gpio
= 1 << 1, .polarity
= NORMAL
},
639 .name
= "Motorola WR850G V1",
641 { .name
= "reset", .gpio
= 1 << 0 },
644 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
645 { .name
= "diag", .gpio
= 1 << 3, .polarity
= REVERSE
},
646 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= NORMAL
},
647 { .name
= "wlan_red", .gpio
= 1 << 5, .polarity
= REVERSE
},
648 { .name
= "wlan_green", .gpio
= 1 << 7, .polarity
= REVERSE
},
652 .name
= "Motorola WR850G V2/V3",
654 { .name
= "reset", .gpio
= 1 << 5 },
657 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
658 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
659 { .name
= "wan", .gpio
= 1 << 6, .polarity
= INPUT
},
660 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
664 .name
= "Motorola WR850GP",
666 { .name
= "reset", .gpio
= 1 << 5 },
669 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
670 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
671 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= REVERSE
},
672 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
678 .name
= "Belkin (unknown)",
679 /* FIXME: verify & add detection */
681 { .name
= "reset", .gpio
= 1 << 7 },
684 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
},
685 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= NORMAL
},
686 { .name
= "connected", .gpio
= 1 << 0, .polarity
= NORMAL
},
691 .name
= "Netgear WGT634U",
693 { .name
= "reset", .gpio
= 1 << 2 },
696 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
},
701 .name
= "Trendware TEW411BRP+",
703 { /* No usable buttons */ },
706 { .name
= "power", .gpio
= 1 << 7, .polarity
= NORMAL
},
707 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
},
708 { .name
= "bridge", .gpio
= 1 << 6, .polarity
= NORMAL
},
713 .name
= "SimpleTech SimpleShare NAS",
715 { .name
= "reset", .gpio
= 1 << 7 }, // on back, hardwired, always resets device regardless OS state
716 { .name
= "power", .gpio
= 1 << 0 }, // on back
719 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
721 .platform_init
= bcm4780_init
,
725 .name
= "D-Link DIR-130",
727 { .name
= "reset", .gpio
= 1 << 3},
728 { .name
= "reserved", .gpio
= 1 << 7},
731 { .name
= "diag", .gpio
= 1 << 0},
732 { .name
= "blue", .gpio
= 1 << 6},
736 .name
= "D-Link DIR-320",
738 { .name
= "reserved", .gpio
= 1 << 6},
739 { .name
= "reset", .gpio
= 1 << 7},
742 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
743 { .name
= "diag", .gpio
= 1 << 1, .polarity
= NORMAL
}, /* "status led */
744 { .name
= "red", .gpio
= 1 << 3, .polarity
= REVERSE
},
745 { .name
= "blue", .gpio
= 1 << 4, .polarity
= REVERSE
},
746 { .name
= "usb", .gpio
= 1 << 5, .polarity
= NORMAL
},
750 .name
= "D-Link DIR-330",
752 { .name
= "reset", .gpio
= 1 << 3},
753 { .name
= "reserved", .gpio
= 1 << 7},
756 { .name
= "diag", .gpio
= 1 << 0},
757 { .name
= "usb", .gpio
= 1 << 4},
758 { .name
= "blue", .gpio
= 1 << 6},
762 .name
= "D-Link DWL-3150",
764 { .name
= "reset", .gpio
= 1 << 7},
767 { .name
= "diag", .gpio
= 1 << 2},
768 { .name
= "status", .gpio
= 1 << 1},
773 .name
= "Sitecom WL-105b",
775 { .name
= "reset", .gpio
= 1 << 10},
778 { .name
= "wlan", .gpio
= 1 << 4},
779 { .name
= "power", .gpio
= 1 << 3},
784 static struct platform_t __init
*platform_detect(void)
786 char *boardnum
, *boardtype
, *buf
;
788 if (strcmp(getvar("nvram_type"), "cfe") == 0)
789 return &platforms
[WGT634U
];
791 /* Look for a model identifier */
793 /* Based on "model_name" */
794 if ((buf
= nvram_get("model_name"))) {
795 if (!strcmp(buf
, "DIR-130"))
796 return &platforms
[DIR130
];
797 if (!strcmp(buf
, "DIR-330"))
798 return &platforms
[DIR330
];
801 /* Based on "model_no" */
802 if ((buf
= nvram_get("model_no"))) {
803 if (startswith(buf
,"WL700")) /* WL700* */
804 return &platforms
[WL700GE
];
807 /* Based on "hardware_version" */
808 if ((buf
= nvram_get("hardware_version"))) {
809 if (startswith(buf
,"WL500GPV2-")) /* WL500GPV2-* */
810 return &platforms
[WL500GPV2
];
811 if (startswith(buf
,"WL520GC-")) /* WL520GU-* */
812 return &platforms
[WL520GC
];
813 if (startswith(buf
,"WL520GU-")) /* WL520GU-* */
814 return &platforms
[WL520GU
];
815 if (startswith(buf
,"WL330GE-")) /* WL330GE-* */
816 return &platforms
[WL330GE
];
819 /* Based on "ModelId" */
820 if ((buf
= nvram_get("ModelId"))) {
821 if (!strcmp(buf
, "WR850GP"))
822 return &platforms
[WR850GP
];
823 if (!strcmp(buf
, "WR850G"))
824 return &platforms
[WR850GV2V3
];
825 if (!strcmp(buf
, "WX-5565") && !strcmp(getvar("boardtype"),"bcm94710ap"))
826 return &platforms
[TM2300
]; /* Dell TrueMobile 2300 */
827 if (startswith(buf
,"WE800G")) /* WE800G* */
828 return &platforms
[WE800G
];
832 if ((buf
= (nvram_get("melco_id") ?: nvram_get("buffalo_id")))) {
833 /* Buffalo hardware, check id for specific hardware matches */
834 if (!strcmp(buf
, "29bb0332"))
835 return &platforms
[WBR2_G54
];
836 if (!strcmp(buf
, "29129"))
837 return &platforms
[WLA2_G54L
];
838 if (!strcmp(buf
, "30189"))
839 return &platforms
[WHR_HP_G54
];
840 if (!strcmp(buf
, "32093"))
841 return &platforms
[WHR_G125
];
842 if (!strcmp(buf
, "30182"))
843 return &platforms
[WHR_G54S
];
844 if (!strcmp(buf
, "290441dd"))
845 return &platforms
[WHR2_A54G54
];
846 if (!strcmp(buf
, "31120"))
847 return &platforms
[WZR_G300N
];
848 if (!strcmp(buf
, "30083"))
849 return &platforms
[WZR_RS_G54
];
850 if (!strcmp(buf
, "30103"))
851 return &platforms
[WZR_RS_G54HP
];
854 /* no easy model number, attempt to guess */
855 boardnum
= getvar("boardnum");
856 boardtype
= getvar("boardtype");
858 if (!strcmp(boardnum
, "20070615")) { /* Linksys WRT600N v1/V1.1 */
859 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "0") && !strcmp(getvar("switch_type"),"BCM5395"))
860 return &platforms
[WRT600NV11
];
862 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "0"))
863 return &platforms
[WRT600N
];
866 if (startswith(getvar("pmon_ver"), "CFE")) {
867 /* CFE based - newer hardware */
868 if (!strcmp(boardnum
, "42")) { /* Linksys */
869 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "1"))
870 return &platforms
[WRT350N
];
872 if (!strcmp(boardtype
, "0x0101") && !strcmp(getvar("boot_ver"), "v3.6"))
873 return &platforms
[WRT54G3G
];
875 if (!strcmp(getvar("et1phyaddr"),"5") && !strcmp(getvar("et1mdcport"), "1"))
876 return &platforms
[WRTSL54GS
];
878 if (!strcmp(boardtype
, "0x0472"))
879 return &platforms
[WRT160N
];
881 /* default to WRT54G */
882 return &platforms
[WRT54G
];
884 if (!strcmp(boardnum
, "1024") && !strcmp(boardtype
, "0x0446"))
885 return &platforms
[WAP54GV2
];
887 if (!strcmp(boardnum
, "44") || !strcmp(boardnum
, "44\r")) {
888 if (!strcmp(boardtype
,"0x0101") || !strcmp(boardtype
, "0x0101\r"))
889 return &platforms
[TM2300V2
]; /* Dell TrueMobile 2300 v2 */
892 if (!strcmp(boardnum
, "45")) { /* ASUS */
893 if (!strcmp(boardtype
,"0x042f"))
894 return &platforms
[WL500GP
];
895 else if (!strcmp(boardtype
,"0x0472"))
896 return &platforms
[WL500W
];
897 else if (!strcmp(boardtype
,"0x467"))
898 return &platforms
[WL320GE
];
900 return &platforms
[WL500GD
];
903 if (!strcmp(boardnum
, "10496"))
904 return &platforms
[USR5461
];
906 if (!strcmp(getvar("boardtype"), "0x0101") && !strcmp(getvar("boardrev"), "0x10")) /* SE505V2 With Modified CFE */
907 return &platforms
[SE505V2
];
909 if (!strcmp(boardtype
, "0x048e") && !strcmp(getvar("boardrev"),"0x35") &&
910 !strcmp(getvar("boardflags"), "0x750")) /* D-Link DIR-320 */
911 return &platforms
[DIR320
];
913 } else { /* PMON based - old stuff */
914 if ((simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 9) &&
915 (simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 30)) {
916 return &platforms
[WR850GV1
];
918 if (startswith(boardtype
, "bcm94710dev")) {
919 if (!strcmp(boardnum
, "42"))
920 return &platforms
[WRT54GV1
];
921 if (simple_strtoul(boardnum
, NULL
, 0) == 2)
922 return &platforms
[WAP54GV1
];
924 if (startswith(getvar("hardware_version"), "WL500-"))
925 return &platforms
[WL500G
];
926 if (startswith(getvar("hardware_version"), "WL300-")) {
927 /* Either WL-300g or WL-HDD, do more extensive checks */
928 if ((simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 0) &&
929 (simple_strtoul(getvar("et1phyaddr"), NULL
, 0) == 1))
930 return &platforms
[WLHDD
];
931 if ((simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 0) &&
932 (simple_strtoul(getvar("et1phyaddr"), NULL
, 0) == 10))
933 return &platforms
[WL300G
];
935 /* Sitecom WL-105b */
936 if (startswith(boardnum
, "2") && simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 1)
937 return &platforms
[WL105B
];
939 /* unknown asus stuff, probably bcm4702 */
940 if (startswith(boardnum
, "asusX"))
941 return &platforms
[ASUS_4702
];
944 if (buf
|| !strcmp(boardnum
, "00")) {/* probably buffalo */
945 if (startswith(boardtype
, "bcm94710ap"))
946 return &platforms
[BUFFALO_UNKNOWN_4710
];
948 return &platforms
[BUFFALO_UNKNOWN
];
951 if (startswith(getvar("CFEver"), "MotoWRv2") ||
952 startswith(getvar("CFEver"), "MotoWRv3") ||
953 !strcmp(getvar("MOTO_BOARD_TYPE"), "WR_FEM1")) {
955 return &platforms
[WR850GV2V3
];
958 if (!strcmp(boardnum
, "44") && !strcmp(getvar("boardflags"),"0x0388")) { /* Trendware TEW-411BRP+ */
959 return &platforms
[TEW411BRPP
];
962 if (startswith(boardnum
, "04FN52")) /* SimpleTech SimpleShare */
963 return &platforms
[STI_NAS
];
965 if (!strcmp(getvar("boardnum"), "10") && !strcmp(getvar("boardrev"), "0x13")) /* D-Link DWL-3150 */
966 return &platforms
[DWL3150
];
972 static void register_buttons(struct button_t
*b
)
975 platform
.button_mask
|= b
->gpio
;
977 platform
.button_mask
&= ~gpiomask
;
979 gpio_outen(platform
.button_mask
, 0);
980 gpio_control(platform
.button_mask
, 0);
981 platform
.button_polarity
= gpio_in() & platform
.button_mask
;
982 gpio_intpolarity(platform
.button_mask
, platform
.button_polarity
);
983 gpio_setintmask(platform
.button_mask
, platform
.button_mask
);
985 gpio_set_irqenable(1, button_handler
);
988 static void unregister_buttons(struct button_t
*b
)
990 gpio_setintmask(platform
.button_mask
, 0);
992 gpio_set_irqenable(0, button_handler
);
997 static void add_msg(struct event_t
*event
, char *msg
, int argv
)
1004 s
= skb_put(event
->skb
, strlen(msg
) + 1);
1008 static void hotplug_button(struct work_struct
*work
)
1010 struct event_t
*event
= container_of(work
, struct event_t
, wq
);
1016 event
->skb
= alloc_skb(2048, GFP_KERNEL
);
1018 s
= skb_put(event
->skb
, strlen(event
->action
) + 2);
1019 sprintf(s
, "%s@", event
->action
);
1022 NETLINK_CB(event
->skb
).dst_group
= 1;
1023 netlink_broadcast(uevent_sock
, event
->skb
, 0, 1, GFP_KERNEL
);
1028 #else /* !LINUX_2_4 */
1029 static inline char *kzalloc(unsigned int size
, unsigned int gfp
)
1033 p
= kmalloc(size
, gfp
);
1042 static void add_msg(struct event_t
*event
, char *msg
, int argv
)
1045 event
->argv
[event
->anr
++] = event
->scratch
;
1047 event
->envp
[event
->enr
++] = event
->scratch
;
1049 event
->scratch
+= sprintf(event
->scratch
, "%s", msg
) + 1;
1052 static void hotplug_button(struct event_t
*event
)
1054 char *scratch
= kzalloc(256, GFP_KERNEL
);
1055 event
->scratch
= scratch
;
1057 add_msg(event
, hotplug_path
, 1);
1058 add_msg(event
, "button", 1);
1060 call_usermodehelper (event
->argv
[0], event
->argv
, event
->envp
);
1064 #endif /* !LINUX_2_4 */
1066 static int fill_event (struct event_t
*event
)
1068 static char buf
[128];
1070 add_msg(event
, "HOME=/", 0);
1071 add_msg(event
, "PATH=/sbin:/bin:/usr/sbin:/usr/bin", 0);
1072 add_msg(event
, "SUBSYSTEM=button", 0);
1073 snprintf(buf
, 128, "ACTION=%s", event
->action
);
1074 add_msg(event
, buf
, 0);
1075 snprintf(buf
, 128, "BUTTON=%s", event
->name
);
1076 add_msg(event
, buf
, 0);
1077 snprintf(buf
, 128, "SEEN=%ld", event
->seen
);
1078 add_msg(event
, buf
, 0);
1080 snprintf(buf
, 128, "SEQNUM=%llu", uevent_next_seqnum());
1081 add_msg(event
, buf
, 0);
1089 static irqreturn_t
button_handler(int irq
, void *dev_id
)
1091 static irqreturn_t
button_handler(int irq
, void *dev_id
, struct pt_regs
*regs
)
1097 in
= gpio_in() & platform
.button_mask
;
1098 gpio_intpolarity(platform
.button_mask
, in
);
1099 changed
= platform
.button_polarity
^ in
;
1100 platform
.button_polarity
= in
;
1102 changed
&= ~gpio_outen(0, 0);
1104 for (b
= platform
.buttons
; b
->name
; b
++) {
1105 struct event_t
*event
;
1107 if (!(b
->gpio
& changed
)) continue;
1111 if ((event
= (struct event_t
*)kzalloc (sizeof(struct event_t
), GFP_ATOMIC
))) {
1112 event
->seen
= (jiffies
- b
->seen
)/HZ
;
1113 event
->name
= b
->name
;
1114 event
->action
= b
->pressed
? "pressed" : "released";
1115 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
1116 INIT_WORK(&event
->wq
, (void *)(void *)hotplug_button
);
1118 INIT_WORK(&event
->wq
, (void *)(void *)hotplug_button
, (void *)event
);
1120 schedule_work(&event
->wq
);
1128 static void register_leds(struct led_t
*l
)
1130 struct proc_dir_entry
*p
;
1135 leds
= proc_mkdir("led", diag
);
1139 for(; l
->name
; l
++) {
1140 if (l
->gpio
& gpiomask
)
1143 if (l
->gpio
& GPIO_TYPE_EXTIF
) {
1147 if (l
->polarity
!= INPUT
) oe_mask
|= l
->gpio
;
1149 val
|= (l
->polarity
== NORMAL
)?0:l
->gpio
;
1152 if (l
->polarity
== INPUT
) continue;
1154 if ((p
= create_proc_entry(l
->name
, S_IRUSR
, leds
))) {
1155 l
->proc
.type
= PROC_LED
;
1157 p
->data
= (void *) &l
->proc
;
1158 p
->proc_fops
= &diag_proc_fops
;
1162 gpio_outen(mask
, oe_mask
);
1163 gpio_control(mask
, 0);
1164 gpio_out(mask
, val
);
1165 gpio_setintmask(mask
, 0);
1168 static void unregister_leds(struct led_t
*l
)
1171 remove_proc_entry(l
->name
, leds
);
1173 remove_proc_entry("led", diag
);
1176 static void set_led_extif(struct led_t
*led
)
1178 gpio_set_extif(led
->gpio
, led
->state
);
1181 static void led_flash(unsigned long dummy
) {
1186 for (l
= platform
.leds
; l
->name
; l
++) {
1188 if (l
->gpio
& GPIO_TYPE_EXTIF
) {
1190 l
->state
= !l
->state
;
1200 u32 val
= ~gpio_in();
1202 gpio_outen(mask
, mask
);
1203 gpio_control(mask
, 0);
1204 gpio_out(mask
, val
);
1206 if (mask
|| extif_blink
) {
1207 mod_timer(&led_timer
, jiffies
+ FLASH_TIME
);
1211 static ssize_t
diag_proc_read(struct file
*file
, char *buf
, size_t count
, loff_t
*ppos
)
1214 struct inode
*inode
= file
->f_dentry
->d_inode
;
1215 struct proc_dir_entry
*dent
= inode
->u
.generic_ip
;
1217 struct proc_dir_entry
*dent
= PDE(file
->f_dentry
->d_inode
);
1222 if ((page
= kmalloc(1024, GFP_KERNEL
)) == NULL
)
1225 if (dent
->data
!= NULL
) {
1226 struct prochandler_t
*handler
= (struct prochandler_t
*) dent
->data
;
1227 switch (handler
->type
) {
1229 struct led_t
* led
= (struct led_t
*) handler
->ptr
;
1231 len
= sprintf(page
, "f\n");
1233 if (led
->gpio
& GPIO_TYPE_EXTIF
) {
1234 len
= sprintf(page
, "%d\n", led
->state
);
1236 u32 in
= (gpio_in() & led
->gpio
? 1 : 0);
1237 u8 p
= (led
->polarity
== NORMAL
? 0 : 1);
1238 len
= sprintf(page
, "%d\n", ((in
^ p
) ? 1 : 0));
1244 len
= sprintf(page
, "%s\n", platform
.name
);
1247 len
= sprintf(page
, "0x%04x\n", gpiomask
);
1254 len
= min_t(int, len
- *ppos
, count
);
1255 if (copy_to_user(buf
, (page
+ *ppos
), len
)) {
1269 static ssize_t
diag_proc_write(struct file
*file
, const char *buf
, size_t count
, loff_t
*ppos
)
1272 struct inode
*inode
= file
->f_dentry
->d_inode
;
1273 struct proc_dir_entry
*dent
= inode
->u
.generic_ip
;
1275 struct proc_dir_entry
*dent
= PDE(file
->f_dentry
->d_inode
);
1280 if ((page
= kmalloc(count
+ 1, GFP_KERNEL
)) == NULL
)
1283 if (copy_from_user(page
, buf
, count
)) {
1289 if (dent
->data
!= NULL
) {
1290 struct prochandler_t
*handler
= (struct prochandler_t
*) dent
->data
;
1291 switch (handler
->type
) {
1293 struct led_t
*led
= (struct led_t
*) handler
->ptr
;
1294 int p
= (led
->polarity
== NORMAL
? 0 : 1);
1296 if (page
[0] == 'f') {
1301 if (led
->gpio
& GPIO_TYPE_EXTIF
) {
1302 led
->state
= p
^ ((page
[0] == '1') ? 1 : 0);
1305 gpio_outen(led
->gpio
, led
->gpio
);
1306 gpio_control(led
->gpio
, 0);
1307 gpio_out(led
->gpio
, ((p
^ (page
[0] == '1')) ? led
->gpio
: 0));
1313 gpiomask
= simple_strtoul(page
, NULL
, 0);
1315 if (platform
.buttons
) {
1316 unregister_buttons(platform
.buttons
);
1317 register_buttons(platform
.buttons
);
1320 if (platform
.leds
) {
1321 unregister_leds(platform
.leds
);
1322 register_leds(platform
.leds
);
1333 static int __init
diag_init(void)
1335 static struct proc_dir_entry
*p
;
1336 static struct platform_t
*detected
;
1338 detected
= platform_detect();
1340 printk(MODULE_NAME
": Router model not detected.\n");
1343 memcpy(&platform
, detected
, sizeof(struct platform_t
));
1345 printk(MODULE_NAME
": Detected '%s'\n", platform
.name
);
1346 if (platform
.platform_init
!= NULL
) {
1347 platform
.platform_init();
1350 if (!(diag
= proc_mkdir("diag", NULL
))) {
1351 printk(MODULE_NAME
": proc_mkdir on /proc/diag failed\n");
1355 if ((p
= create_proc_entry("model", S_IRUSR
, diag
))) {
1356 p
->data
= (void *) &proc_model
;
1357 p
->proc_fops
= &diag_proc_fops
;
1360 if ((p
= create_proc_entry("gpiomask", S_IRUSR
| S_IWUSR
, diag
))) {
1361 p
->data
= (void *) &proc_gpiomask
;
1362 p
->proc_fops
= &diag_proc_fops
;
1365 if (platform
.buttons
)
1366 register_buttons(platform
.buttons
);
1369 register_leds(platform
.leds
);
1374 static void __exit
diag_exit(void)
1376 del_timer(&led_timer
);
1378 if (platform
.buttons
)
1379 unregister_buttons(platform
.buttons
);
1382 unregister_leds(platform
.leds
);
1384 remove_proc_entry("model", diag
);
1385 remove_proc_entry("gpiomask", diag
);
1386 remove_proc_entry("diag", NULL
);
1389 module_init(diag_init
);
1390 module_exit(diag_exit
);
1392 MODULE_AUTHOR("Mike Baker, Felix Fietkau / OpenWrt.org");
1393 MODULE_LICENSE("GPL");