1 // SPDX-License-Identifier: GPL-2.0+
4 * David Feng <fenghua@phytium.com.cn>
9 #include <asm/system.h>
11 DECLARE_GLOBAL_DATA_PTR;
14 * Generic timer implementation of get_tbclk()
16 unsigned long get_tbclk(void)
19 asm volatile("mrs %0, cntfrq_el0" : "=r" (cntfrq));
24 * Generic timer implementation of timer_read_counter()
26 unsigned long timer_read_counter(void)
29 #ifdef CONFIG_SYS_FSL_ERRATUM_A008585
30 /* This erratum number needs to be confirmed to match ARM document */
34 asm volatile("mrs %0, cntpct_el0" : "=r" (cntpct));
35 #ifdef CONFIG_SYS_FSL_ERRATUM_A008585
36 asm volatile("mrs %0, cntpct_el0" : "=r" (temp));
37 while (temp != cntpct) {
38 asm volatile("mrs %0, cntpct_el0" : "=r" (cntpct));
39 asm volatile("mrs %0, cntpct_el0" : "=r" (temp));
45 uint64_t get_ticks(void)
47 unsigned long ticks = timer_read_counter();
54 unsigned long usec2ticks(unsigned long usec)
58 ticks = ((usec * (get_tbclk()/1000)) + 500) / 1000;
60 ticks = ((usec / 10) * (get_tbclk() / 100000));
65 ulong timer_get_boot_us(void)
67 u64 val = get_ticks() * 1000000;
69 return val / get_tbclk();