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