1 /*
2  * Copyright (c) 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016 - 2021, NXP
4  * All rights reserved.
5  *
6  *
7  * SPDX-License-Identifier: BSD-3-Clause
8  */
9 
10 #ifndef _FSL_CLOCK_H_
11 #define _FSL_CLOCK_H_
12 
13 #include "fsl_common.h"
14 
15 /*! @addtogroup clock */
16 /*! @{ */
17 
18 /*! @file */
19 
20 /*******************************************************************************
21  * Definitions
22  *****************************************************************************/
23 
24 /*! @name Driver version */
25 /*@{*/
26 /*! @brief CLOCK driver version 2.3.3. */
27 #define FSL_CLOCK_DRIVER_VERSION (MAKE_VERSION(2, 3, 3))
28 /*@}*/
29 
30 /*! @brief Configure whether driver controls clock
31  *
32  * When set to 0, peripheral drivers will enable clock in initialize function
33  * and disable clock in de-initialize function. When set to 1, peripheral
34  * driver will not control the clock, application could control the clock out of
35  * the driver.
36  *
37  * @note All drivers share this feature switcher. If it is set to 1, application
38  * should handle clock enable and disable for all drivers.
39  */
40 #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL))
41 #define FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL 0
42 #endif
43 
44 /*!
45  * @brief User-defined the size of cache for CLOCK_PllGetConfig() function.
46  *
47  * Once define this MACRO to be non-zero value, CLOCK_PllGetConfig() function
48  * would cache the recent calulation and accelerate the execution to get the
49  * right settings.
50  */
51 #ifndef CLOCK_USR_CFG_PLL_CONFIG_CACHE_COUNT
52 #define CLOCK_USR_CFG_PLL_CONFIG_CACHE_COUNT 2U
53 #endif
54 
55 /* Definition for delay API in clock driver, users can redefine it to the real application. */
56 #ifndef SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY
57 #define SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY (180000000UL)
58 #endif
59 
60 /*! @brief Clock ip name array for ADC. */
61 #define ADC_CLOCKS  \
62     {               \
63         kCLOCK_Adc0 \
64     }
65 /*! @brief Clock ip name array for ROM. */
66 #define ROM_CLOCKS \
67     {              \
68         kCLOCK_Rom \
69     }
70 /*! @brief Clock ip name array for SRAM. */
71 #define SRAM_CLOCKS                              \
72     {                                            \
73         kCLOCK_Sram1, kCLOCK_Sram2, kCLOCK_Sram3 \
74     }
75 /*! @brief Clock ip name array for FLASH. */
76 #define FLASH_CLOCKS \
77     {                \
78         kCLOCK_Flash \
79     }
80 /*! @brief Clock ip name array for FMC. */
81 #define FMC_CLOCKS \
82     {              \
83         kCLOCK_Fmc \
84     }
85 /*! @brief Clock ip name array for EEPROM. */
86 #define EEPROM_CLOCKS \
87     {                 \
88         kCLOCK_Eeprom \
89     }
90 /*! @brief Clock ip name array for SPIFI. */
91 #define SPIFI_CLOCKS \
92     {                \
93         kCLOCK_Spifi \
94     }
95 /*! @brief Clock ip name array for INPUTMUX. */
96 #define INPUTMUX_CLOCKS \
97     {                   \
98         kCLOCK_InputMux \
99     }
100 /*! @brief Clock ip name array for IOCON. */
101 #define IOCON_CLOCKS \
102     {                \
103         kCLOCK_Iocon \
104     }
105 /*! @brief Clock ip name array for GPIO. */
106 #define GPIO_CLOCKS                                                                        \
107     {                                                                                      \
108         kCLOCK_Gpio0, kCLOCK_Gpio1, kCLOCK_Gpio2, kCLOCK_Gpio3, kCLOCK_Gpio4, kCLOCK_Gpio5 \
109     }
110 /*! @brief Clock ip name array for PINT. */
111 #define PINT_CLOCKS \
112     {               \
113         kCLOCK_Pint \
114     }
115 /*! @brief Clock ip name array for GINT. */
116 #define GINT_CLOCKS              \
117     {                            \
118         kCLOCK_Gint, kCLOCK_Gint \
119     }
120 /*! @brief Clock ip name array for DMA. */
121 #define DMA_CLOCKS \
122     {              \
123         kCLOCK_Dma \
124     }
125 /*! @brief Clock ip name array for CRC. */
126 #define CRC_CLOCKS \
127     {              \
128         kCLOCK_Crc \
129     }
130 /*! @brief Clock ip name array for WWDT. */
131 #define WWDT_CLOCKS \
132     {               \
133         kCLOCK_Wwdt \
134     }
135 /*! @brief Clock ip name array for RTC. */
136 #define RTC_CLOCKS \
137     {              \
138         kCLOCK_Rtc \
139     }
140 /*! @brief Clock ip name array for ADC0. */
141 #define ADC0_CLOCKS \
142     {               \
143         kCLOCK_Adc0 \
144     }
145 /*! @brief Clock ip name array for MRT. */
146 #define MRT_CLOCKS \
147     {              \
148         kCLOCK_Mrt \
149     }
150 /*! @brief Clock ip name array for RIT. */
151 #define RIT_CLOCKS \
152     {              \
153         kCLOCK_Rit \
154     }
155 /*! @brief Clock ip name array for SCT0. */
156 #define SCT_CLOCKS  \
157     {               \
158         kCLOCK_Sct0 \
159     }
160 /*! @brief Clock ip name array for MCAN. */
161 #define MCAN_CLOCKS                \
162     {                              \
163         kCLOCK_Mcan0, kCLOCK_Mcan1 \
164     }
165 /*! @brief Clock ip name array for UTICK. */
166 #define UTICK_CLOCKS \
167     {                \
168         kCLOCK_Utick \
169     }
170 /*! @brief Clock ip name array for FLEXCOMM. */
171 #define FLEXCOMM_CLOCKS                                                                                             \
172     {                                                                                                               \
173         kCLOCK_FlexComm0, kCLOCK_FlexComm1, kCLOCK_FlexComm2, kCLOCK_FlexComm3, kCLOCK_FlexComm4, kCLOCK_FlexComm5, \
174             kCLOCK_FlexComm6, kCLOCK_FlexComm7, kCLOCK_FlexComm8, kCLOCK_FlexComm9, kCLOCK_FlexComm10               \
175     }
176 /*! @brief Clock ip name array for LPUART. */
177 #define LPUART_CLOCKS                                                                                         \
178     {                                                                                                         \
179         kCLOCK_MinUart0, kCLOCK_MinUart1, kCLOCK_MinUart2, kCLOCK_MinUart3, kCLOCK_MinUart4, kCLOCK_MinUart5, \
180             kCLOCK_MinUart6, kCLOCK_MinUart7, kCLOCK_MinUart8, kCLOCK_MinUart9                                \
181     }
182 
183 /*! @brief Clock ip name array for BI2C. */
184 #define BI2C_CLOCKS                                                                                       \
185     {                                                                                                     \
186         kCLOCK_BI2c0, kCLOCK_BI2c1, kCLOCK_BI2c2, kCLOCK_BI2c3, kCLOCK_BI2c4, kCLOCK_BI2c5, kCLOCK_BI2c6, \
187             kCLOCK_BI2c7, kCLOCK_BI2c8, kCLOCK_BI2c9                                                      \
188     }
189 /*! @brief Clock ip name array for LSPI. */
190 #define LPSI_CLOCKS                                                                                       \
191     {                                                                                                     \
192         kCLOCK_LSpi0, kCLOCK_LSpi1, kCLOCK_LSpi2, kCLOCK_LSpi3, kCLOCK_LSpi4, kCLOCK_LSpi5, kCLOCK_LSpi6, \
193             kCLOCK_LSpi7, kCLOCK_LSpi8, kCLOCK_LSpi9                                                      \
194     }
195 /*! @brief Clock ip name array for FLEXI2S. */
196 #define FLEXI2S_CLOCKS                                                                                        \
197     {                                                                                                         \
198         kCLOCK_FlexI2s0, kCLOCK_FlexI2s1, kCLOCK_FlexI2s2, kCLOCK_FlexI2s3, kCLOCK_FlexI2s4, kCLOCK_FlexI2s5, \
199             kCLOCK_FlexI2s6, kCLOCK_FlexI2s7, kCLOCK_FlexI2s8, kCLOCK_FlexI2s9                                \
200     }
201 /*! @brief Clock ip name array for DMIC. */
202 #define DMIC_CLOCKS \
203     {               \
204         kCLOCK_DMic \
205     }
206 /*! @brief Clock ip name array for CT32B. */
207 #define CTIMER_CLOCKS                                                             \
208     {                                                                             \
209         kCLOCK_Ct32b0, kCLOCK_Ct32b1, kCLOCK_Ct32b2, kCLOCK_Ct32b3, kCLOCK_Ct32b4 \
210     }
211 /*! @brief Clock ip name array for LCD. */
212 #define LCD_CLOCKS \
213     {              \
214         kCLOCK_Lcd \
215     }
216 /*! @brief Clock ip name array for SDIO. */
217 #define SDIO_CLOCKS \
218     {               \
219         kCLOCK_Sdio \
220     }
221 /*! @brief Clock ip name array for USBRAM. */
222 #define USBRAM_CLOCKS  \
223     {                  \
224         kCLOCK_UsbRam1 \
225     }
226 /*! @brief Clock ip name array for EMC. */
227 #define EMC_CLOCKS \
228     {              \
229         kCLOCK_Emc \
230     }
231 /*! @brief Clock ip name array for ETH. */
232 #define ETH_CLOCKS \
233     {              \
234         kCLOCK_Eth \
235     }
236 /*! @brief Clock ip name array for AES. */
237 #define AES_CLOCKS \
238     {              \
239         kCLOCK_Aes \
240     }
241 /*! @brief Clock ip name array for OTP. */
242 #define OTP_CLOCKS \
243     {              \
244         kCLOCK_Otp \
245     }
246 /*! @brief Clock ip name array for RNG. */
247 #define RNG_CLOCKS \
248     {              \
249         kCLOCK_Rng \
250     }
251 /*! @brief Clock ip name array for USBHMR0. */
252 #define USBHMR0_CLOCKS \
253     {                  \
254         kCLOCK_Usbhmr0 \
255     }
256 /*! @brief Clock ip name array for USBHSL0. */
257 #define USBHSL0_CLOCKS \
258     {                  \
259         kCLOCK_Usbhsl0 \
260     }
261 /*! @brief Clock ip name array for SHA0. */
262 #define SHA0_CLOCKS \
263     {               \
264         kCLOCK_Sha0 \
265     }
266 /*! @brief Clock ip name array for SMARTCARD. */
267 #define SMARTCARD_CLOCKS                     \
268     {                                        \
269         kCLOCK_SmartCard0, kCLOCK_SmartCard1 \
270     }
271 /*! @brief Clock ip name array for USBD. */
272 #define USBD_CLOCKS                              \
273     {                                            \
274         kCLOCK_Usbd0, kCLOCK_Usbh1, kCLOCK_Usbd1 \
275     }
276 /*! @brief Clock ip name array for USBH. */
277 #define USBH_CLOCKS  \
278     {                \
279         kCLOCK_Usbh1 \
280     }
281 /*! @brief Clock gate name used for CLOCK_EnableClock/CLOCK_DisableClock. */
282 /*------------------------------------------------------------------------------
283  clock_ip_name_t definition:
284 ------------------------------------------------------------------------------*/
285 
286 #define CLK_GATE_REG_OFFSET_SHIFT 8U
287 #define CLK_GATE_REG_OFFSET_MASK  0xFFFFFF00U
288 #define CLK_GATE_BIT_SHIFT_SHIFT  0U
289 #define CLK_GATE_BIT_SHIFT_MASK   0x000000FFU
290 
291 #define CLK_GATE_DEFINE(reg_offset, bit_shift)                                  \
292     ((((reg_offset) << CLK_GATE_REG_OFFSET_SHIFT) & CLK_GATE_REG_OFFSET_MASK) | \
293      (((bit_shift) << CLK_GATE_BIT_SHIFT_SHIFT) & CLK_GATE_BIT_SHIFT_MASK))
294 
295 #define CLK_GATE_ABSTRACT_REG_OFFSET(x) (((uint32_t)(x)&CLK_GATE_REG_OFFSET_MASK) >> CLK_GATE_REG_OFFSET_SHIFT)
296 #define CLK_GATE_ABSTRACT_BITS_SHIFT(x) (((uint32_t)(x)&CLK_GATE_BIT_SHIFT_MASK) >> CLK_GATE_BIT_SHIFT_SHIFT)
297 
298 #define AHB_CLK_CTRL0   0
299 #define AHB_CLK_CTRL1   1
300 #define AHB_CLK_CTRL2   2
301 #define ASYNC_CLK_CTRL0 3
302 
303 /*! @brief Clock gate name used for CLOCK_EnableClock/CLOCK_DisableClock. */
304 typedef enum _clock_ip_name
305 {
306     kCLOCK_IpInvalid = 0U,                                /*!< Invalid Ip Name. */
307     kCLOCK_Rom       = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 1), /*!< Clock gate name: Rom. */
308 
309     kCLOCK_Sram1 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 3), /*!< Clock gate name: Sram1. */
310 
311     kCLOCK_Sram2 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 4), /*!< Clock gate name: Sram2. */
312 
313     kCLOCK_Sram3 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 5), /*!< Clock gate name: Sram3. */
314 
315     kCLOCK_Spifi = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 10), /*!< Clock gate name: Spifi. */
316 
317     kCLOCK_InputMux = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 11), /*!< Clock gate name: InputMux. */
318 
319     kCLOCK_Iocon = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 13), /*!< Clock gate name: Iocon. */
320 
321     kCLOCK_Gpio0 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 14), /*!< Clock gate name: Gpio0. */
322 
323     kCLOCK_Gpio1 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 15), /*!< Clock gate name: Gpio1. */
324 
325     kCLOCK_Gpio2 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 16), /*!< Clock gate name: Gpio2. */
326 
327     kCLOCK_Gpio3 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 17), /*!< Clock gate name: Gpio3. */
328 
329     kCLOCK_Pint = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 18), /*!< Clock gate name: Pint. */
330 
331     kCLOCK_Gint = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 19), /*!< Clock gate name: Gint. */
332 
333     kCLOCK_Dma = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 20), /*!< Clock gate name: Dma. */
334 
335     kCLOCK_Crc = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 21), /*!< Clock gate name: Crc. */
336 
337     kCLOCK_Wwdt = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 22), /*!< Clock gate name: Wwdt. */
338 
339     kCLOCK_Rtc = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 23), /*!< Clock gate name: Rtc. */
340 
341     kCLOCK_Adc0 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 27), /*!< Clock gate name: Adc0. */
342 
343     kCLOCK_Mrt = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 0), /*!< Clock gate name: Mrt. */
344 
345     kCLOCK_Rit = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 1), /*!< Clock gate name: Rit. */
346 
347     kCLOCK_Sct0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 2), /*!< Clock gate name: Sct0. */
348 
349     kCLOCK_Mcan0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 7), /*!< Clock gate name: Mcan0. */
350 
351     kCLOCK_Mcan1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 8), /*!< Clock gate name: Mcan1. */
352 
353     kCLOCK_Utick = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 10), /*!< Clock gate name: Utick. */
354 
355     kCLOCK_FlexComm0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 11), /*!< Clock gate name: FlexComm0. */
356 
357     kCLOCK_FlexComm1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 12), /*!< Clock gate name: FlexComm1. */
358 
359     kCLOCK_FlexComm2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 13), /*!< Clock gate name: FlexComm2. */
360 
361     kCLOCK_FlexComm3 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 14), /*!< Clock gate name: FlexComm3. */
362 
363     kCLOCK_FlexComm4 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 15), /*!< Clock gate name: FlexComm4. */
364 
365     kCLOCK_FlexComm5 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 16), /*!< Clock gate name: FlexComm5. */
366 
367     kCLOCK_FlexComm6 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 17), /*!< Clock gate name: FlexComm6. */
368 
369     kCLOCK_FlexComm7 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 18), /*!< Clock gate name: FlexComm7. */
370 
371     kCLOCK_MinUart0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 11), /*!< Clock gate name: MinUart0. */
372 
373     kCLOCK_MinUart1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 12), /*!< Clock gate name: MinUart1. */
374 
375     kCLOCK_MinUart2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 13), /*!< Clock gate name: MinUart2. */
376 
377     kCLOCK_MinUart3 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 14), /*!< Clock gate name: MinUart3. */
378 
379     kCLOCK_MinUart4 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 15), /*!< Clock gate name: MinUart4. */
380 
381     kCLOCK_MinUart5 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 16), /*!< Clock gate name: MinUart5. */
382 
383     kCLOCK_MinUart6 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 17), /*!< Clock gate name: MinUart6. */
384 
385     kCLOCK_MinUart7 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 18), /*!< Clock gate name: MinUart7. */
386 
387     kCLOCK_LSpi0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 11), /*!< Clock gate name: LSpi0. */
388 
389     kCLOCK_LSpi1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 12), /*!< Clock gate name: LSpi1. */
390 
391     kCLOCK_LSpi2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 13), /*!< Clock gate name: LSpi2. */
392 
393     kCLOCK_LSpi3 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 14), /*!< Clock gate name: LSpi3. */
394 
395     kCLOCK_LSpi4 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 15), /*!< Clock gate name: LSpi4. */
396 
397     kCLOCK_LSpi5 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 16), /*!< Clock gate name: LSpi5. */
398 
399     kCLOCK_LSpi6 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 17), /*!< Clock gate name: LSpi6. */
400 
401     kCLOCK_LSpi7 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 18), /*!< Clock gate name: LSpi7. */
402 
403     kCLOCK_BI2c0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 11), /*!< Clock gate name: BI2c0. */
404 
405     kCLOCK_BI2c1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 12), /*!< Clock gate name: BI2c1. */
406 
407     kCLOCK_BI2c2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 13), /*!< Clock gate name: BI2c2. */
408 
409     kCLOCK_BI2c3 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 14), /*!< Clock gate name: BI2c3. */
410 
411     kCLOCK_BI2c4 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 15), /*!< Clock gate name: BI2c4. */
412 
413     kCLOCK_BI2c5 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 16), /*!< Clock gate name: BI2c5. */
414 
415     kCLOCK_BI2c6 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 17), /*!< Clock gate name: BI2c6. */
416 
417     kCLOCK_BI2c7 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 18), /*!< Clock gate name: BI2c7. */
418 
419     kCLOCK_FlexI2s0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 11), /*!< Clock gate name: FlexI2s0. */
420 
421     kCLOCK_FlexI2s1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 12), /*!< Clock gate name: FlexI2s1. */
422 
423     kCLOCK_FlexI2s2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 13), /*!< Clock gate name: FlexI2s2. */
424 
425     kCLOCK_FlexI2s3 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 14), /*!< Clock gate name: FlexI2s3. */
426 
427     kCLOCK_FlexI2s4 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 15), /*!< Clock gate name: FlexI2s4. */
428 
429     kCLOCK_FlexI2s5 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 16), /*!< Clock gate name: FlexI2s5. */
430 
431     kCLOCK_FlexI2s6 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 17), /*!< Clock gate name: FlexI2s6. */
432 
433     kCLOCK_FlexI2s7 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 18), /*!< Clock gate name: FlexI2s7. */
434 
435     kCLOCK_DMic = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 19), /*!< Clock gate name: DMic. */
436 
437     kCLOCK_Ct32b2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 22), /*!< Clock gate name: Ct32b2. */
438 
439     kCLOCK_Usbd0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 25), /*!< Clock gate name: Usbd0. */
440 
441     kCLOCK_Ct32b0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 26), /*!< Clock gate name: Ct32b0. */
442 
443     kCLOCK_Ct32b1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 27), /*!< Clock gate name: Ct32b1. */
444 
445     kCLOCK_BodyBias0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 29), /*!< Clock gate name: BodyBias0. */
446 
447     kCLOCK_EzhArchB0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 31), /*!< Clock gate name: EzhArchB0. */
448 
449     kCLOCK_Lcd = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 2), /*!< Clock gate name: Lcd. */
450 
451     kCLOCK_Sdio = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 3), /*!< Clock gate name: Sdio. */
452 
453     kCLOCK_Usbh1 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 4), /*!< Clock gate name: Usbh1. */
454 
455     kCLOCK_Usbd1 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 5), /*!< Clock gate name: Usbd1. */
456 
457     kCLOCK_UsbRam1 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 6), /*!< Clock gate name: UsbRam1. */
458 
459     kCLOCK_Emc = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 7), /*!< Clock gate name: Emc. */
460 
461     kCLOCK_Eth = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 8), /*!< Clock gate name: Eth. */
462 
463     kCLOCK_Gpio4 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 9), /*!< Clock gate name: Gpio4. */
464 
465     kCLOCK_Gpio5 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 10), /*!< Clock gate name: Gpio5. */
466 
467     kCLOCK_Aes = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 11), /*!< Clock gate name: Aes. */
468 
469     kCLOCK_Otp = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 12), /*!< Clock gate name: Otp. */
470 
471     kCLOCK_Rng = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 13), /*!< Clock gate name: Rng. */
472 
473     kCLOCK_FlexComm8 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 14), /*!< Clock gate name: FlexComm8. */
474 
475     kCLOCK_FlexComm9 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 15), /*!< Clock gate name: FlexComm9. */
476 
477     kCLOCK_MinUart8 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 14), /*!< Clock gate name: MinUart8. */
478 
479     kCLOCK_MinUart9 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 15), /*!< Clock gate name: MinUart9. */
480 
481     kCLOCK_LSpi8 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 14), /*!< Clock gate name: LSpi8. */
482 
483     kCLOCK_LSpi9 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 15), /*!< Clock gate name: LSpi9. */
484 
485     kCLOCK_BI2c8 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 14), /*!< Clock gate name: BI2c8. */
486 
487     kCLOCK_BI2c9 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 15), /*!< Clock gate name: BI2c9. */
488 
489     kCLOCK_FlexI2s8 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 14), /*!< Clock gate name: FlexI2s8. */
490 
491     kCLOCK_FlexI2s9 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 15), /*!< Clock gate name: FlexI2s9. */
492 
493     kCLOCK_Usbhmr0 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 16), /*!< Clock gate name: Usbhmr0. */
494 
495     kCLOCK_Usbhsl0 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 17), /*!< Clock gate name: Usbhsl0. */
496 
497     kCLOCK_Sha0 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 18), /*!< Clock gate name: Sha0. */
498 
499     kCLOCK_SmartCard0 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 19), /*!< Clock gate name: SmartCard0. */
500 
501     kCLOCK_SmartCard1 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 20), /*!< Clock gate name: SmartCard1. */
502 
503     kCLOCK_FlexComm10 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 21), /*!< Clock gate name: FlexComm10. */
504 
505     kCLOCK_Puf = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 23), /*!< Clock gate name: Puf. */
506 
507     kCLOCK_Ct32b3 = CLK_GATE_DEFINE(ASYNC_CLK_CTRL0, 13), /*!< Clock gate name: Ct32b3. */
508 
509     kCLOCK_Ct32b4 = CLK_GATE_DEFINE(ASYNC_CLK_CTRL0, 14) /*!< Clock gate name: Ct32b4. */
510 } clock_ip_name_t;
511 
512 /*! @brief Clock name used to get clock frequency. */
513 typedef enum _clock_name
514 {
515     kCLOCK_CoreSysClk,  /*!< Core/system clock  (aka MAIN_CLK)                       */
516     kCLOCK_BusClk,      /*!< Bus clock (AHB clock)                                   */
517     kCLOCK_ClockOut,    /*!< CLOCKOUT                                                */
518     kCLOCK_FroHf,       /*!< FRO48/96                                                */
519     kCLOCK_UsbPll,      /*!< USB1 PLL                                                */
520     kCLOCK_Mclk,        /*!< MCLK                                                    */
521     kCLOCK_Fro12M,      /*!< FRO12M                                                  */
522     kCLOCK_ExtClk,      /*!< External Clock                                          */
523     kCLOCK_PllOut,      /*!< PLL Output                                              */
524     kCLOCK_UsbClk,      /*!< USB input                                               */
525     kCLOCK_WdtOsc,      /*!< Watchdog Oscillator                                     */
526     kCLOCK_Frg,         /*!< Frg Clock                                               */
527     kCLOCK_AsyncApbClk, /*!< Async APB clock                                         */
528 } clock_name_t;
529 
530 /**
531  * @brief Clock source selections for the asynchronous APB clock
532  */
533 typedef enum _async_clock_src
534 {
535     kCLOCK_AsyncMainClk = 0, /*!< Main System clock */
536     kCLOCK_AsyncFro12Mhz,    /*!< 12MHz FRO */
537     kCLOCK_AsyncAudioPllClk, /*!< Async Audio PLL clock. */
538     kCLOCK_AsyncI2cClkFc6,   /*!< Async I2C clock. */
539 
540 } async_clock_src_t;
541 
542 /*! @brief Clock Mux Switches
543  *  The encoding is as follows each connection identified is 32bits wide while 24bits are valuable
544  *  starting from LSB upwards
545  *
546  *  [4 bits for choice, 0 means invalid choice] [8 bits mux ID]*
547  *
548  */
549 
550 #define CLK_ATTACH_ID(mux, sel, pos) ((((uint32_t)(mux) << 0U) | (((uint32_t)(sel) + 1U) & 0xFU) << 8U) << ((pos)*12U))
551 #define MUX_A(mux, sel)              CLK_ATTACH_ID((mux), (sel), 0U)
552 #define MUX_B(mux, sel, selector)    (CLK_ATTACH_ID((mux), (sel), 1U) | ((selector) << 24U))
553 
554 #define GET_ID_ITEM(connection)      ((connection)&0xFFFU)
555 #define GET_ID_NEXT_ITEM(connection) ((connection) >> 12U)
556 #define GET_ID_ITEM_MUX(connection)  ((uint8_t)((connection)&0xFFU))
557 #define GET_ID_ITEM_SEL(connection)  ((uint8_t)((((connection)&0xF00U) >> 8U) - 1U))
558 #define GET_ID_SELECTOR(connection)  ((connection)&0xF000000U)
559 
560 #define CM_STICKCLKSEL    0
561 #define CM_MAINCLKSELA    1
562 #define CM_MAINCLKSELB    2
563 #define CM_CLKOUTCLKSELA  3
564 #define CM_SYSPLLCLKSEL   5
565 #define CM_AUDPLLCLKSEL   7
566 #define CM_SPIFICLKSEL    9
567 #define CM_ADCASYNCCLKSEL 10
568 #define CM_USB0CLKSEL     11
569 #define CM_USB1CLKSEL     12
570 #define CM_FXCOMCLKSEL0   13
571 #define CM_FXCOMCLKSEL1   14
572 #define CM_FXCOMCLKSEL2   15
573 #define CM_FXCOMCLKSEL3   16
574 #define CM_FXCOMCLKSEL4   17
575 #define CM_FXCOMCLKSEL5   18
576 #define CM_FXCOMCLKSEL6   19
577 #define CM_FXCOMCLKSEL7   20
578 #define CM_FXCOMCLKSEL8   21
579 #define CM_FXCOMCLKSEL9   22
580 #define CM_FXCOMCLKSEL10  23
581 #define CM_MCLKCLKSEL     25
582 #define CM_FRGCLKSEL      27
583 #define CM_DMICCLKSEL     28
584 #define CM_SCTCLKSEL      29
585 #define CM_LCDCLKSEL      30
586 #define CM_SDIOCLKSEL     31
587 
588 #define CM_ASYNCAPB 32U
589 
590 /*!
591  * @brief The enumerator of clock attach Id.
592  */
593 typedef enum _clock_attach_id
594 {
595 
596     kSYSTICK_DIV_CLK_to_SYSTICKCLK = MUX_A(CM_STICKCLKSEL, 0), /*!< Attach SYSTICK_DIV_CLK to SYSTICKCLK. */
597 
598     kWDT_OSC_to_SYSTICKCLK = MUX_A(CM_STICKCLKSEL, 1), /*!< Attach WDT_OSC to SYSTICKCLK. */
599 
600     kOSC32K_to_SYSTICKCLK = MUX_A(CM_STICKCLKSEL, 2), /*!< Attach OSC32K to SYSTICKCLK. */
601 
602     kFRO12M_to_SYSTICKCLK = MUX_A(CM_STICKCLKSEL, 3), /*!< Attach FRO12M to SYSTICKCLK. */
603 
604     kNONE_to_SYSTICKCLK = MUX_A(CM_STICKCLKSEL, 7), /*!< Attach NONE to SYSTICKCLK. */
605 
606     kFRO12M_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 0) | MUX_B(CM_MAINCLKSELB, 0, 0), /*!< Attach FRO12M to MAIN_CLK. */
607 
608     kEXT_CLK_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 1) | MUX_B(CM_MAINCLKSELB, 0, 0), /*!< Attach EXT_CLK to MAIN_CLK. */
609 
610     kWDT_OSC_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 2) | MUX_B(CM_MAINCLKSELB, 0, 0), /*!< Attach WDT_OSC to MAIN_CLK. */
611 
612     kFRO_HF_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 3) | MUX_B(CM_MAINCLKSELB, 0, 0), /*!< Attach FRO_HF to MAIN_CLK. */
613 
614     kSYS_PLL_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 0) | MUX_B(CM_MAINCLKSELB, 2, 0), /*!< Attach SYS_PLL to MAIN_CLK. */
615 
616     kOSC32K_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 0) | MUX_B(CM_MAINCLKSELB, 3, 0), /*!< Attach OSC32K to MAIN_CLK. */
617 
618     kMAIN_CLK_to_CLKOUT = MUX_A(CM_CLKOUTCLKSELA, 0), /*!< Attach MAIN_CLK to CLKOUT. */
619 
620     kEXT_CLK_to_CLKOUT = MUX_A(CM_CLKOUTCLKSELA, 1), /*!< Attach EXT_CLK to CLKOUT. */
621 
622     kWDT_OSC_to_CLKOUT = MUX_A(CM_CLKOUTCLKSELA, 2), /*!< Attach WDT_OSC to CLKOUT. */
623 
624     kFRO_HF_to_CLKOUT = MUX_A(CM_CLKOUTCLKSELA, 3), /*!< Attach FRO_HF to CLKOUT. */
625 
626     kSYS_PLL_to_CLKOUT = MUX_A(CM_CLKOUTCLKSELA, 4), /*!< Attach SYS_PLL to CLKOUT. */
627 
628     kUSB_PLL_to_CLKOUT = MUX_A(CM_CLKOUTCLKSELA, 5), /*!< Attach USB_PLL to CLKOUT. */
629 
630     kAUDIO_PLL_to_CLKOUT = MUX_A(CM_CLKOUTCLKSELA, 6), /*!< Attach AUDIO_PLL to CLKOUT. */
631 
632     kOSC32K_OSC_to_CLKOUT = MUX_A(CM_CLKOUTCLKSELA, 7), /*!< Attach OSC32K_OSC to CLKOUT. */
633 
634     kFRO12M_to_SYS_PLL = MUX_A(CM_SYSPLLCLKSEL, 0), /*!< Attach FRO12M to SYS_PLL. */
635 
636     kEXT_CLK_to_SYS_PLL = MUX_A(CM_SYSPLLCLKSEL, 1), /*!< Attach EXT_CLK to SYS_PLL. */
637 
638     kWDT_OSC_to_SYS_PLL = MUX_A(CM_SYSPLLCLKSEL, 2), /*!< Attach WDT_OSC to SYS_PLL. */
639 
640     kOSC32K_to_SYS_PLL = MUX_A(CM_SYSPLLCLKSEL, 3), /*!< Attach OSC32K to SYS_PLL. */
641 
642     kNONE_to_SYS_PLL = MUX_A(CM_SYSPLLCLKSEL, 7), /*!< Attach NONE to SYS_PLL. */
643 
644     kFRO12M_to_AUDIO_PLL = MUX_A(CM_AUDPLLCLKSEL, 0), /*!< Attach FRO12M to AUDIO_PLL. */
645 
646     kEXT_CLK_to_AUDIO_PLL = MUX_A(CM_AUDPLLCLKSEL, 1), /*!< Attach EXT_CLK to AUDIO_PLL. */
647 
648     kNONE_to_AUDIO_PLL = MUX_A(CM_AUDPLLCLKSEL, 7), /*!< Attach NONE to AUDIO_PLL. */
649 
650     kMAIN_CLK_to_SPIFI_CLK = MUX_A(CM_SPIFICLKSEL, 0), /*!< Attach MAIN_CLK to SPIFI_CLK. */
651 
652     kSYS_PLL_to_SPIFI_CLK = MUX_A(CM_SPIFICLKSEL, 1), /*!< Attach SYS_PLL to SPIFI_CLK. */
653 
654     kUSB_PLL_to_SPIFI_CLK = MUX_A(CM_SPIFICLKSEL, 2), /*!< Attach USB_PLL to SPIFI_CLK. */
655 
656     kFRO_HF_to_SPIFI_CLK = MUX_A(CM_SPIFICLKSEL, 3), /*!< Attach FRO_HF to SPIFI_CLK. */
657 
658     kAUDIO_PLL_to_SPIFI_CLK = MUX_A(CM_SPIFICLKSEL, 4), /*!< Attach AUDIO_PLL to SPIFI_CLK. */
659 
660     kNONE_to_SPIFI_CLK = MUX_A(CM_SPIFICLKSEL, 7), /*!< Attach NONE to SPIFI_CLK. */
661 
662     kFRO_HF_to_ADC_CLK = MUX_A(CM_ADCASYNCCLKSEL, 0), /*!< Attach FRO_HF to ADC_CLK. */
663 
664     kSYS_PLL_to_ADC_CLK = MUX_A(CM_ADCASYNCCLKSEL, 1), /*!< Attach SYS_PLL to ADC_CLK. */
665 
666     kUSB_PLL_to_ADC_CLK = MUX_A(CM_ADCASYNCCLKSEL, 2), /*!< Attach USB_PLL to ADC_CLK. */
667 
668     kAUDIO_PLL_to_ADC_CLK = MUX_A(CM_ADCASYNCCLKSEL, 3), /*!< Attach AUDIO_PLL to ADC_CLK. */
669 
670     kNONE_to_ADC_CLK = MUX_A(CM_ADCASYNCCLKSEL, 7), /*!< Attach NONE to ADC_CLK. */
671 
672     kFRO_HF_to_USB0_CLK = MUX_A(CM_USB0CLKSEL, 0), /*!< Attach FRO_HF to USB0_CLK. */
673 
674     kSYS_PLL_to_USB0_CLK = MUX_A(CM_USB0CLKSEL, 1), /*!< Attach SYS_PLL to USB0_CLK. */
675 
676     kUSB_PLL_to_USB0_CLK = MUX_A(CM_USB0CLKSEL, 2), /*!< Attach USB_PLL to USB0_CLK. */
677 
678     kNONE_to_USB0_CLK = MUX_A(CM_USB0CLKSEL, 7), /*!< Attach NONE to USB0_CLK. */
679 
680     kFRO_HF_to_USB1_CLK = MUX_A(CM_USB1CLKSEL, 0), /*!< Attach FRO_HF to USB1_CLK. */
681 
682     kSYS_PLL_to_USB1_CLK = MUX_A(CM_USB1CLKSEL, 1), /*!< Attach SYS_PLL to USB1_CLK. */
683 
684     kUSB_PLL_to_USB1_CLK = MUX_A(CM_USB1CLKSEL, 2), /*!< Attach USB_PLL to USB1_CLK. */
685 
686     kNONE_to_USB1_CLK = MUX_A(CM_USB1CLKSEL, 7), /*!< Attach NONE to USB1_CLK. */
687 
688     kFRO12M_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 0), /*!< Attach FRO12M to FLEXCOMM0. */
689 
690     kFRO_HF_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 1), /*!< Attach FRO_HF to FLEXCOMM0. */
691 
692     kAUDIO_PLL_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 2), /*!< Attach AUDIO_PLL to FLEXCOMM0. */
693 
694     kMCLK_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 3), /*!< Attach MCLK to FLEXCOMM0. */
695 
696     kFRG_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 4), /*!< Attach FRG to FLEXCOMM0. */
697 
698     kNONE_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 7), /*!< Attach NONE to FLEXCOMM0. */
699 
700     kFRO12M_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 0), /*!< Attach FRO12M to FLEXCOMM1. */
701 
702     kFRO_HF_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 1), /*!< Attach FRO_HF to FLEXCOMM1. */
703 
704     kAUDIO_PLL_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 2), /*!< Attach AUDIO_PLL to FLEXCOMM1. */
705 
706     kMCLK_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 3), /*!< Attach MCLK to FLEXCOMM1. */
707 
708     kFRG_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 4), /*!< Attach FRG to FLEXCOMM1. */
709 
710     kNONE_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 7), /*!< Attach NONE to FLEXCOMM1. */
711 
712     kFRO12M_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 0), /*!< Attach FRO12M to FLEXCOMM2. */
713 
714     kFRO_HF_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 1), /*!< Attach FRO_HF to FLEXCOMM2. */
715 
716     kAUDIO_PLL_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 2), /*!< Attach AUDIO_PLL to FLEXCOMM2. */
717 
718     kMCLK_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 3), /*!< Attach MCLK to FLEXCOMM2. */
719 
720     kFRG_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 4), /*!< Attach FRG to FLEXCOMM2. */
721 
722     kNONE_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 7), /*!< Attach NONE to FLEXCOMM2. */
723 
724     kFRO12M_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 0), /*!< Attach FRO12M to FLEXCOMM3. */
725 
726     kFRO_HF_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 1), /*!< Attach FRO_HF to FLEXCOMM3. */
727 
728     kAUDIO_PLL_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 2), /*!< Attach AUDIO_PLL to FLEXCOMM3. */
729 
730     kMCLK_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 3), /*!< Attach MCLK to FLEXCOMM3. */
731 
732     kFRG_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 4), /*!< Attach FRG to FLEXCOMM3. */
733 
734     kNONE_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 7), /*!< Attach NONE to FLEXCOMM3. */
735 
736     kFRO12M_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 0), /*!< Attach FRO12M to FLEXCOMM4. */
737 
738     kFRO_HF_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 1), /*!< Attach FRO_HF to FLEXCOMM4. */
739 
740     kAUDIO_PLL_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 2), /*!< Attach AUDIO_PLL to FLEXCOMM4. */
741 
742     kMCLK_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 3), /*!< Attach MCLK to FLEXCOMM4. */
743 
744     kFRG_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 4), /*!< Attach FRG to FLEXCOMM4. */
745 
746     kNONE_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 7), /*!< Attach NONE to FLEXCOMM4. */
747 
748     kFRO12M_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 0), /*!< Attach FRO12M to FLEXCOMM5. */
749 
750     kFRO_HF_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 1), /*!< Attach FRO_HF to FLEXCOMM5. */
751 
752     kAUDIO_PLL_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 2), /*!< Attach AUDIO_PLL to FLEXCOMM5. */
753 
754     kMCLK_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 3), /*!< Attach MCLK to FLEXCOMM5. */
755 
756     kFRG_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 4), /*!< Attach FRG to FLEXCOMM5. */
757 
758     kNONE_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 7), /*!< Attach NONE to FLEXCOMM5. */
759 
760     kFRO12M_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 0), /*!< Attach FRO12M to FLEXCOMM6. */
761 
762     kFRO_HF_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 1), /*!< Attach FRO_HF to FLEXCOMM6. */
763 
764     kAUDIO_PLL_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 2), /*!< Attach AUDIO_PLL to FLEXCOMM6. */
765 
766     kMCLK_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 3), /*!< Attach MCLK to FLEXCOMM6. */
767 
768     kFRG_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 4), /*!< Attach FRG to FLEXCOMM6. */
769 
770     kNONE_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 7), /*!< Attach NONE to FLEXCOMM6. */
771 
772     kFRO12M_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 0), /*!< Attach FRO12M to FLEXCOMM7. */
773 
774     kFRO_HF_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 1), /*!< Attach FRO_HF to FLEXCOMM7. */
775 
776     kAUDIO_PLL_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 2), /*!< Attach AUDIO_PLL to FLEXCOMM7. */
777 
778     kMCLK_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 3), /*!< Attach MCLK to FLEXCOMM7. */
779 
780     kFRG_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 4), /*!< Attach FRG to FLEXCOMM7. */
781 
782     kNONE_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 7), /*!< Attach NONE to FLEXCOMM7. */
783 
784     kFRO12M_to_FLEXCOMM8 = MUX_A(CM_FXCOMCLKSEL8, 0), /*!< Attach FRO12M to FLEXCOMM8. */
785 
786     kFRO_HF_to_FLEXCOMM8 = MUX_A(CM_FXCOMCLKSEL8, 1), /*!< Attach FRO_HF to FLEXCOMM8. */
787 
788     kAUDIO_PLL_to_FLEXCOMM8 = MUX_A(CM_FXCOMCLKSEL8, 2), /*!< Attach AUDIO_PLL to FLEXCOMM8. */
789 
790     kMCLK_to_FLEXCOMM8 = MUX_A(CM_FXCOMCLKSEL8, 3), /*!< Attach MCLK to FLEXCOMM8. */
791 
792     kFRG_to_FLEXCOMM8 = MUX_A(CM_FXCOMCLKSEL8, 4), /*!< Attach FRG to FLEXCOMM8. */
793 
794     kNONE_to_FLEXCOMM8 = MUX_A(CM_FXCOMCLKSEL8, 7), /*!< Attach NONE to FLEXCOMM8. */
795 
796     kFRO12M_to_FLEXCOMM9 = MUX_A(CM_FXCOMCLKSEL9, 0), /*!< Attach FRO12M to FLEXCOMM9. */
797 
798     kFRO_HF_to_FLEXCOMM9 = MUX_A(CM_FXCOMCLKSEL9, 1), /*!< Attach FRO_HF to FLEXCOMM9. */
799 
800     kAUDIO_PLL_to_FLEXCOMM9 = MUX_A(CM_FXCOMCLKSEL9, 2), /*!< Attach AUDIO_PLL to FLEXCOMM9. */
801 
802     kMCLK_to_FLEXCOMM9 = MUX_A(CM_FXCOMCLKSEL9, 3), /*!< Attach MCLK to FLEXCOMM9. */
803 
804     kFRG_to_FLEXCOMM9 = MUX_A(CM_FXCOMCLKSEL9, 4), /*!< Attach FRG to FLEXCOMM9. */
805 
806     kNONE_to_FLEXCOMM9 = MUX_A(CM_FXCOMCLKSEL9, 7), /*!< Attach NONE to FLEXCOMM9. */
807 
808     kMAIN_CLK_to_FLEXCOMM10 = MUX_A(CM_FXCOMCLKSEL10, 0), /*!< Attach MAIN_CLK to FLEXCOMM10. */
809 
810     kSYS_PLL_to_FLEXCOMM10 = MUX_A(CM_FXCOMCLKSEL10, 1), /*!< Attach SYS_PLL to FLEXCOMM10. */
811 
812     kUSB_PLL_to_FLEXCOMM10 = MUX_A(CM_FXCOMCLKSEL10, 2), /*!< Attach USB_PLL to FLEXCOMM10. */
813 
814     kFRO_HF_to_FLEXCOMM10 = MUX_A(CM_FXCOMCLKSEL10, 3), /*!< Attach FRO_HF to FLEXCOMM10. */
815 
816     kAUDIO_PLL_to_FLEXCOMM10 = MUX_A(CM_FXCOMCLKSEL10, 4), /*!< Attach AUDIO_PLL to FLEXCOMM10. */
817 
818     kNONE_to_FLEXCOMM10 = MUX_A(CM_FXCOMCLKSEL10, 7), /*!< Attach NONE to FLEXCOMM10. */
819 
820     kFRO_HF_to_MCLK = MUX_A(CM_MCLKCLKSEL, 0), /*!< Attach FRO_HF to MCLK. */
821 
822     kAUDIO_PLL_to_MCLK = MUX_A(CM_MCLKCLKSEL, 1), /*!< Attach AUDIO_PLL to MCLK. */
823 
824     kNONE_to_MCLK = MUX_A(CM_MCLKCLKSEL, 7), /*!< Attach NONE to MCLK. */
825 
826     kMAIN_CLK_to_FRG = MUX_A(CM_FRGCLKSEL, 0), /*!< Attach MAIN_CLK to FRG. */
827 
828     kSYS_PLL_to_FRG = MUX_A(CM_FRGCLKSEL, 1), /*!< Attach SYS_PLL to FRG. */
829 
830     kFRO12M_to_FRG = MUX_A(CM_FRGCLKSEL, 2), /*!< Attach FRO12M to FRG. */
831 
832     kFRO_HF_to_FRG = MUX_A(CM_FRGCLKSEL, 3), /*!< Attach FRO_HF to FRG. */
833 
834     kNONE_to_FRG = MUX_A(CM_FRGCLKSEL, 7), /*!< Attach NONE to FRG. */
835 
836     kFRO12M_to_DMIC = MUX_A(CM_DMICCLKSEL, 0), /*!< Attach FRO12M to DMIC. */
837 
838     kFRO_HF_DIV_to_DMIC = MUX_A(CM_DMICCLKSEL, 1), /*!< Attach FRO_HF_DIV to DMIC. */
839 
840     kAUDIO_PLL_to_DMIC = MUX_A(CM_DMICCLKSEL, 2), /*!< Attach AUDIO_PLL to DMIC. */
841 
842     kMCLK_to_DMIC = MUX_A(CM_DMICCLKSEL, 3), /*!< Attach MCLK to DMIC. */
843 
844     kMAIN_CLK_to_DMIC = MUX_A(CM_DMICCLKSEL, 4), /*!< Attach MAIN_CLK to DMIC. */
845 
846     kWDT_OSC_to_DMIC = MUX_A(CM_DMICCLKSEL, 5), /*!< Attach WDT_OSC to DMIC. */
847 
848     kNONE_to_DMIC = MUX_A(CM_DMICCLKSEL, 7), /*!< Attach NONE to DMIC. */
849 
850     kMAIN_CLK_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 0), /*!< Attach MAIN_CLK to SCT_CLK. */
851 
852     kSYS_PLL_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 1), /*!< Attach SYS_PLL to SCT_CLK. */
853 
854     kFRO_HF_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 2), /*!< Attach FRO_HF to SCT_CLK. */
855 
856     kAUDIO_PLL_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 3), /*!< Attach AUDIO_PLL to SCT_CLK. */
857 
858     kNONE_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 7), /*!< Attach NONE to SCT_CLK. */
859 
860     kMAIN_CLK_to_LCD_CLK = MUX_A(CM_LCDCLKSEL, 0), /*!< Attach MAIN_CLK to LCD_CLK. */
861 
862     kLCDCLKIN_to_LCD_CLK = MUX_A(CM_LCDCLKSEL, 1), /*!< Attach LCDCLKIN to LCD_CLK. */
863 
864     kFRO_HF_to_LCD_CLK = MUX_A(CM_LCDCLKSEL, 2), /*!< Attach FRO_HF to LCD_CLK. */
865 
866     kNONE_to_LCD_CLK = MUX_A(CM_LCDCLKSEL, 3), /*!< Attach NONE to LCD_CLK. */
867 
868     kMAIN_CLK_to_SDIO_CLK = MUX_A(CM_SDIOCLKSEL, 0), /*!< Attach MAIN_CLK to SDIO_CLK. */
869 
870     kSYS_PLL_to_SDIO_CLK = MUX_A(CM_SDIOCLKSEL, 1), /*!< Attach SYS_PLL to SDIO_CLK. */
871 
872     kUSB_PLL_to_SDIO_CLK = MUX_A(CM_SDIOCLKSEL, 2), /*!< Attach USB_PLL to SDIO_CLK. */
873 
874     kFRO_HF_to_SDIO_CLK = MUX_A(CM_SDIOCLKSEL, 3), /*!< Attach FRO_HF to SDIO_CLK. */
875 
876     kAUDIO_PLL_to_SDIO_CLK = MUX_A(CM_SDIOCLKSEL, 4), /*!< Attach AUDIO_PLL to SDIO_CLK. */
877 
878     kNONE_to_SDIO_CLK = MUX_A(CM_SDIOCLKSEL, 7), /*!< Attach NONE to SDIO_CLK. */
879 
880     kMAIN_CLK_to_ASYNC_APB = MUX_A(CM_ASYNCAPB, 0), /*!< Attach MAIN_CLK to ASYNC_APB. */
881 
882     kFRO12M_to_ASYNC_APB = MUX_A(CM_ASYNCAPB, 1), /*!< Attach FRO12M to ASYNC_APB. */
883 
884     kAUDIO_PLL_to_ASYNC_APB = MUX_A(CM_ASYNCAPB, 2), /*!< Attach AUDIO_PLL to ASYNC_APB. */
885 
886     kI2C_CLK_FC6_to_ASYNC_APB = MUX_A(CM_ASYNCAPB, 3), /*!< Attach I2C_CLK_FC6 to ASYNC_APB. */
887 
888     kNONE_to_NONE = (int)0x80000000U, /*!< Attach NONE to NONE. */
889 
890 } clock_attach_id_t;
891 
892 /*! @brief Clock dividers */
893 typedef enum _clock_div_name
894 {
895     kCLOCK_DivSystickClk = 0, /*!< Systick Clock Divider. */
896 
897     kCLOCK_DivArmTrClkDiv = 1, /*!< Arm Tr Clk Div Divider. */
898 
899     kCLOCK_DivCan0Clk = 2, /*!< Can0 Clock Divider. */
900 
901     kCLOCK_DivCan1Clk = 3, /*!< Can1 Clock Divider. */
902 
903     kCLOCK_DivSmartCard0Clk = 4, /*!< Smart Card0 Clock Divider. */
904 
905     kCLOCK_DivSmartCard1Clk = 5, /*!< Smart Card1 Clock Divider. */
906 
907     kCLOCK_DivAhbClk = 32, /*!< Ahb Clock Divider. */
908 
909     kCLOCK_DivClkOut = 33, /*!< Clk Out Divider. */
910 
911     kCLOCK_DivFrohfClk = 34, /*!< Frohf Clock Divider. */
912 
913     kCLOCK_DivSpifiClk = 36, /*!< Spifi Clock Divider. */
914 
915     kCLOCK_DivAdcAsyncClk = 37, /*!< Adc Async Clock Divider. */
916 
917     kCLOCK_DivUsb0Clk = 38, /*!< Usb0 Clock Divider. */
918 
919     kCLOCK_DivUsb1Clk = 39, /*!< Usb1 Clock Divider. */
920 
921     kCLOCK_DivFrg = 40, /*!< Frg Divider. */
922 
923     kCLOCK_DivDmicClk = 42, /*!< Dmic Clock Divider. */
924 
925     kCLOCK_DivMClk = 43, /*!< Main Clock Divider. */
926 
927     kCLOCK_DivLcdClk = 44, /*!< Lcd Clock Divider. */
928 
929     kCLOCK_DivSctClk = 45, /*!< Sct Clock Divider. */
930 
931     kCLOCK_DivEmcClk = 46, /*!< Emc Clock Divider. */
932 
933     kCLOCK_DivSdioClk = 47 /*!< Sdio clock Divider. */
934 } clock_div_name_t;
935 
936 /*******************************************************************************
937  * API
938  ******************************************************************************/
939 
940 #if defined(__cplusplus)
941 extern "C" {
942 #endif /* __cplusplus */
943 
CLOCK_EnableClock(clock_ip_name_t clk)944 static inline void CLOCK_EnableClock(clock_ip_name_t clk)
945 {
946     uint32_t index = CLK_GATE_ABSTRACT_REG_OFFSET(clk);
947     if (index < 3UL)
948     {
949         SYSCON->AHBCLKCTRLSET[index] = (1UL << CLK_GATE_ABSTRACT_BITS_SHIFT(clk));
950     }
951     else
952     {
953         SYSCON->ASYNCAPBCTRL             = SYSCON_ASYNCAPBCTRL_ENABLE(1);
954         ASYNC_SYSCON->ASYNCAPBCLKCTRLSET = (1UL << CLK_GATE_ABSTRACT_BITS_SHIFT(clk));
955     }
956 }
957 
CLOCK_DisableClock(clock_ip_name_t clk)958 static inline void CLOCK_DisableClock(clock_ip_name_t clk)
959 {
960     uint32_t index = CLK_GATE_ABSTRACT_REG_OFFSET(clk);
961     if (index < 3UL)
962     {
963         SYSCON->AHBCLKCTRLCLR[index] = (1UL << CLK_GATE_ABSTRACT_BITS_SHIFT(clk));
964     }
965     else
966     {
967         ASYNC_SYSCON->ASYNCAPBCLKCTRLCLR = (1UL << CLK_GATE_ABSTRACT_BITS_SHIFT(clk));
968         SYSCON->ASYNCAPBCTRL             = SYSCON_ASYNCAPBCTRL_ENABLE(0);
969     }
970 }
971 
972 /**
973  * @brief
974  *  Initialize the Core clock to given frequency (12, 48 or 96 MHz), this API is implememnt in ROM code.
975  * Turns on FRO and uses default CCO, if freq is 12000000, then high speed output is off, else high speed
976  * output is enabled.
977  * Usage: CLOCK_SetupFROClocking(frequency), (frequency must be one of 12, 48 or 96 MHz)
978  *  Note: Need to make sure ROM and OTP has power(PDRUNCFG0[17,29]= 0U) before calling this API since this API is
979  * implemented in ROM code and the FROHF TRIM value is stored in OTP
980  *
981  * @param froFreq target fro frequency.
982  * @return   Nothing
983  */
984 
985 void CLOCK_SetupFROClocking(uint32_t froFreq);
986 
987 /**
988  * @brief	Configure the clock selection muxes.
989  * @param	connection	: Clock to be configured.
990  * @return	Nothing
991  */
992 void CLOCK_AttachClk(clock_attach_id_t connection);
993 /**
994  * @brief   Get the actual clock attach id.
995  * This fuction uses the offset in input attach id, then it reads the actual source value in
996  * the register and combine the offset to obtain an actual attach id.
997  * @param   attachId  : Clock attach id to get.
998  * @return  Clock source value.
999  */
1000 clock_attach_id_t CLOCK_GetClockAttachId(clock_attach_id_t attachId);
1001 /**
1002  * @brief	Setup peripheral clock dividers.
1003  * @param	div_name	: Clock divider name
1004  * @param divided_by_value: Value to be divided
1005  * @param reset :  Whether to reset the divider counter.
1006  * @return	Nothing
1007  */
1008 void CLOCK_SetClkDiv(clock_div_name_t div_name, uint32_t divided_by_value, bool reset);
1009 
1010 /*! @brief	Return Frequency of selected clock
1011  *  @return	Frequency of selected clock
1012  */
1013 uint32_t CLOCK_GetFreq(clock_name_t clockName);
1014 /*! @brief	Return Frequency of FRO 12MHz
1015  *  @return	Frequency of FRO 12MHz
1016  */
1017 uint32_t CLOCK_GetFro12MFreq(void);
1018 /*! @brief	Return Frequency of ClockOut
1019  *  @return	Frequency of ClockOut
1020  */
1021 uint32_t CLOCK_GetClockOutClkFreq(void);
1022 /*! @brief	Return Frequency of Spifi Clock
1023  *  @return	Frequency of Spifi.
1024  */
1025 uint32_t CLOCK_GetSpifiClkFreq(void);
1026 /*! @brief	Return Frequency of Adc Clock
1027  *  @return	Frequency of Adc Clock.
1028  */
1029 uint32_t CLOCK_GetAdcClkFreq(void);
1030 /*! brief	Return Frequency of MCAN Clock
1031  *  param	MCanSel : 0U: MCAN0; 1U: MCAN1
1032  *  return	Frequency of MCAN Clock
1033  */
1034 uint32_t CLOCK_GetMCanClkFreq(uint32_t MCanSel);
1035 /*! @brief	Return Frequency of Usb0 Clock
1036  *  @return	Frequency of Usb0 Clock.
1037  */
1038 uint32_t CLOCK_GetUsb0ClkFreq(void);
1039 /*! @brief	Return Frequency of Usb1 Clock
1040  *  @return	Frequency of Usb1 Clock.
1041  */
1042 uint32_t CLOCK_GetUsb1ClkFreq(void);
1043 /*! @brief	Return Frequency of MClk Clock
1044  *  @return	Frequency of MClk Clock.
1045  */
1046 uint32_t CLOCK_GetMclkClkFreq(void);
1047 /*! @brief	Return Frequency of SCTimer Clock
1048  *  @return	Frequency of SCTimer Clock.
1049  */
1050 uint32_t CLOCK_GetSctClkFreq(void);
1051 /*! @brief	Return Frequency of SDIO Clock
1052  *  @return	Frequency of SDIO Clock.
1053  */
1054 uint32_t CLOCK_GetSdioClkFreq(void);
1055 /*! @brief	Return Frequency of LCD Clock
1056  *  @return	Frequency of LCD Clock.
1057  */
1058 uint32_t CLOCK_GetLcdClkFreq(void);
1059 /*! @brief	Return Frequency of LCD CLKIN Clock
1060  *  @return	Frequency of LCD CLKIN Clock.
1061  */
1062 uint32_t CLOCK_GetLcdClkIn(void);
1063 /*! @brief	Return Frequency of External Clock
1064  *  @return	Frequency of External Clock. If no external clock is used returns 0.
1065  */
1066 uint32_t CLOCK_GetExtClkFreq(void);
1067 /*! @brief	Return Frequency of Watchdog Oscillator
1068  *  @return	Frequency of Watchdog Oscillator
1069  */
1070 uint32_t CLOCK_GetWdtOscFreq(void);
1071 /*! @brief	Return Frequency of High-Freq output of FRO
1072  *  @return	Frequency of High-Freq output of FRO
1073  */
1074 uint32_t CLOCK_GetFroHfFreq(void);
1075 /*! @brief  Return Frequency of frg
1076  *  @return Frequency of FRG
1077  */
1078 uint32_t CLOCK_GetFrgClkFreq(void);
1079 /*! @brief  Return Frequency of dmic
1080  *  @return Frequency of DMIC
1081  */
1082 uint32_t CLOCK_GetDmicClkFreq(void);
1083 
1084 /*!
1085  * @brief Set FRG Clk
1086  * @return
1087  *        1: if set FRG CLK successfully.
1088  *        0: if set FRG CLK fail.
1089  */
1090 uint32_t CLOCK_SetFRGClock(uint32_t freq);
1091 
1092 /*! @brief	Return Frequency of PLL
1093  *  @return	Frequency of PLL
1094  */
1095 uint32_t CLOCK_GetPllOutFreq(void);
1096 /*! @brief	Return Frequency of USB PLL
1097  *  @return	Frequency of PLL
1098  */
1099 uint32_t CLOCK_GetUsbPllOutFreq(void);
1100 /*! @brief	Return Frequency of AUDIO PLL
1101  *  @return	Frequency of PLL
1102  */
1103 uint32_t CLOCK_GetAudioPllOutFreq(void);
1104 /*! @brief	Return Frequency of 32kHz osc
1105  *  @return	Frequency of 32kHz osc
1106  */
1107 uint32_t CLOCK_GetOsc32KFreq(void);
1108 /*! @brief	Return Frequency of Core System
1109  *  @return	Frequency of Core System
1110  */
1111 uint32_t CLOCK_GetCoreSysClkFreq(void);
1112 /*! @brief	Return Frequency of I2S MCLK Clock
1113  *  @return	Frequency of I2S MCLK Clock
1114  */
1115 uint32_t CLOCK_GetI2SMClkFreq(void);
1116 /*! @brief	Return Frequency of Flexcomm functional Clock
1117  *  @return	Frequency of Flexcomm functional Clock
1118  */
1119 uint32_t CLOCK_GetFlexCommClkFreq(uint32_t id);
1120 
1121 /*! @brief return FRG Clk
1122  *  @return Frequency of FRG CLK.
1123  */
1124 uint32_t CLOCK_GetFRGInputClock(void);
1125 /*! @brief	Return Asynchronous APB Clock source
1126  *  @return	Asynchronous APB CLock source
1127  */
CLOCK_GetAsyncApbClkSrc(void)1128 __STATIC_INLINE async_clock_src_t CLOCK_GetAsyncApbClkSrc(void)
1129 {
1130     return (async_clock_src_t)(uint32_t)(ASYNC_SYSCON->ASYNCAPBCLKSELA & 0x3U);
1131 }
1132 /*! @brief	Return Frequency of Asynchronous APB Clock
1133  *  @return	Frequency of Asynchronous APB Clock Clock
1134  */
1135 uint32_t CLOCK_GetAsyncApbClkFreq(void);
1136 /*! @brief	Return EMC source
1137  *  @return	EMC source
1138  */
CLOCK_GetEmcClkFreq(void)1139 __STATIC_INLINE uint32_t CLOCK_GetEmcClkFreq(void)
1140 {
1141     uint32_t freqtmp;
1142 
1143     freqtmp = CLOCK_GetCoreSysClkFreq() / ((SYSCON->AHBCLKDIV & 0xffU) + 1U);
1144     return freqtmp / ((SYSCON->EMCCLKDIV & 0xffU) + 1U);
1145 }
1146 /*! @brief	Return Audio PLL input clock rate
1147  *  @return	Audio PLL input clock rate
1148  */
1149 uint32_t CLOCK_GetAudioPLLInClockRate(void);
1150 /*! @brief	Return System PLL input clock rate
1151  *  @return	System PLL input clock rate
1152  */
1153 uint32_t CLOCK_GetSystemPLLInClockRate(void);
1154 
1155 /*! @brief	Return System PLL output clock rate
1156  *  @param	recompute	: Forces a PLL rate recomputation if true
1157  *  @return	System PLL output clock rate
1158  *  @note	The PLL rate is cached in the driver in a variable as
1159  *  the rate computation function can take some time to perform. It
1160  *  is recommended to use 'false' with the 'recompute' parameter.
1161  */
1162 uint32_t CLOCK_GetSystemPLLOutClockRate(bool recompute);
1163 
1164 /*! @brief	Return System AUDIO PLL output clock rate
1165  *  @param	recompute	: Forces a AUDIO PLL rate recomputation if true
1166  *  @return	System AUDIO PLL output clock rate
1167  *  @note	The AUDIO PLL rate is cached in the driver in a variable as
1168  *  the rate computation function can take some time to perform. It
1169  *  is recommended to use 'false' with the 'recompute' parameter.
1170  */
1171 uint32_t CLOCK_GetAudioPLLOutClockRate(bool recompute);
1172 
1173 /*! @brief	Return System USB PLL output clock rate
1174  *  @param	recompute	: Forces a USB PLL rate recomputation if true
1175  *  @return	System USB PLL output clock rate
1176  *  @note	The USB PLL rate is cached in the driver in a variable as
1177  *  the rate computation function can take some time to perform. It
1178  *  is recommended to use 'false' with the 'recompute' parameter.
1179  */
1180 uint32_t CLOCK_GetUsbPLLOutClockRate(bool recompute);
1181 
1182 /*! @brief	Enables and disables PLL bypass mode
1183  *  @brief	bypass	: true to bypass PLL (PLL output = PLL input, false to disable bypass
1184  *  @return	System PLL output clock rate
1185  */
CLOCK_SetBypassPLL(bool bypass)1186 __STATIC_INLINE void CLOCK_SetBypassPLL(bool bypass)
1187 {
1188     if (bypass)
1189     {
1190         SYSCON->SYSPLLCTRL |= (1UL << SYSCON_SYSPLLCTRL_BYPASS_SHIFT);
1191     }
1192     else
1193     {
1194         SYSCON->SYSPLLCTRL &= ~(1UL << SYSCON_SYSPLLCTRL_BYPASS_SHIFT);
1195     }
1196 }
1197 
1198 /*! @brief	Check if PLL is locked or not
1199  *  @return	true if the PLL is locked, false if not locked
1200  */
CLOCK_IsSystemPLLLocked(void)1201 __STATIC_INLINE bool CLOCK_IsSystemPLLLocked(void)
1202 {
1203     return (bool)((SYSCON->SYSPLLSTAT & SYSCON_SYSPLLSTAT_LOCK_MASK) != 0U);
1204 }
1205 
1206 /*! @brief	Check if USB PLL is locked or not
1207  *  @return	true if the USB PLL is locked, false if not locked
1208  */
CLOCK_IsUsbPLLLocked(void)1209 __STATIC_INLINE bool CLOCK_IsUsbPLLLocked(void)
1210 {
1211     return (bool)((SYSCON->USBPLLSTAT & SYSCON_USBPLLSTAT_LOCK_MASK) != 0U);
1212 }
1213 
1214 /*! @brief	Check if AUDIO PLL is locked or not
1215  *  @return	true if the AUDIO PLL is locked, false if not locked
1216  */
CLOCK_IsAudioPLLLocked(void)1217 __STATIC_INLINE bool CLOCK_IsAudioPLLLocked(void)
1218 {
1219     return (bool)((SYSCON->AUDPLLSTAT & SYSCON_AUDPLLSTAT_LOCK_MASK) != 0U);
1220 }
1221 
1222 /*! @brief	Enables and disables SYS OSC
1223  *  @brief	enable	: true to enable SYS OSC, false to disable SYS OSC
1224  */
CLOCK_Enable_SysOsc(bool enable)1225 __STATIC_INLINE void CLOCK_Enable_SysOsc(bool enable)
1226 {
1227     if (enable)
1228     {
1229         SYSCON->PDRUNCFGCLR[0] |= SYSCON_PDRUNCFG_PDEN_VD2_ANA_MASK;
1230         SYSCON->PDRUNCFGCLR[1] |= SYSCON_PDRUNCFG_PDEN_SYSOSC_MASK;
1231     }
1232 
1233     else
1234     {
1235         SYSCON->PDRUNCFGSET[0] = SYSCON_PDRUNCFG_PDEN_VD2_ANA_MASK;
1236         SYSCON->PDRUNCFGSET[1] = SYSCON_PDRUNCFG_PDEN_SYSOSC_MASK;
1237     }
1238 }
1239 
1240 /*! @brief Store the current PLL rate
1241  *  @param	rate: Current rate of the PLL
1242  *  @return	Nothing
1243  **/
1244 void CLOCK_SetStoredPLLClockRate(uint32_t rate);
1245 
1246 /*! @brief Store the current AUDIO PLL rate
1247  *  @param	rate: Current rate of the PLL
1248  *  @return	Nothing
1249  **/
1250 void CLOCK_SetStoredAudioPLLClockRate(uint32_t rate);
1251 
1252 /*! @brief PLL configuration structure flags for 'flags' field
1253  * These flags control how the PLL configuration function sets up the PLL setup structure.<br>
1254  *
1255  * When the PLL_CONFIGFLAG_USEINRATE flag is selected, the 'InputRate' field in the
1256  * configuration structure must be assigned with the expected PLL frequency. If the
1257  * PLL_CONFIGFLAG_USEINRATE is not used, 'InputRate' is ignored in the configuration
1258  * function and the driver will determine the PLL rate from the currently selected
1259  * PLL source. This flag might be used to configure the PLL input clock more accurately
1260  * when using the WDT oscillator or a more dyanmic CLKIN source.<br>
1261  *
1262  * When the PLL_CONFIGFLAG_FORCENOFRACT flag is selected, the PLL hardware for the
1263  * automatic bandwidth selection, Spread Spectrum (SS) support, and fractional M-divider
1264  * are not used.<br>
1265  */
1266 #define PLL_CONFIGFLAG_USEINRATE (1U << 0U) /*!< Flag to use InputRate in PLL configuration structure for setup */
1267 #define PLL_CONFIGFLAG_FORCENOFRACT                                                                                   \
1268     (1U << 2U) /*!< Force non-fractional output mode, PLL output will not use the fractional, automatic bandwidth, or \
1269                   SS hardware */
1270 
1271 /*! @brief PLL configuration structure
1272  *
1273  * This structure can be used to configure the settings for a PLL
1274  * setup structure. Fill in the desired configuration for the PLL
1275  * and call the PLL setup function to fill in a PLL setup structure.
1276  */
1277 typedef struct _pll_config
1278 {
1279     uint32_t desiredRate; /*!< Desired PLL rate in Hz */
1280     uint32_t inputRate;   /*!< PLL input clock in Hz, only used if PLL_CONFIGFLAG_USEINRATE flag is set */
1281     uint32_t flags;       /*!< PLL configuration flags, Or'ed value of PLL_CONFIGFLAG_* definitions */
1282 } pll_config_t;
1283 
1284 /*! @brief PLL setup structure flags for 'flags' field
1285  * These flags control how the PLL setup function sets up the PLL
1286  */
1287 #define PLL_SETUPFLAG_POWERUP  (1U << 0U) /*!< Setup will power on the PLL after setup */
1288 #define PLL_SETUPFLAG_WAITLOCK (1U << 1U) /*!< Setup will wait for PLL lock, implies the PLL will be pwoered on */
1289 #define PLL_SETUPFLAG_ADGVOLT  (1U << 2U) /*!< Optimize system voltage for the new PLL rate */
1290 
1291 /*! @brief PLL setup structure
1292  * This structure can be used to pre-build a PLL setup configuration
1293  * at run-time and quickly set the PLL to the configuration. It can be
1294  * populated with the PLL setup function. If powering up or waiting
1295  * for PLL lock, the PLL input clock source should be configured prior
1296  * to PLL setup.
1297  */
1298 typedef struct _pll_setup
1299 {
1300     uint32_t pllctrl;    /*!< PLL control register SYSPLLCTRL */
1301     uint32_t pllndec;    /*!< PLL NDEC register SYSPLLNDEC */
1302     uint32_t pllpdec;    /*!< PLL PDEC register SYSPLLPDEC */
1303     uint32_t pllmdec;    /*!< PLL MDEC registers SYSPLLPDEC */
1304     uint32_t pllRate;    /*!< Acutal PLL rate */
1305     uint32_t audpllfrac; /*!< only aduio PLL has this function*/
1306     uint32_t flags;      /*!< PLL setup flags, Or'ed value of PLL_SETUPFLAG_* definitions */
1307 } pll_setup_t;
1308 
1309 /*! @brief PLL status definitions
1310  */
1311 typedef enum _pll_error
1312 {
1313     kStatus_PLL_Success         = MAKE_STATUS(kStatusGroup_Generic, 0), /*!< PLL operation was successful */
1314     kStatus_PLL_OutputTooLow    = MAKE_STATUS(kStatusGroup_Generic, 1), /*!< PLL output rate request was too low */
1315     kStatus_PLL_OutputTooHigh   = MAKE_STATUS(kStatusGroup_Generic, 2), /*!< PLL output rate request was too high */
1316     kStatus_PLL_InputTooLow     = MAKE_STATUS(kStatusGroup_Generic, 3), /*!< PLL input rate is too low */
1317     kStatus_PLL_InputTooHigh    = MAKE_STATUS(kStatusGroup_Generic, 4), /*!< PLL input rate is too high */
1318     kStatus_PLL_OutsideIntLimit = MAKE_STATUS(kStatusGroup_Generic, 5), /*!< Requested output rate isn't possible */
1319     kStatus_PLL_CCOTooLow       = MAKE_STATUS(kStatusGroup_Generic, 6), /*!< Requested CCO rate isn't possible */
1320     kStatus_PLL_CCOTooHigh      = MAKE_STATUS(kStatusGroup_Generic, 7)  /*!< Requested CCO rate isn't possible */
1321 } pll_error_t;
1322 
1323 /*! @brief USB clock source definition. */
1324 typedef enum _clock_usb_src
1325 {
1326     kCLOCK_UsbSrcFro       = (uint32_t)kCLOCK_FroHf,      /*!< Use FRO 96 or 48 MHz. */
1327     kCLOCK_UsbSrcSystemPll = (uint32_t)kCLOCK_PllOut,     /*!< Use System PLL output. */
1328     kCLOCK_UsbSrcMainClock = (uint32_t)kCLOCK_CoreSysClk, /*!< Use Main clock.    */
1329     kCLOCK_UsbSrcUsbPll    = (uint32_t)kCLOCK_UsbPll,     /*!< Use USB PLL clock.    */
1330 
1331     kCLOCK_UsbSrcNone = SYSCON_USB0CLKSEL_SEL(
1332         7U) /*!< Use None, this may be selected in order to reduce power when no output is needed. */
1333 } clock_usb_src_t;
1334 
1335 /*! @brief USB PDEL Divider. */
1336 typedef enum _usb_pll_psel
1337 {
1338     pSel_Divide_1 = 0U,
1339     pSel_Divide_2,
1340     pSel_Divide_4,
1341     pSel_Divide_8
1342 } usb_pll_psel;
1343 
1344 /*! @brief PLL setup structure
1345  * This structure can be used to pre-build a USB PLL setup configuration
1346  * at run-time and quickly set the usb PLL to the configuration. It can be
1347  * populated with the USB PLL setup function. If powering up or waiting
1348  * for USB PLL lock, the PLL input clock source should be configured prior
1349  * to USB PLL setup.
1350  */
1351 typedef struct _usb_pll_setup
1352 {
1353     uint8_t msel;       /*!< USB PLL control register msel:1U-256U */
1354     uint8_t psel;       /*!< USB PLL control register psel:only support inter 1U 2U 4U 8U */
1355     uint8_t nsel;       /*!< USB PLL control register nsel:only suppoet inter 1U 2U 3U 4U */
1356     bool direct;        /*!< USB PLL CCO output control */
1357     bool bypass;        /*!< USB PLL inout clock bypass control  */
1358     bool fbsel;         /*!< USB PLL ineter mode and non-integer mode control*/
1359     uint32_t inputRate; /*!< USB PLL input rate */
1360 } usb_pll_setup_t;
1361 
1362 /*! @brief	Return System PLL output clock rate from setup structure
1363  *  @param	pSetup	: Pointer to a PLL setup structure
1364  *  @return	System PLL output clock rate the setup structure will generate
1365  */
1366 uint32_t CLOCK_GetSystemPLLOutFromSetup(pll_setup_t *pSetup);
1367 
1368 /*! @brief	Return System AUDIO PLL output clock rate from setup structure
1369  *  @param	pSetup	: Pointer to a PLL setup structure
1370  *  @return	System PLL output clock rate the setup structure will generate
1371  */
1372 uint32_t CLOCK_GetAudioPLLOutFromSetup(pll_setup_t *pSetup);
1373 
1374 /*! @brief	Return System AUDIO PLL output clock rate from audio fractioanl setup structure
1375  *  @param	pSetup	: Pointer to a PLL setup structure
1376  *  @return	System PLL output clock rate the setup structure will generate
1377  */
1378 uint32_t CLOCK_GetAudioPLLOutFromFractSetup(pll_setup_t *pSetup);
1379 
1380 /*! @brief	Return System USB PLL output clock rate from setup structure
1381  *  @param	pSetup	: Pointer to a PLL setup structure
1382  *  @return	System PLL output clock rate the setup structure will generate
1383  */
1384 uint32_t CLOCK_GetUsbPLLOutFromSetup(const usb_pll_setup_t *pSetup);
1385 
1386 /*! @brief	Set PLL output based on the passed PLL setup data
1387  *  @param	pControl	: Pointer to populated PLL control structure to generate setup with
1388  *  @param	pSetup		: Pointer to PLL setup structure to be filled
1389  *  @return	PLL_ERROR_SUCCESS on success, or PLL setup error code
1390  *  @note	Actual frequency for setup may vary from the desired frequency based on the
1391  *  accuracy of input clocks, rounding, non-fractional PLL mode, etc.
1392  */
1393 pll_error_t CLOCK_SetupPLLData(pll_config_t *pControl, pll_setup_t *pSetup);
1394 
1395 /*! @brief	Set AUDIO PLL output based on the passed AUDIO PLL setup data
1396  *  @param	pControl	: Pointer to populated PLL control structure to generate setup with
1397  *  @param	pSetup		: Pointer to PLL setup structure to be filled
1398  *  @return	PLL_ERROR_SUCCESS on success, or PLL setup error code
1399  *  @note	Actual frequency for setup may vary from the desired frequency based on the
1400  *  accuracy of input clocks, rounding, non-fractional PLL mode, etc.
1401  */
1402 pll_error_t CLOCK_SetupAudioPLLData(pll_config_t *pControl, pll_setup_t *pSetup);
1403 
1404 /*! @brief	Set PLL output from PLL setup structure (precise frequency)
1405  * @param	pSetup	: Pointer to populated PLL setup structure
1406  * @param flagcfg : Flag configuration for PLL config structure
1407  * @return	PLL_ERROR_SUCCESS on success, or PLL setup error code
1408  * @note	This function will power off the PLL, setup the PLL with the
1409  * new setup data, and then optionally powerup the PLL, wait for PLL lock,
1410  * and adjust system voltages to the new PLL rate. The function will not
1411  * alter any source clocks (ie, main systen clock) that may use the PLL,
1412  * so these should be setup prior to and after exiting the function.
1413  */
1414 pll_error_t CLOCK_SetupSystemPLLPrec(pll_setup_t *pSetup, uint32_t flagcfg);
1415 
1416 /*! @brief	Set AUDIO PLL output from AUDIOPLL setup structure (precise frequency)
1417  * @param	pSetup	: Pointer to populated PLL setup structure
1418  * @param flagcfg : Flag configuration for PLL config structure
1419  * @return	PLL_ERROR_SUCCESS on success, or PLL setup error code
1420  * @note	This function will power off the PLL, setup the PLL with the
1421  * new setup data, and then optionally powerup the AUDIO PLL, wait for PLL lock,
1422  * and adjust system voltages to the new AUDIOPLL rate. The function will not
1423  * alter any source clocks (ie, main systen clock) that may use the AUDIO PLL,
1424  * so these should be setup prior to and after exiting the function.
1425  */
1426 pll_error_t CLOCK_SetupAudioPLLPrec(pll_setup_t *pSetup, uint32_t flagcfg);
1427 
1428 /*! @brief	Set AUDIO PLL output from AUDIOPLL setup structure using the Audio Fractional divider register(precise
1429  * frequency)
1430  * @param	pSetup	: Pointer to populated PLL setup structure
1431  * @param flagcfg : Flag configuration for PLL config structure
1432  * @return	PLL_ERROR_SUCCESS on success, or PLL setup error code
1433  * @note	This function will power off the PLL, setup the PLL with the
1434  * new setup data, and then optionally powerup the AUDIO PLL, wait for PLL lock,
1435  * and adjust system voltages to the new AUDIOPLL rate. The function will not
1436  * alter any source clocks (ie, main systen clock) that may use the AUDIO PLL,
1437  * so these should be setup prior to and after exiting the function.
1438  */
1439 pll_error_t CLOCK_SetupAudioPLLPrecFract(pll_setup_t *pSetup, uint32_t flagcfg);
1440 
1441 /**
1442  * @brief	Set PLL output from PLL setup structure (precise frequency)
1443  * @param	pSetup	: Pointer to populated PLL setup structure
1444  * @return	kStatus_PLL_Success on success, or PLL setup error code
1445  * @note	This function will power off the PLL, setup the PLL with the
1446  * new setup data, and then optionally powerup the PLL, wait for PLL lock,
1447  * and adjust system voltages to the new PLL rate. The function will not
1448  * alter any source clocks (ie, main systen clock) that may use the PLL,
1449  * so these should be setup prior to and after exiting the function.
1450  */
1451 pll_error_t CLOCK_SetPLLFreq(const pll_setup_t *pSetup);
1452 
1453 /**
1454  * @brief	Set Audio PLL output from Audio PLL setup structure (precise frequency)
1455  * @param	pSetup	: Pointer to populated PLL setup structure
1456  * @return	kStatus_PLL_Success on success, or Audio PLL setup error code
1457  * @note	This function will power off the PLL, setup the Audio PLL with the
1458  * new setup data, and then optionally powerup the PLL, wait for Audio PLL lock,
1459  * and adjust system voltages to the new PLL rate. The function will not
1460  * alter any source clocks (ie, main systen clock) that may use the Audio PLL,
1461  * so these should be setup prior to and after exiting the function.
1462  */
1463 pll_error_t CLOCK_SetAudioPLLFreq(const pll_setup_t *pSetup);
1464 
1465 /**
1466  * @brief	Set USB PLL output from USB PLL setup structure (precise frequency)
1467  * @param	pSetup	: Pointer to populated USB PLL setup structure
1468  * @return	kStatus_PLL_Success on success, or USB PLL setup error code
1469  * @note	This function will power off the USB PLL, setup the PLL with the
1470  * new setup data, and then optionally powerup the USB PLL, wait for USB PLL lock,
1471  * and adjust system voltages to the new USB PLL rate. The function will not
1472  * alter any source clocks (ie, usb pll clock) that may use the USB PLL,
1473  * so these should be setup prior to and after exiting the function.
1474  */
1475 pll_error_t CLOCK_SetUsbPLLFreq(const usb_pll_setup_t *pSetup);
1476 
1477 /*! @brief	Set PLL output based on the multiplier and input frequency
1478  * @param	multiply_by	: multiplier
1479  * @param	input_freq	: Clock input frequency of the PLL
1480  * @return	Nothing
1481  * @note	Unlike the Chip_Clock_SetupSystemPLLPrec() function, this
1482  * function does not disable or enable PLL power, wait for PLL lock,
1483  * or adjust system voltages. These must be done in the application.
1484  * The function will not alter any source clocks (ie, main systen clock)
1485  * that may use the PLL, so these should be setup prior to and after
1486  * exiting the function.
1487  */
1488 void CLOCK_SetupSystemPLLMult(uint32_t multiply_by, uint32_t input_freq);
1489 
1490 /*! @brief Disable USB clock.
1491  *
1492  * Disable USB clock.
1493  */
CLOCK_DisableUsbDevicefs0Clock(clock_ip_name_t clk)1494 static inline void CLOCK_DisableUsbDevicefs0Clock(clock_ip_name_t clk)
1495 {
1496     CLOCK_DisableClock(clk);
1497 }
1498 
1499 /*! @brief Enable USB Device FS clock.
1500  * @param	src	: clock source
1501  * @param	freq: clock frequency
1502  * Enable USB Device Full Speed clock.
1503  */
1504 bool CLOCK_EnableUsbfs0DeviceClock(clock_usb_src_t src, uint32_t freq);
1505 
1506 /*! @brief Enable USB HOST FS clock.
1507  * @param	src	: clock source
1508  * @param	freq: clock frequency
1509  * Enable USB HOST Full Speed clock.
1510  */
1511 bool CLOCK_EnableUsbfs0HostClock(clock_usb_src_t src, uint32_t freq);
1512 
1513 /*! @brief Set the current Usb PLL Rate
1514  */
1515 void CLOCK_SetStoredUsbPLLClockRate(uint32_t rate);
1516 
1517 /*! @brief Enable USB Device HS clock.
1518  * @param	src	: clock source
1519  * @param	freq: clock frequency
1520  * Enable USB Device High Speed clock.
1521  */
1522 bool CLOCK_EnableUsbhs0DeviceClock(clock_usb_src_t src, uint32_t freq);
1523 
1524 /*! @brief Enable USB HOST HS clock.
1525  * @param	src	: clock source
1526  * @param	freq: clock frequency
1527  * Enable USB HOST High Speed clock.
1528  */
1529 bool CLOCK_EnableUsbhs0HostClock(clock_usb_src_t src, uint32_t freq);
1530 
1531 #if defined(__cplusplus)
1532 }
1533 #endif /* __cplusplus */
1534 
1535 /*! @} */
1536 
1537 #endif /* _FSL_CLOCK_H_ */
1538