3 * David Feng <fenghua@phytium.com.cn>
5 * SPDX-License-Identifier: GPL-2.0+
10 #include <asm/system.h>
12 DECLARE_GLOBAL_DATA_PTR;
15 * Generic timer implementation of get_tbclk()
17 unsigned long get_tbclk(void)
20 asm volatile("mrs %0, cntfrq_el0" : "=r" (cntfrq));
25 * Generic timer implementation of timer_read_counter()
27 unsigned long timer_read_counter(void)
30 #ifdef CONFIG_SYS_FSL_ERRATUM_A008585
31 /* This erratum number needs to be confirmed to match ARM document */
35 asm volatile("mrs %0, cntpct_el0" : "=r" (cntpct));
36 #ifdef CONFIG_SYS_FSL_ERRATUM_A008585
37 asm volatile("mrs %0, cntpct_el0" : "=r" (temp));
38 while (temp != cntpct) {
39 asm volatile("mrs %0, cntpct_el0" : "=r" (cntpct));
40 asm volatile("mrs %0, cntpct_el0" : "=r" (temp));
46 uint64_t get_ticks(void)
48 unsigned long ticks = timer_read_counter();
55 unsigned long usec2ticks(unsigned long usec)
59 ticks = ((usec * (get_tbclk()/1000)) + 500) / 1000;
61 ticks = ((usec / 10) * (get_tbclk() / 100000));