drm_mipi_dbi.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * MIPI Display Bus Interface (DBI) LCD controller support
  4. *
  5. * Copyright 2016 Noralf Trønnes
  6. */
  7. #ifndef __LINUX_MIPI_DBI_H
  8. #define __LINUX_MIPI_DBI_H
  9. #include <linux/mutex.h>
  10. #include <drm/drm_device.h>
  11. #include <drm/drm_simple_kms_helper.h>
  12. struct drm_rect;
  13. struct spi_device;
  14. struct gpio_desc;
  15. struct regulator;
  16. /**
  17. * struct mipi_dbi - MIPI DBI interface
  18. */
  19. struct mipi_dbi {
  20. /**
  21. * @cmdlock: Command lock
  22. */
  23. struct mutex cmdlock;
  24. /**
  25. * @command: Bus specific callback executing commands.
  26. */
  27. int (*command)(struct mipi_dbi *dbi, u8 *cmd, u8 *param, size_t num);
  28. /**
  29. * @read_commands: Array of read commands terminated by a zero entry.
  30. * Reading is disabled if this is NULL.
  31. */
  32. const u8 *read_commands;
  33. /**
  34. * @swap_bytes: Swap bytes in buffer before transfer
  35. */
  36. bool swap_bytes;
  37. /**
  38. * @reset: Optional reset gpio
  39. */
  40. struct gpio_desc *reset;
  41. /* Type C specific */
  42. /**
  43. * @spi: SPI device
  44. */
  45. struct spi_device *spi;
  46. /**
  47. * @dc: Optional D/C gpio.
  48. */
  49. struct gpio_desc *dc;
  50. /**
  51. * @tx_buf9: Buffer used for Option 1 9-bit conversion
  52. */
  53. void *tx_buf9;
  54. /**
  55. * @tx_buf9_len: Size of tx_buf9.
  56. */
  57. size_t tx_buf9_len;
  58. };
  59. /**
  60. * struct mipi_dbi_dev - MIPI DBI device
  61. */
  62. struct mipi_dbi_dev {
  63. /**
  64. * @drm: DRM device
  65. */
  66. struct drm_device drm;
  67. /**
  68. * @pipe: Display pipe structure
  69. */
  70. struct drm_simple_display_pipe pipe;
  71. /**
  72. * @connector: Connector
  73. */
  74. struct drm_connector connector;
  75. /**
  76. * @mode: Fixed display mode
  77. */
  78. struct drm_display_mode mode;
  79. /**
  80. * @tx_buf: Buffer used for transfer (copy clip rect area)
  81. */
  82. u16 *tx_buf;
  83. /**
  84. * @rotation: initial rotation in degrees Counter Clock Wise
  85. */
  86. unsigned int rotation;
  87. /**
  88. * @left_offset: Horizontal offset of the display relative to the
  89. * controller's driver array
  90. */
  91. unsigned int left_offset;
  92. /**
  93. * @top_offset: Vertical offset of the display relative to the
  94. * controller's driver array
  95. */
  96. unsigned int top_offset;
  97. /**
  98. * @backlight: backlight device (optional)
  99. */
  100. struct backlight_device *backlight;
  101. /**
  102. * @regulator: power regulator (optional)
  103. */
  104. struct regulator *regulator;
  105. /**
  106. * @dbi: MIPI DBI interface
  107. */
  108. struct mipi_dbi dbi;
  109. /**
  110. * @driver_private: Driver private data.
  111. * Necessary for drivers with private data since devm_drm_dev_alloc()
  112. * can't allocate structures that embed a structure which then again
  113. * embeds drm_device.
  114. */
  115. void *driver_private;
  116. };
  117. static inline struct mipi_dbi_dev *drm_to_mipi_dbi_dev(struct drm_device *drm)
  118. {
  119. return container_of(drm, struct mipi_dbi_dev, drm);
  120. }
  121. int mipi_dbi_spi_init(struct spi_device *spi, struct mipi_dbi *dbi,
  122. struct gpio_desc *dc);
  123. int mipi_dbi_dev_init_with_formats(struct mipi_dbi_dev *dbidev,
  124. const struct drm_simple_display_pipe_funcs *funcs,
  125. const uint32_t *formats, unsigned int format_count,
  126. const struct drm_display_mode *mode,
  127. unsigned int rotation, size_t tx_buf_size);
  128. int mipi_dbi_dev_init(struct mipi_dbi_dev *dbidev,
  129. const struct drm_simple_display_pipe_funcs *funcs,
  130. const struct drm_display_mode *mode, unsigned int rotation);
  131. enum drm_mode_status mipi_dbi_pipe_mode_valid(struct drm_simple_display_pipe *pipe,
  132. const struct drm_display_mode *mode);
  133. void mipi_dbi_pipe_update(struct drm_simple_display_pipe *pipe,
  134. struct drm_plane_state *old_state);
  135. void mipi_dbi_enable_flush(struct mipi_dbi_dev *dbidev,
  136. struct drm_crtc_state *crtc_state,
  137. struct drm_plane_state *plan_state);
  138. void mipi_dbi_pipe_disable(struct drm_simple_display_pipe *pipe);
  139. void mipi_dbi_hw_reset(struct mipi_dbi *dbi);
  140. bool mipi_dbi_display_is_on(struct mipi_dbi *dbi);
  141. int mipi_dbi_poweron_reset(struct mipi_dbi_dev *dbidev);
  142. int mipi_dbi_poweron_conditional_reset(struct mipi_dbi_dev *dbidev);
  143. u32 mipi_dbi_spi_cmd_max_speed(struct spi_device *spi, size_t len);
  144. int mipi_dbi_spi_transfer(struct spi_device *spi, u32 speed_hz,
  145. u8 bpw, const void *buf, size_t len);
  146. int mipi_dbi_command_read(struct mipi_dbi *dbi, u8 cmd, u8 *val);
  147. int mipi_dbi_command_buf(struct mipi_dbi *dbi, u8 cmd, u8 *data, size_t len);
  148. int mipi_dbi_command_stackbuf(struct mipi_dbi *dbi, u8 cmd, const u8 *data,
  149. size_t len);
  150. int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
  151. struct drm_rect *clip, bool swap);
  152. /**
  153. * mipi_dbi_command - MIPI DCS command with optional parameter(s)
  154. * @dbi: MIPI DBI structure
  155. * @cmd: Command
  156. * @seq: Optional parameter(s)
  157. *
  158. * Send MIPI DCS command to the controller. Use mipi_dbi_command_read() for
  159. * get/read.
  160. *
  161. * Returns:
  162. * Zero on success, negative error code on failure.
  163. */
  164. #define mipi_dbi_command(dbi, cmd, seq...) \
  165. ({ \
  166. const u8 d[] = { seq }; \
  167. struct device *dev = &(dbi)->spi->dev; \
  168. int ret; \
  169. ret = mipi_dbi_command_stackbuf(dbi, cmd, d, ARRAY_SIZE(d)); \
  170. if (ret) \
  171. dev_err_ratelimited(dev, "error %d when sending command %#02x\n", ret, cmd); \
  172. ret; \
  173. })
  174. #ifdef CONFIG_DEBUG_FS
  175. void mipi_dbi_debugfs_init(struct drm_minor *minor);
  176. #else
  177. static inline void mipi_dbi_debugfs_init(struct drm_minor *minor) {}
  178. #endif
  179. #endif /* __LINUX_MIPI_DBI_H */