drm_mipi_dsi.h 21 KB

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