Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 2 | /* |
Masahiro Yamada | f6e7f07 | 2015-05-29 17:30:00 +0900 | [diff] [blame] | 3 | * Copyright (C) 2012-2015 Masahiro Yamada <yamada.masahiro@socionext.com> |
Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Masahiro Yamada | f6e7f07 | 2015-05-29 17:30:00 +0900 | [diff] [blame] | 7 | #include <linux/io.h> |
Masahiro Yamada | 107b3fb | 2016-01-09 01:51:13 +0900 | [diff] [blame] | 8 | |
| 9 | #include "arm-mpcore.h" |
Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 10 | |
| 11 | #define PERIPHCLK (50 * 1000 * 1000) /* 50 MHz */ |
| 12 | #define PRESCALER ((PERIPHCLK) / (CONFIG_SYS_TIMER_RATE) - 1) |
| 13 | |
| 14 | static void *get_global_timer_base(void) |
| 15 | { |
| 16 | void *val; |
| 17 | |
| 18 | asm("mrc p15, 4, %0, c15, c0, 0" : "=r" (val) : : "memory"); |
| 19 | |
| 20 | return val + GLOBAL_TIMER_OFFSET; |
| 21 | } |
| 22 | |
| 23 | unsigned long timer_read_counter(void) |
| 24 | { |
| 25 | /* |
| 26 | * ARM 64bit Global Timer is too much for our purpose. |
| 27 | * We use only lower 32 bit of the timer counter. |
| 28 | */ |
| 29 | return readl(get_global_timer_base() + GTIMER_CNT_L); |
| 30 | } |
| 31 | |
| 32 | int timer_init(void) |
| 33 | { |
| 34 | /* enable timer */ |
| 35 | writel(PRESCALER << 8 | 1, get_global_timer_base() + GTIMER_CTRL); |
| 36 | |
| 37 | return 0; |
| 38 | } |