Skip to contentSkip to conversation

media: imx: imx7-media-csi: Fix applying format constraints

PATCH Superseded Fabio Estevam 1 participant 1 message Jul 20, 2023

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Fabio Estevam

author reviewer
#0 lore raw

PATCH 1/1 media: imx: imx7-media-csi: Fix applying format constraints

From: Fabio Estevam <[email protected]>

v4l_bound_align_image() aligns to a multiple power of 2 of walign, but the result only needs to be a multiple of walign.

This causes a 640x480 sensor that used to report:

	Width/Height      : 640/480

to incorrectly report:

	Width/Height      : 768/480

Fix this problem by doing the correct alignment via clamp_roundup().

Fixes 6f482c4729d9 ("media: imx: imx7-media-csi: Get rid of superfluous call to imx7_csi_mbus_fmt_to_pix_fmt")
---
 drivers/media/platform/nxp/imx7-media-csi.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/media/platform/nxp/imx7-media-csi.c +13 -2
index 0bd2613b9320..d964b5a714c5 100644
@@ -1108,6 +1108,17 @@ static int imx7_csi_video_g_fmt_vid_cap(struct file *file, void *fh,
 	return 0;
 }
 
+/* Borrowed from drivers/media/v4l2-core/v4l2-common.c */
+static unsigned int clamp_roundup(unsigned int x, unsigned int min,
+				  unsigned int max, unsigned int alignment)
+{
+	x = clamp(x, min, max);
+	if (alignment)
+		x = round_up(x, alignment);
+
+	return x;
+}
+
 static const struct imx7_csi_pixfmt *
 __imx7_csi_video_try_fmt(struct v4l2_pix_format *pixfmt,
 			 struct v4l2_rect *compose)
@@ -1137,8 +1148,8 @@ __imx7_csi_video_try_fmt(struct v4l2_pix_format *pixfmt,
 	 * 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);
+	pixfmt->width = clamp_roundup(pixfmt->width, 1, 0xffff, walign);
+	pixfmt->height = clamp_roundup(pixfmt->height, 1, 0xffff, 1);
 
 	pixfmt->bytesperline = pixfmt->width * cc->bpp / 8;
 	pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height;
Signature · 1 line
2.34.1