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;
1087969338SIcenowy Zheng struct drm_device;
11a63b8e79SSean Paul struct drm_crtc_state;
12*f7e974a3SJernej Skrabec struct drm_display_mode;
1387969338SIcenowy Zheng
1487969338SIcenowy Zheng struct sunxi_engine;
1587969338SIcenowy Zheng
16c4c7c72eSMaxime Ripard /**
17c4c7c72eSMaxime Ripard * struct sunxi_engine_ops - helper operations for sunXi engines
18c4c7c72eSMaxime Ripard *
19c4c7c72eSMaxime Ripard * These hooks are used by the common part of the DRM driver to
20c4c7c72eSMaxime Ripard * implement the proper behaviour.
21c4c7c72eSMaxime Ripard */
2287969338SIcenowy Zheng struct sunxi_engine_ops {
23c4c7c72eSMaxime Ripard /**
246b8562c8SMaxime Ripard * @atomic_begin:
256b8562c8SMaxime Ripard *
266b8562c8SMaxime Ripard * This callback allows to prepare our engine for an atomic
276b8562c8SMaxime Ripard * update. This is mirroring the
286b8562c8SMaxime Ripard * &drm_crtc_helper_funcs.atomic_begin callback, so any
296b8562c8SMaxime Ripard * documentation there applies.
306b8562c8SMaxime Ripard *
316b8562c8SMaxime Ripard * This function is optional.
326b8562c8SMaxime Ripard */
336b8562c8SMaxime Ripard void (*atomic_begin)(struct sunxi_engine *engine,
346b8562c8SMaxime Ripard struct drm_crtc_state *old_state);
356b8562c8SMaxime Ripard
366b8562c8SMaxime Ripard /**
37656e5f65SMaxime Ripard * @atomic_check:
38656e5f65SMaxime Ripard *
39656e5f65SMaxime Ripard * This callback allows to validate plane-update related CRTC
40656e5f65SMaxime Ripard * constraints specific to engines. This is mirroring the
41656e5f65SMaxime Ripard * &drm_crtc_helper_funcs.atomic_check callback, so any
42656e5f65SMaxime Ripard * documentation there applies.
43656e5f65SMaxime Ripard *
44656e5f65SMaxime Ripard * This function is optional.
45656e5f65SMaxime Ripard *
46656e5f65SMaxime Ripard * RETURNS:
47656e5f65SMaxime Ripard *
48656e5f65SMaxime Ripard * 0 on success or a negative error code.
49656e5f65SMaxime Ripard */
50656e5f65SMaxime Ripard int (*atomic_check)(struct sunxi_engine *engine,
51656e5f65SMaxime Ripard struct drm_crtc_state *state);
52656e5f65SMaxime Ripard
53656e5f65SMaxime Ripard /**
54c4c7c72eSMaxime Ripard * @commit:
55c4c7c72eSMaxime Ripard *
56c4c7c72eSMaxime Ripard * This callback will trigger the hardware switch to commit
57c4c7c72eSMaxime Ripard * the new configuration that has been setup during the next
58c4c7c72eSMaxime Ripard * vblank period.
59c4c7c72eSMaxime Ripard *
60c4c7c72eSMaxime Ripard * This function is optional.
61c4c7c72eSMaxime Ripard */
6287969338SIcenowy Zheng void (*commit)(struct sunxi_engine *engine);
63c4c7c72eSMaxime Ripard
64c4c7c72eSMaxime Ripard /**
65c4c7c72eSMaxime Ripard * @layers_init:
66c4c7c72eSMaxime Ripard *
67c4c7c72eSMaxime Ripard * This callback is used to allocate, initialize and register
68c4c7c72eSMaxime Ripard * the layers supported by that engine.
69c4c7c72eSMaxime Ripard *
70c4c7c72eSMaxime Ripard * This function is mandatory.
71c4c7c72eSMaxime Ripard *
72c4c7c72eSMaxime Ripard * RETURNS:
73c4c7c72eSMaxime Ripard *
74c4c7c72eSMaxime Ripard * The array of struct drm_plane backing the layers, or an
75c4c7c72eSMaxime Ripard * error pointer on failure.
76c4c7c72eSMaxime Ripard */
7787969338SIcenowy Zheng struct drm_plane **(*layers_init)(struct drm_device *drm,
7887969338SIcenowy Zheng struct sunxi_engine *engine);
7987969338SIcenowy Zheng
80c4c7c72eSMaxime Ripard /**
81c4c7c72eSMaxime Ripard * @apply_color_correction:
82c4c7c72eSMaxime Ripard *
83c4c7c72eSMaxime Ripard * This callback will enable the color correction in the
84c4c7c72eSMaxime Ripard * engine. This is useful only for the composite output.
85c4c7c72eSMaxime Ripard *
86c4c7c72eSMaxime Ripard * This function is optional.
87c4c7c72eSMaxime Ripard */
8887969338SIcenowy Zheng void (*apply_color_correction)(struct sunxi_engine *engine);
89c4c7c72eSMaxime Ripard
90c4c7c72eSMaxime Ripard /**
91c4c7c72eSMaxime Ripard * @disable_color_correction:
92c4c7c72eSMaxime Ripard *
93c4c7c72eSMaxime Ripard * This callback will stop the color correction in the
94c4c7c72eSMaxime Ripard * engine. This is useful only for the composite output.
95c4c7c72eSMaxime Ripard *
96c4c7c72eSMaxime Ripard * This function is optional.
97c4c7c72eSMaxime Ripard */
9887969338SIcenowy Zheng void (*disable_color_correction)(struct sunxi_engine *engine);
993004f75fSMaxime Ripard
1003004f75fSMaxime Ripard /**
1013004f75fSMaxime Ripard * @vblank_quirk:
1023004f75fSMaxime Ripard *
1033004f75fSMaxime Ripard * This callback is used to implement engine-specific
1043004f75fSMaxime Ripard * behaviour part of the VBLANK event. It is run with all the
1053004f75fSMaxime Ripard * constraints of an interrupt (can't sleep, all local
1063004f75fSMaxime Ripard * interrupts disabled) and therefore should be as fast as
1073004f75fSMaxime Ripard * possible.
1083004f75fSMaxime Ripard *
1093004f75fSMaxime Ripard * This function is optional.
1103004f75fSMaxime Ripard */
1113004f75fSMaxime Ripard void (*vblank_quirk)(struct sunxi_engine *engine);
112*f7e974a3SJernej Skrabec
113*f7e974a3SJernej Skrabec /**
114*f7e974a3SJernej Skrabec * @mode_set
115*f7e974a3SJernej Skrabec *
116*f7e974a3SJernej Skrabec * This callback is used to set mode related parameters
117*f7e974a3SJernej Skrabec * like interlacing, screen size, etc. once per mode set.
118*f7e974a3SJernej Skrabec *
119*f7e974a3SJernej Skrabec * This function is optional.
120*f7e974a3SJernej Skrabec */
121*f7e974a3SJernej Skrabec void (*mode_set)(struct sunxi_engine *engine,
122*f7e974a3SJernej Skrabec const struct drm_display_mode *mode);
12387969338SIcenowy Zheng };
12487969338SIcenowy Zheng
12587969338SIcenowy Zheng /**
12687969338SIcenowy Zheng * struct sunxi_engine - the common parts of an engine for sun4i-drm driver
12787969338SIcenowy Zheng * @ops: the operations of the engine
12887969338SIcenowy Zheng * @node: the of device node of the engine
12987969338SIcenowy Zheng * @regs: the regmap of the engine
13087969338SIcenowy Zheng * @id: the id of the engine (-1 if not used)
13187969338SIcenowy Zheng */
13287969338SIcenowy Zheng struct sunxi_engine {
13387969338SIcenowy Zheng const struct sunxi_engine_ops *ops;
13487969338SIcenowy Zheng
13587969338SIcenowy Zheng struct device_node *node;
13687969338SIcenowy Zheng struct regmap *regs;
13787969338SIcenowy Zheng
13887969338SIcenowy Zheng int id;
13987969338SIcenowy Zheng
14087969338SIcenowy Zheng /* Engine list management */
14187969338SIcenowy Zheng struct list_head list;
14287969338SIcenowy Zheng };
14387969338SIcenowy Zheng
14487969338SIcenowy Zheng /**
14587969338SIcenowy Zheng * sunxi_engine_commit() - commit all changes of the engine
14687969338SIcenowy Zheng * @engine: pointer to the engine
14787969338SIcenowy Zheng */
14887969338SIcenowy Zheng static inline void
sunxi_engine_commit(struct sunxi_engine * engine)14987969338SIcenowy Zheng sunxi_engine_commit(struct sunxi_engine *engine)
15087969338SIcenowy Zheng {
15187969338SIcenowy Zheng if (engine->ops && engine->ops->commit)
15287969338SIcenowy Zheng engine->ops->commit(engine);
15387969338SIcenowy Zheng }
15487969338SIcenowy Zheng
15587969338SIcenowy Zheng /**
15687969338SIcenowy Zheng * sunxi_engine_layers_init() - Create planes (layers) for the engine
15787969338SIcenowy Zheng * @drm: pointer to the drm_device for which planes will be created
15887969338SIcenowy Zheng * @engine: pointer to the engine
15987969338SIcenowy Zheng */
16087969338SIcenowy Zheng static inline struct drm_plane **
sunxi_engine_layers_init(struct drm_device * drm,struct sunxi_engine * engine)16187969338SIcenowy Zheng sunxi_engine_layers_init(struct drm_device *drm, struct sunxi_engine *engine)
16287969338SIcenowy Zheng {
16387969338SIcenowy Zheng if (engine->ops && engine->ops->layers_init)
16487969338SIcenowy Zheng return engine->ops->layers_init(drm, engine);
16587969338SIcenowy Zheng return ERR_PTR(-ENOSYS);
16687969338SIcenowy Zheng }
16787969338SIcenowy Zheng
16887969338SIcenowy Zheng /**
16987969338SIcenowy Zheng * sunxi_engine_apply_color_correction - Apply the RGB2YUV color correction
17087969338SIcenowy Zheng * @engine: pointer to the engine
17187969338SIcenowy Zheng *
17287969338SIcenowy Zheng * This functionality is optional for an engine, however, if the engine is
17387969338SIcenowy Zheng * intended to be used with TV Encoder, the output will be incorrect
17487969338SIcenowy Zheng * without the color correction, due to TV Encoder expects the engine to
17587969338SIcenowy Zheng * output directly YUV signal.
17687969338SIcenowy Zheng */
17787969338SIcenowy Zheng static inline void
sunxi_engine_apply_color_correction(struct sunxi_engine * engine)17887969338SIcenowy Zheng sunxi_engine_apply_color_correction(struct sunxi_engine *engine)
17987969338SIcenowy Zheng {
18087969338SIcenowy Zheng if (engine->ops && engine->ops->apply_color_correction)
18187969338SIcenowy Zheng engine->ops->apply_color_correction(engine);
18287969338SIcenowy Zheng }
18387969338SIcenowy Zheng
18487969338SIcenowy Zheng /**
18587969338SIcenowy Zheng * sunxi_engine_disable_color_correction - Disable the color space correction
18687969338SIcenowy Zheng * @engine: pointer to the engine
18787969338SIcenowy Zheng *
18887969338SIcenowy Zheng * This function is paired with apply_color_correction().
18987969338SIcenowy Zheng */
19087969338SIcenowy Zheng static inline void
sunxi_engine_disable_color_correction(struct sunxi_engine * engine)19187969338SIcenowy Zheng sunxi_engine_disable_color_correction(struct sunxi_engine *engine)
19287969338SIcenowy Zheng {
19387969338SIcenowy Zheng if (engine->ops && engine->ops->disable_color_correction)
19487969338SIcenowy Zheng engine->ops->disable_color_correction(engine);
19587969338SIcenowy Zheng }
196*f7e974a3SJernej Skrabec
197*f7e974a3SJernej Skrabec /**
198*f7e974a3SJernej Skrabec * sunxi_engine_mode_set - Inform engine of a new mode
199*f7e974a3SJernej Skrabec * @engine: pointer to the engine
200*f7e974a3SJernej Skrabec * @mode: new mode
201*f7e974a3SJernej Skrabec *
202*f7e974a3SJernej Skrabec * Engine can use this functionality to set specifics once per mode change.
203*f7e974a3SJernej Skrabec */
204*f7e974a3SJernej Skrabec static inline void
sunxi_engine_mode_set(struct sunxi_engine * engine,const struct drm_display_mode * mode)205*f7e974a3SJernej Skrabec sunxi_engine_mode_set(struct sunxi_engine *engine,
206*f7e974a3SJernej Skrabec const struct drm_display_mode *mode)
207*f7e974a3SJernej Skrabec {
208*f7e974a3SJernej Skrabec if (engine->ops && engine->ops->mode_set)
209*f7e974a3SJernej Skrabec engine->ops->mode_set(engine, mode);
210*f7e974a3SJernej Skrabec }
21187969338SIcenowy Zheng #endif /* _SUNXI_ENGINE_H_ */
212