2 * diag.c - GPIO interface driver for Broadcom boards
4 * Copyright (C) 2006 Mike Baker <mbm@openwrt.org>,
5 * Felix Fietkau <nbd@openwrt.org>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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>
31 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
32 #include <linux/kobject.h>
33 #include <linux/workqueue.h>
34 #define hotplug_path uevent_helper
36 #include <linux/tqueue.h>
37 #define INIT_WORK INIT_TQUEUE
38 #define schedule_work schedule_task
39 #define work_struct tq_struct
44 #define getvar(str) (nvram_get(str)?:"")
46 static unsigned int gpiomask
= 0;
47 module_param(gpiomask
, int, 0644);
109 static void __init
bcm4780_init(void) {
112 /* Enables GPIO 3 that controls HDD and led power on ASUS WL-700gE */
113 printk(MODULE_NAME
": Spinning up HDD and enabling leds\n");
114 gpio_outen(pin
, pin
);
115 gpio_control(pin
, 0);
118 /* Wait 5s, so the HDD can spin up */
119 set_current_state(TASK_INTERRUPTIBLE
);
120 schedule_timeout(HZ
* 5);
123 static struct platform_t __initdata platforms
[] = {
126 .name
= "Linksys WAP54G V1",
128 { .name
= "reset", .gpio
= 1 << 0 },
131 { .name
= "diag", .gpio
= 1 << 3 },
132 { .name
= "wlan", .gpio
= 1 << 4 },
136 .name
= "Linksys WAP54G V3",
138 /* FIXME: verify this */
139 { .name
= "reset", .gpio
= 1 << 7 },
140 { .name
= "ses", .gpio
= 1 << 0 },
144 { .name
= "ses", .gpio
= 1 << 1 },
148 .name
= "Linksys WRT54G V1.x",
150 { .name
= "reset", .gpio
= 1 << 6 },
153 { .name
= "diag", .gpio
= 0x13 | GPIO_TYPE_EXTIF
, .polarity
= NORMAL
},
154 { .name
= "dmz", .gpio
= 0x12 | GPIO_TYPE_EXTIF
, .polarity
= NORMAL
},
158 .name
= "Linksys WRT54G/GS/GL",
160 { .name
= "reset", .gpio
= 1 << 6 },
161 { .name
= "ses", .gpio
= 1 << 4 },
164 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
165 { .name
= "dmz", .gpio
= 1 << 7, .polarity
= REVERSE
},
166 { .name
= "ses_white", .gpio
= 1 << 2, .polarity
= REVERSE
},
167 { .name
= "ses_orange", .gpio
= 1 << 3, .polarity
= REVERSE
},
168 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
172 .name
= "Linksys WRTSL54GS",
174 { .name
= "reset", .gpio
= 1 << 6 },
175 { .name
= "ses", .gpio
= 1 << 4 },
178 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
179 { .name
= "dmz", .gpio
= 1 << 0, .polarity
= REVERSE
},
180 { .name
= "ses_white", .gpio
= 1 << 5, .polarity
= REVERSE
},
181 { .name
= "ses_orange", .gpio
= 1 << 7, .polarity
= REVERSE
},
185 .name
= "Linksys WRT54G3G",
187 { .name
= "reset", .gpio
= 1 << 6 },
188 { .name
= "3g", .gpio
= 1 << 4 },
191 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
192 { .name
= "dmz", .gpio
= 1 << 7, .polarity
= REVERSE
},
193 { .name
= "3g_green", .gpio
= 1 << 2, .polarity
= NORMAL
},
194 { .name
= "3g_blue", .gpio
= 1 << 3, .polarity
= NORMAL
},
195 { .name
= "3g_blink", .gpio
= 1 << 5, .polarity
= NORMAL
},
199 .name
= "Linksys WRT350N",
201 { .name
= "reset", .gpio
= 1 << 6 },
202 { .name
= "ses", .gpio
= 1 << 8 },
205 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
206 { .name
= "ses", .gpio
= 1 << 3, .polarity
= REVERSE
},
211 .name
= "ASUS WL-HDD",
213 { .name
= "reset", .gpio
= 1 << 6 },
216 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
217 { .name
= "usb", .gpio
= 1 << 2, .polarity
= NORMAL
},
221 .name
= "ASUS WL-300g",
223 { .name
= "reset", .gpio
= 1 << 6 },
226 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
230 .name
= "ASUS WL-500g",
232 { .name
= "reset", .gpio
= 1 << 6 },
235 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
239 .name
= "ASUS WL-500g Deluxe",
241 { .name
= "reset", .gpio
= 1 << 6 },
244 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
248 .name
= "ASUS WL-500g Premium",
250 { .name
= "reset", .gpio
= 1 << 0 },
251 { .name
= "ses", .gpio
= 1 << 4 },
254 { .name
= "power", .gpio
= 1 << 1, .polarity
= REVERSE
},
258 .name
= "ASUS WL-500W",
260 { .name
= "reset", .gpio
= 1 << 6 },
261 { .name
= "ses", .gpio
= 1 << 7 },
264 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
268 .name
= "ASUS (unknown, BCM4702)",
270 { .name
= "reset", .gpio
= 1 << 6 },
273 { .name
= "power", .gpio
= 1 << 0, .polarity
= REVERSE
},
277 .name
= "ASUS WL-700gE",
279 { .name
= "reset", .gpio
= 1 << 7 }, // on back, hardwired, always resets device regardless OS state
280 { .name
= "ses", .gpio
= 1 << 4 }, // on back, actual name ezsetup
281 { .name
= "power", .gpio
= 1 << 0 }, // on front
282 { .name
= "copy", .gpio
= 1 << 6 }, // on front
286 // GPIO that controls power led also enables/disables some essential functions
289 { .name
= "power", .gpio
= 1 << 3, .polarity
= NORMAL
}, // actual name power
291 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
293 .platform_init
= bcm4780_init
,
297 .name
= "Buffalo WHR-G54S",
299 { .name
= "reset", .gpio
= 1 << 4 },
300 { .name
= "bridge", .gpio
= 1 << 5 },
301 { .name
= "ses", .gpio
= 1 << 0 },
304 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
305 { .name
= "internal", .gpio
= 1 << 3, .polarity
= REVERSE
},
306 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
307 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
311 .name
= "Buffalo WBR2-G54",
314 { .name
= "reset", .gpio
= 1 << 7 },
317 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
321 .name
= "Buffalo WHR-HP-G54",
323 { .name
= "reset", .gpio
= 1 << 4 },
324 { .name
= "bridge", .gpio
= 1 << 5 },
325 { .name
= "ses", .gpio
= 1 << 0 },
328 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
329 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
330 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
334 .name
= "Buffalo WHR2-A54G54",
336 { .name
= "reset", .gpio
= 1 << 4 },
339 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
343 .name
= "Buffalo WLA2-G54L",
346 { .name
= "reset", .gpio
= 1 << 7 },
349 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
353 .name
= "Buffalo WZR-G300N",
355 { .name
= "reset", .gpio
= 1 << 4 },
358 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
359 { .name
= "bridge", .gpio
= 1 << 1, .polarity
= REVERSE
},
360 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
364 .name
= "Buffalo WZR-RS-G54",
366 { .name
= "ses", .gpio
= 1 << 0 },
367 { .name
= "reset", .gpio
= 1 << 4 },
370 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
371 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
372 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
376 .name
= "Buffalo WZR-RS-G54HP",
378 { .name
= "ses", .gpio
= 1 << 0 },
379 { .name
= "reset", .gpio
= 1 << 4 },
382 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
383 { .name
= "ses", .gpio
= 1 << 6, .polarity
= REVERSE
},
384 { .name
= "vpn", .gpio
= 1 << 1, .polarity
= REVERSE
},
387 [BUFFALO_UNKNOWN
] = {
388 .name
= "Buffalo (unknown)",
390 { .name
= "reset", .gpio
= 1 << 7 },
393 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
396 [BUFFALO_UNKNOWN_4710
] = {
397 .name
= "Buffalo (unknown, BCM4710)",
399 { .name
= "reset", .gpio
= 1 << 4 },
402 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
},
407 .name
= "Siemens SE505 V1",
409 /* No usable buttons */
412 { .name
= "dmz", .gpio
= 1 << 4, .polarity
= REVERSE
},
413 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
417 .name
= "Siemens SE505 V2",
419 /* No usable buttons */
422 { .name
= "power", .gpio
= 1 << 5, .polarity
= REVERSE
},
423 { .name
= "dmz", .gpio
= 1 << 0, .polarity
= REVERSE
},
424 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= REVERSE
},
429 .name
= "U.S. Robotics USR5461",
431 /* No usable buttons */
434 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
435 { .name
= "printer", .gpio
= 1 << 1, .polarity
= REVERSE
},
440 .name
= "Dell TrueMobile 2300",
442 { .name
= "reset", .gpio
= 1 << 0 },
445 { .name
= "wlan", .gpio
= 1 << 6, .polarity
= REVERSE
},
446 { .name
= "power", .gpio
= 1 << 7, .polarity
= REVERSE
},
451 .name
= "Motorola WE800G",
453 { .name
= "reset", .gpio
= 1 << 0 },
456 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
457 { .name
= "diag", .gpio
= 1 << 2, .polarity
= REVERSE
},
458 { .name
= "wlan_amber", .gpio
= 1 << 1, .polarity
= NORMAL
},
462 .name
= "Motorola WR850G V1",
464 { .name
= "reset", .gpio
= 1 << 0 },
467 { .name
= "power", .gpio
= 1 << 4, .polarity
= NORMAL
},
468 { .name
= "diag", .gpio
= 1 << 3, .polarity
= REVERSE
},
469 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= NORMAL
},
470 { .name
= "wlan_red", .gpio
= 1 << 5, .polarity
= REVERSE
},
471 { .name
= "wlan_green", .gpio
= 1 << 7, .polarity
= REVERSE
},
475 .name
= "Motorola WR850G V2/V3",
477 { .name
= "reset", .gpio
= 1 << 5 },
480 { .name
= "power", .gpio
= 1 << 1, .polarity
= NORMAL
},
481 { .name
= "wlan", .gpio
= 1 << 0, .polarity
= REVERSE
},
482 { .name
= "dmz", .gpio
= 1 << 6, .polarity
= REVERSE
},
483 { .name
= "diag", .gpio
= 1 << 7, .polarity
= REVERSE
},
488 .name
= "Belkin (unknown)",
489 /* FIXME: verify & add detection */
491 { .name
= "reset", .gpio
= 1 << 7 },
494 { .name
= "power", .gpio
= 1 << 5, .polarity
= NORMAL
},
495 { .name
= "wlan", .gpio
= 1 << 3, .polarity
= NORMAL
},
496 { .name
= "connected", .gpio
= 1 << 0, .polarity
= NORMAL
},
501 .name
= "Netgear WGT634U",
503 { .name
= "reset", .gpio
= 1 << 2 },
506 { .name
= "power", .gpio
= 1 << 3, .polarity
= REVERSE
},
511 .name
= "Trendware TEW411BRP+",
513 { /* No usable buttons */ },
516 { .name
= "power", .gpio
= 1 << 7, .polarity
= NORMAL
},
517 { .name
= "wlan", .gpio
= 1 << 1, .polarity
= NORMAL
},
518 { .name
= "bridge", .gpio
= 1 << 6, .polarity
= NORMAL
},
523 .name
= "SimpleTech SimpleShare NAS",
525 { .name
= "reset", .gpio
= 1 << 7 }, // on back, hardwired, always resets device regardless OS state
526 { .name
= "power", .gpio
= 1 << 0 }, // on back
529 { .name
= "diag", .gpio
= 1 << 1, .polarity
= REVERSE
}, // actual name ready
531 .platform_init
= bcm4780_init
,
535 static struct platform_t __init
*platform_detect(void)
537 char *boardnum
, *boardtype
, *buf
;
539 boardnum
= getvar("boardnum");
540 boardtype
= getvar("boardtype");
542 if (strcmp(getvar("nvram_type"), "cfe") == 0)
543 return &platforms
[WGT634U
];
545 if (strncmp(getvar("model_no"), "WL700",5) == 0)
546 return &platforms
[WL700GE
];
548 if (strncmp(getvar("pmon_ver"), "CFE", 3) == 0) {
549 /* CFE based - newer hardware */
550 if (!strcmp(boardnum
, "42")) { /* Linksys */
551 if (!strcmp(boardtype
, "0x478") && !strcmp(getvar("cardbus"), "1"))
552 return &platforms
[WRT350N
];
554 if (!strcmp(boardtype
, "0x0101") && !strcmp(getvar("boot_ver"), "v3.6"))
555 return &platforms
[WRT54G3G
];
557 if (!strcmp(getvar("et1phyaddr"),"5") && !strcmp(getvar("et1mdcport"), "1"))
558 return &platforms
[WRTSL54GS
];
560 /* default to WRT54G */
561 return &platforms
[WRT54G
];
564 if (!strcmp(boardnum
, "45")) { /* ASUS */
565 if (!strcmp(boardtype
,"0x042f"))
566 return &platforms
[WL500GP
];
567 else if (!strcmp(boardtype
,"0x0472"))
568 return &platforms
[WL500W
];
570 return &platforms
[WL500GD
];
573 if (!strcmp(boardnum
, "10496"))
574 return &platforms
[USR5461
];
575 } else { /* PMON based - old stuff */
577 /* Dell TrueMobile 2300 */
578 if (!strcmp(getvar("ModelId"),"WX-5565"))
579 return &platforms
[TM2300
];
581 if ((simple_strtoul(getvar("GemtekPmonVer"), NULL
, 0) == 9) &&
582 (simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 30)) {
583 if (!strncmp(getvar("ModelId"),"WE800G", 6))
584 return &platforms
[WE800G
];
586 return &platforms
[WR850GV1
];
588 if (!strncmp(boardtype
, "bcm94710dev", 11)) {
589 if (!strcmp(boardnum
, "42"))
590 return &platforms
[WRT54GV1
];
591 if (simple_strtoul(boardnum
, NULL
, 0) == 2)
592 return &platforms
[WAP54GV1
];
594 if (!strncmp(getvar("hardware_version"), "WL500-", 6))
595 return &platforms
[WL500G
];
596 if (!strncmp(getvar("hardware_version"), "WL300-", 6)) {
597 /* Either WL-300g or WL-HDD, do more extensive checks */
598 if ((simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 0) &&
599 (simple_strtoul(getvar("et1phyaddr"), NULL
, 0) == 1))
600 return &platforms
[WLHDD
];
601 if ((simple_strtoul(getvar("et0phyaddr"), NULL
, 0) == 0) &&
602 (simple_strtoul(getvar("et1phyaddr"), NULL
, 0) == 10))
603 return &platforms
[WL300G
];
606 /* unknown asus stuff, probably bcm4702 */
607 if (!strncmp(boardnum
, "asusX", 5))
608 return &platforms
[ASUS_4702
];
611 if ((buf
= (nvram_get("melco_id") ?: nvram_get("buffalo_id")))) {
612 /* Buffalo hardware, check id for specific hardware matches */
613 if (!strcmp(buf
, "29bb0332"))
614 return &platforms
[WBR2_G54
];
615 if (!strcmp(buf
, "29129"))
616 return &platforms
[WLA2_G54L
];
617 if (!strcmp(buf
, "30189"))
618 return &platforms
[WHR_HP_G54
];
619 if (!strcmp(buf
, "30182"))
620 return &platforms
[WHR_G54S
];
621 if (!strcmp(buf
, "290441dd"))
622 return &platforms
[WHR2_A54G54
];
623 if (!strcmp(buf
, "31120"))
624 return &platforms
[WZR_G300N
];
625 if (!strcmp(buf
, "30083"))
626 return &platforms
[WZR_RS_G54
];
627 if (!strcmp(buf
, "30103"))
628 return &platforms
[WZR_RS_G54HP
];
631 if (buf
|| !strcmp(boardnum
, "00")) {/* probably buffalo */
632 if (!strncmp(boardtype
, "bcm94710ap", 10))
633 return &platforms
[BUFFALO_UNKNOWN_4710
];
635 return &platforms
[BUFFALO_UNKNOWN
];
638 if (!strcmp(getvar("CFEver"), "MotoWRv203") ||
639 !strcmp(getvar("MOTO_BOARD_TYPE"), "WR_FEM1")) {
641 return &platforms
[WR850GV2V3
];
644 if (!strcmp(boardnum
, "44")) { /* Trendware TEW-411BRP+ */
645 return &platforms
[TEW411BRPP
];
648 if (!strncmp(boardnum
, "04FN52", 6)) /* SimpleTech SimpleShare */
649 return &platforms
[STI_NAS
];
655 static void register_buttons(struct button_t
*b
)
658 platform
.button_mask
|= b
->gpio
;
660 platform
.button_mask
&= ~gpiomask
;
662 gpio_outen(platform
.button_mask
, 0);
663 gpio_control(platform
.button_mask
, 0);
664 platform
.button_polarity
= gpio_in() & platform
.button_mask
;
665 gpio_intpolarity(platform
.button_mask
, platform
.button_polarity
);
666 gpio_intmask(platform
.button_mask
, platform
.button_mask
);
668 gpio_set_irqenable(1, button_handler
);
671 static void unregister_buttons(struct button_t
*b
)
673 gpio_intmask(platform
.button_mask
, 0);
675 gpio_set_irqenable(0, button_handler
);
678 static void hotplug_button(struct event_t
*event
)
680 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
681 call_usermodehelper (event
->argv
[0], event
->argv
, event
->envp
, 1);
683 call_usermodehelper (event
->argv
[0], event
->argv
, event
->envp
);
688 static irqreturn_t
button_handler(int irq
, void *dev_id
, struct pt_regs
*regs
)
693 in
= gpio_in() & platform
.button_mask
;
694 gpio_intpolarity(platform
.button_mask
, in
);
695 changed
= platform
.button_polarity
^ in
;
696 platform
.button_polarity
= in
;
698 changed
&= ~gpio_outen(0, 0);
700 for (b
= platform
.buttons
; b
->name
; b
++) {
701 struct event_t
*event
;
703 if (!(b
->gpio
& changed
)) continue;
707 if ((event
= (struct event_t
*)kmalloc (sizeof(struct event_t
), GFP_ATOMIC
))) {
709 char *scratch
= event
->buf
;
712 event
->argv
[i
++] = hotplug_path
;
713 event
->argv
[i
++] = "button";
717 event
->envp
[i
++] = "HOME=/";
718 event
->envp
[i
++] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
719 event
->envp
[i
++] = scratch
;
720 scratch
+= sprintf (scratch
, "ACTION=%s", b
->pressed
?"pressed":"released") + 1;
721 event
->envp
[i
++] = scratch
;
722 scratch
+= sprintf (scratch
, "BUTTON=%s", b
->name
) + 1;
723 event
->envp
[i
++] = scratch
;
724 scratch
+= sprintf (scratch
, "SEEN=%ld", (jiffies
- b
->seen
)/HZ
) + 1;
727 INIT_WORK(&event
->wq
, (void *)(void *)hotplug_button
, (void *)event
);
728 schedule_work(&event
->wq
);
736 static void register_leds(struct led_t
*l
)
738 struct proc_dir_entry
*p
;
742 leds
= proc_mkdir("led", diag
);
746 for(; l
->name
; l
++) {
747 if (l
->gpio
& gpiomask
)
750 if (l
->gpio
& GPIO_TYPE_EXTIF
) {
755 val
|= (l
->polarity
== NORMAL
)?0:l
->gpio
;
758 if ((p
= create_proc_entry(l
->name
, S_IRUSR
, leds
))) {
759 l
->proc
.type
= PROC_LED
;
761 p
->data
= (void *) &l
->proc
;
762 p
->proc_fops
= &diag_proc_fops
;
766 gpio_outen(mask
, mask
);
767 gpio_control(mask
, 0);
771 static void unregister_leds(struct led_t
*l
)
774 remove_proc_entry(l
->name
, leds
);
776 remove_proc_entry("led", diag
);
779 static void set_led_extif(struct led_t
*led
)
781 gpio_set_extif(led
->gpio
, led
->state
);
784 static void led_flash(unsigned long dummy
) {
789 for (l
= platform
.leds
; l
->name
; l
++) {
791 if (l
->gpio
& GPIO_TYPE_EXTIF
) {
793 l
->state
= !l
->state
;
803 u32 val
= ~gpio_in();
805 gpio_outen(mask
, mask
);
806 gpio_control(mask
, 0);
809 if (mask
|| extif_blink
) {
810 mod_timer(&led_timer
, jiffies
+ FLASH_TIME
);
814 static ssize_t
diag_proc_read(struct file
*file
, char *buf
, size_t count
, loff_t
*ppos
)
817 struct inode
*inode
= file
->f_dentry
->d_inode
;
818 struct proc_dir_entry
*dent
= inode
->u
.generic_ip
;
820 struct proc_dir_entry
*dent
= PDE(file
->f_dentry
->d_inode
);
825 if ((page
= kmalloc(1024, GFP_KERNEL
)) == NULL
)
828 if (dent
->data
!= NULL
) {
829 struct prochandler_t
*handler
= (struct prochandler_t
*) dent
->data
;
830 switch (handler
->type
) {
832 struct led_t
* led
= (struct led_t
*) handler
->ptr
;
834 len
= sprintf(page
, "f\n");
836 if (led
->gpio
& GPIO_TYPE_EXTIF
) {
837 len
= sprintf(page
, "%d\n", led
->state
);
839 u32 in
= (gpio_in() & led
->gpio
? 1 : 0);
840 u8 p
= (led
->polarity
== NORMAL
? 0 : 1);
841 len
= sprintf(page
, "%d\n", ((in
^ p
) ? 1 : 0));
847 len
= sprintf(page
, "%s\n", platform
.name
);
850 len
= sprintf(page
, "0x%04x\n", gpiomask
);
857 len
= min_t(int, len
- *ppos
, count
);
858 if (copy_to_user(buf
, (page
+ *ppos
), len
)) {
871 static ssize_t
diag_proc_write(struct file
*file
, const char *buf
, size_t count
, loff_t
*ppos
)
874 struct inode
*inode
= file
->f_dentry
->d_inode
;
875 struct proc_dir_entry
*dent
= inode
->u
.generic_ip
;
877 struct proc_dir_entry
*dent
= PDE(file
->f_dentry
->d_inode
);
882 if ((page
= kmalloc(count
+ 1, GFP_KERNEL
)) == NULL
)
885 if (copy_from_user(page
, buf
, count
)) {
891 if (dent
->data
!= NULL
) {
892 struct prochandler_t
*handler
= (struct prochandler_t
*) dent
->data
;
893 switch (handler
->type
) {
895 struct led_t
*led
= (struct led_t
*) handler
->ptr
;
896 int p
= (led
->polarity
== NORMAL
? 0 : 1);
898 if (page
[0] == 'f') {
903 if (led
->gpio
& GPIO_TYPE_EXTIF
) {
904 led
->state
= p
^ ((page
[0] == '1') ? 1 : 0);
907 gpio_outen(led
->gpio
, led
->gpio
);
908 gpio_control(led
->gpio
, 0);
909 gpio_out(led
->gpio
, ((p
^ (page
[0] == '1')) ? led
->gpio
: 0));
915 gpiomask
= simple_strtoul(page
, NULL
, 0);
917 if (platform
.buttons
) {
918 unregister_buttons(platform
.buttons
);
919 register_buttons(platform
.buttons
);
923 unregister_leds(platform
.leds
);
924 register_leds(platform
.leds
);
935 static int __init
diag_init(void)
937 static struct proc_dir_entry
*p
;
938 static struct platform_t
*detected
;
940 detected
= platform_detect();
942 printk(MODULE_NAME
": Router model not detected.\n");
945 memcpy(&platform
, detected
, sizeof(struct platform_t
));
947 printk(MODULE_NAME
": Detected '%s'\n", platform
.name
);
948 if (platform
.platform_init
!= NULL
) {
949 platform
.platform_init();
952 if (!(diag
= proc_mkdir("diag", NULL
))) {
953 printk(MODULE_NAME
": proc_mkdir on /proc/diag failed\n");
957 if ((p
= create_proc_entry("model", S_IRUSR
, diag
))) {
958 p
->data
= (void *) &proc_model
;
959 p
->proc_fops
= &diag_proc_fops
;
962 if ((p
= create_proc_entry("gpiomask", S_IRUSR
| S_IWUSR
, diag
))) {
963 p
->data
= (void *) &proc_gpiomask
;
964 p
->proc_fops
= &diag_proc_fops
;
967 if (platform
.buttons
)
968 register_buttons(platform
.buttons
);
971 register_leds(platform
.leds
);
976 static void __exit
diag_exit(void)
979 del_timer(&led_timer
);
981 if (platform
.buttons
)
982 unregister_buttons(platform
.buttons
);
985 unregister_leds(platform
.leds
);
987 remove_proc_entry("model", diag
);
988 remove_proc_entry("gpiomask", diag
);
989 remove_proc_entry("diag", NULL
);
992 module_init(diag_init
);
993 module_exit(diag_exit
);
995 MODULE_AUTHOR("Mike Baker, Felix Fietkau / OpenWrt.org");
996 MODULE_LICENSE("GPL");