blob: 8b313fff78ee45f96fb3b7e5524e309eb424b612 [file] [log] [blame]
David Hendricks5ec69ed2013-05-02 13:23:08 -07001/*
2 * This file is part of the coreboot project.
3 *
Stefan Reinauer08dc3572013-05-14 16:57:50 -07004 * Copyright 2013 Google Inc.
David Hendricks5ec69ed2013-05-02 13:23:08 -07005 *
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 Hendricks5ec69ed2013-05-02 13:23:08 -070014 */
15
Julius Werner8d978a82014-12-08 13:16:03 -080016#include <arch/io.h>
Julius Werner44cf8702014-12-08 13:39:14 -080017#include <delay.h>
Julius Werner1ed0c8c2014-10-20 13:16:29 -070018#include <soc/clk.h>
David Hendricks5ec69ed2013-05-02 13:23:08 -070019#include <stdint.h>
David Hendricks5ec69ed2013-05-02 13:23:08 -070020#include <timer.h>
David Hendricks5ec69ed2013-05-02 13:23:08 -070021
David Hendricks5ec69ed2013-05-02 13:23:08 -070022static const uint32_t clocks_per_usec = MCT_HZ/1000000;
23
Julius Werner44cf8702014-12-08 13:39:14 -080024static uint64_t mct_raw_value(void)
Julius Werner8d978a82014-12-08 13:16:03 -080025{
Julius Werner2f37bd62015-02-19 14:51:15 -080026 uint64_t upper = read32(&exynos_mct->g_cnt_u);
27 uint64_t lower = read32(&exynos_mct->g_cnt_l);
Julius Werner8d978a82014-12-08 13:16:03 -080028
29 return (upper << 32) | lower;
30}
31
Julius Werner44cf8702014-12-08 13:39:14 -080032void init_timer(void)
Julius Werner8d978a82014-12-08 13:16:03 -080033{
Julius Werner2f37bd62015-02-19 14:51:15 -080034 write32(&exynos_mct->g_tcon, read32(&exynos_mct->g_tcon) | (0x1 << 8));
Julius Werner8d978a82014-12-08 13:16:03 -080035}
36
David Hendricks5ec69ed2013-05-02 13:23:08 -070037void timer_monotonic_get(struct mono_time *mt)
38{
Stefan Reinauer6ada0532013-09-11 15:18:14 -070039 /* We don't have to call mct_start() here
40 * because it was already called in the bootblock
41 */
David Hendricks5ec69ed2013-05-02 13:23:08 -070042
Gabe Black6ccc45d2013-08-09 00:48:06 -070043 mono_time_set_usecs(mt, mct_raw_value() / clocks_per_usec);
David Hendricks5ec69ed2013-05-02 13:23:08 -070044}