mipi_dsi.h 15 KB

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