drm_mipi_dsi.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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. * @list: list management
  88. */
  89. struct mipi_dsi_host {
  90. struct device *dev;
  91. const struct mipi_dsi_host_ops *ops;
  92. struct list_head list;
  93. };
  94. int mipi_dsi_host_register(struct mipi_dsi_host *host);
  95. void mipi_dsi_host_unregister(struct mipi_dsi_host *host);
  96. struct mipi_dsi_host *of_find_mipi_dsi_host_by_node(struct device_node *node);
  97. /* DSI mode flags */
  98. /* video mode */
  99. #define MIPI_DSI_MODE_VIDEO BIT(0)
  100. /* video burst mode */
  101. #define MIPI_DSI_MODE_VIDEO_BURST BIT(1)
  102. /* video pulse mode */
  103. #define MIPI_DSI_MODE_VIDEO_SYNC_PULSE BIT(2)
  104. /* enable auto vertical count mode */
  105. #define MIPI_DSI_MODE_VIDEO_AUTO_VERT BIT(3)
  106. /* enable hsync-end packets in vsync-pulse and v-porch area */
  107. #define MIPI_DSI_MODE_VIDEO_HSE BIT(4)
  108. /* disable hfront-porch area */
  109. #define MIPI_DSI_MODE_VIDEO_HFP BIT(5)
  110. /* disable hback-porch area */
  111. #define MIPI_DSI_MODE_VIDEO_HBP BIT(6)
  112. /* disable hsync-active area */
  113. #define MIPI_DSI_MODE_VIDEO_HSA BIT(7)
  114. /* flush display FIFO on vsync pulse */
  115. #define MIPI_DSI_MODE_VSYNC_FLUSH BIT(8)
  116. /* disable EoT packets in HS mode */
  117. #define MIPI_DSI_MODE_EOT_PACKET BIT(9)
  118. /* device supports non-continuous clock behavior (DSI spec 5.6.1) */
  119. #define MIPI_DSI_CLOCK_NON_CONTINUOUS BIT(10)
  120. /* transmit data in low power */
  121. #define MIPI_DSI_MODE_LPM BIT(11)
  122. enum mipi_dsi_pixel_format {
  123. MIPI_DSI_FMT_RGB888,
  124. MIPI_DSI_FMT_RGB666,
  125. MIPI_DSI_FMT_RGB666_PACKED,
  126. MIPI_DSI_FMT_RGB565,
  127. };
  128. #define DSI_DEV_NAME_SIZE 20
  129. /**
  130. * struct mipi_dsi_device_info - template for creating a mipi_dsi_device
  131. * @type: DSI peripheral chip type
  132. * @channel: DSI virtual channel assigned to peripheral
  133. * @node: pointer to OF device node or NULL
  134. *
  135. * This is populated and passed to mipi_dsi_device_new to create a new
  136. * DSI device
  137. */
  138. struct mipi_dsi_device_info {
  139. char type[DSI_DEV_NAME_SIZE];
  140. u32 channel;
  141. struct device_node *node;
  142. };
  143. /**
  144. * struct mipi_dsi_device - DSI peripheral device
  145. * @host: DSI host for this peripheral
  146. * @dev: driver model device node for this peripheral
  147. * @name: DSI peripheral chip type
  148. * @channel: virtual channel assigned to the peripheral
  149. * @format: pixel format for video mode
  150. * @lanes: number of active data lanes
  151. * @mode_flags: DSI operation mode related flags
  152. */
  153. struct mipi_dsi_device {
  154. struct mipi_dsi_host *host;
  155. struct device dev;
  156. char name[DSI_DEV_NAME_SIZE];
  157. unsigned int channel;
  158. unsigned int lanes;
  159. enum mipi_dsi_pixel_format format;
  160. unsigned long mode_flags;
  161. };
  162. #define MIPI_DSI_MODULE_PREFIX "mipi-dsi:"
  163. static inline struct mipi_dsi_device *to_mipi_dsi_device(struct device *dev)
  164. {
  165. return container_of(dev, struct mipi_dsi_device, dev);
  166. }
  167. /**
  168. * mipi_dsi_pixel_format_to_bpp - obtain the number of bits per pixel for any
  169. * given pixel format defined by the MIPI DSI
  170. * specification
  171. * @fmt: MIPI DSI pixel format
  172. *
  173. * Returns: The number of bits per pixel of the given pixel format.
  174. */
  175. static inline int mipi_dsi_pixel_format_to_bpp(enum mipi_dsi_pixel_format fmt)
  176. {
  177. switch (fmt) {
  178. case MIPI_DSI_FMT_RGB888:
  179. case MIPI_DSI_FMT_RGB666:
  180. return 24;
  181. case MIPI_DSI_FMT_RGB666_PACKED:
  182. return 18;
  183. case MIPI_DSI_FMT_RGB565:
  184. return 16;
  185. }
  186. return -EINVAL;
  187. }
  188. struct mipi_dsi_device *
  189. mipi_dsi_device_register_full(struct mipi_dsi_host *host,
  190. const struct mipi_dsi_device_info *info);
  191. void mipi_dsi_device_unregister(struct mipi_dsi_device *dsi);
  192. struct mipi_dsi_device *of_find_mipi_dsi_device_by_node(struct device_node *np);
  193. int mipi_dsi_attach(struct mipi_dsi_device *dsi);
  194. int mipi_dsi_detach(struct mipi_dsi_device *dsi);
  195. int mipi_dsi_shutdown_peripheral(struct mipi_dsi_device *dsi);
  196. int mipi_dsi_turn_on_peripheral(struct mipi_dsi_device *dsi);
  197. int mipi_dsi_set_maximum_return_packet_size(struct mipi_dsi_device *dsi,
  198. u16 value);
  199. ssize_t mipi_dsi_generic_write(struct mipi_dsi_device *dsi, const void *payload,
  200. size_t size);
  201. ssize_t mipi_dsi_generic_read(struct mipi_dsi_device *dsi, const void *params,
  202. size_t num_params, void *data, size_t size);
  203. /**
  204. * enum mipi_dsi_dcs_tear_mode - Tearing Effect Output Line mode
  205. * @MIPI_DSI_DCS_TEAR_MODE_VBLANK: the TE output line consists of V-Blanking
  206. * information only
  207. * @MIPI_DSI_DCS_TEAR_MODE_VHBLANK : the TE output line consists of both
  208. * V-Blanking and H-Blanking information
  209. */
  210. enum mipi_dsi_dcs_tear_mode {
  211. MIPI_DSI_DCS_TEAR_MODE_VBLANK,
  212. MIPI_DSI_DCS_TEAR_MODE_VHBLANK,
  213. };
  214. #define MIPI_DSI_DCS_POWER_MODE_DISPLAY (1 << 2)
  215. #define MIPI_DSI_DCS_POWER_MODE_NORMAL (1 << 3)
  216. #define MIPI_DSI_DCS_POWER_MODE_SLEEP (1 << 4)
  217. #define MIPI_DSI_DCS_POWER_MODE_PARTIAL (1 << 5)
  218. #define MIPI_DSI_DCS_POWER_MODE_IDLE (1 << 6)
  219. ssize_t mipi_dsi_dcs_write_buffer(struct mipi_dsi_device *dsi,
  220. const void *data, size_t len);
  221. ssize_t mipi_dsi_dcs_write(struct mipi_dsi_device *dsi, u8 cmd,
  222. const void *data, size_t len);
  223. ssize_t mipi_dsi_dcs_read(struct mipi_dsi_device *dsi, u8 cmd, void *data,
  224. size_t len);
  225. int mipi_dsi_dcs_nop(struct mipi_dsi_device *dsi);
  226. int mipi_dsi_dcs_soft_reset(struct mipi_dsi_device *dsi);
  227. int mipi_dsi_dcs_get_power_mode(struct mipi_dsi_device *dsi, u8 *mode);
  228. int mipi_dsi_dcs_get_pixel_format(struct mipi_dsi_device *dsi, u8 *format);
  229. int mipi_dsi_dcs_enter_sleep_mode(struct mipi_dsi_device *dsi);
  230. int mipi_dsi_dcs_exit_sleep_mode(struct mipi_dsi_device *dsi);
  231. int mipi_dsi_dcs_set_display_off(struct mipi_dsi_device *dsi);
  232. int mipi_dsi_dcs_set_display_on(struct mipi_dsi_device *dsi);
  233. int mipi_dsi_dcs_set_column_address(struct mipi_dsi_device *dsi, u16 start,
  234. u16 end);
  235. int mipi_dsi_dcs_set_page_address(struct mipi_dsi_device *dsi, u16 start,
  236. u16 end);
  237. int mipi_dsi_dcs_set_tear_off(struct mipi_dsi_device *dsi);
  238. int mipi_dsi_dcs_set_tear_on(struct mipi_dsi_device *dsi,
  239. enum mipi_dsi_dcs_tear_mode mode);
  240. int mipi_dsi_dcs_set_pixel_format(struct mipi_dsi_device *dsi, u8 format);
  241. int mipi_dsi_dcs_set_tear_scanline(struct mipi_dsi_device *dsi, u16 scanline);
  242. int mipi_dsi_dcs_set_display_brightness(struct mipi_dsi_device *dsi,
  243. u16 brightness);
  244. int mipi_dsi_dcs_get_display_brightness(struct mipi_dsi_device *dsi,
  245. u16 *brightness);
  246. /**
  247. * struct mipi_dsi_driver - DSI driver
  248. * @driver: device driver model driver
  249. * @probe: callback for device binding
  250. * @remove: callback for device unbinding
  251. * @shutdown: called at shutdown time to quiesce the device
  252. */
  253. struct mipi_dsi_driver {
  254. struct device_driver driver;
  255. int(*probe)(struct mipi_dsi_device *dsi);
  256. int(*remove)(struct mipi_dsi_device *dsi);
  257. void (*shutdown)(struct mipi_dsi_device *dsi);
  258. };
  259. static inline struct mipi_dsi_driver *
  260. to_mipi_dsi_driver(struct device_driver *driver)
  261. {
  262. return container_of(driver, struct mipi_dsi_driver, driver);
  263. }
  264. static inline void *mipi_dsi_get_drvdata(const struct mipi_dsi_device *dsi)
  265. {
  266. return dev_get_drvdata(&dsi->dev);
  267. }
  268. static inline void mipi_dsi_set_drvdata(struct mipi_dsi_device *dsi, void *data)
  269. {
  270. dev_set_drvdata(&dsi->dev, data);
  271. }
  272. int mipi_dsi_driver_register_full(struct mipi_dsi_driver *driver,
  273. struct module *owner);
  274. void mipi_dsi_driver_unregister(struct mipi_dsi_driver *driver);
  275. #define mipi_dsi_driver_register(driver) \
  276. mipi_dsi_driver_register_full(driver, THIS_MODULE)
  277. #define module_mipi_dsi_driver(__mipi_dsi_driver) \
  278. module_driver(__mipi_dsi_driver, mipi_dsi_driver_register, \
  279. mipi_dsi_driver_unregister)
  280. #endif /* __DRM_MIPI_DSI__ */