.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (C) 2017 Icenowy Zheng <icenowy@aosc.io> |
---|
3 | 4 | * |
---|
4 | 5 | * Based on sun4i_backend.c, which is: |
---|
5 | 6 | * Copyright (C) 2015 Free Electrons |
---|
6 | 7 | * Copyright (C) 2015 NextThing Co |
---|
7 | | - * |
---|
8 | | - * This program is free software; you can redistribute it and/or |
---|
9 | | - * modify it under the terms of the GNU General Public License as |
---|
10 | | - * published by the Free Software Foundation; either version 2 of |
---|
11 | | - * the License, or (at your option) any later version. |
---|
12 | 8 | */ |
---|
13 | | - |
---|
14 | | -#include <drm/drmP.h> |
---|
15 | | -#include <drm/drm_atomic_helper.h> |
---|
16 | | -#include <drm/drm_crtc.h> |
---|
17 | | -#include <drm/drm_crtc_helper.h> |
---|
18 | | -#include <drm/drm_fb_cma_helper.h> |
---|
19 | | -#include <drm/drm_gem_cma_helper.h> |
---|
20 | | -#include <drm/drm_plane_helper.h> |
---|
21 | 9 | |
---|
22 | 10 | #include <linux/component.h> |
---|
23 | 11 | #include <linux/dma-mapping.h> |
---|
| 12 | +#include <linux/module.h> |
---|
24 | 13 | #include <linux/of_device.h> |
---|
25 | 14 | #include <linux/of_graph.h> |
---|
26 | 15 | #include <linux/reset.h> |
---|
| 16 | + |
---|
| 17 | +#include <drm/drm_atomic_helper.h> |
---|
| 18 | +#include <drm/drm_crtc.h> |
---|
| 19 | +#include <drm/drm_fb_cma_helper.h> |
---|
| 20 | +#include <drm/drm_gem_cma_helper.h> |
---|
| 21 | +#include <drm/drm_plane_helper.h> |
---|
| 22 | +#include <drm/drm_probe_helper.h> |
---|
27 | 23 | |
---|
28 | 24 | #include "sun4i_drv.h" |
---|
29 | 25 | #include "sun8i_mixer.h" |
---|
.. | .. |
---|
31 | 27 | #include "sun8i_vi_layer.h" |
---|
32 | 28 | #include "sunxi_engine.h" |
---|
33 | 29 | |
---|
| 30 | +struct de2_fmt_info { |
---|
| 31 | + u32 drm_fmt; |
---|
| 32 | + u32 de2_fmt; |
---|
| 33 | +}; |
---|
| 34 | + |
---|
34 | 35 | static const struct de2_fmt_info de2_formats[] = { |
---|
35 | 36 | { |
---|
36 | 37 | .drm_fmt = DRM_FORMAT_ARGB8888, |
---|
37 | 38 | .de2_fmt = SUN8I_MIXER_FBFMT_ARGB8888, |
---|
38 | | - .rgb = true, |
---|
39 | | - .csc = SUN8I_CSC_MODE_OFF, |
---|
40 | 39 | }, |
---|
41 | 40 | { |
---|
42 | 41 | .drm_fmt = DRM_FORMAT_ABGR8888, |
---|
43 | 42 | .de2_fmt = SUN8I_MIXER_FBFMT_ABGR8888, |
---|
44 | | - .rgb = true, |
---|
45 | | - .csc = SUN8I_CSC_MODE_OFF, |
---|
46 | 43 | }, |
---|
47 | 44 | { |
---|
48 | 45 | .drm_fmt = DRM_FORMAT_RGBA8888, |
---|
49 | 46 | .de2_fmt = SUN8I_MIXER_FBFMT_RGBA8888, |
---|
50 | | - .rgb = true, |
---|
51 | | - .csc = SUN8I_CSC_MODE_OFF, |
---|
52 | 47 | }, |
---|
53 | 48 | { |
---|
54 | 49 | .drm_fmt = DRM_FORMAT_BGRA8888, |
---|
55 | 50 | .de2_fmt = SUN8I_MIXER_FBFMT_BGRA8888, |
---|
56 | | - .rgb = true, |
---|
57 | | - .csc = SUN8I_CSC_MODE_OFF, |
---|
58 | 51 | }, |
---|
59 | 52 | { |
---|
60 | 53 | .drm_fmt = DRM_FORMAT_XRGB8888, |
---|
61 | 54 | .de2_fmt = SUN8I_MIXER_FBFMT_XRGB8888, |
---|
62 | | - .rgb = true, |
---|
63 | | - .csc = SUN8I_CSC_MODE_OFF, |
---|
64 | 55 | }, |
---|
65 | 56 | { |
---|
66 | 57 | .drm_fmt = DRM_FORMAT_XBGR8888, |
---|
67 | 58 | .de2_fmt = SUN8I_MIXER_FBFMT_XBGR8888, |
---|
68 | | - .rgb = true, |
---|
69 | | - .csc = SUN8I_CSC_MODE_OFF, |
---|
70 | 59 | }, |
---|
71 | 60 | { |
---|
72 | 61 | .drm_fmt = DRM_FORMAT_RGBX8888, |
---|
73 | 62 | .de2_fmt = SUN8I_MIXER_FBFMT_RGBX8888, |
---|
74 | | - .rgb = true, |
---|
75 | | - .csc = SUN8I_CSC_MODE_OFF, |
---|
76 | 63 | }, |
---|
77 | 64 | { |
---|
78 | 65 | .drm_fmt = DRM_FORMAT_BGRX8888, |
---|
79 | 66 | .de2_fmt = SUN8I_MIXER_FBFMT_BGRX8888, |
---|
80 | | - .rgb = true, |
---|
81 | | - .csc = SUN8I_CSC_MODE_OFF, |
---|
82 | 67 | }, |
---|
83 | 68 | { |
---|
84 | 69 | .drm_fmt = DRM_FORMAT_RGB888, |
---|
85 | 70 | .de2_fmt = SUN8I_MIXER_FBFMT_RGB888, |
---|
86 | | - .rgb = true, |
---|
87 | | - .csc = SUN8I_CSC_MODE_OFF, |
---|
88 | 71 | }, |
---|
89 | 72 | { |
---|
90 | 73 | .drm_fmt = DRM_FORMAT_BGR888, |
---|
91 | 74 | .de2_fmt = SUN8I_MIXER_FBFMT_BGR888, |
---|
92 | | - .rgb = true, |
---|
93 | | - .csc = SUN8I_CSC_MODE_OFF, |
---|
94 | 75 | }, |
---|
95 | 76 | { |
---|
96 | 77 | .drm_fmt = DRM_FORMAT_RGB565, |
---|
97 | 78 | .de2_fmt = SUN8I_MIXER_FBFMT_RGB565, |
---|
98 | | - .rgb = true, |
---|
99 | | - .csc = SUN8I_CSC_MODE_OFF, |
---|
100 | 79 | }, |
---|
101 | 80 | { |
---|
102 | 81 | .drm_fmt = DRM_FORMAT_BGR565, |
---|
103 | 82 | .de2_fmt = SUN8I_MIXER_FBFMT_BGR565, |
---|
104 | | - .rgb = true, |
---|
105 | | - .csc = SUN8I_CSC_MODE_OFF, |
---|
106 | 83 | }, |
---|
107 | 84 | { |
---|
108 | 85 | .drm_fmt = DRM_FORMAT_ARGB4444, |
---|
109 | 86 | .de2_fmt = SUN8I_MIXER_FBFMT_ARGB4444, |
---|
110 | | - .rgb = true, |
---|
111 | | - .csc = SUN8I_CSC_MODE_OFF, |
---|
112 | 87 | }, |
---|
113 | 88 | { |
---|
114 | 89 | /* for DE2 VI layer which ignores alpha */ |
---|
115 | 90 | .drm_fmt = DRM_FORMAT_XRGB4444, |
---|
116 | 91 | .de2_fmt = SUN8I_MIXER_FBFMT_ARGB4444, |
---|
117 | | - .rgb = true, |
---|
118 | | - .csc = SUN8I_CSC_MODE_OFF, |
---|
119 | 92 | }, |
---|
120 | 93 | { |
---|
121 | 94 | .drm_fmt = DRM_FORMAT_ABGR4444, |
---|
122 | 95 | .de2_fmt = SUN8I_MIXER_FBFMT_ABGR4444, |
---|
123 | | - .rgb = true, |
---|
124 | | - .csc = SUN8I_CSC_MODE_OFF, |
---|
125 | 96 | }, |
---|
126 | 97 | { |
---|
127 | 98 | /* for DE2 VI layer which ignores alpha */ |
---|
128 | 99 | .drm_fmt = DRM_FORMAT_XBGR4444, |
---|
129 | 100 | .de2_fmt = SUN8I_MIXER_FBFMT_ABGR4444, |
---|
130 | | - .rgb = true, |
---|
131 | | - .csc = SUN8I_CSC_MODE_OFF, |
---|
132 | 101 | }, |
---|
133 | 102 | { |
---|
134 | 103 | .drm_fmt = DRM_FORMAT_RGBA4444, |
---|
135 | 104 | .de2_fmt = SUN8I_MIXER_FBFMT_RGBA4444, |
---|
136 | | - .rgb = true, |
---|
137 | | - .csc = SUN8I_CSC_MODE_OFF, |
---|
138 | 105 | }, |
---|
139 | 106 | { |
---|
140 | 107 | /* for DE2 VI layer which ignores alpha */ |
---|
141 | 108 | .drm_fmt = DRM_FORMAT_RGBX4444, |
---|
142 | 109 | .de2_fmt = SUN8I_MIXER_FBFMT_RGBA4444, |
---|
143 | | - .rgb = true, |
---|
144 | | - .csc = SUN8I_CSC_MODE_OFF, |
---|
145 | 110 | }, |
---|
146 | 111 | { |
---|
147 | 112 | .drm_fmt = DRM_FORMAT_BGRA4444, |
---|
148 | 113 | .de2_fmt = SUN8I_MIXER_FBFMT_BGRA4444, |
---|
149 | | - .rgb = true, |
---|
150 | | - .csc = SUN8I_CSC_MODE_OFF, |
---|
151 | 114 | }, |
---|
152 | 115 | { |
---|
153 | 116 | /* for DE2 VI layer which ignores alpha */ |
---|
154 | 117 | .drm_fmt = DRM_FORMAT_BGRX4444, |
---|
155 | 118 | .de2_fmt = SUN8I_MIXER_FBFMT_BGRA4444, |
---|
156 | | - .rgb = true, |
---|
157 | | - .csc = SUN8I_CSC_MODE_OFF, |
---|
158 | 119 | }, |
---|
159 | 120 | { |
---|
160 | 121 | .drm_fmt = DRM_FORMAT_ARGB1555, |
---|
161 | 122 | .de2_fmt = SUN8I_MIXER_FBFMT_ARGB1555, |
---|
162 | | - .rgb = true, |
---|
163 | | - .csc = SUN8I_CSC_MODE_OFF, |
---|
164 | 123 | }, |
---|
165 | 124 | { |
---|
166 | 125 | /* for DE2 VI layer which ignores alpha */ |
---|
167 | 126 | .drm_fmt = DRM_FORMAT_XRGB1555, |
---|
168 | 127 | .de2_fmt = SUN8I_MIXER_FBFMT_ARGB1555, |
---|
169 | | - .rgb = true, |
---|
170 | | - .csc = SUN8I_CSC_MODE_OFF, |
---|
171 | 128 | }, |
---|
172 | 129 | { |
---|
173 | 130 | .drm_fmt = DRM_FORMAT_ABGR1555, |
---|
174 | 131 | .de2_fmt = SUN8I_MIXER_FBFMT_ABGR1555, |
---|
175 | | - .rgb = true, |
---|
176 | | - .csc = SUN8I_CSC_MODE_OFF, |
---|
177 | 132 | }, |
---|
178 | 133 | { |
---|
179 | 134 | /* for DE2 VI layer which ignores alpha */ |
---|
180 | 135 | .drm_fmt = DRM_FORMAT_XBGR1555, |
---|
181 | 136 | .de2_fmt = SUN8I_MIXER_FBFMT_ABGR1555, |
---|
182 | | - .rgb = true, |
---|
183 | | - .csc = SUN8I_CSC_MODE_OFF, |
---|
184 | 137 | }, |
---|
185 | 138 | { |
---|
186 | 139 | .drm_fmt = DRM_FORMAT_RGBA5551, |
---|
187 | 140 | .de2_fmt = SUN8I_MIXER_FBFMT_RGBA5551, |
---|
188 | | - .rgb = true, |
---|
189 | | - .csc = SUN8I_CSC_MODE_OFF, |
---|
190 | 141 | }, |
---|
191 | 142 | { |
---|
192 | 143 | /* for DE2 VI layer which ignores alpha */ |
---|
193 | 144 | .drm_fmt = DRM_FORMAT_RGBX5551, |
---|
194 | 145 | .de2_fmt = SUN8I_MIXER_FBFMT_RGBA5551, |
---|
195 | | - .rgb = true, |
---|
196 | | - .csc = SUN8I_CSC_MODE_OFF, |
---|
197 | 146 | }, |
---|
198 | 147 | { |
---|
199 | 148 | .drm_fmt = DRM_FORMAT_BGRA5551, |
---|
200 | 149 | .de2_fmt = SUN8I_MIXER_FBFMT_BGRA5551, |
---|
201 | | - .rgb = true, |
---|
202 | | - .csc = SUN8I_CSC_MODE_OFF, |
---|
203 | 150 | }, |
---|
204 | 151 | { |
---|
205 | 152 | /* for DE2 VI layer which ignores alpha */ |
---|
206 | 153 | .drm_fmt = DRM_FORMAT_BGRX5551, |
---|
207 | 154 | .de2_fmt = SUN8I_MIXER_FBFMT_BGRA5551, |
---|
208 | | - .rgb = true, |
---|
209 | | - .csc = SUN8I_CSC_MODE_OFF, |
---|
| 155 | + }, |
---|
| 156 | + { |
---|
| 157 | + .drm_fmt = DRM_FORMAT_ARGB2101010, |
---|
| 158 | + .de2_fmt = SUN8I_MIXER_FBFMT_ARGB2101010, |
---|
| 159 | + }, |
---|
| 160 | + { |
---|
| 161 | + .drm_fmt = DRM_FORMAT_ABGR2101010, |
---|
| 162 | + .de2_fmt = SUN8I_MIXER_FBFMT_ABGR2101010, |
---|
| 163 | + }, |
---|
| 164 | + { |
---|
| 165 | + .drm_fmt = DRM_FORMAT_RGBA1010102, |
---|
| 166 | + .de2_fmt = SUN8I_MIXER_FBFMT_RGBA1010102, |
---|
| 167 | + }, |
---|
| 168 | + { |
---|
| 169 | + .drm_fmt = DRM_FORMAT_BGRA1010102, |
---|
| 170 | + .de2_fmt = SUN8I_MIXER_FBFMT_BGRA1010102, |
---|
210 | 171 | }, |
---|
211 | 172 | { |
---|
212 | 173 | .drm_fmt = DRM_FORMAT_UYVY, |
---|
213 | 174 | .de2_fmt = SUN8I_MIXER_FBFMT_UYVY, |
---|
214 | | - .rgb = false, |
---|
215 | | - .csc = SUN8I_CSC_MODE_YUV2RGB, |
---|
216 | 175 | }, |
---|
217 | 176 | { |
---|
218 | 177 | .drm_fmt = DRM_FORMAT_VYUY, |
---|
219 | 178 | .de2_fmt = SUN8I_MIXER_FBFMT_VYUY, |
---|
220 | | - .rgb = false, |
---|
221 | | - .csc = SUN8I_CSC_MODE_YUV2RGB, |
---|
222 | 179 | }, |
---|
223 | 180 | { |
---|
224 | 181 | .drm_fmt = DRM_FORMAT_YUYV, |
---|
225 | 182 | .de2_fmt = SUN8I_MIXER_FBFMT_YUYV, |
---|
226 | | - .rgb = false, |
---|
227 | | - .csc = SUN8I_CSC_MODE_YUV2RGB, |
---|
228 | 183 | }, |
---|
229 | 184 | { |
---|
230 | 185 | .drm_fmt = DRM_FORMAT_YVYU, |
---|
231 | 186 | .de2_fmt = SUN8I_MIXER_FBFMT_YVYU, |
---|
232 | | - .rgb = false, |
---|
233 | | - .csc = SUN8I_CSC_MODE_YUV2RGB, |
---|
234 | 187 | }, |
---|
235 | 188 | { |
---|
236 | 189 | .drm_fmt = DRM_FORMAT_NV16, |
---|
237 | 190 | .de2_fmt = SUN8I_MIXER_FBFMT_NV16, |
---|
238 | | - .rgb = false, |
---|
239 | | - .csc = SUN8I_CSC_MODE_YUV2RGB, |
---|
240 | 191 | }, |
---|
241 | 192 | { |
---|
242 | 193 | .drm_fmt = DRM_FORMAT_NV61, |
---|
243 | 194 | .de2_fmt = SUN8I_MIXER_FBFMT_NV61, |
---|
244 | | - .rgb = false, |
---|
245 | | - .csc = SUN8I_CSC_MODE_YUV2RGB, |
---|
246 | 195 | }, |
---|
247 | 196 | { |
---|
248 | 197 | .drm_fmt = DRM_FORMAT_NV12, |
---|
249 | 198 | .de2_fmt = SUN8I_MIXER_FBFMT_NV12, |
---|
250 | | - .rgb = false, |
---|
251 | | - .csc = SUN8I_CSC_MODE_YUV2RGB, |
---|
252 | 199 | }, |
---|
253 | 200 | { |
---|
254 | 201 | .drm_fmt = DRM_FORMAT_NV21, |
---|
255 | 202 | .de2_fmt = SUN8I_MIXER_FBFMT_NV21, |
---|
256 | | - .rgb = false, |
---|
257 | | - .csc = SUN8I_CSC_MODE_YUV2RGB, |
---|
258 | 203 | }, |
---|
259 | 204 | { |
---|
260 | 205 | .drm_fmt = DRM_FORMAT_YUV422, |
---|
261 | 206 | .de2_fmt = SUN8I_MIXER_FBFMT_YUV422, |
---|
262 | | - .rgb = false, |
---|
263 | | - .csc = SUN8I_CSC_MODE_YUV2RGB, |
---|
264 | 207 | }, |
---|
265 | 208 | { |
---|
266 | 209 | .drm_fmt = DRM_FORMAT_YUV420, |
---|
267 | 210 | .de2_fmt = SUN8I_MIXER_FBFMT_YUV420, |
---|
268 | | - .rgb = false, |
---|
269 | | - .csc = SUN8I_CSC_MODE_YUV2RGB, |
---|
270 | 211 | }, |
---|
271 | 212 | { |
---|
272 | 213 | .drm_fmt = DRM_FORMAT_YUV411, |
---|
273 | 214 | .de2_fmt = SUN8I_MIXER_FBFMT_YUV411, |
---|
274 | | - .rgb = false, |
---|
275 | | - .csc = SUN8I_CSC_MODE_YUV2RGB, |
---|
276 | 215 | }, |
---|
277 | 216 | { |
---|
278 | 217 | .drm_fmt = DRM_FORMAT_YVU422, |
---|
279 | 218 | .de2_fmt = SUN8I_MIXER_FBFMT_YUV422, |
---|
280 | | - .rgb = false, |
---|
281 | | - .csc = SUN8I_CSC_MODE_YVU2RGB, |
---|
282 | 219 | }, |
---|
283 | 220 | { |
---|
284 | 221 | .drm_fmt = DRM_FORMAT_YVU420, |
---|
285 | 222 | .de2_fmt = SUN8I_MIXER_FBFMT_YUV420, |
---|
286 | | - .rgb = false, |
---|
287 | | - .csc = SUN8I_CSC_MODE_YVU2RGB, |
---|
288 | 223 | }, |
---|
289 | 224 | { |
---|
290 | 225 | .drm_fmt = DRM_FORMAT_YVU411, |
---|
291 | 226 | .de2_fmt = SUN8I_MIXER_FBFMT_YUV411, |
---|
292 | | - .rgb = false, |
---|
293 | | - .csc = SUN8I_CSC_MODE_YVU2RGB, |
---|
| 227 | + }, |
---|
| 228 | + { |
---|
| 229 | + .drm_fmt = DRM_FORMAT_P010, |
---|
| 230 | + .de2_fmt = SUN8I_MIXER_FBFMT_P010_YUV, |
---|
| 231 | + }, |
---|
| 232 | + { |
---|
| 233 | + .drm_fmt = DRM_FORMAT_P210, |
---|
| 234 | + .de2_fmt = SUN8I_MIXER_FBFMT_P210_YUV, |
---|
294 | 235 | }, |
---|
295 | 236 | }; |
---|
296 | 237 | |
---|
297 | | -const struct de2_fmt_info *sun8i_mixer_format_info(u32 format) |
---|
| 238 | +int sun8i_mixer_drm_format_to_hw(u32 format, u32 *hw_format) |
---|
298 | 239 | { |
---|
299 | 240 | unsigned int i; |
---|
300 | 241 | |
---|
301 | 242 | for (i = 0; i < ARRAY_SIZE(de2_formats); ++i) |
---|
302 | | - if (de2_formats[i].drm_fmt == format) |
---|
303 | | - return &de2_formats[i]; |
---|
| 243 | + if (de2_formats[i].drm_fmt == format) { |
---|
| 244 | + *hw_format = de2_formats[i].de2_fmt; |
---|
| 245 | + return 0; |
---|
| 246 | + } |
---|
304 | 247 | |
---|
305 | | - return NULL; |
---|
| 248 | + return -EINVAL; |
---|
306 | 249 | } |
---|
307 | 250 | |
---|
308 | 251 | static void sun8i_mixer_commit(struct sunxi_engine *engine) |
---|
.. | .. |
---|
334 | 277 | dev_err(drm->dev, |
---|
335 | 278 | "Couldn't initialize overlay plane\n"); |
---|
336 | 279 | return ERR_CAST(layer); |
---|
337 | | - }; |
---|
| 280 | + } |
---|
338 | 281 | |
---|
339 | 282 | planes[i] = &layer->plane; |
---|
340 | | - }; |
---|
| 283 | + } |
---|
341 | 284 | |
---|
342 | 285 | for (i = 0; i < mixer->cfg->ui_num; i++) { |
---|
343 | 286 | struct sun8i_ui_layer *layer; |
---|
.. | .. |
---|
347 | 290 | dev_err(drm->dev, "Couldn't initialize %s plane\n", |
---|
348 | 291 | i ? "overlay" : "primary"); |
---|
349 | 292 | return ERR_CAST(layer); |
---|
350 | | - }; |
---|
| 293 | + } |
---|
351 | 294 | |
---|
352 | 295 | planes[mixer->cfg->vi_num + i] = &layer->plane; |
---|
353 | | - }; |
---|
| 296 | + } |
---|
354 | 297 | |
---|
355 | 298 | return planes; |
---|
356 | 299 | } |
---|
.. | .. |
---|
360 | 303 | .layers_init = sun8i_layers_init, |
---|
361 | 304 | }; |
---|
362 | 305 | |
---|
363 | | -static struct regmap_config sun8i_mixer_regmap_config = { |
---|
| 306 | +static const struct regmap_config sun8i_mixer_regmap_config = { |
---|
364 | 307 | .reg_bits = 32, |
---|
365 | 308 | .val_bits = 32, |
---|
366 | 309 | .reg_stride = 4, |
---|
.. | .. |
---|
369 | 312 | |
---|
370 | 313 | static int sun8i_mixer_of_get_id(struct device_node *node) |
---|
371 | 314 | { |
---|
372 | | - struct device_node *port, *ep; |
---|
373 | | - int ret = -EINVAL; |
---|
| 315 | + struct device_node *ep, *remote; |
---|
| 316 | + struct of_endpoint of_ep; |
---|
374 | 317 | |
---|
375 | | - /* output is port 1 */ |
---|
376 | | - port = of_graph_get_port_by_id(node, 1); |
---|
377 | | - if (!port) |
---|
| 318 | + /* Output port is 1, and we want the first endpoint. */ |
---|
| 319 | + ep = of_graph_get_endpoint_by_regs(node, 1, -1); |
---|
| 320 | + if (!ep) |
---|
378 | 321 | return -EINVAL; |
---|
379 | 322 | |
---|
380 | | - /* try to find downstream endpoint */ |
---|
381 | | - for_each_available_child_of_node(port, ep) { |
---|
382 | | - struct device_node *remote; |
---|
383 | | - u32 reg; |
---|
| 323 | + remote = of_graph_get_remote_endpoint(ep); |
---|
| 324 | + of_node_put(ep); |
---|
| 325 | + if (!remote) |
---|
| 326 | + return -EINVAL; |
---|
384 | 327 | |
---|
385 | | - remote = of_graph_get_remote_endpoint(ep); |
---|
386 | | - if (!remote) |
---|
387 | | - continue; |
---|
388 | | - |
---|
389 | | - ret = of_property_read_u32(remote, "reg", ®); |
---|
390 | | - if (!ret) { |
---|
391 | | - of_node_put(remote); |
---|
392 | | - of_node_put(ep); |
---|
393 | | - of_node_put(port); |
---|
394 | | - |
---|
395 | | - return reg; |
---|
396 | | - } |
---|
397 | | - |
---|
398 | | - of_node_put(remote); |
---|
399 | | - } |
---|
400 | | - |
---|
401 | | - of_node_put(port); |
---|
402 | | - |
---|
403 | | - return ret; |
---|
| 328 | + of_graph_parse_endpoint(remote, &of_ep); |
---|
| 329 | + of_node_put(remote); |
---|
| 330 | + return of_ep.id; |
---|
404 | 331 | } |
---|
405 | 332 | |
---|
406 | 333 | static int sun8i_mixer_bind(struct device *dev, struct device *master, |
---|
.. | .. |
---|
412 | 339 | struct sun8i_mixer *mixer; |
---|
413 | 340 | struct resource *res; |
---|
414 | 341 | void __iomem *regs; |
---|
| 342 | + unsigned int base; |
---|
415 | 343 | int plane_cnt; |
---|
416 | 344 | int i, ret; |
---|
417 | 345 | |
---|
.. | .. |
---|
434 | 362 | dev_set_drvdata(dev, mixer); |
---|
435 | 363 | mixer->engine.ops = &sun8i_engine_ops; |
---|
436 | 364 | mixer->engine.node = dev->of_node; |
---|
| 365 | + |
---|
| 366 | + if (of_find_property(dev->of_node, "iommus", NULL)) { |
---|
| 367 | + /* |
---|
| 368 | + * This assume we have the same DMA constraints for |
---|
| 369 | + * all our the mixers in our pipeline. This sounds |
---|
| 370 | + * bad, but it has always been the case for us, and |
---|
| 371 | + * DRM doesn't do per-device allocation either, so we |
---|
| 372 | + * would need to fix DRM first... |
---|
| 373 | + */ |
---|
| 374 | + ret = of_dma_configure(drm->dev, dev->of_node, true); |
---|
| 375 | + if (ret) |
---|
| 376 | + return ret; |
---|
| 377 | + } |
---|
437 | 378 | |
---|
438 | 379 | /* |
---|
439 | 380 | * While this function can fail, we shouldn't do anything |
---|
.. | .. |
---|
500 | 441 | |
---|
501 | 442 | list_add_tail(&mixer->engine.list, &drv->engine_list); |
---|
502 | 443 | |
---|
503 | | - /* Reset the registers */ |
---|
504 | | - for (i = 0x0; i < 0x20000; i += 4) |
---|
505 | | - regmap_write(mixer->engine.regs, i, 0); |
---|
| 444 | + base = sun8i_blender_base(mixer); |
---|
| 445 | + |
---|
| 446 | + /* Reset registers and disable unused sub-engines */ |
---|
| 447 | + if (mixer->cfg->is_de3) { |
---|
| 448 | + for (i = 0; i < DE3_MIXER_UNIT_SIZE; i += 4) |
---|
| 449 | + regmap_write(mixer->engine.regs, i, 0); |
---|
| 450 | + |
---|
| 451 | + regmap_write(mixer->engine.regs, SUN50I_MIXER_FCE_EN, 0); |
---|
| 452 | + regmap_write(mixer->engine.regs, SUN50I_MIXER_PEAK_EN, 0); |
---|
| 453 | + regmap_write(mixer->engine.regs, SUN50I_MIXER_LCTI_EN, 0); |
---|
| 454 | + regmap_write(mixer->engine.regs, SUN50I_MIXER_BLS_EN, 0); |
---|
| 455 | + regmap_write(mixer->engine.regs, SUN50I_MIXER_FCC_EN, 0); |
---|
| 456 | + regmap_write(mixer->engine.regs, SUN50I_MIXER_DNS_EN, 0); |
---|
| 457 | + regmap_write(mixer->engine.regs, SUN50I_MIXER_DRC_EN, 0); |
---|
| 458 | + regmap_write(mixer->engine.regs, SUN50I_MIXER_FMT_EN, 0); |
---|
| 459 | + regmap_write(mixer->engine.regs, SUN50I_MIXER_CDC0_EN, 0); |
---|
| 460 | + regmap_write(mixer->engine.regs, SUN50I_MIXER_CDC1_EN, 0); |
---|
| 461 | + } else { |
---|
| 462 | + for (i = 0; i < DE2_MIXER_UNIT_SIZE; i += 4) |
---|
| 463 | + regmap_write(mixer->engine.regs, i, 0); |
---|
| 464 | + |
---|
| 465 | + regmap_write(mixer->engine.regs, SUN8I_MIXER_FCE_EN, 0); |
---|
| 466 | + regmap_write(mixer->engine.regs, SUN8I_MIXER_BWS_EN, 0); |
---|
| 467 | + regmap_write(mixer->engine.regs, SUN8I_MIXER_LTI_EN, 0); |
---|
| 468 | + regmap_write(mixer->engine.regs, SUN8I_MIXER_PEAK_EN, 0); |
---|
| 469 | + regmap_write(mixer->engine.regs, SUN8I_MIXER_ASE_EN, 0); |
---|
| 470 | + regmap_write(mixer->engine.regs, SUN8I_MIXER_FCC_EN, 0); |
---|
| 471 | + regmap_write(mixer->engine.regs, SUN8I_MIXER_DCSC_EN, 0); |
---|
| 472 | + } |
---|
506 | 473 | |
---|
507 | 474 | /* Enable the mixer */ |
---|
508 | 475 | regmap_write(mixer->engine.regs, SUN8I_MIXER_GLOBAL_CTL, |
---|
509 | 476 | SUN8I_MIXER_GLOBAL_CTL_RT_EN); |
---|
510 | 477 | |
---|
511 | 478 | /* Set background color to black */ |
---|
512 | | - regmap_write(mixer->engine.regs, SUN8I_MIXER_BLEND_BKCOLOR, |
---|
| 479 | + regmap_write(mixer->engine.regs, SUN8I_MIXER_BLEND_BKCOLOR(base), |
---|
513 | 480 | SUN8I_MIXER_BLEND_COLOR_BLACK); |
---|
514 | 481 | |
---|
515 | 482 | /* |
---|
516 | 483 | * Set fill color of bottom plane to black. Generally not needed |
---|
517 | 484 | * except when VI plane is at bottom (zpos = 0) and enabled. |
---|
518 | 485 | */ |
---|
519 | | - regmap_write(mixer->engine.regs, SUN8I_MIXER_BLEND_PIPE_CTL, |
---|
| 486 | + regmap_write(mixer->engine.regs, SUN8I_MIXER_BLEND_PIPE_CTL(base), |
---|
520 | 487 | SUN8I_MIXER_BLEND_PIPE_CTL_FC_EN(0)); |
---|
521 | | - regmap_write(mixer->engine.regs, SUN8I_MIXER_BLEND_ATTR_FCOLOR(0), |
---|
| 488 | + regmap_write(mixer->engine.regs, SUN8I_MIXER_BLEND_ATTR_FCOLOR(base, 0), |
---|
522 | 489 | SUN8I_MIXER_BLEND_COLOR_BLACK); |
---|
523 | 490 | |
---|
524 | 491 | plane_cnt = mixer->cfg->vi_num + mixer->cfg->ui_num; |
---|
525 | 492 | for (i = 0; i < plane_cnt; i++) |
---|
526 | | - regmap_write(mixer->engine.regs, SUN8I_MIXER_BLEND_MODE(i), |
---|
| 493 | + regmap_write(mixer->engine.regs, |
---|
| 494 | + SUN8I_MIXER_BLEND_MODE(base, i), |
---|
527 | 495 | SUN8I_MIXER_BLEND_MODE_DEF); |
---|
528 | 496 | |
---|
529 | | - regmap_update_bits(mixer->engine.regs, SUN8I_MIXER_BLEND_PIPE_CTL, |
---|
| 497 | + regmap_update_bits(mixer->engine.regs, SUN8I_MIXER_BLEND_PIPE_CTL(base), |
---|
530 | 498 | SUN8I_MIXER_BLEND_PIPE_CTL_EN_MSK, 0); |
---|
531 | 499 | |
---|
532 | 500 | return 0; |
---|
.. | .. |
---|
570 | 538 | static const struct sun8i_mixer_cfg sun8i_a83t_mixer0_cfg = { |
---|
571 | 539 | .ccsc = 0, |
---|
572 | 540 | .scaler_mask = 0xf, |
---|
| 541 | + .scanline_yuv = 2048, |
---|
573 | 542 | .ui_num = 3, |
---|
574 | 543 | .vi_num = 1, |
---|
575 | 544 | }; |
---|
.. | .. |
---|
577 | 546 | static const struct sun8i_mixer_cfg sun8i_a83t_mixer1_cfg = { |
---|
578 | 547 | .ccsc = 1, |
---|
579 | 548 | .scaler_mask = 0x3, |
---|
| 549 | + .scanline_yuv = 2048, |
---|
580 | 550 | .ui_num = 1, |
---|
581 | 551 | .vi_num = 1, |
---|
582 | 552 | }; |
---|
.. | .. |
---|
585 | 555 | .ccsc = 0, |
---|
586 | 556 | .mod_rate = 432000000, |
---|
587 | 557 | .scaler_mask = 0xf, |
---|
| 558 | + .scanline_yuv = 2048, |
---|
588 | 559 | .ui_num = 3, |
---|
| 560 | + .vi_num = 1, |
---|
| 561 | +}; |
---|
| 562 | + |
---|
| 563 | +static const struct sun8i_mixer_cfg sun8i_r40_mixer0_cfg = { |
---|
| 564 | + .ccsc = 0, |
---|
| 565 | + .mod_rate = 297000000, |
---|
| 566 | + .scaler_mask = 0xf, |
---|
| 567 | + .scanline_yuv = 2048, |
---|
| 568 | + .ui_num = 3, |
---|
| 569 | + .vi_num = 1, |
---|
| 570 | +}; |
---|
| 571 | + |
---|
| 572 | +static const struct sun8i_mixer_cfg sun8i_r40_mixer1_cfg = { |
---|
| 573 | + .ccsc = 1, |
---|
| 574 | + .mod_rate = 297000000, |
---|
| 575 | + .scaler_mask = 0x3, |
---|
| 576 | + .scanline_yuv = 2048, |
---|
| 577 | + .ui_num = 1, |
---|
589 | 578 | .vi_num = 1, |
---|
590 | 579 | }; |
---|
591 | 580 | |
---|
.. | .. |
---|
593 | 582 | .vi_num = 2, |
---|
594 | 583 | .ui_num = 1, |
---|
595 | 584 | .scaler_mask = 0x3, |
---|
| 585 | + .scanline_yuv = 2048, |
---|
596 | 586 | .ccsc = 0, |
---|
597 | 587 | .mod_rate = 150000000, |
---|
| 588 | +}; |
---|
| 589 | + |
---|
| 590 | +static const struct sun8i_mixer_cfg sun50i_a64_mixer0_cfg = { |
---|
| 591 | + .ccsc = 0, |
---|
| 592 | + .mod_rate = 297000000, |
---|
| 593 | + .scaler_mask = 0xf, |
---|
| 594 | + .scanline_yuv = 4096, |
---|
| 595 | + .ui_num = 3, |
---|
| 596 | + .vi_num = 1, |
---|
| 597 | +}; |
---|
| 598 | + |
---|
| 599 | +static const struct sun8i_mixer_cfg sun50i_a64_mixer1_cfg = { |
---|
| 600 | + .ccsc = 1, |
---|
| 601 | + .mod_rate = 297000000, |
---|
| 602 | + .scaler_mask = 0x3, |
---|
| 603 | + .scanline_yuv = 2048, |
---|
| 604 | + .ui_num = 1, |
---|
| 605 | + .vi_num = 1, |
---|
| 606 | +}; |
---|
| 607 | + |
---|
| 608 | +static const struct sun8i_mixer_cfg sun50i_h6_mixer0_cfg = { |
---|
| 609 | + .ccsc = 0, |
---|
| 610 | + .is_de3 = true, |
---|
| 611 | + .mod_rate = 600000000, |
---|
| 612 | + .scaler_mask = 0xf, |
---|
| 613 | + .scanline_yuv = 4096, |
---|
| 614 | + .ui_num = 3, |
---|
| 615 | + .vi_num = 1, |
---|
598 | 616 | }; |
---|
599 | 617 | |
---|
600 | 618 | static const struct of_device_id sun8i_mixer_of_table[] = { |
---|
.. | .. |
---|
611 | 629 | .data = &sun8i_h3_mixer0_cfg, |
---|
612 | 630 | }, |
---|
613 | 631 | { |
---|
| 632 | + .compatible = "allwinner,sun8i-r40-de2-mixer-0", |
---|
| 633 | + .data = &sun8i_r40_mixer0_cfg, |
---|
| 634 | + }, |
---|
| 635 | + { |
---|
| 636 | + .compatible = "allwinner,sun8i-r40-de2-mixer-1", |
---|
| 637 | + .data = &sun8i_r40_mixer1_cfg, |
---|
| 638 | + }, |
---|
| 639 | + { |
---|
614 | 640 | .compatible = "allwinner,sun8i-v3s-de2-mixer", |
---|
615 | 641 | .data = &sun8i_v3s_mixer_cfg, |
---|
616 | 642 | }, |
---|
| 643 | + { |
---|
| 644 | + .compatible = "allwinner,sun50i-a64-de2-mixer-0", |
---|
| 645 | + .data = &sun50i_a64_mixer0_cfg, |
---|
| 646 | + }, |
---|
| 647 | + { |
---|
| 648 | + .compatible = "allwinner,sun50i-a64-de2-mixer-1", |
---|
| 649 | + .data = &sun50i_a64_mixer1_cfg, |
---|
| 650 | + }, |
---|
| 651 | + { |
---|
| 652 | + .compatible = "allwinner,sun50i-h6-de3-mixer-0", |
---|
| 653 | + .data = &sun50i_h6_mixer0_cfg, |
---|
| 654 | + }, |
---|
617 | 655 | { } |
---|
618 | 656 | }; |
---|
619 | 657 | MODULE_DEVICE_TABLE(of, sun8i_mixer_of_table); |
---|