media: v4l2-common: Add v4l2_fill_pixfmt_aligned() helper

Add v4l2_fill_pixfmt_aligned(), a variant of v4l2_fill_pixfmt()
that accepts a stride_alignment parameter, mirroring the existing
v4l2_fill_pixfmt_mp() / v4l2_fill_pixfmt_mp_aligned() pair.

v4l2_fill_pixfmt() is refactored to call v4l2_fill_pixfmt_aligned()
with stride_alignment=1, preserving its existing behaviour.

The new helper is needed by drivers whose DMA engine requires the
line stride to be a multiple of a specific value, such as the
Renesas RZ/G3E CRU which requires 128-byte alignment.

Reviewed-by: Jacopo Mondi <jacopo.mondi+renesas@ideasonboard.com>
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
Reviewed-by: Sven Püschel <s.pueschel@pengutronix.de>
Reviewed-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
This commit is contained in:
Tommaso Merciai 2026-08-19 12:28:06 +02:00 committed by Sakari Ailus
parent 89ee42c3fa
commit 9dd982125d
2 changed files with 43 additions and 7 deletions

View File

@ -537,8 +537,8 @@ int v4l2_fill_pixfmt_mp_aligned(struct v4l2_pix_format_mplane *pixfmt,
}
EXPORT_SYMBOL_GPL(v4l2_fill_pixfmt_mp_aligned);
int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat,
u32 width, u32 height)
int v4l2_fill_pixfmt_aligned(struct v4l2_pix_format *pixfmt, u32 pixelformat,
u32 width, u32 height, u8 stride_alignment)
{
const struct v4l2_format_info *info;
int i;
@ -554,15 +554,17 @@ int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat,
pixfmt->width = width;
pixfmt->height = height;
pixfmt->pixelformat = pixelformat;
pixfmt->bytesperline = v4l2_format_plane_stride(info, 0, width, 1);
pixfmt->bytesperline = v4l2_format_plane_stride(info, 0, width,
stride_alignment);
pixfmt->sizeimage = 0;
for (i = 0; i < info->comp_planes; i++)
pixfmt->sizeimage +=
v4l2_format_plane_size(info, i, width, height, 1);
v4l2_format_plane_size(info, i, width, height,
stride_alignment);
return 0;
}
EXPORT_SYMBOL_GPL(v4l2_fill_pixfmt);
EXPORT_SYMBOL_GPL(v4l2_fill_pixfmt_aligned);
#ifdef CONFIG_MEDIA_CONTROLLER
static s64 v4l2_get_link_freq_ctrl(struct v4l2_ctrl_handler *handler,

View File

@ -554,8 +554,42 @@ static inline bool v4l2_is_format_bayer(const struct v4l2_format_info *f)
const struct v4l2_format_info *v4l2_format_info(u32 format);
void v4l2_apply_frmsize_constraints(u32 *width, u32 *height,
const struct v4l2_frmsize_stepwise *frmsize);
int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat,
u32 width, u32 height);
/**
* v4l2_fill_pixfmt_aligned - Fill in a &struct v4l2_pix_format with stride
* alignment requirements
*
* @pixfmt: pointer to the &struct v4l2_pix_format to be filled
* @pixelformat: the V4L2 pixel format (V4L2_PIX_FMT_*)
* @width: image width in pixels
* @height: image height in pixels
* @stride_alignment: stride alignment in bytes, must be a power of 2
*
* Fills all fields of @pixfmt for the given pixel format, dimensions, and
* stride alignment. Only formats stored in a single memory plane are
* supported; returns -EINVAL for multi-memory-plane formats.
*
* @pixfmt->bytesperline is set to the stride of the primary (plane 0) plane,
* rounded up to a multiple of @stride_alignment. For formats that store
* multiple component planes in a single memory buffer (e.g. YUV420), the
* alignment applied to each component plane's stride is scaled relative to
* @stride_alignment so that the chroma stride remains consistently derivable
* from the luma stride. @pixfmt->bytesperline therefore reflects only the
* primary plane stride.
*
* @pixfmt->sizeimage is set to the total size in bytes of all planes.
*
* Return: 0 on success, -EINVAL if @pixelformat is unknown or uses multiple
* memory planes.
*/
int v4l2_fill_pixfmt_aligned(struct v4l2_pix_format *pixfmt, u32 pixelformat,
u32 width, u32 height, u8 stride_alignment);
static inline int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt,
u32 pixelformat, u32 width, u32 height)
{
return v4l2_fill_pixfmt_aligned(pixfmt, pixelformat, width, height, 1);
}
/* @stride_alignment is a power of 2 value in bytes */
int v4l2_fill_pixfmt_mp_aligned(struct v4l2_pix_format_mplane *pixfmt,