From: Sean Anderson <seanga2@gmail.com>
To: u-boot@lists.denx.de
Subject: [PATCH v4 2/8] timer: Add helper for drivers using timebase fallback
Date: Wed, 9 Sep 2020 16:09:24 -0400 [thread overview]
Message-ID: <20200909200930.232174-3-seanga2@gmail.com> (raw)
In-Reply-To: <20200909200930.232174-1-seanga2@gmail.com>
This function is designed to be used when a timer used to be initialized by
the cpu (e.g. RISC-V timers), but now is initialized by dm_timer_init. In
such a case, the timer may prefer to use the clocks and clock-frequency
properties, but should be able to fall back on using the cpu's
timebase-frequency.
Signed-off-by: Sean Anderson <seanga2@gmail.com>
---
Changes in v4:
- New
drivers/timer/timer-uclass.c | 25 +++++++++++++++++++++++++
include/timer.h | 15 +++++++++++++++
2 files changed, 40 insertions(+)
diff --git a/drivers/timer/timer-uclass.c b/drivers/timer/timer-uclass.c
index 14dde950a1..fb2f4c351a 100644
--- a/drivers/timer/timer-uclass.c
+++ b/drivers/timer/timer-uclass.c
@@ -4,6 +4,7 @@
*/
#include <common.h>
+#include <cpu.h>
#include <dm.h>
#include <init.h>
#include <dm/lists.h>
@@ -79,6 +80,30 @@ static int timer_post_probe(struct udevice *dev)
return 0;
}
+int timer_timebase_fallback(struct udevice *dev)
+{
+ struct udevice *cpu;
+ struct cpu_platdata *cpu_plat;
+ struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
+
+ /* Did we get our clock rate from the device tree? */
+ if (uc_priv->clock_rate)
+ return 0;
+
+ /* Fall back to timebase-frequency */
+ dev_dbg(dev, "missing clocks or clock-frequency property; falling back on timebase-frequency\n");
+ cpu = cpu_get_current_dev();
+ if (!cpu)
+ return -ENODEV;
+
+ cpu_plat = dev_get_parent_platdata(cpu);
+ if (!cpu_plat)
+ return -ENODEV;
+
+ uc_priv->clock_rate = cpu_plat->timebase_freq;
+ return 0;
+}
+
u64 timer_conv_64(u32 count)
{
/* increment tbh if tbl has rolled over */
diff --git a/include/timer.h b/include/timer.h
index a49b500ce3..8b9fa51c53 100644
--- a/include/timer.h
+++ b/include/timer.h
@@ -15,6 +15,21 @@
*/
int dm_timer_init(void);
+/**
+ * timer_timebase_fallback() - Helper for timers using timebase fallback
+ * @dev: A timer partially-probed timer device
+ *
+ * This is a helper function designed for timers which need to fall back on the
+ * cpu's timebase. This function is designed to be called during the driver's
+ * probe(). If there is a clocks or clock-frequency property in the timer's
+ * binding, then it will be used. Otherwise, the timebase of the current cpu
+ * will be used. This is initialized by the cpu driver, and usually gotten from
+ * ``/cpus/timebase-frequency`` or ``/cpus/cpu at X/timebase-frequency``.
+ *
+ * Return: 0 if OK, or negative error code on failure
+ */
+int timer_timebase_fallback(struct udevice *dev);
+
/*
* timer_conv_64 - convert 32-bit counter value to 64-bit
*
--
2.28.0
next prev parent reply other threads:[~2020-09-09 20:09 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-09 20:09 [PATCH v4 0/8] riscv: Clean up timer drivers Sean Anderson
2020-09-09 20:09 ` [PATCH v4 1/8] riscv: Rework riscv timer driver to only support S-mode Sean Anderson
2020-09-09 20:09 ` Sean Anderson [this message]
2020-09-10 13:38 ` [PATCH v4 2/8] timer: Add helper for drivers using timebase fallback Simon Glass
2020-09-10 15:13 ` Sean Anderson
2020-09-15 7:13 ` Bin Meng
2020-09-09 20:09 ` [PATCH v4 3/8] riscv: Rework Andes PLMT as a UCLASS_TIMER driver Sean Anderson
2020-09-15 7:18 ` Bin Meng
2020-09-15 10:04 ` Sean Anderson
2020-09-09 20:09 ` [PATCH v4 4/8] riscv: Clean up initialization in Andes PLIC Sean Anderson
2020-09-09 20:09 ` [PATCH v4 5/8] riscv: Rework Sifive CLINT as UCLASS_TIMER driver Sean Anderson
2020-09-15 8:09 ` Bin Meng
2020-09-15 10:06 ` Sean Anderson
2020-09-09 20:09 ` [PATCH v4 6/8] riscv: clk: Add CLINT clock to kendryte clock driver Sean Anderson
2020-09-09 20:09 ` [PATCH v4 7/8] riscv: Update Kendryte device tree for new CLINT driver Sean Anderson
2020-09-15 9:07 ` Bin Meng
2020-09-09 20:09 ` [PATCH v4 8/8] riscv: Update SiFive " Sean Anderson
2020-09-15 9:13 ` Bin Meng
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=20200909200930.232174-3-seanga2@gmail.com \
--to=seanga2@gmail.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