aboutsummaryrefslogtreecommitdiff
path: root/src/soc/ti/am335x/timer.c
diff options
context:
space:
mode:
authorSam Lewis <sam.vr.lewis@gmail.com>2020-08-04 19:47:50 +1000
committerPatrick Georgi <pgeorgi@google.com>2020-11-22 22:32:46 +0000
commitfde084bc490daf99da85292ef87d6dcf3446c212 (patch)
treef005134a3dadedc4fa91ff0f9c07fdd69412fba8 /src/soc/ti/am335x/timer.c
parentb5353965e1b7eff860faaa3312728a935311a8c6 (diff)
soc/ti/am335x: Fix timer implementation
Implements the monotonic timer using the am335x dmtimer peripheral. Change-Id: I4736b6d3b6e26370be9e8f369fc02285ad519223 Signed-off-by: Sam Lewis <sam.vr.lewis@gmail.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/44383 Reviewed-by: Arthur Heymans <arthur@aheymans.xyz> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'src/soc/ti/am335x/timer.c')
-rw-r--r--src/soc/ti/am335x/timer.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/soc/ti/am335x/timer.c b/src/soc/ti/am335x/timer.c
new file mode 100644
index 0000000000..4ed98a3541
--- /dev/null
+++ b/src/soc/ti/am335x/timer.c
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <timer.h>
+#include <delay.h>
+#include <device/mmio.h>
+
+#include "dmtimer.h"
+#include "clock.h"
+
+struct am335x_dmtimer *dmtimer_2 = (struct am335x_dmtimer *)DMTIMER_2;
+
+#define CLKSEL_M_OSC (0x01 << 0)
+
+static uint32_t timer_raw_value(void)
+{
+ return read32(&dmtimer_2->tcrr);
+}
+
+void timer_monotonic_get(struct mono_time *mt)
+{
+ mono_time_set_usecs(mt, timer_raw_value() / M_OSC_MHZ);
+}
+
+void init_timer(void)
+{
+ write32(&am335x_cm_dpll->clksel_timer2_clk, CLKSEL_M_OSC);
+
+ // Start the dmtimer in autoreload mode without any prescalers
+ // With M_OSC at 24MHz, this gives a few minutes before the timer overflows
+ write32(&dmtimer_2->tclr, TCLR_ST | TCLR_AR);
+}