David Hendricks | 5ec69ed | 2013-05-02 13:23:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Stefan Reinauer | 08dc357 | 2013-05-14 16:57:50 -0700 | [diff] [blame] | 4 | * Copyright 2013 Google Inc. |
David Hendricks | 5ec69ed | 2013-05-02 13:23:08 -0700 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
David Hendricks | 5ec69ed | 2013-05-02 13:23:08 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
Julius Werner | 8d978a8 | 2014-12-08 13:16:03 -0800 | [diff] [blame] | 16 | #include <arch/io.h> |
Julius Werner | 44cf870 | 2014-12-08 13:39:14 -0800 | [diff] [blame] | 17 | #include <delay.h> |
Julius Werner | 1ed0c8c | 2014-10-20 13:16:29 -0700 | [diff] [blame] | 18 | #include <soc/clk.h> |
David Hendricks | 5ec69ed | 2013-05-02 13:23:08 -0700 | [diff] [blame] | 19 | #include <stdint.h> |
David Hendricks | 5ec69ed | 2013-05-02 13:23:08 -0700 | [diff] [blame] | 20 | #include <timer.h> |
David Hendricks | 5ec69ed | 2013-05-02 13:23:08 -0700 | [diff] [blame] | 21 | |
David Hendricks | 5ec69ed | 2013-05-02 13:23:08 -0700 | [diff] [blame] | 22 | static const uint32_t clocks_per_usec = MCT_HZ/1000000; |
| 23 | |
Julius Werner | 44cf870 | 2014-12-08 13:39:14 -0800 | [diff] [blame] | 24 | static uint64_t mct_raw_value(void) |
Julius Werner | 8d978a8 | 2014-12-08 13:16:03 -0800 | [diff] [blame] | 25 | { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 26 | uint64_t upper = read32(&exynos_mct->g_cnt_u); |
| 27 | uint64_t lower = read32(&exynos_mct->g_cnt_l); |
Julius Werner | 8d978a8 | 2014-12-08 13:16:03 -0800 | [diff] [blame] | 28 | |
| 29 | return (upper << 32) | lower; |
| 30 | } |
| 31 | |
Julius Werner | 44cf870 | 2014-12-08 13:39:14 -0800 | [diff] [blame] | 32 | void init_timer(void) |
Julius Werner | 8d978a8 | 2014-12-08 13:16:03 -0800 | [diff] [blame] | 33 | { |
Julius Werner | 2f37bd6 | 2015-02-19 14:51:15 -0800 | [diff] [blame] | 34 | write32(&exynos_mct->g_tcon, read32(&exynos_mct->g_tcon) | (0x1 << 8)); |
Julius Werner | 8d978a8 | 2014-12-08 13:16:03 -0800 | [diff] [blame] | 35 | } |
| 36 | |
David Hendricks | 5ec69ed | 2013-05-02 13:23:08 -0700 | [diff] [blame] | 37 | void timer_monotonic_get(struct mono_time *mt) |
| 38 | { |
Stefan Reinauer | 6ada053 | 2013-09-11 15:18:14 -0700 | [diff] [blame] | 39 | /* We don't have to call mct_start() here |
| 40 | * because it was already called in the bootblock |
| 41 | */ |
David Hendricks | 5ec69ed | 2013-05-02 13:23:08 -0700 | [diff] [blame] | 42 | |
Gabe Black | 6ccc45d | 2013-08-09 00:48:06 -0700 | [diff] [blame] | 43 | mono_time_set_usecs(mt, mct_raw_value() / clocks_per_usec); |
David Hendricks | 5ec69ed | 2013-05-02 13:23:08 -0700 | [diff] [blame] | 44 | } |