sunxi_engine.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 sunxi_engine;
  14. struct sunxi_engine_ops {
  15. void (*commit)(struct sunxi_engine *engine);
  16. struct drm_plane **(*layers_init)(struct drm_device *drm,
  17. struct sunxi_engine *engine);
  18. void (*apply_color_correction)(struct sunxi_engine *engine);
  19. void (*disable_color_correction)(struct sunxi_engine *engine);
  20. };
  21. /**
  22. * struct sunxi_engine - the common parts of an engine for sun4i-drm driver
  23. * @ops: the operations of the engine
  24. * @node: the of device node of the engine
  25. * @regs: the regmap of the engine
  26. * @id: the id of the engine (-1 if not used)
  27. */
  28. struct sunxi_engine {
  29. const struct sunxi_engine_ops *ops;
  30. struct device_node *node;
  31. struct regmap *regs;
  32. int id;
  33. /* Engine list management */
  34. struct list_head list;
  35. };
  36. /**
  37. * sunxi_engine_commit() - commit all changes of the engine
  38. * @engine: pointer to the engine
  39. */
  40. static inline void
  41. sunxi_engine_commit(struct sunxi_engine *engine)
  42. {
  43. if (engine->ops && engine->ops->commit)
  44. engine->ops->commit(engine);
  45. }
  46. /**
  47. * sunxi_engine_layers_init() - Create planes (layers) for the engine
  48. * @drm: pointer to the drm_device for which planes will be created
  49. * @engine: pointer to the engine
  50. */
  51. static inline struct drm_plane **
  52. sunxi_engine_layers_init(struct drm_device *drm, struct sunxi_engine *engine)
  53. {
  54. if (engine->ops && engine->ops->layers_init)
  55. return engine->ops->layers_init(drm, engine);
  56. return ERR_PTR(-ENOSYS);
  57. }
  58. /**
  59. * sunxi_engine_apply_color_correction - Apply the RGB2YUV color correction
  60. * @engine: pointer to the engine
  61. *
  62. * This functionality is optional for an engine, however, if the engine is
  63. * intended to be used with TV Encoder, the output will be incorrect
  64. * without the color correction, due to TV Encoder expects the engine to
  65. * output directly YUV signal.
  66. */
  67. static inline void
  68. sunxi_engine_apply_color_correction(struct sunxi_engine *engine)
  69. {
  70. if (engine->ops && engine->ops->apply_color_correction)
  71. engine->ops->apply_color_correction(engine);
  72. }
  73. /**
  74. * sunxi_engine_disable_color_correction - Disable the color space correction
  75. * @engine: pointer to the engine
  76. *
  77. * This function is paired with apply_color_correction().
  78. */
  79. static inline void
  80. sunxi_engine_disable_color_correction(struct sunxi_engine *engine)
  81. {
  82. if (engine->ops && engine->ops->disable_color_correction)
  83. engine->ops->disable_color_correction(engine);
  84. }
  85. #endif /* _SUNXI_ENGINE_H_ */