diff options
author | Ruilin Hao <rlhao@marvell.com> | 2015-11-09 22:37:09 -0800 |
---|---|---|
committer | Patrick Georgi <pgeorgi@google.com> | 2016-02-04 11:28:41 +0100 |
commit | 2c8b0b137382c969d791c734dca7c1a7a03b07ca (patch) | |
tree | 60c52e4c8acd3fe15878d933fd710135cf229c0c /src/soc/marvell/armada38x/monotonic_timer.c | |
parent | 0e06f5bd70b45fd330d8dfb1dc77cce043caf841 (diff) |
soc/marvell/armada38x: Add generic support for armada38x
Skeleton for soc armada38x
BUG=chrome-os-partner:47462
TEST=None
BRANCH=tot
Change-Id: I76f631ee6cdfc90c44727cb20aa960796bc785a5
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: e91cc19468325f005c6ac920bbe27a174c409727
Original-Change-Id: Iac5fc34df1ba18b4515029aa2fcff8f78a5df191
Original-Signed-off-by: Ruilin Hao <rlhao@marvell.com>
Original-Reviewed-on: https://chromium-review.googlesource.com/313179
Original-Commit-Ready: Kan Yan <kyan@google.com>
Original-Tested-by: Kan Yan <kyan@google.com>
Original-Reviewed-by: Kan Yan <kyan@google.com>
Reviewed-on: https://review.coreboot.org/13110
Tested-by: build bot (Jenkins)
Reviewed-by: Martin Roth <martinroth@google.com>
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Diffstat (limited to 'src/soc/marvell/armada38x/monotonic_timer.c')
-rw-r--r-- | src/soc/marvell/armada38x/monotonic_timer.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/soc/marvell/armada38x/monotonic_timer.c b/src/soc/marvell/armada38x/monotonic_timer.c new file mode 100644 index 0000000000..b314f1185e --- /dev/null +++ b/src/soc/marvell/armada38x/monotonic_timer.c @@ -0,0 +1,58 @@ +/* + * This file is part of the coreboot project. + * + * Copyright 2015 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. + */ + +#include <arch/io.h> +#include <timer.h> +#include <delay.h> + +#define TIMER_CTRL_REG 0xf1020300 +#define TIMER_RELOAD_REG 0xf1020310 +#define TIMER_REG 0xf1020314 +#define TIMER_RELOAD_VALUE 0xffffffff + +#define MHZ_NUM 25 + +void init_timer(void) +{ + unsigned int reg; + + /* Set the reload timer */ + write32((void *)TIMER_RELOAD_REG, TIMER_RELOAD_VALUE); + /* Set the initial value to TIMER_RELOAD_VALUE - 1 + * (instead of TIMER_RELOAD_VALUE) to avoid 'fake' + * overflow being detected in timer_monotonic_get + * if it's called close enough with 'this' function */ + write32((void *)TIMER_REG, TIMER_RELOAD_VALUE - 1); + reg = read32((const void *)TIMER_CTRL_REG); + /* Let it start counting */ + reg |= 0x3; + write32((void *)TIMER_CTRL_REG, reg); +} + +void timer_monotonic_get(struct mono_time *mt) +{ + static uint64_t total_ticks = 0; + uint64_t overflow = 0; + uint32_t current_ticks = + TIMER_RELOAD_VALUE - read32((const void *)TIMER_REG); + + /* Assuming at most one overflow happened since last call */ + if (current_ticks <= total_ticks) + overflow = 1ULL << 32; + + total_ticks = (((total_ticks + overflow) >> 32) << 32) + current_ticks; + mono_time_set_usecs(mt, total_ticks / MHZ_NUM); +} + |