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.
24 #include <linux/module.h>
25 #include <linux/pci.h>
26 #include <linux/kmod.h>
27 #include <linux/proc_fs.h>
28 #include <linux/timer.h>
29 #include <linux/version.h>
30 #include <asm/uaccess.h>
33 #include <linux/workqueue.h>
34 #include <linux/skbuff.h>
35 #include <linux/netlink.h>
37 extern struct sock
*uevent_sock
;
38 extern u64
uevent_next_seqnum(void);
40 #include <linux/tqueue.h>
41 #define INIT_WORK INIT_TQUEUE
42 #define schedule_work schedule_task
43 #define work_struct tq_struct
48 #define getvar(str) (nvram_get(str)?:"")
50 static inline int startswith (char *source
, char *cmp
) { return !strncmp(source
,cmp
,strlen(cmp
)); }
51 static int fill_event(struct event_t
*);
52 static unsigned int gpiomask
= 0;
53 module_param(gpiomask
, int, 0644);
134 static void __init
bcm4780_init(void) {
137 /* Enables GPIO 3 that controls HDD and led power on ASUS WL-700gE */
138 printk(MODULE_NAME
": Spinning up HDD and enabling leds\n");
139 gpio_outen(pin
, pin
);
140 gpio_control(pin
, 0);
143 /* Wait 5s, so the HDD can spin up */
144 set_current_state(TASK_INTERRUPTIBLE
);
145 schedule_timeout(HZ
* 5);
148 static void __init
bcm57xx_init(void) {
152 /* FIXME: switch comes up, but port mappings/vlans not right */
153 gpio_outen(pin
, pin
);
154 gpio_control(pin
, 0);
159 static struct platform_t __initdata platforms
[] = {
162 .name
= "Linksys WAP54G V1",
164 { .name
= "reset", .gpio
= 1 << 0 },
167 { .name
= "diag", .gpio
= 1 << 3 },
168 { .name
= "wlan", .gpio
= 1 << 4 },
172 .name
= "Linksys WAP54G V2",
174 { .name
= "reset", .gpio
= 1 << 0 },
177 { .name
= "wlan", .gpio
= 1 << 5, .polarity
= REVERSE
},
178 /* GPIO 6 is b44 (eth0, LAN) PHY power */
182 .name
= "Linksys WAP54G V3",
184 /* FIXME: verify this */
185 { .name
= "reset", .gpio
= 1 << 7 },
186 { .name
= "ses", .gpio
= 1 << 0 },
190 { .name
= "ses", .gpio
= 1 << 1 },
194 .name
= "Linksys WRT54G V1.x",
196 { .name
= "reset", .gpio
= 1 << 6 },
199 { .name
= "diag", .gpio
= 0x13 | GPIO_TYPE_EXTIF
, .polarity
= NORMAL
},
200 { .name
= "dmz", .gpio
= 0x12 | GPIO_TYPE_EXTIF
, .polarity
= NORMAL
},
204 .name
= "Linksys WRT54G/GS/GL",
206 { .name
= "reset", .gpio
= 1 << 6 },
207 { .name
= "ses", .gpio
= 1 << 4 },
210 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
211 { .name
= "dmz", .gpio
= 1 << 7, .polarity
= REVERSE
},
212 { .name
= "ses_white", .gpio
= 1 << 2, .polarity
= REVERSE
},
213 { .name
= "ses_orange", .gpio
= 1 << 3, .polarity
= REVERSE
},
214 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
218 .name
= "Linksys WRTSL54GS",
220 { .name
= "reset", .gpio
= 1 << 6 },
221 { .name
= "ses", .gpio
= 1 << 4 },
224 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
225 { .name
= "dmz", .gpio
= 1 << 0, .polarity
= REVERSE
},
226 { .name
= "ses_white", .gpio
= 1 << 5, .polarity
= REVERSE
},
227 { .name
= "ses_orange", .gpio
= 1 << 7, .polarity
= REVERSE
},
231 .name
= "Linksys WRT54G3G",
233 { .name
= "reset", .gpio
= 1 << 6 },
234 { .name
= "3g", .gpio
= 1 << 4 },
237 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
238 { .name
= "dmz", .gpio
= 1 << 7, .polarity
= REVERSE
},
239 { .name
= "3g_green", .gpio
= 1 << 2, .polarity
= NORMAL
},
240 { .name
= "3g_blue", .gpio
= 1 << 3, .polarity
= NORMAL
},
241 { .name
= "3g_blink", .gpio
= 1 << 5, .polarity
= NORMAL
},
245 .name
= "Linksys WRT350N",
247 { .name
= "reset", .gpio
= 1 << 6 },
248 { .name
= "ses", .gpio
= 1 << 8 },
251 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
252 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
253 { .name
= "ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
},
254 { .name
= "usb_blink", .gpio
= 1 << 10, .polarity
= REVERSE
},
255 { .name
= "usb", .gpio
= 1 << 11, .polarity
= REVERSE
},
257 .platform_init
= bcm57xx_init
,
260 .name
= "Linksys WRT600N",
262 { .name
= "reset", .gpio
= 1 << 6 },
263 { .name
= "ses", .gpio
= 1 << 7 },
266 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
}, // Power LED
267 { .name
= "usb", .gpio
= 1 << 3, .polarity
= REVERSE
}, // USB LED
268 { .name
= "wl0_ses_amber", .gpio
= 1 << 8, .polarity
= REVERSE
}, // 2.4Ghz LED Amber
269 { .name
= "wl0_ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
}, // 2.4Ghz LED Green
270 { .name
= "wl1_ses_amber", .gpio
= 1 << 10, .polarity
= REVERSE
}, // 5.6Ghz LED Amber
271 { .name
= "wl1_ses_green", .gpio
= 1 << 11, .polarity
= REVERSE
}, // 5.6Ghz LED Green
273 .platform_init
= bcm57xx_init
,
276 .name
= "Linksys WRT600N V1.1",
278 { .name
= "reset", .gpio
= 1 << 6 },
279 { .name
= "ses", .gpio
= 1 << 7 },
282 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
}, // Power LED
283 { .name
= "usb", .gpio
= 1 << 3, .polarity
= REVERSE
}, // USB LED
284 { .name
= "wl0_ses_amber", .gpio
= 1 << 8, .polarity
= REVERSE
}, // 2.4Ghz LED Amber
285 { .name
= "wl0_ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
}, // 2.4Ghz LED Green
286 { .name
= "wl1_ses_amber", .gpio
= 1 << 10, .polarity
= REVERSE
}, // 5.6Ghz LED Amber
287 { .name
= "wl1_ses_green", .gpio
= 1 << 11, .polarity
= REVERSE
}, // 5.6Ghz LED Green
289 .platform_init
= bcm57xx_init
,
293 .name
= "ASUS WL-HDD",
295 { .name
= "reset", .gpio
= 1 << 6 },
298 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
299 { .name
= "usb", .gpio
= 1 << 2, .polarity
= NORMAL
},
303 .name
= "ASUS WL-300g",
305 { .name
= "reset", .gpio
= 1 << 6 },
308 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
312 .name
= "ASUS WL-320gE/WL-320gP",
314 { .name
= "reset", .gpio
= 1 << 6 },
317 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
318 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
},
319 { .name
= "link", .gpio
= 1 << 11, .polarity
= REVERSE
},
323 .name
= "ASUS WL-330gE",
325 { .name
= "reset", .gpio
= 1 << 2 },
328 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
332 .name
= "ASUS WL-500g",
334 { .name
= "reset", .gpio
= 1 << 6 },
337 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
341 .name
= "ASUS WL-500g Deluxe",
343 { .name
= "reset", .gpio
= 1 << 6 },
346 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
350 .name
= "ASUS WL-500g Premium",
352 { .name
= "reset", .gpio
= 1 << 0 },
353 { .name
= "ses", .gpio
= 1 << 4 },
356 { .name
= "power", .gpio
= 1 << 1, .polarity
= REVERSE
},
360 .name
= "ASUS WL-500g Premium V2",
362 { .name
= "reset", .gpio
= 1 << 2 },
363 { .name
= "ses", .gpio
= 1 << 3 },
366 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
367 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
371 .name
= "ASUS WL-500W",
373 { .name
= "reset", .gpio
= 1 << 6 },
374 { .name
= "ses", .gpio
= 1 << 7 },
377 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
381 .name
= "ASUS WL-520GC",
383 { .name
= "reset", .gpio
= 1 << 2 },
384 { .name
= "ses", .gpio
= 1 << 3 },
387 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
388 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
392 .name
= "ASUS WL-520gU",
394 { .name
= "reset", .gpio
= 1 << 2 },
395 { .name
= "ses", .gpio
= 1 << 3 },
398 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
399 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
403 .name
= "ASUS (unknown, BCM4702)",
405 { .name
= "reset", .gpio
= 1 << 6 },
408 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
412 .name
= "ASUS WL-700gE",
414 { .name
= "reset", .gpio
= 1 << 7 }, // on back, hardwired, always resets device regardless OS state
415 { .name
= "ses", .gpio
= 1 << 4 }, // on back, actual name ezsetup
416 { .name
= "power", .gpio
= 1 << 0 }, // on front
417 { .name
= "copy", .gpio
= 1 << 6 }, // on front
421 // GPIO that controls power led also enables/disables some essential functions
424 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
}, // actual name power
426 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
428 .platform_init
= bcm4780_init
,
432 .name
= "Buffalo WHR-G54S",
434 { .name
= "reset", .gpio
= 1 << 4 },
435 { .name
= "bridge", .gpio
= 1 << 5 },
436 { .name
= "ses", .gpio
= 1 << 0 },
439 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
440 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
441 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
442 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
443 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
447 .name
= "Buffalo WBR2-G54",
450 { .name
= "reset", .gpio
= 1 << 7 },
453 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
457 .name
= "Buffalo WHR-HP-G54",
459 { .name
= "reset", .gpio
= 1 << 4 },
460 { .name
= "bridge", .gpio
= 1 << 5 },
461 { .name
= "ses", .gpio
= 1 << 0 },
464 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
465 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
466 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
467 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
468 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
472 .name
= "Buffalo WHR-G125",
474 { .name
= "reset", .gpio
= 1 << 4 },
475 { .name
= "bridge", .gpio
= 1 << 5 },
476 { .name
= "ses", .gpio
= 1 << 0 },
479 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
480 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
481 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
482 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
483 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
487 .name
= "Buffalo WHR2-A54G54",
489 { .name
= "reset", .gpio
= 1 << 4 },
492 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
496 .name
= "Buffalo WLA2-G54L",
499 { .name
= "reset", .gpio
= 1 << 7 },
502 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
506 .name
= "Buffalo WZR-G300N",
508 { .name
= "reset", .gpio
= 1 << 4 },
511 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
512 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
513 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
517 .name
= "Buffalo WZR-RS-G54",
519 { .name
= "ses", .gpio
= 1 << 0 },
520 { .name
= "reset", .gpio
= 1 << 4 },
523 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
524 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
525 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
529 .name
= "Buffalo WZR-RS-G54HP",
531 { .name
= "ses", .gpio
= 1 << 0 },
532 { .name
= "reset", .gpio
= 1 << 4 },
535 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
536 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
537 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
540 [BUFFALO_UNKNOWN
] = {
541 .name
= "Buffalo (unknown)",
543 { .name
= "reset", .gpio
= 1 << 7 },
546 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
549 [BUFFALO_UNKNOWN_4710
] = {
550 .name
= "Buffalo (unknown, BCM4710)",
552 { .name
= "reset", .gpio
= 1 << 4 },
555 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
560 .name
= "Siemens SE505 V1",
562 /* No usable buttons */
565 // { .name = "power", .gpio = 1 << 0 .polarity = REVERSE }, // Usable when retrofitting D26 (?)
566 { .name
= "dmz", .gpio
= 1 << 4, .polarity
= REVERSE
}, // actual name WWW
567 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
571 .name
= "Siemens SE505 V2",
573 /* No usable buttons */
576 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
577 { .name
= "dmz", .gpio
= 1 << 0, .polarity
= REVERSE
}, // actual name WWW
578 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
583 .name
= "U.S. Robotics USR5461",
585 /* No usable buttons */
588 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
589 { .name
= "printer", .gpio
= 1 << 1, .polarity
= REVERSE
},
594 .name
= "Dell TrueMobile 2300",
596 { .name
= "reset", .gpio
= 1 << 0 },
599 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
600 { .name
= "power", .gpio
= 1 << 7, .polarity
= REVERSE
},
604 .name
= "Dell TrueMobile 2300 v2",
606 { .name
= "reset", .gpio
= 1 << 0 },
609 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
610 { .name
= "power", .gpio
= 1 << 7, .polarity
= REVERSE
},
615 .name
= "Motorola WE800G",
617 { .name
= "reset", .gpio
= 1 << 0 },
620 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
621 { .name
= "diag", .gpio
= 1 << 2, .polarity
= REVERSE
},
622 { .name
= "wlan_amber", .gpio
= 1 << 1, .polarity
= NORMAL
},
626 .name
= "Motorola WR850G V1",
628 { .name
= "reset", .gpio
= 1 << 0 },
631 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
632 { .name
= "diag", .gpio
= 1 << 3, .polarity
= REVERSE
},
633 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= NORMAL
},
634 { .name
= "wlan_red", .gpio
= 1 << 5, .polarity
= REVERSE
},
635 { .name
= "wlan_green", .gpio
= 1 << 7, .polarity
= REVERSE
},
639 .name
= "Motorola WR850G V2/V3",
641 { .name
= "reset", .gpio
= 1 << 5 },
644 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
645 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
646 { .name
= "wan", .gpio
= 1 << 6, .polarity
= INPUT
},
647 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
651 .name
= "Motorola WR850GP",
653 { .name
= "reset", .gpio
= 1 << 5 },
656 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
657 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
658 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= REVERSE
},
659 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
665 .name
= "Belkin (unknown)",
666 /* FIXME: verify & add detection */
668 { .name
= "reset", .gpio
= 1 << 7 },
671 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
},
672 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= NORMAL
},
673 { .name
= "connected", .gpio
= 1 << 0, .polarity
= NORMAL
},
678 .name
= "Netgear WGT634U",
680 { .name
= "reset", .gpio
= 1 << 2 },
683 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
},
688 .name
= "Trendware TEW411BRP+",
690 { /* No usable buttons */ },
693 { .name
= "power", .gpio
= 1 << 7, .polarity
= NORMAL
},
694 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
},
695 { .name
= "bridge", .gpio
= 1 << 6, .polarity
= NORMAL
},
700 .name
= "SimpleTech SimpleShare NAS",
702 { .name
= "reset", .gpio
= 1 << 7 }, // on back, hardwired, always resets device regardless OS state
703 { .name
= "power", .gpio
= 1 << 0 }, // on back
706 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
708 .platform_init
= bcm4780_init
,
712 .name
= "D-Link DIR-130",
714 { .name
= "reset", .gpio
= 1 << 3},
715 { .name
= "reserved", .gpio
= 1 << 7},
718 { .name
= "diag", .gpio
= 1 << 0},
719 { .name
= "blue", .gpio
= 1 << 6},
723 .name
= "D-Link DIR-330",
725 { .name
= "reset", .gpio
= 1 << 3},
726 { .name
= "reserved", .gpio
= 1 << 7},
729 { .name
= "diag", .gpio
= 1 << 0},
730 { .name
= "usb", .gpio
= 1 << 4},
731 { .name
= "blue", .gpio
= 1 << 6},
735 .name
= "D-Link DWL-3150",
737 { .name
= "reset", .gpio
= 1 << 7},
740 { .name
= "diag", .gpio
= 1 << 2},
741 { .name
= "status", .gpio
= 1 << 1},
746 .name
= "Sitecom WL-105b",
748 { .name
= "reset", .gpio
= 1 << 10},
751 { .name
= "wlan", .gpio
= 1 << 4},
752 { .name
= "power", .gpio
= 1 << 3},
757 static struct platform_t __init
*platform_detect(void)
759 char *boardnum
, *boardtype
, *buf
;
761 if (strcmp(getvar("nvram_type"), "cfe") == 0)
762 return &platforms
[WGT634U
];
764 /* Look for a model identifier */
766 /* Based on "model_name" */
767 if ((buf
= nvram_get("model_name"))) {
768 if (!strcmp(buf
, "DIR-130"))
769 return &platforms
[DIR130
];
770 if (!strcmp(buf
, "DIR-330"))
771 return &platforms
[DIR330
];
774 /* Based on "model_no" */
775 if ((buf
= nvram_get("model_no"))) {
776 if (startswith(buf
,"WL700")) /* WL700* */
777 return &platforms
[WL700GE
];
780 /* Based on "hardware_version" */
781 if ((buf
= nvram_get("hardware_version"))) {
782 if (startswith(buf
,"WL500GPV2-")) /* WL500GPV2-* */
783 return &platforms
[WL500GPV2
];
784 if (startswith(buf
,"WL520GC-")) /* WL520GU-* */
785 return &platforms
[WL520GC
];
786 if (startswith(buf
,"WL520GU-")) /* WL520GU-* */
787 return &platforms
[WL520GU
];
788 if (startswith(buf
,"WL330GE-")) /* WL330GE-* */
789 return &platforms
[WL330GE
];
792 /* Based on "ModelId" */
793 if ((buf
= nvram_get("ModelId"))) {
794 if (!strcmp(buf
, "WR850GP"))
795 return &platforms
[WR850GP
];
796 if (!strcmp(buf
, "WX-5565") && !strcmp(getvar("boardtype"),"bcm94710ap"))
797 return &platforms
[TM2300
]; /* Dell TrueMobile 2300 */
798 if (startswith(buf
,"WE800G")) /* WE800G* */
799 return &platforms
[WE800G
];
803 if ((buf
= (nvram_get("melco_id") ?: nvram_get("buffalo_id")))) {
804 /* Buffalo hardware, check id for specific hardware matches */
805 if (!strcmp(buf
, "29bb0332"))
806 return &platforms
[WBR2_G54
];
807 if (!strcmp(buf
, "29129"))
808 return &platforms
[WLA2_G54L
];
809 if (!strcmp(buf
, "30189"))
810 return &platforms
[WHR_HP_G54
];
811 if (!strcmp(buf
, "32093"))
812 return &platforms
[WHR_G125
];
813 if (!strcmp(buf
, "30182"))
814 return &platforms
[WHR_G54S
];
815 if (!strcmp(buf
, "290441dd"))
816 return &platforms
[WHR2_A54G54
];
817 if (!strcmp(buf
, "31120"))
818 return &platforms
[WZR_G300N
];
819 if (!strcmp(buf
, "30083"))
820 return &platforms
[WZR_RS_G54
];
821 if (!strcmp(buf
, "30103"))
822 return &platforms
[WZR_RS_G54HP
];
825 /* no easy model number, attempt to guess */
826 boardnum
= getvar("boardnum");
827 boardtype
= getvar("boardtype");
829 if (!strcmp(boardnum
, "20070615")) { /* Linksys WRT600N v1/V1.1 */
830 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "0") && !strcmp(getvar("switch_type"),"BCM5395"))
831 return &platforms
[WRT600NV11
];
833 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "0"))
834 return &platforms
[WRT600N
];
837 if (startswith(getvar("pmon_ver"), "CFE")) {
838 /* CFE based - newer hardware */
839 if (!strcmp(boardnum
, "42")) { /* Linksys */
840 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "1"))
841 return &platforms
[WRT350N
];
843 if (!strcmp(boardtype
, "0x0101") && !strcmp(getvar("boot_ver"), "v3.6"))
844 return &platforms
[WRT54G3G
];
846 if (!strcmp(getvar("et1phyaddr"),"5") && !strcmp(getvar("et1mdcport"), "1"))
847 return &platforms
[WRTSL54GS
];
849 /* default to WRT54G */
850 return &platforms
[WRT54G
];
852 if (!strcmp(boardnum
, "1024") && !strcmp(boardtype
, "0x0446"))
853 return &platforms
[WAP54GV2
];
855 if (!strcmp(boardnum
, "44") || !strcmp(boardnum
, "44\r")) {
856 if (!strcmp(boardtype
,"0x0101") || !strcmp(boardtype
, "0x0101\r"))
857 return &platforms
[TM2300V2
]; /* Dell TrueMobile 2300 v2 */
860 if (!strcmp(boardnum
, "45")) { /* ASUS */
861 if (!strcmp(boardtype
,"0x042f"))
862 return &platforms
[WL500GP
];
863 else if (!strcmp(boardtype
,"0x0472"))
864 return &platforms
[WL500W
];
865 else if (!strcmp(boardtype
,"0x467"))
866 return &platforms
[WL320GE
];
868 return &platforms
[WL500GD
];
871 if (!strcmp(boardnum
, "10496"))
872 return &platforms
[USR5461
];
874 if (!strcmp(getvar("boardtype"), "0x0101") && !strcmp(getvar("boardrev"), "0x10")) /* SE505V2 With Modified CFE */
875 return &platforms
[SE505V2
];
877 } else { /* PMON based - old stuff */
878 if ((simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 9) &&
879 (simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 30)) {
880 return &platforms
[WR850GV1
];
882 if (startswith(boardtype
, "bcm94710dev")) {
883 if (!strcmp(boardnum
, "42"))
884 return &platforms
[WRT54GV1
];
885 if (simple_strtoul(boardnum
, NULL
, 0) == 2)
886 return &platforms
[WAP54GV1
];
888 if (startswith(getvar("hardware_version"), "WL500-"))
889 return &platforms
[WL500G
];
890 if (startswith(getvar("hardware_version"), "WL300-")) {
891 /* Either WL-300g or WL-HDD, do more extensive checks */
892 if ((simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 0) &&
893 (simple_strtoul(getvar("et1phyaddr"), NULL
, 0) == 1))
894 return &platforms
[WLHDD
];
895 if ((simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 0) &&
896 (simple_strtoul(getvar("et1phyaddr"), NULL
, 0) == 10))
897 return &platforms
[WL300G
];
899 /* Sitecom WL-105b */
900 if (startswith(boardnum
, "2") && simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 1)
901 return &platforms
[WL105B
];
903 /* unknown asus stuff, probably bcm4702 */
904 if (startswith(boardnum
, "asusX"))
905 return &platforms
[ASUS_4702
];
908 if (buf
|| !strcmp(boardnum
, "00")) {/* probably buffalo */
909 if (startswith(boardtype
, "bcm94710ap"))
910 return &platforms
[BUFFALO_UNKNOWN_4710
];
912 return &platforms
[BUFFALO_UNKNOWN
];
915 if (startswith(getvar("CFEver"), "MotoWRv2") ||
916 startswith(getvar("CFEver"), "MotoWRv3") ||
917 !strcmp(getvar("MOTO_BOARD_TYPE"), "WR_FEM1")) {
919 return &platforms
[WR850GV2V3
];
922 if (!strcmp(boardnum
, "44") && !strcmp(getvar("boardflags"),"0x0388")) { /* Trendware TEW-411BRP+ */
923 return &platforms
[TEW411BRPP
];
926 if (startswith(boardnum
, "04FN52")) /* SimpleTech SimpleShare */
927 return &platforms
[STI_NAS
];
929 if (!strcmp(getvar("boardnum"), "10") && !strcmp(getvar("boardrev"), "0x13")) /* D-Link DWL-3150 */
930 return &platforms
[DWL3150
];
936 static void register_buttons(struct button_t
*b
)
939 platform
.button_mask
|= b
->gpio
;
941 platform
.button_mask
&= ~gpiomask
;
943 gpio_outen(platform
.button_mask
, 0);
944 gpio_control(platform
.button_mask
, 0);
945 platform
.button_polarity
= gpio_in() & platform
.button_mask
;
946 gpio_intpolarity(platform
.button_mask
, platform
.button_polarity
);
947 gpio_setintmask(platform
.button_mask
, platform
.button_mask
);
949 gpio_set_irqenable(1, button_handler
);
952 static void unregister_buttons(struct button_t
*b
)
954 gpio_setintmask(platform
.button_mask
, 0);
956 gpio_set_irqenable(0, button_handler
);
961 static void add_msg(struct event_t
*event
, char *msg
, int argv
)
968 s
= skb_put(event
->skb
, strlen(msg
) + 1);
972 static void hotplug_button(struct work_struct
*work
)
974 struct event_t
*event
= container_of(work
, struct event_t
, wq
);
980 event
->skb
= alloc_skb(2048, GFP_KERNEL
);
982 s
= skb_put(event
->skb
, strlen(event
->action
) + 2);
983 sprintf(s
, "%s@", event
->action
);
986 NETLINK_CB(event
->skb
).dst_group
= 1;
987 netlink_broadcast(uevent_sock
, event
->skb
, 0, 1, GFP_KERNEL
);
992 #else /* !LINUX_2_4 */
993 static inline char *kzalloc(unsigned int size
, unsigned int gfp
)
997 p
= kmalloc(size
, gfp
);
1006 static void add_msg(struct event_t
*event
, char *msg
, int argv
)
1009 event
->argv
[event
->anr
++] = event
->scratch
;
1011 event
->envp
[event
->enr
++] = event
->scratch
;
1013 event
->scratch
+= sprintf(event
->scratch
, "%s", msg
) + 1;
1016 static void hotplug_button(struct event_t
*event
)
1018 char *scratch
= kzalloc(256, GFP_KERNEL
);
1019 event
->scratch
= scratch
;
1021 add_msg(event
, hotplug_path
, 1);
1022 add_msg(event
, "button", 1);
1024 call_usermodehelper (event
->argv
[0], event
->argv
, event
->envp
);
1028 #endif /* !LINUX_2_4 */
1030 static int fill_event (struct event_t
*event
)
1032 static char buf
[128];
1034 add_msg(event
, "HOME=/", 0);
1035 add_msg(event
, "PATH=/sbin:/bin:/usr/sbin:/usr/bin", 0);
1036 add_msg(event
, "SUBSYSTEM=button", 0);
1037 snprintf(buf
, 128, "ACTION=%s", event
->action
);
1038 add_msg(event
, buf
, 0);
1039 snprintf(buf
, 128, "BUTTON=%s", event
->name
);
1040 add_msg(event
, buf
, 0);
1041 snprintf(buf
, 128, "SEEN=%ld", event
->seen
);
1042 add_msg(event
, buf
, 0);
1044 snprintf(buf
, 128, "SEQNUM=%llu", uevent_next_seqnum());
1045 add_msg(event
, buf
, 0);
1053 static irqreturn_t
button_handler(int irq
, void *dev_id
)
1055 static irqreturn_t
button_handler(int irq
, void *dev_id
, struct pt_regs
*regs
)
1061 in
= gpio_in() & platform
.button_mask
;
1062 gpio_intpolarity(platform
.button_mask
, in
);
1063 changed
= platform
.button_polarity
^ in
;
1064 platform
.button_polarity
= in
;
1066 changed
&= ~gpio_outen(0, 0);
1068 for (b
= platform
.buttons
; b
->name
; b
++) {
1069 struct event_t
*event
;
1071 if (!(b
->gpio
& changed
)) continue;
1075 if ((event
= (struct event_t
*)kzalloc (sizeof(struct event_t
), GFP_ATOMIC
))) {
1076 event
->seen
= (jiffies
- b
->seen
)/HZ
;
1077 event
->name
= b
->name
;
1078 event
->action
= b
->pressed
? "pressed" : "released";
1079 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
1080 INIT_WORK(&event
->wq
, (void *)(void *)hotplug_button
);
1082 INIT_WORK(&event
->wq
, (void *)(void *)hotplug_button
, (void *)event
);
1084 schedule_work(&event
->wq
);
1092 static void register_leds(struct led_t
*l
)
1094 struct proc_dir_entry
*p
;
1099 leds
= proc_mkdir("led", diag
);
1103 for(; l
->name
; l
++) {
1104 if (l
->gpio
& gpiomask
)
1107 if (l
->gpio
& GPIO_TYPE_EXTIF
) {
1111 if (l
->polarity
!= INPUT
) oe_mask
|= l
->gpio
;
1113 val
|= (l
->polarity
== NORMAL
)?0:l
->gpio
;
1116 if (l
->polarity
== INPUT
) continue;
1118 if ((p
= create_proc_entry(l
->name
, S_IRUSR
, leds
))) {
1119 l
->proc
.type
= PROC_LED
;
1121 p
->data
= (void *) &l
->proc
;
1122 p
->proc_fops
= &diag_proc_fops
;
1126 gpio_outen(mask
, oe_mask
);
1127 gpio_control(mask
, 0);
1128 gpio_out(mask
, val
);
1129 gpio_setintmask(mask
, 0);
1132 static void unregister_leds(struct led_t
*l
)
1135 remove_proc_entry(l
->name
, leds
);
1137 remove_proc_entry("led", diag
);
1140 static void set_led_extif(struct led_t
*led
)
1142 gpio_set_extif(led
->gpio
, led
->state
);
1145 static void led_flash(unsigned long dummy
) {
1150 for (l
= platform
.leds
; l
->name
; l
++) {
1152 if (l
->gpio
& GPIO_TYPE_EXTIF
) {
1154 l
->state
= !l
->state
;
1164 u32 val
= ~gpio_in();
1166 gpio_outen(mask
, mask
);
1167 gpio_control(mask
, 0);
1168 gpio_out(mask
, val
);
1170 if (mask
|| extif_blink
) {
1171 mod_timer(&led_timer
, jiffies
+ FLASH_TIME
);
1175 static ssize_t
diag_proc_read(struct file
*file
, char *buf
, size_t count
, loff_t
*ppos
)
1178 struct inode
*inode
= file
->f_dentry
->d_inode
;
1179 struct proc_dir_entry
*dent
= inode
->u
.generic_ip
;
1181 struct proc_dir_entry
*dent
= PDE(file
->f_dentry
->d_inode
);
1186 if ((page
= kmalloc(1024, GFP_KERNEL
)) == NULL
)
1189 if (dent
->data
!= NULL
) {
1190 struct prochandler_t
*handler
= (struct prochandler_t
*) dent
->data
;
1191 switch (handler
->type
) {
1193 struct led_t
* led
= (struct led_t
*) handler
->ptr
;
1195 len
= sprintf(page
, "f\n");
1197 if (led
->gpio
& GPIO_TYPE_EXTIF
) {
1198 len
= sprintf(page
, "%d\n", led
->state
);
1200 u32 in
= (gpio_in() & led
->gpio
? 1 : 0);
1201 u8 p
= (led
->polarity
== NORMAL
? 0 : 1);
1202 len
= sprintf(page
, "%d\n", ((in
^ p
) ? 1 : 0));
1208 len
= sprintf(page
, "%s\n", platform
.name
);
1211 len
= sprintf(page
, "0x%04x\n", gpiomask
);
1218 len
= min_t(int, len
- *ppos
, count
);
1219 if (copy_to_user(buf
, (page
+ *ppos
), len
)) {
1233 static ssize_t
diag_proc_write(struct file
*file
, const char *buf
, size_t count
, loff_t
*ppos
)
1236 struct inode
*inode
= file
->f_dentry
->d_inode
;
1237 struct proc_dir_entry
*dent
= inode
->u
.generic_ip
;
1239 struct proc_dir_entry
*dent
= PDE(file
->f_dentry
->d_inode
);
1244 if ((page
= kmalloc(count
+ 1, GFP_KERNEL
)) == NULL
)
1247 if (copy_from_user(page
, buf
, count
)) {
1253 if (dent
->data
!= NULL
) {
1254 struct prochandler_t
*handler
= (struct prochandler_t
*) dent
->data
;
1255 switch (handler
->type
) {
1257 struct led_t
*led
= (struct led_t
*) handler
->ptr
;
1258 int p
= (led
->polarity
== NORMAL
? 0 : 1);
1260 if (page
[0] == 'f') {
1265 if (led
->gpio
& GPIO_TYPE_EXTIF
) {
1266 led
->state
= p
^ ((page
[0] == '1') ? 1 : 0);
1269 gpio_outen(led
->gpio
, led
->gpio
);
1270 gpio_control(led
->gpio
, 0);
1271 gpio_out(led
->gpio
, ((p
^ (page
[0] == '1')) ? led
->gpio
: 0));
1277 gpiomask
= simple_strtoul(page
, NULL
, 0);
1279 if (platform
.buttons
) {
1280 unregister_buttons(platform
.buttons
);
1281 register_buttons(platform
.buttons
);
1284 if (platform
.leds
) {
1285 unregister_leds(platform
.leds
);
1286 register_leds(platform
.leds
);
1297 static int __init
diag_init(void)
1299 static struct proc_dir_entry
*p
;
1300 static struct platform_t
*detected
;
1302 detected
= platform_detect();
1304 printk(MODULE_NAME
": Router model not detected.\n");
1307 memcpy(&platform
, detected
, sizeof(struct platform_t
));
1309 printk(MODULE_NAME
": Detected '%s'\n", platform
.name
);
1310 if (platform
.platform_init
!= NULL
) {
1311 platform
.platform_init();
1314 if (!(diag
= proc_mkdir("diag", NULL
))) {
1315 printk(MODULE_NAME
": proc_mkdir on /proc/diag failed\n");
1319 if ((p
= create_proc_entry("model", S_IRUSR
, diag
))) {
1320 p
->data
= (void *) &proc_model
;
1321 p
->proc_fops
= &diag_proc_fops
;
1324 if ((p
= create_proc_entry("gpiomask", S_IRUSR
| S_IWUSR
, diag
))) {
1325 p
->data
= (void *) &proc_gpiomask
;
1326 p
->proc_fops
= &diag_proc_fops
;
1329 if (platform
.buttons
)
1330 register_buttons(platform
.buttons
);
1333 register_leds(platform
.leds
);
1338 static void __exit
diag_exit(void)
1340 del_timer(&led_timer
);
1342 if (platform
.buttons
)
1343 unregister_buttons(platform
.buttons
);
1346 unregister_leds(platform
.leds
);
1348 remove_proc_entry("model", diag
);
1349 remove_proc_entry("gpiomask", diag
);
1350 remove_proc_entry("diag", NULL
);
1353 module_init(diag_init
);
1354 module_exit(diag_exit
);
1356 MODULE_AUTHOR("Mike Baker, Felix Fietkau / OpenWrt.org");
1357 MODULE_LICENSE("GPL");