1
1
/*
2
- * Copyright 2024 NXP
2
+ * Copyright 2024,2025 NXP
3
3
*
4
4
* SPDX-License-Identifier: Apache-2.0
5
5
*/
17
17
#include <zephyr/linker/sections.h>
18
18
#include <zephyr/cache.h>
19
19
#include <soc.h>
20
+ #include "fsl_power.h"
21
+ #include "fsl_clock.h"
20
22
21
23
void soc_early_init_hook (void )
22
24
{
@@ -35,3 +37,73 @@ void soc_reset_hook(void)
35
37
}
36
38
37
39
#endif /* CONFIG_SOC_RESET_HOOK */
40
+
41
+ #ifdef CONFIG_MIPI_DSI
42
+ /* Weak so board can override this function */
43
+ void __weak imxrt_pre_init_display_interface (void )
44
+ {
45
+ /* Assert MIPI control reset. */
46
+ RESET_SetPeripheralReset (kMIPI_DSI_CTRL_RST_SHIFT_RSTn );
47
+
48
+ /* Disable MIPI DSI power down. */
49
+ POWER_DisablePD (kPDRUNCFG_APD_MIPIDSI );
50
+ POWER_DisablePD (kPDRUNCFG_PPD_MIPIDSI );
51
+ POWER_DisablePD (kPDRUNCFG_PD_VDD2_MIPI );
52
+
53
+ /* Apply power down configuration. */
54
+ POWER_ApplyPD ();
55
+
56
+ /* Configure MIPY ESC clock. */
57
+ /* Use PLL PFD1 as clock source, 396m. */
58
+ CLOCK_AttachClk (kMAIN_PLL_PFD1_to_MIPI_DPHYESC_CLK );
59
+ /* RxClkEsc min 60MHz, TxClkEsc 12 to 20MHz. */
60
+ /* RxClkEsc = 396MHz / 6 = 66MHz. */
61
+ CLOCK_SetClkDiv (kCLOCK_DivDphyEscRxClk , 6 );
62
+ /* TxClkEsc = 396MHz / 6 / 4 = 16.5MHz. */
63
+ CLOCK_SetClkDiv (kCLOCK_DivDphyEscTxClk , 4 );
64
+
65
+ #ifdef CONFIG_MIPI_DBI
66
+ /* When using LCDIF, with 279.53MHz DBI source clock and 16bpp format, a 14 wr
67
+ * period requires a 279.53MHz / 14 * 16 = 319.46Mhz DPHY clk source. Considering
68
+ * the DCS packaging cost, the MIPI DPHY speed shall be ***SLIGHTLY*** larger
69
+ * than the DBI interface speed. DPHY uses AUDIO_PLL_PFD2 which is 532.48MHz as
70
+ * source, the frequency is 532.48 * 18 / 30 = 319.49MHz, which meets the
71
+ * requirement.
72
+ */
73
+ uint32_t mipiDsiDphyBitClkFreq_Hz =
74
+ DT_PROP (DT_NODELABEL (lcdif ), clock_frequency ) /
75
+ DT_PROP_OR (DT_NODELABEL (lcdif ), divider , 1 ) /
76
+ DT_PROP (DT_NODELABEL (lcdif ), wr_period ) * 16U ;
77
+ #else
78
+ /* The DPHY bit clock must be fast enough to send out the pixels, it should be
79
+ * larger than:
80
+ * (Pixel clock * bit per output pixel) / number of MIPI data lane
81
+ * DPHY uses AUDIO pll pfd2 as aource, and its max allowed clock frequency is
82
+ * 532.48 x 18 / 16 = 599.04MHz. The MIPI panel supports up to 850MHz bit clock.
83
+ */
84
+ uint32_t mipiDsiDphyBitClkFreq_Hz = DT_PROP (DT_NODELABEL (mipi_dsi ), phy_clock );
85
+ #endif
86
+ uint8_t clockDiv = (uint8_t )((uint64_t )CLOCK_GetAudioPllFreq () * 18U /
87
+ (uint64_t )mipiDsiDphyBitClkFreq_Hz );
88
+
89
+ CLOCK_InitAudioPfd (kCLOCK_Pfd2 , clockDiv );
90
+
91
+ CLOCK_AttachClk (kAUDIO_PLL_PFD2_to_MIPI_DSI_HOST_PHY );
92
+ CLOCK_SetClkDiv (kCLOCK_DivDphyClk , 1 );
93
+ }
94
+
95
+ void __weak imxrt_post_init_display_interface (void )
96
+ {
97
+ /* Clear MIPI control reset. */
98
+ RESET_ClearPeripheralReset (kMIPI_DSI_CTRL_RST_SHIFT_RSTn );
99
+ }
100
+
101
+ void __weak imxrt_deinit_display_interface (void )
102
+ {
103
+ /* Assert MIPI DSI reset */
104
+ RESET_SetPeripheralReset (kMIPI_DSI_CTRL_RST_SHIFT_RSTn );
105
+ /* Remove clock from DPHY */
106
+ CLOCK_AttachClk (kNONE_to_MIPI_DSI_HOST_PHY );
107
+ }
108
+
109
+ #endif
0 commit comments