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)
This commit is contained in:
parent
008616247d
commit
5ec69ed884
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue