diff options
author | David Hendricks <dhendrix@chromium.org> | 2013-05-02 13:23:08 -0700 |
---|---|---|
committer | Stefan Reinauer <stefan.reinauer@coreboot.org> | 2013-05-03 06:28:54 +0200 |
commit | 5ec69ed884852426e17439263e3678c5dfbc71e7 (patch) | |
tree | 35ad1882b197bd5f484e32eabb3eebbf0e38d0eb | |
parent | 008616247d4f03b47b2eb996029072a21789f3e0 (diff) |
exynos5250: monotonic timer implementation (using MCT)
This implements the new monotonic timer API using the global
multi-core timer (MCT).
Change-Id: Id56249ff5d3e0f85808f5754954c83c0bc75f1c1
Signed-off-by: David Hendricks <dhendrix@chromium.org>
Reviewed-on: http://review.coreboot.org/3175
Reviewed-by: Aaron Durbin <adurbin@google.com>
Tested-by: build bot (Jenkins)
-rw-r--r-- | src/cpu/samsung/exynos5250/clk.h | 2 | ||||
-rw-r--r-- | src/cpu/samsung/exynos5250/mct.c | 5 | ||||
-rw-r--r-- | src/cpu/samsung/exynos5250/monotonic_timer.c | 58 |
3 files changed, 62 insertions, 3 deletions
diff --git a/src/cpu/samsung/exynos5250/clk.h b/src/cpu/samsung/exynos5250/clk.h index 4785894668..1894c006d2 100644 --- a/src/cpu/samsung/exynos5250/clk.h +++ b/src/cpu/samsung/exynos5250/clk.h @@ -585,4 +585,6 @@ int clock_get_mem_selection(enum ddr_mode *mem_type, unsigned *frequency_mhz, unsigned *arm_freq, enum mem_manuf *mem_manuf); +uint64_t mct_raw_value(void); + #endif diff --git a/src/cpu/samsung/exynos5250/mct.c b/src/cpu/samsung/exynos5250/mct.c index ddabbf7957..4216643140 100644 --- a/src/cpu/samsung/exynos5250/mct.c +++ b/src/cpu/samsung/exynos5250/mct.c @@ -88,7 +88,7 @@ static int enabled = 0; static struct mct_regs *const mct = (struct mct_regs *)MCT_ADDRESS; -static uint64_t timer_raw_value(void) +uint64_t mct_raw_value(void) { if (!enabled) { writel(readl(&mct->g_tcon) | (0x1 << 8), &mct->g_tcon); @@ -109,9 +109,8 @@ void timer_start(void) u32 timer_us(void) { - uint64_t raw = timer_raw_value(); + uint64_t raw = mct_raw_value(); static uint32_t ticks_per_microsecond = MCT_HZ/1000000; uint32_t usec = raw / ticks_per_microsecond; return usec; } - diff --git a/src/cpu/samsung/exynos5250/monotonic_timer.c b/src/cpu/samsung/exynos5250/monotonic_timer.c new file mode 100644 index 0000000000..85fb2082b3 --- /dev/null +++ b/src/cpu/samsung/exynos5250/monotonic_timer.c @@ -0,0 +1,58 @@ +/* + * This file is part of the coreboot project. + * + * Copyright (C) 2013 Google, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <stdint.h> +#include <delay.h> +#include <timer.h> +#include <time.h> /* TODO: deprecate in favor of monotonic timer stuff */ + +#include "clk.h" + +static struct monotonic_counter { + int initialized; + struct mono_time time; + uint64_t last_value; +} mono_counter; + +static const uint32_t clocks_per_usec = MCT_HZ/1000000; + +void timer_monotonic_get(struct mono_time *mt) +{ + uint64_t current_tick; + uint64_t usecs_elapsed; + + if (!mono_counter.initialized) { + init_timer(); + mono_counter.last_value = mct_raw_value(); + mono_counter.initialized = 1; + } + + current_tick = mct_raw_value(); + usecs_elapsed = (current_tick - mono_counter.last_value) / + clocks_per_usec; + + /* Update current time and tick values only if a full tick occurred. */ + if (usecs_elapsed) { + mono_time_add_usecs(&mono_counter.time, usecs_elapsed); + mono_counter.last_value = current_tick; + } + + /* Save result. */ + *mt = mono_counter.time; +} |