2 * (C) Copyright 2015 Rockchip Electronics Co., Ltd
4 * SPDX-License-Identifier: GPL-2.0+
7 #include <asm/arch/timer.h>
10 #include <linux/types.h>
12 struct rk_timer * const timer_ptr = (void *)CONFIG_SYS_TIMER_BASE;
14 static uint64_t rockchip_get_ticks(void)
16 uint64_t timebase_h, timebase_l;
18 timebase_l = readl(&timer_ptr->timer_curr_value0);
19 timebase_h = readl(&timer_ptr->timer_curr_value1);
21 return timebase_h << 32 | timebase_l;
24 static uint64_t usec_to_tick(unsigned int usec)
27 tick *= CONFIG_SYS_TIMER_RATE / (1000 * 1000);
31 void rockchip_udelay(unsigned int usec)
36 tmp = rockchip_get_ticks() + usec_to_tick(usec);
39 while (rockchip_get_ticks() < tmp+1)
43 void rockchip_timer_init(void)
45 writel(0xffffffff, &timer_ptr->timer_load_count0);
46 writel(0xffffffff, &timer_ptr->timer_load_count1);
47 writel(1, &timer_ptr->timer_ctrl_reg);