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>
30 #include <linux/workqueue.h>
31 #include <linux/skbuff.h>
32 #include <linux/netlink.h>
33 #include <linux/kobject.h>
35 extern u64
uevent_next_seqnum(void);
39 #define getvar(str) (nvram_get(str)?:"")
41 static inline int startswith (char *source
, char *cmp
) { return !strncmp(source
,cmp
,strlen(cmp
)); }
42 static int fill_event(struct event_t
*);
43 static unsigned int gpiomask
= 0;
44 module_param(gpiomask
, int, 0644);
138 /* Western Digital */
154 static void __init
bcm4780_init(void) {
157 /* Enables GPIO 3 that controls HDD and led power on ASUS WL-700gE */
158 printk(MODULE_NAME
": Spinning up HDD and enabling leds\n");
159 gpio_outen(pin
, pin
);
160 gpio_control(pin
, 0);
163 /* Wait 5s, so the HDD can spin up */
164 set_current_state(TASK_INTERRUPTIBLE
);
165 schedule_timeout(HZ
* 5);
168 static void __init
NetCenter_init(void) {
169 /* unset pin 6 (+12V) */
171 gpio_outen(pin
, pin
);
172 gpio_control(pin
, 0);
174 /* unset pin 1 (turn off red led, blue will light alone if +5V comes up) */
176 gpio_outen(pin
, pin
);
177 gpio_control(pin
, 0);
179 /* unset pin 3 (+5V) and wait 5 seconds (harddisk spin up) */
183 static void __init
bcm57xx_init(void) {
186 /* FIXME: switch comes up, but port mappings/vlans not right */
187 gpio_outen(pin
, pin
);
188 gpio_control(pin
, 0);
192 static struct platform_t __initdata platforms
[] = {
195 .name
= "Linksys WAP54G V1",
197 { .name
= "reset", .gpio
= 1 << 0 },
200 { .name
= "diag", .gpio
= 1 << 3 },
201 { .name
= "wlan", .gpio
= 1 << 4 },
205 .name
= "Linksys WAP54G V2",
207 { .name
= "reset", .gpio
= 1 << 0 },
210 { .name
= "wlan", .gpio
= 1 << 5, .polarity
= REVERSE
},
211 /* GPIO 6 is b44 (eth0, LAN) PHY power */
215 .name
= "Linksys WAP54G V3",
217 /* FIXME: verify this */
218 { .name
= "reset", .gpio
= 1 << 7 },
219 { .name
= "ses", .gpio
= 1 << 0 },
223 { .name
= "ses", .gpio
= 1 << 1 },
227 .name
= "Linksys WRT54G V1.x",
229 { .name
= "reset", .gpio
= 1 << 6 },
232 { .name
= "diag", .gpio
= 0x13 | GPIO_TYPE_EXTIF
, .polarity
= NORMAL
},
233 { .name
= "dmz", .gpio
= 0x12 | GPIO_TYPE_EXTIF
, .polarity
= NORMAL
},
237 .name
= "Linksys WRT54G/GS/GL",
239 { .name
= "reset", .gpio
= 1 << 6 },
240 { .name
= "ses", .gpio
= 1 << 4 },
243 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
244 { .name
= "dmz", .gpio
= 1 << 7, .polarity
= REVERSE
},
245 { .name
= "ses_white", .gpio
= 1 << 2, .polarity
= REVERSE
},
246 { .name
= "ses_orange", .gpio
= 1 << 3, .polarity
= REVERSE
},
247 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
251 .name
= "Linksys WRTSL54GS",
253 { .name
= "reset", .gpio
= 1 << 6 },
254 { .name
= "ses", .gpio
= 1 << 4 },
257 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
258 { .name
= "dmz", .gpio
= 1 << 0, .polarity
= REVERSE
},
259 { .name
= "ses_white", .gpio
= 1 << 5, .polarity
= REVERSE
},
260 { .name
= "ses_orange", .gpio
= 1 << 7, .polarity
= REVERSE
},
264 .name
= "Linksys WRT54G3G",
266 { .name
= "reset", .gpio
= 1 << 6 },
267 { .name
= "3g", .gpio
= 1 << 4 },
270 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
271 { .name
= "dmz", .gpio
= 1 << 7, .polarity
= REVERSE
},
272 { .name
= "3g_green", .gpio
= 1 << 2, .polarity
= NORMAL
},
273 { .name
= "3g_blue", .gpio
= 1 << 3, .polarity
= NORMAL
},
274 { .name
= "3g_blink", .gpio
= 1 << 5, .polarity
= NORMAL
},
278 .name
= "Linksys WRT54G3GV2-VF",
280 { .name
= "reset", .gpio
= 1 << 6 },
281 { .name
= "3g", .gpio
= 1 << 5 },
284 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
285 { .name
= "3g_green", .gpio
= 1 << 2, .polarity
= NORMAL
},
286 { .name
= "3g_blue", .gpio
= 1 << 3, .polarity
= NORMAL
},
290 .name
= "Linksys WRT150N V1",
292 { .name
= "reset", .gpio
= 1 << 6 },
293 { .name
= "ses", .gpio
= 1 << 4 },
296 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
297 { .name
= "ses_green", .gpio
= 1 << 5, .polarity
= REVERSE
},
298 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
302 .name
= "Linksys WRT150N V1.1",
304 { .name
= "reset", .gpio
= 1 << 6 },
305 { .name
= "ses", .gpio
= 1 << 4 },
308 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
309 { .name
= "ses_green", .gpio
= 1 << 5, .polarity
= REVERSE
},
310 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
314 .name
= "Linksys WRT160N v1.x",
316 { .name
= "reset", .gpio
= 1 << 6 },
317 { .name
= "ses", .gpio
= 1 << 4 },
320 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
321 { .name
= "ses_blue", .gpio
= 1 << 5, .polarity
= REVERSE
},
322 { .name
= "ses_orange", .gpio
= 1 << 3, .polarity
= REVERSE
},
326 .name
= "Linksys WRT160N V3",
328 { .name
= "reset", .gpio
= 1 << 6 },
329 { .name
= "ses", .gpio
= 1 << 5 },
332 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
333 { .name
= "ses_blue", .gpio
= 1 << 4, .polarity
= REVERSE
},
334 { .name
= "ses_orange", .gpio
= 1 << 2, .polarity
= REVERSE
},
338 .name
= "Linksys WRT300N V1.1",
340 { .name
= "reset", .gpio
= 1 << 6 }, // "Reset" on back panel
341 { .name
= "ses", .gpio
= 1 << 4 }, // "Reserved" on top panel
344 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
}, // "Power"
345 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
}, // "Security" Amber
346 { .name
= "ses_green", .gpio
= 1 << 5, .polarity
= REVERSE
}, // "Security" Green
348 .platform_init
= bcm57xx_init
,
351 .name
= "Linksys WRT350N",
353 { .name
= "reset", .gpio
= 1 << 6 },
354 { .name
= "ses", .gpio
= 1 << 8 },
357 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
358 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
359 { .name
= "ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
},
360 { .name
= "usb_blink", .gpio
= 1 << 10, .polarity
= REVERSE
},
361 { .name
= "usb", .gpio
= 1 << 11, .polarity
= REVERSE
},
363 .platform_init
= bcm57xx_init
,
366 .name
= "Linksys WRT600N",
368 { .name
= "reset", .gpio
= 1 << 6 },
369 { .name
= "ses", .gpio
= 1 << 7 },
372 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
}, // Power LED
373 { .name
= "usb", .gpio
= 1 << 3, .polarity
= REVERSE
}, // USB LED
374 { .name
= "wl0_ses_amber", .gpio
= 1 << 8, .polarity
= REVERSE
}, // 2.4Ghz LED Amber
375 { .name
= "wl0_ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
}, // 2.4Ghz LED Green
376 { .name
= "wl1_ses_amber", .gpio
= 1 << 10, .polarity
= REVERSE
}, // 5.6Ghz LED Amber
377 { .name
= "wl1_ses_green", .gpio
= 1 << 11, .polarity
= REVERSE
}, // 5.6Ghz LED Green
379 .platform_init
= bcm57xx_init
,
382 .name
= "Linksys WRT600N V1.1",
384 { .name
= "reset", .gpio
= 1 << 6 },
385 { .name
= "ses", .gpio
= 1 << 7 },
388 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
}, // Power LED
389 { .name
= "usb", .gpio
= 1 << 3, .polarity
= REVERSE
}, // USB LED
390 { .name
= "wl0_ses_amber", .gpio
= 1 << 8, .polarity
= REVERSE
}, // 2.4Ghz LED Amber
391 { .name
= "wl0_ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
}, // 2.4Ghz LED Green
392 { .name
= "wl1_ses_amber", .gpio
= 1 << 10, .polarity
= REVERSE
}, // 5.6Ghz LED Amber
393 { .name
= "wl1_ses_green", .gpio
= 1 << 11, .polarity
= REVERSE
}, // 5.6Ghz LED Green
395 .platform_init
= bcm57xx_init
,
398 .name
= "Linksys WRT610N",
400 { .name
= "reset", .gpio
= 1 << 6 },
401 { .name
= "ses", .gpio
= 1 << 8 },
404 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
}, // Power LED
405 { .name
= "usb", .gpio
= 1 << 0, .polarity
= REVERSE
}, // USB LED
406 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
}, // WiFi protected setup LED amber
407 { .name
= "ses_blue", .gpio
= 1 << 9, .polarity
= REVERSE
}, // WiFi protected setup LED blue
411 .name
= "Linksys WRT610N V2",
413 { .name
= "reset", .gpio
= 1 << 6 },
414 { .name
= "ses", .gpio
= 1 << 4 },
417 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
}, // Power LED
418 { .name
= "usb", .gpio
= 1 << 7, .polarity
= NORMAL
}, // USB LED
419 { .name
= "ses_amber", .gpio
= 1 << 0, .polarity
= REVERSE
}, // WiFi protected setup LED amber
420 { .name
= "ses_blue", .gpio
= 1 << 3, .polarity
= REVERSE
}, // WiFi protected setup LED blue
421 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
}, // Wireless LED
425 .name
= "Linksys E3000 V1",
427 { .name
= "reset", .gpio
= 1 << 6 },
428 { .name
= "ses", .gpio
= 1 << 4 },
431 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
}, // Power LED
432 { .name
= "usb", .gpio
= 1 << 7, .polarity
= NORMAL
}, // USB LED
433 { .name
= "ses_amber", .gpio
= 1 << 0, .polarity
= REVERSE
}, // WiFi protected setup LED amber
434 { .name
= "ses_blue", .gpio
= 1 << 3, .polarity
= REVERSE
}, // WiFi protected setup LED blue
435 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
}, // Wireless LED
440 .name
= "ASUS WL-HDD",
442 { .name
= "reset", .gpio
= 1 << 6 },
445 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
446 { .name
= "usb", .gpio
= 1 << 2, .polarity
= REVERSE
},
450 .name
= "ASUS WL-300g",
452 { .name
= "reset", .gpio
= 1 << 6 },
455 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
459 .name
= "ASUS WL-320gE/WL-320gP",
461 { .name
= "reset", .gpio
= 1 << 6 },
464 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
465 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
},
466 { .name
= "link", .gpio
= 1 << 11, .polarity
= REVERSE
},
470 .name
= "ASUS WL-330gE",
472 { .name
= "reset", .gpio
= 1 << 2 },
475 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
479 .name
= "ASUS WL-500g",
481 { .name
= "reset", .gpio
= 1 << 6 },
484 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
488 .name
= "ASUS WL-500g Deluxe",
490 { .name
= "reset", .gpio
= 1 << 6 },
493 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
497 .name
= "ASUS WL-500g Premium",
499 { .name
= "reset", .gpio
= 1 << 0 },
500 { .name
= "ses", .gpio
= 1 << 4 },
503 { .name
= "power", .gpio
= 1 << 1, .polarity
= REVERSE
},
507 .name
= "ASUS WL-500g Premium V2",
509 { .name
= "reset", .gpio
= 1 << 2 },
510 { .name
= "ses", .gpio
= 1 << 3 },
513 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
514 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
518 .name
= "ASUS WL-500W",
520 { .name
= "reset", .gpio
= 1 << 6 },
521 { .name
= "ses", .gpio
= 1 << 7 },
524 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
528 .name
= "ASUS WL-520GC",
530 { .name
= "reset", .gpio
= 1 << 2 },
531 { .name
= "ses", .gpio
= 1 << 3 },
534 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
535 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
539 .name
= "ASUS WL-520gU",
541 { .name
= "reset", .gpio
= 1 << 2 },
542 { .name
= "ses", .gpio
= 1 << 3 },
545 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
546 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
550 .name
= "ASUS (unknown, BCM4702)",
552 { .name
= "reset", .gpio
= 1 << 6 },
555 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
559 .name
= "ASUS WL-700gE",
561 { .name
= "reset", .gpio
= 1 << 7 }, // on back, hardwired, always resets device regardless OS state
562 { .name
= "ses", .gpio
= 1 << 4 }, // on back, actual name ezsetup
563 { .name
= "power", .gpio
= 1 << 0 }, // on front
564 { .name
= "copy", .gpio
= 1 << 6 }, // on front
568 // GPIO that controls power led also enables/disables some essential functions
571 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
}, // actual name power
573 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
575 .platform_init
= bcm4780_init
,
578 .name
= "ASUS RT-N16",
580 { .name
= "reset", .gpio
= 1 << 8 },
581 { .name
= "ses", .gpio
= 1 << 5 },
584 { .name
= "power", .gpio
= 1 << 1, .polarity
= REVERSE
},
585 { .name
= "wlan", .gpio
= 1 << 7, .polarity
= NORMAL
},
590 .name
= "Buffalo WHR-G54S",
592 { .name
= "reset", .gpio
= 1 << 4 },
593 { .name
= "bridge", .gpio
= 1 << 5 },
594 { .name
= "ses", .gpio
= 1 << 0 },
597 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
598 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
599 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
600 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
601 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
605 .name
= "Buffalo WBR2-G54",
608 { .name
= "reset", .gpio
= 1 << 7 },
611 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
615 .name
= "Buffalo WHR-HP-G54",
617 { .name
= "reset", .gpio
= 1 << 4 },
618 { .name
= "bridge", .gpio
= 1 << 5 },
619 { .name
= "ses", .gpio
= 1 << 0 },
622 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
623 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
624 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
625 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
626 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
630 .name
= "Buffalo WHR-G125",
632 { .name
= "reset", .gpio
= 1 << 4 },
633 { .name
= "bridge", .gpio
= 1 << 5 },
634 { .name
= "ses", .gpio
= 1 << 0 },
637 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
638 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
639 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
640 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
641 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
645 .name
= "Buffalo WHR2-A54G54",
647 { .name
= "reset", .gpio
= 1 << 4 },
650 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
654 .name
= "Buffalo WLA2-G54L",
657 { .name
= "reset", .gpio
= 1 << 7 },
660 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
664 .name
= "Buffalo WZR-G300N",
666 { .name
= "reset", .gpio
= 1 << 4 },
669 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
670 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
671 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
675 .name
= "Buffalo WZR-RS-G54",
677 { .name
= "ses", .gpio
= 1 << 0 },
678 { .name
= "reset", .gpio
= 1 << 4 },
681 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
682 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
683 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
687 .name
= "Buffalo WZR-RS-G54HP",
689 { .name
= "ses", .gpio
= 1 << 0 },
690 { .name
= "reset", .gpio
= 1 << 4 },
693 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
694 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
695 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
698 [BUFFALO_UNKNOWN
] = {
699 .name
= "Buffalo (unknown)",
701 { .name
= "reset", .gpio
= 1 << 7 },
704 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
707 [BUFFALO_UNKNOWN_4710
] = {
708 .name
= "Buffalo (unknown, BCM4710)",
710 { .name
= "reset", .gpio
= 1 << 4 },
713 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
718 .name
= "Siemens SE505 V1",
720 /* No usable buttons */
723 // { .name = "power", .gpio = 1 << 0 .polarity = REVERSE }, // Usable when retrofitting D26 (?)
724 { .name
= "dmz", .gpio
= 1 << 4, .polarity
= REVERSE
}, // actual name WWW
725 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
729 .name
= "Siemens SE505 V2",
731 /* No usable buttons */
734 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
735 { .name
= "dmz", .gpio
= 1 << 0, .polarity
= REVERSE
}, // actual name WWW
736 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
741 .name
= "U.S. Robotics USR5461",
743 /* No usable buttons */
746 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
747 { .name
= "printer", .gpio
= 1 << 1, .polarity
= REVERSE
},
752 .name
= "Dell TrueMobile 2300",
754 { .name
= "reset", .gpio
= 1 << 0 },
757 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
758 { .name
= "power", .gpio
= 1 << 7, .polarity
= REVERSE
},
762 .name
= "Dell TrueMobile 2300 v2",
764 { .name
= "reset", .gpio
= 1 << 0 },
767 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
768 { .name
= "power", .gpio
= 1 << 7, .polarity
= REVERSE
},
773 .name
= "Motorola WE800G",
775 { .name
= "reset", .gpio
= 1 << 0 },
778 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
779 { .name
= "diag", .gpio
= 1 << 2, .polarity
= REVERSE
},
780 { .name
= "wlan_amber", .gpio
= 1 << 1, .polarity
= NORMAL
},
784 .name
= "Motorola WR850G V1",
786 { .name
= "reset", .gpio
= 1 << 0 },
789 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
790 { .name
= "diag", .gpio
= 1 << 3, .polarity
= REVERSE
},
791 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= NORMAL
},
792 { .name
= "wlan_red", .gpio
= 1 << 5, .polarity
= REVERSE
},
793 { .name
= "wlan_green", .gpio
= 1 << 7, .polarity
= REVERSE
},
797 .name
= "Motorola WR850G V2/V3",
799 { .name
= "reset", .gpio
= 1 << 5 },
802 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
803 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
804 { .name
= "wan", .gpio
= 1 << 6, .polarity
= INPUT
},
805 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
809 .name
= "Motorola WR850GP",
811 { .name
= "reset", .gpio
= 1 << 5 },
814 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
815 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
816 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= REVERSE
},
817 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
823 .name
= "Belkin (unknown)",
824 /* FIXME: verify & add detection */
826 { .name
= "reset", .gpio
= 1 << 7 },
829 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
},
830 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= NORMAL
},
831 { .name
= "connected", .gpio
= 1 << 0, .polarity
= NORMAL
},
835 .name
= "Belkin PlayMax F7D4301",
837 { .name
= "reset", .gpio
= 1 << 6 },
838 { .name
= "wps", .gpio
= 1 << 8 },
841 { .name
= "power", .gpio
= 1 << 11, .polarity
= REVERSE
},
842 { .name
= "wlan", .gpio
= 1 << 13, .polarity
= REVERSE
},
843 { .name
= "led0", .gpio
= 1 << 14, .polarity
= REVERSE
},
844 { .name
= "led1", .gpio
= 1 << 15, .polarity
= REVERSE
},
849 .name
= "Netgear WGT634U",
851 { .name
= "reset", .gpio
= 1 << 2 },
854 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
},
859 .name
= "Netgear WNR834B V1",
860 .buttons
= { /* TODO: add reset button and confirm LEDs - GPIO from dd-wrt */ },
862 { .name
= "power", .gpio
= 1 << 4, .polarity
= REVERSE
},
863 { .name
= "diag", .gpio
= 1 << 5, .polarity
= REVERSE
},
864 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
869 .name
= "Netgear WNR834B V2",
871 { .name
= "reset", .gpio
= 1 << 6 },
874 { .name
= "power", .gpio
= 1 << 2, .polarity
= NORMAL
},
875 { .name
= "diag", .gpio
= 1 << 3, .polarity
= NORMAL
},
876 { .name
= "connected", .gpio
= 1 << 7, .polarity
= NORMAL
},
881 .name
= "Trendware TEW411BRP+",
883 { /* No usable buttons */ },
886 { .name
= "power", .gpio
= 1 << 7, .polarity
= NORMAL
},
887 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
},
888 { .name
= "bridge", .gpio
= 1 << 6, .polarity
= NORMAL
},
893 .name
= "SimpleTech SimpleShare NAS",
895 { .name
= "reset", .gpio
= 1 << 0 }, // Power button on back, named reset to enable failsafe.
898 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
900 .platform_init
= bcm4780_init
,
904 .name
= "D-Link DIR-130",
906 { .name
= "reset", .gpio
= 1 << 3},
907 { .name
= "reserved", .gpio
= 1 << 7},
910 { .name
= "diag", .gpio
= 1 << 0},
911 { .name
= "blue", .gpio
= 1 << 6},
915 .name
= "D-Link DIR-320",
917 { .name
= "reserved", .gpio
= 1 << 6},
918 { .name
= "reset", .gpio
= 1 << 7},
921 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
922 { .name
= "diag", .gpio
= 1 << 1, .polarity
= NORMAL
}, /* "status led */
923 { .name
= "red", .gpio
= 1 << 3, .polarity
= REVERSE
},
924 { .name
= "blue", .gpio
= 1 << 4, .polarity
= REVERSE
},
925 { .name
= "usb", .gpio
= 1 << 5, .polarity
= NORMAL
},
929 .name
= "D-Link DIR-330",
931 { .name
= "reset", .gpio
= 1 << 3},
932 { .name
= "reserved", .gpio
= 1 << 7},
935 { .name
= "diag", .gpio
= 1 << 0},
936 { .name
= "usb", .gpio
= 1 << 4},
937 { .name
= "blue", .gpio
= 1 << 6},
941 .name
= "D-Link DWL-3150",
943 { .name
= "reset", .gpio
= 1 << 7},
946 { .name
= "diag", .gpio
= 1 << 2},
947 { .name
= "status", .gpio
= 1 << 1},
952 .name
= "Sitecom WL-105b",
954 { .name
= "reset", .gpio
= 1 << 10},
957 { .name
= "wlan", .gpio
= 1 << 4},
958 { .name
= "power", .gpio
= 1 << 3},
961 /* Western Digital Net Center */
963 .name
= "Western Digital NetCenter",
965 { .name
= "power", .gpio
= 1 << 0},
966 { .name
= "reset", .gpio
= 1 << 7},
968 .platform_init
= NetCenter_init
,
970 /* Askey (and clones) */
972 .name
= "Askey RT210W",
974 /* Power button is hard-wired to hardware reset */
975 /* but is also connected to GPIO 7 (probably for bootloader recovery) */
976 { .name
= "power", .gpio
= 1 << 7},
979 /* These were verified and named based on Belkin F5D4230-4 v1112 */
980 { .name
= "connected", .gpio
= 1 << 0, .polarity
= REVERSE
},
981 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
982 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
986 .name
= "OvisLink WL-1600GL",
988 { .name
= "reset", .gpio
= 1 << 3 },
989 { .name
= "ses", .gpio
= 1 << 4 },
992 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
993 { .name
= "wps", .gpio
= 1 << 2, .polarity
= REVERSE
},
994 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
995 { .name
= "connected", .gpio
= 1 << 0, .polarity
= REVERSE
},
1000 .name
= "Microsoft MN-700",
1002 { .name
= "reset", .gpio
= 1 << 7 },
1005 { .name
= "power", .gpio
= 1 << 6, .polarity
= NORMAL
},
1010 .name
= "Edimax PS-1208MFG",
1012 { .name
= "reset", .gpio
= 1 << 4 },
1015 { .name
= "status", .gpio
= 1 << 1, .polarity
= NORMAL
},
1016 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
1021 static struct platform_t __init
*platform_detect(void)
1023 char *boardnum
, *boardtype
, *buf
;
1025 if (strcmp(getvar("nvram_type"), "cfe") == 0)
1026 return &platforms
[WGT634U
];
1028 /* Look for a model identifier */
1030 /* Based on "model_name" */
1031 if ((buf
= nvram_get("model_name"))) {
1032 if (!strcmp(buf
, "DIR-130"))
1033 return &platforms
[DIR130
];
1034 if (!strcmp(buf
, "DIR-330"))
1035 return &platforms
[DIR330
];
1038 /* Based on "wsc_modelname */
1039 if ((buf
= nvram_get("wsc_modelname"))) {
1040 if (!strcmp(buf
, "WRT610N"))
1041 return &platforms
[WRT610N
];
1044 /* Based on "model_no" */
1045 if ((buf
= nvram_get("model_no"))) {
1046 if (startswith(buf
,"WL700")) /* WL700* */
1047 return &platforms
[WL700GE
];
1050 /* Based on "hardware_version" */
1051 if ((buf
= nvram_get("hardware_version"))) {
1052 if (startswith(buf
,"WL500GPV2-")) /* WL500GPV2-* */
1053 return &platforms
[WL500GPV2
];
1054 if (startswith(buf
,"WL520GC-")) /* WL520GU-* */
1055 return &platforms
[WL520GC
];
1056 if (startswith(buf
,"WL520GU-")) /* WL520GU-* */
1057 return &platforms
[WL520GU
];
1058 if (startswith(buf
,"WL330GE-")) /* WL330GE-* */
1059 return &platforms
[WL330GE
];
1060 if (startswith(buf
,"RT-N16-")) /* RT-N16-* */
1061 return &platforms
[RTN16
];
1062 if (startswith(buf
,"F7D4301")) /* F7D4301* */
1063 return &platforms
[BELKIN_F7D4301
];
1066 /* Based on "ModelId" */
1067 if ((buf
= nvram_get("ModelId"))) {
1068 if (!strcmp(buf
, "WR850GP"))
1069 return &platforms
[WR850GP
];
1070 if (!strcmp(buf
, "WR850G"))
1071 return &platforms
[WR850GV2V3
];
1072 if (!strcmp(buf
, "WX-5565") && !strcmp(getvar("boardtype"),"bcm94710ap"))
1073 return &platforms
[TM2300
]; /* Dell TrueMobile 2300 */
1074 if (startswith(buf
,"WE800G")) /* WE800G* */
1075 return &platforms
[WE800G
];
1079 if ((buf
= (nvram_get("melco_id") ?: nvram_get("buffalo_id")))) {
1080 /* Buffalo hardware, check id for specific hardware matches */
1081 if (!strcmp(buf
, "29bb0332"))
1082 return &platforms
[WBR2_G54
];
1083 if (!strcmp(buf
, "29129"))
1084 return &platforms
[WLA2_G54L
];
1085 if (!strcmp(buf
, "30189"))
1086 return &platforms
[WHR_HP_G54
];
1087 if (!strcmp(buf
, "32093"))
1088 return &platforms
[WHR_G125
];
1089 if (!strcmp(buf
, "30182"))
1090 return &platforms
[WHR_G54S
];
1091 if (!strcmp(buf
, "290441dd"))
1092 return &platforms
[WHR2_A54G54
];
1093 if (!strcmp(buf
, "31120"))
1094 return &platforms
[WZR_G300N
];
1095 if (!strcmp(buf
, "30083"))
1096 return &platforms
[WZR_RS_G54
];
1097 if (!strcmp(buf
, "30103"))
1098 return &platforms
[WZR_RS_G54HP
];
1101 /* no easy model number, attempt to guess */
1102 boardnum
= getvar("boardnum");
1103 boardtype
= getvar("boardtype");
1105 if (!strcmp(boardnum
, "20070615")) { /* Linksys WRT600N v1/V1.1 */
1106 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "0") && !strcmp(getvar("switch_type"),"BCM5395"))
1107 return &platforms
[WRT600NV11
];
1109 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "0"))
1110 return &platforms
[WRT600N
];
1114 * Normally, these would go inside the "CFE based - newer hardware" block below; however, during early init, the
1115 * "pmon_ver" variable is not available on the E3000v1 (and probably the WRT610Nv2 also). Until this is figured out,
1116 * these will need to remain here in order for platform detection to work.
1118 if (!strcmp(boardnum
, "42")) { /* Linksys */
1119 if (!strcmp(boardtype
, "0x04cf") && !strcmp(getvar("boot_hw_model"), "E300") && !strcmp(getvar("boot_hw_ver"), "1.0"))
1120 return &platforms
[E3000V1
];
1122 if (!strcmp(boardtype
, "0x04cf") && !strcmp(getvar("boot_hw_model"), "WRT610N") && !strcmp(getvar("boot_hw_ver"), "2.0"))
1123 return &platforms
[WRT610NV2
];
1126 if (startswith(getvar("pmon_ver"), "CFE")) {
1127 /* CFE based - newer hardware */
1128 if (!strcmp(boardnum
, "42")) { /* Linksys */
1129 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("boot_hw_model"), "WRT300N") && !strcmp(getvar("boot_hw_ver"), "1.1"))
1130 return &platforms
[WRT300NV11
];
1132 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "1"))
1133 return &platforms
[WRT350N
];
1135 if (!strcmp(boardtype
, "0x0101") && !strcmp(getvar("boot_ver"), "v3.6"))
1136 return &platforms
[WRT54G3G
];
1138 if (!strcmp(boardtype
, "0x042f") && !strcmp(getvar("model_name"), "WRT54G3GV2-VF"))
1139 return &platforms
[WRT54G3GV2_VF
];
1141 if (!strcmp(getvar("et1phyaddr"),"5") && !strcmp(getvar("et1mdcport"), "1"))
1142 return &platforms
[WRTSL54GS
];
1144 if (!strcmp(boardtype
, "0x0472")) {
1145 if(!strcmp(getvar("boot_hw_model"), "WRT150N")) {
1146 if(!strcmp(getvar("boot_hw_ver"), "1"))
1147 return &platforms
[WRT150NV1
];
1148 else if(!strcmp(getvar("boot_hw_ver"), "1.1"))
1149 return &platforms
[WRT150NV11
];
1151 else if(!strcmp(getvar("boot_hw_model"), "WRT160N")) {
1152 if(!strcmp(getvar("boot_hw_ver"), "1.0"))
1153 return &platforms
[WRT160NV1
];
1154 else if(!strcmp(getvar("boot_hw_ver"), "3.0"))
1155 return &platforms
[WRT160NV3
];
1159 /* default to WRT54G */
1160 return &platforms
[WRT54G
];
1162 if (!strcmp(boardnum
, "1024") && !strcmp(boardtype
, "0x0446"))
1163 return &platforms
[WAP54GV2
];
1165 if (!strcmp(boardnum
, "8") && !strcmp(boardtype
, "0x048e"))
1166 return &platforms
[WL1600GL
];
1169 if (!strcmp(boardnum
, "44") || !strcmp(boardnum
, "44\r")) {
1170 if (!strcmp(boardtype
,"0x0101") || !strcmp(boardtype
, "0x0101\r"))
1171 return &platforms
[TM2300V2
]; /* Dell TrueMobile 2300 v2 */
1174 if (!strcmp(boardnum
, "45")) { /* ASUS */
1175 if (!strcmp(boardtype
,"0x042f"))
1176 return &platforms
[WL500GP
];
1177 else if (!strcmp(boardtype
,"0x0472"))
1178 return &platforms
[WL500W
];
1179 else if (!strcmp(boardtype
,"0x467"))
1180 return &platforms
[WL320GE
];
1182 return &platforms
[WL500GD
];
1185 if (!strcmp(boardnum
, "10496"))
1186 return &platforms
[USR5461
];
1188 if (!strcmp(getvar("boardtype"), "0x0101") && !strcmp(getvar("boardrev"), "0x10")) /* SE505V2 With Modified CFE */
1189 return &platforms
[SE505V2
];
1191 if (!strcmp(boardtype
, "0x048e") && !strcmp(getvar("boardrev"),"0x35") &&
1192 !strcmp(getvar("boardflags"), "0x750")) /* D-Link DIR-320 */
1193 return &platforms
[DIR320
];
1195 if (!strncmp(boardnum
, "TH",2) && !strcmp(boardtype
,"0x042f")) {
1196 return &platforms
[WDNetCenter
];
1199 if (!strcmp(boardtype
,"0x0472") && !strcmp(getvar("cardbus"), "1")) { /* Netgear WNR834B V1 and V2*/
1200 if (!strcmp(boardnum
, "08") || !strcmp(boardnum
, "8"))
1201 return &platforms
[WNR834BV1
];
1202 if (!strcmp(boardnum
, "01") || !strcmp(boardnum
, "1"))
1203 return &platforms
[WNR834BV2
];
1206 } else { /* PMON based - old stuff */
1207 if ((simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 9) &&
1208 (simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 30)) {
1209 return &platforms
[WR850GV1
];
1211 if (startswith(boardtype
, "bcm94710dev")) {
1212 if (!strcmp(boardnum
, "42"))
1213 return &platforms
[WRT54GV1
];
1214 if (simple_strtoul(boardnum
, NULL
, 0) == 2)
1215 return &platforms
[WAP54GV1
];
1217 /* MN-700 has also hardware_version 'WL500-...', so use boardnum */
1218 if (startswith(getvar("hardware_version"), "WL500-")) {
1219 if (!strcmp(getvar("boardnum"), "mn700"))
1220 return &platforms
[MN700
];
1222 return &platforms
[WL500G
];
1224 if (startswith(getvar("hardware_version"), "WL300-")) {
1225 /* Either WL-300g or WL-HDD, do more extensive checks */
1226 if ((simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 0) &&
1227 (simple_strtoul(getvar("et1phyaddr"), NULL
, 0) == 1))
1228 return &platforms
[WLHDD
];
1229 if ((simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 0) &&
1230 (simple_strtoul(getvar("et1phyaddr"), NULL
, 0) == 10))
1231 return &platforms
[WL300G
];
1233 /* Sitecom WL-105b */
1234 if (startswith(boardnum
, "2") && simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 1)
1235 return &platforms
[WL105B
];
1237 /* unknown asus stuff, probably bcm4702 */
1238 if (startswith(boardnum
, "asusX"))
1239 return &platforms
[ASUS_4702
];
1241 /* bcm4702 based Askey RT210W clones, Including:
1242 * Askey RT210W (duh?)
1244 * Belkin F5D7230-4 before version v1444 (MiniPCI slot, not integrated)
1246 if (!strcmp(boardtype
,"bcm94710r4")
1247 && !strcmp(boardnum
,"100")
1248 && !strcmp(getvar("pmon_ver"),"v1.03.12.bk")
1250 return &platforms
[RT210W
];
1254 if (buf
|| !strcmp(boardnum
, "00")) {/* probably buffalo */
1255 if (startswith(boardtype
, "bcm94710ap"))
1256 return &platforms
[BUFFALO_UNKNOWN_4710
];
1258 return &platforms
[BUFFALO_UNKNOWN
];
1261 if (startswith(getvar("CFEver"), "MotoWRv2") ||
1262 startswith(getvar("CFEver"), "MotoWRv3") ||
1263 !strcmp(getvar("MOTO_BOARD_TYPE"), "WR_FEM1")) {
1265 return &platforms
[WR850GV2V3
];
1268 if (!strcmp(boardnum
, "44") && !strcmp(getvar("boardflags"),"0x0388")) { /* Trendware TEW-411BRP+ */
1269 return &platforms
[TEW411BRPP
];
1272 if (startswith(boardnum
, "04FN")) /* SimpleTech SimpleShare */
1273 return &platforms
[STI_NAS
];
1275 if (!strcmp(boardnum
, "10") && !strcmp(getvar("boardrev"), "0x13")) /* D-Link DWL-3150 */
1276 return &platforms
[DWL3150
];
1278 if (!strcmp(boardnum
, "01") && !strcmp(boardtype
, "0x048e") && /* Edimax PS1208MFG */
1279 !strcmp(getvar("status_gpio"), "1")) /* gpio based detection */
1280 return &platforms
[PS1208MFG
];
1286 static void register_buttons(struct button_t
*b
)
1288 for (; b
->name
; b
++)
1289 platform
.button_mask
|= b
->gpio
;
1291 platform
.button_mask
&= ~gpiomask
;
1293 gpio_outen(platform
.button_mask
, 0);
1294 gpio_control(platform
.button_mask
, 0);
1295 platform
.button_polarity
= gpio_in() & platform
.button_mask
;
1296 gpio_intpolarity(platform
.button_mask
, platform
.button_polarity
);
1297 gpio_setintmask(platform
.button_mask
, platform
.button_mask
);
1299 gpio_set_irqenable(1, button_handler
);
1302 static void unregister_buttons(struct button_t
*b
)
1304 gpio_setintmask(platform
.button_mask
, 0);
1306 gpio_set_irqenable(0, button_handler
);
1310 static void add_msg(struct event_t
*event
, char *msg
, int argv
)
1317 s
= skb_put(event
->skb
, strlen(msg
) + 1);
1321 static void hotplug_button(struct work_struct
*work
)
1323 struct event_t
*event
= container_of(work
, struct event_t
, wq
);
1326 event
->skb
= alloc_skb(2048, GFP_KERNEL
);
1328 s
= skb_put(event
->skb
, strlen(event
->action
) + 2);
1329 sprintf(s
, "%s@", event
->action
);
1332 NETLINK_CB(event
->skb
).dst_group
= 1;
1333 broadcast_uevent(event
->skb
, 0, 1, GFP_KERNEL
);
1339 static int fill_event (struct event_t
*event
)
1341 static char buf
[128];
1343 add_msg(event
, "HOME=/", 0);
1344 add_msg(event
, "PATH=/sbin:/bin:/usr/sbin:/usr/bin", 0);
1345 add_msg(event
, "SUBSYSTEM=button", 0);
1346 snprintf(buf
, 128, "ACTION=%s", event
->action
);
1347 add_msg(event
, buf
, 0);
1348 snprintf(buf
, 128, "BUTTON=%s", event
->name
);
1349 add_msg(event
, buf
, 0);
1350 snprintf(buf
, 128, "SEEN=%ld", event
->seen
);
1351 add_msg(event
, buf
, 0);
1352 snprintf(buf
, 128, "SEQNUM=%llu", uevent_next_seqnum());
1353 add_msg(event
, buf
, 0);
1359 static irqreturn_t
button_handler(int irq
, void *dev_id
)
1364 in
= gpio_in() & platform
.button_mask
;
1365 gpio_intpolarity(platform
.button_mask
, in
);
1366 changed
= platform
.button_polarity
^ in
;
1367 platform
.button_polarity
= in
;
1369 changed
&= ~gpio_outen(0, 0);
1371 for (b
= platform
.buttons
; b
->name
; b
++) {
1372 struct event_t
*event
;
1374 if (!(b
->gpio
& changed
)) continue;
1378 if ((event
= (struct event_t
*)kzalloc (sizeof(struct event_t
), GFP_ATOMIC
))) {
1379 event
->seen
= (jiffies
- b
->seen
)/HZ
;
1380 event
->name
= b
->name
;
1381 event
->action
= b
->pressed
? "pressed" : "released";
1382 INIT_WORK(&event
->wq
, (void *)(void *)hotplug_button
);
1383 schedule_work(&event
->wq
);
1391 static void register_leds(struct led_t
*l
)
1393 struct proc_dir_entry
*p
;
1398 leds
= proc_mkdir("led", diag
);
1402 for(; l
->name
; l
++) {
1403 if (l
->gpio
& gpiomask
)
1406 if (l
->gpio
& GPIO_TYPE_EXTIF
) {
1410 if (l
->polarity
!= INPUT
) oe_mask
|= l
->gpio
;
1412 val
|= (l
->polarity
== NORMAL
)?0:l
->gpio
;
1415 if (l
->polarity
== INPUT
) continue;
1417 if ((p
= create_proc_entry(l
->name
, S_IRUSR
, leds
))) {
1418 l
->proc
.type
= PROC_LED
;
1420 p
->data
= (void *) &l
->proc
;
1421 p
->proc_fops
= &diag_proc_fops
;
1425 gpio_outen(mask
, oe_mask
);
1426 gpio_control(mask
, 0);
1427 gpio_out(mask
, val
);
1428 gpio_setintmask(mask
, 0);
1431 static void unregister_leds(struct led_t
*l
)
1434 remove_proc_entry(l
->name
, leds
);
1436 remove_proc_entry("led", diag
);
1439 static void set_led_extif(struct led_t
*led
)
1441 gpio_set_extif(led
->gpio
, led
->state
);
1444 static void led_flash(unsigned long dummy
) {
1449 for (l
= platform
.leds
; l
->name
; l
++) {
1451 if (l
->gpio
& GPIO_TYPE_EXTIF
) {
1453 l
->state
= !l
->state
;
1463 u32 val
= ~gpio_in();
1465 gpio_outen(mask
, mask
);
1466 gpio_control(mask
, 0);
1467 gpio_out(mask
, val
);
1469 if (mask
|| extif_blink
) {
1470 mod_timer(&led_timer
, jiffies
+ FLASH_TIME
);
1474 static ssize_t
diag_proc_read(struct file
*file
, char *buf
, size_t count
, loff_t
*ppos
)
1476 struct proc_dir_entry
*dent
= PDE(file
->f_dentry
->d_inode
);
1480 if ((page
= kmalloc(1024, GFP_KERNEL
)) == NULL
)
1483 if (dent
->data
!= NULL
) {
1484 struct prochandler_t
*handler
= (struct prochandler_t
*) dent
->data
;
1485 switch (handler
->type
) {
1487 struct led_t
* led
= (struct led_t
*) handler
->ptr
;
1489 len
= sprintf(page
, "f\n");
1491 if (led
->gpio
& GPIO_TYPE_EXTIF
) {
1492 len
= sprintf(page
, "%d\n", led
->state
);
1494 u32 in
= (gpio_in() & led
->gpio
? 1 : 0);
1495 u8 p
= (led
->polarity
== NORMAL
? 0 : 1);
1496 len
= sprintf(page
, "%d\n", ((in
^ p
) ? 1 : 0));
1502 len
= sprintf(page
, "%s\n", platform
.name
);
1505 len
= sprintf(page
, "0x%04x\n", gpiomask
);
1512 len
= min_t(int, len
- *ppos
, count
);
1513 if (copy_to_user(buf
, (page
+ *ppos
), len
)) {
1527 static ssize_t
diag_proc_write(struct file
*file
, const char *buf
, size_t count
, loff_t
*ppos
)
1529 struct proc_dir_entry
*dent
= PDE(file
->f_dentry
->d_inode
);
1533 if ((page
= kmalloc(count
+ 1, GFP_KERNEL
)) == NULL
)
1536 if (copy_from_user(page
, buf
, count
)) {
1542 if (dent
->data
!= NULL
) {
1543 struct prochandler_t
*handler
= (struct prochandler_t
*) dent
->data
;
1544 switch (handler
->type
) {
1546 struct led_t
*led
= (struct led_t
*) handler
->ptr
;
1547 int p
= (led
->polarity
== NORMAL
? 0 : 1);
1549 if (page
[0] == 'f') {
1554 if (led
->gpio
& GPIO_TYPE_EXTIF
) {
1555 led
->state
= p
^ ((page
[0] == '1') ? 1 : 0);
1558 gpio_outen(led
->gpio
, led
->gpio
);
1559 gpio_control(led
->gpio
, 0);
1560 gpio_out(led
->gpio
, ((p
^ (page
[0] == '1')) ? led
->gpio
: 0));
1566 gpiomask
= simple_strtoul(page
, NULL
, 0);
1568 if (platform
.buttons
) {
1569 unregister_buttons(platform
.buttons
);
1570 register_buttons(platform
.buttons
);
1573 if (platform
.leds
) {
1574 unregister_leds(platform
.leds
);
1575 register_leds(platform
.leds
);
1586 static int __init
diag_init(void)
1588 static struct proc_dir_entry
*p
;
1589 static struct platform_t
*detected
;
1591 detected
= platform_detect();
1593 printk(MODULE_NAME
": Router model not detected.\n");
1596 memcpy(&platform
, detected
, sizeof(struct platform_t
));
1598 printk(MODULE_NAME
": Detected '%s'\n", platform
.name
);
1599 if (platform
.platform_init
!= NULL
) {
1600 platform
.platform_init();
1603 if (!(diag
= proc_mkdir("diag", NULL
))) {
1604 printk(MODULE_NAME
": proc_mkdir on /proc/diag failed\n");
1608 if ((p
= create_proc_entry("model", S_IRUSR
, diag
))) {
1609 p
->data
= (void *) &proc_model
;
1610 p
->proc_fops
= &diag_proc_fops
;
1613 if ((p
= create_proc_entry("gpiomask", S_IRUSR
| S_IWUSR
, diag
))) {
1614 p
->data
= (void *) &proc_gpiomask
;
1615 p
->proc_fops
= &diag_proc_fops
;
1618 if (platform
.buttons
)
1619 register_buttons(platform
.buttons
);
1622 register_leds(platform
.leds
);
1627 static void __exit
diag_exit(void)
1629 del_timer(&led_timer
);
1631 if (platform
.buttons
)
1632 unregister_buttons(platform
.buttons
);
1635 unregister_leds(platform
.leds
);
1637 remove_proc_entry("model", diag
);
1638 remove_proc_entry("gpiomask", diag
);
1639 remove_proc_entry("diag", NULL
);
1642 module_init(diag_init
);
1643 module_exit(diag_exit
);
1645 MODULE_AUTHOR("Mike Baker, Felix Fietkau / OpenWrt.org");
1646 MODULE_LICENSE("GPL");