u-boot.lists.denx.de archive mirror
 help / color / mirror / Atom feed
From: Stefan Roese <sr@denx.de>
To: u-boot@lists.denx.de
Cc: "Pali Rohár" <pali@kernel.org>,
	"Michael Walle" <michael@walle.cc>,
	"Tony Dinh" <mibodhi@gmail.com>
Subject: [PATCH] timer: orion-timer: Fix problem with early static variable
Date: Wed, 21 Dec 2022 10:18:49 +0100	[thread overview]
Message-ID: <20221221091849.1018783-1-sr@denx.de> (raw)

We've noticed that at least one Kirkwood board (Pogo v4) has problems
with the new orion DM timer implementation. Debugging revealed that this
issue is related with the static variable "early_init_done" which does
not work correctly before relocation in all cases.

This patch removes this static variable and replaces it's functionality
via a function that detects if the timer is already initialized.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Pali Rohár <pali@kernel.org>
Cc: Michael Walle <michael@walle.cc>
Cc: Tony Dinh <mibodhi@gmail.com>
---
 drivers/timer/orion-timer.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/timer/orion-timer.c b/drivers/timer/orion-timer.c
index d0eab3ce781d..6804bf0fa2cb 100644
--- a/drivers/timer/orion-timer.c
+++ b/drivers/timer/orion-timer.c
@@ -23,15 +23,19 @@ struct orion_timer_priv {
 
 #define MVEBU_TIMER_FIXED_RATE_25MHZ	25000000
 
-static bool early_init_done __section(".data") = false;
+static bool early_init_done(void *base)
+{
+	if (readl(base + TIMER_CTRL) & TIMER0_EN)
+		return true;
+	return false;
+}
 
 /* Common functions for early (boot) and DM based timer */
 static void orion_timer_init(void *base, enum input_clock_type type)
 {
 	/* Only init the timer once */
-	if (early_init_done)
+	if (early_init_done(base))
 		return;
-	early_init_done = true;
 
 	writel(~0, base + TIMER0_VAL);
 	writel(~0, base + TIMER0_RELOAD);
-- 
2.39.0


             reply	other threads:[~2022-12-21  9:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-21  9:18 Stefan Roese [this message]
2022-12-21 22:48 ` [PATCH] timer: orion-timer: Fix problem with early static variable Tony Dinh
2023-01-02 10:47 ` Stefan Roese

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=20221221091849.1018783-1-sr@denx.de \
    --to=sr@denx.de \
    --cc=mibodhi@gmail.com \
    --cc=michael@walle.cc \
    --cc=pali@kernel.org \
    --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).