blob: 4ba3e180440584c15d091e06b4d47ca1c1b5cccc [file] [log] [blame]
wdenk48b42612003-06-19 23:01:32 +00001/*
2 * (C) Copyright 2000-2003
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
25#include <status_led.h>
26
27/*
28 * The purpose of this code is to signal the operational status of a
29 * target which usually boots over the network; while running in
30 * U-Boot, a status LED is blinking. As soon as a valid BOOTP reply
31 * message has been received, the LED is turned off. The Linux
32 * kernel, once it is running, will start blinking the LED again,
33 * with another frequency.
34 */
35
36/* ------------------------------------------------------------------------- */
37
wdenk48b42612003-06-19 23:01:32 +000038typedef struct {
39 led_id_t mask;
40 int state;
41 int period;
42 int cnt;
43} led_dev_t;
44
45led_dev_t led_dev[] = {
46 { STATUS_LED_BIT,
47 STATUS_LED_STATE,
48 STATUS_LED_PERIOD,
49 0,
50 },
51#if defined(STATUS_LED_BIT1)
52 { STATUS_LED_BIT1,
53 STATUS_LED_STATE1,
54 STATUS_LED_PERIOD1,
55 0,
56 },
57#endif
58#if defined(STATUS_LED_BIT2)
59 { STATUS_LED_BIT2,
60 STATUS_LED_STATE2,
61 STATUS_LED_PERIOD2,
62 0,
63 },
64#endif
65#if defined(STATUS_LED_BIT3)
66 { STATUS_LED_BIT3,
67 STATUS_LED_STATE3,
68 STATUS_LED_PERIOD3,
69 0,
70 },
71#endif
72};
73
74#define MAX_LED_DEV (sizeof(led_dev)/sizeof(led_dev_t))
75
76static int status_led_init_done = 0;
77
78static void status_led_init (void)
79{
80 led_dev_t *ld;
81 int i;
82
83 for (i = 0, ld = led_dev; i < MAX_LED_DEV; i++, ld++)
84 __led_init (ld->mask, ld->state);
85 status_led_init_done = 1;
86}
87
88void status_led_tick (ulong timestamp)
89{
90 led_dev_t *ld;
91 int i;
92
93 if (!status_led_init_done)
94 status_led_init ();
95
96 for (i = 0, ld = led_dev; i < MAX_LED_DEV; i++, ld++) {
97
98 if (ld->state != STATUS_LED_BLINKING)
99 continue;
100
101 if (++ld->cnt >= ld->period) {
102 __led_toggle (ld->mask);
103 ld->cnt -= ld->period;
104 }
105
106 }
107}
108
109void status_led_set (int led, int state)
110{
111 led_dev_t *ld;
112
113 if (led < 0 || led >= MAX_LED_DEV)
114 return;
115
116 if (!status_led_init_done)
117 status_led_init ();
118
119 ld = &led_dev[led];
120
121 ld->state = state;
122 if (state == STATUS_LED_BLINKING) {
123 ld->cnt = 0; /* always start with full period */
124 state = STATUS_LED_ON; /* always start with LED _ON_ */
125 }
126 __led_set (ld->mask, state);
127}