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