Angel Pons | 1ddb894 | 2020-04-04 18:51:26 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
David Hendricks | 5ec69ed | 2013-05-02 13:23:08 -0700 | [diff] [blame] | 2 | |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 3 | #include <device/mmio.h> |
Julius Werner | 44cf870 | 2014-12-08 13:39:14 -0800 | [diff] [blame] | 4 | #include <delay.h> |
Julius Werner | 1ed0c8c | 2014-10-20 13:16:29 -0700 | [diff] [blame] | 5 | #include <soc/clk.h> |
David Hendricks | 5ec69ed | 2013-05-02 13:23:08 -0700 | [diff] [blame] | 6 | #include <stdint.h> |
David Hendricks | 5ec69ed | 2013-05-02 13:23:08 -0700 | [diff] [blame] | 7 | #include <timer.h> |
David Hendricks | 5ec69ed | 2013-05-02 13:23:08 -0700 | [diff] [blame] | 8 | |
David Hendricks | 5ec69ed | 2013-05-02 13:23:08 -0700 | [diff] [blame] | 9 | static const uint32_t clocks_per_usec = MCT_HZ/1000000; |
10 | |||||
Julius Werner | 44cf870 | 2014-12-08 13:39:14 -0800 | [diff] [blame] | 11 | static uint64_t mct_raw_value(void) |
Julius Werner | 8d978a8 | 2014-12-08 13:16:03 -0800 | [diff] [blame] | 12 | { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 13 | uint64_t upper = read32(&exynos_mct->g_cnt_u); |
14 | uint64_t lower = read32(&exynos_mct->g_cnt_l); | ||||
Julius Werner | 8d978a8 | 2014-12-08 13:16:03 -0800 | [diff] [blame] | 15 | |
16 | return (upper << 32) | lower; | ||||
17 | } | ||||
18 | |||||
Julius Werner | 44cf870 | 2014-12-08 13:39:14 -0800 | [diff] [blame] | 19 | void init_timer(void) |
Julius Werner | 8d978a8 | 2014-12-08 13:16:03 -0800 | [diff] [blame] | 20 | { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 21 | write32(&exynos_mct->g_tcon, read32(&exynos_mct->g_tcon) | (0x1 << 8)); |
Julius Werner | 8d978a8 | 2014-12-08 13:16:03 -0800 | [diff] [blame] | 22 | } |
23 | |||||
David Hendricks | 5ec69ed | 2013-05-02 13:23:08 -0700 | [diff] [blame] | 24 | void timer_monotonic_get(struct mono_time *mt) |
25 | { | ||||
Stefan Reinauer | 6ada053 | 2013-09-11 15:18:14 -0700 | [diff] [blame] | 26 | /* We don't have to call mct_start() here |
27 | * because it was already called in the bootblock | ||||
28 | */ | ||||
David Hendricks | 5ec69ed | 2013-05-02 13:23:08 -0700 | [diff] [blame] | 29 | |
Gabe Black | 6ccc45d | 2013-08-09 00:48:06 -0700 | [diff] [blame] | 30 | mono_time_set_usecs(mt, mct_raw_value() / clocks_per_usec); |
David Hendricks | 5ec69ed | 2013-05-02 13:23:08 -0700 | [diff] [blame] | 31 | } |