Skip to content

Commit 676278c

Browse files
danieldegrassecarlescufi
authored andcommitted
soc: arm: nxp_imx: r5xx: add clock initialization for MIPI and LCDIF
Add clock initialization for MIPI and LCIDF to NXP RT5xx SOC. Note that clock divider properties are used by both initialization routines, as the required clock divider will vary depending on attached display. Signed-off-by: Daniel DeGrasse <[email protected]>
1 parent 5364c11 commit 676278c

File tree

2 files changed

+79
-2
lines changed

2 files changed

+79
-2
lines changed

soc/arm/nxp_imx/rt5xx/soc.c

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, NXP
2+
* Copyright 2022-2023, NXP
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -303,6 +303,33 @@ static void clock_init(void)
303303
#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(pmic_i2c), nxp_lpc_i2c, okay)
304304
CLOCK_AttachClk(kFRO_DIV4_to_FLEXCOMM15);
305305
#endif
306+
#if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(lcdif), nxp_dcnano_lcdif, okay) && CONFIG_DISPLAY
307+
POWER_DisablePD(kPDRUNCFG_APD_DCNANO_SRAM);
308+
POWER_DisablePD(kPDRUNCFG_PPD_DCNANO_SRAM);
309+
POWER_ApplyPD();
310+
311+
CLOCK_AttachClk(kAUX0_PLL_to_DCPIXEL_CLK);
312+
/* Note- pixel clock follows formula
313+
* (height + VSW + VFP + VBP) * (width + HSW + HFP + HBP) * frame rate.
314+
* this means the clock divider will vary depending on
315+
* the attached display.
316+
*/
317+
CLOCK_SetClkDiv(kCLOCK_DivDcPixelClk,
318+
DT_PROP(DT_NODELABEL(lcdif), clk_div));
319+
320+
CLOCK_EnableClock(kCLOCK_DisplayCtrl);
321+
RESET_ClearPeripheralReset(kDISP_CTRL_RST_SHIFT_RSTn);
322+
323+
CLOCK_EnableClock(kCLOCK_AxiSwitch);
324+
RESET_ClearPeripheralReset(kAXI_SWITCH_RST_SHIFT_RSTn);
325+
#if defined(CONFIG_MEMC) && DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(flexspi2), \
326+
nxp_imx_flexspi, okay)
327+
/* Enable write-through for FlexSPI1 space */
328+
CACHE64_POLSEL0->REG1_TOP = 0x27FFFC00U;
329+
CACHE64_POLSEL0->POLSEL = 0x11U;
330+
#endif
331+
#endif
332+
306333
/* Switch CLKOUT to FRO_DIV2 */
307334
CLOCK_AttachClk(kFRO_DIV2_to_CLKOUT);
308335

@@ -363,6 +390,49 @@ static void clock_init(void)
363390
POWER_SetDeepSleepClock(kDeepSleepClk_Fro);
364391
}
365392

393+
#if CONFIG_MIPI_DSI
394+
void imxrt_pre_init_display_interface(void)
395+
{
396+
/* Assert MIPI DPHY reset. */
397+
RESET_SetPeripheralReset(kMIPI_DSI_PHY_RST_SHIFT_RSTn);
398+
POWER_DisablePD(kPDRUNCFG_APD_MIPIDSI_SRAM);
399+
POWER_DisablePD(kPDRUNCFG_PPD_MIPIDSI_SRAM);
400+
POWER_DisablePD(kPDRUNCFG_PD_MIPIDSI);
401+
POWER_ApplyPD();
402+
403+
/* RxClkEsc max 60MHz, TxClkEsc 12 to 20MHz. */
404+
CLOCK_AttachClk(kFRO_DIV1_to_MIPI_DPHYESC_CLK);
405+
/* RxClkEsc = 192MHz / 4 = 48MHz. */
406+
CLOCK_SetClkDiv(kCLOCK_DivDphyEscRxClk, 4);
407+
/* TxClkEsc = 192MHz / 4 / 3 = 16MHz. */
408+
CLOCK_SetClkDiv(kCLOCK_DivDphyEscTxClk, 3);
409+
410+
/*
411+
* The DPHY bit clock must be fast enough to send out the pixels,
412+
* it should be larger than:
413+
*
414+
* (Pixel clock * bit per output pixel) / number of MIPI data lane
415+
*
416+
* DPHY supports up to 895.1MHz bit clock.
417+
* Note: AUX1 PLL clock is system pll clock * 18 / pfd.
418+
* system pll clock is configured at 528MHz by default.
419+
*/
420+
CLOCK_AttachClk(kAUX1_PLL_to_MIPI_DPHY_CLK);
421+
CLOCK_InitSysPfd(kCLOCK_Pfd3,
422+
DT_PROP(DT_NODELABEL(mipi_dsi), dphy_clk_div));
423+
CLOCK_SetClkDiv(kCLOCK_DivDphyClk, 1);
424+
425+
/* Clear DSI control reset (Note that DPHY reset is cleared later)*/
426+
RESET_ClearPeripheralReset(kMIPI_DSI_CTRL_RST_SHIFT_RSTn);
427+
}
428+
429+
void imxrt_post_init_display_interface(void)
430+
{
431+
/* Deassert MIPI DPHY reset. */
432+
RESET_ClearPeripheralReset(kMIPI_DSI_PHY_RST_SHIFT_RSTn);
433+
}
434+
#endif
435+
366436
/**
367437
*
368438
* @brief Perform basic hardware initialization

soc/arm/nxp_imx/rt5xx/soc.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, NXP
2+
* Copyright 2022-2023, NXP
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -75,6 +75,13 @@
7575
/* Workaround to handle macro variation in the SDK */
7676
#ifndef INPUTMUX_PINTSEL_COUNT
7777
#define INPUTMUX_PINTSEL_COUNT INPUTMUX_PINT_SEL_COUNT
78+
79+
#if CONFIG_MIPI_DSI
80+
void imxrt_pre_init_display_interface(void);
81+
82+
void imxrt_post_init_display_interface(void);
83+
#endif
84+
7885
#endif
7986

8087
#endif /* _SOC__H_ */

0 commit comments

Comments
 (0)