[PATCH 6/8] drm/meson: select RGB plane registers by OSD index
Guillaume La Roque
glaroque at baylibre.com
Wed Dec 2 03:57:08 PST 2026
Le 01/12/2026 à 09:32, Neil Armstrong a écrit :
> On 11/30/26 22:57, 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 | 35
>> +++++++++++++++++++++--------------
>> drivers/gpu/drm/meson/meson_drv.c | 2 +-
>> drivers/gpu/drm/meson/meson_plane.c | 37
>> +++++++++++++++++++++++--------------
>> drivers/gpu/drm/meson/meson_plane.h | 2 +-
>> 4 files changed, 46 insertions(+), 30 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/meson/meson_crtc.c
>> b/drivers/gpu/drm/meson/meson_crtc.c
>> index 27a10508c56e..55edb8e2e1af 100644
>> --- a/drivers/gpu/drm/meson/meson_crtc.c
>> +++ b/drivers/gpu/drm/meson/meson_crtc.c
>> @@ -145,6 +145,26 @@ 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));
>
> Both can fit in a single line
>
ok i will do in v2
>> + 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 +337,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..dca295841728 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,12 @@ 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];
>> + bool afbcd;
>> /*
>> * Update Coordinates
>> @@ -269,9 +271,10 @@ static void meson_plane_atomic_update(struct
>> drm_plane *plane,
>> 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;
>> + afbcd = true;
>> else
>> - priv->viu.osd1_afbcd = false;
>> + afbcd = false;
>> + priv->viu.osd1_afbcd = afbcd;
>
> Drop this since you're rewritting it completly in patch 8, keep afbcd
> handling as-is for this patch
>
>> /* Enable OSD and BLK0, set max global alpha */
>> osd->ctrl_stat = OSD_ENABLE |
>> @@ -279,14 +282,12 @@ 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 (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;
>> @@ -310,7 +311,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,
>> @@ -385,7 +386,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;
>> @@ -429,7 +430,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 +543,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 +562,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 +584,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 */
>>
>
More information about the linux-arm-kernel
mailing list