1 /* SPDX-License-Identifier: GPL-2.0 */
5 * Copyright (C) 2012-2013, Samsung Electronics, Co., Ltd.
6 * Copyright (C) 2018 STMicroelectronics - All Rights Reserved
7 * Author(s): Andrzej Hajda <a.hajda@samsung.com>
8 * Yannick Fertre <yannick.fertre@st.com>
9 * Philippe Cornu <philippe.cornu@st.com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
18 #include <mipi_display.h>
21 struct mipi_dsi_device;
23 /* request ACK from peripheral */
24 #define MIPI_DSI_MSG_REQ_ACK BIT(0)
25 /* use Low Power Mode to transmit message */
26 #define MIPI_DSI_MSG_USE_LPM BIT(1)
29 * struct mipi_dsi_msg - read/write DSI buffer
30 * @channel: virtual channel id
31 * @type: payload data type
32 * @flags: flags controlling this message transmission
33 * @tx_len: length of @tx_buf
34 * @tx_buf: data to be written
35 * @rx_len: length of @rx_buf
36 * @rx_buf: data to be read, or NULL
50 bool mipi_dsi_packet_format_is_short(u8 type);
51 bool mipi_dsi_packet_format_is_long(u8 type);
54 * struct mipi_dsi_packet - represents a MIPI DSI packet in protocol format
55 * @size: size (in bytes) of the packet
56 * @header: the four bytes that make up the header (Data ID, Word Count or
57 * Packet Data, and ECC)
58 * @payload_length: number of bytes in the payload
59 * @payload: a pointer to a buffer containing the payload, if any
61 struct mipi_dsi_packet {
64 size_t payload_length;
68 int mipi_dsi_create_packet(struct mipi_dsi_packet *packet,
69 const struct mipi_dsi_msg *msg);
72 * struct mipi_dsi_host_ops - DSI bus operations
73 * @attach: attach DSI device to DSI host
74 * @detach: detach DSI device from DSI host
75 * @transfer: transmit a DSI packet
77 * DSI packets transmitted by .transfer() are passed in as mipi_dsi_msg
78 * structures. This structure contains information about the type of packet
79 * being transmitted as well as the transmit and receive buffers. When an
80 * error is encountered during transmission, this function will return a
81 * negative error code. On success it shall return the number of bytes
82 * transmitted for write packets or the number of bytes received for read
85 * Note that typically DSI packet transmission is atomic, so the .transfer()
86 * function will seldomly return anything other than the number of bytes
87 * contained in the transmit buffer on success.
89 struct mipi_dsi_host_ops {
90 int (*attach)(struct mipi_dsi_host *host,
91 struct mipi_dsi_device *dsi);
92 int (*detach)(struct mipi_dsi_host *host,
93 struct mipi_dsi_device *dsi);
94 ssize_t (*transfer)(struct mipi_dsi_host *host,
95 const struct mipi_dsi_msg *msg);
99 * struct mipi_dsi_phy_ops - DSI host physical operations
100 * @init: initialized host physical part
101 * @get_lane_mbps: get lane bitrate per lane (mbps)
102 * @post_set_mode: operation that should after set mode
104 struct mipi_dsi_phy_ops {
105 int (*init)(void *priv_data);
106 int (*get_lane_mbps)(void *priv_data, struct display_timing *timings,
107 u32 lanes, u32 format, unsigned int *lane_mbps);
108 void (*post_set_mode)(void *priv_data, unsigned long mode_flags);
112 * struct mipi_dsi_host - DSI host device
113 * @dev: driver model device node for this DSI host
114 * @ops: DSI host operations
115 * @list: list management
117 struct mipi_dsi_host {
119 const struct mipi_dsi_host_ops *ops;
120 struct list_head list;
126 #define MIPI_DSI_MODE_VIDEO BIT(0)
127 /* video burst mode */
128 #define MIPI_DSI_MODE_VIDEO_BURST BIT(1)
129 /* video pulse mode */
130 #define MIPI_DSI_MODE_VIDEO_SYNC_PULSE BIT(2)
131 /* enable auto vertical count mode */
132 #define MIPI_DSI_MODE_VIDEO_AUTO_VERT BIT(3)
133 /* enable hsync-end packets in vsync-pulse and v-porch area */
134 #define MIPI_DSI_MODE_VIDEO_HSE BIT(4)
135 /* disable hfront-porch area */
136 #define MIPI_DSI_MODE_VIDEO_HFP BIT(5)
137 /* disable hback-porch area */
138 #define MIPI_DSI_MODE_VIDEO_HBP BIT(6)
139 /* disable hsync-active area */
140 #define MIPI_DSI_MODE_VIDEO_HSA BIT(7)
141 /* flush display FIFO on vsync pulse */
142 #define MIPI_DSI_MODE_VSYNC_FLUSH BIT(8)
143 /* disable EoT packets in HS mode */
144 #define MIPI_DSI_MODE_EOT_PACKET BIT(9)
145 /* device supports non-continuous clock behavior (DSI spec 5.6.1) */
146 #define MIPI_DSI_CLOCK_NON_CONTINUOUS BIT(10)
147 /* transmit data in low power */
148 #define MIPI_DSI_MODE_LPM BIT(11)
150 enum mipi_dsi_pixel_format {
153 MIPI_DSI_FMT_RGB666_PACKED,
157 #define DSI_DEV_NAME_SIZE 20
160 * struct mipi_dsi_device_info - template for creating a mipi_dsi_device
161 * @type: DSI peripheral chip type
162 * @channel: DSI virtual channel assigned to peripheral
163 * @node: pointer to OF device node or NULL
165 * This is populated and passed to mipi_dsi_device_new to create a new
168 struct mipi_dsi_device_info {
169 char type[DSI_DEV_NAME_SIZE];
171 struct device_node *node;
175 * struct mipi_dsi_device - DSI peripheral device
176 * @host: DSI host for this peripheral
177 * @dev: driver model device node for this peripheral
178 * @name: DSI peripheral chip type
179 * @channel: virtual channel assigned to the peripheral
180 * @format: pixel format for video mode
181 * @lanes: number of active data lanes
182 * @mode_flags: DSI operation mode related flags
184 struct mipi_dsi_device {
185 struct mipi_dsi_host *host;
188 char name[DSI_DEV_NAME_SIZE];
189 unsigned int channel;
191 enum mipi_dsi_pixel_format format;
192 unsigned long mode_flags;
196 * mipi_dsi_pixel_format_to_bpp - obtain the number of bits per pixel for any
197 * given pixel format defined by the MIPI DSI
199 * @fmt: MIPI DSI pixel format
201 * Returns: The number of bits per pixel of the given pixel format.
203 static inline int mipi_dsi_pixel_format_to_bpp(enum mipi_dsi_pixel_format fmt)
206 case MIPI_DSI_FMT_RGB888:
207 case MIPI_DSI_FMT_RGB666:
210 case MIPI_DSI_FMT_RGB666_PACKED:
213 case MIPI_DSI_FMT_RGB565:
221 * struct mipi_dsi_panel_plat - DSI panel platform data
222 * @device: DSI peripheral device
224 struct mipi_dsi_panel_plat {
225 struct mipi_dsi_device *device;
229 * mipi_dsi_attach - attach a DSI device to its DSI host
230 * @dsi: DSI peripheral
232 int mipi_dsi_attach(struct mipi_dsi_device *dsi);
235 * mipi_dsi_detach - detach a DSI device from its DSI host
236 * @dsi: DSI peripheral
238 int mipi_dsi_detach(struct mipi_dsi_device *dsi);
239 int mipi_dsi_shutdown_peripheral(struct mipi_dsi_device *dsi);
240 int mipi_dsi_turn_on_peripheral(struct mipi_dsi_device *dsi);
241 int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi,
244 ssize_t mipi_dsi_generic_write(struct mipi_dsi_device *dsi, const void *payload,
246 ssize_t mipi_dsi_generic_read(struct mipi_dsi_device *dsi, const void *params,
247 size_t num_params, void *data, size_t size);
250 * enum mipi_dsi_dcs_tear_mode - Tearing Effect Output Line mode
251 * @MIPI_DSI_DCS_TEAR_MODE_VBLANK: the TE output line consists of V-Blanking
253 * @MIPI_DSI_DCS_TEAR_MODE_VHBLANK : the TE output line consists of both
254 * V-Blanking and H-Blanking information
256 enum mipi_dsi_dcs_tear_mode {
257 MIPI_DSI_DCS_TEAR_MODE_VBLANK,
258 MIPI_DSI_DCS_TEAR_MODE_VHBLANK,
261 #define MIPI_DSI_DCS_POWER_MODE_DISPLAY BIT(2)
262 #define MIPI_DSI_DCS_POWER_MODE_NORMAL BIT(3)
263 #define MIPI_DSI_DCS_POWER_MODE_SLEEP BIT(4)
264 #define MIPI_DSI_DCS_POWER_MODE_PARTIAL BIT(5)
265 #define MIPI_DSI_DCS_POWER_MODE_IDLE BIT(6)
268 * mipi_dsi_dcs_write_buffer() - transmit a DCS command with payload
269 * @dsi: DSI peripheral device
270 * @data: buffer containing data to be transmitted
271 * @len: size of transmission buffer
273 * This function will automatically choose the right data type depending on
274 * the command payload length.
276 * Return: The number of bytes successfully transmitted or a negative error
279 ssize_t mipi_dsi_dcs_write_buffer(struct mipi_dsi_device *dsi,
280 const void *data, size_t len);
283 * mipi_dsi_dcs_write() - send DCS write command
284 * @dsi: DSI peripheral device
286 * @data: buffer containing the command payload
287 * @len: command payload length
289 * This function will automatically choose the right data type depending on
290 * the command payload length.
294 ssize_t mipi_dsi_dcs_write(struct mipi_dsi_device *dsi, u8 cmd,
295 const void *data, size_t len);
298 * mipi_dsi_dcs_read() - send DCS read request command
299 * @dsi: DSI peripheral device
301 * @data: buffer in which to receive data
302 * @len: size of receive buffer
304 * Return: The number of bytes read or a negative error code on failure.
306 ssize_t mipi_dsi_dcs_read(struct mipi_dsi_device *dsi, u8 cmd, void *data,
310 * mipi_dsi_dcs_nop() - send DCS nop packet
311 * @dsi: DSI peripheral device
313 * Return: 0 on success or a negative error code on failure.
315 int mipi_dsi_dcs_nop(struct mipi_dsi_device *dsi);
318 * mipi_dsi_dcs_soft_reset() - perform a software reset of the display module
319 * @dsi: DSI peripheral device
321 * Return: 0 on success or a negative error code on failure.
323 int mipi_dsi_dcs_soft_reset(struct mipi_dsi_device *dsi);
326 * mipi_dsi_dcs_get_power_mode() - query the display module's current power
328 * @dsi: DSI peripheral device
329 * @mode: return location for the current power mode
331 * Return: 0 on success or a negative error code on failure.
333 int mipi_dsi_dcs_get_power_mode(struct mipi_dsi_device *dsi, u8 *mode);
336 * mipi_dsi_dcs_get_pixel_format() - gets the pixel format for the RGB image
337 * data used by the interface
338 * @dsi: DSI peripheral device
339 * @format: return location for the pixel format
341 * Return: 0 on success or a negative error code on failure.
343 int mipi_dsi_dcs_get_pixel_format(struct mipi_dsi_device *dsi, u8 *format);
346 * mipi_dsi_dcs_enter_sleep_mode() - disable all unnecessary blocks inside the
347 * display module except interface communication
348 * @dsi: DSI peripheral device
350 * Return: 0 on success or a negative error code on failure.
352 int mipi_dsi_dcs_enter_sleep_mode(struct mipi_dsi_device *dsi);
355 * mipi_dsi_dcs_exit_sleep_mode() - enable all blocks inside the display
357 * @dsi: DSI peripheral device
359 * Return: 0 on success or a negative error code on failure.
361 int mipi_dsi_dcs_exit_sleep_mode(struct mipi_dsi_device *dsi);
364 * mipi_dsi_dcs_set_display_off() - stop displaying the image data on the
366 * @dsi: DSI peripheral device
368 * Return: 0 on success or a negative error code on failure.
370 int mipi_dsi_dcs_set_display_off(struct mipi_dsi_device *dsi);
373 * mipi_dsi_dcs_set_display_on() - start displaying the image data on the
375 * @dsi: DSI peripheral device
377 * Return: 0 on success or a negative error code on failure
379 int mipi_dsi_dcs_set_display_on(struct mipi_dsi_device *dsi);
382 * mipi_dsi_dcs_set_column_address() - define the column extent of the frame
383 * memory accessed by the host processor
384 * @dsi: DSI peripheral device
385 * @start: first column of frame memory
386 * @end: last column of frame memory
388 * Return: 0 on success or a negative error code on failure.
390 int mipi_dsi_dcs_set_column_address(struct mipi_dsi_device *dsi, u16 start,
393 * mipi_dsi_dcs_set_page_address() - define the page extent of the frame
394 * memory accessed by the host processor
395 * @dsi: DSI peripheral device
396 * @start: first page of frame memory
397 * @end: last page of frame memory
399 * Return: 0 on success or a negative error code on failure.
401 int mipi_dsi_dcs_set_page_address(struct mipi_dsi_device *dsi, u16 start,
405 * mipi_dsi_dcs_set_tear_off() - turn off the display module's Tearing Effect
406 * output signal on the TE signal line
407 * @dsi: DSI peripheral device
409 * Return: 0 on success or a negative error code on failure
411 int mipi_dsi_dcs_set_tear_off(struct mipi_dsi_device *dsi);
414 * mipi_dsi_dcs_set_tear_on() - turn on the display module's Tearing Effect
415 * output signal on the TE signal line.
416 * @dsi: DSI peripheral device
417 * @mode: the Tearing Effect Output Line mode
419 * Return: 0 on success or a negative error code on failure
421 int mipi_dsi_dcs_set_tear_on(struct mipi_dsi_device *dsi,
422 enum mipi_dsi_dcs_tear_mode mode);
425 * mipi_dsi_dcs_set_pixel_format() - sets the pixel format for the RGB image
426 * data used by the interface
427 * @dsi: DSI peripheral device
428 * @format: pixel format
430 * Return: 0 on success or a negative error code on failure.
432 int mipi_dsi_dcs_set_pixel_format(struct mipi_dsi_device *dsi, u8 format);
435 * mipi_dsi_dcs_set_tear_scanline() - set the scanline to use as trigger for
436 * the Tearing Effect output signal of the display module
437 * @dsi: DSI peripheral device
438 * @scanline: scanline to use as trigger
440 * Return: 0 on success or a negative error code on failure
442 int mipi_dsi_dcs_set_tear_scanline(struct mipi_dsi_device *dsi, u16 scanline);
445 * mipi_dsi_dcs_set_display_brightness() - sets the brightness value of the
447 * @dsi: DSI peripheral device
448 * @brightness: brightness value
450 * Return: 0 on success or a negative error code on failure.
452 int mipi_dsi_dcs_set_display_brightness(struct mipi_dsi_device *dsi,
456 * mipi_dsi_dcs_get_display_brightness() - gets the current brightness value
458 * @dsi: DSI peripheral device
459 * @brightness: brightness value
461 * Return: 0 on success or a negative error code on failure.
463 int mipi_dsi_dcs_get_display_brightness(struct mipi_dsi_device *dsi,
466 #endif /* MIPI_DSI_H */