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