mipi_dsi.h 14 KB

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