blob: fb3ea4f95d4aa2e7cc8b6ea006d674c1c8cd9f55 [file] [log] [blame]
Laurent Pinchart4bf8e192013-06-19 13:54:11 +02001/*
2 * rcar_du_plane.c -- R-Car Display Unit Planes
3 *
Laurent Pinchart36d50462014-02-06 18:13:52 +01004 * Copyright (C) 2013-2014 Renesas Electronics Corporation
Laurent Pinchart4bf8e192013-06-19 13:54:11 +02005 *
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;
Laurent Pincharteb863012013-11-13 14:26:01 +0100107 u32 mwr;
108
109 /* Memory pitch (expressed in pixels) */
110 if (plane->format->planes == 2)
111 mwr = plane->pitch;
112 else
113 mwr = plane->pitch * 8 / plane->format->bpp;
114
115 rcar_du_plane_write(rgrp, index, PnMWR, mwr);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200116
Laurent Pinchart9e7db062013-06-14 20:54:16 +0200117 /* The Y position is expressed in raster line units and must be doubled
118 * for 32bpp formats, according to the R8A7790 datasheet. No mention of
119 * doubling the Y position is found in the R8A7779 datasheet, but the
120 * rule seems to apply there as well.
121 *
122 * Similarly, for the second plane, NV12 and NV21 formats seem to
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200123 * require a halved Y position value.
124 */
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200125 rcar_du_plane_write(rgrp, index, PnSPXR, plane->src_x);
126 rcar_du_plane_write(rgrp, index, PnSPYR, plane->src_y *
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200127 (plane->format->bpp == 32 ? 2 : 1));
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200128 rcar_du_plane_write(rgrp, index, PnDSA0R, plane->dma[0]);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200129
130 if (plane->format->planes == 2) {
131 index = (index + 1) % 8;
132
Laurent Pinchart49785e22014-12-09 22:45:11 +0200133 rcar_du_plane_write(rgrp, index, PnMWR, plane->pitch);
134
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200135 rcar_du_plane_write(rgrp, index, PnSPXR, plane->src_x);
136 rcar_du_plane_write(rgrp, index, PnSPYR, plane->src_y *
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200137 (plane->format->bpp == 16 ? 2 : 1) / 2);
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200138 rcar_du_plane_write(rgrp, index, PnDSA0R, plane->dma[1]);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200139 }
140}
141
142void rcar_du_plane_compute_base(struct rcar_du_plane *plane,
143 struct drm_framebuffer *fb)
144{
145 struct drm_gem_cma_object *gem;
146
Laurent Pincharteb863012013-11-13 14:26:01 +0100147 plane->pitch = fb->pitches[0];
148
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200149 gem = drm_fb_cma_get_gem_obj(fb, 0);
150 plane->dma[0] = gem->paddr + fb->offsets[0];
151
152 if (plane->format->planes == 2) {
153 gem = drm_fb_cma_get_gem_obj(fb, 1);
154 plane->dma[1] = gem->paddr + fb->offsets[1];
155 }
156}
157
158static void rcar_du_plane_setup_mode(struct rcar_du_plane *plane,
159 unsigned int index)
160{
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200161 struct rcar_du_group *rgrp = plane->group;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200162 u32 colorkey;
163 u32 pnmr;
164
165 /* The PnALPHAR register controls alpha-blending in 16bpp formats
166 * (ARGB1555 and XRGB1555).
167 *
168 * For ARGB, set the alpha value to 0, and enable alpha-blending when
169 * the A bit is 0. This maps A=0 to alpha=0 and A=1 to alpha=255.
170 *
171 * For XRGB, set the alpha value to the plane-wide alpha value and
172 * enable alpha-blending regardless of the X bit value.
173 */
174 if (plane->format->fourcc != DRM_FORMAT_XRGB1555)
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200175 rcar_du_plane_write(rgrp, index, PnALPHAR, PnALPHAR_ABIT_0);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200176 else
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200177 rcar_du_plane_write(rgrp, index, PnALPHAR,
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200178 PnALPHAR_ABIT_X | plane->alpha);
179
180 pnmr = PnMR_BM_MD | plane->format->pnmr;
181
182 /* Disable color keying when requested. YUV formats have the
183 * PnMR_SPIM_TP_OFF bit set in their pnmr field, disabling color keying
184 * automatically.
185 */
186 if ((plane->colorkey & RCAR_DU_COLORKEY_MASK) == RCAR_DU_COLORKEY_NONE)
187 pnmr |= PnMR_SPIM_TP_OFF;
188
189 /* For packed YUV formats we need to select the U/V order. */
190 if (plane->format->fourcc == DRM_FORMAT_YUYV)
191 pnmr |= PnMR_YCDF_YUYV;
192
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200193 rcar_du_plane_write(rgrp, index, PnMR, pnmr);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200194
195 switch (plane->format->fourcc) {
196 case DRM_FORMAT_RGB565:
197 colorkey = ((plane->colorkey & 0xf80000) >> 8)
198 | ((plane->colorkey & 0x00fc00) >> 5)
199 | ((plane->colorkey & 0x0000f8) >> 3);
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200200 rcar_du_plane_write(rgrp, index, PnTC2R, colorkey);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200201 break;
202
203 case DRM_FORMAT_ARGB1555:
204 case DRM_FORMAT_XRGB1555:
205 colorkey = ((plane->colorkey & 0xf80000) >> 9)
206 | ((plane->colorkey & 0x00f800) >> 6)
207 | ((plane->colorkey & 0x0000f8) >> 3);
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200208 rcar_du_plane_write(rgrp, index, PnTC2R, colorkey);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200209 break;
210
211 case DRM_FORMAT_XRGB8888:
212 case DRM_FORMAT_ARGB8888:
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200213 rcar_du_plane_write(rgrp, index, PnTC3R,
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200214 PnTC3R_CODE | (plane->colorkey & 0xffffff));
215 break;
216 }
217}
218
219static void __rcar_du_plane_setup(struct rcar_du_plane *plane,
220 unsigned int index)
221{
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200222 struct rcar_du_group *rgrp = plane->group;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200223 u32 ddcr2 = PnDDCR2_CODE;
224 u32 ddcr4;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200225
226 /* Data format
227 *
228 * The data format is selected by the DDDF field in PnMR and the EDF
229 * field in DDCR4.
230 */
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200231 ddcr4 = rcar_du_plane_read(rgrp, index, PnDDCR4);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200232 ddcr4 &= ~PnDDCR4_EDF_MASK;
233 ddcr4 |= plane->format->edf | PnDDCR4_CODE;
234
235 rcar_du_plane_setup_mode(plane, index);
236
237 if (plane->format->planes == 2) {
238 if (plane->hwindex != index) {
239 if (plane->format->fourcc == DRM_FORMAT_NV12 ||
240 plane->format->fourcc == DRM_FORMAT_NV21)
241 ddcr2 |= PnDDCR2_Y420;
242
243 if (plane->format->fourcc == DRM_FORMAT_NV21)
244 ddcr2 |= PnDDCR2_NV21;
245
246 ddcr2 |= PnDDCR2_DIVU;
247 } else {
248 ddcr2 |= PnDDCR2_DIVY;
249 }
250 }
251
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200252 rcar_du_plane_write(rgrp, index, PnDDCR2, ddcr2);
253 rcar_du_plane_write(rgrp, index, PnDDCR4, ddcr4);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200254
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200255 /* Destination position and size */
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200256 rcar_du_plane_write(rgrp, index, PnDSXR, plane->width);
257 rcar_du_plane_write(rgrp, index, PnDSYR, plane->height);
258 rcar_du_plane_write(rgrp, index, PnDPXR, plane->dst_x);
259 rcar_du_plane_write(rgrp, index, PnDPYR, plane->dst_y);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200260
261 /* Wrap-around and blinking, disabled */
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200262 rcar_du_plane_write(rgrp, index, PnWASPR, 0);
263 rcar_du_plane_write(rgrp, index, PnWAMWR, 4095);
264 rcar_du_plane_write(rgrp, index, PnBTR, 0);
265 rcar_du_plane_write(rgrp, index, PnMLR, 0);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200266}
267
268void rcar_du_plane_setup(struct rcar_du_plane *plane)
269{
270 __rcar_du_plane_setup(plane, plane->hwindex);
271 if (plane->format->planes == 2)
272 __rcar_du_plane_setup(plane, (plane->hwindex + 1) % 8);
273
274 rcar_du_plane_update_base(plane);
275}
276
277static int
278rcar_du_plane_update(struct drm_plane *plane, struct drm_crtc *crtc,
279 struct drm_framebuffer *fb, int crtc_x, int crtc_y,
280 unsigned int crtc_w, unsigned int crtc_h,
281 uint32_t src_x, uint32_t src_y,
282 uint32_t src_w, uint32_t src_h)
283{
284 struct rcar_du_plane *rplane = to_rcar_plane(plane);
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200285 struct rcar_du_device *rcdu = rplane->group->dev;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200286 const struct rcar_du_format_info *format;
287 unsigned int nplanes;
288 int ret;
289
290 format = rcar_du_format_info(fb->pixel_format);
291 if (format == NULL) {
292 dev_dbg(rcdu->dev, "%s: unsupported format %08x\n", __func__,
293 fb->pixel_format);
294 return -EINVAL;
295 }
296
297 if (src_w >> 16 != crtc_w || src_h >> 16 != crtc_h) {
298 dev_dbg(rcdu->dev, "%s: scaling not supported\n", __func__);
299 return -EINVAL;
300 }
301
302 nplanes = rplane->format ? rplane->format->planes : 0;
303
304 /* Reallocate hardware planes if the number of required planes has
305 * changed.
306 */
307 if (format->planes != nplanes) {
308 rcar_du_plane_release(rplane);
309 ret = rcar_du_plane_reserve(rplane, format);
310 if (ret < 0)
311 return ret;
312 }
313
314 rplane->crtc = crtc;
315 rplane->format = format;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200316
317 rplane->src_x = src_x >> 16;
318 rplane->src_y = src_y >> 16;
319 rplane->dst_x = crtc_x;
320 rplane->dst_y = crtc_y;
321 rplane->width = crtc_w;
322 rplane->height = crtc_h;
323
324 rcar_du_plane_compute_base(rplane, fb);
325 rcar_du_plane_setup(rplane);
326
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200327 mutex_lock(&rplane->group->planes.lock);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200328 rplane->enabled = true;
329 rcar_du_crtc_update_planes(rplane->crtc);
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200330 mutex_unlock(&rplane->group->planes.lock);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200331
332 return 0;
333}
334
335static int rcar_du_plane_disable(struct drm_plane *plane)
336{
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200337 struct rcar_du_plane *rplane = to_rcar_plane(plane);
338
339 if (!rplane->enabled)
340 return 0;
341
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200342 mutex_lock(&rplane->group->planes.lock);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200343 rplane->enabled = false;
344 rcar_du_crtc_update_planes(rplane->crtc);
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200345 mutex_unlock(&rplane->group->planes.lock);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200346
347 rcar_du_plane_release(rplane);
348
349 rplane->crtc = NULL;
350 rplane->format = NULL;
351
352 return 0;
353}
354
355/* Both the .set_property and the .update_plane operations are called with the
356 * mode_config lock held. There is this no need to explicitly protect access to
357 * the alpha and colorkey fields and the mode register.
358 */
359static void rcar_du_plane_set_alpha(struct rcar_du_plane *plane, u32 alpha)
360{
361 if (plane->alpha == alpha)
362 return;
363
364 plane->alpha = alpha;
365 if (!plane->enabled || plane->format->fourcc != DRM_FORMAT_XRGB1555)
366 return;
367
368 rcar_du_plane_setup_mode(plane, plane->hwindex);
369}
370
371static void rcar_du_plane_set_colorkey(struct rcar_du_plane *plane,
372 u32 colorkey)
373{
374 if (plane->colorkey == colorkey)
375 return;
376
377 plane->colorkey = colorkey;
378 if (!plane->enabled)
379 return;
380
381 rcar_du_plane_setup_mode(plane, plane->hwindex);
382}
383
384static void rcar_du_plane_set_zpos(struct rcar_du_plane *plane,
385 unsigned int zpos)
386{
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200387 mutex_lock(&plane->group->planes.lock);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200388 if (plane->zpos == zpos)
389 goto done;
390
391 plane->zpos = zpos;
392 if (!plane->enabled)
393 goto done;
394
395 rcar_du_crtc_update_planes(plane->crtc);
396
397done:
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200398 mutex_unlock(&plane->group->planes.lock);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200399}
400
401static int rcar_du_plane_set_property(struct drm_plane *plane,
402 struct drm_property *property,
403 uint64_t value)
404{
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200405 struct rcar_du_plane *rplane = to_rcar_plane(plane);
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200406 struct rcar_du_group *rgrp = rplane->group;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200407
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200408 if (property == rgrp->planes.alpha)
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200409 rcar_du_plane_set_alpha(rplane, value);
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200410 else if (property == rgrp->planes.colorkey)
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200411 rcar_du_plane_set_colorkey(rplane, value);
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200412 else if (property == rgrp->planes.zpos)
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200413 rcar_du_plane_set_zpos(rplane, value);
414 else
415 return -EINVAL;
416
417 return 0;
418}
419
420static const struct drm_plane_funcs rcar_du_plane_funcs = {
421 .update_plane = rcar_du_plane_update,
422 .disable_plane = rcar_du_plane_disable,
423 .set_property = rcar_du_plane_set_property,
424 .destroy = drm_plane_cleanup,
425};
426
427static const uint32_t formats[] = {
428 DRM_FORMAT_RGB565,
429 DRM_FORMAT_ARGB1555,
430 DRM_FORMAT_XRGB1555,
431 DRM_FORMAT_XRGB8888,
432 DRM_FORMAT_ARGB8888,
433 DRM_FORMAT_UYVY,
434 DRM_FORMAT_YUYV,
435 DRM_FORMAT_NV12,
436 DRM_FORMAT_NV21,
437 DRM_FORMAT_NV16,
438};
439
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200440int rcar_du_planes_init(struct rcar_du_group *rgrp)
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200441{
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200442 struct rcar_du_planes *planes = &rgrp->planes;
443 struct rcar_du_device *rcdu = rgrp->dev;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200444 unsigned int i;
445
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200446 mutex_init(&planes->lock);
447 planes->free = 0xff;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200448
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200449 planes->alpha =
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200450 drm_property_create_range(rcdu->ddev, 0, "alpha", 0, 255);
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200451 if (planes->alpha == NULL)
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200452 return -ENOMEM;
453
454 /* The color key is expressed as an RGB888 triplet stored in a 32-bit
455 * integer in XRGB8888 format. Bit 24 is used as a flag to disable (0)
456 * or enable source color keying (1).
457 */
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200458 planes->colorkey =
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200459 drm_property_create_range(rcdu->ddev, 0, "colorkey",
460 0, 0x01ffffff);
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200461 if (planes->colorkey == NULL)
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200462 return -ENOMEM;
463
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200464 planes->zpos =
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200465 drm_property_create_range(rcdu->ddev, 0, "zpos", 1, 7);
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200466 if (planes->zpos == NULL)
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200467 return -ENOMEM;
468
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200469 for (i = 0; i < ARRAY_SIZE(planes->planes); ++i) {
470 struct rcar_du_plane *plane = &planes->planes[i];
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200471
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200472 plane->group = rgrp;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200473 plane->hwindex = -1;
474 plane->alpha = 255;
475 plane->colorkey = RCAR_DU_COLORKEY_NONE;
476 plane->zpos = 0;
477 }
478
479 return 0;
480}
481
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200482int rcar_du_planes_register(struct rcar_du_group *rgrp)
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200483{
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200484 struct rcar_du_planes *planes = &rgrp->planes;
485 struct rcar_du_device *rcdu = rgrp->dev;
Laurent Pincharta5f0ef52013-06-17 00:29:25 +0200486 unsigned int crtcs;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200487 unsigned int i;
488 int ret;
489
Laurent Pincharta5f0ef52013-06-17 00:29:25 +0200490 crtcs = ((1 << rcdu->num_crtcs) - 1) & (3 << (2 * rgrp->index));
491
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200492 for (i = 0; i < RCAR_DU_NUM_KMS_PLANES; ++i) {
493 struct rcar_du_kms_plane *plane;
494
495 plane = devm_kzalloc(rcdu->dev, sizeof(*plane), GFP_KERNEL);
496 if (plane == NULL)
497 return -ENOMEM;
498
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200499 plane->hwplane = &planes->planes[i + 2];
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200500 plane->hwplane->zpos = 1;
501
Laurent Pincharta5f0ef52013-06-17 00:29:25 +0200502 ret = drm_plane_init(rcdu->ddev, &plane->plane, crtcs,
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200503 &rcar_du_plane_funcs, formats,
504 ARRAY_SIZE(formats), false);
505 if (ret < 0)
506 return ret;
507
508 drm_object_attach_property(&plane->plane.base,
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200509 planes->alpha, 255);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200510 drm_object_attach_property(&plane->plane.base,
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200511 planes->colorkey,
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200512 RCAR_DU_COLORKEY_NONE);
513 drm_object_attach_property(&plane->plane.base,
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200514 planes->zpos, 1);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200515 }
516
517 return 0;
518}