[PATCH v2 10/15] media: tegra-video: vi: Implement link_validate for video entity
From: Svyatoslav Ryhel
Date: Sun Nov 29 2026 - 13:08:09 EST
Add tegra_channel_link_validate() and attach it via
tegra_channel_media_ops to chan->video.entity.ops to verify that the
remote subdevice pad's active format (dimensions and media bus code)
matches the channel's configured format during media pipeline validation.
Signed-off-by: Svyatoslav Ryhel <clamor95@xxxxxxxxx>
---
.../media/platform/nvidia/tegra-video/vi.c | 41 +++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/drivers/media/platform/nvidia/tegra-video/vi.c b/drivers/media/platform/nvidia/tegra-video/vi.c
index c292443783b14..f9d50d7571e10 100644
--- a/drivers/media/platform/nvidia/tegra-video/vi.c
+++ b/drivers/media/platform/nvidia/tegra-video/vi.c
@@ -485,6 +485,46 @@ static int tegra_channel_s_input(struct file *file, void *priv,
return 0;
}
+static int tegra_channel_link_validate(struct media_link *link)
+{
+ struct video_device *video =
+ media_entity_to_video_device(link->sink->entity);
+ struct v4l2_subdev *subdev =
+ media_entity_to_v4l2_subdev(link->source->entity);
+ struct tegra_vi_channel *chan = video_get_drvdata(video);
+ struct v4l2_subdev_format fmt = {
+ .which = V4L2_SUBDEV_FORMAT_ACTIVE,
+ .pad = link->source->index,
+ };
+ int ret;
+
+ if (!chan->fmtinfo)
+ return -EPIPE;
+
+ ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &fmt);
+ if (ret)
+ return ret;
+
+ if (fmt.format.height != chan->format.height ||
+ fmt.format.width != chan->format.width ||
+ fmt.format.code != chan->fmtinfo->code) {
+ dev_dbg(chan->vi->dev,
+ "link '%s':%u -> '%s':%u not valid: 0x%04x/%ux%u != 0x%04x/%ux%u\n",
+ link->source->entity->name, link->source->index,
+ link->sink->entity->name, link->sink->index,
+ fmt.format.code, fmt.format.width, fmt.format.height,
+ chan->fmtinfo->code, chan->format.width,
+ chan->format.height);
+ return -EPIPE;
+ }
+
+ return 0;
+}
+
+static const struct media_entity_operations tegra_channel_media_ops = {
+ .link_validate = tegra_channel_link_validate,
+};
+
static const struct v4l2_ioctl_ops tegra_channel_ioctl_ops = {
.vidioc_querycap = tegra_channel_querycap,
.vidioc_enum_framesizes = tegra_channel_enum_framesizes,
@@ -764,6 +804,7 @@ static int tegra_channel_init(struct tegra_vi_channel *chan)
dev_name(vi->dev), "output", chan->portnos[0]);
chan->video.vfl_type = VFL_TYPE_VIDEO;
chan->video.vfl_dir = VFL_DIR_RX;
+ chan->video.entity.ops = &tegra_channel_media_ops;
chan->video.ioctl_ops = &tegra_channel_ioctl_ops;
chan->video.ctrl_handler = &chan->ctrl_handler;
chan->video.lock = &chan->video_lock;
--
2.53.0