]>
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 { |
656e5f65 MR |
25 | /** |
26 | * @atomic_check: | |
27 | * | |
28 | * This callback allows to validate plane-update related CRTC | |
29 | * constraints specific to engines. This is mirroring the | |
30 | * &drm_crtc_helper_funcs.atomic_check callback, so any | |
31 | * documentation there applies. | |
32 | * | |
33 | * This function is optional. | |
34 | * | |
35 | * RETURNS: | |
36 | * | |
37 | * 0 on success or a negative error code. | |
38 | */ | |
39 | int (*atomic_check)(struct sunxi_engine *engine, | |
40 | struct drm_crtc_state *state); | |
41 | ||
c4c7c72e MR |
42 | /** |
43 | * @commit: | |
44 | * | |
45 | * This callback will trigger the hardware switch to commit | |
46 | * the new configuration that has been setup during the next | |
47 | * vblank period. | |
48 | * | |
49 | * This function is optional. | |
50 | */ | |
87969338 | 51 | void (*commit)(struct sunxi_engine *engine); |
c4c7c72e MR |
52 | |
53 | /** | |
54 | * @layers_init: | |
55 | * | |
56 | * This callback is used to allocate, initialize and register | |
57 | * the layers supported by that engine. | |
58 | * | |
59 | * This function is mandatory. | |
60 | * | |
61 | * RETURNS: | |
62 | * | |
63 | * The array of struct drm_plane backing the layers, or an | |
64 | * error pointer on failure. | |
65 | */ | |
87969338 IZ |
66 | struct drm_plane **(*layers_init)(struct drm_device *drm, |
67 | struct sunxi_engine *engine); | |
68 | ||
c4c7c72e MR |
69 | /** |
70 | * @apply_color_correction: | |
71 | * | |
72 | * This callback will enable the color correction in the | |
73 | * engine. This is useful only for the composite output. | |
74 | * | |
75 | * This function is optional. | |
76 | */ | |
87969338 | 77 | void (*apply_color_correction)(struct sunxi_engine *engine); |
c4c7c72e MR |
78 | |
79 | /** | |
80 | * @disable_color_correction: | |
81 | * | |
82 | * This callback will stop the color correction in the | |
83 | * engine. This is useful only for the composite output. | |
84 | * | |
85 | * This function is optional. | |
86 | */ | |
87969338 IZ |
87 | void (*disable_color_correction)(struct sunxi_engine *engine); |
88 | }; | |
89 | ||
90 | /** | |
91 | * struct sunxi_engine - the common parts of an engine for sun4i-drm driver | |
92 | * @ops: the operations of the engine | |
93 | * @node: the of device node of the engine | |
94 | * @regs: the regmap of the engine | |
95 | * @id: the id of the engine (-1 if not used) | |
96 | */ | |
97 | struct sunxi_engine { | |
98 | const struct sunxi_engine_ops *ops; | |
99 | ||
100 | struct device_node *node; | |
101 | struct regmap *regs; | |
102 | ||
103 | int id; | |
104 | ||
105 | /* Engine list management */ | |
106 | struct list_head list; | |
107 | }; | |
108 | ||
109 | /** | |
110 | * sunxi_engine_commit() - commit all changes of the engine | |
111 | * @engine: pointer to the engine | |
112 | */ | |
113 | static inline void | |
114 | sunxi_engine_commit(struct sunxi_engine *engine) | |
115 | { | |
116 | if (engine->ops && engine->ops->commit) | |
117 | engine->ops->commit(engine); | |
118 | } | |
119 | ||
120 | /** | |
121 | * sunxi_engine_layers_init() - Create planes (layers) for the engine | |
122 | * @drm: pointer to the drm_device for which planes will be created | |
123 | * @engine: pointer to the engine | |
124 | */ | |
125 | static inline struct drm_plane ** | |
126 | sunxi_engine_layers_init(struct drm_device *drm, struct sunxi_engine *engine) | |
127 | { | |
128 | if (engine->ops && engine->ops->layers_init) | |
129 | return engine->ops->layers_init(drm, engine); | |
130 | return ERR_PTR(-ENOSYS); | |
131 | } | |
132 | ||
133 | /** | |
134 | * sunxi_engine_apply_color_correction - Apply the RGB2YUV color correction | |
135 | * @engine: pointer to the engine | |
136 | * | |
137 | * This functionality is optional for an engine, however, if the engine is | |
138 | * intended to be used with TV Encoder, the output will be incorrect | |
139 | * without the color correction, due to TV Encoder expects the engine to | |
140 | * output directly YUV signal. | |
141 | */ | |
142 | static inline void | |
143 | sunxi_engine_apply_color_correction(struct sunxi_engine *engine) | |
144 | { | |
145 | if (engine->ops && engine->ops->apply_color_correction) | |
146 | engine->ops->apply_color_correction(engine); | |
147 | } | |
148 | ||
149 | /** | |
150 | * sunxi_engine_disable_color_correction - Disable the color space correction | |
151 | * @engine: pointer to the engine | |
152 | * | |
153 | * This function is paired with apply_color_correction(). | |
154 | */ | |
155 | static inline void | |
156 | sunxi_engine_disable_color_correction(struct sunxi_engine *engine) | |
157 | { | |
158 | if (engine->ops && engine->ops->disable_color_correction) | |
159 | engine->ops->disable_color_correction(engine); | |
160 | } | |
161 | #endif /* _SUNXI_ENGINE_H_ */ |