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);
139 /* Western Digital */
155 static void __init
bcm4780_init(void) {
158 /* Enables GPIO 3 that controls HDD and led power on ASUS WL-700gE */
159 printk(MODULE_NAME
": Spinning up HDD and enabling leds\n");
160 bcm47xx_gpio_outen(pin
, pin
);
161 bcm47xx_gpio_control(pin
, 0);
162 bcm47xx_gpio_out(pin
, pin
);
164 /* Wait 5s, so the HDD can spin up */
165 set_current_state(TASK_INTERRUPTIBLE
);
166 schedule_timeout(HZ
* 5);
169 static void __init
NetCenter_init(void) {
170 /* unset pin 6 (+12V) */
172 bcm47xx_gpio_outen(pin
, pin
);
173 bcm47xx_gpio_control(pin
, 0);
174 bcm47xx_gpio_out(pin
, pin
);
175 /* unset pin 1 (turn off red led, blue will light alone if +5V comes up) */
177 bcm47xx_gpio_outen(pin
, pin
);
178 bcm47xx_gpio_control(pin
, 0);
179 bcm47xx_gpio_out(pin
, pin
);
180 /* unset pin 3 (+5V) and wait 5 seconds (harddisk spin up) */
184 static void __init
bcm57xx_init(void) {
187 /* FIXME: switch comes up, but port mappings/vlans not right */
188 bcm47xx_gpio_outen(pin
, pin
);
189 bcm47xx_gpio_control(pin
, 0);
190 bcm47xx_gpio_out(pin
, pin
);
193 static struct platform_t __initdata platforms
[] = {
196 .name
= "Linksys WAP54G V1",
198 { .name
= "reset", .gpio
= 1 << 0 },
201 { .name
= "diag", .gpio
= 1 << 3 },
202 { .name
= "wlan", .gpio
= 1 << 4 },
206 .name
= "Linksys WAP54G V2",
208 { .name
= "reset", .gpio
= 1 << 0 },
211 { .name
= "wlan", .gpio
= 1 << 5, .polarity
= REVERSE
},
212 /* GPIO 6 is b44 (eth0, LAN) PHY power */
216 .name
= "Linksys WAP54G V3",
218 /* FIXME: verify this */
219 { .name
= "reset", .gpio
= 1 << 7 },
220 { .name
= "ses", .gpio
= 1 << 0 },
224 { .name
= "ses", .gpio
= 1 << 1 },
228 .name
= "Linksys WRT54G V1.x",
230 { .name
= "reset", .gpio
= 1 << 6 },
233 { .name
= "diag", .gpio
= 0x13 | GPIO_TYPE_EXTIF
, .polarity
= NORMAL
},
234 { .name
= "dmz", .gpio
= 0x12 | GPIO_TYPE_EXTIF
, .polarity
= NORMAL
},
238 .name
= "Linksys WRT54G/GS/GL",
240 { .name
= "reset", .gpio
= 1 << 6 },
241 { .name
= "ses", .gpio
= 1 << 4 },
244 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
245 { .name
= "dmz", .gpio
= 1 << 7, .polarity
= REVERSE
},
246 { .name
= "ses_white", .gpio
= 1 << 2, .polarity
= REVERSE
},
247 { .name
= "ses_orange", .gpio
= 1 << 3, .polarity
= REVERSE
},
248 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
252 .name
= "Linksys WRTSL54GS",
254 { .name
= "reset", .gpio
= 1 << 6 },
255 { .name
= "ses", .gpio
= 1 << 4 },
258 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
259 { .name
= "dmz", .gpio
= 1 << 0, .polarity
= REVERSE
},
260 { .name
= "ses_white", .gpio
= 1 << 5, .polarity
= REVERSE
},
261 { .name
= "ses_orange", .gpio
= 1 << 7, .polarity
= REVERSE
},
265 .name
= "Linksys WRT54G3G",
267 { .name
= "reset", .gpio
= 1 << 6 },
268 { .name
= "3g", .gpio
= 1 << 4 },
271 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
272 { .name
= "dmz", .gpio
= 1 << 7, .polarity
= REVERSE
},
273 { .name
= "3g_green", .gpio
= 1 << 2, .polarity
= NORMAL
},
274 { .name
= "3g_blue", .gpio
= 1 << 3, .polarity
= NORMAL
},
275 { .name
= "3g_blink", .gpio
= 1 << 5, .polarity
= NORMAL
},
279 .name
= "Linksys WRT54G3GV2-VF",
281 { .name
= "reset", .gpio
= 1 << 6 },
282 { .name
= "3g", .gpio
= 1 << 5 },
285 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
286 { .name
= "3g_green", .gpio
= 1 << 2, .polarity
= NORMAL
},
287 { .name
= "3g_blue", .gpio
= 1 << 3, .polarity
= NORMAL
},
291 .name
= "Linksys WRT150N V1",
293 { .name
= "reset", .gpio
= 1 << 6 },
294 { .name
= "ses", .gpio
= 1 << 4 },
297 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
298 { .name
= "ses_green", .gpio
= 1 << 5, .polarity
= REVERSE
},
299 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
303 .name
= "Linksys WRT150N V1.1",
305 { .name
= "reset", .gpio
= 1 << 6 },
306 { .name
= "ses", .gpio
= 1 << 4 },
309 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
310 { .name
= "ses_green", .gpio
= 1 << 5, .polarity
= REVERSE
},
311 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
315 .name
= "Linksys WRT160N v1.x",
317 { .name
= "reset", .gpio
= 1 << 6 },
318 { .name
= "ses", .gpio
= 1 << 4 },
321 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
322 { .name
= "ses_blue", .gpio
= 1 << 5, .polarity
= REVERSE
},
323 { .name
= "ses_orange", .gpio
= 1 << 3, .polarity
= REVERSE
},
327 .name
= "Linksys WRT160N V3",
329 { .name
= "reset", .gpio
= 1 << 6 },
330 { .name
= "ses", .gpio
= 1 << 5 },
333 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
334 { .name
= "ses_blue", .gpio
= 1 << 4, .polarity
= REVERSE
},
335 { .name
= "ses_orange", .gpio
= 1 << 2, .polarity
= REVERSE
},
339 .name
= "Linksys WRT300N V1.1",
341 { .name
= "reset", .gpio
= 1 << 6 }, // "Reset" on back panel
342 { .name
= "ses", .gpio
= 1 << 4 }, // "Reserved" on top panel
345 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
}, // "Power"
346 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
}, // "Security" Amber
347 { .name
= "ses_green", .gpio
= 1 << 5, .polarity
= REVERSE
}, // "Security" Green
349 .platform_init
= bcm57xx_init
,
352 .name
= "Linksys WRT350N",
354 { .name
= "reset", .gpio
= 1 << 6 },
355 { .name
= "ses", .gpio
= 1 << 8 },
358 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
359 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
},
360 { .name
= "ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
},
361 { .name
= "usb_blink", .gpio
= 1 << 10, .polarity
= REVERSE
},
362 { .name
= "usb", .gpio
= 1 << 11, .polarity
= REVERSE
},
364 .platform_init
= bcm57xx_init
,
367 .name
= "Linksys WRT600N",
369 { .name
= "reset", .gpio
= 1 << 6 },
370 { .name
= "ses", .gpio
= 1 << 7 },
373 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
}, // Power LED
374 { .name
= "usb", .gpio
= 1 << 3, .polarity
= REVERSE
}, // USB LED
375 { .name
= "wl0_ses_amber", .gpio
= 1 << 8, .polarity
= REVERSE
}, // 2.4Ghz LED Amber
376 { .name
= "wl0_ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
}, // 2.4Ghz LED Green
377 { .name
= "wl1_ses_amber", .gpio
= 1 << 10, .polarity
= REVERSE
}, // 5.6Ghz LED Amber
378 { .name
= "wl1_ses_green", .gpio
= 1 << 11, .polarity
= REVERSE
}, // 5.6Ghz LED Green
380 .platform_init
= bcm57xx_init
,
383 .name
= "Linksys WRT600N V1.1",
385 { .name
= "reset", .gpio
= 1 << 6 },
386 { .name
= "ses", .gpio
= 1 << 7 },
389 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
}, // Power LED
390 { .name
= "usb", .gpio
= 1 << 3, .polarity
= REVERSE
}, // USB LED
391 { .name
= "wl0_ses_amber", .gpio
= 1 << 8, .polarity
= REVERSE
}, // 2.4Ghz LED Amber
392 { .name
= "wl0_ses_green", .gpio
= 1 << 9, .polarity
= REVERSE
}, // 2.4Ghz LED Green
393 { .name
= "wl1_ses_amber", .gpio
= 1 << 10, .polarity
= REVERSE
}, // 5.6Ghz LED Amber
394 { .name
= "wl1_ses_green", .gpio
= 1 << 11, .polarity
= REVERSE
}, // 5.6Ghz LED Green
396 .platform_init
= bcm57xx_init
,
399 .name
= "Linksys WRT610N",
401 { .name
= "reset", .gpio
= 1 << 6 },
402 { .name
= "ses", .gpio
= 1 << 8 },
405 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
}, // Power LED
406 { .name
= "usb", .gpio
= 1 << 0, .polarity
= REVERSE
}, // USB LED
407 { .name
= "ses_amber", .gpio
= 1 << 3, .polarity
= REVERSE
}, // WiFi protected setup LED amber
408 { .name
= "ses_blue", .gpio
= 1 << 9, .polarity
= REVERSE
}, // WiFi protected setup LED blue
412 .name
= "Linksys WRT610N V2",
414 { .name
= "reset", .gpio
= 1 << 6 },
415 { .name
= "ses", .gpio
= 1 << 4 },
418 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
}, // Power LED
419 { .name
= "usb", .gpio
= 1 << 7, .polarity
= NORMAL
}, // USB LED
420 { .name
= "ses_amber", .gpio
= 1 << 0, .polarity
= REVERSE
}, // WiFi protected setup LED amber
421 { .name
= "ses_blue", .gpio
= 1 << 3, .polarity
= REVERSE
}, // WiFi protected setup LED blue
422 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
}, // Wireless LED
425 /* same hardware as WRT160NV3 and Cisco Valet M10V1, but different board detection, combine? */
427 .name
= "Linksys E1000 V1",
429 { .name
= "reset", .gpio
= 1 << 6 },
430 { .name
= "wps", .gpio
= 1 << 5 }, /* nvram get gpio5=wps_button */
433 /** turns on leds for all ethernet ports (wan too)
434 * this also disconnects some, or maybe all, ethernet ports
435 * 1: leds work normally
436 * 0: all lit all the time */
437 /* nvram get gpio3=robo_reset */
438 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
439 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
440 { .name
= "ses_blue", .gpio
= 1 << 4, .polarity
= REVERSE
}, /* nvram get gpio4=wps_led */
441 { .name
= "ses_orange", .gpio
= 1 << 2, .polarity
= REVERSE
}, /* nvram get gpio2=wps_status_led */
445 .name
= "Linksys E3000 V1",
447 { .name
= "reset", .gpio
= 1 << 6 },
448 { .name
= "ses", .gpio
= 1 << 4 },
451 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
}, // Power LED
452 { .name
= "usb", .gpio
= 1 << 7, .polarity
= NORMAL
}, // USB LED
453 { .name
= "ses_amber", .gpio
= 1 << 0, .polarity
= REVERSE
}, // WiFi protected setup LED amber
454 { .name
= "ses_blue", .gpio
= 1 << 3, .polarity
= REVERSE
}, // WiFi protected setup LED blue
455 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
}, // Wireless LED
460 .name
= "ASUS WL-HDD",
462 { .name
= "reset", .gpio
= 1 << 6 },
465 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
466 { .name
= "usb", .gpio
= 1 << 2, .polarity
= REVERSE
},
470 .name
= "ASUS WL-300g",
472 { .name
= "reset", .gpio
= 1 << 6 },
475 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
479 .name
= "ASUS WL-320gE/WL-320gP",
481 { .name
= "reset", .gpio
= 1 << 6 },
484 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
485 { .name
= "power", .gpio
= 1 << 2, .polarity
= REVERSE
},
486 { .name
= "link", .gpio
= 1 << 11, .polarity
= REVERSE
},
490 .name
= "ASUS WL-330gE",
492 { .name
= "reset", .gpio
= 1 << 2 },
495 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
499 .name
= "ASUS WL-500g",
501 { .name
= "reset", .gpio
= 1 << 6 },
504 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
508 .name
= "ASUS WL-500g Deluxe",
510 { .name
= "reset", .gpio
= 1 << 6 },
513 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
517 .name
= "ASUS WL-500g Premium",
519 { .name
= "reset", .gpio
= 1 << 0 },
520 { .name
= "ses", .gpio
= 1 << 4 },
523 { .name
= "power", .gpio
= 1 << 1, .polarity
= REVERSE
},
527 .name
= "ASUS WL-500g Premium V2",
529 { .name
= "reset", .gpio
= 1 << 2 },
530 { .name
= "ses", .gpio
= 1 << 3 },
533 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
534 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
538 .name
= "ASUS WL-500W",
540 { .name
= "reset", .gpio
= 1 << 6 },
541 { .name
= "ses", .gpio
= 1 << 7 },
544 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
548 .name
= "ASUS WL-520GC",
550 { .name
= "reset", .gpio
= 1 << 2 },
551 { .name
= "ses", .gpio
= 1 << 3 },
554 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
555 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
559 .name
= "ASUS WL-520gU",
561 { .name
= "reset", .gpio
= 1 << 2 },
562 { .name
= "ses", .gpio
= 1 << 3 },
565 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
566 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
570 .name
= "ASUS (unknown, BCM4702)",
572 { .name
= "reset", .gpio
= 1 << 6 },
575 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
579 .name
= "ASUS WL-700gE",
581 { .name
= "reset", .gpio
= 1 << 7 }, // on back, hardwired, always resets device regardless OS state
582 { .name
= "ses", .gpio
= 1 << 4 }, // on back, actual name ezsetup
583 { .name
= "power", .gpio
= 1 << 0 }, // on front
584 { .name
= "copy", .gpio
= 1 << 6 }, // on front
588 // GPIO that controls power led also enables/disables some essential functions
591 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
}, // actual name power
593 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
595 .platform_init
= bcm4780_init
,
598 .name
= "ASUS RT-N16",
600 { .name
= "reset", .gpio
= 1 << 8 },
601 { .name
= "ses", .gpio
= 1 << 5 },
604 { .name
= "power", .gpio
= 1 << 1, .polarity
= REVERSE
},
605 { .name
= "wlan", .gpio
= 1 << 7, .polarity
= NORMAL
},
610 .name
= "Buffalo WHR-G54S",
612 { .name
= "reset", .gpio
= 1 << 4 },
613 { .name
= "bridge", .gpio
= 1 << 5 },
614 { .name
= "ses", .gpio
= 1 << 0 },
617 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
618 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
619 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
620 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
621 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
625 .name
= "Buffalo WBR2-G54",
628 { .name
= "reset", .gpio
= 1 << 7 },
631 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
635 .name
= "Buffalo WHR-HP-G54",
637 { .name
= "reset", .gpio
= 1 << 4 },
638 { .name
= "bridge", .gpio
= 1 << 5 },
639 { .name
= "ses", .gpio
= 1 << 0 },
642 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
643 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
644 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
645 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
646 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
650 .name
= "Buffalo WHR-G125",
652 { .name
= "reset", .gpio
= 1 << 4 },
653 { .name
= "bridge", .gpio
= 1 << 5 },
654 { .name
= "ses", .gpio
= 1 << 0 },
657 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
658 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
659 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
660 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
661 { .name
= "wlan", .gpio
= 1 << 2, .polarity
= REVERSE
},
665 .name
= "Buffalo WHR2-A54G54",
667 { .name
= "reset", .gpio
= 1 << 4 },
670 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
674 .name
= "Buffalo WLA2-G54L",
677 { .name
= "reset", .gpio
= 1 << 7 },
680 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
684 .name
= "Buffalo WZR-G300N",
686 { .name
= "reset", .gpio
= 1 << 4 },
689 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
690 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
691 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
695 .name
= "Buffalo WZR-RS-G54",
697 { .name
= "ses", .gpio
= 1 << 0 },
698 { .name
= "reset", .gpio
= 1 << 4 },
701 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
702 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
703 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
707 .name
= "Buffalo WZR-RS-G54HP",
709 { .name
= "ses", .gpio
= 1 << 0 },
710 { .name
= "reset", .gpio
= 1 << 4 },
713 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
714 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
715 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
718 [BUFFALO_UNKNOWN
] = {
719 .name
= "Buffalo (unknown)",
721 { .name
= "reset", .gpio
= 1 << 7 },
724 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
727 [BUFFALO_UNKNOWN_4710
] = {
728 .name
= "Buffalo (unknown, BCM4710)",
730 { .name
= "reset", .gpio
= 1 << 4 },
733 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
738 .name
= "Siemens SE505 V1",
740 /* No usable buttons */
743 // { .name = "power", .gpio = 1 << 0 .polarity = REVERSE }, // Usable when retrofitting D26 (?)
744 { .name
= "dmz", .gpio
= 1 << 4, .polarity
= REVERSE
}, // actual name WWW
745 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
749 .name
= "Siemens SE505 V2",
751 /* No usable buttons */
754 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
755 { .name
= "dmz", .gpio
= 1 << 0, .polarity
= REVERSE
}, // actual name WWW
756 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
761 .name
= "U.S. Robotics USR5461",
763 /* No usable buttons */
766 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
767 { .name
= "printer", .gpio
= 1 << 1, .polarity
= REVERSE
},
772 .name
= "Dell TrueMobile 2300",
774 { .name
= "reset", .gpio
= 1 << 0 },
777 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
778 { .name
= "power", .gpio
= 1 << 7, .polarity
= REVERSE
},
782 .name
= "Dell TrueMobile 2300 v2",
784 { .name
= "reset", .gpio
= 1 << 0 },
787 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
788 { .name
= "power", .gpio
= 1 << 7, .polarity
= REVERSE
},
793 .name
= "Motorola WE800G",
795 { .name
= "reset", .gpio
= 1 << 0 },
798 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
799 { .name
= "diag", .gpio
= 1 << 2, .polarity
= REVERSE
},
800 { .name
= "wlan_amber", .gpio
= 1 << 1, .polarity
= NORMAL
},
804 .name
= "Motorola WR850G V1",
806 { .name
= "reset", .gpio
= 1 << 0 },
809 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
810 { .name
= "diag", .gpio
= 1 << 3, .polarity
= REVERSE
},
811 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= NORMAL
},
812 { .name
= "wlan_red", .gpio
= 1 << 5, .polarity
= REVERSE
},
813 { .name
= "wlan_green", .gpio
= 1 << 7, .polarity
= REVERSE
},
817 .name
= "Motorola WR850G V2/V3",
819 { .name
= "reset", .gpio
= 1 << 5 },
822 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
823 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
824 { .name
= "wan", .gpio
= 1 << 6, .polarity
= INPUT
},
825 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
829 .name
= "Motorola WR850GP",
831 { .name
= "reset", .gpio
= 1 << 5 },
834 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
835 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
836 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= REVERSE
},
837 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
843 .name
= "Belkin (unknown)",
844 /* FIXME: verify & add detection */
846 { .name
= "reset", .gpio
= 1 << 7 },
849 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
},
850 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= NORMAL
},
851 { .name
= "connected", .gpio
= 1 << 0, .polarity
= NORMAL
},
855 .name
= "Belkin PlayMax F7D4301",
857 { .name
= "reset", .gpio
= 1 << 6 },
858 { .name
= "wps", .gpio
= 1 << 8 },
861 { .name
= "power", .gpio
= 1 << 11, .polarity
= REVERSE
},
862 { .name
= "wlan", .gpio
= 1 << 13, .polarity
= REVERSE
},
863 { .name
= "led0", .gpio
= 1 << 14, .polarity
= REVERSE
},
864 { .name
= "led1", .gpio
= 1 << 15, .polarity
= REVERSE
},
869 .name
= "Netgear WGT634U",
871 { .name
= "reset", .gpio
= 1 << 2 },
874 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
},
879 .name
= "Netgear WNR834B V1",
880 .buttons
= { /* TODO: add reset button and confirm LEDs - GPIO from dd-wrt */ },
882 { .name
= "power", .gpio
= 1 << 4, .polarity
= REVERSE
},
883 { .name
= "diag", .gpio
= 1 << 5, .polarity
= REVERSE
},
884 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
889 .name
= "Netgear WNR834B V2",
891 { .name
= "reset", .gpio
= 1 << 6 },
894 { .name
= "power", .gpio
= 1 << 2, .polarity
= NORMAL
},
895 { .name
= "diag", .gpio
= 1 << 3, .polarity
= NORMAL
},
896 { .name
= "connected", .gpio
= 1 << 7, .polarity
= NORMAL
},
901 .name
= "Trendware TEW411BRP+",
903 { /* No usable buttons */ },
906 { .name
= "power", .gpio
= 1 << 7, .polarity
= NORMAL
},
907 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
},
908 { .name
= "bridge", .gpio
= 1 << 6, .polarity
= NORMAL
},
913 .name
= "SimpleTech SimpleShare NAS",
915 { .name
= "reset", .gpio
= 1 << 0 }, // Power button on back, named reset to enable failsafe.
918 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
920 .platform_init
= bcm4780_init
,
924 .name
= "D-Link DIR-130",
926 { .name
= "reset", .gpio
= 1 << 3},
927 { .name
= "reserved", .gpio
= 1 << 7},
930 { .name
= "diag", .gpio
= 1 << 0},
931 { .name
= "blue", .gpio
= 1 << 6},
935 .name
= "D-Link DIR-320",
937 { .name
= "reserved", .gpio
= 1 << 6},
938 { .name
= "reset", .gpio
= 1 << 7},
941 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
942 { .name
= "diag", .gpio
= 1 << 1, .polarity
= NORMAL
}, /* "status led */
943 { .name
= "red", .gpio
= 1 << 3, .polarity
= REVERSE
},
944 { .name
= "blue", .gpio
= 1 << 4, .polarity
= REVERSE
},
945 { .name
= "usb", .gpio
= 1 << 5, .polarity
= NORMAL
},
949 .name
= "D-Link DIR-330",
951 { .name
= "reset", .gpio
= 1 << 3},
952 { .name
= "reserved", .gpio
= 1 << 7},
955 { .name
= "diag", .gpio
= 1 << 0},
956 { .name
= "usb", .gpio
= 1 << 4},
957 { .name
= "blue", .gpio
= 1 << 6},
961 .name
= "D-Link DWL-3150",
963 { .name
= "reset", .gpio
= 1 << 7},
966 { .name
= "diag", .gpio
= 1 << 2},
967 { .name
= "status", .gpio
= 1 << 1},
972 .name
= "Sitecom WL-105b",
974 { .name
= "reset", .gpio
= 1 << 10},
977 { .name
= "wlan", .gpio
= 1 << 4},
978 { .name
= "power", .gpio
= 1 << 3},
981 /* Western Digital Net Center */
983 .name
= "Western Digital NetCenter",
985 { .name
= "power", .gpio
= 1 << 0},
986 { .name
= "reset", .gpio
= 1 << 7},
988 .platform_init
= NetCenter_init
,
990 /* Askey (and clones) */
992 .name
= "Askey RT210W",
994 /* Power button is hard-wired to hardware reset */
995 /* but is also connected to GPIO 7 (probably for bootloader recovery) */
996 { .name
= "power", .gpio
= 1 << 7},
999 /* These were verified and named based on Belkin F5D4230-4 v1112 */
1000 { .name
= "connected", .gpio
= 1 << 0, .polarity
= REVERSE
},
1001 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
1002 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
1006 .name
= "OvisLink WL-1600GL",
1008 { .name
= "reset", .gpio
= 1 << 3 },
1009 { .name
= "ses", .gpio
= 1 << 4 },
1012 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
1013 { .name
= "wps", .gpio
= 1 << 2, .polarity
= REVERSE
},
1014 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= REVERSE
},
1015 { .name
= "connected", .gpio
= 1 << 0, .polarity
= REVERSE
},
1020 .name
= "Microsoft MN-700",
1022 { .name
= "reset", .gpio
= 1 << 7 },
1025 { .name
= "power", .gpio
= 1 << 6, .polarity
= NORMAL
},
1030 .name
= "Edimax PS-1208MFG",
1032 { .name
= "reset", .gpio
= 1 << 4 },
1035 { .name
= "status", .gpio
= 1 << 1, .polarity
= NORMAL
},
1036 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= NORMAL
},
1041 static struct platform_t __init
*platform_detect(void)
1043 char *boardnum
, *boardtype
, *buf
;
1045 if (strcmp(getvar("nvram_type"), "cfe") == 0)
1046 return &platforms
[WGT634U
];
1048 /* Look for a model identifier */
1050 /* Based on "model_name" */
1051 if ((buf
= nvram_get("model_name"))) {
1052 if (!strcmp(buf
, "DIR-130"))
1053 return &platforms
[DIR130
];
1054 if (!strcmp(buf
, "DIR-330"))
1055 return &platforms
[DIR330
];
1058 /* Based on "wsc_modelname */
1059 if ((buf
= nvram_get("wsc_modelname"))) {
1060 if (!strcmp(buf
, "WRT610N"))
1061 return &platforms
[WRT610N
];
1064 /* Based on "model_no" */
1065 if ((buf
= nvram_get("model_no"))) {
1066 if (startswith(buf
,"WL700")) /* WL700* */
1067 return &platforms
[WL700GE
];
1070 /* Based on "hardware_version" */
1071 if ((buf
= nvram_get("hardware_version"))) {
1072 if (startswith(buf
,"WL500GPV2-")) /* WL500GPV2-* */
1073 return &platforms
[WL500GPV2
];
1074 if (startswith(buf
,"WL520GC-")) /* WL520GU-* */
1075 return &platforms
[WL520GC
];
1076 if (startswith(buf
,"WL520GU-")) /* WL520GU-* */
1077 return &platforms
[WL520GU
];
1078 if (startswith(buf
,"WL330GE-")) /* WL330GE-* */
1079 return &platforms
[WL330GE
];
1080 if (startswith(buf
,"RT-N16-")) /* RT-N16-* */
1081 return &platforms
[RTN16
];
1082 if (startswith(buf
,"F7D4301")) /* F7D4301* */
1083 return &platforms
[BELKIN_F7D4301
];
1086 /* Based on "ModelId" */
1087 if ((buf
= nvram_get("ModelId"))) {
1088 if (!strcmp(buf
, "WR850GP"))
1089 return &platforms
[WR850GP
];
1090 if (!strcmp(buf
, "WR850G"))
1091 return &platforms
[WR850GV2V3
];
1092 if (!strcmp(buf
, "WX-5565") && !strcmp(getvar("boardtype"),"bcm94710ap"))
1093 return &platforms
[TM2300
]; /* Dell TrueMobile 2300 */
1094 if (startswith(buf
,"WE800G")) /* WE800G* */
1095 return &platforms
[WE800G
];
1099 if ((buf
= (nvram_get("melco_id") ?: nvram_get("buffalo_id")))) {
1100 /* Buffalo hardware, check id for specific hardware matches */
1101 if (!strcmp(buf
, "29bb0332"))
1102 return &platforms
[WBR2_G54
];
1103 if (!strcmp(buf
, "29129"))
1104 return &platforms
[WLA2_G54L
];
1105 if (!strcmp(buf
, "30189"))
1106 return &platforms
[WHR_HP_G54
];
1107 if (!strcmp(buf
, "32093"))
1108 return &platforms
[WHR_G125
];
1109 if (!strcmp(buf
, "30182"))
1110 return &platforms
[WHR_G54S
];
1111 if (!strcmp(buf
, "290441dd"))
1112 return &platforms
[WHR2_A54G54
];
1113 if (!strcmp(buf
, "31120"))
1114 return &platforms
[WZR_G300N
];
1115 if (!strcmp(buf
, "30083"))
1116 return &platforms
[WZR_RS_G54
];
1117 if (!strcmp(buf
, "30103"))
1118 return &platforms
[WZR_RS_G54HP
];
1121 /* no easy model number, attempt to guess */
1122 boardnum
= getvar("boardnum");
1123 boardtype
= getvar("boardtype");
1125 if (!strcmp(boardnum
, "20070615")) { /* Linksys WRT600N v1/V1.1 */
1126 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "0") && !strcmp(getvar("switch_type"),"BCM5395"))
1127 return &platforms
[WRT600NV11
];
1129 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "0"))
1130 return &platforms
[WRT600N
];
1134 * Normally, these would go inside the "CFE based - newer hardware" block below; however, during early init, the
1135 * "pmon_ver" variable is not available on the E3000v1 (and probably the WRT610Nv2 also). Until this is figured out,
1136 * these will need to remain here in order for platform detection to work.
1138 if (!strcmp(boardnum
, "42")) { /* Linksys */
1139 if (!strcmp(boardtype
, "0x04cf") && !strcmp(getvar("boot_hw_model"), "E300") && !strcmp(getvar("boot_hw_ver"), "1.0"))
1140 return &platforms
[E3000V1
];
1142 if (!strcmp(boardtype
, "0x04cf") && !strcmp(getvar("boot_hw_model"), "WRT610N") && !strcmp(getvar("boot_hw_ver"), "2.0"))
1143 return &platforms
[WRT610NV2
];
1146 if (startswith(getvar("pmon_ver"), "CFE")) {
1147 /* CFE based - newer hardware */
1148 if (!strcmp(boardnum
, "42")) { /* Linksys */
1149 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("boot_hw_model"), "WRT300N") && !strcmp(getvar("boot_hw_ver"), "1.1"))
1150 return &platforms
[WRT300NV11
];
1152 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "1"))
1153 return &platforms
[WRT350N
];
1155 if (!strcmp(boardtype
, "0x0101") && !strcmp(getvar("boot_ver"), "v3.6"))
1156 return &platforms
[WRT54G3G
];
1158 if (!strcmp(boardtype
, "0x042f") && !strcmp(getvar("model_name"), "WRT54G3GV2-VF"))
1159 return &platforms
[WRT54G3GV2_VF
];
1161 if (!strcmp(getvar("et1phyaddr"),"5") && !strcmp(getvar("et1mdcport"), "1"))
1162 return &platforms
[WRTSL54GS
];
1164 if (!strcmp(boardtype
, "0x0472")) {
1165 if(!strcmp(getvar("boot_hw_model"), "WRT150N")) {
1166 if(!strcmp(getvar("boot_hw_ver"), "1"))
1167 return &platforms
[WRT150NV1
];
1168 else if(!strcmp(getvar("boot_hw_ver"), "1.1"))
1169 return &platforms
[WRT150NV11
];
1171 else if(!strcmp(getvar("boot_hw_model"), "WRT160N")) {
1172 if(!strcmp(getvar("boot_hw_ver"), "1.0"))
1173 return &platforms
[WRT160NV1
];
1174 else if(!strcmp(getvar("boot_hw_ver"), "3.0"))
1175 return &platforms
[WRT160NV3
];
1179 if (!strcmp(boardtype
, "0x04cd")) {
1180 if (!strcmp(getvar("boot_hw_model"), "E100")) {
1181 if (!strcmp(getvar("boot_hw_ver"), "1.0"))
1182 return &platforms
[E1000V1
];
1186 /* default to WRT54G */
1187 return &platforms
[WRT54G
];
1189 if (!strcmp(boardnum
, "1024") && !strcmp(boardtype
, "0x0446"))
1190 return &platforms
[WAP54GV2
];
1192 if (!strcmp(boardnum
, "8") && !strcmp(boardtype
, "0x048e"))
1193 return &platforms
[WL1600GL
];
1196 if (!strcmp(boardnum
, "44") || !strcmp(boardnum
, "44\r")) {
1197 if (!strcmp(boardtype
,"0x0101") || !strcmp(boardtype
, "0x0101\r"))
1198 return &platforms
[TM2300V2
]; /* Dell TrueMobile 2300 v2 */
1201 if (!strcmp(boardnum
, "45")) { /* ASUS */
1202 if (!strcmp(boardtype
,"0x042f"))
1203 return &platforms
[WL500GP
];
1204 else if (!strcmp(boardtype
,"0x0472"))
1205 return &platforms
[WL500W
];
1206 else if (!strcmp(boardtype
,"0x467"))
1207 return &platforms
[WL320GE
];
1209 return &platforms
[WL500GD
];
1212 if (!strcmp(boardnum
, "10496"))
1213 return &platforms
[USR5461
];
1215 if (!strcmp(getvar("boardtype"), "0x0101") && !strcmp(getvar("boardrev"), "0x10")) /* SE505V2 With Modified CFE */
1216 return &platforms
[SE505V2
];
1218 if (!strcmp(boardtype
, "0x048e") && !strcmp(getvar("boardrev"),"0x35") &&
1219 !strcmp(getvar("boardflags"), "0x750")) /* D-Link DIR-320 */
1220 return &platforms
[DIR320
];
1222 if (!strncmp(boardnum
, "TH",2) && !strcmp(boardtype
,"0x042f")) {
1223 return &platforms
[WDNetCenter
];
1226 if (!strcmp(boardtype
,"0x0472") && !strcmp(getvar("cardbus"), "1")) { /* Netgear WNR834B V1 and V2*/
1227 if (!strcmp(boardnum
, "08") || !strcmp(boardnum
, "8"))
1228 return &platforms
[WNR834BV1
];
1229 if (!strcmp(boardnum
, "01") || !strcmp(boardnum
, "1"))
1230 return &platforms
[WNR834BV2
];
1233 } else { /* PMON based - old stuff */
1234 if ((simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 9) &&
1235 (simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 30)) {
1236 return &platforms
[WR850GV1
];
1238 if (startswith(boardtype
, "bcm94710dev")) {
1239 if (!strcmp(boardnum
, "42"))
1240 return &platforms
[WRT54GV1
];
1241 if (simple_strtoul(boardnum
, NULL
, 0) == 2)
1242 return &platforms
[WAP54GV1
];
1244 /* MN-700 has also hardware_version 'WL500-...', so use boardnum */
1245 if (startswith(getvar("hardware_version"), "WL500-")) {
1246 if (!strcmp(getvar("boardnum"), "mn700"))
1247 return &platforms
[MN700
];
1249 return &platforms
[WL500G
];
1251 if (startswith(getvar("hardware_version"), "WL300-")) {
1252 /* Either WL-300g or WL-HDD, do more extensive checks */
1253 if ((simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 0) &&
1254 (simple_strtoul(getvar("et1phyaddr"), NULL
, 0) == 1))
1255 return &platforms
[WLHDD
];
1256 if ((simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 0) &&
1257 (simple_strtoul(getvar("et1phyaddr"), NULL
, 0) == 10))
1258 return &platforms
[WL300G
];
1260 /* Sitecom WL-105b */
1261 if (startswith(boardnum
, "2") && simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 1)
1262 return &platforms
[WL105B
];
1264 /* unknown asus stuff, probably bcm4702 */
1265 if (startswith(boardnum
, "asusX"))
1266 return &platforms
[ASUS_4702
];
1268 /* bcm4702 based Askey RT210W clones, Including:
1269 * Askey RT210W (duh?)
1271 * Belkin F5D7230-4 before version v1444 (MiniPCI slot, not integrated)
1273 if (!strcmp(boardtype
,"bcm94710r4")
1274 && !strcmp(boardnum
,"100")
1275 && !strcmp(getvar("pmon_ver"),"v1.03.12.bk")
1277 return &platforms
[RT210W
];
1281 if (buf
|| !strcmp(boardnum
, "00")) {/* probably buffalo */
1282 if (startswith(boardtype
, "bcm94710ap"))
1283 return &platforms
[BUFFALO_UNKNOWN_4710
];
1285 return &platforms
[BUFFALO_UNKNOWN
];
1288 if (startswith(getvar("CFEver"), "MotoWRv2") ||
1289 startswith(getvar("CFEver"), "MotoWRv3") ||
1290 !strcmp(getvar("MOTO_BOARD_TYPE"), "WR_FEM1")) {
1292 return &platforms
[WR850GV2V3
];
1295 if (!strcmp(boardnum
, "44") && !strcmp(getvar("boardflags"),"0x0388")) { /* Trendware TEW-411BRP+ */
1296 return &platforms
[TEW411BRPP
];
1299 if (startswith(boardnum
, "04FN")) /* SimpleTech SimpleShare */
1300 return &platforms
[STI_NAS
];
1302 if (!strcmp(boardnum
, "10") && !strcmp(getvar("boardrev"), "0x13")) /* D-Link DWL-3150 */
1303 return &platforms
[DWL3150
];
1305 if (!strcmp(boardnum
, "01") && !strcmp(boardtype
, "0x048e") && /* Edimax PS1208MFG */
1306 !strcmp(getvar("status_gpio"), "1")) /* gpio based detection */
1307 return &platforms
[PS1208MFG
];
1313 static inline void ssb_maskset32(struct ssb_device
*dev
,
1314 u16 offset
, u32 mask
, u32 set
)
1316 ssb_write32(dev
, offset
, (ssb_read32(dev
, offset
) & mask
) | set
);
1319 static void gpio_set_irqenable(int enabled
, irqreturn_t (*handler
)(int, void *))
1323 irq
= gpio_to_irq(0);
1324 if (irq
== -EINVAL
) return;
1327 if (request_irq(irq
, handler
, IRQF_SHARED
, "gpio", handler
))
1330 free_irq(irq
, handler
);
1333 switch (bcm47xx_bus_type
) {
1334 #ifdef CONFIG_BCM47XX_SSB
1335 case BCM47XX_BUS_TYPE_SSB
:
1336 if (bcm47xx_bus
.ssb
.chipco
.dev
)
1337 ssb_maskset32(bcm47xx_bus
.ssb
.chipco
.dev
, SSB_CHIPCO_IRQMASK
, ~SSB_CHIPCO_IRQ_GPIO
, (enabled
? SSB_CHIPCO_IRQ_GPIO
: 0));
1340 #ifdef CONFIG_BCM47XX_BCMA
1341 case BCM47XX_BUS_TYPE_BCMA
:
1342 if (bcm47xx_bus
.bcma
.bus
.drv_cc
.core
)
1343 bcma_maskset32(bcm47xx_bus
.bcma
.bus
.drv_cc
.core
, BCMA_CC_IRQMASK
, ~BCMA_CC_IRQ_GPIO
, (enabled
? BCMA_CC_IRQ_GPIO
: 0));
1349 static void register_buttons(struct button_t
*b
)
1351 for (; b
->name
; b
++)
1352 platform
.button_mask
|= b
->gpio
;
1354 platform
.button_mask
&= ~gpiomask
;
1356 bcm47xx_gpio_outen(platform
.button_mask
, 0);
1357 bcm47xx_gpio_control(platform
.button_mask
, 0);
1358 platform
.button_polarity
= bcm47xx_gpio_in(~0) & platform
.button_mask
;
1359 bcm47xx_gpio_polarity(platform
.button_mask
, platform
.button_polarity
);
1360 bcm47xx_gpio_intmask(platform
.button_mask
, platform
.button_mask
);
1362 gpio_set_irqenable(1, button_handler
);
1365 static void unregister_buttons(struct button_t
*b
)
1367 bcm47xx_gpio_intmask(platform
.button_mask
, 0);
1369 gpio_set_irqenable(0, button_handler
);
1373 static void add_msg(struct event_t
*event
, char *msg
, int argv
)
1380 s
= skb_put(event
->skb
, strlen(msg
) + 1);
1384 static void hotplug_button(struct work_struct
*work
)
1386 struct event_t
*event
= container_of(work
, struct event_t
, wq
);
1389 event
->skb
= alloc_skb(2048, GFP_KERNEL
);
1391 s
= skb_put(event
->skb
, strlen(event
->action
) + 2);
1392 sprintf(s
, "%s@", event
->action
);
1395 NETLINK_CB(event
->skb
).dst_group
= 1;
1396 broadcast_uevent(event
->skb
, 0, 1, GFP_KERNEL
);
1402 static int fill_event (struct event_t
*event
)
1404 static char buf
[128];
1406 add_msg(event
, "HOME=/", 0);
1407 add_msg(event
, "PATH=/sbin:/bin:/usr/sbin:/usr/bin", 0);
1408 add_msg(event
, "SUBSYSTEM=button", 0);
1409 snprintf(buf
, 128, "ACTION=%s", event
->action
);
1410 add_msg(event
, buf
, 0);
1411 snprintf(buf
, 128, "BUTTON=%s", event
->name
);
1412 add_msg(event
, buf
, 0);
1413 snprintf(buf
, 128, "SEEN=%ld", event
->seen
);
1414 add_msg(event
, buf
, 0);
1415 snprintf(buf
, 128, "SEQNUM=%llu", uevent_next_seqnum());
1416 add_msg(event
, buf
, 0);
1422 static irqreturn_t
button_handler(int irq
, void *dev_id
)
1427 in
= bcm47xx_gpio_in(~0) & platform
.button_mask
;
1428 bcm47xx_gpio_polarity(platform
.button_mask
, in
);
1429 changed
= platform
.button_polarity
^ in
;
1430 platform
.button_polarity
= in
;
1432 changed
&= ~bcm47xx_gpio_outen(0, 0);
1434 for (b
= platform
.buttons
; b
->name
; b
++) {
1435 struct event_t
*event
;
1437 if (!(b
->gpio
& changed
)) continue;
1441 if ((event
= (struct event_t
*)kzalloc (sizeof(struct event_t
), GFP_ATOMIC
))) {
1442 event
->seen
= (jiffies
- b
->seen
)/HZ
;
1443 event
->name
= b
->name
;
1444 event
->action
= b
->pressed
? "pressed" : "released";
1445 INIT_WORK(&event
->wq
, (void *)(void *)hotplug_button
);
1446 schedule_work(&event
->wq
);
1454 static void register_leds(struct led_t
*l
)
1456 struct proc_dir_entry
*p
;
1461 leds
= proc_mkdir("led", diag
);
1465 for(; l
->name
; l
++) {
1466 if (l
->gpio
& gpiomask
)
1469 if (l
->gpio
& GPIO_TYPE_EXTIF
) {
1473 if (l
->polarity
!= INPUT
) oe_mask
|= l
->gpio
;
1475 val
|= (l
->polarity
== NORMAL
)?0:l
->gpio
;
1478 if (l
->polarity
== INPUT
) continue;
1480 if ((p
= create_proc_entry(l
->name
, S_IRUSR
, leds
))) {
1481 l
->proc
.type
= PROC_LED
;
1483 p
->data
= (void *) &l
->proc
;
1484 p
->proc_fops
= &diag_proc_fops
;
1488 bcm47xx_gpio_outen(mask
, oe_mask
);
1489 bcm47xx_gpio_control(mask
, 0);
1490 bcm47xx_gpio_out(mask
, val
);
1491 bcm47xx_gpio_intmask(mask
, 0);
1494 static void unregister_leds(struct led_t
*l
)
1497 remove_proc_entry(l
->name
, leds
);
1499 remove_proc_entry("led", diag
);
1502 static void set_led_extif(struct led_t
*led
)
1504 volatile u8
*addr
= (volatile u8
*) KSEG1ADDR(EXTIF_UART
) + (led
->gpio
& ~GPIO_TYPE_MASK
);
1511 static void led_flash(unsigned long dummy
) {
1516 for (l
= platform
.leds
; l
->name
; l
++) {
1518 if (l
->gpio
& GPIO_TYPE_EXTIF
) {
1520 l
->state
= !l
->state
;
1530 u32 val
= ~bcm47xx_gpio_in(~0);
1532 bcm47xx_gpio_outen(mask
, mask
);
1533 bcm47xx_gpio_control(mask
, 0);
1534 bcm47xx_gpio_out(mask
, val
);
1536 if (mask
|| extif_blink
) {
1537 mod_timer(&led_timer
, jiffies
+ FLASH_TIME
);
1541 static ssize_t
diag_proc_read(struct file
*file
, char *buf
, size_t count
, loff_t
*ppos
)
1543 struct proc_dir_entry
*dent
= PDE(file
->f_dentry
->d_inode
);
1547 if ((page
= kmalloc(1024, GFP_KERNEL
)) == NULL
)
1550 if (dent
->data
!= NULL
) {
1551 struct prochandler_t
*handler
= (struct prochandler_t
*) dent
->data
;
1552 switch (handler
->type
) {
1554 struct led_t
* led
= (struct led_t
*) handler
->ptr
;
1556 len
= sprintf(page
, "f\n");
1558 if (led
->gpio
& GPIO_TYPE_EXTIF
) {
1559 len
= sprintf(page
, "%d\n", led
->state
);
1561 u32 in
= (bcm47xx_gpio_in(~0) & led
->gpio
? 1 : 0);
1562 u8 p
= (led
->polarity
== NORMAL
? 0 : 1);
1563 len
= sprintf(page
, "%d\n", ((in
^ p
) ? 1 : 0));
1569 len
= sprintf(page
, "%s\n", platform
.name
);
1572 len
= sprintf(page
, "0x%04x\n", gpiomask
);
1579 len
= min_t(int, len
- *ppos
, count
);
1580 if (copy_to_user(buf
, (page
+ *ppos
), len
)) {
1594 static ssize_t
diag_proc_write(struct file
*file
, const char *buf
, size_t count
, loff_t
*ppos
)
1596 struct proc_dir_entry
*dent
= PDE(file
->f_dentry
->d_inode
);
1600 if ((page
= kmalloc(count
+ 1, GFP_KERNEL
)) == NULL
)
1603 if (copy_from_user(page
, buf
, count
)) {
1609 if (dent
->data
!= NULL
) {
1610 struct prochandler_t
*handler
= (struct prochandler_t
*) dent
->data
;
1611 switch (handler
->type
) {
1613 struct led_t
*led
= (struct led_t
*) handler
->ptr
;
1614 int p
= (led
->polarity
== NORMAL
? 0 : 1);
1616 if (page
[0] == 'f') {
1621 if (led
->gpio
& GPIO_TYPE_EXTIF
) {
1622 led
->state
= p
^ ((page
[0] == '1') ? 1 : 0);
1625 bcm47xx_gpio_outen(led
->gpio
, led
->gpio
);
1626 bcm47xx_gpio_control(led
->gpio
, 0);
1627 bcm47xx_gpio_out(led
->gpio
, ((p
^ (page
[0] == '1')) ? led
->gpio
: 0));
1633 gpiomask
= simple_strtoul(page
, NULL
, 0);
1635 if (platform
.buttons
) {
1636 unregister_buttons(platform
.buttons
);
1637 register_buttons(platform
.buttons
);
1640 if (platform
.leds
) {
1641 unregister_leds(platform
.leds
);
1642 register_leds(platform
.leds
);
1653 static int __init
diag_init(void)
1655 static struct proc_dir_entry
*p
;
1656 static struct platform_t
*detected
;
1658 detected
= platform_detect();
1660 printk(MODULE_NAME
": Router model not detected.\n");
1663 memcpy(&platform
, detected
, sizeof(struct platform_t
));
1665 printk(MODULE_NAME
": Detected '%s'\n", platform
.name
);
1666 if (platform
.platform_init
!= NULL
) {
1667 platform
.platform_init();
1670 if (!(diag
= proc_mkdir("diag", NULL
))) {
1671 printk(MODULE_NAME
": proc_mkdir on /proc/diag failed\n");
1675 if ((p
= create_proc_entry("model", S_IRUSR
, diag
))) {
1676 p
->data
= (void *) &proc_model
;
1677 p
->proc_fops
= &diag_proc_fops
;
1680 if ((p
= create_proc_entry("gpiomask", S_IRUSR
| S_IWUSR
, diag
))) {
1681 p
->data
= (void *) &proc_gpiomask
;
1682 p
->proc_fops
= &diag_proc_fops
;
1685 if (platform
.buttons
)
1686 register_buttons(platform
.buttons
);
1689 register_leds(platform
.leds
);
1694 static void __exit
diag_exit(void)
1696 del_timer(&led_timer
);
1698 if (platform
.buttons
)
1699 unregister_buttons(platform
.buttons
);
1702 unregister_leds(platform
.leds
);
1704 remove_proc_entry("model", diag
);
1705 remove_proc_entry("gpiomask", diag
);
1706 remove_proc_entry("diag", NULL
);
1709 module_init(diag_init
);
1710 module_exit(diag_exit
);
1712 MODULE_AUTHOR("Mike Baker, Felix Fietkau / OpenWrt.org");
1713 MODULE_LICENSE("GPL");