[PATCH v1 10/13] media: tegra-video: Remove remote source subdev helper

From: Svyatoslav Ryhel

Date: Wed Nov 25 2026 - 06:09:29 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 | 28 ++++++++++++-----
.../media/platform/nvidia/tegra-video/vi.c | 30 -------------------
.../media/platform/nvidia/tegra-video/vi.h | 2 --
3 files changed, 21 insertions(+), 39 deletions(-)

diff --git a/drivers/media/platform/nvidia/tegra-video/csi.c b/drivers/media/platform/nvidia/tegra-video/csi.c
index add526de536f9..ab6162720ab78 100644
--- a/drivers/media/platform/nvidia/tegra-video/csi.c
+++ b/drivers/media/platform/nvidia/tegra-video/csi.c
@@ -282,12 +282,17 @@ 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;
+
+ pad = media_entity_remote_source_pad_unique(&subdev->entity);
+ if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
+ dev_err_probe(csi_chan->csi->dev, -ENODEV,
+ "failed to get source entity\n");

- chan = v4l2_get_subdev_hostdata(&csi_chan->subdev);
- src_subdev = tegra_channel_get_remote_source_subdev(chan);
+ 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 +388,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 +399,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 (!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 +435,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,8 +445,13 @@ 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 (!pad || !is_media_entity_v4l2_subdev(pad->entity))
+ dev_err_probe(csi->dev, err, "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");
diff --git a/drivers/media/platform/nvidia/tegra-video/vi.c b/drivers/media/platform/nvidia/tegra-video/vi.c
index f2de3aeb05bbc..98411c3f4a037 100644
--- a/drivers/media/platform/nvidia/tegra-video/vi.c
+++ b/drivers/media/platform/nvidia/tegra-video/vi.c
@@ -150,33 +150,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;
@@ -1134,9 +1107,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);
-
return v4l2_device_register_subdev_nodes(&vid->v4l2_dev);

unregister_video:
diff --git a/drivers/media/platform/nvidia/tegra-video/vi.h b/drivers/media/platform/nvidia/tegra-video/vi.h
index fb377d428d510..44893c5c6e651 100644
--- a/drivers/media/platform/nvidia/tegra-video/vi.h
+++ b/drivers/media/platform/nvidia/tegra-video/vi.h
@@ -300,8 +300,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