[PATCH v1 09/13] media: tegra-video: vi: Configure capture format locally without subdev calls
From: Svyatoslav Ryhel
Date: Wed Nov 25 2026 - 06:09:22 EST
Simplify __tegra_channel_try_format() and tegra_channel_set_format() to
validate, align, and store the capture pixel format locally on the video
channel instead of querying or setting formats on the remote subdevice
and allocating temporary subdev state.
Signed-off-by: Svyatoslav Ryhel <clamor95@xxxxxxxxx>
---
.../media/platform/nvidia/tegra-video/vi.c | 81 +------------------
1 file changed, 4 insertions(+), 77 deletions(-)
diff --git a/drivers/media/platform/nvidia/tegra-video/vi.c b/drivers/media/platform/nvidia/tegra-video/vi.c
index 4a0742b514a2b..f2de3aeb05bbc 100644
--- a/drivers/media/platform/nvidia/tegra-video/vi.c
+++ b/drivers/media/platform/nvidia/tegra-video/vi.c
@@ -340,82 +340,23 @@ static int __tegra_channel_try_format(struct tegra_vi_channel *chan,
struct v4l2_pix_format *pix)
{
const struct tegra_video_format *fmtinfo;
- static struct lock_class_key key;
- struct v4l2_subdev *subdev;
- struct v4l2_subdev_format fmt = {
- .which = V4L2_SUBDEV_FORMAT_TRY,
- };
- struct v4l2_subdev_state *sd_state;
- struct v4l2_subdev_frame_size_enum fse = {
- .which = V4L2_SUBDEV_FORMAT_TRY,
- };
- struct v4l2_subdev_selection sdsel = {
- .which = V4L2_SUBDEV_FORMAT_ACTIVE,
- .target = V4L2_SEL_TGT_CROP_BOUNDS,
- };
- struct v4l2_rect *try_crop;
- int ret = 0;
-
- subdev = tegra_channel_get_remote_source_subdev(chan);
- if (!subdev)
- return -ENODEV;
+ struct tegra_vi *vi = chan->vi;
- /*
- * FIXME: Drop this call, drivers are not supposed to use
- * __v4l2_subdev_state_alloc().
- */
- sd_state = __v4l2_subdev_state_alloc(subdev, "tegra:state->lock",
- &key);
- if (IS_ERR(sd_state))
- return PTR_ERR(sd_state);
/*
* 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(vi, 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(vi, pix->pixelformat);
}
pix->field = V4L2_FIELD_NONE;
- fmt.pad = 0;
- v4l2_fill_mbus_format(&fmt.format, pix, fmtinfo->code);
-
- /*
- * Attempt to obtain the format size from subdev.
- * If not available, try to get crop boundary from subdev.
- */
- try_crop = v4l2_subdev_state_get_crop(sd_state, 0);
- fse.code = fmtinfo->code;
- ret = v4l2_subdev_call(subdev, pad, enum_frame_size, sd_state, &fse);
- if (ret) {
- if (!v4l2_subdev_has_op(subdev, pad, get_selection) ||
- v4l2_subdev_call(subdev, pad, get_selection, NULL, NULL, &sdsel)) {
- try_crop->width = 0;
- try_crop->height = 0;
- } else {
- try_crop->width = sdsel.r.width;
- try_crop->height = sdsel.r.height;
- }
- } else {
- try_crop->width = fse.max_width;
- try_crop->height = fse.max_height;
- }
-
- ret = v4l2_subdev_call(subdev, pad, set_fmt, NULL, sd_state, &fmt);
- if (ret < 0)
- goto out_free;
-
- v4l2_fill_pix_format(pix, &fmt.format);
chan->vi->ops->vi_fmt_align(pix, NULL, fmtinfo->bpp);
-out_free:
- __v4l2_subdev_state_free(sd_state);
-
- return ret;
+ return 0;
}
static int tegra_channel_try_format(struct file *file, void *fh,
@@ -439,10 +380,6 @@ static int tegra_channel_set_format(struct file *file, void *fh,
{
struct tegra_vi_channel *chan = video_drvdata(file);
const struct tegra_video_format *fmtinfo;
- struct v4l2_subdev_format fmt = {
- .which = V4L2_SUBDEV_FORMAT_ACTIVE,
- };
- struct v4l2_subdev *subdev;
struct v4l2_pix_format *pix = &format->fmt.pix;
int ret;
@@ -456,16 +393,6 @@ static int tegra_channel_set_format(struct file *file, void *fh,
fmtinfo = tegra_get_format_by_fourcc(chan->vi, pix->pixelformat);
- fmt.pad = 0;
- v4l2_fill_mbus_format(&fmt.format, pix, fmtinfo->code);
- subdev = tegra_channel_get_remote_source_subdev(chan);
- ret = v4l2_subdev_call(subdev, pad, set_fmt, NULL, NULL, &fmt);
- if (ret < 0)
- return ret;
-
- v4l2_fill_pix_format(pix, &fmt.format);
- chan->vi->ops->vi_fmt_align(pix, NULL, fmtinfo->bpp);
-
chan->format = *pix;
chan->fmtinfo = fmtinfo;
tegra_channel_update_gangports(chan);
--
2.53.0