Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp413742pxv; Fri, 9 Jul 2021 00:40:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFbpzeQwso+14TowV8l8G/9RdjrlOXHrWYCldZeIVaFK1ommOUTk+CrU6ITjR5loCKKA4o X-Received: by 2002:a50:b2c5:: with SMTP id p63mr43617108edd.5.1625816407661; Fri, 09 Jul 2021 00:40:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625816407; cv=none; d=google.com; s=arc-20160816; b=sITyY528073tXgoUDeiA8ZhEoGQmtxDrRBD6Se8fVwRGrTTEqc0Usywm/Aba+c5BgE jTjHgwDjjrXFdyS28JfJlqPoJHKjgZHsvW0ZazwT3xqMYzmRZXuzG2bGx/PPgY2yKvw+ fmAQlhIa20C10XeJk2M5C29LpBYpKrKOFJYy5qpaiz4EJ1WD10/vS82JdWaB0YvCPNlG L/Kb0M9Y1LZCcosu/VQirxKqVPvyZHehON6hxpHthx/k0YZqnkYQQaN1IvlfPKyA49Ug reg7YH/dfjij1yuewuauH77gQquaCqyr9u6pp5W/93q/YRs5q+baInlIA34CrBMlg5Zh yZCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=VaG3Y7YczFtAXNuFBMM0Ku3shZIALJVSIv8n6IlowFI=; b=ZvSIDEZaz77lvNfekjRO6f06vLxyehz8WU6gjB+AdL0kv8R/0mdQODzVdwozotZMYT vYV2fm+qYvi9wu5fZV07O497vsnkuLK/pnQ7dJgNLuwl1qcAuyyctOn+/Vb9OEjpJibv 2ShvaKkJRbAAJLLA5vLZVE4rtdOM6L1yCZkQuubZF7GmbIoNQO1zjEETUfdV0Ghj8YKT 9upuOhIhdNKlF1lP2SPHb3Su4uRqbw3fDmBwOJn7T+Ov54dst5nS+u6nYjYvbmLASerf bB/H5Vqpq1FTm7y+Rd6qU9WPsdnwpQsYQGG9FqiMnlAlBiE8FYoNRjHs1uHQPYgGZJGf czjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fAL6q6qn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gs7si5536646ejc.609.2021.07.09.00.39.43; Fri, 09 Jul 2021 00:40:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fAL6q6qn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231196AbhGIHjE (ORCPT + 99 others); Fri, 9 Jul 2021 03:39:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230121AbhGIHjD (ORCPT ); Fri, 9 Jul 2021 03:39:03 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8FE6C0613DD for ; Fri, 9 Jul 2021 00:36:19 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id a18so21441627lfs.10 for ; Fri, 09 Jul 2021 00:36:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version; bh=VaG3Y7YczFtAXNuFBMM0Ku3shZIALJVSIv8n6IlowFI=; b=fAL6q6qniIU8H4H9DZhMzTcZDmbFXGInT7nT4vDDgE2+uPu79twQBY3pMVuoUX/vGD K1A6drmmCko1gcimQqFYsAUhHEvqD8MHRzu5I8lWnE/nkiadzl1J5liTypQyR4J98WCU EVhMPUBbGB+vjyhSREsr18E9DwZluKSLjc4N3J5yfH6GrT1gitjYnqJpAyxs0cZ7i7XB u99eWTyUzZG25JhSP8TS9VhiBSdyVhuvWvVl7sGsynAgIGwxHm2nnwu2dYDPkcjQTyRi htoJUG3K5J7BcxeCnIF0CBcb4h4iAGul3ITWJyOnQ76JlKNUYOFo2bzYH/U6TvSKBB8D sl/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version; bh=VaG3Y7YczFtAXNuFBMM0Ku3shZIALJVSIv8n6IlowFI=; b=C3NRIXokPF1z1VsLDax0ozFu7GUR6BBJqbsH8Glwt5AyRMqqhXQRBBw3c8o3Db86M9 xwaQQ3FXOLv1NQ9i4BtBiZCPFvj56I3lXbunr08pxUv59FWPnuVge2R6yIHNwzs6ghF6 Iq34a7Bi56IwDyGJXaQgjzZkHZUbtex53imXOX2fxIPTUWta+co0tnQG1Xu15h8mlrcc /+w51dZDEcq/9XXEjB6QATa/iXa7FaX7bZa//vMNcFawMLda7Y50JuSt6JGri3zzcpCs ipwwT9SI8q1OB45nK6zmuFFViV9L3kkWZfYzZioWT/J0LAgY0XQFQwmSi8aTFoh5rm8k C3Mg== X-Gm-Message-State: AOAM533eyPqADZct0Q+RmWH8e6+PjrvEfnvPXnyIMlYc2UjdwyNo/+IJ ic20M/y4DuHpYv6eJ4NmuAw= X-Received: by 2002:a05:6512:33d0:: with SMTP id d16mr19179190lfg.311.1625816178129; Fri, 09 Jul 2021 00:36:18 -0700 (PDT) Received: from eldfell ([194.136.85.206]) by smtp.gmail.com with ESMTPSA id l15sm394730lfh.228.2021.07.09.00.36.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jul 2021 00:36:17 -0700 (PDT) Date: Fri, 9 Jul 2021 10:36:14 +0300 From: Pekka Paalanen To: Raphael GALLAIS-POU - foss Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Yannick FERTRE - foss , Philippe CORNU - foss , Benjamin Gaignard , Maxime Coquelin , Alexandre TORGUE - foss , Matt Roper , "dri-devel@lists.freedesktop.org" , "linux-kernel@vger.kernel.org" , "linux-stm32@st-md-mailman.stormreply.com" , "linux-arm-kernel@lists.infradead.org" , Yannick FERTRE , Raphael GALLAIS-POU , Philippe CORNU Subject: Re: [PATCH 2/2] drm/stm: ltdc: add crtc background color property support Message-ID: <20210709103614.6d5932ca@eldfell> In-Reply-To: <20210707084557.22443-3-raphael.gallais-pou@foss.st.com> References: <20210707084557.22443-1-raphael.gallais-pou@foss.st.com> <20210707084557.22443-3-raphael.gallais-pou@foss.st.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: multipart/signed; boundary="Sig_/W0kPe8=pA33zQt1ChIiblgo"; protocol="application/pgp-signature"; micalg=pgp-sha256 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --Sig_/W0kPe8=pA33zQt1ChIiblgo Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable On Wed, 7 Jul 2021 08:48:55 +0000 Raphael GALLAIS-POU - foss wrote: > This patch comes from the need to display small resolution pictures with > very few DDR usage. In practice, using a background color, produced by the > drm CRTC, around this picture allows to fetch less data in memory than > setting a full frame picture. And therefore the picture in DDR is smaller > than the size of the screen. >=20 > It uses the DRM framework background color property and modifies the > color to any value between 0x000000 and 0xFFFFFF from userland with a > RGB24 value (0x00RRGGBB). >=20 > Using this feature is observable only if layers are not full screen > or if layers use color formats with alpha and are "transparent" at > least on some pixels. >=20 > Depending on the hardware version, the background color can not be > properly displayed with non-alpha color formats derived from native > alpha color formats (such as XR24 or XR15) since the use of this > pixel format generates a non transparent layer. As a workaround, > the stage background color of the layer and the general background > color need to be synced. >=20 > Signed-off-by: Raphael Gallais-Pou > --- > drivers/gpu/drm/stm/ltdc.c | 48 ++++++++++++++++++++++++++++++++++---- > 1 file changed, 43 insertions(+), 5 deletions(-) >=20 > diff --git a/drivers/gpu/drm/stm/ltdc.c b/drivers/gpu/drm/stm/ltdc.c > index 1f9392fb58e1..0aca245288cc 100644 > --- a/drivers/gpu/drm/stm/ltdc.c > +++ b/drivers/gpu/drm/stm/ltdc.c > @@ -196,6 +196,11 @@ > =20 > #define NB_PF 8 /* Max nb of HW pixel format */ > =20 > +#define DRM_ARGB_TO_LTDC_RGB24(bgcolor) \ > + ((u32)(DRM_ARGB_RED(bgcolor, 8) << 16 \ > + | DRM_ARGB_GREEN(bgcolor, 8) << 8 \ > + | DRM_ARGB_BLUE(bgcolor, 8))) > + > enum ltdc_pix_fmt { > PF_NONE, > /* RGB formats */ > @@ -364,6 +369,15 @@ static inline u32 get_pixelformat_without_alpha(u32 = drm) > } > } > =20 > +/* > + * All non-alpha color formats derived from native alpha color formats a= re > + * either characterized by a FourCC format code (such as XR24, RX24, BX2= 4...) > + */ > +static inline u32 is_xrgb(u32 drm) > +{ > + return ((drm & 'X') =3D=3D 'X' || (drm & ('X' << 8)) =3D=3D ('X' << 8)); Hi, if you're trying to test whether the last or second last byte in the format code is exactly 'X', this doesn't do that. What this does is ignores all the bits that are zero in 'X' and ensures that all the bits that are one in 'X' are also one in the tested value. Thanks, pq > +} > + > static irqreturn_t ltdc_irq_thread(int irq, void *arg) > { > struct drm_device *ddev =3D arg; > @@ -431,7 +445,8 @@ static void ltdc_crtc_atomic_enable(struct drm_crtc *= crtc, > pm_runtime_get_sync(ddev->dev); > =20 > /* Sets the background color value */ > - reg_write(ldev->regs, LTDC_BCCR, BCCR_BCBLACK); > + reg_write(ldev->regs, LTDC_BCCR, > + DRM_ARGB_TO_LTDC_RGB24(crtc->state->bgcolor)); > =20 > /* Enable IRQ */ > reg_set(ldev->regs, LTDC_IER, IER_RRIE | IER_FUIE | IER_TERRIE); > @@ -452,6 +467,9 @@ static void ltdc_crtc_atomic_disable(struct drm_crtc = *crtc, > =20 > drm_crtc_vblank_off(crtc); > =20 > + /* Reset background color */ > + reg_write(ldev->regs, LTDC_BCCR, BCCR_BCBLACK); > + > /* disable IRQ */ > reg_clear(ldev->regs, LTDC_IER, IER_RRIE | IER_FUIE | IER_TERRIE); > =20 > @@ -790,6 +808,7 @@ static void ltdc_plane_atomic_update(struct drm_plane= *plane, > u32 y1 =3D newstate->crtc_y + newstate->crtc_h - 1; > u32 src_x, src_y, src_w, src_h; > u32 val, pitch_in_bytes, line_length, paddr, ahbp, avbp, bpcr; > + u32 bgcolor =3D DRM_ARGB_TO_LTDC_RGB24(newstate->crtc->state->bgcolor); > enum ltdc_pix_fmt pf; > =20 > if (!newstate->crtc || !fb) { > @@ -853,10 +872,28 @@ static void ltdc_plane_atomic_update(struct drm_pla= ne *plane, > if (!fb->format->has_alpha) > val =3D BF1_CA | BF2_1CA; > =20 > - /* Manage hw-specific capabilities */ > - if (ldev->caps.non_alpha_only_l1 && > - plane->type !=3D DRM_PLANE_TYPE_PRIMARY) > - val =3D BF1_PAXCA | BF2_1PAXCA; > + /* > + * Manage hw-specific capabilities > + * > + * Depending on the hardware version, the background color can not be > + * properly displayed with non-alpha color formats derived from native > + * alpha color formats (such as XR24 or XR15) since the use of this > + * pixel format generates a non transparent layer. As a workaround, > + * the stage background color of the layer and the general background > + * color need to be synced. > + * > + * This is done by activating for all XRGB color format the default > + * color as the background color and then setting blending factor > + * accordingly. > + */ > + if (ldev->caps.non_alpha_only_l1) { > + if (is_xrgb(fb->format->format)) { > + val =3D BF1_CA | BF2_1CA; > + reg_write(ldev->regs, LTDC_L1DCCR + lofs, bgcolor); > + } else { > + val =3D BF1_PAXCA | BF2_1PAXCA; > + } > + } > =20 > reg_update_bits(ldev->regs, LTDC_L1BFCR + lofs, > LXBFCR_BF2 | LXBFCR_BF1, val); > @@ -1033,6 +1070,7 @@ static int ltdc_crtc_init(struct drm_device *ddev, = struct drm_crtc *crtc) > =20 > drm_crtc_helper_add(crtc, <dc_crtc_helper_funcs); > =20 > + drm_crtc_add_bgcolor_property(crtc); > drm_mode_crtc_set_gamma_size(crtc, CLUT_SIZE); > drm_crtc_enable_color_mgmt(crtc, 0, false, CLUT_SIZE); > =20 --Sig_/W0kPe8=pA33zQt1ChIiblgo Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEJQjwWQChkWOYOIONI1/ltBGqqqcFAmDn/G4ACgkQI1/ltBGq qqdSAQ/+O54N12B96VfgTSJt/h50b8vyqH6nlYk53aAjDGv71t3XQRp8Z0Yd/TKn mDoGkBad4FHRWfaorqc1DqJztkS8bqmbpz8Jg4mUt/1f/JDfRcIKDlfh/RL2dyrw rNhik+zr6dTPTL7Xs5joQspZ5HvO5yeo1rbSFE0SlpsEJHN+qWnBpobGfiAL4Uue RkXJrEJyAZEuPGcEq8D27ciGqZIQJmMLP/9GuX0+mELmGPOqKFLZaryBqsahGrVo kJu/iGDECeG/bTrczBm02rj4TAkJLcef/s4XESL3N0zFvu3w62ev0CJxFJDcHoh5 WXXnuNgZ2uR1HjnCJojHnjyBYrOAY8PlPL/A3duuKZRS4t+O9nNCxd6/6SICV4eS XmXPmZ68uhUfDNVjyGhHDVGHjfmO3nqzXX2dDxAuKn+lZDwXguza03bX9bJVHdx+ Tj91Addw0b1hPh6T25QIco3SDaQcf6jfTmpMW5pEgJQp/Z50u0Ku2w6rsSRYE8OD XyTDtLOPamHBgLNbEBJW7d7NJcbmsH/K/ucKXBeXUJo5qo4HijTkALl6dcpqF44Y uzJeSCwRzBh/DpDYpDyg5o6tmjZo42cLOSKHAvWZTsWRxT4JIOjVf4UHxEESHg4h Spd7Gp/ks8BeSQ78CkAfsusgn742wkiUE0ExDwyXQCW99mq3UEs= =ft4v -----END PGP SIGNATURE----- --Sig_/W0kPe8=pA33zQt1ChIiblgo--