[PATCH 03/16] media: rockchip: rga: align stride to 16 bytes

Nicolas Dufresne nicolas at ndufresne.ca
Tue Oct 7 11:19:15 PDT 2025


Hi,


Le mardi 07 octobre 2025 à 10:31 +0200, Sven Püschel a écrit :
> Align the stride to a multiple of 16 according to the RGA3 requirements
> mentioned in the datasheet. This also ensures that the stride of the RGA2
> is aligned to 4 bytes, as it needs to divide the value by 4 (one word)
> before storing it in the register.
> 
> Increasing the stride for the alignment also requires to increase the
> sizeimage value. This is usually handled by v4l2_fill_pixfmt_mp, but
> it doesn't allow to set a stride alignment. Therefore use the generated
> values to calculate the total number of lines to properly update the
> sizeimage value after the bytesperline has been aligned.
> 
> Signed-off-by: Sven Püschel <s.pueschel at pengutronix.de>
> ---
>  drivers/media/platform/rockchip/rga/rga.c | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
> 
> diff --git a/drivers/media/platform/rockchip/rga/rga.c
> b/drivers/media/platform/rockchip/rga/rga.c
> index
> 6438119a6c7aeff1e89e7aa95dcd5d2921fefa08..3cb7ce470c47e39d694e8176875a75fad271
> 7f96 100644
> --- a/drivers/media/platform/rockchip/rga/rga.c
> +++ b/drivers/media/platform/rockchip/rga/rga.c
> @@ -459,6 +459,25 @@ static int vidioc_enum_fmt(struct file *file, void *priv,
> struct v4l2_fmtdesc *f
>  	return 0;
>  }
>  
> +static void align_pixfmt(struct v4l2_pix_format_mplane *pix_fmt)
> +{
> +	int lines;
> +	struct v4l2_plane_pix_format *fmt;
> +
> +	/*
> +	 * Align stride to 16 for the RGA3 (based on the datasheet)
> +	 * To not dismiss the v4l2_fill_pixfmt_mp helper
> +	 * (and manually write it again), we're approximating the new
> sizeimage
> +	 */
> +	for (fmt = pix_fmt->plane_fmt;
> +	     fmt < pix_fmt->plane_fmt + pix_fmt->num_planes;
> +	     fmt++) {
> +		lines = DIV_ROUND_UP(fmt->sizeimage, fmt->bytesperline);
> +		fmt->bytesperline = (fmt->bytesperline + 0xf) & ~0xf;
> +		fmt->sizeimage = fmt->bytesperline * lines;

Instead of open coding this, describe this with struct v4l2_frmsize_stepwise and
then use v4l2_apply_frmsize_constraints().

Nicolas

> +	}
> +}
> +
>  static int vidioc_g_fmt(struct file *file, void *priv, struct v4l2_format *f)
>  {
>  	struct v4l2_pix_format_mplane *pix_fmt = &f->fmt.pix_mp;
> @@ -474,6 +493,7 @@ static int vidioc_g_fmt(struct file *file, void *priv,
> struct v4l2_format *f)
>  		return PTR_ERR(frm);
>  
>  	v4l2_fill_pixfmt_mp(pix_fmt, frm->fmt->fourcc, frm->width, frm-
> >height);
> +	align_pixfmt(pix_fmt);
>  
>  	pix_fmt->field = V4L2_FIELD_NONE;
>  	pix_fmt->colorspace = frm->colorspace;
> @@ -496,6 +516,7 @@ static int vidioc_try_fmt(struct file *file, void *priv,
> struct v4l2_format *f)
>  				(u32)MIN_HEIGHT, (u32)MAX_HEIGHT);
>  
>  	v4l2_fill_pixfmt_mp(pix_fmt, fmt->fourcc, pix_fmt->width, pix_fmt-
> >height);
> +	align_pixfmt(pix_fmt);
>  	pix_fmt->field = V4L2_FIELD_NONE;
>  
>  	return 0;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: This is a digitally signed message part
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20251007/27d2c807/attachment.sig>


More information about the linux-arm-kernel mailing list