u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
From: Javad Rahimi <javad321javad@gmail.com>
To: u-boot@lists.denx.de
Cc: jagan@amarulasolutions.com, hdegoede@redhat.com,
	andre.przywara@arm.com, Javad Rahimi <javad321javad@gmail.com>
Subject: [Cubieboard2 PATCH v1] Enable early LED support
Date: Fri, 17 Dec 2021 08:37:52 +0330	[thread overview]
Message-ID: <20211217050752.7686-1-javad321javad@gmail.com> (raw)

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@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


                 reply	other threads:[~2021-12-17  5:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211217050752.7686-1-javad321javad@gmail.com \
    --to=javad321javad@gmail.com \
    --cc=andre.przywara@arm.com \
    --cc=hdegoede@redhat.com \
    --cc=jagan@amarulasolutions.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).