[PATCH v3 07/27] media: rockchip: rga: use stride for offset calculation

Nicolas Dufresne nicolas at ndufresne.ca
Fri Mar 20 10:36:30 PDT 2026


Le mardi 27 janvier 2026 à 15:39 +0100, Sven Püschel a écrit :
> Use the stride instead of the width for the offset calculation. This
> ensures that the bytesperline value doesn't need to match the width
> value of the image.
> 
> Furthermore this patch removes the dependency on the uv_factor property
> and instead reuses the v4l2_format_info to determine the correct
> division factor.
> 
> Signed-off-by: Sven Püschel <s.pueschel at pengutronix.de>

Reviewed-by: Nicolas Dufresne <nicolas.dufresne at collabora.com>

> ---
>  drivers/media/platform/rockchip/rga/rga-buf.c | 14 +++++++++-----
>  drivers/media/platform/rockchip/rga/rga.c     | 16 ----------------
>  drivers/media/platform/rockchip/rga/rga.h     |  1 -
>  3 files changed, 9 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/media/platform/rockchip/rga/rga-buf.c b/drivers/media/platform/rockchip/rga/rga-buf.c
> index bb575873f2b24..65fc0d5b4aa10 100644
> --- a/drivers/media/platform/rockchip/rga/rga-buf.c
> +++ b/drivers/media/platform/rockchip/rga/rga-buf.c
> @@ -14,7 +14,6 @@
>  #include <media/videobuf2-dma-sg.h>
>  #include <media/videobuf2-v4l2.h>
>  
> -#include "rga-hw.h"
>  #include "rga.h"
>  
>  static ssize_t fill_descriptors(struct rga_dma_desc *desc, size_t max_desc,
> @@ -95,14 +94,19 @@ static int rga_buf_init(struct vb2_buffer *vb)
>  	return 0;
>  }
>  
> -static int get_plane_offset(struct rga_frame *f, int plane)
> +static int get_plane_offset(struct rga_frame *f,
> +			    const struct v4l2_format_info *info,
> +			    int plane)
>  {
> +	u32 stride = f->pix.plane_fmt[0].bytesperline;
> +
>  	if (plane == 0)
>  		return 0;
>  	if (plane == 1)
> -		return f->width * f->height;
> +		return stride * f->height;
>  	if (plane == 2)
> -		return f->width * f->height + (f->width * f->height / f->fmt->uv_factor);
> +		return stride * f->height +
> +		       (stride * f->height / info->hdiv / info->vdiv);
>  
>  	return -EINVAL;
>  }
> @@ -148,7 +152,7 @@ static int rga_buf_prepare(struct vb2_buffer *vb)
>  	/* Fill the remaining planes */
>  	info = v4l2_format_info(f->fmt->fourcc);
>  	for (i = info->mem_planes; i < info->comp_planes; i++)
> -		offsets[i] = get_plane_offset(f, i);
> +		offsets[i] = get_plane_offset(f, info, i);
>  
>  	rbuf->offset.y_off = offsets[0];
>  	rbuf->offset.u_off = offsets[1];
> diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/platform/rockchip/rga/rga.c
> index 338c7796490bc..da4d5bec7a0a5 100644
> --- a/drivers/media/platform/rockchip/rga/rga.c
> +++ b/drivers/media/platform/rockchip/rga/rga.c
> @@ -190,7 +190,6 @@ static struct rga_fmt formats[] = {
>  		.color_swap = RGA_COLOR_ALPHA_SWAP,
>  		.hw_format = RGA_COLOR_FMT_ABGR8888,
>  		.depth = 32,
> -		.uv_factor = 1,
>  		.y_div = 1,
>  		.x_div = 1,
>  	},
> @@ -199,7 +198,6 @@ static struct rga_fmt formats[] = {
>  		.color_swap = RGA_COLOR_RB_SWAP,
>  		.hw_format = RGA_COLOR_FMT_ABGR8888,
>  		.depth = 32,
> -		.uv_factor = 1,
>  		.y_div = 1,
>  		.x_div = 1,
>  	},
> @@ -208,7 +206,6 @@ static struct rga_fmt formats[] = {
>  		.color_swap = RGA_COLOR_RB_SWAP,
>  		.hw_format = RGA_COLOR_FMT_XBGR8888,
>  		.depth = 32,
> -		.uv_factor = 1,
>  		.y_div = 1,
>  		.x_div = 1,
>  	},
> @@ -217,7 +214,6 @@ static struct rga_fmt formats[] = {
>  		.color_swap = RGA_COLOR_NONE_SWAP,
>  		.hw_format = RGA_COLOR_FMT_RGB888,
>  		.depth = 24,
> -		.uv_factor = 1,
>  		.y_div = 1,
>  		.x_div = 1,
>  	},
> @@ -226,7 +222,6 @@ static struct rga_fmt formats[] = {
>  		.color_swap = RGA_COLOR_RB_SWAP,
>  		.hw_format = RGA_COLOR_FMT_RGB888,
>  		.depth = 24,
> -		.uv_factor = 1,
>  		.y_div = 1,
>  		.x_div = 1,
>  	},
> @@ -235,7 +230,6 @@ static struct rga_fmt formats[] = {
>  		.color_swap = RGA_COLOR_RB_SWAP,
>  		.hw_format = RGA_COLOR_FMT_ABGR4444,
>  		.depth = 16,
> -		.uv_factor = 1,
>  		.y_div = 1,
>  		.x_div = 1,
>  	},
> @@ -244,7 +238,6 @@ static struct rga_fmt formats[] = {
>  		.color_swap = RGA_COLOR_RB_SWAP,
>  		.hw_format = RGA_COLOR_FMT_ABGR1555,
>  		.depth = 16,
> -		.uv_factor = 1,
>  		.y_div = 1,
>  		.x_div = 1,
>  	},
> @@ -253,7 +246,6 @@ static struct rga_fmt formats[] = {
>  		.color_swap = RGA_COLOR_RB_SWAP,
>  		.hw_format = RGA_COLOR_FMT_BGR565,
>  		.depth = 16,
> -		.uv_factor = 1,
>  		.y_div = 1,
>  		.x_div = 1,
>  	},
> @@ -262,7 +254,6 @@ static struct rga_fmt formats[] = {
>  		.color_swap = RGA_COLOR_UV_SWAP,
>  		.hw_format = RGA_COLOR_FMT_YUV420SP,
>  		.depth = 12,
> -		.uv_factor = 4,
>  		.y_div = 2,
>  		.x_div = 1,
>  	},
> @@ -271,7 +262,6 @@ static struct rga_fmt formats[] = {
>  		.color_swap = RGA_COLOR_UV_SWAP,
>  		.hw_format = RGA_COLOR_FMT_YUV422SP,
>  		.depth = 16,
> -		.uv_factor = 2,
>  		.y_div = 1,
>  		.x_div = 1,
>  	},
> @@ -280,7 +270,6 @@ static struct rga_fmt formats[] = {
>  		.color_swap = RGA_COLOR_NONE_SWAP,
>  		.hw_format = RGA_COLOR_FMT_YUV420SP,
>  		.depth = 12,
> -		.uv_factor = 4,
>  		.y_div = 2,
>  		.x_div = 1,
>  	},
> @@ -289,7 +278,6 @@ static struct rga_fmt formats[] = {
>  		.color_swap = RGA_COLOR_NONE_SWAP,
>  		.hw_format = RGA_COLOR_FMT_YUV420SP,
>  		.depth = 12,
> -		.uv_factor = 4,
>  		.y_div = 2,
>  		.x_div = 1,
>  	},
> @@ -298,7 +286,6 @@ static struct rga_fmt formats[] = {
>  		.color_swap = RGA_COLOR_NONE_SWAP,
>  		.hw_format = RGA_COLOR_FMT_YUV422SP,
>  		.depth = 16,
> -		.uv_factor = 2,
>  		.y_div = 1,
>  		.x_div = 1,
>  	},
> @@ -307,7 +294,6 @@ static struct rga_fmt formats[] = {
>  		.color_swap = RGA_COLOR_NONE_SWAP,
>  		.hw_format = RGA_COLOR_FMT_YUV420P,
>  		.depth = 12,
> -		.uv_factor = 4,
>  		.y_div = 2,
>  		.x_div = 2,
>  	},
> @@ -316,7 +302,6 @@ static struct rga_fmt formats[] = {
>  		.color_swap = RGA_COLOR_NONE_SWAP,
>  		.hw_format = RGA_COLOR_FMT_YUV422P,
>  		.depth = 16,
> -		.uv_factor = 2,
>  		.y_div = 1,
>  		.x_div = 2,
>  	},
> @@ -325,7 +310,6 @@ static struct rga_fmt formats[] = {
>  		.color_swap = RGA_COLOR_UV_SWAP,
>  		.hw_format = RGA_COLOR_FMT_YUV420P,
>  		.depth = 12,
> -		.uv_factor = 4,
>  		.y_div = 2,
>  		.x_div = 2,
>  	},
> diff --git a/drivers/media/platform/rockchip/rga/rga.h b/drivers/media/platform/rockchip/rga/rga.h
> index 2db10acecb405..477cf5b62bbb2 100644
> --- a/drivers/media/platform/rockchip/rga/rga.h
> +++ b/drivers/media/platform/rockchip/rga/rga.h
> @@ -17,7 +17,6 @@
>  struct rga_fmt {
>  	u32 fourcc;
>  	int depth;
> -	u8 uv_factor;
>  	u8 y_div;
>  	u8 x_div;
>  	u8 color_swap;
-------------- 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-rockchip/attachments/20260320/95992a84/attachment.sig>


More information about the Linux-rockchip mailing list