[PATCH v2 6/9] drm/meson: select RGB plane registers by OSD index

Neil Armstrong neil.armstrong at linaro.org
Thu Dec 3 11:33:10 PST 2026


On 12/3/26 20:21, Guillaume La Roque wrote:
> Pass the OSD index through plane creation and use it to select the scanout
> cache, canvas and control registers. Move the common register writes to
> meson_crtc_flush_osd() so OSD2 can reuse them.
> 
> Keep OSD1 as the only registered RGB plane and preserve its AFBC test and
> hardware programming order.
> 
> Signed-off-by: Guillaume La Roque <glaroque at baylibre.com>
> ---
>   drivers/gpu/drm/meson/meson_crtc.c  | 33 +++++++++++++++++++--------------
>   drivers/gpu/drm/meson/meson_drv.c   |  2 +-
>   drivers/gpu/drm/meson/meson_plane.c | 25 ++++++++++++++++---------
>   drivers/gpu/drm/meson/meson_plane.h |  2 +-
>   4 files changed, 37 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/gpu/drm/meson/meson_crtc.c b/drivers/gpu/drm/meson/meson_crtc.c
> index 27a10508c56e..71efaa58c183 100644
> --- a/drivers/gpu/drm/meson/meson_crtc.c
> +++ b/drivers/gpu/drm/meson/meson_crtc.c
> @@ -145,6 +145,24 @@ static void meson_crtc_atomic_enable(struct drm_crtc *crtc,
>   	drm_crtc_vblank_on(crtc);
>   }
>   
> +static void meson_crtc_flush_osd(struct meson_drm *priv, unsigned int index)
> +{
> +	struct meson_osd_state *osd = &priv->viu.osd[index];
> +	u32 ctrl_stat = index ? VIU_OSD2_CTRL_STAT : VIU_OSD1_CTRL_STAT;
> +	u32 ctrl_stat2 = index ? VIU_OSD2_CTRL_STAT2 : VIU_OSD1_CTRL_STAT2;
> +	u32 blk0_cfg = index ? VIU_OSD2_BLK0_CFG_W0 : VIU_OSD1_BLK0_CFG_W0;
> +	u32 blk0_cfg4 = index ? VIU_OSD2_BLK0_CFG_W4 : VIU_OSD1_BLK0_CFG_W4;
> +	unsigned int i;
> +
> +	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++)
> +		writel_relaxed(osd->blk0_cfg[i],
> +			       priv->io_base + _REG(blk0_cfg + i));
> +
> +	writel_relaxed(osd->blk0_cfg[4], priv->io_base + _REG(blk0_cfg4));
> +}
> +
>   static void meson_g12a_crtc_atomic_disable(struct drm_crtc *crtc,
>   					   struct drm_atomic_commit *state)
>   {
> @@ -317,20 +335,7 @@ void meson_crtc_irq(struct meson_drm *priv)
>   
>   	/* Update the OSD registers */
>   	if (priv->viu.osd[0].enabled && priv->viu.osd[0].commit) {
> -		writel_relaxed(priv->viu.osd[0].ctrl_stat,
> -			       priv->io_base + _REG(VIU_OSD1_CTRL_STAT));
> -		writel_relaxed(priv->viu.osd[0].ctrl_stat2,
> -			       priv->io_base + _REG(VIU_OSD1_CTRL_STAT2));
> -		writel_relaxed(priv->viu.osd[0].blk0_cfg[0],
> -			       priv->io_base + _REG(VIU_OSD1_BLK0_CFG_W0));
> -		writel_relaxed(priv->viu.osd[0].blk0_cfg[1],
> -			       priv->io_base + _REG(VIU_OSD1_BLK0_CFG_W1));
> -		writel_relaxed(priv->viu.osd[0].blk0_cfg[2],
> -			       priv->io_base + _REG(VIU_OSD1_BLK0_CFG_W2));
> -		writel_relaxed(priv->viu.osd[0].blk0_cfg[3],
> -			       priv->io_base + _REG(VIU_OSD1_BLK0_CFG_W3));
> -		writel_relaxed(priv->viu.osd[0].blk0_cfg[4],
> -			       priv->io_base + _REG(VIU_OSD1_BLK0_CFG_W4));
> +		meson_crtc_flush_osd(priv, 0);
>   
>   		if (priv->viu.osd1_afbcd) {
>   			if (meson_crtc->enable_osd1_afbc)
> diff --git a/drivers/gpu/drm/meson/meson_drv.c b/drivers/gpu/drm/meson/meson_drv.c
> index 94d100d8963c..1a3215bf239c 100644
> --- a/drivers/gpu/drm/meson/meson_drv.c
> +++ b/drivers/gpu/drm/meson/meson_drv.c
> @@ -328,7 +328,7 @@ static int meson_drv_bind_master(struct device *dev, bool has_components)
>   			goto exit_afbcd;
>   	}
>   
> -	ret = meson_plane_create(priv);
> +	ret = meson_plane_create(priv, 0);
>   	if (ret)
>   		goto exit_afbcd;
>   
> diff --git a/drivers/gpu/drm/meson/meson_plane.c b/drivers/gpu/drm/meson/meson_plane.c
> index 1c65aedd3926..4d8580263d36 100644
> --- a/drivers/gpu/drm/meson/meson_plane.c
> +++ b/drivers/gpu/drm/meson/meson_plane.c
> @@ -66,6 +66,7 @@
>   struct meson_plane {
>   	struct drm_plane base;
>   	struct meson_drm *priv;
> +	unsigned int index;
>   	bool enabled;
>   };
>   #define to_meson_plane(x) container_of(x, struct meson_plane, base)
> @@ -251,11 +252,11 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
>   									   plane);
>   	struct drm_rect dest = drm_plane_state_dest(new_state);
>   	struct meson_drm *priv = meson_plane->priv;
> -	struct meson_osd_state *osd = &priv->viu.osd[0];
>   	struct drm_framebuffer *fb = new_state->fb;
>   	struct drm_gem_dma_object *gem;
>   	unsigned long flags;
> -	u8 canvas_id_osd1;
> +	unsigned int index = meson_plane->index;
> +	struct meson_osd_state *osd = &priv->viu.osd[index];
>   
>   	/*
>   	 * Update Coordinates
> @@ -279,12 +280,10 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
>   				   OSD_BLK0_ENABLE;
>   
>   	osd->ctrl_stat2 = readl(priv->io_base +
> -					  _REG(VIU_OSD1_CTRL_STAT2));
> -
> -	canvas_id_osd1 = priv->canvas_id_osd[0];
> +					  _REG(index ? VIU_OSD2_CTRL_STAT2 : VIU_OSD1_CTRL_STAT2));
>   
>   	/* Set up BLK0 to point to the right canvas */
> -	osd->blk0_cfg[0] = canvas_id_osd1 << OSD_CANVAS_SEL;
> +	osd->blk0_cfg[0] = priv->canvas_id_osd[index] << OSD_CANVAS_SEL;
>   
>   	if (priv->viu.osd1_afbcd) {
>   		if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
> @@ -429,7 +428,7 @@ static void meson_plane_atomic_disable(struct drm_plane *plane,
>   				    priv->io_base + _REG(VPP_MISC));
>   
>   	meson_plane->enabled = false;
> -	priv->viu.osd[0].enabled = false;
> +	priv->viu.osd[meson_plane->index].enabled = false;
>   }
>   
>   static const struct drm_plane_helper_funcs meson_plane_helper_funcs = {
> @@ -542,7 +541,14 @@ static const uint64_t format_modifiers_default[] = {
>   	DRM_FORMAT_MOD_INVALID,
>   };
>   
> -int meson_plane_create(struct meson_drm *priv)
> +/**
> + * meson_plane_create - Register an RGB plane
> + * @priv: Meson DRM device
> + * @index: Zero-based OSD index
> + *
> + * Return: 0 on success or a negative error code.
> + */
> +int meson_plane_create(struct meson_drm *priv, unsigned int index)
>   {
>   	struct meson_plane *meson_plane;
>   	struct drm_plane *plane;
> @@ -554,6 +560,7 @@ int meson_plane_create(struct meson_drm *priv)
>   		return -ENOMEM;
>   
>   	meson_plane->priv = priv;
> +	meson_plane->index = index;
>   	plane = &meson_plane->base;
>   
>   	if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM))
> @@ -575,7 +582,7 @@ int meson_plane_create(struct meson_drm *priv)
>   	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, 1);
> +	ret = drm_plane_create_zpos_immutable_property(plane, index + 1);
>   	if (ret) {
>   		drm_plane_cleanup(plane);
>   		return ret;
> diff --git a/drivers/gpu/drm/meson/meson_plane.h b/drivers/gpu/drm/meson/meson_plane.h
> index 1460e182cd22..6e891d54bb63 100644
> --- a/drivers/gpu/drm/meson/meson_plane.h
> +++ b/drivers/gpu/drm/meson/meson_plane.h
> @@ -13,6 +13,6 @@
>   
>   #include "meson_drv.h"
>   
> -int meson_plane_create(struct meson_drm *priv);
> +int meson_plane_create(struct meson_drm *priv, unsigned int index);
>   
>   #endif /* __MESON_PLANE_H */
> 

Reviewed-by: Neil Armstrong <neil.armstrong at linaro.org>

Thanks,
Neil



More information about the linux-arm-kernel mailing list