drm_mipi_dsi.h 4.3 KB

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