e39f5b4143e311fb9d97973d53a6663fbf554ad9
[openwrt/svn-archive/archive.git] / package / kernel / broadcom-diag / src / diag.c
1 /*
2 * diag.c - GPIO interface driver for Broadcom boards
3 *
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>
7 *
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.
12 *
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.
17 *
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.
21 *
22 */
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>
34 #include <net/sock.h>
35 #include <bcm47xx_board.h>
36 extern u64 uevent_next_seqnum(void);
37
38 #include "gpio.h"
39 #include "diag.h"
40 #define getvar(str) (nvram_get(str)?:"")
41
42 static inline int startswith (char *source, char *cmp) { return !strncmp(source,cmp,strlen(cmp)); }
43 static int fill_event(struct event_t *);
44 static unsigned int gpiomask = 0;
45 module_param(gpiomask, int, 0644);
46
47 extern char *nvram_get(char *str);
48 static void led_flash(unsigned long dummy);
49
50 static struct platform_t platform;
51
52 static struct timer_list led_timer = TIMER_INITIALIZER(&led_flash, 0, 0);
53
54 static struct proc_dir_entry *diag, *leds;
55
56 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,9,0)
57 static inline struct inode *file_inode(struct file *f)
58 {
59 return f->f_path.dentry->d_inode;
60 }
61 #endif
62
63 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)
64 static inline void *PDE_DATA(const struct inode *inode)
65 {
66 return PDE(inode)->data;
67 }
68 #endif
69
70
71 enum {
72 /* Linksys */
73 WAP54GV1,
74 WAP54GV2,
75 WAP54GV3,
76 WRT54GV1,
77 WRT54G,
78 WRTSL54GS,
79 WRT54G3G,
80 WRT54G3GV2_VF,
81 WRT150NV1,
82 WRT150NV11,
83 WRT160NV1,
84 WRT160NV3,
85 WRT300NV11,
86 WRT310NV1,
87 WRT350N,
88 WRT600N,
89 WRT600NV11,
90 WRT610N,
91 WRT610NV2,
92 E1000V1,
93 E1000V21,
94 E2000V1,
95 E3000V1,
96 E3200V1,
97 E4200V1,
98
99 /* ASUS */
100 WLHDD,
101 WL300G,
102 WL320GE,
103 WL330GE,
104 WL500G,
105 WL500GD,
106 WL500GP,
107 WL500GPV2,
108 WL500W,
109 WL520GC,
110 WL520GU,
111 ASUS_4702,
112 WL700GE,
113 RTN12,
114 RTN16,
115 RTN66U,
116
117 /* Buffalo */
118 WBR2_G54,
119 WHR_G54S,
120 WHR_HP_G54,
121 WHR_G125,
122 WHR2_A54G54,
123 WLA2_G54L,
124 WZR_G300N,
125 WZR_RS_G54,
126 WZR_RS_G54HP,
127 BUFFALO_UNKNOWN_4710,
128
129 /* Siemens */
130 SE505V1,
131 SE505V2,
132
133 /* US Robotics */
134 USR5461,
135
136 /* Dell */
137 TM2300,
138 TM2300V2,
139
140 /* Motorola */
141 WE800G,
142 WR850GV1,
143 WR850GV2V3,
144 WR850GP,
145
146 /* Belkin */
147 BELKIN_F7D4301,
148
149 /* Netgear */
150 WGT634U,
151 WNR834BV1,
152 WNR834BV2,
153 WNDR3400V1,
154 WNDR3700V3,
155
156 /* Trendware */
157 TEW411BRPP,
158
159 /* SimpleTech */
160 STI_NAS,
161
162 /* D-Link */
163 DIR130,
164 DIR320,
165 DIR330,
166 DWL3150,
167
168 /* Sitecom */
169 WL105B,
170
171 /* Western Digital */
172 WDNetCenter,
173
174 /* Askey */
175 RT210W,
176
177 /* OvisLink */
178 WL1600GL,
179
180 /* Microsoft */
181 MN700,
182
183 /* Edimax */
184 PS1208MFG,
185
186 /* Huawei */
187 HUAWEI_E970,
188 };
189
190 static void __init bcm4780_init(void) {
191 int pin = 1 << 3;
192
193 /* Enables GPIO 3 that controls HDD and led power on ASUS WL-700gE */
194 printk(MODULE_NAME ": Spinning up HDD and enabling leds\n");
195 bcm47xx_gpio_outen(pin, pin);
196 bcm47xx_gpio_control(pin, 0);
197 bcm47xx_gpio_out(pin, pin);
198
199 /* Wait 5s, so the HDD can spin up */
200 set_current_state(TASK_INTERRUPTIBLE);
201 schedule_timeout(HZ * 5);
202 }
203
204 static void __init NetCenter_init(void) {
205 /* unset pin 6 (+12V) */
206 int pin = 1 << 6;
207 bcm47xx_gpio_outen(pin, pin);
208 bcm47xx_gpio_control(pin, 0);
209 bcm47xx_gpio_out(pin, pin);
210 /* unset pin 1 (turn off red led, blue will light alone if +5V comes up) */
211 pin = 1 << 1;
212 bcm47xx_gpio_outen(pin, pin);
213 bcm47xx_gpio_control(pin, 0);
214 bcm47xx_gpio_out(pin, pin);
215 /* unset pin 3 (+5V) and wait 5 seconds (harddisk spin up) */
216 bcm4780_init();
217 }
218
219 static void __init bcm57xx_init(void) {
220 int pin = 1 << 2;
221
222 /* FIXME: switch comes up, but port mappings/vlans not right */
223 bcm47xx_gpio_outen(pin, pin);
224 bcm47xx_gpio_control(pin, 0);
225 bcm47xx_gpio_out(pin, pin);
226 }
227
228 static struct platform_t __initdata platforms[] = {
229 /* Linksys */
230 [WAP54GV1] = {
231 .name = "Linksys WAP54G V1",
232 .buttons = {
233 { .name = "reset", .gpio = 1 << 0 },
234 },
235 .leds = {
236 { .name = "diag", .gpio = 1 << 3 },
237 { .name = "wlan", .gpio = 1 << 4 },
238 },
239 },
240 [WAP54GV2] = {
241 .name = "Linksys WAP54G V2",
242 .buttons = {
243 { .name = "reset", .gpio = 1 << 0 },
244 },
245 .leds = {
246 { .name = "wlan", .gpio = 1 << 5, .polarity = REVERSE },
247 /* GPIO 6 is b44 (eth0, LAN) PHY power */
248 },
249 },
250 [WAP54GV3] = {
251 .name = "Linksys WAP54G V3",
252 .buttons = {
253 /* FIXME: verify this */
254 { .name = "reset", .gpio = 1 << 7 },
255 { .name = "ses", .gpio = 1 << 0 },
256 },
257 .leds = {
258 /* FIXME: diag? */
259 { .name = "ses", .gpio = 1 << 1 },
260 },
261 },
262 [WRT54GV1] = {
263 .name = "Linksys WRT54G V1.x",
264 .buttons = {
265 { .name = "reset", .gpio = 1 << 6 },
266 },
267 .leds = {
268 { .name = "diag", .gpio = 0x13 | GPIO_TYPE_EXTIF, .polarity = NORMAL },
269 { .name = "dmz", .gpio = 0x12 | GPIO_TYPE_EXTIF, .polarity = NORMAL },
270 },
271 },
272 [WRT54G] = {
273 .name = "Linksys WRT54G/GS/GL",
274 .buttons = {
275 { .name = "reset", .gpio = 1 << 6 },
276 { .name = "ses", .gpio = 1 << 4 },
277 },
278 .leds = {
279 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
280 { .name = "dmz", .gpio = 1 << 7, .polarity = REVERSE },
281 { .name = "ses_white", .gpio = 1 << 2, .polarity = REVERSE },
282 { .name = "ses_orange", .gpio = 1 << 3, .polarity = REVERSE },
283 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
284 },
285 },
286 [WRTSL54GS] = {
287 .name = "Linksys WRTSL54GS",
288 .buttons = {
289 { .name = "reset", .gpio = 1 << 6 },
290 { .name = "ses", .gpio = 1 << 4 },
291 },
292 .leds = {
293 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
294 { .name = "dmz", .gpio = 1 << 0, .polarity = REVERSE },
295 { .name = "ses_white", .gpio = 1 << 5, .polarity = REVERSE },
296 { .name = "ses_orange", .gpio = 1 << 7, .polarity = REVERSE },
297 },
298 },
299 [WRT54G3G] = {
300 .name = "Linksys WRT54G3G",
301 .buttons = {
302 { .name = "reset", .gpio = 1 << 6 },
303 { .name = "3g", .gpio = 1 << 4 },
304 },
305 .leds = {
306 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
307 { .name = "dmz", .gpio = 1 << 7, .polarity = REVERSE },
308 { .name = "3g_green", .gpio = 1 << 2, .polarity = NORMAL },
309 { .name = "3g_blue", .gpio = 1 << 3, .polarity = NORMAL },
310 { .name = "3g_blink", .gpio = 1 << 5, .polarity = NORMAL },
311 },
312 },
313 [WRT54G3GV2_VF] = {
314 .name = "Linksys WRT54G3GV2-VF",
315 .buttons = {
316 { .name = "reset", .gpio = 1 << 6 },
317 { .name = "3g", .gpio = 1 << 5 },
318 },
319 .leds = {
320 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
321 { .name = "3g_green", .gpio = 1 << 2, .polarity = NORMAL },
322 { .name = "3g_blue", .gpio = 1 << 3, .polarity = NORMAL },
323 },
324 },
325 [WRT150NV1] = {
326 .name = "Linksys WRT150N V1",
327 .buttons = {
328 { .name = "reset", .gpio = 1 << 6 },
329 { .name = "ses", .gpio = 1 << 4 },
330 },
331 .leds = {
332 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
333 { .name = "ses_green", .gpio = 1 << 5, .polarity = REVERSE },
334 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE },
335 },
336 },
337 [WRT150NV11] = {
338 .name = "Linksys WRT150N V1.1",
339 .buttons = {
340 { .name = "reset", .gpio = 1 << 6 },
341 { .name = "ses", .gpio = 1 << 4 },
342 },
343 .leds = {
344 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
345 { .name = "ses_green", .gpio = 1 << 5, .polarity = REVERSE },
346 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE },
347 },
348 },
349 [WRT160NV1] = {
350 .name = "Linksys WRT160N v1.x",
351 .buttons = {
352 { .name = "reset", .gpio = 1 << 6 },
353 { .name = "ses", .gpio = 1 << 4 },
354 },
355 .leds = {
356 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
357 { .name = "ses_blue", .gpio = 1 << 5, .polarity = REVERSE },
358 { .name = "ses_orange", .gpio = 1 << 3, .polarity = REVERSE },
359 },
360 },
361 [WRT160NV3] = {
362 .name = "Linksys WRT160N V3",
363 .buttons = {
364 { .name = "reset", .gpio = 1 << 6 },
365 { .name = "ses", .gpio = 1 << 5 },
366 },
367 .leds = {
368 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
369 { .name = "ses_blue", .gpio = 1 << 4, .polarity = REVERSE },
370 { .name = "ses_orange", .gpio = 1 << 2, .polarity = REVERSE },
371 },
372 },
373 [WRT300NV11] = {
374 .name = "Linksys WRT300N V1.1",
375 .buttons = {
376 { .name = "reset", .gpio = 1 << 6 }, // "Reset" on back panel
377 { .name = "ses", .gpio = 1 << 4 }, // "Reserved" on top panel
378 },
379 .leds = {
380 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL }, // "Power"
381 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE }, // "Security" Amber
382 { .name = "ses_green", .gpio = 1 << 5, .polarity = REVERSE }, // "Security" Green
383 },
384 .platform_init = bcm57xx_init,
385 },
386 [WRT310NV1] = {
387 .name = "Linksys WRT310N V1",
388 .buttons = {
389 { .name = "reset", .gpio = 1 << 6 }, // "Reset" on back panel
390 { .name = "ses", .gpio = 1 << 8 }, // "Reserved" on top panel
391 },
392 .leds = {
393 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL }, // Power LED
394 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE }, // "Security" Amber
395 { .name = "ses_blue", .gpio = 1 << 9, .polarity = REVERSE }, // "Security" Blue
396 },
397 },
398 [WRT350N] = {
399 .name = "Linksys WRT350N",
400 .buttons = {
401 { .name = "reset", .gpio = 1 << 6 },
402 { .name = "ses", .gpio = 1 << 8 },
403 },
404 .leds = {
405 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
406 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE },
407 { .name = "ses_green", .gpio = 1 << 9, .polarity = REVERSE },
408 { .name = "usb_blink", .gpio = 1 << 10, .polarity = REVERSE },
409 { .name = "usb", .gpio = 1 << 11, .polarity = REVERSE },
410 },
411 .platform_init = bcm57xx_init,
412 },
413 [WRT600N] = {
414 .name = "Linksys WRT600N",
415 .buttons = {
416 { .name = "reset", .gpio = 1 << 6 },
417 { .name = "ses", .gpio = 1 << 7 },
418 },
419 .leds = {
420 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE }, // Power LED
421 { .name = "usb", .gpio = 1 << 3, .polarity = REVERSE }, // USB LED
422 { .name = "wl0_ses_amber", .gpio = 1 << 8, .polarity = REVERSE }, // 2.4Ghz LED Amber
423 { .name = "wl0_ses_green", .gpio = 1 << 9, .polarity = REVERSE }, // 2.4Ghz LED Green
424 { .name = "wl1_ses_amber", .gpio = 1 << 10, .polarity = REVERSE }, // 5.6Ghz LED Amber
425 { .name = "wl1_ses_green", .gpio = 1 << 11, .polarity = REVERSE }, // 5.6Ghz LED Green
426 },
427 .platform_init = bcm57xx_init,
428 },
429 [WRT600NV11] = {
430 .name = "Linksys WRT600N V1.1",
431 .buttons = {
432 { .name = "reset", .gpio = 1 << 6 },
433 { .name = "ses", .gpio = 1 << 7 },
434 },
435 .leds = {
436 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE }, // Power LED
437 { .name = "usb", .gpio = 1 << 3, .polarity = REVERSE }, // USB LED
438 { .name = "wl0_ses_amber", .gpio = 1 << 8, .polarity = REVERSE }, // 2.4Ghz LED Amber
439 { .name = "wl0_ses_green", .gpio = 1 << 9, .polarity = REVERSE }, // 2.4Ghz LED Green
440 { .name = "wl1_ses_amber", .gpio = 1 << 10, .polarity = REVERSE }, // 5.6Ghz LED Amber
441 { .name = "wl1_ses_green", .gpio = 1 << 11, .polarity = REVERSE }, // 5.6Ghz LED Green
442 },
443 .platform_init = bcm57xx_init,
444 },
445 [WRT610N] = {
446 .name = "Linksys WRT610N",
447 .buttons = {
448 { .name = "reset", .gpio = 1 << 6 },
449 { .name = "ses", .gpio = 1 << 8 },
450 },
451 .leds = {
452 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL }, // Power LED
453 { .name = "usb", .gpio = 1 << 0, .polarity = REVERSE }, // USB LED
454 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE }, // WiFi protected setup LED amber
455 { .name = "ses_blue", .gpio = 1 << 9, .polarity = REVERSE }, // WiFi protected setup LED blue
456 },
457 },
458 [WRT610NV2] = {
459 .name = "Linksys WRT610N V2",
460 .buttons = {
461 { .name = "reset", .gpio = 1 << 6 },
462 { .name = "ses", .gpio = 1 << 4 },
463 },
464 .leds = {
465 { .name = "power", .gpio = 1 << 5, .polarity = NORMAL }, // Power LED
466 { .name = "usb", .gpio = 1 << 7, .polarity = NORMAL }, // USB LED
467 { .name = "ses_amber", .gpio = 1 << 0, .polarity = REVERSE }, // WiFi protected setup LED amber
468 { .name = "ses_blue", .gpio = 1 << 3, .polarity = REVERSE }, // WiFi protected setup LED blue
469 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL }, // Wireless LED
470 },
471 },
472 /* same hardware as WRT160NV3 and Cisco Valet M10V1, but different board detection, combine? */
473 [E1000V1] = {
474 .name = "Linksys E1000 V1",
475 .buttons = {
476 { .name = "reset", .gpio = 1 << 6 },
477 { .name = "wps", .gpio = 1 << 5 }, /* nvram get gpio5=wps_button */
478 },
479 .leds = {
480 /** turns on leds for all ethernet ports (wan too)
481 * this also disconnects some, or maybe all, ethernet ports
482 * 1: leds work normally
483 * 0: all lit all the time */
484 /* nvram get gpio3=robo_reset */
485 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
486 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
487 { .name = "ses_blue", .gpio = 1 << 4, .polarity = REVERSE }, /* nvram get gpio4=wps_led */
488 { .name = "ses_orange", .gpio = 1 << 2, .polarity = REVERSE }, /* nvram get gpio2=wps_status_led */
489 },
490 },
491 [E1000V21] = {
492 .name = "Linksys E1000 V2.1",
493 .buttons = {
494 { .name = "reset", .gpio = 1 << 10 }, /* nvram get reset_gpio=10 */
495 { .name = "wps", .gpio = 1 << 9 }, /* nvram get gpio9=wps_button */
496 },
497 .leds = {
498 { .name = "power", .gpio = 1 << 6, .polarity = REVERSE },
499 { .name = "wlan", .gpio = 1 << 5, .polarity = NORMAL },
500 { .name = "ses_blue", .gpio = 1 << 8, .polarity = NORMAL }, /* nvram get gpio8=wps_led */
501 { .name = "ses_orange", .gpio = 1 << 7, .polarity = NORMAL }, /* nvram get gpio7=wps_status_led */
502 },
503 },
504 [E2000V1] = {
505 .name = "Linksys E2000 V1",
506 .buttons = {
507 { .name = "reset", .gpio = 1 << 8 },
508 { .name = "ses", .gpio = 1 << 5 },
509 },
510 .leds = {
511 { .name = "power", .gpio = 1 << 2, .polarity = NORMAL },
512 { .name = "ses_amber", .gpio = 1 << 4, .polarity = REVERSE },
513 { .name = "ses_blue", .gpio = 1 << 3, .polarity = REVERSE },
514 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL },
515 },
516 },
517 [E3000V1] = {
518 .name = "Linksys E3000 V1",
519 .buttons = {
520 { .name = "reset", .gpio = 1 << 6 },
521 { .name = "ses", .gpio = 1 << 4 },
522 },
523 .leds = {
524 { .name = "power", .gpio = 1 << 5, .polarity = NORMAL }, // Power LED
525 { .name = "usb", .gpio = 1 << 7, .polarity = NORMAL }, // USB LED
526 { .name = "ses_amber", .gpio = 1 << 0, .polarity = REVERSE }, // WiFi protected setup LED amber
527 { .name = "ses_blue", .gpio = 1 << 3, .polarity = REVERSE }, // WiFi protected setup LED blue
528 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL }, // Wireless LED
529 },
530 },
531 [E3200V1] = {
532 .name = "Linksys E3200 V1",
533 .buttons = {
534 /* { .name = "switch", .gpio = 1 << 4 },*/ /* nvram get gpio4=robo_reset */
535 { .name = "reset", .gpio = 1 << 5 }, /* nvram get reset_gpio=5 */
536 { .name = "wps", .gpio = 1 << 8 }, /* nvram get gpio8=wps_button */
537 /* { .name = "wombo", .gpio = 1 << 23 },*/ /* nvram get gpio23=wombo_reset - wireless on motherboard */
538 },
539 .leds = {
540 { .name = "power", .gpio = 1 << 3, .polarity = REVERSE }, /* Power LED */
541 },
542 },
543 [E4200V1] = {
544 .name = "Linksys E4200 V1",
545 .buttons = {
546 { .name = "reset", .gpio = 1 << 6 },
547 { .name = "wps", .gpio = 1 << 4 },
548 },
549 .leds = {
550 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
551 },
552 },
553 /* Asus */
554 [WLHDD] = {
555 .name = "ASUS WL-HDD",
556 .buttons = {
557 { .name = "reset", .gpio = 1 << 6 },
558 },
559 .leds = {
560 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
561 { .name = "usb", .gpio = 1 << 2, .polarity = REVERSE },
562 },
563 },
564 [WL300G] = {
565 .name = "ASUS WL-300g",
566 .buttons = {
567 { .name = "reset", .gpio = 1 << 6 },
568 },
569 .leds = {
570 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
571 },
572 },
573 [WL320GE] = {
574 .name = "ASUS WL-320gE/WL-320gP",
575 .buttons = {
576 { .name = "reset", .gpio = 1 << 6 },
577 },
578 .leds = {
579 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
580 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE },
581 { .name = "link", .gpio = 1 << 11, .polarity = REVERSE },
582 },
583 },
584 [WL330GE] = {
585 .name = "ASUS WL-330gE",
586 .buttons = {
587 { .name = "reset", .gpio = 1 << 2 },
588 },
589 .leds = {
590 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
591 },
592 },
593 [WL500G] = {
594 .name = "ASUS WL-500g",
595 .buttons = {
596 { .name = "reset", .gpio = 1 << 6 },
597 },
598 .leds = {
599 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
600 },
601 },
602 [WL500GD] = {
603 .name = "ASUS WL-500g Deluxe",
604 .buttons = {
605 { .name = "reset", .gpio = 1 << 6 },
606 },
607 .leds = {
608 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
609 },
610 },
611 [WL500GP] = {
612 .name = "ASUS WL-500g Premium",
613 .buttons = {
614 { .name = "reset", .gpio = 1 << 0 },
615 { .name = "ses", .gpio = 1 << 4 },
616 },
617 .leds = {
618 { .name = "power", .gpio = 1 << 1, .polarity = REVERSE },
619 },
620 },
621 [WL500GPV2] = {
622 .name = "ASUS WL-500g Premium V2",
623 .buttons = {
624 { .name = "reset", .gpio = 1 << 2 },
625 { .name = "ses", .gpio = 1 << 3 },
626 },
627 .leds = {
628 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
629 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
630 },
631 },
632 [WL500W] = {
633 .name = "ASUS WL-500W",
634 .buttons = {
635 { .name = "reset", .gpio = 1 << 6 },
636 { .name = "ses", .gpio = 1 << 7 },
637 },
638 .leds = {
639 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
640 },
641 },
642 [WL520GC] = {
643 .name = "ASUS WL-520GC",
644 .buttons = {
645 { .name = "reset", .gpio = 1 << 2 },
646 { .name = "ses", .gpio = 1 << 3 },
647 },
648 .leds = {
649 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
650 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
651 },
652 },
653 [WL520GU] = {
654 .name = "ASUS WL-520gU",
655 .buttons = {
656 { .name = "reset", .gpio = 1 << 2 },
657 { .name = "ses", .gpio = 1 << 3 },
658 },
659 .leds = {
660 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
661 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
662 },
663 },
664 [ASUS_4702] = {
665 .name = "ASUS (unknown, BCM4702)",
666 .buttons = {
667 { .name = "reset", .gpio = 1 << 6 },
668 },
669 .leds = {
670 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
671 },
672 },
673 [WL700GE] = {
674 .name = "ASUS WL-700gE",
675 .buttons = {
676 { .name = "reset", .gpio = 1 << 7 }, // on back, hardwired, always resets device regardless OS state
677 { .name = "ses", .gpio = 1 << 4 }, // on back, actual name ezsetup
678 { .name = "power", .gpio = 1 << 0 }, // on front
679 { .name = "copy", .gpio = 1 << 6 }, // on front
680 },
681 .leds = {
682 #if 0
683 // GPIO that controls power led also enables/disables some essential functions
684 // - power to HDD
685 // - switch leds
686 { .name = "power", .gpio = 1 << 3, .polarity = NORMAL }, // actual name power
687 #endif
688 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE }, // actual name ready
689 },
690 .platform_init = bcm4780_init,
691 },
692 [RTN12] = {
693 .name = "ASUS RT-N12",
694 .buttons = {
695 { .name = "wps", .gpio = 1 << 0 },
696 { .name = "reset", .gpio = 1 << 1 },
697 // this is the router/repeater/ap switch
698 { .name = "sw1", .gpio = 1 << 4 },
699 { .name = "sw2", .gpio = 1 << 5 },
700 { .name = "sw3", .gpio = 1 << 6 },
701 },
702 .leds = {
703 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE },
704 { .name = "wlan", .gpio = 1 << 7, .polarity = NORMAL },
705 // gpio3 forces WAN and LAN1-4 all on
706 //{ .name = "eth", .gpio = 1 << 3, .polarity = REVERSE },
707 },
708 },
709 [RTN16] = {
710 .name = "ASUS RT-N16",
711 .buttons = {
712 { .name = "reset", .gpio = 1 << 8 },
713 { .name = "ses", .gpio = 1 << 6 },
714 },
715 .leds = {
716 { .name = "power", .gpio = 1 << 1, .polarity = REVERSE },
717 { .name = "wlan", .gpio = 1 << 7, .polarity = NORMAL },
718 },
719 },
720 [RTN66U] = {
721 .name = "ASUS RT-N66U",
722 .buttons = {
723 { .name = "reset", .gpio = 1 << 9 },
724 { .name = "wps", .gpio = 1 << 4 },
725 },
726 .leds = {
727 { .name = "power", .gpio = 1 << 12, .polarity = REVERSE },
728 { .name = "usb", .gpio = 1 << 15, .polarity = REVERSE },
729 },
730 },
731 /* Buffalo */
732 [WHR_G54S] = {
733 .name = "Buffalo WHR-G54S",
734 .buttons = {
735 { .name = "reset", .gpio = 1 << 4 },
736 { .name = "bridge", .gpio = 1 << 5 },
737 { .name = "ses", .gpio = 1 << 0 },
738 },
739 .leds = {
740 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
741 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
742 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
743 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
744 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
745 },
746 },
747 [WBR2_G54] = {
748 .name = "Buffalo WBR2-G54",
749 /* FIXME: verify */
750 .buttons = {
751 { .name = "reset", .gpio = 1 << 7 },
752 },
753 .leds = {
754 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
755 },
756 },
757 [WHR_HP_G54] = {
758 .name = "Buffalo WHR-HP-G54",
759 .buttons = {
760 { .name = "reset", .gpio = 1 << 4 },
761 { .name = "bridge", .gpio = 1 << 5 },
762 { .name = "ses", .gpio = 1 << 0 },
763 },
764 .leds = {
765 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
766 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
767 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
768 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
769 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
770 },
771 },
772 [WHR_G125] = {
773 .name = "Buffalo WHR-G125",
774 .buttons = {
775 { .name = "reset", .gpio = 1 << 4 },
776 { .name = "bridge", .gpio = 1 << 5 },
777 { .name = "ses", .gpio = 1 << 0 },
778 },
779 .leds = {
780 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
781 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
782 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
783 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
784 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
785 },
786 },
787 [WHR2_A54G54] = {
788 .name = "Buffalo WHR2-A54G54",
789 .buttons = {
790 { .name = "reset", .gpio = 1 << 4 },
791 },
792 .leds = {
793 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
794 },
795 },
796 [WLA2_G54L] = {
797 .name = "Buffalo WLA2-G54L",
798 /* FIXME: verify */
799 .buttons = {
800 { .name = "reset", .gpio = 1 << 7 },
801 },
802 .leds = {
803 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
804 },
805 },
806 [WZR_G300N] = {
807 .name = "Buffalo WZR-G300N",
808 .buttons = {
809 { .name = "reset", .gpio = 1 << 4 },
810 },
811 .leds = {
812 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
813 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
814 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
815 },
816 },
817 [WZR_RS_G54] = {
818 .name = "Buffalo WZR-RS-G54",
819 .buttons = {
820 { .name = "ses", .gpio = 1 << 0 },
821 { .name = "reset", .gpio = 1 << 4 },
822 },
823 .leds = {
824 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
825 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
826 { .name = "vpn", .gpio = 1 << 1, .polarity = REVERSE },
827 },
828 },
829 [WZR_RS_G54HP] = {
830 .name = "Buffalo WZR-RS-G54HP",
831 .buttons = {
832 { .name = "ses", .gpio = 1 << 0 },
833 { .name = "reset", .gpio = 1 << 4 },
834 },
835 .leds = {
836 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
837 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
838 { .name = "vpn", .gpio = 1 << 1, .polarity = REVERSE },
839 },
840 },
841 [BUFFALO_UNKNOWN_4710] = {
842 .name = "Buffalo (unknown, BCM4710)",
843 .buttons = {
844 { .name = "reset", .gpio = 1 << 4 },
845 },
846 .leds = {
847 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
848 },
849 },
850 /* Siemens */
851 [SE505V1] = {
852 .name = "Siemens SE505 V1",
853 .buttons = {
854 /* No usable buttons */
855 },
856 .leds = {
857 // { .name = "power", .gpio = 1 << 0 .polarity = REVERSE }, // Usable when retrofitting D26 (?)
858 { .name = "dmz", .gpio = 1 << 4, .polarity = REVERSE }, // actual name WWW
859 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
860 },
861 },
862 [SE505V2] = {
863 .name = "Siemens SE505 V2",
864 .buttons = {
865 /* No usable buttons */
866 },
867 .leds = {
868 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
869 { .name = "dmz", .gpio = 1 << 0, .polarity = REVERSE }, // actual name WWW
870 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
871 },
872 },
873 /* US Robotics */
874 [USR5461] = {
875 .name = "U.S. Robotics USR5461",
876 .buttons = {
877 /* No usable buttons */
878 },
879 .leds = {
880 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
881 { .name = "printer", .gpio = 1 << 1, .polarity = REVERSE },
882 },
883 },
884 /* Dell */
885 [TM2300] = {
886 .name = "Dell TrueMobile 2300",
887 .buttons = {
888 { .name = "reset", .gpio = 1 << 0 },
889 },
890 .leds = {
891 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
892 { .name = "power", .gpio = 1 << 7, .polarity = REVERSE },
893 },
894 },
895 [TM2300V2] = {
896 .name = "Dell TrueMobile 2300 v2",
897 .buttons = {
898 { .name = "reset", .gpio = 1 << 0 },
899 },
900 .leds = {
901 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
902 { .name = "power", .gpio = 1 << 7, .polarity = REVERSE },
903 },
904 },
905 /* Motorola */
906 [WE800G] = {
907 .name = "Motorola WE800G",
908 .buttons = {
909 { .name = "reset", .gpio = 1 << 0 },
910 },
911 .leds = {
912 { .name = "power", .gpio = 1 << 4, .polarity = NORMAL },
913 { .name = "diag", .gpio = 1 << 2, .polarity = REVERSE },
914 { .name = "wlan_amber", .gpio = 1 << 1, .polarity = NORMAL },
915 },
916 },
917 [WR850GV1] = {
918 .name = "Motorola WR850G V1",
919 .buttons = {
920 { .name = "reset", .gpio = 1 << 0 },
921 },
922 .leds = {
923 { .name = "power", .gpio = 1 << 4, .polarity = NORMAL },
924 { .name = "diag", .gpio = 1 << 3, .polarity = REVERSE },
925 { .name = "dmz", .gpio = 1 << 6, .polarity = NORMAL },
926 { .name = "wlan_red", .gpio = 1 << 5, .polarity = REVERSE },
927 { .name = "wlan_green", .gpio = 1 << 7, .polarity = REVERSE },
928 },
929 },
930 [WR850GV2V3] = {
931 .name = "Motorola WR850G V2/V3",
932 .buttons = {
933 { .name = "reset", .gpio = 1 << 5 },
934 },
935 .leds = {
936 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
937 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
938 { .name = "wan", .gpio = 1 << 6, .polarity = INPUT },
939 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
940 },
941 },
942 [WR850GP] = {
943 .name = "Motorola WR850GP",
944 .buttons = {
945 { .name = "reset", .gpio = 1 << 5 },
946 },
947 .leds = {
948 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
949 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
950 { .name = "dmz", .gpio = 1 << 6, .polarity = REVERSE },
951 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
952 },
953 },
954
955 /* Belkin */
956 [BELKIN_F7D4301] = {
957 .name = "Belkin PlayMax F7D4301",
958 .buttons = {
959 { .name = "reset", .gpio = 1 << 6 },
960 { .name = "wps", .gpio = 1 << 8 },
961 },
962 .leds = {
963 { .name = "power", .gpio = 1 << 10, .polarity = REVERSE },
964 { .name = "warn", .gpio = 1 << 11, .polarity = REVERSE },
965 { .name = "wps", .gpio = 1 << 12, .polarity = REVERSE },
966 { .name = "wlan", .gpio = 1 << 13, .polarity = REVERSE },
967 { .name = "usb0", .gpio = 1 << 14, .polarity = REVERSE },
968 { .name = "usb1", .gpio = 1 << 15, .polarity = REVERSE },
969 },
970 },
971 /* Netgear */
972 [WGT634U] = {
973 .name = "Netgear WGT634U",
974 .buttons = {
975 { .name = "reset", .gpio = 1 << 2 },
976 },
977 .leds = {
978 { .name = "power", .gpio = 1 << 3, .polarity = NORMAL },
979 },
980 },
981 /* Netgear */
982 [WNR834BV1] = {
983 .name = "Netgear WNR834B V1",
984 .buttons = { /* TODO: add reset button and confirm LEDs - GPIO from dd-wrt */ },
985 .leds = {
986 { .name = "power", .gpio = 1 << 4, .polarity = REVERSE },
987 { .name = "diag", .gpio = 1 << 5, .polarity = REVERSE },
988 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
989 },
990 },
991 /* Netgear */
992 [WNR834BV2] = {
993 .name = "Netgear WNR834B V2",
994 .buttons = {
995 { .name = "reset", .gpio = 1 << 6 },
996 },
997 .leds = {
998 { .name = "power", .gpio = 1 << 2, .polarity = NORMAL },
999 { .name = "diag", .gpio = 1 << 3, .polarity = NORMAL },
1000 { .name = "connected", .gpio = 1 << 7, .polarity = NORMAL },
1001 },
1002 },
1003 [WNDR3400V1] = {
1004 .name = "Netgear WNDR3400 V1",
1005 .buttons = {
1006 /* nvram get gpio5=robo_reset */
1007 { .name = "reset", .gpio = 1 << 4 },
1008 { .name = "wps", .gpio = 1 << 6 },
1009 { .name = "wlan", .gpio = 1 << 8 },
1010 },
1011 .leds = {
1012 { .name = "wlan", .gpio = 0 << 0, .polarity = NORMAL },
1013 { .name = "connected", .gpio = 1 << 0, .polarity = NORMAL },
1014 { .name = "power", .gpio = 1 << 3, .polarity = NORMAL },
1015 { .name = "diag", .gpio = 1 << 7, .polarity = NORMAL },
1016 { .name = "usb", .gpio = 1 << 2, .polarity = REVERSE },
1017 },
1018 },
1019 [WNDR3700V3] = {
1020 .name = "Netgear WNDR3700 V3",
1021 .buttons = {
1022 /* { .name = "usb", .gpio = 1 << 1 }, */ /* this button doesn't seem to exist. */
1023 { .name = "wlan", .gpio = 1 << 2 },
1024 { .name = "reset", .gpio = 1 << 3 },
1025 { .name = "wps", .gpio = 1 << 4 },
1026 /* { .name = "switch", .gpio = 1 << 5 },*/ /* nvram get gpio5=robo_reset */
1027 },
1028 .leds = {
1029 { .name = "power", .gpio = (1 << 0) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1030 { .name = "diag", .gpio = (1 << 1) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1031 /* WAN LED doesn't respond to GPIO control. The switch is probably driving it.
1032 * { .name = "wan", .gpio = (1 << 2) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1033 */
1034 { .name = "wlan2g", .gpio = (1 << 3) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1035 { .name = "wlan5g", .gpio = (1 << 4) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1036 { .name = "usb", .gpio = (1 << 5) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1037 { .name = "wps", .gpio = (1 << 6) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1038 { .name = "wlan", .gpio = (1 << 7) | GPIO_TYPE_SHIFT, .polarity = REVERSE },
1039 },
1040 },
1041 /* Trendware */
1042 [TEW411BRPP] = {
1043 .name = "Trendware TEW411BRP+",
1044 .buttons = {
1045 { /* No usable buttons */ },
1046 },
1047 .leds = {
1048 { .name = "power", .gpio = 1 << 7, .polarity = NORMAL },
1049 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL },
1050 { .name = "bridge", .gpio = 1 << 6, .polarity = NORMAL },
1051 },
1052 },
1053 /* SimpleTech */
1054 [STI_NAS] = {
1055 .name = "SimpleTech SimpleShare NAS",
1056 .buttons = {
1057 { .name = "reset", .gpio = 1 << 0 }, // Power button on back, named reset to enable failsafe.
1058 },
1059 .leds = {
1060 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE }, // actual name ready
1061 },
1062 .platform_init = bcm4780_init,
1063 },
1064 /* D-Link */
1065 [DIR130] = {
1066 .name = "D-Link DIR-130",
1067 .buttons = {
1068 { .name = "reset", .gpio = 1 << 3},
1069 { .name = "reserved", .gpio = 1 << 7},
1070 },
1071 .leds = {
1072 { .name = "diag", .gpio = 1 << 0},
1073 { .name = "blue", .gpio = 1 << 6},
1074 },
1075 },
1076 [DIR320] = {
1077 .name = "D-Link DIR-320",
1078 .buttons = {
1079 { .name = "reserved", .gpio = 1 << 6},
1080 { .name = "reset", .gpio = 1 << 7},
1081 },
1082 .leds = {
1083 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
1084 { .name = "diag", .gpio = 1 << 1, .polarity = NORMAL }, /* "status led */
1085 { .name = "red", .gpio = 1 << 3, .polarity = REVERSE },
1086 { .name = "blue", .gpio = 1 << 4, .polarity = REVERSE },
1087 { .name = "usb", .gpio = 1 << 5, .polarity = NORMAL },
1088 },
1089 },
1090 [DIR330] = {
1091 .name = "D-Link DIR-330",
1092 .buttons = {
1093 { .name = "reset", .gpio = 1 << 3},
1094 { .name = "reserved", .gpio = 1 << 7},
1095 },
1096 .leds = {
1097 { .name = "diag", .gpio = 1 << 0},
1098 { .name = "usb", .gpio = 1 << 4},
1099 { .name = "blue", .gpio = 1 << 6},
1100 },
1101 },
1102 [DWL3150] = {
1103 .name = "D-Link DWL-3150",
1104 .buttons = {
1105 { .name = "reset", .gpio = 1 << 7},
1106 },
1107 .leds = {
1108 { .name = "diag", .gpio = 1 << 2},
1109 { .name = "status", .gpio = 1 << 1},
1110 },
1111 },
1112 /* Double check */
1113 [WL105B] = {
1114 .name = "Sitecom WL-105b",
1115 .buttons = {
1116 { .name = "reset", .gpio = 1 << 10},
1117 },
1118 .leds = {
1119 { .name = "wlan", .gpio = 1 << 4},
1120 { .name = "power", .gpio = 1 << 3},
1121 },
1122 },
1123 /* Western Digital Net Center */
1124 [WDNetCenter] = {
1125 .name = "Western Digital NetCenter",
1126 .buttons = {
1127 { .name = "power", .gpio = 1 << 0},
1128 { .name = "reset", .gpio = 1 << 7},
1129 },
1130 .platform_init = NetCenter_init,
1131 },
1132 /* Askey (and clones) */
1133 [RT210W] = {
1134 .name = "Askey RT210W",
1135 .buttons = {
1136 /* Power button is hard-wired to hardware reset */
1137 /* but is also connected to GPIO 7 (probably for bootloader recovery) */
1138 { .name = "power", .gpio = 1 << 7},
1139 },
1140 .leds = {
1141 /* These were verified and named based on Belkin F5D4230-4 v1112 */
1142 { .name = "connected", .gpio = 1 << 0, .polarity = REVERSE },
1143 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
1144 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
1145 },
1146 },
1147 [WL1600GL] = {
1148 .name = "OvisLink WL-1600GL",
1149 .buttons = {
1150 { .name = "reset", .gpio = 1 << 3 },
1151 { .name = "ses", .gpio = 1 << 4 },
1152 },
1153 .leds = {
1154 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
1155 { .name = "wps", .gpio = 1 << 2, .polarity = REVERSE },
1156 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
1157 { .name = "connected", .gpio = 1 << 0, .polarity = REVERSE },
1158 },
1159 },
1160 /* Microsoft */
1161 [MN700] = {
1162 .name = "Microsoft MN-700",
1163 .buttons = {
1164 { .name = "reset", .gpio = 1 << 7 },
1165 },
1166 .leds = {
1167 { .name = "power", .gpio = 1 << 6, .polarity = NORMAL },
1168 },
1169 },
1170 /* Edimax */
1171 [PS1208MFG] = {
1172 .name = "Edimax PS-1208MFG",
1173 .buttons = {
1174 { .name = "reset", .gpio = 1 << 4 },
1175 },
1176 .leds = {
1177 { .name = "status", .gpio = 1 << 1, .polarity = NORMAL },
1178 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
1179 },
1180 },
1181 /* Huawei */
1182 [HUAWEI_E970] = {
1183 .name = "Huawei E970",
1184 .buttons = {
1185 { .name = "reset", .gpio = 1 << 6 },
1186 },
1187 .leds = {
1188 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
1189 },
1190 },
1191 };
1192
1193 static struct platform_t __init *platform_detect_legacy(void)
1194 {
1195 char *boardnum, *boardtype;
1196
1197 if (strcmp(getvar("nvram_type"), "cfe") == 0)
1198 return &platforms[WGT634U];
1199
1200
1201 /* no easy model number, attempt to guess */
1202 boardnum = getvar("boardnum");
1203 boardtype = getvar("boardtype");
1204
1205 if (!strcmp(boardnum, "20070615")) { /* Linksys WRT600N v1/V1.1 */
1206 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "0") && !strcmp(getvar("switch_type"),"BCM5395"))
1207 return &platforms[WRT600NV11];
1208
1209 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "0"))
1210 return &platforms[WRT600N];
1211 }
1212
1213 if (startswith(getvar("pmon_ver"), "CFE")) {
1214 /* CFE based - newer hardware */
1215 if (!strcmp(boardnum, "42")) { /* Linksys */
1216 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "1"))
1217 return &platforms[WRT350N];
1218
1219 if (!strcmp(boardtype, "0x0101") && !strcmp(getvar("boot_ver"), "v3.6"))
1220 return &platforms[WRT54G3G];
1221
1222 /* default to WRT54G if no boot_hw_model is set */
1223 if (nvram_get("boot_hw_model") == NULL)
1224 return &platforms[WRT54G];
1225 }
1226 if (!strcmp(boardnum, "1024") && !strcmp(boardtype, "0x0446"))
1227 return &platforms[WAP54GV2];
1228
1229 if (!strcmp(boardnum, "8") && !strcmp(boardtype, "0x048e"))
1230 return &platforms[WL1600GL];
1231
1232
1233 if (!strcmp(boardnum, "44") || !strcmp(boardnum, "44\r")) {
1234 if (!strcmp(boardtype,"0x0101") || !strcmp(boardtype, "0x0101\r"))
1235 return &platforms[TM2300V2]; /* Dell TrueMobile 2300 v2 */
1236 }
1237
1238 if (!strcmp(boardnum, "10496"))
1239 return &platforms[USR5461];
1240
1241 if (!strcmp(getvar("boardtype"), "0x0101") && !strcmp(getvar("boardrev"), "0x10")) /* SE505V2 With Modified CFE */
1242 return &platforms[SE505V2];
1243
1244 if (!strcmp(boardtype, "0x048e") && !strcmp(getvar("boardrev"),"0x35") &&
1245 !strcmp(getvar("boardflags"), "0x750")) /* D-Link DIR-320 */
1246 return &platforms[DIR320];
1247
1248 if (!strncmp(boardnum, "TH",2) && !strcmp(boardtype,"0x042f")) {
1249 return &platforms[WDNetCenter];
1250 }
1251
1252 if (!strcmp(boardtype,"0x0472") && !strcmp(getvar("cardbus"), "1")) { /* Netgear WNR834B V1 and V2*/
1253 if (!strcmp(boardnum, "08") || !strcmp(boardnum, "8"))
1254 return &platforms[WNR834BV1];
1255 if (!strcmp(boardnum, "01") || !strcmp(boardnum, "1"))
1256 return &platforms[WNR834BV2];
1257 }
1258
1259 } else { /* PMON based - old stuff */
1260 if ((simple_strtoul(getvar("GemtekPmonVer"), NULL, 0) == 9) &&
1261 (simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 30)) {
1262 return &platforms[WR850GV1];
1263 }
1264 if (startswith(boardtype, "bcm94710dev")) {
1265 if (!strcmp(boardnum, "42"))
1266 return &platforms[WRT54GV1];
1267 if (simple_strtoul(boardnum, NULL, 0) == 2)
1268 return &platforms[WAP54GV1];
1269 }
1270 /* MN-700 has also hardware_version 'WL500-...', so use boardnum */
1271 if (startswith(getvar("hardware_version"), "WL500-")) {
1272 if (!strcmp(getvar("boardnum"), "mn700"))
1273 return &platforms[MN700];
1274 else
1275 return &platforms[WL500G];
1276 }
1277 /* Sitecom WL-105b */
1278 if (startswith(boardnum, "2") && simple_strtoul(getvar("GemtekPmonVer"), NULL, 0) == 1)
1279 return &platforms[WL105B];
1280
1281 /* unknown asus stuff, probably bcm4702 */
1282 if (startswith(boardnum, "asusX"))
1283 return &platforms[ASUS_4702];
1284
1285 /* bcm4702 based Askey RT210W clones, Including:
1286 * Askey RT210W (duh?)
1287 * Siemens SE505v1
1288 * Belkin F5D7230-4 before version v1444 (MiniPCI slot, not integrated)
1289 */
1290 if (!strcmp(boardtype,"bcm94710r4")
1291 && !strcmp(boardnum ,"100")
1292 && !strcmp(getvar("pmon_ver"),"v1.03.12.bk")
1293 ){
1294 return &platforms[RT210W];
1295 }
1296 }
1297
1298 if (boardnum || !strcmp(boardnum, "00")) {/* probably buffalo */
1299 if (startswith(boardtype, "bcm94710ap"))
1300 return &platforms[BUFFALO_UNKNOWN_4710];
1301 }
1302
1303 if (startswith(getvar("CFEver"), "MotoWRv2") ||
1304 startswith(getvar("CFEver"), "MotoWRv3") ||
1305 !strcmp(getvar("MOTO_BOARD_TYPE"), "WR_FEM1")) {
1306
1307 return &platforms[WR850GV2V3];
1308 }
1309
1310 if (!strcmp(boardnum, "44") && !strcmp(getvar("boardflags"),"0x0388")) { /* Trendware TEW-411BRP+ */
1311 return &platforms[TEW411BRPP];
1312 }
1313
1314 if (startswith(boardnum, "04FN")) /* SimpleTech SimpleShare */
1315 return &platforms[STI_NAS];
1316
1317 if (!strcmp(boardnum, "10") && !strcmp(getvar("boardrev"), "0x13")) /* D-Link DWL-3150 */
1318 return &platforms[DWL3150];
1319
1320 if (!strcmp(boardnum, "01") && !strcmp(boardtype, "0x048e") && /* Edimax PS1208MFG */
1321 !strcmp(getvar("status_gpio"), "1")) /* gpio based detection */
1322 return &platforms[PS1208MFG];
1323
1324 /* not found */
1325 return NULL;
1326 }
1327
1328 static struct platform_t __init *platform_detect(void)
1329 {
1330 enum bcm47xx_board board;
1331 const char *board_name;
1332
1333
1334 board = bcm47xx_board_get();
1335 board_name = bcm47xx_board_get_name();
1336 if (board != BCM47XX_BOARD_UNKNOWN && board != BCM47XX_BOARD_NO)
1337 printk(MODULE_NAME ": kernel found a \"%s\"\n", board_name);
1338
1339 switch(board) {
1340 case BCM47XX_BOARD_ASUS_RTN12:
1341 return &platforms[RTN12];
1342 case BCM47XX_BOARD_ASUS_RTN16:
1343 return &platforms[RTN16];
1344 case BCM47XX_BOARD_ASUS_RTN66U:
1345 return &platforms[RTN66U];
1346 case BCM47XX_BOARD_ASUS_WL300G:
1347 return &platforms[WL300G];
1348 case BCM47XX_BOARD_ASUS_WL320GE:
1349 return &platforms[WL320GE];
1350 case BCM47XX_BOARD_ASUS_WL330GE:
1351 return &platforms[WL330GE];
1352 case BCM47XX_BOARD_ASUS_WL500GD:
1353 return &platforms[WL500GD];
1354 case BCM47XX_BOARD_ASUS_WL500GPV1:
1355 return &platforms[WL500GP];
1356 case BCM47XX_BOARD_ASUS_WL500GPV2:
1357 return &platforms[WL500GPV2];
1358 case BCM47XX_BOARD_ASUS_WL500W:
1359 return &platforms[WL500W];
1360 case BCM47XX_BOARD_ASUS_WL520GC:
1361 return &platforms[WL520GC];
1362 case BCM47XX_BOARD_ASUS_WL520GU:
1363 return &platforms[WL520GU];
1364 case BCM47XX_BOARD_ASUS_WL700GE:
1365 return &platforms[WL700GE];
1366 case BCM47XX_BOARD_ASUS_WLHDD:
1367 return &platforms[WLHDD];
1368 case BCM47XX_BOARD_BELKIN_F7D4301:
1369 return &platforms[BELKIN_F7D4301];
1370 case BCM47XX_BOARD_BUFFALO_WBR2_G54:
1371 return &platforms[WBR2_G54];
1372 case BCM47XX_BOARD_BUFFALO_WHR2_A54G54:
1373 return &platforms[WHR2_A54G54];
1374 case BCM47XX_BOARD_BUFFALO_WHR_G125:
1375 return &platforms[WHR_G125];
1376 case BCM47XX_BOARD_BUFFALO_WHR_G54S:
1377 return &platforms[WHR_G54S];
1378 case BCM47XX_BOARD_BUFFALO_WHR_HP_G54:
1379 return &platforms[WHR_HP_G54];
1380 case BCM47XX_BOARD_BUFFALO_WLA2_G54L:
1381 return &platforms[WLA2_G54L];
1382 case BCM47XX_BOARD_BUFFALO_WZR_G300N:
1383 return &platforms[WZR_G300N];
1384 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54:
1385 return &platforms[WZR_RS_G54];
1386 case BCM47XX_BOARD_BUFFALO_WZR_RS_G54HP:
1387 return &platforms[WZR_RS_G54HP];
1388 case BCM47XX_BOARD_DELL_TM2300:
1389 return &platforms[TM2300];
1390 case BCM47XX_BOARD_DLINK_DIR130:
1391 return &platforms[DIR130];
1392 case BCM47XX_BOARD_DLINK_DIR330:
1393 return &platforms[DIR330];
1394 case BCM47XX_BOARD_HUAWEI_E970:
1395 return &platforms[HUAWEI_E970];
1396 case BCM47XX_BOARD_LINKSYS_E1000V1:
1397 return &platforms[E1000V1];
1398 case BCM47XX_BOARD_LINKSYS_E1000V21:
1399 return &platforms[E1000V21];
1400 case BCM47XX_BOARD_LINKSYS_E2000V1:
1401 return &platforms[E2000V1];
1402 case BCM47XX_BOARD_LINKSYS_E3000V1:
1403 return &platforms[E3000V1];
1404 case BCM47XX_BOARD_LINKSYS_E3200V1:
1405 return &platforms[E3200V1];
1406 case BCM47XX_BOARD_LINKSYS_E4200V1:
1407 return &platforms[E4200V1];
1408 case BCM47XX_BOARD_LINKSYS_WRT150NV1:
1409 return &platforms[WRT150NV1];
1410 case BCM47XX_BOARD_LINKSYS_WRT150NV11:
1411 return &platforms[WRT150NV11];
1412 case BCM47XX_BOARD_LINKSYS_WRT160NV1:
1413 return &platforms[WRT160NV1];
1414 case BCM47XX_BOARD_LINKSYS_WRT160NV3:
1415 return &platforms[WRT160NV3];
1416 case BCM47XX_BOARD_LINKSYS_WRT300NV11:
1417 return &platforms[WRT300NV11];
1418 case BCM47XX_BOARD_LINKSYS_WRT310NV1:
1419 return &platforms[WRT310NV1];
1420 case BCM47XX_BOARD_LINKSYS_WRT54GSV1:
1421 return &platforms[WRT54G];
1422 case BCM47XX_BOARD_LINKSYS_WRT54G3GV2:
1423 return &platforms[WRT54G3GV2_VF];
1424 case BCM47XX_BOARD_LINKSYS_WRT610NV1:
1425 return &platforms[WRT610N];
1426 case BCM47XX_BOARD_LINKSYS_WRT610NV2:
1427 return &platforms[WRT610NV2];
1428 case BCM47XX_BOARD_LINKSYS_WRTSL54GS:
1429 return &platforms[WRTSL54GS];
1430 case BCM47XX_BOARD_MOTOROLA_WE800G:
1431 return &platforms[WE800G];
1432 case BCM47XX_BOARD_MOTOROLA_WR850GP:
1433 return &platforms[WR850GP];
1434 case BCM47XX_BOARD_MOTOROLA_WR850GV2V3:
1435 return &platforms[WR850GV2V3];
1436 case BCM47XX_BOARD_NETGEAR_WNDR3400V1:
1437 return &platforms[WNDR3400V1];
1438 case BCM47XX_BOARD_NETGEAR_WNDR3700V3:
1439 return &platforms[WNDR3700V3];
1440 case BCM47XX_BOARD_UNKNOWN:
1441 case BCM47XX_BOARD_NO:
1442 printk(MODULE_NAME ": unknown board found, try legacy detect\n");
1443 printk(MODULE_NAME ": please open a ticket at https://dev.openwrt.org and attach the complete nvram\n");
1444 return platform_detect_legacy();
1445 default:
1446 printk(MODULE_NAME ": board was detected as \"%s\", but not gpio configuration available\n", board_name);
1447 printk(MODULE_NAME ": now trying legacy detect\n");
1448 return platform_detect_legacy();
1449 }
1450 }
1451
1452 static inline void ssb_maskset32(struct ssb_device *dev,
1453 u16 offset, u32 mask, u32 set)
1454 {
1455 ssb_write32(dev, offset, (ssb_read32(dev, offset) & mask) | set);
1456 }
1457
1458 static void gpio_set_irqenable(int enabled, irqreturn_t (*handler)(int, void *))
1459 {
1460 int irq;
1461 int err;
1462
1463 irq = gpio_to_irq(0);
1464 if (irq < 0) {
1465 pr_err("no irq for gpio available\n");
1466 return;
1467 }
1468
1469 if (enabled) {
1470 err = request_irq(irq, handler, IRQF_SHARED, "gpio", handler);
1471 if (err) {
1472 pr_err("can not reqeust irq\n");
1473 return;
1474 }
1475 } else {
1476 free_irq(irq, handler);
1477 }
1478
1479 switch (bcm47xx_bus_type) {
1480 #ifdef CONFIG_BCM47XX_SSB
1481 case BCM47XX_BUS_TYPE_SSB:
1482 if (bcm47xx_bus.ssb.chipco.dev)
1483 ssb_maskset32(bcm47xx_bus.ssb.chipco.dev, SSB_CHIPCO_IRQMASK, ~SSB_CHIPCO_IRQ_GPIO, (enabled ? SSB_CHIPCO_IRQ_GPIO : 0));
1484 break;
1485 #endif
1486 #ifdef CONFIG_BCM47XX_BCMA
1487 case BCM47XX_BUS_TYPE_BCMA:
1488 if (bcm47xx_bus.bcma.bus.drv_cc.core)
1489 bcma_maskset32(bcm47xx_bus.bcma.bus.drv_cc.core, BCMA_CC_IRQMASK, ~BCMA_CC_IRQ_GPIO, (enabled ? BCMA_CC_IRQ_GPIO : 0));
1490 break;
1491 #endif
1492 }
1493 }
1494
1495 static void hotplug_button(struct work_struct *work)
1496 {
1497 struct event_t *event = container_of(work, struct event_t, wq);
1498 char *s;
1499
1500 event->skb = alloc_skb(2048, GFP_KERNEL);
1501
1502 s = skb_put(event->skb, strlen(event->action) + 2);
1503 sprintf(s, "%s@", event->action);
1504 fill_event(event);
1505
1506 NETLINK_CB(event->skb).dst_group = 1;
1507 broadcast_uevent(event->skb, 0, 1, GFP_KERNEL);
1508
1509 kfree(event);
1510 }
1511
1512 static irqreturn_t button_handler(int irq, void *dev_id)
1513 {
1514 struct button_t *b;
1515 u32 in, changed;
1516
1517 in = bcm47xx_gpio_in(~0) & platform.button_mask;
1518 bcm47xx_gpio_polarity(platform.button_mask, in);
1519 changed = platform.button_polarity ^ in;
1520 platform.button_polarity = in;
1521
1522 changed &= ~bcm47xx_gpio_outen(0, 0);
1523
1524 for (b = platform.buttons; b->name; b++) {
1525 struct event_t *event;
1526
1527 if (!(b->gpio & changed)) continue;
1528
1529 b->pressed ^= 1;
1530
1531 if ((event = (struct event_t *)kzalloc (sizeof(struct event_t), GFP_ATOMIC))) {
1532 event->seen = (jiffies - b->seen)/HZ;
1533 event->name = b->name;
1534 event->action = b->pressed ? "pressed" : "released";
1535 INIT_WORK(&event->wq, (void *)(void *)hotplug_button);
1536 schedule_work(&event->wq);
1537 }
1538
1539 b->seen = jiffies;
1540 }
1541 return IRQ_HANDLED;
1542 }
1543
1544 static void register_buttons(struct button_t *b)
1545 {
1546 for (; b->name; b++)
1547 platform.button_mask |= b->gpio;
1548
1549 platform.button_mask &= ~gpiomask;
1550
1551 bcm47xx_gpio_outen(platform.button_mask, 0);
1552 bcm47xx_gpio_control(platform.button_mask, 0);
1553 platform.button_polarity = bcm47xx_gpio_in(~0) & platform.button_mask;
1554 bcm47xx_gpio_polarity(platform.button_mask, platform.button_polarity);
1555 bcm47xx_gpio_intmask(platform.button_mask, platform.button_mask);
1556
1557 gpio_set_irqenable(1, button_handler);
1558 }
1559
1560 static void unregister_buttons(struct button_t *b)
1561 {
1562 bcm47xx_gpio_intmask(platform.button_mask, 0);
1563
1564 gpio_set_irqenable(0, button_handler);
1565 }
1566
1567
1568 static void add_msg(struct event_t *event, char *msg, int argv)
1569 {
1570 char *s;
1571
1572 if (argv)
1573 return;
1574
1575 s = skb_put(event->skb, strlen(msg) + 1);
1576 strcpy(s, msg);
1577 }
1578
1579 static int fill_event (struct event_t *event)
1580 {
1581 static char buf[128];
1582
1583 add_msg(event, "HOME=/", 0);
1584 add_msg(event, "PATH=/sbin:/bin:/usr/sbin:/usr/bin", 0);
1585 add_msg(event, "SUBSYSTEM=button", 0);
1586 snprintf(buf, 128, "ACTION=%s", event->action);
1587 add_msg(event, buf, 0);
1588 snprintf(buf, 128, "BUTTON=%s", event->name);
1589 add_msg(event, buf, 0);
1590 snprintf(buf, 128, "SEEN=%ld", event->seen);
1591 add_msg(event, buf, 0);
1592 snprintf(buf, 128, "SEQNUM=%llu", uevent_next_seqnum());
1593 add_msg(event, buf, 0);
1594
1595 return 0;
1596 }
1597
1598 /*
1599 * This should be extended to allow the platform to specify the pins and width
1600 * of the shift register. They're hardcoded for now because only the WNDR3700v3
1601 * uses it.
1602 */
1603 static void shiftreg_output(unsigned int val)
1604 {
1605 unsigned int mask;
1606
1607 bcm47xx_gpio_out(SHIFTREG_DATA, SHIFTREG_DATA); /* init off, pull high */
1608 bcm47xx_gpio_out(SHIFTREG_CLK, 0); /* init reset */
1609
1610 /* shift 8 times */
1611 for(mask = 1 << (SHIFTREG_MAX_BITS-1); mask; mask >>= 1)
1612 {
1613 bcm47xx_gpio_out(SHIFTREG_DATA, (val & mask) ? SHIFTREG_DATA : 0);
1614 bcm47xx_gpio_out(SHIFTREG_CLK, SHIFTREG_CLK); /* pull high to trigger */
1615 bcm47xx_gpio_out(SHIFTREG_CLK, 0); /* reset to low */
1616 }
1617 }
1618
1619 static void set_led_shift(struct led_t *led)
1620 {
1621 static u32 shiftreg = 0;
1622 u32 old = shiftreg;
1623 u32 pin = (led->gpio & ~GPIO_TYPE_MASK);
1624
1625 if (led->state) {
1626 shiftreg |= pin;
1627 } else {
1628 shiftreg &= ~pin;
1629 }
1630
1631 /* Clock the bits out. */
1632 if (shiftreg != old) {
1633 shiftreg_output(shiftreg);
1634 }
1635 }
1636
1637 static void set_led_extif(struct led_t *led)
1638 {
1639 volatile u8 *addr = (volatile u8 *) KSEG1ADDR(EXTIF_UART) + (led->gpio & ~GPIO_TYPE_MASK);
1640 if (led->state)
1641 *addr = 0xFF;
1642 else
1643 *addr;
1644 }
1645
1646
1647 static void led_flash(unsigned long dummy) {
1648 struct led_t *l;
1649 u32 mask = 0;
1650 u8 extif_blink = 0;
1651
1652 for (l = platform.leds; l->name; l++) {
1653 if (!l->flash) continue;
1654 switch (l->gpio & GPIO_TYPE_MASK) {
1655 case GPIO_TYPE_EXTIF:
1656 extif_blink = 1;
1657 l->state = !l->state;
1658 set_led_extif(l);
1659 break;
1660 case GPIO_TYPE_SHIFT:
1661 extif_blink = 1;
1662 l->state = !l->state;
1663 set_led_shift(l);
1664 break;
1665 case GPIO_TYPE_NORMAL:
1666 default:
1667 mask |= l->gpio;
1668 break;
1669 }
1670 }
1671
1672 mask &= ~gpiomask;
1673 if (mask) {
1674 u32 val = ~bcm47xx_gpio_in(~0);
1675
1676 bcm47xx_gpio_outen(mask, mask);
1677 bcm47xx_gpio_control(mask, 0);
1678 bcm47xx_gpio_out(mask, val);
1679 }
1680 if (mask || extif_blink) {
1681 mod_timer(&led_timer, jiffies + FLASH_TIME);
1682 }
1683 }
1684
1685 static int diag_led_show(struct seq_file *m, void *v)
1686 {
1687 struct led_t * led = m->private;
1688
1689 u8 p = (led->polarity == NORMAL ? 0 : 1);
1690 if (led->flash) {
1691 return seq_printf(m, "f\n");
1692 } else if ((led->gpio & GPIO_TYPE_MASK) != GPIO_TYPE_NORMAL) {
1693 return seq_printf(m, "%d\n", ((led->state ^ p) ? 1 : 0));
1694 } else {
1695 u32 in = (bcm47xx_gpio_in(~0) & led->gpio ? 1 : 0);
1696 return seq_printf(m, "%d\n", ((in ^ p) ? 1 : 0));
1697 }
1698 }
1699
1700 static int diag_led_open(struct inode *inode, struct file *file)
1701 {
1702 return single_open(file, diag_led_show, PDE_DATA(inode));
1703 }
1704
1705 static ssize_t diag_led_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
1706 {
1707 struct led_t *led = PDE_DATA(file_inode(file));
1708 char cmd[5];
1709 size_t len;
1710 int p;
1711
1712 len = min(count, sizeof(cmd) - 1);
1713 if (copy_from_user(cmd, buf, len))
1714 return -EFAULT;
1715
1716 cmd[len] = 0;
1717
1718 p = (led->polarity == NORMAL ? 0 : 1);
1719 if (cmd[0] == 'f') {
1720 led->flash = 1;
1721 led_flash(0);
1722 } else {
1723 led->flash = 0;
1724 if ((led->gpio & GPIO_TYPE_MASK) == GPIO_TYPE_EXTIF) {
1725 led->state = p ^ ((cmd[0] == '1') ? 1 : 0);
1726 set_led_extif(led);
1727 } else if ((led->gpio & GPIO_TYPE_MASK) == GPIO_TYPE_SHIFT) {
1728 led->state = p ^ ((cmd[0] == '1') ? 1 : 0);
1729 set_led_shift(led);
1730 } else {
1731 bcm47xx_gpio_outen(led->gpio, led->gpio);
1732 bcm47xx_gpio_control(led->gpio, 0);
1733 bcm47xx_gpio_out(led->gpio, ((p ^ (cmd[0] == '1')) ? led->gpio : 0));
1734 }
1735 }
1736 return count;
1737 }
1738
1739 static const struct file_operations diag_led_fops = {
1740 .open = diag_led_open,
1741 .read = seq_read,
1742 .llseek = seq_lseek,
1743 .write = diag_led_write
1744 };
1745
1746 static void register_leds(struct led_t *l)
1747 {
1748 struct proc_dir_entry *p;
1749 u32 mask = 0;
1750 u32 oe_mask = 0;
1751 u32 val = 0;
1752
1753 leds = proc_mkdir("led", diag);
1754 if (!leds)
1755 return;
1756
1757 for(; l->name; l++) {
1758 if (l->gpio & gpiomask)
1759 continue;
1760
1761 switch (l->gpio & GPIO_TYPE_MASK) {
1762 case GPIO_TYPE_EXTIF:
1763 l->state = 0;
1764 set_led_extif(l);
1765 break;
1766 case GPIO_TYPE_SHIFT:
1767 mask |= (SHIFTREG_DATA | SHIFTREG_CLK);
1768 oe_mask |= (SHIFTREG_DATA | SHIFTREG_CLK);
1769 l->state = (l->polarity != NORMAL);
1770 set_led_shift(l);
1771 break;
1772 case GPIO_TYPE_NORMAL:
1773 default:
1774 if (l->polarity != INPUT) oe_mask |= l->gpio;
1775 mask |= l->gpio;
1776 val |= (l->polarity == NORMAL)?0:l->gpio;
1777 break;
1778 }
1779
1780 if (l->polarity == INPUT) continue;
1781
1782 p = proc_create_data(l->name, S_IRUSR, leds, &diag_led_fops, l);
1783 }
1784
1785 bcm47xx_gpio_outen(mask, oe_mask);
1786 bcm47xx_gpio_control(mask, 0);
1787 bcm47xx_gpio_out(mask, val);
1788 bcm47xx_gpio_intmask(mask, 0);
1789 }
1790
1791 static void unregister_leds(struct led_t *l)
1792 {
1793 for(; l->name; l++)
1794 remove_proc_entry(l->name, leds);
1795
1796 remove_proc_entry("led", diag);
1797 }
1798
1799 static int diag_model_show(struct seq_file *m, void *v)
1800 {
1801 return seq_printf(m, "%s\n", platform.name);
1802 }
1803
1804 static int diag_model_open(struct inode *inode, struct file *file)
1805 {
1806 return single_open(file, diag_model_show, PDE_DATA(inode));
1807 }
1808
1809 static const struct file_operations diag_model_fops = {
1810 .open = diag_model_open,
1811 .read = seq_read,
1812 .llseek = seq_lseek
1813 };
1814
1815 static int diag_gpiomask_show(struct seq_file *m, void *v)
1816 {
1817 return seq_printf(m, "0x%04x\n", gpiomask);
1818 }
1819
1820 static int diag_gpiomask_open(struct inode *inode, struct file *file)
1821 {
1822 return single_open(file, diag_gpiomask_show, PDE_DATA(inode));
1823 }
1824
1825 static ssize_t diag_gpiomask_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
1826 {
1827 int err = kstrtouint_from_user(buf, count, 0, &gpiomask);
1828 if (err)
1829 return err;
1830
1831 if (platform.buttons) {
1832 unregister_buttons(platform.buttons);
1833 register_buttons(platform.buttons);
1834 }
1835
1836 if (platform.leds) {
1837 unregister_leds(platform.leds);
1838 register_leds(platform.leds);
1839 }
1840
1841 return count;
1842 }
1843
1844 static const struct file_operations diag_gpiomask_fops = {
1845 .open = diag_gpiomask_open,
1846 .read = seq_read,
1847 .llseek = seq_lseek,
1848 .write = diag_gpiomask_write
1849 };
1850
1851 static int __init diag_init(void)
1852 {
1853 static struct proc_dir_entry *p;
1854 static struct platform_t *detected;
1855
1856 detected = platform_detect();
1857 if (!detected) {
1858 printk(MODULE_NAME ": Router model not detected.\n");
1859 return -ENODEV;
1860 }
1861 memcpy(&platform, detected, sizeof(struct platform_t));
1862
1863 printk(MODULE_NAME ": Detected '%s'\n", platform.name);
1864 if (platform.platform_init != NULL) {
1865 platform.platform_init();
1866 }
1867
1868 if (!(diag = proc_mkdir("diag", NULL))) {
1869 printk(MODULE_NAME ": proc_mkdir on /proc/diag failed\n");
1870 return -EINVAL;
1871 }
1872
1873 p = proc_create("model", S_IRUSR, diag, &diag_model_fops);
1874 if (!p) {
1875 remove_proc_entry("diag", NULL);
1876 return -EINVAL;
1877 }
1878
1879 p = proc_create("gpiomask", S_IRUSR | S_IWUSR, diag, &diag_gpiomask_fops);
1880 if (!p) {
1881 remove_proc_entry("model", diag);
1882 remove_proc_entry("diag", NULL);
1883 return -EINVAL;
1884 }
1885
1886 if (platform.buttons)
1887 register_buttons(platform.buttons);
1888
1889 if (platform.leds)
1890 register_leds(platform.leds);
1891
1892 return 0;
1893 }
1894
1895 static void __exit diag_exit(void)
1896 {
1897 del_timer(&led_timer);
1898
1899 if (platform.buttons)
1900 unregister_buttons(platform.buttons);
1901
1902 if (platform.leds)
1903 unregister_leds(platform.leds);
1904
1905 remove_proc_entry("model", diag);
1906 remove_proc_entry("gpiomask", diag);
1907 remove_proc_entry("diag", NULL);
1908 }
1909
1910 module_init(diag_init);
1911 module_exit(diag_exit);
1912
1913 MODULE_AUTHOR("Mike Baker, Felix Fietkau / OpenWrt.org");
1914 MODULE_LICENSE("GPL");