diff options
-rw-r--r-- | arch/arm/cpu/armv7/Makefile | 6 | ||||
-rw-r--r-- | arch/arm/cpu/armv7/sp804_timer.c | 54 |
2 files changed, 60 insertions, 0 deletions
diff --git a/arch/arm/cpu/armv7/Makefile b/arch/arm/cpu/armv7/Makefile index 45dd3caec6..288d14732e 100644 --- a/arch/arm/cpu/armv7/Makefile +++ b/arch/arm/cpu/armv7/Makefile @@ -22,7 +22,13 @@ obj-$(CONFIG_ARMV7_PSCI) += psci.o psci-common.o obj-$(CONFIG_IPROC) += iproc-common/ obj-$(CONFIG_KONA) += kona-common/ + +SUPPORT_ARCH_TIMER ?= yes +ifeq ($(SUPPORT_ARCH_TIMER),no) +obj-y += sp804_timer.o +else obj-$(CONFIG_SYS_ARCH_TIMER) += arch_timer.o +endif ifneq (,$(filter s5pc1xx exynos,$(SOC))) obj-y += s5p-common/ diff --git a/arch/arm/cpu/armv7/sp804_timer.c b/arch/arm/cpu/armv7/sp804_timer.c new file mode 100644 index 0000000000..9c1ecf3fa0 --- /dev/null +++ b/arch/arm/cpu/armv7/sp804_timer.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2019, Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <common.h> +#include <asm/io.h> +#include <div64.h> +#include <bootstage.h> + +DECLARE_GLOBAL_DATA_PTR; + +#define SP804_TIMER0_BASE UL(0x1C110000) +#define SP804_TIMER1_VALUE_OFFSET UL(0x004) + +int timer_init(void) +{ + gd->arch.timer_rate_hz = CONFIG_SYS_HZ_CLOCK / CONFIG_SYS_HZ; + return 0; +} + +static inline uint32_t mmio_read_32(uintptr_t addr) +{ + return *(volatile uint32_t*)addr; +} + +unsigned long long get_ticks(void) +{ + return UINT_MAX - mmio_read_32(SP804_TIMER0_BASE + SP804_TIMER1_VALUE_OFFSET); +} + +ulong get_timer(ulong base) +{ + return lldiv(get_ticks(), gd->arch.timer_rate_hz) - base; +} + +void __udelay(unsigned long usec) +{ + unsigned long endtime; + + endtime = lldiv((unsigned long long)usec * gd->arch.timer_rate_hz, + 1000UL); + + endtime += get_ticks(); + + while (get_ticks() < endtime) + ; +} + +ulong get_tbclk(void) +{ + return gd->arch.timer_rate_hz; +} |