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
];
1150 else if(!strcmp(getvar("boot_hw_model"), "WRT160N"))
1151 if(!strcmp(getvar("boot_hw_ver"), "1.0"))
1152 return &platforms
[WRT160NV1
];
1153 else if(!strcmp(getvar("boot_hw_ver"), "3.0"))
1154 return &platforms
[WRT160NV3
];
1157 /* default to WRT54G */
1158 return &platforms
[WRT54G
];
1160 if (!strcmp(boardnum
, "1024") && !strcmp(boardtype
, "0x0446"))
1161 return &platforms
[WAP54GV2
];
1163 if (!strcmp(boardnum
, "8") && !strcmp(boardtype
, "0x048e"))
1164 return &platforms
[WL1600GL
];
1167 if (!strcmp(boardnum
, "44") || !strcmp(boardnum
, "44\r")) {
1168 if (!strcmp(boardtype
,"0x0101") || !strcmp(boardtype
, "0x0101\r"))
1169 return &platforms
[TM2300V2
]; /* Dell TrueMobile 2300 v2 */
1172 if (!strcmp(boardnum
, "45")) { /* ASUS */
1173 if (!strcmp(boardtype
,"0x042f"))
1174 return &platforms
[WL500GP
];
1175 else if (!strcmp(boardtype
,"0x0472"))
1176 return &platforms
[WL500W
];
1177 else if (!strcmp(boardtype
,"0x467"))
1178 return &platforms
[WL320GE
];
1180 return &platforms
[WL500GD
];
1183 if (!strcmp(boardnum
, "10496"))
1184 return &platforms
[USR5461
];
1186 if (!strcmp(getvar("boardtype"), "0x0101") && !strcmp(getvar("boardrev"), "0x10")) /* SE505V2 With Modified CFE */
1187 return &platforms
[SE505V2
];
1189 if (!strcmp(boardtype
, "0x048e") && !strcmp(getvar("boardrev"),"0x35") &&
1190 !strcmp(getvar("boardflags"), "0x750")) /* D-Link DIR-320 */
1191 return &platforms
[DIR320
];
1193 if (!strncmp(boardnum
, "TH",2) && !strcmp(boardtype
,"0x042f")) {
1194 return &platforms
[WDNetCenter
];
1197 if (!strcmp(boardtype
,"0x0472") && !strcmp(getvar("cardbus"), "1")) { /* Netgear WNR834B V1 and V2*/
1198 if (!strcmp(boardnum
, "08") || !strcmp(boardnum
, "8"))
1199 return &platforms
[WNR834BV1
];
1200 if (!strcmp(boardnum
, "01") || !strcmp(boardnum
, "1"))
1201 return &platforms
[WNR834BV2
];
1204 } else { /* PMON based - old stuff */
1205 if ((simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 9) &&
1206 (simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 30)) {
1207 return &platforms
[WR850GV1
];
1209 if (startswith(boardtype
, "bcm94710dev")) {
1210 if (!strcmp(boardnum
, "42"))
1211 return &platforms
[WRT54GV1
];
1212 if (simple_strtoul(boardnum
, NULL
, 0) == 2)
1213 return &platforms
[WAP54GV1
];
1215 /* MN-700 has also hardware_version 'WL500-...', so use boardnum */
1216 if (startswith(getvar("hardware_version"), "WL500-")) {
1217 if (!strcmp(getvar("boardnum"), "mn700"))
1218 return &platforms
[MN700
];
1220 return &platforms
[WL500G
];
1222 if (startswith(getvar("hardware_version"), "WL300-")) {
1223 /* Either WL-300g or WL-HDD, do more extensive checks */
1224 if ((simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 0) &&
1225 (simple_strtoul(getvar("et1phyaddr"), NULL
, 0) == 1))
1226 return &platforms
[WLHDD
];
1227 if ((simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 0) &&
1228 (simple_strtoul(getvar("et1phyaddr"), NULL
, 0) == 10))
1229 return &platforms
[WL300G
];
1231 /* Sitecom WL-105b */
1232 if (startswith(boardnum
, "2") && simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 1)
1233 return &platforms
[WL105B
];
1235 /* unknown asus stuff, probably bcm4702 */
1236 if (startswith(boardnum
, "asusX"))
1237 return &platforms
[ASUS_4702
];
1239 /* bcm4702 based Askey RT210W clones, Including:
1240 * Askey RT210W (duh?)
1242 * Belkin F5D7230-4 before version v1444 (MiniPCI slot, not integrated)
1244 if (!strcmp(boardtype
,"bcm94710r4")
1245 && !strcmp(boardnum
,"100")
1246 && !strcmp(getvar("pmon_ver"),"v1.03.12.bk")
1248 return &platforms
[RT210W
];
1252 if (buf
|| !strcmp(boardnum
, "00")) {/* probably buffalo */
1253 if (startswith(boardtype
, "bcm94710ap"))
1254 return &platforms
[BUFFALO_UNKNOWN_4710
];
1256 return &platforms
[BUFFALO_UNKNOWN
];
1259 if (startswith(getvar("CFEver"), "MotoWRv2") ||
1260 startswith(getvar("CFEver"), "MotoWRv3") ||
1261 !strcmp(getvar("MOTO_BOARD_TYPE"), "WR_FEM1")) {
1263 return &platforms
[WR850GV2V3
];
1266 if (!strcmp(boardnum
, "44") && !strcmp(getvar("boardflags"),"0x0388")) { /* Trendware TEW-411BRP+ */
1267 return &platforms
[TEW411BRPP
];
1270 if (startswith(boardnum
, "04FN")) /* SimpleTech SimpleShare */
1271 return &platforms
[STI_NAS
];
1273 if (!strcmp(boardnum
, "10") && !strcmp(getvar("boardrev"), "0x13")) /* D-Link DWL-3150 */
1274 return &platforms
[DWL3150
];
1276 if (!strcmp(boardnum
, "01") && !strcmp(boardtype
, "0x048e") && /* Edimax PS1208MFG */
1277 !strcmp(getvar("status_gpio"), "1")) /* gpio based detection */
1278 return &platforms
[PS1208MFG
];
1284 static void register_buttons(struct button_t
*b
)
1286 for (; b
->name
; b
++)
1287 platform
.button_mask
|= b
->gpio
;
1289 platform
.button_mask
&= ~gpiomask
;
1291 gpio_outen(platform
.button_mask
, 0);
1292 gpio_control(platform
.button_mask
, 0);
1293 platform
.button_polarity
= gpio_in() & platform
.button_mask
;
1294 gpio_intpolarity(platform
.button_mask
, platform
.button_polarity
);
1295 gpio_setintmask(platform
.button_mask
, platform
.button_mask
);
1297 gpio_set_irqenable(1, button_handler
);
1300 static void unregister_buttons(struct button_t
*b
)
1302 gpio_setintmask(platform
.button_mask
, 0);
1304 gpio_set_irqenable(0, button_handler
);
1308 static void add_msg(struct event_t
*event
, char *msg
, int argv
)
1315 s
= skb_put(event
->skb
, strlen(msg
) + 1);
1319 static void hotplug_button(struct work_struct
*work
)
1321 struct event_t
*event
= container_of(work
, struct event_t
, wq
);
1324 event
->skb
= alloc_skb(2048, GFP_KERNEL
);
1326 s
= skb_put(event
->skb
, strlen(event
->action
) + 2);
1327 sprintf(s
, "%s@", event
->action
);
1330 NETLINK_CB(event
->skb
).dst_group
= 1;
1331 broadcast_uevent(event
->skb
, 0, 1, GFP_KERNEL
);
1337 static int fill_event (struct event_t
*event
)
1339 static char buf
[128];
1341 add_msg(event
, "HOME=/", 0);
1342 add_msg(event
, "PATH=/sbin:/bin:/usr/sbin:/usr/bin", 0);
1343 add_msg(event
, "SUBSYSTEM=button", 0);
1344 snprintf(buf
, 128, "ACTION=%s", event
->action
);
1345 add_msg(event
, buf
, 0);
1346 snprintf(buf
, 128, "BUTTON=%s", event
->name
);
1347 add_msg(event
, buf
, 0);
1348 snprintf(buf
, 128, "SEEN=%ld", event
->seen
);
1349 add_msg(event
, buf
, 0);
1350 snprintf(buf
, 128, "SEQNUM=%llu", uevent_next_seqnum());
1351 add_msg(event
, buf
, 0);
1357 static irqreturn_t
button_handler(int irq
, void *dev_id
)
1362 in
= gpio_in() & platform
.button_mask
;
1363 gpio_intpolarity(platform
.button_mask
, in
);
1364 changed
= platform
.button_polarity
^ in
;
1365 platform
.button_polarity
= in
;
1367 changed
&= ~gpio_outen(0, 0);
1369 for (b
= platform
.buttons
; b
->name
; b
++) {
1370 struct event_t
*event
;
1372 if (!(b
->gpio
& changed
)) continue;
1376 if ((event
= (struct event_t
*)kzalloc (sizeof(struct event_t
), GFP_ATOMIC
))) {
1377 event
->seen
= (jiffies
- b
->seen
)/HZ
;
1378 event
->name
= b
->name
;
1379 event
->action
= b
->pressed
? "pressed" : "released";
1380 INIT_WORK(&event
->wq
, (void *)(void *)hotplug_button
);
1381 schedule_work(&event
->wq
);
1389 static void register_leds(struct led_t
*l
)
1391 struct proc_dir_entry
*p
;
1396 leds
= proc_mkdir("led", diag
);
1400 for(; l
->name
; l
++) {
1401 if (l
->gpio
& gpiomask
)
1404 if (l
->gpio
& GPIO_TYPE_EXTIF
) {
1408 if (l
->polarity
!= INPUT
) oe_mask
|= l
->gpio
;
1410 val
|= (l
->polarity
== NORMAL
)?0:l
->gpio
;
1413 if (l
->polarity
== INPUT
) continue;
1415 if ((p
= create_proc_entry(l
->name
, S_IRUSR
, leds
))) {
1416 l
->proc
.type
= PROC_LED
;
1418 p
->data
= (void *) &l
->proc
;
1419 p
->proc_fops
= &diag_proc_fops
;
1423 gpio_outen(mask
, oe_mask
);
1424 gpio_control(mask
, 0);
1425 gpio_out(mask
, val
);
1426 gpio_setintmask(mask
, 0);
1429 static void unregister_leds(struct led_t
*l
)
1432 remove_proc_entry(l
->name
, leds
);
1434 remove_proc_entry("led", diag
);
1437 static void set_led_extif(struct led_t
*led
)
1439 gpio_set_extif(led
->gpio
, led
->state
);
1442 static void led_flash(unsigned long dummy
) {
1447 for (l
= platform
.leds
; l
->name
; l
++) {
1449 if (l
->gpio
& GPIO_TYPE_EXTIF
) {
1451 l
->state
= !l
->state
;
1461 u32 val
= ~gpio_in();
1463 gpio_outen(mask
, mask
);
1464 gpio_control(mask
, 0);
1465 gpio_out(mask
, val
);
1467 if (mask
|| extif_blink
) {
1468 mod_timer(&led_timer
, jiffies
+ FLASH_TIME
);
1472 static ssize_t
diag_proc_read(struct file
*file
, char *buf
, size_t count
, loff_t
*ppos
)
1474 struct proc_dir_entry
*dent
= PDE(file
->f_dentry
->d_inode
);
1478 if ((page
= kmalloc(1024, GFP_KERNEL
)) == NULL
)
1481 if (dent
->data
!= NULL
) {
1482 struct prochandler_t
*handler
= (struct prochandler_t
*) dent
->data
;
1483 switch (handler
->type
) {
1485 struct led_t
* led
= (struct led_t
*) handler
->ptr
;
1487 len
= sprintf(page
, "f\n");
1489 if (led
->gpio
& GPIO_TYPE_EXTIF
) {
1490 len
= sprintf(page
, "%d\n", led
->state
);
1492 u32 in
= (gpio_in() & led
->gpio
? 1 : 0);
1493 u8 p
= (led
->polarity
== NORMAL
? 0 : 1);
1494 len
= sprintf(page
, "%d\n", ((in
^ p
) ? 1 : 0));
1500 len
= sprintf(page
, "%s\n", platform
.name
);
1503 len
= sprintf(page
, "0x%04x\n", gpiomask
);
1510 len
= min_t(int, len
- *ppos
, count
);
1511 if (copy_to_user(buf
, (page
+ *ppos
), len
)) {
1525 static ssize_t
diag_proc_write(struct file
*file
, const char *buf
, size_t count
, loff_t
*ppos
)
1527 struct proc_dir_entry
*dent
= PDE(file
->f_dentry
->d_inode
);
1531 if ((page
= kmalloc(count
+ 1, GFP_KERNEL
)) == NULL
)
1534 if (copy_from_user(page
, buf
, count
)) {
1540 if (dent
->data
!= NULL
) {
1541 struct prochandler_t
*handler
= (struct prochandler_t
*) dent
->data
;
1542 switch (handler
->type
) {
1544 struct led_t
*led
= (struct led_t
*) handler
->ptr
;
1545 int p
= (led
->polarity
== NORMAL
? 0 : 1);
1547 if (page
[0] == 'f') {
1552 if (led
->gpio
& GPIO_TYPE_EXTIF
) {
1553 led
->state
= p
^ ((page
[0] == '1') ? 1 : 0);
1556 gpio_outen(led
->gpio
, led
->gpio
);
1557 gpio_control(led
->gpio
, 0);
1558 gpio_out(led
->gpio
, ((p
^ (page
[0] == '1')) ? led
->gpio
: 0));
1564 gpiomask
= simple_strtoul(page
, NULL
, 0);
1566 if (platform
.buttons
) {
1567 unregister_buttons(platform
.buttons
);
1568 register_buttons(platform
.buttons
);
1571 if (platform
.leds
) {
1572 unregister_leds(platform
.leds
);
1573 register_leds(platform
.leds
);
1584 static int __init
diag_init(void)
1586 static struct proc_dir_entry
*p
;
1587 static struct platform_t
*detected
;
1589 detected
= platform_detect();
1591 printk(MODULE_NAME
": Router model not detected.\n");
1594 memcpy(&platform
, detected
, sizeof(struct platform_t
));
1596 printk(MODULE_NAME
": Detected '%s'\n", platform
.name
);
1597 if (platform
.platform_init
!= NULL
) {
1598 platform
.platform_init();
1601 if (!(diag
= proc_mkdir("diag", NULL
))) {
1602 printk(MODULE_NAME
": proc_mkdir on /proc/diag failed\n");
1606 if ((p
= create_proc_entry("model", S_IRUSR
, diag
))) {
1607 p
->data
= (void *) &proc_model
;
1608 p
->proc_fops
= &diag_proc_fops
;
1611 if ((p
= create_proc_entry("gpiomask", S_IRUSR
| S_IWUSR
, diag
))) {
1612 p
->data
= (void *) &proc_gpiomask
;
1613 p
->proc_fops
= &diag_proc_fops
;
1616 if (platform
.buttons
)
1617 register_buttons(platform
.buttons
);
1620 register_leds(platform
.leds
);
1625 static void __exit
diag_exit(void)
1627 del_timer(&led_timer
);
1629 if (platform
.buttons
)
1630 unregister_buttons(platform
.buttons
);
1633 unregister_leds(platform
.leds
);
1635 remove_proc_entry("model", diag
);
1636 remove_proc_entry("gpiomask", diag
);
1637 remove_proc_entry("diag", NULL
);
1640 module_init(diag_init
);
1641 module_exit(diag_exit
);
1643 MODULE_AUTHOR("Mike Baker, Felix Fietkau / OpenWrt.org");
1644 MODULE_LICENSE("GPL");