[Cubieboard2 PATCH v1] Enable early LED support
Javad Rahimi
javad321javad at gmail.com
Fri Dec 17 06:07:52 CET 2021
This patch removes the "status_led_init_done" global variable.
By removing that variable, it is possible
to use LEDs early in SPL, in architectures
where .BSS is placed in DRAM area. (For example A20 series)
Signed-off-by: Javad Rahimi <javad321javad at gmail.com>
---
Changes in v1:
- "state" variable is used as initialization flag
- Helper macros defined for initialization
- Initialization is checked at begining of LED operations
drivers/misc/status_led.c | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/drivers/misc/status_led.c b/drivers/misc/status_led.c
index a6e9c03a02..23d932ec6e 100644
--- a/drivers/misc/status_led.c
+++ b/drivers/misc/status_led.c
@@ -69,17 +69,22 @@ led_dev_t led_dev[] = {
};
#define MAX_LED_DEV (sizeof(led_dev)/sizeof(led_dev_t))
+#define LED_INITIALIZED_BIT 0x8
+#define LED_STATE_MASK 0x3
-static int status_led_init_done = 0;
+#define LED_IS_INITIALIZED(x) (!!((x) & LED_INITIALIZED_BIT))
+#define LED_INITIALIZE(x) ((x) |= (LED_INITIALIZED_BIT))
+#define LED_GET_STATE(x) ((x) & LED_STATE_MASK)
void status_led_init(void)
{
led_dev_t *ld;
int i;
- for (i = 0, ld = led_dev; i < MAX_LED_DEV; i++, ld++)
+ for (i = 0, ld = led_dev; i < MAX_LED_DEV; i++, ld++) {
__led_init (ld->mask, ld->state);
- status_led_init_done = 1;
+ LED_INITIALIZE(ld->state);
+ }
}
void status_led_tick(ulong timestamp)
@@ -87,11 +92,11 @@ void status_led_tick(ulong timestamp)
led_dev_t *ld;
int i;
- if (!status_led_init_done)
- status_led_init();
-
for (i = 0, ld = led_dev; i < MAX_LED_DEV; i++, ld++) {
+ if (!LED_IS_INITIALIZED(ld->state))
+ status_led_init();
+
if (ld->state != CONFIG_LED_STATUS_BLINKING)
continue;
@@ -99,7 +104,6 @@ void status_led_tick(ulong timestamp)
__led_toggle (ld->mask);
ld->cnt -= ld->period;
}
-
}
}
@@ -110,12 +114,12 @@ void status_led_set(int led, int state)
if (led < 0 || led >= MAX_LED_DEV)
return;
- if (!status_led_init_done)
- status_led_init();
-
ld = &led_dev[led];
- ld->state = state;
+ if (!LED_IS_INITIALIZED(ld->state))
+ status_led_init();
+
+ ld->state = LED_GET_STATE(ld->state);
if (state == CONFIG_LED_STATUS_BLINKING) {
ld->cnt = 0; /* always start with full period */
state = CONFIG_LED_STATUS_ON; /* always start with LED _ON_ */
--
2.25.1
More information about the U-Boot
mailing list