1 /*
2  * Copyright 2019-2023 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #ifndef FSL_SMARTDMA_RT500_H_
9 #define FSL_SMARTDMA_RT500_H_
10 
11 #include "fsl_common.h"
12 
13 /*!
14  * @addtogroup smartdma_rt500 RT500 SMARTDMA Firmware
15  * @ingroup smartdma
16  * @{
17  */
18 
19 /*******************************************************************************
20  * Definitions
21  ******************************************************************************/
22 #define SMARTDMA_DISPLAY_MIPI_AND_FLEXIO 0
23 #define SMARTDMA_DISPLAY_MIPI_ONLY       1
24 #define SMARTDMA_DISPLAY_FLEXIO_ONLY     2
25 
26 /* Select firmware for MIPI and FLEXIO by default. */
27 #ifndef SMARTDMA_DISPLAY_FIRMWARE_SELECT
28 #define SMARTDMA_DISPLAY_FIRMWARE_SELECT SMARTDMA_DISPLAY_MIPI_AND_FLEXIO
29 #endif
30 
31 /*! @brief The firmware used for display. */
32 extern const uint8_t s_smartdmaDisplayFirmware[];
33 
34 /*! @brief The s_smartdmaDisplayFirmware firmware memory address. */
35 #define SMARTDMA_DISPLAY_MEM_ADDR 0x24100000U
36 
37 /*! @brief Size of s_smartdmaDisplayFirmware */
38 #define SMARTDMA_DISPLAY_FIRMWARE_SIZE (s_smartdmaDisplayFirmwareSize)
39 
40 /*! @brief Size of s_smartdmaDisplayFirmware */
41 extern const uint32_t s_smartdmaDisplayFirmwareSize;
42 
43 #if (SMARTDMA_DISPLAY_FIRMWARE_SELECT == SMARTDMA_DISPLAY_MIPI_AND_FLEXIO)
44 /*!
45  * @brief The API index when using s_smartdmaDisplayFirmware.
46  */
47 enum _smartdma_display_api
48 {
49     kSMARTDMA_FlexIO_DMA_Endian_Swap = 0U,
50     kSMARTDMA_FlexIO_DMA_Reverse32,
51     kSMARTDMA_FlexIO_DMA,
52     kSMARTDMA_FlexIO_DMA_Reverse,              /*!< Send data to FlexIO with reverse order. */
53     kSMARTDMA_RGB565To888,                     /*!< Convert RGB565 to RGB888 and save to output memory, use parameter
54                                                   smartdma_rgb565_rgb888_param_t. */
55     kSMARTDMA_FlexIO_DMA_RGB565To888,          /*!< Convert RGB565 to RGB888 and send to FlexIO, use parameter
56                                                   smartdma_flexio_mculcd_param_t. */
57     kSMARTDMA_FlexIO_DMA_ARGB2RGB,             /*!< Convert ARGB to RGB and send to FlexIO, use parameter
58                                                   smartdma_flexio_mculcd_param_t. */
59     kSMARTDMA_FlexIO_DMA_ARGB2RGB_Endian_Swap, /*!< Convert ARGB to RGB, then swap endian, and send to
60                                                  FlexIO, use         parameter smartdma_flexio_mculcd_param_t. */
61     kSMARTDMA_FlexIO_DMA_ARGB2RGB_Endian_Swap_Reverse, /*!< Convert ARGB to RGB, then swap endian and reverse, and send
62                                                  to FlexIO, use parameter smartdma_flexio_mculcd_param_t. */
63     kSMARTDMA_MIPI_RGB565_DMA,               /*!< Send RGB565 data to MIPI DSI, use parameter smartdma_dsi_param_t. */
64     kSMARTDMA_MIPI_RGB565_DMA2D,             /*!< Send RGB565 data to MIPI DSI, use parameter smartdma_dsi_2d_param_t.
65                                               */
66     kSMARTDMA_MIPI_RGB888_DMA,               /*!< Send RGB888 data to MIPI DSI, use parameter smartdma_dsi_param_t. */
67     kSMARTDMA_MIPI_RGB888_DMA2D,             /*!< Send RGB565 data to MIPI DSI, use parameter smartdma_dsi_2d_param_t.
68                                               */
69     kSMARTDMA_MIPI_XRGB2RGB_DMA,             /*!< Send XRGB8888 data to MIPI DSI, use parameter smartdma_dsi_param_t */
70     kSMARTDMA_MIPI_XRGB2RGB_DMA2D,           /*!< Send XRGB8888 data to MIPI DSI, use parameter
71                                                 smartdma_dsi_2d_param_t. */
72     kSMARTDMA_MIPI_RGB565_R180_DMA,          /*!< Send RGB565 data to MIPI DSI, Rotate 180, use parameter
73                                               * smartdma_dsi_param_t.
74                                               */
75     kSMARTDMA_MIPI_RGB888_R180_DMA,          /*!< Send RGB888 data to MIPI DSI, Rotate 180, use parameter
76                                               * smartdma_dsi_param_t.
77                                               */
78     kSMARTDMA_MIPI_XRGB2RGB_R180_DMA,        /*!< Send XRGB8888 data to MIPI DSI, Rotate 180, use parameter
79                                                 smartdma_dsi_param_t */
80     kSMARTDMA_MIPI_RGB5652RGB888_DMA,        /*!< Send RGB565 data to MIPI DSI, use parameter smartdma_dsi_param_t.
81                                               */
82     kSMARTDMA_MIPI_RGB888_CHECKER_BOARD_DMA, /*!< Send RGB888 data to MIPI DSI with checker board pattern,
83                                                 use parameter smartdma_dsi_checkerboard_param_t. */
84     kSMARTDMA_MIPI_Enter_ULPS, /*!< Set MIPI-DSI to enter ultra low power state. */
85     kSMARTDMA_MIPI_Exit_ULPS, /*!< Set MIPI-DSI to exit ultra low power state. */
86     kSMARTDMA_FlexIO_DMA_ONELANE,            /*!< FlexIO DMA for one SHIFTBUF, Write Data to SHIFTBUF[OFFSET] */
87     kSMARTDMA_FlexIO_FIFO2RAM, /*!< Read data from FlexIO FIFO to ram space. */
88 };
89 
90 #elif (SMARTDMA_DISPLAY_FIRMWARE_SELECT == SMARTDMA_DISPLAY_MIPI_ONLY)
91 
92 /*!
93  * @brief The API index when using s_smartdmaDisplayFirmware.
94  */
95 enum _smartdma_display_api
96 {
97     kSMARTDMA_MIPI_RGB565_DMA,               /*!< Send RGB565 data to MIPI DSI, use parameter smartdma_dsi_param_t. */
98     kSMARTDMA_MIPI_RGB565_DMA2D,             /*!< Send RGB565 data to MIPI DSI, use parameter smartdma_dsi_2d_param_t.
99                                               */
100     kSMARTDMA_MIPI_RGB888_DMA,               /*!< Send RGB888 data to MIPI DSI, use parameter smartdma_dsi_param_t. */
101     kSMARTDMA_MIPI_RGB888_DMA2D,             /*!< Send RGB565 data to MIPI DSI, use parameter smartdma_dsi_2d_param_t.
102                                               */
103     kSMARTDMA_MIPI_XRGB2RGB_DMA,             /*!< Send XRGB8888 data to MIPI DSI, use parameter smartdma_dsi_param_t */
104     kSMARTDMA_MIPI_XRGB2RGB_DMA2D,           /*!< Send XRGB8888 data to MIPI DSI, use parameter
105                                                 smartdma_dsi_2d_param_t. */
106     kSMARTDMA_MIPI_RGB565_R180_DMA,          /*!< Send RGB565 data to MIPI DSI, Rotate 180, use parameter
107                                               * smartdma_dsi_param_t.
108                                               */
109     kSMARTDMA_MIPI_RGB888_R180_DMA,          /*!< Send RGB888 data to MIPI DSI, Rotate 180, use parameter
110                                               * smartdma_dsi_param_t.
111                                               */
112     kSMARTDMA_MIPI_XRGB2RGB_R180_DMA,        /*!< Send XRGB8888 data to MIPI DSI, Rotate 180, use parameter
113                                                 smartdma_dsi_param_t */
114     kSMARTDMA_MIPI_RGB5652RGB888_DMA,        /*!< Send RGB565 data to MIPI DSI, use parameter smartdma_dsi_param_t.
115                                               */
116     kSMARTDMA_MIPI_RGB888_CHECKER_BOARD_DMA, /*!< Send RGB888 data to MIPI DSI with checker board pattern,
117                                                 use parameter smartdma_dsi_checkerboard_param_t. */
118     kSMARTDMA_MIPI_Enter_ULPS, /*!< Set MIPI-DSI to enter ultra low power state. */
119     kSMARTDMA_MIPI_Exit_ULPS, /*!< Set MIPI-DSI to exit ultra low power state. */
120 };
121 
122 #elif (SMARTDMA_DISPLAY_FIRMWARE_SELECT == SMARTDMA_DISPLAY_FLEXIO_ONLY)
123 
124 /*!
125  * @brief The API index when using s_smartdmaDisplayFirmware.
126  */
127 enum _smartdma_display_api
128 {
129     kSMARTDMA_FlexIO_DMA_Endian_Swap = 0U,
130     kSMARTDMA_FlexIO_DMA_Reverse32,
131     kSMARTDMA_FlexIO_DMA,
132     kSMARTDMA_FlexIO_DMA_Reverse,              /*!< Send data to FlexIO with reverse order. */
133     kSMARTDMA_FlexIO_DMA_RGB565To888,          /*!< Convert RGB565 to RGB888 and send to FlexIO, use parameter
134                                                   smartdma_flexio_mculcd_param_t. */
135     kSMARTDMA_FlexIO_DMA_ARGB2RGB,             /*!< Convert ARGB to RGB and send to FlexIO, use parameter
136                                                   smartdma_flexio_mculcd_param_t. */
137     kSMARTDMA_FlexIO_DMA_ARGB2RGB_Endian_Swap, /*!< Convert ARGB to RGB, then swap endian, and send to FlexIO, use
138                                                  parameter smartdma_flexio_mculcd_param_t. */
139     kSMARTDMA_FlexIO_DMA_ARGB2RGB_Endian_Swap_Reverse, /*!< Convert ARGB to RGB, then swap endian and reverse, and send
140                                                  to FlexIO, use parameter smartdma_flexio_mculcd_param_t. */
141     kSMARTDMA_FlexIO_DMA_ONELANE, /*!< FlexIO DMA for one SHIFTBUF, Write Data to SHIFTBUF[OFFSET] */
142     kSMARTDMA_FlexIO_FIFO2RAM, /*!< Read data from FlexIO FIFO to ram space. */
143 };
144 #endif
145 
146 /*!
147  * @brief Parameter for FlexIO MCULCD except kSMARTDMA_FlexIO_DMA_ONELANE
148  */
149 typedef struct _smartdma_flexio_mculcd_param
150 {
151     uint32_t *p_buffer;
152     uint32_t buffersize;
153     uint32_t *smartdma_stack;
154 } smartdma_flexio_mculcd_param_t;
155 
156 /*!
157  * @brief Parameter for kSMARTDMA_FlexIO_DMA_ONELANE
158  */
159 typedef struct _smartdma_flexio_onelane_mculcd_param
160 {
161     uint32_t *p_buffer;
162     uint32_t buffersize;
163     uint32_t offset;
164     uint32_t *smartdma_stack;
165 } smartdma_flexio_onelane_mculcd_param_t;
166 
167 /*!
168  * @brief Parameter for MIPI DSI
169  */
170 typedef struct _smartdma_dsi_param
171 {
172     /*! Pointer to the buffer to send. */
173     const uint8_t *p_buffer;
174     /*! Buffer size in byte. */
175     uint32_t buffersize;
176     /*! Stack used by SMARTDMA. */
177     uint32_t *smartdma_stack;
178     /*!
179      * If set to 1, the pixels are filled to MIPI DSI FIFO directly.
180      * If set to 0, the pixel bytes are swapped then filled to
181      * MIPI DSI FIFO. For example, when set to 0 and frame buffer pixel
182      * format is RGB565:
183      * LSB                                           MSB
184      * B0 B1 B2 B3 B4 G0 G1 G2 | G3 G4 G5 R0 R1 R2 R3 R4
185      * Then the pixel filled to DSI FIFO is:
186      * LSB                                           MSB
187      * G3 G4 G5 R0 R1 R2 R3 R4 | B0 B1 B2 B3 B4 G0 G1 G2
188      */
189     uint32_t disablePixelByteSwap;
190 } smartdma_dsi_param_t;
191 
192 /*!
193  * @brief Parameter for kSMARTDMA_MIPI_RGB565_DMA2D, kSMARTDMA_MIPI_RGB888_DMA2D
194  * and kSMARTDMA_MIPI_XRGB2RGB_DMA2D.
195  */
196 typedef struct _smartdma_dsi_2d_param
197 {
198     /*! Pointer to the buffer to send. */
199     const uint8_t *p_buffer;
200     /*! SRC data transfer in a minor loop */
201     uint32_t minorLoop;
202     /*! SRC data offset added after a minor loop */
203     uint32_t minorLoopOffset;
204     /*! SRC data transfer in a major loop */
205     uint32_t majorLoop;
206     /*! Stack used by SMARTDMA. */
207     uint32_t *smartdma_stack;
208     /*!
209      * If set to 1, the pixels are filled to MIPI DSI FIFO directly.
210      * If set to 0, the pixel bytes are swapped then filled to
211      * MIPI DSI FIFO. For example, when set to 0 and frame buffer pixel
212      * format is RGB565:
213      * LSB                                           MSB
214      * B0 B1 B2 B3 B4 G0 G1 G2 | G3 G4 G5 R0 R1 R2 R3 R4
215      * Then the pixel filled to DSI FIFO is:
216      * LSB                                           MSB
217      * G3 G4 G5 R0 R1 R2 R3 R4 | B0 B1 B2 B3 B4 G0 G1 G2
218      */
219     uint32_t disablePixelByteSwap;
220 } smartdma_dsi_2d_param_t;
221 
222 /*!
223  * @brief Parameter for kSMARTDMA_MIPI_RGB888_CHECKER_BOARD_DMA
224  */
225 typedef struct _smartdma_dsi_checkerboard_param
226 {
227     /*! Pointer to the buffer to send, pixel format is ARGB8888. */
228     const uint8_t *p_buffer;
229     uint32_t height; /*! Height resolution in pixel. */
230     uint32_t width;  /*! Width resolution in pixel. */
231     /*! Cube block type.
232      * cbType=1 : 1/2 pixel mask cases
233      * cbType=2 : 1/4 pixel mask cases
234      */
235     uint32_t cbType;
236     /*! which pixel is turned off in each type
237      *  cbType=2: indexOff= 1,2,3,4
238      *  cbType=1: indexOff= 0,1
239      */
240     uint32_t indexOff;
241     /*! Stack used by SMARTDMA. */
242     uint32_t *smartdma_stack;
243     /*!
244      * If set to 1, the pixels are filled to MIPI DSI FIFO directly.
245      * If set to 0, the pixel bytes are swapped then filled to
246      * MIPI DSI FIFO. For example, when set to 0 and frame buffer pixel
247      * for example
248      * format is RGB888:
249      * LSB                                           MSB
250      * B0 B1 B2 B3 B4 B5 B6 B7 | G0 G1 G2 G3 G4 G5 G6 G7 | R0 R1 R2 R3 R4 R5 R6 R7
251      * Then the pixel filled to DSI FIFO is:
252      * LSB                                           MSB
253      * R0 R1 R2 R3 R4 R5 R6 R7 | G0 G1 G2 G3 G4 G5 G6 G7 | B0 B1 B2 B3 B4 B5 B6 B7
254      */
255     uint32_t disablePixelByteSwap;
256 } smartdma_dsi_checkerboard_param_t;
257 
258 /*!
259  * @brief Parameter for RGB565To888
260  */
261 typedef struct _smartdma_rgb565_rgb888_param
262 {
263     uint32_t *inBuf;
264     uint32_t *outBuf;
265     uint32_t buffersize;
266     uint32_t *smartdma_stack;
267 } smartdma_rgb565_rgb888_param_t;
268 
269 /*!
270  * @brief Parameter for all supported APIs.
271  */
272 typedef union
273 {
274     /*! Parameter for flexio MCULCD. */
275     smartdma_flexio_mculcd_param_t flexioMcuLcdParam;
276     /*! Parameter for flexio MCULCD with one shift buffer. */
277     smartdma_flexio_onelane_mculcd_param_t flexioOneLineMcuLcdParam;
278     /*! Parameter for MIPI DSI functions. */
279     smartdma_dsi_param_t dsiParam;
280     /*! Parameter for MIPI DSI 2D functions. */
281     smartdma_dsi_2d_param_t dsi2DParam;
282     /*! Parameter for MIPI DSI checker board functions. */
283     smartdma_dsi_checkerboard_param_t dsiCheckerBoardParam;
284     /*! Parameter for RGB565_RGB888 convertion. */
285     smartdma_rgb565_rgb888_param_t rgb565_rgb888Param;
286 } smartdma_param_t;
287 
288 typedef struct
289 {
290     uint8_t RESERVED_0[32];
291     __IO uint32_t BOOTADR;    /* 0x20 */
292     __IO uint32_t CTRL;       /* 0x24 */
293     __I uint32_t PC;          /* 0x28 */
294     __I uint32_t SP;          /* 0x2C */
295     __IO uint32_t BREAK_ADDR; /* 0x30 */
296     __IO uint32_t BREAK_VECT; /* 0x34 */
297     __IO uint32_t EMER_VECT;  /* 0x38 */
298     __IO uint32_t EMER_SEL;   /* 0x3C */
299     __IO uint32_t ARM2EZH;    /* 0x40 */
300     __IO uint32_t EZH2ARM;    /* 0x44 */
301     __IO uint32_t PENDTRAP;   /* 0x48 */
302 } SMARTDMA_Type;
303 
304 #define SMARTDMA_BASE 0x40027000
305 #define SMARTDMA      ((volatile SMARTDMA_Type *)SMARTDMA_BASE)
306 
307 /*******************************************************************************
308  * APIs
309  ******************************************************************************/
310 
311 #if defined(__cplusplus)
312 extern "C" {
313 #endif /* __cplusplus */
314 
315 #if defined(__cplusplus)
316 }
317 #endif
318 
319 /*! @} */
320 
321 #endif /* FSL_SMARTDMA_RT500_H_ */
322