• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef TIMER_HI35XX_H
17 #define TIMER_HI35XX_H
18 
19 #include "hdf_base.h"
20 #include "los_vm_zone.h"
21 #include "platform_dumper.h"
22 #include "timer_core.h"
23 
24 #ifdef __cplusplus
25 #if __cplusplus
26 extern "C" {
27 #endif /* __cplusplus */
28 #endif /* __cplusplus */
29 
30 #define TIMER_MAX_REG_SIZE (64 * 1024)
31 #define TIMER_DUMPER_NAME_PREFIX "timer_dumper_"
32 #define TIMER_DUMPER_NAME_LEN 64
33 #define TIMER_DUMPER_DATAS_REGISTER_SIZE 10
34 
35 struct TimerHi35xxInfo {
36     uint32_t number;
37     uint32_t busClock;
38     uint32_t mode;
39     uint32_t initCountVal;
40     uint32_t irq;
41     bool isIrqReg;
42     bool isPeriod;
43     volatile uint8_t *regBase;
44     TimerHandleCb cb;
45     char *dumperName;
46     struct PlatformDumper *dumper;
47 };
48 
49 #define HI35XX_SC_CTRL_REG (0x12020000 + 0x0000)
50 #define HI35XX_SC_CTRL_TIMEREN0OV (0x1 << 16)
51 #define HI35XX_SC_CTRL_TIMEREN0OV_SHIFT 16
52 #define HI35XX_SC_CTRL_TIMEREN1OV (0x1 << 17)
53 #define HI35XX_SC_CTRL_TIMEREN1OV_SHIFT 17
54 #define HI35XX_SC_CTRL_TIMEREN2OV (0x1 << 18)
55 #define HI35XX_SC_CTRL_TIMEREN2OV_SHIFT 18
56 #define HI35XX_SC_CTRL_TIMEREN3OV (0x1 << 19)
57 #define HI35XX_SC_CTRL_TIMEREN3OV_SHIFT 19
58 #define HI35XX_SC_CTRL_TIMEREN4OV (0x1 << 20)
59 #define HI35XX_SC_CTRL_TIMEREN4OV_SHIFT 20
60 #define HI35XX_SC_CTRL_TIMEREN5OV (0x1 << 21)
61 #define HI35XX_SC_CTRL_TIMEREN5OV_SHIFT 21
62 #define HI35XX_SC_CTRL_TIMEREN6OV (0x1 << 22)
63 #define HI35XX_SC_CTRL_TIMEREN6OV_SHIFT 22
64 #define HI35XX_SC_CTRL_TIMEREN7OV (0x1 << 23)
65 #define HI35XX_SC_CTRL_TIMEREN7OV_SHIFT 23
66 
67 #define HI35XX_TIMERx_LOAD 0x000
68 #define HI35XX_TIMERx_VALUE 0x004
69 #define HI35XX_TIMERx_CONTROL 0x008
70 #define HI35XX_TIMERx_INTCLR 0x00C
71 #define HI35XX_TIMERx_RIS 0x010
72 #define HI35XX_TIMERx_MIS 0x014
73 #define HI35XX_TIMERx_BGLOAD 0x018
74 
75 #define HI35XX_TIMERx_CLOCK_HZ (3 * 1000 * 1000)
76 #define HI35XX_TIMERx_LOAD_INIT_VAL 0x1000
77 #define HI35XX_TIMERx_US_TRANS_S 1000
78 
79 #define HI35XX_TIMER0_1_INT_NUM 33
80 #define HI35XX_TIMER2_3_INT_NUM 34
81 #define HI35XX_TIMER4_5_INT_NUM 35
82 #define HI35XX_TIMER6_7_INT_NUM 36
83 
84 // HI35XX_TIMERx_CONTROL reg control info
85 #define TIMERx_CONTROL_TIMEREN (0x1 << 7)
86 #define TIMERx_CONTROL_TIMEREN_SHIFT 7
87 #define TIMERx_CONTROL_TIMERMODE (0x1 << 6)
88 #define TIMERx_CONTROL_TIMERMODE_SHIFT 6
89 #define TIMERx_CONTROL_INTENABLE (0x1 << 5)
90 #define TIMERx_CONTROL_INTENABLE_SHIFT 5
91 #define TIMERx_CONTROL_TIMERPRE (0x3 << 2)
92 #define TIMERx_CONTROL_TIMERPRE_SHIFT 2
93 #define TIMERx_CONTROL_TIMERSIZE (0x1 << 1)
94 #define TIMERx_CONTROL_TIMERSIZE_SHIFT 1
95 #define TIMERx_CONTROL_ONESHOT (0x1 << 0)
96 #define TIMERx_CONTROL_ONESHOT_SHIFT 0
97 
98 #define TIMERx_CONTROL_TIMERMODE_FREE 0x0
99 #define TIMERx_CONTROL_TIMERMODE_PERIOD 0x1
100 #define TIMERx_CONTROL_TIMERMODE_ONESHOT 0x2
101 
102 #define TIMERx_CONTROL_TIMERMODE_ONESHOT_PERIOD 0x0
103 #define TIMERx_CONTROL_TIMERMODE_ONESHOT_ONE 0x1
104 
105 #define TIMERx_CONTROL_TIMERPRE_NOT 0x0
106 #define TIMERx_CONTROL_TIMERPRE_4_LEVEL 0x01
107 #define TIMERx_CONTROL_TIMERPRE_8_LEVEL 0x10
108 #define TIMERx_CONTROL_TIMERPRE_UNDEFINE 0x11
109 
110 #ifdef __cplusplus
111 #if __cplusplus
112 }
113 #endif /* __cplusplus */
114 #endif /* __cplusplus */
115 #endif /* TIMER_HI35XX_H */
116