1  /*
2  * Copyright (C) 2017-2024 Alibaba Group Holding Limited
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 /******************************************************************************
20  * @file     drv/porting.h
21  * @brief    Header File for SOC Porting
22  * @version  V1.0
23  * @date     8. Apr 2020
24  * @model    porting
25  ******************************************************************************/
26 
27 #ifndef _DRV_PORTING_H_
28 #define _DRV_PORTING_H_
29 
30 #include <stdint.h>
31 #include <stdbool.h>
32 #include <drv/common.h>
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 typedef enum {
39     BOOTREASON_WDT      = 0,    // System WDT reset
40     BOOTREASON_SOFT     = 1,    // soft reset
41     BOOTREASON_POWER    = 2,    // chip power on reset
42     BOOTREASON_OTHER    = 0xFF
43 } boot_reason_t;
44 
45 /*
46   \brief       Soc get boot reason
47   \return      boot reason, \ref boot_reason_t
48 */
49 boot_reason_t soc_get_boot_reason(void);
50 
51 /**
52   \brief       Soc get device frequence.
53   \param[in]   idx      Device index
54   \return      frequence
55 */
56 uint32_t soc_get_apb_freq(uint32_t idx);
57 uint32_t soc_get_ahb_freq(uint32_t idx);
58 uint32_t soc_get_cpu_freq(uint32_t idx);
59 
60 uint32_t soc_get_uart_freq(uint32_t idx);
61 uint32_t soc_get_spi_freq(uint32_t idx);
62 uint32_t soc_get_iic_freq(uint32_t idx);
63 uint32_t soc_get_i2s_freq(uint32_t idx);
64 uint32_t soc_get_pwm_freq(uint32_t idx);
65 uint32_t soc_get_adc_freq(uint32_t idx);
66 uint32_t soc_get_qspi_freq(uint32_t idx);
67 uint32_t soc_get_usi_freq(uint32_t idx);
68 uint32_t soc_get_timer_freq(uint32_t idx);
69 uint32_t soc_get_rtc_freq(uint32_t idx);
70 uint32_t soc_get_wdt_freq(uint32_t idx);
71 uint32_t soc_get_sdio_freq(uint32_t idx);
72 uint32_t soc_get_emmc_freq(uint32_t idx);
73 uint32_t soc_get_usb_freq(uint32_t idx);
74 uint32_t soc_get_ref_clk_freq(uint32_t idx);
75 uint32_t soc_get_coretim_freq(void);
76 uint32_t soc_get_cur_cpu_freq(void);
77 uint32_t soc_get_sys_freq(void);
78 
79 /**
80   \brief       Soc get device frequence.
81   \param[in]   freq     CPU frequence
82   \return      none
83 */
84 void soc_set_sys_freq(uint32_t freq);
85 
86 /*
87   \brief       Soc init clock unit
88   \return      none
89 */
90 void soc_clk_init(void);
91 
92 /*
93   \brief       Soc enable device clock
94   \param[in]   module   Clock module, defined in sys_clk.h, \ref clk_module_t
95   \return      none
96 */
97 void soc_clk_enable(int32_t module);
98 
99 /*
100   \brief       Soc disable device clock
101   \param[in]   module   Clock module, defined in sys_clk.h, \ref clk_module_t
102   \return      none
103 */
104 void soc_clk_disable(int32_t module);
105 
106 /*
107   \brief       Get CPU ID
108   \return      CPU ID, the val is 0, 1, 2...
109 */
110 uint32_t soc_get_cpu_id(void);
111 
112 /**
113   \brief       SOC Dcache clean & invalid by range.
114   \return      None
115 */
116 void soc_dcache_clean_invalid_range(unsigned long addr, uint32_t size);
117 
118 /**
119   \brief       SOC Dcache clean & invalid all.
120   \return      None
121 */
122 void soc_dcache_clean_invalid_all(void);
123 
124 /**
125   \brief       SOC Dcache invalid by range.
126   \return      None
127 */
128 void soc_dcache_invalid_range(unsigned long addr, uint32_t size);
129 
130 /**
131   \brief       SOC Dcache invalid all.
132   \return      None
133 */
134 void soc_dcache_invalid(void);
135 
136 /**
137   \brief       SOC Dcache clean all.
138   \return      None
139 */
140 void soc_dcache_clean(void);
141 
142 
143 /**
144   \brief       SOC Dcache clean by range.
145   \return      None
146 */
147 void soc_dcache_clean_range(unsigned long addr, uint32_t size);
148 
149 /**
150   \brief       SOC Icache invalid all.
151   \return      None
152 */
153 void soc_icache_invalid(void);
154 
155 /**
156   \brief       SOC dma address remap.
157   \return      Remaped address
158 */
159 extern unsigned long soc_dma_address_remap(unsigned long addr);
160 
161 
162 #ifdef CONFIG_PM
163 /**
164   \brief       SoC enter low-power mode, each chip's implementation is different
165                called by csi_pm_enter_sleep
166   \param[in]   mode        low-power mode
167   \return      Error code
168 */
169 csi_error_t soc_pm_enter_sleep(csi_pm_mode_t mode);
170 
171 /**
172   \brief       SoC the wakeup source.
173   \param[in]   wakeup_num  Wakeup source num
174   \param[in]   enable      Flag control the wakeup source is enable or not
175   \return      Error code
176 */
177 csi_error_t soc_pm_config_wakeup_source(uint32_t wakeup_num, bool enable);
178 #endif
179 
180 #ifdef __cplusplus
181 }
182 #endif
183 
184 #endif /* _DRV_PORTING_H_ */
185