drm_mipi_dsi.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. * @tx_len: length of @tx_buf
  25. * @tx_buf: data to be written
  26. * @rx_len: length of @rx_buf
  27. * @rx_buf: data to be read, or NULL
  28. */
  29. struct mipi_dsi_msg {
  30. u8 channel;
  31. u8 type;
  32. u16 flags;
  33. size_t tx_len;
  34. const void *tx_buf;
  35. size_t rx_len;
  36. void *rx_buf;
  37. };
  38. /**
  39. * struct mipi_dsi_host_ops - DSI bus operations
  40. * @attach: attach DSI device to DSI host
  41. * @detach: detach DSI device from DSI host
  42. * @transfer: send and/or receive DSI packet, return number of received bytes,
  43. * or error
  44. */
  45. struct mipi_dsi_host_ops {
  46. int (*attach)(struct mipi_dsi_host *host,
  47. struct mipi_dsi_device *dsi);
  48. int (*detach)(struct mipi_dsi_host *host,
  49. struct mipi_dsi_device *dsi);
  50. ssize_t (*transfer)(struct mipi_dsi_host *host,
  51. struct mipi_dsi_msg *msg);
  52. };
  53. /**
  54. * struct mipi_dsi_host - DSI host device
  55. * @dev: driver model device node for this DSI host
  56. * @ops: DSI host operations
  57. */
  58. struct mipi_dsi_host {
  59. struct device *dev;
  60. const struct mipi_dsi_host_ops *ops;
  61. };
  62. int mipi_dsi_host_register(struct mipi_dsi_host *host);
  63. void mipi_dsi_host_unregister(struct mipi_dsi_host *host);
  64. /* DSI mode flags */
  65. /* video mode */
  66. #define MIPI_DSI_MODE_VIDEO BIT(0)
  67. /* video burst mode */
  68. #define MIPI_DSI_MODE_VIDEO_BURST BIT(1)
  69. /* video pulse mode */
  70. #define MIPI_DSI_MODE_VIDEO_SYNC_PULSE BIT(2)
  71. /* enable auto vertical count mode */
  72. #define MIPI_DSI_MODE_VIDEO_AUTO_VERT BIT(3)
  73. /* enable hsync-end packets in vsync-pulse and v-porch area */
  74. #define MIPI_DSI_MODE_VIDEO_HSE BIT(4)
  75. /* disable hfront-porch area */
  76. #define MIPI_DSI_MODE_VIDEO_HFP BIT(5)
  77. /* disable hback-porch area */
  78. #define MIPI_DSI_MODE_VIDEO_HBP BIT(6)
  79. /* disable hsync-active area */
  80. #define MIPI_DSI_MODE_VIDEO_HSA BIT(7)
  81. /* flush display FIFO on vsync pulse */
  82. #define MIPI_DSI_MODE_VSYNC_FLUSH BIT(8)
  83. /* disable EoT packets in HS mode */
  84. #define MIPI_DSI_MODE_EOT_PACKET BIT(9)
  85. /* device supports non-continuous clock behavior (DSI spec 5.6.1) */
  86. #define MIPI_DSI_CLOCK_NON_CONTINUOUS BIT(10)
  87. /* transmit data in low power */
  88. #define MIPI_DSI_MODE_LPM BIT(11)
  89. enum mipi_dsi_pixel_format {
  90. MIPI_DSI_FMT_RGB888,
  91. MIPI_DSI_FMT_RGB666,
  92. MIPI_DSI_FMT_RGB666_PACKED,
  93. MIPI_DSI_FMT_RGB565,
  94. };
  95. /**
  96. * struct mipi_dsi_device - DSI peripheral device
  97. * @host: DSI host for this peripheral
  98. * @dev: driver model device node for this peripheral
  99. * @channel: virtual channel assigned to the peripheral
  100. * @format: pixel format for video mode
  101. * @lanes: number of active data lanes
  102. * @mode_flags: DSI operation mode related flags
  103. */
  104. struct mipi_dsi_device {
  105. struct mipi_dsi_host *host;
  106. struct device dev;
  107. unsigned int channel;
  108. unsigned int lanes;
  109. enum mipi_dsi_pixel_format format;
  110. unsigned long mode_flags;
  111. };
  112. static inline struct mipi_dsi_device *to_mipi_dsi_device(struct device *dev)
  113. {
  114. return container_of(dev, struct mipi_dsi_device, dev);
  115. }
  116. int mipi_dsi_attach(struct mipi_dsi_device *dsi);
  117. int mipi_dsi_detach(struct mipi_dsi_device *dsi);
  118. ssize_t mipi_dsi_dcs_write(struct mipi_dsi_device *dsi, const void *data,
  119. size_t len);
  120. ssize_t mipi_dsi_dcs_read(struct mipi_dsi_device *dsi, u8 cmd, void *data,
  121. size_t len);
  122. /**
  123. * struct mipi_dsi_driver - DSI driver
  124. * @driver: device driver model driver
  125. * @probe: callback for device binding
  126. * @remove: callback for device unbinding
  127. * @shutdown: called at shutdown time to quiesce the device
  128. */
  129. struct mipi_dsi_driver {
  130. struct device_driver driver;
  131. int(*probe)(struct mipi_dsi_device *dsi);
  132. int(*remove)(struct mipi_dsi_device *dsi);
  133. void (*shutdown)(struct mipi_dsi_device *dsi);
  134. };
  135. static inline struct mipi_dsi_driver *
  136. to_mipi_dsi_driver(struct device_driver *driver)
  137. {
  138. return container_of(driver, struct mipi_dsi_driver, driver);
  139. }
  140. static inline void *mipi_dsi_get_drvdata(const struct mipi_dsi_device *dsi)
  141. {
  142. return dev_get_drvdata(&dsi->dev);
  143. }
  144. static inline void mipi_dsi_set_drvdata(struct mipi_dsi_device *dsi, void *data)
  145. {
  146. dev_set_drvdata(&dsi->dev, data);
  147. }
  148. int mipi_dsi_driver_register(struct mipi_dsi_driver *driver);
  149. void mipi_dsi_driver_unregister(struct mipi_dsi_driver *driver);
  150. #define module_mipi_dsi_driver(__mipi_dsi_driver) \
  151. module_driver(__mipi_dsi_driver, mipi_dsi_driver_register, \
  152. mipi_dsi_driver_unregister)
  153. #endif /* __DRM_MIPI_DSI__ */