• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 HPMicro
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef HPM_MIPI_DSI_DRV_H
9 #define HPM_MIPI_DSI_DRV_H
10 
11 /**
12  * @brief MIPI_DSI APIs
13  * @defgroup mipi_dsi_interface MIPI_DSI driver APIs
14  * @ingroup mipi_dsi_interfaces
15  * @{
16  */
17 
18 #include "hpm_common.h"
19 #include "hpm_soc.h"
20 #include "hpm_mipi_dsi_regs.h"
21 
22 
23 /* MIPI DSI Processor-to-Peripheral transaction types */
24 typedef enum mipi_dsi_tx_cmd {
25     MIPI_DSI_SHUTDOWN_PERIPHERAL = 0x22,
26     MIPI_DSI_TURN_ON_PERIPHERAL = 0x32,
27     MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM = 0x03,
28     MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM = 0x13,
29     MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM = 0x23,
30     MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM = 0x04,
31     MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM = 0x14,
32     MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM = 0x24,
33     MIPI_DSI_DCS_SHORT_WRITE = 0x05,
34     MIPI_DSI_DCS_SHORT_WRITE_PARAM = 0x15,
35     MIPI_DSI_DCS_READ = 0x06,
36     MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE = 0x37,
37     MIPI_DSI_GENERIC_LONG_WRITE = 0x29,
38     MIPI_DSI_DCS_LONG_WRITE	= 0x39
39 } mipi_dsi_tx_cmd_t;
40 
41 /* MIPI DCS commands */
42 typedef enum mipi_dcs_cmd {
43     MIPI_DCS_NOP = 0x00,
44     MIPI_DCS_SOFT_RESET = 0x01,
45     MIPI_DCS_GET_DISPLAY_ID = 0x04,
46     MIPI_DCS_GET_RED_CHANNEL = 0x06,
47     MIPI_DCS_GET_GREEN_CHANNEL = 0x07,
48     MIPI_DCS_GET_BLUE_CHANNEL = 0x08,
49     MIPI_DCS_GET_DISPLAY_STATUS = 0x09,
50     MIPI_DCS_GET_POWER_MODE = 0x0A,
51     MIPI_DCS_GET_ADDRESS_MODE = 0x0B,
52     MIPI_DCS_GET_PIXEL_FORMAT = 0x0C,
53     MIPI_DCS_GET_DISPLAY_MODE = 0x0D,
54     MIPI_DCS_GET_SIGNAL_MODE = 0x0E,
55     MIPI_DCS_GET_DIAGNOSTIC_RESULT = 0x0F,
56     MIPI_DCS_ENTER_SLEEP_MODE = 0x10,
57     MIPI_DCS_EXIT_SLEEP_MODE = 0x11,
58     MIPI_DCS_ENTER_PARTIAL_MODE = 0x12,
59     MIPI_DCS_ENTER_NORMAL_MODE = 0x13,
60     MIPI_DCS_EXIT_INVERT_MODE = 0x20,
61     MIPI_DCS_ENTER_INVERT_MODE = 0x21,
62     MIPI_DCS_SET_GAMMA_CURVE = 0x26,
63     MIPI_DCS_SET_DISPLAY_OFF = 0x28,
64     MIPI_DCS_SET_DISPLAY_ON = 0x29,
65     MIPI_DCS_SET_COLUMN_ADDRESS = 0x2A,
66     MIPI_DCS_SET_PAGE_ADDRESS = 0x2B,
67     MIPI_DCS_WRITE_MEMORY_START = 0x2C,
68     MIPI_DCS_WRITE_LUT = 0x2D,
69     MIPI_DCS_READ_MEMORY_START = 0x2E,
70     MIPI_DCS_SET_PARTIAL_AREA = 0x30,
71     MIPI_DCS_SET_SCROLL_AREA = 0x33,
72     MIPI_DCS_SET_TEAR_OFF = 0x34,
73     MIPI_DCS_SET_TEAR_ON = 0x35,
74     MIPI_DCS_SET_ADDRESS_MODE = 0x36,
75     MIPI_DCS_SET_SCROLL_START = 0x37,
76     MIPI_DCS_EXIT_IDLE_MODE = 0x38,
77     MIPI_DCS_ENTER_IDLE_MODE = 0x39,
78     MIPI_DCS_SET_PIXEL_FORMAT = 0x3A,
79     MIPI_DCS_WRITE_MEMORY_CONTINUE = 0x3C,
80     MIPI_DCS_READ_MEMORY_CONTINUE = 0x3E,
81     MIPI_DCS_SET_TEAR_SCANLINE = 0x44,
82     MIPI_DCS_GET_SCANLINE = 0x45,
83     MIPI_DCS_SET_DISPLAY_BRIGHTNESS = 0x51,		/* MIPI DCS 1.3 */
84     MIPI_DCS_GET_DISPLAY_BRIGHTNESS = 0x52,		/* MIPI DCS 1.3 */
85     MIPI_DCS_WRITE_CONTROL_DISPLAY = 0x53,		/* MIPI DCS 1.3 */
86     MIPI_DCS_GET_CONTROL_DISPLAY = 0x54,		/* MIPI DCS 1.3 */
87     MIPI_DCS_WRITE_POWER_SAVE = 0x55,		/* MIPI DCS 1.3 */
88     MIPI_DCS_GET_POWER_SAVE = 0x56,		/* MIPI DCS 1.3 */
89     MIPI_DCS_SET_CABC_MIN_BRIGHTNESS = 0x5E,	/* MIPI DCS 1.3 */
90     MIPI_DCS_GET_CABC_MIN_BRIGHTNESS = 0x5F,	/* MIPI DCS 1.3 */
91     MIPI_DCS_READ_DDB_START = 0xA1,
92     MIPI_DCS_READ_DDB_CONTINUE = 0xA8,
93 } mipi_dcs_cmd_t;
94 
95 typedef enum mipi_dsi_pixel_format {
96 	MIPI_DSI_FMT_RGB888,
97 	MIPI_DSI_FMT_RGB666,
98 	MIPI_DSI_FMT_RGB666_PACKED,
99 	MIPI_DSI_FMT_RGB565,
100 } mipi_dsi_pixel_format_t;
101 
102 typedef enum mipi_dsi_video_mode {
103     MIPI_DSI_VIDEO_MODE_SYNC_PULSE = 0x00,
104     MIPI_DSI_VIDEO_MODE_SYNC_EVENT = 0x01,
105 	MIPI_DSI_VIDEO_MODE_BURST = 0x02,
106 } mipi_dsi_video_mode_t;
107 
108 /**
109  * mipi_dsi_msg_t - read/write DSI buffer
110  * @channel: virtual channel id
111  * @type: payload data type
112  * @flags: flags controlling this message transmission
113  * @tx_len: length of @tx_buf
114  * @tx_buf: data to be written
115  * @rx_len: length of @rx_buf
116  * @rx_buf: data to be read, or NULL
117  */
118 typedef struct mipi_dsi_msg {
119     uint8_t channel;
120     uint8_t type;
121     uint16_t tx_len;
122     const void *tx_buf;
123     uint16_t rx_len;
124     void *rx_buf;
125 } mipi_dsi_msg_t;
126 
127 typedef struct mipi_video_para {
128     uint32_t pixel_clock_khz;
129     uint32_t hactive;		/*!< hor. active video */
130 	uint32_t hfront_porch;	/*!< hor. front porch */
131 	uint32_t hback_porch;	/*!< hor. back porch */
132 	uint32_t hsync_len;		/*!< hor. sync len */
133 
134 	uint32_t vactive;		/*!< ver. active video */
135 	uint32_t vfront_porch;	/*!< ver. front porch */
136 	uint32_t vback_porch;	/*!< ver. back porch */
137 	uint32_t vsync_len;		/*!< ver. sync len */
138 } mipi_video_para_t;
139 
140 typedef struct mipi_dsi_config {
141     uint32_t lane_mbps;
142     uint8_t channel;
143     uint8_t lanes;
144     bool disable_eotp;
145     mipi_dsi_pixel_format_t pixel_format;
146     mipi_video_para_t video_para;
147     mipi_dsi_video_mode_t video_mode;
148 } mipi_dsi_config_t;
149 
150 
151 #ifdef __cplusplus
152 extern "C" {
153 #endif
154 
155 /**
156  * @brief get MIPI_DSI default config on video mode
157  *
158  * @cfg: MIPI_DSI default config
159  */
160 void mipi_dsi_get_defconfig_on_video(mipi_dsi_config_t *cfg);
161 
162 /**
163  * @brief MIPI_DSI init
164  *
165  * @param ptr MIPI_DSI base address
166  * @param cfg config of MIPI_DSI
167  */
168 void mipi_dsi_init(MIPI_DSI_Type *ptr, mipi_dsi_config_t *cfg);
169 
170 /**
171  * @brief MIPI_DSI phy interface power on
172  *
173  * @param ptr MIPI_DSI base address
174  */
175 void mipi_dsi_phy_poweron(MIPI_DSI_Type *ptr);
176 
177 /**
178  * @brief MIPI_DSI phy interface power down
179  *
180  * @param ptr MIPI_DSI base address
181  */
182 void mipi_dsi_phy_powerdown(MIPI_DSI_Type *ptr);
183 
184 /**
185  * @brief MIPI_DSI hs transfer start
186  *
187  * @param ptr MIPI_DSI base address
188  */
189 void mipi_dsi_video_mode_hs_transfer_enable(MIPI_DSI_Type *ptr);
190 
191 /**
192  * @brief MIPI_DSI hs transfer stop
193  *
194  * @param ptr MIPI_DSI base address
195  */
196 void mipi_dsi_video_mode_hs_transfer_disable(MIPI_DSI_Type *ptr);
197 
198 /**
199  * @brief transmit data using mipi dsi message in low power mode
200  *
201  * @param ptr MIPI_DSI base address
202  * @param msg MPI_DSI message
203  *
204  * @return The number of bytes transmitted on success or a negative error code
205  * on failure.
206  */
207 int mipi_dsi_lp_cmd_transfer(MIPI_DSI_Type *ptr, const mipi_dsi_msg_t *msg);
208 
209 /**
210  * @brief specify the maximum size of the
211  *	the payload in a long packet transmitted from the peripheral back to the
212  *	host processor
213  *
214  * @ptr: MIPI_DSI base address
215  * @channel: virtual channel
216  * @value: the maximum size of the payload
217  *
218  * @return: true on success or false on failure.
219  */
220 int mipi_dsi_set_maximum_return_packet_size(MIPI_DSI_Type *ptr, uint8_t channel, uint16_t value);
221 
222 /**
223  * @brief transmit data using a generic write packet
224  *
225  * @ptr: MIPI_DSI base address
226  * @channel: virtual channel
227  * @payload: buffer containing the payload
228  * @size: size of payload buffer
229  *
230  * This function will automatically choose the right data type depending on
231  * the payload length.
232  *
233  * @return: The number of bytes transmitted on success or a negative error code
234  * on failure.
235  */
236 int mipi_dsi_generic_write(MIPI_DSI_Type *ptr, uint8_t channel, const void *payload,
237 			       uint16_t size);
238 
239 /**
240  * @brief receive data using a generic read packet
241  *
242  * @ptr: MIPI_DSI base address
243  * @channel: virtual channel
244  * @params: buffer containing the request parameters
245  * @num_params: number of request parameters
246  * @data: buffer in which to return the received data
247  * @size: size of receive buffer
248  *
249  * This function will automatically choose the right data type depending on
250  * the number of parameters passed in.
251  *
252  * @return: The number of bytes successfully read or a negative error code on
253  * failure.
254  */
255 int mipi_dsi_generic_read(MIPI_DSI_Type *ptr, uint8_t channel, const void *params,
256 			      uint16_t num_params, void *data, uint16_t size);
257 
258 /**
259  * @brief transmit a DCS command with payload
260  *
261  * @ptr: MIPI_DSI base address
262  * @channel: virtual channel
263  * @data: buffer containing data to be transmitted
264  * @len: size of transmission buffer
265  *
266  * This function will automatically choose the right data type depending on
267  * the command payload length.
268  *
269  * @return: The number of bytes successfully transmitted or a negative error
270  * code on failure.
271  */
272 int mipi_dsi_dcs_write_buffer(MIPI_DSI_Type *ptr, uint8_t channel,
273 				  const void *data, uint16_t len);
274 
275 /**
276  * @brief send DCS write command
277  *
278  * @ptr: MIPI_DSI base address
279  * @channel: virtual channel
280  * @cmd: DCS command
281  * @data: buffer containing the command payload
282  * @len: command payload length
283  *
284  * This function will automatically choose the right data type depending on
285  * the command payload length.
286  *
287  * @return: The number of bytes successfully transmitted or a negative error
288  * code on failure.
289  */
290 int mipi_dsi_dcs_write(MIPI_DSI_Type *ptr, uint8_t channel, uint8_t cmd,
291 			   const void *data, uint16_t len);
292 
293 /**
294  * @brief send DCS read request command
295  *
296  * @ptr: MIPI_DSI base address
297  * @channel: virtual channel
298  * @cmd: DCS command
299  * @data: buffer in which to receive data
300  * @len: size of receive buffer
301  *
302  * @return: The number of bytes read or a negative error code on failure.
303  */
304 int mipi_dsi_dcs_read(MIPI_DSI_Type *ptr, uint8_t channel, uint8_t cmd, void *data, uint16_t len);
305 
306 
307 #ifdef __cplusplus
308 }
309 #endif
310 
311 /**
312  * @}
313  */
314 #endif /* HPM_MIPI_DSI_DRV_H */
315