]>
Commit | Line | Data |
---|---|---|
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 | ||
13 | struct drm_plane; | |
14 | struct drm_device; | |
15 | ||
16 | struct sunxi_engine; | |
17 | ||
c4c7c72e MR |
18 | /** |
19 | * struct sunxi_engine_ops - helper operations for sunXi engines | |
20 | * | |
21 | * These hooks are used by the common part of the DRM driver to | |
22 | * implement the proper behaviour. | |
23 | */ | |
87969338 | 24 | struct sunxi_engine_ops { |
6b8562c8 MR |
25 | /** |
26 | * @atomic_begin: | |
27 | * | |
28 | * This callback allows to prepare our engine for an atomic | |
29 | * update. This is mirroring the | |
30 | * &drm_crtc_helper_funcs.atomic_begin callback, so any | |
31 | * documentation there applies. | |
32 | * | |
33 | * This function is optional. | |
34 | */ | |
35 | void (*atomic_begin)(struct sunxi_engine *engine, | |
36 | struct drm_crtc_state *old_state); | |
37 | ||
656e5f65 MR |
38 | /** |
39 | * @atomic_check: | |
40 | * | |
41 | * This callback allows to validate plane-update related CRTC | |
42 | * constraints specific to engines. This is mirroring the | |
43 | * &drm_crtc_helper_funcs.atomic_check callback, so any | |
44 | * documentation there applies. | |
45 | * | |
46 | * This function is optional. | |
47 | * | |
48 | * RETURNS: | |
49 | * | |
50 | * 0 on success or a negative error code. | |
51 | */ | |
52 | int (*atomic_check)(struct sunxi_engine *engine, | |
53 | struct drm_crtc_state *state); | |
54 | ||
c4c7c72e MR |
55 | /** |
56 | * @commit: | |
57 | * | |
58 | * This callback will trigger the hardware switch to commit | |
59 | * the new configuration that has been setup during the next | |
60 | * vblank period. | |
61 | * | |
62 | * This function is optional. | |
63 | */ | |
87969338 | 64 | void (*commit)(struct sunxi_engine *engine); |
c4c7c72e MR |
65 | |
66 | /** | |
67 | * @layers_init: | |
68 | * | |
69 | * This callback is used to allocate, initialize and register | |
70 | * the layers supported by that engine. | |
71 | * | |
72 | * This function is mandatory. | |
73 | * | |
74 | * RETURNS: | |
75 | * | |
76 | * The array of struct drm_plane backing the layers, or an | |
77 | * error pointer on failure. | |
78 | */ | |
87969338 IZ |
79 | struct drm_plane **(*layers_init)(struct drm_device *drm, |
80 | struct sunxi_engine *engine); | |
81 | ||
c4c7c72e MR |
82 | /** |
83 | * @apply_color_correction: | |
84 | * | |
85 | * This callback will enable the color correction in the | |
86 | * engine. This is useful only for the composite output. | |
87 | * | |
88 | * This function is optional. | |
89 | */ | |
87969338 | 90 | void (*apply_color_correction)(struct sunxi_engine *engine); |
c4c7c72e MR |
91 | |
92 | /** | |
93 | * @disable_color_correction: | |
94 | * | |
95 | * This callback will stop the color correction in the | |
96 | * engine. This is useful only for the composite output. | |
97 | * | |
98 | * This function is optional. | |
99 | */ | |
87969338 | 100 | void (*disable_color_correction)(struct sunxi_engine *engine); |
3004f75f MR |
101 | |
102 | /** | |
103 | * @vblank_quirk: | |
104 | * | |
105 | * This callback is used to implement engine-specific | |
106 | * behaviour part of the VBLANK event. It is run with all the | |
107 | * constraints of an interrupt (can't sleep, all local | |
108 | * interrupts disabled) and therefore should be as fast as | |
109 | * possible. | |
110 | * | |
111 | * This function is optional. | |
112 | */ | |
113 | void (*vblank_quirk)(struct sunxi_engine *engine); | |
87969338 IZ |
114 | }; |
115 | ||
116 | /** | |
117 | * struct sunxi_engine - the common parts of an engine for sun4i-drm driver | |
118 | * @ops: the operations of the engine | |
119 | * @node: the of device node of the engine | |
120 | * @regs: the regmap of the engine | |
121 | * @id: the id of the engine (-1 if not used) | |
122 | */ | |
123 | struct sunxi_engine { | |
124 | const struct sunxi_engine_ops *ops; | |
125 | ||
126 | struct device_node *node; | |
127 | struct regmap *regs; | |
128 | ||
129 | int id; | |
130 | ||
131 | /* Engine list management */ | |
132 | struct list_head list; | |
133 | }; | |
134 | ||
135 | /** | |
136 | * sunxi_engine_commit() - commit all changes of the engine | |
137 | * @engine: pointer to the engine | |
138 | */ | |
139 | static inline void | |
140 | sunxi_engine_commit(struct sunxi_engine *engine) | |
141 | { | |
142 | if (engine->ops && engine->ops->commit) | |
143 | engine->ops->commit(engine); | |
144 | } | |
145 | ||
146 | /** | |
147 | * sunxi_engine_layers_init() - Create planes (layers) for the engine | |
148 | * @drm: pointer to the drm_device for which planes will be created | |
149 | * @engine: pointer to the engine | |
150 | */ | |
151 | static inline struct drm_plane ** | |
152 | sunxi_engine_layers_init(struct drm_device *drm, struct sunxi_engine *engine) | |
153 | { | |
154 | if (engine->ops && engine->ops->layers_init) | |
155 | return engine->ops->layers_init(drm, engine); | |
156 | return ERR_PTR(-ENOSYS); | |
157 | } | |
158 | ||
159 | /** | |
160 | * sunxi_engine_apply_color_correction - Apply the RGB2YUV color correction | |
161 | * @engine: pointer to the engine | |
162 | * | |
163 | * This functionality is optional for an engine, however, if the engine is | |
164 | * intended to be used with TV Encoder, the output will be incorrect | |
165 | * without the color correction, due to TV Encoder expects the engine to | |
166 | * output directly YUV signal. | |
167 | */ | |
168 | static inline void | |
169 | sunxi_engine_apply_color_correction(struct sunxi_engine *engine) | |
170 | { | |
171 | if (engine->ops && engine->ops->apply_color_correction) | |
172 | engine->ops->apply_color_correction(engine); | |
173 | } | |
174 | ||
175 | /** | |
176 | * sunxi_engine_disable_color_correction - Disable the color space correction | |
177 | * @engine: pointer to the engine | |
178 | * | |
179 | * This function is paired with apply_color_correction(). | |
180 | */ | |
181 | static inline void | |
182 | sunxi_engine_disable_color_correction(struct sunxi_engine *engine) | |
183 | { | |
184 | if (engine->ops && engine->ops->disable_color_correction) | |
185 | engine->ops->disable_color_correction(engine); | |
186 | } | |
187 | #endif /* _SUNXI_ENGINE_H_ */ |