diff options
author | 2023-10-10 14:33:42 +0000 | |
---|---|---|
committer | 2023-10-10 14:33:42 +0000 | |
commit | af1a266670d040d2f4083ff309d732d648afba2a (patch) | |
tree | 2fc46203448ddcc6f81546d379abfaeb323575e9 /roms/u-boot/arch/arm/cpu/armv7/arch_timer.c | |
parent | e02cda008591317b1625707ff8e115a4841aa889 (diff) |
Change-Id: Iaf8d18082d3991dec7c0ebbea540f092188eb4ec
Diffstat (limited to 'roms/u-boot/arch/arm/cpu/armv7/arch_timer.c')
-rw-r--r-- | roms/u-boot/arch/arm/cpu/armv7/arch_timer.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/roms/u-boot/arch/arm/cpu/armv7/arch_timer.c b/roms/u-boot/arch/arm/cpu/armv7/arch_timer.c new file mode 100644 index 000000000..d96406f76 --- /dev/null +++ b/roms/u-boot/arch/arm/cpu/armv7/arch_timer.c @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * (C) Copyright 2012-2014 + * Texas Instruments Incorporated, <www.ti.com> + */ + +#include <common.h> +#include <init.h> +#include <time.h> +#include <asm/global_data.h> +#include <asm/io.h> +#include <div64.h> +#include <bootstage.h> + +DECLARE_GLOBAL_DATA_PTR; + +#ifndef CONFIG_SYS_HZ_CLOCK +static inline u32 read_cntfrq(void) +{ + u32 frq; + + asm volatile("mrc p15, 0, %0, c14, c0, 0" : "=r" (frq)); + return frq; +} +#endif + +int timer_init(void) +{ + gd->arch.tbl = 0; + gd->arch.tbu = 0; + +#ifdef CONFIG_SYS_HZ_CLOCK + gd->arch.timer_rate_hz = CONFIG_SYS_HZ_CLOCK; +#else + gd->arch.timer_rate_hz = read_cntfrq(); +#endif + return 0; +} + +unsigned long long get_ticks(void) +{ + ulong nowl, nowu; + + asm volatile("mrrc p15, 0, %0, %1, c14" : "=r" (nowl), "=r" (nowu)); + + gd->arch.tbl = nowl; + gd->arch.tbu = nowu; + + return (((unsigned long long)gd->arch.tbu) << 32) | gd->arch.tbl; +} + + +ulong timer_get_boot_us(void) +{ + if (!gd->arch.timer_rate_hz) + timer_init(); + + return lldiv(get_ticks(), gd->arch.timer_rate_hz / 1000000); +} + +ulong get_tbclk(void) +{ + return gd->arch.timer_rate_hz; +} |