media: tegra-video: Fix channel format alignment
authorSowjanya Komatineni <skomatineni@nvidia.com>
Wed, 12 Aug 2020 00:27:12 +0000 (02:27 +0200)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Fri, 28 Aug 2020 13:06:59 +0000 (15:06 +0200)
Pixel format width is mistakenly aligned to surface align bytes
and altering width to aligned value may force sensor mode change
other than the requested one and also cause mismatch in width
programmed between sensor and vi which can lead to capture errors.

This patch removes width alignment and clamps width as per Tegra
minimum and maximum limits.

Signed-off-by: Sowjanya Komatineni <skomatineni@nvidia.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/staging/media/tegra-video/vi.c

index a3b9b21..0ae1771 100644 (file)
@@ -359,25 +359,15 @@ static void tegra_channel_fmt_align(struct tegra_vi_channel *chan,
                                    struct v4l2_pix_format *pix,
                                    unsigned int bpp)
 {
-       unsigned int align;
-       unsigned int min_width;
-       unsigned int max_width;
-       unsigned int width;
        unsigned int min_bpl;
        unsigned int max_bpl;
        unsigned int bpl;
 
        /*
-        * The transfer alignment requirements are expressed in bytes. Compute
-        * minimum and maximum values, clamp the requested width and convert
-        * it back to pixels. Use bytesperline to adjust the width.
+        * The transfer alignment requirements are expressed in bytes.
+        * Clamp the requested width and height to the limits.
         */
-       align = lcm(SURFACE_ALIGN_BYTES, bpp);
-       min_width = roundup(TEGRA_MIN_WIDTH, align);
-       max_width = rounddown(TEGRA_MAX_WIDTH, align);
-       width = roundup(pix->width * bpp, align);
-
-       pix->width = clamp(width, min_width, max_width) / bpp;
+       pix->width = clamp(pix->width, TEGRA_MIN_WIDTH, TEGRA_MAX_WIDTH);
        pix->height = clamp(pix->height, TEGRA_MIN_HEIGHT, TEGRA_MAX_HEIGHT);
 
        /* Clamp the requested bytes per line value. If the maximum bytes per