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