1 /* SPDX-License-Identifier: BSD-3-Clause */
3 #include <device/mmio.h>
6 #include <soc/ipq_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)
15 * init_timer - initialize 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);
27 write32(GCNT_CNTCR
, 1);
30 static inline uint64_t read_gcnt_val(void)
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
);
43 * udelay - generates micro second delay.
44 * @param usec: delay duration in microseconds
46 void udelay(unsigned int usec
)
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()));