mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Svyatoslav Ryhel <clamor95@gmail.com>
To: Mauro Carvalho Chehab <mchehab@kernel.org>,
	Thierry Reding <thierry.reding@kernel.org>,
	Jonathan Hunter <jonathanh@nvidia.com>,
	Sowjanya Komatineni <skomatineni@nvidia.com>,
	Luca Ceresoli <luca.ceresoli@bootlin.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Svyatoslav Ryhel <clamor95@gmail.com>,
	Hans Verkuil <hverkuil+cisco@kernel.org>,
	Mikko Perttunen <mperttunen@nvidia.com>
Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
	linux-tegra@vger.kernel.org, linux-staging@lists.linux.dev
Subject: [PATCH v2 12/15] media: tegra-video: Remove remote source subdev helper
Date: Sun, 29 Nov 2026 20:07:19 +0200	[thread overview]
Message-ID: <20261129180722.142186-13-clamor95@gmail.com> (raw)
In-Reply-To: <20261129180722.142186-1-clamor95@gmail.com>

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@gmail.com>
---
 .../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


  parent reply	other threads:[~2026-11-29 18:08 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 18:07 [PATCH v2 00/15] tegra-video: Convert to media-centric pipe Svyatoslav Ryhel
2026-11-29 18:07 ` [PATCH v2 01/15] staging: media: tegra-video: Move driver to media/platform/nvidia Svyatoslav Ryhel
2026-11-29 18:07 ` [PATCH v2 02/15] media: tegra-video: vi: Drop controls consolidation into VI device Svyatoslav Ryhel
2026-11-29 18:07 ` [PATCH v2 03/15] media: tegra-video: vi: Expose all sub-devices in the pipeline Svyatoslav Ryhel
2026-11-29 18:07 ` [PATCH v2 04/15] media: tegra-video: vi: Drop subdevice passthrough and input ioctls Svyatoslav Ryhel
2026-11-29 18:07 ` [PATCH v2 05/15] media: tegra-video: vi: Build bitmap of formats compatible with CSI/VIP instead of source Svyatoslav Ryhel
2026-11-29 18:07 ` [PATCH v2 06/15] media: tegra-video: Expose SoC stepwise frame size limits Svyatoslav Ryhel
2026-11-29 18:07 ` [PATCH v2 07/15] media: tegra-video: vi: Match fourcc against channel format bitmap Svyatoslav Ryhel
2026-11-29 18:07 ` [PATCH v2 08/15] media: tegra-video: vi: Report stepwise frame sizes instead of querying subdev Svyatoslav Ryhel
2026-11-29 18:07 ` [PATCH v2 09/15] media: tegra-video: vi: Configure capture format locally without subdev calls Svyatoslav Ryhel
2026-11-29 18:07 ` [PATCH v2 10/15] media: tegra-video: vi: Implement link_validate for video entity Svyatoslav Ryhel
2026-11-29 18:07 ` [PATCH v2 11/15] media: tegra-video: video: Resolve video device via media graph on notifications Svyatoslav Ryhel
2026-11-29 18:07 ` Svyatoslav Ryhel [this message]
2026-11-29 18:07 ` [PATCH v2 13/15] media: tegra-video: csi: Scope pad and state ops to TPG mode Svyatoslav Ryhel
2026-11-29 18:07 ` [PATCH v2 14/15] media: tegra-video: csi: Add pad and media operations for own CSI channels Svyatoslav Ryhel
2026-11-29 18:07 ` [PATCH v2 15/15] media: tegra-video: vip: Add pad and media operations for VIP Svyatoslav Ryhel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261129180722.142186-13-clamor95@gmail.com \
    --to=clamor95@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hverkuil+cisco@kernel.org \
    --cc=jonathanh@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=linux-tegra@vger.kernel.org \
    --cc=luca.ceresoli@bootlin.com \
    --cc=mchehab@kernel.org \
    --cc=mperttunen@nvidia.com \
    --cc=skomatineni@nvidia.com \
    --cc=thierry.reding@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®