xref: /linux/include/drm/drm_mipi_dsi.h (revision aec2f682d47c54ef434b2d440992626d80b1ebdc)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * MIPI DSI Bus
4  *
5  * Copyright (C) 2012-2013, Samsung Electronics, Co., Ltd.
6  * Andrzej Hajda <a.hajda@samsung.com>
7  */
8 
9 #ifndef __DRM_MIPI_DSI_H__
10 #define __DRM_MIPI_DSI_H__
11 
12 #include <linux/device.h>
13 #include <linux/delay.h>
14 
15 struct mipi_dsi_host;
16 struct mipi_dsi_device;
17 struct drm_dsc_picture_parameter_set;
18 
19 /* request ACK from peripheral */
20 #define MIPI_DSI_MSG_REQ_ACK	BIT(0)
21 /* use Low Power Mode to transmit message */
22 #define MIPI_DSI_MSG_USE_LPM	BIT(1)
23 
24 /**
25  * struct mipi_dsi_msg - read/write DSI buffer
26  * @channel: virtual channel id
27  * @type: payload data type
28  * @flags: flags controlling this message transmission
29  * @tx_len: length of @tx_buf
30  * @tx_buf: data to be written
31  * @rx_len: length of @rx_buf
32  * @rx_buf: data to be read, or NULL
33  */
34 struct mipi_dsi_msg {
35 	u8 channel;
36 	u8 type;
37 	u16 flags;
38 
39 	size_t tx_len;
40 	const void *tx_buf;
41 
42 	size_t rx_len;
43 	void *rx_buf;
44 };
45 
46 bool mipi_dsi_packet_format_is_short(u8 type);
47 bool mipi_dsi_packet_format_is_long(u8 type);
48 
49 /**
50  * struct mipi_dsi_packet - represents a MIPI DSI packet in protocol format
51  * @size: size (in bytes) of the packet
52  * @header: the four bytes that make up the header (Data ID, Word Count or
53  *     Packet Data, and ECC)
54  * @payload_length: number of bytes in the payload
55  * @payload: a pointer to a buffer containing the payload, if any
56  */
57 struct mipi_dsi_packet {
58 	size_t size;
59 	u8 header[4];
60 	size_t payload_length;
61 	const u8 *payload;
62 };
63 
64 int mipi_dsi_create_packet(struct mipi_dsi_packet *packet,
65 			   const struct mipi_dsi_msg *msg);
66 
67 /**
68  * struct mipi_dsi_host_ops - DSI bus operations
69  * @attach: attach DSI device to DSI host
70  * @detach: detach DSI device from DSI host
71  * @transfer: transmit a DSI packet
72  *
73  * DSI packets transmitted by .transfer() are passed in as mipi_dsi_msg
74  * structures. This structure contains information about the type of packet
75  * being transmitted as well as the transmit and receive buffers. When an
76  * error is encountered during transmission, this function will return a
77  * negative error code. On success it shall return the number of bytes
78  * transmitted for write packets or the number of bytes received for read
79  * packets.
80  *
81  * Note that typically DSI packet transmission is atomic, so the .transfer()
82  * function will seldomly return anything other than the number of bytes
83  * contained in the transmit buffer on success.
84  *
85  * Also note that those callbacks can be called no matter the state the
86  * host is in. Drivers that need the underlying device to be powered to
87  * perform these operations will first need to make sure it's been
88  * properly enabled.
89  */
90 struct mipi_dsi_host_ops {
91 	int (*attach)(struct mipi_dsi_host *host,
92 		      struct mipi_dsi_device *dsi);
93 	int (*detach)(struct mipi_dsi_host *host,
94 		      struct mipi_dsi_device *dsi);
95 	ssize_t (*transfer)(struct mipi_dsi_host *host,
96 			    const struct mipi_dsi_msg *msg);
97 };
98 
99 /**
100  * struct mipi_dsi_host - DSI host device
101  * @dev: driver model device node for this DSI host
102  * @ops: DSI host operations
103  * @list: list management
104  */
105 struct mipi_dsi_host {
106 	struct device *dev;
107 	const struct mipi_dsi_host_ops *ops;
108 	struct list_head list;
109 };
110 
111 int mipi_dsi_host_register(struct mipi_dsi_host *host);
112 void mipi_dsi_host_unregister(struct mipi_dsi_host *host);
113 struct mipi_dsi_host *of_find_mipi_dsi_host_by_node(struct device_node *node);
114 
115 /* DSI mode flags */
116 
117 /* video mode */
118 #define MIPI_DSI_MODE_VIDEO		BIT(0)
119 /* video burst mode */
120 #define MIPI_DSI_MODE_VIDEO_BURST	BIT(1)
121 /* video pulse mode */
122 #define MIPI_DSI_MODE_VIDEO_SYNC_PULSE	BIT(2)
123 /* enable auto vertical count mode */
124 #define MIPI_DSI_MODE_VIDEO_AUTO_VERT	BIT(3)
125 /* enable hsync-end packets in vsync-pulse and v-porch area */
126 #define MIPI_DSI_MODE_VIDEO_HSE		BIT(4)
127 /* disable hfront-porch area */
128 #define MIPI_DSI_MODE_VIDEO_NO_HFP	BIT(5)
129 /* disable hback-porch area */
130 #define MIPI_DSI_MODE_VIDEO_NO_HBP	BIT(6)
131 /* disable hsync-active area */
132 #define MIPI_DSI_MODE_VIDEO_NO_HSA	BIT(7)
133 /* disable EoT packets in HS mode */
134 #define MIPI_DSI_MODE_NO_EOT_PACKET	BIT(9)
135 /* device supports non-continuous clock behavior (DSI spec 5.6.1) */
136 #define MIPI_DSI_CLOCK_NON_CONTINUOUS	BIT(10)
137 /* transmit data in low power */
138 #define MIPI_DSI_MODE_LPM		BIT(11)
139 /* transmit data ending at the same time for all lanes within one hsync */
140 #define MIPI_DSI_HS_PKT_END_ALIGNED	BIT(12)
141 
142 enum mipi_dsi_pixel_format {
143 	MIPI_DSI_FMT_RGB888,
144 	MIPI_DSI_FMT_RGB666,
145 	MIPI_DSI_FMT_RGB666_PACKED,
146 	MIPI_DSI_FMT_RGB565,
147 	MIPI_DSI_FMT_RGB101010,
148 };
149 
150 #define DSI_DEV_NAME_SIZE		20
151 
152 /**
153  * struct mipi_dsi_device_info - template for creating a mipi_dsi_device
154  * @type: DSI peripheral chip type
155  * @channel: DSI virtual channel assigned to peripheral
156  * @node: pointer to OF device node or NULL
157  *
158  * This is populated and passed to mipi_dsi_device_new to create a new
159  * DSI device
160  */
161 struct mipi_dsi_device_info {
162 	char type[DSI_DEV_NAME_SIZE];
163 	u32 channel;
164 	struct device_node *node;
165 };
166 
167 /**
168  * struct mipi_dsi_device - DSI peripheral device
169  * @host: DSI host for this peripheral
170  * @dev: driver model device node for this peripheral
171  * @attached: the DSI device has been successfully attached
172  * @name: DSI peripheral chip type
173  * @channel: virtual channel assigned to the peripheral
174  * @format: pixel format for video mode
175  * @lanes: number of active data lanes
176  * @mode_flags: DSI operation mode related flags
177  * @hs_rate: maximum lane frequency for high speed mode in hertz, this should
178  * be set to the real limits of the hardware, zero is only accepted for
179  * legacy drivers
180  * @lp_rate: maximum lane frequency for low power mode in hertz, this should
181  * be set to the real limits of the hardware, zero is only accepted for
182  * legacy drivers
183  * @dsc: panel/bridge DSC pps payload to be sent
184  */
185 struct mipi_dsi_device {
186 	struct mipi_dsi_host *host;
187 	struct device dev;
188 	bool attached;
189 
190 	char name[DSI_DEV_NAME_SIZE];
191 	unsigned int channel;
192 	unsigned int lanes;
193 	enum mipi_dsi_pixel_format format;
194 	unsigned long mode_flags;
195 	unsigned long hs_rate;
196 	unsigned long lp_rate;
197 	struct drm_dsc_config *dsc;
198 };
199 
200 /**
201  * struct mipi_dsi_multi_context - Context to call multiple MIPI DSI funcs in a row
202  */
203 struct mipi_dsi_multi_context {
204 	/**
205 	 * @dsi: Pointer to the MIPI DSI device
206 	 */
207 	struct mipi_dsi_device *dsi;
208 
209 	/**
210 	 * @accum_err: Storage for the accumulated error over the multiple calls
211 	 *
212 	 * Init to 0. If a function encounters an error then the error code
213 	 * will be stored here. If you call a function and this points to a
214 	 * non-zero value then the function will be a noop. This allows calling
215 	 * a function many times in a row and just checking the error at the
216 	 * end to see if any of them failed.
217 	 */
218 	int accum_err;
219 };
220 
221 #define MIPI_DSI_MODULE_PREFIX "mipi-dsi:"
222 
223 #define to_mipi_dsi_device(__dev)	container_of_const(__dev, struct mipi_dsi_device, dev)
224 
225 extern const struct bus_type mipi_dsi_bus_type;
226 #define dev_is_mipi_dsi(dev)	((dev)->bus == &mipi_dsi_bus_type)
227 
228 /**
229  * mipi_dsi_pixel_format_to_bpp - obtain the number of bits per pixel for any
230  *                                given pixel format defined by the MIPI DSI
231  *                                specification
232  * @fmt: MIPI DSI pixel format
233  *
234  * Returns: The number of bits per pixel of the given pixel format.
235  */
236 static inline int mipi_dsi_pixel_format_to_bpp(enum mipi_dsi_pixel_format fmt)
237 {
238 	switch (fmt) {
239 	case MIPI_DSI_FMT_RGB101010:
240 		return 30;
241 
242 	case MIPI_DSI_FMT_RGB888:
243 	case MIPI_DSI_FMT_RGB666:
244 		return 24;
245 
246 	case MIPI_DSI_FMT_RGB666_PACKED:
247 		return 18;
248 
249 	case MIPI_DSI_FMT_RGB565:
250 		return 16;
251 	}
252 
253 	return -EINVAL;
254 }
255 
256 enum mipi_dsi_compression_algo {
257 	MIPI_DSI_COMPRESSION_DSC = 0,
258 	MIPI_DSI_COMPRESSION_VENDOR = 3,
259 	/* other two values are reserved, DSI 1.3 */
260 };
261 
262 struct mipi_dsi_device *
263 mipi_dsi_device_register_full(struct mipi_dsi_host *host,
264 			      const struct mipi_dsi_device_info *info);
265 void mipi_dsi_device_unregister(struct mipi_dsi_device *dsi);
266 struct mipi_dsi_device *
267 devm_mipi_dsi_device_register_full(struct device *dev, struct mipi_dsi_host *host,
268 				   const struct mipi_dsi_device_info *info);
269 struct mipi_dsi_device *of_find_mipi_dsi_device_by_node(struct device_node *np);
270 int mipi_dsi_attach(struct mipi_dsi_device *dsi);
271 int mipi_dsi_detach(struct mipi_dsi_device *dsi);
272 int devm_mipi_dsi_attach(struct device *dev, struct mipi_dsi_device *dsi);
273 int mipi_dsi_shutdown_peripheral(struct mipi_dsi_device *dsi);
274 int mipi_dsi_turn_on_peripheral(struct mipi_dsi_device *dsi);
275 int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi,
276 					    u16 value);
277 int mipi_dsi_compression_mode(struct mipi_dsi_device *dsi, bool enable);
278 int mipi_dsi_compression_mode_ext(struct mipi_dsi_device *dsi, bool enable,
279 				  enum mipi_dsi_compression_algo algo,
280 				  unsigned int pps_selector);
281 int mipi_dsi_picture_parameter_set(struct mipi_dsi_device *dsi,
282 				   const struct drm_dsc_picture_parameter_set *pps);
283 
284 void mipi_dsi_compression_mode_ext_multi(struct mipi_dsi_multi_context *ctx,
285 					 bool enable,
286 					 enum mipi_dsi_compression_algo algo,
287 					 unsigned int pps_selector);
288 void mipi_dsi_compression_mode_multi(struct mipi_dsi_multi_context *ctx,
289 				     bool enable);
290 void mipi_dsi_picture_parameter_set_multi(struct mipi_dsi_multi_context *ctx,
291 					  const struct drm_dsc_picture_parameter_set *pps);
292 
293 ssize_t mipi_dsi_generic_write(struct mipi_dsi_device *dsi, const void *payload,
294 			       size_t size);
295 void mipi_dsi_generic_write_multi(struct mipi_dsi_multi_context *ctx,
296 				  const void *payload, size_t size);
297 void mipi_dsi_dual_generic_write_multi(struct mipi_dsi_multi_context *ctx,
298 				       struct mipi_dsi_device *dsi1,
299 				       struct mipi_dsi_device *dsi2,
300 				       const void *payload, size_t size);
301 ssize_t mipi_dsi_generic_read(struct mipi_dsi_device *dsi, const void *params,
302 			      size_t num_params, void *data, size_t size);
303 u32 drm_mipi_dsi_get_input_bus_fmt(enum mipi_dsi_pixel_format dsi_format);
304 
305 #define mipi_dsi_msleep(ctx, delay)	\
306 	do {				\
307 		if (!(ctx)->accum_err)	\
308 			msleep(delay);	\
309 	} while (0)
310 
311 #define mipi_dsi_usleep_range(ctx, min, max)	\
312 	do {					\
313 		if (!(ctx)->accum_err)		\
314 			usleep_range(min, max);	\
315 	} while (0)
316 
317 /**
318  * enum mipi_dsi_dcs_tear_mode - Tearing Effect Output Line mode
319  * @MIPI_DSI_DCS_TEAR_MODE_VBLANK: the TE output line consists of V-Blanking
320  *    information only
321  * @MIPI_DSI_DCS_TEAR_MODE_VHBLANK : the TE output line consists of both
322  *    V-Blanking and H-Blanking information
323  */
324 enum mipi_dsi_dcs_tear_mode {
325 	MIPI_DSI_DCS_TEAR_MODE_VBLANK,
326 	MIPI_DSI_DCS_TEAR_MODE_VHBLANK,
327 };
328 
329 #define MIPI_DSI_DCS_POWER_MODE_DISPLAY (1 << 2)
330 #define MIPI_DSI_DCS_POWER_MODE_NORMAL  (1 << 3)
331 #define MIPI_DSI_DCS_POWER_MODE_SLEEP   (1 << 4)
332 #define MIPI_DSI_DCS_POWER_MODE_PARTIAL (1 << 5)
333 #define MIPI_DSI_DCS_POWER_MODE_IDLE    (1 << 6)
334 
335 ssize_t mipi_dsi_dcs_write_buffer(struct mipi_dsi_device *dsi,
336 				  const void *data, size_t len);
337 int mipi_dsi_dcs_write_buffer_chatty(struct mipi_dsi_device *dsi,
338 				     const void *data, size_t len);
339 void mipi_dsi_dcs_write_buffer_multi(struct mipi_dsi_multi_context *ctx,
340 				     const void *data, size_t len);
341 void mipi_dsi_dual_dcs_write_buffer_multi(struct mipi_dsi_multi_context *ctx,
342 					  struct mipi_dsi_device *dsi1,
343 					  struct mipi_dsi_device *dsi2,
344 					  const void *data, size_t len);
345 ssize_t mipi_dsi_dcs_write(struct mipi_dsi_device *dsi, u8 cmd,
346 			   const void *data, size_t len);
347 ssize_t mipi_dsi_dcs_read(struct mipi_dsi_device *dsi, u8 cmd, void *data,
348 			  size_t len);
349 void mipi_dsi_dcs_read_multi(struct mipi_dsi_multi_context *ctx, u8 cmd,
350 			     void *data, size_t len);
351 int mipi_dsi_dcs_nop(struct mipi_dsi_device *dsi);
352 int mipi_dsi_dcs_soft_reset(struct mipi_dsi_device *dsi);
353 int mipi_dsi_dcs_get_power_mode(struct mipi_dsi_device *dsi, u8 *mode);
354 int mipi_dsi_dcs_get_pixel_format(struct mipi_dsi_device *dsi, u8 *format);
355 int mipi_dsi_dcs_enter_sleep_mode(struct mipi_dsi_device *dsi);
356 int mipi_dsi_dcs_exit_sleep_mode(struct mipi_dsi_device *dsi);
357 int mipi_dsi_dcs_set_display_off(struct mipi_dsi_device *dsi);
358 int mipi_dsi_dcs_set_display_on(struct mipi_dsi_device *dsi);
359 int mipi_dsi_dcs_set_column_address(struct mipi_dsi_device *dsi, u16 start,
360 				    u16 end);
361 int mipi_dsi_dcs_set_page_address(struct mipi_dsi_device *dsi, u16 start,
362 				  u16 end);
363 int mipi_dsi_dcs_set_tear_on(struct mipi_dsi_device *dsi,
364 			     enum mipi_dsi_dcs_tear_mode mode);
365 int mipi_dsi_dcs_set_pixel_format(struct mipi_dsi_device *dsi, u8 format);
366 int mipi_dsi_dcs_set_tear_scanline(struct mipi_dsi_device *dsi, u16 scanline);
367 int mipi_dsi_dcs_set_display_brightness(struct mipi_dsi_device *dsi,
368 					u16 brightness);
369 int mipi_dsi_dcs_get_display_brightness(struct mipi_dsi_device *dsi,
370 					u16 *brightness);
371 int mipi_dsi_dcs_set_display_brightness_large(struct mipi_dsi_device *dsi,
372 					     u16 brightness);
373 int mipi_dsi_dcs_get_display_brightness_large(struct mipi_dsi_device *dsi,
374 					     u16 *brightness);
375 
376 void mipi_dsi_dcs_nop_multi(struct mipi_dsi_multi_context *ctx);
377 void mipi_dsi_dcs_enter_sleep_mode_multi(struct mipi_dsi_multi_context *ctx);
378 void mipi_dsi_dcs_exit_sleep_mode_multi(struct mipi_dsi_multi_context *ctx);
379 void mipi_dsi_dcs_set_display_off_multi(struct mipi_dsi_multi_context *ctx);
380 void mipi_dsi_dcs_set_display_on_multi(struct mipi_dsi_multi_context *ctx);
381 void mipi_dsi_dcs_set_tear_on_multi(struct mipi_dsi_multi_context *ctx,
382 				    enum mipi_dsi_dcs_tear_mode mode);
383 void mipi_dsi_turn_on_peripheral_multi(struct mipi_dsi_multi_context *ctx);
384 void mipi_dsi_dcs_soft_reset_multi(struct mipi_dsi_multi_context *ctx);
385 void mipi_dsi_dcs_set_display_brightness_multi(struct mipi_dsi_multi_context *ctx,
386 					       u16 brightness);
387 void mipi_dsi_dcs_set_pixel_format_multi(struct mipi_dsi_multi_context *ctx,
388 					 u8 format);
389 void mipi_dsi_dcs_set_column_address_multi(struct mipi_dsi_multi_context *ctx,
390 					   u16 start, u16 end);
391 void mipi_dsi_dcs_set_page_address_multi(struct mipi_dsi_multi_context *ctx,
392 					 u16 start, u16 end);
393 void mipi_dsi_dcs_set_tear_scanline_multi(struct mipi_dsi_multi_context *ctx,
394 					  u16 scanline);
395 void mipi_dsi_dcs_set_tear_off_multi(struct mipi_dsi_multi_context *ctx);
396 
397 /**
398  * mipi_dsi_generic_write_seq_multi - transmit data using a generic write packet
399  *
400  * This macro will print errors for you and error handling is optimized for
401  * callers that call this multiple times in a row.
402  *
403  * @ctx: Context for multiple DSI transactions
404  * @seq: buffer containing the payload
405  */
406 #define mipi_dsi_generic_write_seq_multi(ctx, seq...)                \
407 	do {                                                         \
408 		static const u8 d[] = { seq };                       \
409 		mipi_dsi_generic_write_multi(ctx, d, ARRAY_SIZE(d)); \
410 	} while (0)
411 
412 /**
413  * mipi_dsi_generic_write_var_seq_multi - transmit non-constant data using a
414  * generic write packet
415  *
416  * This macro will print errors for you and error handling is optimized for
417  * callers that call this multiple times in a row.
418  *
419  * @ctx: Context for multiple DSI transactions
420  * @seq: buffer containing the payload
421  */
422 #define mipi_dsi_generic_write_var_seq_multi(ctx, seq...)	     \
423 	do {							     \
424 		const u8 d[] = { seq };				     \
425 		mipi_dsi_generic_write_multi(ctx, d, ARRAY_SIZE(d)); \
426 	} while (0)
427 
428 /**
429  * mipi_dsi_dcs_write_seq_multi - transmit a DCS command with payload
430  *
431  * This macro will print errors for you and error handling is optimized for
432  * callers that call this multiple times in a row.
433  *
434  * @ctx: Context for multiple DSI transactions
435  * @cmd: Command
436  * @seq: buffer containing data to be transmitted
437  */
438 #define mipi_dsi_dcs_write_seq_multi(ctx, cmd, seq...)                  \
439 	do {                                                            \
440 		static const u8 d[] = { cmd, seq };                     \
441 		mipi_dsi_dcs_write_buffer_multi(ctx, d, ARRAY_SIZE(d)); \
442 	} while (0)
443 
444 /**
445  * mipi_dsi_dcs_write_var_seq_multi - transmit a DCS command with non-constant
446  * payload
447  *
448  * This macro will print errors for you and error handling is optimized for
449  * callers that call this multiple times in a row.
450  *
451  * @ctx: Context for multiple DSI transactions
452  * @cmd: Command
453  * @seq: buffer containing data to be transmitted
454  */
455 #define mipi_dsi_dcs_write_var_seq_multi(ctx, cmd, seq...)		\
456 	do {								\
457 		const u8 d[] = { cmd, seq };				\
458 		mipi_dsi_dcs_write_buffer_multi(ctx, d, ARRAY_SIZE(d));	\
459 	} while (0)
460 
461 /**
462  * mipi_dsi_dual - send the same MIPI DSI command to two interfaces
463  *
464  * This macro will send the specified MIPI DSI command twice, once per each of
465  * the two interfaces supplied. This is useful for reducing duplication of code
466  * in panel drivers which use two parallel serial interfaces.
467  *
468  * Note that the _func parameter cannot accept a macro such as
469  * mipi_dsi_generic_write_multi() or mipi_dsi_dcs_write_buffer_multi(). See
470  * mipi_dsi_dual_generic_write_multi() and
471  * mipi_dsi_dual_dcs_write_buffer_multi() instead.
472  *
473  * WARNING: This macro reuses the _func argument and the optional trailing
474  * arguments twice each, which may cause unintended side effects. For example,
475  * adding the postfix increment ++ operator to one of the arguments to be
476  * passed to _func will cause the variable to be incremented twice instead of
477  * once and the variable will be its original value + 1 when sent to _dsi2.
478  *
479  * @_func: MIPI DSI function to pass context and arguments into
480  * @_ctx: Context for multiple DSI transactions
481  * @_dsi1: First DSI interface to act as recipient of the MIPI DSI command
482  * @_dsi2: Second DSI interface to act as recipient of the MIPI DSI command
483  * @...: Arguments to pass to MIPI DSI function or macro
484  */
485 
486 #define mipi_dsi_dual(_func, _ctx, _dsi1, _dsi2, ...)		 \
487 	do {							 \
488 		struct mipi_dsi_multi_context *_ctxcpy = (_ctx); \
489 		_ctxcpy->dsi = (_dsi1);				 \
490 		(_func)(_ctxcpy, ##__VA_ARGS__);		 \
491 		_ctxcpy->dsi = (_dsi2);				 \
492 		(_func)(_ctxcpy, ##__VA_ARGS__);		 \
493 	} while (0)
494 
495 /**
496  * mipi_dsi_dual_generic_write_seq_multi - transmit data using a generic write
497  * packet to two dsi interfaces, one after the other
498  *
499  * This macro will send the specified generic packet twice, once per each of
500  * the two interfaces supplied. This is useful for reducing duplication of code
501  * in panel drivers which use two parallel serial interfaces.
502  *
503  * Note that if an error occurs while transmitting the packet to the first DSI
504  * interface, the packet will not be sent to the second DSI interface.
505  *
506  * This macro will print errors for you and error handling is optimized for
507  * callers that call this multiple times in a row.
508  *
509  * @_ctx: Context for multiple DSI transactions
510  * @_dsi1: First DSI interface to act as recipient of packet
511  * @_dsi2: Second DSI interface to act as recipient of packet
512  * @_seq: buffer containing the payload
513  */
514 #define mipi_dsi_dual_generic_write_seq_multi(_ctx, _dsi1, _dsi2, _seq...) \
515 	do {								   \
516 		static const u8 d[] = { _seq };				   \
517 		mipi_dsi_dual_generic_write_multi(_ctx, _dsi1, _dsi2, d,   \
518 						  ARRAY_SIZE(d));	   \
519 	} while (0)
520 
521 /**
522  * mipi_dsi_dual_dcs_write_seq_multi - transmit a DCS command with payload to
523  * two dsi interfaces, one after the other
524  *
525  * This macro will send the specified DCS command with payload twice, once per
526  * each of the two interfaces supplied. This is useful for reducing duplication
527  * of code in panel drivers which use two parallel serial interfaces.
528  *
529  * Note that if an error occurs while transmitting the payload to the first DSI
530  * interface, the payload will not be sent to the second DSI interface.
531  *
532  * This macro will print errors for you and error handling is optimized for
533  * callers that call this multiple times in a row.
534  *
535  * @_ctx: Context for multiple DSI transactions
536  * @_dsi1: First DSI interface to act as recipient of packet
537  * @_dsi2: Second DSI interface to act as recipient of packet
538  * @_cmd: Command
539  * @_seq: buffer containing the payload
540  */
541 #define mipi_dsi_dual_dcs_write_seq_multi(_ctx, _dsi1, _dsi2, _cmd, _seq...) \
542 	do {								     \
543 		static const u8 d[] = { _cmd, _seq };			     \
544 		mipi_dsi_dual_dcs_write_buffer_multi(_ctx, _dsi1, _dsi2, d,  \
545 						     ARRAY_SIZE(d));	     \
546 	} while (0)
547 
548 /**
549  * struct mipi_dsi_driver - DSI driver
550  * @driver: device driver model driver
551  * @probe: callback for device binding
552  * @remove: callback for device unbinding
553  * @shutdown: called at shutdown time to quiesce the device
554  */
555 struct mipi_dsi_driver {
556 	struct device_driver driver;
557 	int(*probe)(struct mipi_dsi_device *dsi);
558 	void (*remove)(struct mipi_dsi_device *dsi);
559 	void (*shutdown)(struct mipi_dsi_device *dsi);
560 };
561 
562 static inline struct mipi_dsi_driver *
563 to_mipi_dsi_driver(struct device_driver *driver)
564 {
565 	return container_of(driver, struct mipi_dsi_driver, driver);
566 }
567 
568 static inline void *mipi_dsi_get_drvdata(const struct mipi_dsi_device *dsi)
569 {
570 	return dev_get_drvdata(&dsi->dev);
571 }
572 
573 static inline void mipi_dsi_set_drvdata(struct mipi_dsi_device *dsi, void *data)
574 {
575 	dev_set_drvdata(&dsi->dev, data);
576 }
577 
578 int mipi_dsi_driver_register_full(struct mipi_dsi_driver *driver,
579 				  struct module *owner);
580 void mipi_dsi_driver_unregister(struct mipi_dsi_driver *driver);
581 
582 #define mipi_dsi_driver_register(driver) \
583 	mipi_dsi_driver_register_full(driver, THIS_MODULE)
584 
585 #define module_mipi_dsi_driver(__mipi_dsi_driver) \
586 	module_driver(__mipi_dsi_driver, mipi_dsi_driver_register, \
587 			mipi_dsi_driver_unregister)
588 
589 #endif /* __DRM_MIPI_DSI__ */
590