mb/system76/cml-u/dt: Make use of chipset devicetree
[coreboot.git] / src / soc / ti / am335x / timer.c
blob4ed98a3541d381728de32156d0395f441db6e9f1
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <timer.h>
4 #include <delay.h>
5 #include <device/mmio.h>
7 #include "dmtimer.h"
8 #include "clock.h"
10 struct am335x_dmtimer *dmtimer_2 = (struct am335x_dmtimer *)DMTIMER_2;
12 #define CLKSEL_M_OSC (0x01 << 0)
14 static uint32_t timer_raw_value(void)
16 return read32(&dmtimer_2->tcrr);
19 void timer_monotonic_get(struct mono_time *mt)
21 mono_time_set_usecs(mt, timer_raw_value() / M_OSC_MHZ);
24 void init_timer(void)
26 write32(&am335x_cm_dpll->clksel_timer2_clk, CLKSEL_M_OSC);
28 // Start the dmtimer in autoreload mode without any prescalers
29 // With M_OSC at 24MHz, this gives a few minutes before the timer overflows
30 write32(&dmtimer_2->tclr, TCLR_ST | TCLR_AR);