blob: 2fa5745fca37aacac75312542f41b8469d91e4e1 [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>
Laurent Pinchart3e8da872015-02-20 11:30:59 +020015#include <drm/drm_atomic_helper.h>
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020016#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>
Laurent Pinchart920888a2015-02-18 12:18:05 +020020#include <drm/drm_plane_helper.h>
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020021
22#include "rcar_du_drv.h"
Laurent Pinchart34a04f22013-06-21 17:54:50 +020023#include "rcar_du_group.h"
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020024#include "rcar_du_kms.h"
25#include "rcar_du_plane.h"
26#include "rcar_du_regs.h"
27
28#define RCAR_DU_COLORKEY_NONE (0 << 24)
29#define RCAR_DU_COLORKEY_SOURCE (1 << 24)
30#define RCAR_DU_COLORKEY_MASK (1 << 24)
31
Laurent Pinchartcb2025d2013-06-16 21:01:02 +020032static void rcar_du_plane_write(struct rcar_du_group *rgrp,
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020033 unsigned int index, u32 reg, u32 data)
34{
Laurent Pinchartcb2025d2013-06-16 21:01:02 +020035 rcar_du_write(rgrp->dev, rgrp->mmio_offset + index * PLANE_OFF + reg,
36 data);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020037}
38
Laurent Pinchart34a04f22013-06-21 17:54:50 +020039static void rcar_du_plane_setup_scanout(struct rcar_du_group *rgrp,
40 const struct rcar_du_plane_state *state)
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020041{
Laurent Pinchart5bfcbce2015-02-23 02:59:35 +020042 unsigned int src_x = state->state.src_x >> 16;
43 unsigned int src_y = state->state.src_y >> 16;
Laurent Pinchart5ee5a812015-02-25 18:27:19 +020044 unsigned int index = state->hwindex;
Laurent Pinchart2f13c522015-07-27 13:43:09 +030045 unsigned int pitch;
Laurent Pinchart906eff72014-12-09 19:11:18 +020046 bool interlaced;
Laurent Pinchart2f13c522015-07-27 13:43:09 +030047 u32 dma[2];
Laurent Pincharteb863012013-11-13 14:26:01 +010048
Laurent Pinchart5bfcbce2015-02-23 02:59:35 +020049 interlaced = state->state.crtc->state->adjusted_mode.flags
Laurent Pinchart47094192015-02-22 19:24:59 +020050 & DRM_MODE_FLAG_INTERLACE;
Laurent Pinchart906eff72014-12-09 19:11:18 +020051
Laurent Pinchart34a04f22013-06-21 17:54:50 +020052 if (state->source == RCAR_DU_PLANE_MEMORY) {
53 struct drm_framebuffer *fb = state->state.fb;
54 struct drm_gem_cma_object *gem;
55 unsigned int i;
56
57 if (state->format->planes == 2)
58 pitch = fb->pitches[0];
59 else
60 pitch = fb->pitches[0] * 8 / state->format->bpp;
61
62 for (i = 0; i < state->format->planes; ++i) {
63 gem = drm_fb_cma_get_gem_obj(fb, i);
64 dma[i] = gem->paddr + fb->offsets[i];
65 }
66 } else {
67 pitch = state->state.src_w >> 16;
68 dma[0] = 0;
69 dma[1] = 0;
70 }
71
Laurent Pinchart906eff72014-12-09 19:11:18 +020072 /* Memory pitch (expressed in pixels). Must be doubled for interlaced
73 * operation with 32bpp formats.
74 */
Laurent Pinchart2f13c522015-07-27 13:43:09 +030075 rcar_du_plane_write(rgrp, index, PnMWR,
76 (interlaced && state->format->bpp == 32) ?
77 pitch * 2 : pitch);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020078
Laurent Pinchart9e7db062013-06-14 20:54:16 +020079 /* The Y position is expressed in raster line units and must be doubled
80 * for 32bpp formats, according to the R8A7790 datasheet. No mention of
81 * doubling the Y position is found in the R8A7779 datasheet, but the
82 * rule seems to apply there as well.
83 *
Laurent Pinchart906eff72014-12-09 19:11:18 +020084 * Despite not being documented, doubling seem not to be needed when
85 * operating in interlaced mode.
86 *
Laurent Pinchart9e7db062013-06-14 20:54:16 +020087 * Similarly, for the second plane, NV12 and NV21 formats seem to
Laurent Pinchart906eff72014-12-09 19:11:18 +020088 * require a halved Y position value, in both progressive and interlaced
89 * modes.
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020090 */
Laurent Pinchart287bdf02015-02-20 15:58:38 +020091 rcar_du_plane_write(rgrp, index, PnSPXR, src_x);
92 rcar_du_plane_write(rgrp, index, PnSPYR, src_y *
Laurent Pinchart5bfcbce2015-02-23 02:59:35 +020093 (!interlaced && state->format->bpp == 32 ? 2 : 1));
Laurent Pinchartf398f342015-02-23 01:25:19 +020094
Laurent Pinchart2f13c522015-07-27 13:43:09 +030095 rcar_du_plane_write(rgrp, index, PnDSA0R, dma[0]);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020096
Laurent Pinchart5bfcbce2015-02-23 02:59:35 +020097 if (state->format->planes == 2) {
Laurent Pinchart4bf8e192013-06-19 13:54:11 +020098 index = (index + 1) % 8;
99
Laurent Pinchart2f13c522015-07-27 13:43:09 +0300100 rcar_du_plane_write(rgrp, index, PnMWR, pitch);
Laurent Pinchart49785e22014-12-09 22:45:11 +0200101
Laurent Pinchart287bdf02015-02-20 15:58:38 +0200102 rcar_du_plane_write(rgrp, index, PnSPXR, src_x);
103 rcar_du_plane_write(rgrp, index, PnSPYR, src_y *
Laurent Pinchart5bfcbce2015-02-23 02:59:35 +0200104 (state->format->bpp == 16 ? 2 : 1) / 2);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200105
Laurent Pinchart2f13c522015-07-27 13:43:09 +0300106 rcar_du_plane_write(rgrp, index, PnDSA0R, dma[1]);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200107 }
108}
109
Laurent Pinchart34a04f22013-06-21 17:54:50 +0200110static void rcar_du_plane_setup_mode(struct rcar_du_group *rgrp,
111 unsigned int index,
112 const struct rcar_du_plane_state *state)
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200113{
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200114 u32 colorkey;
115 u32 pnmr;
116
117 /* The PnALPHAR register controls alpha-blending in 16bpp formats
118 * (ARGB1555 and XRGB1555).
119 *
120 * For ARGB, set the alpha value to 0, and enable alpha-blending when
121 * the A bit is 0. This maps A=0 to alpha=0 and A=1 to alpha=255.
122 *
123 * For XRGB, set the alpha value to the plane-wide alpha value and
124 * enable alpha-blending regardless of the X bit value.
125 */
Laurent Pinchart5bfcbce2015-02-23 02:59:35 +0200126 if (state->format->fourcc != DRM_FORMAT_XRGB1555)
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200127 rcar_du_plane_write(rgrp, index, PnALPHAR, PnALPHAR_ABIT_0);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200128 else
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200129 rcar_du_plane_write(rgrp, index, PnALPHAR,
Laurent Pinchart4407cc02015-02-23 02:36:31 +0200130 PnALPHAR_ABIT_X | state->alpha);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200131
Laurent Pinchart5bfcbce2015-02-23 02:59:35 +0200132 pnmr = PnMR_BM_MD | state->format->pnmr;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200133
134 /* Disable color keying when requested. YUV formats have the
135 * PnMR_SPIM_TP_OFF bit set in their pnmr field, disabling color keying
136 * automatically.
137 */
Laurent Pinchart4407cc02015-02-23 02:36:31 +0200138 if ((state->colorkey & RCAR_DU_COLORKEY_MASK) == RCAR_DU_COLORKEY_NONE)
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200139 pnmr |= PnMR_SPIM_TP_OFF;
140
141 /* For packed YUV formats we need to select the U/V order. */
Laurent Pinchart5bfcbce2015-02-23 02:59:35 +0200142 if (state->format->fourcc == DRM_FORMAT_YUYV)
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200143 pnmr |= PnMR_YCDF_YUYV;
144
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200145 rcar_du_plane_write(rgrp, index, PnMR, pnmr);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200146
Laurent Pinchart5bfcbce2015-02-23 02:59:35 +0200147 switch (state->format->fourcc) {
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200148 case DRM_FORMAT_RGB565:
Laurent Pinchart4407cc02015-02-23 02:36:31 +0200149 colorkey = ((state->colorkey & 0xf80000) >> 8)
150 | ((state->colorkey & 0x00fc00) >> 5)
151 | ((state->colorkey & 0x0000f8) >> 3);
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200152 rcar_du_plane_write(rgrp, index, PnTC2R, colorkey);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200153 break;
154
155 case DRM_FORMAT_ARGB1555:
156 case DRM_FORMAT_XRGB1555:
Laurent Pinchart4407cc02015-02-23 02:36:31 +0200157 colorkey = ((state->colorkey & 0xf80000) >> 9)
158 | ((state->colorkey & 0x00f800) >> 6)
159 | ((state->colorkey & 0x0000f8) >> 3);
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200160 rcar_du_plane_write(rgrp, index, PnTC2R, colorkey);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200161 break;
162
163 case DRM_FORMAT_XRGB8888:
164 case DRM_FORMAT_ARGB8888:
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200165 rcar_du_plane_write(rgrp, index, PnTC3R,
Laurent Pinchart4407cc02015-02-23 02:36:31 +0200166 PnTC3R_CODE | (state->colorkey & 0xffffff));
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200167 break;
168 }
169}
170
Laurent Pinchart34a04f22013-06-21 17:54:50 +0200171static void rcar_du_plane_setup_format(struct rcar_du_group *rgrp,
172 unsigned int index,
173 const struct rcar_du_plane_state *state)
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200174{
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200175 u32 ddcr2 = PnDDCR2_CODE;
176 u32 ddcr4;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200177
178 /* Data format
179 *
180 * The data format is selected by the DDDF field in PnMR and the EDF
181 * field in DDCR4.
182 */
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200183
Laurent Pinchart34a04f22013-06-21 17:54:50 +0200184 rcar_du_plane_setup_mode(rgrp, index, state);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200185
Laurent Pinchart5bfcbce2015-02-23 02:59:35 +0200186 if (state->format->planes == 2) {
Laurent Pinchart5ee5a812015-02-25 18:27:19 +0200187 if (state->hwindex != index) {
Laurent Pinchart5bfcbce2015-02-23 02:59:35 +0200188 if (state->format->fourcc == DRM_FORMAT_NV12 ||
189 state->format->fourcc == DRM_FORMAT_NV21)
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200190 ddcr2 |= PnDDCR2_Y420;
191
Laurent Pinchart5bfcbce2015-02-23 02:59:35 +0200192 if (state->format->fourcc == DRM_FORMAT_NV21)
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200193 ddcr2 |= PnDDCR2_NV21;
194
195 ddcr2 |= PnDDCR2_DIVU;
196 } else {
197 ddcr2 |= PnDDCR2_DIVY;
198 }
199 }
200
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200201 rcar_du_plane_write(rgrp, index, PnDDCR2, ddcr2);
Laurent Pinchartff967362015-07-27 12:46:44 +0300202
203 ddcr4 = state->format->edf | PnDDCR4_CODE;
Laurent Pinchart34a04f22013-06-21 17:54:50 +0200204 if (state->source != RCAR_DU_PLANE_MEMORY)
205 ddcr4 |= PnDDCR4_VSPS;
Laurent Pinchartff967362015-07-27 12:46:44 +0300206
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200207 rcar_du_plane_write(rgrp, index, PnDDCR4, ddcr4);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200208
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200209 /* Destination position and size */
Laurent Pinchart34a04f22013-06-21 17:54:50 +0200210 rcar_du_plane_write(rgrp, index, PnDSXR, state->state.crtc_w);
211 rcar_du_plane_write(rgrp, index, PnDSYR, state->state.crtc_h);
212 rcar_du_plane_write(rgrp, index, PnDPXR, state->state.crtc_x);
213 rcar_du_plane_write(rgrp, index, PnDPYR, state->state.crtc_y);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200214
215 /* Wrap-around and blinking, disabled */
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200216 rcar_du_plane_write(rgrp, index, PnWASPR, 0);
217 rcar_du_plane_write(rgrp, index, PnWAMWR, 4095);
218 rcar_du_plane_write(rgrp, index, PnBTR, 0);
219 rcar_du_plane_write(rgrp, index, PnMLR, 0);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200220}
221
222void rcar_du_plane_setup(struct rcar_du_plane *plane)
223{
Laurent Pinchart5bfcbce2015-02-23 02:59:35 +0200224 struct rcar_du_plane_state *state =
Laurent Pinchartec69a402015-04-29 00:48:17 +0300225 to_rcar_plane_state(plane->plane.state);
Laurent Pinchart34a04f22013-06-21 17:54:50 +0200226 struct rcar_du_group *rgrp = plane->group;
Laurent Pinchart5bfcbce2015-02-23 02:59:35 +0200227
Laurent Pinchart34a04f22013-06-21 17:54:50 +0200228 rcar_du_plane_setup_format(rgrp, state->hwindex, state);
Laurent Pinchart5bfcbce2015-02-23 02:59:35 +0200229 if (state->format->planes == 2)
Laurent Pinchart34a04f22013-06-21 17:54:50 +0200230 rcar_du_plane_setup_format(rgrp, (state->hwindex + 1) % 8,
231 state);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200232
Laurent Pinchart34a04f22013-06-21 17:54:50 +0200233 rcar_du_plane_setup_scanout(rgrp, state);
234
235 if (state->source == RCAR_DU_PLANE_VSPD1) {
236 unsigned int vspd1_sink = rgrp->index ? 2 : 0;
237 struct rcar_du_device *rcdu = rgrp->dev;
238
239 if (rcdu->vspd1_sink != vspd1_sink) {
240 rcdu->vspd1_sink = vspd1_sink;
241 rcar_du_set_dpad0_vsp1_routing(rcdu);
242 }
243 }
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200244}
245
Laurent Pinchart920888a2015-02-18 12:18:05 +0200246static int rcar_du_plane_atomic_check(struct drm_plane *plane,
247 struct drm_plane_state *state)
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200248{
Laurent Pinchartec69a402015-04-29 00:48:17 +0300249 struct rcar_du_plane_state *rstate = to_rcar_plane_state(state);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200250 struct rcar_du_plane *rplane = to_rcar_plane(plane);
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200251 struct rcar_du_device *rcdu = rplane->group->dev;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200252
Laurent Pinchart5ee5a812015-02-25 18:27:19 +0200253 if (!state->fb || !state->crtc) {
254 rstate->format = NULL;
Laurent Pinchart920888a2015-02-18 12:18:05 +0200255 return 0;
Laurent Pinchart5ee5a812015-02-25 18:27:19 +0200256 }
Laurent Pinchart917de182015-02-17 18:34:17 +0200257
Laurent Pinchart920888a2015-02-18 12:18:05 +0200258 if (state->src_w >> 16 != state->crtc_w ||
259 state->src_h >> 16 != state->crtc_h) {
260 dev_dbg(rcdu->dev, "%s: scaling not supported\n", __func__);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200261 return -EINVAL;
262 }
263
Laurent Pinchart5ee5a812015-02-25 18:27:19 +0200264 rstate->format = rcar_du_format_info(state->fb->pixel_format);
265 if (rstate->format == NULL) {
Laurent Pinchart920888a2015-02-18 12:18:05 +0200266 dev_dbg(rcdu->dev, "%s: unsupported format %08x\n", __func__,
267 state->fb->pixel_format);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200268 return -EINVAL;
269 }
270
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200271 return 0;
272}
273
Laurent Pinchart920888a2015-02-18 12:18:05 +0200274static void rcar_du_plane_atomic_update(struct drm_plane *plane,
275 struct drm_plane_state *old_state)
276{
277 struct rcar_du_plane *rplane = to_rcar_plane(plane);
Laurent Pinchart2af03942013-08-24 02:17:03 +0200278 struct rcar_du_plane_state *old_rstate;
279 struct rcar_du_plane_state *new_rstate;
Laurent Pinchart5bfcbce2015-02-23 02:59:35 +0200280
Laurent Pinchart2af03942013-08-24 02:17:03 +0200281 if (!plane->state->crtc)
282 return;
283
284 rcar_du_plane_setup(rplane);
285
286 /* Check whether the source has changed from memory to live source or
287 * from live source to memory. The source has been configured by the
288 * VSPS bit in the PnDDCR4 register. Although the datasheet states that
289 * the bit is updated during vertical blanking, it seems that updates
290 * only occur when the DU group is held in reset through the DSYSR.DRES
291 * bit. We thus need to restart the group if the source changes.
292 */
293 old_rstate = to_rcar_plane_state(old_state);
294 new_rstate = to_rcar_plane_state(plane->state);
295
296 if ((old_rstate->source == RCAR_DU_PLANE_MEMORY) !=
297 (new_rstate->source == RCAR_DU_PLANE_MEMORY))
298 rplane->group->need_restart = true;
Laurent Pinchart920888a2015-02-18 12:18:05 +0200299}
300
301static const struct drm_plane_helper_funcs rcar_du_plane_helper_funcs = {
302 .atomic_check = rcar_du_plane_atomic_check,
303 .atomic_update = rcar_du_plane_atomic_update,
304};
305
Laurent Pinchart4407cc02015-02-23 02:36:31 +0200306static struct drm_plane_state *
307rcar_du_plane_atomic_duplicate_state(struct drm_plane *plane)
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200308{
Laurent Pinchart4407cc02015-02-23 02:36:31 +0200309 struct rcar_du_plane_state *state;
310 struct rcar_du_plane_state *copy;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200311
Laurent Pinchart263b39f2015-05-27 16:36:29 +0300312 if (WARN_ON(!plane->state))
313 return NULL;
314
Laurent Pinchartec69a402015-04-29 00:48:17 +0300315 state = to_rcar_plane_state(plane->state);
Laurent Pinchart4407cc02015-02-23 02:36:31 +0200316 copy = kmemdup(state, sizeof(*state), GFP_KERNEL);
317 if (copy == NULL)
318 return NULL;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200319
Laurent Pinchart263b39f2015-05-27 16:36:29 +0300320 __drm_atomic_helper_plane_duplicate_state(plane, &copy->state);
Laurent Pinchart4407cc02015-02-23 02:36:31 +0200321
322 return &copy->state;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200323}
324
Laurent Pinchart4407cc02015-02-23 02:36:31 +0200325static void rcar_du_plane_atomic_destroy_state(struct drm_plane *plane,
326 struct drm_plane_state *state)
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200327{
Laurent Pinchart263b39f2015-05-27 16:36:29 +0300328 __drm_atomic_helper_plane_destroy_state(plane, state);
Laurent Pinchartec69a402015-04-29 00:48:17 +0300329 kfree(to_rcar_plane_state(state));
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200330}
331
Laurent Pincharta32a3c82015-07-27 11:42:54 +0300332static void rcar_du_plane_reset(struct drm_plane *plane)
333{
334 struct rcar_du_plane_state *state;
335
336 if (plane->state) {
337 rcar_du_plane_atomic_destroy_state(plane, plane->state);
338 plane->state = NULL;
339 }
340
341 state = kzalloc(sizeof(*state), GFP_KERNEL);
342 if (state == NULL)
343 return;
344
345 state->hwindex = -1;
Laurent Pinchartaf8ad962013-06-21 17:36:15 +0200346 state->source = RCAR_DU_PLANE_MEMORY;
Laurent Pincharta32a3c82015-07-27 11:42:54 +0300347 state->alpha = 255;
348 state->colorkey = RCAR_DU_COLORKEY_NONE;
349 state->zpos = plane->type == DRM_PLANE_TYPE_PRIMARY ? 0 : 1;
350
351 plane->state = &state->state;
352 plane->state->plane = plane;
353}
354
Laurent Pinchart4407cc02015-02-23 02:36:31 +0200355static int rcar_du_plane_atomic_set_property(struct drm_plane *plane,
356 struct drm_plane_state *state,
357 struct drm_property *property,
358 uint64_t val)
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200359{
Laurent Pinchartec69a402015-04-29 00:48:17 +0300360 struct rcar_du_plane_state *rstate = to_rcar_plane_state(state);
Laurent Pinchart9f6aee92015-04-28 23:59:29 +0300361 struct rcar_du_device *rcdu = to_rcar_plane(plane)->group->dev;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200362
Laurent Pinchart9f6aee92015-04-28 23:59:29 +0300363 if (property == rcdu->props.alpha)
Laurent Pinchart4407cc02015-02-23 02:36:31 +0200364 rstate->alpha = val;
Laurent Pinchart9f6aee92015-04-28 23:59:29 +0300365 else if (property == rcdu->props.colorkey)
Laurent Pinchart4407cc02015-02-23 02:36:31 +0200366 rstate->colorkey = val;
Laurent Pinchart9f6aee92015-04-28 23:59:29 +0300367 else if (property == rcdu->props.zpos)
Laurent Pinchart4407cc02015-02-23 02:36:31 +0200368 rstate->zpos = val;
369 else
370 return -EINVAL;
371
372 return 0;
373}
374
375static int rcar_du_plane_atomic_get_property(struct drm_plane *plane,
376 const struct drm_plane_state *state, struct drm_property *property,
377 uint64_t *val)
378{
379 const struct rcar_du_plane_state *rstate =
380 container_of(state, const struct rcar_du_plane_state, state);
Laurent Pinchart9f6aee92015-04-28 23:59:29 +0300381 struct rcar_du_device *rcdu = to_rcar_plane(plane)->group->dev;
Laurent Pinchart4407cc02015-02-23 02:36:31 +0200382
Laurent Pinchart9f6aee92015-04-28 23:59:29 +0300383 if (property == rcdu->props.alpha)
Laurent Pinchart4407cc02015-02-23 02:36:31 +0200384 *val = rstate->alpha;
Laurent Pinchart9f6aee92015-04-28 23:59:29 +0300385 else if (property == rcdu->props.colorkey)
Laurent Pinchart4407cc02015-02-23 02:36:31 +0200386 *val = rstate->colorkey;
Laurent Pinchart9f6aee92015-04-28 23:59:29 +0300387 else if (property == rcdu->props.zpos)
Laurent Pinchart4407cc02015-02-23 02:36:31 +0200388 *val = rstate->zpos;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200389 else
390 return -EINVAL;
391
392 return 0;
393}
394
395static const struct drm_plane_funcs rcar_du_plane_funcs = {
Laurent Pinchart336d04a2015-02-20 13:18:56 +0200396 .update_plane = drm_atomic_helper_update_plane,
397 .disable_plane = drm_atomic_helper_disable_plane,
Laurent Pinchart4407cc02015-02-23 02:36:31 +0200398 .reset = rcar_du_plane_reset,
399 .set_property = drm_atomic_helper_plane_set_property,
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200400 .destroy = drm_plane_cleanup,
Laurent Pinchart4407cc02015-02-23 02:36:31 +0200401 .atomic_duplicate_state = rcar_du_plane_atomic_duplicate_state,
402 .atomic_destroy_state = rcar_du_plane_atomic_destroy_state,
403 .atomic_set_property = rcar_du_plane_atomic_set_property,
404 .atomic_get_property = rcar_du_plane_atomic_get_property,
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200405};
406
407static const uint32_t formats[] = {
408 DRM_FORMAT_RGB565,
409 DRM_FORMAT_ARGB1555,
410 DRM_FORMAT_XRGB1555,
411 DRM_FORMAT_XRGB8888,
412 DRM_FORMAT_ARGB8888,
413 DRM_FORMAT_UYVY,
414 DRM_FORMAT_YUYV,
415 DRM_FORMAT_NV12,
416 DRM_FORMAT_NV21,
417 DRM_FORMAT_NV16,
418};
419
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200420int rcar_du_planes_init(struct rcar_du_group *rgrp)
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200421{
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200422 struct rcar_du_device *rcdu = rgrp->dev;
Laurent Pinchart917de182015-02-17 18:34:17 +0200423 unsigned int crtcs;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200424 unsigned int i;
Laurent Pinchart917de182015-02-17 18:34:17 +0200425 int ret;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200426
Laurent Pinchart9f6aee92015-04-28 23:59:29 +0300427 /* Create one primary plane per CRTC in this group and seven overlay
Laurent Pinchart917de182015-02-17 18:34:17 +0200428 * planes.
429 */
Laurent Pinchartd6aed572015-05-25 16:32:45 +0300430 rgrp->num_planes = rgrp->num_crtcs + 7;
Laurent Pinchart917de182015-02-17 18:34:17 +0200431
432 crtcs = ((1 << rcdu->num_crtcs) - 1) & (3 << (2 * rgrp->index));
433
Laurent Pinchartd6aed572015-05-25 16:32:45 +0300434 for (i = 0; i < rgrp->num_planes; ++i) {
Laurent Pinchartfe6fbe92015-04-28 17:36:33 +0300435 enum drm_plane_type type = i < rgrp->num_crtcs
Laurent Pinchart917de182015-02-17 18:34:17 +0200436 ? DRM_PLANE_TYPE_PRIMARY
437 : DRM_PLANE_TYPE_OVERLAY;
Laurent Pinchart99caede2015-04-29 00:05:56 +0300438 struct rcar_du_plane *plane = &rgrp->planes[i];
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200439
Laurent Pinchartcb2025d2013-06-16 21:01:02 +0200440 plane->group = rgrp;
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200441
Laurent Pinchart917de182015-02-17 18:34:17 +0200442 ret = drm_universal_plane_init(rcdu->ddev, &plane->plane, crtcs,
443 &rcar_du_plane_funcs, formats,
Ville Syrjäläb0b3b792015-12-09 16:19:55 +0200444 ARRAY_SIZE(formats), type,
445 NULL);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200446 if (ret < 0)
447 return ret;
448
Laurent Pinchart920888a2015-02-18 12:18:05 +0200449 drm_plane_helper_add(&plane->plane,
450 &rcar_du_plane_helper_funcs);
451
Laurent Pinchart917de182015-02-17 18:34:17 +0200452 if (type == DRM_PLANE_TYPE_PRIMARY)
453 continue;
454
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200455 drm_object_attach_property(&plane->plane.base,
Laurent Pinchart9f6aee92015-04-28 23:59:29 +0300456 rcdu->props.alpha, 255);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200457 drm_object_attach_property(&plane->plane.base,
Laurent Pinchart9f6aee92015-04-28 23:59:29 +0300458 rcdu->props.colorkey,
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200459 RCAR_DU_COLORKEY_NONE);
460 drm_object_attach_property(&plane->plane.base,
Laurent Pinchart9f6aee92015-04-28 23:59:29 +0300461 rcdu->props.zpos, 1);
Laurent Pinchart4bf8e192013-06-19 13:54:11 +0200462 }
463
464 return 0;
465}