sunxi_engine.h 5.4 KB

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