1 /* SPDX-License-Identifier: GPL-2.0-or-later */
6 #ifndef _SUNXI_ENGINE_H_
7 #define _SUNXI_ENGINE_H_
12 struct drm_crtc_state;
13 struct drm_display_mode;
18 * struct sunxi_engine_ops - helper operations for sunXi engines
20 * These hooks are used by the common part of the DRM driver to
21 * implement the proper behaviour.
23 struct sunxi_engine_ops {
27 * This callback allows to prepare our engine for an atomic
28 * update. This is mirroring the
29 * &drm_crtc_helper_funcs.atomic_begin callback, so any
30 * documentation there applies.
32 * This function is optional.
34 void (*atomic_begin)(struct sunxi_engine *engine,
35 struct drm_crtc_state *old_state);
40 * This callback allows to validate plane-update related CRTC
41 * constraints specific to engines. This is mirroring the
42 * &drm_crtc_helper_funcs.atomic_check callback, so any
43 * documentation there applies.
45 * This function is optional.
49 * 0 on success or a negative error code.
51 int (*atomic_check)(struct sunxi_engine *engine,
52 struct drm_crtc_state *state);
57 * This callback will trigger the hardware switch to commit
58 * the new configuration that has been setup during the next
61 * This function is optional.
63 void (*commit)(struct sunxi_engine *engine,
64 struct drm_crtc *crtc,
65 struct drm_atomic_state *state);
70 * This callback is used to allocate, initialize and register
71 * the layers supported by that engine.
73 * This function is mandatory.
77 * The array of struct drm_plane backing the layers, or an
78 * error pointer on failure.
80 struct drm_plane **(*layers_init)(struct drm_device *drm,
81 struct sunxi_engine *engine);
84 * @apply_color_correction:
86 * This callback will enable the color correction in the
87 * engine. This is useful only for the composite output.
89 * This function is optional.
91 void (*apply_color_correction)(struct sunxi_engine *engine);
94 * @disable_color_correction:
96 * This callback will stop the color correction in the
97 * engine. This is useful only for the composite output.
99 * This function is optional.
101 void (*disable_color_correction)(struct sunxi_engine *engine);
106 * This callback is used to implement engine-specific
107 * behaviour part of the VBLANK event. It is run with all the
108 * constraints of an interrupt (can't sleep, all local
109 * interrupts disabled) and therefore should be as fast as
112 * This function is optional.
114 void (*vblank_quirk)(struct sunxi_engine *engine);
119 * This callback is used to set mode related parameters
120 * like interlacing, screen size, etc. once per mode set.
122 * This function is optional.
124 void (*mode_set)(struct sunxi_engine *engine,
125 const struct drm_display_mode *mode);
129 * struct sunxi_engine - the common parts of an engine for sun4i-drm driver
130 * @ops: the operations of the engine
131 * @node: the of device node of the engine
132 * @regs: the regmap of the engine
133 * @id: the id of the engine (-1 if not used)
135 struct sunxi_engine {
136 const struct sunxi_engine_ops *ops;
138 struct device_node *node;
143 /* Engine list management */
144 struct list_head list;
148 * sunxi_engine_commit() - commit all changes of the engine
149 * @engine: pointer to the engine
150 * @crtc: pointer to crtc the engine is associated with
151 * @state: atomic state
154 sunxi_engine_commit(struct sunxi_engine *engine,
155 struct drm_crtc *crtc,
156 struct drm_atomic_state *state)
158 if (engine->ops && engine->ops->commit)
159 engine->ops->commit(engine, crtc, state);
163 * sunxi_engine_layers_init() - Create planes (layers) for the engine
164 * @drm: pointer to the drm_device for which planes will be created
165 * @engine: pointer to the engine
167 static inline struct drm_plane **
168 sunxi_engine_layers_init(struct drm_device *drm, struct sunxi_engine *engine)
170 if (engine->ops && engine->ops->layers_init)
171 return engine->ops->layers_init(drm, engine);
172 return ERR_PTR(-ENOSYS);
176 * sunxi_engine_apply_color_correction - Apply the RGB2YUV color correction
177 * @engine: pointer to the engine
179 * This functionality is optional for an engine, however, if the engine is
180 * intended to be used with TV Encoder, the output will be incorrect
181 * without the color correction, due to TV Encoder expects the engine to
182 * output directly YUV signal.
185 sunxi_engine_apply_color_correction(struct sunxi_engine *engine)
187 if (engine->ops && engine->ops->apply_color_correction)
188 engine->ops->apply_color_correction(engine);
192 * sunxi_engine_disable_color_correction - Disable the color space correction
193 * @engine: pointer to the engine
195 * This function is paired with apply_color_correction().
198 sunxi_engine_disable_color_correction(struct sunxi_engine *engine)
200 if (engine->ops && engine->ops->disable_color_correction)
201 engine->ops->disable_color_correction(engine);
205 * sunxi_engine_mode_set - Inform engine of a new mode
206 * @engine: pointer to the engine
209 * Engine can use this functionality to set specifics once per mode change.
212 sunxi_engine_mode_set(struct sunxi_engine *engine,
213 const struct drm_display_mode *mode)
215 if (engine->ops && engine->ops->mode_set)
216 engine->ops->mode_set(engine, mode);
218 #endif /* _SUNXI_ENGINE_H_ */