1 /* 2 * Copyright (c) 2023, NXP 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include <fsl_clock.h> 8 #include <soc.h> 9 10 /* reimplementation of non-inline CLOCK_GetFreq(kCLOCK_Usb1PllPfd0Clk) */ clock_get_usb1_pll_pfd0_clk(void)11static uint32_t clock_get_usb1_pll_pfd0_clk(void) 12 { 13 uint32_t freq; 14 15 if (!CLOCK_IsPllEnabled(CCM_ANALOG, kCLOCK_PllUsb1)) { 16 return 0; 17 } 18 19 freq = CLOCK_GetPllBypassRefClk(CCM_ANALOG, kCLOCK_PllUsb1); 20 21 if (CLOCK_IsPllBypassed(CCM_ANALOG, kCLOCK_PllUsb1)) { 22 return freq; 23 } 24 25 freq *= ((CCM_ANALOG->PLL_USB1 & CCM_ANALOG_PLL_USB1_DIV_SELECT_MASK) != 0) ? 22 : 20; 26 27 /* get current USB1 PLL PFD output frequency */ 28 freq /= (CCM_ANALOG->PFD_480 & CCM_ANALOG_PFD_480_PFD0_FRAC_MASK) >> 29 CCM_ANALOG_PFD_480_PFD0_FRAC_SHIFT; 30 freq *= 18; 31 32 return freq; 33 } 34 flexspi_clock_set_div(uint32_t value)35void flexspi_clock_set_div(uint32_t value) 36 { 37 CLOCK_DisableClock(kCLOCK_FlexSpi); 38 39 CLOCK_SetDiv(kCLOCK_FlexspiDiv, value); 40 41 CLOCK_EnableClock(kCLOCK_FlexSpi); 42 } 43 flexspi_clock_get_freq(void)44uint32_t flexspi_clock_get_freq(void) 45 { 46 uint32_t divider; 47 uint32_t frequency; 48 49 divider = CLOCK_GetDiv(kCLOCK_FlexspiDiv); 50 51 frequency = clock_get_usb1_pll_pfd0_clk() / (divider + 1); 52 53 return frequency; 54 } 55