Re: [PATCH v3 3/4] media: imx: imx7-media-csi: Lift width constraints for 8bpp formats

Laurent Pinchart
2023-04-18T16:00:48Z

Hi Alexander,

Thank you for the patch.

The commit message should state "Lift width constraint for 16bpp
formats". I would also phrase is "Relax" instead of "Lift" as it's not
completely lifted.

On Tue, Apr 18, 2023 at 02:20:40PM +0200, Alexander Stein wrote:
> For 8-bit formats the image_width just needs to be a multiple of 8 pixels
> others just a multiple of 4 pixels.

This is a bit terse, and I think a word or two are missing. It could be
improved:

The driver unconditionally aligns the image width to multiples of 8
pixels. The real alignment constraint is 8 bytes, as indicated by the
CSI_IMAG_PARA.IMAGE_WIDTH documentation that calls for 8 pixel alignment
for 8bpp formats and 4 pixel alignment for other formats.

> Signed-off-by: Alexander Stein <alexander.stein@ew.tq-group.com>
> ---
> Changes in v3:
> * Fix commit message (Only 8-bit formats needs multiple of 8 pixels)
>
> drivers/media/platform/nxp/imx7-media-csi.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/media/platform/nxp/imx7-media-csi.c b/drivers/media/platform/nxp/imx7-media-csi.c
> index 1315f5743b76f..730c9c57bf4bc 100644
> --- a/drivers/media/platform/nxp/imx7-media-csi.c
> +++ b/drivers/media/platform/nxp/imx7-media-csi.c
> @@ -1146,6 +1146,7 @@ __imx7_csi_video_try_fmt(struct v4l2_pix_format *pixfmt,
> struct v4l2_rect *compose)
> {
> const struct imx7_csi_pixfmt *cc;
> + u32 walign;
>
> if (compose) {
> compose->width = pixfmt->width;
> @@ -1162,13 +1163,19 @@ __imx7_csi_video_try_fmt(struct v4l2_pix_format *pixfmt,
> cc = imx7_csi_find_pixel_format(pixfmt->pixelformat);
> }
>
> + /* Refer to CSI_IMAG_PARA.IMAGE_WIDTH description */
> + if (cc->bpp == 8)
> + walign = 8;
> + else
> + walign = 4;

Would the following convey the purpose better ?

/*
* The width alignment is 8 bytes as indicated by the
* CSI_IMAG_PARA.IMAGE_WIDTH documentation. Convert it to pixels.
*/
walign = 8 * 8 / cc->bpp;

> +
> /*
> * Round up width for minimum burst size.
> *
> * TODO: Implement configurable stride support, and check what the real
> * hardware alignment constraint on the width is.
> */

We can now drop the second part of the sentence :-) The first line is
actually not very accurate anymore. How about

/*
* The width alignment is 8 bytes as indicated by the
* CSI_IMAG_PARA.IMAGE_WIDTH documentation. Convert it to pixels.
*
* TODO: Implement configurable stride support.
*/
walign = 8 * 8 / cc->bpp;
v4l_bound_align_image(&pixfmt->width, 1, 0xffff, walign,
&pixfmt->height, 1, 0xffff, 1, 0);

> - v4l_bound_align_image(&pixfmt->width, 1, 0xffff, 8,
> + v4l_bound_align_image(&pixfmt->width, 1, 0xffff, walign,
> &pixfmt->height, 1, 0xffff, 1, 0);
>
> pixfmt->bytesperline = pixfmt->width * cc->bpp / 8;

--
Regards,

Laurent Pinchart