]> git.sur5r.net Git - u-boot/commitdiff
cmd_led: Extend led command to support blinking and more leds
authorStefan Roese <sr@denx.de>
Wed, 11 Mar 2015 08:51:39 +0000 (09:51 +0100)
committerTom Rini <trini@konsulko.com>
Thu, 23 Apr 2015 13:43:08 +0000 (09:43 -0400)
This patch extends the U-Boot "led" command to support automatic blinking
by setting a blink frequency in milliseconds. Additionally the number of
supported LEDs is increased to 6 (0...5).

This will be used by the PCA9551 LED driver.

Signed-off-by: Stefan Roese <sr@denx.de>
Reviewed-by: Tom Rini <trini@konsulko.com>
common/cmd_led.c
drivers/misc/status_led.c
include/status_led.h

index 172bc30bd6fc9b272ef60b33f7777c31e9497794..b0f1a61b1bb02cb813452b8ba696619645691f61 100644 (file)
@@ -39,6 +39,12 @@ static const led_tbl_t led_commands[] = {
 #ifdef STATUS_LED_BIT3
        { "3", STATUS_LED_BIT3, NULL, NULL, NULL },
 #endif
+#ifdef STATUS_LED_BIT4
+       { "4", STATUS_LED_BIT4, NULL, NULL, NULL },
+#endif
+#ifdef STATUS_LED_BIT5
+       { "5", STATUS_LED_BIT5, NULL, NULL, NULL },
+#endif
 #endif
 #ifdef STATUS_LED_GREEN
        { "green", STATUS_LED_GREEN, green_led_off, green_led_on, NULL },
@@ -55,30 +61,39 @@ static const led_tbl_t led_commands[] = {
        { NULL, 0, NULL, NULL, NULL }
 };
 
-enum led_cmd { LED_ON, LED_OFF, LED_TOGGLE };
+enum led_cmd { LED_ON, LED_OFF, LED_TOGGLE, LED_BLINK };
 
 enum led_cmd get_led_cmd(char *var)
 {
-       if (strcmp(var, "off") == 0) {
+       if (strcmp(var, "off") == 0)
                return LED_OFF;
-       }
-       if (strcmp(var, "on") == 0) {
+       if (strcmp(var, "on") == 0)
                return LED_ON;
-       }
        if (strcmp(var, "toggle") == 0)
                return LED_TOGGLE;
+       if (strcmp(var, "blink") == 0)
+               return LED_BLINK;
+
        return -1;
 }
 
+/*
+ * LED drivers providing a blinking LED functionality, like the
+ * PCA9551, can override this empty weak function
+ */
+void __weak __led_blink(led_id_t mask, int freq)
+{
+}
+
 int do_led (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
        int i, match = 0;
        enum led_cmd cmd;
+       int freq;
 
        /* Validate arguments */
-       if ((argc != 3)) {
+       if ((argc < 3) || (argc > 4))
                return CMD_RET_USAGE;
-       }
 
        cmd = get_led_cmd(argv[2]);
        if (cmd < 0) {
@@ -109,6 +124,13 @@ int do_led (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
                                        led_commands[i].toggle();
                                else
                                        __led_toggle(led_commands[i].mask);
+                               break;
+                       case LED_BLINK:
+                               if (argc != 4)
+                                       return CMD_RET_USAGE;
+
+                               freq = simple_strtoul(argv[3], NULL, 10);
+                               __led_blink(led_commands[i].mask, freq);
                        }
                        /* Need to set only 1 led if led_name wasn't 'all' */
                        if (strcmp("all", argv[1]) != 0)
@@ -125,7 +147,7 @@ int do_led (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 }
 
 U_BOOT_CMD(
-       led, 3, 1, do_led,
+       led, 4, 1, do_led,
        "["
 #ifdef CONFIG_BOARD_SPECIFIC_LED
 #ifdef STATUS_LED_BIT
@@ -140,6 +162,12 @@ U_BOOT_CMD(
 #ifdef STATUS_LED_BIT3
        "3|"
 #endif
+#ifdef STATUS_LED_BIT4
+       "4|"
+#endif
+#ifdef STATUS_LED_BIT5
+       "5|"
+#endif
 #endif
 #ifdef STATUS_LED_GREEN
        "green|"
@@ -153,6 +181,6 @@ U_BOOT_CMD(
 #ifdef STATUS_LED_BLUE
        "blue|"
 #endif
-       "all] [on|off|toggle]",
-       "[led_name] [on|off|toggle] sets or clears led(s)"
+       "all] [on|off|toggle|blink] [blink-freq in ms]",
+       "[led_name] [on|off|toggle|blink] sets or clears led(s)"
 );
index ed9adb21d6ad6b643f8b81e5461f579020f258a1..9869d98c10c073f51238bd21c8fc35683e969609 100644 (file)
@@ -53,6 +53,20 @@ led_dev_t led_dev[] = {
        0,
     },
 #endif
+#if defined(STATUS_LED_BIT4)
+    {  STATUS_LED_BIT4,
+       STATUS_LED_STATE4,
+       STATUS_LED_PERIOD4,
+       0,
+    },
+#endif
+#if defined(STATUS_LED_BIT5)
+    {  STATUS_LED_BIT5,
+       STATUS_LED_STATE5,
+       STATUS_LED_PERIOD5,
+       0,
+    },
+#endif
 };
 
 #define MAX_LED_DEV    (sizeof(led_dev)/sizeof(led_dev_t))
index 27f4bdfa8773b36233f7bdc57136c655d5908e5c..a5e35df80ac1b13db6d82137a34c71f8ca63c9d5 100644 (file)
@@ -105,6 +105,7 @@ typedef unsigned long led_id_t;
 extern void __led_toggle (led_id_t mask);
 extern void __led_init (led_id_t mask, int state);
 extern void __led_set (led_id_t mask, int state);
+void __led_blink(led_id_t mask, int freq);
 #else
 # error Status LED configuration missing
 #endif