1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright (C) 2017 Icenowy Zheng <icenowy@aosc.io>
6 #ifndef _SUNXI_ENGINE_H_
7 #define _SUNXI_ENGINE_H_
11 struct drm_crtc_state
;
16 * struct sunxi_engine_ops - helper operations for sunXi engines
18 * These hooks are used by the common part of the DRM driver to
19 * implement the proper behaviour.
21 struct sunxi_engine_ops
{
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.
30 * This function is optional.
32 void (*atomic_begin
)(struct sunxi_engine
*engine
,
33 struct drm_crtc_state
*old_state
);
38 * This callback allows to validate plane-update related CRTC
39 * constraints specific to engines. This is mirroring the
40 * &drm_crtc_helper_funcs.atomic_check callback, so any
41 * documentation there applies.
43 * This function is optional.
47 * 0 on success or a negative error code.
49 int (*atomic_check
)(struct sunxi_engine
*engine
,
50 struct drm_crtc_state
*state
);
55 * This callback will trigger the hardware switch to commit
56 * the new configuration that has been setup during the next
59 * This function is optional.
61 void (*commit
)(struct sunxi_engine
*engine
);
66 * This callback is used to allocate, initialize and register
67 * the layers supported by that engine.
69 * This function is mandatory.
73 * The array of struct drm_plane backing the layers, or an
74 * error pointer on failure.
76 struct drm_plane
**(*layers_init
)(struct drm_device
*drm
,
77 struct sunxi_engine
*engine
);
80 * @apply_color_correction:
82 * This callback will enable the color correction in the
83 * engine. This is useful only for the composite output.
85 * This function is optional.
87 void (*apply_color_correction
)(struct sunxi_engine
*engine
);
90 * @disable_color_correction:
92 * This callback will stop the color correction in the
93 * engine. This is useful only for the composite output.
95 * This function is optional.
97 void (*disable_color_correction
)(struct sunxi_engine
*engine
);
102 * This callback is used to implement engine-specific
103 * behaviour part of the VBLANK event. It is run with all the
104 * constraints of an interrupt (can't sleep, all local
105 * interrupts disabled) and therefore should be as fast as
108 * This function is optional.
110 void (*vblank_quirk
)(struct sunxi_engine
*engine
);
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)
120 struct sunxi_engine
{
121 const struct sunxi_engine_ops
*ops
;
123 struct device_node
*node
;
128 /* Engine list management */
129 struct list_head list
;
133 * sunxi_engine_commit() - commit all changes of the engine
134 * @engine: pointer to the engine
137 sunxi_engine_commit(struct sunxi_engine
*engine
)
139 if (engine
->ops
&& engine
->ops
->commit
)
140 engine
->ops
->commit(engine
);
144 * sunxi_engine_layers_init() - Create planes (layers) for the engine
145 * @drm: pointer to the drm_device for which planes will be created
146 * @engine: pointer to the engine
148 static inline struct drm_plane
**
149 sunxi_engine_layers_init(struct drm_device
*drm
, struct sunxi_engine
*engine
)
151 if (engine
->ops
&& engine
->ops
->layers_init
)
152 return engine
->ops
->layers_init(drm
, engine
);
153 return ERR_PTR(-ENOSYS
);
157 * sunxi_engine_apply_color_correction - Apply the RGB2YUV color correction
158 * @engine: pointer to the engine
160 * This functionality is optional for an engine, however, if the engine is
161 * intended to be used with TV Encoder, the output will be incorrect
162 * without the color correction, due to TV Encoder expects the engine to
163 * output directly YUV signal.
166 sunxi_engine_apply_color_correction(struct sunxi_engine
*engine
)
168 if (engine
->ops
&& engine
->ops
->apply_color_correction
)
169 engine
->ops
->apply_color_correction(engine
);
173 * sunxi_engine_disable_color_correction - Disable the color space correction
174 * @engine: pointer to the engine
176 * This function is paired with apply_color_correction().
179 sunxi_engine_disable_color_correction(struct sunxi_engine
*engine
)
181 if (engine
->ops
&& engine
->ops
->disable_color_correction
)
182 engine
->ops
->disable_color_correction(engine
);
184 #endif /* _SUNXI_ENGINE_H_ */