drm_mipi_dsi.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /*
  2. * MIPI DSI Bus
  3. *
  4. * Copyright (C) 2012-2013, Samsung Electronics, Co., Ltd.
  5. * Andrzej Hajda <a.hajda@samsung.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #ifndef __DRM_MIPI_DSI_H__
  12. #define __DRM_MIPI_DSI_H__
  13. #include <linux/device.h>
  14. struct mipi_dsi_host;
  15. struct mipi_dsi_device;
  16. /* request ACK from peripheral */
  17. #define MIPI_DSI_MSG_REQ_ACK BIT(0)
  18. /* use Low Power Mode to transmit message */
  19. #define MIPI_DSI_MSG_USE_LPM BIT(1)
  20. /**
  21. * struct mipi_dsi_msg - read/write DSI buffer
  22. * @channel: virtual channel id
  23. * @type: payload data type
  24. * @flags: flags controlling this message transmission
  25. * @tx_len: length of @tx_buf
  26. * @tx_buf: data to be written
  27. * @rx_len: length of @rx_buf
  28. * @rx_buf: data to be read, or NULL
  29. */
  30. struct mipi_dsi_msg {
  31. u8 channel;
  32. u8 type;
  33. u16 flags;
  34. size_t tx_len;
  35. const void *tx_buf;
  36. size_t rx_len;
  37. void *rx_buf;
  38. };
  39. bool mipi_dsi_packet_format_is_short(u8 type);
  40. bool mipi_dsi_packet_format_is_long(u8 type);
  41. /**
  42. * struct mipi_dsi_packet - represents a MIPI DSI packet in protocol format
  43. * @size: size (in bytes) of the packet
  44. * @header: the four bytes that make up the header (Data ID, Word Count or
  45. * Packet Data, and ECC)
  46. * @payload_length: number of bytes in the payload
  47. * @payload: a pointer to a buffer containing the payload, if any
  48. */
  49. struct mipi_dsi_packet {
  50. size_t size;
  51. u8 header[4];
  52. size_t payload_length;
  53. const u8 *payload;
  54. };
  55. int mipi_dsi_create_packet(struct mipi_dsi_packet *packet,
  56. const struct mipi_dsi_msg *msg);
  57. /**
  58. * struct mipi_dsi_host_ops - DSI bus operations
  59. * @attach: attach DSI device to DSI host
  60. * @detach: detach DSI device from DSI host
  61. * @transfer: transmit a DSI packet
  62. *
  63. * DSI packets transmitted by .transfer() are passed in as mipi_dsi_msg
  64. * structures. This structure contains information about the type of packet
  65. * being transmitted as well as the transmit and receive buffers. When an
  66. * error is encountered during transmission, this function will return a
  67. * negative error code. On success it shall return the number of bytes
  68. * transmitted for write packets or the number of bytes received for read
  69. * packets.
  70. *
  71. * Note that typically DSI packet transmission is atomic, so the .transfer()
  72. * function will seldomly return anything other than the number of bytes
  73. * contained in the transmit buffer on success.
  74. */
  75. struct mipi_dsi_host_ops {
  76. int (*attach)(struct mipi_dsi_host *host,
  77. struct mipi_dsi_device *dsi);
  78. int (*detach)(struct mipi_dsi_host *host,
  79. struct mipi_dsi_device *dsi);
  80. ssize_t (*transfer)(struct mipi_dsi_host *host,
  81. const struct mipi_dsi_msg *msg);
  82. };
  83. /**
  84. * struct mipi_dsi_host - DSI host device
  85. * @dev: driver model device node for this DSI host
  86. * @ops: DSI host operations
  87. */
  88. struct mipi_dsi_host {
  89. struct device *dev;
  90. const struct mipi_dsi_host_ops *ops;
  91. };
  92. int mipi_dsi_host_register(struct mipi_dsi_host *host);
  93. void mipi_dsi_host_unregister(struct mipi_dsi_host *host);
  94. /* DSI mode flags */
  95. /* video mode */
  96. #define MIPI_DSI_MODE_VIDEO BIT(0)
  97. /* video burst mode */
  98. #define MIPI_DSI_MODE_VIDEO_BURST BIT(1)
  99. /* video pulse mode */
  100. #define MIPI_DSI_MODE_VIDEO_SYNC_PULSE BIT(2)
  101. /* enable auto vertical count mode */
  102. #define MIPI_DSI_MODE_VIDEO_AUTO_VERT BIT(3)
  103. /* enable hsync-end packets in vsync-pulse and v-porch area */
  104. #define MIPI_DSI_MODE_VIDEO_HSE BIT(4)
  105. /* disable hfront-porch area */
  106. #define MIPI_DSI_MODE_VIDEO_HFP BIT(5)
  107. /* disable hback-porch area */
  108. #define MIPI_DSI_MODE_VIDEO_HBP BIT(6)
  109. /* disable hsync-active area */
  110. #define MIPI_DSI_MODE_VIDEO_HSA BIT(7)
  111. /* flush display FIFO on vsync pulse */
  112. #define MIPI_DSI_MODE_VSYNC_FLUSH BIT(8)
  113. /* disable EoT packets in HS mode */
  114. #define MIPI_DSI_MODE_EOT_PACKET BIT(9)
  115. /* device supports non-continuous clock behavior (DSI spec 5.6.1) */
  116. #define MIPI_DSI_CLOCK_NON_CONTINUOUS BIT(10)
  117. /* transmit data in low power */
  118. #define MIPI_DSI_MODE_LPM BIT(11)
  119. enum mipi_dsi_pixel_format {
  120. MIPI_DSI_FMT_RGB888,
  121. MIPI_DSI_FMT_RGB666,
  122. MIPI_DSI_FMT_RGB666_PACKED,
  123. MIPI_DSI_FMT_RGB565,
  124. };
  125. /**
  126. * struct mipi_dsi_device - DSI peripheral device
  127. * @host: DSI host for this peripheral
  128. * @dev: driver model device node for this peripheral
  129. * @channel: virtual channel assigned to the peripheral
  130. * @format: pixel format for video mode
  131. * @lanes: number of active data lanes
  132. * @mode_flags: DSI operation mode related flags
  133. */
  134. struct mipi_dsi_device {
  135. struct mipi_dsi_host *host;
  136. struct device dev;
  137. unsigned int channel;
  138. unsigned int lanes;
  139. enum mipi_dsi_pixel_format format;
  140. unsigned long mode_flags;
  141. };
  142. static inline struct mipi_dsi_device *to_mipi_dsi_device(struct device *dev)
  143. {
  144. return container_of(dev, struct mipi_dsi_device, dev);
  145. }
  146. struct mipi_dsi_device *of_find_mipi_dsi_device_by_node(struct device_node *np);
  147. int mipi_dsi_attach(struct mipi_dsi_device *dsi);
  148. int mipi_dsi_detach(struct mipi_dsi_device *dsi);
  149. int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi,
  150. u16 value);
  151. ssize_t mipi_dsi_generic_write(struct mipi_dsi_device *dsi, const void *payload,
  152. size_t size);
  153. ssize_t mipi_dsi_generic_read(struct mipi_dsi_device *dsi, const void *params,
  154. size_t num_params, void *data, size_t size);
  155. /**
  156. * enum mipi_dsi_dcs_tear_mode - Tearing Effect Output Line mode
  157. * @MIPI_DSI_DCS_TEAR_MODE_VBLANK: the TE output line consists of V-Blanking
  158. * information only
  159. * @MIPI_DSI_DCS_TEAR_MODE_VHBLANK : the TE output line consists of both
  160. * V-Blanking and H-Blanking information
  161. */
  162. enum mipi_dsi_dcs_tear_mode {
  163. MIPI_DSI_DCS_TEAR_MODE_VBLANK,
  164. MIPI_DSI_DCS_TEAR_MODE_VHBLANK,
  165. };
  166. #define MIPI_DSI_DCS_POWER_MODE_DISPLAY (1 << 2)
  167. #define MIPI_DSI_DCS_POWER_MODE_NORMAL (1 << 3)
  168. #define MIPI_DSI_DCS_POWER_MODE_SLEEP (1 << 4)
  169. #define MIPI_DSI_DCS_POWER_MODE_PARTIAL (1 << 5)
  170. #define MIPI_DSI_DCS_POWER_MODE_IDLE (1 << 6)
  171. ssize_t mipi_dsi_dcs_write_buffer(struct mipi_dsi_device *dsi,
  172. const void *data, size_t len);
  173. ssize_t mipi_dsi_dcs_write(struct mipi_dsi_device *dsi, u8 cmd,
  174. const void *data, size_t len);
  175. ssize_t mipi_dsi_dcs_read(struct mipi_dsi_device *dsi, u8 cmd, void *data,
  176. size_t len);
  177. int mipi_dsi_dcs_nop(struct mipi_dsi_device *dsi);
  178. int mipi_dsi_dcs_soft_reset(struct mipi_dsi_device *dsi);
  179. int mipi_dsi_dcs_get_power_mode(struct mipi_dsi_device *dsi, u8 *mode);
  180. int mipi_dsi_dcs_get_pixel_format(struct mipi_dsi_device *dsi, u8 *format);
  181. int mipi_dsi_dcs_enter_sleep_mode(struct mipi_dsi_device *dsi);
  182. int mipi_dsi_dcs_exit_sleep_mode(struct mipi_dsi_device *dsi);
  183. int mipi_dsi_dcs_set_display_off(struct mipi_dsi_device *dsi);
  184. int mipi_dsi_dcs_set_display_on(struct mipi_dsi_device *dsi);
  185. int mipi_dsi_dcs_set_column_address(struct mipi_dsi_device *dsi, u16 start,
  186. u16 end);
  187. int mipi_dsi_dcs_set_page_address(struct mipi_dsi_device *dsi, u16 start,
  188. u16 end);
  189. int mipi_dsi_dcs_set_tear_off(struct mipi_dsi_device *dsi);
  190. int mipi_dsi_dcs_set_tear_on(struct mipi_dsi_device *dsi,
  191. enum mipi_dsi_dcs_tear_mode mode);
  192. int mipi_dsi_dcs_set_pixel_format(struct mipi_dsi_device *dsi, u8 format);
  193. /**
  194. * struct mipi_dsi_driver - DSI driver
  195. * @driver: device driver model driver
  196. * @probe: callback for device binding
  197. * @remove: callback for device unbinding
  198. * @shutdown: called at shutdown time to quiesce the device
  199. */
  200. struct mipi_dsi_driver {
  201. struct device_driver driver;
  202. int(*probe)(struct mipi_dsi_device *dsi);
  203. int(*remove)(struct mipi_dsi_device *dsi);
  204. void (*shutdown)(struct mipi_dsi_device *dsi);
  205. };
  206. static inline struct mipi_dsi_driver *
  207. to_mipi_dsi_driver(struct device_driver *driver)
  208. {
  209. return container_of(driver, struct mipi_dsi_driver, driver);
  210. }
  211. static inline void *mipi_dsi_get_drvdata(const struct mipi_dsi_device *dsi)
  212. {
  213. return dev_get_drvdata(&dsi->dev);
  214. }
  215. static inline void mipi_dsi_set_drvdata(struct mipi_dsi_device *dsi, void *data)
  216. {
  217. dev_set_drvdata(&dsi->dev, data);
  218. }
  219. int mipi_dsi_driver_register_full(struct mipi_dsi_driver *driver,
  220. struct module *owner);
  221. void mipi_dsi_driver_unregister(struct mipi_dsi_driver *driver);
  222. #define mipi_dsi_driver_register(driver) \
  223. mipi_dsi_driver_register_full(driver, THIS_MODULE)
  224. #define module_mipi_dsi_driver(__mipi_dsi_driver) \
  225. module_driver(__mipi_dsi_driver, mipi_dsi_driver_register, \
  226. mipi_dsi_driver_unregister)
  227. #endif /* __DRM_MIPI_DSI__ */