merge r16434 to 8.09
[openwrt/svn-archive/archive.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 * $Id$
23 */
24 #include <linux/module.h>
25 #include <linux/pci.h>
26 #include <linux/kmod.h>
27 #include <linux/proc_fs.h>
28 #include <linux/timer.h>
29 #include <linux/version.h>
30 #include <asm/uaccess.h>
31
32 #ifndef LINUX_2_4
33 #include <linux/workqueue.h>
34 #include <linux/skbuff.h>
35 #include <linux/netlink.h>
36 #include <net/sock.h>
37 extern struct sock *uevent_sock;
38 extern u64 uevent_next_seqnum(void);
39 #else
40 #include <linux/tqueue.h>
41 #define INIT_WORK INIT_TQUEUE
42 #define schedule_work schedule_task
43 #define work_struct tq_struct
44 #endif
45
46 #include "gpio.h"
47 #include "diag.h"
48 #define getvar(str) (nvram_get(str)?:"")
49
50 static inline int startswith (char *source, char *cmp) { return !strncmp(source,cmp,strlen(cmp)); }
51 static int fill_event(struct event_t *);
52 static unsigned int gpiomask = 0;
53 module_param(gpiomask, int, 0644);
54
55 enum {
56 /* Linksys */
57 WAP54GV1,
58 WAP54GV2,
59 WAP54GV3,
60 WRT54GV1,
61 WRT54G,
62 WRTSL54GS,
63 WRT54G3G,
64 WRT350N,
65 WRT600N,
66 WRT600NV11,
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
83 /* Buffalo */
84 WBR2_G54,
85 WHR_G54S,
86 WHR_HP_G54,
87 WHR_G125,
88 WHR2_A54G54,
89 WLA2_G54L,
90 WZR_G300N,
91 WZR_RS_G54,
92 WZR_RS_G54HP,
93 BUFFALO_UNKNOWN,
94 BUFFALO_UNKNOWN_4710,
95
96 /* Siemens */
97 SE505V1,
98 SE505V2,
99
100 /* US Robotics */
101 USR5461,
102
103 /* Dell */
104 TM2300,
105 TM2300V2,
106
107 /* Motorola */
108 WE800G,
109 WR850GV1,
110 WR850GV2V3,
111 WR850GP,
112
113 /* Belkin */
114 BELKIN_UNKNOWN,
115
116 /* Netgear */
117 WGT634U,
118
119 /* Trendware */
120 TEW411BRPP,
121
122 /* SimpleTech */
123 STI_NAS,
124
125 /* D-Link */
126 DIR130,
127 DIR330,
128 DWL3150,
129
130 /* Sitecom */
131 WL105B,
132 };
133
134 static void __init bcm4780_init(void) {
135 int pin = 1 << 3;
136
137 /* Enables GPIO 3 that controls HDD and led power on ASUS WL-700gE */
138 printk(MODULE_NAME ": Spinning up HDD and enabling leds\n");
139 gpio_outen(pin, pin);
140 gpio_control(pin, 0);
141 gpio_out(pin, pin);
142
143 /* Wait 5s, so the HDD can spin up */
144 set_current_state(TASK_INTERRUPTIBLE);
145 schedule_timeout(HZ * 5);
146 }
147
148 static void __init bcm57xx_init(void) {
149 int pin = 1 << 2;
150
151 #ifndef LINUX_2_4
152 /* FIXME: switch comes up, but port mappings/vlans not right */
153 gpio_outen(pin, pin);
154 gpio_control(pin, 0);
155 gpio_out(pin, pin);
156 #endif
157 }
158
159 static struct platform_t __initdata platforms[] = {
160 /* Linksys */
161 [WAP54GV1] = {
162 .name = "Linksys WAP54G V1",
163 .buttons = {
164 { .name = "reset", .gpio = 1 << 0 },
165 },
166 .leds = {
167 { .name = "diag", .gpio = 1 << 3 },
168 { .name = "wlan", .gpio = 1 << 4 },
169 },
170 },
171 [WAP54GV2] = {
172 .name = "Linksys WAP54G V2",
173 .buttons = {
174 { .name = "reset", .gpio = 1 << 0 },
175 },
176 .leds = {
177 { .name = "wlan", .gpio = 1 << 5, .polarity = REVERSE },
178 /* GPIO 6 is b44 (eth0, LAN) PHY power */
179 },
180 },
181 [WAP54GV3] = {
182 .name = "Linksys WAP54G V3",
183 .buttons = {
184 /* FIXME: verify this */
185 { .name = "reset", .gpio = 1 << 7 },
186 { .name = "ses", .gpio = 1 << 0 },
187 },
188 .leds = {
189 /* FIXME: diag? */
190 { .name = "ses", .gpio = 1 << 1 },
191 },
192 },
193 [WRT54GV1] = {
194 .name = "Linksys WRT54G V1.x",
195 .buttons = {
196 { .name = "reset", .gpio = 1 << 6 },
197 },
198 .leds = {
199 { .name = "diag", .gpio = 0x13 | GPIO_TYPE_EXTIF, .polarity = NORMAL },
200 { .name = "dmz", .gpio = 0x12 | GPIO_TYPE_EXTIF, .polarity = NORMAL },
201 },
202 },
203 [WRT54G] = {
204 .name = "Linksys WRT54G/GS/GL",
205 .buttons = {
206 { .name = "reset", .gpio = 1 << 6 },
207 { .name = "ses", .gpio = 1 << 4 },
208 },
209 .leds = {
210 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
211 { .name = "dmz", .gpio = 1 << 7, .polarity = REVERSE },
212 { .name = "ses_white", .gpio = 1 << 2, .polarity = REVERSE },
213 { .name = "ses_orange", .gpio = 1 << 3, .polarity = REVERSE },
214 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
215 },
216 },
217 [WRTSL54GS] = {
218 .name = "Linksys WRTSL54GS",
219 .buttons = {
220 { .name = "reset", .gpio = 1 << 6 },
221 { .name = "ses", .gpio = 1 << 4 },
222 },
223 .leds = {
224 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
225 { .name = "dmz", .gpio = 1 << 0, .polarity = REVERSE },
226 { .name = "ses_white", .gpio = 1 << 5, .polarity = REVERSE },
227 { .name = "ses_orange", .gpio = 1 << 7, .polarity = REVERSE },
228 },
229 },
230 [WRT54G3G] = {
231 .name = "Linksys WRT54G3G",
232 .buttons = {
233 { .name = "reset", .gpio = 1 << 6 },
234 { .name = "3g", .gpio = 1 << 4 },
235 },
236 .leds = {
237 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
238 { .name = "dmz", .gpio = 1 << 7, .polarity = REVERSE },
239 { .name = "3g_green", .gpio = 1 << 2, .polarity = NORMAL },
240 { .name = "3g_blue", .gpio = 1 << 3, .polarity = NORMAL },
241 { .name = "3g_blink", .gpio = 1 << 5, .polarity = NORMAL },
242 },
243 },
244 [WRT350N] = {
245 .name = "Linksys WRT350N",
246 .buttons = {
247 { .name = "reset", .gpio = 1 << 6 },
248 { .name = "ses", .gpio = 1 << 8 },
249 },
250 .leds = {
251 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
252 { .name = "ses_amber", .gpio = 1 << 3, .polarity = REVERSE },
253 { .name = "ses_green", .gpio = 1 << 9, .polarity = REVERSE },
254 { .name = "usb_blink", .gpio = 1 << 10, .polarity = REVERSE },
255 { .name = "usb", .gpio = 1 << 11, .polarity = REVERSE },
256 },
257 .platform_init = bcm57xx_init,
258 },
259 [WRT600N] = {
260 .name = "Linksys WRT600N",
261 .buttons = {
262 { .name = "reset", .gpio = 1 << 6 },
263 { .name = "ses", .gpio = 1 << 7 },
264 },
265 .leds = {
266 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE }, // Power LED
267 { .name = "usb", .gpio = 1 << 3, .polarity = REVERSE }, // USB LED
268 { .name = "wl0_ses_amber", .gpio = 1 << 8, .polarity = REVERSE }, // 2.4Ghz LED Amber
269 { .name = "wl0_ses_green", .gpio = 1 << 9, .polarity = REVERSE }, // 2.4Ghz LED Green
270 { .name = "wl1_ses_amber", .gpio = 1 << 10, .polarity = REVERSE }, // 5.6Ghz LED Amber
271 { .name = "wl1_ses_green", .gpio = 1 << 11, .polarity = REVERSE }, // 5.6Ghz LED Green
272 },
273 .platform_init = bcm57xx_init,
274 },
275 [WRT600NV11] = {
276 .name = "Linksys WRT600N V1.1",
277 .buttons = {
278 { .name = "reset", .gpio = 1 << 6 },
279 { .name = "ses", .gpio = 1 << 7 },
280 },
281 .leds = {
282 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE }, // Power LED
283 { .name = "usb", .gpio = 1 << 3, .polarity = REVERSE }, // USB LED
284 { .name = "wl0_ses_amber", .gpio = 1 << 8, .polarity = REVERSE }, // 2.4Ghz LED Amber
285 { .name = "wl0_ses_green", .gpio = 1 << 9, .polarity = REVERSE }, // 2.4Ghz LED Green
286 { .name = "wl1_ses_amber", .gpio = 1 << 10, .polarity = REVERSE }, // 5.6Ghz LED Amber
287 { .name = "wl1_ses_green", .gpio = 1 << 11, .polarity = REVERSE }, // 5.6Ghz LED Green
288 },
289 .platform_init = bcm57xx_init,
290 },
291 /* Asus */
292 [WLHDD] = {
293 .name = "ASUS WL-HDD",
294 .buttons = {
295 { .name = "reset", .gpio = 1 << 6 },
296 },
297 .leds = {
298 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
299 { .name = "usb", .gpio = 1 << 2, .polarity = NORMAL },
300 },
301 },
302 [WL300G] = {
303 .name = "ASUS WL-300g",
304 .buttons = {
305 { .name = "reset", .gpio = 1 << 6 },
306 },
307 .leds = {
308 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
309 },
310 },
311 [WL320GE] = {
312 .name = "ASUS WL-320gE/WL-320gP",
313 .buttons = {
314 { .name = "reset", .gpio = 1 << 6 },
315 },
316 .leds = {
317 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
318 { .name = "power", .gpio = 1 << 2, .polarity = REVERSE },
319 { .name = "link", .gpio = 1 << 11, .polarity = REVERSE },
320 },
321 },
322 [WL330GE] = {
323 .name = "ASUS WL-330gE",
324 .buttons = {
325 { .name = "reset", .gpio = 1 << 2 },
326 },
327 .leds = {
328 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
329 },
330 },
331 [WL500G] = {
332 .name = "ASUS WL-500g",
333 .buttons = {
334 { .name = "reset", .gpio = 1 << 6 },
335 },
336 .leds = {
337 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
338 },
339 },
340 [WL500GD] = {
341 .name = "ASUS WL-500g Deluxe",
342 .buttons = {
343 { .name = "reset", .gpio = 1 << 6 },
344 },
345 .leds = {
346 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
347 },
348 },
349 [WL500GP] = {
350 .name = "ASUS WL-500g Premium",
351 .buttons = {
352 { .name = "reset", .gpio = 1 << 0 },
353 { .name = "ses", .gpio = 1 << 4 },
354 },
355 .leds = {
356 { .name = "power", .gpio = 1 << 1, .polarity = REVERSE },
357 },
358 },
359 [WL500GPV2] = {
360 .name = "ASUS WL-500g Premium V2",
361 .buttons = {
362 { .name = "reset", .gpio = 1 << 2 },
363 { .name = "ses", .gpio = 1 << 3 },
364 },
365 .leds = {
366 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
367 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
368 },
369 },
370 [WL500W] = {
371 .name = "ASUS WL-500W",
372 .buttons = {
373 { .name = "reset", .gpio = 1 << 6 },
374 { .name = "ses", .gpio = 1 << 7 },
375 },
376 .leds = {
377 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
378 },
379 },
380 [WL520GC] = {
381 .name = "ASUS WL-520GC",
382 .buttons = {
383 { .name = "reset", .gpio = 1 << 2 },
384 { .name = "ses", .gpio = 1 << 3 },
385 },
386 .leds = {
387 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
388 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
389 },
390 },
391 [WL520GU] = {
392 .name = "ASUS WL-520gU",
393 .buttons = {
394 { .name = "reset", .gpio = 1 << 2 },
395 { .name = "ses", .gpio = 1 << 3 },
396 },
397 .leds = {
398 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
399 { .name = "wlan", .gpio = 1 << 1, .polarity = REVERSE },
400 },
401 },
402 [ASUS_4702] = {
403 .name = "ASUS (unknown, BCM4702)",
404 .buttons = {
405 { .name = "reset", .gpio = 1 << 6 },
406 },
407 .leds = {
408 { .name = "power", .gpio = 1 << 0, .polarity = REVERSE },
409 },
410 },
411 [WL700GE] = {
412 .name = "ASUS WL-700gE",
413 .buttons = {
414 { .name = "reset", .gpio = 1 << 7 }, // on back, hardwired, always resets device regardless OS state
415 { .name = "ses", .gpio = 1 << 4 }, // on back, actual name ezsetup
416 { .name = "power", .gpio = 1 << 0 }, // on front
417 { .name = "copy", .gpio = 1 << 6 }, // on front
418 },
419 .leds = {
420 #if 0
421 // GPIO that controls power led also enables/disables some essential functions
422 // - power to HDD
423 // - switch leds
424 { .name = "power", .gpio = 1 << 3, .polarity = NORMAL }, // actual name power
425 #endif
426 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE }, // actual name ready
427 },
428 .platform_init = bcm4780_init,
429 },
430 /* Buffalo */
431 [WHR_G54S] = {
432 .name = "Buffalo WHR-G54S",
433 .buttons = {
434 { .name = "reset", .gpio = 1 << 4 },
435 { .name = "bridge", .gpio = 1 << 5 },
436 { .name = "ses", .gpio = 1 << 0 },
437 },
438 .leds = {
439 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
440 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
441 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
442 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
443 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
444 },
445 },
446 [WBR2_G54] = {
447 .name = "Buffalo WBR2-G54",
448 /* FIXME: verify */
449 .buttons = {
450 { .name = "reset", .gpio = 1 << 7 },
451 },
452 .leds = {
453 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
454 },
455 },
456 [WHR_HP_G54] = {
457 .name = "Buffalo WHR-HP-G54",
458 .buttons = {
459 { .name = "reset", .gpio = 1 << 4 },
460 { .name = "bridge", .gpio = 1 << 5 },
461 { .name = "ses", .gpio = 1 << 0 },
462 },
463 .leds = {
464 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
465 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
466 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
467 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
468 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
469 },
470 },
471 [WHR_G125] = {
472 .name = "Buffalo WHR-G125",
473 .buttons = {
474 { .name = "reset", .gpio = 1 << 4 },
475 { .name = "bridge", .gpio = 1 << 5 },
476 { .name = "ses", .gpio = 1 << 0 },
477 },
478 .leds = {
479 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
480 { .name = "internal", .gpio = 1 << 3, .polarity = REVERSE },
481 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
482 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
483 { .name = "wlan", .gpio = 1 << 2, .polarity = REVERSE },
484 },
485 },
486 [WHR2_A54G54] = {
487 .name = "Buffalo WHR2-A54G54",
488 .buttons = {
489 { .name = "reset", .gpio = 1 << 4 },
490 },
491 .leds = {
492 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
493 },
494 },
495 [WLA2_G54L] = {
496 .name = "Buffalo WLA2-G54L",
497 /* FIXME: verify */
498 .buttons = {
499 { .name = "reset", .gpio = 1 << 7 },
500 },
501 .leds = {
502 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
503 },
504 },
505 [WZR_G300N] = {
506 .name = "Buffalo WZR-G300N",
507 .buttons = {
508 { .name = "reset", .gpio = 1 << 4 },
509 },
510 .leds = {
511 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
512 { .name = "bridge", .gpio = 1 << 1, .polarity = REVERSE },
513 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
514 },
515 },
516 [WZR_RS_G54] = {
517 .name = "Buffalo WZR-RS-G54",
518 .buttons = {
519 { .name = "ses", .gpio = 1 << 0 },
520 { .name = "reset", .gpio = 1 << 4 },
521 },
522 .leds = {
523 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
524 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
525 { .name = "vpn", .gpio = 1 << 1, .polarity = REVERSE },
526 },
527 },
528 [WZR_RS_G54HP] = {
529 .name = "Buffalo WZR-RS-G54HP",
530 .buttons = {
531 { .name = "ses", .gpio = 1 << 0 },
532 { .name = "reset", .gpio = 1 << 4 },
533 },
534 .leds = {
535 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
536 { .name = "ses", .gpio = 1 << 6, .polarity = REVERSE },
537 { .name = "vpn", .gpio = 1 << 1, .polarity = REVERSE },
538 },
539 },
540 [BUFFALO_UNKNOWN] = {
541 .name = "Buffalo (unknown)",
542 .buttons = {
543 { .name = "reset", .gpio = 1 << 7 },
544 },
545 .leds = {
546 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
547 },
548 },
549 [BUFFALO_UNKNOWN_4710] = {
550 .name = "Buffalo (unknown, BCM4710)",
551 .buttons = {
552 { .name = "reset", .gpio = 1 << 4 },
553 },
554 .leds = {
555 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE },
556 },
557 },
558 /* Siemens */
559 [SE505V1] = {
560 .name = "Siemens SE505 V1",
561 .buttons = {
562 /* No usable buttons */
563 },
564 .leds = {
565 // { .name = "power", .gpio = 1 << 0 .polarity = REVERSE }, // Usable when retrofitting D26 (?)
566 { .name = "dmz", .gpio = 1 << 4, .polarity = REVERSE }, // actual name WWW
567 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
568 },
569 },
570 [SE505V2] = {
571 .name = "Siemens SE505 V2",
572 .buttons = {
573 /* No usable buttons */
574 },
575 .leds = {
576 { .name = "power", .gpio = 1 << 5, .polarity = REVERSE },
577 { .name = "dmz", .gpio = 1 << 0, .polarity = REVERSE }, // actual name WWW
578 { .name = "wlan", .gpio = 1 << 3, .polarity = REVERSE },
579 },
580 },
581 /* US Robotics */
582 [USR5461] = {
583 .name = "U.S. Robotics USR5461",
584 .buttons = {
585 /* No usable buttons */
586 },
587 .leds = {
588 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
589 { .name = "printer", .gpio = 1 << 1, .polarity = REVERSE },
590 },
591 },
592 /* Dell */
593 [TM2300] = {
594 .name = "Dell TrueMobile 2300",
595 .buttons = {
596 { .name = "reset", .gpio = 1 << 0 },
597 },
598 .leds = {
599 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
600 { .name = "power", .gpio = 1 << 7, .polarity = REVERSE },
601 },
602 },
603 [TM2300V2] = {
604 .name = "Dell TrueMobile 2300 v2",
605 .buttons = {
606 { .name = "reset", .gpio = 1 << 0 },
607 },
608 .leds = {
609 { .name = "wlan", .gpio = 1 << 6, .polarity = REVERSE },
610 { .name = "power", .gpio = 1 << 7, .polarity = REVERSE },
611 },
612 },
613 /* Motorola */
614 [WE800G] = {
615 .name = "Motorola WE800G",
616 .buttons = {
617 { .name = "reset", .gpio = 1 << 0 },
618 },
619 .leds = {
620 { .name = "power", .gpio = 1 << 4, .polarity = NORMAL },
621 { .name = "diag", .gpio = 1 << 2, .polarity = REVERSE },
622 { .name = "wlan_amber", .gpio = 1 << 1, .polarity = NORMAL },
623 },
624 },
625 [WR850GV1] = {
626 .name = "Motorola WR850G V1",
627 .buttons = {
628 { .name = "reset", .gpio = 1 << 0 },
629 },
630 .leds = {
631 { .name = "power", .gpio = 1 << 4, .polarity = NORMAL },
632 { .name = "diag", .gpio = 1 << 3, .polarity = REVERSE },
633 { .name = "dmz", .gpio = 1 << 6, .polarity = NORMAL },
634 { .name = "wlan_red", .gpio = 1 << 5, .polarity = REVERSE },
635 { .name = "wlan_green", .gpio = 1 << 7, .polarity = REVERSE },
636 },
637 },
638 [WR850GV2V3] = {
639 .name = "Motorola WR850G V2/V3",
640 .buttons = {
641 { .name = "reset", .gpio = 1 << 5 },
642 },
643 .leds = {
644 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
645 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
646 { .name = "wan", .gpio = 1 << 6, .polarity = INPUT },
647 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
648 },
649 },
650 [WR850GP] = {
651 .name = "Motorola WR850GP",
652 .buttons = {
653 { .name = "reset", .gpio = 1 << 5 },
654 },
655 .leds = {
656 { .name = "power", .gpio = 1 << 1, .polarity = NORMAL },
657 { .name = "wlan", .gpio = 1 << 0, .polarity = REVERSE },
658 { .name = "dmz", .gpio = 1 << 6, .polarity = REVERSE },
659 { .name = "diag", .gpio = 1 << 7, .polarity = REVERSE },
660 },
661 },
662
663 /* Belkin */
664 [BELKIN_UNKNOWN] = {
665 .name = "Belkin (unknown)",
666 /* FIXME: verify & add detection */
667 .buttons = {
668 { .name = "reset", .gpio = 1 << 7 },
669 },
670 .leds = {
671 { .name = "power", .gpio = 1 << 5, .polarity = NORMAL },
672 { .name = "wlan", .gpio = 1 << 3, .polarity = NORMAL },
673 { .name = "connected", .gpio = 1 << 0, .polarity = NORMAL },
674 },
675 },
676 /* Netgear */
677 [WGT634U] = {
678 .name = "Netgear WGT634U",
679 .buttons = {
680 { .name = "reset", .gpio = 1 << 2 },
681 },
682 .leds = {
683 { .name = "power", .gpio = 1 << 3, .polarity = NORMAL },
684 },
685 },
686 /* Trendware */
687 [TEW411BRPP] = {
688 .name = "Trendware TEW411BRP+",
689 .buttons = {
690 { /* No usable buttons */ },
691 },
692 .leds = {
693 { .name = "power", .gpio = 1 << 7, .polarity = NORMAL },
694 { .name = "wlan", .gpio = 1 << 1, .polarity = NORMAL },
695 { .name = "bridge", .gpio = 1 << 6, .polarity = NORMAL },
696 },
697 },
698 /* SimpleTech */
699 [STI_NAS] = {
700 .name = "SimpleTech SimpleShare NAS",
701 .buttons = {
702 { .name = "reset", .gpio = 1 << 7 }, // on back, hardwired, always resets device regardless OS state
703 { .name = "power", .gpio = 1 << 0 }, // on back
704 },
705 .leds = {
706 { .name = "diag", .gpio = 1 << 1, .polarity = REVERSE }, // actual name ready
707 },
708 .platform_init = bcm4780_init,
709 },
710 /* D-Link */
711 [DIR130] = {
712 .name = "D-Link DIR-130",
713 .buttons = {
714 { .name = "reset", .gpio = 1 << 3},
715 { .name = "reserved", .gpio = 1 << 7},
716 },
717 .leds = {
718 { .name = "diag", .gpio = 1 << 0},
719 { .name = "blue", .gpio = 1 << 6},
720 },
721 },
722 [DIR330] = {
723 .name = "D-Link DIR-330",
724 .buttons = {
725 { .name = "reset", .gpio = 1 << 3},
726 { .name = "reserved", .gpio = 1 << 7},
727 },
728 .leds = {
729 { .name = "diag", .gpio = 1 << 0},
730 { .name = "usb", .gpio = 1 << 4},
731 { .name = "blue", .gpio = 1 << 6},
732 },
733 },
734 [DWL3150] = {
735 .name = "D-Link DWL-3150",
736 .buttons = {
737 { .name = "reset", .gpio = 1 << 7},
738 },
739 .leds = {
740 { .name = "diag", .gpio = 1 << 2},
741 { .name = "status", .gpio = 1 << 1},
742 },
743 },
744 /* Double check */
745 [WL105B] = {
746 .name = "Sitecom WL-105b",
747 .buttons = {
748 { .name = "reset", .gpio = 1 << 10},
749 },
750 .leds = {
751 { .name = "wlan", .gpio = 1 << 4},
752 { .name = "power", .gpio = 1 << 3},
753 },
754 },
755 };
756
757 static struct platform_t __init *platform_detect(void)
758 {
759 char *boardnum, *boardtype, *buf;
760
761 if (strcmp(getvar("nvram_type"), "cfe") == 0)
762 return &platforms[WGT634U];
763
764 /* Look for a model identifier */
765
766 /* Based on "model_name" */
767 if ((buf = nvram_get("model_name"))) {
768 if (!strcmp(buf, "DIR-130"))
769 return &platforms[DIR130];
770 if (!strcmp(buf, "DIR-330"))
771 return &platforms[DIR330];
772 }
773
774 /* Based on "model_no" */
775 if ((buf = nvram_get("model_no"))) {
776 if (startswith(buf,"WL700")) /* WL700* */
777 return &platforms[WL700GE];
778 }
779
780 /* Based on "hardware_version" */
781 if ((buf = nvram_get("hardware_version"))) {
782 if (startswith(buf,"WL500GPV2-")) /* WL500GPV2-* */
783 return &platforms[WL500GPV2];
784 if (startswith(buf,"WL520GC-")) /* WL520GU-* */
785 return &platforms[WL520GC];
786 if (startswith(buf,"WL520GU-")) /* WL520GU-* */
787 return &platforms[WL520GU];
788 if (startswith(buf,"WL330GE-")) /* WL330GE-* */
789 return &platforms[WL330GE];
790 }
791
792 /* Based on "ModelId" */
793 if ((buf = nvram_get("ModelId"))) {
794 if (!strcmp(buf, "WR850GP"))
795 return &platforms[WR850GP];
796 if (!strcmp(buf, "WX-5565") && !strcmp(getvar("boardtype"),"bcm94710ap"))
797 return &platforms[TM2300]; /* Dell TrueMobile 2300 */
798 if (startswith(buf,"WE800G")) /* WE800G* */
799 return &platforms[WE800G];
800 }
801
802 /* Buffalo */
803 if ((buf = (nvram_get("melco_id") ?: nvram_get("buffalo_id")))) {
804 /* Buffalo hardware, check id for specific hardware matches */
805 if (!strcmp(buf, "29bb0332"))
806 return &platforms[WBR2_G54];
807 if (!strcmp(buf, "29129"))
808 return &platforms[WLA2_G54L];
809 if (!strcmp(buf, "30189"))
810 return &platforms[WHR_HP_G54];
811 if (!strcmp(buf, "32093"))
812 return &platforms[WHR_G125];
813 if (!strcmp(buf, "30182"))
814 return &platforms[WHR_G54S];
815 if (!strcmp(buf, "290441dd"))
816 return &platforms[WHR2_A54G54];
817 if (!strcmp(buf, "31120"))
818 return &platforms[WZR_G300N];
819 if (!strcmp(buf, "30083"))
820 return &platforms[WZR_RS_G54];
821 if (!strcmp(buf, "30103"))
822 return &platforms[WZR_RS_G54HP];
823 }
824
825 /* no easy model number, attempt to guess */
826 boardnum = getvar("boardnum");
827 boardtype = getvar("boardtype");
828
829 if (!strcmp(boardnum, "20070615")) { /* Linksys WRT600N v1/V1.1 */
830 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "0") && !strcmp(getvar("switch_type"),"BCM5395"))
831 return &platforms[WRT600NV11];
832
833 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "0"))
834 return &platforms[WRT600N];
835 }
836
837 if (startswith(getvar("pmon_ver"), "CFE")) {
838 /* CFE based - newer hardware */
839 if (!strcmp(boardnum, "42")) { /* Linksys */
840 if (!strcmp(boardtype, "0x478") && !strcmp(getvar("cardbus"), "1"))
841 return &platforms[WRT350N];
842
843 if (!strcmp(boardtype, "0x0101") && !strcmp(getvar("boot_ver"), "v3.6"))
844 return &platforms[WRT54G3G];
845
846 if (!strcmp(getvar("et1phyaddr"),"5") && !strcmp(getvar("et1mdcport"), "1"))
847 return &platforms[WRTSL54GS];
848
849 /* default to WRT54G */
850 return &platforms[WRT54G];
851 }
852 if (!strcmp(boardnum, "1024") && !strcmp(boardtype, "0x0446"))
853 return &platforms[WAP54GV2];
854
855 if (!strcmp(boardnum, "44") || !strcmp(boardnum, "44\r")) {
856 if (!strcmp(boardtype,"0x0101") || !strcmp(boardtype, "0x0101\r"))
857 return &platforms[TM2300V2]; /* Dell TrueMobile 2300 v2 */
858 }
859
860 if (!strcmp(boardnum, "45")) { /* ASUS */
861 if (!strcmp(boardtype,"0x042f"))
862 return &platforms[WL500GP];
863 else if (!strcmp(boardtype,"0x0472"))
864 return &platforms[WL500W];
865 else if (!strcmp(boardtype,"0x467"))
866 return &platforms[WL320GE];
867 else
868 return &platforms[WL500GD];
869 }
870
871 if (!strcmp(boardnum, "10496"))
872 return &platforms[USR5461];
873
874 if (!strcmp(getvar("boardtype"), "0x0101") && !strcmp(getvar("boardrev"), "0x10")) /* SE505V2 With Modified CFE */
875 return &platforms[SE505V2];
876
877 } else { /* PMON based - old stuff */
878 if ((simple_strtoul(getvar("GemtekPmonVer"), NULL, 0) == 9) &&
879 (simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 30)) {
880 return &platforms[WR850GV1];
881 }
882 if (startswith(boardtype, "bcm94710dev")) {
883 if (!strcmp(boardnum, "42"))
884 return &platforms[WRT54GV1];
885 if (simple_strtoul(boardnum, NULL, 0) == 2)
886 return &platforms[WAP54GV1];
887 }
888 if (startswith(getvar("hardware_version"), "WL500-"))
889 return &platforms[WL500G];
890 if (startswith(getvar("hardware_version"), "WL300-")) {
891 /* Either WL-300g or WL-HDD, do more extensive checks */
892 if ((simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 0) &&
893 (simple_strtoul(getvar("et1phyaddr"), NULL, 0) == 1))
894 return &platforms[WLHDD];
895 if ((simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 0) &&
896 (simple_strtoul(getvar("et1phyaddr"), NULL, 0) == 10))
897 return &platforms[WL300G];
898 }
899 /* Sitecom WL-105b */
900 if (startswith(boardnum, "2") && simple_strtoul(getvar("GemtekPmonVer"), NULL, 0) == 1)
901 return &platforms[WL105B];
902
903 /* unknown asus stuff, probably bcm4702 */
904 if (startswith(boardnum, "asusX"))
905 return &platforms[ASUS_4702];
906 }
907
908 if (buf || !strcmp(boardnum, "00")) {/* probably buffalo */
909 if (startswith(boardtype, "bcm94710ap"))
910 return &platforms[BUFFALO_UNKNOWN_4710];
911 else
912 return &platforms[BUFFALO_UNKNOWN];
913 }
914
915 if (startswith(getvar("CFEver"), "MotoWRv2") ||
916 startswith(getvar("CFEver"), "MotoWRv3") ||
917 !strcmp(getvar("MOTO_BOARD_TYPE"), "WR_FEM1")) {
918
919 return &platforms[WR850GV2V3];
920 }
921
922 if (!strcmp(boardnum, "44") && !strcmp(getvar("boardflags"),"0x0388")) { /* Trendware TEW-411BRP+ */
923 return &platforms[TEW411BRPP];
924 }
925
926 if (startswith(boardnum, "04FN52")) /* SimpleTech SimpleShare */
927 return &platforms[STI_NAS];
928
929 if (!strcmp(getvar("boardnum"), "10") && !strcmp(getvar("boardrev"), "0x13")) /* D-Link DWL-3150 */
930 return &platforms[DWL3150];
931
932 /* not found */
933 return NULL;
934 }
935
936 static void register_buttons(struct button_t *b)
937 {
938 for (; b->name; b++)
939 platform.button_mask |= b->gpio;
940
941 platform.button_mask &= ~gpiomask;
942
943 gpio_outen(platform.button_mask, 0);
944 gpio_control(platform.button_mask, 0);
945 platform.button_polarity = gpio_in() & platform.button_mask;
946 gpio_intpolarity(platform.button_mask, platform.button_polarity);
947 gpio_setintmask(platform.button_mask, platform.button_mask);
948
949 gpio_set_irqenable(1, button_handler);
950 }
951
952 static void unregister_buttons(struct button_t *b)
953 {
954 gpio_setintmask(platform.button_mask, 0);
955
956 gpio_set_irqenable(0, button_handler);
957 }
958
959
960 #ifndef LINUX_2_4
961 static void add_msg(struct event_t *event, char *msg, int argv)
962 {
963 char *s;
964
965 if (argv)
966 return;
967
968 s = skb_put(event->skb, strlen(msg) + 1);
969 strcpy(s, msg);
970 }
971
972 static void hotplug_button(struct work_struct *work)
973 {
974 struct event_t *event = container_of(work, struct event_t, wq);
975 char *s;
976
977 if (!uevent_sock)
978 return;
979
980 event->skb = alloc_skb(2048, GFP_KERNEL);
981
982 s = skb_put(event->skb, strlen(event->action) + 2);
983 sprintf(s, "%s@", event->action);
984 fill_event(event);
985
986 NETLINK_CB(event->skb).dst_group = 1;
987 netlink_broadcast(uevent_sock, event->skb, 0, 1, GFP_KERNEL);
988
989 kfree(event);
990 }
991
992 #else /* !LINUX_2_4 */
993 static inline char *kzalloc(unsigned int size, unsigned int gfp)
994 {
995 char *p;
996
997 p = kmalloc(size, gfp);
998 if (p == NULL)
999 return NULL;
1000
1001 memset(p, 0, size);
1002
1003 return p;
1004 }
1005
1006 static void add_msg(struct event_t *event, char *msg, int argv)
1007 {
1008 if (argv)
1009 event->argv[event->anr++] = event->scratch;
1010 else
1011 event->envp[event->enr++] = event->scratch;
1012
1013 event->scratch += sprintf(event->scratch, "%s", msg) + 1;
1014 }
1015
1016 static void hotplug_button(struct event_t *event)
1017 {
1018 char *scratch = kzalloc(256, GFP_KERNEL);
1019 event->scratch = scratch;
1020
1021 add_msg(event, hotplug_path, 1);
1022 add_msg(event, "button", 1);
1023 fill_event(event);
1024 call_usermodehelper (event->argv[0], event->argv, event->envp);
1025 kfree(scratch);
1026 kfree(event);
1027 }
1028 #endif /* !LINUX_2_4 */
1029
1030 static int fill_event (struct event_t *event)
1031 {
1032 static char buf[128];
1033
1034 add_msg(event, "HOME=/", 0);
1035 add_msg(event, "PATH=/sbin:/bin:/usr/sbin:/usr/bin", 0);
1036 add_msg(event, "SUBSYSTEM=button", 0);
1037 snprintf(buf, 128, "ACTION=%s", event->action);
1038 add_msg(event, buf, 0);
1039 snprintf(buf, 128, "BUTTON=%s", event->name);
1040 add_msg(event, buf, 0);
1041 snprintf(buf, 128, "SEEN=%ld", event->seen);
1042 add_msg(event, buf, 0);
1043 #ifndef LINUX_2_4
1044 snprintf(buf, 128, "SEQNUM=%llu", uevent_next_seqnum());
1045 add_msg(event, buf, 0);
1046 #endif
1047
1048 return 0;
1049 }
1050
1051
1052 #ifndef LINUX_2_4
1053 static irqreturn_t button_handler(int irq, void *dev_id)
1054 #else
1055 static irqreturn_t button_handler(int irq, void *dev_id, struct pt_regs *regs)
1056 #endif
1057 {
1058 struct button_t *b;
1059 u32 in, changed;
1060
1061 in = gpio_in() & platform.button_mask;
1062 gpio_intpolarity(platform.button_mask, in);
1063 changed = platform.button_polarity ^ in;
1064 platform.button_polarity = in;
1065
1066 changed &= ~gpio_outen(0, 0);
1067
1068 for (b = platform.buttons; b->name; b++) {
1069 struct event_t *event;
1070
1071 if (!(b->gpio & changed)) continue;
1072
1073 b->pressed ^= 1;
1074
1075 if ((event = (struct event_t *)kzalloc (sizeof(struct event_t), GFP_ATOMIC))) {
1076 event->seen = (jiffies - b->seen)/HZ;
1077 event->name = b->name;
1078 event->action = b->pressed ? "pressed" : "released";
1079 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
1080 INIT_WORK(&event->wq, (void *)(void *)hotplug_button);
1081 #else
1082 INIT_WORK(&event->wq, (void *)(void *)hotplug_button, (void *)event);
1083 #endif
1084 schedule_work(&event->wq);
1085 }
1086
1087 b->seen = jiffies;
1088 }
1089 return IRQ_HANDLED;
1090 }
1091
1092 static void register_leds(struct led_t *l)
1093 {
1094 struct proc_dir_entry *p;
1095 u32 mask = 0;
1096 u32 oe_mask = 0;
1097 u32 val = 0;
1098
1099 leds = proc_mkdir("led", diag);
1100 if (!leds)
1101 return;
1102
1103 for(; l->name; l++) {
1104 if (l->gpio & gpiomask)
1105 continue;
1106
1107 if (l->gpio & GPIO_TYPE_EXTIF) {
1108 l->state = 0;
1109 set_led_extif(l);
1110 } else {
1111 if (l->polarity != INPUT) oe_mask |= l->gpio;
1112 mask |= l->gpio;
1113 val |= (l->polarity == NORMAL)?0:l->gpio;
1114 }
1115
1116 if (l->polarity == INPUT) continue;
1117
1118 if ((p = create_proc_entry(l->name, S_IRUSR, leds))) {
1119 l->proc.type = PROC_LED;
1120 l->proc.ptr = l;
1121 p->data = (void *) &l->proc;
1122 p->proc_fops = &diag_proc_fops;
1123 }
1124 }
1125
1126 gpio_outen(mask, oe_mask);
1127 gpio_control(mask, 0);
1128 gpio_out(mask, val);
1129 gpio_setintmask(mask, 0);
1130 }
1131
1132 static void unregister_leds(struct led_t *l)
1133 {
1134 for(; l->name; l++)
1135 remove_proc_entry(l->name, leds);
1136
1137 remove_proc_entry("led", diag);
1138 }
1139
1140 static void set_led_extif(struct led_t *led)
1141 {
1142 gpio_set_extif(led->gpio, led->state);
1143 }
1144
1145 static void led_flash(unsigned long dummy) {
1146 struct led_t *l;
1147 u32 mask = 0;
1148 u8 extif_blink = 0;
1149
1150 for (l = platform.leds; l->name; l++) {
1151 if (l->flash) {
1152 if (l->gpio & GPIO_TYPE_EXTIF) {
1153 extif_blink = 1;
1154 l->state = !l->state;
1155 set_led_extif(l);
1156 } else {
1157 mask |= l->gpio;
1158 }
1159 }
1160 }
1161
1162 mask &= ~gpiomask;
1163 if (mask) {
1164 u32 val = ~gpio_in();
1165
1166 gpio_outen(mask, mask);
1167 gpio_control(mask, 0);
1168 gpio_out(mask, val);
1169 }
1170 if (mask || extif_blink) {
1171 mod_timer(&led_timer, jiffies + FLASH_TIME);
1172 }
1173 }
1174
1175 static ssize_t diag_proc_read(struct file *file, char *buf, size_t count, loff_t *ppos)
1176 {
1177 #ifdef LINUX_2_4
1178 struct inode *inode = file->f_dentry->d_inode;
1179 struct proc_dir_entry *dent = inode->u.generic_ip;
1180 #else
1181 struct proc_dir_entry *dent = PDE(file->f_dentry->d_inode);
1182 #endif
1183 char *page;
1184 int len = 0;
1185
1186 if ((page = kmalloc(1024, GFP_KERNEL)) == NULL)
1187 return -ENOBUFS;
1188
1189 if (dent->data != NULL) {
1190 struct prochandler_t *handler = (struct prochandler_t *) dent->data;
1191 switch (handler->type) {
1192 case PROC_LED: {
1193 struct led_t * led = (struct led_t *) handler->ptr;
1194 if (led->flash) {
1195 len = sprintf(page, "f\n");
1196 } else {
1197 if (led->gpio & GPIO_TYPE_EXTIF) {
1198 len = sprintf(page, "%d\n", led->state);
1199 } else {
1200 u32 in = (gpio_in() & led->gpio ? 1 : 0);
1201 u8 p = (led->polarity == NORMAL ? 0 : 1);
1202 len = sprintf(page, "%d\n", ((in ^ p) ? 1 : 0));
1203 }
1204 }
1205 break;
1206 }
1207 case PROC_MODEL:
1208 len = sprintf(page, "%s\n", platform.name);
1209 break;
1210 case PROC_GPIOMASK:
1211 len = sprintf(page, "0x%04x\n", gpiomask);
1212 break;
1213 }
1214 }
1215 len += 1;
1216
1217 if (*ppos < len) {
1218 len = min_t(int, len - *ppos, count);
1219 if (copy_to_user(buf, (page + *ppos), len)) {
1220 kfree(page);
1221 return -EFAULT;
1222 }
1223 *ppos += len;
1224 } else {
1225 len = 0;
1226 }
1227
1228 kfree(page);
1229 return len;
1230 }
1231
1232
1233 static ssize_t diag_proc_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
1234 {
1235 #ifdef LINUX_2_4
1236 struct inode *inode = file->f_dentry->d_inode;
1237 struct proc_dir_entry *dent = inode->u.generic_ip;
1238 #else
1239 struct proc_dir_entry *dent = PDE(file->f_dentry->d_inode);
1240 #endif
1241 char *page;
1242 int ret = -EINVAL;
1243
1244 if ((page = kmalloc(count + 1, GFP_KERNEL)) == NULL)
1245 return -ENOBUFS;
1246
1247 if (copy_from_user(page, buf, count)) {
1248 kfree(page);
1249 return -EINVAL;
1250 }
1251 page[count] = 0;
1252
1253 if (dent->data != NULL) {
1254 struct prochandler_t *handler = (struct prochandler_t *) dent->data;
1255 switch (handler->type) {
1256 case PROC_LED: {
1257 struct led_t *led = (struct led_t *) handler->ptr;
1258 int p = (led->polarity == NORMAL ? 0 : 1);
1259
1260 if (page[0] == 'f') {
1261 led->flash = 1;
1262 led_flash(0);
1263 } else {
1264 led->flash = 0;
1265 if (led->gpio & GPIO_TYPE_EXTIF) {
1266 led->state = p ^ ((page[0] == '1') ? 1 : 0);
1267 set_led_extif(led);
1268 } else {
1269 gpio_outen(led->gpio, led->gpio);
1270 gpio_control(led->gpio, 0);
1271 gpio_out(led->gpio, ((p ^ (page[0] == '1')) ? led->gpio : 0));
1272 }
1273 }
1274 break;
1275 }
1276 case PROC_GPIOMASK:
1277 gpiomask = simple_strtoul(page, NULL, 0);
1278
1279 if (platform.buttons) {
1280 unregister_buttons(platform.buttons);
1281 register_buttons(platform.buttons);
1282 }
1283
1284 if (platform.leds) {
1285 unregister_leds(platform.leds);
1286 register_leds(platform.leds);
1287 }
1288 break;
1289 }
1290 ret = count;
1291 }
1292
1293 kfree(page);
1294 return ret;
1295 }
1296
1297 static int __init diag_init(void)
1298 {
1299 static struct proc_dir_entry *p;
1300 static struct platform_t *detected;
1301
1302 detected = platform_detect();
1303 if (!detected) {
1304 printk(MODULE_NAME ": Router model not detected.\n");
1305 return -ENODEV;
1306 }
1307 memcpy(&platform, detected, sizeof(struct platform_t));
1308
1309 printk(MODULE_NAME ": Detected '%s'\n", platform.name);
1310 if (platform.platform_init != NULL) {
1311 platform.platform_init();
1312 }
1313
1314 if (!(diag = proc_mkdir("diag", NULL))) {
1315 printk(MODULE_NAME ": proc_mkdir on /proc/diag failed\n");
1316 return -EINVAL;
1317 }
1318
1319 if ((p = create_proc_entry("model", S_IRUSR, diag))) {
1320 p->data = (void *) &proc_model;
1321 p->proc_fops = &diag_proc_fops;
1322 }
1323
1324 if ((p = create_proc_entry("gpiomask", S_IRUSR | S_IWUSR, diag))) {
1325 p->data = (void *) &proc_gpiomask;
1326 p->proc_fops = &diag_proc_fops;
1327 }
1328
1329 if (platform.buttons)
1330 register_buttons(platform.buttons);
1331
1332 if (platform.leds)
1333 register_leds(platform.leds);
1334
1335 return 0;
1336 }
1337
1338 static void __exit diag_exit(void)
1339 {
1340 del_timer(&led_timer);
1341
1342 if (platform.buttons)
1343 unregister_buttons(platform.buttons);
1344
1345 if (platform.leds)
1346 unregister_leds(platform.leds);
1347
1348 remove_proc_entry("model", diag);
1349 remove_proc_entry("gpiomask", diag);
1350 remove_proc_entry("diag", NULL);
1351 }
1352
1353 module_init(diag_init);
1354 module_exit(diag_exit);
1355
1356 MODULE_AUTHOR("Mike Baker, Felix Fietkau / OpenWrt.org");
1357 MODULE_LICENSE("GPL");