Skip to content

Commit 2908042

Browse files
Fabio Estevammchehab
authored andcommitted
media: imx: imx7-media-csi: Fix applying format constraints
v4l_bound_align_image() aligns to a multiple of 2 to the power of walign, not to walign. Depending on the pixel format, this causes the image width to be aligned to 16 or 256 pixels instead of 4 or 8 as required by the hardware. Fix it by rounding and clamping the width and height manually. Closes: https://lore.kernel.org/linux-media/CAJ+vNU0BOVLTL17ofgHwtexbpuMYwH_aGUC==EXABUtHHiv_ag@mail.gmail.com Reported-by: Tim Harvey <tharvey@gateworks.com> Fixes: 6f482c4 ("media: imx: imx7-media-csi: Get rid of superfluous call to imx7_csi_mbus_fmt_to_pix_fmt") Co-developed-by: Alexander Stein <alexander.stein@ew.tq-group.com> Signed-off-by: Alexander Stein <alexander.stein@ew.tq-group.com> Signed-off-by: Fabio Estevam <festevam@denx.de> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
1 parent 6d00f4e commit 2908042

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

drivers/media/platform/nxp/imx7-media-csi.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
#include <linux/clk.h>
1010
#include <linux/delay.h>
1111
#include <linux/interrupt.h>
12+
#include <linux/math.h>
1213
#include <linux/mfd/syscon.h>
14+
#include <linux/minmax.h>
1315
#include <linux/module.h>
1416
#include <linux/of_device.h>
1517
#include <linux/of_graph.h>
@@ -1137,8 +1139,9 @@ __imx7_csi_video_try_fmt(struct v4l2_pix_format *pixfmt,
11371139
* TODO: Implement configurable stride support.
11381140
*/
11391141
walign = 8 * 8 / cc->bpp;
1140-
v4l_bound_align_image(&pixfmt->width, 1, 0xffff, walign,
1141-
&pixfmt->height, 1, 0xffff, 1, 0);
1142+
pixfmt->width = clamp(round_up(pixfmt->width, walign), walign,
1143+
round_down(65535U, walign));
1144+
pixfmt->height = clamp(pixfmt->height, 1U, 65535U);
11421145

11431146
pixfmt->bytesperline = pixfmt->width * cc->bpp / 8;
11441147
pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height;

0 commit comments

Comments
 (0)