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