diff mbox series

[v4,3/4] media: imx: imx7-media-csi: Relax width constraints for non-8bpp formats

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

Commit Message

Alexander Stein April 19, 2023, 7:07 a.m. UTC
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 v4:
* Improve commit message
* Simplify walign calculation
* Remove comment on hardware alignment constraints

 drivers/media/platform/nxp/imx7-media-csi.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Laurent Pinchart April 20, 2023, 10:33 a.m. UTC | #1
Hi Alexander,

Thank you for the patch.

On Wed, Apr 19, 2023 at 09:07:11AM +0200, Alexander Stein wrote:
> 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>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
> Changes in v4:
> * Improve commit message
> * Simplify walign calculation
> * Remove comment on hardware alignment constraints
> 
>  drivers/media/platform/nxp/imx7-media-csi.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/platform/nxp/imx7-media-csi.c b/drivers/media/platform/nxp/imx7-media-csi.c
> index 1315f5743b76f..e6abbfbc5c129 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;
> @@ -1163,12 +1164,13 @@ __imx7_csi_video_try_fmt(struct v4l2_pix_format *pixfmt,
>  	}
>  
>  	/*
> -	 * Round up width for minimum burst size.
> +	 * 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, and check what the real
> -	 * hardware alignment constraint on the width is.
> +	 * TODO: Implement configurable stride support.
>  	 */
> -	v4l_bound_align_image(&pixfmt->width, 1, 0xffff, 8,
> +	walign = 8 * 8 / cc->bpp;
> +	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..e6abbfbc5c129 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;
@@ -1163,12 +1164,13 @@  __imx7_csi_video_try_fmt(struct v4l2_pix_format *pixfmt,
 	}
 
 	/*
-	 * Round up width for minimum burst size.
+	 * 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, and check what the real
-	 * hardware alignment constraint on the width is.
+	 * TODO: Implement configurable stride support.
 	 */
-	v4l_bound_align_image(&pixfmt->width, 1, 0xffff, 8,
+	walign = 8 * 8 / cc->bpp;
+	v4l_bound_align_image(&pixfmt->width, 1, 0xffff, walign,
 			      &pixfmt->height, 1, 0xffff, 1, 0);
 
 	pixfmt->bytesperline = pixfmt->width * cc->bpp / 8;