1 /*
2 * Copyright 2017-2019 NXP
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #ifndef _FSL_CLOCK_H_
8 #define _FSL_CLOCK_H_
9
10 #include "fsl_device_registers.h"
11 #include <stdint.h>
12 #include <stdbool.h>
13 #include <assert.h>
14
15 #include "svc/pm/pm_api.h"
16
17 /*! @addtogroup clock */
18 /*! @{ */
19
20 /*! @file */
21
22 /*******************************************************************************
23 * Definitions
24 ******************************************************************************/
25
26 /*! @brief Configure whether driver controls clock
27 *
28 * When set to 0, peripheral drivers will enable clock in initialize function
29 * and disable clock in de-initialize function. When set to 1, peripheral
30 * driver will not control the clock, application could control the clock out of
31 * the driver.
32 *
33 * @note All drivers share this feature switcher. If it is set to 1, application
34 * should handle clock enable and disable for all drivers.
35 */
36 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL))
37 #define FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL 0
38 #endif
39
40 /*! @name Driver version */
41 /*@{*/
42 /*! @brief CLOCK driver version 2.3.1. */
43 #define FSL_CLOCK_DRIVER_VERSION (MAKE_VERSION(2, 3, 1))
44 /*@}*/
45
46 /* Definition for delay API in clock driver, users can redefine it to the real application. */
47 #ifndef SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY
48 #define SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY (400000000UL)
49 #endif
50
51 /*! @brief Clock ip name array for MU. */
52 #define MU_CLOCKS \
53 { \
54 kCLOCK_M4_0_Mu0A0, kCLOCK_M4_0_Mu0A1, kCLOCK_M4_0_Mu0A2, kCLOCK_M4_0_Mu0A3, kCLOCK_M4_0_Mu0B, \
55 kCLOCK_M4_0_Mu0B, kCLOCK_M4_0_Mu0B, kCLOCK_M4_0_Mu0B, kCLOCK_M4_0_Mu1A, kCLOCK_LSIO_Mu0A, \
56 kCLOCK_LSIO_Mu1A, kCLOCK_LSIO_Mu2A, kCLOCK_LSIO_Mu3A, kCLOCK_LSIO_Mu4A, kCLOCK_LSIO_Mu5A, \
57 kCLOCK_LSIO_Mu5B, kCLOCK_LSIO_Mu6A, kCLOCK_LSIO_Mu6B, kCLOCK_LSIO_Mu7A, kCLOCK_LSIO_Mu7B, \
58 kCLOCK_LSIO_Mu8A, kCLOCK_LSIO_Mu8B, kCLOCK_LSIO_Mu9A, kCLOCK_LSIO_Mu9B, kCLOCK_LSIO_Mu10A, \
59 kCLOCK_LSIO_Mu10B, kCLOCK_LSIO_Mu11A, kCLOCK_LSIO_Mu11B, kCLOCK_LSIO_Mu12A, kCLOCK_LSIO_Mu12B, \
60 kCLOCK_LSIO_Mu13A, kCLOCK_LSIO_Mu13B, kCLOCK_SCU_Mu0A0, kCLOCK_SCU_Mu0A1, kCLOCK_SCU_Mu0A2, \
61 kCLOCK_SCU_Mu0A3, kCLOCK_SCU_Mu0B, kCLOCK_SCU_Mu0B, kCLOCK_SCU_Mu0B, kCLOCK_SCU_Mu0B, kCLOCK_SCU_Mu1A, \
62 }
63
64 /*! @brief Clock ip name array for GPIO. */
65 #define GPIO_CLOCKS \
66 { \
67 kCLOCK_IpInvalid, kCLOCK_IpInvalid, kCLOCK_IpInvalid, kCLOCK_HSIO_Gpio, kCLOCK_LSIO_Gpio0, kCLOCK_LSIO_Gpio1, \
68 kCLOCK_LSIO_Gpio2, kCLOCK_LSIO_Gpio3, kCLOCK_LSIO_Gpio4, kCLOCK_LSIO_Gpio5, kCLOCK_LSIO_Gpio6, \
69 kCLOCK_LSIO_Gpio7, kCLOCK_IpInvalid, \
70 }
71
72 /*! @brief Clock ip name array for FLEXSPI. */
73 #define FLEXSPI_CLOCKS \
74 { \
75 kCLOCK_LSIO_Flexspi0, kCLOCK_LSIO_Flexspi1, \
76 }
77
78 /*! @brief Clock ip name array for RGPIO. */
79 #define RGPIO_CLOCKS \
80 { \
81 kCLOCK_M4_0_Rgpio, \
82 }
83
84 /*! @brief Clock ip name array for FTM. */
85 #define FTM_CLOCKS \
86 { \
87 kCLOCK_DMA_Ftm0, kCLOCK_DMA_Ftm1, \
88 }
89
90 /*! @brief Clock ip name array for GPT. */
91 #define GPT_CLOCKS \
92 { \
93 kCLOCK_AUDIO_Gpt0, kCLOCK_AUDIO_Gpt1, kCLOCK_AUDIO_Gpt2, kCLOCK_AUDIO_Gpt3, kCLOCK_AUDIO_Gpt4, \
94 kCLOCK_AUDIO_Gpt5, kCLOCK_LSIO_Gpt0, kCLOCK_LSIO_Gpt1, kCLOCK_LSIO_Gpt2, kCLOCK_LSIO_Gpt3, \
95 kCLOCK_LSIO_Gpt4, \
96 }
97 /*! @brief Clock ip name array for FLEXCAN. */
98 #define FLEXCAN_CLOCKS \
99 { \
100 kCLOCK_DMA_Can0, kCLOCK_DMA_Can0, kCLOCK_DMA_Can0, \
101 }
102
103 /*! @brief Clock ip name array for LPUART. */
104 #define LPUART_CLOCKS \
105 { \
106 kCLOCK_DMA_Lpuart0, kCLOCK_DMA_Lpuart1, kCLOCK_DMA_Lpuart2, kCLOCK_DMA_Lpuart3, kCLOCK_M4_0_Lpuart, \
107 kCLOCK_SCU_Lpuart, \
108 }
109
110 /*! @brief Clock ip name array for LPADC. */
111 #define LPADC_CLOCKS \
112 { \
113 kCLOCK_ADMA_Lpadc0, \
114 }
115
116 /*! @brief Clock ip name array for INTMUX. */
117 #define INTMUX_CLOCKS \
118 { \
119 kCLOCK_M4_0_Intmux, kCLOCK_SCU_Intmux, \
120 }
121
122 /*! @brief Clock ip name array for SAI. */
123 #define SAI_CLOCKS \
124 { \
125 kCLOCK_AUDIO_Sai0, kCLOCK_AUDIO_Sai1, kCLOCK_AUDIO_Sai2, kCLOCK_AUDIO_Sai3, kCLOCK_AUDIO_Sai4, \
126 kCLOCK_AUDIO_Sai5, \
127 }
128
129 /*! @brief Clock ip name array for SAI. */
130 #define SEMA42_CLOCKS \
131 { \
132 kCLOCK_M4_0_Sema42, kCLOCK_SCU_Sema42, \
133 }
134
135 /*! @brief Clock ip name array for TPM. */
136 #define TPM_CLOCKS \
137 { \
138 kCLOCK_M4_0_Tpm, kCLOCK_SCU_Tpm, \
139 }
140
141 /*! @brief Clock ip name array for LPIT. */
142 #define LPIT_CLOCKS \
143 { \
144 kCLOCK_M4_0_Lpit, kCLOCK_SCU_Lpit, \
145 }
146
147 /*! @brief Clock ip name array for LPI2C. */
148 #define LPI2C_CLOCKS \
149 { \
150 kCLOCK_DMA_Lpi2c0, kCLOCK_DMA_Lpi2c1, kCLOCK_DMA_Lpi2c2, kCLOCK_DMA_Lpi2c3, kCLOCK_CiPiLpi2c, \
151 kCLOCK_M4_0_Lpi2c, kCLOCK_DiMiPiDsiLvds0Lpi2c0, kCLOCK_DiMiPiDsiLvds0Lpi2c1, kCLOCK_DiMiPiDsiLvds1Lpi2c0, \
152 kCLOCK_DiMiPiDsiLvds1Lpi2c1, kCLOCK_MipiCsiLpi2c, kCLOCK_SCU_Lpi2c, \
153 }
154
155 /*! @brief Clock ip name array for LPSPI. */
156 #define LPSPI_CLOCKS \
157 { \
158 kCLOCK_DMA_Lpspi0, kCLOCK_DMA_Lpspi1, kCLOCK_DMA_Lpspi2, kCLOCK_DMA_Lpspi3, \
159 }
160
161 /*! @brief Clock ip name array for IRQSTEER */
162 #define IRQSTEER_CLOCKS \
163 { \
164 kCLOCK_M4_0_Irqsteer, \
165 }
166
167 /*! @brief Clock ip name array for EDMA. */
168 #define EDMA_CLOCKS \
169 { \
170 kCLOCK_DMA_Dma0, \
171 }
172
173 /*! @brief Clock ip name array for LPIT. */
174 #define ESAI_CLOCKS \
175 { \
176 kCLOCK_AUDIO_Esai0, kCLOCK_AUDIO_Esai1, \
177 }
178
179 /*! @brief Clock ip name array for ISI. */
180 #define ISI_CLOCKS \
181 { \
182 kCLOCK_IMAGING_Isi0, kCLOCK_IMAGING_Isi1, kCLOCK_IMAGING_Isi2, kCLOCK_IMAGING_Isi3, kCLOCK_IMAGING_Isi4, \
183 kCLOCK_IMAGING_Isi5, \
184 }
185
186 /*! @brief Clock ip name array for MIPI CSI2 RX. */
187 #define MIPI_CSI2RX_CLOCKS \
188 { \
189 kCLOCK_MipiCsi2Rx0, \
190 }
191
192 /*! @brief Clock ip name array for MIPI DSI host. */
193 #define MIPI_DSI_HOST_CLOCKS \
194 { \
195 kCLOCK_MipiDsiHost0, kCLOCK_MipiDsiHost1 \
196 }
197
198 /*! @brief Clock ip name array for ENET. */
199 #define ENET_CLOCKS \
200 { \
201 kCLOCK_CONNECTIVITY_Enet0, kCLOCK_CONNECTIVITY_Enet1 \
202 }
203
204 /*! @brief Clock ip name array for DPU. */
205 #define DPU_CLOCKS \
206 { \
207 kCLOCK_Dpu0, \
208 }
209
210 /*! @brief Clock ip name array for CI_PI. */
211 #define CI_PI_CLOCKS \
212 { \
213 kCLOCK_CiPi0, \
214 }
215
216 /*! @brief Clock ip name array for CAAM. */
217 #define CAAM_CLOCKS \
218 { \
219 kCLOCK_CAAM_JR1, kCLOCK_CAAM_JR2, kCLOCK_CAAM_JR3, \
220 }
221
222 /*! @brief Clock ip name array for LVDS display bridge(LDB). */
223 #define LDB_CLOCKS \
224 { \
225 kCLOCK_Ldb0, kCLOCK_Ldb1 \
226 }
227
228 /*!
229 * @brief Clock source for peripherals that support various clock selections.
230 */
231 typedef enum _clock_ip_src
232 {
233 kCLOCK_IpSrcNone = 0U, /*!< Clock is off. */
234 kCLOCK_IpSrcDummy = 1U, /*!< Clock option 1. */
235 } clock_ip_src_t;
236
237 /*! @brief Clock name used to get clock frequency. */
238 typedef enum _clock_name
239 {
240 /* ----------------------------- System layer clock ---------------------- */
241 kCLOCK_CoreSysClk, /*!< Core/system clock for M4 */
242
243 /* --------------------------------- Other clock ------------------------- */
244 kCLOCK_CONECTIVITY_AhbClk, /*!< AHB clock in Connectivity subsystem */
245 } clock_name_t;
246
247 /*!
248 * @brief LPCG TUPLE macors to map corresponding ip clock name, SCFW API resource index and LPCG Register base address.
249 * The LPCG base should be 4KB aligned, if not it will be truncated.
250 */
251 #define LPCG_TUPLE(rsrc, base) ((uint32_t)((((base) >> 12U) << 10U) | (rsrc)))
252 /*! @brief Get the LPCG REG base address. */
253 #define LPCG_TUPLE_REG_BASE(tuple) ((volatile uint32_t *)((((uint32_t)(tuple) >> 10U) & 0xFFFFFU) << 12U))
254 /*! @brief Get the resource index. */
255 #define LPCG_TUPLE_RSRC(tuple) ((sc_rsrc_t)((uint32_t)(tuple)&0x3FFU))
256 /*! @brief LPCG Cell not available. */
257 #define NV (0U)
258
259 /*!
260 * @brief Peripheral clock name difinition used for clock gate, clock source
261 * and clock divider setting. It is defined as the corresponding register address.
262 */
263 typedef enum _clock_ip_name
264 {
265 kCLOCK_M4_0_Irqsteer = LPCG_TUPLE(SC_R_IRQSTR_M4_0, NV),
266 kCLOCK_DMA_Lpspi0 = LPCG_TUPLE(SC_R_SPI_0, ADMA__LPCG_SPI0_IPG_CLK_BASE),
267 kCLOCK_DMA_Lpspi1 = LPCG_TUPLE(SC_R_SPI_1, ADMA__LPCG_SPI1_IPG_CLK_BASE),
268 kCLOCK_DMA_Lpspi2 = LPCG_TUPLE(SC_R_SPI_2, ADMA__LPCG_SPI2_IPG_CLK_BASE),
269 kCLOCK_DMA_Lpspi3 = LPCG_TUPLE(SC_R_SPI_3, ADMA__LPCG_SPI3_IPG_CLK_BASE),
270 kCLOCK_DMA_Lpuart0 = LPCG_TUPLE(SC_R_UART_0, ADMA__LPCG_UART0_IPG_CLK_BASE),
271 kCLOCK_DMA_Lpuart1 = LPCG_TUPLE(SC_R_UART_1, ADMA__LPCG_UART1_IPG_CLK_BASE),
272 kCLOCK_DMA_Lpuart2 = LPCG_TUPLE(SC_R_UART_2, ADMA__LPCG_UART2_IPG_CLK_BASE),
273 kCLOCK_DMA_Lpuart3 = LPCG_TUPLE(SC_R_UART_3, ADMA__LPCG_UART3_IPG_CLK_BASE),
274 kCLOCK_DMA_Dma0 = LPCG_TUPLE(SC_R_DMA_0_CH0, NV),
275 kCLOCK_DMA_Lpi2c0 = LPCG_TUPLE(SC_R_I2C_0, ADMA__LPCG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CLK_24M_BASE),
307 kCLOCK_AUDIO_Gpt2 = LPCG_TUPLE(SC_R_GPT_7, ADMA__LPCG_GPT2_IPG_CLK_24M_BASE),
308 kCLOCK_AUDIO_Gpt3 = LPCG_TUPLE(SC_R_GPT_8, ADMA__LPCG_GPT3_IPG_CLK_24M_BASE),
309 kCLOCK_AUDIO_Gpt4 = LPCG_TUPLE(SC_R_GPT_9, ADMA__LPCG_GPT4_IPG_CLK_24M_BASE),
310 kCLOCK_AUDIO_Gpt5 = LPCG_TUPLE(SC_R_GPT_10, ADMA__LPCG_GPT5_IPG_CLK_24M_BASE),
311 kCLOCK_LSIO_Gpt0 = LPCG_TUPLE(SC_R_GPT_0, LSIO__LPCG_GPT0_BASE),
312 kCLOCK_LSIO_Gpt1 = LPCG_TUPLE(SC_R_GPT_1, LSIO__LPCG_GPT1_BASE),
313 kCLOCK_LSIO_Gpt2 = LPCG_TUPLE(SC_R_GPT_2, LSIO__LPCG_GPT2_BASE),
314 kCLOCK_LSIO_Gpt3 = LPCG_TUPLE(SC_R_GPT_3, LSIO__LPCG_GPT3_BASE),
315 kCLOCK_LSIO_Gpt4 = LPCG_TUPLE(SC_R_GPT_4, LSIO__LPCG_GPT4_BASE),
316 kCLOCK_LSIO_Mu0A = LPCG_TUPLE(SC_R_MU_0A, NV),
317 kCLOCK_LSIO_Mu1A = LPCG_TUPLE(SC_R_MU_1A, NV),
318 kCLOCK_LSIO_Mu2A = LPCG_TUPLE(SC_R_MU_2A, NV),
319 kCLOCK_LSIO_Mu3A = LPCG_TUPLE(SC_R_MU_3A, NV),
320 kCLOCK_LSIO_Mu4A = LPCG_TUPLE(SC_R_MU_4A, NV),
321 kCLOCK_LSIO_Mu5A = LPCG_TUPLE(SC_R_MU_5A, LSIO__LPCG_MU5_MCU_BASE),
322 kCLOCK_LSIO_Mu6A = LPCG_TUPLE(SC_R_MU_6A, LSIO__LPCG_MU6_MCU_BASE),
323 kCLOCK_LSIO_Mu7A = LPCG_TUPLE(SC_R_MU_7A, LSIO__LPCG_MU7_MCU_BASE),
324 kCLOCK_LSIO_Mu8A = LPCG_TUPLE(SC_R_MU_8A, LSIO__LPCG_MU8_MCU_BASE),
325 kCLOCK_LSIO_Mu9A = LPCG_TUPLE(SC_R_MU_9A, LSIO__LPCG_MU9_MCU_BASE),
326 kCLOCK_LSIO_Mu10A = LPCG_TUPLE(SC_R_MU_10A, LSIO__LPCG_MU10_MCU_BASE),
327 kCLOCK_LSIO_Mu11A = LPCG_TUPLE(SC_R_MU_11A, LSIO__LPCG_MU11_MCU_BASE),
328 kCLOCK_LSIO_Mu12A = LPCG_TUPLE(SC_R_MU_12A, LSIO__LPCG_MU12_MCU_BASE),
329 kCLOCK_LSIO_Mu13A = LPCG_TUPLE(SC_R_MU_13A, LSIO__LPCG_MU13_MCU_BASE),
330 kCLOCK_LSIO_Mu5B = LPCG_TUPLE(SC_R_MU_5B, LSIO__LPCG_MU5_DSP_BASE),
331 kCLOCK_LSIO_Mu6B = LPCG_TUPLE(SC_R_MU_6B, LSIO__LPCG_MU6_DSP_BASE),
332 kCLOCK_LSIO_Mu7B = LPCG_TUPLE(SC_R_MU_7B, LSIO__LPCG_MU7_DSP_BASE),
333 kCLOCK_LSIO_Mu8B = LPCG_TUPLE(SC_R_MU_8B, LSIO__LPCG_MU8_DSP_BASE),
334 kCLOCK_LSIO_Mu9B = LPCG_TUPLE(SC_R_MU_9B, LSIO__LPCG_MU9_DSP_BASE),
335 kCLOCK_LSIO_Mu10B = LPCG_TUPLE(SC_R_MU_10B, LSIO__LPCG_MU10_DSP_BASE),
336 kCLOCK_LSIO_Mu11B = LPCG_TUPLE(SC_R_MU_11B, LSIO__LPCG_MU11_DSP_BASE),
337 kCLOCK_LSIO_Mu12B = LPCG_TUPLE(SC_R_MU_12B, LSIO__LPCG_MU12_DSP_BASE),
338 kCLOCK_LSIO_Mu13B = LPCG_TUPLE(SC_R_MU_13B, LSIO__LPCG_MU13_DSP_BASE),
339 kCLOCK_SCU_Mu0B = LPCG_TUPLE(SC_R_SC_MU_0B, NV),
340 kCLOCK_SCU_Mu0A0 = LPCG_TUPLE(SC_R_SC_MU_0A0, NV),
341 kCLOCK_SCU_Mu0A1 = LPCG_TUPLE(SC_R_SC_MU_0A1, NV),
342 kCLOCK_SCU_Mu0A2 = LPCG_TUPLE(SC_R_SC_MU_0A2, NV),
343 kCLOCK_SCU_Mu0A3 = LPCG_TUPLE(SC_R_SC_MU_0A3, NV),
344 kCLOCK_SCU_Mu1A = LPCG_TUPLE(SC_R_SC_MU_1A, NV),
345 kCLOCK_LSIO_Flexspi0 = LPCG_TUPLE(SC_R_FSPI_0, LSIO__LPCG_QSPI0_BASE),
346 kCLOCK_LSIO_Flexspi1 = LPCG_TUPLE(SC_R_FSPI_1, LSIO__LPCG_QSPI1_BASE),
347 kCLOCK_M4_0_Rgpio = LPCG_TUPLE(SC_R_M4_0_RGPIO, NV),
348 kCLOCK_M4_0_Sema42 = LPCG_TUPLE(SC_R_M4_0_SEMA42, NV),
349 kCLOCK_M4_0_Tpm = LPCG_TUPLE(SC_R_M4_0_TPM, CM4__LPCG_TPM_BASE),
350 kCLOCK_M4_0_Lpit = LPCG_TUPLE(SC_R_M4_0_PIT, CM4__LPCG_LPIT_BASE),
351 kCLOCK_M4_0_Lpuart = LPCG_TUPLE(SC_R_M4_0_UART, CM4__LPCG_LPUART_BASE),
352 kCLOCK_M4_0_Lpi2c = LPCG_TUPLE(SC_R_M4_0_I2C, CM4__LPCG_LPI2C_BASE),
353 kCLOCK_M4_0_Intmux = LPCG_TUPLE(SC_R_M4_0_INTMUX, NV),
354 kCLOCK_M4_0_Mu0B = LPCG_TUPLE(SC_R_M4_0_MU_0B, NV),
355 kCLOCK_M4_0_Mu0A0 = LPCG_TUPLE(SC_R_M4_0_MU_0A0, NV),
356 kCLOCK_M4_0_Mu0A1 = LPCG_TUPLE(SC_R_M4_0_MU_0A1, NV),
357 kCLOCK_M4_0_Mu0A2 = LPCG_TUPLE(SC_R_M4_0_MU_0A2, NV),
358 kCLOCK_M4_0_Mu0A3 = LPCG_TUPLE(SC_R_M4_0_MU_0A3, NV),
359 kCLOCK_M4_0_Mu1A = LPCG_TUPLE(SC_R_M4_0_MU_1A, NV),
360 kCLOCK_SCU_Lpuart = LPCG_TUPLE(SC_R_SC_UART, SCU__LPCG_LPUART_BASE),
361 kCLOCK_ADMA_Lpadc0 = LPCG_TUPLE(SC_R_ADC_0, NV),
362 kCLOCK_SCU_Lpi2c = LPCG_TUPLE(SC_R_SC_I2C, SCU__LPCG_LPI2C_BASE),
363 kCLOCK_SCU_Sema42 = LPCG_TUPLE(SC_R_SC_SEMA42, NV),
364 kCLOCK_SCU_Lpit = LPCG_TUPLE(SC_R_SC_PIT, SCU__LPCG_LPIT_BASE),
365 kCLOCK_SCU_Tpm = LPCG_TUPLE(SC_R_SC_TPM, SCU__LPCG_TPM_BASE),
366 kCLOCK_SCU_Intmux = LPCG_TUPLE(SC_R_LAST, NV),
367 kCLOCK_AUDIO_Sai0 = LPCG_TUPLE(SC_R_SAI_0, ADMA__LPCG_SAI0_IPG_CLK_BASE),
368 kCLOCK_AUDIO_Sai1 = LPCG_TUPLE(SC_R_SAI_1, ADMA__LPCG_SAI1_IPG_CLK_BASE),
369 kCLOCK_AUDIO_Sai2 = LPCG_TUPLE(SC_R_SAI_2, ADMA__LPCG_SAI2_IPG_CLK_BASE),
370 kCLOCK_AUDIO_Sai3 = LPCG_TUPLE(SC_R_SAI_3, ADMA__LPCG_SAI3_IPG_CLK_BASE),
371 kCLOCK_AUDIO_Sai4 = LPCG_TUPLE(SC_R_SAI_4, ADMA__LPCG_SAI4_IPG_CLK_BASE),
372 kCLOCK_AUDIO_Sai5 = LPCG_TUPLE(SC_R_SAI_5, ADMA__LPCG_SAI5_IPG_CLK_BASE),
373 kCLOCK_AUDIO_Esai0 = LPCG_TUPLE(SC_R_ESAI_0, ADMA__LPCG_ESAI0_EXTAL_CLK_BASE),
374 kCLOCK_AUDIO_Esai1 = LPCG_TUPLE(SC_R_ESAI_0, NV),
375 kCLOCK_IMAGING_Isi0 = LPCG_TUPLE(SC_R_ISI_CH0, NV),
376 kCLOCK_IMAGING_Isi1 = LPCG_TUPLE(SC_R_ISI_CH1, NV),
377 kCLOCK_IMAGING_Isi2 = LPCG_TUPLE(SC_R_ISI_CH2, NV),
378 kCLOCK_IMAGING_Isi3 = LPCG_TUPLE(SC_R_ISI_CH3, NV),
379 kCLOCK_IMAGING_Isi4 = LPCG_TUPLE(SC_R_ISI_CH4, NV),
380 kCLOCK_IMAGING_Isi5 = LPCG_TUPLE(SC_R_ISI_CH5, NV),
381 kCLOCK_MipiCsi2Rx0 = LPCG_TUPLE(SC_R_CSI_0, NV),
382 kCLOCK_MipiCsi2Rx1 = LPCG_TUPLE(SC_R_CSI_1, NV),
383 kCLOCK_DiMiPiDsiLvds0Lpi2c0 = LPCG_TUPLE(SC_R_MIPI_0_I2C_0, DI_MIPI_DSI_LVDS_0__LPCG_LIS_IPG_CLK_BASE),
384 kCLOCK_DiMiPiDsiLvds0Lpi2c1 = LPCG_TUPLE(SC_R_MIPI_0_I2C_1, DI_MIPI_DSI_LVDS_0__LPCG_LIS_IPG_CLK_BASE),
385 kCLOCK_DiMiPiDsiLvds1Lpi2c0 = LPCG_TUPLE(SC_R_MIPI_1_I2C_0, DI_MIPI_DSI_LVDS_1__LPCG_LIS_IPG_CLK_BASE),
386 kCLOCK_DiMiPiDsiLvds1Lpi2c1 = LPCG_TUPLE(SC_R_MIPI_1_I2C_1, DI_MIPI_DSI_LVDS_1__LPCG_LIS_IPG_CLK_BASE),
387 kCLOCK_CiPiLpi2c = LPCG_TUPLE(SC_R_LAST, NV),
388 kCLOCK_MipiCsiLpi2c = LPCG_TUPLE(SC_R_CSI_0_I2C_0, NV),
389 kCLOCK_MipiDsiHost0 = LPCG_TUPLE(SC_R_MIPI_0, NV),
390 kCLOCK_MipiDsiHost1 = LPCG_TUPLE(SC_R_MIPI_1, NV),
391 kCLOCK_Dpu0 = LPCG_TUPLE(SC_R_DC_0, DC__LPCG_DSP0_CLK_BASE),
392 kCLOCK_Dpu1 = LPCG_TUPLE(SC_R_DC_1, NV),
393 kCLOCK_HDMI_Lpi2c0 = LPCG_TUPLE(SC_R_HDMI_I2C_0, NV),
394 kCLOCK_HDMI_RX_Lpi2c0 = LPCG_TUPLE(SC_R_HDMI_RX_I2C_0, NV),
395 kCLOCK_Ldb0 = LPCG_TUPLE(SC_R_LVDS_0, NV),
396 kCLOCK_Ldb1 = LPCG_TUPLE(SC_R_LVDS_1, NV),
397 kCLOCK_CONNECTIVITY_Enet0 = LPCG_TUPLE(SC_R_ENET_0, CONNECTIVITY__LPCG_ENET0_BASE),
398 kCLOCK_CONNECTIVITY_Enet1 = LPCG_TUPLE(SC_R_ENET_1, CONNECTIVITY__LPCG_ENET1_BASE),
399 kCLOCK_CONNECTIVITY_Usdhc0 = LPCG_TUPLE(SC_R_SDHC_0, CONNECTIVITY__LPCG_USDHC0_BASE),
400 kCLOCK_CONNECTIVITY_Usdhc1 = LPCG_TUPLE(SC_R_SDHC_1, CONNECTIVITY__LPCG_USDHC1_BASE),
401 kCLOCK_AUDIO_Pll0 = LPCG_TUPLE(SC_R_AUDIO_PLL_0, NV),
402 kCLOCK_AUDIO_Pll1 = LPCG_TUPLE(SC_R_AUDIO_PLL_1, NV),
403 kCLOCK_CAAM_JR1 = LPCG_TUPLE(SC_R_CAAM_JR1, NV),
404 kCLOCK_CAAM_JR2 = LPCG_TUPLE(SC_R_CAAM_JR2, NV),
405 kCLOCK_CAAM_JR3 = LPCG_TUPLE(SC_R_CAAM_JR3, NV),
406 kCLOCK_CiPi0 = LPCG_TUPLE(SC_R_PI_0, NV),
407 kCLOCK_Isi0 = LPCG_TUPLE(SC_R_ISI_CH0, NV),
408 kCLOCK_Isi1 = LPCG_TUPLE(SC_R_ISI_CH1, NV),
409 kCLOCK_Isi2 = LPCG_TUPLE(SC_R_ISI_CH2, NV),
410 kCLOCK_Isi3 = LPCG_TUPLE(SC_R_ISI_CH3, NV),
411 kCLOCK_Isi4 = LPCG_TUPLE(SC_R_ISI_CH4, NV),
412 kCLOCK_Isi5 = LPCG_TUPLE(SC_R_ISI_CH5, NV),
413 kCLOCK_Isi6 = LPCG_TUPLE(SC_R_ISI_CH6, NV),
414 kCLOCK_Isi7 = LPCG_TUPLE(SC_R_ISI_CH7, NV),
415 kCLOCK_IpInvalid = LPCG_TUPLE(SC_R_LAST, NV) /* The selected IP does not support clock control. */
416 } clock_ip_name_t;
417
418 #if defined(__cplusplus)
419 extern "C" {
420 #endif /* _cplusplus */
421
422 /*!
423 * @brief Initialize Clock module.
424 *
425 * @param ipc IPC handle for communication with SCU.
426 */
427 void CLOCK_Init(sc_ipc_t ipc);
428
429 /*!
430 * @brief Deinitialize Clock module.
431 */
432 void CLOCK_Deinit(void);
433
434 /*!
435 * @brief Enable the clock for specific IP, with gate setting.
436 *
437 * @param name Which clock to enable, see \ref clock_ip_name_t.
438 * @param gate 0: clock always on, 1: HW auto clock gating.
439 * @return true if success, false if failure.
440 */
441 bool CLOCK_EnableClockExt(clock_ip_name_t name, uint32_t gate);
442
443 /*!
444 * @brief Enable the clock for specific IP.
445 *
446 * @param name Which clock to enable, see \ref clock_ip_name_t.
447 * @return true for success, false for failure.
448 */
CLOCK_EnableClock(clock_ip_name_t name)449 static inline bool CLOCK_EnableClock(clock_ip_name_t name)
450 {
451 return CLOCK_EnableClockExt(name, 0);
452 }
453
454 /*!
455 * @brief Disable the clock for specific IP.
456 *
457 * @param name Which clock to disable, see \ref clock_ip_name_t.
458 * @return true for success, false for failure.
459 */
460 bool CLOCK_DisableClock(clock_ip_name_t name);
461
462 /*!
463 * @brief Set the clock frequency for specific IP module.
464 *
465 * This function sets the IP module clock frequency.
466 *
467 * @param name Which peripheral to check, see \ref clock_ip_name_t.
468 * @param freq Target clock frequency value in hertz.
469 * @return the Real clock frequency value in hertz, or 0 if failed
470 */
471 uint32_t CLOCK_SetIpFreq(clock_ip_name_t name, uint32_t freq);
472
473 /*!
474 * @brief Get the clock frequency for a specific IP module.
475 *
476 * This function gets the IP module clock frequency.
477 *
478 * @param name Which peripheral to get, see \ref clock_ip_name_t.
479 * @return Clock frequency value in hertz, or 0 if failed
480 */
481 uint32_t CLOCK_GetIpFreq(clock_ip_name_t name);
482
483 /*!
484 * @brief Gets the clock frequency for a specific clock name.
485 *
486 * This function checks the current clock configurations and then calculates
487 * the clock frequency for a specific clock name defined in clock_name_t.
488 *
489 * @param name Clock names defined in clock_name_t
490 * @return Clock frequency value in hertz
491 */
492 uint32_t CLOCK_GetFreq(clock_name_t name);
493
494 /*!
495 * @brief Get the core clock or system clock frequency.
496 *
497 * @return Clock frequency in Hz.
498 */
499 uint32_t CLOCK_GetCoreSysClkFreq(void);
500
501 /*!
502 * @brief Config the LPCG cell for specific IP.
503 *
504 * @param name Which clock to enable, see \ref clock_ip_name_t.
505 * @param swGate Software clock gating. 0: clock is gated; 1: clock is enabled
506 * @param hwGate Hardware auto gating. 0: disable the HW clock gate control; 1: HW clock gating is enabled
507 */
508 void CLOCK_ConfigLPCG(clock_ip_name_t name, bool swGate, bool hwGate);
509
510 /*!
511 * @brief Set LPCG gate for specific LPCG.
512 *
513 * @param regBase LPCG register base address.
514 * @param swGate Software clock gating. 0: clock is gated; 1: clock is enabled
515 * @param hwGate Hardware auto gating. 0: disable the HW clock gate control; 1: HW clock gating is enabled
516 * @param bitsMask The available bits in LPCG register. Each bit indicate the corresponding bit is available or not.
517 */
518 void CLOCK_SetLpcgGate(volatile uint32_t *regBase, bool swGate, bool hwGate, uint32_t bitsMask);
519
520 #if defined(__cplusplus)
521 }
522 #endif /* __cplusplus */
523
524 /*! @} */
525
526 #endif /* _FSL_CLOCK_H_ */
527