12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
287969338SIcenowy Zheng /*
387969338SIcenowy Zheng * Copyright (C) 2017 Icenowy Zheng <icenowy@aosc.io>
487969338SIcenowy Zheng */
587969338SIcenowy Zheng
687969338SIcenowy Zheng #ifndef _SUNXI_ENGINE_H_
787969338SIcenowy Zheng #define _SUNXI_ENGINE_H_
887969338SIcenowy Zheng
987969338SIcenowy Zheng struct drm_plane;
10*aa0b4a69SOndrej Jirman struct drm_crtc;
1187969338SIcenowy Zheng struct drm_device;
12a63b8e79SSean Paul struct drm_crtc_state;
13f7e974a3SJernej Skrabec struct drm_display_mode;
1487969338SIcenowy Zheng
1587969338SIcenowy Zheng struct sunxi_engine;
1687969338SIcenowy Zheng
17c4c7c72eSMaxime Ripard /**
18c4c7c72eSMaxime Ripard * struct sunxi_engine_ops - helper operations for sunXi engines
19c4c7c72eSMaxime Ripard *
20c4c7c72eSMaxime Ripard * These hooks are used by the common part of the DRM driver to
21c4c7c72eSMaxime Ripard * implement the proper behaviour.
22c4c7c72eSMaxime Ripard */
2387969338SIcenowy Zheng struct sunxi_engine_ops {
24c4c7c72eSMaxime Ripard /**
256b8562c8SMaxime Ripard * @atomic_begin:
266b8562c8SMaxime Ripard *
276b8562c8SMaxime Ripard * This callback allows to prepare our engine for an atomic
286b8562c8SMaxime Ripard * update. This is mirroring the
296b8562c8SMaxime Ripard * &drm_crtc_helper_funcs.atomic_begin callback, so any
306b8562c8SMaxime Ripard * documentation there applies.
316b8562c8SMaxime Ripard *
326b8562c8SMaxime Ripard * This function is optional.
336b8562c8SMaxime Ripard */
346b8562c8SMaxime Ripard void (*atomic_begin)(struct sunxi_engine *engine,
356b8562c8SMaxime Ripard struct drm_crtc_state *old_state);
366b8562c8SMaxime Ripard
376b8562c8SMaxime Ripard /**
38656e5f65SMaxime Ripard * @atomic_check:
39656e5f65SMaxime Ripard *
40656e5f65SMaxime Ripard * This callback allows to validate plane-update related CRTC
41656e5f65SMaxime Ripard * constraints specific to engines. This is mirroring the
42656e5f65SMaxime Ripard * &drm_crtc_helper_funcs.atomic_check callback, so any
43656e5f65SMaxime Ripard * documentation there applies.
44656e5f65SMaxime Ripard *
45656e5f65SMaxime Ripard * This function is optional.
46656e5f65SMaxime Ripard *
47656e5f65SMaxime Ripard * RETURNS:
48656e5f65SMaxime Ripard *
49656e5f65SMaxime Ripard * 0 on success or a negative error code.
50656e5f65SMaxime Ripard */
51656e5f65SMaxime Ripard int (*atomic_check)(struct sunxi_engine *engine,
52656e5f65SMaxime Ripard struct drm_crtc_state *state);
53656e5f65SMaxime Ripard
54656e5f65SMaxime Ripard /**
55c4c7c72eSMaxime Ripard * @commit:
56c4c7c72eSMaxime Ripard *
57c4c7c72eSMaxime Ripard * This callback will trigger the hardware switch to commit
58c4c7c72eSMaxime Ripard * the new configuration that has been setup during the next
59c4c7c72eSMaxime Ripard * vblank period.
60c4c7c72eSMaxime Ripard *
61c4c7c72eSMaxime Ripard * This function is optional.
62c4c7c72eSMaxime Ripard */
63*aa0b4a69SOndrej Jirman void (*commit)(struct sunxi_engine *engine,
64*aa0b4a69SOndrej Jirman struct drm_crtc *crtc,
65*aa0b4a69SOndrej Jirman struct drm_atomic_state *state);
66c4c7c72eSMaxime Ripard
67c4c7c72eSMaxime Ripard /**
68c4c7c72eSMaxime Ripard * @layers_init:
69c4c7c72eSMaxime Ripard *
70c4c7c72eSMaxime Ripard * This callback is used to allocate, initialize and register
71c4c7c72eSMaxime Ripard * the layers supported by that engine.
72c4c7c72eSMaxime Ripard *
73c4c7c72eSMaxime Ripard * This function is mandatory.
74c4c7c72eSMaxime Ripard *
75c4c7c72eSMaxime Ripard * RETURNS:
76c4c7c72eSMaxime Ripard *
77c4c7c72eSMaxime Ripard * The array of struct drm_plane backing the layers, or an
78c4c7c72eSMaxime Ripard * error pointer on failure.
79c4c7c72eSMaxime Ripard */
8087969338SIcenowy Zheng struct drm_plane **(*layers_init)(struct drm_device *drm,
8187969338SIcenowy Zheng struct sunxi_engine *engine);
8287969338SIcenowy Zheng
83c4c7c72eSMaxime Ripard /**
84c4c7c72eSMaxime Ripard * @apply_color_correction:
85c4c7c72eSMaxime Ripard *
86c4c7c72eSMaxime Ripard * This callback will enable the color correction in the
87c4c7c72eSMaxime Ripard * engine. This is useful only for the composite output.
88c4c7c72eSMaxime Ripard *
89c4c7c72eSMaxime Ripard * This function is optional.
90c4c7c72eSMaxime Ripard */
9187969338SIcenowy Zheng void (*apply_color_correction)(struct sunxi_engine *engine);
92c4c7c72eSMaxime Ripard
93c4c7c72eSMaxime Ripard /**
94c4c7c72eSMaxime Ripard * @disable_color_correction:
95c4c7c72eSMaxime Ripard *
96c4c7c72eSMaxime Ripard * This callback will stop the color correction in the
97c4c7c72eSMaxime Ripard * engine. This is useful only for the composite output.
98c4c7c72eSMaxime Ripard *
99c4c7c72eSMaxime Ripard * This function is optional.
100c4c7c72eSMaxime Ripard */
10187969338SIcenowy Zheng void (*disable_color_correction)(struct sunxi_engine *engine);
1023004f75fSMaxime Ripard
1033004f75fSMaxime Ripard /**
1043004f75fSMaxime Ripard * @vblank_quirk:
1053004f75fSMaxime Ripard *
1063004f75fSMaxime Ripard * This callback is used to implement engine-specific
1073004f75fSMaxime Ripard * behaviour part of the VBLANK event. It is run with all the
1083004f75fSMaxime Ripard * constraints of an interrupt (can't sleep, all local
1093004f75fSMaxime Ripard * interrupts disabled) and therefore should be as fast as
1103004f75fSMaxime Ripard * possible.
1113004f75fSMaxime Ripard *
1123004f75fSMaxime Ripard * This function is optional.
1133004f75fSMaxime Ripard */
1143004f75fSMaxime Ripard void (*vblank_quirk)(struct sunxi_engine *engine);
115f7e974a3SJernej Skrabec
116f7e974a3SJernej Skrabec /**
117f7e974a3SJernej Skrabec * @mode_set
118f7e974a3SJernej Skrabec *
119f7e974a3SJernej Skrabec * This callback is used to set mode related parameters
120f7e974a3SJernej Skrabec * like interlacing, screen size, etc. once per mode set.
121f7e974a3SJernej Skrabec *
122f7e974a3SJernej Skrabec * This function is optional.
123f7e974a3SJernej Skrabec */
124f7e974a3SJernej Skrabec void (*mode_set)(struct sunxi_engine *engine,
125f7e974a3SJernej Skrabec const struct drm_display_mode *mode);
12687969338SIcenowy Zheng };
12787969338SIcenowy Zheng
12887969338SIcenowy Zheng /**
12987969338SIcenowy Zheng * struct sunxi_engine - the common parts of an engine for sun4i-drm driver
13087969338SIcenowy Zheng * @ops: the operations of the engine
13187969338SIcenowy Zheng * @node: the of device node of the engine
13287969338SIcenowy Zheng * @regs: the regmap of the engine
13387969338SIcenowy Zheng * @id: the id of the engine (-1 if not used)
13487969338SIcenowy Zheng */
13587969338SIcenowy Zheng struct sunxi_engine {
13687969338SIcenowy Zheng const struct sunxi_engine_ops *ops;
13787969338SIcenowy Zheng
13887969338SIcenowy Zheng struct device_node *node;
13987969338SIcenowy Zheng struct regmap *regs;
14087969338SIcenowy Zheng
14187969338SIcenowy Zheng int id;
14287969338SIcenowy Zheng
14387969338SIcenowy Zheng /* Engine list management */
14487969338SIcenowy Zheng struct list_head list;
14587969338SIcenowy Zheng };
14687969338SIcenowy Zheng
14787969338SIcenowy Zheng /**
14887969338SIcenowy Zheng * sunxi_engine_commit() - commit all changes of the engine
14987969338SIcenowy Zheng * @engine: pointer to the engine
150*aa0b4a69SOndrej Jirman * @crtc: pointer to crtc the engine is associated with
151*aa0b4a69SOndrej Jirman * @state: atomic state
15287969338SIcenowy Zheng */
15387969338SIcenowy Zheng static inline void
sunxi_engine_commit(struct sunxi_engine * engine,struct drm_crtc * crtc,struct drm_atomic_state * state)154*aa0b4a69SOndrej Jirman sunxi_engine_commit(struct sunxi_engine *engine,
155*aa0b4a69SOndrej Jirman struct drm_crtc *crtc,
156*aa0b4a69SOndrej Jirman struct drm_atomic_state *state)
15787969338SIcenowy Zheng {
15887969338SIcenowy Zheng if (engine->ops && engine->ops->commit)
159*aa0b4a69SOndrej Jirman engine->ops->commit(engine, crtc, state);
16087969338SIcenowy Zheng }
16187969338SIcenowy Zheng
16287969338SIcenowy Zheng /**
16387969338SIcenowy Zheng * sunxi_engine_layers_init() - Create planes (layers) for the engine
16487969338SIcenowy Zheng * @drm: pointer to the drm_device for which planes will be created
16587969338SIcenowy Zheng * @engine: pointer to the engine
16687969338SIcenowy Zheng */
16787969338SIcenowy Zheng static inline struct drm_plane **
sunxi_engine_layers_init(struct drm_device * drm,struct sunxi_engine * engine)16887969338SIcenowy Zheng sunxi_engine_layers_init(struct drm_device *drm, struct sunxi_engine *engine)
16987969338SIcenowy Zheng {
17087969338SIcenowy Zheng if (engine->ops && engine->ops->layers_init)
17187969338SIcenowy Zheng return engine->ops->layers_init(drm, engine);
17287969338SIcenowy Zheng return ERR_PTR(-ENOSYS);
17387969338SIcenowy Zheng }
17487969338SIcenowy Zheng
17587969338SIcenowy Zheng /**
17687969338SIcenowy Zheng * sunxi_engine_apply_color_correction - Apply the RGB2YUV color correction
17787969338SIcenowy Zheng * @engine: pointer to the engine
17887969338SIcenowy Zheng *
17987969338SIcenowy Zheng * This functionality is optional for an engine, however, if the engine is
18087969338SIcenowy Zheng * intended to be used with TV Encoder, the output will be incorrect
18187969338SIcenowy Zheng * without the color correction, due to TV Encoder expects the engine to
18287969338SIcenowy Zheng * output directly YUV signal.
18387969338SIcenowy Zheng */
18487969338SIcenowy Zheng static inline void
sunxi_engine_apply_color_correction(struct sunxi_engine * engine)18587969338SIcenowy Zheng sunxi_engine_apply_color_correction(struct sunxi_engine *engine)
18687969338SIcenowy Zheng {
18787969338SIcenowy Zheng if (engine->ops && engine->ops->apply_color_correction)
18887969338SIcenowy Zheng engine->ops->apply_color_correction(engine);
18987969338SIcenowy Zheng }
19087969338SIcenowy Zheng
19187969338SIcenowy Zheng /**
19287969338SIcenowy Zheng * sunxi_engine_disable_color_correction - Disable the color space correction
19387969338SIcenowy Zheng * @engine: pointer to the engine
19487969338SIcenowy Zheng *
19587969338SIcenowy Zheng * This function is paired with apply_color_correction().
19687969338SIcenowy Zheng */
19787969338SIcenowy Zheng static inline void
sunxi_engine_disable_color_correction(struct sunxi_engine * engine)19887969338SIcenowy Zheng sunxi_engine_disable_color_correction(struct sunxi_engine *engine)
19987969338SIcenowy Zheng {
20087969338SIcenowy Zheng if (engine->ops && engine->ops->disable_color_correction)
20187969338SIcenowy Zheng engine->ops->disable_color_correction(engine);
20287969338SIcenowy Zheng }
203f7e974a3SJernej Skrabec
204f7e974a3SJernej Skrabec /**
205f7e974a3SJernej Skrabec * sunxi_engine_mode_set - Inform engine of a new mode
206f7e974a3SJernej Skrabec * @engine: pointer to the engine
207f7e974a3SJernej Skrabec * @mode: new mode
208f7e974a3SJernej Skrabec *
209f7e974a3SJernej Skrabec * Engine can use this functionality to set specifics once per mode change.
210f7e974a3SJernej Skrabec */
211f7e974a3SJernej Skrabec static inline void
sunxi_engine_mode_set(struct sunxi_engine * engine,const struct drm_display_mode * mode)212f7e974a3SJernej Skrabec sunxi_engine_mode_set(struct sunxi_engine *engine,
213f7e974a3SJernej Skrabec const struct drm_display_mode *mode)
214f7e974a3SJernej Skrabec {
215f7e974a3SJernej Skrabec if (engine->ops && engine->ops->mode_set)
216f7e974a3SJernej Skrabec engine->ops->mode_set(engine, mode);
217f7e974a3SJernej Skrabec }
21887969338SIcenowy Zheng #endif /* _SUNXI_ENGINE_H_ */
219