blob: c53195f1a3605e74440922c1ac70e8b838b50852 [file] [log] [blame]
Jason Kridner931ced02011-04-18 17:22:44 -04001/*
2 * (C) Copyright 2010
3 * Jason Kridner <jkridner@beagleboard.org>
4 *
5 * Based on cmd_led.c patch from:
6 * http://www.mail-archive.com/u-boot@lists.denx.de/msg06873.html
7 * (C) Copyright 2008
8 * Ulf Samuelsson <ulf.samuelsson@atmel.com>
9 *
10 * See file CREDITS for list of people who contributed to this
11 * project.
12 *
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.
17 *
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.
22 *
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,
26 * MA 02111-1307 USA
27 */
28
29#include <common.h>
30#include <config.h>
31#include <command.h>
32#include <status_led.h>
33
34struct led_tbl_s {
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 */
39};
40
41typedef struct led_tbl_s led_tbl_t;
42
43static const led_tbl_t led_commands[] = {
44#ifdef CONFIG_BOARD_SPECIFIC_LED
45#ifdef STATUS_LED_BIT
46 { "0", STATUS_LED_BIT, NULL, NULL },
47#endif
48#ifdef STATUS_LED_BIT1
49 { "1", STATUS_LED_BIT1, NULL, NULL },
50#endif
51#ifdef STATUS_LED_BIT2
52 { "2", STATUS_LED_BIT2, NULL, NULL },
53#endif
54#ifdef STATUS_LED_BIT3
55 { "3", STATUS_LED_BIT3, NULL, NULL },
56#endif
57#endif
58#ifdef STATUS_LED_GREEN
59 { "green", STATUS_LED_GREEN, green_LED_off, green_LED_on },
60#endif
61#ifdef STATUS_LED_YELLOW
62 { "yellow", STATUS_LED_YELLOW, yellow_LED_off, yellow_LED_on },
63#endif
64#ifdef STATUS_LED_RED
65 { "red", STATUS_LED_RED, red_LED_off, red_LED_on },
66#endif
67#ifdef STATUS_LED_BLUE
68 { "blue", STATUS_LED_BLUE, blue_LED_off, blue_LED_on },
69#endif
70 { NULL, 0, NULL, NULL }
71};
72
73int str_onoff (char *var)
74{
75 if (strcmp(var, "off") == 0) {
76 return 0;
77 }
78 if (strcmp(var, "on") == 0) {
79 return 1;
80 }
81 return -1;
82}
83
84int do_led (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
85{
86 int state, i;
87
88 /* Validate arguments */
89 if ((argc != 3)) {
90 return cmd_usage(cmdtp);
91 }
92
93 state = str_onoff(argv[2]);
94 if (state < 0) {
95 return cmd_usage(cmdtp);
96 }
97
98 for (i = 0; led_commands[i].string; i++) {
Wolfgang Denk80f70212011-05-19 22:21:41 +020099 if ((strcmp("all", argv[1]) == 0) ||
Jason Kridner931ced02011-04-18 17:22:44 -0400100 (strcmp(led_commands[i].string, argv[1]) == 0)) {
101 if (led_commands[i].on) {
102 if (state) {
103 led_commands[i].on();
104 } else {
105 led_commands[i].off();
106 }
107 } else {
108 __led_set(led_commands[i].mask, state);
109 }
110 break;
111 }
112 }
113
114 /* If we ran out of matches, print Usage */
115 if (!led_commands[i].string && !(strcmp("all", argv[1]) == 0)) {
116 return cmd_usage(cmdtp);
117 }
118
119 return 0;
120}
121
122U_BOOT_CMD(
123 led, 3, 1, do_led,
124 "led\t- ["
125#ifdef CONFIG_BOARD_SPECIFIC_LED
126#ifdef STATUS_LED_BIT
127 "0|"
128#endif
129#ifdef STATUS_LED_BIT1
130 "1|"
131#endif
132#ifdef STATUS_LED_BIT2
133 "2|"
134#endif
135#ifdef STATUS_LED_BIT3
136 "3|"
137#endif
138#endif
139#ifdef STATUS_LED_GREEN
140 "green|"
141#endif
142#ifdef STATUS_LED_YELLOW
143 "yellow|"
144#endif
145#ifdef STATUS_LED_RED
146 "red|"
147#endif
148#ifdef STATUS_LED_BLUE
149 "blue|"
150#endif
151 "all] [on|off]\n",
152 "led [led_name] [on|off] sets or clears led(s)\n"
153);