* [PATCH 0/8] drm/meson: add a second RGB plane on G12A
@ 2026-11-30 21:57 Guillaume La Roque
2026-11-30 21:57 ` [PATCH 1/8] drm/meson: honor framebuffer offsets for the primary plane Guillaume La Roque
` (7 more replies)
0 siblings, 8 replies; 11+ messages in thread
From: Guillaume La Roque @ 2026-11-30 21:57 UTC (permalink / raw)
To: Neil Armstrong, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Kevin Hilman,
Jerome Brunet, Martin Blumenstingl
Cc: dri-devel, linux-amlogic, linux-arm-kernel, Simona Vetter,
Guillaume La Roque
VD1 only accepts YUV buffers. Add OSD2 as a second RGB plane on G12A,
G12B and SM1.
OSD2 supports linear 32-bit RGB buffers, alpha blending and clipping.
Scaling, AFBC and interlaced output are not supported.
Tested on VIM3 with modetest and atomic KMS tests: 1080p, 720p, clipping,
framebuffer offsets, alpha and enable/disable cycles. Canvas pitch limits
and devices-only suspend/resume also pass.
Based on v7.4-rc4. Built for arm64 with Clang and W=1.
---
Guillaume La Roque (8):
drm/meson: honor framebuffer offsets for the primary plane
drm/meson: isolate primary plane scaler setup
drm/meson: keep RGB scanout state per OSD
drm/meson: parameterize the G12A OSD color matrix setup
drm/meson: handle primary plane zpos allocation failure
drm/meson: select RGB plane registers by OSD index
drm/meson: serialize OSD state updates with the IRQ
drm/meson: add a linear RGB overlay on G12A OSD2
drivers/gpu/drm/meson/meson_crtc.c | 132 ++++++++---
drivers/gpu/drm/meson/meson_drv.c | 25 +-
drivers/gpu/drm/meson/meson_drv.h | 44 ++--
drivers/gpu/drm/meson/meson_osd_afbcd.c | 36 +--
drivers/gpu/drm/meson/meson_plane.c | 409 ++++++++++++++++++++------------
drivers/gpu/drm/meson/meson_plane.h | 2 +-
drivers/gpu/drm/meson/meson_registers.h | 5 +
drivers/gpu/drm/meson/meson_viu.c | 52 ++--
8 files changed, 467 insertions(+), 238 deletions(-)
---
base-commit: 8d7fe9885c62fc9a95bf55d9db244d9672a8aadc
base-tree: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
change-id: 20261124-meson-g12a-osd2-24b18a3c10c8
Best regards,
--
Guillaume La Roque <glaroque@baylibre.com>
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 1/8] drm/meson: honor framebuffer offsets for the primary plane
2026-11-30 21:57 [PATCH 0/8] drm/meson: add a second RGB plane on G12A Guillaume La Roque
@ 2026-11-30 21:57 ` Guillaume La Roque
2026-11-30 21:57 ` [PATCH 2/8] drm/meson: isolate primary plane scaler setup Guillaume La Roque
` (6 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Guillaume La Roque @ 2026-11-30 21:57 UTC (permalink / raw)
To: Neil Armstrong, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Kevin Hilman,
Jerome Brunet, Martin Blumenstingl
Cc: dri-devel, linux-amlogic, linux-arm-kernel, Simona Vetter,
Guillaume La Roque
The canvas and AFBC decoder use the GEM object address directly. Include
the framebuffer plane offset so scanout starts at the requested buffer
within the object.
Fixes: bbbe775ec5b5 ("drm: Add support for Amlogic Meson Graphic Controller")
Signed-off-by: Guillaume La Roque <glaroque@baylibre.com>
---
drivers/gpu/drm/meson/meson_plane.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/meson/meson_plane.c b/drivers/gpu/drm/meson/meson_plane.c
index 76eb8b80ad8a..639234d2f9d4 100644
--- a/drivers/gpu/drm/meson/meson_plane.c
+++ b/drivers/gpu/drm/meson/meson_plane.c
@@ -368,7 +368,7 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
/* Update Canvas with buffer address */
gem = drm_fb_dma_get_gem_obj(fb, 0);
- priv->viu.osd1_addr = gem->dma_addr;
+ priv->viu.osd1_addr = gem->dma_addr + fb->offsets[0];
priv->viu.osd1_stride = fb->pitches[0];
priv->viu.osd1_height = fb->height;
priv->viu.osd1_width = fb->width;
--
2.34.1
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/8] drm/meson: isolate primary plane scaler setup
2026-11-30 21:57 [PATCH 0/8] drm/meson: add a second RGB plane on G12A Guillaume La Roque
2026-11-30 21:57 ` [PATCH 1/8] drm/meson: honor framebuffer offsets for the primary plane Guillaume La Roque
@ 2026-11-30 21:57 ` Guillaume La Roque
2026-11-30 21:57 ` [PATCH 3/8] drm/meson: keep RGB scanout state per OSD Guillaume La Roque
` (5 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Guillaume La Roque @ 2026-11-30 21:57 UTC (permalink / raw)
To: Neil Armstrong, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Kevin Hilman,
Jerome Brunet, Martin Blumenstingl
Cc: dri-devel, linux-amlogic, linux-arm-kernel, Simona Vetter,
Guillaume La Roque
Separate the OSD1 scaler from format, buffer and geometry handling so
another RGB plane can reuse scanout setup without changing the primary
scaler state.
Keep the primary blender dimensions based on crtc_w and crtc_h,
including the existing height division for interlaced modes.
Signed-off-by: Guillaume La Roque <glaroque@baylibre.com>
---
drivers/gpu/drm/meson/meson_plane.c | 224 +++++++++++++++++++-----------------
1 file changed, 119 insertions(+), 105 deletions(-)
diff --git a/drivers/gpu/drm/meson/meson_plane.c b/drivers/gpu/drm/meson/meson_plane.c
index 639234d2f9d4..04c28289106b 100644
--- a/drivers/gpu/drm/meson/meson_plane.c
+++ b/drivers/gpu/drm/meson/meson_plane.c
@@ -131,6 +131,118 @@ static u32 meson_g12a_afbcd_line_stride(struct meson_drm *priv)
return ((line_stride + 1) >> 1) << 1;
}
+static void meson_plane_setup_scaler(struct meson_drm *priv,
+ struct drm_plane_state *new_state,
+ struct drm_rect *dest)
+{
+ int vsc_ini_rcv_num, vsc_ini_rpt_p0_num;
+ int vsc_bot_rcv_num, vsc_bot_rpt_p0_num;
+ int hsc_ini_rcv_num, hsc_ini_rpt_p0_num;
+ int hf_phase_step, vf_phase_step;
+ int src_w, src_h, dst_w, dst_h;
+ int bot_ini_phase;
+ int hf_bank_len;
+ int vf_bank_len;
+
+ /* Default scaler parameters */
+ vsc_bot_rcv_num = 0;
+ vsc_bot_rpt_p0_num = 0;
+ hf_bank_len = 4;
+ vf_bank_len = 4;
+
+ if (new_state->crtc->mode.flags & DRM_MODE_FLAG_INTERLACE) {
+ vsc_bot_rcv_num = 6;
+ vsc_bot_rpt_p0_num = 2;
+ }
+
+ hsc_ini_rcv_num = hf_bank_len;
+ vsc_ini_rcv_num = vf_bank_len;
+ hsc_ini_rpt_p0_num = (hf_bank_len / 2) - 1;
+ vsc_ini_rpt_p0_num = (vf_bank_len / 2) - 1;
+
+ src_w = fixed16_to_int(new_state->src_w);
+ src_h = fixed16_to_int(new_state->src_h);
+ dst_w = new_state->crtc_w;
+ dst_h = new_state->crtc_h;
+
+ /*
+ * When the output is interlaced, the OSD must switch between
+ * each field using the INTERLACE_SEL_ODD (0) of VIU_OSD1_BLK0_CFG_W0
+ * at each vsync.
+ * But the vertical scaler can provide such funtionnality if
+ * is configured for 2:1 scaling with interlace options enabled.
+ */
+ if (new_state->crtc->mode.flags & DRM_MODE_FLAG_INTERLACE) {
+ dest->y1 /= 2;
+ dest->y2 /= 2;
+ dst_h /= 2;
+ }
+
+ hf_phase_step = ((src_w << 18) / dst_w) << 6;
+ vf_phase_step = (src_h << 20) / dst_h;
+
+ if (new_state->crtc->mode.flags & DRM_MODE_FLAG_INTERLACE)
+ bot_ini_phase = ((vf_phase_step / 2) >> 4);
+ else
+ bot_ini_phase = 0;
+
+ vf_phase_step = (vf_phase_step << 4);
+
+ /* In interlaced mode, scaler is always active */
+ if (src_h != dst_h || src_w != dst_w) {
+ priv->viu.osd_sc_i_wh_m1 = SCI_WH_M1_W(src_w - 1) |
+ SCI_WH_M1_H(src_h - 1);
+ priv->viu.osd_sc_o_h_start_end = SCO_HV_START(dest->x1) |
+ SCO_HV_END(dest->x2 - 1);
+ priv->viu.osd_sc_o_v_start_end = SCO_HV_START(dest->y1) |
+ SCO_HV_END(dest->y2 - 1);
+ /* Enable OSD Scaler */
+ priv->viu.osd_sc_ctrl0 = SC_CTRL0_PATH_EN | SC_CTRL0_SEL_OSD1;
+ } else {
+ priv->viu.osd_sc_i_wh_m1 = 0;
+ priv->viu.osd_sc_o_h_start_end = 0;
+ priv->viu.osd_sc_o_v_start_end = 0;
+ priv->viu.osd_sc_ctrl0 = 0;
+ }
+
+ /* In interlaced mode, vertical scaler is always active */
+ if (src_h != dst_h) {
+ priv->viu.osd_sc_v_ctrl0 =
+ VSC_BANK_LEN(vf_bank_len) |
+ VSC_TOP_INI_RCV_NUM(vsc_ini_rcv_num) |
+ VSC_TOP_RPT_L0_NUM(vsc_ini_rpt_p0_num) |
+ VSC_VERTICAL_SCALER_EN;
+
+ if (new_state->crtc->mode.flags & DRM_MODE_FLAG_INTERLACE)
+ priv->viu.osd_sc_v_ctrl0 |=
+ VSC_BOT_INI_RCV_NUM(vsc_bot_rcv_num) |
+ VSC_BOT_RPT_L0_NUM(vsc_bot_rpt_p0_num) |
+ VSC_PROG_INTERLACE;
+
+ priv->viu.osd_sc_v_phase_step = SC_PHASE_STEP(vf_phase_step);
+ priv->viu.osd_sc_v_ini_phase = VSC_INI_PHASE_BOT(bot_ini_phase);
+ } else {
+ priv->viu.osd_sc_v_ctrl0 = 0;
+ priv->viu.osd_sc_v_phase_step = 0;
+ priv->viu.osd_sc_v_ini_phase = 0;
+ }
+
+ /* Horizontal scaler is only used if width does not match */
+ if (src_w != dst_w) {
+ priv->viu.osd_sc_h_ctrl0 =
+ HSC_BANK_LENGTH(hf_bank_len) |
+ HSC_INI_RCV_NUM0(hsc_ini_rcv_num) |
+ HSC_RPT_P0_NUM0(hsc_ini_rpt_p0_num) |
+ HSC_HORIZ_SCALER_EN;
+ priv->viu.osd_sc_h_phase_step = SC_PHASE_STEP(hf_phase_step);
+ priv->viu.osd_sc_h_ini_phase = 0;
+ } else {
+ priv->viu.osd_sc_h_ctrl0 = 0;
+ priv->viu.osd_sc_h_phase_step = 0;
+ priv->viu.osd_sc_h_ini_phase = 0;
+ }
+}
+
static void meson_plane_atomic_update(struct drm_plane *plane,
struct drm_atomic_commit *state)
{
@@ -142,14 +254,6 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
struct drm_framebuffer *fb = new_state->fb;
struct drm_gem_dma_object *gem;
unsigned long flags;
- int vsc_ini_rcv_num, vsc_ini_rpt_p0_num;
- int vsc_bot_rcv_num, vsc_bot_rpt_p0_num;
- int hsc_ini_rcv_num, hsc_ini_rpt_p0_num;
- int hf_phase_step, vf_phase_step;
- int src_w, src_h, dst_w, dst_h;
- int bot_ini_phase;
- int hf_bank_len;
- int vf_bank_len;
u8 canvas_id_osd1;
/*
@@ -246,103 +350,7 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
break;
}
- /* Default scaler parameters */
- vsc_bot_rcv_num = 0;
- vsc_bot_rpt_p0_num = 0;
- hf_bank_len = 4;
- vf_bank_len = 4;
-
- if (new_state->crtc->mode.flags & DRM_MODE_FLAG_INTERLACE) {
- vsc_bot_rcv_num = 6;
- vsc_bot_rpt_p0_num = 2;
- }
-
- hsc_ini_rcv_num = hf_bank_len;
- vsc_ini_rcv_num = vf_bank_len;
- hsc_ini_rpt_p0_num = (hf_bank_len / 2) - 1;
- vsc_ini_rpt_p0_num = (vf_bank_len / 2) - 1;
-
- src_w = fixed16_to_int(new_state->src_w);
- src_h = fixed16_to_int(new_state->src_h);
- dst_w = new_state->crtc_w;
- dst_h = new_state->crtc_h;
-
- /*
- * When the output is interlaced, the OSD must switch between
- * each field using the INTERLACE_SEL_ODD (0) of VIU_OSD1_BLK0_CFG_W0
- * at each vsync.
- * But the vertical scaler can provide such funtionnality if
- * is configured for 2:1 scaling with interlace options enabled.
- */
- if (new_state->crtc->mode.flags & DRM_MODE_FLAG_INTERLACE) {
- dest.y1 /= 2;
- dest.y2 /= 2;
- dst_h /= 2;
- }
-
- hf_phase_step = ((src_w << 18) / dst_w) << 6;
- vf_phase_step = (src_h << 20) / dst_h;
-
- if (new_state->crtc->mode.flags & DRM_MODE_FLAG_INTERLACE)
- bot_ini_phase = ((vf_phase_step / 2) >> 4);
- else
- bot_ini_phase = 0;
-
- vf_phase_step = (vf_phase_step << 4);
-
- /* In interlaced mode, scaler is always active */
- if (src_h != dst_h || src_w != dst_w) {
- priv->viu.osd_sc_i_wh_m1 = SCI_WH_M1_W(src_w - 1) |
- SCI_WH_M1_H(src_h - 1);
- priv->viu.osd_sc_o_h_start_end = SCO_HV_START(dest.x1) |
- SCO_HV_END(dest.x2 - 1);
- priv->viu.osd_sc_o_v_start_end = SCO_HV_START(dest.y1) |
- SCO_HV_END(dest.y2 - 1);
- /* Enable OSD Scaler */
- priv->viu.osd_sc_ctrl0 = SC_CTRL0_PATH_EN | SC_CTRL0_SEL_OSD1;
- } else {
- priv->viu.osd_sc_i_wh_m1 = 0;
- priv->viu.osd_sc_o_h_start_end = 0;
- priv->viu.osd_sc_o_v_start_end = 0;
- priv->viu.osd_sc_ctrl0 = 0;
- }
-
- /* In interlaced mode, vertical scaler is always active */
- if (src_h != dst_h) {
- priv->viu.osd_sc_v_ctrl0 =
- VSC_BANK_LEN(vf_bank_len) |
- VSC_TOP_INI_RCV_NUM(vsc_ini_rcv_num) |
- VSC_TOP_RPT_L0_NUM(vsc_ini_rpt_p0_num) |
- VSC_VERTICAL_SCALER_EN;
-
- if (new_state->crtc->mode.flags & DRM_MODE_FLAG_INTERLACE)
- priv->viu.osd_sc_v_ctrl0 |=
- VSC_BOT_INI_RCV_NUM(vsc_bot_rcv_num) |
- VSC_BOT_RPT_L0_NUM(vsc_bot_rpt_p0_num) |
- VSC_PROG_INTERLACE;
-
- priv->viu.osd_sc_v_phase_step = SC_PHASE_STEP(vf_phase_step);
- priv->viu.osd_sc_v_ini_phase = VSC_INI_PHASE_BOT(bot_ini_phase);
- } else {
- priv->viu.osd_sc_v_ctrl0 = 0;
- priv->viu.osd_sc_v_phase_step = 0;
- priv->viu.osd_sc_v_ini_phase = 0;
- }
-
- /* Horizontal scaler is only used if width does not match */
- if (src_w != dst_w) {
- priv->viu.osd_sc_h_ctrl0 =
- HSC_BANK_LENGTH(hf_bank_len) |
- HSC_INI_RCV_NUM0(hsc_ini_rcv_num) |
- HSC_RPT_P0_NUM0(hsc_ini_rpt_p0_num) |
- HSC_HORIZ_SCALER_EN;
- priv->viu.osd_sc_h_phase_step = SC_PHASE_STEP(hf_phase_step);
- priv->viu.osd_sc_h_ini_phase = 0;
- } else {
- priv->viu.osd_sc_h_ctrl0 = 0;
- priv->viu.osd_sc_h_phase_step = 0;
- priv->viu.osd_sc_h_ini_phase = 0;
- }
+ meson_plane_setup_scaler(priv, new_state, &dest);
/*
* The format of these registers is (x2 << 16 | x1),
@@ -359,6 +367,12 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
priv->viu.osd1_blk0_cfg[4] = ((dest.y2 - 1) << 16) | dest.y1;
if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
+ int dst_w = new_state->crtc_w;
+ int dst_h = new_state->crtc_h;
+
+ if (new_state->crtc->mode.flags & DRM_MODE_FLAG_INTERLACE)
+ dst_h /= 2;
+
priv->viu.osd_blend_din0_scope_h = ((dest.x2 - 1) << 16) | dest.x1;
priv->viu.osd_blend_din0_scope_v = ((dest.y2 - 1) << 16) | dest.y1;
priv->viu.osb_blend0_size = dst_h << 16 | dst_w;
--
2.34.1
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 3/8] drm/meson: keep RGB scanout state per OSD
2026-11-30 21:57 [PATCH 0/8] drm/meson: add a second RGB plane on G12A Guillaume La Roque
2026-11-30 21:57 ` [PATCH 1/8] drm/meson: honor framebuffer offsets for the primary plane Guillaume La Roque
2026-11-30 21:57 ` [PATCH 2/8] drm/meson: isolate primary plane scaler setup Guillaume La Roque
@ 2026-11-30 21:57 ` Guillaume La Roque
2026-11-30 21:57 ` [PATCH 4/8] drm/meson: parameterize the G12A OSD color matrix setup Guillaume La Roque
` (4 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Guillaume La Roque @ 2026-11-30 21:57 UTC (permalink / raw)
To: Neil Armstrong, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Kevin Hilman,
Jerome Brunet, Martin Blumenstingl
Cc: dri-devel, linux-amlogic, linux-arm-kernel, Simona Vetter,
Guillaume La Roque
Group the register cache and framebuffer parameters per RGB plane. Keep
the primary scaler and AFBC controls separate so each OSD can own its
scanout state.
Signed-off-by: Guillaume La Roque <glaroque@baylibre.com>
---
drivers/gpu/drm/meson/meson_crtc.c | 58 ++++++++++++++--------------
drivers/gpu/drm/meson/meson_drv.c | 6 +--
drivers/gpu/drm/meson/meson_drv.h | 42 +++++++++++++-------
drivers/gpu/drm/meson/meson_osd_afbcd.c | 36 ++++++++---------
drivers/gpu/drm/meson/meson_plane.c | 68 ++++++++++++++++-----------------
drivers/gpu/drm/meson/meson_viu.c | 4 +-
6 files changed, 113 insertions(+), 101 deletions(-)
diff --git a/drivers/gpu/drm/meson/meson_crtc.c b/drivers/gpu/drm/meson/meson_crtc.c
index d1317ddcdfab..27a10508c56e 100644
--- a/drivers/gpu/drm/meson/meson_crtc.c
+++ b/drivers/gpu/drm/meson/meson_crtc.c
@@ -155,8 +155,8 @@ static void meson_g12a_crtc_atomic_disable(struct drm_crtc *crtc,
drm_crtc_vblank_off(crtc);
- priv->viu.osd1_enabled = false;
- priv->viu.osd1_commit = false;
+ priv->viu.osd[0].enabled = false;
+ priv->viu.osd[0].commit = false;
priv->viu.vd1_enabled = false;
priv->viu.vd1_commit = false;
@@ -180,8 +180,8 @@ static void meson_crtc_atomic_disable(struct drm_crtc *crtc,
drm_crtc_vblank_off(crtc);
- priv->viu.osd1_enabled = false;
- priv->viu.osd1_commit = false;
+ priv->viu.osd[0].enabled = false;
+ priv->viu.osd[0].commit = false;
priv->viu.vd1_enabled = false;
priv->viu.vd1_commit = false;
@@ -222,7 +222,7 @@ static void meson_crtc_atomic_flush(struct drm_crtc *crtc,
struct meson_crtc *meson_crtc = to_meson_crtc(crtc);
struct meson_drm *priv = meson_crtc->priv;
- priv->viu.osd1_commit = true;
+ priv->viu.osd[0].commit = true;
priv->viu.vd1_commit = true;
}
@@ -268,16 +268,16 @@ static void meson_crtc_g12a_enable_osd1_afbc(struct meson_drm *priv)
static void meson_g12a_crtc_enable_osd1(struct meson_drm *priv)
{
- writel_relaxed(priv->viu.osd_blend_din0_scope_h,
+ writel_relaxed(priv->viu.osd[0].blk0_cfg[3],
priv->io_base +
_REG(VIU_OSD_BLEND_DIN0_SCOPE_H));
- writel_relaxed(priv->viu.osd_blend_din0_scope_v,
+ writel_relaxed(priv->viu.osd[0].blk0_cfg[4],
priv->io_base +
_REG(VIU_OSD_BLEND_DIN0_SCOPE_V));
- writel_relaxed(priv->viu.osb_blend0_size,
+ writel_relaxed(priv->viu.osd[0].blend_size,
priv->io_base +
_REG(VIU_OSD_BLEND_BLEND0_SIZE));
- writel_relaxed(priv->viu.osb_blend1_size,
+ writel_relaxed(priv->viu.osd[0].blend_size,
priv->io_base +
_REG(VIU_OSD_BLEND_BLEND1_SIZE));
writel_bits_relaxed(3 << 8, 3 << 8,
@@ -316,21 +316,21 @@ void meson_crtc_irq(struct meson_drm *priv)
unsigned long flags;
/* Update the OSD registers */
- if (priv->viu.osd1_enabled && priv->viu.osd1_commit) {
- writel_relaxed(priv->viu.osd1_ctrl_stat,
- priv->io_base + _REG(VIU_OSD1_CTRL_STAT));
- writel_relaxed(priv->viu.osd1_ctrl_stat2,
- priv->io_base + _REG(VIU_OSD1_CTRL_STAT2));
- writel_relaxed(priv->viu.osd1_blk0_cfg[0],
- priv->io_base + _REG(VIU_OSD1_BLK0_CFG_W0));
- writel_relaxed(priv->viu.osd1_blk0_cfg[1],
- priv->io_base + _REG(VIU_OSD1_BLK0_CFG_W1));
- writel_relaxed(priv->viu.osd1_blk0_cfg[2],
- priv->io_base + _REG(VIU_OSD1_BLK0_CFG_W2));
- writel_relaxed(priv->viu.osd1_blk0_cfg[3],
- priv->io_base + _REG(VIU_OSD1_BLK0_CFG_W3));
- writel_relaxed(priv->viu.osd1_blk0_cfg[4],
- priv->io_base + _REG(VIU_OSD1_BLK0_CFG_W4));
+ 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));
if (priv->viu.osd1_afbcd) {
if (meson_crtc->enable_osd1_afbc)
@@ -367,10 +367,10 @@ void meson_crtc_irq(struct meson_drm *priv)
priv->io_base + _REG(VPP_OSD_VSC_CTRL0));
if (!priv->viu.osd1_afbcd)
- meson_canvas_config(priv->canvas, priv->canvas_id_osd1,
- priv->viu.osd1_addr,
- priv->viu.osd1_stride,
- priv->viu.osd1_height,
+ meson_canvas_config(priv->canvas, priv->canvas_id_osd[0],
+ priv->viu.osd[0].addr,
+ priv->viu.osd[0].stride,
+ priv->viu.osd[0].height,
MESON_CANVAS_WRAP_NONE,
MESON_CANVAS_BLKMODE_LINEAR, 0);
@@ -385,7 +385,7 @@ void meson_crtc_irq(struct meson_drm *priv)
meson_crtc->vsync_forced = true;
}
- priv->viu.osd1_commit = false;
+ priv->viu.osd[0].commit = false;
}
/* Update the VD1 registers */
diff --git a/drivers/gpu/drm/meson/meson_drv.c b/drivers/gpu/drm/meson/meson_drv.c
index 38bf2811d068..94d100d8963c 100644
--- a/drivers/gpu/drm/meson/meson_drv.c
+++ b/drivers/gpu/drm/meson/meson_drv.c
@@ -247,7 +247,7 @@ static int meson_drv_bind_master(struct device *dev, bool has_components)
goto free_drm;
}
- ret = meson_canvas_alloc(priv->canvas, &priv->canvas_id_osd1);
+ ret = meson_canvas_alloc(priv->canvas, &priv->canvas_id_osd[0]);
if (ret)
goto free_drm;
ret = meson_canvas_alloc(priv->canvas, &priv->canvas_id_vd1_0);
@@ -370,7 +370,7 @@ static int meson_drv_bind_master(struct device *dev, bool has_components)
free_canvas_vd1_0:
meson_canvas_free(priv->canvas, priv->canvas_id_vd1_0);
free_canvas_osd1:
- meson_canvas_free(priv->canvas, priv->canvas_id_osd1);
+ meson_canvas_free(priv->canvas, priv->canvas_id_osd[0]);
free_drm:
drm_dev_put(drm);
@@ -395,7 +395,7 @@ static void meson_drv_unbind(struct device *dev)
struct drm_device *drm = priv->drm;
if (priv->canvas) {
- meson_canvas_free(priv->canvas, priv->canvas_id_osd1);
+ meson_canvas_free(priv->canvas, priv->canvas_id_osd[0]);
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 be4b0e4df6e1..77a5c5e792e9 100644
--- a/drivers/gpu/drm/meson/meson_drv.h
+++ b/drivers/gpu/drm/meson/meson_drv.h
@@ -40,6 +40,32 @@ struct meson_drm_soc_limits {
unsigned long long max_hdmi_phy_freq;
};
+/**
+ * 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
+ * @ctrl_stat: OSD control and global alpha
+ * @ctrl_stat2: Pixel alpha replacement control
+ * @blk0_cfg: Format and source/destination rectangles
+ * @addr: Framebuffer DMA address, including its plane offset
+ * @stride: Framebuffer pitch in bytes
+ * @height: Framebuffer height in pixels
+ * @width: Framebuffer width in pixels
+ * @blend_size: OSD blender input size
+ */
+struct meson_osd_state {
+ bool enabled;
+ bool commit;
+ u32 ctrl_stat;
+ u32 ctrl_stat2;
+ u32 blk0_cfg[5];
+ u32 addr;
+ u32 stride;
+ u32 height;
+ u32 width;
+ u32 blend_size;
+};
+
struct meson_drm {
struct device *dev;
enum vpu_compatible compat;
@@ -48,7 +74,7 @@ struct meson_drm {
int vsync_irq;
struct meson_canvas *canvas;
- u8 canvas_id_osd1;
+ u8 canvas_id_osd[2];
u8 canvas_id_vd1_0;
u8 canvas_id_vd1_1;
u8 canvas_id_vd1_2;
@@ -63,19 +89,11 @@ struct meson_drm {
/* Components Data */
struct {
- bool osd1_enabled;
+ struct meson_osd_state osd[2];
bool osd1_interlace;
- bool osd1_commit;
bool osd1_afbcd;
- uint32_t osd1_ctrl_stat;
- uint32_t osd1_ctrl_stat2;
- uint32_t osd1_blk0_cfg[5];
uint32_t osd1_blk1_cfg4;
uint32_t osd1_blk2_cfg4;
- uint32_t osd1_addr;
- uint32_t osd1_stride;
- uint32_t osd1_height;
- uint32_t osd1_width;
uint32_t osd_sc_ctrl0;
uint32_t osd_sc_i_wh_m1;
uint32_t osd_sc_o_h_start_end;
@@ -86,10 +104,6 @@ struct meson_drm {
uint32_t osd_sc_h_phase_step;
uint32_t osd_sc_h_ctrl0;
uint32_t osd_sc_v_ctrl0;
- uint32_t osd_blend_din0_scope_h;
- uint32_t osd_blend_din0_scope_v;
- uint32_t osb_blend0_size;
- uint32_t osb_blend1_size;
bool vd1_enabled;
bool vd1_commit;
diff --git a/drivers/gpu/drm/meson/meson_osd_afbcd.c b/drivers/gpu/drm/meson/meson_osd_afbcd.c
index 0cdbe899402f..8f6e9bb73a30 100644
--- a/drivers/gpu/drm/meson/meson_osd_afbcd.c
+++ b/drivers/gpu/drm/meson/meson_osd_afbcd.c
@@ -133,28 +133,28 @@ static int meson_gxm_afbcd_setup(struct meson_drm *priv)
writel_relaxed(mode, priv->io_base + _REG(OSD1_AFBCD_MODE));
writel_relaxed(FIELD_PREP(OSD1_AFBCD_HREG_VSIZE_IN,
- priv->viu.osd1_width) |
+ priv->viu.osd[0].width) |
FIELD_PREP(OSD1_AFBCD_HREG_HSIZE_IN,
- priv->viu.osd1_height),
+ priv->viu.osd[0].height),
priv->io_base + _REG(OSD1_AFBCD_SIZE_IN));
- writel_relaxed(priv->viu.osd1_addr >> 4,
+ writel_relaxed(priv->viu.osd[0].addr >> 4,
priv->io_base + _REG(OSD1_AFBCD_HDR_PTR));
- writel_relaxed(priv->viu.osd1_addr >> 4,
+ writel_relaxed(priv->viu.osd[0].addr >> 4,
priv->io_base + _REG(OSD1_AFBCD_FRAME_PTR));
/* TOFIX: bits 31:24 are not documented, nor the meaning of 0xe4 */
- writel_relaxed((0xe4 << 24) | (priv->viu.osd1_addr & 0xffffff),
+ writel_relaxed((0xe4 << 24) | (priv->viu.osd[0].addr & 0xffffff),
priv->io_base + _REG(OSD1_AFBCD_CHROMA_PTR));
- if (priv->viu.osd1_width <= 128)
+ if (priv->viu.osd[0].width <= 128)
conv_lbuf_len = 32;
- else if (priv->viu.osd1_width <= 256)
+ else if (priv->viu.osd[0].width <= 256)
conv_lbuf_len = 64;
- else if (priv->viu.osd1_width <= 512)
+ else if (priv->viu.osd[0].width <= 512)
conv_lbuf_len = 128;
- else if (priv->viu.osd1_width <= 1024)
+ else if (priv->viu.osd[0].width <= 1024)
conv_lbuf_len = 256;
- else if (priv->viu.osd1_width <= 2048)
+ else if (priv->viu.osd[0].width <= 2048)
conv_lbuf_len = 512;
else
conv_lbuf_len = 1024;
@@ -164,12 +164,12 @@ static int meson_gxm_afbcd_setup(struct meson_drm *priv)
writel_relaxed(FIELD_PREP(OSD1_AFBCD_DEC_PIXEL_BGN_H, 0) |
FIELD_PREP(OSD1_AFBCD_DEC_PIXEL_END_H,
- priv->viu.osd1_width - 1),
+ priv->viu.osd[0].width - 1),
priv->io_base + _REG(OSD1_AFBCD_PIXEL_HSCOPE));
writel_relaxed(FIELD_PREP(OSD1_AFBCD_DEC_PIXEL_BGN_V, 0) |
FIELD_PREP(OSD1_AFBCD_DEC_PIXEL_END_V,
- priv->viu.osd1_height - 1),
+ priv->viu.osd[0].height - 1),
priv->io_base + _REG(OSD1_AFBCD_PIXEL_VSCOPE));
return 0;
@@ -359,23 +359,23 @@ static int meson_g12a_afbcd_setup(struct meson_drm *priv)
meson_rdma_writel_sync(priv, format,
VPU_MAFBC_FORMAT_SPECIFIER_S0);
- meson_rdma_writel_sync(priv, priv->viu.osd1_addr,
+ meson_rdma_writel_sync(priv, priv->viu.osd[0].addr,
VPU_MAFBC_HEADER_BUF_ADDR_LOW_S0);
meson_rdma_writel_sync(priv, 0,
VPU_MAFBC_HEADER_BUF_ADDR_HIGH_S0);
- meson_rdma_writel_sync(priv, priv->viu.osd1_width,
+ meson_rdma_writel_sync(priv, priv->viu.osd[0].width,
VPU_MAFBC_BUFFER_WIDTH_S0);
- meson_rdma_writel_sync(priv, ALIGN(priv->viu.osd1_height, 32),
+ meson_rdma_writel_sync(priv, ALIGN(priv->viu.osd[0].height, 32),
VPU_MAFBC_BUFFER_HEIGHT_S0);
meson_rdma_writel_sync(priv, 0,
VPU_MAFBC_BOUNDING_BOX_X_START_S0);
- meson_rdma_writel_sync(priv, priv->viu.osd1_width - 1,
+ meson_rdma_writel_sync(priv, priv->viu.osd[0].width - 1,
VPU_MAFBC_BOUNDING_BOX_X_END_S0);
meson_rdma_writel_sync(priv, 0,
VPU_MAFBC_BOUNDING_BOX_Y_START_S0);
- meson_rdma_writel_sync(priv, priv->viu.osd1_height - 1,
+ meson_rdma_writel_sync(priv, priv->viu.osd[0].height - 1,
VPU_MAFBC_BOUNDING_BOX_Y_END_S0);
meson_rdma_writel_sync(priv, MESON_G12A_AFBCD_OUT_ADDR,
@@ -383,7 +383,7 @@ static int meson_g12a_afbcd_setup(struct meson_drm *priv)
meson_rdma_writel_sync(priv, 0,
VPU_MAFBC_OUTPUT_BUF_ADDR_HIGH_S0);
- meson_rdma_writel_sync(priv, priv->viu.osd1_width *
+ meson_rdma_writel_sync(priv, priv->viu.osd[0].width *
(meson_g12a_afbcd_bpp(priv->afbcd.format) / 8),
VPU_MAFBC_OUTPUT_BUF_STRIDE_S0);
diff --git a/drivers/gpu/drm/meson/meson_plane.c b/drivers/gpu/drm/meson/meson_plane.c
index 04c28289106b..3c73fd678fb2 100644
--- a/drivers/gpu/drm/meson/meson_plane.c
+++ b/drivers/gpu/drm/meson/meson_plane.c
@@ -117,14 +117,14 @@ static u32 meson_g12a_afbcd_line_stride(struct meson_drm *priv)
switch (priv->afbcd.format) {
case DRM_FORMAT_RGB565:
- line_stride = ((priv->viu.osd1_width << 4) + 127) >> 7;
+ line_stride = ((priv->viu.osd[0].width << 4) + 127) >> 7;
break;
case DRM_FORMAT_RGB888:
case DRM_FORMAT_XRGB8888:
case DRM_FORMAT_ARGB8888:
case DRM_FORMAT_XBGR8888:
case DRM_FORMAT_ABGR8888:
- line_stride = ((priv->viu.osd1_width << 5) + 127) >> 7;
+ line_stride = ((priv->viu.osd[0].width << 5) + 127) >> 7;
break;
}
@@ -251,6 +251,7 @@ 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;
@@ -273,65 +274,65 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
priv->viu.osd1_afbcd = false;
/* Enable OSD and BLK0, set max global alpha */
- priv->viu.osd1_ctrl_stat = OSD_ENABLE |
+ osd->ctrl_stat = OSD_ENABLE |
(0x100 << OSD_GLOBAL_ALPHA_SHIFT) |
OSD_BLK0_ENABLE;
- priv->viu.osd1_ctrl_stat2 = readl(priv->io_base +
+ osd->ctrl_stat2 = readl(priv->io_base +
_REG(VIU_OSD1_CTRL_STAT2));
- canvas_id_osd1 = priv->canvas_id_osd1;
+ canvas_id_osd1 = priv->canvas_id_osd[0];
/* Set up BLK0 to point to the right canvas */
- priv->viu.osd1_blk0_cfg[0] = canvas_id_osd1 << OSD_CANVAS_SEL;
+ osd->blk0_cfg[0] = canvas_id_osd1 << OSD_CANVAS_SEL;
if (priv->viu.osd1_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;
- priv->viu.osd1_blk0_cfg[0] |= OSD_ENDIANNESS_BE;
- priv->viu.osd1_ctrl_stat2 |= OSD_PENDING_STAT_CLEAN;
- priv->viu.osd1_ctrl_stat |= VIU_OSD1_CFG_SYN_EN;
+ osd->blk0_cfg[0] |= OSD_ENDIANNESS_BE;
+ osd->ctrl_stat2 |= OSD_PENDING_STAT_CLEAN;
+ osd->ctrl_stat |= VIU_OSD1_CFG_SYN_EN;
}
if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM)) {
- priv->viu.osd1_blk0_cfg[0] |= OSD_ENDIANNESS_LE;
- priv->viu.osd1_ctrl_stat2 |= OSD_DPATH_MALI_AFBCD;
+ osd->blk0_cfg[0] |= OSD_ENDIANNESS_LE;
+ osd->ctrl_stat2 |= OSD_DPATH_MALI_AFBCD;
}
} else {
- priv->viu.osd1_blk0_cfg[0] |= OSD_ENDIANNESS_LE;
+ osd->blk0_cfg[0] |= OSD_ENDIANNESS_LE;
if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM))
- priv->viu.osd1_ctrl_stat2 &= ~OSD_DPATH_MALI_AFBCD;
+ osd->ctrl_stat2 &= ~OSD_DPATH_MALI_AFBCD;
}
/* On GXBB, Use the old non-HDR RGB2YUV converter */
if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXBB))
- priv->viu.osd1_blk0_cfg[0] |= OSD_OUTPUT_COLOR_RGB;
+ osd->blk0_cfg[0] |= OSD_OUTPUT_COLOR_RGB;
if (priv->viu.osd1_afbcd &&
meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
- priv->viu.osd1_blk0_cfg[0] |= OSD_MALI_SRC_EN |
+ osd->blk0_cfg[0] |= OSD_MALI_SRC_EN |
priv->afbcd.ops->fmt_to_blk_mode(fb->modifier,
fb->format->format);
} else {
switch (fb->format->format) {
case DRM_FORMAT_XRGB8888:
case DRM_FORMAT_ARGB8888:
- priv->viu.osd1_blk0_cfg[0] |= OSD_BLK_MODE_32 |
+ osd->blk0_cfg[0] |= OSD_BLK_MODE_32 |
OSD_COLOR_MATRIX_32_ARGB;
break;
case DRM_FORMAT_XBGR8888:
case DRM_FORMAT_ABGR8888:
- priv->viu.osd1_blk0_cfg[0] |= OSD_BLK_MODE_32 |
+ osd->blk0_cfg[0] |= OSD_BLK_MODE_32 |
OSD_COLOR_MATRIX_32_ABGR;
break;
case DRM_FORMAT_RGB888:
- priv->viu.osd1_blk0_cfg[0] |= OSD_BLK_MODE_24 |
+ osd->blk0_cfg[0] |= OSD_BLK_MODE_24 |
OSD_COLOR_MATRIX_24_RGB;
break;
case DRM_FORMAT_RGB565:
- priv->viu.osd1_blk0_cfg[0] |= OSD_BLK_MODE_16 |
+ osd->blk0_cfg[0] |= OSD_BLK_MODE_16 |
OSD_COLOR_MATRIX_16_RGB565;
break;
}
@@ -341,12 +342,12 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
case DRM_FORMAT_XRGB8888:
case DRM_FORMAT_XBGR8888:
/* For XRGB, replace the pixel's alpha by 0xFF */
- priv->viu.osd1_ctrl_stat2 |= OSD_REPLACE_EN;
+ osd->ctrl_stat2 |= OSD_REPLACE_EN;
break;
case DRM_FORMAT_ARGB8888:
case DRM_FORMAT_ABGR8888:
/* For ARGB, use the pixel's alpha */
- priv->viu.osd1_ctrl_stat2 &= ~OSD_REPLACE_EN;
+ osd->ctrl_stat2 &= ~OSD_REPLACE_EN;
break;
}
@@ -357,14 +358,14 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
* where x2 is exclusive.
* e.g. +30x1920 would be (1919 << 16) | 30
*/
- priv->viu.osd1_blk0_cfg[1] =
+ osd->blk0_cfg[1] =
((fixed16_to_int(new_state->src.x2) - 1) << 16) |
fixed16_to_int(new_state->src.x1);
- priv->viu.osd1_blk0_cfg[2] =
+ osd->blk0_cfg[2] =
((fixed16_to_int(new_state->src.y2) - 1) << 16) |
fixed16_to_int(new_state->src.y1);
- priv->viu.osd1_blk0_cfg[3] = ((dest.x2 - 1) << 16) | dest.x1;
- priv->viu.osd1_blk0_cfg[4] = ((dest.y2 - 1) << 16) | dest.y1;
+ osd->blk0_cfg[3] = ((dest.x2 - 1) << 16) | dest.x1;
+ osd->blk0_cfg[4] = ((dest.y2 - 1) << 16) | dest.y1;
if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
int dst_w = new_state->crtc_w;
@@ -373,19 +374,16 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
if (new_state->crtc->mode.flags & DRM_MODE_FLAG_INTERLACE)
dst_h /= 2;
- priv->viu.osd_blend_din0_scope_h = ((dest.x2 - 1) << 16) | dest.x1;
- priv->viu.osd_blend_din0_scope_v = ((dest.y2 - 1) << 16) | dest.y1;
- priv->viu.osb_blend0_size = dst_h << 16 | dst_w;
- priv->viu.osb_blend1_size = dst_h << 16 | dst_w;
+ osd->blend_size = dst_h << 16 | dst_w;
}
/* Update Canvas with buffer address */
gem = drm_fb_dma_get_gem_obj(fb, 0);
- priv->viu.osd1_addr = gem->dma_addr + fb->offsets[0];
- priv->viu.osd1_stride = fb->pitches[0];
- priv->viu.osd1_height = fb->height;
- priv->viu.osd1_width = fb->width;
+ osd->addr = gem->dma_addr + fb->offsets[0];
+ osd->stride = fb->pitches[0];
+ osd->height = fb->height;
+ osd->width = fb->width;
if (priv->viu.osd1_afbcd) {
priv->afbcd.modifier = fb->modifier;
@@ -406,7 +404,7 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
meson_plane->enabled = true;
}
- priv->viu.osd1_enabled = true;
+ osd->enabled = true;
spin_unlock_irqrestore(&priv->drm->event_lock, flags);
}
@@ -431,7 +429,7 @@ static void meson_plane_atomic_disable(struct drm_plane *plane,
priv->io_base + _REG(VPP_MISC));
meson_plane->enabled = false;
- priv->viu.osd1_enabled = false;
+ priv->viu.osd[0].enabled = false;
}
static const struct drm_plane_helper_funcs meson_plane_helper_funcs = {
diff --git a/drivers/gpu/drm/meson/meson_viu.c b/drivers/gpu/drm/meson/meson_viu.c
index cd399b0b7181..2716d970fe8c 100644
--- a/drivers/gpu/drm/meson/meson_viu.c
+++ b/drivers/gpu/drm/meson/meson_viu.c
@@ -500,7 +500,7 @@ void meson_viu_init(struct meson_drm *priv)
if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM))
meson_viu_gxm_disable_osd1_afbc(priv);
- priv->viu.osd1_enabled = false;
- priv->viu.osd1_commit = false;
+ priv->viu.osd[0].enabled = false;
+ priv->viu.osd[0].commit = false;
priv->viu.osd1_interlace = false;
}
--
2.34.1
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 4/8] drm/meson: parameterize the G12A OSD color matrix setup
2026-11-30 21:57 [PATCH 0/8] drm/meson: add a second RGB plane on G12A Guillaume La Roque
` (2 preceding siblings ...)
2026-11-30 21:57 ` [PATCH 3/8] drm/meson: keep RGB scanout state per OSD Guillaume La Roque
@ 2026-11-30 21:57 ` Guillaume La Roque
2026-11-30 21:57 ` [PATCH 5/8] drm/meson: handle primary plane zpos allocation failure Guillaume La Roque
` (3 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Guillaume La Roque @ 2026-11-30 21:57 UTC (permalink / raw)
To: Neil Armstrong, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Kevin Hilman,
Jerome Brunet, Martin Blumenstingl
Cc: dri-devel, linux-amlogic, linux-arm-kernel, Simona Vetter,
Guillaume La Roque
The OSD wrap matrices have the same register layout at different bases.
Select the base by OSD index so both RGB planes can share the CSC setup.
Signed-off-by: Guillaume La Roque <glaroque@baylibre.com>
---
drivers/gpu/drm/meson/meson_viu.c | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/drivers/gpu/drm/meson/meson_viu.c b/drivers/gpu/drm/meson/meson_viu.c
index 2716d970fe8c..eb6a6f44cb2d 100644
--- a/drivers/gpu/drm/meson/meson_viu.c
+++ b/drivers/gpu/drm/meson/meson_viu.c
@@ -78,32 +78,33 @@ static int eotf_bypass_coeff[EOTF_COEFF_SIZE] = {
EOTF_COEFF_RIGHTSHIFT /* right shift */
};
-static void meson_viu_set_g12a_osd1_matrix(struct meson_drm *priv,
- int *m, bool csc_on)
+static void meson_viu_set_g12a_osd_matrix(struct meson_drm *priv,
+ unsigned int index, int *m)
{
- /* VPP WRAP OSD1 matrix */
+ u32 offset = index * (VPP_WRAP_OSD2_MATRIX_COEF00_01 -
+ VPP_WRAP_OSD1_MATRIX_COEF00_01);
writel(((m[0] & 0xfff) << 16) | (m[1] & 0xfff),
- priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_PRE_OFFSET0_1));
+ priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_PRE_OFFSET0_1 + offset));
writel(m[2] & 0xfff,
- priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_PRE_OFFSET2));
+ priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_PRE_OFFSET2 + offset));
writel(((m[3] & 0x1fff) << 16) | (m[4] & 0x1fff),
- priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_COEF00_01));
+ priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_COEF00_01 + offset));
writel(((m[5] & 0x1fff) << 16) | (m[6] & 0x1fff),
- priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_COEF02_10));
+ priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_COEF02_10 + offset));
writel(((m[7] & 0x1fff) << 16) | (m[8] & 0x1fff),
- priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_COEF11_12));
+ priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_COEF11_12 + offset));
writel(((m[9] & 0x1fff) << 16) | (m[10] & 0x1fff),
- priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_COEF20_21));
+ priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_COEF20_21 + offset));
writel((m[11] & 0x1fff),
- priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_COEF22));
+ priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_COEF22 + offset));
writel(((m[18] & 0xfff) << 16) | (m[19] & 0xfff),
- priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_OFFSET0_1));
+ priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_OFFSET0_1 + offset));
writel(m[20] & 0xfff,
- priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_OFFSET2));
+ priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_OFFSET2 + offset));
- writel_bits_relaxed(BIT(0), csc_on ? BIT(0) : 0,
- priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_EN_CTRL));
+ writel_bits_relaxed(BIT(0), BIT(0),
+ priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_EN_CTRL + offset));
}
static void meson_viu_set_osd_matrix(struct meson_drm *priv,
@@ -426,8 +427,7 @@ void meson_viu_init(struct meson_drm *priv)
meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXL))
meson_viu_load_matrix(priv);
else if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
- meson_viu_set_g12a_osd1_matrix(priv, RGB709_to_YUV709l_coeff,
- true);
+ meson_viu_set_g12a_osd_matrix(priv, 0, 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,
--
2.34.1
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 5/8] drm/meson: handle primary plane zpos allocation failure
2026-11-30 21:57 [PATCH 0/8] drm/meson: add a second RGB plane on G12A Guillaume La Roque
` (3 preceding siblings ...)
2026-11-30 21:57 ` [PATCH 4/8] drm/meson: parameterize the G12A OSD color matrix setup Guillaume La Roque
@ 2026-11-30 21:57 ` Guillaume La Roque
2026-11-30 21:57 ` [PATCH 6/8] drm/meson: select RGB plane registers by OSD index Guillaume La Roque
` (2 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Guillaume La Roque @ 2026-11-30 21:57 UTC (permalink / raw)
To: Neil Armstrong, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Kevin Hilman,
Jerome Brunet, Martin Blumenstingl
Cc: dri-devel, linux-amlogic, linux-arm-kernel, Simona Vetter,
Guillaume La Roque
Return the allocation error and clean up the primary plane if its zpos
property cannot be created. Otherwise probe succeeds without the property
that describes the plane's fixed stacking order.
Fixes: fd311d880c76 ("drm/meson: Add zpos immutable property to planes")
Signed-off-by: Guillaume La Roque <glaroque@baylibre.com>
---
drivers/gpu/drm/meson/meson_plane.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/meson/meson_plane.c b/drivers/gpu/drm/meson/meson_plane.c
index 3c73fd678fb2..1c65aedd3926 100644
--- a/drivers/gpu/drm/meson/meson_plane.c
+++ b/drivers/gpu/drm/meson/meson_plane.c
@@ -575,7 +575,11 @@ 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 */
- drm_plane_create_zpos_immutable_property(plane, 1);
+ ret = drm_plane_create_zpos_immutable_property(plane, 1);
+ if (ret) {
+ drm_plane_cleanup(plane);
+ return ret;
+ }
priv->primary_plane = plane;
--
2.34.1
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 6/8] drm/meson: select RGB plane registers by OSD index
2026-11-30 21:57 [PATCH 0/8] drm/meson: add a second RGB plane on G12A Guillaume La Roque
` (4 preceding siblings ...)
2026-11-30 21:57 ` [PATCH 5/8] drm/meson: handle primary plane zpos allocation failure Guillaume La Roque
@ 2026-11-30 21:57 ` Guillaume La Roque
2026-11-30 21:57 ` [PATCH 7/8] drm/meson: serialize OSD state updates with the IRQ Guillaume La Roque
2026-11-30 21:57 ` [PATCH 8/8] drm/meson: add a linear RGB overlay on G12A OSD2 Guillaume La Roque
7 siblings, 0 replies; 11+ messages in thread
From: Guillaume La Roque @ 2026-11-30 21:57 UTC (permalink / raw)
To: Neil Armstrong, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Kevin Hilman,
Jerome Brunet, Martin Blumenstingl
Cc: dri-devel, linux-amlogic, linux-arm-kernel, Simona Vetter,
Guillaume La Roque
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@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));
+ 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;
/* 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 */
--
2.34.1
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 7/8] drm/meson: serialize OSD state updates with the IRQ
2026-11-30 21:57 [PATCH 0/8] drm/meson: add a second RGB plane on G12A Guillaume La Roque
` (5 preceding siblings ...)
2026-11-30 21:57 ` [PATCH 6/8] drm/meson: select RGB plane registers by OSD index Guillaume La Roque
@ 2026-11-30 21:57 ` Guillaume La Roque
2026-11-30 22:14 ` sashiko-bot
2026-11-30 21:57 ` [PATCH 8/8] drm/meson: add a linear RGB overlay on G12A OSD2 Guillaume La Roque
7 siblings, 1 reply; 11+ messages in thread
From: Guillaume La Roque @ 2026-11-30 21:57 UTC (permalink / raw)
To: Neil Armstrong, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Kevin Hilman,
Jerome Brunet, Martin Blumenstingl
Cc: dri-devel, linux-amlogic, linux-arm-kernel, Simona Vetter,
Guillaume La Roque
Use event_lock when the IRQ consumes the cached OSD state and when atomic
flush publishes the commit flags, matching the lock held by plane update.
Clear the cached enable state under the same lock before disabling the
primary hardware. This prevents the IRQ from programming it during
teardown and prepares the shared state handling for a second OSD.
Signed-off-by: Guillaume La Roque <glaroque@baylibre.com>
---
drivers/gpu/drm/meson/meson_crtc.c | 10 ++++++++++
drivers/gpu/drm/meson/meson_plane.c | 9 ++++++---
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/meson/meson_crtc.c b/drivers/gpu/drm/meson/meson_crtc.c
index 55edb8e2e1af..b2181151acd6 100644
--- a/drivers/gpu/drm/meson/meson_crtc.c
+++ b/drivers/gpu/drm/meson/meson_crtc.c
@@ -170,13 +170,16 @@ static void meson_g12a_crtc_atomic_disable(struct drm_crtc *crtc,
{
struct meson_crtc *meson_crtc = to_meson_crtc(crtc);
struct meson_drm *priv = meson_crtc->priv;
+ unsigned long flags;
DRM_DEBUG_DRIVER("\n");
drm_crtc_vblank_off(crtc);
+ spin_lock_irqsave(&priv->drm->event_lock, flags);
priv->viu.osd[0].enabled = false;
priv->viu.osd[0].commit = false;
+ spin_unlock_irqrestore(&priv->drm->event_lock, flags);
priv->viu.vd1_enabled = false;
priv->viu.vd1_commit = false;
@@ -241,9 +244,12 @@ static void meson_crtc_atomic_flush(struct drm_crtc *crtc,
{
struct meson_crtc *meson_crtc = to_meson_crtc(crtc);
struct meson_drm *priv = meson_crtc->priv;
+ unsigned long flags;
+ spin_lock_irqsave(&priv->drm->event_lock, flags);
priv->viu.osd[0].commit = true;
priv->viu.vd1_commit = true;
+ spin_unlock_irqrestore(&priv->drm->event_lock, flags);
}
static const struct drm_crtc_helper_funcs meson_crtc_helper_funcs = {
@@ -335,6 +341,8 @@ void meson_crtc_irq(struct meson_drm *priv)
struct meson_crtc *meson_crtc = to_meson_crtc(priv->crtc);
unsigned long flags;
+ spin_lock_irqsave(&priv->drm->event_lock, flags);
+
/* Update the OSD registers */
if (priv->viu.osd[0].enabled && priv->viu.osd[0].commit) {
meson_crtc_flush_osd(priv, 0);
@@ -395,6 +403,8 @@ void meson_crtc_irq(struct meson_drm *priv)
priv->viu.osd[0].commit = false;
}
+ spin_unlock_irqrestore(&priv->drm->event_lock, flags);
+
/* Update the VD1 registers */
if (priv->viu.vd1_enabled && priv->viu.vd1_commit) {
diff --git a/drivers/gpu/drm/meson/meson_plane.c b/drivers/gpu/drm/meson/meson_plane.c
index dca295841728..1af65299497f 100644
--- a/drivers/gpu/drm/meson/meson_plane.c
+++ b/drivers/gpu/drm/meson/meson_plane.c
@@ -415,6 +415,12 @@ static void meson_plane_atomic_disable(struct drm_plane *plane,
{
struct meson_plane *meson_plane = to_meson_plane(plane);
struct meson_drm *priv = meson_plane->priv;
+ unsigned long flags;
+
+ spin_lock_irqsave(&priv->drm->event_lock, flags);
+ meson_plane->enabled = false;
+ priv->viu.osd[meson_plane->index].enabled = false;
+ spin_unlock_irqrestore(&priv->drm->event_lock, flags);
if (priv->afbcd.ops) {
priv->afbcd.ops->reset(priv);
@@ -428,9 +434,6 @@ static void meson_plane_atomic_disable(struct drm_plane *plane,
else
writel_bits_relaxed(VPP_OSD1_POSTBLEND, 0,
priv->io_base + _REG(VPP_MISC));
-
- meson_plane->enabled = false;
- priv->viu.osd[meson_plane->index].enabled = false;
}
static const struct drm_plane_helper_funcs meson_plane_helper_funcs = {
--
2.34.1
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 8/8] drm/meson: add a linear RGB overlay on G12A OSD2
2026-11-30 21:57 [PATCH 0/8] drm/meson: add a second RGB plane on G12A Guillaume La Roque
` (6 preceding siblings ...)
2026-11-30 21:57 ` [PATCH 7/8] drm/meson: serialize OSD state updates with the IRQ Guillaume La Roque
@ 2026-11-30 21:57 ` Guillaume La Roque
2026-11-30 22:16 ` sashiko-bot
7 siblings, 1 reply; 11+ messages in thread
From: Guillaume La Roque @ 2026-11-30 21:57 UTC (permalink / raw)
To: Neil Armstrong, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Kevin Hilman,
Jerome Brunet, Martin Blumenstingl
Cc: dri-devel, linux-amlogic, linux-arm-kernel, Simona Vetter,
Guillaume La Roque
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 | 59 +++++++++++-
drivers/gpu/drm/meson/meson_drv.c | 17 +++-
drivers/gpu/drm/meson/meson_drv.h | 2 +
drivers/gpu/drm/meson/meson_plane.c | 155 +++++++++++++++++++++++---------
drivers/gpu/drm/meson/meson_registers.h | 5 ++
drivers/gpu/drm/meson/meson_viu.c | 16 ++++
6 files changed, 212 insertions(+), 42 deletions(-)
diff --git a/drivers/gpu/drm/meson/meson_crtc.c b/drivers/gpu/drm/meson/meson_crtc.c
index b2181151acd6..8ae03ce0308f 100644
--- a/drivers/gpu/drm/meson/meson_crtc.c
+++ b/drivers/gpu/drm/meson/meson_crtc.c
@@ -154,6 +154,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,
@@ -163,6 +175,38 @@ 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));
+ 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,
@@ -179,6 +223,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 +252,8 @@ static void meson_crtc_atomic_disable(struct drm_crtc *crtc,
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;
@@ -248,6 +297,7 @@ static void meson_crtc_atomic_flush(struct drm_crtc *crtc,
spin_lock_irqsave(&priv->drm->event_lock, flags);
priv->viu.osd[0].commit = true;
+ priv->viu.osd[1].commit = true;
priv->viu.vd1_commit = true;
spin_unlock_irqrestore(&priv->drm->event_lock, flags);
}
@@ -303,7 +353,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,
@@ -343,6 +394,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..edfb36ae1583 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];
diff --git a/drivers/gpu/drm/meson/meson_plane.c b/drivers/gpu/drm/meson/meson_plane.c
index 1af65299497f..752fdc791c8c 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,7 +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;
+ bool afbcd = false;
/*
* Update Coordinates
@@ -267,19 +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))
- afbcd = true;
- else
- afbcd = false;
- priv->viu.osd1_afbcd = afbcd;
+ 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));
@@ -352,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),
@@ -372,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;
}
@@ -396,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))
@@ -422,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);
@@ -455,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;
@@ -497,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 |
@@ -549,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.
*/
@@ -568,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;
@@ -586,14 +647,28 @@ 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;
+ } 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 eb6a6f44cb2d..c6c0f4cc28b4 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;
}
--
2.34.1
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 7/8] drm/meson: serialize OSD state updates with the IRQ
2026-11-30 21:57 ` [PATCH 7/8] drm/meson: serialize OSD state updates with the IRQ Guillaume La Roque
@ 2026-11-30 22:14 ` sashiko-bot
0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-11-30 22:14 UTC (permalink / raw)
To: Guillaume La Roque; +Cc: dri-devel, linux-amlogic, neil.armstrong
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/meson: missing event_lock around osd[0] disable in
meson_crtc_atomic_disable()
--
commit e0db1ea984d5b9d13ce988817e791f6169eef00f
Author: Guillaume La Roque <glaroque@baylibre.com>
drm/meson: serialize OSD state updates with the IRQ
This commit uses event_lock to serialize OSD state updates and commit
flags across atomic flush, plane/CRTC disable, and the CRTC IRQ handler.
> diff --git a/drivers/gpu/drm/meson/meson_crtc.c b/drivers/gpu/drm/meson/meson_crtc.c
> index 55edb8e2e1af4..b2181151acd67 100644
> --- a/drivers/gpu/drm/meson/meson_crtc.c
> +++ b/drivers/gpu/drm/meson/meson_crtc.c
> @@ -170,13 +170,16 @@ static void meson_g12a_crtc_atomic_disable(struct drm_crtc *crtc,
> {
> struct meson_crtc *meson_crtc = to_meson_crtc(crtc);
> struct meson_drm *priv = meson_crtc->priv;
> + unsigned long flags;
>
> DRM_DEBUG_DRIVER("\n");
>
> drm_crtc_vblank_off(crtc);
>
> + spin_lock_irqsave(&priv->drm->event_lock, flags);
> priv->viu.osd[0].enabled = false;
> priv->viu.osd[0].commit = false;
> + spin_unlock_irqrestore(&priv->drm->event_lock, flags);
>
> priv->viu.vd1_enabled = false;
> priv->viu.vd1_commit = false;
[Severity: Medium]
Should meson_crtc_atomic_disable() also take priv->drm->event_lock when
clearing priv->viu.osd[0].enabled and priv->viu.osd[0].commit?
drivers/gpu/drm/meson/meson_crtc.c:meson_crtc_atomic_disable() {
...
drm_crtc_vblank_off(crtc);
priv->viu.osd[0].enabled = false;
priv->viu.osd[0].commit = false;
...
/* Disable VPP Postblend */
writel_bits_relaxed(VPP_OSD1_POSTBLEND | VPP_VD1_POSTBLEND |
VPP_VD1_PREBLEND | VPP_POSTBLEND_ENABLE, 0,
priv->io_base + _REG(VPP_MISC));
...
}
drm_crtc_vblank_off() does not disable hardware vsync when vsync_forced is
set (e.g. on GXM with AFBCD active) and does not wait for an in-flight
meson_crtc_irq() to complete. Without event_lock,
meson_crtc_atomic_disable() can run concurrently with meson_crtc_irq() on
non-G12A SoCs:
CPU0 CPU1
meson_crtc_irq() meson_crtc_atomic_disable()
spin_lock_irqsave(&event_lock)
if (osd[0].enabled &&
osd[0].commit)
osd[0].enabled = false;
osd[0].commit = false;
writel_bits_relaxed(..., 0,
... + _REG(VPP_MISC))
meson_crtc_enable_osd1()
writel_bits_relaxed(
VPP_OSD1_POSTBLEND, ...,
... + _REG(VPP_MISC)) <-- re-enables OSD1 / races on VPP_MISC
afbcd.ops->enable()
spin_unlock_irqrestore(&event_lock)
This can corrupt the read-modify-write on VPP_MISC or leave OSD1 and AFBCD
enabled after CRTC disable.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130-meson-g12a-osd2-v1-0-aa982300c20e@baylibre.com?part=7
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 8/8] drm/meson: add a linear RGB overlay on G12A OSD2
2026-11-30 21:57 ` [PATCH 8/8] drm/meson: add a linear RGB overlay on G12A OSD2 Guillaume La Roque
@ 2026-11-30 22:16 ` sashiko-bot
0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-11-30 22:16 UTC (permalink / raw)
To: Guillaume La Roque; +Cc: dri-devel, linux-amlogic, neil.armstrong
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] drm/meson: stale osd[0].commit flag when OSD1 is disabled in
meson_crtc_irq()
- [Medium] drm/meson: unlocked viu.osd state clear in
meson_crtc_atomic_disable()
- [Medium] drm/meson: OSD2 RGB-to-YUV matrix left enabled on MIPI-DSI
outputs
--
commit 62aaa32388dc51ac638495c67084358f3b970884
Author: Guillaume La Roque <glaroque@baylibre.com>
drm/meson: add a linear RGB overlay on G12A OSD2
This commit exposes the OSD2 plane as a linear RGB overlay above the
primary plane on G12A, G12B, and SM1 SoCs.
> diff --git a/drivers/gpu/drm/meson/meson_crtc.c b/drivers/gpu/drm/meson/meson_crtc.c
> index b2181151acd67..8ae03ce0308fe 100644
> --- a/drivers/gpu/drm/meson/meson_crtc.c
> +++ b/drivers/gpu/drm/meson/meson_crtc.c
[ ... ]
> @@ -179,6 +223,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 +252,8 @@ static void meson_crtc_atomic_disable(struct drm_crtc *crtc,
>
> priv->viu.osd[0].enabled = false;
> priv->viu.osd[0].commit = false;
> + priv->viu.osd[1].enabled = false;
> + priv->viu.osd[1].commit = false;
[Severity: Medium]
Should meson_crtc_atomic_disable() acquire priv->drm->event_lock around the
priv->viu.osd state clear and VPP_MISC update, like
meson_g12a_crtc_atomic_disable() does?
drm_crtc_vblank_off() does not wait for an in-flight meson_irq() on another
CPU, and meson_crtc_disable_vblank() leaves the hardware vsync interrupt
enabled when meson_crtc->vsync_forced is set (such as on GXM with AFBC).
Without event_lock, meson_crtc_irq() can race with
meson_crtc_atomic_disable():
CPU0 CPU1
meson_crtc_atomic_disable() meson_crtc_irq()
drm_crtc_vblank_off(crtc) spin_lock_irqsave(&event_lock)
priv->viu.osd[0].enabled = false if (osd[0].enabled && osd[0].commit)
... meson_crtc_enable_osd1()
writel_bits_relaxed(..., VPP_MISC) writel_bits_relaxed(..., VPP_MISC)
priv->afbcd.ops->enable(priv)
spin_unlock_irqrestore(&event_lock)
This can corrupt VPP_MISC or leave OSD1 postblend and AFBC enabled after
the CRTC is disabled.
> @@ -248,6 +297,7 @@ static void meson_crtc_atomic_flush(struct drm_crtc *crtc,
>
> spin_lock_irqsave(&priv->drm->event_lock, flags);
> priv->viu.osd[0].commit = true;
> + priv->viu.osd[1].commit = true;
> priv->viu.vd1_commit = true;
> spin_unlock_irqrestore(&priv->drm->event_lock, flags);
> }
> @@ -303,7 +353,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,
> @@ -343,6 +394,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) {
[Severity: Medium]
Can priv->viu.osd[0].commit stay stuck at true when OSD1 is disabled while
the CRTC remains active?
meson_crtc_atomic_flush() sets both osd[0].commit and osd[1].commit to true
on every CRTC flush, including commits where OSD1 is disabled and only OSD2
or VD1 is active. Unlike osd[1].commit, meson_crtc_irq() only clears
osd[0].commit when osd[0].enabled is true.
If a later atomic commit re-enables OSD1 and also updates or disables OSD2,
meson_plane_atomic_update() sets osd[0].enabled = true and drops event_lock
before OSD2's plane callback and meson_crtc_atomic_flush() run:
CPU0 <hardirq>
drm_atomic_helper_commit_planes()
meson_plane_atomic_update(OSD1)
spin_lock_irqsave(&event_lock)
osd[0].enabled = true
spin_unlock_irqrestore(&event_lock)
meson_crtc_irq()
/* osd[0].commit was already true */
meson_crtc_flush_osd(priv, 0)
meson_g12a_crtc_enable_osd1()
/* uses stale osd[1] state */
meson_plane_atomic_update(OSD2)
meson_crtc_atomic_flush()
This flushes OSD1 before meson_crtc_atomic_flush() and programs
VIU_OSD_BLEND_BLEND1_SIZE with stale osd[1].enabled and osd[1].blend_size
for one frame.
> diff --git a/drivers/gpu/drm/meson/meson_viu.c b/drivers/gpu/drm/meson/meson_viu.c
> index eb6a6f44cb2de..c6c0f4cc28b4b 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);
[Severity: Medium]
Does VPP_WRAP_OSD2_MATRIX_EN_CTRL also need to be disabled when driving a
MIPI-DSI output?
meson_viu_set_g12a_osd_matrix(priv, 1, ...) enables BIT(0) of
VPP_WRAP_OSD2_MATRIX_EN_CTRL to convert OSD2 from RGB to YUV. However, the
G12A MIPI-DSI encoder configures ENCL for RGB input and only toggles
VPP_WRAP_OSD1_MATRIX_EN_CTRL:
drivers/gpu/drm/meson/meson_encoder_dsi.c:meson_encoder_dsi_atomic_enable() {
...
writel_bits_relaxed(BIT(0), 0, priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_EN_CTRL));
writel_relaxed(1, priv->io_base + _REG(ENCL_VIDEO_EN));
}
drivers/gpu/drm/meson/meson_encoder_dsi.c:meson_encoder_dsi_atomic_disable() {
...
writel_bits_relaxed(BIT(0), BIT(0), priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_EN_CTRL));
}
On a MIPI-DSI panel, OSD2 will convert its RGB pixels to YUV before
blending into the RGB pipeline, causing wrong colors on the overlay plane.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130-meson-g12a-osd2-v1-0-aa982300c20e@baylibre.com?part=8
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2026-11-30 22:16 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 21:57 [PATCH 0/8] drm/meson: add a second RGB plane on G12A Guillaume La Roque
2026-11-30 21:57 ` [PATCH 1/8] drm/meson: honor framebuffer offsets for the primary plane Guillaume La Roque
2026-11-30 21:57 ` [PATCH 2/8] drm/meson: isolate primary plane scaler setup Guillaume La Roque
2026-11-30 21:57 ` [PATCH 3/8] drm/meson: keep RGB scanout state per OSD Guillaume La Roque
2026-11-30 21:57 ` [PATCH 4/8] drm/meson: parameterize the G12A OSD color matrix setup Guillaume La Roque
2026-11-30 21:57 ` [PATCH 5/8] drm/meson: handle primary plane zpos allocation failure Guillaume La Roque
2026-11-30 21:57 ` [PATCH 6/8] drm/meson: select RGB plane registers by OSD index Guillaume La Roque
2026-11-30 21:57 ` [PATCH 7/8] drm/meson: serialize OSD state updates with the IRQ Guillaume La Roque
2026-11-30 22:14 ` sashiko-bot
2026-11-30 21:57 ` [PATCH 8/8] drm/meson: add a linear RGB overlay on G12A OSD2 Guillaume La Roque
2026-11-30 22:16 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox