[PATCH v2 12/15] media: tegra-video: Remove remote source subdev helper
From: Svyatoslav Ryhel
Date: Sun Nov 29 2026 - 13:08:56 EST
Look up the remote source subdevice directly via
media_entity_remote_source_pad_unique() in csi_get_pixel_rate(),
tegra_csi_enable_stream(), and tegra_csi_disable_stream(), allowing
tegra_channel_get_remote_source_subdev() and its subdev hostdata setup in
VI to be removed.
Signed-off-by: Svyatoslav Ryhel <clamor95@xxxxxxxxx>
---
.../media/platform/nvidia/tegra-video/csi.c | 31 ++++++++++++++-----
.../media/platform/nvidia/tegra-video/vi.c | 30 ------------------
.../media/platform/nvidia/tegra-video/vi.h | 2 --
3 files changed, 23 insertions(+), 40 deletions(-)
diff --git a/drivers/media/platform/nvidia/tegra-video/csi.c b/drivers/media/platform/nvidia/tegra-video/csi.c
index add526de536f9..30c547d57c479 100644
--- a/drivers/media/platform/nvidia/tegra-video/csi.c
+++ b/drivers/media/platform/nvidia/tegra-video/csi.c
@@ -282,12 +282,18 @@ static int csi_init_state(struct v4l2_subdev *sd,
static unsigned int csi_get_pixel_rate(struct tegra_csi_channel *csi_chan)
{
- struct tegra_vi_channel *chan;
+ struct v4l2_subdev *subdev = &csi_chan->subdev;
struct v4l2_subdev *src_subdev;
struct v4l2_ctrl *ctrl;
+ struct media_pad *pad;
- chan = v4l2_get_subdev_hostdata(&csi_chan->subdev);
- src_subdev = tegra_channel_get_remote_source_subdev(chan);
+ pad = media_entity_remote_source_pad_unique(&subdev->entity);
+ if (IS_ERR(pad) || !is_media_entity_v4l2_subdev(pad->entity)) {
+ dev_err(csi_chan->csi->dev, "failed to get source entity\n");
+ return 0;
+ }
+
+ src_subdev = media_entity_to_v4l2_subdev(pad->entity);
ctrl = v4l2_ctrl_find(src_subdev->ctrl_handler, V4L2_CID_PIXEL_RATE);
if (ctrl)
return v4l2_ctrl_g_ctrl_int64(ctrl);
@@ -383,6 +389,8 @@ static int tegra_csi_enable_stream(struct v4l2_subdev *subdev)
if (csi_chan->mipi) {
struct v4l2_subdev *src_subdev;
+ struct media_pad *pad;
+
/*
* TRM has incorrectly documented to wait for done status from
* calibration logic after CSI interface power on.
@@ -392,9 +400,12 @@ static int tegra_csi_enable_stream(struct v4l2_subdev *subdev)
* CSI subdev stream-on triggers start of MIPI pads calibration.
* Wait for calibration to finish here after sensor subdev stream-on.
*/
- src_subdev = tegra_channel_get_remote_source_subdev(chan);
- ret = v4l2_subdev_call(src_subdev, video, s_stream, true);
+ pad = media_entity_remote_source_pad_unique(&subdev->entity);
+ if (IS_ERR(pad) || !is_media_entity_v4l2_subdev(pad->entity))
+ goto disable_csi_stream;
+ src_subdev = media_entity_to_v4l2_subdev(pad->entity);
+ ret = v4l2_subdev_call(src_subdev, video, s_stream, true);
if (ret < 0 && ret != -ENOIOCTLCMD)
goto disable_csi_stream;
@@ -425,7 +436,6 @@ static int tegra_csi_enable_stream(struct v4l2_subdev *subdev)
static int tegra_csi_disable_stream(struct v4l2_subdev *subdev)
{
- struct tegra_vi_channel *chan = v4l2_get_subdev_hostdata(subdev);
struct tegra_csi_channel *csi_chan = to_csi_chan(subdev);
struct tegra_csi *csi = csi_chan->csi;
int err;
@@ -436,11 +446,16 @@ static int tegra_csi_disable_stream(struct v4l2_subdev *subdev)
*/
if (csi_chan->mipi) {
struct v4l2_subdev *src_subdev;
+ struct media_pad *pad;
+
+ pad = media_entity_remote_source_pad_unique(&subdev->entity);
+ if (IS_ERR(pad) || !is_media_entity_v4l2_subdev(pad->entity))
+ dev_err(csi->dev, "failed to get source entity\n");
- src_subdev = tegra_channel_get_remote_source_subdev(chan);
+ src_subdev = media_entity_to_v4l2_subdev(pad->entity);
err = v4l2_subdev_call(src_subdev, video, s_stream, false);
if (err < 0 && err != -ENOIOCTLCMD)
- dev_err_probe(csi->dev, err, "source subdev stream off failed\n");
+ dev_err(csi->dev, "source subdev stream off failed: %d\n", err);
}
csi->ops->csi_stop_streaming(csi_chan);
diff --git a/drivers/media/platform/nvidia/tegra-video/vi.c b/drivers/media/platform/nvidia/tegra-video/vi.c
index f9d50d7571e10..56aa289a288bd 100644
--- a/drivers/media/platform/nvidia/tegra-video/vi.c
+++ b/drivers/media/platform/nvidia/tegra-video/vi.c
@@ -181,33 +181,6 @@ tegra_channel_get_remote_bridge_subdev(struct tegra_vi_channel *chan)
return media_entity_to_v4l2_subdev(pad->entity);
}
-/*
- * Walk up the chain until the initial source (e.g. image sensor)
- */
-struct v4l2_subdev *
-tegra_channel_get_remote_source_subdev(struct tegra_vi_channel *chan)
-{
- struct media_pad *pad;
- struct v4l2_subdev *subdev;
- struct media_entity *entity;
-
- subdev = tegra_channel_get_remote_bridge_subdev(chan);
- if (!subdev)
- return NULL;
-
- pad = &subdev->entity.pads[0];
- while (!(pad->flags & MEDIA_PAD_FL_SOURCE)) {
- pad = media_pad_remote_pad_first(pad);
- if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
- break;
- entity = pad->entity;
- pad = &entity->pads[0];
- subdev = media_entity_to_v4l2_subdev(entity);
- }
-
- return subdev;
-}
-
static int tegra_channel_enable_stream(struct tegra_vi_channel *chan)
{
struct v4l2_subdev *subdev;
@@ -1285,9 +1258,6 @@ static int tegra_vi_graph_notify_complete(struct v4l2_async_notifier *notifier)
v4l2_set_subdev_hostdata(subdev, chan);
- subdev = tegra_channel_get_remote_source_subdev(chan);
- v4l2_set_subdev_hostdata(subdev, chan);
-
ret = v4l2_device_register_subdev_nodes(&vid->v4l2_dev);
if (ret) {
dev_err(vi->dev, "failed to register subdev nodes\n");
diff --git a/drivers/media/platform/nvidia/tegra-video/vi.h b/drivers/media/platform/nvidia/tegra-video/vi.h
index 8788a88b9528f..0e2a32ecef7df 100644
--- a/drivers/media/platform/nvidia/tegra-video/vi.h
+++ b/drivers/media/platform/nvidia/tegra-video/vi.h
@@ -303,8 +303,6 @@ extern const struct tegra_vi_soc tegra210_vi_soc;
struct v4l2_subdev *
tegra_channel_get_remote_csi_subdev(struct tegra_vi_channel *chan);
-struct v4l2_subdev *
-tegra_channel_get_remote_source_subdev(struct tegra_vi_channel *chan);
int tegra_channel_set_stream(struct tegra_vi_channel *chan, bool on);
void tegra_channel_release_buffers(struct tegra_vi_channel *chan,
enum vb2_buffer_state state);
--
2.53.0