summaryrefslogtreecommitdiff
path: root/board/ssv/common/cmd_sled.c
blob: cb796982b9f29092c6e5f924b18ae914cfec006d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
 * (C) Copyright 2004, Li-Pro.Net <www.li-pro.net>
 * Stephan Linz <linz@li-pro.net>
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 */

#include <common.h>
#include <command.h>
#include <status_led.h>

#if	defined(CONFIG_STATUS_LED)

/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 * !!!!!       Q u i c k   &   D i r t y   H a c k	 !!!!!
 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 * !!!!!						 !!!!!
 * !!!!! Next type definition was coming from original	 !!!!!
 * !!!!! status LED driver drivers/misc/status_led.c	 !!!!!
 * !!!!! and should be exported for using it here.	 !!!!!
 * !!!!!						 !!!!!
 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */

typedef struct {
	led_id_t mask;
	int state;
	int period;
	int cnt;
} led_dev_t;

extern led_dev_t led_dev[];

#if defined(CONFIG_CMD_BSP)
int do_sled (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
{
	int led_id = 0;

	if (argc > 1) {
#ifdef	STATUS_LED_BOOT
		if (!strcmp (argv[1], "boot")) {
			led_id = STATUS_LED_BOOT + 1;
		}
#endif
#ifdef	STATUS_LED_RED
		if (!strcmp (argv[1], "red")) {
			led_id = STATUS_LED_RED + 1;
		}
#endif
#ifdef	STATUS_LED_YELLOW
		if (!strcmp (argv[1], "yellow")) {
			led_id = STATUS_LED_YELLOW + 1;
		}
#endif
#ifdef	STATUS_LED_GREEN
		if (!strcmp (argv[1], "green")) {
			led_id = STATUS_LED_GREEN + 1;
		}
#endif
	}

	switch (argc) {
	case 1:
#if	(STATUS_LED_BITS > 3)
		for (; led_id < 4; led_id++)
#elif	(STATUS_LED_BITS > 2)
		for (; led_id < 3; led_id++)
#elif	(STATUS_LED_BITS > 1)
		for (; led_id < 2; led_id++)
#elif	(STATUS_LED_BITS > 0)
		for (; led_id < 1; led_id++)
#else
#error "*** STATUS_LED_BITS not correct defined ***"
#endif
		{
			printf ("Status LED '%s' is %s\n",
				led_id == STATUS_LED_BOOT ? "boot"
				: led_id == STATUS_LED_RED ? "red"
				: led_id == STATUS_LED_YELLOW ? "yellow"
				: led_id ==
				STATUS_LED_GREEN ? "green" : "unknown",
				led_dev[led_id].state ==
				STATUS_LED_ON ? "on" : led_dev[led_id].
				state ==
				STATUS_LED_OFF ? "off" : led_dev[led_id].
				state ==
				STATUS_LED_BLINKING ? "blinking" : "unknown");
		}
		return 0;
	case 2:
		if (led_id) {
			printf ("Status LED '%s' is %s\n", argv[1],
				led_dev[led_id - 1].state ==
				STATUS_LED_ON ? "on" : led_dev[led_id -
							       1].state ==
				STATUS_LED_OFF ? "off" : led_dev[led_id -
								 1].state ==
				STATUS_LED_BLINKING ? "blinking" : "unknown");
			return 0;
		} else
			break;
	case 3:
		if (led_id) {
			if (!strcmp (argv[2], "on")) {
				status_led_set (led_id - 1, STATUS_LED_ON);
				return 0;
			} else if (!strcmp (argv[2], "off")) {
				status_led_set (led_id - 1, STATUS_LED_OFF);
				return 0;
			} else if (!strcmp (argv[2], "blink")) {
				status_led_set (led_id - 1,
						STATUS_LED_BLINKING);
				return 0;
			} else
				break;
		} else
			break;
	default:
		break;
	}
	cmd_usage(cmdtp);
	return 1;
}

#ifdef	STATUS_LED_BOOT
#ifdef	STATUS_LED_RED
#ifdef	STATUS_LED_YELLOW
#ifdef	STATUS_LED_GREEN
#define __NAME_STR		"    - name: boot|red|yellow|green\n"
#else
#define __NAME_STR		"    - name: boot|red|yellow\n"
#endif
#else
#define __NAME_STR		"    - name: boot|red\n"
#endif
#else
#define __NAME_STR		"    - name: boot\n"
#endif
#else
#define __NAME_STR		"    - name: (no such defined)\n"
#endif

U_BOOT_CMD (sled, 3, 0, do_sled,
	    "sled    - check and set status led\n",
	    "sled [name [state]]\n" __NAME_STR "    - state: on|off|blink\n");
#endif
#endif	/* CONFIG_STATUS_LED */