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 * See file CREDITS for list of people who contributed to this
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation; either version 2 of
16 * the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 #include <status_led.h>
35 char *string; /* String for use in the command */
36 led_id_t mask; /* Mask used for calling __led_set() */
37 void (*off)(void); /* Optional function for turning LED off */
38 void (*on)(void); /* Optional function for turning LED on */
39 void (*toggle)(void);/* Optional function for toggling LED */
42 typedef struct led_tbl_s led_tbl_t;
44 static const led_tbl_t led_commands[] = {
45 #ifdef CONFIG_BOARD_SPECIFIC_LED
47 { "0", STATUS_LED_BIT, NULL, NULL, NULL },
49 #ifdef STATUS_LED_BIT1
50 { "1", STATUS_LED_BIT1, NULL, NULL, NULL },
52 #ifdef STATUS_LED_BIT2
53 { "2", STATUS_LED_BIT2, NULL, NULL, NULL },
55 #ifdef STATUS_LED_BIT3
56 { "3", STATUS_LED_BIT3, NULL, NULL, NULL },
59 #ifdef STATUS_LED_GREEN
60 { "green", STATUS_LED_GREEN, green_led_off, green_led_on, NULL },
62 #ifdef STATUS_LED_YELLOW
63 { "yellow", STATUS_LED_YELLOW, yellow_led_off, yellow_led_on, NULL },
66 { "red", STATUS_LED_RED, red_led_off, red_led_on, NULL },
68 #ifdef STATUS_LED_BLUE
69 { "blue", STATUS_LED_BLUE, blue_led_off, blue_led_on, NULL },
71 { NULL, 0, NULL, NULL, NULL }
74 enum led_cmd { LED_ON, LED_OFF, LED_TOGGLE };
76 enum led_cmd get_led_cmd(char *var)
78 if (strcmp(var, "off") == 0) {
81 if (strcmp(var, "on") == 0) {
84 if (strcmp(var, "toggle") == 0)
89 int do_led (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
94 /* Validate arguments */
96 return cmd_usage(cmdtp);
99 cmd = get_led_cmd(argv[2]);
101 return cmd_usage(cmdtp);
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, 1);
116 if (led_commands[i].off)
117 led_commands[i].off();
119 __led_set(led_commands[i].mask, 0);
122 if (led_commands[i].toggle)
123 led_commands[i].toggle();
125 __led_toggle(led_commands[i].mask);
127 /* Need to set only 1 led if led_name wasn't 'all' */
128 if (strcmp("all", argv[1]) != 0)
133 /* If we ran out of matches, print Usage */
135 return cmd_usage(cmdtp);
144 #ifdef CONFIG_BOARD_SPECIFIC_LED
145 #ifdef STATUS_LED_BIT
148 #ifdef STATUS_LED_BIT1
151 #ifdef STATUS_LED_BIT2
154 #ifdef STATUS_LED_BIT3
158 #ifdef STATUS_LED_GREEN
161 #ifdef STATUS_LED_YELLOW
164 #ifdef STATUS_LED_RED
167 #ifdef STATUS_LED_BLUE
170 "all] [on|off|toggle]\n",
171 "led [led_name] [on|off|toggle] sets or clears led(s)\n"