Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 1 | /* |
| 2 | * rcar_du_plane.c -- R-Car Display Unit Planes |
| 3 | * |
Laurent Pinchart | 36d5046 | 2014-02-06 18:13:52 +0100 | [diff] [blame] | 4 | * Copyright (C) 2013-2014 Renesas Electronics Corporation |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 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> |
Laurent Pinchart | 3e8da87 | 2015-02-20 11:30:59 +0200 | [diff] [blame] | 15 | #include <drm/drm_atomic_helper.h> |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 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> |
Laurent Pinchart | 920888a | 2015-02-18 12:18:05 +0200 | [diff] [blame] | 20 | #include <drm/drm_plane_helper.h> |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 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 | |
Laurent Pinchart | cb2025d | 2013-06-16 21:01:02 +0200 | [diff] [blame] | 31 | static void rcar_du_plane_write(struct rcar_du_group *rgrp, |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 32 | unsigned int index, u32 reg, u32 data) |
| 33 | { |
Laurent Pinchart | cb2025d | 2013-06-16 21:01:02 +0200 | [diff] [blame] | 34 | rcar_du_write(rgrp->dev, rgrp->mmio_offset + index * PLANE_OFF + reg, |
| 35 | data); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 36 | } |
| 37 | |
Laurent Pinchart | f398f34 | 2015-02-23 01:25:19 +0200 | [diff] [blame] | 38 | static void rcar_du_plane_setup_fb(struct rcar_du_plane *plane) |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 39 | { |
Laurent Pinchart | 5bfcbce | 2015-02-23 02:59:35 +0200 | [diff] [blame] | 40 | struct rcar_du_plane_state *state = |
Laurent Pinchart | ec69a40 | 2015-04-29 00:48:17 +0300 | [diff] [blame] | 41 | to_rcar_plane_state(plane->plane.state); |
Laurent Pinchart | f398f34 | 2015-02-23 01:25:19 +0200 | [diff] [blame] | 42 | struct drm_framebuffer *fb = plane->plane.state->fb; |
Laurent Pinchart | cb2025d | 2013-06-16 21:01:02 +0200 | [diff] [blame] | 43 | struct rcar_du_group *rgrp = plane->group; |
Laurent Pinchart | 5bfcbce | 2015-02-23 02:59:35 +0200 | [diff] [blame] | 44 | unsigned int src_x = state->state.src_x >> 16; |
| 45 | unsigned int src_y = state->state.src_y >> 16; |
Laurent Pinchart | 5ee5a81 | 2015-02-25 18:27:19 +0200 | [diff] [blame] | 46 | unsigned int index = state->hwindex; |
Laurent Pinchart | f398f34 | 2015-02-23 01:25:19 +0200 | [diff] [blame] | 47 | struct drm_gem_cma_object *gem; |
Laurent Pinchart | 906eff7 | 2014-12-09 19:11:18 +0200 | [diff] [blame] | 48 | bool interlaced; |
Laurent Pinchart | eb86301 | 2013-11-13 14:26:01 +0100 | [diff] [blame] | 49 | u32 mwr; |
| 50 | |
Laurent Pinchart | 5bfcbce | 2015-02-23 02:59:35 +0200 | [diff] [blame] | 51 | interlaced = state->state.crtc->state->adjusted_mode.flags |
Laurent Pinchart | 4709419 | 2015-02-22 19:24:59 +0200 | [diff] [blame] | 52 | & DRM_MODE_FLAG_INTERLACE; |
Laurent Pinchart | 906eff7 | 2014-12-09 19:11:18 +0200 | [diff] [blame] | 53 | |
| 54 | /* Memory pitch (expressed in pixels). Must be doubled for interlaced |
| 55 | * operation with 32bpp formats. |
| 56 | */ |
Laurent Pinchart | 5bfcbce | 2015-02-23 02:59:35 +0200 | [diff] [blame] | 57 | if (state->format->planes == 2) |
Laurent Pinchart | f398f34 | 2015-02-23 01:25:19 +0200 | [diff] [blame] | 58 | mwr = fb->pitches[0]; |
Laurent Pinchart | eb86301 | 2013-11-13 14:26:01 +0100 | [diff] [blame] | 59 | else |
Laurent Pinchart | 5bfcbce | 2015-02-23 02:59:35 +0200 | [diff] [blame] | 60 | mwr = fb->pitches[0] * 8 / state->format->bpp; |
Laurent Pinchart | eb86301 | 2013-11-13 14:26:01 +0100 | [diff] [blame] | 61 | |
Laurent Pinchart | 5bfcbce | 2015-02-23 02:59:35 +0200 | [diff] [blame] | 62 | if (interlaced && state->format->bpp == 32) |
Laurent Pinchart | 906eff7 | 2014-12-09 19:11:18 +0200 | [diff] [blame] | 63 | mwr *= 2; |
| 64 | |
Laurent Pinchart | eb86301 | 2013-11-13 14:26:01 +0100 | [diff] [blame] | 65 | rcar_du_plane_write(rgrp, index, PnMWR, mwr); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 66 | |
Laurent Pinchart | 9e7db06 | 2013-06-14 20:54:16 +0200 | [diff] [blame] | 67 | /* The Y position is expressed in raster line units and must be doubled |
| 68 | * for 32bpp formats, according to the R8A7790 datasheet. No mention of |
| 69 | * doubling the Y position is found in the R8A7779 datasheet, but the |
| 70 | * rule seems to apply there as well. |
| 71 | * |
Laurent Pinchart | 906eff7 | 2014-12-09 19:11:18 +0200 | [diff] [blame] | 72 | * Despite not being documented, doubling seem not to be needed when |
| 73 | * operating in interlaced mode. |
| 74 | * |
Laurent Pinchart | 9e7db06 | 2013-06-14 20:54:16 +0200 | [diff] [blame] | 75 | * Similarly, for the second plane, NV12 and NV21 formats seem to |
Laurent Pinchart | 906eff7 | 2014-12-09 19:11:18 +0200 | [diff] [blame] | 76 | * require a halved Y position value, in both progressive and interlaced |
| 77 | * modes. |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 78 | */ |
Laurent Pinchart | 287bdf0 | 2015-02-20 15:58:38 +0200 | [diff] [blame] | 79 | rcar_du_plane_write(rgrp, index, PnSPXR, src_x); |
| 80 | rcar_du_plane_write(rgrp, index, PnSPYR, src_y * |
Laurent Pinchart | 5bfcbce | 2015-02-23 02:59:35 +0200 | [diff] [blame] | 81 | (!interlaced && state->format->bpp == 32 ? 2 : 1)); |
Laurent Pinchart | f398f34 | 2015-02-23 01:25:19 +0200 | [diff] [blame] | 82 | |
| 83 | gem = drm_fb_cma_get_gem_obj(fb, 0); |
| 84 | rcar_du_plane_write(rgrp, index, PnDSA0R, gem->paddr + fb->offsets[0]); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 85 | |
Laurent Pinchart | 5bfcbce | 2015-02-23 02:59:35 +0200 | [diff] [blame] | 86 | if (state->format->planes == 2) { |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 87 | index = (index + 1) % 8; |
| 88 | |
Laurent Pinchart | f398f34 | 2015-02-23 01:25:19 +0200 | [diff] [blame] | 89 | rcar_du_plane_write(rgrp, index, PnMWR, fb->pitches[0]); |
Laurent Pinchart | 49785e2 | 2014-12-09 22:45:11 +0200 | [diff] [blame] | 90 | |
Laurent Pinchart | 287bdf0 | 2015-02-20 15:58:38 +0200 | [diff] [blame] | 91 | rcar_du_plane_write(rgrp, index, PnSPXR, src_x); |
| 92 | rcar_du_plane_write(rgrp, index, PnSPYR, src_y * |
Laurent Pinchart | 5bfcbce | 2015-02-23 02:59:35 +0200 | [diff] [blame] | 93 | (state->format->bpp == 16 ? 2 : 1) / 2); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 94 | |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 95 | gem = drm_fb_cma_get_gem_obj(fb, 1); |
Laurent Pinchart | f398f34 | 2015-02-23 01:25:19 +0200 | [diff] [blame] | 96 | rcar_du_plane_write(rgrp, index, PnDSA0R, |
| 97 | gem->paddr + fb->offsets[1]); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | |
| 101 | static void rcar_du_plane_setup_mode(struct rcar_du_plane *plane, |
| 102 | unsigned int index) |
| 103 | { |
Laurent Pinchart | 4407cc0 | 2015-02-23 02:36:31 +0200 | [diff] [blame] | 104 | struct rcar_du_plane_state *state = |
Laurent Pinchart | ec69a40 | 2015-04-29 00:48:17 +0300 | [diff] [blame] | 105 | to_rcar_plane_state(plane->plane.state); |
Laurent Pinchart | cb2025d | 2013-06-16 21:01:02 +0200 | [diff] [blame] | 106 | struct rcar_du_group *rgrp = plane->group; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 107 | u32 colorkey; |
| 108 | u32 pnmr; |
| 109 | |
| 110 | /* The PnALPHAR register controls alpha-blending in 16bpp formats |
| 111 | * (ARGB1555 and XRGB1555). |
| 112 | * |
| 113 | * For ARGB, set the alpha value to 0, and enable alpha-blending when |
| 114 | * the A bit is 0. This maps A=0 to alpha=0 and A=1 to alpha=255. |
| 115 | * |
| 116 | * For XRGB, set the alpha value to the plane-wide alpha value and |
| 117 | * enable alpha-blending regardless of the X bit value. |
| 118 | */ |
Laurent Pinchart | 5bfcbce | 2015-02-23 02:59:35 +0200 | [diff] [blame] | 119 | if (state->format->fourcc != DRM_FORMAT_XRGB1555) |
Laurent Pinchart | cb2025d | 2013-06-16 21:01:02 +0200 | [diff] [blame] | 120 | rcar_du_plane_write(rgrp, index, PnALPHAR, PnALPHAR_ABIT_0); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 121 | else |
Laurent Pinchart | cb2025d | 2013-06-16 21:01:02 +0200 | [diff] [blame] | 122 | rcar_du_plane_write(rgrp, index, PnALPHAR, |
Laurent Pinchart | 4407cc0 | 2015-02-23 02:36:31 +0200 | [diff] [blame] | 123 | PnALPHAR_ABIT_X | state->alpha); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 124 | |
Laurent Pinchart | 5bfcbce | 2015-02-23 02:59:35 +0200 | [diff] [blame] | 125 | pnmr = PnMR_BM_MD | state->format->pnmr; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 126 | |
| 127 | /* Disable color keying when requested. YUV formats have the |
| 128 | * PnMR_SPIM_TP_OFF bit set in their pnmr field, disabling color keying |
| 129 | * automatically. |
| 130 | */ |
Laurent Pinchart | 4407cc0 | 2015-02-23 02:36:31 +0200 | [diff] [blame] | 131 | if ((state->colorkey & RCAR_DU_COLORKEY_MASK) == RCAR_DU_COLORKEY_NONE) |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 132 | pnmr |= PnMR_SPIM_TP_OFF; |
| 133 | |
| 134 | /* For packed YUV formats we need to select the U/V order. */ |
Laurent Pinchart | 5bfcbce | 2015-02-23 02:59:35 +0200 | [diff] [blame] | 135 | if (state->format->fourcc == DRM_FORMAT_YUYV) |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 136 | pnmr |= PnMR_YCDF_YUYV; |
| 137 | |
Laurent Pinchart | cb2025d | 2013-06-16 21:01:02 +0200 | [diff] [blame] | 138 | rcar_du_plane_write(rgrp, index, PnMR, pnmr); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 139 | |
Laurent Pinchart | 5bfcbce | 2015-02-23 02:59:35 +0200 | [diff] [blame] | 140 | switch (state->format->fourcc) { |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 141 | case DRM_FORMAT_RGB565: |
Laurent Pinchart | 4407cc0 | 2015-02-23 02:36:31 +0200 | [diff] [blame] | 142 | colorkey = ((state->colorkey & 0xf80000) >> 8) |
| 143 | | ((state->colorkey & 0x00fc00) >> 5) |
| 144 | | ((state->colorkey & 0x0000f8) >> 3); |
Laurent Pinchart | cb2025d | 2013-06-16 21:01:02 +0200 | [diff] [blame] | 145 | rcar_du_plane_write(rgrp, index, PnTC2R, colorkey); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 146 | break; |
| 147 | |
| 148 | case DRM_FORMAT_ARGB1555: |
| 149 | case DRM_FORMAT_XRGB1555: |
Laurent Pinchart | 4407cc0 | 2015-02-23 02:36:31 +0200 | [diff] [blame] | 150 | colorkey = ((state->colorkey & 0xf80000) >> 9) |
| 151 | | ((state->colorkey & 0x00f800) >> 6) |
| 152 | | ((state->colorkey & 0x0000f8) >> 3); |
Laurent Pinchart | cb2025d | 2013-06-16 21:01:02 +0200 | [diff] [blame] | 153 | rcar_du_plane_write(rgrp, index, PnTC2R, colorkey); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 154 | break; |
| 155 | |
| 156 | case DRM_FORMAT_XRGB8888: |
| 157 | case DRM_FORMAT_ARGB8888: |
Laurent Pinchart | cb2025d | 2013-06-16 21:01:02 +0200 | [diff] [blame] | 158 | rcar_du_plane_write(rgrp, index, PnTC3R, |
Laurent Pinchart | 4407cc0 | 2015-02-23 02:36:31 +0200 | [diff] [blame] | 159 | PnTC3R_CODE | (state->colorkey & 0xffffff)); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 160 | break; |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | static void __rcar_du_plane_setup(struct rcar_du_plane *plane, |
| 165 | unsigned int index) |
| 166 | { |
Laurent Pinchart | 5bfcbce | 2015-02-23 02:59:35 +0200 | [diff] [blame] | 167 | struct rcar_du_plane_state *state = |
Laurent Pinchart | ec69a40 | 2015-04-29 00:48:17 +0300 | [diff] [blame] | 168 | to_rcar_plane_state(plane->plane.state); |
Laurent Pinchart | cb2025d | 2013-06-16 21:01:02 +0200 | [diff] [blame] | 169 | struct rcar_du_group *rgrp = plane->group; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 170 | u32 ddcr2 = PnDDCR2_CODE; |
| 171 | u32 ddcr4; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 172 | |
| 173 | /* Data format |
| 174 | * |
| 175 | * The data format is selected by the DDDF field in PnMR and the EDF |
| 176 | * field in DDCR4. |
| 177 | */ |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 178 | |
| 179 | rcar_du_plane_setup_mode(plane, index); |
| 180 | |
Laurent Pinchart | 5bfcbce | 2015-02-23 02:59:35 +0200 | [diff] [blame] | 181 | if (state->format->planes == 2) { |
Laurent Pinchart | 5ee5a81 | 2015-02-25 18:27:19 +0200 | [diff] [blame] | 182 | if (state->hwindex != index) { |
Laurent Pinchart | 5bfcbce | 2015-02-23 02:59:35 +0200 | [diff] [blame] | 183 | if (state->format->fourcc == DRM_FORMAT_NV12 || |
| 184 | state->format->fourcc == DRM_FORMAT_NV21) |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 185 | ddcr2 |= PnDDCR2_Y420; |
| 186 | |
Laurent Pinchart | 5bfcbce | 2015-02-23 02:59:35 +0200 | [diff] [blame] | 187 | if (state->format->fourcc == DRM_FORMAT_NV21) |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 188 | ddcr2 |= PnDDCR2_NV21; |
| 189 | |
| 190 | ddcr2 |= PnDDCR2_DIVU; |
| 191 | } else { |
| 192 | ddcr2 |= PnDDCR2_DIVY; |
| 193 | } |
| 194 | } |
| 195 | |
Laurent Pinchart | cb2025d | 2013-06-16 21:01:02 +0200 | [diff] [blame] | 196 | rcar_du_plane_write(rgrp, index, PnDDCR2, ddcr2); |
Laurent Pinchart | ff96736 | 2015-07-27 12:46:44 +0300 | [diff] [blame^] | 197 | |
| 198 | ddcr4 = state->format->edf | PnDDCR4_CODE; |
| 199 | |
Laurent Pinchart | cb2025d | 2013-06-16 21:01:02 +0200 | [diff] [blame] | 200 | rcar_du_plane_write(rgrp, index, PnDDCR4, ddcr4); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 201 | |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 202 | /* Destination position and size */ |
Laurent Pinchart | 287bdf0 | 2015-02-20 15:58:38 +0200 | [diff] [blame] | 203 | rcar_du_plane_write(rgrp, index, PnDSXR, plane->plane.state->crtc_w); |
| 204 | rcar_du_plane_write(rgrp, index, PnDSYR, plane->plane.state->crtc_h); |
| 205 | rcar_du_plane_write(rgrp, index, PnDPXR, plane->plane.state->crtc_x); |
| 206 | rcar_du_plane_write(rgrp, index, PnDPYR, plane->plane.state->crtc_y); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 207 | |
| 208 | /* Wrap-around and blinking, disabled */ |
Laurent Pinchart | cb2025d | 2013-06-16 21:01:02 +0200 | [diff] [blame] | 209 | rcar_du_plane_write(rgrp, index, PnWASPR, 0); |
| 210 | rcar_du_plane_write(rgrp, index, PnWAMWR, 4095); |
| 211 | rcar_du_plane_write(rgrp, index, PnBTR, 0); |
| 212 | rcar_du_plane_write(rgrp, index, PnMLR, 0); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | void rcar_du_plane_setup(struct rcar_du_plane *plane) |
| 216 | { |
Laurent Pinchart | 5bfcbce | 2015-02-23 02:59:35 +0200 | [diff] [blame] | 217 | struct rcar_du_plane_state *state = |
Laurent Pinchart | ec69a40 | 2015-04-29 00:48:17 +0300 | [diff] [blame] | 218 | to_rcar_plane_state(plane->plane.state); |
Laurent Pinchart | 5bfcbce | 2015-02-23 02:59:35 +0200 | [diff] [blame] | 219 | |
Laurent Pinchart | 5ee5a81 | 2015-02-25 18:27:19 +0200 | [diff] [blame] | 220 | __rcar_du_plane_setup(plane, state->hwindex); |
Laurent Pinchart | 5bfcbce | 2015-02-23 02:59:35 +0200 | [diff] [blame] | 221 | if (state->format->planes == 2) |
Laurent Pinchart | 5ee5a81 | 2015-02-25 18:27:19 +0200 | [diff] [blame] | 222 | __rcar_du_plane_setup(plane, (state->hwindex + 1) % 8); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 223 | |
Laurent Pinchart | f398f34 | 2015-02-23 01:25:19 +0200 | [diff] [blame] | 224 | rcar_du_plane_setup_fb(plane); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 225 | } |
| 226 | |
Laurent Pinchart | 920888a | 2015-02-18 12:18:05 +0200 | [diff] [blame] | 227 | static int rcar_du_plane_atomic_check(struct drm_plane *plane, |
| 228 | struct drm_plane_state *state) |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 229 | { |
Laurent Pinchart | ec69a40 | 2015-04-29 00:48:17 +0300 | [diff] [blame] | 230 | struct rcar_du_plane_state *rstate = to_rcar_plane_state(state); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 231 | struct rcar_du_plane *rplane = to_rcar_plane(plane); |
Laurent Pinchart | cb2025d | 2013-06-16 21:01:02 +0200 | [diff] [blame] | 232 | struct rcar_du_device *rcdu = rplane->group->dev; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 233 | |
Laurent Pinchart | 5ee5a81 | 2015-02-25 18:27:19 +0200 | [diff] [blame] | 234 | if (!state->fb || !state->crtc) { |
| 235 | rstate->format = NULL; |
Laurent Pinchart | 920888a | 2015-02-18 12:18:05 +0200 | [diff] [blame] | 236 | return 0; |
Laurent Pinchart | 5ee5a81 | 2015-02-25 18:27:19 +0200 | [diff] [blame] | 237 | } |
Laurent Pinchart | 917de18 | 2015-02-17 18:34:17 +0200 | [diff] [blame] | 238 | |
Laurent Pinchart | 920888a | 2015-02-18 12:18:05 +0200 | [diff] [blame] | 239 | if (state->src_w >> 16 != state->crtc_w || |
| 240 | state->src_h >> 16 != state->crtc_h) { |
| 241 | dev_dbg(rcdu->dev, "%s: scaling not supported\n", __func__); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 242 | return -EINVAL; |
| 243 | } |
| 244 | |
Laurent Pinchart | 5ee5a81 | 2015-02-25 18:27:19 +0200 | [diff] [blame] | 245 | rstate->format = rcar_du_format_info(state->fb->pixel_format); |
| 246 | if (rstate->format == NULL) { |
Laurent Pinchart | 920888a | 2015-02-18 12:18:05 +0200 | [diff] [blame] | 247 | dev_dbg(rcdu->dev, "%s: unsupported format %08x\n", __func__, |
| 248 | state->fb->pixel_format); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 249 | return -EINVAL; |
| 250 | } |
| 251 | |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 252 | return 0; |
| 253 | } |
| 254 | |
Laurent Pinchart | 920888a | 2015-02-18 12:18:05 +0200 | [diff] [blame] | 255 | static void rcar_du_plane_atomic_update(struct drm_plane *plane, |
| 256 | struct drm_plane_state *old_state) |
| 257 | { |
| 258 | struct rcar_du_plane *rplane = to_rcar_plane(plane); |
Laurent Pinchart | 5bfcbce | 2015-02-23 02:59:35 +0200 | [diff] [blame] | 259 | |
Laurent Pinchart | 5ee5a81 | 2015-02-25 18:27:19 +0200 | [diff] [blame] | 260 | if (plane->state->crtc) |
| 261 | rcar_du_plane_setup(rplane); |
Laurent Pinchart | 920888a | 2015-02-18 12:18:05 +0200 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | static const struct drm_plane_helper_funcs rcar_du_plane_helper_funcs = { |
| 265 | .atomic_check = rcar_du_plane_atomic_check, |
| 266 | .atomic_update = rcar_du_plane_atomic_update, |
| 267 | }; |
| 268 | |
Laurent Pinchart | 4407cc0 | 2015-02-23 02:36:31 +0200 | [diff] [blame] | 269 | static struct drm_plane_state * |
| 270 | rcar_du_plane_atomic_duplicate_state(struct drm_plane *plane) |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 271 | { |
Laurent Pinchart | 4407cc0 | 2015-02-23 02:36:31 +0200 | [diff] [blame] | 272 | struct rcar_du_plane_state *state; |
| 273 | struct rcar_du_plane_state *copy; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 274 | |
Laurent Pinchart | 263b39f | 2015-05-27 16:36:29 +0300 | [diff] [blame] | 275 | if (WARN_ON(!plane->state)) |
| 276 | return NULL; |
| 277 | |
Laurent Pinchart | ec69a40 | 2015-04-29 00:48:17 +0300 | [diff] [blame] | 278 | state = to_rcar_plane_state(plane->state); |
Laurent Pinchart | 4407cc0 | 2015-02-23 02:36:31 +0200 | [diff] [blame] | 279 | copy = kmemdup(state, sizeof(*state), GFP_KERNEL); |
| 280 | if (copy == NULL) |
| 281 | return NULL; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 282 | |
Laurent Pinchart | 263b39f | 2015-05-27 16:36:29 +0300 | [diff] [blame] | 283 | __drm_atomic_helper_plane_duplicate_state(plane, ©->state); |
Laurent Pinchart | 4407cc0 | 2015-02-23 02:36:31 +0200 | [diff] [blame] | 284 | |
| 285 | return ©->state; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 286 | } |
| 287 | |
Laurent Pinchart | 4407cc0 | 2015-02-23 02:36:31 +0200 | [diff] [blame] | 288 | static void rcar_du_plane_atomic_destroy_state(struct drm_plane *plane, |
| 289 | struct drm_plane_state *state) |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 290 | { |
Laurent Pinchart | 263b39f | 2015-05-27 16:36:29 +0300 | [diff] [blame] | 291 | __drm_atomic_helper_plane_destroy_state(plane, state); |
Laurent Pinchart | ec69a40 | 2015-04-29 00:48:17 +0300 | [diff] [blame] | 292 | kfree(to_rcar_plane_state(state)); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 293 | } |
| 294 | |
Laurent Pinchart | a32a3c8 | 2015-07-27 11:42:54 +0300 | [diff] [blame] | 295 | static void rcar_du_plane_reset(struct drm_plane *plane) |
| 296 | { |
| 297 | struct rcar_du_plane_state *state; |
| 298 | |
| 299 | if (plane->state) { |
| 300 | rcar_du_plane_atomic_destroy_state(plane, plane->state); |
| 301 | plane->state = NULL; |
| 302 | } |
| 303 | |
| 304 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
| 305 | if (state == NULL) |
| 306 | return; |
| 307 | |
| 308 | state->hwindex = -1; |
| 309 | state->alpha = 255; |
| 310 | state->colorkey = RCAR_DU_COLORKEY_NONE; |
| 311 | state->zpos = plane->type == DRM_PLANE_TYPE_PRIMARY ? 0 : 1; |
| 312 | |
| 313 | plane->state = &state->state; |
| 314 | plane->state->plane = plane; |
| 315 | } |
| 316 | |
Laurent Pinchart | 4407cc0 | 2015-02-23 02:36:31 +0200 | [diff] [blame] | 317 | static int rcar_du_plane_atomic_set_property(struct drm_plane *plane, |
| 318 | struct drm_plane_state *state, |
| 319 | struct drm_property *property, |
| 320 | uint64_t val) |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 321 | { |
Laurent Pinchart | ec69a40 | 2015-04-29 00:48:17 +0300 | [diff] [blame] | 322 | struct rcar_du_plane_state *rstate = to_rcar_plane_state(state); |
Laurent Pinchart | 9f6aee9 | 2015-04-28 23:59:29 +0300 | [diff] [blame] | 323 | struct rcar_du_device *rcdu = to_rcar_plane(plane)->group->dev; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 324 | |
Laurent Pinchart | 9f6aee9 | 2015-04-28 23:59:29 +0300 | [diff] [blame] | 325 | if (property == rcdu->props.alpha) |
Laurent Pinchart | 4407cc0 | 2015-02-23 02:36:31 +0200 | [diff] [blame] | 326 | rstate->alpha = val; |
Laurent Pinchart | 9f6aee9 | 2015-04-28 23:59:29 +0300 | [diff] [blame] | 327 | else if (property == rcdu->props.colorkey) |
Laurent Pinchart | 4407cc0 | 2015-02-23 02:36:31 +0200 | [diff] [blame] | 328 | rstate->colorkey = val; |
Laurent Pinchart | 9f6aee9 | 2015-04-28 23:59:29 +0300 | [diff] [blame] | 329 | else if (property == rcdu->props.zpos) |
Laurent Pinchart | 4407cc0 | 2015-02-23 02:36:31 +0200 | [diff] [blame] | 330 | rstate->zpos = val; |
| 331 | else |
| 332 | return -EINVAL; |
| 333 | |
| 334 | return 0; |
| 335 | } |
| 336 | |
| 337 | static int rcar_du_plane_atomic_get_property(struct drm_plane *plane, |
| 338 | const struct drm_plane_state *state, struct drm_property *property, |
| 339 | uint64_t *val) |
| 340 | { |
| 341 | const struct rcar_du_plane_state *rstate = |
| 342 | container_of(state, const struct rcar_du_plane_state, state); |
Laurent Pinchart | 9f6aee9 | 2015-04-28 23:59:29 +0300 | [diff] [blame] | 343 | struct rcar_du_device *rcdu = to_rcar_plane(plane)->group->dev; |
Laurent Pinchart | 4407cc0 | 2015-02-23 02:36:31 +0200 | [diff] [blame] | 344 | |
Laurent Pinchart | 9f6aee9 | 2015-04-28 23:59:29 +0300 | [diff] [blame] | 345 | if (property == rcdu->props.alpha) |
Laurent Pinchart | 4407cc0 | 2015-02-23 02:36:31 +0200 | [diff] [blame] | 346 | *val = rstate->alpha; |
Laurent Pinchart | 9f6aee9 | 2015-04-28 23:59:29 +0300 | [diff] [blame] | 347 | else if (property == rcdu->props.colorkey) |
Laurent Pinchart | 4407cc0 | 2015-02-23 02:36:31 +0200 | [diff] [blame] | 348 | *val = rstate->colorkey; |
Laurent Pinchart | 9f6aee9 | 2015-04-28 23:59:29 +0300 | [diff] [blame] | 349 | else if (property == rcdu->props.zpos) |
Laurent Pinchart | 4407cc0 | 2015-02-23 02:36:31 +0200 | [diff] [blame] | 350 | *val = rstate->zpos; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 351 | else |
| 352 | return -EINVAL; |
| 353 | |
| 354 | return 0; |
| 355 | } |
| 356 | |
| 357 | static const struct drm_plane_funcs rcar_du_plane_funcs = { |
Laurent Pinchart | 336d04a | 2015-02-20 13:18:56 +0200 | [diff] [blame] | 358 | .update_plane = drm_atomic_helper_update_plane, |
| 359 | .disable_plane = drm_atomic_helper_disable_plane, |
Laurent Pinchart | 4407cc0 | 2015-02-23 02:36:31 +0200 | [diff] [blame] | 360 | .reset = rcar_du_plane_reset, |
| 361 | .set_property = drm_atomic_helper_plane_set_property, |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 362 | .destroy = drm_plane_cleanup, |
Laurent Pinchart | 4407cc0 | 2015-02-23 02:36:31 +0200 | [diff] [blame] | 363 | .atomic_duplicate_state = rcar_du_plane_atomic_duplicate_state, |
| 364 | .atomic_destroy_state = rcar_du_plane_atomic_destroy_state, |
| 365 | .atomic_set_property = rcar_du_plane_atomic_set_property, |
| 366 | .atomic_get_property = rcar_du_plane_atomic_get_property, |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 367 | }; |
| 368 | |
| 369 | static const uint32_t formats[] = { |
| 370 | DRM_FORMAT_RGB565, |
| 371 | DRM_FORMAT_ARGB1555, |
| 372 | DRM_FORMAT_XRGB1555, |
| 373 | DRM_FORMAT_XRGB8888, |
| 374 | DRM_FORMAT_ARGB8888, |
| 375 | DRM_FORMAT_UYVY, |
| 376 | DRM_FORMAT_YUYV, |
| 377 | DRM_FORMAT_NV12, |
| 378 | DRM_FORMAT_NV21, |
| 379 | DRM_FORMAT_NV16, |
| 380 | }; |
| 381 | |
Laurent Pinchart | cb2025d | 2013-06-16 21:01:02 +0200 | [diff] [blame] | 382 | int rcar_du_planes_init(struct rcar_du_group *rgrp) |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 383 | { |
Laurent Pinchart | cb2025d | 2013-06-16 21:01:02 +0200 | [diff] [blame] | 384 | struct rcar_du_device *rcdu = rgrp->dev; |
Laurent Pinchart | 917de18 | 2015-02-17 18:34:17 +0200 | [diff] [blame] | 385 | unsigned int crtcs; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 386 | unsigned int i; |
Laurent Pinchart | 917de18 | 2015-02-17 18:34:17 +0200 | [diff] [blame] | 387 | int ret; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 388 | |
Laurent Pinchart | 9f6aee9 | 2015-04-28 23:59:29 +0300 | [diff] [blame] | 389 | /* Create one primary plane per CRTC in this group and seven overlay |
Laurent Pinchart | 917de18 | 2015-02-17 18:34:17 +0200 | [diff] [blame] | 390 | * planes. |
| 391 | */ |
Laurent Pinchart | d6aed57 | 2015-05-25 16:32:45 +0300 | [diff] [blame] | 392 | rgrp->num_planes = rgrp->num_crtcs + 7; |
Laurent Pinchart | 917de18 | 2015-02-17 18:34:17 +0200 | [diff] [blame] | 393 | |
| 394 | crtcs = ((1 << rcdu->num_crtcs) - 1) & (3 << (2 * rgrp->index)); |
| 395 | |
Laurent Pinchart | d6aed57 | 2015-05-25 16:32:45 +0300 | [diff] [blame] | 396 | for (i = 0; i < rgrp->num_planes; ++i) { |
Laurent Pinchart | fe6fbe9 | 2015-04-28 17:36:33 +0300 | [diff] [blame] | 397 | enum drm_plane_type type = i < rgrp->num_crtcs |
Laurent Pinchart | 917de18 | 2015-02-17 18:34:17 +0200 | [diff] [blame] | 398 | ? DRM_PLANE_TYPE_PRIMARY |
| 399 | : DRM_PLANE_TYPE_OVERLAY; |
Laurent Pinchart | 99caede | 2015-04-29 00:05:56 +0300 | [diff] [blame] | 400 | struct rcar_du_plane *plane = &rgrp->planes[i]; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 401 | |
Laurent Pinchart | cb2025d | 2013-06-16 21:01:02 +0200 | [diff] [blame] | 402 | plane->group = rgrp; |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 403 | |
Laurent Pinchart | 917de18 | 2015-02-17 18:34:17 +0200 | [diff] [blame] | 404 | ret = drm_universal_plane_init(rcdu->ddev, &plane->plane, crtcs, |
| 405 | &rcar_du_plane_funcs, formats, |
Ville Syrjälä | b0b3b79 | 2015-12-09 16:19:55 +0200 | [diff] [blame] | 406 | ARRAY_SIZE(formats), type, |
| 407 | NULL); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 408 | if (ret < 0) |
| 409 | return ret; |
| 410 | |
Laurent Pinchart | 920888a | 2015-02-18 12:18:05 +0200 | [diff] [blame] | 411 | drm_plane_helper_add(&plane->plane, |
| 412 | &rcar_du_plane_helper_funcs); |
| 413 | |
Laurent Pinchart | 917de18 | 2015-02-17 18:34:17 +0200 | [diff] [blame] | 414 | if (type == DRM_PLANE_TYPE_PRIMARY) |
| 415 | continue; |
| 416 | |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 417 | drm_object_attach_property(&plane->plane.base, |
Laurent Pinchart | 9f6aee9 | 2015-04-28 23:59:29 +0300 | [diff] [blame] | 418 | rcdu->props.alpha, 255); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 419 | drm_object_attach_property(&plane->plane.base, |
Laurent Pinchart | 9f6aee9 | 2015-04-28 23:59:29 +0300 | [diff] [blame] | 420 | rcdu->props.colorkey, |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 421 | RCAR_DU_COLORKEY_NONE); |
| 422 | drm_object_attach_property(&plane->plane.base, |
Laurent Pinchart | 9f6aee9 | 2015-04-28 23:59:29 +0300 | [diff] [blame] | 423 | rcdu->props.zpos, 1); |
Laurent Pinchart | 4bf8e19 | 2013-06-19 13:54:11 +0200 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | return 0; |
| 427 | } |