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