diff options
Diffstat (limited to 'lib/chibios-contrib/ext/mcux-sdk/devices/LPC54618/drivers/fsl_clock.h')
-rw-r--r-- | lib/chibios-contrib/ext/mcux-sdk/devices/LPC54618/drivers/fsl_clock.h | 1323 |
1 files changed, 1323 insertions, 0 deletions
diff --git a/lib/chibios-contrib/ext/mcux-sdk/devices/LPC54618/drivers/fsl_clock.h b/lib/chibios-contrib/ext/mcux-sdk/devices/LPC54618/drivers/fsl_clock.h new file mode 100644 index 000000000..65f53d030 --- /dev/null +++ b/lib/chibios-contrib/ext/mcux-sdk/devices/LPC54618/drivers/fsl_clock.h | |||
@@ -0,0 +1,1323 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2016, Freescale Semiconductor, Inc. | ||
3 | * Copyright 2016 - 2020, 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.1. */ | ||
27 | #define FSL_CLOCK_DRIVER_VERSION (MAKE_VERSION(2, 5, 1)) | ||
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 (180000000UL) | ||
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 | ((((uint32_t)(reg_offset) << CLK_GATE_REG_OFFSET_SHIFT) & CLK_GATE_REG_OFFSET_MASK) | \ | ||
305 | (((uint32_t)(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 0U | ||
311 | #define AHB_CLK_CTRL1 1U | ||
312 | #define AHB_CLK_CTRL2 2U | ||
313 | #define ASYNC_CLK_CTRL0 3U | ||
314 | |||
315 | /*! @brief Clock gate name used for CLOCK_EnableClock/CLOCK_DisableClock. */ | ||
316 | typedef enum _clock_ip_name | ||
317 | { | ||
318 | kCLOCK_IpInvalid = 0U, | ||
319 | kCLOCK_Rom = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 1), | ||
320 | kCLOCK_Sram1 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 3), | ||
321 | kCLOCK_Sram2 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 4), | ||
322 | kCLOCK_Sram3 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 5), | ||
323 | kCLOCK_Flash = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 7), | ||
324 | kCLOCK_Fmc = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 8), | ||
325 | kCLOCK_Eeprom = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 9), | ||
326 | kCLOCK_Spifi = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 10), | ||
327 | kCLOCK_InputMux = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 11), | ||
328 | kCLOCK_Iocon = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 13), | ||
329 | kCLOCK_Gpio0 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 14), | ||
330 | kCLOCK_Gpio1 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 15), | ||
331 | kCLOCK_Gpio2 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 16), | ||
332 | kCLOCK_Gpio3 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 17), | ||
333 | kCLOCK_Pint = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 18), | ||
334 | kCLOCK_Gint = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 19), | ||
335 | kCLOCK_Dma = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 20), | ||
336 | kCLOCK_Crc = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 21), | ||
337 | kCLOCK_Wwdt = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 22), | ||
338 | kCLOCK_Rtc = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 23), | ||
339 | kCLOCK_Adc0 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 27), | ||
340 | kCLOCK_Mrt = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 0), | ||
341 | kCLOCK_Rit = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 1), | ||
342 | kCLOCK_Sct0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 2), | ||
343 | kCLOCK_Mcan0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 7), | ||
344 | kCLOCK_Mcan1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 8), | ||
345 | kCLOCK_Utick = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 10), | ||
346 | kCLOCK_FlexComm0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 11), | ||
347 | kCLOCK_FlexComm1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 12), | ||
348 | kCLOCK_FlexComm2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 13), | ||
349 | kCLOCK_FlexComm3 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 14), | ||
350 | kCLOCK_FlexComm4 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 15), | ||
351 | kCLOCK_FlexComm5 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 16), | ||
352 | kCLOCK_FlexComm6 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 17), | ||
353 | kCLOCK_FlexComm7 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 18), | ||
354 | kCLOCK_MinUart0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 11), | ||
355 | kCLOCK_MinUart1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 12), | ||
356 | kCLOCK_MinUart2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 13), | ||
357 | kCLOCK_MinUart3 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 14), | ||
358 | kCLOCK_MinUart4 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 15), | ||
359 | kCLOCK_MinUart5 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 16), | ||
360 | kCLOCK_MinUart6 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 17), | ||
361 | kCLOCK_MinUart7 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 18), | ||
362 | kCLOCK_LSpi0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 11), | ||
363 | kCLOCK_LSpi1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 12), | ||
364 | kCLOCK_LSpi2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 13), | ||
365 | kCLOCK_LSpi3 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 14), | ||
366 | kCLOCK_LSpi4 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 15), | ||
367 | kCLOCK_LSpi5 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 16), | ||
368 | kCLOCK_LSpi6 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 17), | ||
369 | kCLOCK_LSpi7 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 18), | ||
370 | kCLOCK_BI2c0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 11), | ||
371 | kCLOCK_BI2c1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 12), | ||
372 | kCLOCK_BI2c2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 13), | ||
373 | kCLOCK_BI2c3 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 14), | ||
374 | kCLOCK_BI2c4 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 15), | ||
375 | kCLOCK_BI2c5 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 16), | ||
376 | kCLOCK_BI2c6 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 17), | ||
377 | kCLOCK_BI2c7 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 18), | ||
378 | kCLOCK_FlexI2s0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 11), | ||
379 | kCLOCK_FlexI2s1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 12), | ||
380 | kCLOCK_FlexI2s2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 13), | ||
381 | kCLOCK_FlexI2s3 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 14), | ||
382 | kCLOCK_FlexI2s4 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 15), | ||
383 | kCLOCK_FlexI2s5 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 16), | ||
384 | kCLOCK_FlexI2s6 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 17), | ||
385 | kCLOCK_FlexI2s7 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 18), | ||
386 | kCLOCK_DMic = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 19), | ||
387 | kCLOCK_Ct32b2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 22), | ||
388 | kCLOCK_Usbd0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 25), | ||
389 | kCLOCK_Ct32b0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 26), | ||
390 | kCLOCK_Ct32b1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 27), | ||
391 | kCLOCK_BodyBias0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 29), | ||
392 | kCLOCK_EzhArchB0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 31), | ||
393 | kCLOCK_Lcd = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 2), | ||
394 | kCLOCK_Sdio = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 3), | ||
395 | kCLOCK_Usbh1 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 4), | ||
396 | kCLOCK_Usbd1 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 5), | ||
397 | kCLOCK_UsbRam1 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 6), | ||
398 | kCLOCK_Emc = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 7), | ||
399 | kCLOCK_Eth = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 8), | ||
400 | kCLOCK_Gpio4 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 9), | ||
401 | kCLOCK_Gpio5 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 10), | ||
402 | kCLOCK_Aes = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 11), | ||
403 | kCLOCK_Otp = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 12), | ||
404 | kCLOCK_Rng = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 13), | ||
405 | kCLOCK_FlexComm8 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 14), | ||
406 | kCLOCK_FlexComm9 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 15), | ||
407 | kCLOCK_MinUart8 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 14), | ||
408 | kCLOCK_MinUart9 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 15), | ||
409 | kCLOCK_LSpi8 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 14), | ||
410 | kCLOCK_LSpi9 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 15), | ||
411 | kCLOCK_BI2c8 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 14), | ||
412 | kCLOCK_BI2c9 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 15), | ||
413 | kCLOCK_FlexI2s8 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 14), | ||
414 | kCLOCK_FlexI2s9 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 15), | ||
415 | kCLOCK_Usbhmr0 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 16), | ||
416 | kCLOCK_Usbhsl0 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 17), | ||
417 | kCLOCK_Sha0 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 18), | ||
418 | kCLOCK_SmartCard0 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 19), | ||
419 | kCLOCK_SmartCard1 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 20), | ||
420 | |||
421 | kCLOCK_Ct32b3 = CLK_GATE_DEFINE(ASYNC_CLK_CTRL0, 13), | ||
422 | kCLOCK_Ct32b4 = CLK_GATE_DEFINE(ASYNC_CLK_CTRL0, 14) | ||
423 | } clock_ip_name_t; | ||
424 | |||
425 | /*! @brief Clock name used to get clock frequency. */ | ||
426 | typedef enum _clock_name | ||
427 | { | ||
428 | kCLOCK_CoreSysClk, /*!< Core/system clock (aka MAIN_CLK) */ | ||
429 | kCLOCK_BusClk, /*!< Bus clock (AHB clock) */ | ||
430 | kCLOCK_ClockOut, /*!< CLOCKOUT */ | ||
431 | kCLOCK_FroHf, /*!< FRO48/96 */ | ||
432 | kCLOCK_UsbPll, /*!< USB1 PLL */ | ||
433 | kCLOCK_Mclk, /*!< MCLK */ | ||
434 | kCLOCK_Fro12M, /*!< FRO12M */ | ||
435 | kCLOCK_ExtClk, /*!< External Clock */ | ||
436 | kCLOCK_PllOut, /*!< PLL Output */ | ||
437 | kCLOCK_UsbClk, /*!< USB input */ | ||
438 | kCLOCK_WdtOsc, /*!< Watchdog Oscillator */ | ||
439 | kCLOCK_Frg, /*!< Frg Clock */ | ||
440 | kCLOCK_AsyncApbClk, /*!< Async APB clock */ | ||
441 | kCLOCK_FlexI2S, /*!< FlexI2S clock */ | ||
442 | |||
443 | } clock_name_t; | ||
444 | |||
445 | /** | ||
446 | * Clock source selections for the asynchronous APB clock | ||
447 | */ | ||
448 | typedef enum _async_clock_src | ||
449 | { | ||
450 | kCLOCK_AsyncMainClk = 0, /*!< Main System clock */ | ||
451 | kCLOCK_AsyncFro12Mhz, /*!< 12MHz FRO */ | ||
452 | kCLOCK_AsyncAudioPllClk, | ||
453 | kCLOCK_AsyncI2cClkFc6, | ||
454 | |||
455 | } async_clock_src_t; | ||
456 | |||
457 | /*! @brief Clock Mux Switches | ||
458 | * The encoding is as follows each connection identified is 32bits wide while 24bits are valuable | ||
459 | * starting from LSB upwards | ||
460 | * | ||
461 | * [4 bits for choice, 0 means invalid choice] [8 bits mux ID]* | ||
462 | * | ||
463 | */ | ||
464 | |||
465 | #define CLK_ATTACH_ID(mux, sel, pos) \ | ||
466 | ((((uint32_t)(mux) << 0U) | (((uint32_t)(sel) + 1U) & 0xFU) << 8U) << ((uint32_t)(pos)*12U)) | ||
467 | #define MUX_A(mux, sel) CLK_ATTACH_ID((mux), (sel), 0U) | ||
468 | #define MUX_B(mux, sel, selector) (CLK_ATTACH_ID((mux), (sel), 1U) | ((selector) << 24U)) | ||
469 | |||
470 | #define GET_ID_ITEM(connection) ((connection)&0xFFFU) | ||
471 | #define GET_ID_NEXT_ITEM(connection) ((connection) >> 12U) | ||
472 | #define GET_ID_ITEM_MUX(connection) ((uint8_t)((connection)&0xFFU)) | ||
473 | #define GET_ID_ITEM_SEL(connection) (uint8_t)(((((connection)&0xF00U) >> 8U) - 1U)) | ||
474 | #define GET_ID_SELECTOR(connection) ((connection)&0xF000000U) | ||
475 | |||
476 | #define CM_MAINCLKSELA 0 | ||
477 | #define CM_MAINCLKSELB 1 | ||
478 | #define CM_CLKOUTCLKSELA 2 | ||
479 | #define CM_SYSPLLCLKSEL 4 | ||
480 | #define CM_AUDPLLCLKSEL 6 | ||
481 | #define CM_SPIFICLKSEL 8 | ||
482 | #define CM_ADCASYNCCLKSEL 9 | ||
483 | #define CM_USB0CLKSEL 10 | ||
484 | #define CM_USB1CLKSEL 11 | ||
485 | #define CM_FXCOMCLKSEL0 12 | ||
486 | #define CM_FXCOMCLKSEL1 13 | ||
487 | #define CM_FXCOMCLKSEL2 14 | ||
488 | #define CM_FXCOMCLKSEL3 15 | ||
489 | #define CM_FXCOMCLKSEL4 16 | ||
490 | #define CM_FXCOMCLKSEL5 17 | ||
491 | #define CM_FXCOMCLKSEL6 18 | ||
492 | #define CM_FXCOMCLKSEL7 19 | ||
493 | #define CM_FXCOMCLKSEL8 20 | ||
494 | #define CM_FXCOMCLKSEL9 21 | ||
495 | #define CM_MCLKCLKSEL 24 | ||
496 | #define CM_FRGCLKSEL 26 | ||
497 | #define CM_DMICCLKSEL 27 | ||
498 | #define CM_SCTCLKSEL 28 | ||
499 | #define CM_LCDCLKSEL 29 | ||
500 | #define CM_SDIOCLKSEL 30 | ||
501 | |||
502 | #define CM_ASYNCAPB 31U | ||
503 | |||
504 | typedef enum _clock_attach_id | ||
505 | { | ||
506 | |||
507 | kFRO12M_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 0) | MUX_B(CM_MAINCLKSELB, 0, 0), | ||
508 | kEXT_CLK_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 1) | MUX_B(CM_MAINCLKSELB, 0, 0), | ||
509 | kWDT_OSC_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 2) | MUX_B(CM_MAINCLKSELB, 0, 0), | ||
510 | kFRO_HF_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 3) | MUX_B(CM_MAINCLKSELB, 0, 0), | ||
511 | kSYS_PLL_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 0) | MUX_B(CM_MAINCLKSELB, 2, 0), | ||
512 | kOSC32K_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 0) | MUX_B(CM_MAINCLKSELB, 3, 0), | ||
513 | |||
514 | kMAIN_CLK_to_CLKOUT = MUX_A(CM_CLKOUTCLKSELA, 0), | ||
515 | kEXT_CLK_to_CLKOUT = MUX_A(CM_CLKOUTCLKSELA, 1), | ||
516 | kWDT_OSC_to_CLKOUT = MUX_A(CM_CLKOUTCLKSELA, 2), | ||
517 | kFRO_HF_to_CLKOUT = MUX_A(CM_CLKOUTCLKSELA, 3), | ||
518 | kSYS_PLL_to_CLKOUT = MUX_A(CM_CLKOUTCLKSELA, 4), | ||
519 | kUSB_PLL_to_CLKOUT = MUX_A(CM_CLKOUTCLKSELA, 5), | ||
520 | kAUDIO_PLL_to_CLKOUT = MUX_A(CM_CLKOUTCLKSELA, 6), | ||
521 | kOSC32K_OSC_to_CLKOUT = MUX_A(CM_CLKOUTCLKSELA, 7), | ||
522 | |||
523 | kFRO12M_to_SYS_PLL = MUX_A(CM_SYSPLLCLKSEL, 0), | ||
524 | kEXT_CLK_to_SYS_PLL = MUX_A(CM_SYSPLLCLKSEL, 1), | ||
525 | kWDT_OSC_to_SYS_PLL = MUX_A(CM_SYSPLLCLKSEL, 2), | ||
526 | kOSC32K_to_SYS_PLL = MUX_A(CM_SYSPLLCLKSEL, 3), | ||
527 | kNONE_to_SYS_PLL = MUX_A(CM_SYSPLLCLKSEL, 7), | ||
528 | |||
529 | kFRO12M_to_AUDIO_PLL = MUX_A(CM_AUDPLLCLKSEL, 0), | ||
530 | kEXT_CLK_to_AUDIO_PLL = MUX_A(CM_AUDPLLCLKSEL, 1), | ||
531 | kNONE_to_AUDIO_PLL = MUX_A(CM_AUDPLLCLKSEL, 7), | ||
532 | |||
533 | kMAIN_CLK_to_SPIFI_CLK = MUX_A(CM_SPIFICLKSEL, 0), | ||
534 | kSYS_PLL_to_SPIFI_CLK = MUX_A(CM_SPIFICLKSEL, 1), | ||
535 | kUSB_PLL_to_SPIFI_CLK = MUX_A(CM_SPIFICLKSEL, 2), | ||
536 | kFRO_HF_to_SPIFI_CLK = MUX_A(CM_SPIFICLKSEL, 3), | ||
537 | kAUDIO_PLL_to_SPIFI_CLK = MUX_A(CM_SPIFICLKSEL, 4), | ||
538 | kNONE_to_SPIFI_CLK = MUX_A(CM_SPIFICLKSEL, 7), | ||
539 | |||
540 | kFRO_HF_to_ADC_CLK = MUX_A(CM_ADCASYNCCLKSEL, 0), | ||
541 | kSYS_PLL_to_ADC_CLK = MUX_A(CM_ADCASYNCCLKSEL, 1), | ||
542 | kUSB_PLL_to_ADC_CLK = MUX_A(CM_ADCASYNCCLKSEL, 2), | ||
543 | kAUDIO_PLL_to_ADC_CLK = MUX_A(CM_ADCASYNCCLKSEL, 3), | ||
544 | kNONE_to_ADC_CLK = MUX_A(CM_ADCASYNCCLKSEL, 7), | ||
545 | |||
546 | kFRO_HF_to_USB0_CLK = MUX_A(CM_USB0CLKSEL, 0), | ||
547 | kSYS_PLL_to_USB0_CLK = MUX_A(CM_USB0CLKSEL, 1), | ||
548 | kUSB_PLL_to_USB0_CLK = MUX_A(CM_USB0CLKSEL, 2), | ||
549 | kNONE_to_USB0_CLK = MUX_A(CM_USB0CLKSEL, 7), | ||
550 | |||
551 | kFRO_HF_to_USB1_CLK = MUX_A(CM_USB1CLKSEL, 0), | ||
552 | kSYS_PLL_to_USB1_CLK = MUX_A(CM_USB1CLKSEL, 1), | ||
553 | kUSB_PLL_to_USB1_CLK = MUX_A(CM_USB1CLKSEL, 2), | ||
554 | kNONE_to_USB1_CLK = MUX_A(CM_USB1CLKSEL, 7), | ||
555 | |||
556 | kFRO12M_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 0), | ||
557 | kFRO_HF_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 1), | ||
558 | kAUDIO_PLL_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 2), | ||
559 | kMCLK_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 3), | ||
560 | kFRG_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 4), | ||
561 | kNONE_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 7), | ||
562 | |||
563 | kFRO12M_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 0), | ||
564 | kFRO_HF_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 1), | ||
565 | kAUDIO_PLL_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 2), | ||
566 | kMCLK_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 3), | ||
567 | kFRG_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 4), | ||
568 | kNONE_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 7), | ||
569 | |||
570 | kFRO12M_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 0), | ||
571 | kFRO_HF_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 1), | ||
572 | kAUDIO_PLL_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 2), | ||
573 | kMCLK_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 3), | ||
574 | kFRG_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 4), | ||
575 | kNONE_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 7), | ||
576 | |||
577 | kFRO12M_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 0), | ||
578 | kFRO_HF_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 1), | ||
579 | kAUDIO_PLL_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 2), | ||
580 | kMCLK_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 3), | ||
581 | kFRG_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 4), | ||
582 | kNONE_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 7), | ||
583 | |||
584 | kFRO12M_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 0), | ||
585 | kFRO_HF_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 1), | ||
586 | kAUDIO_PLL_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 2), | ||
587 | kMCLK_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 3), | ||
588 | kFRG_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 4), | ||
589 | kNONE_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 7), | ||
590 | |||
591 | kFRO12M_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 0), | ||
592 | kFRO_HF_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 1), | ||
593 | kAUDIO_PLL_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 2), | ||
594 | kMCLK_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 3), | ||
595 | kFRG_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 4), | ||
596 | kNONE_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 7), | ||
597 | |||
598 | kFRO12M_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 0), | ||
599 | kFRO_HF_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 1), | ||
600 | kAUDIO_PLL_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 2), | ||
601 | kMCLK_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 3), | ||
602 | kFRG_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 4), | ||
603 | kNONE_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 7), | ||
604 | |||
605 | kFRO12M_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 0), | ||
606 | kFRO_HF_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 1), | ||
607 | kAUDIO_PLL_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 2), | ||
608 | kMCLK_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 3), | ||
609 | kFRG_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 4), | ||
610 | kNONE_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 7), | ||
611 | |||
612 | kFRO12M_to_FLEXCOMM8 = MUX_A(CM_FXCOMCLKSEL8, 0), | ||
613 | kFRO_HF_to_FLEXCOMM8 = MUX_A(CM_FXCOMCLKSEL8, 1), | ||
614 | kAUDIO_PLL_to_FLEXCOMM8 = MUX_A(CM_FXCOMCLKSEL8, 2), | ||
615 | kMCLK_to_FLEXCOMM8 = MUX_A(CM_FXCOMCLKSEL8, 3), | ||
616 | kFRG_to_FLEXCOMM8 = MUX_A(CM_FXCOMCLKSEL8, 4), | ||
617 | kNONE_to_FLEXCOMM8 = MUX_A(CM_FXCOMCLKSEL8, 7), | ||
618 | |||
619 | kFRO12M_to_FLEXCOMM9 = MUX_A(CM_FXCOMCLKSEL9, 0), | ||
620 | kFRO_HF_to_FLEXCOMM9 = MUX_A(CM_FXCOMCLKSEL9, 1), | ||
621 | kAUDIO_PLL_to_FLEXCOMM9 = MUX_A(CM_FXCOMCLKSEL9, 2), | ||
622 | kMCLK_to_FLEXCOMM9 = MUX_A(CM_FXCOMCLKSEL9, 3), | ||
623 | kFRG_to_FLEXCOMM9 = MUX_A(CM_FXCOMCLKSEL9, 4), | ||
624 | kNONE_to_FLEXCOMM9 = MUX_A(CM_FXCOMCLKSEL9, 7), | ||
625 | |||
626 | kFRO_HF_to_MCLK = MUX_A(CM_MCLKCLKSEL, 0), | ||
627 | kAUDIO_PLL_to_MCLK = MUX_A(CM_MCLKCLKSEL, 1), | ||
628 | kNONE_to_MCLK = MUX_A(CM_MCLKCLKSEL, 7), | ||
629 | |||
630 | kMAIN_CLK_to_FRG = MUX_A(CM_FRGCLKSEL, 0), | ||
631 | kSYS_PLL_to_FRG = MUX_A(CM_FRGCLKSEL, 1), | ||
632 | kFRO12M_to_FRG = MUX_A(CM_FRGCLKSEL, 2), | ||
633 | kFRO_HF_to_FRG = MUX_A(CM_FRGCLKSEL, 3), | ||
634 | kNONE_to_FRG = MUX_A(CM_FRGCLKSEL, 7), | ||
635 | |||
636 | kFRO12M_to_DMIC = MUX_A(CM_DMICCLKSEL, 0), | ||
637 | kFRO_HF_DIV_to_DMIC = MUX_A(CM_DMICCLKSEL, 1), | ||
638 | kAUDIO_PLL_to_DMIC = MUX_A(CM_DMICCLKSEL, 2), | ||
639 | kMCLK_to_DMIC = MUX_A(CM_DMICCLKSEL, 3), | ||
640 | kNONE_to_DMIC = MUX_A(CM_DMICCLKSEL, 7), | ||
641 | |||
642 | kMAIN_CLK_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 0), | ||
643 | kSYS_PLL_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 1), | ||
644 | kFRO_HF_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 2), | ||
645 | kAUDIO_PLL_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 3), | ||
646 | kNONE_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 7), | ||
647 | |||
648 | kMAIN_CLK_to_SDIO_CLK = MUX_A(CM_SDIOCLKSEL, 0), | ||
649 | kSYS_PLL_to_SDIO_CLK = MUX_A(CM_SDIOCLKSEL, 1), | ||
650 | kUSB_PLL_to_SDIO_CLK = MUX_A(CM_SDIOCLKSEL, 2), | ||
651 | kFRO_HF_to_SDIO_CLK = MUX_A(CM_SDIOCLKSEL, 3), | ||
652 | kAUDIO_PLL_to_SDIO_CLK = MUX_A(CM_SDIOCLKSEL, 4), | ||
653 | kNONE_to_SDIO_CLK = MUX_A(CM_SDIOCLKSEL, 7), | ||
654 | |||
655 | kMAIN_CLK_to_LCD_CLK = MUX_A(CM_LCDCLKSEL, 0), | ||
656 | kLCDCLKIN_to_LCD_CLK = MUX_A(CM_LCDCLKSEL, 1), | ||
657 | kFRO_HF_to_LCD_CLK = MUX_A(CM_LCDCLKSEL, 2), | ||
658 | kNONE_to_LCD_CLK = MUX_A(CM_LCDCLKSEL, 3), | ||
659 | |||
660 | kMAIN_CLK_to_ASYNC_APB = MUX_A(CM_ASYNCAPB, 0), | ||
661 | kFRO12M_to_ASYNC_APB = MUX_A(CM_ASYNCAPB, 1), | ||
662 | kAUDIO_PLL_to_ASYNC_APB = MUX_A(CM_ASYNCAPB, 2), | ||
663 | kI2C_CLK_FC6_to_ASYNC_APB = MUX_A(CM_ASYNCAPB, 3), | ||
664 | kNONE_to_NONE = (int)0x80000000U, | ||
665 | } clock_attach_id_t; | ||
666 | |||
667 | /* Clock dividers */ | ||
668 | typedef enum _clock_div_name | ||
669 | { | ||
670 | kCLOCK_DivSystickClk = 0, | ||
671 | kCLOCK_DivArmTrClkDiv = 1, | ||
672 | kCLOCK_DivCan0Clk = 2, | ||
673 | kCLOCK_DivCan1Clk = 3, | ||
674 | kCLOCK_DivSmartCard0Clk = 4, | ||
675 | kCLOCK_DivSmartCard1Clk = 5, | ||
676 | kCLOCK_DivAhbClk = 32, | ||
677 | kCLOCK_DivClkOut = 33, | ||
678 | kCLOCK_DivFrohfClk = 34, | ||
679 | kCLOCK_DivSpifiClk = 36, | ||
680 | kCLOCK_DivAdcAsyncClk = 37, | ||
681 | kCLOCK_DivUsb0Clk = 38, | ||
682 | kCLOCK_DivUsb1Clk = 39, | ||
683 | kCLOCK_DivFrg = 40, | ||
684 | kCLOCK_DivDmicClk = 42, | ||
685 | kCLOCK_DivMClk = 43, | ||
686 | kCLOCK_DivLcdClk = 44, | ||
687 | kCLOCK_DivSctClk = 45, | ||
688 | kCLOCK_DivEmcClk = 46, | ||
689 | kCLOCK_DivSdioClk = 47 | ||
690 | } clock_div_name_t; | ||
691 | |||
692 | /******************************************************************************* | ||
693 | * API | ||
694 | ******************************************************************************/ | ||
695 | |||
696 | #if defined(__cplusplus) | ||
697 | extern "C" { | ||
698 | #endif /* __cplusplus */ | ||
699 | |||
700 | static inline void CLOCK_EnableClock(clock_ip_name_t clk) | ||
701 | { | ||
702 | uint32_t index = CLK_GATE_ABSTRACT_REG_OFFSET(clk); | ||
703 | if (index < 3U) | ||
704 | { | ||
705 | SYSCON->AHBCLKCTRLSET[index] = (1UL << CLK_GATE_ABSTRACT_BITS_SHIFT(clk)); | ||
706 | } | ||
707 | else | ||
708 | { | ||
709 | SYSCON->ASYNCAPBCTRL = SYSCON_ASYNCAPBCTRL_ENABLE(1); | ||
710 | ASYNC_SYSCON->ASYNCAPBCLKCTRLSET = (1UL << CLK_GATE_ABSTRACT_BITS_SHIFT(clk)); | ||
711 | } | ||
712 | } | ||
713 | |||
714 | static inline void CLOCK_DisableClock(clock_ip_name_t clk) | ||
715 | { | ||
716 | uint32_t index = CLK_GATE_ABSTRACT_REG_OFFSET(clk); | ||
717 | if (index < 3U) | ||
718 | { | ||
719 | SYSCON->AHBCLKCTRLCLR[index] = (1UL << CLK_GATE_ABSTRACT_BITS_SHIFT(clk)); | ||
720 | } | ||
721 | else | ||
722 | { | ||
723 | ASYNC_SYSCON->ASYNCAPBCLKCTRLCLR = (1UL << CLK_GATE_ABSTRACT_BITS_SHIFT(clk)); | ||
724 | SYSCON->ASYNCAPBCTRL = SYSCON_ASYNCAPBCTRL_ENABLE(0); | ||
725 | } | ||
726 | } | ||
727 | /** | ||
728 | * @brief FLASH Access time definitions | ||
729 | */ | ||
730 | typedef enum _clock_flashtim | ||
731 | { | ||
732 | kCLOCK_Flash1Cycle = 0, /*!< Flash accesses use 1 CPU clocks */ | ||
733 | kCLOCK_Flash2Cycle, /*!< Flash accesses use 2 CPU clocks */ | ||
734 | kCLOCK_Flash3Cycle, /*!< Flash accesses use 3 CPU clocks */ | ||
735 | kCLOCK_Flash4Cycle, /*!< Flash accesses use 4 CPU clocks */ | ||
736 | kCLOCK_Flash5Cycle, /*!< Flash accesses use 5 CPU clocks */ | ||
737 | kCLOCK_Flash6Cycle, /*!< Flash accesses use 6 CPU clocks */ | ||
738 | kCLOCK_Flash7Cycle, /*!< Flash accesses use 7 CPU clocks */ | ||
739 | kCLOCK_Flash8Cycle, /*!< Flash accesses use 8 CPU clocks */ | ||
740 | kCLOCK_Flash9Cycle /*!< Flash accesses use 9 CPU clocks */ | ||
741 | } clock_flashtim_t; | ||
742 | |||
743 | /** | ||
744 | * @brief Set FLASH memory access time in clocks | ||
745 | * @param clks : Clock cycles for FLASH access | ||
746 | * @return Nothing | ||
747 | */ | ||
748 | static inline void CLOCK_SetFLASHAccessCycles(clock_flashtim_t clks) | ||
749 | { | ||
750 | uint32_t tmp; | ||
751 | |||
752 | tmp = SYSCON->FLASHCFG & ~(SYSCON_FLASHCFG_FLASHTIM_MASK); | ||
753 | |||
754 | /* Don't alter lower bits */ | ||
755 | SYSCON->FLASHCFG = tmp | ((uint32_t)clks << SYSCON_FLASHCFG_FLASHTIM_SHIFT); | ||
756 | } | ||
757 | |||
758 | /** | ||
759 | * @brief Initialize the Core clock to given frequency (12, 48 or 96 MHz). | ||
760 | * Turns on FRO and uses default CCO, if freq is 12000000, then high speed output is off, else high speed output is | ||
761 | * enabled. | ||
762 | * @param iFreq : Desired frequency (must be one of CLK_FRO_12MHZ or CLK_FRO_48MHZ or CLK_FRO_96MHZ) | ||
763 | * @return returns success or fail status. | ||
764 | */ | ||
765 | status_t CLOCK_SetupFROClocking(uint32_t iFreq); | ||
766 | /** | ||
767 | * @brief Configure the clock selection muxes. | ||
768 | * @param connection : Clock to be configured. | ||
769 | * @return Nothing | ||
770 | */ | ||
771 | void CLOCK_AttachClk(clock_attach_id_t connection); | ||
772 | /** | ||
773 | * @brief Get the actual clock attach id. | ||
774 | * This fuction uses the offset in input attach id, then it reads the actual source value in | ||
775 | * the register and combine the offset to obtain an actual attach id. | ||
776 | * @param attachId : Clock attach id to get. | ||
777 | * @return Clock source value. | ||
778 | */ | ||
779 | clock_attach_id_t CLOCK_GetClockAttachId(clock_attach_id_t attachId); | ||
780 | /** | ||
781 | * @brief Setup peripheral clock dividers. | ||
782 | * @param div_name : Clock divider name | ||
783 | * @param divided_by_value: Value to be divided | ||
784 | * @param reset : Whether to reset the divider counter. | ||
785 | * @return Nothing | ||
786 | */ | ||
787 | void CLOCK_SetClkDiv(clock_div_name_t div_name, uint32_t divided_by_value, bool reset); | ||
788 | /** | ||
789 | * @brief Set the flash wait states for the input freuqency. | ||
790 | * @param iFreq : Input frequency | ||
791 | * @return Nothing | ||
792 | */ | ||
793 | void CLOCK_SetFLASHAccessCyclesForFreq(uint32_t iFreq); | ||
794 | |||
795 | /** | ||
796 | * @brief Set the frg output frequency. | ||
797 | * @param freq : output frequency | ||
798 | * @return 0 : the frequency range is out of range. | ||
799 | * 1 : switch successfully. | ||
800 | */ | ||
801 | uint32_t CLOCK_SetFRGClock(uint32_t freq); | ||
802 | |||
803 | /*! @brief Return Frequency of FRG input clock | ||
804 | * @return Frequency value | ||
805 | */ | ||
806 | uint32_t CLOCK_GetFRGInputClock(void); | ||
807 | |||
808 | /*! @brief Return Frequency of selected clock | ||
809 | * @return Frequency of selected clock | ||
810 | */ | ||
811 | uint32_t CLOCK_GetFreq(clock_name_t clockName); | ||
812 | /*! @brief Return Frequency of FRO 12MHz | ||
813 | * @return Frequency of FRO 12MHz | ||
814 | */ | ||
815 | uint32_t CLOCK_GetFro12MFreq(void); | ||
816 | /*! @brief Return Frequency of ClockOut | ||
817 | * @return Frequency of ClockOut | ||
818 | */ | ||
819 | uint32_t CLOCK_GetClockOutClkFreq(void); | ||
820 | /*! @brief Return Frequency of Spifi Clock | ||
821 | * @return Frequency of Spifi. | ||
822 | */ | ||
823 | uint32_t CLOCK_GetSpifiClkFreq(void); | ||
824 | /*! @brief Return Frequency of Adc Clock | ||
825 | * @return Frequency of Adc Clock. | ||
826 | */ | ||
827 | uint32_t CLOCK_GetAdcClkFreq(void); | ||
828 | /*! brief Return Frequency of MCAN Clock | ||
829 | * param MCanSel : 0U: MCAN0; 1U: MCAN1 | ||
830 | * return Frequency of MCAN Clock | ||
831 | */ | ||
832 | uint32_t CLOCK_GetMCanClkFreq(uint32_t MCanSel); | ||
833 | /*! @brief Return Frequency of Usb0 Clock | ||
834 | * @return Frequency of Usb0 Clock. | ||
835 | */ | ||
836 | uint32_t CLOCK_GetUsb0ClkFreq(void); | ||
837 | /*! @brief Return Frequency of Usb1 Clock | ||
838 | * @return Frequency of Usb1 Clock. | ||
839 | */ | ||
840 | uint32_t CLOCK_GetUsb1ClkFreq(void); | ||
841 | /*! @brief Return Frequency of MClk Clock | ||
842 | * @return Frequency of MClk Clock. | ||
843 | */ | ||
844 | uint32_t CLOCK_GetMclkClkFreq(void); | ||
845 | /*! @brief Return Frequency of SCTimer Clock | ||
846 | * @return Frequency of SCTimer Clock. | ||
847 | */ | ||
848 | uint32_t CLOCK_GetSctClkFreq(void); | ||
849 | /*! @brief Return Frequency of SDIO Clock | ||
850 | * @return Frequency of SDIO Clock. | ||
851 | */ | ||
852 | uint32_t CLOCK_GetSdioClkFreq(void); | ||
853 | /*! @brief Return Frequency of LCD Clock | ||
854 | * @return Frequency of LCD Clock. | ||
855 | */ | ||
856 | uint32_t CLOCK_GetLcdClkFreq(void); | ||
857 | /*! @brief Return Frequency of LCD CLKIN Clock | ||
858 | * @return Frequency of LCD CLKIN Clock. | ||
859 | */ | ||
860 | uint32_t CLOCK_GetLcdClkIn(void); | ||
861 | /*! @brief Return Frequency of External Clock | ||
862 | * @return Frequency of External Clock. If no external clock is used returns 0. | ||
863 | */ | ||
864 | uint32_t CLOCK_GetExtClkFreq(void); | ||
865 | /*! @brief Return Frequency of Watchdog Oscillator | ||
866 | * @return Frequency of Watchdog Oscillator | ||
867 | */ | ||
868 | uint32_t CLOCK_GetWdtOscFreq(void); | ||
869 | /*! @brief Return Frequency of High-Freq output of FRO | ||
870 | * @return Frequency of High-Freq output of FRO | ||
871 | */ | ||
872 | uint32_t CLOCK_GetFroHfFreq(void); | ||
873 | /*! @brief Return Frequency of frg | ||
874 | * @return Frequency of FRG | ||
875 | */ | ||
876 | uint32_t CLOCK_GetFrgClkFreq(void); | ||
877 | /*! @brief Return Frequency of dmic | ||
878 | * @return Frequency of DMIC | ||
879 | */ | ||
880 | uint32_t CLOCK_GetDmicClkFreq(void); | ||
881 | /*! @brief Return Frequency of PLL | ||
882 | * @return Frequency of PLL | ||
883 | */ | ||
884 | uint32_t CLOCK_GetPllOutFreq(void); | ||
885 | /*! @brief Return Frequency of USB PLL | ||
886 | * @return Frequency of PLL | ||
887 | */ | ||
888 | uint32_t CLOCK_GetUsbPllOutFreq(void); | ||
889 | /*! @brief Return Frequency of AUDIO PLL | ||
890 | * @return Frequency of PLL | ||
891 | */ | ||
892 | uint32_t CLOCK_GetAudioPllOutFreq(void); | ||
893 | /*! @brief Return Frequency of 32kHz osc | ||
894 | * @return Frequency of 32kHz osc | ||
895 | */ | ||
896 | uint32_t CLOCK_GetOsc32KFreq(void); | ||
897 | /*! @brief Return Frequency of Core System | ||
898 | * @return Frequency of Core System | ||
899 | */ | ||
900 | uint32_t CLOCK_GetCoreSysClkFreq(void); | ||
901 | /*! @brief Return Frequency of I2S MCLK Clock | ||
902 | * @return Frequency of I2S MCLK Clock | ||
903 | */ | ||
904 | uint32_t CLOCK_GetI2SMClkFreq(void); | ||
905 | /*! @brief Return Frequency of Flexcomm functional Clock | ||
906 | * @return Frequency of Flexcomm functional Clock | ||
907 | */ | ||
908 | uint32_t CLOCK_GetFlexCommClkFreq(uint32_t id); | ||
909 | /*! @brief Return Asynchronous APB Clock source | ||
910 | * @return Asynchronous APB CLock source | ||
911 | */ | ||
912 | __STATIC_INLINE async_clock_src_t CLOCK_GetAsyncApbClkSrc(void) | ||
913 | { | ||
914 | return (async_clock_src_t)(uint8_t)(ASYNC_SYSCON->ASYNCAPBCLKSELA & 0x3U); | ||
915 | } | ||
916 | /*! @brief Return Frequency of Asynchronous APB Clock | ||
917 | * @return Frequency of Asynchronous APB Clock Clock | ||
918 | */ | ||
919 | uint32_t CLOCK_GetAsyncApbClkFreq(void); | ||
920 | /*! @brief Return EMC source | ||
921 | * @return EMC source | ||
922 | */ | ||
923 | __STATIC_INLINE uint32_t CLOCK_GetEmcClkFreq(void) | ||
924 | { | ||
925 | uint32_t freqtmp; | ||
926 | |||
927 | freqtmp = CLOCK_GetCoreSysClkFreq() / ((SYSCON->AHBCLKDIV & 0xffU) + 1U); | ||
928 | return freqtmp / ((SYSCON->EMCCLKDIV & 0xffU) + 1U); | ||
929 | } | ||
930 | /*! @brief Return Audio PLL input clock rate | ||
931 | * @return Audio PLL input clock rate | ||
932 | */ | ||
933 | uint32_t CLOCK_GetAudioPLLInClockRate(void); | ||
934 | /*! @brief Return System PLL input clock rate | ||
935 | * @return System PLL input clock rate | ||
936 | */ | ||
937 | uint32_t CLOCK_GetSystemPLLInClockRate(void); | ||
938 | |||
939 | /*! @brief Return System PLL output clock rate | ||
940 | * @param recompute : Forces a PLL rate recomputation if true | ||
941 | * @return System PLL output clock rate | ||
942 | * @note The PLL rate is cached in the driver in a variable as | ||
943 | * the rate computation function can take some time to perform. It | ||
944 | * is recommended to use 'false' with the 'recompute' parameter. | ||
945 | */ | ||
946 | uint32_t CLOCK_GetSystemPLLOutClockRate(bool recompute); | ||
947 | |||
948 | /*! @brief Return System AUDIO PLL output clock rate | ||
949 | * @param recompute : Forces a AUDIO PLL rate recomputation if true | ||
950 | * @return System AUDIO PLL output clock rate | ||
951 | * @note The AUDIO PLL rate is cached in the driver in a variable as | ||
952 | * the rate computation function can take some time to perform. It | ||
953 | * is recommended to use 'false' with the 'recompute' parameter. | ||
954 | */ | ||
955 | uint32_t CLOCK_GetAudioPLLOutClockRate(bool recompute); | ||
956 | |||
957 | /*! @brief Return System USB PLL output clock rate | ||
958 | * @param recompute : Forces a USB PLL rate recomputation if true | ||
959 | * @return System USB PLL output clock rate | ||
960 | * @note The USB PLL rate is cached in the driver in a variable as | ||
961 | * the rate computation function can take some time to perform. It | ||
962 | * is recommended to use 'false' with the 'recompute' parameter. | ||
963 | */ | ||
964 | uint32_t CLOCK_GetUsbPLLOutClockRate(bool recompute); | ||
965 | |||
966 | /*! @brief Enables and disables PLL bypass mode | ||
967 | * @brief bypass : true to bypass PLL (PLL output = PLL input, false to disable bypass | ||
968 | * @return System PLL output clock rate | ||
969 | */ | ||
970 | __STATIC_INLINE void CLOCK_SetBypassPLL(bool bypass) | ||
971 | { | ||
972 | if (bypass) | ||
973 | { | ||
974 | SYSCON->SYSPLLCTRL |= (1UL << SYSCON_SYSPLLCTRL_BYPASS_SHIFT); | ||
975 | } | ||
976 | else | ||
977 | { | ||
978 | SYSCON->SYSPLLCTRL &= ~(1UL << SYSCON_SYSPLLCTRL_BYPASS_SHIFT); | ||
979 | } | ||
980 | } | ||
981 | |||
982 | /*! @brief Check if PLL is locked or not | ||
983 | * @return true if the PLL is locked, false if not locked | ||
984 | */ | ||
985 | __STATIC_INLINE bool CLOCK_IsSystemPLLLocked(void) | ||
986 | { | ||
987 | return ((SYSCON->SYSPLLSTAT & SYSCON_SYSPLLSTAT_LOCK_MASK) != 0U); | ||
988 | } | ||
989 | |||
990 | /*! @brief Check if USB PLL is locked or not | ||
991 | * @return true if the USB PLL is locked, false if not locked | ||
992 | */ | ||
993 | __STATIC_INLINE bool CLOCK_IsUsbPLLLocked(void) | ||
994 | { | ||
995 | return ((SYSCON->USBPLLSTAT & SYSCON_USBPLLSTAT_LOCK_MASK) != 0U); | ||
996 | } | ||
997 | |||
998 | /*! @brief Check if AUDIO PLL is locked or not | ||
999 | * @return true if the AUDIO PLL is locked, false if not locked | ||
1000 | */ | ||
1001 | __STATIC_INLINE bool CLOCK_IsAudioPLLLocked(void) | ||
1002 | { | ||
1003 | return ((SYSCON->AUDPLLSTAT & SYSCON_AUDPLLSTAT_LOCK_MASK) != 0U); | ||
1004 | } | ||
1005 | |||
1006 | /*! @brief Enables and disables SYS OSC | ||
1007 | * @brief enable : true to enable SYS OSC, false to disable SYS OSC | ||
1008 | */ | ||
1009 | __STATIC_INLINE void CLOCK_Enable_SysOsc(bool enable) | ||
1010 | { | ||
1011 | if (enable) | ||
1012 | { | ||
1013 | SYSCON->PDRUNCFGCLR[0] |= SYSCON_PDRUNCFG_PDEN_VD2_ANA_MASK; | ||
1014 | SYSCON->PDRUNCFGCLR[1] |= SYSCON_PDRUNCFG_PDEN_SYSOSC_MASK; | ||
1015 | } | ||
1016 | |||
1017 | else | ||
1018 | { | ||
1019 | SYSCON->PDRUNCFGSET[0] = SYSCON_PDRUNCFG_PDEN_VD2_ANA_MASK; | ||
1020 | SYSCON->PDRUNCFGSET[1] = SYSCON_PDRUNCFG_PDEN_SYSOSC_MASK; | ||
1021 | } | ||
1022 | } | ||
1023 | |||
1024 | /*! @brief Store the current PLL rate | ||
1025 | * @param rate: Current rate of the PLL | ||
1026 | * @return Nothing | ||
1027 | **/ | ||
1028 | void CLOCK_SetStoredPLLClockRate(uint32_t rate); | ||
1029 | |||
1030 | /*! @brief Store the current AUDIO PLL rate | ||
1031 | * @param rate: Current rate of the PLL | ||
1032 | * @return Nothing | ||
1033 | **/ | ||
1034 | void CLOCK_SetStoredAudioPLLClockRate(uint32_t rate); | ||
1035 | |||
1036 | /*! @brief PLL configuration structure flags for 'flags' field | ||
1037 | * These flags control how the PLL configuration function sets up the PLL setup structure.<br> | ||
1038 | * | ||
1039 | * When the PLL_CONFIGFLAG_USEINRATE flag is selected, the 'InputRate' field in the | ||
1040 | * configuration structure must be assigned with the expected PLL frequency. If the | ||
1041 | * PLL_CONFIGFLAG_USEINRATE is not used, 'InputRate' is ignored in the configuration | ||
1042 | * function and the driver will determine the PLL rate from the currently selected | ||
1043 | * PLL source. This flag might be used to configure the PLL input clock more accurately | ||
1044 | * when using the WDT oscillator or a more dyanmic CLKIN source.<br> | ||
1045 | * | ||
1046 | * When the PLL_CONFIGFLAG_FORCENOFRACT flag is selected, the PLL hardware for the | ||
1047 | * automatic bandwidth selection, Spread Spectrum (SS) support, and fractional M-divider | ||
1048 | * are not used.<br> | ||
1049 | */ | ||
1050 | #define PLL_CONFIGFLAG_USEINRATE (1UL << 0U) /*!< Flag to use InputRate in PLL configuration structure for setup */ | ||
1051 | #define PLL_CONFIGFLAG_FORCENOFRACT \ | ||
1052 | (1UL << 2U) /*!< Force non-fractional output mode, \ | ||
1053 | PLL output will not use the fractional, \ | ||
1054 | automatic bandwidth, or SS hardware */ | ||
1055 | |||
1056 | /*! @brief PLL configuration structure | ||
1057 | * | ||
1058 | * This structure can be used to configure the settings for a PLL | ||
1059 | * setup structure. Fill in the desired configuration for the PLL | ||
1060 | * and call the PLL setup function to fill in a PLL setup structure. | ||
1061 | */ | ||
1062 | typedef struct _pll_config | ||
1063 | { | ||
1064 | uint32_t desiredRate; /*!< Desired PLL rate in Hz */ | ||
1065 | uint32_t inputRate; /*!< PLL input clock in Hz, only used if PLL_CONFIGFLAG_USEINRATE flag is set */ | ||
1066 | uint32_t flags; /*!< PLL configuration flags, Or'ed value of PLL_CONFIGFLAG_* definitions */ | ||
1067 | } pll_config_t; | ||
1068 | |||
1069 | /*! @brief PLL setup structure flags for 'flags' field | ||
1070 | * These flags control how the PLL setup function sets up the PLL | ||
1071 | */ | ||
1072 | #define PLL_SETUPFLAG_POWERUP (1UL << 0U) /*!< Setup will power on the PLL after setup */ | ||
1073 | #define PLL_SETUPFLAG_WAITLOCK (1UL << 1U) /*!< Setup will wait for PLL lock, implying the PLL will be pwoered on */ | ||
1074 | #define PLL_SETUPFLAG_ADGVOLT (1UL << 2U) /*!< Optimize system voltage for the new PLL rate */ | ||
1075 | |||
1076 | /*! @brief PLL setup structure | ||
1077 | * This structure can be used to pre-build a PLL setup configuration | ||
1078 | * at run-time and quickly set the PLL to the configuration. It can be | ||
1079 | * populated with the PLL setup function. If powering up or waiting | ||
1080 | * for PLL lock, the PLL input clock source should be configured prior | ||
1081 | * to PLL setup. | ||
1082 | */ | ||
1083 | typedef struct _pll_setup | ||
1084 | { | ||
1085 | uint32_t pllctrl; /*!< PLL control register SYSPLLCTRL */ | ||
1086 | uint32_t pllndec; /*!< PLL NDEC register SYSPLLNDEC */ | ||
1087 | uint32_t pllpdec; /*!< PLL PDEC register SYSPLLPDEC */ | ||
1088 | uint32_t pllmdec; /*!< PLL MDEC registers SYSPLLPDEC */ | ||
1089 | uint32_t pllRate; /*!< Acutal PLL rate */ | ||
1090 | uint32_t audpllfrac; /*!< only aduio PLL has this function*/ | ||
1091 | uint32_t flags; /*!< PLL setup flags, Or'ed value of PLL_SETUPFLAG_* definitions */ | ||
1092 | } pll_setup_t; | ||
1093 | |||
1094 | /*! @brief PLL status definitions | ||
1095 | */ | ||
1096 | typedef enum _pll_error | ||
1097 | { | ||
1098 | kStatus_PLL_Success = MAKE_STATUS(kStatusGroup_Generic, 0), /*!< PLL operation was successful */ | ||
1099 | kStatus_PLL_OutputTooLow = MAKE_STATUS(kStatusGroup_Generic, 1), /*!< PLL output rate request was too low */ | ||
1100 | kStatus_PLL_OutputTooHigh = MAKE_STATUS(kStatusGroup_Generic, 2), /*!< PLL output rate request was too high */ | ||
1101 | kStatus_PLL_InputTooLow = MAKE_STATUS(kStatusGroup_Generic, 3), /*!< PLL input rate is too low */ | ||
1102 | kStatus_PLL_InputTooHigh = MAKE_STATUS(kStatusGroup_Generic, 4), /*!< PLL input rate is too high */ | ||
1103 | kStatus_PLL_OutsideIntLimit = MAKE_STATUS(kStatusGroup_Generic, 5), /*!< Requested output rate isn't possible */ | ||
1104 | kStatus_PLL_CCOTooLow = MAKE_STATUS(kStatusGroup_Generic, 6), /*!< Requested CCO rate isn't possible */ | ||
1105 | kStatus_PLL_CCOTooHigh = MAKE_STATUS(kStatusGroup_Generic, 7) /*!< Requested CCO rate isn't possible */ | ||
1106 | } pll_error_t; | ||
1107 | |||
1108 | /*! @brief USB clock source definition. */ | ||
1109 | typedef enum _clock_usb_src | ||
1110 | { | ||
1111 | kCLOCK_UsbSrcFro = (uint32_t)kCLOCK_FroHf, /*!< Use FRO 96 or 48 MHz. */ | ||
1112 | kCLOCK_UsbSrcSystemPll = (uint32_t)kCLOCK_PllOut, /*!< Use System PLL output. */ | ||
1113 | kCLOCK_UsbSrcMainClock = (uint32_t)kCLOCK_CoreSysClk, /*!< Use Main clock. */ | ||
1114 | kCLOCK_UsbSrcUsbPll = (uint32_t)kCLOCK_UsbPll, /*!< Use USB PLL clock. */ | ||
1115 | |||
1116 | kCLOCK_UsbSrcNone = SYSCON_USB0CLKSEL_SEL( | ||
1117 | 7) /*!< Use None, this may be selected in order to reduce power when no output is needed. */ | ||
1118 | } clock_usb_src_t; | ||
1119 | |||
1120 | /*! @brief USB PDEL Divider. */ | ||
1121 | typedef enum _usb_pll_psel | ||
1122 | { | ||
1123 | pSel_Divide_1 = 0U, | ||
1124 | pSel_Divide_2, | ||
1125 | pSel_Divide_4, | ||
1126 | pSel_Divide_8 | ||
1127 | } usb_pll_psel; | ||
1128 | |||
1129 | /*! @brief PLL setup structure | ||
1130 | * This structure can be used to pre-build a USB PLL setup configuration | ||
1131 | * at run-time and quickly set the usb PLL to the configuration. It can be | ||
1132 | * populated with the USB PLL setup function. If powering up or waiting | ||
1133 | * for USB PLL lock, the PLL input clock source should be configured prior | ||
1134 | * to USB PLL setup. | ||
1135 | */ | ||
1136 | typedef struct _usb_pll_setup | ||
1137 | { | ||
1138 | uint8_t msel; /*!< USB PLL control register msel:1U-256U */ | ||
1139 | uint8_t psel; /*!< USB PLL control register psel:only support inter 1U 2U 4U 8U */ | ||
1140 | uint8_t nsel; /*!< USB PLL control register nsel:only suppoet inter 1U 2U 3U 4U */ | ||
1141 | bool direct; /*!< USB PLL CCO output control */ | ||
1142 | bool bypass; /*!< USB PLL inout clock bypass control */ | ||
1143 | bool fbsel; /*!< USB PLL ineter mode and non-integer mode control*/ | ||
1144 | uint32_t inputRate; /*!< USB PLL input rate */ | ||
1145 | } usb_pll_setup_t; | ||
1146 | |||
1147 | /*! @brief Return System PLL output clock rate from setup structure | ||
1148 | * @param pSetup : Pointer to a PLL setup structure | ||
1149 | * @return System PLL output clock rate the setup structure will generate | ||
1150 | */ | ||
1151 | uint32_t CLOCK_GetSystemPLLOutFromSetup(pll_setup_t *pSetup); | ||
1152 | |||
1153 | /*! @brief Return System AUDIO PLL output clock rate from setup structure | ||
1154 | * @param pSetup : Pointer to a PLL setup structure | ||
1155 | * @return System PLL output clock rate the setup structure will generate | ||
1156 | */ | ||
1157 | uint32_t CLOCK_GetAudioPLLOutFromSetup(pll_setup_t *pSetup); | ||
1158 | |||
1159 | /*! @brief Return System AUDIO PLL output clock rate from audio fractioanl setup structure | ||
1160 | * @param pSetup : Pointer to a PLL setup structure | ||
1161 | * @return System PLL output clock rate the setup structure will generate | ||
1162 | */ | ||
1163 | uint32_t CLOCK_GetAudioPLLOutFromFractSetup(pll_setup_t *pSetup); | ||
1164 | |||
1165 | /*! @brief Return System USB PLL output clock rate from setup structure | ||
1166 | * @param pSetup : Pointer to a PLL setup structure | ||
1167 | * @return System PLL output clock rate the setup structure will generate | ||
1168 | */ | ||
1169 | uint32_t CLOCK_GetUsbPLLOutFromSetup(const usb_pll_setup_t *pSetup); | ||
1170 | |||
1171 | /*! @brief Set USB PLL output frequency | ||
1172 | * @param rate : frequency value | ||
1173 | * | ||
1174 | */ | ||
1175 | void CLOCK_SetStoredUsbPLLClockRate(uint32_t rate); | ||
1176 | /*! @brief Set PLL output based on the passed PLL setup data | ||
1177 | * @param pControl : Pointer to populated PLL control structure to generate setup with | ||
1178 | * @param pSetup : Pointer to PLL setup structure to be filled | ||
1179 | * @return PLL_ERROR_SUCCESS on success, or PLL setup error code | ||
1180 | * @note Actual frequency for setup may vary from the desired frequency based on the | ||
1181 | * accuracy of input clocks, rounding, non-fractional PLL mode, etc. | ||
1182 | */ | ||
1183 | pll_error_t CLOCK_SetupPLLData(pll_config_t *pControl, pll_setup_t *pSetup); | ||
1184 | |||
1185 | /*! @brief Set AUDIO PLL output based on the passed AUDIO PLL setup data | ||
1186 | * @param pControl : Pointer to populated PLL control structure to generate setup with | ||
1187 | * @param pSetup : Pointer to PLL setup structure to be filled | ||
1188 | * @return PLL_ERROR_SUCCESS on success, or PLL setup error code | ||
1189 | * @note Actual frequency for setup may vary from the desired frequency based on the | ||
1190 | * accuracy of input clocks, rounding, non-fractional PLL mode, etc. | ||
1191 | */ | ||
1192 | pll_error_t CLOCK_SetupAudioPLLData(pll_config_t *pControl, pll_setup_t *pSetup); | ||
1193 | |||
1194 | /*! @brief Set PLL output from PLL setup structure (precise frequency) | ||
1195 | * @param pSetup : Pointer to populated PLL setup structure | ||
1196 | * @param flagcfg : Flag configuration for PLL config structure | ||
1197 | * @return PLL_ERROR_SUCCESS on success, or PLL setup error code | ||
1198 | * @note This function will power off the PLL, setup the PLL with the | ||
1199 | * new setup data, and then optionally powerup the PLL, wait for PLL lock, | ||
1200 | * and adjust system voltages to the new PLL rate. The function will not | ||
1201 | * alter any source clocks (ie, main systen clock) that may use the PLL, | ||
1202 | * so these should be setup prior to and after exiting the function. | ||
1203 | */ | ||
1204 | pll_error_t CLOCK_SetupSystemPLLPrec(pll_setup_t *pSetup, uint32_t flagcfg); | ||
1205 | |||
1206 | /*! @brief Set AUDIO PLL output from AUDIOPLL setup structure (precise frequency) | ||
1207 | * @param pSetup : Pointer to populated PLL setup structure | ||
1208 | * @param flagcfg : Flag configuration for PLL config structure | ||
1209 | * @return PLL_ERROR_SUCCESS on success, or PLL setup error code | ||
1210 | * @note This function will power off the PLL, setup the PLL with the | ||
1211 | * new setup data, and then optionally powerup the AUDIO PLL, wait for PLL lock, | ||
1212 | * and adjust system voltages to the new AUDIOPLL rate. The function will not | ||
1213 | * alter any source clocks (ie, main systen clock) that may use the AUDIO PLL, | ||
1214 | * so these should be setup prior to and after exiting the function. | ||
1215 | */ | ||
1216 | pll_error_t CLOCK_SetupAudioPLLPrec(pll_setup_t *pSetup, uint32_t flagcfg); | ||
1217 | |||
1218 | /*! @brief Set AUDIO PLL output from AUDIOPLL setup structure using the Audio Fractional divider register(precise | ||
1219 | * frequency) | ||
1220 | * @param pSetup : Pointer to populated PLL setup structure | ||
1221 | * @param flagcfg : Flag configuration for PLL config structure | ||
1222 | * @return PLL_ERROR_SUCCESS on success, or PLL setup error code | ||
1223 | * @note This function will power off the PLL, setup the PLL with the | ||
1224 | * new setup data, and then optionally powerup the AUDIO PLL, wait for PLL lock, | ||
1225 | * and adjust system voltages to the new AUDIOPLL rate. The function will not | ||
1226 | * alter any source clocks (ie, main systen clock) that may use the AUDIO PLL, | ||
1227 | * so these should be setup prior to and after exiting the function. | ||
1228 | */ | ||
1229 | pll_error_t CLOCK_SetupAudioPLLPrecFract(pll_setup_t *pSetup, uint32_t flagcfg); | ||
1230 | |||
1231 | /** | ||
1232 | * @brief Set PLL output from PLL setup structure (precise frequency) | ||
1233 | * @param pSetup : Pointer to populated PLL setup structure | ||
1234 | * @return kStatus_PLL_Success on success, or PLL setup error code | ||
1235 | * @note This function will power off the PLL, setup the PLL with the | ||
1236 | * new setup data, and then optionally powerup the PLL, wait for PLL lock, | ||
1237 | * and adjust system voltages to the new PLL rate. The function will not | ||
1238 | * alter any source clocks (ie, main systen clock) that may use the PLL, | ||
1239 | * so these should be setup prior to and after exiting the function. | ||
1240 | */ | ||
1241 | pll_error_t CLOCK_SetPLLFreq(const pll_setup_t *pSetup); | ||
1242 | |||
1243 | /** | ||
1244 | * @brief Set Audio PLL output from Audio PLL setup structure (precise frequency) | ||
1245 | * @param pSetup : Pointer to populated PLL setup structure | ||
1246 | * @return kStatus_PLL_Success on success, or Audio PLL setup error code | ||
1247 | * @note This function will power off the PLL, setup the Audio PLL with the | ||
1248 | * new setup data, and then optionally powerup the PLL, wait for Audio PLL lock, | ||
1249 | * and adjust system voltages to the new PLL rate. The function will not | ||
1250 | * alter any source clocks (ie, main systen clock) that may use the Audio PLL, | ||
1251 | * so these should be setup prior to and after exiting the function. | ||
1252 | */ | ||
1253 | pll_error_t CLOCK_SetAudioPLLFreq(const pll_setup_t *pSetup); | ||
1254 | |||
1255 | /** | ||
1256 | * @brief Set USB PLL output from USB PLL setup structure (precise frequency) | ||
1257 | * @param pSetup : Pointer to populated USB PLL setup structure | ||
1258 | * @return kStatus_PLL_Success on success, or USB PLL setup error code | ||
1259 | * @note This function will power off the USB PLL, setup the PLL with the | ||
1260 | * new setup data, and then optionally powerup the USB PLL, wait for USB PLL lock, | ||
1261 | * and adjust system voltages to the new USB PLL rate. The function will not | ||
1262 | * alter any source clocks (ie, usb pll clock) that may use the USB PLL, | ||
1263 | * so these should be setup prior to and after exiting the function. | ||
1264 | */ | ||
1265 | pll_error_t CLOCK_SetUsbPLLFreq(const usb_pll_setup_t *pSetup); | ||
1266 | |||
1267 | /*! @brief Set PLL output based on the multiplier and input frequency | ||
1268 | * @param multiply_by : multiplier | ||
1269 | * @param input_freq : Clock input frequency of the PLL | ||
1270 | * @return Nothing | ||
1271 | * @note Unlike the Chip_Clock_SetupSystemPLLPrec() function, this | ||
1272 | * function does not disable or enable PLL power, wait for PLL lock, | ||
1273 | * or adjust system voltages. These must be done in the application. | ||
1274 | * The function will not alter any source clocks (ie, main systen clock) | ||
1275 | * that may use the PLL, so these should be setup prior to and after | ||
1276 | * exiting the function. | ||
1277 | */ | ||
1278 | void CLOCK_SetupSystemPLLMult(uint32_t multiply_by, uint32_t input_freq); | ||
1279 | |||
1280 | /*! @brief Disable USB clock. | ||
1281 | * | ||
1282 | * Disable USB clock. | ||
1283 | */ | ||
1284 | static inline void CLOCK_DisableUsbDevicefs0Clock(clock_ip_name_t clk) | ||
1285 | { | ||
1286 | CLOCK_DisableClock(clk); | ||
1287 | } | ||
1288 | |||
1289 | /*! @brief Enable USB Device FS clock. | ||
1290 | * @param src : clock source | ||
1291 | * @param freq: clock frequency | ||
1292 | * Enable USB Device Full Speed clock. | ||
1293 | */ | ||
1294 | bool CLOCK_EnableUsbfs0DeviceClock(clock_usb_src_t src, uint32_t freq); | ||
1295 | |||
1296 | /*! @brief Enable USB HOST FS clock. | ||
1297 | * @param src : clock source | ||
1298 | * @param freq: clock frequency | ||
1299 | * Enable USB HOST Full Speed clock. | ||
1300 | */ | ||
1301 | bool CLOCK_EnableUsbfs0HostClock(clock_usb_src_t src, uint32_t freq); | ||
1302 | |||
1303 | /*! @brief Enable USB Device HS clock. | ||
1304 | * @param src : clock source | ||
1305 | * @param freq: clock frequency | ||
1306 | * Enable USB Device High Speed clock. | ||
1307 | */ | ||
1308 | bool CLOCK_EnableUsbhs0DeviceClock(clock_usb_src_t src, uint32_t freq); | ||
1309 | |||
1310 | /*! @brief Enable USB HOST HS clock. | ||
1311 | * @param src : clock source | ||
1312 | * @param freq: clock frequency | ||
1313 | * Enable USB HOST High Speed clock. | ||
1314 | */ | ||
1315 | bool CLOCK_EnableUsbhs0HostClock(clock_usb_src_t src, uint32_t freq); | ||
1316 | |||
1317 | #if defined(__cplusplus) | ||
1318 | } | ||
1319 | #endif /* __cplusplus */ | ||
1320 | |||
1321 | /*! @} */ | ||
1322 | |||
1323 | #endif /* _FSL_CLOCK_H_ */ | ||