blob: e751f29d0f64611f1377e11505b4266331cf032a [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
huang lin8db3e242015-11-17 14:20:09 +08002/*
3 * (C) Copyright 2015 Rockchip Electronics Co., Ltd
huang lin8db3e242015-11-17 14:20:09 +08004 */
5
Philipp Tomsich8592ac02017-07-14 18:09:25 +02006#include <common.h>
huang lin8db3e242015-11-17 14:20:09 +08007#include <asm/arch/timer.h>
8#include <asm/io.h>
huang lin8db3e242015-11-17 14:20:09 +08009#include <linux/types.h>
10
11struct rk_timer * const timer_ptr = (void *)CONFIG_SYS_TIMER_BASE;
12
13static uint64_t rockchip_get_ticks(void)
14{
15 uint64_t timebase_h, timebase_l;
16
17 timebase_l = readl(&timer_ptr->timer_curr_value0);
18 timebase_h = readl(&timer_ptr->timer_curr_value1);
19
20 return timebase_h << 32 | timebase_l;
21}
22
23static uint64_t usec_to_tick(unsigned int usec)
24{
25 uint64_t tick = usec;
26 tick *= CONFIG_SYS_TIMER_RATE / (1000 * 1000);
27 return tick;
28}
29
30void rockchip_udelay(unsigned int usec)
31{
32 uint64_t tmp;
33
34 /* get timestamp */
35 tmp = rockchip_get_ticks() + usec_to_tick(usec);
36
37 /* loop till event */
38 while (rockchip_get_ticks() < tmp+1)
39 ;
40}
41
42void rockchip_timer_init(void)
43{
44 writel(0xffffffff, &timer_ptr->timer_load_count0);
45 writel(0xffffffff, &timer_ptr->timer_load_count1);
46 writel(1, &timer_ptr->timer_ctrl_reg);
47}