sunxi_engine.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * Copyright (C) 2017 Icenowy Zheng <icenowy@aosc.io>
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of
  7. * the License, or (at your option) any later version.
  8. */
  9. #ifndef _SUNXI_ENGINE_H_
  10. #define _SUNXI_ENGINE_H_
  11. struct drm_plane;
  12. struct drm_device;
  13. struct drm_crtc_state;
  14. struct sunxi_engine;
  15. /**
  16. * struct sunxi_engine_ops - helper operations for sunXi engines
  17. *
  18. * These hooks are used by the common part of the DRM driver to
  19. * implement the proper behaviour.
  20. */
  21. struct sunxi_engine_ops {
  22. /**
  23. * @atomic_begin:
  24. *
  25. * This callback allows to prepare our engine for an atomic
  26. * update. This is mirroring the
  27. * &drm_crtc_helper_funcs.atomic_begin callback, so any
  28. * documentation there applies.
  29. *
  30. * This function is optional.
  31. */
  32. void (*atomic_begin)(struct sunxi_engine *engine,
  33. struct drm_crtc_state *old_state);
  34. /**
  35. * @atomic_check:
  36. *
  37. * This callback allows to validate plane-update related CRTC
  38. * constraints specific to engines. This is mirroring the
  39. * &drm_crtc_helper_funcs.atomic_check callback, so any
  40. * documentation there applies.
  41. *
  42. * This function is optional.
  43. *
  44. * RETURNS:
  45. *
  46. * 0 on success or a negative error code.
  47. */
  48. int (*atomic_check)(struct sunxi_engine *engine,
  49. struct drm_crtc_state *state);
  50. /**
  51. * @commit:
  52. *
  53. * This callback will trigger the hardware switch to commit
  54. * the new configuration that has been setup during the next
  55. * vblank period.
  56. *
  57. * This function is optional.
  58. */
  59. void (*commit)(struct sunxi_engine *engine);
  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. /**
  107. * struct sunxi_engine - the common parts of an engine for sun4i-drm driver
  108. * @ops: the operations of the engine
  109. * @node: the of device node of the engine
  110. * @regs: the regmap of the engine
  111. * @id: the id of the engine (-1 if not used)
  112. */
  113. struct sunxi_engine {
  114. const struct sunxi_engine_ops *ops;
  115. struct device_node *node;
  116. struct regmap *regs;
  117. int id;
  118. /* Engine list management */
  119. struct list_head list;
  120. };
  121. /**
  122. * sunxi_engine_commit() - commit all changes of the engine
  123. * @engine: pointer to the engine
  124. */
  125. static inline void
  126. sunxi_engine_commit(struct sunxi_engine *engine)
  127. {
  128. if (engine->ops && engine->ops->commit)
  129. engine->ops->commit(engine);
  130. }
  131. /**
  132. * sunxi_engine_layers_init() - Create planes (layers) for the engine
  133. * @drm: pointer to the drm_device for which planes will be created
  134. * @engine: pointer to the engine
  135. */
  136. static inline struct drm_plane **
  137. sunxi_engine_layers_init(struct drm_device *drm, struct sunxi_engine *engine)
  138. {
  139. if (engine->ops && engine->ops->layers_init)
  140. return engine->ops->layers_init(drm, engine);
  141. return ERR_PTR(-ENOSYS);
  142. }
  143. /**
  144. * sunxi_engine_apply_color_correction - Apply the RGB2YUV color correction
  145. * @engine: pointer to the engine
  146. *
  147. * This functionality is optional for an engine, however, if the engine is
  148. * intended to be used with TV Encoder, the output will be incorrect
  149. * without the color correction, due to TV Encoder expects the engine to
  150. * output directly YUV signal.
  151. */
  152. static inline void
  153. sunxi_engine_apply_color_correction(struct sunxi_engine *engine)
  154. {
  155. if (engine->ops && engine->ops->apply_color_correction)
  156. engine->ops->apply_color_correction(engine);
  157. }
  158. /**
  159. * sunxi_engine_disable_color_correction - Disable the color space correction
  160. * @engine: pointer to the engine
  161. *
  162. * This function is paired with apply_color_correction().
  163. */
  164. static inline void
  165. sunxi_engine_disable_color_correction(struct sunxi_engine *engine)
  166. {
  167. if (engine->ops && engine->ops->disable_color_correction)
  168. engine->ops->disable_color_correction(engine);
  169. }
  170. #endif /* _SUNXI_ENGINE_H_ */