mipi_dsi.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * MIPI DSI Bus
  4. *
  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>
  10. *
  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.
  14. */
  15. #ifndef MIPI_DSI_H
  16. #define MIPI_DSI_H
  17. #include <mipi_display.h>
  18. struct mipi_dsi_host;
  19. struct mipi_dsi_device;
  20. /* request ACK from peripheral */
  21. #define MIPI_DSI_MSG_REQ_ACK BIT(0)
  22. /* use Low Power Mode to transmit message */
  23. #define MIPI_DSI_MSG_USE_LPM BIT(1)
  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. size_t tx_len;
  39. const void *tx_buf;
  40. size_t rx_len;
  41. void *rx_buf;
  42. };
  43. bool mipi_dsi_packet_format_is_short(u8 type);
  44. bool mipi_dsi_packet_format_is_long(u8 type);
  45. /**
  46. * struct mipi_dsi_packet - represents a MIPI DSI packet in protocol format
  47. * @size: size (in bytes) of the packet
  48. * @header: the four bytes that make up the header (Data ID, Word Count or
  49. * Packet Data, and ECC)
  50. * @payload_length: number of bytes in the payload
  51. * @payload: a pointer to a buffer containing the payload, if any
  52. */
  53. struct mipi_dsi_packet {
  54. size_t size;
  55. u8 header[4];
  56. size_t payload_length;
  57. const u8 *payload;
  58. };
  59. int mipi_dsi_create_packet(struct mipi_dsi_packet *packet,
  60. const struct mipi_dsi_msg *msg);
  61. /**
  62. * struct mipi_dsi_host_ops - DSI bus operations
  63. * @attach: attach DSI device to DSI host
  64. * @detach: detach DSI device from DSI host
  65. * @transfer: transmit a DSI packet
  66. *
  67. * DSI packets transmitted by .transfer() are passed in as mipi_dsi_msg
  68. * structures. This structure contains information about the type of packet
  69. * being transmitted as well as the transmit and receive buffers. When an
  70. * error is encountered during transmission, this function will return a
  71. * negative error code. On success it shall return the number of bytes
  72. * transmitted for write packets or the number of bytes received for read
  73. * packets.
  74. *
  75. * Note that typically DSI packet transmission is atomic, so the .transfer()
  76. * function will seldomly return anything other than the number of bytes
  77. * contained in the transmit buffer on success.
  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_phy_ops - DSI host physical operations
  89. * @init: initialized host physical part
  90. * @get_lane_mbps: get lane bitrate per lane (mbps)
  91. * @post_set_mode: operation that should after set mode
  92. */
  93. struct mipi_dsi_phy_ops {
  94. int (*init)(void *priv_data);
  95. int (*get_lane_mbps)(void *priv_data, struct display_timing *timings,
  96. u32 lanes, u32 format, unsigned int *lane_mbps);
  97. void (*post_set_mode)(void *priv_data, unsigned long mode_flags);
  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. /* DSI mode flags */
  111. /* video mode */
  112. #define MIPI_DSI_MODE_VIDEO BIT(0)
  113. /* video burst mode */
  114. #define MIPI_DSI_MODE_VIDEO_BURST BIT(1)
  115. /* video pulse mode */
  116. #define MIPI_DSI_MODE_VIDEO_SYNC_PULSE BIT(2)
  117. /* enable auto vertical count mode */
  118. #define MIPI_DSI_MODE_VIDEO_AUTO_VERT BIT(3)
  119. /* enable hsync-end packets in vsync-pulse and v-porch area */
  120. #define MIPI_DSI_MODE_VIDEO_HSE BIT(4)
  121. /* disable hfront-porch area */
  122. #define MIPI_DSI_MODE_VIDEO_HFP BIT(5)
  123. /* disable hback-porch area */
  124. #define MIPI_DSI_MODE_VIDEO_HBP BIT(6)
  125. /* disable hsync-active area */
  126. #define MIPI_DSI_MODE_VIDEO_HSA BIT(7)
  127. /* flush display FIFO on vsync pulse */
  128. #define MIPI_DSI_MODE_VSYNC_FLUSH BIT(8)
  129. /* disable EoT packets in HS mode */
  130. #define MIPI_DSI_MODE_EOT_PACKET BIT(9)
  131. /* device supports non-continuous clock behavior (DSI spec 5.6.1) */
  132. #define MIPI_DSI_CLOCK_NON_CONTINUOUS BIT(10)
  133. /* transmit data in low power */
  134. #define MIPI_DSI_MODE_LPM BIT(11)
  135. enum mipi_dsi_pixel_format {
  136. MIPI_DSI_FMT_RGB888,
  137. MIPI_DSI_FMT_RGB666,
  138. MIPI_DSI_FMT_RGB666_PACKED,
  139. MIPI_DSI_FMT_RGB565,
  140. };
  141. #define DSI_DEV_NAME_SIZE 20
  142. /**
  143. * struct mipi_dsi_device_info - template for creating a mipi_dsi_device
  144. * @type: DSI peripheral chip type
  145. * @channel: DSI virtual channel assigned to peripheral
  146. * @node: pointer to OF device node or NULL
  147. *
  148. * This is populated and passed to mipi_dsi_device_new to create a new
  149. * DSI device
  150. */
  151. struct mipi_dsi_device_info {
  152. char type[DSI_DEV_NAME_SIZE];
  153. u32 channel;
  154. struct device_node *node;
  155. };
  156. /**
  157. * struct mipi_dsi_device - DSI peripheral device
  158. * @host: DSI host for this peripheral
  159. * @dev: driver model device node for this peripheral
  160. * @name: DSI peripheral chip type
  161. * @channel: virtual channel assigned to the peripheral
  162. * @format: pixel format for video mode
  163. * @lanes: number of active data lanes
  164. * @mode_flags: DSI operation mode related flags
  165. */
  166. struct mipi_dsi_device {
  167. struct mipi_dsi_host *host;
  168. struct udevice *dev;
  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. };
  175. /**
  176. * mipi_dsi_pixel_format_to_bpp - obtain the number of bits per pixel for any
  177. * given pixel format defined by the MIPI DSI
  178. * specification
  179. * @fmt: MIPI DSI pixel format
  180. *
  181. * Returns: The number of bits per pixel of the given pixel format.
  182. */
  183. static inline int mipi_dsi_pixel_format_to_bpp(enum mipi_dsi_pixel_format fmt)
  184. {
  185. switch (fmt) {
  186. case MIPI_DSI_FMT_RGB888:
  187. case MIPI_DSI_FMT_RGB666:
  188. return 24;
  189. case MIPI_DSI_FMT_RGB666_PACKED:
  190. return 18;
  191. case MIPI_DSI_FMT_RGB565:
  192. return 16;
  193. }
  194. return -EINVAL;
  195. }
  196. /**
  197. * struct mipi_dsi_panel_plat - DSI panel platform data
  198. * @device: DSI peripheral device
  199. */
  200. struct mipi_dsi_panel_plat {
  201. struct mipi_dsi_device *device;
  202. };
  203. /**
  204. * mipi_dsi_attach - attach a DSI device to its DSI host
  205. * @dsi: DSI peripheral
  206. */
  207. int mipi_dsi_attach(struct mipi_dsi_device *dsi);
  208. /**
  209. * mipi_dsi_detach - detach a DSI device from its DSI host
  210. * @dsi: DSI peripheral
  211. */
  212. int mipi_dsi_detach(struct mipi_dsi_device *dsi);
  213. int mipi_dsi_shutdown_peripheral(struct mipi_dsi_device *dsi);
  214. int mipi_dsi_turn_on_peripheral(struct mipi_dsi_device *dsi);
  215. int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi,
  216. u16 value);
  217. ssize_t mipi_dsi_generic_write(struct mipi_dsi_device *dsi, const void *payload,
  218. size_t size);
  219. ssize_t mipi_dsi_generic_read(struct mipi_dsi_device *dsi, const void *params,
  220. size_t num_params, void *data, size_t size);
  221. /**
  222. * enum mipi_dsi_dcs_tear_mode - Tearing Effect Output Line mode
  223. * @MIPI_DSI_DCS_TEAR_MODE_VBLANK: the TE output line consists of V-Blanking
  224. * information only
  225. * @MIPI_DSI_DCS_TEAR_MODE_VHBLANK : the TE output line consists of both
  226. * V-Blanking and H-Blanking information
  227. */
  228. enum mipi_dsi_dcs_tear_mode {
  229. MIPI_DSI_DCS_TEAR_MODE_VBLANK,
  230. MIPI_DSI_DCS_TEAR_MODE_VHBLANK,
  231. };
  232. #define MIPI_DSI_DCS_POWER_MODE_DISPLAY BIT(2)
  233. #define MIPI_DSI_DCS_POWER_MODE_NORMAL BIT(3)
  234. #define MIPI_DSI_DCS_POWER_MODE_SLEEP BIT(4)
  235. #define MIPI_DSI_DCS_POWER_MODE_PARTIAL BIT(5)
  236. #define MIPI_DSI_DCS_POWER_MODE_IDLE BIT(6)
  237. /**
  238. * mipi_dsi_dcs_write_buffer() - transmit a DCS command with payload
  239. * @dsi: DSI peripheral device
  240. * @data: buffer containing data to be transmitted
  241. * @len: size of transmission buffer
  242. *
  243. * This function will automatically choose the right data type depending on
  244. * the command payload length.
  245. *
  246. * Return: The number of bytes successfully transmitted or a negative error
  247. * code on failure.
  248. */
  249. ssize_t mipi_dsi_dcs_write_buffer(struct mipi_dsi_device *dsi,
  250. const void *data, size_t len);
  251. /**
  252. * mipi_dsi_dcs_write() - send DCS write command
  253. * @dsi: DSI peripheral device
  254. * @cmd: DCS command
  255. * @data: buffer containing the command payload
  256. * @len: command payload length
  257. *
  258. * This function will automatically choose the right data type depending on
  259. * the command payload length.
  260. * code on failure.
  261. */
  262. ssize_t mipi_dsi_dcs_write(struct mipi_dsi_device *dsi, u8 cmd,
  263. const void *data, size_t len);
  264. /**
  265. * mipi_dsi_dcs_read() - send DCS read request command
  266. * @dsi: DSI peripheral device
  267. * @cmd: DCS command
  268. * @data: buffer in which to receive data
  269. * @len: size of receive buffer
  270. *
  271. * Return: The number of bytes read or a negative error code on failure.
  272. */
  273. ssize_t mipi_dsi_dcs_read(struct mipi_dsi_device *dsi, u8 cmd, void *data,
  274. size_t len);
  275. /**
  276. * mipi_dsi_dcs_nop() - send DCS nop packet
  277. * @dsi: DSI peripheral device
  278. *
  279. * Return: 0 on success or a negative error code on failure.
  280. */
  281. int mipi_dsi_dcs_nop(struct mipi_dsi_device *dsi);
  282. /**
  283. * mipi_dsi_dcs_soft_reset() - perform a software reset of the display module
  284. * @dsi: DSI peripheral device
  285. *
  286. * Return: 0 on success or a negative error code on failure.
  287. */
  288. int mipi_dsi_dcs_soft_reset(struct mipi_dsi_device *dsi);
  289. /**
  290. * mipi_dsi_dcs_get_power_mode() - query the display module's current power
  291. * mode
  292. * @dsi: DSI peripheral device
  293. * @mode: return location for the current power mode
  294. *
  295. * Return: 0 on success or a negative error code on failure.
  296. */
  297. int mipi_dsi_dcs_get_power_mode(struct mipi_dsi_device *dsi, u8 *mode);
  298. /**
  299. * mipi_dsi_dcs_get_pixel_format() - gets the pixel format for the RGB image
  300. * data used by the interface
  301. * @dsi: DSI peripheral device
  302. * @format: return location for the pixel format
  303. *
  304. * Return: 0 on success or a negative error code on failure.
  305. */
  306. int mipi_dsi_dcs_get_pixel_format(struct mipi_dsi_device *dsi, u8 *format);
  307. /**
  308. * mipi_dsi_dcs_enter_sleep_mode() - disable all unnecessary blocks inside the
  309. * display module except interface communication
  310. * @dsi: DSI peripheral device
  311. *
  312. * Return: 0 on success or a negative error code on failure.
  313. */
  314. int mipi_dsi_dcs_enter_sleep_mode(struct mipi_dsi_device *dsi);
  315. /**
  316. * mipi_dsi_dcs_exit_sleep_mode() - enable all blocks inside the display
  317. * module
  318. * @dsi: DSI peripheral device
  319. *
  320. * Return: 0 on success or a negative error code on failure.
  321. */
  322. int mipi_dsi_dcs_exit_sleep_mode(struct mipi_dsi_device *dsi);
  323. /**
  324. * mipi_dsi_dcs_set_display_off() - stop displaying the image data on the
  325. * display device
  326. * @dsi: DSI peripheral device
  327. *
  328. * Return: 0 on success or a negative error code on failure.
  329. */
  330. int mipi_dsi_dcs_set_display_off(struct mipi_dsi_device *dsi);
  331. /**
  332. * mipi_dsi_dcs_set_display_on() - start displaying the image data on the
  333. * display device
  334. * @dsi: DSI peripheral device
  335. *
  336. * Return: 0 on success or a negative error code on failure
  337. */
  338. int mipi_dsi_dcs_set_display_on(struct mipi_dsi_device *dsi);
  339. /**
  340. * mipi_dsi_dcs_set_column_address() - define the column extent of the frame
  341. * memory accessed by the host processor
  342. * @dsi: DSI peripheral device
  343. * @start: first column of frame memory
  344. * @end: last column of frame memory
  345. *
  346. * Return: 0 on success or a negative error code on failure.
  347. */
  348. int mipi_dsi_dcs_set_column_address(struct mipi_dsi_device *dsi, u16 start,
  349. u16 end);
  350. /**
  351. * mipi_dsi_dcs_set_page_address() - define the page extent of the frame
  352. * memory accessed by the host processor
  353. * @dsi: DSI peripheral device
  354. * @start: first page of frame memory
  355. * @end: last page of frame memory
  356. *
  357. * Return: 0 on success or a negative error code on failure.
  358. */
  359. int mipi_dsi_dcs_set_page_address(struct mipi_dsi_device *dsi, u16 start,
  360. u16 end);
  361. /**
  362. * mipi_dsi_dcs_set_tear_off() - turn off the display module's Tearing Effect
  363. * output signal on the TE signal line
  364. * @dsi: DSI peripheral device
  365. *
  366. * Return: 0 on success or a negative error code on failure
  367. */
  368. int mipi_dsi_dcs_set_tear_off(struct mipi_dsi_device *dsi);
  369. /**
  370. * mipi_dsi_dcs_set_tear_on() - turn on the display module's Tearing Effect
  371. * output signal on the TE signal line.
  372. * @dsi: DSI peripheral device
  373. * @mode: the Tearing Effect Output Line mode
  374. *
  375. * Return: 0 on success or a negative error code on failure
  376. */
  377. int mipi_dsi_dcs_set_tear_on(struct mipi_dsi_device *dsi,
  378. enum mipi_dsi_dcs_tear_mode mode);
  379. /**
  380. * mipi_dsi_dcs_set_pixel_format() - sets the pixel format for the RGB image
  381. * data used by the interface
  382. * @dsi: DSI peripheral device
  383. * @format: pixel format
  384. *
  385. * Return: 0 on success or a negative error code on failure.
  386. */
  387. int mipi_dsi_dcs_set_pixel_format(struct mipi_dsi_device *dsi, u8 format);
  388. /**
  389. * mipi_dsi_dcs_set_tear_scanline() - set the scanline to use as trigger for
  390. * the Tearing Effect output signal of the display module
  391. * @dsi: DSI peripheral device
  392. * @scanline: scanline to use as trigger
  393. *
  394. * Return: 0 on success or a negative error code on failure
  395. */
  396. int mipi_dsi_dcs_set_tear_scanline(struct mipi_dsi_device *dsi, u16 scanline);
  397. /**
  398. * mipi_dsi_dcs_set_display_brightness() - sets the brightness value of the
  399. * display
  400. * @dsi: DSI peripheral device
  401. * @brightness: brightness value
  402. *
  403. * Return: 0 on success or a negative error code on failure.
  404. */
  405. int mipi_dsi_dcs_set_display_brightness(struct mipi_dsi_device *dsi,
  406. u16 brightness);
  407. /**
  408. * mipi_dsi_dcs_get_display_brightness() - gets the current brightness value
  409. * of the display
  410. * @dsi: DSI peripheral device
  411. * @brightness: brightness value
  412. *
  413. * Return: 0 on success or a negative error code on failure.
  414. */
  415. int mipi_dsi_dcs_get_display_brightness(struct mipi_dsi_device *dsi,
  416. u16 *brightness);
  417. #endif /* MIPI_DSI_H */