blob: a6e9c03a02ecda7e36fd3d195d3504e34f49b8ae [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk48b42612003-06-19 23:01:32 +00002/*
3 * (C) Copyright 2000-2003
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
wdenk48b42612003-06-19 23:01:32 +00005 */
6
7#include <common.h>
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
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.
17 */
18
19/* ------------------------------------------------------------------------- */
20
wdenk48b42612003-06-19 23:01:32 +000021typedef struct {
22 led_id_t mask;
23 int state;
24 int period;
25 int cnt;
26} led_dev_t;
27
28led_dev_t led_dev[] = {
Uri Mashiach2d8d1902017-01-19 10:51:45 +020029 { 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 },
wdenk48b42612003-06-19 23:01:32 +000040#endif
Uri Mashiach2d8d1902017-01-19 10:51:45 +020041#if defined(CONFIG_LED_STATUS2)
42 { CONFIG_LED_STATUS_BIT2,
43 CONFIG_LED_STATUS_STATE2,
44 LED_STATUS_PERIOD2,
45 0,
46 },
wdenk48b42612003-06-19 23:01:32 +000047#endif
Uri Mashiach2d8d1902017-01-19 10:51:45 +020048#if defined(CONFIG_LED_STATUS3)
49 { CONFIG_LED_STATUS_BIT3,
50 CONFIG_LED_STATUS_STATE3,
51 LED_STATUS_PERIOD3,
52 0,
53 },
wdenk48b42612003-06-19 23:01:32 +000054#endif
Uri Mashiach2d8d1902017-01-19 10:51:45 +020055#if defined(CONFIG_LED_STATUS4)
56 { CONFIG_LED_STATUS_BIT4,
57 CONFIG_LED_STATUS_STATE4,
58 LED_STATUS_PERIOD4,
59 0,
60 },
Stefan Roesea8eeaf22015-03-11 09:51:39 +010061#endif
Uri Mashiach2d8d1902017-01-19 10:51:45 +020062#if defined(CONFIG_LED_STATUS5)
63 { CONFIG_LED_STATUS_BIT5,
64 CONFIG_LED_STATUS_STATE5,
65 LED_STATUS_PERIOD5,
66 0,
67 },
Stefan Roesea8eeaf22015-03-11 09:51:39 +010068#endif
wdenk48b42612003-06-19 23:01:32 +000069};
70
71#define MAX_LED_DEV (sizeof(led_dev)/sizeof(led_dev_t))
72
73static int status_led_init_done = 0;
74
Bernhard Nortmann13cfbe52015-08-21 15:13:21 +020075void status_led_init(void)
wdenk48b42612003-06-19 23:01:32 +000076{
77 led_dev_t *ld;
78 int i;
79
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;
83}
84
Simon Glassc076e5c2019-11-14 12:57:12 -070085void status_led_tick(ulong timestamp)
wdenk48b42612003-06-19 23:01:32 +000086{
87 led_dev_t *ld;
88 int i;
89
90 if (!status_led_init_done)
Simon Glassc076e5c2019-11-14 12:57:12 -070091 status_led_init();
wdenk48b42612003-06-19 23:01:32 +000092
93 for (i = 0, ld = led_dev; i < MAX_LED_DEV; i++, ld++) {
94
Uri Mashiach2d8d1902017-01-19 10:51:45 +020095 if (ld->state != CONFIG_LED_STATUS_BLINKING)
wdenk48b42612003-06-19 23:01:32 +000096 continue;
97
98 if (++ld->cnt >= ld->period) {
99 __led_toggle (ld->mask);
100 ld->cnt -= ld->period;
101 }
102
103 }
104}
105
Simon Glassc076e5c2019-11-14 12:57:12 -0700106void status_led_set(int led, int state)
wdenk48b42612003-06-19 23:01:32 +0000107{
108 led_dev_t *ld;
109
110 if (led < 0 || led >= MAX_LED_DEV)
111 return;
112
113 if (!status_led_init_done)
Simon Glassc076e5c2019-11-14 12:57:12 -0700114 status_led_init();
wdenk48b42612003-06-19 23:01:32 +0000115
116 ld = &led_dev[led];
117
118 ld->state = state;
Uri Mashiach2d8d1902017-01-19 10:51:45 +0200119 if (state == CONFIG_LED_STATUS_BLINKING) {
wdenk48b42612003-06-19 23:01:32 +0000120 ld->cnt = 0; /* always start with full period */
Uri Mashiach2d8d1902017-01-19 10:51:45 +0200121 state = CONFIG_LED_STATUS_ON; /* always start with LED _ON_ */
wdenk48b42612003-06-19 23:01:32 +0000122 }
123 __led_set (ld->mask, state);
124}