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