1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2000-2003
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
8 #include <status_led.h>
11 * The purpose of this code is to signal the operational status of a
12 * target which usually boots over the network; while running in
13 * U-Boot, a status LED is blinking. As soon as a valid BOOTP reply
14 * message has been received, the LED is turned off. The Linux
15 * kernel, once it is running, will start blinking the LED again,
16 * with another frequency.
19 /* ------------------------------------------------------------------------- */
28 led_dev_t led_dev
[] = {
29 { CONFIG_LED_STATUS_BIT
,
30 CONFIG_LED_STATUS_STATE
,
34 #if defined(CONFIG_LED_STATUS1)
35 { CONFIG_LED_STATUS_BIT1
,
36 CONFIG_LED_STATUS_STATE1
,
41 #if defined(CONFIG_LED_STATUS2)
42 { CONFIG_LED_STATUS_BIT2
,
43 CONFIG_LED_STATUS_STATE2
,
48 #if defined(CONFIG_LED_STATUS3)
49 { CONFIG_LED_STATUS_BIT3
,
50 CONFIG_LED_STATUS_STATE3
,
55 #if defined(CONFIG_LED_STATUS4)
56 { CONFIG_LED_STATUS_BIT4
,
57 CONFIG_LED_STATUS_STATE4
,
62 #if defined(CONFIG_LED_STATUS5)
63 { CONFIG_LED_STATUS_BIT5
,
64 CONFIG_LED_STATUS_STATE5
,
71 #define MAX_LED_DEV (sizeof(led_dev)/sizeof(led_dev_t))
73 static int status_led_init_done
= 0;
75 void status_led_init(void)
80 for (i
= 0, ld
= led_dev
; i
< MAX_LED_DEV
; i
++, ld
++)
81 __led_init (ld
->mask
, ld
->state
);
82 status_led_init_done
= 1;
85 void status_led_tick (ulong timestamp
)
90 if (!status_led_init_done
)
93 for (i
= 0, ld
= led_dev
; i
< MAX_LED_DEV
; i
++, ld
++) {
95 if (ld
->state
!= CONFIG_LED_STATUS_BLINKING
)
98 if (++ld
->cnt
>= ld
->period
) {
99 __led_toggle (ld
->mask
);
100 ld
->cnt
-= ld
->period
;
106 void status_led_set (int led
, int state
)
110 if (led
< 0 || led
>= MAX_LED_DEV
)
113 if (!status_led_init_done
)
119 if (state
== CONFIG_LED_STATUS_BLINKING
) {
120 ld
->cnt
= 0; /* always start with full period */
121 state
= CONFIG_LED_STATUS_ON
; /* always start with LED _ON_ */
123 __led_set (ld
->mask
, state
);