1 /*
2  * Copyright (c) 2015 MediaTek Inc.
3  *
4  * Use of this source code is governed by a MIT-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/MIT
7  */
8 #include <sys/types.h>
9 #include <lk/debug.h>
10 #include <lk/err.h>
11 #include <lk/reg.h>
12 
13 #include <platform/mt_typedefs.h>
14 #include <platform/mt_reg_base.h>
15 #include <platform/mt_gpt.h>
16 
17 #define AP_PERI_GLOBALCON_PDN0 (PERICFG_BASE+0x10)
18 
gpt_power_on(bool bPowerOn)19 static void gpt_power_on(bool bPowerOn) {
20     if (!bPowerOn) {
21         DRV_SetReg32(AP_PERI_GLOBALCON_PDN0, 1<<13);
22     } else {
23         DRV_ClrReg32(AP_PERI_GLOBALCON_PDN0, 1<<13);
24     }
25 }
26 
gpt4_start(void)27 static void gpt4_start(void) {
28     DRV_WriteReg32(GPT4_CLK_REG, GPT4_SYS_CLK);
29     DRV_WriteReg32(GPT4_CON_REG, GPT4_EN|GPT4_FREERUN);
30 }
31 
gpt4_stop(void)32 static void gpt4_stop(void) {
33     DRV_WriteReg32(GPT4_CON_REG, 0x0); // disable
34     DRV_WriteReg32(GPT4_CON_REG, 0x2); // clear counter
35 }
36 
gpt4_init(bool bStart)37 static void gpt4_init(bool bStart) {
38     gpt4_stop();
39 
40     if (bStart) {
41         gpt4_start();
42     }
43 }
44 
gpt_init(void)45 void gpt_init(void) {
46     gpt_power_on(TRUE);
47 
48     gpt4_init(TRUE);
49 }
50 
51