]>
git.ipfire.org Git - people/ms/u-boot.git/blob - common/cmd_led.c
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 (*on
)(void); /* Optional fucntion for turning LED on */
38 void (*off
)(void); /* Optional fucntion for turning LED on */
41 typedef struct led_tbl_s led_tbl_t
;
43 static const led_tbl_t led_commands
[] = {
44 #ifdef CONFIG_BOARD_SPECIFIC_LED
46 { "0", STATUS_LED_BIT
, NULL
, NULL
},
48 #ifdef STATUS_LED_BIT1
49 { "1", STATUS_LED_BIT1
, NULL
, NULL
},
51 #ifdef STATUS_LED_BIT2
52 { "2", STATUS_LED_BIT2
, NULL
, NULL
},
54 #ifdef STATUS_LED_BIT3
55 { "3", STATUS_LED_BIT3
, NULL
, NULL
},
58 #ifdef STATUS_LED_GREEN
59 { "green", STATUS_LED_GREEN
, green_LED_off
, green_LED_on
},
61 #ifdef STATUS_LED_YELLOW
62 { "yellow", STATUS_LED_YELLOW
, yellow_LED_off
, yellow_LED_on
},
65 { "red", STATUS_LED_RED
, red_LED_off
, red_LED_on
},
67 #ifdef STATUS_LED_BLUE
68 { "blue", STATUS_LED_BLUE
, blue_LED_off
, blue_LED_on
},
70 { NULL
, 0, NULL
, NULL
}
73 int str_onoff (char *var
)
75 if (strcmp(var
, "off") == 0) {
78 if (strcmp(var
, "on") == 0) {
84 int do_led (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
86 int state
, i
, match
= 0;
88 /* Validate arguments */
90 return cmd_usage(cmdtp
);
93 state
= str_onoff(argv
[2]);
95 return cmd_usage(cmdtp
);
98 for (i
= 0; led_commands
[i
].string
; i
++) {
99 if ((strcmp("all", argv
[1]) == 0) ||
100 (strcmp(led_commands
[i
].string
, argv
[1]) == 0)) {
102 if (led_commands
[i
].on
) {
104 led_commands
[i
].on();
106 led_commands
[i
].off();
109 __led_set(led_commands
[i
].mask
, state
);
115 /* If we ran out of matches, print Usage */
117 return cmd_usage(cmdtp
);
126 #ifdef CONFIG_BOARD_SPECIFIC_LED
127 #ifdef STATUS_LED_BIT
130 #ifdef STATUS_LED_BIT1
133 #ifdef STATUS_LED_BIT2
136 #ifdef STATUS_LED_BIT3
140 #ifdef STATUS_LED_GREEN
143 #ifdef STATUS_LED_YELLOW
146 #ifdef STATUS_LED_RED
149 #ifdef STATUS_LED_BLUE
153 "led [led_name] [on|off] sets or clears led(s)\n"