mb/google/nissa/var/rull: Add 6W and 15W DPTF parameters
[coreboot.git] / src / soc / qualcomm / ipq40xx / timer.c
blob48e06b550cf31b33de257f92ecf9eae1ac809c47
1 /* SPDX-License-Identifier: BSD-3-Clause */
3 #include <device/mmio.h>
4 #include <delay.h>
5 #include <soc/iomap.h>
6 #include <soc/ipq_timer.h>
7 #include <timer.h>
9 #define GCNT_FREQ_MHZ 48
11 #define TIMER_TICKS(us) (GCNT_FREQ_MHZ * (us))
12 #define TIMER_USECS(ticks) ((ticks) / GCNT_FREQ_MHZ)
14 /**
15 * init_timer - initialize timer
17 void init_timer(void)
19 /* disable timer */
20 write32(GCNT_CNTCR, 0);
22 /* Reset the counters to zero */
23 write32(GCNT_GLB_CNTCV_LO, 0);
24 write32(GCNT_GLB_CNTCV_HI, 0);
26 /* Enable timer */
27 write32(GCNT_CNTCR, 1);
30 static inline uint64_t read_gcnt_val(void)
32 uint32_t hi, lo;
34 do {
35 hi = read32(GCNT_CNTCV_HI);
36 lo = read32(GCNT_CNTCV_LO);
37 } while (hi != read32(GCNT_CNTCV_HI));
39 return ((((uint64_t)hi) << 32) | lo);
42 /**
43 * udelay - generates micro second delay.
44 * @param usec: delay duration in microseconds
46 void udelay(unsigned int usec)
48 uint64_t expire;
50 expire = read_gcnt_val() + TIMER_TICKS(usec);
52 while (expire >= read_gcnt_val())
56 void timer_monotonic_get(struct mono_time *mt)
58 mono_time_set_usecs(mt, TIMER_USECS(read_gcnt_val()));