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_LED_STATUS_BOARD_SPECIFIC
30 #ifdef CONFIG_LED_STATUS0
31 { "0", CONFIG_LED_STATUS_BIT, NULL, NULL, NULL },
33 #ifdef CONFIG_LED_STATUS1
34 { "1", CONFIG_LED_STATUS_BIT1, NULL, NULL, NULL },
36 #ifdef CONFIG_LED_STATUS2
37 { "2", CONFIG_LED_STATUS_BIT2, NULL, NULL, NULL },
39 #ifdef CONFIG_LED_STATUS3
40 { "3", CONFIG_LED_STATUS_BIT3, NULL, NULL, NULL },
42 #ifdef CONFIG_LED_STATUS4
43 { "4", CONFIG_LED_STATUS_BIT4, NULL, NULL, NULL },
45 #ifdef CONFIG_LED_STATUS5
46 { "5", CONFIG_LED_STATUS_BIT5, NULL, NULL, NULL },
49 #ifdef CONFIG_LED_STATUS_GREEN
50 { "green", CONFIG_LED_STATUS_GREEN, green_led_off, green_led_on, NULL },
52 #ifdef CONFIG_LED_STATUS_YELLOW
53 { "yellow", CONFIG_LED_STATUS_YELLOW, yellow_led_off, yellow_led_on,
56 #ifdef CONFIG_LED_STATUS_RED
57 { "red", CONFIG_LED_STATUS_RED, red_led_off, red_led_on, NULL },
59 #ifdef CONFIG_LED_STATUS_BLUE
60 { "blue", CONFIG_LED_STATUS_BLUE, blue_led_off, blue_led_on, NULL },
62 { NULL, 0, NULL, NULL, NULL }
65 enum led_cmd { LED_ON, LED_OFF, LED_TOGGLE, LED_BLINK };
67 enum led_cmd get_led_cmd(char *var)
69 if (strcmp(var, "off") == 0)
71 if (strcmp(var, "on") == 0)
73 if (strcmp(var, "toggle") == 0)
75 if (strcmp(var, "blink") == 0)
82 * LED drivers providing a blinking LED functionality, like the
83 * PCA9551, can override this empty weak function
85 void __weak __led_blink(led_id_t mask, int freq)
89 int do_legacy_led(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
95 /* Validate arguments */
96 if ((argc < 3) || (argc > 4))
99 cmd = get_led_cmd(argv[2]);
101 return CMD_RET_USAGE;
104 for (i = 0; led_commands[i].string; i++) {
105 if ((strcmp("all", argv[1]) == 0) ||
106 (strcmp(led_commands[i].string, argv[1]) == 0)) {
110 if (led_commands[i].on)
111 led_commands[i].on();
113 __led_set(led_commands[i].mask,
114 CONFIG_LED_STATUS_ON);
117 if (led_commands[i].off)
118 led_commands[i].off();
120 __led_set(led_commands[i].mask,
121 CONFIG_LED_STATUS_OFF);
124 if (led_commands[i].toggle)
125 led_commands[i].toggle();
127 __led_toggle(led_commands[i].mask);
131 return CMD_RET_USAGE;
133 freq = simple_strtoul(argv[3], NULL, 10);
134 __led_blink(led_commands[i].mask, freq);
136 /* Need to set only 1 led if led_name wasn't 'all' */
137 if (strcmp("all", argv[1]) != 0)
142 /* If we ran out of matches, print Usage */
144 return CMD_RET_USAGE;
151 led, 4, 1, do_legacy_led,
153 #ifdef CONFIG_LED_STATUS_BOARD_SPECIFIC
154 #ifdef CONFIG_LED_STATUS0
157 #ifdef CONFIG_LED_STATUS1
160 #ifdef CONFIG_LED_STATUS2
163 #ifdef CONFIG_LED_STATUS3
166 #ifdef CONFIG_LED_STATUS4
169 #ifdef CONFIG_LED_STATUS5
173 #ifdef CONFIG_LED_STATUS_GREEN
176 #ifdef CONFIG_LED_STATUS_YELLOW
179 #ifdef CONFIG_LED_STATUS_RED
182 #ifdef CONFIG_LED_STATUS_BLUE
185 "all] [on|off|toggle|blink] [blink-freq in ms]",
186 "[led_name] [on|off|toggle|blink] sets or clears led(s)"