From: Neil Armstrong <neil.armstrong@linaro.org>
To: Guillaume La Roque <glaroque@baylibre.com>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
Kevin Hilman <khilman@baylibre.com>,
Jerome Brunet <jbrunet@baylibre.com>,
Martin Blumenstingl <martin.blumenstingl@googlemail.com>
Cc: dri-devel@lists.freedesktop.org,
linux-amlogic@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
Simona Vetter <simona.vetter@ffwll.ch>
Subject: Re: [PATCH v2 9/9] drm/meson: add a linear RGB overlay on G12A OSD2
Date: Thu, 3 Dec 2026 20:34:44 +0100 [thread overview]
Message-ID: <7de598cb-212e-42e8-bc48-f166ecf1b7cb@linaro.org> (raw)
In-Reply-To: <20261203-meson-g12a-osd2-v2-9-8a4a57d32e20@baylibre.com>
On 12/3/26 20:21, Guillaume La Roque wrote:
> The VD1 overlay cannot scan out the RGB buffers used by the UI. Expose
> OSD2 above the primary plane on G12A, G12B and SM1 to allow hardware
> composition of another RGB layer.
>
> The RGB-to-YUV CSC expects straight RGB. Enable the alpha divider for
> premultiplied buffers and use straight alpha at postblend. Limit this
> plane to linear buffers without scaling or interlace.
>
> Signed-off-by: Guillaume La Roque <glaroque@baylibre.com>
> ---
> drivers/gpu/drm/meson/meson_crtc.c | 68 ++++++++++++-
> drivers/gpu/drm/meson/meson_drv.c | 17 +++-
> drivers/gpu/drm/meson/meson_drv.h | 3 +
> drivers/gpu/drm/meson/meson_encoder_dsi.c | 2 +
> drivers/gpu/drm/meson/meson_plane.c | 161 ++++++++++++++++++++++--------
> drivers/gpu/drm/meson/meson_registers.h | 5 +
> drivers/gpu/drm/meson/meson_viu.c | 16 +++
> 7 files changed, 229 insertions(+), 43 deletions(-)
>
> diff --git a/drivers/gpu/drm/meson/meson_crtc.c b/drivers/gpu/drm/meson/meson_crtc.c
> index 19412d0d7432..38a813772c79 100644
> --- a/drivers/gpu/drm/meson/meson_crtc.c
> +++ b/drivers/gpu/drm/meson/meson_crtc.c
> @@ -12,6 +12,7 @@
> #include <linux/bitfield.h>
> #include <linux/soc/amlogic/meson-canvas.h>
>
> +#include <drm/drm_atomic.h>
> #include <drm/drm_atomic_helper.h>
> #include <drm/drm_device.h>
> #include <drm/drm_print.h>
> @@ -154,6 +155,18 @@ static void meson_crtc_flush_osd(struct meson_drm *priv, unsigned int index)
> u32 blk0_cfg4 = index ? VIU_OSD2_BLK0_CFG_W4 : VIU_OSD1_BLK0_CFG_W4;
> unsigned int i;
>
> + if (!osd->enabled) {
> + writel_bits_relaxed(OSD_ENABLE | OSD_BLK0_ENABLE, 0,
> + priv->io_base + _REG(ctrl_stat));
> + if (index) {
> + writel_bits_relaxed(OSD_BLEND_POSTBLD_SRC_MASK, 0,
> + priv->io_base + _REG(OSD2_BLEND_SRC_CTRL));
> + writel_bits_relaxed(VIU_OSD_BLEND_DIN_EN(8), 0,
> + priv->io_base + _REG(VIU_OSD_BLEND_CTRL));
> + }
> + return;
> + }
> +
> writel_relaxed(osd->ctrl_stat, priv->io_base + _REG(ctrl_stat));
> writel_relaxed(osd->ctrl_stat2, priv->io_base + _REG(ctrl_stat2));
> for (i = 0; i < 4; i++)
> @@ -161,6 +174,44 @@ static void meson_crtc_flush_osd(struct meson_drm *priv, unsigned int index)
> priv->io_base + _REG(blk0_cfg + i));
>
> writel_relaxed(osd->blk0_cfg[4], priv->io_base + _REG(blk0_cfg4));
> +
> + if (!index)
> + return;
> +
> + meson_canvas_config(priv->canvas, priv->canvas_id_osd[index],
> + osd->addr, osd->stride, osd->height,
> + MESON_CANVAS_WRAP_NONE,
> + MESON_CANVAS_BLKMODE_LINEAR, 0);
> +
> + writel_bits_relaxed(OSD_MALI_ALPHA_DIV_EN,
> + osd->alpha_div ? OSD_MALI_ALPHA_DIV_EN : 0,
> + priv->io_base + _REG(VIU_OSD2_MALI_UNPACK_CTRL));
> + writel_relaxed(osd->blk0_cfg[3],
> + priv->io_base + _REG(VIU_OSD_BLEND_DIN3_SCOPE_H));
> + writel_relaxed(osd->blk0_cfg[4],
> + priv->io_base + _REG(VIU_OSD_BLEND_DIN3_SCOPE_V));
> + /*
> + * DIN0 and DIN3 feed DOUT0 and DOUT1 directly. The BLEND1-to-BLEND2
> + * route stays configured but is outside both bypass paths. DIN3 and
> + * VPP scopes stay in CRTC coordinates; BLEND1_SIZE is the clipped
> + * OSD2 raster size without the CRTC offset.
> + */
> + writel_relaxed(osd->blend_size,
> + priv->io_base + _REG(VIU_OSD_BLEND_BLEND1_SIZE));
> + writel_relaxed((osd->blk0_cfg[3] << 16) | (osd->blk0_cfg[3] >> 16),
> + priv->io_base + _REG(VPP_OSD2_BLD_H_SCOPE));
> + writel_relaxed((osd->blk0_cfg[4] << 16) | (osd->blk0_cfg[4] >> 16),
> + priv->io_base + _REG(VPP_OSD2_BLD_V_SCOPE));
> + writel_bits_relaxed(VIU_OSD_BLEND_REORDER(3, 0xf) |
> + VIU_OSD_BLEND_DIN_EN(8),
> + VIU_OSD_BLEND_REORDER(3, 2) |
> + VIU_OSD_BLEND_DIN_EN(8),
> + priv->io_base + _REG(VIU_OSD_BLEND_CTRL));
> + /* DIN3 bypasses the OSD blender, so VPP receives straight alpha. */
> + writel_bits_relaxed(OSD_BLEND_POSTBLD_SRC_MASK |
> + OSD_BLEND_POSTBLD_PREMULT_EN,
> + OSD_BLEND_POSTBLD_SRC_OSD2,
> + priv->io_base + _REG(OSD2_BLEND_SRC_CTRL));
> }
>
> static void meson_g12a_crtc_atomic_disable(struct drm_crtc *crtc,
> @@ -177,6 +228,9 @@ static void meson_g12a_crtc_atomic_disable(struct drm_crtc *crtc,
> spin_lock_irqsave(&priv->drm->event_lock, flags);
> priv->viu.osd[0].enabled = false;
> priv->viu.osd[0].commit = false;
> + priv->viu.osd[1].enabled = false;
> + priv->viu.osd[1].commit = false;
> + meson_crtc_flush_osd(priv, 1);
> spin_unlock_irqrestore(&priv->drm->event_lock, flags);
>
> priv->viu.vd1_enabled = false;
> @@ -205,6 +259,8 @@ static void meson_crtc_atomic_disable(struct drm_crtc *crtc,
> spin_lock_irqsave(&priv->drm->event_lock, flags);
> priv->viu.osd[0].enabled = false;
> priv->viu.osd[0].commit = false;
> + priv->viu.osd[1].enabled = false;
> + priv->viu.osd[1].commit = false;
>
> priv->viu.vd1_enabled = false;
> priv->viu.vd1_commit = false;
> @@ -249,6 +305,9 @@ static void meson_crtc_atomic_flush(struct drm_crtc *crtc,
>
> spin_lock_irqsave(&priv->drm->event_lock, flags);
> priv->viu.osd[0].commit = true;
> + if (priv->osd2_plane &&
> + drm_atomic_get_new_plane_state(state, priv->osd2_plane))
> + priv->viu.osd[1].commit = true;
> priv->viu.vd1_commit = true;
> spin_unlock_irqrestore(&priv->drm->event_lock, flags);
> }
> @@ -304,7 +363,8 @@ static void meson_g12a_crtc_enable_osd1(struct meson_drm *priv)
> writel_relaxed(priv->viu.osd[0].blend_size,
> priv->io_base +
> _REG(VIU_OSD_BLEND_BLEND0_SIZE));
> - writel_relaxed(priv->viu.osd[0].blend_size,
> + writel_relaxed(priv->viu.osd[1].enabled ? priv->viu.osd[1].blend_size :
> + priv->viu.osd[0].blend_size,
> priv->io_base +
> _REG(VIU_OSD_BLEND_BLEND1_SIZE));
> writel_bits_relaxed(3 << 8, 3 << 8,
> @@ -344,6 +404,12 @@ void meson_crtc_irq(struct meson_drm *priv)
>
> spin_lock_irqsave(&priv->drm->event_lock, flags);
>
> + if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A) &&
> + priv->viu.osd[1].commit) {
> + meson_crtc_flush_osd(priv, 1);
> + priv->viu.osd[1].commit = false;
> + }
> +
> /* Update the OSD registers */
> if (priv->viu.osd[0].enabled && priv->viu.osd[0].commit) {
> meson_crtc_flush_osd(priv, 0);
> diff --git a/drivers/gpu/drm/meson/meson_drv.c b/drivers/gpu/drm/meson/meson_drv.c
> index 1a3215bf239c..ab4d8420bbaf 100644
> --- a/drivers/gpu/drm/meson/meson_drv.c
> +++ b/drivers/gpu/drm/meson/meson_drv.c
> @@ -250,9 +250,14 @@ static int meson_drv_bind_master(struct device *dev, bool has_components)
> ret = meson_canvas_alloc(priv->canvas, &priv->canvas_id_osd[0]);
> if (ret)
> goto free_drm;
> + if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
> + ret = meson_canvas_alloc(priv->canvas, &priv->canvas_id_osd[1]);
> + if (ret)
> + goto free_canvas_osd1;
> + }
> ret = meson_canvas_alloc(priv->canvas, &priv->canvas_id_vd1_0);
> if (ret)
> - goto free_canvas_osd1;
> + goto free_canvas_osd2;
> ret = meson_canvas_alloc(priv->canvas, &priv->canvas_id_vd1_1);
> if (ret)
> goto free_canvas_vd1_0;
> @@ -335,6 +340,11 @@ static int meson_drv_bind_master(struct device *dev, bool has_components)
> ret = meson_overlay_create(priv);
> if (ret)
> goto exit_afbcd;
> + if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
> + ret = meson_plane_create(priv, 1);
> + if (ret)
> + goto exit_afbcd;
> + }
>
> ret = meson_crtc_create(priv);
> if (ret)
> @@ -369,6 +379,9 @@ static int meson_drv_bind_master(struct device *dev, bool has_components)
> meson_canvas_free(priv->canvas, priv->canvas_id_vd1_1);
> free_canvas_vd1_0:
> meson_canvas_free(priv->canvas, priv->canvas_id_vd1_0);
> +free_canvas_osd2:
> + if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A))
> + meson_canvas_free(priv->canvas, priv->canvas_id_osd[1]);
> free_canvas_osd1:
> meson_canvas_free(priv->canvas, priv->canvas_id_osd[0]);
> free_drm:
> @@ -396,6 +409,8 @@ static void meson_drv_unbind(struct device *dev)
>
> if (priv->canvas) {
> meson_canvas_free(priv->canvas, priv->canvas_id_osd[0]);
> + if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A))
> + meson_canvas_free(priv->canvas, priv->canvas_id_osd[1]);
> meson_canvas_free(priv->canvas, priv->canvas_id_vd1_0);
> meson_canvas_free(priv->canvas, priv->canvas_id_vd1_1);
> meson_canvas_free(priv->canvas, priv->canvas_id_vd1_2);
> diff --git a/drivers/gpu/drm/meson/meson_drv.h b/drivers/gpu/drm/meson/meson_drv.h
> index 77a5c5e792e9..0f2dcf9755b2 100644
> --- a/drivers/gpu/drm/meson/meson_drv.h
> +++ b/drivers/gpu/drm/meson/meson_drv.h
> @@ -44,6 +44,7 @@ struct meson_drm_soc_limits {
> * struct meson_osd_state - RGB plane registers applied at vblank
> * @enabled: Whether the plane is visible
> * @commit: Whether the register cache is ready to be applied
> + * @alpha_div: Convert premultiplied RGB to straight RGB before the CSC
> * @ctrl_stat: OSD control and global alpha
> * @ctrl_stat2: Pixel alpha replacement control
> * @blk0_cfg: Format and source/destination rectangles
> @@ -56,6 +57,7 @@ struct meson_drm_soc_limits {
> struct meson_osd_state {
> bool enabled;
> bool commit;
> + bool alpha_div;
> u32 ctrl_stat;
> u32 ctrl_stat2;
> u32 blk0_cfg[5];
> @@ -82,6 +84,7 @@ struct meson_drm {
> struct drm_device *drm;
> struct drm_crtc *crtc;
> struct drm_plane *primary_plane;
> + struct drm_plane *osd2_plane;
> struct drm_plane *overlay_plane;
> void *encoders[MESON_ENC_LAST];
>
> diff --git a/drivers/gpu/drm/meson/meson_encoder_dsi.c b/drivers/gpu/drm/meson/meson_encoder_dsi.c
> index 912cd676bbe2..e61a2248504b 100644
> --- a/drivers/gpu/drm/meson/meson_encoder_dsi.c
> +++ b/drivers/gpu/drm/meson/meson_encoder_dsi.c
> @@ -74,6 +74,7 @@ static void meson_encoder_dsi_atomic_enable(struct drm_bridge *bridge,
> writel_relaxed(0, priv->io_base + _REG(ENCL_TST_EN));
>
> writel_bits_relaxed(BIT(0), 0, priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_EN_CTRL));
> + writel_bits_relaxed(BIT(0), 0, priv->io_base + _REG(VPP_WRAP_OSD2_MATRIX_EN_CTRL));
>
> writel_relaxed(1, priv->io_base + _REG(ENCL_VIDEO_EN));
> }
> @@ -88,6 +89,7 @@ static void meson_encoder_dsi_atomic_disable(struct drm_bridge *bridge,
> writel_relaxed(0, priv->io_base + _REG(ENCL_VIDEO_EN));
>
> writel_bits_relaxed(BIT(0), BIT(0), priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_EN_CTRL));
> + writel_bits_relaxed(BIT(0), BIT(0), priv->io_base + _REG(VPP_WRAP_OSD2_MATRIX_EN_CTRL));
> }
>
> static const struct drm_bridge_funcs meson_encoder_dsi_bridge_funcs = {
> diff --git a/drivers/gpu/drm/meson/meson_plane.c b/drivers/gpu/drm/meson/meson_plane.c
> index ea198582ebbc..cf45a33ea5f9 100644
> --- a/drivers/gpu/drm/meson/meson_plane.c
> +++ b/drivers/gpu/drm/meson/meson_plane.c
> @@ -10,6 +10,7 @@
> */
>
> #include <linux/bitfield.h>
> +#include <linux/sizes.h>
>
> #include <drm/drm_atomic.h>
> #include <drm/drm_atomic_helper.h>
> @@ -78,7 +79,11 @@ static int meson_plane_atomic_check(struct drm_plane *plane,
> {
> struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
> plane);
> + struct meson_plane *meson_plane = to_meson_plane(plane);
> + struct drm_framebuffer *fb = new_plane_state->fb;
> + struct drm_gem_dma_object *gem;
> struct drm_crtc_state *crtc_state;
> + int ret;
>
> if (!new_plane_state->crtc)
> return 0;
> @@ -88,16 +93,33 @@ static int meson_plane_atomic_check(struct drm_plane *plane,
> if (IS_ERR(crtc_state))
> return PTR_ERR(crtc_state);
>
> - /*
> - * Only allow :
> - * - Upscaling up to 5x, vertical and horizontal
> - * - Final coordinates must match crtc size
> - */
> - return drm_atomic_helper_check_plane_state(new_plane_state,
> - crtc_state,
> - FRAC_16_16(1, 5),
> - DRM_PLANE_NO_SCALING,
> - false, true);
> + if (meson_plane->index &&
> + crtc_state->adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
> + return -EINVAL;
> +
> + /* OSD1 can upscale up to 5x; OSD2 is positioned without scaling. */
> + ret = drm_atomic_helper_check_plane_state(new_plane_state, crtc_state,
> + meson_plane->index ?
> + DRM_PLANE_NO_SCALING : FRAC_16_16(1, 5),
> + DRM_PLANE_NO_SCALING,
> + meson_plane->index != 0, true);
> + if (ret || !meson_plane->index || !new_plane_state->visible)
> + return ret;
> +
> + if ((new_plane_state->src.x1 | new_plane_state->src.y1 |
> + new_plane_state->src.x2 | new_plane_state->src.y2) & 0xffff)
> + return -EINVAL;
> +
> + /* The canvas stride is a 12-bit field in units of eight bytes. */
> + if (fb->pitches[0] >= SZ_32K)
> + return -EINVAL;
> +
> + gem = drm_fb_dma_get_gem_obj(fb, 0);
> + if (!IS_ALIGNED(gem->dma_addr + fb->offsets[0], 8) ||
> + !IS_ALIGNED(fb->pitches[0], 8))
> + return -EINVAL;
> +
> + return 0;
> }
>
> #define MESON_MOD_AFBC_VALID_BITS (AFBC_FORMAT_MOD_BLOCK_SIZE_16x16 | \
> @@ -257,6 +279,7 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
> unsigned long flags;
> unsigned int index = meson_plane->index;
> struct meson_osd_state *osd = &priv->viu.osd[index];
> + bool afbcd = false;
>
> /*
> * Update Coordinates
> @@ -266,18 +289,27 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
> */
> spin_lock_irqsave(&priv->drm->event_lock, flags);
>
> - /* Check if AFBC decoder is required for this buffer */
> - if ((meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM) ||
> - meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) &&
> - fb->modifier & DRM_FORMAT_MOD_ARM_AFBC(MESON_MOD_AFBC_VALID_BITS))
> - priv->viu.osd1_afbcd = true;
> - else
> - priv->viu.osd1_afbcd = false;
> + if (index && !new_state->visible) {
> + osd->enabled = false;
> + spin_unlock_irqrestore(&priv->drm->event_lock, flags);
> + return;
> + }
>
> - /* Enable OSD and BLK0, set max global alpha */
> - osd->ctrl_stat = OSD_ENABLE |
> - (0x100 << OSD_GLOBAL_ALPHA_SHIFT) |
> - OSD_BLK0_ENABLE;
> + if (index) {
> + dest = new_state->dst;
> + } else {
> + /* Only OSD1 has an AFBC decoder in this pipeline. */
> + if ((meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM) ||
> + meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) &&
> + fb->modifier & DRM_FORMAT_MOD_ARM_AFBC(MESON_MOD_AFBC_VALID_BITS))
> + afbcd = true;
> + priv->viu.osd1_afbcd = afbcd;
> + }
> +
> + /* Enable OSD and BLK0. */
> + osd->ctrl_stat = OSD_ENABLE | OSD_BLK0_ENABLE |
> + ((index ? DIV_ROUND_CLOSEST(new_state->alpha * 256, 0xffff) :
> + 0x100) << OSD_GLOBAL_ALPHA_SHIFT);
>
> osd->ctrl_stat2 = readl(priv->io_base +
> _REG(index ? VIU_OSD2_CTRL_STAT2 : VIU_OSD1_CTRL_STAT2));
> @@ -285,7 +317,7 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
> /* Set up BLK0 to point to the right canvas */
> osd->blk0_cfg[0] = priv->canvas_id_osd[index] << OSD_CANVAS_SEL;
>
> - if (priv->viu.osd1_afbcd) {
> + if (afbcd) {
> if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
> /* This is the internal decoding memory address */
> priv->viu.osd1_blk1_cfg4 = MESON_G12A_AFBCD_OUT_ADDR;
> @@ -309,7 +341,7 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
> if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXBB))
> osd->blk0_cfg[0] |= OSD_OUTPUT_COLOR_RGB;
>
> - if (priv->viu.osd1_afbcd &&
> + if (afbcd &&
> meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
> osd->blk0_cfg[0] |= OSD_MALI_SRC_EN |
> priv->afbcd.ops->fmt_to_blk_mode(fb->modifier,
> @@ -350,7 +382,17 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
> break;
> }
>
> - meson_plane_setup_scaler(priv, new_state, &dest);
> + if (index) {
> + if (new_state->pixel_blend_mode == DRM_MODE_BLEND_PIXEL_NONE)
> + osd->ctrl_stat2 |= OSD_REPLACE_EN;
> +
> + /* The RGB-to-YUV CSC requires straight RGB components. */
> + osd->alpha_div = fb->format->has_alpha &&
> + new_state->pixel_blend_mode == DRM_MODE_BLEND_PREMULTI;
> + }
> +
> + if (!index)
> + meson_plane_setup_scaler(priv, new_state, &dest);
>
> /*
> * The format of these registers is (x2 << 16 | x1),
> @@ -370,8 +412,12 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
> int dst_w = new_state->crtc_w;
> int dst_h = new_state->crtc_h;
>
> - if (new_state->crtc->mode.flags & DRM_MODE_FLAG_INTERLACE)
> + if (index) {
> + dst_w = drm_rect_width(&dest);
> + dst_h = drm_rect_height(&dest);
> + } else if (new_state->crtc->mode.flags & DRM_MODE_FLAG_INTERLACE) {
> dst_h /= 2;
> + }
>
> osd->blend_size = dst_h << 16 | dst_w;
> }
> @@ -384,7 +430,7 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
> osd->height = fb->height;
> osd->width = fb->width;
>
> - if (priv->viu.osd1_afbcd) {
> + if (afbcd) {
> priv->afbcd.modifier = fb->modifier;
> priv->afbcd.format = fb->format->format;
>
> @@ -394,7 +440,7 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
> meson_g12a_afbcd_line_stride(priv);
> }
>
> - if (!meson_plane->enabled) {
> + if (!index && !meson_plane->enabled) {
> /* Reset OSD1 before enabling it on GXL+ SoCs */
> if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM) ||
> meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXL))
> @@ -420,6 +466,9 @@ static void meson_plane_atomic_disable(struct drm_plane *plane,
> priv->viu.osd[meson_plane->index].enabled = false;
> spin_unlock_irqrestore(&priv->drm->event_lock, flags);
>
> + if (meson_plane->index)
> + return;
> +
> if (priv->afbcd.ops) {
> priv->afbcd.ops->reset(priv);
> priv->afbcd.ops->disable(priv);
> @@ -453,6 +502,9 @@ static bool meson_plane_format_mod_supported(struct drm_plane *plane,
> if (modifier == DRM_FORMAT_MOD_LINEAR)
> return true;
>
> + if (meson_plane->index)
> + return false;
> +
> if (!meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM) &&
> !meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A))
> return false;
> @@ -495,6 +547,13 @@ static const uint32_t supported_drm_formats[] = {
> DRM_FORMAT_RGB565,
> };
>
> +static const u32 supported_drm_formats_osd2[] = {
> + DRM_FORMAT_ARGB8888,
> + DRM_FORMAT_ABGR8888,
> + DRM_FORMAT_XRGB8888,
> + DRM_FORMAT_XBGR8888,
> +};
> +
> static const uint64_t format_modifiers_afbc_gxm[] = {
> DRM_FORMAT_MOD_ARM_AFBC(AFBC_FORMAT_MOD_BLOCK_SIZE_16x16 |
> AFBC_FORMAT_MOD_SPARSE |
> @@ -547,7 +606,7 @@ static const uint64_t format_modifiers_default[] = {
> /**
> * meson_plane_create - Register an RGB plane
> * @priv: Meson DRM device
> - * @index: Zero-based OSD index
> + * @index: OSD index, 0 for the primary plane or 1 for the G12A overlay
> *
> * Return: 0 on success or a negative error code.
> */
> @@ -566,17 +625,21 @@ int meson_plane_create(struct meson_drm *priv, unsigned int index)
> meson_plane->index = index;
> plane = &meson_plane->base;
>
> - if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM))
> - format_modifiers = format_modifiers_afbc_gxm;
> - else if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A))
> - format_modifiers = format_modifiers_afbc_g12a;
> + if (!index) {
> + if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM))
> + format_modifiers = format_modifiers_afbc_gxm;
> + else if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A))
> + format_modifiers = format_modifiers_afbc_g12a;
> + }
>
> ret = drm_universal_plane_init(priv->drm, plane, 0xFF,
> &meson_plane_funcs,
> - supported_drm_formats,
> - ARRAY_SIZE(supported_drm_formats),
> + index ? supported_drm_formats_osd2 : supported_drm_formats,
> + index ? ARRAY_SIZE(supported_drm_formats_osd2) :
> + ARRAY_SIZE(supported_drm_formats),
> format_modifiers,
> - DRM_PLANE_TYPE_PRIMARY, "meson_primary_plane");
> + index ? DRM_PLANE_TYPE_OVERLAY : DRM_PLANE_TYPE_PRIMARY,
> + index ? "meson_osd2_plane" : "meson_primary_plane");
> if (ret) {
> devm_kfree(priv->drm->dev, meson_plane);
> return ret;
> @@ -584,14 +647,30 @@ int meson_plane_create(struct meson_drm *priv, unsigned int index)
>
> drm_plane_helper_add(plane, &meson_plane_helper_funcs);
>
> - /* For now, OSD Primary plane is always on the front */
> ret = drm_plane_create_zpos_immutable_property(plane, index + 1);
> - if (ret) {
> - drm_plane_cleanup(plane);
> - return ret;
> + if (ret)
> + goto cleanup;
> +
> + if (index) {
> + ret = drm_plane_create_alpha_property(plane);
> + if (ret)
> + goto cleanup;
> +
> + ret = drm_plane_create_blend_mode_property(plane,
> + BIT(DRM_MODE_BLEND_PIXEL_NONE) |
> + BIT(DRM_MODE_BLEND_PREMULTI) |
> + BIT(DRM_MODE_BLEND_COVERAGE));
> + if (ret)
> + goto cleanup;
> +
> + priv->osd2_plane = plane;
> + } else {
> + priv->primary_plane = plane;
> }
>
> - priv->primary_plane = plane;
> -
> return 0;
> +
> +cleanup:
> + drm_plane_cleanup(plane);
> + return ret;
> }
> diff --git a/drivers/gpu/drm/meson/meson_registers.h b/drivers/gpu/drm/meson/meson_registers.h
> index 3d73d00a1f4c..4b882d628192 100644
> --- a/drivers/gpu/drm/meson/meson_registers.h
> +++ b/drivers/gpu/drm/meson/meson_registers.h
> @@ -238,6 +238,9 @@
> #define VIU_OSD2_TEST_RDDATA 0x1a4c
> #define VIU_OSD2_PROT_CTRL 0x1a4e
> #define VIU_OSD2_MALI_UNPACK_CTRL 0x1abd
> +#define OSD_MALI_ALPHA_DIV_EN BIT(28)
> +#define OSD_MALI_ALPHA_DIV_CLK_GATE GENMASK(27, 26)
> +#define OSD_MALI_ALPHA_MAPPING GENMASK(25, 24)
> #define VIU_OSD2_DIMM_CTRL 0x1acf
>
> #define VIU_OSD3_CTRL_STAT 0x3d80
> @@ -1896,6 +1899,8 @@
> #define VD_BLEND_POSTBLD_PREMULT_EN BIT(16)
> #define OSD1_BLEND_SRC_CTRL 0x1dfd
> #define OSD2_BLEND_SRC_CTRL 0x1dfe
> +#define OSD_BLEND_POSTBLD_PREMULT_EN BIT(16)
> +#define OSD_BLEND_POSTBLD_SRC_MASK GENMASK(11, 8)
> #define OSD_BLEND_POSTBLD_SRC_VD1 (1 << 8)
> #define OSD_BLEND_POSTBLD_SRC_VD2 (2 << 8)
> #define OSD_BLEND_POSTBLD_SRC_OSD1 (3 << 8)
> diff --git a/drivers/gpu/drm/meson/meson_viu.c b/drivers/gpu/drm/meson/meson_viu.c
> index f618e6ba4731..9d10766c8bca 100644
> --- a/drivers/gpu/drm/meson/meson_viu.c
> +++ b/drivers/gpu/drm/meson/meson_viu.c
> @@ -428,6 +428,7 @@ void meson_viu_init(struct meson_drm *priv)
> meson_viu_load_matrix(priv);
> else if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
> meson_viu_set_g12a_osd_matrix(priv, 0, RGB709_to_YUV709l_coeff);
> + meson_viu_set_g12a_osd_matrix(priv, 1, RGB709_to_YUV709l_coeff);
> /* fix green/pink color distortion from vendor u-boot */
> writel_bits_relaxed(OSD1_HDR2_CTRL_REG_ONLY_MAT |
> OSD1_HDR2_CTRL_VDIN0_HDR2_TOP_EN, 0,
> @@ -495,6 +496,19 @@ void meson_viu_init(struct meson_drm *priv)
> priv->io_base + _REG(DOLBY_PATH_CTRL));
>
> meson_viu_g12a_disable_osd1_afbc(priv);
> +
> + /* OSD2 uses the canvas path without its scaler or AFBC decoder. */
> + writel_relaxed(0, priv->io_base + _REG(OSD2_SC_CTRL0));
> + writel_relaxed(0, priv->io_base + _REG(OSD2_VSC_CTRL0));
> + writel_relaxed(0, priv->io_base + _REG(OSD2_HSC_CTRL0));
> + writel_relaxed(0, priv->io_base + _REG(VIU_OSD2_DIMM_CTRL));
> + writel_bits_relaxed(OSD_PATH_OSD_AXI_SEL_OSD2_AFBCD, 0,
> + priv->io_base + _REG(OSD_PATH_MISC_CTRL));
> + writel_bits_relaxed(VIU_OSD1_MALI_UNPACK_EN |
> + OSD_MALI_ALPHA_DIV_EN |
> + OSD_MALI_ALPHA_DIV_CLK_GATE |
> + OSD_MALI_ALPHA_MAPPING, 0,
> + priv->io_base + _REG(VIU_OSD2_MALI_UNPACK_CTRL));
> }
>
> if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM))
> @@ -502,5 +516,7 @@ void meson_viu_init(struct meson_drm *priv)
>
> priv->viu.osd[0].enabled = false;
> priv->viu.osd[0].commit = false;
> + priv->viu.osd[1].enabled = false;
> + priv->viu.osd[1].commit = false;
> priv->viu.osd1_interlace = false;
> }
>
Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
Thanks,
Neil
next prev parent reply other threads:[~2026-12-03 20:51 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 19:21 [PATCH v2 0/9] drm/meson: add a second RGB plane on G12A Guillaume La Roque
2026-12-03 19:21 ` [PATCH v2 1/9] drm/meson: honor framebuffer offsets for the primary plane Guillaume La Roque
2026-12-03 19:31 ` Neil Armstrong
2026-12-03 19:21 ` [PATCH v2 2/9] drm/meson: isolate primary plane scaler setup Guillaume La Roque
2026-12-03 19:32 ` Neil Armstrong
2026-12-03 19:21 ` [PATCH v2 3/9] drm/meson: keep RGB scanout state per OSD Guillaume La Roque
2026-12-03 19:32 ` Neil Armstrong
2026-12-03 19:21 ` [PATCH v2 4/9] drm/meson: parameterize the G12A OSD color matrix setup Guillaume La Roque
2026-12-03 19:21 ` [PATCH v2 5/9] drm/meson: handle primary plane zpos allocation failure Guillaume La Roque
2026-12-03 19:21 ` [PATCH v2 6/9] drm/meson: select RGB plane registers by OSD index Guillaume La Roque
2026-12-03 19:33 ` Neil Armstrong
2026-12-03 19:21 ` [PATCH v2 7/9] drm/meson: serialize OSD state updates with the IRQ Guillaume La Roque
2026-12-03 19:21 ` [PATCH v2 8/9] drm/meson: clear pending primary updates while disabled Guillaume La Roque
2026-12-03 19:33 ` Neil Armstrong
2026-12-03 19:21 ` [PATCH v2 9/9] drm/meson: add a linear RGB overlay on G12A OSD2 Guillaume La Roque
2026-12-03 19:34 ` Neil Armstrong [this message]
2026-12-03 19:38 ` [PATCH v2 0/9] drm/meson: add a second RGB plane on G12A Neil Armstrong
2026-12-03 19:58 ` Guillaume La Roque
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7de598cb-212e-42e8-bc48-f166ecf1b7cb@linaro.org \
--to=neil.armstrong@linaro.org \
--cc=airlied@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=glaroque@baylibre.com \
--cc=jbrunet@baylibre.com \
--cc=khilman@baylibre.com \
--cc=linux-amlogic@lists.infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=martin.blumenstingl@googlemail.com \
--cc=mripard@kernel.org \
--cc=simona.vetter@ffwll.ch \
--cc=simona@ffwll.ch \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox