Debian Codegraph @

src/soc/xilinx/zynq7000/timer.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <timer.h>
4 #include <delay.h>
5 #include <device/mmio.h>
6 #include <stdint.h>
7
8 #define G_TIMER_COUNTER_0 ((void *)0xF8F00200u)
9 #define G_TIMER_COUNTER_1 ((void *)0xF8F00204u)
10 #define G_TIMER_CTRL ((void *)0xF8F00208u)
11
12 #define CLK_PER_USEC 108
13
14 static inline uint64_t timer_raw_value(void)
15 {
16 uint32_t upper, lower;
17 do {
18 upper = read32(G_TIMER_COUNTER_1);
19 lower = read32(G_TIMER_COUNTER_0);
20 } while (upper != read32(G_TIMER_COUNTER_1));
21
22 return (((uint64_t)upper) << 32) | lower;
23 }
24
25 void init_timer(void)
26 {
27 /* Disable timer */
28 write32(G_TIMER_CTRL, read32(G_TIMER_CTRL) & ~0x1);
29 write32(G_TIMER_COUNTER_0, 0);
30 write32(G_TIMER_COUNTER_1, 0);
31 /* Enable timer */
32 write32(G_TIMER_CTRL, read32(G_TIMER_CTRL) | 0x1);
33 }
34
35 void timer_monotonic_get(struct mono_time *mt)
36 {
37 mono_time_set_usecs(mt, timer_raw_value() / CLK_PER_USEC);
38 }