Skip to contentSkip to conversation

drm/rockchip: vop2: RK3588 clocking, sync polarity and window fixes

PATCH New Arun Iyengar 1 participant 9 messages Nov 19

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v4 cover drm/rockchip: vop2: RK3588 clocking, sync polarity and window fixes

Fixes for the RK3588 VOP2 found while bringing up HDMI and DisplayPort on an Orange Pi 5 (RK3588S).

Tested on an Orange Pi 5 with an HDMI 2.1 TV and a DisplayPort monitor, pictures judged with a camera, v7.3 based kernel: VP_CLK_CTRL reads back without the garbage divider; the HDMI controller sees the sync polarities of +/+ and mixed modes; HDMI from 148.5 to 1188 MHz (TMDS and FRL) and DP show a correct picture; RGB565 on the Cluster windows scans out without YTR; NV12 in two GEM objects and an AFBC overlay at x=1001 show correctly. Not tested: -HSync/-VSync modes (none in the TV's list), BGR565, HDMI1, eDP, MIPI DSI and DPI (no hardware).

Developed with Claude (Anthropic), which wrote the code and the commit messages. I reviewed every change.

---
Changes in v4:
- Patches 1 and 2: Reviewed-by added (Damon Ding).
- Patch 4: the GRF sync polarity bits get names in rockchip_drm_vop2.h (Damon Ding); comment dropped.
- Patch 5: check moved after the 10bpc check, with a comment and a drm_dbg_kms() (Damon Ding); it tests drm_is_afbc() there, as it now runs before the linear return.
- Rebased on drm-misc-next.
- Link to v3: https://patch.msgid.link/[email protected]

---
Arun Iyengar (8):
drm/rockchip: vop2: Take the UV plane address from the second GEM object drm/rockchip: vop2: Don't use uninitialised dividers on RK3588 drm/rockchip: vop2: Fix the HDMI sync polarity on RK3588 drm/rockchip: vop2: Fix the HDMI sync polarity bit order on RK3588 drm/rockchip: vop2: Only accept AFBC YTR for 8 bit RGB on RK3588 drm/rockchip: vop2: Find the first mixer of a video port with Esmart3 too drm/rockchip: vop2: Keep the other LUT_PORT_SEL fields on gamma LUT updates drm/rockchip: vop2: Fix the AFBC offsets of a source that starts inside a superblock

 drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 27 +++++++++++++++++++--------
 drivers/gpu/drm/rockchip/rockchip_drm_vop2.h |  3 +++
 drivers/gpu/drm/rockchip/rockchip_vop2_reg.c | 16 ++++++++++++----
 3 files changed, 34 insertions(+), 12 deletions(-)

---
base-commit: fac7a5f16230779cfb0d50ca49e9467cc94a2ea9
change-id: 20261110-vop2-fixes-fa45142799c1

Best regards,

Signature · 1 line
Arun Iyengar <[email protected]>
#1 lore raw

PATCH v4 1/8 drm/rockchip: vop2: Take the UV plane address from the second GEM object

vop2_plane_atomic_update() takes the chroma plane address from fb->obj[0]. The planes of a framebuffer can be in different GEM objects (ADDFB2 with two handles, e.g. NV12M from a V4L2 decoder), and the window then fetches the chroma plane from the luma buffer.

Use fb->obj[1] for formats with more than one plane.

---
 drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +2 -1
index 76d151b8bc52..e8ef83d6924b 100644
@@ -1369,7 +1369,8 @@ static void vop2_plane_atomic_update(struct drm_plane *plane,
 		if ((pstate->rotation & DRM_MODE_REFLECT_Y) && !afbc_en)
 			offset += fb->pitches[1] * ((pstate->src_h >> 16) - 2) / vsub;
 
-		rk_obj = to_rockchip_obj(fb->obj[0]);
+		if (fb->format->num_planes > 1)
+			rk_obj = to_rockchip_obj(fb->obj[1]);
 		uv_mst = rk_obj->dma_addr + offset + fb->offsets[1];
 	}
 
Signature · 1 line
2.55.0
#2 lore raw

PATCH v4 2/8 drm/rockchip: vop2: Don't use uninitialised dividers on RK3588

In reply to Arun Iyengar

rk3588_calc_cru_cfg() converts all four dividers with ilog2(), but every interface only sets the ones it uses: dclk_out_div is left uninitialised for HDMI, eDP and DPI, if_dclk_div for DP, MIPI and DPI, and if_pixclk_div for DP and DPI. For HDMI and eDP the uninitialised dclk_out_div is then written to RK3588_VP_CLK_CTRL.

Set the dividers an interface doesn't use to 1.

Fixes 5a028e8f062f ("drm/rockchip: vop2: Add support for rk3588")
---
 drivers/gpu/drm/rockchip/rockchip_vop2_reg.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/gpu/drm/rockchip/rockchip_vop2_reg.c +8 -0
index c44648e1bc0d..f340aba5bfd1 100644
@@ -1597,6 +1597,7 @@ static unsigned long rk3588_calc_cru_cfg(struct vop2_video_port *vp, int id,
 		 */
 		*if_pixclk_div = 2;
 		*if_dclk_div = 4;
+		*dclk_out_div = 1;
 	} else if (vop2_output_if_is_edp(id)) {
 		/*
 		 * edp_pixclk = edp_dclk > dclk_core
@@ -1609,6 +1610,7 @@ static unsigned long rk3588_calc_cru_cfg(struct vop2_video_port *vp, int id,
 		 */
 		*if_pixclk_div = K;
 		*if_dclk_div = K;
+		*dclk_out_div = 1;
 	} else if (vop2_output_if_is_dp(id)) {
 		if (output_mode == ROCKCHIP_OUT_MODE_YUV420)
 			dclk_out_rate = v_pixclk >> 3;
@@ -1622,6 +1624,8 @@ static unsigned long rk3588_calc_cru_cfg(struct vop2_video_port *vp, int id,
 			return 0;
 		}
 		*dclk_out_div = dclk_rate / dclk_out_rate;
+		*if_pixclk_div = 1;
+		*if_dclk_div = 1;
 	} else if (vop2_output_if_is_mipi(id)) {
 		if_pixclk_rate = dclk_core_rate / K;
 		/*
@@ -1643,8 +1647,12 @@ static unsigned long rk3588_calc_cru_cfg(struct vop2_video_port *vp, int id,
 		 * mipi pixclk == dclk_out
 		 */
 		*if_pixclk_div = 1;
+		*if_dclk_div = 1;
 	} else if (vop2_output_if_is_dpi(id)) {
 		dclk_rate = v_pixclk;
+		*dclk_out_div = 1;
+		*if_pixclk_div = 1;
+		*if_dclk_div = 1;
 	}
 
 	*dclk_core_div = dclk_rate / dclk_core_rate;
Signature · 1 line
2.55.0
#3 lore raw

PATCH v4 3/8 drm/rockchip: vop2: Fix the HDMI sync polarity on RK3588

In reply to Arun Iyengar

rk3588_get_hdmi_pol() is passed the POLFLAG bits of the mode but tests them as DRM mode flags, so the HDMI sync polarity bits in GRF_VO1_CON0 come out wrong: +HSync/+VSync modes get one of them set and -HSync/-VSync modes none.

The bits are set for a negative sync. Test the POLFLAG bits instead.

Fixes 5a028e8f062f ("drm/rockchip: vop2: Add support for rk3588")
Cc Cristian Ciocaltea <[email protected]>
---
 drivers/gpu/drm/rockchip/rockchip_vop2_reg.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/rockchip/rockchip_vop2_reg.c +4 -3
index f340aba5bfd1..3e654cb99ddf 100644
@@ -1683,12 +1683,13 @@ static u32 rk3588_get_mipi_port_mux(int vp_id)
 		return 0;
 }
 
-static u32 rk3588_get_hdmi_pol(u32 flags)
+/* The sync polarity bits in GRF_VO1_CON0 are set for a negative sync */
+static u32 rk3588_get_hdmi_pol(u32 polflags)
 {
 	u32 val;
 
-	val = (flags & DRM_MODE_FLAG_NHSYNC) ? BIT(HSYNC_POSITIVE) : 0;
-	val |= (flags & DRM_MODE_FLAG_NVSYNC) ? BIT(VSYNC_POSITIVE) : 0;
+	val = (polflags & BIT(HSYNC_POSITIVE)) ? 0 : BIT(HSYNC_POSITIVE);
+	val |= (polflags & BIT(VSYNC_POSITIVE)) ? 0 : BIT(VSYNC_POSITIVE);
 
 	return val;
 }
Signature · 1 line
2.55.0
#4 lore raw

PATCH v4 4/8 drm/rockchip: vop2: Fix the HDMI sync polarity bit order on RK3588

In reply to Arun Iyengar

In GRF_VO1_CON0 the HDMI vsync polarity bit comes before the hsync one (bits 5 and 6 for HDMI0, 7 and 8 for HDMI1), but rk3588_get_hdmi_pol() puts hsync first. Modes with mixed sync polarities go out with both syncs inverted: the HDMI controller sees 1920x1080@144 +HSync -VSync as -HSync +VSync in VIDEO_INTERFACE_STATUS0.

Swap them and name the bits.

Fixes 5a028e8f062f ("drm/rockchip: vop2: Add support for rk3588")
---
 drivers/gpu/drm/rockchip/rockchip_drm_vop2.h | 2 ++
 drivers/gpu/drm/rockchip/rockchip_vop2_reg.c | 5 ++---
 2 files changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/rockchip/rockchip_drm_vop2.h +2 -0
index 1c2d7d97a6c2..de325cc50c59 100644
@@ -409,6 +409,8 @@ enum dst_factor_mode {
 #define RK3588_GRF_SOC_CON1			0x0304
 #define RK3588_GRF_VOP_CON2			0x08
 #define RK3588_GRF_VO1_CON0			0x00
+#define RK3588_HDMI_VSYNC_INVERT		BIT(0)
+#define RK3588_HDMI_HSYNC_INVERT		BIT(1)
 
 /* System registers definition */
 #define RK3568_REG_CFG_DONE			0x000
drivers/gpu/drm/rockchip/rockchip_vop2_reg.c +2 -3
index 3e654cb99ddf..3a95d2f9516c 100644
@@ -1683,13 +1683,12 @@ static u32 rk3588_get_mipi_port_mux(int vp_id)
 		return 0;
 }
 
-/* The sync polarity bits in GRF_VO1_CON0 are set for a negative sync */
 static u32 rk3588_get_hdmi_pol(u32 polflags)
 {
 	u32 val;
 
-	val = (polflags & BIT(HSYNC_POSITIVE)) ? 0 : BIT(HSYNC_POSITIVE);
-	val |= (polflags & BIT(VSYNC_POSITIVE)) ? 0 : BIT(VSYNC_POSITIVE);
+	val = (polflags & BIT(VSYNC_POSITIVE)) ? 0 : RK3588_HDMI_VSYNC_INVERT;
+	val |= (polflags & BIT(HSYNC_POSITIVE)) ? 0 : RK3588_HDMI_HSYNC_INVERT;
 
 	return val;
 }
Signature · 1 line
2.55.0
#5 lore raw

PATCH v4 5/8 drm/rockchip: vop2: Only accept AFBC YTR for 8 bit RGB on RK3588

In reply to Arun Iyengar

According to the TRM, the AFBC decoder of the RK3588 Cluster windows supports the lossless colour transform (YTR) only for the 8 bit RGB formats. An RGB565 buffer with YTR gives a black picture and POST_BUF_EMPTY, while the same buffer without YTR displays fine.

Don't accept YTR for any other format on RK3588.

Fixes 5a028e8f062f ("drm/rockchip: vop2: Add support for rk3588")
---
 drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +9 -0
index e8ef83d6924b..1408b539c311 100644
@@ -396,6 +396,15 @@ static bool rockchip_vop2_mod_supported(struct drm_plane *plane, u32 format,
 		return false;
 	}
 
+	/* AFBC YTR on 3588 is for 8bpc RGB only */
+	if (vop2->version == VOP_VERSION_RK3588 && drm_is_afbc(modifier) &&
+	    (modifier & AFBC_FORMAT_MOD_YTR) &&
+	    vop2_convert_afbc_format(format) != VOP2_AFBC_FMT_ARGB8888 &&
+	    vop2_convert_afbc_format(format) != VOP2_AFBC_FMT_RGB888) {
+		drm_dbg_kms(vop2->drm, "Only support YTR with 8bpc RGB formats\n");
+		return false;
+	}
+
 	/* Linear is otherwise supported everywhere */
 	if (modifier == DRM_FORMAT_MOD_LINEAR)
 		return true;
Signature · 1 line
2.55.0
#6 lore raw

PATCH v4 6/8 drm/rockchip: vop2: Find the first mixer of a video port with Esmart3 too

In reply to Arun Iyengar

vop2_find_start_mixer_id_for_vp() passes ROCKCHIP_VOP2_ESMART3, the highest window id, as the bit count to for_each_set_bit(), so Esmart3 is never found and a video port whose bottom layer is Esmart3 programs the mixers of other video ports.

Add ROCKCHIP_VOP2_MAX_LAYER_ID after the last window id and search up to it.

Fixes d3fe9aa49585 ("drm/rockchip: vop2: Use OVL_LAYER_SEL configuration instead of use win_mask calculate used layers")
---
 drivers/gpu/drm/rockchip/rockchip_drm_vop2.h | 1 +
 drivers/gpu/drm/rockchip/rockchip_vop2_reg.c | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/rockchip/rockchip_drm_vop2.h +1 -0
index de325cc50c59..a1668d234b84 100644
@@ -807,6 +807,7 @@ enum vop2_layer_phy_id {
 	ROCKCHIP_VOP2_CLUSTER3,
 	ROCKCHIP_VOP2_ESMART2,
 	ROCKCHIP_VOP2_ESMART3,
+	ROCKCHIP_VOP2_MAX_LAYER_ID,
 	ROCKCHIP_VOP2_PHY_ID_INVALID = -1,
 };
 
drivers/gpu/drm/rockchip/rockchip_vop2_reg.c +1 -1
index 3a95d2f9516c..6927db8a592d 100644
@@ -1881,7 +1881,7 @@ static int vop2_find_start_mixer_id_for_vp(struct vop2_video_port *vp)
 
 	for (i = 0; i < 31; i += 4) {
 		match = false;
-		for_each_set_bit(phys_id, &win_mask, ROCKCHIP_VOP2_ESMART3) {
+		for_each_set_bit(phys_id, &win_mask, ROCKCHIP_VOP2_MAX_LAYER_ID) {
 			win = vop2_find_win_by_phys_id(vop2, phys_id);
 			if (win->data->layer_sel_id[vp->id] == ((layer_sel >> i) & 0xf)) {
 				match = true;
Signature · 1 line
2.55.0
#7 lore raw

PATCH v4 7/8 drm/rockchip: vop2: Keep the other LUT_PORT_SEL fields on gamma LUT updates

In reply to Arun Iyengar

On RK3588 the gamma LUT update writes the whole LUT_PORT_SEL register to select the write port, which clears the dclk source selection of video ports 0 and 2 and the VP0/VP1 merge enable held in the same register.

Only update the write select field.

Fixes 4f537776340d ("rockchip/drm: vop2: add support for gamma LUT")
---
 drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +3 -2
index 1408b539c311..d4103e02f37f 100644
@@ -1625,8 +1625,9 @@ static void vop2_crtc_atomic_set_gamma_seamless(struct vop2 *vop2,
 						struct vop2_video_port *vp,
 						struct drm_crtc *crtc)
 {
-	vop2_writel(vop2, RK3568_LUT_PORT_SEL,
-		    FIELD_PREP(RK3588_LUT_PORT_SEL__GAMMA_AHB_WRITE_SEL, vp->id));
+	regmap_update_bits(vop2->map, RK3568_LUT_PORT_SEL,
+			   RK3588_LUT_PORT_SEL__GAMMA_AHB_WRITE_SEL,
+			   FIELD_PREP(RK3588_LUT_PORT_SEL__GAMMA_AHB_WRITE_SEL, vp->id));
 	vop2_vp_dsp_lut_enable(vp);
 	vop2_crtc_write_gamma_lut(vop2, crtc);
 	vop2_vp_dsp_lut_update_enable(vp);
Signature · 1 line
2.55.0
#8 lore raw

PATCH v4 8/8 drm/rockchip: vop2: Fix the AFBC offsets of a source that starts inside a superblock

In reply to Arun Iyengar

For an AFBC source that starts inside a superblock, AFBC_TILE_NUM misses the first, partial superblock column, and the transform offset is the whole x position (truncated to 8 bits) instead of the offset inside the superblock.

Count the columns from the first one the source touches and take the x offset modulo the superblock width, as the vendor kernel does.

Fixes 604be85547ce ("drm/rockchip: Add VOP2 driver")
---
 drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +5 -5
index d4103e02f37f..670875ade4c4 100644
@@ -435,7 +435,7 @@ static bool vop2_half_block_enable(struct drm_plane_state *pstate)
 }
 
 static u32 vop2_afbc_transform_offset(struct drm_plane_state *pstate,
-				      bool afbc_half_block_en)
+				      bool afbc_half_block_en, u32 block_w)
 {
 	struct drm_rect *src = &pstate->src;
 	struct drm_framebuffer *fb = pstate->fb;
@@ -483,7 +483,7 @@ static u32 vop2_afbc_transform_offset(struct drm_plane_state *pstate,
 		ty = act_yoffset;
 		break;
 	case DRM_MODE_REFLECT_Y:
-		tx = act_xoffset;
+		tx = act_xoffset % block_w;
 		ty = bottom_crop_line_num - act_yoffset;
 		break;
 	case DRM_MODE_ROTATE_90:
@@ -495,7 +495,7 @@ static u32 vop2_afbc_transform_offset(struct drm_plane_state *pstate,
 		ty = vir_width - width - act_xoffset;
 		break;
 	case 0:
-		tx = act_xoffset;
+		tx = act_xoffset % block_w;
 		ty = act_yoffset;
 		break;
 	}
@@ -1437,7 +1437,7 @@ static void vop2_plane_atomic_update(struct drm_plane *plane,
 		if (fb->modifier & AFBC_FORMAT_MOD_YTR)
 			afbc_format |= (1 << 4);
 
-		afbc_tile_num = ALIGN(src_w, block_w) / block_w;
+		afbc_tile_num = ALIGN(src_w + (src->x1 >> 16) % block_w, block_w) / block_w;
 
 		/*
 		 * AFBC pic_vir_width is count by pixel, this is different
@@ -1488,7 +1488,7 @@ static void vop2_plane_atomic_update(struct drm_plane *plane,
 			vop2_win_write(win, VOP2_WIN_AFBC_PLD_OFFSET, yrgb_mst);
 		}
 
-		transform_offset = vop2_afbc_transform_offset(pstate, half_block_en);
+		transform_offset = vop2_afbc_transform_offset(pstate, half_block_en, block_w);
 		vop2_win_write(win, VOP2_WIN_AFBC_HDR_PTR, yrgb_mst);
 		vop2_win_write(win, VOP2_WIN_AFBC_PIC_SIZE, act_info);
 		vop2_win_write(win, VOP2_WIN_TRANSFORM_OFFSET, transform_offset);
Signature · 1 line
2.55.0