drm_mipi_dsi.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. enum mipi_dsi_pixel_format {
  86. MIPI_DSI_FMT_RGB888,
  87. MIPI_DSI_FMT_RGB666,
  88. MIPI_DSI_FMT_RGB666_PACKED,
  89. MIPI_DSI_FMT_RGB565,
  90. };
  91. /**
  92. * struct mipi_dsi_device - DSI peripheral device
  93. * @host: DSI host for this peripheral
  94. * @dev: driver model device node for this peripheral
  95. * @channel: virtual channel assigned to the peripheral
  96. * @format: pixel format for video mode
  97. * @lanes: number of active data lanes
  98. * @mode_flags: DSI operation mode related flags
  99. */
  100. struct mipi_dsi_device {
  101. struct mipi_dsi_host *host;
  102. struct device dev;
  103. unsigned int channel;
  104. unsigned int lanes;
  105. enum mipi_dsi_pixel_format format;
  106. unsigned long mode_flags;
  107. };
  108. #define to_mipi_dsi_device(d) container_of(d, struct mipi_dsi_device, dev)
  109. int mipi_dsi_attach(struct mipi_dsi_device *dsi);
  110. int mipi_dsi_detach(struct mipi_dsi_device *dsi);
  111. int mipi_dsi_dcs_write(struct mipi_dsi_device *dsi, unsigned int channel,
  112. const void *data, size_t len);
  113. ssize_t mipi_dsi_dcs_read(struct mipi_dsi_device *dsi, unsigned int channel,
  114. u8 cmd, void *data, size_t len);
  115. /**
  116. * struct mipi_dsi_driver - DSI driver
  117. * @driver: device driver model driver
  118. * @probe: callback for device binding
  119. * @remove: callback for device unbinding
  120. * @shutdown: called at shutdown time to quiesce the device
  121. */
  122. struct mipi_dsi_driver {
  123. struct device_driver driver;
  124. int(*probe)(struct mipi_dsi_device *dsi);
  125. int(*remove)(struct mipi_dsi_device *dsi);
  126. void (*shutdown)(struct mipi_dsi_device *dsi);
  127. };
  128. #define to_mipi_dsi_driver(d) container_of(d, struct mipi_dsi_driver, driver)
  129. static inline void *mipi_dsi_get_drvdata(const struct mipi_dsi_device *dsi)
  130. {
  131. return dev_get_drvdata(&dsi->dev);
  132. }
  133. static inline void mipi_dsi_set_drvdata(struct mipi_dsi_device *dsi, void *data)
  134. {
  135. dev_set_drvdata(&dsi->dev, data);
  136. }
  137. int mipi_dsi_driver_register(struct mipi_dsi_driver *driver);
  138. void mipi_dsi_driver_unregister(struct mipi_dsi_driver *driver);
  139. #define module_mipi_dsi_driver(__mipi_dsi_driver) \
  140. module_driver(__mipi_dsi_driver, mipi_dsi_driver_register, \
  141. mipi_dsi_driver_unregister)
  142. #endif /* __DRM_MIPI_DSI__ */