public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Johannes Krottmayer <krjdev@gmail.com>
To: u-boot@lists.denx.de
Cc: Johannes Krottmayer <krjdev@gmail.com>,
	Wolfgang Denk <wd@denx.de>, Thomas Chou <thomas@wytron.com.tw>,
	Rick Chen <rick@andestech.com>, Leo <ycliang@andestech.com>,
	Bin Meng <bmeng.cn@gmail.com>, Sean Anderson <seanga2@gmail.com>,
	Anup Patel <anup@brainfault.org>
Subject: [PATCH 1/2] lib: time: Change behaviour of CONFIG_TIMER_EARLY
Date: Fri, 11 Mar 2022 18:11:50 +0100	[thread overview]
Message-ID: <20220311171151.29004-2-krjdev@gmail.com> (raw)
In-Reply-To: <20220311171151.29004-1-krjdev@gmail.com>

If CONFIG_TIMER_EARLY is selected and the timer driver implements
timer_early_get_count() and timer_early_get_rate(), check first
if the virtual root driver is running, when it is initialized yet
use the virtual timer driver instead. When the virtual root driver
doesn't exists fallback to the timer_early_get_count() and
timer_early_get_rate().

Signed-off-by: Johannes Krottmayer <krjdev@gmail.com>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Thomas Chou <thomas@wytron.com.tw>
Cc: Rick Chen <rick@andestech.com>
Cc: Leo <ycliang@andestech.com>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Sean Anderson <seanga2@gmail.com>
Cc: Anup Patel <anup@brainfault.org>
Cc: Thomas Chou <thomas@wytron.com.tw>
---
 lib/time.c | 42 +++++++++++++++++++++++++++++++++---------
 1 file changed, 33 insertions(+), 9 deletions(-)

diff --git a/lib/time.c b/lib/time.c
index 96074b84af..b5c9760042 100644
--- a/lib/time.c
+++ b/lib/time.c
@@ -8,6 +8,7 @@
 #include <clock_legacy.h>
 #include <bootstage.h>
 #include <dm.h>
+#include <dm/root.h>
 #include <errno.h>
 #include <init.h>
 #include <spl.h>
@@ -66,16 +67,28 @@ extern unsigned long __weak timer_read_counter(void);
 #if CONFIG_IS_ENABLED(TIMER)
 ulong notrace get_tbclk(void)
 {
-	if (!gd->timer) {
+	int ret;
+
 #ifdef CONFIG_TIMER_EARLY
+
+	/*
+	 * Check if the virtual root driver does not yet exist,
+	 * if not fallback to timer_early_get_rate().
+	 */
+	if (gd->dm_root == NULL)
 		return timer_early_get_rate();
-#else
-		int ret;
 
+#endif /* CONFIG_TIMER_EARLY */
+
+	/*
+	 * Check if the virtual timer driver does not yet exist,
+	 * if not initialize the driver.
+	 */
+	if (!gd->timer) {
 		ret = dm_timer_init();
+
 		if (ret)
-			return ret;
-#endif
+			panic("Could not initialize timer (err %d)\n", ret);
 	}
 
 	return timer_get_rate(gd->timer);
@@ -86,19 +99,30 @@ uint64_t notrace get_ticks(void)
 	u64 count;
 	int ret;
 
-	if (!gd->timer) {
 #ifdef CONFIG_TIMER_EARLY
+
+	/*
+	 * Check if the virtual root driver does not yet exist,
+	 * if not fallback to timer_early_get_rate().
+	 */
+	if (gd->dm_root == NULL)
 		return timer_early_get_count();
-#else
-		int ret;
 
+#endif /* CONFIG_TIMER_EARLY */
+
+	/*
+	 * Check if the virtual timer driver does not yet exist,
+	 * if not initialize the driver.
+	 */
+	if (!gd->timer) {
 		ret = dm_timer_init();
+
 		if (ret)
 			panic("Could not initialize timer (err %d)\n", ret);
-#endif
 	}
 
 	ret = timer_get_count(gd->timer, &count);
+
 	if (ret) {
 		if (spl_phase() > PHASE_TPL)
 			panic("Could not read count from timer (err %d)\n",
-- 
2.34.1


  reply	other threads:[~2022-03-11 17:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-11 17:11 [PATCH 0/2] Change behaviour of CONFIG_TIMER_EARLY Johannes Krottmayer
2022-03-11 17:11 ` Johannes Krottmayer [this message]
2022-03-20 17:56   ` [PATCH 1/2] lib: time: " Sean Anderson
2022-03-11 17:11 ` [PATCH 2/2] common: board_f: Fix CONFIG_TIMER_EARLY issue (EAGAIN) Johannes Krottmayer

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=20220311171151.29004-2-krjdev@gmail.com \
    --to=krjdev@gmail.com \
    --cc=anup@brainfault.org \
    --cc=bmeng.cn@gmail.com \
    --cc=rick@andestech.com \
    --cc=seanga2@gmail.com \
    --cc=thomas@wytron.com.tw \
    --cc=u-boot@lists.denx.de \
    --cc=wd@denx.de \
    --cc=ycliang@andestech.com \
    /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