blob: 53000644733f29c25a5db1edb5d24e5090bbc666 [file] [log] [blame]
Laurent Pinchart4bf8e192013-06-19 13:54:11 +02001/*
2 * rcar_du_plane.c -- R-Car Display Unit Planes
3 *
4 * Copyright (C) 2013 Renesas Corporation
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>
19
20#include "rcar_du_drv.h"
21#include "rcar_du_kms.h"
22#include "rcar_du_plane.h"
23#include "rcar_du_regs.h"
24
25#define RCAR_DU_COLORKEY_NONE (0 << 24)
26#define RCAR_DU_COLORKEY_SOURCE (1 << 24)
27#define RCAR_DU_COLORKEY_MASK (1 << 24)
28
29struct rcar_du_kms_plane {
30 struct drm_plane plane;
31 struct rcar_du_plane *hwplane;
32};
33
34static inline struct rcar_du_plane *to_rcar_plane(struct drm_plane *plane)
35{
36 return container_of(plane, struct rcar_du_kms_plane, plane)->hwplane;
37}
38
Laurent Pinchartcb2025d2013-06-16 21:01:02 +020039static u32 rcar_du_plane_read(struct rcar_du_group *rgrp,
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020040 unsigned int index, u32 reg)
41{
Laurent Pinchartcb2025d2013-06-16 21:01:02 +020042 return rcar_du_read(rgrp->dev,
43 rgrp->mmio_offset + index * PLANE_OFF + reg);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020044}
45
Laurent Pinchartcb2025d2013-06-16 21:01:02 +020046static void rcar_du_plane_write(struct rcar_du_group *rgrp,
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020047 unsigned int index, u32 reg, u32 data)
48{
Laurent Pinchartcb2025d2013-06-16 21:01:02 +020049 rcar_du_write(rgrp->dev, rgrp->mmio_offset + index * PLANE_OFF + reg,
50 data);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020051}
52
53int rcar_du_plane_reserve(struct rcar_du_plane *plane,
54 const struct rcar_du_format_info *format)
55{
Laurent Pinchartcb2025d2013-06-16 21:01:02 +020056 struct rcar_du_group *rgrp = plane->group;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020057 unsigned int i;
58 int ret = -EBUSY;
59
Laurent Pinchartcb2025d2013-06-16 21:01:02 +020060 mutex_lock(&rgrp->planes.lock);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020061
Laurent Pinchartcb2025d2013-06-16 21:01:02 +020062 for (i = 0; i < ARRAY_SIZE(rgrp->planes.planes); ++i) {
63 if (!(rgrp->planes.free & (1 << i)))
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020064 continue;
65
66 if (format->planes == 1 ||
Laurent Pinchartcb2025d2013-06-16 21:01:02 +020067 rgrp->planes.free & (1 << ((i + 1) % 8)))
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020068 break;
69 }
70
Laurent Pinchartcb2025d2013-06-16 21:01:02 +020071 if (i == ARRAY_SIZE(rgrp->planes.planes))
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020072 goto done;
73
Laurent Pinchartcb2025d2013-06-16 21:01:02 +020074 rgrp->planes.free &= ~(1 << i);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020075 if (format->planes == 2)
Laurent Pinchartcb2025d2013-06-16 21:01:02 +020076 rgrp->planes.free &= ~(1 << ((i + 1) % 8));
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020077
78 plane->hwindex = i;
79
80 ret = 0;
81
82done:
Laurent Pinchartcb2025d2013-06-16 21:01:02 +020083 mutex_unlock(&rgrp->planes.lock);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020084 return ret;
85}
86
87void rcar_du_plane_release(struct rcar_du_plane *plane)
88{
Laurent Pinchartcb2025d2013-06-16 21:01:02 +020089 struct rcar_du_group *rgrp = plane->group;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020090
91 if (plane->hwindex == -1)
92 return;
93
Laurent Pinchartcb2025d2013-06-16 21:01:02 +020094 mutex_lock(&rgrp->planes.lock);
95 rgrp->planes.free |= 1 << plane->hwindex;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020096 if (plane->format->planes == 2)
Laurent Pinchartcb2025d2013-06-16 21:01:02 +020097 rgrp->planes.free |= 1 << ((plane->hwindex + 1) % 8);
98 mutex_unlock(&rgrp->planes.lock);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020099
100 plane->hwindex = -1;
101}
102
103void rcar_du_plane_update_base(struct rcar_du_plane *plane)
104{
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200105 struct rcar_du_group *rgrp = plane->group;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200106 unsigned int index = plane->hwindex;
107
Laurent Pinchart9e7db062013-06-14 20:54:16 +0200108 /* The Y position is expressed in raster line units and must be doubled
109 * for 32bpp formats, according to the R8A7790 datasheet. No mention of
110 * doubling the Y position is found in the R8A7779 datasheet, but the
111 * rule seems to apply there as well.
112 *
113 * Similarly, for the second plane, NV12 and NV21 formats seem to
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200114 * require a halved Y position value.
115 */
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200116 rcar_du_plane_write(rgrp, index, PnSPXR, plane->src_x);
117 rcar_du_plane_write(rgrp, index, PnSPYR, plane->src_y *
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200118 (plane->format->bpp == 32 ? 2 : 1));
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200119 rcar_du_plane_write(rgrp, index, PnDSA0R, plane->dma[0]);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200120
121 if (plane->format->planes == 2) {
122 index = (index + 1) % 8;
123
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200124 rcar_du_plane_write(rgrp, index, PnSPXR, plane->src_x);
125 rcar_du_plane_write(rgrp, index, PnSPYR, plane->src_y *
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200126 (plane->format->bpp == 16 ? 2 : 1) / 2);
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200127 rcar_du_plane_write(rgrp, index, PnDSA0R, plane->dma[1]);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200128 }
129}
130
131void rcar_du_plane_compute_base(struct rcar_du_plane *plane,
132 struct drm_framebuffer *fb)
133{
134 struct drm_gem_cma_object *gem;
135
136 gem = drm_fb_cma_get_gem_obj(fb, 0);
137 plane->dma[0] = gem->paddr + fb->offsets[0];
138
139 if (plane->format->planes == 2) {
140 gem = drm_fb_cma_get_gem_obj(fb, 1);
141 plane->dma[1] = gem->paddr + fb->offsets[1];
142 }
143}
144
145static void rcar_du_plane_setup_mode(struct rcar_du_plane *plane,
146 unsigned int index)
147{
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200148 struct rcar_du_group *rgrp = plane->group;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200149 u32 colorkey;
150 u32 pnmr;
151
152 /* The PnALPHAR register controls alpha-blending in 16bpp formats
153 * (ARGB1555 and XRGB1555).
154 *
155 * For ARGB, set the alpha value to 0, and enable alpha-blending when
156 * the A bit is 0. This maps A=0 to alpha=0 and A=1 to alpha=255.
157 *
158 * For XRGB, set the alpha value to the plane-wide alpha value and
159 * enable alpha-blending regardless of the X bit value.
160 */
161 if (plane->format->fourcc != DRM_FORMAT_XRGB1555)
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200162 rcar_du_plane_write(rgrp, index, PnALPHAR, PnALPHAR_ABIT_0);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200163 else
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200164 rcar_du_plane_write(rgrp, index, PnALPHAR,
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200165 PnALPHAR_ABIT_X | plane->alpha);
166
167 pnmr = PnMR_BM_MD | plane->format->pnmr;
168
169 /* Disable color keying when requested. YUV formats have the
170 * PnMR_SPIM_TP_OFF bit set in their pnmr field, disabling color keying
171 * automatically.
172 */
173 if ((plane->colorkey & RCAR_DU_COLORKEY_MASK) == RCAR_DU_COLORKEY_NONE)
174 pnmr |= PnMR_SPIM_TP_OFF;
175
176 /* For packed YUV formats we need to select the U/V order. */
177 if (plane->format->fourcc == DRM_FORMAT_YUYV)
178 pnmr |= PnMR_YCDF_YUYV;
179
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200180 rcar_du_plane_write(rgrp, index, PnMR, pnmr);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200181
182 switch (plane->format->fourcc) {
183 case DRM_FORMAT_RGB565:
184 colorkey = ((plane->colorkey & 0xf80000) >> 8)
185 | ((plane->colorkey & 0x00fc00) >> 5)
186 | ((plane->colorkey & 0x0000f8) >> 3);
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200187 rcar_du_plane_write(rgrp, index, PnTC2R, colorkey);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200188 break;
189
190 case DRM_FORMAT_ARGB1555:
191 case DRM_FORMAT_XRGB1555:
192 colorkey = ((plane->colorkey & 0xf80000) >> 9)
193 | ((plane->colorkey & 0x00f800) >> 6)
194 | ((plane->colorkey & 0x0000f8) >> 3);
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200195 rcar_du_plane_write(rgrp, index, PnTC2R, colorkey);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200196 break;
197
198 case DRM_FORMAT_XRGB8888:
199 case DRM_FORMAT_ARGB8888:
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200200 rcar_du_plane_write(rgrp, index, PnTC3R,
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200201 PnTC3R_CODE | (plane->colorkey & 0xffffff));
202 break;
203 }
204}
205
206static void __rcar_du_plane_setup(struct rcar_du_plane *plane,
207 unsigned int index)
208{
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200209 struct rcar_du_group *rgrp = plane->group;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200210 u32 ddcr2 = PnDDCR2_CODE;
211 u32 ddcr4;
212 u32 mwr;
213
214 /* Data format
215 *
216 * The data format is selected by the DDDF field in PnMR and the EDF
217 * field in DDCR4.
218 */
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200219 ddcr4 = rcar_du_plane_read(rgrp, index, PnDDCR4);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200220 ddcr4 &= ~PnDDCR4_EDF_MASK;
221 ddcr4 |= plane->format->edf | PnDDCR4_CODE;
222
223 rcar_du_plane_setup_mode(plane, index);
224
225 if (plane->format->planes == 2) {
226 if (plane->hwindex != index) {
227 if (plane->format->fourcc == DRM_FORMAT_NV12 ||
228 plane->format->fourcc == DRM_FORMAT_NV21)
229 ddcr2 |= PnDDCR2_Y420;
230
231 if (plane->format->fourcc == DRM_FORMAT_NV21)
232 ddcr2 |= PnDDCR2_NV21;
233
234 ddcr2 |= PnDDCR2_DIVU;
235 } else {
236 ddcr2 |= PnDDCR2_DIVY;
237 }
238 }
239
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200240 rcar_du_plane_write(rgrp, index, PnDDCR2, ddcr2);
241 rcar_du_plane_write(rgrp, index, PnDDCR4, ddcr4);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200242
243 /* Memory pitch (expressed in pixels) */
244 if (plane->format->planes == 2)
245 mwr = plane->pitch;
246 else
247 mwr = plane->pitch * 8 / plane->format->bpp;
248
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200249 rcar_du_plane_write(rgrp, index, PnMWR, mwr);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200250
251 /* Destination position and size */
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200252 rcar_du_plane_write(rgrp, index, PnDSXR, plane->width);
253 rcar_du_plane_write(rgrp, index, PnDSYR, plane->height);
254 rcar_du_plane_write(rgrp, index, PnDPXR, plane->dst_x);
255 rcar_du_plane_write(rgrp, index, PnDPYR, plane->dst_y);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200256
257 /* Wrap-around and blinking, disabled */
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200258 rcar_du_plane_write(rgrp, index, PnWASPR, 0);
259 rcar_du_plane_write(rgrp, index, PnWAMWR, 4095);
260 rcar_du_plane_write(rgrp, index, PnBTR, 0);
261 rcar_du_plane_write(rgrp, index, PnMLR, 0);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200262}
263
264void rcar_du_plane_setup(struct rcar_du_plane *plane)
265{
266 __rcar_du_plane_setup(plane, plane->hwindex);
267 if (plane->format->planes == 2)
268 __rcar_du_plane_setup(plane, (plane->hwindex + 1) % 8);
269
270 rcar_du_plane_update_base(plane);
271}
272
273static int
274rcar_du_plane_update(struct drm_plane *plane, struct drm_crtc *crtc,
275 struct drm_framebuffer *fb, int crtc_x, int crtc_y,
276 unsigned int crtc_w, unsigned int crtc_h,
277 uint32_t src_x, uint32_t src_y,
278 uint32_t src_w, uint32_t src_h)
279{
280 struct rcar_du_plane *rplane = to_rcar_plane(plane);
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200281 struct rcar_du_device *rcdu = rplane->group->dev;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200282 const struct rcar_du_format_info *format;
283 unsigned int nplanes;
284 int ret;
285
286 format = rcar_du_format_info(fb->pixel_format);
287 if (format == NULL) {
288 dev_dbg(rcdu->dev, "%s: unsupported format %08x\n", __func__,
289 fb->pixel_format);
290 return -EINVAL;
291 }
292
293 if (src_w >> 16 != crtc_w || src_h >> 16 != crtc_h) {
294 dev_dbg(rcdu->dev, "%s: scaling not supported\n", __func__);
295 return -EINVAL;
296 }
297
298 nplanes = rplane->format ? rplane->format->planes : 0;
299
300 /* Reallocate hardware planes if the number of required planes has
301 * changed.
302 */
303 if (format->planes != nplanes) {
304 rcar_du_plane_release(rplane);
305 ret = rcar_du_plane_reserve(rplane, format);
306 if (ret < 0)
307 return ret;
308 }
309
310 rplane->crtc = crtc;
311 rplane->format = format;
312 rplane->pitch = fb->pitches[0];
313
314 rplane->src_x = src_x >> 16;
315 rplane->src_y = src_y >> 16;
316 rplane->dst_x = crtc_x;
317 rplane->dst_y = crtc_y;
318 rplane->width = crtc_w;
319 rplane->height = crtc_h;
320
321 rcar_du_plane_compute_base(rplane, fb);
322 rcar_du_plane_setup(rplane);
323
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200324 mutex_lock(&rplane->group->planes.lock);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200325 rplane->enabled = true;
326 rcar_du_crtc_update_planes(rplane->crtc);
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200327 mutex_unlock(&rplane->group->planes.lock);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200328
329 return 0;
330}
331
332static int rcar_du_plane_disable(struct drm_plane *plane)
333{
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200334 struct rcar_du_plane *rplane = to_rcar_plane(plane);
335
336 if (!rplane->enabled)
337 return 0;
338
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200339 mutex_lock(&rplane->group->planes.lock);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200340 rplane->enabled = false;
341 rcar_du_crtc_update_planes(rplane->crtc);
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200342 mutex_unlock(&rplane->group->planes.lock);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200343
344 rcar_du_plane_release(rplane);
345
346 rplane->crtc = NULL;
347 rplane->format = NULL;
348
349 return 0;
350}
351
352/* Both the .set_property and the .update_plane operations are called with the
353 * mode_config lock held. There is this no need to explicitly protect access to
354 * the alpha and colorkey fields and the mode register.
355 */
356static void rcar_du_plane_set_alpha(struct rcar_du_plane *plane, u32 alpha)
357{
358 if (plane->alpha == alpha)
359 return;
360
361 plane->alpha = alpha;
362 if (!plane->enabled || plane->format->fourcc != DRM_FORMAT_XRGB1555)
363 return;
364
365 rcar_du_plane_setup_mode(plane, plane->hwindex);
366}
367
368static void rcar_du_plane_set_colorkey(struct rcar_du_plane *plane,
369 u32 colorkey)
370{
371 if (plane->colorkey == colorkey)
372 return;
373
374 plane->colorkey = colorkey;
375 if (!plane->enabled)
376 return;
377
378 rcar_du_plane_setup_mode(plane, plane->hwindex);
379}
380
381static void rcar_du_plane_set_zpos(struct rcar_du_plane *plane,
382 unsigned int zpos)
383{
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200384 mutex_lock(&plane->group->planes.lock);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200385 if (plane->zpos == zpos)
386 goto done;
387
388 plane->zpos = zpos;
389 if (!plane->enabled)
390 goto done;
391
392 rcar_du_crtc_update_planes(plane->crtc);
393
394done:
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200395 mutex_unlock(&plane->group->planes.lock);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200396}
397
398static int rcar_du_plane_set_property(struct drm_plane *plane,
399 struct drm_property *property,
400 uint64_t value)
401{
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200402 struct rcar_du_plane *rplane = to_rcar_plane(plane);
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200403 struct rcar_du_group *rgrp = rplane->group;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200404
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200405 if (property == rgrp->planes.alpha)
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200406 rcar_du_plane_set_alpha(rplane, value);
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200407 else if (property == rgrp->planes.colorkey)
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200408 rcar_du_plane_set_colorkey(rplane, value);
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200409 else if (property == rgrp->planes.zpos)
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200410 rcar_du_plane_set_zpos(rplane, value);
411 else
412 return -EINVAL;
413
414 return 0;
415}
416
417static const struct drm_plane_funcs rcar_du_plane_funcs = {
418 .update_plane = rcar_du_plane_update,
419 .disable_plane = rcar_du_plane_disable,
420 .set_property = rcar_du_plane_set_property,
421 .destroy = drm_plane_cleanup,
422};
423
424static const uint32_t formats[] = {
425 DRM_FORMAT_RGB565,
426 DRM_FORMAT_ARGB1555,
427 DRM_FORMAT_XRGB1555,
428 DRM_FORMAT_XRGB8888,
429 DRM_FORMAT_ARGB8888,
430 DRM_FORMAT_UYVY,
431 DRM_FORMAT_YUYV,
432 DRM_FORMAT_NV12,
433 DRM_FORMAT_NV21,
434 DRM_FORMAT_NV16,
435};
436
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200437int rcar_du_planes_init(struct rcar_du_group *rgrp)
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200438{
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200439 struct rcar_du_planes *planes = &rgrp->planes;
440 struct rcar_du_device *rcdu = rgrp->dev;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200441 unsigned int i;
442
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200443 mutex_init(&planes->lock);
444 planes->free = 0xff;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200445
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200446 planes->alpha =
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200447 drm_property_create_range(rcdu->ddev, 0, "alpha", 0, 255);
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200448 if (planes->alpha == NULL)
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200449 return -ENOMEM;
450
451 /* The color key is expressed as an RGB888 triplet stored in a 32-bit
452 * integer in XRGB8888 format. Bit 24 is used as a flag to disable (0)
453 * or enable source color keying (1).
454 */
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200455 planes->colorkey =
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200456 drm_property_create_range(rcdu->ddev, 0, "colorkey",
457 0, 0x01ffffff);
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200458 if (planes->colorkey == NULL)
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200459 return -ENOMEM;
460
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200461 planes->zpos =
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200462 drm_property_create_range(rcdu->ddev, 0, "zpos", 1, 7);
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200463 if (planes->zpos == NULL)
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200464 return -ENOMEM;
465
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200466 for (i = 0; i < ARRAY_SIZE(planes->planes); ++i) {
467 struct rcar_du_plane *plane = &planes->planes[i];
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200468
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200469 plane->group = rgrp;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200470 plane->hwindex = -1;
471 plane->alpha = 255;
472 plane->colorkey = RCAR_DU_COLORKEY_NONE;
473 plane->zpos = 0;
474 }
475
476 return 0;
477}
478
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200479int rcar_du_planes_register(struct rcar_du_group *rgrp)
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200480{
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200481 struct rcar_du_planes *planes = &rgrp->planes;
482 struct rcar_du_device *rcdu = rgrp->dev;
Laurent Pincharta5f0ef52013-06-17 00:29:25 +0200483 unsigned int crtcs;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200484 unsigned int i;
485 int ret;
486
Laurent Pincharta5f0ef52013-06-17 00:29:25 +0200487 crtcs = ((1 << rcdu->num_crtcs) - 1) & (3 << (2 * rgrp->index));
488
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200489 for (i = 0; i < RCAR_DU_NUM_KMS_PLANES; ++i) {
490 struct rcar_du_kms_plane *plane;
491
492 plane = devm_kzalloc(rcdu->dev, sizeof(*plane), GFP_KERNEL);
493 if (plane == NULL)
494 return -ENOMEM;
495
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200496 plane->hwplane = &planes->planes[i + 2];
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200497 plane->hwplane->zpos = 1;
498
Laurent Pincharta5f0ef52013-06-17 00:29:25 +0200499 ret = drm_plane_init(rcdu->ddev, &plane->plane, crtcs,
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200500 &rcar_du_plane_funcs, formats,
501 ARRAY_SIZE(formats), false);
502 if (ret < 0)
503 return ret;
504
505 drm_object_attach_property(&plane->plane.base,
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200506 planes->alpha, 255);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200507 drm_object_attach_property(&plane->plane.base,
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200508 planes->colorkey,
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200509 RCAR_DU_COLORKEY_NONE);
510 drm_object_attach_property(&plane->plane.base,
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200511 planes->zpos, 1);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200512 }
513
514 return 0;
515}