3 * Jason Kridner <jkridner@beagleboard.org>
5 * Based on cmd_led.c patch from:
6 * http://www.mail-archive.com/u-boot@lists.denx.de/msg06873.html
8 * Ulf Samuelsson <ulf.samuelsson@atmel.com>
10 * SPDX-License-Identifier: GPL-2.0+
16 #include <status_led.h>
19 char *string; /* String for use in the command */
20 led_id_t mask; /* Mask used for calling __led_set() */
21 void (*off)(void); /* Optional function for turning LED off */
22 void (*on)(void); /* Optional function for turning LED on */
23 void (*toggle)(void);/* Optional function for toggling LED */
26 typedef struct led_tbl_s led_tbl_t;
28 static const led_tbl_t led_commands[] = {
29 #ifdef CONFIG_BOARD_SPECIFIC_LED
31 { "0", STATUS_LED_BIT, NULL, NULL, NULL },
33 #ifdef STATUS_LED_BIT1
34 { "1", STATUS_LED_BIT1, NULL, NULL, NULL },
36 #ifdef STATUS_LED_BIT2
37 { "2", STATUS_LED_BIT2, NULL, NULL, NULL },
39 #ifdef STATUS_LED_BIT3
40 { "3", STATUS_LED_BIT3, NULL, NULL, NULL },
43 #ifdef STATUS_LED_GREEN
44 { "green", STATUS_LED_GREEN, green_led_off, green_led_on, NULL },
46 #ifdef STATUS_LED_YELLOW
47 { "yellow", STATUS_LED_YELLOW, yellow_led_off, yellow_led_on, NULL },
50 { "red", STATUS_LED_RED, red_led_off, red_led_on, NULL },
52 #ifdef STATUS_LED_BLUE
53 { "blue", STATUS_LED_BLUE, blue_led_off, blue_led_on, NULL },
55 { NULL, 0, NULL, NULL, NULL }
58 enum led_cmd { LED_ON, LED_OFF, LED_TOGGLE };
60 enum led_cmd get_led_cmd(char *var)
62 if (strcmp(var, "off") == 0) {
65 if (strcmp(var, "on") == 0) {
68 if (strcmp(var, "toggle") == 0)
73 int do_led (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
78 /* Validate arguments */
83 cmd = get_led_cmd(argv[2]);
88 for (i = 0; led_commands[i].string; i++) {
89 if ((strcmp("all", argv[1]) == 0) ||
90 (strcmp(led_commands[i].string, argv[1]) == 0)) {
94 if (led_commands[i].on)
97 __led_set(led_commands[i].mask,
101 if (led_commands[i].off)
102 led_commands[i].off();
104 __led_set(led_commands[i].mask,
108 if (led_commands[i].toggle)
109 led_commands[i].toggle();
111 __led_toggle(led_commands[i].mask);
113 /* Need to set only 1 led if led_name wasn't 'all' */
114 if (strcmp("all", argv[1]) != 0)
119 /* If we ran out of matches, print Usage */
121 return CMD_RET_USAGE;
130 #ifdef CONFIG_BOARD_SPECIFIC_LED
131 #ifdef STATUS_LED_BIT
134 #ifdef STATUS_LED_BIT1
137 #ifdef STATUS_LED_BIT2
140 #ifdef STATUS_LED_BIT3
144 #ifdef STATUS_LED_GREEN
147 #ifdef STATUS_LED_YELLOW
150 #ifdef STATUS_LED_RED
153 #ifdef STATUS_LED_BLUE
156 "all] [on|off|toggle]",
157 "[led_name] [on|off|toggle] sets or clears led(s)"