busybox 1.19.4 update patch
[openwrt.git] / package / 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 extern u64 uevent_next_seqnum(void);
36
37 #include "gpio.h"
38 #include "diag.h"
39 #define getvar(str) (nvram_get(str)?:"")
40
41 static inline int startswith (char *source, char *cmp) { return !strncmp(source,cmp,strlen(cmp)); }
42 static int fill_event(struct event_t *);
43 static unsigned int gpiomask = 0;
44 module_param(gpiomask, int, 0644);
45
46 enum {
47 /* Linksys */
48 WAP54GV1,
49 WAP54GV2,
50 WAP54GV3,
51 WRT54GV1,
52 WRT54G,
53 WRTSL54GS,
54 WRT54G3G,
55 WRT54G3GV2_VF,
56 WRT150NV1,
57 WRT150NV11,
58 WRT160NV1,
59 WRT160NV3,
60 WRT300NV11,
61 WRT350N,
62 WRT600N,
63 WRT600NV11,
64 WRT610N,
65 WRT610NV2,
66 E3000V1,
67
68 /* ASUS */
69 WLHDD,
70 WL300G,
71 WL320GE,
72 WL330GE,
73 WL500G,
74 WL500GD,
75 WL500GP,
76 WL500GPV2,
77 WL500W,
78 WL520GC,
79 WL520GU,
80 ASUS_4702,
81 WL700GE,
82 RTN16,
83
84 /* Buffalo */
85 WBR2_G54,
86 WHR_G54S,
87 WHR_HP_G54,
88 WHR_G125,
89 WHR2_A54G54,
90 WLA2_G54L,
91 WZR_G300N,
92 WZR_RS_G54,
93 WZR_RS_G54HP,
94 BUFFALO_UNKNOWN,
95 BUFFALO_UNKNOWN_4710,
96
97 /* Siemens */
98 SE505V1,
99 SE505V2,
100
101 /* US Robotics */
102 USR5461,
103
104 /* Dell */
105 TM2300,
106 TM2300V2,
107
108 /* Motorola */
109 WE800G,
110 WR850GV1,
111 WR850GV2V3,
112 WR850GP,
113
114 /* Belkin */
115 BELKIN_UNKNOWN,
116 BELKIN_F7D4301,
117
118 /* Netgear */
119 WGT634U,
120 WNR834BV1,
121 WNR834BV2,
122
123 /* Trendware */
124 TEW411BRPP,
125
126 /* SimpleTech */
127 STI_NAS,
128
129 /* D-Link */
130 DIR130,
131 DIR320,
132 DIR330,
133 DWL3150,
134
135 /* Sitecom */
136 WL105B,
137
138 /* Western Digital */
139 WDNetCenter,
140
141 /* Askey */
142 RT210W,
143
144 /* OvisLink */
145 WL1600GL,
146
147 /* Microsoft */
148 MN700,
149
150 /* Edimax */
151 PS1208MFG,
152 };
153
154 static void __init bcm4780_init(void) {
155 int pin = 1 << 3;
156
157 /* Enables GPIO 3 that controls HDD and led power on ASUS WL-700gE */
158 printk(MODULE_NAME ": Spinning up HDD and enabling leds\n");
159 gpio_outen(pin, pin);
160 gpio_control(pin, 0);
161 gpio_out(pin, pin);
162
163 /* Wait 5s, so the HDD can spin up */
164 set_current_state(TASK_INTERRUPTIBLE);
165 schedule_timeout(HZ * 5);
166 }
167
168 static void __init NetCenter_init(void) {
169 /* unset pin 6 (+12V) */
170 int pin = 1 << 6;
171 gpio_outen(pin, pin);
172 gpio_control(pin, 0);
173 gpio_out(pin, pin);
174 /* unset pin 1 (turn off red led, blue will light alone if +5V comes up) */
175 pin = 1 << 1;
176 gpio_outen(pin, pin);
177 gpio_control(pin, 0);
178 gpio_out(pin, pin);
179 /* unset pin 3 (+5V) and wait 5 seconds (harddisk spin up) */
180 bcm4780_init();
181 }
182
183 static void __init bcm57xx_init(void) {
184 int pin = 1 << 2;
185
186 /* FIXME: switch comes up, but port mappings/vlans not right */
187 gpio_outen(pin, pin);
188 gpio_control(pin, 0);
189 gpio_out(pin, pin);
190 }
191
192 static struct platform_t __initdata platforms[] = {
193 /* Linksys */
194 [WAP54GV1] = {
195 .name = "Linksys WAP54G V1",
196 .buttons = {
197 { .name = "reset", .gpio = 1 << 0 },
198 },
199 .leds = {
200 { .name = "diag", .gpio = 1 << 3 },
201 { .name = "wlan", .gpio = 1 << 4 },
202 },
203 },
204 [WAP54GV2] = {
205 .name = "Linksys WAP54G V2",
206 .buttons = {
207 { .name = "reset", .gpio = 1 << 0 },
208 },
209 .leds = {
210 { .name = "wlan", .gpio = 1 << 5, .polarity = REVERSE },
211 /* GPIO 6 is b44 (eth0, LAN) PHY power */
212 },
213 },
214 [WAP54GV3] = {
215 .name = "Linksys WAP54G V3",
216 .buttons = {
217 /* FIXME: verify this */
218 { .name = "reset", .gpio = 1 << 7 },
219 { .name = "ses", .gpio = 1 << 0 },
220 },
221 .leds = {
222 /* FIXME: diag? */
223 { .name = "ses", .gpio = 1 << 1 },
224 },
225 },
226 [WRT54GV1] = {
227 .name = "Linksys WRT54G V1.x",
228 .buttons = {
229 { .name = "reset", .gpio = 1 << 6 },
230 },
231 .leds = {
232 { .name = "diag", .gpio = 0x13 | GPIO_TYPE_EXTIF, .polarity = NORMAL },
233 { .name = "dmz", .gpio = 0x12 | GPIO_TYPE_EXTIF, .polarity = NORMAL },
234 },
235 },
236 [WRT54G] = {
237 .name = "Linksys WRT54G/GS/GL",
238 .buttons = {
239 { .name = "reset", .gpio = 1 << 6 },
240 { .name = "ses", .gpio = 1 << 4 },
241 },
242 .leds = {
243 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
244 { .name = "dmz", .gpio = 1 << 7, .polarity = REVERSE },
245 { .name = "ses_white", .gpio = 1 << 2, .polarity = REVERSE },
246 { .name = "ses_orange", .gpio = 1 << 3, .polarity = REVERSE },
247 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
248 },
249 },
250 [WRTSL54GS] = {
251 .name = "Linksys WRTSL54GS",
252 .buttons = {
253 { .name = "reset", .gpio = 1 << 6 },
254 { .name = "ses", .gpio = 1 << 4 },
255 },
256 .leds = {
257 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
258 { .name = "dmz", .gpio = 1 << 0, .polarity = REVERSE },
259 { .name = "ses_white", .gpio = 1 << 5, .polarity = REVERSE },
260 { .name = "ses_orange", .gpio = 1 << 7, .polarity = REVERSE },
261 },
262 },
263 [WRT54G3G] = {
264 .name = "Linksys WRT54G3G",
265 .buttons = {
266 { .name = "reset", .gpio = 1 << 6 },
267 { .name = "3g", .gpio = 1 << 4 },
268 },
269 .leds = {
270 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
271 { .name = "dmz", .gpio = 1 << 7, .polarity = REVERSE },
272 { .name = "3g_green", .gpio = 1 << 2, .polarity = NORMAL },
273 { .name = "3g_blue", .gpio = 1 << 3, .polarity = NORMAL },
274 { .name = "3g_blink", .gpio = 1 << 5, .polarity = NORMAL },
275 },
276 },
277 [WRT54G3GV2_VF] = {
278 .name = "Linksys WRT54G3GV2-VF",
279 .buttons = {
280 { .name = "reset", .gpio = 1 << 6 },
281 { .name = "3g", .gpio = 1 << 5 },
282 },
283 .leds = {
284 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
285 { .name = "3g_green", .gpio = 1 << 2, .polarity = NORMAL },
286 { .name = "3g_blue", .gpio = 1 << 3, .polarity = NORMAL },
287 },
288 },
289 [WRT150NV1] = {
290 .name = "Linksys WRT150N V1",
291 .buttons = {
292 { .name = "reset", .gpio = 1 << 6 },
293 { .name = "ses", .gpio = 1 << 4 },
294 },
295 .leds = {
296 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
297 { .name = "ses_green", .gpio = 1 << 5, .polarity = REVERSE },
298 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE },
299 },
300 },
301 [WRT150NV11] = {
302 .name = "Linksys WRT150N V1.1",
303 .buttons = {
304 { .name = "reset", .gpio = 1 << 6 },
305 { .name = "ses", .gpio = 1 << 4 },
306 },
307 .leds = {
308 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
309 { .name = "ses_green", .gpio = 1 << 5, .polarity = REVERSE },
310 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE },
311 },
312 },
313 [WRT160NV1] = {
314 .name = "Linksys WRT160N v1.x",
315 .buttons = {
316 { .name = "reset", .gpio = 1 << 6 },
317 { .name = "ses", .gpio = 1 << 4 },
318 },
319 .leds = {
320 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
321 { .name = "ses_blue", .gpio = 1 << 5, .polarity = REVERSE },
322 { .name = "ses_orange", .gpio = 1 << 3, .polarity = REVERSE },
323 },
324 },
325 [WRT160NV3] = {
326 .name = "Linksys WRT160N V3",
327 .buttons = {
328 { .name = "reset", .gpio = 1 << 6 },
329 { .name = "ses", .gpio = 1 << 5 },
330 },
331 .leds = {
332 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
333 { .name = "ses_blue", .gpio = 1 << 4, .polarity = REVERSE },
334 { .name = "ses_orange", .gpio = 1 << 2, .polarity = REVERSE },
335 },
336 },
337 [WRT300NV11] = {
338 .name = "Linksys WRT300N V1.1",
339 .buttons = {
340 { .name = "reset", .gpio = 1 << 6 }, // "Reset" on back panel
341 { .name = "ses", .gpio = 1 << 4 }, // "Reserved" on top panel
342 },
343 .leds = {
344 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL }, // "Power"
345 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE }, // "Security" Amber
346 { .name = "ses_green", .gpio = 1 << 5, .polarity = REVERSE }, // "Security" Green
347 },
348 .platform_init = bcm57xx_init,
349 },
350 [WRT350N] = {
351 .name = "Linksys WRT350N",
352 .buttons = {
353 { .name = "reset", .gpio = 1 << 6 },
354 { .name = "ses", .gpio = 1 << 8 },
355 },
356 .leds = {
357 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
358 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE },
359 { .name = "ses_green", .gpio = 1 << 9, .polarity = REVERSE },
360 { .name = "usb_blink", .gpio = 1 << 10, .polarity = REVERSE },
361 { .name = "usb", .gpio = 1 << 11, .polarity = REVERSE },
362 },
363 .platform_init = bcm57xx_init,
364 },
365 [WRT600N] = {
366 .name = "Linksys WRT600N",
367 .buttons = {
368 { .name = "reset", .gpio = 1 << 6 },
369 { .name = "ses", .gpio = 1 << 7 },
370 },
371 .leds = {
372 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE }, // Power LED
373 { .name = "usb", .gpio = 1 << 3, .polarity = REVERSE }, // USB LED
374 { .name = "wl0_ses_amber", .gpio = 1 << 8, .polarity = REVERSE }, // 2.4Ghz LED Amber
375 { .name = "wl0_ses_green", .gpio = 1 << 9, .polarity = REVERSE }, // 2.4Ghz LED Green
376 { .name = "wl1_ses_amber", .gpio = 1 << 10, .polarity = REVERSE }, // 5.6Ghz LED Amber
377 { .name = "wl1_ses_green", .gpio = 1 << 11, .polarity = REVERSE }, // 5.6Ghz LED Green
378 },
379 .platform_init = bcm57xx_init,
380 },
381 [WRT600NV11] = {
382 .name = "Linksys WRT600N V1.1",
383 .buttons = {
384 { .name = "reset", .gpio = 1 << 6 },
385 { .name = "ses", .gpio = 1 << 7 },
386 },
387 .leds = {
388 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE }, // Power LED
389 { .name = "usb", .gpio = 1 << 3, .polarity = REVERSE }, // USB LED
390 { .name = "wl0_ses_amber", .gpio = 1 << 8, .polarity = REVERSE }, // 2.4Ghz LED Amber
391 { .name = "wl0_ses_green", .gpio = 1 << 9, .polarity = REVERSE }, // 2.4Ghz LED Green
392 { .name = "wl1_ses_amber", .gpio = 1 << 10, .polarity = REVERSE }, // 5.6Ghz LED Amber
393 { .name = "wl1_ses_green", .gpio = 1 << 11, .polarity = REVERSE }, // 5.6Ghz LED Green
394 },
395 .platform_init = bcm57xx_init,
396 },
397 [WRT610N] = {
398 .name = "Linksys WRT610N",
399 .buttons = {
400 { .name = "reset", .gpio = 1 << 6 },
401 { .name = "ses", .gpio = 1 << 8 },
402 },
403 .leds = {
404 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL }, // Power LED
405 { .name = "usb", .gpio = 1 << 0, .polarity = REVERSE }, // USB LED
406 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE }, // WiFi protected setup LED amber
407 { .name = "ses_blue", .gpio = 1 << 9, .polarity = REVERSE }, // WiFi protected setup LED blue
408 },
409 },
410 [WRT610NV2] = {
411 .name = "Linksys WRT610N V2",
412 .buttons = {
413 { .name = "reset", .gpio = 1 << 6 },
414 { .name = "ses", .gpio = 1 << 4 },
415 },
416 .leds = {
417 { .name = "power", .gpio = 1 << 5, .polarity = NORMAL }, // Power LED
418 { .name = "usb", .gpio = 1 << 7, .polarity = NORMAL }, // USB LED
419 { .name = "ses_amber", .gpio = 1 << 0, .polarity = REVERSE }, // WiFi protected setup LED amber
420 { .name = "ses_blue", .gpio = 1 << 3, .polarity = REVERSE }, // WiFi protected setup LED blue
421 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL }, // Wireless LED
422 },
423 },
424 [E3000V1] = {
425 .name = "Linksys E3000 V1",
426 .buttons = {
427 { .name = "reset", .gpio = 1 << 6 },
428 { .name = "ses", .gpio = 1 << 4 },
429 },
430 .leds = {
431 { .name = "power", .gpio = 1 << 5, .polarity = NORMAL }, // Power LED
432 { .name = "usb", .gpio = 1 << 7, .polarity = NORMAL }, // USB LED
433 { .name = "ses_amber", .gpio = 1 << 0, .polarity = REVERSE }, // WiFi protected setup LED amber
434 { .name = "ses_blue", .gpio = 1 << 3, .polarity = REVERSE }, // WiFi protected setup LED blue
435 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL }, // Wireless LED
436 },
437 },
438 /* Asus */
439 [WLHDD] = {
440 .name = "ASUS WL-HDD",
441 .buttons = {
442 { .name = "reset", .gpio = 1 << 6 },
443 },
444 .leds = {
445 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
446 { .name = "usb", .gpio = 1 << 2, .polarity = REVERSE },
447 },
448 },
449 [WL300G] = {
450 .name = "ASUS WL-300g",
451 .buttons = {
452 { .name = "reset", .gpio = 1 << 6 },
453 },
454 .leds = {
455 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
456 },
457 },
458 [WL320GE] = {
459 .name = "ASUS WL-320gE/WL-320gP",
460 .buttons = {
461 { .name = "reset", .gpio = 1 << 6 },
462 },
463 .leds = {
464 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
465 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE },
466 { .name = "link", .gpio = 1 << 11, .polarity = REVERSE },
467 },
468 },
469 [WL330GE] = {
470 .name = "ASUS WL-330gE",
471 .buttons = {
472 { .name = "reset", .gpio = 1 << 2 },
473 },
474 .leds = {
475 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
476 },
477 },
478 [WL500G] = {
479 .name = "ASUS WL-500g",
480 .buttons = {
481 { .name = "reset", .gpio = 1 << 6 },
482 },
483 .leds = {
484 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
485 },
486 },
487 [WL500GD] = {
488 .name = "ASUS WL-500g Deluxe",
489 .buttons = {
490 { .name = "reset", .gpio = 1 << 6 },
491 },
492 .leds = {
493 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
494 },
495 },
496 [WL500GP] = {
497 .name = "ASUS WL-500g Premium",
498 .buttons = {
499 { .name = "reset", .gpio = 1 << 0 },
500 { .name = "ses", .gpio = 1 << 4 },
501 },
502 .leds = {
503 { .name = "power", .gpio = 1 << 1, .polarity = REVERSE },
504 },
505 },
506 [WL500GPV2] = {
507 .name = "ASUS WL-500g Premium V2",
508 .buttons = {
509 { .name = "reset", .gpio = 1 << 2 },
510 { .name = "ses", .gpio = 1 << 3 },
511 },
512 .leds = {
513 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
514 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
515 },
516 },
517 [WL500W] = {
518 .name = "ASUS WL-500W",
519 .buttons = {
520 { .name = "reset", .gpio = 1 << 6 },
521 { .name = "ses", .gpio = 1 << 7 },
522 },
523 .leds = {
524 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
525 },
526 },
527 [WL520GC] = {
528 .name = "ASUS WL-520GC",
529 .buttons = {
530 { .name = "reset", .gpio = 1 << 2 },
531 { .name = "ses", .gpio = 1 << 3 },
532 },
533 .leds = {
534 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
535 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
536 },
537 },
538 [WL520GU] = {
539 .name = "ASUS WL-520gU",
540 .buttons = {
541 { .name = "reset", .gpio = 1 << 2 },
542 { .name = "ses", .gpio = 1 << 3 },
543 },
544 .leds = {
545 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
546 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
547 },
548 },
549 [ASUS_4702] = {
550 .name = "ASUS (unknown, BCM4702)",
551 .buttons = {
552 { .name = "reset", .gpio = 1 << 6 },
553 },
554 .leds = {
555 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
556 },
557 },
558 [WL700GE] = {
559 .name = "ASUS WL-700gE",
560 .buttons = {
561 { .name = "reset", .gpio = 1 << 7 }, // on back, hardwired, always resets device regardless OS state
562 { .name = "ses", .gpio = 1 << 4 }, // on back, actual name ezsetup
563 { .name = "power", .gpio = 1 << 0 }, // on front
564 { .name = "copy", .gpio = 1 << 6 }, // on front
565 },
566 .leds = {
567 #if 0
568 // GPIO that controls power led also enables/disables some essential functions
569 // - power to HDD
570 // - switch leds
571 { .name = "power", .gpio = 1 << 3, .polarity = NORMAL }, // actual name power
572 #endif
573 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE }, // actual name ready
574 },
575 .platform_init = bcm4780_init,
576 },
577 [RTN16] = {
578 .name = "ASUS RT-N16",
579 .buttons = {
580 { .name = "reset", .gpio = 1 << 8 },
581 { .name = "ses", .gpio = 1 << 5 },
582 },
583 .leds = {
584 { .name = "power", .gpio = 1 << 1, .polarity = REVERSE },
585 { .name = "wlan", .gpio = 1 << 7, .polarity = NORMAL },
586 },
587 },
588 /* Buffalo */
589 [WHR_G54S] = {
590 .name = "Buffalo WHR-G54S",
591 .buttons = {
592 { .name = "reset", .gpio = 1 << 4 },
593 { .name = "bridge", .gpio = 1 << 5 },
594 { .name = "ses", .gpio = 1 << 0 },
595 },
596 .leds = {
597 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
598 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
599 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
600 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
601 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
602 },
603 },
604 [WBR2_G54] = {
605 .name = "Buffalo WBR2-G54",
606 /* FIXME: verify */
607 .buttons = {
608 { .name = "reset", .gpio = 1 << 7 },
609 },
610 .leds = {
611 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
612 },
613 },
614 [WHR_HP_G54] = {
615 .name = "Buffalo WHR-HP-G54",
616 .buttons = {
617 { .name = "reset", .gpio = 1 << 4 },
618 { .name = "bridge", .gpio = 1 << 5 },
619 { .name = "ses", .gpio = 1 << 0 },
620 },
621 .leds = {
622 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
623 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
624 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
625 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
626 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
627 },
628 },
629 [WHR_G125] = {
630 .name = "Buffalo WHR-G125",
631 .buttons = {
632 { .name = "reset", .gpio = 1 << 4 },
633 { .name = "bridge", .gpio = 1 << 5 },
634 { .name = "ses", .gpio = 1 << 0 },
635 },
636 .leds = {
637 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
638 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
639 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
640 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
641 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
642 },
643 },
644 [WHR2_A54G54] = {
645 .name = "Buffalo WHR2-A54G54",
646 .buttons = {
647 { .name = "reset", .gpio = 1 << 4 },
648 },
649 .leds = {
650 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
651 },
652 },
653 [WLA2_G54L] = {
654 .name = "Buffalo WLA2-G54L",
655 /* FIXME: verify */
656 .buttons = {
657 { .name = "reset", .gpio = 1 << 7 },
658 },
659 .leds = {
660 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
661 },
662 },
663 [WZR_G300N] = {
664 .name = "Buffalo WZR-G300N",
665 .buttons = {
666 { .name = "reset", .gpio = 1 << 4 },
667 },
668 .leds = {
669 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
670 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
671 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
672 },
673 },
674 [WZR_RS_G54] = {
675 .name = "Buffalo WZR-RS-G54",
676 .buttons = {
677 { .name = "ses", .gpio = 1 << 0 },
678 { .name = "reset", .gpio = 1 << 4 },
679 },
680 .leds = {
681 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
682 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
683 { .name = "vpn", .gpio = 1 << 1, .polarity = REVERSE },
684 },
685 },
686 [WZR_RS_G54HP] = {
687 .name = "Buffalo WZR-RS-G54HP",
688 .buttons = {
689 { .name = "ses", .gpio = 1 << 0 },
690 { .name = "reset", .gpio = 1 << 4 },
691 },
692 .leds = {
693 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
694 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
695 { .name = "vpn", .gpio = 1 << 1, .polarity = REVERSE },
696 },
697 },
698 [BUFFALO_UNKNOWN] = {
699 .name = "Buffalo (unknown)",
700 .buttons = {
701 { .name = "reset", .gpio = 1 << 7 },
702 },
703 .leds = {
704 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
705 },
706 },
707 [BUFFALO_UNKNOWN_4710] = {
708 .name = "Buffalo (unknown, BCM4710)",
709 .buttons = {
710 { .name = "reset", .gpio = 1 << 4 },
711 },
712 .leds = {
713 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
714 },
715 },
716 /* Siemens */
717 [SE505V1] = {
718 .name = "Siemens SE505 V1",
719 .buttons = {
720 /* No usable buttons */
721 },
722 .leds = {
723 // { .name = "power", .gpio = 1 << 0 .polarity = REVERSE }, // Usable when retrofitting D26 (?)
724 { .name = "dmz", .gpio = 1 << 4, .polarity = REVERSE }, // actual name WWW
725 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
726 },
727 },
728 [SE505V2] = {
729 .name = "Siemens SE505 V2",
730 .buttons = {
731 /* No usable buttons */
732 },
733 .leds = {
734 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
735 { .name = "dmz", .gpio = 1 << 0, .polarity = REVERSE }, // actual name WWW
736 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
737 },
738 },
739 /* US Robotics */
740 [USR5461] = {
741 .name = "U.S. Robotics USR5461",
742 .buttons = {
743 /* No usable buttons */
744 },
745 .leds = {
746 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
747 { .name = "printer", .gpio = 1 << 1, .polarity = REVERSE },
748 },
749 },
750 /* Dell */
751 [TM2300] = {
752 .name = "Dell TrueMobile 2300",
753 .buttons = {
754 { .name = "reset", .gpio = 1 << 0 },
755 },
756 .leds = {
757 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
758 { .name = "power", .gpio = 1 << 7, .polarity = REVERSE },
759 },
760 },
761 [TM2300V2] = {
762 .name = "Dell TrueMobile 2300 v2",
763 .buttons = {
764 { .name = "reset", .gpio = 1 << 0 },
765 },
766 .leds = {
767 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
768 { .name = "power", .gpio = 1 << 7, .polarity = REVERSE },
769 },
770 },
771 /* Motorola */
772 [WE800G] = {
773 .name = "Motorola WE800G",
774 .buttons = {
775 { .name = "reset", .gpio = 1 << 0 },
776 },
777 .leds = {
778 { .name = "power", .gpio = 1 << 4, .polarity = NORMAL },
779 { .name = "diag", .gpio = 1 << 2, .polarity = REVERSE },
780 { .name = "wlan_amber", .gpio = 1 << 1, .polarity = NORMAL },
781 },
782 },
783 [WR850GV1] = {
784 .name = "Motorola WR850G V1",
785 .buttons = {
786 { .name = "reset", .gpio = 1 << 0 },
787 },
788 .leds = {
789 { .name = "power", .gpio = 1 << 4, .polarity = NORMAL },
790 { .name = "diag", .gpio = 1 << 3, .polarity = REVERSE },
791 { .name = "dmz", .gpio = 1 << 6, .polarity = NORMAL },
792 { .name = "wlan_red", .gpio = 1 << 5, .polarity = REVERSE },
793 { .name = "wlan_green", .gpio = 1 << 7, .polarity = REVERSE },
794 },
795 },
796 [WR850GV2V3] = {
797 .name = "Motorola WR850G V2/V3",
798 .buttons = {
799 { .name = "reset", .gpio = 1 << 5 },
800 },
801 .leds = {
802 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
803 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
804 { .name = "wan", .gpio = 1 << 6, .polarity = INPUT },
805 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
806 },
807 },
808 [WR850GP] = {
809 .name = "Motorola WR850GP",
810 .buttons = {
811 { .name = "reset", .gpio = 1 << 5 },
812 },
813 .leds = {
814 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
815 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
816 { .name = "dmz", .gpio = 1 << 6, .polarity = REVERSE },
817 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
818 },
819 },
820
821 /* Belkin */
822 [BELKIN_UNKNOWN] = {
823 .name = "Belkin (unknown)",
824 /* FIXME: verify & add detection */
825 .buttons = {
826 { .name = "reset", .gpio = 1 << 7 },
827 },
828 .leds = {
829 { .name = "power", .gpio = 1 << 5, .polarity = NORMAL },
830 { .name = "wlan", .gpio = 1 << 3, .polarity = NORMAL },
831 { .name = "connected", .gpio = 1 << 0, .polarity = NORMAL },
832 },
833 },
834 [BELKIN_F7D4301] = {
835 .name = "Belkin PlayMax F7D4301",
836 .buttons = {
837 { .name = "reset", .gpio = 1 << 6 },
838 { .name = "wps", .gpio = 1 << 8 },
839 },
840 .leds = {
841 { .name = "power", .gpio = 1 << 11, .polarity = REVERSE },
842 { .name = "wlan", .gpio = 1 << 13, .polarity = REVERSE },
843 { .name = "led0", .gpio = 1 << 14, .polarity = REVERSE },
844 { .name = "led1", .gpio = 1 << 15, .polarity = REVERSE },
845 },
846 },
847 /* Netgear */
848 [WGT634U] = {
849 .name = "Netgear WGT634U",
850 .buttons = {
851 { .name = "reset", .gpio = 1 << 2 },
852 },
853 .leds = {
854 { .name = "power", .gpio = 1 << 3, .polarity = NORMAL },
855 },
856 },
857 /* Netgear */
858 [WNR834BV1] = {
859 .name = "Netgear WNR834B V1",
860 .buttons = { /* TODO: add reset button and confirm LEDs - GPIO from dd-wrt */ },
861 .leds = {
862 { .name = "power", .gpio = 1 << 4, .polarity = REVERSE },
863 { .name = "diag", .gpio = 1 << 5, .polarity = REVERSE },
864 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
865 },
866 },
867 /* Netgear */
868 [WNR834BV2] = {
869 .name = "Netgear WNR834B V2",
870 .buttons = {
871 { .name = "reset", .gpio = 1 << 6 },
872 },
873 .leds = {
874 { .name = "power", .gpio = 1 << 2, .polarity = NORMAL },
875 { .name = "diag", .gpio = 1 << 3, .polarity = NORMAL },
876 { .name = "connected", .gpio = 1 << 7, .polarity = NORMAL },
877 },
878 },
879 /* Trendware */
880 [TEW411BRPP] = {
881 .name = "Trendware TEW411BRP+",
882 .buttons = {
883 { /* No usable buttons */ },
884 },
885 .leds = {
886 { .name = "power", .gpio = 1 << 7, .polarity = NORMAL },
887 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL },
888 { .name = "bridge", .gpio = 1 << 6, .polarity = NORMAL },
889 },
890 },
891 /* SimpleTech */
892 [STI_NAS] = {
893 .name = "SimpleTech SimpleShare NAS",
894 .buttons = {
895 { .name = "reset", .gpio = 1 << 0 }, // Power button on back, named reset to enable failsafe.
896 },
897 .leds = {
898 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE }, // actual name ready
899 },
900 .platform_init = bcm4780_init,
901 },
902 /* D-Link */
903 [DIR130] = {
904 .name = "D-Link DIR-130",
905 .buttons = {
906 { .name = "reset", .gpio = 1 << 3},
907 { .name = "reserved", .gpio = 1 << 7},
908 },
909 .leds = {
910 { .name = "diag", .gpio = 1 << 0},
911 { .name = "blue", .gpio = 1 << 6},
912 },
913 },
914 [DIR320] = {
915 .name = "D-Link DIR-320",
916 .buttons = {
917 { .name = "reserved", .gpio = 1 << 6},
918 { .name = "reset", .gpio = 1 << 7},
919 },
920 .leds = {
921 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
922 { .name = "diag", .gpio = 1 << 1, .polarity = NORMAL }, /* "status led */
923 { .name = "red", .gpio = 1 << 3, .polarity = REVERSE },
924 { .name = "blue", .gpio = 1 << 4, .polarity = REVERSE },
925 { .name = "usb", .gpio = 1 << 5, .polarity = NORMAL },
926 },
927 },
928 [DIR330] = {
929 .name = "D-Link DIR-330",
930 .buttons = {
931 { .name = "reset", .gpio = 1 << 3},
932 { .name = "reserved", .gpio = 1 << 7},
933 },
934 .leds = {
935 { .name = "diag", .gpio = 1 << 0},
936 { .name = "usb", .gpio = 1 << 4},
937 { .name = "blue", .gpio = 1 << 6},
938 },
939 },
940 [DWL3150] = {
941 .name = "D-Link DWL-3150",
942 .buttons = {
943 { .name = "reset", .gpio = 1 << 7},
944 },
945 .leds = {
946 { .name = "diag", .gpio = 1 << 2},
947 { .name = "status", .gpio = 1 << 1},
948 },
949 },
950 /* Double check */
951 [WL105B] = {
952 .name = "Sitecom WL-105b",
953 .buttons = {
954 { .name = "reset", .gpio = 1 << 10},
955 },
956 .leds = {
957 { .name = "wlan", .gpio = 1 << 4},
958 { .name = "power", .gpio = 1 << 3},
959 },
960 },
961 /* Western Digital Net Center */
962 [WDNetCenter] = {
963 .name = "Western Digital NetCenter",
964 .buttons = {
965 { .name = "power", .gpio = 1 << 0},
966 { .name = "reset", .gpio = 1 << 7},
967 },
968 .platform_init = NetCenter_init,
969 },
970 /* Askey (and clones) */
971 [RT210W] = {
972 .name = "Askey RT210W",
973 .buttons = {
974 /* Power button is hard-wired to hardware reset */
975 /* but is also connected to GPIO 7 (probably for bootloader recovery) */
976 { .name = "power", .gpio = 1 << 7},
977 },
978 .leds = {
979 /* These were verified and named based on Belkin F5D4230-4 v1112 */
980 { .name = "connected", .gpio = 1 << 0, .polarity = REVERSE },
981 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
982 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
983 },
984 },
985 [WL1600GL] = {
986 .name = "OvisLink WL-1600GL",
987 .buttons = {
988 { .name = "reset", .gpio = 1 << 3 },
989 { .name = "ses", .gpio = 1 << 4 },
990 },
991 .leds = {
992 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
993 { .name = "wps", .gpio = 1 << 2, .polarity = REVERSE },
994 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
995 { .name = "connected", .gpio = 1 << 0, .polarity = REVERSE },
996 },
997 },
998 /* Microsoft */
999 [MN700] = {
1000 .name = "Microsoft MN-700",
1001 .buttons = {
1002 { .name = "reset", .gpio = 1 << 7 },
1003 },
1004 .leds = {
1005 { .name = "power", .gpio = 1 << 6, .polarity = NORMAL },
1006 },
1007 },
1008 /* Edimax */
1009 [PS1208MFG] = {
1010 .name = "Edimax PS-1208MFG",
1011 .buttons = {
1012 { .name = "reset", .gpio = 1 << 4 },
1013 },
1014 .leds = {
1015 { .name = "status", .gpio = 1 << 1, .polarity = NORMAL },
1016 { .name = "wlan", .gpio = 1 << 0, .polarity = NORMAL },
1017 },
1018 },
1019 };
1020
1021 static struct platform_t __init *platform_detect(void)
1022 {
1023 char *boardnum, *boardtype, *buf;
1024
1025 if (strcmp(getvar("nvram_type"), "cfe") == 0)
1026 return &platforms[WGT634U];
1027
1028 /* Look for a model identifier */
1029
1030 /* Based on "model_name" */
1031 if ((buf = nvram_get("model_name"))) {
1032 if (!strcmp(buf, "DIR-130"))
1033 return &platforms[DIR130];
1034 if (!strcmp(buf, "DIR-330"))
1035 return &platforms[DIR330];
1036 }
1037
1038 /* Based on "wsc_modelname */
1039 if ((buf = nvram_get("wsc_modelname"))) {
1040 if (!strcmp(buf, "WRT610N"))
1041 return &platforms[WRT610N];
1042 }
1043
1044 /* Based on "model_no" */
1045 if ((buf = nvram_get("model_no"))) {
1046 if (startswith(buf,"WL700")) /* WL700* */
1047 return &platforms[WL700GE];
1048 }
1049
1050 /* Based on "hardware_version" */
1051 if ((buf = nvram_get("hardware_version"))) {
1052 if (startswith(buf,"WL500GPV2-")) /* WL500GPV2-* */
1053 return &platforms[WL500GPV2];
1054 if (startswith(buf,"WL520GC-")) /* WL520GU-* */
1055 return &platforms[WL520GC];
1056 if (startswith(buf,"WL520GU-")) /* WL520GU-* */
1057 return &platforms[WL520GU];
1058 if (startswith(buf,"WL330GE-")) /* WL330GE-* */
1059 return &platforms[WL330GE];
1060 if (startswith(buf,"RT-N16-")) /* RT-N16-* */
1061 return &platforms[RTN16];
1062 if (startswith(buf,"F7D4301")) /* F7D4301* */
1063 return &platforms[BELKIN_F7D4301];
1064 }
1065
1066 /* Based on "ModelId" */
1067 if ((buf = nvram_get("ModelId"))) {
1068 if (!strcmp(buf, "WR850GP"))
1069 return &platforms[WR850GP];
1070 if (!strcmp(buf, "WR850G"))
1071 return &platforms[WR850GV2V3];
1072 if (!strcmp(buf, "WX-5565") && !strcmp(getvar("boardtype"),"bcm94710ap"))
1073 return &platforms[TM2300]; /* Dell TrueMobile 2300 */
1074 if (startswith(buf,"WE800G")) /* WE800G* */
1075 return &platforms[WE800G];
1076 }
1077
1078 /* Buffalo */
1079 if ((buf = (nvram_get("melco_id") ?: nvram_get("buffalo_id")))) {
1080 /* Buffalo hardware, check id for specific hardware matches */
1081 if (!strcmp(buf, "29bb0332"))
1082 return &platforms[WBR2_G54];
1083 if (!strcmp(buf, "29129"))
1084 return &platforms[WLA2_G54L];
1085 if (!strcmp(buf, "30189"))
1086 return &platforms[WHR_HP_G54];
1087 if (!strcmp(buf, "32093"))
1088 return &platforms[WHR_G125];
1089 if (!strcmp(buf, "30182"))
1090 return &platforms[WHR_G54S];
1091 if (!strcmp(buf, "290441dd"))
1092 return &platforms[WHR2_A54G54];
1093 if (!strcmp(buf, "31120"))
1094 return &platforms[WZR_G300N];
1095 if (!strcmp(buf, "30083"))
1096 return &platforms[WZR_RS_G54];
1097 if (!strcmp(buf, "30103"))
1098 return &platforms[WZR_RS_G54HP];
1099 }
1100
1101 /* no easy model number, attempt to guess */
1102 boardnum = getvar("boardnum");
1103 boardtype = getvar("boardtype");
1104
1105 if (!strcmp(boardnum, "20070615")) { /* Linksys WRT600N v1/V1.1 */
1106 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "0") && !strcmp(getvar("switch_type"),"BCM5395"))
1107 return &platforms[WRT600NV11];
1108
1109 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "0"))
1110 return &platforms[WRT600N];
1111 }
1112
1113 /*
1114 * Normally, these would go inside the "CFE based - newer hardware" block below; however, during early init, the
1115 * "pmon_ver" variable is not available on the E3000v1 (and probably the WRT610Nv2 also). Until this is figured out,
1116 * these will need to remain here in order for platform detection to work.
1117 */
1118 if (!strcmp(boardnum, "42")) { /* Linksys */
1119 if (!strcmp(boardtype, "0x04cf") && !strcmp(getvar("boot_hw_model"), "E300") && !strcmp(getvar("boot_hw_ver"), "1.0"))
1120 return &platforms[E3000V1];
1121
1122 if (!strcmp(boardtype, "0x04cf") && !strcmp(getvar("boot_hw_model"), "WRT610N") && !strcmp(getvar("boot_hw_ver"), "2.0"))
1123 return &platforms[WRT610NV2];
1124 }
1125
1126 if (startswith(getvar("pmon_ver"), "CFE")) {
1127 /* CFE based - newer hardware */
1128 if (!strcmp(boardnum, "42")) { /* Linksys */
1129 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("boot_hw_model"), "WRT300N") && !strcmp(getvar("boot_hw_ver"), "1.1"))
1130 return &platforms[WRT300NV11];
1131
1132 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "1"))
1133 return &platforms[WRT350N];
1134
1135 if (!strcmp(boardtype, "0x0101") && !strcmp(getvar("boot_ver"), "v3.6"))
1136 return &platforms[WRT54G3G];
1137
1138 if (!strcmp(boardtype, "0x042f") && !strcmp(getvar("model_name"), "WRT54G3GV2-VF"))
1139 return &platforms[WRT54G3GV2_VF];
1140
1141 if (!strcmp(getvar("et1phyaddr"),"5") && !strcmp(getvar("et1mdcport"), "1"))
1142 return &platforms[WRTSL54GS];
1143
1144 if (!strcmp(boardtype, "0x0472")) {
1145 if(!strcmp(getvar("boot_hw_model"), "WRT150N")) {
1146 if(!strcmp(getvar("boot_hw_ver"), "1"))
1147 return &platforms[WRT150NV1];
1148 else if(!strcmp(getvar("boot_hw_ver"), "1.1"))
1149 return &platforms[WRT150NV11];
1150 }
1151 else if(!strcmp(getvar("boot_hw_model"), "WRT160N")) {
1152 if(!strcmp(getvar("boot_hw_ver"), "1.0"))
1153 return &platforms[WRT160NV1];
1154 else if(!strcmp(getvar("boot_hw_ver"), "3.0"))
1155 return &platforms[WRT160NV3];
1156 }
1157 }
1158
1159 /* default to WRT54G */
1160 return &platforms[WRT54G];
1161 }
1162 if (!strcmp(boardnum, "1024") && !strcmp(boardtype, "0x0446"))
1163 return &platforms[WAP54GV2];
1164
1165 if (!strcmp(boardnum, "8") && !strcmp(boardtype, "0x048e"))
1166 return &platforms[WL1600GL];
1167
1168
1169 if (!strcmp(boardnum, "44") || !strcmp(boardnum, "44\r")) {
1170 if (!strcmp(boardtype,"0x0101") || !strcmp(boardtype, "0x0101\r"))
1171 return &platforms[TM2300V2]; /* Dell TrueMobile 2300 v2 */
1172 }
1173
1174 if (!strcmp(boardnum, "45")) { /* ASUS */
1175 if (!strcmp(boardtype,"0x042f"))
1176 return &platforms[WL500GP];
1177 else if (!strcmp(boardtype,"0x0472"))
1178 return &platforms[WL500W];
1179 else if (!strcmp(boardtype,"0x467"))
1180 return &platforms[WL320GE];
1181 else
1182 return &platforms[WL500GD];
1183 }
1184
1185 if (!strcmp(boardnum, "10496"))
1186 return &platforms[USR5461];
1187
1188 if (!strcmp(getvar("boardtype"), "0x0101") && !strcmp(getvar("boardrev"), "0x10")) /* SE505V2 With Modified CFE */
1189 return &platforms[SE505V2];
1190
1191 if (!strcmp(boardtype, "0x048e") && !strcmp(getvar("boardrev"),"0x35") &&
1192 !strcmp(getvar("boardflags"), "0x750")) /* D-Link DIR-320 */
1193 return &platforms[DIR320];
1194
1195 if (!strncmp(boardnum, "TH",2) && !strcmp(boardtype,"0x042f")) {
1196 return &platforms[WDNetCenter];
1197 }
1198
1199 if (!strcmp(boardtype,"0x0472") && !strcmp(getvar("cardbus"), "1")) { /* Netgear WNR834B V1 and V2*/
1200 if (!strcmp(boardnum, "08") || !strcmp(boardnum, "8"))
1201 return &platforms[WNR834BV1];
1202 if (!strcmp(boardnum, "01") || !strcmp(boardnum, "1"))
1203 return &platforms[WNR834BV2];
1204 }
1205
1206 } else { /* PMON based - old stuff */
1207 if ((simple_strtoul(getvar("GemtekPmonVer"), NULL, 0) == 9) &&
1208 (simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 30)) {
1209 return &platforms[WR850GV1];
1210 }
1211 if (startswith(boardtype, "bcm94710dev")) {
1212 if (!strcmp(boardnum, "42"))
1213 return &platforms[WRT54GV1];
1214 if (simple_strtoul(boardnum, NULL, 0) == 2)
1215 return &platforms[WAP54GV1];
1216 }
1217 /* MN-700 has also hardware_version 'WL500-...', so use boardnum */
1218 if (startswith(getvar("hardware_version"), "WL500-")) {
1219 if (!strcmp(getvar("boardnum"), "mn700"))
1220 return &platforms[MN700];
1221 else
1222 return &platforms[WL500G];
1223 }
1224 if (startswith(getvar("hardware_version"), "WL300-")) {
1225 /* Either WL-300g or WL-HDD, do more extensive checks */
1226 if ((simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 0) &&
1227 (simple_strtoul(getvar("et1phyaddr"), NULL, 0) == 1))
1228 return &platforms[WLHDD];
1229 if ((simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 0) &&
1230 (simple_strtoul(getvar("et1phyaddr"), NULL, 0) == 10))
1231 return &platforms[WL300G];
1232 }
1233 /* Sitecom WL-105b */
1234 if (startswith(boardnum, "2") && simple_strtoul(getvar("GemtekPmonVer"), NULL, 0) == 1)
1235 return &platforms[WL105B];
1236
1237 /* unknown asus stuff, probably bcm4702 */
1238 if (startswith(boardnum, "asusX"))
1239 return &platforms[ASUS_4702];
1240
1241 /* bcm4702 based Askey RT210W clones, Including:
1242 * Askey RT210W (duh?)
1243 * Siemens SE505v1
1244 * Belkin F5D7230-4 before version v1444 (MiniPCI slot, not integrated)
1245 */
1246 if (!strcmp(boardtype,"bcm94710r4")
1247 && !strcmp(boardnum ,"100")
1248 && !strcmp(getvar("pmon_ver"),"v1.03.12.bk")
1249 ){
1250 return &platforms[RT210W];
1251 }
1252 }
1253
1254 if (buf || !strcmp(boardnum, "00")) {/* probably buffalo */
1255 if (startswith(boardtype, "bcm94710ap"))
1256 return &platforms[BUFFALO_UNKNOWN_4710];
1257 else
1258 return &platforms[BUFFALO_UNKNOWN];
1259 }
1260
1261 if (startswith(getvar("CFEver"), "MotoWRv2") ||
1262 startswith(getvar("CFEver"), "MotoWRv3") ||
1263 !strcmp(getvar("MOTO_BOARD_TYPE"), "WR_FEM1")) {
1264
1265 return &platforms[WR850GV2V3];
1266 }
1267
1268 if (!strcmp(boardnum, "44") && !strcmp(getvar("boardflags"),"0x0388")) { /* Trendware TEW-411BRP+ */
1269 return &platforms[TEW411BRPP];
1270 }
1271
1272 if (startswith(boardnum, "04FN")) /* SimpleTech SimpleShare */
1273 return &platforms[STI_NAS];
1274
1275 if (!strcmp(boardnum, "10") && !strcmp(getvar("boardrev"), "0x13")) /* D-Link DWL-3150 */
1276 return &platforms[DWL3150];
1277
1278 if (!strcmp(boardnum, "01") && !strcmp(boardtype, "0x048e") && /* Edimax PS1208MFG */
1279 !strcmp(getvar("status_gpio"), "1")) /* gpio based detection */
1280 return &platforms[PS1208MFG];
1281
1282 /* not found */
1283 return NULL;
1284 }
1285
1286 static void register_buttons(struct button_t *b)
1287 {
1288 for (; b->name; b++)
1289 platform.button_mask |= b->gpio;
1290
1291 platform.button_mask &= ~gpiomask;
1292
1293 gpio_outen(platform.button_mask, 0);
1294 gpio_control(platform.button_mask, 0);
1295 platform.button_polarity = gpio_in() & platform.button_mask;
1296 gpio_intpolarity(platform.button_mask, platform.button_polarity);
1297 gpio_setintmask(platform.button_mask, platform.button_mask);
1298
1299 gpio_set_irqenable(1, button_handler);
1300 }
1301
1302 static void unregister_buttons(struct button_t *b)
1303 {
1304 gpio_setintmask(platform.button_mask, 0);
1305
1306 gpio_set_irqenable(0, button_handler);
1307 }
1308
1309
1310 static void add_msg(struct event_t *event, char *msg, int argv)
1311 {
1312 char *s;
1313
1314 if (argv)
1315 return;
1316
1317 s = skb_put(event->skb, strlen(msg) + 1);
1318 strcpy(s, msg);
1319 }
1320
1321 static void hotplug_button(struct work_struct *work)
1322 {
1323 struct event_t *event = container_of(work, struct event_t, wq);
1324 char *s;
1325
1326 event->skb = alloc_skb(2048, GFP_KERNEL);
1327
1328 s = skb_put(event->skb, strlen(event->action) + 2);
1329 sprintf(s, "%s@", event->action);
1330 fill_event(event);
1331
1332 NETLINK_CB(event->skb).dst_group = 1;
1333 broadcast_uevent(event->skb, 0, 1, GFP_KERNEL);
1334
1335 kfree(event);
1336 }
1337
1338
1339 static int fill_event (struct event_t *event)
1340 {
1341 static char buf[128];
1342
1343 add_msg(event, "HOME=/", 0);
1344 add_msg(event, "PATH=/sbin:/bin:/usr/sbin:/usr/bin", 0);
1345 add_msg(event, "SUBSYSTEM=button", 0);
1346 snprintf(buf, 128, "ACTION=%s", event->action);
1347 add_msg(event, buf, 0);
1348 snprintf(buf, 128, "BUTTON=%s", event->name);
1349 add_msg(event, buf, 0);
1350 snprintf(buf, 128, "SEEN=%ld", event->seen);
1351 add_msg(event, buf, 0);
1352 snprintf(buf, 128, "SEQNUM=%llu", uevent_next_seqnum());
1353 add_msg(event, buf, 0);
1354
1355 return 0;
1356 }
1357
1358
1359 static irqreturn_t button_handler(int irq, void *dev_id)
1360 {
1361 struct button_t *b;
1362 u32 in, changed;
1363
1364 in = gpio_in() & platform.button_mask;
1365 gpio_intpolarity(platform.button_mask, in);
1366 changed = platform.button_polarity ^ in;
1367 platform.button_polarity = in;
1368
1369 changed &= ~gpio_outen(0, 0);
1370
1371 for (b = platform.buttons; b->name; b++) {
1372 struct event_t *event;
1373
1374 if (!(b->gpio & changed)) continue;
1375
1376 b->pressed ^= 1;
1377
1378 if ((event = (struct event_t *)kzalloc (sizeof(struct event_t), GFP_ATOMIC))) {
1379 event->seen = (jiffies - b->seen)/HZ;
1380 event->name = b->name;
1381 event->action = b->pressed ? "pressed" : "released";
1382 INIT_WORK(&event->wq, (void *)(void *)hotplug_button);
1383 schedule_work(&event->wq);
1384 }
1385
1386 b->seen = jiffies;
1387 }
1388 return IRQ_HANDLED;
1389 }
1390
1391 static void register_leds(struct led_t *l)
1392 {
1393 struct proc_dir_entry *p;
1394 u32 mask = 0;
1395 u32 oe_mask = 0;
1396 u32 val = 0;
1397
1398 leds = proc_mkdir("led", diag);
1399 if (!leds)
1400 return;
1401
1402 for(; l->name; l++) {
1403 if (l->gpio & gpiomask)
1404 continue;
1405
1406 if (l->gpio & GPIO_TYPE_EXTIF) {
1407 l->state = 0;
1408 set_led_extif(l);
1409 } else {
1410 if (l->polarity != INPUT) oe_mask |= l->gpio;
1411 mask |= l->gpio;
1412 val |= (l->polarity == NORMAL)?0:l->gpio;
1413 }
1414
1415 if (l->polarity == INPUT) continue;
1416
1417 if ((p = create_proc_entry(l->name, S_IRUSR, leds))) {
1418 l->proc.type = PROC_LED;
1419 l->proc.ptr = l;
1420 p->data = (void *) &l->proc;
1421 p->proc_fops = &diag_proc_fops;
1422 }
1423 }
1424
1425 gpio_outen(mask, oe_mask);
1426 gpio_control(mask, 0);
1427 gpio_out(mask, val);
1428 gpio_setintmask(mask, 0);
1429 }
1430
1431 static void unregister_leds(struct led_t *l)
1432 {
1433 for(; l->name; l++)
1434 remove_proc_entry(l->name, leds);
1435
1436 remove_proc_entry("led", diag);
1437 }
1438
1439 static void set_led_extif(struct led_t *led)
1440 {
1441 gpio_set_extif(led->gpio, led->state);
1442 }
1443
1444 static void led_flash(unsigned long dummy) {
1445 struct led_t *l;
1446 u32 mask = 0;
1447 u8 extif_blink = 0;
1448
1449 for (l = platform.leds; l->name; l++) {
1450 if (l->flash) {
1451 if (l->gpio & GPIO_TYPE_EXTIF) {
1452 extif_blink = 1;
1453 l->state = !l->state;
1454 set_led_extif(l);
1455 } else {
1456 mask |= l->gpio;
1457 }
1458 }
1459 }
1460
1461 mask &= ~gpiomask;
1462 if (mask) {
1463 u32 val = ~gpio_in();
1464
1465 gpio_outen(mask, mask);
1466 gpio_control(mask, 0);
1467 gpio_out(mask, val);
1468 }
1469 if (mask || extif_blink) {
1470 mod_timer(&led_timer, jiffies + FLASH_TIME);
1471 }
1472 }
1473
1474 static ssize_t diag_proc_read(struct file *file, char *buf, size_t count, loff_t *ppos)
1475 {
1476 struct proc_dir_entry *dent = PDE(file->f_dentry->d_inode);
1477 char *page;
1478 int len = 0;
1479
1480 if ((page = kmalloc(1024, GFP_KERNEL)) == NULL)
1481 return -ENOBUFS;
1482
1483 if (dent->data != NULL) {
1484 struct prochandler_t *handler = (struct prochandler_t *) dent->data;
1485 switch (handler->type) {
1486 case PROC_LED: {
1487 struct led_t * led = (struct led_t *) handler->ptr;
1488 if (led->flash) {
1489 len = sprintf(page, "f\n");
1490 } else {
1491 if (led->gpio & GPIO_TYPE_EXTIF) {
1492 len = sprintf(page, "%d\n", led->state);
1493 } else {
1494 u32 in = (gpio_in() & led->gpio ? 1 : 0);
1495 u8 p = (led->polarity == NORMAL ? 0 : 1);
1496 len = sprintf(page, "%d\n", ((in ^ p) ? 1 : 0));
1497 }
1498 }
1499 break;
1500 }
1501 case PROC_MODEL:
1502 len = sprintf(page, "%s\n", platform.name);
1503 break;
1504 case PROC_GPIOMASK:
1505 len = sprintf(page, "0x%04x\n", gpiomask);
1506 break;
1507 }
1508 }
1509 len += 1;
1510
1511 if (*ppos < len) {
1512 len = min_t(int, len - *ppos, count);
1513 if (copy_to_user(buf, (page + *ppos), len)) {
1514 kfree(page);
1515 return -EFAULT;
1516 }
1517 *ppos += len;
1518 } else {
1519 len = 0;
1520 }
1521
1522 kfree(page);
1523 return len;
1524 }
1525
1526
1527 static ssize_t diag_proc_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
1528 {
1529 struct proc_dir_entry *dent = PDE(file->f_dentry->d_inode);
1530 char *page;
1531 int ret = -EINVAL;
1532
1533 if ((page = kmalloc(count + 1, GFP_KERNEL)) == NULL)
1534 return -ENOBUFS;
1535
1536 if (copy_from_user(page, buf, count)) {
1537 kfree(page);
1538 return -EINVAL;
1539 }
1540 page[count] = 0;
1541
1542 if (dent->data != NULL) {
1543 struct prochandler_t *handler = (struct prochandler_t *) dent->data;
1544 switch (handler->type) {
1545 case PROC_LED: {
1546 struct led_t *led = (struct led_t *) handler->ptr;
1547 int p = (led->polarity == NORMAL ? 0 : 1);
1548
1549 if (page[0] == 'f') {
1550 led->flash = 1;
1551 led_flash(0);
1552 } else {
1553 led->flash = 0;
1554 if (led->gpio & GPIO_TYPE_EXTIF) {
1555 led->state = p ^ ((page[0] == '1') ? 1 : 0);
1556 set_led_extif(led);
1557 } else {
1558 gpio_outen(led->gpio, led->gpio);
1559 gpio_control(led->gpio, 0);
1560 gpio_out(led->gpio, ((p ^ (page[0] == '1')) ? led->gpio : 0));
1561 }
1562 }
1563 break;
1564 }
1565 case PROC_GPIOMASK:
1566 gpiomask = simple_strtoul(page, NULL, 0);
1567
1568 if (platform.buttons) {
1569 unregister_buttons(platform.buttons);
1570 register_buttons(platform.buttons);
1571 }
1572
1573 if (platform.leds) {
1574 unregister_leds(platform.leds);
1575 register_leds(platform.leds);
1576 }
1577 break;
1578 }
1579 ret = count;
1580 }
1581
1582 kfree(page);
1583 return ret;
1584 }
1585
1586 static int __init diag_init(void)
1587 {
1588 static struct proc_dir_entry *p;
1589 static struct platform_t *detected;
1590
1591 detected = platform_detect();
1592 if (!detected) {
1593 printk(MODULE_NAME ": Router model not detected.\n");
1594 return -ENODEV;
1595 }
1596 memcpy(&platform, detected, sizeof(struct platform_t));
1597
1598 printk(MODULE_NAME ": Detected '%s'\n", platform.name);
1599 if (platform.platform_init != NULL) {
1600 platform.platform_init();
1601 }
1602
1603 if (!(diag = proc_mkdir("diag", NULL))) {
1604 printk(MODULE_NAME ": proc_mkdir on /proc/diag failed\n");
1605 return -EINVAL;
1606 }
1607
1608 if ((p = create_proc_entry("model", S_IRUSR, diag))) {
1609 p->data = (void *) &proc_model;
1610 p->proc_fops = &diag_proc_fops;
1611 }
1612
1613 if ((p = create_proc_entry("gpiomask", S_IRUSR | S_IWUSR, diag))) {
1614 p->data = (void *) &proc_gpiomask;
1615 p->proc_fops = &diag_proc_fops;
1616 }
1617
1618 if (platform.buttons)
1619 register_buttons(platform.buttons);
1620
1621 if (platform.leds)
1622 register_leds(platform.leds);
1623
1624 return 0;
1625 }
1626
1627 static void __exit diag_exit(void)
1628 {
1629 del_timer(&led_timer);
1630
1631 if (platform.buttons)
1632 unregister_buttons(platform.buttons);
1633
1634 if (platform.leds)
1635 unregister_leds(platform.leds);
1636
1637 remove_proc_entry("model", diag);
1638 remove_proc_entry("gpiomask", diag);
1639 remove_proc_entry("diag", NULL);
1640 }
1641
1642 module_init(diag_init);
1643 module_exit(diag_exit);
1644
1645 MODULE_AUTHOR("Mike Baker, Felix Fietkau / OpenWrt.org");
1646 MODULE_LICENSE("GPL");
This page took 0.151822 seconds and 5 git commands to generate.