summaryrefslogtreecommitdiff
path: root/drivers/timer/riscv_aclint_timer.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2023-10-05 13:26:44 -0400
committerTom Rini <trini@konsulko.com>2023-10-05 13:26:44 -0400
commitbe2abe73df58a35da9e8d5afb13fccdf1b0faa8e (patch)
treea41b676d6169cd846d33dcf18c8e8c6ea181784c /drivers/timer/riscv_aclint_timer.c
parentcb59d23584a7a0f2431025a56f4938d424c49ca5 (diff)
parent7cfdacbe8020292845bd5eba63b576b8586c433c (diff)
Merge https://source.denx.de/u-boot/custodians/u-boot-riscv
+ ae350: modify memory layout and target name + ae350: use generic RISC-V timer driver in S-mode + Support bootstage report for RISC-V + Support C extension exception command for RISC-V + Add Starfive timer support
Diffstat (limited to 'drivers/timer/riscv_aclint_timer.c')
-rw-r--r--drivers/timer/riscv_aclint_timer.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/drivers/timer/riscv_aclint_timer.c b/drivers/timer/riscv_aclint_timer.c
index e29d527c8d7..73fb8791285 100644
--- a/drivers/timer/riscv_aclint_timer.c
+++ b/drivers/timer/riscv_aclint_timer.c
@@ -6,6 +6,7 @@
#include <common.h>
#include <clk.h>
+#include <div64.h>
#include <dm.h>
#include <timer.h>
#include <asm/io.h>
@@ -44,6 +45,28 @@ u64 notrace timer_early_get_count(void)
}
#endif
+#if CONFIG_IS_ENABLED(RISCV_MMODE) && CONFIG_IS_ENABLED(BOOTSTAGE)
+ulong timer_get_boot_us(void)
+{
+ int ret;
+ u64 ticks = 0;
+ u32 rate;
+
+ ret = dm_timer_init();
+ if (!ret) {
+ rate = timer_get_rate(gd->timer);
+ timer_get_count(gd->timer, &ticks);
+ } else {
+ rate = RISCV_MMODE_TIMER_FREQ;
+ ticks = readq((void __iomem *)MTIME_REG(RISCV_MMODE_TIMERBASE,
+ RISCV_MMODE_TIMEROFF));
+ }
+
+ /* Below is converted from time(us) = (tick / rate) * 10000000 */
+ return lldiv(ticks * 1000, (rate / 1000));
+}
+#endif
+
static const struct timer_ops riscv_aclint_timer_ops = {
.get_count = riscv_aclint_timer_get_count,
};