xref: /linux/include/drm/drm_mipi_dsi.h (revision 7db28abbea0f7dc1ec4fdfdc149db5fbd9e4c994)
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 /* pack all DSC slices for a line into a single packet */
142 #define MIPI_DSI_MODE_DSC_ALL_SLICES_IN_PKT	BIT(13)
143 
144 enum mipi_dsi_pixel_format {
145 	MIPI_DSI_FMT_RGB888,
146 	MIPI_DSI_FMT_RGB666,
147 	MIPI_DSI_FMT_RGB666_PACKED,
148 	MIPI_DSI_FMT_RGB565,
149 	MIPI_DSI_FMT_RGB101010,
150 };
151 
152 #define DSI_DEV_NAME_SIZE		20
153 
154 /**
155  * struct mipi_dsi_device_info - template for creating a mipi_dsi_device
156  * @type: DSI peripheral chip type
157  * @channel: DSI virtual channel assigned to peripheral
158  * @node: pointer to OF device node or NULL
159  *
160  * This is populated and passed to mipi_dsi_device_new to create a new
161  * DSI device
162  */
163 struct mipi_dsi_device_info {
164 	char type[DSI_DEV_NAME_SIZE];
165 	u32 channel;
166 	struct device_node *node;
167 };
168 
169 /**
170  * struct mipi_dsi_device - DSI peripheral device
171  * @host: DSI host for this peripheral
172  * @dev: driver model device node for this peripheral
173  * @attached: the DSI device has been successfully attached
174  * @name: DSI peripheral chip type
175  * @channel: virtual channel assigned to the peripheral
176  * @format: pixel format for video mode
177  * @lanes: number of active data lanes
178  * @mode_flags: DSI operation mode related flags
179  * @hs_rate: maximum lane frequency for high speed mode in hertz, this should
180  * be set to the real limits of the hardware, zero is only accepted for
181  * legacy drivers
182  * @lp_rate: maximum lane frequency for low power mode in hertz, this should
183  * be set to the real limits of the hardware, zero is only accepted for
184  * legacy drivers
185  * @dsc: panel/bridge DSC pps payload to be sent
186  */
187 struct mipi_dsi_device {
188 	struct mipi_dsi_host *host;
189 	struct device dev;
190 	bool attached;
191 
192 	char name[DSI_DEV_NAME_SIZE];
193 	unsigned int channel;
194 	unsigned int lanes;
195 	enum mipi_dsi_pixel_format format;
196 	unsigned long mode_flags;
197 	unsigned long hs_rate;
198 	unsigned long lp_rate;
199 	struct drm_dsc_config *dsc;
200 };
201 
202 /**
203  * struct mipi_dsi_multi_context - Context to call multiple MIPI DSI funcs in a row
204  */
205 struct mipi_dsi_multi_context {
206 	/**
207 	 * @dsi: Pointer to the MIPI DSI device
208 	 */
209 	struct mipi_dsi_device *dsi;
210 
211 	/**
212 	 * @accum_err: Storage for the accumulated error over the multiple calls
213 	 *
214 	 * Init to 0. If a function encounters an error then the error code
215 	 * will be stored here. If you call a function and this points to a
216 	 * non-zero value then the function will be a noop. This allows calling
217 	 * a function many times in a row and just checking the error at the
218 	 * end to see if any of them failed.
219 	 */
220 	int accum_err;
221 };
222 
223 #define MIPI_DSI_MODULE_PREFIX "mipi-dsi:"
224 
225 #define to_mipi_dsi_device(__dev)	container_of_const(__dev, struct mipi_dsi_device, dev)
226 
227 extern const struct bus_type mipi_dsi_bus_type;
228 #define dev_is_mipi_dsi(dev)	((dev)->bus == &mipi_dsi_bus_type)
229 
230 /**
231  * mipi_dsi_pixel_format_to_bpp - obtain the number of bits per pixel for any
232  *                                given pixel format defined by the MIPI DSI
233  *                                specification
234  * @fmt: MIPI DSI pixel format
235  *
236  * Returns: The number of bits per pixel of the given pixel format.
237  */
238 static inline int mipi_dsi_pixel_format_to_bpp(enum mipi_dsi_pixel_format fmt)
239 {
240 	switch (fmt) {
241 	case MIPI_DSI_FMT_RGB101010:
242 		return 30;
243 
244 	case MIPI_DSI_FMT_RGB888:
245 	case MIPI_DSI_FMT_RGB666:
246 		return 24;
247 
248 	case MIPI_DSI_FMT_RGB666_PACKED:
249 		return 18;
250 
251 	case MIPI_DSI_FMT_RGB565:
252 		return 16;
253 	}
254 
255 	return -EINVAL;
256 }
257 
258 enum mipi_dsi_compression_algo {
259 	MIPI_DSI_COMPRESSION_DSC = 0,
260 	MIPI_DSI_COMPRESSION_VENDOR = 3,
261 	/* other two values are reserved, DSI 1.3 */
262 };
263 
264 struct mipi_dsi_device *
265 mipi_dsi_device_register_full(struct mipi_dsi_host *host,
266 			      const struct mipi_dsi_device_info *info);
267 void mipi_dsi_device_unregister(struct mipi_dsi_device *dsi);
268 struct mipi_dsi_device *
269 devm_mipi_dsi_device_register_full(struct device *dev, struct mipi_dsi_host *host,
270 				   const struct mipi_dsi_device_info *info);
271 struct mipi_dsi_device *of_find_mipi_dsi_device_by_node(struct device_node *np);
272 int mipi_dsi_attach(struct mipi_dsi_device *dsi);
273 int mipi_dsi_detach(struct mipi_dsi_device *dsi);
274 int devm_mipi_dsi_attach(struct device *dev, struct mipi_dsi_device *dsi);
275 int mipi_dsi_shutdown_peripheral(struct mipi_dsi_device *dsi);
276 int mipi_dsi_turn_on_peripheral(struct mipi_dsi_device *dsi);
277 int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi,
278 					    u16 value);
279 int mipi_dsi_compression_mode(struct mipi_dsi_device *dsi, bool enable);
280 int mipi_dsi_compression_mode_ext(struct mipi_dsi_device *dsi, bool enable,
281 				  enum mipi_dsi_compression_algo algo,
282 				  unsigned int pps_selector);
283 int mipi_dsi_picture_parameter_set(struct mipi_dsi_device *dsi,
284 				   const struct drm_dsc_picture_parameter_set *pps);
285 
286 void mipi_dsi_compression_mode_ext_multi(struct mipi_dsi_multi_context *ctx,
287 					 bool enable,
288 					 enum mipi_dsi_compression_algo algo,
289 					 unsigned int pps_selector);
290 void mipi_dsi_compression_mode_multi(struct mipi_dsi_multi_context *ctx,
291 				     bool enable);
292 void mipi_dsi_picture_parameter_set_multi(struct mipi_dsi_multi_context *ctx,
293 					  const struct drm_dsc_picture_parameter_set *pps);
294 
295 ssize_t mipi_dsi_generic_write(struct mipi_dsi_device *dsi, const void *payload,
296 			       size_t size);
297 void mipi_dsi_generic_write_multi(struct mipi_dsi_multi_context *ctx,
298 				  const void *payload, size_t size);
299 void mipi_dsi_dual_generic_write_multi(struct mipi_dsi_multi_context *ctx,
300 				       struct mipi_dsi_device *dsi1,
301 				       struct mipi_dsi_device *dsi2,
302 				       const void *payload, size_t size);
303 ssize_t mipi_dsi_generic_read(struct mipi_dsi_device *dsi, const void *params,
304 			      size_t num_params, void *data, size_t size);
305 u32 drm_mipi_dsi_get_input_bus_fmt(enum mipi_dsi_pixel_format dsi_format);
306 
307 #define mipi_dsi_msleep(ctx, delay)	\
308 	do {				\
309 		if (!(ctx)->accum_err)	\
310 			msleep(delay);	\
311 	} while (0)
312 
313 #define mipi_dsi_usleep_range(ctx, min, max)	\
314 	do {					\
315 		if (!(ctx)->accum_err)		\
316 			usleep_range(min, max);	\
317 	} while (0)
318 
319 /**
320  * enum mipi_dsi_dcs_tear_mode - Tearing Effect Output Line mode
321  * @MIPI_DSI_DCS_TEAR_MODE_VBLANK: the TE output line consists of V-Blanking
322  *    information only
323  * @MIPI_DSI_DCS_TEAR_MODE_VHBLANK : the TE output line consists of both
324  *    V-Blanking and H-Blanking information
325  */
326 enum mipi_dsi_dcs_tear_mode {
327 	MIPI_DSI_DCS_TEAR_MODE_VBLANK,
328 	MIPI_DSI_DCS_TEAR_MODE_VHBLANK,
329 };
330 
331 #define MIPI_DSI_DCS_POWER_MODE_DISPLAY (1 << 2)
332 #define MIPI_DSI_DCS_POWER_MODE_NORMAL  (1 << 3)
333 #define MIPI_DSI_DCS_POWER_MODE_SLEEP   (1 << 4)
334 #define MIPI_DSI_DCS_POWER_MODE_PARTIAL (1 << 5)
335 #define MIPI_DSI_DCS_POWER_MODE_IDLE    (1 << 6)
336 
337 ssize_t mipi_dsi_dcs_write_buffer(struct mipi_dsi_device *dsi,
338 				  const void *data, size_t len);
339 int mipi_dsi_dcs_write_buffer_chatty(struct mipi_dsi_device *dsi,
340 				     const void *data, size_t len);
341 void mipi_dsi_dcs_write_buffer_multi(struct mipi_dsi_multi_context *ctx,
342 				     const void *data, size_t len);
343 void mipi_dsi_dual_dcs_write_buffer_multi(struct mipi_dsi_multi_context *ctx,
344 					  struct mipi_dsi_device *dsi1,
345 					  struct mipi_dsi_device *dsi2,
346 					  const void *data, size_t len);
347 ssize_t mipi_dsi_dcs_write(struct mipi_dsi_device *dsi, u8 cmd,
348 			   const void *data, size_t len);
349 ssize_t mipi_dsi_dcs_read(struct mipi_dsi_device *dsi, u8 cmd, void *data,
350 			  size_t len);
351 void mipi_dsi_dcs_read_multi(struct mipi_dsi_multi_context *ctx, u8 cmd,
352 			     void *data, size_t len);
353 int mipi_dsi_dcs_nop(struct mipi_dsi_device *dsi);
354 int mipi_dsi_dcs_soft_reset(struct mipi_dsi_device *dsi);
355 int mipi_dsi_dcs_get_power_mode(struct mipi_dsi_device *dsi, u8 *mode);
356 int mipi_dsi_dcs_get_pixel_format(struct mipi_dsi_device *dsi, u8 *format);
357 int mipi_dsi_dcs_enter_sleep_mode(struct mipi_dsi_device *dsi);
358 int mipi_dsi_dcs_exit_sleep_mode(struct mipi_dsi_device *dsi);
359 int mipi_dsi_dcs_set_display_off(struct mipi_dsi_device *dsi);
360 int mipi_dsi_dcs_set_display_on(struct mipi_dsi_device *dsi);
361 int mipi_dsi_dcs_set_column_address(struct mipi_dsi_device *dsi, u16 start,
362 				    u16 end);
363 int mipi_dsi_dcs_set_page_address(struct mipi_dsi_device *dsi, u16 start,
364 				  u16 end);
365 int mipi_dsi_dcs_set_tear_on(struct mipi_dsi_device *dsi,
366 			     enum mipi_dsi_dcs_tear_mode mode);
367 int mipi_dsi_dcs_set_pixel_format(struct mipi_dsi_device *dsi, u8 format);
368 int mipi_dsi_dcs_set_tear_scanline(struct mipi_dsi_device *dsi, u16 scanline);
369 int mipi_dsi_dcs_set_display_brightness(struct mipi_dsi_device *dsi,
370 					u16 brightness);
371 int mipi_dsi_dcs_get_display_brightness(struct mipi_dsi_device *dsi,
372 					u16 *brightness);
373 int mipi_dsi_dcs_set_display_brightness_large(struct mipi_dsi_device *dsi,
374 					     u16 brightness);
375 int mipi_dsi_dcs_get_display_brightness_large(struct mipi_dsi_device *dsi,
376 					     u16 *brightness);
377 
378 void mipi_dsi_dcs_nop_multi(struct mipi_dsi_multi_context *ctx);
379 void mipi_dsi_dcs_enter_sleep_mode_multi(struct mipi_dsi_multi_context *ctx);
380 void mipi_dsi_dcs_exit_sleep_mode_multi(struct mipi_dsi_multi_context *ctx);
381 void mipi_dsi_dcs_set_display_off_multi(struct mipi_dsi_multi_context *ctx);
382 void mipi_dsi_dcs_set_display_on_multi(struct mipi_dsi_multi_context *ctx);
383 void mipi_dsi_dcs_set_tear_on_multi(struct mipi_dsi_multi_context *ctx,
384 				    enum mipi_dsi_dcs_tear_mode mode);
385 void mipi_dsi_turn_on_peripheral_multi(struct mipi_dsi_multi_context *ctx);
386 void mipi_dsi_dcs_soft_reset_multi(struct mipi_dsi_multi_context *ctx);
387 void mipi_dsi_dcs_set_display_brightness_multi(struct mipi_dsi_multi_context *ctx,
388 					       u16 brightness);
389 void mipi_dsi_dcs_set_pixel_format_multi(struct mipi_dsi_multi_context *ctx,
390 					 u8 format);
391 void mipi_dsi_dcs_set_column_address_multi(struct mipi_dsi_multi_context *ctx,
392 					   u16 start, u16 end);
393 void mipi_dsi_dcs_set_page_address_multi(struct mipi_dsi_multi_context *ctx,
394 					 u16 start, u16 end);
395 void mipi_dsi_dcs_set_tear_scanline_multi(struct mipi_dsi_multi_context *ctx,
396 					  u16 scanline);
397 void mipi_dsi_dcs_set_tear_off_multi(struct mipi_dsi_multi_context *ctx);
398 void mipi_dsi_shutdown_peripheral_multi(struct mipi_dsi_multi_context *ctx);
399 
400 /**
401  * mipi_dsi_generic_write_seq_multi - transmit data using a generic write packet
402  *
403  * This macro will print errors for you and error handling is optimized for
404  * callers that call this multiple times in a row.
405  *
406  * @ctx: Context for multiple DSI transactions
407  * @seq: buffer containing the payload
408  */
409 #define mipi_dsi_generic_write_seq_multi(ctx, seq...)                \
410 	do {                                                         \
411 		static const u8 d[] = { seq };                       \
412 		mipi_dsi_generic_write_multi(ctx, d, ARRAY_SIZE(d)); \
413 	} while (0)
414 
415 /**
416  * mipi_dsi_generic_write_var_seq_multi - transmit non-constant data using a
417  * generic write packet
418  *
419  * This macro will print errors for you and error handling is optimized for
420  * callers that call this multiple times in a row.
421  *
422  * @ctx: Context for multiple DSI transactions
423  * @seq: buffer containing the payload
424  */
425 #define mipi_dsi_generic_write_var_seq_multi(ctx, seq...)	     \
426 	do {							     \
427 		const u8 d[] = { seq };				     \
428 		mipi_dsi_generic_write_multi(ctx, d, ARRAY_SIZE(d)); \
429 	} while (0)
430 
431 /**
432  * mipi_dsi_dcs_write_seq_multi - transmit a DCS command with payload
433  *
434  * This macro will print errors for you and error handling is optimized for
435  * callers that call this multiple times in a row.
436  *
437  * @ctx: Context for multiple DSI transactions
438  * @cmd: Command
439  * @seq: buffer containing data to be transmitted
440  */
441 #define mipi_dsi_dcs_write_seq_multi(ctx, cmd, seq...)                  \
442 	do {                                                            \
443 		static const u8 d[] = { cmd, seq };                     \
444 		mipi_dsi_dcs_write_buffer_multi(ctx, d, ARRAY_SIZE(d)); \
445 	} while (0)
446 
447 /**
448  * mipi_dsi_dcs_write_var_seq_multi - transmit a DCS command with non-constant
449  * payload
450  *
451  * This macro will print errors for you and error handling is optimized for
452  * callers that call this multiple times in a row.
453  *
454  * @ctx: Context for multiple DSI transactions
455  * @cmd: Command
456  * @seq: buffer containing data to be transmitted
457  */
458 #define mipi_dsi_dcs_write_var_seq_multi(ctx, cmd, seq...)		\
459 	do {								\
460 		const u8 d[] = { cmd, seq };				\
461 		mipi_dsi_dcs_write_buffer_multi(ctx, d, ARRAY_SIZE(d));	\
462 	} while (0)
463 
464 /**
465  * mipi_dsi_dual - send the same MIPI DSI command to two interfaces
466  *
467  * This macro will send the specified MIPI DSI command twice, once per each of
468  * the two interfaces supplied. This is useful for reducing duplication of code
469  * in panel drivers which use two parallel serial interfaces.
470  *
471  * Note that the _func parameter cannot accept a macro such as
472  * mipi_dsi_generic_write_multi() or mipi_dsi_dcs_write_buffer_multi(). See
473  * mipi_dsi_dual_generic_write_multi() and
474  * mipi_dsi_dual_dcs_write_buffer_multi() instead.
475  *
476  * WARNING: This macro reuses the _func argument and the optional trailing
477  * arguments twice each, which may cause unintended side effects. For example,
478  * adding the postfix increment ++ operator to one of the arguments to be
479  * passed to _func will cause the variable to be incremented twice instead of
480  * once and the variable will be its original value + 1 when sent to _dsi2.
481  *
482  * @_func: MIPI DSI function to pass context and arguments into
483  * @_ctx: Context for multiple DSI transactions
484  * @_dsi1: First DSI interface to act as recipient of the MIPI DSI command
485  * @_dsi2: Second DSI interface to act as recipient of the MIPI DSI command
486  * @...: Arguments to pass to MIPI DSI function or macro
487  */
488 
489 #define mipi_dsi_dual(_func, _ctx, _dsi1, _dsi2, ...)		 \
490 	do {							 \
491 		struct mipi_dsi_multi_context *_ctxcpy = (_ctx); \
492 		_ctxcpy->dsi = (_dsi1);				 \
493 		(_func)(_ctxcpy, ##__VA_ARGS__);		 \
494 		_ctxcpy->dsi = (_dsi2);				 \
495 		(_func)(_ctxcpy, ##__VA_ARGS__);		 \
496 	} while (0)
497 
498 /**
499  * mipi_dsi_dual_generic_write_seq_multi - transmit data using a generic write
500  * packet to two dsi interfaces, one after the other
501  *
502  * This macro will send the specified generic packet twice, once per each of
503  * the two interfaces supplied. This is useful for reducing duplication of code
504  * in panel drivers which use two parallel serial interfaces.
505  *
506  * Note that if an error occurs while transmitting the packet to the first DSI
507  * interface, the packet will not be sent to the second DSI interface.
508  *
509  * This macro will print errors for you and error handling is optimized for
510  * callers that call this multiple times in a row.
511  *
512  * @_ctx: Context for multiple DSI transactions
513  * @_dsi1: First DSI interface to act as recipient of packet
514  * @_dsi2: Second DSI interface to act as recipient of packet
515  * @_seq: buffer containing the payload
516  */
517 #define mipi_dsi_dual_generic_write_seq_multi(_ctx, _dsi1, _dsi2, _seq...) \
518 	do {								   \
519 		static const u8 d[] = { _seq };				   \
520 		mipi_dsi_dual_generic_write_multi(_ctx, _dsi1, _dsi2, d,   \
521 						  ARRAY_SIZE(d));	   \
522 	} while (0)
523 
524 /**
525  * mipi_dsi_dual_dcs_write_seq_multi - transmit a DCS command with payload to
526  * two dsi interfaces, one after the other
527  *
528  * This macro will send the specified DCS command with payload twice, once per
529  * each of the two interfaces supplied. This is useful for reducing duplication
530  * of code in panel drivers which use two parallel serial interfaces.
531  *
532  * Note that if an error occurs while transmitting the payload to the first DSI
533  * interface, the payload will not be sent to the second DSI interface.
534  *
535  * This macro will print errors for you and error handling is optimized for
536  * callers that call this multiple times in a row.
537  *
538  * @_ctx: Context for multiple DSI transactions
539  * @_dsi1: First DSI interface to act as recipient of packet
540  * @_dsi2: Second DSI interface to act as recipient of packet
541  * @_cmd: Command
542  * @_seq: buffer containing the payload
543  */
544 #define mipi_dsi_dual_dcs_write_seq_multi(_ctx, _dsi1, _dsi2, _cmd, _seq...) \
545 	do {								     \
546 		static const u8 d[] = { _cmd, _seq };			     \
547 		mipi_dsi_dual_dcs_write_buffer_multi(_ctx, _dsi1, _dsi2, d,  \
548 						     ARRAY_SIZE(d));	     \
549 	} while (0)
550 
551 /**
552  * struct mipi_dsi_driver - DSI driver
553  * @driver: device driver model driver
554  * @probe: callback for device binding
555  * @remove: callback for device unbinding
556  * @shutdown: called at shutdown time to quiesce the device
557  */
558 struct mipi_dsi_driver {
559 	struct device_driver driver;
560 	int(*probe)(struct mipi_dsi_device *dsi);
561 	void (*remove)(struct mipi_dsi_device *dsi);
562 	void (*shutdown)(struct mipi_dsi_device *dsi);
563 };
564 
565 static inline struct mipi_dsi_driver *
566 to_mipi_dsi_driver(struct device_driver *driver)
567 {
568 	return container_of(driver, struct mipi_dsi_driver, driver);
569 }
570 
571 static inline void *mipi_dsi_get_drvdata(const struct mipi_dsi_device *dsi)
572 {
573 	return dev_get_drvdata(&dsi->dev);
574 }
575 
576 static inline void mipi_dsi_set_drvdata(struct mipi_dsi_device *dsi, void *data)
577 {
578 	dev_set_drvdata(&dsi->dev, data);
579 }
580 
581 int mipi_dsi_driver_register_full(struct mipi_dsi_driver *driver,
582 				  struct module *owner);
583 void mipi_dsi_driver_unregister(struct mipi_dsi_driver *driver);
584 
585 #define mipi_dsi_driver_register(driver) \
586 	mipi_dsi_driver_register_full(driver, THIS_MODULE)
587 
588 #define module_mipi_dsi_driver(__mipi_dsi_driver) \
589 	module_driver(__mipi_dsi_driver, mipi_dsi_driver_register, \
590 			mipi_dsi_driver_unregister)
591 
592 #endif /* __DRM_MIPI_DSI__ */
593