All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 08/16] timer: Provide an early timer
Date: Sun, 14 Feb 2016 18:36:52 -0700	[thread overview]
Message-ID: <1455500220-1324-9-git-send-email-sjg@chromium.org> (raw)
In-Reply-To: <1455500220-1324-1-git-send-email-sjg@chromium.org>

In some cases the timer must be accessible before driver model is active.
Examples include when using CONFIG_TRACE to trace U-Boot's execution before
driver model is set up. Enable this option to use an early timer. These
functions must be supported by your timer driver: timer_early_get_count()
and timer_early_get_rate().

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/timer/Kconfig | 10 ++++++++++
 include/timer.h       | 21 +++++++++++++++++++++
 lib/time.c            | 28 +++++++++++++++++++++-------
 3 files changed, 52 insertions(+), 7 deletions(-)

diff --git a/drivers/timer/Kconfig b/drivers/timer/Kconfig
index ff65a73..cb18f12 100644
--- a/drivers/timer/Kconfig
+++ b/drivers/timer/Kconfig
@@ -9,6 +9,16 @@ config TIMER
 	  will be used. The timer is usually a 32 bits free-running up
 	  counter. There may be no real tick, and no timer interrupt.
 
+config TIMER_EARLY
+	bool "Allow timer to be used early in U-Boot"
+	depends on TIMER
+	help
+	  In some cases the timer must be accessible before driver model is
+	  active. Examples include when using CONFIG_TRACE to trace U-Boot's
+	  execution before driver model is set up. Enable this option to
+	  use an early timer. These functions must be supported by your timer
+	  driver: timer_early_get_count() and timer_early_get_rate().
+
 config ALTERA_TIMER
 	bool "Altera timer support"
 	depends on TIMER
diff --git a/include/timer.h b/include/timer.h
index f14725c..a503bfd 100644
--- a/include/timer.h
+++ b/include/timer.h
@@ -67,4 +67,25 @@ struct timer_dev_priv {
 	unsigned long clock_rate;
 };
 
+/**
+ * timer_early_get_count() - Implement timer_get_count() before driver model
+ *
+ * If CONFIG_TIMER_EARLY is enabled, this function wil be called to return
+ * the current timer value before the proper driver model timer is ready.
+ * It should be implemented by one of the timer values. This is mostly useful
+ * for tracing.
+ */
+u64 timer_early_get_count(void);
+
+/**
+ * timer_early_get_rate() - Get the timer rate before driver model
+ *
+ * If CONFIG_TIMER_EARLY is enabled, this function wil be called to return
+ * the current timer rate  in Hz before the proper driver model timer is ready.
+ * It should be implemented by one of the timer values. This is mostly useful
+ * for tracing. This corresponds to the clock_rate value in struct
+ * timer_dev_priv.
+ */
+unsigned long timer_early_get_rate(void);
+
 #endif	/* _TIMER_H_ */
diff --git a/lib/time.c b/lib/time.c
index e9f6861..f37150f 100644
--- a/lib/time.c
+++ b/lib/time.c
@@ -43,11 +43,17 @@ extern unsigned long __weak timer_read_counter(void);
 #ifdef CONFIG_TIMER
 ulong notrace get_tbclk(void)
 {
-	int ret;
+	if (!gd->timer) {
+#ifdef CONFIG_TIMER_EARLY
+		return timer_early_get_rate();
+#else
+		int ret;
 
-	ret = dm_timer_init();
-	if (ret)
-		return ret;
+		ret = dm_timer_init();
+		if (ret)
+			return ret;
+#endif
+	}
 
 	return timer_get_rate(gd->timer);
 }
@@ -57,9 +63,17 @@ uint64_t notrace get_ticks(void)
 	u64 count;
 	int ret;
 
-	ret = dm_timer_init();
-	if (ret)
-		return ret;
+	if (!gd->timer) {
+#ifdef CONFIG_TIMER_EARLY
+		return timer_early_get_count();
+#else
+		int ret;
+
+		ret = dm_timer_init();
+		if (ret)
+			return ret;
+#endif
+	}
 
 	ret = timer_get_count(gd->timer, &count);
 	if (ret)
-- 
2.7.0.rc3.207.g0ac5344

  parent reply	other threads:[~2016-02-15  1:36 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-15  1:36 [U-Boot] [PATCH 00/16] image: Fix various test failures Simon Glass
2016-02-15  1:36 ` [U-Boot] [PATCH 01/16] image: Correct the OS location code to work on sandbox Simon Glass
2016-02-15  1:36 ` [U-Boot] [PATCH 02/16] Revert "image-fit: Fix signature checking" Simon Glass
2016-02-15  1:36 ` [U-Boot] [PATCH 03/16] image: Fix FIT and vboot tests to exit sandbox correctly Simon Glass
2016-02-15  1:36 ` [U-Boot] [PATCH 04/16] trace: Fix compiler warnings in trace Simon Glass
2016-02-16  9:21   ` Bin Meng
2016-02-15  1:36 ` [U-Boot] [PATCH 05/16] lib: Don't instrument the div64 function Simon Glass
2016-02-16  9:21   ` Bin Meng
2016-02-15  1:36 ` [U-Boot] [PATCH 06/16] trace: Improve the trace test number recognition Simon Glass
2016-02-15  1:36 ` [U-Boot] [PATCH 07/16] timer: Support tracing fully Simon Glass
2016-02-16  9:21   ` Bin Meng
2016-02-23  6:37     ` Simon Glass
2016-02-15  1:36 ` Simon Glass [this message]
2016-02-16  9:21   ` [U-Boot] [PATCH 08/16] timer: Provide an early timer Bin Meng
2016-02-23  6:37     ` Simon Glass
2016-02-15  1:36 ` [U-Boot] [PATCH 09/16] timer: Set up the real timer after driver model is available Simon Glass
2016-02-16  9:21   ` Bin Meng
2016-02-15  1:36 ` [U-Boot] [PATCH 10/16] sandbox: timer: Support the early timer Simon Glass
2016-02-16  9:22   ` Bin Meng
2016-02-23  6:37     ` Simon Glass
2016-02-15  1:36 ` [U-Boot] [PATCH 11/16] sandbox: Correct ordering of defconfig Simon Glass
2016-02-15  1:36 ` [U-Boot] [PATCH 12/16] sandbox: Enable the early timer Simon Glass
2016-02-16  9:22   ` Bin Meng
2016-02-15  1:36 ` [U-Boot] [PATCH 13/16] sandbox: spi: Add more debugging to SPI emulation Simon Glass
2016-02-15 19:01   ` Jagan Teki
2016-02-15  1:36 ` [U-Boot] [PATCH 14/16] sandbox: spi: Remove an incorrect free() Simon Glass
2016-02-15 19:02   ` Jagan Teki
2016-02-15 22:37   ` Tom Rini
2016-02-15  1:36 ` [U-Boot] [PATCH 15/16] spi: Correct two error return values Simon Glass
2016-02-15 19:10   ` Jagan Teki
2016-02-15  1:37 ` [U-Boot] [PATCH 16/16] spi: Re-enable the SPI flash tests Simon Glass
2016-02-15 19:10   ` Jagan Teki
2016-02-16 22:03 ` [U-Boot] [PATCH 00/16] image: Fix various test failures Stephen Warren

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=1455500220-1324-9-git-send-email-sjg@chromium.org \
    --to=sjg@chromium.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.