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