]> Git Repo - J-u-boot.git/blame - drivers/misc/status_led.c
efi_selftest: simplify Makefile
[J-u-boot.git] / drivers / misc / status_led.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
6a30c4ca 2/*
48b42616 3 * (C) Copyright 2000-2003
6a30c4ca 4 * Wolfgang Denk, DENX Software Engineering, [email protected].
6a30c4ca
WD
5 */
6
7#include <common.h>
6a30c4ca
WD
8#include <status_led.h>
9
10/*
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
48b42616 13 * U-Boot, a status LED is blinking. As soon as a valid BOOTP reply
6a30c4ca
WD
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.
17 */
18
19/* ------------------------------------------------------------------------- */
20
6a30c4ca 21typedef struct {
48b42616
WD
22 led_id_t mask;
23 int state;
24 int period;
25 int cnt;
6a30c4ca
WD
26} led_dev_t;
27
28led_dev_t led_dev[] = {
2d8d190c
UM
29 { CONFIG_LED_STATUS_BIT,
30 CONFIG_LED_STATUS_STATE,
31 LED_STATUS_PERIOD,
32 0,
33 },
34#if defined(CONFIG_LED_STATUS1)
35 { CONFIG_LED_STATUS_BIT1,
36 CONFIG_LED_STATUS_STATE1,
37 LED_STATUS_PERIOD1,
38 0,
39 },
6a30c4ca 40#endif
2d8d190c
UM
41#if defined(CONFIG_LED_STATUS2)
42 { CONFIG_LED_STATUS_BIT2,
43 CONFIG_LED_STATUS_STATE2,
44 LED_STATUS_PERIOD2,
45 0,
46 },
6a30c4ca 47#endif
2d8d190c
UM
48#if defined(CONFIG_LED_STATUS3)
49 { CONFIG_LED_STATUS_BIT3,
50 CONFIG_LED_STATUS_STATE3,
51 LED_STATUS_PERIOD3,
52 0,
53 },
6a30c4ca 54#endif
2d8d190c
UM
55#if defined(CONFIG_LED_STATUS4)
56 { CONFIG_LED_STATUS_BIT4,
57 CONFIG_LED_STATUS_STATE4,
58 LED_STATUS_PERIOD4,
59 0,
60 },
a8eeaf2f 61#endif
2d8d190c
UM
62#if defined(CONFIG_LED_STATUS5)
63 { CONFIG_LED_STATUS_BIT5,
64 CONFIG_LED_STATUS_STATE5,
65 LED_STATUS_PERIOD5,
66 0,
67 },
a8eeaf2f 68#endif
6a30c4ca
WD
69};
70
71#define MAX_LED_DEV (sizeof(led_dev)/sizeof(led_dev_t))
72
73static int status_led_init_done = 0;
74
13cfbe51 75void status_led_init(void)
6a30c4ca 76{
48b42616
WD
77 led_dev_t *ld;
78 int i;
6a30c4ca 79
48b42616
WD
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;
6a30c4ca
WD
83}
84
c076e5c9 85void status_led_tick(ulong timestamp)
6a30c4ca 86{
48b42616
WD
87 led_dev_t *ld;
88 int i;
89
90 if (!status_led_init_done)
c076e5c9 91 status_led_init();
6a30c4ca 92
48b42616 93 for (i = 0, ld = led_dev; i < MAX_LED_DEV; i++, ld++) {
6a30c4ca 94
2d8d190c 95 if (ld->state != CONFIG_LED_STATUS_BLINKING)
48b42616 96 continue;
6a30c4ca 97
48b42616
WD
98 if (++ld->cnt >= ld->period) {
99 __led_toggle (ld->mask);
100 ld->cnt -= ld->period;
101 }
6a30c4ca 102
6a30c4ca 103 }
6a30c4ca
WD
104}
105
c076e5c9 106void status_led_set(int led, int state)
6a30c4ca 107{
48b42616
WD
108 led_dev_t *ld;
109
110 if (led < 0 || led >= MAX_LED_DEV)
111 return;
112
113 if (!status_led_init_done)
c076e5c9 114 status_led_init();
48b42616
WD
115
116 ld = &led_dev[led];
117
118 ld->state = state;
2d8d190c 119 if (state == CONFIG_LED_STATUS_BLINKING) {
48b42616 120 ld->cnt = 0; /* always start with full period */
2d8d190c 121 state = CONFIG_LED_STATUS_ON; /* always start with LED _ON_ */
48b42616
WD
122 }
123 __led_set (ld->mask, state);
6a30c4ca 124}
This page took 0.519363 seconds and 4 git commands to generate.