Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
huang lin | cc2244b | 2015-11-17 14:20:09 +0800 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2015 Rockchip Electronics Co., Ltd |
huang lin | cc2244b | 2015-11-17 14:20:09 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
Philipp Tomsich | cb91173 | 2017-07-14 18:09:25 +0200 | [diff] [blame] | 6 | #include <common.h> |
Kever Yang | 15f09a1 | 2019-03-28 11:01:23 +0800 | [diff] [blame] | 7 | #include <asm/arch-rockchip/timer.h> |
huang lin | cc2244b | 2015-11-17 14:20:09 +0800 | [diff] [blame] | 8 | #include <asm/io.h> |
huang lin | cc2244b | 2015-11-17 14:20:09 +0800 | [diff] [blame] | 9 | #include <linux/types.h> |
| 10 | |
| 11 | struct rk_timer * const timer_ptr = (void *)CONFIG_SYS_TIMER_BASE; |
| 12 | |
| 13 | static 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 | |
huang lin | cc2244b | 2015-11-17 14:20:09 +0800 | [diff] [blame] | 23 | void rockchip_udelay(unsigned int usec) |
| 24 | { |
| 25 | uint64_t tmp; |
| 26 | |
| 27 | /* get timestamp */ |
| 28 | tmp = rockchip_get_ticks() + usec_to_tick(usec); |
| 29 | |
| 30 | /* loop till event */ |
| 31 | while (rockchip_get_ticks() < tmp+1) |
| 32 | ; |
| 33 | } |
| 34 | |
| 35 | void rockchip_timer_init(void) |
| 36 | { |
| 37 | writel(0xffffffff, &timer_ptr->timer_load_count0); |
| 38 | writel(0xffffffff, &timer_ptr->timer_load_count1); |
| 39 | writel(1, &timer_ptr->timer_ctrl_reg); |
| 40 | } |