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