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);
128 static void __init
bcm4780_init(void) {
131 /* Enables GPIO 3 that controls HDD and led power on ASUS WL-700gE */
132 printk(MODULE_NAME
": Spinning up HDD and enabling leds\n");
133 gpio_outen(pin
, pin
);
134 gpio_control(pin
, 0);
137 /* Wait 5s, so the HDD can spin up */
138 set_current_state(TASK_INTERRUPTIBLE
);
139 schedule_timeout(HZ
* 5);
142 static void __init
bcm57xx_init(void) {
146 /* FIXME: switch comes up, but port mappings/vlans not right */
147 gpio_outen(pin
, pin
);
148 gpio_control(pin
, 0);
153 static struct platform_t __initdata platforms
[] = {
156 .name
= "Linksys WAP54G V1",
158 { .name
= "reset", .gpio
= 1 << 0 },
161 { .name
= "diag", .gpio
= 1 << 3 },
162 { .name
= "wlan", .gpio
= 1 << 4 },
166 .name
= "Linksys WAP54G V3",
168 /* FIXME: verify this */
169 { .name
= "reset", .gpio
= 1 << 7 },
170 { .name
= "ses", .gpio
= 1 << 0 },
174 { .name
= "ses", .gpio
= 1 << 1 },
178 .name
= "Linksys WRT54G V1.x",
180 { .name
= "reset", .gpio
= 1 << 6 },
183 { .name
= "diag", .gpio
= 0x13 | GPIO_TYPE_EXTIF
, .polarity
= NORMAL
},
184 { .name
= "dmz", .gpio
= 0x12 | GPIO_TYPE_EXTIF
, .polarity
= NORMAL
},
188 .name
= "Linksys WRT54G/GS/GL",
190 { .name
= "reset", .gpio
= 1 << 6 },
191 { .name
= "ses", .gpio
= 1 << 4 },
194 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
195 { .name
= "dmz", .gpio
= 1 << 7, .polarity
= REVERSE
},
196 { .name
= "ses_white", .gpio
= 1 << 2, .polarity
= REVERSE
},
197 { .name
= "ses_orange", .gpio
= 1 << 3, .polarity
= REVERSE
},
198 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
202 .name
= "Linksys WRTSL54GS",
204 { .name
= "reset", .gpio
= 1 << 6 },
205 { .name
= "ses", .gpio
= 1 << 4 },
208 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
209 { .name
= "dmz", .gpio
= 1 << 0, .polarity
= REVERSE
},
210 { .name
= "ses_white", .gpio
= 1 << 5, .polarity
= REVERSE
},
211 { .name
= "ses_orange", .gpio
= 1 << 7, .polarity
= REVERSE
},
215 .name
= "Linksys WRT54G3G",
217 { .name
= "reset", .gpio
= 1 << 6 },
218 { .name
= "3g", .gpio
= 1 << 4 },
221 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
222 { .name
= "dmz", .gpio
= 1 << 7, .polarity
= REVERSE
},
223 { .name
= "3g_green", .gpio
= 1 << 2, .polarity
= NORMAL
},
224 { .name
= "3g_blue", .gpio
= 1 << 3, .polarity
= NORMAL
},
225 { .name
= "3g_blink", .gpio
= 1 << 5, .polarity
= NORMAL
},
229 .name
= "Linksys WRT350N",
231 { .name
= "reset", .gpio
= 1 << 6 },
232 { .name
= "ses", .gpio
= 1 << 8 },
235 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
236 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
237 { .name
= "ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
},
238 { .name
= "usb_blink", .gpio
= 1 << 10, .polarity
= REVERSE
},
239 { .name
= "usb", .gpio
= 1 << 11, .polarity
= REVERSE
},
241 .platform_init
= bcm57xx_init
,
245 .name
= "ASUS WL-HDD",
247 { .name
= "reset", .gpio
= 1 << 6 },
250 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
251 { .name
= "usb", .gpio
= 1 << 2, .polarity
= NORMAL
},
255 .name
= "ASUS WL-300g",
257 { .name
= "reset", .gpio
= 1 << 6 },
260 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
264 .name
= "ASUS WL-500g",
266 { .name
= "reset", .gpio
= 1 << 6 },
269 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
273 .name
= "ASUS WL-500g Deluxe",
275 { .name
= "reset", .gpio
= 1 << 6 },
278 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
282 .name
= "ASUS WL-500g Premium",
284 { .name
= "reset", .gpio
= 1 << 0 },
285 { .name
= "ses", .gpio
= 1 << 4 },
288 { .name
= "power", .gpio
= 1 << 1, .polarity
= REVERSE
},
292 .name
= "ASUS WL-500g Premium V2",
294 { .name
= "reset", .gpio
= 1 << 2 },
295 { .name
= "ses", .gpio
= 1 << 3 },
298 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
299 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
303 .name
= "ASUS WL-500W",
305 { .name
= "reset", .gpio
= 1 << 6 },
306 { .name
= "ses", .gpio
= 1 << 7 },
309 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
313 .name
= "ASUS WL-520GC",
315 { .name
= "reset", .gpio
= 1 << 2 },
316 { .name
= "ses", .gpio
= 1 << 3 },
319 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
320 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
324 .name
= "ASUS WL-520gU",
326 { .name
= "reset", .gpio
= 1 << 2 },
327 { .name
= "ses", .gpio
= 1 << 3 },
330 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
331 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
335 .name
= "ASUS (unknown, BCM4702)",
337 { .name
= "reset", .gpio
= 1 << 6 },
340 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
344 .name
= "ASUS WL-700gE",
346 { .name
= "reset", .gpio
= 1 << 7 }, // on back, hardwired, always resets device regardless OS state
347 { .name
= "ses", .gpio
= 1 << 4 }, // on back, actual name ezsetup
348 { .name
= "power", .gpio
= 1 << 0 }, // on front
349 { .name
= "copy", .gpio
= 1 << 6 }, // on front
353 // GPIO that controls power led also enables/disables some essential functions
356 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
}, // actual name power
358 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
360 .platform_init
= bcm4780_init
,
364 .name
= "Buffalo WHR-G54S",
366 { .name
= "reset", .gpio
= 1 << 4 },
367 { .name
= "bridge", .gpio
= 1 << 5 },
368 { .name
= "ses", .gpio
= 1 << 0 },
371 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
372 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
373 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
374 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
375 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
379 .name
= "Buffalo WBR2-G54",
382 { .name
= "reset", .gpio
= 1 << 7 },
385 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
389 .name
= "Buffalo WHR-HP-G54",
391 { .name
= "reset", .gpio
= 1 << 4 },
392 { .name
= "bridge", .gpio
= 1 << 5 },
393 { .name
= "ses", .gpio
= 1 << 0 },
396 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
397 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
398 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
399 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
400 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
404 .name
= "Buffalo WHR-G125",
406 { .name
= "reset", .gpio
= 1 << 4 },
407 { .name
= "bridge", .gpio
= 1 << 5 },
408 { .name
= "ses", .gpio
= 1 << 0 },
411 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
412 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
413 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
414 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
415 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
419 .name
= "Buffalo WHR2-A54G54",
421 { .name
= "reset", .gpio
= 1 << 4 },
424 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
428 .name
= "Buffalo WLA2-G54L",
431 { .name
= "reset", .gpio
= 1 << 7 },
434 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
438 .name
= "Buffalo WZR-G300N",
440 { .name
= "reset", .gpio
= 1 << 4 },
443 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
444 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
445 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
449 .name
= "Buffalo WZR-RS-G54",
451 { .name
= "ses", .gpio
= 1 << 0 },
452 { .name
= "reset", .gpio
= 1 << 4 },
455 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
456 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
457 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
461 .name
= "Buffalo WZR-RS-G54HP",
463 { .name
= "ses", .gpio
= 1 << 0 },
464 { .name
= "reset", .gpio
= 1 << 4 },
467 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
468 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
469 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
472 [BUFFALO_UNKNOWN
] = {
473 .name
= "Buffalo (unknown)",
475 { .name
= "reset", .gpio
= 1 << 7 },
478 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
481 [BUFFALO_UNKNOWN_4710
] = {
482 .name
= "Buffalo (unknown, BCM4710)",
484 { .name
= "reset", .gpio
= 1 << 4 },
487 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
492 .name
= "Siemens SE505 V1",
494 /* No usable buttons */
497 // { .name = "power", .gpio = 1 << 0 .polarity = REVERSE }, // Usable when retrofitting D26 (?)
498 { .name
= "dmz", .gpio
= 1 << 4, .polarity
= REVERSE
}, // actual name WWW
499 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
503 .name
= "Siemens SE505 V2",
505 /* No usable buttons */
508 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
509 { .name
= "dmz", .gpio
= 1 << 0, .polarity
= REVERSE
}, // actual name WWW
510 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
515 .name
= "U.S. Robotics USR5461",
517 /* No usable buttons */
520 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
521 { .name
= "printer", .gpio
= 1 << 1, .polarity
= REVERSE
},
526 .name
= "Dell TrueMobile 2300",
528 { .name
= "reset", .gpio
= 1 << 0 },
531 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
532 { .name
= "power", .gpio
= 1 << 7, .polarity
= REVERSE
},
537 .name
= "Motorola WE800G",
539 { .name
= "reset", .gpio
= 1 << 0 },
542 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
543 { .name
= "diag", .gpio
= 1 << 2, .polarity
= REVERSE
},
544 { .name
= "wlan_amber", .gpio
= 1 << 1, .polarity
= NORMAL
},
548 .name
= "Motorola WR850G V1",
550 { .name
= "reset", .gpio
= 1 << 0 },
553 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
554 { .name
= "diag", .gpio
= 1 << 3, .polarity
= REVERSE
},
555 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= NORMAL
},
556 { .name
= "wlan_red", .gpio
= 1 << 5, .polarity
= REVERSE
},
557 { .name
= "wlan_green", .gpio
= 1 << 7, .polarity
= REVERSE
},
561 .name
= "Motorola WR850G V2/V3",
563 { .name
= "reset", .gpio
= 1 << 5 },
566 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
567 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
568 { .name
= "wan", .gpio
= 1 << 6, .polarity
= INPUT
},
569 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
573 .name
= "Motorola WR850GP",
575 { .name
= "reset", .gpio
= 1 << 5 },
578 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
579 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
580 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= REVERSE
},
581 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
587 .name
= "Belkin (unknown)",
588 /* FIXME: verify & add detection */
590 { .name
= "reset", .gpio
= 1 << 7 },
593 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
},
594 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= NORMAL
},
595 { .name
= "connected", .gpio
= 1 << 0, .polarity
= NORMAL
},
600 .name
= "Netgear WGT634U",
602 { .name
= "reset", .gpio
= 1 << 2 },
605 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
},
610 .name
= "Trendware TEW411BRP+",
612 { /* No usable buttons */ },
615 { .name
= "power", .gpio
= 1 << 7, .polarity
= NORMAL
},
616 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
},
617 { .name
= "bridge", .gpio
= 1 << 6, .polarity
= NORMAL
},
622 .name
= "SimpleTech SimpleShare NAS",
624 { .name
= "reset", .gpio
= 1 << 7 }, // on back, hardwired, always resets device regardless OS state
625 { .name
= "power", .gpio
= 1 << 0 }, // on back
628 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
630 .platform_init
= bcm4780_init
,
634 .name
= "D-Link DIR-130",
636 { .name
= "reset", .gpio
= 1 << 3},
637 { .name
= "reserved", .gpio
= 1 << 7},
640 { .name
= "diag", .gpio
= 1 << 0},
641 { .name
= "blue", .gpio
= 1 << 6},
645 .name
= "D-Link DIR-330",
647 { .name
= "reset", .gpio
= 1 << 3},
648 { .name
= "reserved", .gpio
= 1 << 7},
651 { .name
= "diag", .gpio
= 1 << 0},
652 { .name
= "usb", .gpio
= 1 << 4},
653 { .name
= "blue", .gpio
= 1 << 6},
657 .name
= "D-Link DWL-3150",
659 { .name
= "reset", .gpio
= 1 << 7},
662 { .name
= "diag", .gpio
= 1 << 2},
663 { .name
= "status", .gpio
= 1 << 1},
668 .name
= "Sitecom WL-105b",
670 { .name
= "reset", .gpio
= 1 << 10},
673 { .name
= "wlan", .gpio
= 1 << 4},
674 { .name
= "power", .gpio
= 1 << 3},
679 static struct platform_t __init
*platform_detect(void)
681 char *boardnum
, *boardtype
, *buf
;
683 if (strcmp(getvar("nvram_type"), "cfe") == 0)
684 return &platforms
[WGT634U
];
686 /* Look for a model identifier */
688 /* Based on "model_name" */
689 if ((buf
= nvram_get("model_name"))) {
690 if (!strcmp(buf
, "DIR-130"))
691 return &platforms
[DIR130
];
692 if (!strcmp(buf
, "DIR-330"))
693 return &platforms
[DIR330
];
696 /* Based on "model_no" */
697 if ((buf
= nvram_get("model_no"))) {
698 if (startswith(buf
,"WL700")) /* WL700* */
699 return &platforms
[WL700GE
];
702 /* Based on "hardware_version" */
703 if ((buf
= nvram_get("hardware_version"))) {
704 if (startswith(buf
,"WL500GPV2-")) /* WL500GPV2-* */
705 return &platforms
[WL500GPV2
];
706 if (startswith(buf
,"WL520GC-")) /* WL520GU-* */
707 return &platforms
[WL520GC
];
708 if (startswith(buf
,"WL520GU-")) /* WL520GU-* */
709 return &platforms
[WL520GU
];
712 /* Based on "ModelId" */
713 if ((buf
= nvram_get("ModelId"))) {
714 if (!strcmp(buf
, "WR850GP"))
715 return &platforms
[WR850GP
];
716 if (!strcmp(buf
,"WX-5565"))
717 return &platforms
[TM2300
];
718 if (startswith(buf
,"WE800G")) /* WE800G* */
719 return &platforms
[WE800G
];
723 if ((buf
= (nvram_get("melco_id") ?: nvram_get("buffalo_id")))) {
724 /* Buffalo hardware, check id for specific hardware matches */
725 if (!strcmp(buf
, "29bb0332"))
726 return &platforms
[WBR2_G54
];
727 if (!strcmp(buf
, "29129"))
728 return &platforms
[WLA2_G54L
];
729 if (!strcmp(buf
, "30189"))
730 return &platforms
[WHR_HP_G54
];
731 if (!strcmp(buf
, "32093"))
732 return &platforms
[WHR_G125
];
733 if (!strcmp(buf
, "30182"))
734 return &platforms
[WHR_G54S
];
735 if (!strcmp(buf
, "290441dd"))
736 return &platforms
[WHR2_A54G54
];
737 if (!strcmp(buf
, "31120"))
738 return &platforms
[WZR_G300N
];
739 if (!strcmp(buf
, "30083"))
740 return &platforms
[WZR_RS_G54
];
741 if (!strcmp(buf
, "30103"))
742 return &platforms
[WZR_RS_G54HP
];
745 /* no easy model number, attempt to guess */
746 boardnum
= getvar("boardnum");
747 boardtype
= getvar("boardtype");
749 if (startswith(getvar("pmon_ver"), "CFE")) {
750 /* CFE based - newer hardware */
751 if (!strcmp(boardnum
, "42")) { /* Linksys */
752 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "1"))
753 return &platforms
[WRT350N
];
755 if (!strcmp(boardtype
, "0x0101") && !strcmp(getvar("boot_ver"), "v3.6"))
756 return &platforms
[WRT54G3G
];
758 if (!strcmp(getvar("et1phyaddr"),"5") && !strcmp(getvar("et1mdcport"), "1"))
759 return &platforms
[WRTSL54GS
];
761 /* default to WRT54G */
762 return &platforms
[WRT54G
];
765 if (!strcmp(boardnum
, "45")) { /* ASUS */
766 if (!strcmp(boardtype
,"0x042f"))
767 return &platforms
[WL500GP
];
768 else if (!strcmp(boardtype
,"0x0472"))
769 return &platforms
[WL500W
];
771 return &platforms
[WL500GD
];
774 if (!strcmp(boardnum
, "10496"))
775 return &platforms
[USR5461
];
777 if (!strcmp(getvar("boardtype"), "0x0101") && !strcmp(getvar("boardrev"), "0x10")) /* SE505V2 With Modified CFE */
778 return &platforms
[SE505V2
];
780 } else { /* PMON based - old stuff */
781 if ((simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 9) &&
782 (simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 30)) {
783 return &platforms
[WR850GV1
];
785 if (startswith(boardtype
, "bcm94710dev")) {
786 if (!strcmp(boardnum
, "42"))
787 return &platforms
[WRT54GV1
];
788 if (simple_strtoul(boardnum
, NULL
, 0) == 2)
789 return &platforms
[WAP54GV1
];
791 if (startswith(getvar("hardware_version"), "WL500-"))
792 return &platforms
[WL500G
];
793 if (startswith(getvar("hardware_version"), "WL300-")) {
794 /* Either WL-300g or WL-HDD, do more extensive checks */
795 if ((simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 0) &&
796 (simple_strtoul(getvar("et1phyaddr"), NULL
, 0) == 1))
797 return &platforms
[WLHDD
];
798 if ((simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 0) &&
799 (simple_strtoul(getvar("et1phyaddr"), NULL
, 0) == 10))
800 return &platforms
[WL300G
];
802 /* Sitecom WL-105b */
803 if (startswith(boardnum
, "2") && simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 1)
804 return &platforms
[WL105B
];
806 /* unknown asus stuff, probably bcm4702 */
807 if (startswith(boardnum
, "asusX"))
808 return &platforms
[ASUS_4702
];
811 if (buf
|| !strcmp(boardnum
, "00")) {/* probably buffalo */
812 if (startswith(boardtype
, "bcm94710ap"))
813 return &platforms
[BUFFALO_UNKNOWN_4710
];
815 return &platforms
[BUFFALO_UNKNOWN
];
818 if (startswith(getvar("CFEver"), "MotoWRv2") ||
819 startswith(getvar("CFEver"), "MotoWRv3") ||
820 !strcmp(getvar("MOTO_BOARD_TYPE"), "WR_FEM1")) {
822 return &platforms
[WR850GV2V3
];
825 if (!strcmp(boardnum
, "44") && !strcmp(getvar("boardflags"),"0x0388")) { /* Trendware TEW-411BRP+ */
826 return &platforms
[TEW411BRPP
];
829 if (startswith(boardnum
, "04FN52")) /* SimpleTech SimpleShare */
830 return &platforms
[STI_NAS
];
832 if (!strcmp(getvar("boardnum"), "10") && !strcmp(getvar("boardrev"), "0x13")) /* D-Link DWL-3150 */
833 return &platforms
[DWL3150
];
839 static void register_buttons(struct button_t
*b
)
842 platform
.button_mask
|= b
->gpio
;
844 platform
.button_mask
&= ~gpiomask
;
846 gpio_outen(platform
.button_mask
, 0);
847 gpio_control(platform
.button_mask
, 0);
848 platform
.button_polarity
= gpio_in() & platform
.button_mask
;
849 gpio_intpolarity(platform
.button_mask
, platform
.button_polarity
);
850 gpio_intmask(platform
.button_mask
, platform
.button_mask
);
852 gpio_set_irqenable(1, button_handler
);
855 static void unregister_buttons(struct button_t
*b
)
857 gpio_intmask(platform
.button_mask
, 0);
859 gpio_set_irqenable(0, button_handler
);
864 static void add_msg(struct event_t
*event
, char *msg
, int argv
)
871 s
= skb_put(event
->skb
, strlen(msg
) + 1);
875 static void hotplug_button(struct work_struct
*work
)
877 struct event_t
*event
= container_of(work
, struct event_t
, wq
);
883 event
->skb
= alloc_skb(2048, GFP_KERNEL
);
885 s
= skb_put(event
->skb
, strlen(event
->action
) + 2);
886 sprintf(s
, "%s@", event
->action
);
889 NETLINK_CB(event
->skb
).dst_group
= 1;
890 netlink_broadcast(uevent_sock
, event
->skb
, 0, 1, GFP_KERNEL
);
895 #else /* !LINUX_2_4 */
896 static inline char *kzalloc(unsigned int size
, unsigned int gfp
)
900 p
= kmalloc(size
, gfp
);
909 static void add_msg(struct event_t
*event
, char *msg
, int argv
)
912 event
->argv
[event
->anr
++] = event
->scratch
;
914 event
->envp
[event
->enr
++] = event
->scratch
;
916 event
->scratch
+= sprintf(event
->scratch
, "%s", msg
) + 1;
919 static void hotplug_button(struct event_t
*event
)
921 char *scratch
= kzalloc(256, GFP_KERNEL
);
922 event
->scratch
= scratch
;
924 add_msg(event
, hotplug_path
, 1);
925 add_msg(event
, "button", 1);
927 call_usermodehelper (event
->argv
[0], event
->argv
, event
->envp
);
931 #endif /* !LINUX_2_4 */
933 static int fill_event (struct event_t
*event
)
935 static char buf
[128];
937 add_msg(event
, "HOME=/", 0);
938 add_msg(event
, "PATH=/sbin:/bin:/usr/sbin:/usr/bin", 0);
939 add_msg(event
, "SUBSYSTEM=button", 0);
940 snprintf(buf
, 128, "ACTION=%s", event
->action
);
941 add_msg(event
, buf
, 0);
942 snprintf(buf
, 128, "BUTTON=%s", event
->name
);
943 add_msg(event
, buf
, 0);
944 snprintf(buf
, 128, "SEEN=%ld", event
->seen
);
945 add_msg(event
, buf
, 0);
947 snprintf(buf
, 128, "SEQNUM=%llu", uevent_next_seqnum());
948 add_msg(event
, buf
, 0);
956 static irqreturn_t
button_handler(int irq
, void *dev_id
)
958 static irqreturn_t
button_handler(int irq
, void *dev_id
, struct pt_regs
*regs
)
964 in
= gpio_in() & platform
.button_mask
;
965 gpio_intpolarity(platform
.button_mask
, in
);
966 changed
= platform
.button_polarity
^ in
;
967 platform
.button_polarity
= in
;
969 changed
&= ~gpio_outen(0, 0);
971 for (b
= platform
.buttons
; b
->name
; b
++) {
972 struct event_t
*event
;
974 if (!(b
->gpio
& changed
)) continue;
978 if ((event
= (struct event_t
*)kzalloc (sizeof(struct event_t
), GFP_ATOMIC
))) {
979 event
->seen
= (jiffies
- b
->seen
)/HZ
;
980 event
->name
= b
->name
;
981 event
->action
= b
->pressed
? "pressed" : "released";
982 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
983 INIT_WORK(&event
->wq
, (void *)(void *)hotplug_button
);
985 INIT_WORK(&event
->wq
, (void *)(void *)hotplug_button
, (void *)event
);
987 schedule_work(&event
->wq
);
995 static void register_leds(struct led_t
*l
)
997 struct proc_dir_entry
*p
;
1002 leds
= proc_mkdir("led", diag
);
1006 for(; l
->name
; l
++) {
1007 if (l
->gpio
& gpiomask
)
1010 if (l
->gpio
& GPIO_TYPE_EXTIF
) {
1014 if (l
->polarity
!= INPUT
) oe_mask
|= l
->gpio
;
1016 val
|= (l
->polarity
== NORMAL
)?0:l
->gpio
;
1019 if (l
->polarity
== INPUT
) continue;
1021 if ((p
= create_proc_entry(l
->name
, S_IRUSR
, leds
))) {
1022 l
->proc
.type
= PROC_LED
;
1024 p
->data
= (void *) &l
->proc
;
1025 p
->proc_fops
= &diag_proc_fops
;
1029 gpio_outen(mask
, oe_mask
);
1030 gpio_control(mask
, 0);
1031 gpio_out(mask
, val
);
1034 static void unregister_leds(struct led_t
*l
)
1037 remove_proc_entry(l
->name
, leds
);
1039 remove_proc_entry("led", diag
);
1042 static void set_led_extif(struct led_t
*led
)
1044 gpio_set_extif(led
->gpio
, led
->state
);
1047 static void led_flash(unsigned long dummy
) {
1052 for (l
= platform
.leds
; l
->name
; l
++) {
1054 if (l
->gpio
& GPIO_TYPE_EXTIF
) {
1056 l
->state
= !l
->state
;
1066 u32 val
= ~gpio_in();
1068 gpio_outen(mask
, mask
);
1069 gpio_control(mask
, 0);
1070 gpio_out(mask
, val
);
1072 if (mask
|| extif_blink
) {
1073 mod_timer(&led_timer
, jiffies
+ FLASH_TIME
);
1077 static ssize_t
diag_proc_read(struct file
*file
, char *buf
, size_t count
, loff_t
*ppos
)
1080 struct inode
*inode
= file
->f_dentry
->d_inode
;
1081 struct proc_dir_entry
*dent
= inode
->u
.generic_ip
;
1083 struct proc_dir_entry
*dent
= PDE(file
->f_dentry
->d_inode
);
1088 if ((page
= kmalloc(1024, GFP_KERNEL
)) == NULL
)
1091 if (dent
->data
!= NULL
) {
1092 struct prochandler_t
*handler
= (struct prochandler_t
*) dent
->data
;
1093 switch (handler
->type
) {
1095 struct led_t
* led
= (struct led_t
*) handler
->ptr
;
1097 len
= sprintf(page
, "f\n");
1099 if (led
->gpio
& GPIO_TYPE_EXTIF
) {
1100 len
= sprintf(page
, "%d\n", led
->state
);
1102 u32 in
= (gpio_in() & led
->gpio
? 1 : 0);
1103 u8 p
= (led
->polarity
== NORMAL
? 0 : 1);
1104 len
= sprintf(page
, "%d\n", ((in
^ p
) ? 1 : 0));
1110 len
= sprintf(page
, "%s\n", platform
.name
);
1113 len
= sprintf(page
, "0x%04x\n", gpiomask
);
1120 len
= min_t(int, len
- *ppos
, count
);
1121 if (copy_to_user(buf
, (page
+ *ppos
), len
)) {
1135 static ssize_t
diag_proc_write(struct file
*file
, const char *buf
, size_t count
, loff_t
*ppos
)
1138 struct inode
*inode
= file
->f_dentry
->d_inode
;
1139 struct proc_dir_entry
*dent
= inode
->u
.generic_ip
;
1141 struct proc_dir_entry
*dent
= PDE(file
->f_dentry
->d_inode
);
1146 if ((page
= kmalloc(count
+ 1, GFP_KERNEL
)) == NULL
)
1149 if (copy_from_user(page
, buf
, count
)) {
1155 if (dent
->data
!= NULL
) {
1156 struct prochandler_t
*handler
= (struct prochandler_t
*) dent
->data
;
1157 switch (handler
->type
) {
1159 struct led_t
*led
= (struct led_t
*) handler
->ptr
;
1160 int p
= (led
->polarity
== NORMAL
? 0 : 1);
1162 if (page
[0] == 'f') {
1167 if (led
->gpio
& GPIO_TYPE_EXTIF
) {
1168 led
->state
= p
^ ((page
[0] == '1') ? 1 : 0);
1171 gpio_outen(led
->gpio
, led
->gpio
);
1172 gpio_control(led
->gpio
, 0);
1173 gpio_out(led
->gpio
, ((p
^ (page
[0] == '1')) ? led
->gpio
: 0));
1179 gpiomask
= simple_strtoul(page
, NULL
, 0);
1181 if (platform
.buttons
) {
1182 unregister_buttons(platform
.buttons
);
1183 register_buttons(platform
.buttons
);
1186 if (platform
.leds
) {
1187 unregister_leds(platform
.leds
);
1188 register_leds(platform
.leds
);
1199 static int __init
diag_init(void)
1201 static struct proc_dir_entry
*p
;
1202 static struct platform_t
*detected
;
1204 detected
= platform_detect();
1206 printk(MODULE_NAME
": Router model not detected.\n");
1209 memcpy(&platform
, detected
, sizeof(struct platform_t
));
1211 printk(MODULE_NAME
": Detected '%s'\n", platform
.name
);
1212 if (platform
.platform_init
!= NULL
) {
1213 platform
.platform_init();
1216 if (!(diag
= proc_mkdir("diag", NULL
))) {
1217 printk(MODULE_NAME
": proc_mkdir on /proc/diag failed\n");
1221 if ((p
= create_proc_entry("model", S_IRUSR
, diag
))) {
1222 p
->data
= (void *) &proc_model
;
1223 p
->proc_fops
= &diag_proc_fops
;
1226 if ((p
= create_proc_entry("gpiomask", S_IRUSR
| S_IWUSR
, diag
))) {
1227 p
->data
= (void *) &proc_gpiomask
;
1228 p
->proc_fops
= &diag_proc_fops
;
1231 if (platform
.buttons
)
1232 register_buttons(platform
.buttons
);
1235 register_leds(platform
.leds
);
1240 static void __exit
diag_exit(void)
1242 del_timer(&led_timer
);
1244 if (platform
.buttons
)
1245 unregister_buttons(platform
.buttons
);
1248 unregister_leds(platform
.leds
);
1250 remove_proc_entry("model", diag
);
1251 remove_proc_entry("gpiomask", diag
);
1252 remove_proc_entry("diag", NULL
);
1255 module_init(diag_init
);
1256 module_exit(diag_exit
);
1258 MODULE_AUTHOR("Mike Baker, Felix Fietkau / OpenWrt.org");
1259 MODULE_LICENSE("GPL");