diff mbox series

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

Message ID 20230418122041.1318862-4-alexander.stein@ew.tq-group.com
State New
Headers show
Series Fix imx7-media-csi format settings | expand

Commit Message

Alexander Stein April 18, 2023, 12:20 p.m. UTC
For 8-bit formats the image_width just needs to be a multiple of 8 pixels
others just a multiple of 4 pixels.

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(-)

Comments

Laurent Pinchart April 18, 2023, 3:59 p.m. UTC | #1
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;
Alexander Stein April 19, 2023, 7:01 a.m. UTC | #2
Hi Laurent,

thanks for the feedback.

Am Dienstag, 18. April 2023, 17:59:47 CEST schrieb Laurent Pinchart:
> Hi Alexander,
> 
> Thank you for the patch.
> 
> The commit message should state "Lift width constraint for 16bpp
> formats".

To be pedantic it should be called "Lift width constraint for non-8bpp 
formats" :)

> I would also phrase is "Relax" instead of "Lift" as it's not
> completely lifted.

That's true, this subtle difference should be accounted for. Thanks.

> 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.

Thanks for this suggestion. This sounds much better.

> > 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;

I was wondering how to shorten this calculation without using ? operator, 
nice.

> > +
> > 
> >  	/*
> >  	
> >  	 * 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);

That's neat, thanks. I'll update accordingly.

Best regards,
Alexander

> > -	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;
diff mbox series

Patch

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;
+
 	/*
 	 * Round up width for minimum burst size.
 	 *
 	 * TODO: Implement configurable stride support, and check what the real
 	 * hardware alignment constraint on the width is.
 	 */
-	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;