Commit | Line | Data |
---|---|---|
4bf8e196 LP |
1 | /* |
2 | * rcar_du_plane.c -- R-Car Display Unit Planes | |
3 | * | |
36d50464 | 4 | * Copyright (C) 2013-2014 Renesas Electronics Corporation |
4bf8e196 LP |
5 | * |
6 | * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com) | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2 of the License, or | |
11 | * (at your option) any later version. | |
12 | */ | |
13 | ||
14 | #include <drm/drmP.h> | |
15 | #include <drm/drm_crtc.h> | |
16 | #include <drm/drm_crtc_helper.h> | |
17 | #include <drm/drm_fb_cma_helper.h> | |
18 | #include <drm/drm_gem_cma_helper.h> | |
920888a2 | 19 | #include <drm/drm_plane_helper.h> |
4bf8e196 LP |
20 | |
21 | #include "rcar_du_drv.h" | |
22 | #include "rcar_du_kms.h" | |
23 | #include "rcar_du_plane.h" | |
24 | #include "rcar_du_regs.h" | |
25 | ||
26 | #define RCAR_DU_COLORKEY_NONE (0 << 24) | |
27 | #define RCAR_DU_COLORKEY_SOURCE (1 << 24) | |
28 | #define RCAR_DU_COLORKEY_MASK (1 << 24) | |
29 | ||
4bf8e196 LP |
30 | static inline struct rcar_du_plane *to_rcar_plane(struct drm_plane *plane) |
31 | { | |
917de180 | 32 | return container_of(plane, struct rcar_du_plane, plane); |
4bf8e196 LP |
33 | } |
34 | ||
cb2025d2 | 35 | static u32 rcar_du_plane_read(struct rcar_du_group *rgrp, |
4bf8e196 LP |
36 | unsigned int index, u32 reg) |
37 | { | |
cb2025d2 LP |
38 | return rcar_du_read(rgrp->dev, |
39 | rgrp->mmio_offset + index * PLANE_OFF + reg); | |
4bf8e196 LP |
40 | } |
41 | ||
cb2025d2 | 42 | static void rcar_du_plane_write(struct rcar_du_group *rgrp, |
4bf8e196 LP |
43 | unsigned int index, u32 reg, u32 data) |
44 | { | |
cb2025d2 LP |
45 | rcar_du_write(rgrp->dev, rgrp->mmio_offset + index * PLANE_OFF + reg, |
46 | data); | |
4bf8e196 LP |
47 | } |
48 | ||
920888a2 LP |
49 | static int rcar_du_plane_reserve_check(struct rcar_du_plane *plane, |
50 | const struct rcar_du_format_info *format) | |
51 | { | |
52 | struct rcar_du_group *rgrp = plane->group; | |
53 | unsigned int free; | |
54 | unsigned int i; | |
55 | int ret; | |
56 | ||
57 | mutex_lock(&rgrp->planes.lock); | |
58 | ||
59 | free = rgrp->planes.free; | |
60 | ||
61 | if (plane->hwindex != -1) { | |
62 | free |= 1 << plane->hwindex; | |
63 | if (plane->format->planes == 2) | |
64 | free |= 1 << ((plane->hwindex + 1) % 8); | |
65 | } | |
66 | ||
67 | for (i = 0; i < ARRAY_SIZE(rgrp->planes.planes); ++i) { | |
68 | if (!(free & (1 << i))) | |
69 | continue; | |
70 | ||
71 | if (format->planes == 1 || free & (1 << ((i + 1) % 8))) | |
72 | break; | |
73 | } | |
74 | ||
75 | ret = i == ARRAY_SIZE(rgrp->planes.planes) ? -EBUSY : 0; | |
76 | ||
77 | mutex_unlock(&rgrp->planes.lock); | |
78 | return ret; | |
79 | } | |
80 | ||
4bf8e196 LP |
81 | int rcar_du_plane_reserve(struct rcar_du_plane *plane, |
82 | const struct rcar_du_format_info *format) | |
83 | { | |
cb2025d2 | 84 | struct rcar_du_group *rgrp = plane->group; |
4bf8e196 LP |
85 | unsigned int i; |
86 | int ret = -EBUSY; | |
87 | ||
cb2025d2 | 88 | mutex_lock(&rgrp->planes.lock); |
4bf8e196 | 89 | |
30534604 | 90 | for (i = 0; i < RCAR_DU_NUM_HW_PLANES; ++i) { |
cb2025d2 | 91 | if (!(rgrp->planes.free & (1 << i))) |
4bf8e196 LP |
92 | continue; |
93 | ||
94 | if (format->planes == 1 || | |
cb2025d2 | 95 | rgrp->planes.free & (1 << ((i + 1) % 8))) |
4bf8e196 LP |
96 | break; |
97 | } | |
98 | ||
30534604 | 99 | if (i == RCAR_DU_NUM_HW_PLANES) |
4bf8e196 LP |
100 | goto done; |
101 | ||
cb2025d2 | 102 | rgrp->planes.free &= ~(1 << i); |
4bf8e196 | 103 | if (format->planes == 2) |
cb2025d2 | 104 | rgrp->planes.free &= ~(1 << ((i + 1) % 8)); |
4bf8e196 LP |
105 | |
106 | plane->hwindex = i; | |
107 | ||
108 | ret = 0; | |
109 | ||
110 | done: | |
cb2025d2 | 111 | mutex_unlock(&rgrp->planes.lock); |
4bf8e196 LP |
112 | return ret; |
113 | } | |
114 | ||
115 | void rcar_du_plane_release(struct rcar_du_plane *plane) | |
116 | { | |
cb2025d2 | 117 | struct rcar_du_group *rgrp = plane->group; |
4bf8e196 LP |
118 | |
119 | if (plane->hwindex == -1) | |
120 | return; | |
121 | ||
cb2025d2 LP |
122 | mutex_lock(&rgrp->planes.lock); |
123 | rgrp->planes.free |= 1 << plane->hwindex; | |
4bf8e196 | 124 | if (plane->format->planes == 2) |
cb2025d2 LP |
125 | rgrp->planes.free |= 1 << ((plane->hwindex + 1) % 8); |
126 | mutex_unlock(&rgrp->planes.lock); | |
4bf8e196 LP |
127 | |
128 | plane->hwindex = -1; | |
129 | } | |
130 | ||
131 | void rcar_du_plane_update_base(struct rcar_du_plane *plane) | |
132 | { | |
cb2025d2 | 133 | struct rcar_du_group *rgrp = plane->group; |
4bf8e196 | 134 | unsigned int index = plane->hwindex; |
906eff7f | 135 | bool interlaced; |
eb86301f LP |
136 | u32 mwr; |
137 | ||
906eff7f LP |
138 | interlaced = plane->crtc->mode.flags & DRM_MODE_FLAG_INTERLACE; |
139 | ||
140 | /* Memory pitch (expressed in pixels). Must be doubled for interlaced | |
141 | * operation with 32bpp formats. | |
142 | */ | |
eb86301f LP |
143 | if (plane->format->planes == 2) |
144 | mwr = plane->pitch; | |
145 | else | |
146 | mwr = plane->pitch * 8 / plane->format->bpp; | |
147 | ||
906eff7f LP |
148 | if (interlaced && plane->format->bpp == 32) |
149 | mwr *= 2; | |
150 | ||
eb86301f | 151 | rcar_du_plane_write(rgrp, index, PnMWR, mwr); |
4bf8e196 | 152 | |
9e7db06d LP |
153 | /* The Y position is expressed in raster line units and must be doubled |
154 | * for 32bpp formats, according to the R8A7790 datasheet. No mention of | |
155 | * doubling the Y position is found in the R8A7779 datasheet, but the | |
156 | * rule seems to apply there as well. | |
157 | * | |
906eff7f LP |
158 | * Despite not being documented, doubling seem not to be needed when |
159 | * operating in interlaced mode. | |
160 | * | |
9e7db06d | 161 | * Similarly, for the second plane, NV12 and NV21 formats seem to |
906eff7f LP |
162 | * require a halved Y position value, in both progressive and interlaced |
163 | * modes. | |
4bf8e196 | 164 | */ |
cb2025d2 LP |
165 | rcar_du_plane_write(rgrp, index, PnSPXR, plane->src_x); |
166 | rcar_du_plane_write(rgrp, index, PnSPYR, plane->src_y * | |
906eff7f | 167 | (!interlaced && plane->format->bpp == 32 ? 2 : 1)); |
cb2025d2 | 168 | rcar_du_plane_write(rgrp, index, PnDSA0R, plane->dma[0]); |
4bf8e196 LP |
169 | |
170 | if (plane->format->planes == 2) { | |
171 | index = (index + 1) % 8; | |
172 | ||
49785e25 LP |
173 | rcar_du_plane_write(rgrp, index, PnMWR, plane->pitch); |
174 | ||
cb2025d2 LP |
175 | rcar_du_plane_write(rgrp, index, PnSPXR, plane->src_x); |
176 | rcar_du_plane_write(rgrp, index, PnSPYR, plane->src_y * | |
4bf8e196 | 177 | (plane->format->bpp == 16 ? 2 : 1) / 2); |
cb2025d2 | 178 | rcar_du_plane_write(rgrp, index, PnDSA0R, plane->dma[1]); |
4bf8e196 LP |
179 | } |
180 | } | |
181 | ||
182 | void rcar_du_plane_compute_base(struct rcar_du_plane *plane, | |
183 | struct drm_framebuffer *fb) | |
184 | { | |
185 | struct drm_gem_cma_object *gem; | |
186 | ||
eb86301f LP |
187 | plane->pitch = fb->pitches[0]; |
188 | ||
4bf8e196 LP |
189 | gem = drm_fb_cma_get_gem_obj(fb, 0); |
190 | plane->dma[0] = gem->paddr + fb->offsets[0]; | |
191 | ||
192 | if (plane->format->planes == 2) { | |
193 | gem = drm_fb_cma_get_gem_obj(fb, 1); | |
194 | plane->dma[1] = gem->paddr + fb->offsets[1]; | |
195 | } | |
196 | } | |
197 | ||
198 | static void rcar_du_plane_setup_mode(struct rcar_du_plane *plane, | |
199 | unsigned int index) | |
200 | { | |
cb2025d2 | 201 | struct rcar_du_group *rgrp = plane->group; |
4bf8e196 LP |
202 | u32 colorkey; |
203 | u32 pnmr; | |
204 | ||
205 | /* The PnALPHAR register controls alpha-blending in 16bpp formats | |
206 | * (ARGB1555 and XRGB1555). | |
207 | * | |
208 | * For ARGB, set the alpha value to 0, and enable alpha-blending when | |
209 | * the A bit is 0. This maps A=0 to alpha=0 and A=1 to alpha=255. | |
210 | * | |
211 | * For XRGB, set the alpha value to the plane-wide alpha value and | |
212 | * enable alpha-blending regardless of the X bit value. | |
213 | */ | |
214 | if (plane->format->fourcc != DRM_FORMAT_XRGB1555) | |
cb2025d2 | 215 | rcar_du_plane_write(rgrp, index, PnALPHAR, PnALPHAR_ABIT_0); |
4bf8e196 | 216 | else |
cb2025d2 | 217 | rcar_du_plane_write(rgrp, index, PnALPHAR, |
4bf8e196 LP |
218 | PnALPHAR_ABIT_X | plane->alpha); |
219 | ||
220 | pnmr = PnMR_BM_MD | plane->format->pnmr; | |
221 | ||
222 | /* Disable color keying when requested. YUV formats have the | |
223 | * PnMR_SPIM_TP_OFF bit set in their pnmr field, disabling color keying | |
224 | * automatically. | |
225 | */ | |
226 | if ((plane->colorkey & RCAR_DU_COLORKEY_MASK) == RCAR_DU_COLORKEY_NONE) | |
227 | pnmr |= PnMR_SPIM_TP_OFF; | |
228 | ||
229 | /* For packed YUV formats we need to select the U/V order. */ | |
230 | if (plane->format->fourcc == DRM_FORMAT_YUYV) | |
231 | pnmr |= PnMR_YCDF_YUYV; | |
232 | ||
cb2025d2 | 233 | rcar_du_plane_write(rgrp, index, PnMR, pnmr); |
4bf8e196 LP |
234 | |
235 | switch (plane->format->fourcc) { | |
236 | case DRM_FORMAT_RGB565: | |
237 | colorkey = ((plane->colorkey & 0xf80000) >> 8) | |
238 | | ((plane->colorkey & 0x00fc00) >> 5) | |
239 | | ((plane->colorkey & 0x0000f8) >> 3); | |
cb2025d2 | 240 | rcar_du_plane_write(rgrp, index, PnTC2R, colorkey); |
4bf8e196 LP |
241 | break; |
242 | ||
243 | case DRM_FORMAT_ARGB1555: | |
244 | case DRM_FORMAT_XRGB1555: | |
245 | colorkey = ((plane->colorkey & 0xf80000) >> 9) | |
246 | | ((plane->colorkey & 0x00f800) >> 6) | |
247 | | ((plane->colorkey & 0x0000f8) >> 3); | |
cb2025d2 | 248 | rcar_du_plane_write(rgrp, index, PnTC2R, colorkey); |
4bf8e196 LP |
249 | break; |
250 | ||
251 | case DRM_FORMAT_XRGB8888: | |
252 | case DRM_FORMAT_ARGB8888: | |
cb2025d2 | 253 | rcar_du_plane_write(rgrp, index, PnTC3R, |
4bf8e196 LP |
254 | PnTC3R_CODE | (plane->colorkey & 0xffffff)); |
255 | break; | |
256 | } | |
257 | } | |
258 | ||
259 | static void __rcar_du_plane_setup(struct rcar_du_plane *plane, | |
260 | unsigned int index) | |
261 | { | |
cb2025d2 | 262 | struct rcar_du_group *rgrp = plane->group; |
4bf8e196 LP |
263 | u32 ddcr2 = PnDDCR2_CODE; |
264 | u32 ddcr4; | |
4bf8e196 LP |
265 | |
266 | /* Data format | |
267 | * | |
268 | * The data format is selected by the DDDF field in PnMR and the EDF | |
269 | * field in DDCR4. | |
270 | */ | |
cb2025d2 | 271 | ddcr4 = rcar_du_plane_read(rgrp, index, PnDDCR4); |
4bf8e196 LP |
272 | ddcr4 &= ~PnDDCR4_EDF_MASK; |
273 | ddcr4 |= plane->format->edf | PnDDCR4_CODE; | |
274 | ||
275 | rcar_du_plane_setup_mode(plane, index); | |
276 | ||
277 | if (plane->format->planes == 2) { | |
278 | if (plane->hwindex != index) { | |
279 | if (plane->format->fourcc == DRM_FORMAT_NV12 || | |
280 | plane->format->fourcc == DRM_FORMAT_NV21) | |
281 | ddcr2 |= PnDDCR2_Y420; | |
282 | ||
283 | if (plane->format->fourcc == DRM_FORMAT_NV21) | |
284 | ddcr2 |= PnDDCR2_NV21; | |
285 | ||
286 | ddcr2 |= PnDDCR2_DIVU; | |
287 | } else { | |
288 | ddcr2 |= PnDDCR2_DIVY; | |
289 | } | |
290 | } | |
291 | ||
cb2025d2 LP |
292 | rcar_du_plane_write(rgrp, index, PnDDCR2, ddcr2); |
293 | rcar_du_plane_write(rgrp, index, PnDDCR4, ddcr4); | |
4bf8e196 | 294 | |
4bf8e196 | 295 | /* Destination position and size */ |
cb2025d2 LP |
296 | rcar_du_plane_write(rgrp, index, PnDSXR, plane->width); |
297 | rcar_du_plane_write(rgrp, index, PnDSYR, plane->height); | |
298 | rcar_du_plane_write(rgrp, index, PnDPXR, plane->dst_x); | |
299 | rcar_du_plane_write(rgrp, index, PnDPYR, plane->dst_y); | |
4bf8e196 LP |
300 | |
301 | /* Wrap-around and blinking, disabled */ | |
cb2025d2 LP |
302 | rcar_du_plane_write(rgrp, index, PnWASPR, 0); |
303 | rcar_du_plane_write(rgrp, index, PnWAMWR, 4095); | |
304 | rcar_du_plane_write(rgrp, index, PnBTR, 0); | |
305 | rcar_du_plane_write(rgrp, index, PnMLR, 0); | |
4bf8e196 LP |
306 | } |
307 | ||
308 | void rcar_du_plane_setup(struct rcar_du_plane *plane) | |
309 | { | |
310 | __rcar_du_plane_setup(plane, plane->hwindex); | |
311 | if (plane->format->planes == 2) | |
312 | __rcar_du_plane_setup(plane, (plane->hwindex + 1) % 8); | |
313 | ||
314 | rcar_du_plane_update_base(plane); | |
315 | } | |
316 | ||
920888a2 LP |
317 | static int rcar_du_plane_atomic_check(struct drm_plane *plane, |
318 | struct drm_plane_state *state) | |
4bf8e196 LP |
319 | { |
320 | struct rcar_du_plane *rplane = to_rcar_plane(plane); | |
cb2025d2 | 321 | struct rcar_du_device *rcdu = rplane->group->dev; |
4bf8e196 LP |
322 | const struct rcar_du_format_info *format; |
323 | unsigned int nplanes; | |
324 | int ret; | |
325 | ||
920888a2 LP |
326 | if (!state->fb || !state->crtc) |
327 | return 0; | |
917de180 | 328 | |
920888a2 LP |
329 | if (state->src_w >> 16 != state->crtc_w || |
330 | state->src_h >> 16 != state->crtc_h) { | |
331 | dev_dbg(rcdu->dev, "%s: scaling not supported\n", __func__); | |
4bf8e196 LP |
332 | return -EINVAL; |
333 | } | |
334 | ||
920888a2 LP |
335 | format = rcar_du_format_info(state->fb->pixel_format); |
336 | if (format == NULL) { | |
337 | dev_dbg(rcdu->dev, "%s: unsupported format %08x\n", __func__, | |
338 | state->fb->pixel_format); | |
4bf8e196 LP |
339 | return -EINVAL; |
340 | } | |
341 | ||
342 | nplanes = rplane->format ? rplane->format->planes : 0; | |
343 | ||
920888a2 LP |
344 | /* If the number of required planes has changed we will need to |
345 | * reallocate hardware planes. Ensure free planes are available. | |
4bf8e196 LP |
346 | */ |
347 | if (format->planes != nplanes) { | |
920888a2 LP |
348 | ret = rcar_du_plane_reserve_check(rplane, format); |
349 | if (ret < 0) { | |
350 | dev_dbg(rcdu->dev, "%s: no available hardware plane\n", | |
351 | __func__); | |
4bf8e196 | 352 | return ret; |
920888a2 | 353 | } |
4bf8e196 LP |
354 | } |
355 | ||
4bf8e196 LP |
356 | return 0; |
357 | } | |
358 | ||
920888a2 | 359 | static void rcar_du_plane_disable(struct rcar_du_plane *rplane) |
4bf8e196 | 360 | { |
4bf8e196 | 361 | if (!rplane->enabled) |
920888a2 | 362 | return; |
4bf8e196 | 363 | |
cb2025d2 | 364 | mutex_lock(&rplane->group->planes.lock); |
4bf8e196 LP |
365 | rplane->enabled = false; |
366 | rcar_du_crtc_update_planes(rplane->crtc); | |
cb2025d2 | 367 | mutex_unlock(&rplane->group->planes.lock); |
4bf8e196 LP |
368 | |
369 | rcar_du_plane_release(rplane); | |
370 | ||
371 | rplane->crtc = NULL; | |
372 | rplane->format = NULL; | |
920888a2 | 373 | } |
4bf8e196 | 374 | |
920888a2 LP |
375 | static void rcar_du_plane_atomic_update(struct drm_plane *plane, |
376 | struct drm_plane_state *old_state) | |
377 | { | |
378 | struct rcar_du_plane *rplane = to_rcar_plane(plane); | |
379 | struct drm_plane_state *state = plane->state; | |
380 | const struct rcar_du_format_info *format; | |
381 | unsigned int nplanes; | |
382 | ||
383 | if (!state->crtc) { | |
384 | rcar_du_plane_disable(rplane); | |
385 | return; | |
386 | } | |
387 | ||
388 | format = rcar_du_format_info(state->fb->pixel_format); | |
389 | nplanes = rplane->format ? rplane->format->planes : 0; | |
390 | ||
391 | /* Reallocate hardware planes if the number of required planes has | |
392 | * changed. | |
393 | */ | |
394 | if (format->planes != nplanes) { | |
395 | rcar_du_plane_release(rplane); | |
396 | rcar_du_plane_reserve(rplane, format); | |
397 | } | |
398 | ||
399 | rplane->crtc = state->crtc; | |
400 | rplane->format = format; | |
401 | ||
402 | rplane->src_x = state->src_x >> 16; | |
403 | rplane->src_y = state->src_y >> 16; | |
404 | rplane->dst_x = state->crtc_x; | |
405 | rplane->dst_y = state->crtc_y; | |
406 | rplane->width = state->crtc_w; | |
407 | rplane->height = state->crtc_h; | |
408 | ||
409 | rcar_du_plane_compute_base(rplane, state->fb); | |
410 | rcar_du_plane_setup(rplane); | |
411 | ||
412 | mutex_lock(&rplane->group->planes.lock); | |
413 | rplane->enabled = true; | |
414 | rcar_du_crtc_update_planes(rplane->crtc); | |
415 | mutex_unlock(&rplane->group->planes.lock); | |
4bf8e196 LP |
416 | } |
417 | ||
920888a2 LP |
418 | static const struct drm_plane_helper_funcs rcar_du_plane_helper_funcs = { |
419 | .atomic_check = rcar_du_plane_atomic_check, | |
420 | .atomic_update = rcar_du_plane_atomic_update, | |
421 | }; | |
422 | ||
4bf8e196 LP |
423 | /* Both the .set_property and the .update_plane operations are called with the |
424 | * mode_config lock held. There is this no need to explicitly protect access to | |
425 | * the alpha and colorkey fields and the mode register. | |
426 | */ | |
427 | static void rcar_du_plane_set_alpha(struct rcar_du_plane *plane, u32 alpha) | |
428 | { | |
429 | if (plane->alpha == alpha) | |
430 | return; | |
431 | ||
432 | plane->alpha = alpha; | |
433 | if (!plane->enabled || plane->format->fourcc != DRM_FORMAT_XRGB1555) | |
434 | return; | |
435 | ||
436 | rcar_du_plane_setup_mode(plane, plane->hwindex); | |
437 | } | |
438 | ||
439 | static void rcar_du_plane_set_colorkey(struct rcar_du_plane *plane, | |
440 | u32 colorkey) | |
441 | { | |
442 | if (plane->colorkey == colorkey) | |
443 | return; | |
444 | ||
445 | plane->colorkey = colorkey; | |
446 | if (!plane->enabled) | |
447 | return; | |
448 | ||
449 | rcar_du_plane_setup_mode(plane, plane->hwindex); | |
450 | } | |
451 | ||
452 | static void rcar_du_plane_set_zpos(struct rcar_du_plane *plane, | |
453 | unsigned int zpos) | |
454 | { | |
cb2025d2 | 455 | mutex_lock(&plane->group->planes.lock); |
4bf8e196 LP |
456 | if (plane->zpos == zpos) |
457 | goto done; | |
458 | ||
459 | plane->zpos = zpos; | |
460 | if (!plane->enabled) | |
461 | goto done; | |
462 | ||
463 | rcar_du_crtc_update_planes(plane->crtc); | |
464 | ||
465 | done: | |
cb2025d2 | 466 | mutex_unlock(&plane->group->planes.lock); |
4bf8e196 LP |
467 | } |
468 | ||
469 | static int rcar_du_plane_set_property(struct drm_plane *plane, | |
470 | struct drm_property *property, | |
471 | uint64_t value) | |
472 | { | |
4bf8e196 | 473 | struct rcar_du_plane *rplane = to_rcar_plane(plane); |
cb2025d2 | 474 | struct rcar_du_group *rgrp = rplane->group; |
4bf8e196 | 475 | |
cb2025d2 | 476 | if (property == rgrp->planes.alpha) |
4bf8e196 | 477 | rcar_du_plane_set_alpha(rplane, value); |
cb2025d2 | 478 | else if (property == rgrp->planes.colorkey) |
4bf8e196 | 479 | rcar_du_plane_set_colorkey(rplane, value); |
cb2025d2 | 480 | else if (property == rgrp->planes.zpos) |
4bf8e196 LP |
481 | rcar_du_plane_set_zpos(rplane, value); |
482 | else | |
483 | return -EINVAL; | |
484 | ||
485 | return 0; | |
486 | } | |
487 | ||
488 | static const struct drm_plane_funcs rcar_du_plane_funcs = { | |
920888a2 LP |
489 | .update_plane = drm_plane_helper_update, |
490 | .disable_plane = drm_plane_helper_disable, | |
4bf8e196 LP |
491 | .set_property = rcar_du_plane_set_property, |
492 | .destroy = drm_plane_cleanup, | |
493 | }; | |
494 | ||
495 | static const uint32_t formats[] = { | |
496 | DRM_FORMAT_RGB565, | |
497 | DRM_FORMAT_ARGB1555, | |
498 | DRM_FORMAT_XRGB1555, | |
499 | DRM_FORMAT_XRGB8888, | |
500 | DRM_FORMAT_ARGB8888, | |
501 | DRM_FORMAT_UYVY, | |
502 | DRM_FORMAT_YUYV, | |
503 | DRM_FORMAT_NV12, | |
504 | DRM_FORMAT_NV21, | |
505 | DRM_FORMAT_NV16, | |
506 | }; | |
507 | ||
cb2025d2 | 508 | int rcar_du_planes_init(struct rcar_du_group *rgrp) |
4bf8e196 | 509 | { |
cb2025d2 LP |
510 | struct rcar_du_planes *planes = &rgrp->planes; |
511 | struct rcar_du_device *rcdu = rgrp->dev; | |
917de180 LP |
512 | unsigned int num_planes; |
513 | unsigned int num_crtcs; | |
514 | unsigned int crtcs; | |
4bf8e196 | 515 | unsigned int i; |
917de180 | 516 | int ret; |
4bf8e196 | 517 | |
cb2025d2 LP |
518 | mutex_init(&planes->lock); |
519 | planes->free = 0xff; | |
4bf8e196 | 520 | |
cb2025d2 | 521 | planes->alpha = |
4bf8e196 | 522 | drm_property_create_range(rcdu->ddev, 0, "alpha", 0, 255); |
cb2025d2 | 523 | if (planes->alpha == NULL) |
4bf8e196 LP |
524 | return -ENOMEM; |
525 | ||
526 | /* The color key is expressed as an RGB888 triplet stored in a 32-bit | |
527 | * integer in XRGB8888 format. Bit 24 is used as a flag to disable (0) | |
528 | * or enable source color keying (1). | |
529 | */ | |
cb2025d2 | 530 | planes->colorkey = |
4bf8e196 LP |
531 | drm_property_create_range(rcdu->ddev, 0, "colorkey", |
532 | 0, 0x01ffffff); | |
cb2025d2 | 533 | if (planes->colorkey == NULL) |
4bf8e196 LP |
534 | return -ENOMEM; |
535 | ||
cb2025d2 | 536 | planes->zpos = |
4bf8e196 | 537 | drm_property_create_range(rcdu->ddev, 0, "zpos", 1, 7); |
cb2025d2 | 538 | if (planes->zpos == NULL) |
4bf8e196 LP |
539 | return -ENOMEM; |
540 | ||
917de180 LP |
541 | /* Create one primary plane per in this group CRTC and seven overlay |
542 | * planes. | |
543 | */ | |
544 | num_crtcs = min(rcdu->num_crtcs - 2 * rgrp->index, 2U); | |
545 | num_planes = num_crtcs + 7; | |
546 | ||
547 | crtcs = ((1 << rcdu->num_crtcs) - 1) & (3 << (2 * rgrp->index)); | |
548 | ||
549 | for (i = 0; i < num_planes; ++i) { | |
550 | enum drm_plane_type type = i < num_crtcs | |
551 | ? DRM_PLANE_TYPE_PRIMARY | |
552 | : DRM_PLANE_TYPE_OVERLAY; | |
cb2025d2 | 553 | struct rcar_du_plane *plane = &planes->planes[i]; |
4bf8e196 | 554 | |
cb2025d2 | 555 | plane->group = rgrp; |
4bf8e196 LP |
556 | plane->hwindex = -1; |
557 | plane->alpha = 255; | |
558 | plane->colorkey = RCAR_DU_COLORKEY_NONE; | |
917de180 | 559 | plane->zpos = type == DRM_PLANE_TYPE_PRIMARY ? 0 : 1; |
4bf8e196 | 560 | |
917de180 LP |
561 | ret = drm_universal_plane_init(rcdu->ddev, &plane->plane, crtcs, |
562 | &rcar_du_plane_funcs, formats, | |
563 | ARRAY_SIZE(formats), type); | |
4bf8e196 LP |
564 | if (ret < 0) |
565 | return ret; | |
566 | ||
920888a2 LP |
567 | drm_plane_helper_add(&plane->plane, |
568 | &rcar_du_plane_helper_funcs); | |
569 | ||
917de180 LP |
570 | if (type == DRM_PLANE_TYPE_PRIMARY) |
571 | continue; | |
572 | ||
4bf8e196 | 573 | drm_object_attach_property(&plane->plane.base, |
cb2025d2 | 574 | planes->alpha, 255); |
4bf8e196 | 575 | drm_object_attach_property(&plane->plane.base, |
cb2025d2 | 576 | planes->colorkey, |
4bf8e196 LP |
577 | RCAR_DU_COLORKEY_NONE); |
578 | drm_object_attach_property(&plane->plane.base, | |
cb2025d2 | 579 | planes->zpos, 1); |
4bf8e196 LP |
580 | } |
581 | ||
582 | return 0; | |
583 | } |