1 // SPDX-License-Identifier: GPL-2.0+
4 * Jason Kridner <jkridner@beagleboard.org>
6 * Based on cmd_led.c patch from:
7 * http://www.mail-archive.com/u-boot@lists.denx.de/msg06873.html
9 * Ulf Samuelsson <ulf.samuelsson@atmel.com>
15 #include <status_led.h>
18 char *string; /* String for use in the command */
19 led_id_t mask; /* Mask used for calling __led_set() */
20 void (*off)(void); /* Optional function for turning LED off */
21 void (*on)(void); /* Optional function for turning LED on */
22 void (*toggle)(void);/* Optional function for toggling LED */
25 typedef struct led_tbl_s led_tbl_t;
27 static const led_tbl_t led_commands[] = {
28 #ifdef CONFIG_LED_STATUS_BOARD_SPECIFIC
29 #ifdef CONFIG_LED_STATUS0
30 { "0", CONFIG_LED_STATUS_BIT, NULL, NULL, NULL },
32 #ifdef CONFIG_LED_STATUS1
33 { "1", CONFIG_LED_STATUS_BIT1, NULL, NULL, NULL },
35 #ifdef CONFIG_LED_STATUS2
36 { "2", CONFIG_LED_STATUS_BIT2, NULL, NULL, NULL },
38 #ifdef CONFIG_LED_STATUS3
39 { "3", CONFIG_LED_STATUS_BIT3, NULL, NULL, NULL },
41 #ifdef CONFIG_LED_STATUS4
42 { "4", CONFIG_LED_STATUS_BIT4, NULL, NULL, NULL },
44 #ifdef CONFIG_LED_STATUS5
45 { "5", CONFIG_LED_STATUS_BIT5, NULL, NULL, NULL },
48 #ifdef CONFIG_LED_STATUS_GREEN
49 { "green", CONFIG_LED_STATUS_GREEN, green_led_off, green_led_on, NULL },
51 #ifdef CONFIG_LED_STATUS_YELLOW
52 { "yellow", CONFIG_LED_STATUS_YELLOW, yellow_led_off, yellow_led_on,
55 #ifdef CONFIG_LED_STATUS_RED
56 { "red", CONFIG_LED_STATUS_RED, red_led_off, red_led_on, NULL },
58 #ifdef CONFIG_LED_STATUS_BLUE
59 { "blue", CONFIG_LED_STATUS_BLUE, blue_led_off, blue_led_on, NULL },
61 { NULL, 0, NULL, NULL, NULL }
64 enum led_cmd { LED_ON, LED_OFF, LED_TOGGLE, LED_BLINK };
66 enum led_cmd get_led_cmd(char *var)
68 if (strcmp(var, "off") == 0)
70 if (strcmp(var, "on") == 0)
72 if (strcmp(var, "toggle") == 0)
74 if (strcmp(var, "blink") == 0)
81 * LED drivers providing a blinking LED functionality, like the
82 * PCA9551, can override this empty weak function
84 void __weak __led_blink(led_id_t mask, int freq)
88 int do_legacy_led(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
94 /* Validate arguments */
95 if ((argc < 3) || (argc > 4))
98 cmd = get_led_cmd(argv[2]);
100 return CMD_RET_USAGE;
103 for (i = 0; led_commands[i].string; i++) {
104 if ((strcmp("all", argv[1]) == 0) ||
105 (strcmp(led_commands[i].string, argv[1]) == 0)) {
109 if (led_commands[i].on)
110 led_commands[i].on();
112 __led_set(led_commands[i].mask,
113 CONFIG_LED_STATUS_ON);
116 if (led_commands[i].off)
117 led_commands[i].off();
119 __led_set(led_commands[i].mask,
120 CONFIG_LED_STATUS_OFF);
123 if (led_commands[i].toggle)
124 led_commands[i].toggle();
126 __led_toggle(led_commands[i].mask);
130 return CMD_RET_USAGE;
132 freq = simple_strtoul(argv[3], NULL, 10);
133 __led_blink(led_commands[i].mask, freq);
135 /* Need to set only 1 led if led_name wasn't 'all' */
136 if (strcmp("all", argv[1]) != 0)
141 /* If we ran out of matches, print Usage */
143 return CMD_RET_USAGE;
150 led, 4, 1, do_legacy_led,
152 #ifdef CONFIG_LED_STATUS_BOARD_SPECIFIC
153 #ifdef CONFIG_LED_STATUS0
156 #ifdef CONFIG_LED_STATUS1
159 #ifdef CONFIG_LED_STATUS2
162 #ifdef CONFIG_LED_STATUS3
165 #ifdef CONFIG_LED_STATUS4
168 #ifdef CONFIG_LED_STATUS5
172 #ifdef CONFIG_LED_STATUS_GREEN
175 #ifdef CONFIG_LED_STATUS_YELLOW
178 #ifdef CONFIG_LED_STATUS_RED
181 #ifdef CONFIG_LED_STATUS_BLUE
184 "all] [on|off|toggle|blink] [blink-freq in ms]",
185 "[led_name] [on|off|toggle|blink] sets or clears led(s)"