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);
133 static void __init
bcm4780_init(void) {
136 /* Enables GPIO 3 that controls HDD and led power on ASUS WL-700gE */
137 printk(MODULE_NAME
": Spinning up HDD and enabling leds\n");
138 gpio_outen(pin
, pin
);
139 gpio_control(pin
, 0);
142 /* Wait 5s, so the HDD can spin up */
143 set_current_state(TASK_INTERRUPTIBLE
);
144 schedule_timeout(HZ
* 5);
147 static void __init
bcm57xx_init(void) {
151 /* FIXME: switch comes up, but port mappings/vlans not right */
152 gpio_outen(pin
, pin
);
153 gpio_control(pin
, 0);
158 static struct platform_t __initdata platforms
[] = {
161 .name
= "Linksys WAP54G V1",
163 { .name
= "reset", .gpio
= 1 << 0 },
166 { .name
= "diag", .gpio
= 1 << 3 },
167 { .name
= "wlan", .gpio
= 1 << 4 },
171 .name
= "Linksys WAP54G V2",
173 { .name
= "reset", .gpio
= 1 << 0 },
176 { .name
= "wlan", .gpio
= 1 << 5, .polarity
= REVERSE
},
177 /* GPIO 6 is b44 (eth0, LAN) PHY power */
181 .name
= "Linksys WAP54G V3",
183 /* FIXME: verify this */
184 { .name
= "reset", .gpio
= 1 << 7 },
185 { .name
= "ses", .gpio
= 1 << 0 },
189 { .name
= "ses", .gpio
= 1 << 1 },
193 .name
= "Linksys WRT54G V1.x",
195 { .name
= "reset", .gpio
= 1 << 6 },
198 { .name
= "diag", .gpio
= 0x13 | GPIO_TYPE_EXTIF
, .polarity
= NORMAL
},
199 { .name
= "dmz", .gpio
= 0x12 | GPIO_TYPE_EXTIF
, .polarity
= NORMAL
},
203 .name
= "Linksys WRT54G/GS/GL",
205 { .name
= "reset", .gpio
= 1 << 6 },
206 { .name
= "ses", .gpio
= 1 << 4 },
209 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
210 { .name
= "dmz", .gpio
= 1 << 7, .polarity
= REVERSE
},
211 { .name
= "ses_white", .gpio
= 1 << 2, .polarity
= REVERSE
},
212 { .name
= "ses_orange", .gpio
= 1 << 3, .polarity
= REVERSE
},
213 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
217 .name
= "Linksys WRTSL54GS",
219 { .name
= "reset", .gpio
= 1 << 6 },
220 { .name
= "ses", .gpio
= 1 << 4 },
223 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
224 { .name
= "dmz", .gpio
= 1 << 0, .polarity
= REVERSE
},
225 { .name
= "ses_white", .gpio
= 1 << 5, .polarity
= REVERSE
},
226 { .name
= "ses_orange", .gpio
= 1 << 7, .polarity
= REVERSE
},
230 .name
= "Linksys WRT54G3G",
232 { .name
= "reset", .gpio
= 1 << 6 },
233 { .name
= "3g", .gpio
= 1 << 4 },
236 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
237 { .name
= "dmz", .gpio
= 1 << 7, .polarity
= REVERSE
},
238 { .name
= "3g_green", .gpio
= 1 << 2, .polarity
= NORMAL
},
239 { .name
= "3g_blue", .gpio
= 1 << 3, .polarity
= NORMAL
},
240 { .name
= "3g_blink", .gpio
= 1 << 5, .polarity
= NORMAL
},
244 .name
= "Linksys WRT350N",
246 { .name
= "reset", .gpio
= 1 << 6 },
247 { .name
= "ses", .gpio
= 1 << 8 },
250 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
251 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
252 { .name
= "ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
},
253 { .name
= "usb_blink", .gpio
= 1 << 10, .polarity
= REVERSE
},
254 { .name
= "usb", .gpio
= 1 << 11, .polarity
= REVERSE
},
256 .platform_init
= bcm57xx_init
,
259 .name
= "Linksys WRT600N",
261 { .name
= "reset", .gpio
= 1 << 6 },
262 { .name
= "ses", .gpio
= 1 << 7 },
265 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
}, // Power LED
266 { .name
= "usb", .gpio
= 1 << 3, .polarity
= REVERSE
}, // USB LED
267 { .name
= "wl0_ses_amber", .gpio
= 1 << 8, .polarity
= REVERSE
}, // 2.4Ghz LED Amber
268 { .name
= "wl0_ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
}, // 2.4Ghz LED Green
269 { .name
= "wl1_ses_amber", .gpio
= 1 << 10, .polarity
= REVERSE
}, // 5.6Ghz LED Amber
270 { .name
= "wl1_ses_green", .gpio
= 1 << 11, .polarity
= REVERSE
}, // 5.6Ghz LED Green
272 .platform_init
= bcm57xx_init
,
275 .name
= "Linksys WRT600N V1.1",
277 { .name
= "reset", .gpio
= 1 << 6 },
278 { .name
= "ses", .gpio
= 1 << 7 },
281 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
}, // Power LED
282 { .name
= "usb", .gpio
= 1 << 3, .polarity
= REVERSE
}, // USB LED
283 { .name
= "wl0_ses_amber", .gpio
= 1 << 8, .polarity
= REVERSE
}, // 2.4Ghz LED Amber
284 { .name
= "wl0_ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
}, // 2.4Ghz LED Green
285 { .name
= "wl1_ses_amber", .gpio
= 1 << 10, .polarity
= REVERSE
}, // 5.6Ghz LED Amber
286 { .name
= "wl1_ses_green", .gpio
= 1 << 11, .polarity
= REVERSE
}, // 5.6Ghz LED Green
288 .platform_init
= bcm57xx_init
,
292 .name
= "ASUS WL-HDD",
294 { .name
= "reset", .gpio
= 1 << 6 },
297 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
298 { .name
= "usb", .gpio
= 1 << 2, .polarity
= NORMAL
},
302 .name
= "ASUS WL-300g",
304 { .name
= "reset", .gpio
= 1 << 6 },
307 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
311 .name
= "ASUS WL-320gE/WL-320gP",
313 { .name
= "reset", .gpio
= 1 << 6 },
316 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
317 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
},
318 { .name
= "link", .gpio
= 1 << 11, .polarity
= REVERSE
},
322 .name
= "ASUS WL-330gE",
324 { .name
= "reset", .gpio
= 1 << 2 },
327 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
331 .name
= "ASUS WL-500g",
333 { .name
= "reset", .gpio
= 1 << 6 },
336 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
340 .name
= "ASUS WL-500g Deluxe",
342 { .name
= "reset", .gpio
= 1 << 6 },
345 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
349 .name
= "ASUS WL-500g Premium",
351 { .name
= "reset", .gpio
= 1 << 0 },
352 { .name
= "ses", .gpio
= 1 << 4 },
355 { .name
= "power", .gpio
= 1 << 1, .polarity
= REVERSE
},
359 .name
= "ASUS WL-500g Premium V2",
361 { .name
= "reset", .gpio
= 1 << 2 },
362 { .name
= "ses", .gpio
= 1 << 3 },
365 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
366 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
370 .name
= "ASUS WL-500W",
372 { .name
= "reset", .gpio
= 1 << 6 },
373 { .name
= "ses", .gpio
= 1 << 7 },
376 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
380 .name
= "ASUS WL-520GC",
382 { .name
= "reset", .gpio
= 1 << 2 },
383 { .name
= "ses", .gpio
= 1 << 3 },
386 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
387 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
391 .name
= "ASUS WL-520gU",
393 { .name
= "reset", .gpio
= 1 << 2 },
394 { .name
= "ses", .gpio
= 1 << 3 },
397 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
398 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
402 .name
= "ASUS (unknown, BCM4702)",
404 { .name
= "reset", .gpio
= 1 << 6 },
407 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
411 .name
= "ASUS WL-700gE",
413 { .name
= "reset", .gpio
= 1 << 7 }, // on back, hardwired, always resets device regardless OS state
414 { .name
= "ses", .gpio
= 1 << 4 }, // on back, actual name ezsetup
415 { .name
= "power", .gpio
= 1 << 0 }, // on front
416 { .name
= "copy", .gpio
= 1 << 6 }, // on front
420 // GPIO that controls power led also enables/disables some essential functions
423 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
}, // actual name power
425 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
427 .platform_init
= bcm4780_init
,
431 .name
= "Buffalo WHR-G54S",
433 { .name
= "reset", .gpio
= 1 << 4 },
434 { .name
= "bridge", .gpio
= 1 << 5 },
435 { .name
= "ses", .gpio
= 1 << 0 },
438 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
439 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
440 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
441 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
442 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
446 .name
= "Buffalo WBR2-G54",
449 { .name
= "reset", .gpio
= 1 << 7 },
452 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
456 .name
= "Buffalo WHR-HP-G54",
458 { .name
= "reset", .gpio
= 1 << 4 },
459 { .name
= "bridge", .gpio
= 1 << 5 },
460 { .name
= "ses", .gpio
= 1 << 0 },
463 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
464 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
465 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
466 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
467 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
471 .name
= "Buffalo WHR-G125",
473 { .name
= "reset", .gpio
= 1 << 4 },
474 { .name
= "bridge", .gpio
= 1 << 5 },
475 { .name
= "ses", .gpio
= 1 << 0 },
478 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
479 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
480 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
481 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
482 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
486 .name
= "Buffalo WHR2-A54G54",
488 { .name
= "reset", .gpio
= 1 << 4 },
491 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
495 .name
= "Buffalo WLA2-G54L",
498 { .name
= "reset", .gpio
= 1 << 7 },
501 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
505 .name
= "Buffalo WZR-G300N",
507 { .name
= "reset", .gpio
= 1 << 4 },
510 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
511 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
512 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
516 .name
= "Buffalo WZR-RS-G54",
518 { .name
= "ses", .gpio
= 1 << 0 },
519 { .name
= "reset", .gpio
= 1 << 4 },
522 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
523 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
524 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
528 .name
= "Buffalo WZR-RS-G54HP",
530 { .name
= "ses", .gpio
= 1 << 0 },
531 { .name
= "reset", .gpio
= 1 << 4 },
534 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
535 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
536 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
539 [BUFFALO_UNKNOWN
] = {
540 .name
= "Buffalo (unknown)",
542 { .name
= "reset", .gpio
= 1 << 7 },
545 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
548 [BUFFALO_UNKNOWN_4710
] = {
549 .name
= "Buffalo (unknown, BCM4710)",
551 { .name
= "reset", .gpio
= 1 << 4 },
554 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
559 .name
= "Siemens SE505 V1",
561 /* No usable buttons */
564 // { .name = "power", .gpio = 1 << 0 .polarity = REVERSE }, // Usable when retrofitting D26 (?)
565 { .name
= "dmz", .gpio
= 1 << 4, .polarity
= REVERSE
}, // actual name WWW
566 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
570 .name
= "Siemens SE505 V2",
572 /* No usable buttons */
575 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
576 { .name
= "dmz", .gpio
= 1 << 0, .polarity
= REVERSE
}, // actual name WWW
577 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
582 .name
= "U.S. Robotics USR5461",
584 /* No usable buttons */
587 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
588 { .name
= "printer", .gpio
= 1 << 1, .polarity
= REVERSE
},
593 .name
= "Dell TrueMobile 2300",
595 { .name
= "reset", .gpio
= 1 << 0 },
598 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
599 { .name
= "power", .gpio
= 1 << 7, .polarity
= REVERSE
},
603 .name
= "Dell TrueMobile 2300 v2",
605 { .name
= "reset", .gpio
= 1 << 0 },
608 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
609 { .name
= "power", .gpio
= 1 << 7, .polarity
= REVERSE
},
614 .name
= "Motorola WE800G",
616 { .name
= "reset", .gpio
= 1 << 0 },
619 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
620 { .name
= "diag", .gpio
= 1 << 2, .polarity
= REVERSE
},
621 { .name
= "wlan_amber", .gpio
= 1 << 1, .polarity
= NORMAL
},
625 .name
= "Motorola WR850G V1",
627 { .name
= "reset", .gpio
= 1 << 0 },
630 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
631 { .name
= "diag", .gpio
= 1 << 3, .polarity
= REVERSE
},
632 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= NORMAL
},
633 { .name
= "wlan_red", .gpio
= 1 << 5, .polarity
= REVERSE
},
634 { .name
= "wlan_green", .gpio
= 1 << 7, .polarity
= REVERSE
},
638 .name
= "Motorola WR850G V2/V3",
640 { .name
= "reset", .gpio
= 1 << 5 },
643 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
644 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
645 { .name
= "wan", .gpio
= 1 << 6, .polarity
= INPUT
},
646 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
650 .name
= "Motorola WR850GP",
652 { .name
= "reset", .gpio
= 1 << 5 },
655 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
656 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
657 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= REVERSE
},
658 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
664 .name
= "Belkin (unknown)",
665 /* FIXME: verify & add detection */
667 { .name
= "reset", .gpio
= 1 << 7 },
670 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
},
671 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= NORMAL
},
672 { .name
= "connected", .gpio
= 1 << 0, .polarity
= NORMAL
},
677 .name
= "Netgear WGT634U",
679 { .name
= "reset", .gpio
= 1 << 2 },
682 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
},
687 .name
= "Trendware TEW411BRP+",
689 { /* No usable buttons */ },
692 { .name
= "power", .gpio
= 1 << 7, .polarity
= NORMAL
},
693 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
},
694 { .name
= "bridge", .gpio
= 1 << 6, .polarity
= NORMAL
},
699 .name
= "SimpleTech SimpleShare NAS",
701 { .name
= "reset", .gpio
= 1 << 7 }, // on back, hardwired, always resets device regardless OS state
702 { .name
= "power", .gpio
= 1 << 0 }, // on back
705 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
707 .platform_init
= bcm4780_init
,
711 .name
= "D-Link DIR-130",
713 { .name
= "reset", .gpio
= 1 << 3},
714 { .name
= "reserved", .gpio
= 1 << 7},
717 { .name
= "diag", .gpio
= 1 << 0},
718 { .name
= "blue", .gpio
= 1 << 6},
722 .name
= "D-Link DIR-330",
724 { .name
= "reset", .gpio
= 1 << 3},
725 { .name
= "reserved", .gpio
= 1 << 7},
728 { .name
= "diag", .gpio
= 1 << 0},
729 { .name
= "usb", .gpio
= 1 << 4},
730 { .name
= "blue", .gpio
= 1 << 6},
734 .name
= "D-Link DWL-3150",
736 { .name
= "reset", .gpio
= 1 << 7},
739 { .name
= "diag", .gpio
= 1 << 2},
740 { .name
= "status", .gpio
= 1 << 1},
745 .name
= "Sitecom WL-105b",
747 { .name
= "reset", .gpio
= 1 << 10},
750 { .name
= "wlan", .gpio
= 1 << 4},
751 { .name
= "power", .gpio
= 1 << 3},
756 static struct platform_t __init
*platform_detect(void)
758 char *boardnum
, *boardtype
, *buf
;
760 if (strcmp(getvar("nvram_type"), "cfe") == 0)
761 return &platforms
[WGT634U
];
763 /* Look for a model identifier */
765 /* Based on "model_name" */
766 if ((buf
= nvram_get("model_name"))) {
767 if (!strcmp(buf
, "DIR-130"))
768 return &platforms
[DIR130
];
769 if (!strcmp(buf
, "DIR-330"))
770 return &platforms
[DIR330
];
773 /* Based on "model_no" */
774 if ((buf
= nvram_get("model_no"))) {
775 if (startswith(buf
,"WL700")) /* WL700* */
776 return &platforms
[WL700GE
];
779 /* Based on "hardware_version" */
780 if ((buf
= nvram_get("hardware_version"))) {
781 if (startswith(buf
,"WL500GPV2-")) /* WL500GPV2-* */
782 return &platforms
[WL500GPV2
];
783 if (startswith(buf
,"WL520GC-")) /* WL520GU-* */
784 return &platforms
[WL520GC
];
785 if (startswith(buf
,"WL520GU-")) /* WL520GU-* */
786 return &platforms
[WL520GU
];
787 if (startswith(buf
,"WL330GE-")) /* WL330GE-* */
788 return &platforms
[WL330GE
];
791 /* Based on "ModelId" */
792 if ((buf
= nvram_get("ModelId"))) {
793 if (!strcmp(buf
, "WR850GP"))
794 return &platforms
[WR850GP
];
795 if (!strcmp(buf
, "WR850G"))
796 return &platforms
[WR850GV2V3
];
797 if (!strcmp(buf
, "WX-5565") && !strcmp(getvar("boardtype"),"bcm94710ap"))
798 return &platforms
[TM2300
]; /* Dell TrueMobile 2300 */
799 if (startswith(buf
,"WE800G")) /* WE800G* */
800 return &platforms
[WE800G
];
804 if ((buf
= (nvram_get("melco_id") ?: nvram_get("buffalo_id")))) {
805 /* Buffalo hardware, check id for specific hardware matches */
806 if (!strcmp(buf
, "29bb0332"))
807 return &platforms
[WBR2_G54
];
808 if (!strcmp(buf
, "29129"))
809 return &platforms
[WLA2_G54L
];
810 if (!strcmp(buf
, "30189"))
811 return &platforms
[WHR_HP_G54
];
812 if (!strcmp(buf
, "32093"))
813 return &platforms
[WHR_G125
];
814 if (!strcmp(buf
, "30182"))
815 return &platforms
[WHR_G54S
];
816 if (!strcmp(buf
, "290441dd"))
817 return &platforms
[WHR2_A54G54
];
818 if (!strcmp(buf
, "31120"))
819 return &platforms
[WZR_G300N
];
820 if (!strcmp(buf
, "30083"))
821 return &platforms
[WZR_RS_G54
];
822 if (!strcmp(buf
, "30103"))
823 return &platforms
[WZR_RS_G54HP
];
826 /* no easy model number, attempt to guess */
827 boardnum
= getvar("boardnum");
828 boardtype
= getvar("boardtype");
830 if (!strcmp(boardnum
, "20070615")) { /* Linksys WRT600N v1/V1.1 */
831 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "0") && !strcmp(getvar("switch_type"),"BCM5395"))
832 return &platforms
[WRT600NV11
];
834 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "0"))
835 return &platforms
[WRT600N
];
838 if (startswith(getvar("pmon_ver"), "CFE")) {
839 /* CFE based - newer hardware */
840 if (!strcmp(boardnum
, "42")) { /* Linksys */
841 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "1"))
842 return &platforms
[WRT350N
];
844 if (!strcmp(boardtype
, "0x0101") && !strcmp(getvar("boot_ver"), "v3.6"))
845 return &platforms
[WRT54G3G
];
847 if (!strcmp(getvar("et1phyaddr"),"5") && !strcmp(getvar("et1mdcport"), "1"))
848 return &platforms
[WRTSL54GS
];
850 /* default to WRT54G */
851 return &platforms
[WRT54G
];
853 if (!strcmp(boardnum
, "1024") && !strcmp(boardtype
, "0x0446"))
854 return &platforms
[WAP54GV2
];
856 if (!strcmp(boardnum
, "44") || !strcmp(boardnum
, "44\r")) {
857 if (!strcmp(boardtype
,"0x0101") || !strcmp(boardtype
, "0x0101\r"))
858 return &platforms
[TM2300V2
]; /* Dell TrueMobile 2300 v2 */
861 if (!strcmp(boardnum
, "45")) { /* ASUS */
862 if (!strcmp(boardtype
,"0x042f"))
863 return &platforms
[WL500GP
];
864 else if (!strcmp(boardtype
,"0x0472"))
865 return &platforms
[WL500W
];
866 else if (!strcmp(boardtype
,"0x467"))
867 return &platforms
[WL320GE
];
869 return &platforms
[WL500GD
];
872 if (!strcmp(boardnum
, "10496"))
873 return &platforms
[USR5461
];
875 if (!strcmp(getvar("boardtype"), "0x0101") && !strcmp(getvar("boardrev"), "0x10")) /* SE505V2 With Modified CFE */
876 return &platforms
[SE505V2
];
878 } else { /* PMON based - old stuff */
879 if ((simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 9) &&
880 (simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 30)) {
881 return &platforms
[WR850GV1
];
883 if (startswith(boardtype
, "bcm94710dev")) {
884 if (!strcmp(boardnum
, "42"))
885 return &platforms
[WRT54GV1
];
886 if (simple_strtoul(boardnum
, NULL
, 0) == 2)
887 return &platforms
[WAP54GV1
];
889 if (startswith(getvar("hardware_version"), "WL500-"))
890 return &platforms
[WL500G
];
891 if (startswith(getvar("hardware_version"), "WL300-")) {
892 /* Either WL-300g or WL-HDD, do more extensive checks */
893 if ((simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 0) &&
894 (simple_strtoul(getvar("et1phyaddr"), NULL
, 0) == 1))
895 return &platforms
[WLHDD
];
896 if ((simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 0) &&
897 (simple_strtoul(getvar("et1phyaddr"), NULL
, 0) == 10))
898 return &platforms
[WL300G
];
900 /* Sitecom WL-105b */
901 if (startswith(boardnum
, "2") && simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 1)
902 return &platforms
[WL105B
];
904 /* unknown asus stuff, probably bcm4702 */
905 if (startswith(boardnum
, "asusX"))
906 return &platforms
[ASUS_4702
];
909 if (buf
|| !strcmp(boardnum
, "00")) {/* probably buffalo */
910 if (startswith(boardtype
, "bcm94710ap"))
911 return &platforms
[BUFFALO_UNKNOWN_4710
];
913 return &platforms
[BUFFALO_UNKNOWN
];
916 if (startswith(getvar("CFEver"), "MotoWRv2") ||
917 startswith(getvar("CFEver"), "MotoWRv3") ||
918 !strcmp(getvar("MOTO_BOARD_TYPE"), "WR_FEM1")) {
920 return &platforms
[WR850GV2V3
];
923 if (!strcmp(boardnum
, "44") && !strcmp(getvar("boardflags"),"0x0388")) { /* Trendware TEW-411BRP+ */
924 return &platforms
[TEW411BRPP
];
927 if (startswith(boardnum
, "04FN52")) /* SimpleTech SimpleShare */
928 return &platforms
[STI_NAS
];
930 if (!strcmp(getvar("boardnum"), "10") && !strcmp(getvar("boardrev"), "0x13")) /* D-Link DWL-3150 */
931 return &platforms
[DWL3150
];
937 static void register_buttons(struct button_t
*b
)
940 platform
.button_mask
|= b
->gpio
;
942 platform
.button_mask
&= ~gpiomask
;
944 gpio_outen(platform
.button_mask
, 0);
945 gpio_control(platform
.button_mask
, 0);
946 platform
.button_polarity
= gpio_in() & platform
.button_mask
;
947 gpio_intpolarity(platform
.button_mask
, platform
.button_polarity
);
948 gpio_setintmask(platform
.button_mask
, platform
.button_mask
);
950 gpio_set_irqenable(1, button_handler
);
953 static void unregister_buttons(struct button_t
*b
)
955 gpio_setintmask(platform
.button_mask
, 0);
957 gpio_set_irqenable(0, button_handler
);
962 static void add_msg(struct event_t
*event
, char *msg
, int argv
)
969 s
= skb_put(event
->skb
, strlen(msg
) + 1);
973 static void hotplug_button(struct work_struct
*work
)
975 struct event_t
*event
= container_of(work
, struct event_t
, wq
);
981 event
->skb
= alloc_skb(2048, GFP_KERNEL
);
983 s
= skb_put(event
->skb
, strlen(event
->action
) + 2);
984 sprintf(s
, "%s@", event
->action
);
987 NETLINK_CB(event
->skb
).dst_group
= 1;
988 netlink_broadcast(uevent_sock
, event
->skb
, 0, 1, GFP_KERNEL
);
993 #else /* !LINUX_2_4 */
994 static inline char *kzalloc(unsigned int size
, unsigned int gfp
)
998 p
= kmalloc(size
, gfp
);
1007 static void add_msg(struct event_t
*event
, char *msg
, int argv
)
1010 event
->argv
[event
->anr
++] = event
->scratch
;
1012 event
->envp
[event
->enr
++] = event
->scratch
;
1014 event
->scratch
+= sprintf(event
->scratch
, "%s", msg
) + 1;
1017 static void hotplug_button(struct event_t
*event
)
1019 char *scratch
= kzalloc(256, GFP_KERNEL
);
1020 event
->scratch
= scratch
;
1022 add_msg(event
, hotplug_path
, 1);
1023 add_msg(event
, "button", 1);
1025 call_usermodehelper (event
->argv
[0], event
->argv
, event
->envp
);
1029 #endif /* !LINUX_2_4 */
1031 static int fill_event (struct event_t
*event
)
1033 static char buf
[128];
1035 add_msg(event
, "HOME=/", 0);
1036 add_msg(event
, "PATH=/sbin:/bin:/usr/sbin:/usr/bin", 0);
1037 add_msg(event
, "SUBSYSTEM=button", 0);
1038 snprintf(buf
, 128, "ACTION=%s", event
->action
);
1039 add_msg(event
, buf
, 0);
1040 snprintf(buf
, 128, "BUTTON=%s", event
->name
);
1041 add_msg(event
, buf
, 0);
1042 snprintf(buf
, 128, "SEEN=%ld", event
->seen
);
1043 add_msg(event
, buf
, 0);
1045 snprintf(buf
, 128, "SEQNUM=%llu", uevent_next_seqnum());
1046 add_msg(event
, buf
, 0);
1054 static irqreturn_t
button_handler(int irq
, void *dev_id
)
1056 static irqreturn_t
button_handler(int irq
, void *dev_id
, struct pt_regs
*regs
)
1062 in
= gpio_in() & platform
.button_mask
;
1063 gpio_intpolarity(platform
.button_mask
, in
);
1064 changed
= platform
.button_polarity
^ in
;
1065 platform
.button_polarity
= in
;
1067 changed
&= ~gpio_outen(0, 0);
1069 for (b
= platform
.buttons
; b
->name
; b
++) {
1070 struct event_t
*event
;
1072 if (!(b
->gpio
& changed
)) continue;
1076 if ((event
= (struct event_t
*)kzalloc (sizeof(struct event_t
), GFP_ATOMIC
))) {
1077 event
->seen
= (jiffies
- b
->seen
)/HZ
;
1078 event
->name
= b
->name
;
1079 event
->action
= b
->pressed
? "pressed" : "released";
1080 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
1081 INIT_WORK(&event
->wq
, (void *)(void *)hotplug_button
);
1083 INIT_WORK(&event
->wq
, (void *)(void *)hotplug_button
, (void *)event
);
1085 schedule_work(&event
->wq
);
1093 static void register_leds(struct led_t
*l
)
1095 struct proc_dir_entry
*p
;
1100 leds
= proc_mkdir("led", diag
);
1104 for(; l
->name
; l
++) {
1105 if (l
->gpio
& gpiomask
)
1108 if (l
->gpio
& GPIO_TYPE_EXTIF
) {
1112 if (l
->polarity
!= INPUT
) oe_mask
|= l
->gpio
;
1114 val
|= (l
->polarity
== NORMAL
)?0:l
->gpio
;
1117 if (l
->polarity
== INPUT
) continue;
1119 if ((p
= create_proc_entry(l
->name
, S_IRUSR
, leds
))) {
1120 l
->proc
.type
= PROC_LED
;
1122 p
->data
= (void *) &l
->proc
;
1123 p
->proc_fops
= &diag_proc_fops
;
1127 gpio_outen(mask
, oe_mask
);
1128 gpio_control(mask
, 0);
1129 gpio_out(mask
, val
);
1130 gpio_setintmask(mask
, 0);
1133 static void unregister_leds(struct led_t
*l
)
1136 remove_proc_entry(l
->name
, leds
);
1138 remove_proc_entry("led", diag
);
1141 static void set_led_extif(struct led_t
*led
)
1143 gpio_set_extif(led
->gpio
, led
->state
);
1146 static void led_flash(unsigned long dummy
) {
1151 for (l
= platform
.leds
; l
->name
; l
++) {
1153 if (l
->gpio
& GPIO_TYPE_EXTIF
) {
1155 l
->state
= !l
->state
;
1165 u32 val
= ~gpio_in();
1167 gpio_outen(mask
, mask
);
1168 gpio_control(mask
, 0);
1169 gpio_out(mask
, val
);
1171 if (mask
|| extif_blink
) {
1172 mod_timer(&led_timer
, jiffies
+ FLASH_TIME
);
1176 static ssize_t
diag_proc_read(struct file
*file
, char *buf
, size_t count
, loff_t
*ppos
)
1179 struct inode
*inode
= file
->f_dentry
->d_inode
;
1180 struct proc_dir_entry
*dent
= inode
->u
.generic_ip
;
1182 struct proc_dir_entry
*dent
= PDE(file
->f_dentry
->d_inode
);
1187 if ((page
= kmalloc(1024, GFP_KERNEL
)) == NULL
)
1190 if (dent
->data
!= NULL
) {
1191 struct prochandler_t
*handler
= (struct prochandler_t
*) dent
->data
;
1192 switch (handler
->type
) {
1194 struct led_t
* led
= (struct led_t
*) handler
->ptr
;
1196 len
= sprintf(page
, "f\n");
1198 if (led
->gpio
& GPIO_TYPE_EXTIF
) {
1199 len
= sprintf(page
, "%d\n", led
->state
);
1201 u32 in
= (gpio_in() & led
->gpio
? 1 : 0);
1202 u8 p
= (led
->polarity
== NORMAL
? 0 : 1);
1203 len
= sprintf(page
, "%d\n", ((in
^ p
) ? 1 : 0));
1209 len
= sprintf(page
, "%s\n", platform
.name
);
1212 len
= sprintf(page
, "0x%04x\n", gpiomask
);
1219 len
= min_t(int, len
- *ppos
, count
);
1220 if (copy_to_user(buf
, (page
+ *ppos
), len
)) {
1234 static ssize_t
diag_proc_write(struct file
*file
, const char *buf
, size_t count
, loff_t
*ppos
)
1237 struct inode
*inode
= file
->f_dentry
->d_inode
;
1238 struct proc_dir_entry
*dent
= inode
->u
.generic_ip
;
1240 struct proc_dir_entry
*dent
= PDE(file
->f_dentry
->d_inode
);
1245 if ((page
= kmalloc(count
+ 1, GFP_KERNEL
)) == NULL
)
1248 if (copy_from_user(page
, buf
, count
)) {
1254 if (dent
->data
!= NULL
) {
1255 struct prochandler_t
*handler
= (struct prochandler_t
*) dent
->data
;
1256 switch (handler
->type
) {
1258 struct led_t
*led
= (struct led_t
*) handler
->ptr
;
1259 int p
= (led
->polarity
== NORMAL
? 0 : 1);
1261 if (page
[0] == 'f') {
1266 if (led
->gpio
& GPIO_TYPE_EXTIF
) {
1267 led
->state
= p
^ ((page
[0] == '1') ? 1 : 0);
1270 gpio_outen(led
->gpio
, led
->gpio
);
1271 gpio_control(led
->gpio
, 0);
1272 gpio_out(led
->gpio
, ((p
^ (page
[0] == '1')) ? led
->gpio
: 0));
1278 gpiomask
= simple_strtoul(page
, NULL
, 0);
1280 if (platform
.buttons
) {
1281 unregister_buttons(platform
.buttons
);
1282 register_buttons(platform
.buttons
);
1285 if (platform
.leds
) {
1286 unregister_leds(platform
.leds
);
1287 register_leds(platform
.leds
);
1298 static int __init
diag_init(void)
1300 static struct proc_dir_entry
*p
;
1301 static struct platform_t
*detected
;
1303 detected
= platform_detect();
1305 printk(MODULE_NAME
": Router model not detected.\n");
1308 memcpy(&platform
, detected
, sizeof(struct platform_t
));
1310 printk(MODULE_NAME
": Detected '%s'\n", platform
.name
);
1311 if (platform
.platform_init
!= NULL
) {
1312 platform
.platform_init();
1315 if (!(diag
= proc_mkdir("diag", NULL
))) {
1316 printk(MODULE_NAME
": proc_mkdir on /proc/diag failed\n");
1320 if ((p
= create_proc_entry("model", S_IRUSR
, diag
))) {
1321 p
->data
= (void *) &proc_model
;
1322 p
->proc_fops
= &diag_proc_fops
;
1325 if ((p
= create_proc_entry("gpiomask", S_IRUSR
| S_IWUSR
, diag
))) {
1326 p
->data
= (void *) &proc_gpiomask
;
1327 p
->proc_fops
= &diag_proc_fops
;
1330 if (platform
.buttons
)
1331 register_buttons(platform
.buttons
);
1334 register_leds(platform
.leds
);
1339 static void __exit
diag_exit(void)
1341 del_timer(&led_timer
);
1343 if (platform
.buttons
)
1344 unregister_buttons(platform
.buttons
);
1347 unregister_leds(platform
.leds
);
1349 remove_proc_entry("model", diag
);
1350 remove_proc_entry("gpiomask", diag
);
1351 remove_proc_entry("diag", NULL
);
1354 module_init(diag_init
);
1355 module_exit(diag_exit
);
1357 MODULE_AUTHOR("Mike Baker, Felix Fietkau / OpenWrt.org");
1358 MODULE_LICENSE("GPL");