coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
timer.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <device/mmio.h>
4 #include <timer.h>
5 #include <delay.h>
6 #include <thread.h>
7 
8 #include <soc/addressmap.h>
9 #include <soc/timer.h>
10 
11 static struct mtk_gpt_regs *const mtk_gpt = (void *)GPT_BASE;
12 
13 __weak void timer_prepare(void) { /* do nothing */ }
14 
16 {
17  /*
18  * According to "General-Purpose Timer (GPT).pdf", The read operation of
19  * gpt6_cnt_l will make gpt6_cnt_h fixed until the next read operation
20  * of gpt6_cnt_l. Therefore, we must read gpt6_cnt_l before gpt6_cnt_h.
21  */
24 
25  return low | (uint64_t)high << 32;
26 }
27 
29 {
31 }
32 
33 void init_timer(void)
34 {
35  timer_prepare();
36 
37  /* Disable timer and clear the counter */
40 
41  /* Set clock source to system clock and set clock divider to 1 */
43  GPT6_CLK_CLK6, GPT6_CLK_CLK6_SYS,
44  GPT6_CLK_CLKDIV6, GPT6_CLK_CLKDIV_DIV1);
45  /* Set operation mode to FREERUN mode and enable timer */
47  GPT6_CON_MODE6, GPT6_MODE_FREERUN,
48  GPT6_CON_EN6, GPT6_CON_EN);
49 }
static uint32_t read32(const void *addr)
Definition: mmio.h:22
#define setbits32(addr, set)
Definition: mmio.h:21
#define SET32_BITFIELDS(addr,...)
Definition: mmio.h:201
#define clrbits32(addr, clear)
Definition: mmio.h:26
static void mono_time_set_usecs(struct mono_time *mt, long us)
Definition: timer.h:53
__weak void init_timer(void)
Definition: timer.c:7
const struct smm_save_state_ops *legacy_ops __weak
Definition: save_state.c:8
void timer_monotonic_get(struct mono_time *mt)
Definition: timer.c:7
__weak void timer_prepare(void)
Definition: timer.c:13
static uint64_t timer_raw_value(void)
Definition: timer.c:15
static struct mtk_gpt_regs *const mtk_gpt
Definition: timer.c:11
@ GPT_BASE
Definition: addressmap.h:21
unsigned int uint32_t
Definition: stdint.h:14
unsigned long long uint64_t
Definition: stdint.h:17
u32 gpt6_cnt_l
Definition: timer_v1.h:16
u32 gpt6_con
Definition: timer_v1.h:14
u32 gpt6_cnt_h
Definition: timer_v1.h:18
@ GPT6_CON_EN
Definition: timer_common.h:9
@ GPT6_MODE_FREERUN
Definition: timer_common.h:11
@ GPT6_CON_CLR
Definition: timer_common.h:10
@ GPT6_CLK_CLK6_SYS
Definition: timer_common.h:12
@ GPT6_CLK_CLKDIV_DIV1
Definition: timer_common.h:13
#define GPT6_CLOCK_REG(x)
Definition: timer_v1.h:30
#define GPT_MHZ
Definition: timer_v1.h:10