mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-19 11:24:42 +00:00
timer: riscv_aclint_timer: add timer_get_boot_us for BOOTSTAGE
timer_get_boot_us function is required to record the boot stages as us-based timestamp. To get a micro-second time from a timer tick, this converts the formula like below to avoid zero result of (tick / rate) part. From: time(us) = (tick / rate) * 1000000 To : time(us) = (tick * 1000) / (rate / 1000) Signed-off-by: Chanho Park <chanho61.park@samsung.com> Reviewed-by: Leo Yu-Chi Liang <ycliang@andestech.com>
This commit is contained in:
parent
74fbd74ed2
commit
6d78473b3d
1 changed files with 23 additions and 0 deletions
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include <common.h>
|
#include <common.h>
|
||||||
#include <clk.h>
|
#include <clk.h>
|
||||||
|
#include <div64.h>
|
||||||
#include <dm.h>
|
#include <dm.h>
|
||||||
#include <timer.h>
|
#include <timer.h>
|
||||||
#include <asm/io.h>
|
#include <asm/io.h>
|
||||||
|
@ -44,6 +45,28 @@ u64 notrace timer_early_get_count(void)
|
||||||
}
|
}
|
||||||
#endif
|
#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 = {
|
static const struct timer_ops riscv_aclint_timer_ops = {
|
||||||
.get_count = riscv_aclint_timer_get_count,
|
.get_count = riscv_aclint_timer_get_count,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue