[PATCH v2 2/9] drm/meson: isolate primary plane scaler setup

Neil Armstrong neil.armstrong at linaro.org
Thu Dec 3 11:32:43 PST 2026


On 12/3/26 20:21, Guillaume La Roque wrote:
> 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 at 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;
> 

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

Thanks,
Neil



More information about the linux-arm-kernel mailing list