2022-01-07 11:33:48 -06:00
|
|
|
/*
|
2023-01-09 13:24:13 -06:00
|
|
|
* Copyright 2022-2023, NXP
|
2022-01-07 11:33:48 -06:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief System/hardware module for NXP RT5XX platform
|
|
|
|
*
|
|
|
|
* This module provides routines to initialize and support board-level
|
|
|
|
* hardware for the RT5XX platforms.
|
|
|
|
*/
|
|
|
|
|
2022-10-05 11:12:53 +02:00
|
|
|
#include <zephyr/arch/arm/aarch32/nmi.h>
|
2022-05-06 11:11:04 +02:00
|
|
|
#include <zephyr/init.h>
|
2022-10-05 11:35:22 +02:00
|
|
|
#include <zephyr/devicetree.h>
|
2022-10-04 15:33:53 +02:00
|
|
|
#include <zephyr/irq.h>
|
2022-10-13 16:50:49 -05:00
|
|
|
#include <zephyr/linker/sections.h>
|
2022-01-07 11:33:48 -06:00
|
|
|
#include <soc.h>
|
|
|
|
#include "fsl_power.h"
|
|
|
|
#include "fsl_clock.h"
|
2022-11-30 16:06:40 -06:00
|
|
|
#include <fsl_cache.h>
|
2022-01-07 11:33:48 -06:00
|
|
|
|
2022-12-21 09:27:33 -06:00
|
|
|
#ifdef CONFIG_FLASH_MCUX_FLEXSPI_XIP
|
|
|
|
#include "flash_clock_setup.h"
|
|
|
|
#endif
|
|
|
|
|
2022-08-16 15:53:04 -05:00
|
|
|
#if CONFIG_USB_DC_NXP_LPCIP3511
|
|
|
|
#include "usb_phy.h"
|
2022-08-18 19:14:27 -05:00
|
|
|
#include "usb.h"
|
2022-08-16 15:53:04 -05:00
|
|
|
#endif
|
|
|
|
|
2022-01-07 11:33:48 -06:00
|
|
|
/* Board System oscillator settling time in us */
|
|
|
|
#define BOARD_SYSOSC_SETTLING_US 100U
|
|
|
|
/* Board xtal frequency in Hz */
|
|
|
|
#define BOARD_XTAL_SYS_CLK_HZ 24000000U
|
|
|
|
/* Core clock frequency: 198000000Hz */
|
|
|
|
#define CLOCK_INIT_CORE_CLOCK 198000000U
|
|
|
|
|
2022-05-19 14:29:14 +08:00
|
|
|
#define CTIMER_CLOCK_SOURCE(node_id) \
|
|
|
|
TO_CTIMER_CLOCK_SOURCE(DT_CLOCKS_CELL(node_id, name), DT_PROP(node_id, clk_source))
|
|
|
|
#define TO_CTIMER_CLOCK_SOURCE(inst, val) TO_CLOCK_ATTACH_ID(inst, val)
|
|
|
|
#define TO_CLOCK_ATTACH_ID(inst, val) CLKCTL1_TUPLE_MUXA(CT32BIT##inst##FCLKSEL_OFFSET, val)
|
|
|
|
#define CTIMER_CLOCK_SETUP(node_id) CLOCK_AttachClk(CTIMER_CLOCK_SOURCE(node_id));
|
|
|
|
|
2022-01-07 11:33:48 -06:00
|
|
|
const clock_sys_pll_config_t g_sysPllConfig_clock_init = {
|
|
|
|
/* OSC clock */
|
|
|
|
.sys_pll_src = kCLOCK_SysPllXtalIn,
|
|
|
|
/* Numerator of the SYSPLL0 fractional loop divider is 0 */
|
|
|
|
.numerator = 0,
|
|
|
|
/* Denominator of the SYSPLL0 fractional loop divider is 1 */
|
|
|
|
.denominator = 1,
|
|
|
|
/* Divide by 22 */
|
|
|
|
.sys_pll_mult = kCLOCK_SysPllMult22
|
|
|
|
};
|
|
|
|
|
|
|
|
const clock_audio_pll_config_t g_audioPllConfig_clock_init = {
|
|
|
|
/* OSC clock */
|
|
|
|
.audio_pll_src = kCLOCK_AudioPllXtalIn,
|
|
|
|
/* Numerator of the Audio PLL fractional loop divider is 0 */
|
|
|
|
.numerator = 5040,
|
|
|
|
/* Denominator of the Audio PLL fractional loop divider is 1 */
|
|
|
|
.denominator = 27000,
|
|
|
|
/* Divide by 22 */
|
|
|
|
.audio_pll_mult = kCLOCK_AudioPllMult22
|
|
|
|
};
|
|
|
|
|
|
|
|
const clock_frg_clk_config_t g_frg0Config_clock_init = {
|
|
|
|
.num = 0,
|
|
|
|
.sfg_clock_src = kCLOCK_FrgPllDiv,
|
|
|
|
.divider = 255U,
|
|
|
|
.mult = 0
|
|
|
|
};
|
|
|
|
|
|
|
|
const clock_frg_clk_config_t g_frg12Config_clock_init = {
|
|
|
|
.num = 12,
|
|
|
|
.sfg_clock_src = kCLOCK_FrgMainClk,
|
|
|
|
.divider = 255U,
|
|
|
|
.mult = 167
|
|
|
|
};
|
|
|
|
|
2022-08-16 15:53:04 -05:00
|
|
|
#if CONFIG_USB_DC_NXP_LPCIP3511
|
|
|
|
/* USB PHY condfiguration */
|
|
|
|
#define BOARD_USB_PHY_D_CAL (0x0CU)
|
|
|
|
#define BOARD_USB_PHY_TXCAL45DP (0x06U)
|
|
|
|
#define BOARD_USB_PHY_TXCAL45DM (0x06U)
|
|
|
|
#endif
|
|
|
|
|
2022-01-07 11:33:48 -06:00
|
|
|
/* System clock frequency. */
|
|
|
|
extern uint32_t SystemCoreClock;
|
2023-01-26 16:18:59 -06:00
|
|
|
/* Main stack pointer */
|
|
|
|
extern char z_main_stack[];
|
2022-01-07 11:33:48 -06:00
|
|
|
|
|
|
|
#ifdef CONFIG_NXP_IMX_RT5XX_BOOT_HEADER
|
|
|
|
extern char _flash_used[];
|
|
|
|
|
|
|
|
extern void z_arm_reset(void);
|
|
|
|
extern void z_arm_nmi(void);
|
|
|
|
extern void z_arm_hard_fault(void);
|
|
|
|
extern void z_arm_mpu_fault(void);
|
|
|
|
extern void z_arm_bus_fault(void);
|
|
|
|
extern void z_arm_usage_fault(void);
|
|
|
|
extern void z_arm_secure_fault(void);
|
|
|
|
extern void z_arm_svc(void);
|
|
|
|
extern void z_arm_debug_monitor(void);
|
|
|
|
extern void z_arm_pendsv(void);
|
|
|
|
extern void sys_clock_isr(void);
|
|
|
|
extern void z_arm_exc_spurious(void);
|
|
|
|
|
|
|
|
__imx_boot_ivt_section void (* const image_vector_table[])(void) = {
|
|
|
|
(void (*)())(z_main_stack + CONFIG_MAIN_STACK_SIZE), /* 0x00 */
|
|
|
|
z_arm_reset, /* 0x04 */
|
|
|
|
z_arm_nmi, /* 0x08 */
|
|
|
|
z_arm_hard_fault, /* 0x0C */
|
|
|
|
z_arm_mpu_fault, /* 0x10 */
|
|
|
|
z_arm_bus_fault, /* 0x14 */
|
|
|
|
z_arm_usage_fault, /* 0x18 */
|
|
|
|
#if defined(CONFIG_ARM_SECURE_FIRMWARE)
|
|
|
|
z_arm_secure_fault, /* 0x1C */
|
|
|
|
#else
|
|
|
|
z_arm_exc_spurious,
|
|
|
|
#endif /* CONFIG_ARM_SECURE_FIRMWARE */
|
|
|
|
(void (*)())_flash_used, /* 0x20, imageLength. */
|
|
|
|
0, /* 0x24, imageType (Plain Image) */
|
|
|
|
0, /* 0x28, authBlockOffset/crcChecksum */
|
|
|
|
z_arm_svc, /* 0x2C */
|
|
|
|
z_arm_debug_monitor, /* 0x30 */
|
|
|
|
(void (*)())image_vector_table, /* 0x34, imageLoadAddress. */
|
|
|
|
z_arm_pendsv, /* 0x38 */
|
|
|
|
#if defined(CONFIG_SYS_CLOCK_EXISTS) && \
|
|
|
|
defined(CONFIG_CORTEX_M_SYSTICK_INSTALL_ISR)
|
|
|
|
sys_clock_isr, /* 0x3C */
|
|
|
|
#else
|
|
|
|
z_arm_exc_spurious,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
#endif /* CONFIG_NXP_IMX_RT5XX_BOOT_HEADER */
|
|
|
|
|
2022-08-16 15:53:04 -05:00
|
|
|
#if CONFIG_USB_DC_NXP_LPCIP3511
|
|
|
|
|
|
|
|
static void usb_device_clock_init(void)
|
|
|
|
{
|
|
|
|
uint8_t usbClockDiv = 1;
|
|
|
|
uint32_t usbClockFreq;
|
|
|
|
usb_phy_config_struct_t phyConfig = {
|
|
|
|
BOARD_USB_PHY_D_CAL,
|
|
|
|
BOARD_USB_PHY_TXCAL45DP,
|
|
|
|
BOARD_USB_PHY_TXCAL45DM,
|
|
|
|
};
|
|
|
|
|
2022-08-30 10:30:44 -05:00
|
|
|
/* Make sure USBHS ram buffer and usb1 phy has power up */
|
2022-08-16 15:53:04 -05:00
|
|
|
POWER_DisablePD(kPDRUNCFG_APD_USBHS_SRAM);
|
|
|
|
POWER_DisablePD(kPDRUNCFG_PPD_USBHS_SRAM);
|
|
|
|
POWER_ApplyPD();
|
|
|
|
|
|
|
|
RESET_PeripheralReset(kUSBHS_PHY_RST_SHIFT_RSTn);
|
|
|
|
RESET_PeripheralReset(kUSBHS_DEVICE_RST_SHIFT_RSTn);
|
|
|
|
RESET_PeripheralReset(kUSBHS_HOST_RST_SHIFT_RSTn);
|
|
|
|
RESET_PeripheralReset(kUSBHS_SRAM_RST_SHIFT_RSTn);
|
|
|
|
|
|
|
|
/* enable usb ip clock */
|
|
|
|
CLOCK_EnableUsbHs0DeviceClock(kOSC_CLK_to_USB_CLK, usbClockDiv);
|
|
|
|
/* save usb ip clock freq*/
|
|
|
|
usbClockFreq = g_xtalFreq / usbClockDiv;
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivPfc1Clk, 4);
|
|
|
|
/* enable usb ram clock */
|
|
|
|
CLOCK_EnableClock(kCLOCK_UsbhsSram);
|
|
|
|
/* enable USB PHY PLL clock, the phy bus clock (480MHz) source is same with USB IP */
|
|
|
|
CLOCK_EnableUsbHs0PhyPllClock(kOSC_CLK_to_USB_CLK, usbClockFreq);
|
|
|
|
|
|
|
|
/* USB PHY initialization */
|
|
|
|
USB_EhciPhyInit(kUSB_ControllerLpcIp3511Hs0, BOARD_XTAL_SYS_CLK_HZ, &phyConfig);
|
|
|
|
|
|
|
|
#if defined(FSL_FEATURE_USBHSD_USB_RAM) && (FSL_FEATURE_USBHSD_USB_RAM)
|
|
|
|
for (int i = 0; i < FSL_FEATURE_USBHSD_USB_RAM; i++) {
|
|
|
|
((uint8_t *)FSL_FEATURE_USBHSD_USB_RAM_BASE_ADDRESS)[i] = 0x00U;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* The following code should run after phy initialization and should wait
|
|
|
|
* some microseconds to make sure utmi clock valid
|
|
|
|
*/
|
|
|
|
/* enable usb1 host clock */
|
|
|
|
CLOCK_EnableClock(kCLOCK_UsbhsHost);
|
|
|
|
/* Wait until host_needclk de-asserts */
|
|
|
|
while (SYSCTL0->USB0CLKSTAT & SYSCTL0_USB0CLKSTAT_HOST_NEED_CLKST_MASK) {
|
|
|
|
__ASM("nop");
|
|
|
|
}
|
|
|
|
/* According to reference mannual, device mode setting has to be set by access
|
|
|
|
* usb host register
|
|
|
|
*/
|
|
|
|
USBHSH->PORTMODE |= USBHSH_PORTMODE_DEV_ENABLE_MASK;
|
|
|
|
/* disable usb1 host clock */
|
|
|
|
CLOCK_DisableClock(kCLOCK_UsbhsHost);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2022-01-07 11:33:48 -06:00
|
|
|
void z_arm_platform_init(void)
|
|
|
|
{
|
2023-01-26 16:18:59 -06:00
|
|
|
#ifndef CONFIG_NXP_IMX_RT5XX_BOOT_HEADER
|
|
|
|
/*
|
|
|
|
* If boot did not proceed using a boot header, we should not assume
|
|
|
|
* the core is in reset state. Disable the MPU and correctly
|
|
|
|
* set the stack pointer, since we are about to push to
|
|
|
|
* the stack when we call SystemInit
|
|
|
|
*/
|
|
|
|
/* Clear stack limit registers */
|
|
|
|
__set_MSPLIM(0);
|
|
|
|
__set_PSPLIM(0);
|
|
|
|
/* Disable MPU */
|
|
|
|
MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk;
|
|
|
|
/* Set stack pointer */
|
|
|
|
__set_MSP((uint32_t)(z_main_stack + CONFIG_MAIN_STACK_SIZE));
|
|
|
|
#endif /* !CONFIG_NXP_IMX_RT5XX_BOOT_HEADER */
|
2022-01-07 11:33:48 -06:00
|
|
|
/* This is provided by the SDK */
|
|
|
|
SystemInit();
|
|
|
|
}
|
|
|
|
|
2022-10-07 20:47:33 -05:00
|
|
|
static void clock_init(void)
|
2022-01-07 11:33:48 -06:00
|
|
|
{
|
|
|
|
/* Configure LPOSC 1M */
|
|
|
|
/* Power on LPOSC (1MHz) */
|
|
|
|
POWER_DisablePD(kPDRUNCFG_PD_LPOSC);
|
|
|
|
/* Wait until LPOSC stable */
|
|
|
|
CLOCK_EnableLpOscClk();
|
|
|
|
|
|
|
|
/* Configure FRO clock source */
|
|
|
|
/* Power on FRO (192MHz or 96MHz) */
|
|
|
|
POWER_DisablePD(kPDRUNCFG_PD_FFRO);
|
|
|
|
/* FRO_DIV1 is always enabled and used as Main clock during PLL update. */
|
|
|
|
/* Enable all FRO outputs */
|
|
|
|
CLOCK_EnableFroClk(kCLOCK_FroAllOutEn);
|
|
|
|
|
2022-12-21 09:27:33 -06:00
|
|
|
#ifdef CONFIG_FLASH_MCUX_FLEXSPI_XIP
|
2022-01-07 11:33:48 -06:00
|
|
|
/*
|
|
|
|
* Call function flexspi_clock_safe_config() to move FlexSPI clock to a stable
|
|
|
|
* clock source to avoid instruction/data fetch issue when updating PLL and Main
|
|
|
|
* clock if XIP(execute code on FLEXSPI memory).
|
|
|
|
*/
|
|
|
|
flexspi_clock_safe_config();
|
2022-12-21 09:27:33 -06:00
|
|
|
#endif
|
2022-01-07 11:33:48 -06:00
|
|
|
|
|
|
|
/* Let CPU run on FRO with divider 2 for safe switching. */
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivSysCpuAhbClk, 2);
|
|
|
|
CLOCK_AttachClk(kFRO_DIV1_to_MAIN_CLK);
|
|
|
|
|
|
|
|
/* Configure SYSOSC clock source. */
|
|
|
|
/* Power on SYSXTAL */
|
|
|
|
POWER_DisablePD(kPDRUNCFG_PD_SYSXTAL);
|
|
|
|
/* Updated XTAL oscillator settling time */
|
|
|
|
POWER_UpdateOscSettlingTime(BOARD_SYSOSC_SETTLING_US);
|
|
|
|
/* Enable system OSC */
|
|
|
|
CLOCK_EnableSysOscClk(true, true, BOARD_SYSOSC_SETTLING_US);
|
|
|
|
/* Sets external XTAL OSC freq */
|
|
|
|
CLOCK_SetXtalFreq(BOARD_XTAL_SYS_CLK_HZ);
|
|
|
|
|
|
|
|
/* Configure SysPLL0 clock source. */
|
|
|
|
CLOCK_InitSysPll(&g_sysPllConfig_clock_init);
|
|
|
|
/* Enable MAIN PLL clock */
|
|
|
|
CLOCK_InitSysPfd(kCLOCK_Pfd0, 24);
|
|
|
|
/* Enable AUX0 PLL clock */
|
|
|
|
CLOCK_InitSysPfd(kCLOCK_Pfd2, 24);
|
|
|
|
|
|
|
|
/* Configure Audio PLL clock source. */
|
|
|
|
CLOCK_InitAudioPll(&g_audioPllConfig_clock_init);
|
|
|
|
/* Enable Audio PLL clock */
|
|
|
|
CLOCK_InitAudioPfd(kCLOCK_Pfd0, 26);
|
|
|
|
|
|
|
|
/* Set SYSCPUAHBCLKDIV divider to value 2 */
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivSysCpuAhbClk, 2U);
|
|
|
|
|
|
|
|
/* Setup FRG0 clock */
|
|
|
|
CLOCK_SetFRGClock(&g_frg0Config_clock_init);
|
|
|
|
/* Setup FRG12 clock */
|
|
|
|
CLOCK_SetFRGClock(&g_frg12Config_clock_init);
|
|
|
|
|
|
|
|
/* Set up clock selectors - Attach clocks to the peripheries. */
|
|
|
|
/* Switch MAIN_CLK to MAIN_PLL */
|
|
|
|
CLOCK_AttachClk(kMAIN_PLL_to_MAIN_CLK);
|
|
|
|
/* Switch SYSTICK_CLK to MAIN_CLK_DIV */
|
|
|
|
CLOCK_AttachClk(kMAIN_CLK_DIV_to_SYSTICK_CLK);
|
|
|
|
#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(flexcomm0), nxp_lpc_usart, okay)
|
|
|
|
/* Switch FLEXCOMM0 to FRG */
|
|
|
|
CLOCK_AttachClk(kFRG_to_FLEXCOMM0);
|
|
|
|
#endif
|
2022-08-16 15:53:04 -05:00
|
|
|
#if CONFIG_USB_DC_NXP_LPCIP3511
|
|
|
|
usb_device_clock_init();
|
|
|
|
#endif
|
2023-05-04 14:21:39 -04:00
|
|
|
|
|
|
|
#if (DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(flexcomm1), nxp_lpc_i2s, okay) && CONFIG_I2S)
|
|
|
|
/* attach AUDIO PLL clock to FLEXCOMM1 (I2S1) */
|
|
|
|
CLOCK_AttachClk(kAUDIO_PLL_to_FLEXCOMM1);
|
|
|
|
#endif
|
|
|
|
#if (DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(flexcomm3), nxp_lpc_i2s, okay) && CONFIG_I2S)
|
|
|
|
/* attach AUDIO PLL clock to FLEXCOMM3 (I2S3) */
|
|
|
|
CLOCK_AttachClk(kAUDIO_PLL_to_FLEXCOMM3);
|
|
|
|
#endif
|
|
|
|
|
2022-05-16 11:02:25 +08:00
|
|
|
#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(flexcomm4), nxp_lpc_i2c, okay)
|
|
|
|
/* Switch FLEXCOMM4 to FRO_DIV4 */
|
|
|
|
CLOCK_AttachClk(kFRO_DIV4_to_FLEXCOMM4);
|
|
|
|
#endif
|
2022-05-19 14:22:35 +08:00
|
|
|
#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(hs_spi1), nxp_lpc_spi, okay)
|
|
|
|
CLOCK_AttachClk(kFRO_DIV4_to_FLEXCOMM16);
|
|
|
|
#endif
|
2022-01-07 11:33:48 -06:00
|
|
|
#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(flexcomm12), nxp_lpc_usart, okay)
|
|
|
|
/* Switch FLEXCOMM12 to FRG */
|
|
|
|
CLOCK_AttachClk(kFRG_to_FLEXCOMM12);
|
2022-08-22 11:20:45 -04:00
|
|
|
#endif
|
|
|
|
#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pmic_i2c), nxp_lpc_i2c, okay)
|
|
|
|
CLOCK_AttachClk(kFRO_DIV4_to_FLEXCOMM15);
|
2022-01-07 11:33:48 -06:00
|
|
|
#endif
|
2023-01-09 13:24:13 -06:00
|
|
|
#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(lcdif), nxp_dcnano_lcdif, okay) && CONFIG_DISPLAY
|
|
|
|
POWER_DisablePD(kPDRUNCFG_APD_DCNANO_SRAM);
|
|
|
|
POWER_DisablePD(kPDRUNCFG_PPD_DCNANO_SRAM);
|
|
|
|
POWER_ApplyPD();
|
|
|
|
|
|
|
|
CLOCK_AttachClk(kAUX0_PLL_to_DCPIXEL_CLK);
|
|
|
|
/* Note- pixel clock follows formula
|
|
|
|
* (height + VSW + VFP + VBP) * (width + HSW + HFP + HBP) * frame rate.
|
|
|
|
* this means the clock divider will vary depending on
|
|
|
|
* the attached display.
|
2023-01-17 15:36:31 -06:00
|
|
|
*
|
|
|
|
* The root clock used here is the AUX0 PLL (PLL0 PFD2).
|
2023-01-09 13:24:13 -06:00
|
|
|
*/
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivDcPixelClk,
|
2023-01-17 15:36:31 -06:00
|
|
|
((CLOCK_GetSysPfdFreq(kCLOCK_Pfd2) /
|
2023-01-18 10:40:15 -06:00
|
|
|
DT_PROP(DT_CHILD(DT_NODELABEL(lcdif), display_timings),
|
|
|
|
clock_frequency)) + 1));
|
2023-01-09 13:24:13 -06:00
|
|
|
|
|
|
|
CLOCK_EnableClock(kCLOCK_DisplayCtrl);
|
|
|
|
RESET_ClearPeripheralReset(kDISP_CTRL_RST_SHIFT_RSTn);
|
|
|
|
|
|
|
|
CLOCK_EnableClock(kCLOCK_AxiSwitch);
|
|
|
|
RESET_ClearPeripheralReset(kAXI_SWITCH_RST_SHIFT_RSTn);
|
|
|
|
#if defined(CONFIG_MEMC) && DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(flexspi2), \
|
|
|
|
nxp_imx_flexspi, okay)
|
|
|
|
/* Enable write-through for FlexSPI1 space */
|
|
|
|
CACHE64_POLSEL0->REG1_TOP = 0x27FFFC00U;
|
|
|
|
CACHE64_POLSEL0->POLSEL = 0x11U;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2022-01-07 11:33:48 -06:00
|
|
|
/* Switch CLKOUT to FRO_DIV2 */
|
|
|
|
CLOCK_AttachClk(kFRO_DIV2_to_CLKOUT);
|
|
|
|
|
2022-08-30 10:30:44 -05:00
|
|
|
#if DT_NODE_HAS_STATUS(DT_NODELABEL(usdhc0), okay) && CONFIG_IMX_USDHC
|
2022-08-30 10:19:09 -05:00
|
|
|
/* Make sure USDHC ram buffer has been power up*/
|
|
|
|
POWER_DisablePD(kPDRUNCFG_APD_USDHC0_SRAM);
|
|
|
|
POWER_DisablePD(kPDRUNCFG_PPD_USDHC0_SRAM);
|
|
|
|
POWER_DisablePD(kPDRUNCFG_PD_LPOSC);
|
|
|
|
POWER_ApplyPD();
|
|
|
|
|
|
|
|
/* usdhc depend on 32K clock also */
|
|
|
|
CLOCK_AttachClk(kLPOSC_DIV32_to_32KHZWAKE_CLK);
|
|
|
|
CLOCK_AttachClk(kAUX0_PLL_to_SDIO0_CLK);
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivSdio0Clk, 1);
|
|
|
|
CLOCK_EnableClock(kCLOCK_Sdio0);
|
|
|
|
RESET_PeripheralReset(kSDIO0_RST_SHIFT_RSTn);
|
|
|
|
#endif
|
|
|
|
|
2022-05-19 14:29:14 +08:00
|
|
|
DT_FOREACH_STATUS_OKAY(nxp_lpc_ctimer, CTIMER_CLOCK_SETUP)
|
|
|
|
|
2022-01-07 11:33:48 -06:00
|
|
|
/* Set up dividers. */
|
|
|
|
/* Set AUDIOPLLCLKDIV divider to value 15 */
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivAudioPllClk, 15U);
|
|
|
|
/* Set FRGPLLCLKDIV divider to value 11 */
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivPLLFRGClk, 11U);
|
|
|
|
/* Set SYSTICKFCLKDIV divider to value 2 */
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivSystickClk, 2U);
|
|
|
|
/* Set PFC0DIV divider to value 2 */
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivPfc0Clk, 2U);
|
|
|
|
/* Set PFC1DIV divider to value 4 */
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivPfc1Clk, 4U);
|
|
|
|
/* Set CLKOUTFCLKDIV divider to value 100 */
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivClockOut, 100U);
|
|
|
|
|
2022-12-21 09:27:33 -06:00
|
|
|
#ifdef CONFIG_FLASH_MCUX_FLEXSPI_XIP
|
2022-01-07 11:33:48 -06:00
|
|
|
/*
|
|
|
|
* Call function flexspi_setup_clock() to set user configured clock source/divider
|
|
|
|
* for FlexSPI.
|
|
|
|
*/
|
|
|
|
flexspi_setup_clock(FLEXSPI0, 0U, 2U);
|
2022-12-21 09:27:33 -06:00
|
|
|
#endif
|
2022-01-07 11:33:48 -06:00
|
|
|
|
2022-12-20 17:06:39 -06:00
|
|
|
#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(flexspi2), nxp_imx_flexspi, okay)
|
|
|
|
/* Power up FlexSPI1 SRAM */
|
|
|
|
POWER_DisablePD(kPDRUNCFG_APD_FLEXSPI1_SRAM);
|
|
|
|
POWER_DisablePD(kPDRUNCFG_PPD_FLEXSPI1_SRAM);
|
|
|
|
POWER_ApplyPD();
|
|
|
|
/* Setup clock frequency for FlexSPI1 */
|
|
|
|
CLOCK_AttachClk(kMAIN_CLK_to_FLEXSPI1_CLK);
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivFlexspi1Clk, 1);
|
|
|
|
/* Reset peripheral module */
|
|
|
|
RESET_PeripheralReset(kFLEXSPI1_RST_SHIFT_RSTn);
|
|
|
|
#endif
|
2023-04-04 16:00:25 -05:00
|
|
|
|
|
|
|
#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(lpadc0), nxp_lpc_lpadc, okay)
|
|
|
|
SYSCTL0->PDRUNCFG0_CLR = SYSCTL0_PDRUNCFG0_ADC_PD_MASK;
|
|
|
|
SYSCTL0->PDRUNCFG0_CLR = SYSCTL0_PDRUNCFG0_ADC_LP_MASK;
|
|
|
|
RESET_PeripheralReset(kADC0_RST_SHIFT_RSTn);
|
|
|
|
CLOCK_AttachClk(kFRO_DIV4_to_ADC_CLK);
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivAdcClk, 1);
|
|
|
|
#endif
|
|
|
|
|
2022-01-07 11:33:48 -06:00
|
|
|
/* Set SystemCoreClock variable. */
|
|
|
|
SystemCoreClock = CLOCK_INIT_CORE_CLOCK;
|
|
|
|
|
|
|
|
/* Set main clock to FRO as deep sleep clock by default. */
|
|
|
|
POWER_SetDeepSleepClock(kDeepSleepClk_Fro);
|
|
|
|
}
|
|
|
|
|
2023-01-09 13:24:13 -06:00
|
|
|
#if CONFIG_MIPI_DSI
|
|
|
|
void imxrt_pre_init_display_interface(void)
|
|
|
|
{
|
|
|
|
/* Assert MIPI DPHY reset. */
|
|
|
|
RESET_SetPeripheralReset(kMIPI_DSI_PHY_RST_SHIFT_RSTn);
|
|
|
|
POWER_DisablePD(kPDRUNCFG_APD_MIPIDSI_SRAM);
|
|
|
|
POWER_DisablePD(kPDRUNCFG_PPD_MIPIDSI_SRAM);
|
|
|
|
POWER_DisablePD(kPDRUNCFG_PD_MIPIDSI);
|
|
|
|
POWER_ApplyPD();
|
|
|
|
|
|
|
|
/* RxClkEsc max 60MHz, TxClkEsc 12 to 20MHz. */
|
|
|
|
CLOCK_AttachClk(kFRO_DIV1_to_MIPI_DPHYESC_CLK);
|
|
|
|
/* RxClkEsc = 192MHz / 4 = 48MHz. */
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivDphyEscRxClk, 4);
|
|
|
|
/* TxClkEsc = 192MHz / 4 / 3 = 16MHz. */
|
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivDphyEscTxClk, 3);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The DPHY bit clock must be fast enough to send out the pixels,
|
|
|
|
* it should be larger than:
|
|
|
|
*
|
|
|
|
* (Pixel clock * bit per output pixel) / number of MIPI data lane
|
|
|
|
*
|
|
|
|
* DPHY supports up to 895.1MHz bit clock.
|
2023-01-17 14:05:22 -06:00
|
|
|
* We set the divider of the PFD3 output of the SYSPLL, which has a
|
|
|
|
* fixed multiplied of 18, and use this output frequency for the DPHY.
|
2023-01-09 13:24:13 -06:00
|
|
|
*/
|
|
|
|
CLOCK_AttachClk(kAUX1_PLL_to_MIPI_DPHY_CLK);
|
|
|
|
CLOCK_InitSysPfd(kCLOCK_Pfd3,
|
2023-01-17 14:05:22 -06:00
|
|
|
((CLOCK_GetSysPllFreq() * 18ull) /
|
|
|
|
((unsigned long long)(DT_PROP(DT_NODELABEL(mipi_dsi), phy_clock)))));
|
2023-01-09 13:24:13 -06:00
|
|
|
CLOCK_SetClkDiv(kCLOCK_DivDphyClk, 1);
|
|
|
|
|
|
|
|
/* Clear DSI control reset (Note that DPHY reset is cleared later)*/
|
|
|
|
RESET_ClearPeripheralReset(kMIPI_DSI_CTRL_RST_SHIFT_RSTn);
|
|
|
|
}
|
|
|
|
|
|
|
|
void imxrt_post_init_display_interface(void)
|
|
|
|
{
|
|
|
|
/* Deassert MIPI DPHY reset. */
|
|
|
|
RESET_ClearPeripheralReset(kMIPI_DSI_PHY_RST_SHIFT_RSTn);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-01-07 11:33:48 -06:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @brief Perform basic hardware initialization
|
|
|
|
*
|
|
|
|
* Initialize the interrupt controller device drivers.
|
|
|
|
* Also initialize the timer device driver, if required.
|
|
|
|
*
|
|
|
|
* @return 0
|
|
|
|
*/
|
init: remove the need for a dummy device pointer in SYS_INIT functions
The init infrastructure, found in `init.h`, is currently used by:
- `SYS_INIT`: to call functions before `main`
- `DEVICE_*`: to initialize devices
They are all sorted according to an initialization level + a priority.
`SYS_INIT` calls are really orthogonal to devices, however, the required
function signature requires a `const struct device *dev` as a first
argument. The only reason for that is because the same init machinery is
used by devices, so we have something like:
```c
struct init_entry {
int (*init)(const struct device *dev);
/* only set by DEVICE_*, otherwise NULL */
const struct device *dev;
}
```
As a result, we end up with such weird/ugly pattern:
```c
static int my_init(const struct device *dev)
{
/* always NULL! add ARG_UNUSED to avoid compiler warning */
ARG_UNUSED(dev);
...
}
```
This is really a result of poor internals isolation. This patch proposes
a to make init entries more flexible so that they can accept sytem
initialization calls like this:
```c
static int my_init(void)
{
...
}
```
This is achieved using a union:
```c
union init_function {
/* for SYS_INIT, used when init_entry.dev == NULL */
int (*sys)(void);
/* for DEVICE*, used when init_entry.dev != NULL */
int (*dev)(const struct device *dev);
};
struct init_entry {
/* stores init function (either for SYS_INIT or DEVICE*)
union init_function init_fn;
/* stores device pointer for DEVICE*, NULL for SYS_INIT. Allows
* to know which union entry to call.
*/
const struct device *dev;
}
```
This solution **does not increase ROM usage**, and allows to offer clean
public APIs for both SYS_INIT and DEVICE*. Note that however, init
machinery keeps a coupling with devices.
**NOTE**: This is a breaking change! All `SYS_INIT` functions will need
to be converted to the new signature. See the script offered in the
following commit.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
init: convert SYS_INIT functions to the new signature
Conversion scripted using scripts/utils/migrate_sys_init.py.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
manifest: update projects for SYS_INIT changes
Update modules with updated SYS_INIT calls:
- hal_ti
- lvgl
- sof
- TraceRecorderSource
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
tests: devicetree: devices: adjust test
Adjust test according to the recently introduced SYS_INIT
infrastructure.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
tests: kernel: threads: adjust SYS_INIT call
Adjust to the new signature: int (*init_fn)(void);
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-10-19 09:33:44 +02:00
|
|
|
static int nxp_rt500_init(void)
|
2022-01-07 11:33:48 -06:00
|
|
|
{
|
|
|
|
|
|
|
|
/* old interrupt lock level */
|
|
|
|
unsigned int oldLevel;
|
|
|
|
|
|
|
|
/* disable interrupts */
|
|
|
|
oldLevel = irq_lock();
|
|
|
|
|
|
|
|
/* Initialize clocks with tool generated code */
|
|
|
|
clock_init();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* install default handler that simply resets the CPU if configured in
|
|
|
|
* the kernel, NOP otherwise
|
|
|
|
*/
|
|
|
|
NMI_INIT();
|
|
|
|
|
2022-11-30 16:08:08 -06:00
|
|
|
#ifndef CONFIG_IMXRT5XX_CODE_CACHE
|
2022-11-30 16:06:40 -06:00
|
|
|
CACHE64_DisableCache(CACHE64_CTRL0);
|
|
|
|
#endif
|
|
|
|
|
2022-01-07 11:33:48 -06:00
|
|
|
/* restore interrupt state */
|
|
|
|
irq_unlock(oldLevel);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SYS_INIT(nxp_rt500_init, PRE_KERNEL_1, 0);
|