From 6ca098a70e8fa7c77f2d77c1509b60e92b206c5a Mon Sep 17 00:00:00 2001 From: Fedor Date: Sun, 19 Dec 2010 05:31:41 -0500 Subject: [PATCH] rc: USB LED support --- release/src-rt/linux/linux-2.6/config_base | 8 +++++- release/src/router/Makefile | 2 ++ release/src/router/rc/usb.c | 20 ++++++++++++--- release/src/router/shared/led.c | 40 ++++++++++++++++-------------- release/src/router/shared/shared.h | 9 +++++-- 5 files changed, 53 insertions(+), 26 deletions(-) diff --git a/release/src-rt/linux/linux-2.6/config_base b/release/src-rt/linux/linux-2.6/config_base index 7dd0448861..a1e2c3a80c 100644 --- a/release/src-rt/linux/linux-2.6/config_base +++ b/release/src-rt/linux/linux-2.6/config_base @@ -1428,15 +1428,21 @@ CONFIG_USB_SERIAL_OPTION=m # # LED devices # -# CONFIG_NEW_LEDS is not set +CONFIG_NEW_LEDS=y +CONFIG_LEDS_CLASS=m # # LED drivers # +CONFIG_LEDS_USBGPIO=m # # LED Triggers # +CONFIG_LEDS_TRIGGERS=y +# CONFIG_LEDS_TRIGGER_TIMER is not set +# CONFIG_LEDS_TRIGGER_HEARTBEAT is not set +CONFIG_LEDS_TRIGGER_USBDEV=m # # InfiniBand support diff --git a/release/src/router/Makefile b/release/src/router/Makefile index ea03ae2b4a..ca46814b21 100644 --- a/release/src/router/Makefile +++ b/release/src/router/Makefile @@ -358,6 +358,7 @@ endif $(if $(TCONFIG_USB),@cp -f,@mv) $(TARGETDIR)/lib/modules/*/kernel/fs/nls_*.*o $(PLATFORMDIR)/extras/ || true $(if $(TCONFIG_USB),@cp -f,@mv) $(TARGETDIR)/lib/modules/*/kernel/drivers/usb/*.*o $(PLATFORMDIR)/extras/ || true $(if $(TCONFIG_USB),@cp -f,@mv) $(TARGETDIR)/lib/modules/*/kernel/drivers/scsi/*.*o $(PLATFORMDIR)/extras/ || true + $(if $(TCONFIG_USB),@cp -f,@mv) $(TARGETDIR)/lib/modules/*/kernel/drivers/leds/*.*o $(PLATFORMDIR)/extras/ || true $(if $(TCONFIG_USB),@cp -f,@mv) $(TARGETDIR)/lib/modules/*/kernel/fs/ext2.*o $(PLATFORMDIR)/extras/ || true $(if $(TCONFIG_USB),@cp -f,@mv) $(TARGETDIR)/lib/modules/*/kernel/fs/ext3.*o $(PLATFORMDIR)/extras/ || true $(if $(TCONFIG_USB),@cp -f,@mv) $(TARGETDIR)/lib/modules/*/kernel/fs/jbd.*o $(PLATFORMDIR)/extras/ || true @@ -369,6 +370,7 @@ endif ifneq ($(TCONFIG_USB),y) @rm -rf $(TARGETDIR)/lib/modules/*/kernel/drivers/usb || true @rm -rf $(TARGETDIR)/lib/modules/*/kernel/drivers/scsi || true + @rm -rf $(TARGETDIR)/lib/modules/*/kernel/drivers/leds || true endif $(if $(TCONFIG_USB_EXTRAS),@cp -f,@mv) $(TARGETDIR)/lib/modules/*/kernel/drivers/connector/cn.*o $(PLATFORMDIR)/extras/ || true diff --git a/release/src/router/rc/usb.c b/release/src/router/rc/usb.c index ec380c5626..cc9ded34b5 100644 --- a/release/src/router/rc/usb.c +++ b/release/src/router/rc/usb.c @@ -88,12 +88,21 @@ void start_usb(void) tune_bdflush(); if (nvram_get_int("usb_enable")) { -// led(LED_AOSS, LED_ON); modprobe(USBCORE_MOD); /* mount usb device filesystem */ mount(USBFS, "/proc/bus/usb", USBFS, MS_MGC_VAL, NULL); +#ifdef LINUX26 + i = do_led(LED_USB, LED_PROBE); + if (i != 255) { + modprobe("ledtrig-usbdev"); + modprobe("leds-usb"); + sprintf(param, "%d", i); + f_write_string("/sys/class/leds/usb-led/gpio_pin", param, 0, 0); + f_write_string("/sys/class/leds/usb-led/device_name", "1-1", 0, 0); + } +#endif if (nvram_get_int("usb_storage")) { /* insert scsi and storage modules before usb drivers */ modprobe(SCSI_MOD); @@ -150,9 +159,6 @@ void start_usb(void) } } } - else { -// led(LED_AOSS, LED_OFF); - } } void stop_usb(void) @@ -201,6 +207,12 @@ void stop_usb(void) if (nvram_get_int("usb_uhci") != 1) modprobe_r(USBUHCI_MOD); if (nvram_get_int("usb_usb2") != 1) modprobe_r(USB20_MOD); +#ifdef LINUX26 + modprobe_r("leds-usb"); + modprobe_r("ledtrig-usbdev"); + led(LED_USB, LED_OFF); +#endif + // only unload core modules if usb is disabled if (!nvram_get_int("usb_enable")) { umount("/proc/bus/usb"); // unmount usb device filesystem diff --git a/release/src/router/shared/led.c b/release/src/router/shared/led.c index e91955da85..6c5f90165d 100644 --- a/release/src/router/shared/led.c +++ b/release/src/router/shared/led.c @@ -177,7 +177,7 @@ int nvget_gpio(const char *name, int *gpio, int *inv) // --- move end --- -int led(int which, int mode) +int do_led(int which, int mode) { // WLAN DIAG WHITE AMBER DMZ AOSS BRIDG MYST/USB // ----- ----- ----- ----- ----- ----- ----- ----- @@ -205,28 +205,29 @@ int led(int which, int mode) char s[16]; int n; int b = 255, c = 255; + int ret = 255; - if ((which < 0) || (which >= LED_COUNT)) return 0; + if ((which < 0) || (which >= LED_COUNT)) return ret; switch (nvram_match("led_override", "1") ? MODEL_UNKNOWN : get_model()) { case MODEL_WRT54G: if (check_hw_type() == HW_BCM4702) { // G v1.x - if ((which != LED_DIAG) && (which != LED_DMZ)) return 0; + if ((which != LED_DIAG) && (which != LED_DMZ)) return ret; + b = (which == LED_DMZ) ? 1 : 4; if (mode != LED_PROBE) { if (f_read_string("/proc/sys/diag", s, sizeof(s)) > 0) { - b = (which == LED_DMZ) ? 1 : 4; n = atoi(s); sprintf(s, "%u", mode ? (n | b) : (n & ~b)); f_write_string("/proc/sys/diag", s, 0, 0); } } - return 1; + return b; } switch (which) { case LED_AMBER: case LED_WHITE: - if (!supports(SUP_WHAM_LED)) return 0; + if (!supports(SUP_WHAM_LED)) return ret; break; } b = wrt54g[which]; @@ -254,12 +255,12 @@ int led(int which, int mode) break; /* case MODEL_WHR2A54G54: - if (which != LED_DIAG) return 0; + if (which != LED_DIAG) return ret; b = 7; break; */ case MODEL_WBRG54: - if (which != LED_DIAG) return 0; + if (which != LED_DIAG) return ret; b = 7; break; case MODEL_WBR2G54: @@ -273,11 +274,11 @@ int led(int which, int mode) b = wr850g2[which]; break; case MODEL_WL500GP: - if (which != LED_DIAG) return 0; + if (which != LED_DIAG) return ret; b = -1; // power light break; case MODEL_WL500W: - if (which != LED_DIAG) return 0; + if (which != LED_DIAG) return ret; b = -5; // power light break; case MODEL_DIR320: @@ -292,17 +293,17 @@ int led(int which, int mode) case MODEL_WL500GPv2: case MODEL_WL500GD: case MODEL_WL520GU: - if (which != LED_DIAG) return 0; + if (which != LED_DIAG) return ret; b = -99; // Invert power light as diag indicator break; #ifdef CONFIG_BCMWL5 case MODEL_RTN12: - if (which != LED_DIAG) return 0; + if (which != LED_DIAG) return ret; b = -2; // power light break; case MODEL_RTN10: case MODEL_RTN16: - if (which != LED_DIAG) return 0; + if (which != LED_DIAG) return ret; b = -1; // power light break; case MODEL_WNR3500L: @@ -336,15 +337,15 @@ int led(int which, int mode) break; */ case MODEL_MN700: - if (which != LED_DIAG) return 0; + if (which != LED_DIAG) return ret; b = 6; break; case MODEL_WLA2G54L: - if (which != LED_DIAG) return 0; + if (which != LED_DIAG) return ret; b = 1; break; case MODEL_WRT300N: - if (which != LED_DIAG) return 0; + if (which != LED_DIAG) return ret; b = 1; break; case MODEL_WRT310Nv1: @@ -357,11 +358,13 @@ int led(int which, int mode) sprintf(s, "led_%s", led_names[which]); if (nvget_gpio(s, &b, &n)) { if ((mode != LED_PROBE) && (n)) mode = !mode; + ret = (n) ? b : ((b) ? -b : -99); goto SET; } - return 0; + return ret; } + ret = b; if (b < 0) { if (b == -99) b = 0; // -0 substitute else b = -b; @@ -382,8 +385,7 @@ SET: else mode = !mode; if (c < 16) gpio_write(1 << c, mode); } - return 1; } - return 0; + return ret; } diff --git a/release/src/router/shared/shared.h b/release/src/router/shared/shared.h index c6bf85818b..4f8b7f5edd 100644 --- a/release/src/router/shared/shared.h +++ b/release/src/router/shared/shared.h @@ -271,7 +271,8 @@ extern int f_wait_notexists(const char *name, int max); #define LED_DMZ 4 #define LED_AOSS 5 #define LED_BRIDGE 6 -#define LED_MYSTERY 7 // (unmarked LED between wireless and bridge on WHR-G54S) +#define LED_USB 7 +#define LED_MYSTERY LED_USB // (unmarked LED between wireless and bridge on WHR-G54S) #define LED_COUNT 8 #define LED_OFF 0 @@ -286,7 +287,11 @@ extern void gpio_write(uint32_t bit, int en); extern uint32_t gpio_read(void); extern uint32_t _gpio_read(int f); extern int nvget_gpio(const char *name, int *gpio, int *inv); -extern int led(int which, int mode); +extern int do_led(int which, int mode); +static inline int led(int which, int mode) +{ + return (do_led(which, mode) != 255); +} // base64.c -- 2.11.4.GIT