sunxi_engine.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (C) 2017 Icenowy Zheng <icenowy@aosc.io>
  4. */
  5. #ifndef _SUNXI_ENGINE_H_
  6. #define _SUNXI_ENGINE_H_
  7. struct drm_plane;
  8. struct drm_crtc;
  9. struct drm_device;
  10. struct drm_crtc_state;
  11. struct drm_display_mode;
  12. struct sunxi_engine;
  13. /**
  14. * struct sunxi_engine_ops - helper operations for sunXi engines
  15. *
  16. * These hooks are used by the common part of the DRM driver to
  17. * implement the proper behaviour.
  18. */
  19. struct sunxi_engine_ops {
  20. /**
  21. * @atomic_begin:
  22. *
  23. * This callback allows to prepare our engine for an atomic
  24. * update. This is mirroring the
  25. * &drm_crtc_helper_funcs.atomic_begin callback, so any
  26. * documentation there applies.
  27. *
  28. * This function is optional.
  29. */
  30. void (*atomic_begin)(struct sunxi_engine *engine,
  31. struct drm_crtc_state *old_state);
  32. /**
  33. * @atomic_check:
  34. *
  35. * This callback allows to validate plane-update related CRTC
  36. * constraints specific to engines. This is mirroring the
  37. * &drm_crtc_helper_funcs.atomic_check callback, so any
  38. * documentation there applies.
  39. *
  40. * This function is optional.
  41. *
  42. * RETURNS:
  43. *
  44. * 0 on success or a negative error code.
  45. */
  46. int (*atomic_check)(struct sunxi_engine *engine,
  47. struct drm_crtc_state *state);
  48. /**
  49. * @commit:
  50. *
  51. * This callback will trigger the hardware switch to commit
  52. * the new configuration that has been setup during the next
  53. * vblank period.
  54. *
  55. * This function is optional.
  56. */
  57. void (*commit)(struct sunxi_engine *engine,
  58. struct drm_crtc *crtc,
  59. struct drm_atomic_state *state);
  60. /**
  61. * @layers_init:
  62. *
  63. * This callback is used to allocate, initialize and register
  64. * the layers supported by that engine.
  65. *
  66. * This function is mandatory.
  67. *
  68. * RETURNS:
  69. *
  70. * The array of struct drm_plane backing the layers, or an
  71. * error pointer on failure.
  72. */
  73. struct drm_plane **(*layers_init)(struct drm_device *drm,
  74. struct sunxi_engine *engine);
  75. /**
  76. * @apply_color_correction:
  77. *
  78. * This callback will enable the color correction in the
  79. * engine. This is useful only for the composite output.
  80. *
  81. * This function is optional.
  82. */
  83. void (*apply_color_correction)(struct sunxi_engine *engine);
  84. /**
  85. * @disable_color_correction:
  86. *
  87. * This callback will stop the color correction in the
  88. * engine. This is useful only for the composite output.
  89. *
  90. * This function is optional.
  91. */
  92. void (*disable_color_correction)(struct sunxi_engine *engine);
  93. /**
  94. * @vblank_quirk:
  95. *
  96. * This callback is used to implement engine-specific
  97. * behaviour part of the VBLANK event. It is run with all the
  98. * constraints of an interrupt (can't sleep, all local
  99. * interrupts disabled) and therefore should be as fast as
  100. * possible.
  101. *
  102. * This function is optional.
  103. */
  104. void (*vblank_quirk)(struct sunxi_engine *engine);
  105. /**
  106. * @mode_set
  107. *
  108. * This callback is used to set mode related parameters
  109. * like interlacing, screen size, etc. once per mode set.
  110. *
  111. * This function is optional.
  112. */
  113. void (*mode_set)(struct sunxi_engine *engine,
  114. const struct drm_display_mode *mode);
  115. };
  116. /**
  117. * struct sunxi_engine - the common parts of an engine for sun4i-drm driver
  118. * @ops: the operations of the engine
  119. * @node: the of device node of the engine
  120. * @regs: the regmap of the engine
  121. * @id: the id of the engine (-1 if not used)
  122. */
  123. struct sunxi_engine {
  124. const struct sunxi_engine_ops *ops;
  125. struct device_node *node;
  126. struct regmap *regs;
  127. int id;
  128. /* Engine list management */
  129. struct list_head list;
  130. };
  131. /**
  132. * sunxi_engine_commit() - commit all changes of the engine
  133. * @engine: pointer to the engine
  134. * @crtc: pointer to crtc the engine is associated with
  135. * @state: atomic state
  136. */
  137. static inline void
  138. sunxi_engine_commit(struct sunxi_engine *engine,
  139. struct drm_crtc *crtc,
  140. struct drm_atomic_state *state)
  141. {
  142. if (engine->ops && engine->ops->commit)
  143. engine->ops->commit(engine, crtc, state);
  144. }
  145. /**
  146. * sunxi_engine_layers_init() - Create planes (layers) for the engine
  147. * @drm: pointer to the drm_device for which planes will be created
  148. * @engine: pointer to the engine
  149. */
  150. static inline struct drm_plane **
  151. sunxi_engine_layers_init(struct drm_device *drm, struct sunxi_engine *engine)
  152. {
  153. if (engine->ops && engine->ops->layers_init)
  154. return engine->ops->layers_init(drm, engine);
  155. return ERR_PTR(-ENOSYS);
  156. }
  157. /**
  158. * sunxi_engine_apply_color_correction - Apply the RGB2YUV color correction
  159. * @engine: pointer to the engine
  160. *
  161. * This functionality is optional for an engine, however, if the engine is
  162. * intended to be used with TV Encoder, the output will be incorrect
  163. * without the color correction, due to TV Encoder expects the engine to
  164. * output directly YUV signal.
  165. */
  166. static inline void
  167. sunxi_engine_apply_color_correction(struct sunxi_engine *engine)
  168. {
  169. if (engine->ops && engine->ops->apply_color_correction)
  170. engine->ops->apply_color_correction(engine);
  171. }
  172. /**
  173. * sunxi_engine_disable_color_correction - Disable the color space correction
  174. * @engine: pointer to the engine
  175. *
  176. * This function is paired with apply_color_correction().
  177. */
  178. static inline void
  179. sunxi_engine_disable_color_correction(struct sunxi_engine *engine)
  180. {
  181. if (engine->ops && engine->ops->disable_color_correction)
  182. engine->ops->disable_color_correction(engine);
  183. }
  184. /**
  185. * sunxi_engine_mode_set - Inform engine of a new mode
  186. * @engine: pointer to the engine
  187. * @mode: new mode
  188. *
  189. * Engine can use this functionality to set specifics once per mode change.
  190. */
  191. static inline void
  192. sunxi_engine_mode_set(struct sunxi_engine *engine,
  193. const struct drm_display_mode *mode)
  194. {
  195. if (engine->ops && engine->ops->mode_set)
  196. engine->ops->mode_set(engine, mode);
  197. }
  198. #endif /* _SUNXI_ENGINE_H_ */