[PATCH v2 07/15] media: tegra-video: vi: Match fourcc against channel format bitmap
From: Svyatoslav Ryhel
Date: Sun Nov 29 2026 - 13:08:29 EST
From: Jonas Schwöbel <jonasschwoebel@xxxxxxxx>
Update tegra_get_format_by_fourcc() to accept a struct tegra_vi_channel
pointer and match fourcc values against the channel's TPG or subdevice
format bitmap, updating callers in vi.c accordingly.
This is required because VI supports different media bus formats with the
same pixel format, so only the first matching instance would be returned
without checking whether the index is among the supported formats.
Co-developed-by: Svyatoslav Ryhel <clamor95@xxxxxxxxx>
Signed-off-by: Jonas Schwöbel <jonasschwoebel@xxxxxxxx>
Signed-off-by: Svyatoslav Ryhel <clamor95@xxxxxxxxx>
---
.../media/platform/nvidia/tegra-video/vi.c | 27 ++++++++++++-------
1 file changed, 17 insertions(+), 10 deletions(-)
diff --git a/drivers/media/platform/nvidia/tegra-video/vi.c b/drivers/media/platform/nvidia/tegra-video/vi.c
index 2a0ffdd3896f6..15f05ca19c752 100644
--- a/drivers/media/platform/nvidia/tegra-video/vi.c
+++ b/drivers/media/platform/nvidia/tegra-video/vi.c
@@ -88,16 +88,24 @@ static u32 tegra_get_format_fourcc_by_idx(struct tegra_vi *vi,
}
static const struct tegra_video_format *
-tegra_get_format_by_fourcc(struct tegra_vi *vi, u32 fourcc)
+tegra_get_format_by_fourcc(struct tegra_vi_channel *chan, u32 fourcc)
{
+ unsigned long *fmts_bitmap = chan->tpg_fmts_bitmap;
+ struct tegra_vi *vi = chan->vi;
unsigned int i;
- for (i = 0; i < vi->soc->nformats; ++i) {
+ if (!IS_ENABLED(CONFIG_VIDEO_TEGRA_TPG))
+ fmts_bitmap = chan->fmts_bitmap;
+
+ for (i = 0; i < vi->soc->nformats; ++i)
if (vi->soc->video_formats[i].fourcc == fourcc)
- return &vi->soc->video_formats[i];
- }
+ if (test_bit(i, fmts_bitmap))
+ break;
- return NULL;
+ if (i >= vi->soc->nformats)
+ return NULL;
+
+ return &vi->soc->video_formats[i];
}
/*
@@ -320,7 +328,7 @@ static int tegra_channel_enum_framesizes(struct file *file, void *fh,
.which = V4L2_SUBDEV_FORMAT_ACTIVE,
};
- fmtinfo = tegra_get_format_by_fourcc(chan->vi, sizes->pixel_format);
+ fmtinfo = tegra_get_format_by_fourcc(chan, sizes->pixel_format);
if (!fmtinfo)
return -EINVAL;
@@ -403,12 +411,11 @@ static int __tegra_channel_try_format(struct tegra_vi_channel *chan,
* Retrieve the format information and if requested format isn't
* supported, keep the current format.
*/
- fmtinfo = tegra_get_format_by_fourcc(chan->vi, pix->pixelformat);
+ fmtinfo = tegra_get_format_by_fourcc(chan, pix->pixelformat);
if (!fmtinfo) {
pix->pixelformat = chan->format.pixelformat;
pix->colorspace = chan->format.colorspace;
- fmtinfo = tegra_get_format_by_fourcc(chan->vi,
- pix->pixelformat);
+ fmtinfo = tegra_get_format_by_fourcc(chan, pix->pixelformat);
}
pix->field = V4L2_FIELD_NONE;
@@ -485,7 +492,7 @@ static int tegra_channel_set_format(struct file *file, void *fh,
if (ret)
return ret;
- fmtinfo = tegra_get_format_by_fourcc(chan->vi, pix->pixelformat);
+ fmtinfo = tegra_get_format_by_fourcc(chan, pix->pixelformat);
fmt.pad = 0;
v4l2_fill_mbus_format(&fmt.format, pix, fmtinfo->code);
--
2.53.0