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);
131 static void __init
bcm4780_init(void) {
134 /* Enables GPIO 3 that controls HDD and led power on ASUS WL-700gE */
135 printk(MODULE_NAME
": Spinning up HDD and enabling leds\n");
136 gpio_outen(pin
, pin
);
137 gpio_control(pin
, 0);
140 /* Wait 5s, so the HDD can spin up */
141 set_current_state(TASK_INTERRUPTIBLE
);
142 schedule_timeout(HZ
* 5);
145 static void __init
bcm57xx_init(void) {
149 /* FIXME: switch comes up, but port mappings/vlans not right */
150 gpio_outen(pin
, pin
);
151 gpio_control(pin
, 0);
156 static struct platform_t __initdata platforms
[] = {
159 .name
= "Linksys WAP54G V1",
161 { .name
= "reset", .gpio
= 1 << 0 },
164 { .name
= "diag", .gpio
= 1 << 3 },
165 { .name
= "wlan", .gpio
= 1 << 4 },
169 .name
= "Linksys WAP54G V3",
171 /* FIXME: verify this */
172 { .name
= "reset", .gpio
= 1 << 7 },
173 { .name
= "ses", .gpio
= 1 << 0 },
177 { .name
= "ses", .gpio
= 1 << 1 },
181 .name
= "Linksys WRT54G V1.x",
183 { .name
= "reset", .gpio
= 1 << 6 },
186 { .name
= "diag", .gpio
= 0x13 | GPIO_TYPE_EXTIF
, .polarity
= NORMAL
},
187 { .name
= "dmz", .gpio
= 0x12 | GPIO_TYPE_EXTIF
, .polarity
= NORMAL
},
191 .name
= "Linksys WRT54G/GS/GL",
193 { .name
= "reset", .gpio
= 1 << 6 },
194 { .name
= "ses", .gpio
= 1 << 4 },
197 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
198 { .name
= "dmz", .gpio
= 1 << 7, .polarity
= REVERSE
},
199 { .name
= "ses_white", .gpio
= 1 << 2, .polarity
= REVERSE
},
200 { .name
= "ses_orange", .gpio
= 1 << 3, .polarity
= REVERSE
},
201 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
205 .name
= "Linksys WRTSL54GS",
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 << 0, .polarity
= REVERSE
},
213 { .name
= "ses_white", .gpio
= 1 << 5, .polarity
= REVERSE
},
214 { .name
= "ses_orange", .gpio
= 1 << 7, .polarity
= REVERSE
},
218 .name
= "Linksys WRT54G3G",
220 { .name
= "reset", .gpio
= 1 << 6 },
221 { .name
= "3g", .gpio
= 1 << 4 },
224 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
225 { .name
= "dmz", .gpio
= 1 << 7, .polarity
= REVERSE
},
226 { .name
= "3g_green", .gpio
= 1 << 2, .polarity
= NORMAL
},
227 { .name
= "3g_blue", .gpio
= 1 << 3, .polarity
= NORMAL
},
228 { .name
= "3g_blink", .gpio
= 1 << 5, .polarity
= NORMAL
},
232 .name
= "Linksys WRT350N",
234 { .name
= "reset", .gpio
= 1 << 6 },
235 { .name
= "ses", .gpio
= 1 << 8 },
238 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
239 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
240 { .name
= "ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
},
241 { .name
= "usb_blink", .gpio
= 1 << 10, .polarity
= REVERSE
},
242 { .name
= "usb", .gpio
= 1 << 11, .polarity
= REVERSE
},
244 .platform_init
= bcm57xx_init
,
247 .name
= "Linksys WRT600N",
249 { .name
= "reset", .gpio
= 1 << 6 },
250 { .name
= "ses", .gpio
= 1 << 7 },
253 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
}, // Power LED
254 { .name
= "usb", .gpio
= 1 << 3, .polarity
= REVERSE
}, // USB LED
255 { .name
= "wl0_ses_amber", .gpio
= 1 << 8, .polarity
= REVERSE
}, // 2.4Ghz LED Amber
256 { .name
= "wl0_ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
}, // 2.4Ghz LED Green
257 { .name
= "wl1_ses_amber", .gpio
= 1 << 10, .polarity
= REVERSE
}, // 5.6Ghz LED Amber
258 { .name
= "wl1_ses_green", .gpio
= 1 << 11, .polarity
= REVERSE
}, // 5.6Ghz LED Green
260 .platform_init
= bcm57xx_init
,
263 .name
= "Linksys WRT600N V1.1",
265 { .name
= "reset", .gpio
= 1 << 6 },
266 { .name
= "ses", .gpio
= 1 << 7 },
269 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
}, // Power LED
270 { .name
= "usb", .gpio
= 1 << 3, .polarity
= REVERSE
}, // USB LED
271 { .name
= "wl0_ses_amber", .gpio
= 1 << 8, .polarity
= REVERSE
}, // 2.4Ghz LED Amber
272 { .name
= "wl0_ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
}, // 2.4Ghz LED Green
273 { .name
= "wl1_ses_amber", .gpio
= 1 << 10, .polarity
= REVERSE
}, // 5.6Ghz LED Amber
274 { .name
= "wl1_ses_green", .gpio
= 1 << 11, .polarity
= REVERSE
}, // 5.6Ghz LED Green
276 .platform_init
= bcm57xx_init
,
280 .name
= "ASUS WL-HDD",
282 { .name
= "reset", .gpio
= 1 << 6 },
285 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
286 { .name
= "usb", .gpio
= 1 << 2, .polarity
= NORMAL
},
290 .name
= "ASUS WL-300g",
292 { .name
= "reset", .gpio
= 1 << 6 },
295 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
299 .name
= "ASUS WL-500g",
301 { .name
= "reset", .gpio
= 1 << 6 },
304 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
308 .name
= "ASUS WL-500g Deluxe",
310 { .name
= "reset", .gpio
= 1 << 6 },
313 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
317 .name
= "ASUS WL-500g Premium",
319 { .name
= "reset", .gpio
= 1 << 0 },
320 { .name
= "ses", .gpio
= 1 << 4 },
323 { .name
= "power", .gpio
= 1 << 1, .polarity
= REVERSE
},
327 .name
= "ASUS WL-500g Premium V2",
329 { .name
= "reset", .gpio
= 1 << 2 },
330 { .name
= "ses", .gpio
= 1 << 3 },
333 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
334 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
338 .name
= "ASUS WL-500W",
340 { .name
= "reset", .gpio
= 1 << 6 },
341 { .name
= "ses", .gpio
= 1 << 7 },
344 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
348 .name
= "ASUS WL-520GC",
350 { .name
= "reset", .gpio
= 1 << 2 },
351 { .name
= "ses", .gpio
= 1 << 3 },
354 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
355 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
359 .name
= "ASUS WL-520gU",
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 (unknown, BCM4702)",
372 { .name
= "reset", .gpio
= 1 << 6 },
375 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
379 .name
= "ASUS WL-700gE",
381 { .name
= "reset", .gpio
= 1 << 7 }, // on back, hardwired, always resets device regardless OS state
382 { .name
= "ses", .gpio
= 1 << 4 }, // on back, actual name ezsetup
383 { .name
= "power", .gpio
= 1 << 0 }, // on front
384 { .name
= "copy", .gpio
= 1 << 6 }, // on front
388 // GPIO that controls power led also enables/disables some essential functions
391 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
}, // actual name power
393 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
395 .platform_init
= bcm4780_init
,
399 .name
= "Buffalo WHR-G54S",
401 { .name
= "reset", .gpio
= 1 << 4 },
402 { .name
= "bridge", .gpio
= 1 << 5 },
403 { .name
= "ses", .gpio
= 1 << 0 },
406 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
407 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
408 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
409 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
410 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
414 .name
= "Buffalo WBR2-G54",
417 { .name
= "reset", .gpio
= 1 << 7 },
420 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
424 .name
= "Buffalo WHR-HP-G54",
426 { .name
= "reset", .gpio
= 1 << 4 },
427 { .name
= "bridge", .gpio
= 1 << 5 },
428 { .name
= "ses", .gpio
= 1 << 0 },
431 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
432 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
433 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
434 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
435 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
439 .name
= "Buffalo WHR-G125",
441 { .name
= "reset", .gpio
= 1 << 4 },
442 { .name
= "bridge", .gpio
= 1 << 5 },
443 { .name
= "ses", .gpio
= 1 << 0 },
446 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
447 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
448 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
449 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
450 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
454 .name
= "Buffalo WHR2-A54G54",
456 { .name
= "reset", .gpio
= 1 << 4 },
459 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
463 .name
= "Buffalo WLA2-G54L",
466 { .name
= "reset", .gpio
= 1 << 7 },
469 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
473 .name
= "Buffalo WZR-G300N",
475 { .name
= "reset", .gpio
= 1 << 4 },
478 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
479 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
480 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
484 .name
= "Buffalo WZR-RS-G54",
486 { .name
= "ses", .gpio
= 1 << 0 },
487 { .name
= "reset", .gpio
= 1 << 4 },
490 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
491 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
492 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
496 .name
= "Buffalo WZR-RS-G54HP",
498 { .name
= "ses", .gpio
= 1 << 0 },
499 { .name
= "reset", .gpio
= 1 << 4 },
502 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
503 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
504 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
507 [BUFFALO_UNKNOWN
] = {
508 .name
= "Buffalo (unknown)",
510 { .name
= "reset", .gpio
= 1 << 7 },
513 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
516 [BUFFALO_UNKNOWN_4710
] = {
517 .name
= "Buffalo (unknown, BCM4710)",
519 { .name
= "reset", .gpio
= 1 << 4 },
522 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
527 .name
= "Siemens SE505 V1",
529 /* No usable buttons */
532 // { .name = "power", .gpio = 1 << 0 .polarity = REVERSE }, // Usable when retrofitting D26 (?)
533 { .name
= "dmz", .gpio
= 1 << 4, .polarity
= REVERSE
}, // actual name WWW
534 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
538 .name
= "Siemens SE505 V2",
540 /* No usable buttons */
543 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
544 { .name
= "dmz", .gpio
= 1 << 0, .polarity
= REVERSE
}, // actual name WWW
545 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
550 .name
= "U.S. Robotics USR5461",
552 /* No usable buttons */
555 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
556 { .name
= "printer", .gpio
= 1 << 1, .polarity
= REVERSE
},
561 .name
= "Dell TrueMobile 2300",
563 { .name
= "reset", .gpio
= 1 << 0 },
566 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
567 { .name
= "power", .gpio
= 1 << 7, .polarity
= REVERSE
},
571 .name
= "Dell TrueMobile 2300 v2",
573 { .name
= "reset", .gpio
= 1 << 0 },
576 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
577 { .name
= "power", .gpio
= 1 << 7, .polarity
= REVERSE
},
582 .name
= "Motorola WE800G",
584 { .name
= "reset", .gpio
= 1 << 0 },
587 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
588 { .name
= "diag", .gpio
= 1 << 2, .polarity
= REVERSE
},
589 { .name
= "wlan_amber", .gpio
= 1 << 1, .polarity
= NORMAL
},
593 .name
= "Motorola WR850G V1",
595 { .name
= "reset", .gpio
= 1 << 0 },
598 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
599 { .name
= "diag", .gpio
= 1 << 3, .polarity
= REVERSE
},
600 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= NORMAL
},
601 { .name
= "wlan_red", .gpio
= 1 << 5, .polarity
= REVERSE
},
602 { .name
= "wlan_green", .gpio
= 1 << 7, .polarity
= REVERSE
},
606 .name
= "Motorola WR850G V2/V3",
608 { .name
= "reset", .gpio
= 1 << 5 },
611 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
612 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
613 { .name
= "wan", .gpio
= 1 << 6, .polarity
= INPUT
},
614 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
618 .name
= "Motorola WR850GP",
620 { .name
= "reset", .gpio
= 1 << 5 },
623 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
624 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
625 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= REVERSE
},
626 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
632 .name
= "Belkin (unknown)",
633 /* FIXME: verify & add detection */
635 { .name
= "reset", .gpio
= 1 << 7 },
638 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
},
639 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= NORMAL
},
640 { .name
= "connected", .gpio
= 1 << 0, .polarity
= NORMAL
},
645 .name
= "Netgear WGT634U",
647 { .name
= "reset", .gpio
= 1 << 2 },
650 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
},
655 .name
= "Trendware TEW411BRP+",
657 { /* No usable buttons */ },
660 { .name
= "power", .gpio
= 1 << 7, .polarity
= NORMAL
},
661 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
},
662 { .name
= "bridge", .gpio
= 1 << 6, .polarity
= NORMAL
},
667 .name
= "SimpleTech SimpleShare NAS",
669 { .name
= "reset", .gpio
= 1 << 7 }, // on back, hardwired, always resets device regardless OS state
670 { .name
= "power", .gpio
= 1 << 0 }, // on back
673 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
675 .platform_init
= bcm4780_init
,
679 .name
= "D-Link DIR-130",
681 { .name
= "reset", .gpio
= 1 << 3},
682 { .name
= "reserved", .gpio
= 1 << 7},
685 { .name
= "diag", .gpio
= 1 << 0},
686 { .name
= "blue", .gpio
= 1 << 6},
690 .name
= "D-Link DIR-330",
692 { .name
= "reset", .gpio
= 1 << 3},
693 { .name
= "reserved", .gpio
= 1 << 7},
696 { .name
= "diag", .gpio
= 1 << 0},
697 { .name
= "usb", .gpio
= 1 << 4},
698 { .name
= "blue", .gpio
= 1 << 6},
702 .name
= "D-Link DWL-3150",
704 { .name
= "reset", .gpio
= 1 << 7},
707 { .name
= "diag", .gpio
= 1 << 2},
708 { .name
= "status", .gpio
= 1 << 1},
713 .name
= "Sitecom WL-105b",
715 { .name
= "reset", .gpio
= 1 << 10},
718 { .name
= "wlan", .gpio
= 1 << 4},
719 { .name
= "power", .gpio
= 1 << 3},
724 static struct platform_t __init
*platform_detect(void)
726 char *boardnum
, *boardtype
, *buf
;
728 if (strcmp(getvar("nvram_type"), "cfe") == 0)
729 return &platforms
[WGT634U
];
731 /* Look for a model identifier */
733 /* Based on "model_name" */
734 if ((buf
= nvram_get("model_name"))) {
735 if (!strcmp(buf
, "DIR-130"))
736 return &platforms
[DIR130
];
737 if (!strcmp(buf
, "DIR-330"))
738 return &platforms
[DIR330
];
741 /* Based on "model_no" */
742 if ((buf
= nvram_get("model_no"))) {
743 if (startswith(buf
,"WL700")) /* WL700* */
744 return &platforms
[WL700GE
];
747 /* Based on "hardware_version" */
748 if ((buf
= nvram_get("hardware_version"))) {
749 if (startswith(buf
,"WL500GPV2-")) /* WL500GPV2-* */
750 return &platforms
[WL500GPV2
];
751 if (startswith(buf
,"WL520GC-")) /* WL520GU-* */
752 return &platforms
[WL520GC
];
753 if (startswith(buf
,"WL520GU-")) /* WL520GU-* */
754 return &platforms
[WL520GU
];
757 /* Based on "ModelId" */
758 if ((buf
= nvram_get("ModelId"))) {
759 if (!strcmp(buf
, "WR850GP"))
760 return &platforms
[WR850GP
];
761 if (!strcmp(buf
, "WX-5565") && !strcmp(getvar("boardtype"),"bcm94710ap"))
762 return &platforms
[TM2300
]; /* Dell TrueMobile 2300 */
763 if (startswith(buf
,"WE800G")) /* WE800G* */
764 return &platforms
[WE800G
];
768 if ((buf
= (nvram_get("melco_id") ?: nvram_get("buffalo_id")))) {
769 /* Buffalo hardware, check id for specific hardware matches */
770 if (!strcmp(buf
, "29bb0332"))
771 return &platforms
[WBR2_G54
];
772 if (!strcmp(buf
, "29129"))
773 return &platforms
[WLA2_G54L
];
774 if (!strcmp(buf
, "30189"))
775 return &platforms
[WHR_HP_G54
];
776 if (!strcmp(buf
, "32093"))
777 return &platforms
[WHR_G125
];
778 if (!strcmp(buf
, "30182"))
779 return &platforms
[WHR_G54S
];
780 if (!strcmp(buf
, "290441dd"))
781 return &platforms
[WHR2_A54G54
];
782 if (!strcmp(buf
, "31120"))
783 return &platforms
[WZR_G300N
];
784 if (!strcmp(buf
, "30083"))
785 return &platforms
[WZR_RS_G54
];
786 if (!strcmp(buf
, "30103"))
787 return &platforms
[WZR_RS_G54HP
];
790 /* no easy model number, attempt to guess */
791 boardnum
= getvar("boardnum");
792 boardtype
= getvar("boardtype");
794 if (!strcmp(boardnum
, "20070615")) { /* Linksys WRT600N v1/V1.1 */
795 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "0") && !strcmp(getvar("switch_type"),"BCM5395"))
796 return &platforms
[WRT600NV11
];
798 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "0"))
799 return &platforms
[WRT600N
];
802 if (startswith(getvar("pmon_ver"), "CFE")) {
803 /* CFE based - newer hardware */
804 if (!strcmp(boardnum
, "42")) { /* Linksys */
805 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "1"))
806 return &platforms
[WRT350N
];
808 if (!strcmp(boardtype
, "0x0101") && !strcmp(getvar("boot_ver"), "v3.6"))
809 return &platforms
[WRT54G3G
];
811 if (!strcmp(getvar("et1phyaddr"),"5") && !strcmp(getvar("et1mdcport"), "1"))
812 return &platforms
[WRTSL54GS
];
814 /* default to WRT54G */
815 return &platforms
[WRT54G
];
818 if (!strcmp(boardnum
, "44") || !strcmp(boardnum
, "44\r")) {
819 if (!strcmp(boardtype
,"0x0101") || !strcmp(boardtype
, "0x0101\r"))
820 return &platforms
[TM2300V2
]; /* Dell TrueMobile 2300 v2 */
823 if (!strcmp(boardnum
, "45")) { /* ASUS */
824 if (!strcmp(boardtype
,"0x042f"))
825 return &platforms
[WL500GP
];
826 else if (!strcmp(boardtype
,"0x0472"))
827 return &platforms
[WL500W
];
829 return &platforms
[WL500GD
];
832 if (!strcmp(boardnum
, "10496"))
833 return &platforms
[USR5461
];
835 if (!strcmp(getvar("boardtype"), "0x0101") && !strcmp(getvar("boardrev"), "0x10")) /* SE505V2 With Modified CFE */
836 return &platforms
[SE505V2
];
838 } else { /* PMON based - old stuff */
839 if ((simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 9) &&
840 (simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 30)) {
841 return &platforms
[WR850GV1
];
843 if (startswith(boardtype
, "bcm94710dev")) {
844 if (!strcmp(boardnum
, "42"))
845 return &platforms
[WRT54GV1
];
846 if (simple_strtoul(boardnum
, NULL
, 0) == 2)
847 return &platforms
[WAP54GV1
];
849 if (startswith(getvar("hardware_version"), "WL500-"))
850 return &platforms
[WL500G
];
851 if (startswith(getvar("hardware_version"), "WL300-")) {
852 /* Either WL-300g or WL-HDD, do more extensive checks */
853 if ((simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 0) &&
854 (simple_strtoul(getvar("et1phyaddr"), NULL
, 0) == 1))
855 return &platforms
[WLHDD
];
856 if ((simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 0) &&
857 (simple_strtoul(getvar("et1phyaddr"), NULL
, 0) == 10))
858 return &platforms
[WL300G
];
860 /* Sitecom WL-105b */
861 if (startswith(boardnum
, "2") && simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 1)
862 return &platforms
[WL105B
];
864 /* unknown asus stuff, probably bcm4702 */
865 if (startswith(boardnum
, "asusX"))
866 return &platforms
[ASUS_4702
];
869 if (buf
|| !strcmp(boardnum
, "00")) {/* probably buffalo */
870 if (startswith(boardtype
, "bcm94710ap"))
871 return &platforms
[BUFFALO_UNKNOWN_4710
];
873 return &platforms
[BUFFALO_UNKNOWN
];
876 if (startswith(getvar("CFEver"), "MotoWRv2") ||
877 startswith(getvar("CFEver"), "MotoWRv3") ||
878 !strcmp(getvar("MOTO_BOARD_TYPE"), "WR_FEM1")) {
880 return &platforms
[WR850GV2V3
];
883 if (!strcmp(boardnum
, "44") && !strcmp(getvar("boardflags"),"0x0388")) { /* Trendware TEW-411BRP+ */
884 return &platforms
[TEW411BRPP
];
887 if (startswith(boardnum
, "04FN52")) /* SimpleTech SimpleShare */
888 return &platforms
[STI_NAS
];
890 if (!strcmp(getvar("boardnum"), "10") && !strcmp(getvar("boardrev"), "0x13")) /* D-Link DWL-3150 */
891 return &platforms
[DWL3150
];
897 static void register_buttons(struct button_t
*b
)
900 platform
.button_mask
|= b
->gpio
;
902 platform
.button_mask
&= ~gpiomask
;
904 gpio_outen(platform
.button_mask
, 0);
905 gpio_control(platform
.button_mask
, 0);
906 platform
.button_polarity
= gpio_in() & platform
.button_mask
;
907 gpio_intpolarity(platform
.button_mask
, platform
.button_polarity
);
908 gpio_intmask(platform
.button_mask
, platform
.button_mask
);
910 gpio_set_irqenable(1, button_handler
);
913 static void unregister_buttons(struct button_t
*b
)
915 gpio_intmask(platform
.button_mask
, 0);
917 gpio_set_irqenable(0, button_handler
);
922 static void add_msg(struct event_t
*event
, char *msg
, int argv
)
929 s
= skb_put(event
->skb
, strlen(msg
) + 1);
933 static void hotplug_button(struct work_struct
*work
)
935 struct event_t
*event
= container_of(work
, struct event_t
, wq
);
941 event
->skb
= alloc_skb(2048, GFP_KERNEL
);
943 s
= skb_put(event
->skb
, strlen(event
->action
) + 2);
944 sprintf(s
, "%s@", event
->action
);
947 NETLINK_CB(event
->skb
).dst_group
= 1;
948 netlink_broadcast(uevent_sock
, event
->skb
, 0, 1, GFP_KERNEL
);
953 #else /* !LINUX_2_4 */
954 static inline char *kzalloc(unsigned int size
, unsigned int gfp
)
958 p
= kmalloc(size
, gfp
);
967 static void add_msg(struct event_t
*event
, char *msg
, int argv
)
970 event
->argv
[event
->anr
++] = event
->scratch
;
972 event
->envp
[event
->enr
++] = event
->scratch
;
974 event
->scratch
+= sprintf(event
->scratch
, "%s", msg
) + 1;
977 static void hotplug_button(struct event_t
*event
)
979 char *scratch
= kzalloc(256, GFP_KERNEL
);
980 event
->scratch
= scratch
;
982 add_msg(event
, hotplug_path
, 1);
983 add_msg(event
, "button", 1);
985 call_usermodehelper (event
->argv
[0], event
->argv
, event
->envp
);
989 #endif /* !LINUX_2_4 */
991 static int fill_event (struct event_t
*event
)
993 static char buf
[128];
995 add_msg(event
, "HOME=/", 0);
996 add_msg(event
, "PATH=/sbin:/bin:/usr/sbin:/usr/bin", 0);
997 add_msg(event
, "SUBSYSTEM=button", 0);
998 snprintf(buf
, 128, "ACTION=%s", event
->action
);
999 add_msg(event
, buf
, 0);
1000 snprintf(buf
, 128, "BUTTON=%s", event
->name
);
1001 add_msg(event
, buf
, 0);
1002 snprintf(buf
, 128, "SEEN=%ld", event
->seen
);
1003 add_msg(event
, buf
, 0);
1005 snprintf(buf
, 128, "SEQNUM=%llu", uevent_next_seqnum());
1006 add_msg(event
, buf
, 0);
1014 static irqreturn_t
button_handler(int irq
, void *dev_id
)
1016 static irqreturn_t
button_handler(int irq
, void *dev_id
, struct pt_regs
*regs
)
1022 in
= gpio_in() & platform
.button_mask
;
1023 gpio_intpolarity(platform
.button_mask
, in
);
1024 changed
= platform
.button_polarity
^ in
;
1025 platform
.button_polarity
= in
;
1027 changed
&= ~gpio_outen(0, 0);
1029 for (b
= platform
.buttons
; b
->name
; b
++) {
1030 struct event_t
*event
;
1032 if (!(b
->gpio
& changed
)) continue;
1036 if ((event
= (struct event_t
*)kzalloc (sizeof(struct event_t
), GFP_ATOMIC
))) {
1037 event
->seen
= (jiffies
- b
->seen
)/HZ
;
1038 event
->name
= b
->name
;
1039 event
->action
= b
->pressed
? "pressed" : "released";
1040 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
1041 INIT_WORK(&event
->wq
, (void *)(void *)hotplug_button
);
1043 INIT_WORK(&event
->wq
, (void *)(void *)hotplug_button
, (void *)event
);
1045 schedule_work(&event
->wq
);
1053 static void register_leds(struct led_t
*l
)
1055 struct proc_dir_entry
*p
;
1060 leds
= proc_mkdir("led", diag
);
1064 for(; l
->name
; l
++) {
1065 if (l
->gpio
& gpiomask
)
1068 if (l
->gpio
& GPIO_TYPE_EXTIF
) {
1072 if (l
->polarity
!= INPUT
) oe_mask
|= l
->gpio
;
1074 val
|= (l
->polarity
== NORMAL
)?0:l
->gpio
;
1077 if (l
->polarity
== INPUT
) continue;
1079 if ((p
= create_proc_entry(l
->name
, S_IRUSR
, leds
))) {
1080 l
->proc
.type
= PROC_LED
;
1082 p
->data
= (void *) &l
->proc
;
1083 p
->proc_fops
= &diag_proc_fops
;
1087 gpio_outen(mask
, oe_mask
);
1088 gpio_control(mask
, 0);
1089 gpio_out(mask
, val
);
1090 gpio_intmask(mask
, 0);
1093 static void unregister_leds(struct led_t
*l
)
1096 remove_proc_entry(l
->name
, leds
);
1098 remove_proc_entry("led", diag
);
1101 static void set_led_extif(struct led_t
*led
)
1103 gpio_set_extif(led
->gpio
, led
->state
);
1106 static void led_flash(unsigned long dummy
) {
1111 for (l
= platform
.leds
; l
->name
; l
++) {
1113 if (l
->gpio
& GPIO_TYPE_EXTIF
) {
1115 l
->state
= !l
->state
;
1125 u32 val
= ~gpio_in();
1127 gpio_outen(mask
, mask
);
1128 gpio_control(mask
, 0);
1129 gpio_out(mask
, val
);
1131 if (mask
|| extif_blink
) {
1132 mod_timer(&led_timer
, jiffies
+ FLASH_TIME
);
1136 static ssize_t
diag_proc_read(struct file
*file
, char *buf
, size_t count
, loff_t
*ppos
)
1139 struct inode
*inode
= file
->f_dentry
->d_inode
;
1140 struct proc_dir_entry
*dent
= inode
->u
.generic_ip
;
1142 struct proc_dir_entry
*dent
= PDE(file
->f_dentry
->d_inode
);
1147 if ((page
= kmalloc(1024, GFP_KERNEL
)) == NULL
)
1150 if (dent
->data
!= NULL
) {
1151 struct prochandler_t
*handler
= (struct prochandler_t
*) dent
->data
;
1152 switch (handler
->type
) {
1154 struct led_t
* led
= (struct led_t
*) handler
->ptr
;
1156 len
= sprintf(page
, "f\n");
1158 if (led
->gpio
& GPIO_TYPE_EXTIF
) {
1159 len
= sprintf(page
, "%d\n", led
->state
);
1161 u32 in
= (gpio_in() & led
->gpio
? 1 : 0);
1162 u8 p
= (led
->polarity
== NORMAL
? 0 : 1);
1163 len
= sprintf(page
, "%d\n", ((in
^ p
) ? 1 : 0));
1169 len
= sprintf(page
, "%s\n", platform
.name
);
1172 len
= sprintf(page
, "0x%04x\n", gpiomask
);
1179 len
= min_t(int, len
- *ppos
, count
);
1180 if (copy_to_user(buf
, (page
+ *ppos
), len
)) {
1194 static ssize_t
diag_proc_write(struct file
*file
, const char *buf
, size_t count
, loff_t
*ppos
)
1197 struct inode
*inode
= file
->f_dentry
->d_inode
;
1198 struct proc_dir_entry
*dent
= inode
->u
.generic_ip
;
1200 struct proc_dir_entry
*dent
= PDE(file
->f_dentry
->d_inode
);
1205 if ((page
= kmalloc(count
+ 1, GFP_KERNEL
)) == NULL
)
1208 if (copy_from_user(page
, buf
, count
)) {
1214 if (dent
->data
!= NULL
) {
1215 struct prochandler_t
*handler
= (struct prochandler_t
*) dent
->data
;
1216 switch (handler
->type
) {
1218 struct led_t
*led
= (struct led_t
*) handler
->ptr
;
1219 int p
= (led
->polarity
== NORMAL
? 0 : 1);
1221 if (page
[0] == 'f') {
1226 if (led
->gpio
& GPIO_TYPE_EXTIF
) {
1227 led
->state
= p
^ ((page
[0] == '1') ? 1 : 0);
1230 gpio_outen(led
->gpio
, led
->gpio
);
1231 gpio_control(led
->gpio
, 0);
1232 gpio_out(led
->gpio
, ((p
^ (page
[0] == '1')) ? led
->gpio
: 0));
1238 gpiomask
= simple_strtoul(page
, NULL
, 0);
1240 if (platform
.buttons
) {
1241 unregister_buttons(platform
.buttons
);
1242 register_buttons(platform
.buttons
);
1245 if (platform
.leds
) {
1246 unregister_leds(platform
.leds
);
1247 register_leds(platform
.leds
);
1258 static int __init
diag_init(void)
1260 static struct proc_dir_entry
*p
;
1261 static struct platform_t
*detected
;
1263 detected
= platform_detect();
1265 printk(MODULE_NAME
": Router model not detected.\n");
1268 memcpy(&platform
, detected
, sizeof(struct platform_t
));
1270 printk(MODULE_NAME
": Detected '%s'\n", platform
.name
);
1271 if (platform
.platform_init
!= NULL
) {
1272 platform
.platform_init();
1275 if (!(diag
= proc_mkdir("diag", NULL
))) {
1276 printk(MODULE_NAME
": proc_mkdir on /proc/diag failed\n");
1280 if ((p
= create_proc_entry("model", S_IRUSR
, diag
))) {
1281 p
->data
= (void *) &proc_model
;
1282 p
->proc_fops
= &diag_proc_fops
;
1285 if ((p
= create_proc_entry("gpiomask", S_IRUSR
| S_IWUSR
, diag
))) {
1286 p
->data
= (void *) &proc_gpiomask
;
1287 p
->proc_fops
= &diag_proc_fops
;
1290 if (platform
.buttons
)
1291 register_buttons(platform
.buttons
);
1294 register_leds(platform
.leds
);
1299 static void __exit
diag_exit(void)
1301 del_timer(&led_timer
);
1303 if (platform
.buttons
)
1304 unregister_buttons(platform
.buttons
);
1307 unregister_leds(platform
.leds
);
1309 remove_proc_entry("model", diag
);
1310 remove_proc_entry("gpiomask", diag
);
1311 remove_proc_entry("diag", NULL
);
1314 module_init(diag_init
);
1315 module_exit(diag_exit
);
1317 MODULE_AUTHOR("Mike Baker, Felix Fietkau / OpenWrt.org");
1318 MODULE_LICENSE("GPL");