drm_mipi_dbi.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. static inline struct mipi_dbi_dev *drm_to_mipi_dbi_dev(struct drm_device *drm)
  111. {
  112. return container_of(drm, struct mipi_dbi_dev, drm);
  113. }
  114. int mipi_dbi_spi_init(struct spi_device *spi, struct mipi_dbi *dbi,
  115. struct gpio_desc *dc);
  116. int mipi_dbi_dev_init_with_formats(struct mipi_dbi_dev *dbidev,
  117. const struct drm_simple_display_pipe_funcs *funcs,
  118. const uint32_t *formats, unsigned int format_count,
  119. const struct drm_display_mode *mode,
  120. unsigned int rotation, size_t tx_buf_size);
  121. int mipi_dbi_dev_init(struct mipi_dbi_dev *dbidev,
  122. const struct drm_simple_display_pipe_funcs *funcs,
  123. const struct drm_display_mode *mode, unsigned int rotation);
  124. void mipi_dbi_pipe_update(struct drm_simple_display_pipe *pipe,
  125. struct drm_plane_state *old_state);
  126. void mipi_dbi_enable_flush(struct mipi_dbi_dev *dbidev,
  127. struct drm_crtc_state *crtc_state,
  128. struct drm_plane_state *plan_state);
  129. void mipi_dbi_pipe_disable(struct drm_simple_display_pipe *pipe);
  130. void mipi_dbi_hw_reset(struct mipi_dbi *dbi);
  131. bool mipi_dbi_display_is_on(struct mipi_dbi *dbi);
  132. int mipi_dbi_poweron_reset(struct mipi_dbi_dev *dbidev);
  133. int mipi_dbi_poweron_conditional_reset(struct mipi_dbi_dev *dbidev);
  134. u32 mipi_dbi_spi_cmd_max_speed(struct spi_device *spi, size_t len);
  135. int mipi_dbi_spi_transfer(struct spi_device *spi, u32 speed_hz,
  136. u8 bpw, const void *buf, size_t len);
  137. int mipi_dbi_command_read(struct mipi_dbi *dbi, u8 cmd, u8 *val);
  138. int mipi_dbi_command_buf(struct mipi_dbi *dbi, u8 cmd, u8 *data, size_t len);
  139. int mipi_dbi_command_stackbuf(struct mipi_dbi *dbi, u8 cmd, const u8 *data,
  140. size_t len);
  141. int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
  142. struct drm_rect *clip, bool swap);
  143. /**
  144. * mipi_dbi_command - MIPI DCS command with optional parameter(s)
  145. * @dbi: MIPI DBI structure
  146. * @cmd: Command
  147. * @seq...: Optional parameter(s)
  148. *
  149. * Send MIPI DCS command to the controller. Use mipi_dbi_command_read() for
  150. * get/read.
  151. *
  152. * Returns:
  153. * Zero on success, negative error code on failure.
  154. */
  155. #define mipi_dbi_command(dbi, cmd, seq...) \
  156. ({ \
  157. const u8 d[] = { seq }; \
  158. mipi_dbi_command_stackbuf(dbi, cmd, d, ARRAY_SIZE(d)); \
  159. })
  160. #ifdef CONFIG_DEBUG_FS
  161. void mipi_dbi_debugfs_init(struct drm_minor *minor);
  162. #else
  163. #define mipi_dbi_debugfs_init NULL
  164. #endif
  165. #endif /* __LINUX_MIPI_DBI_H */