mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v4 0/3] media: subdev: Add v4l2_subdev_get_frame_desc_passthrough and use it
@ 2025-03-24  8:04 Tomi Valkeinen
  2025-03-24  8:04 ` [PATCH v4 1/3] media: subdev: Add v4l2_subdev_get_frame_desc_passthrough helper Tomi Valkeinen
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Tomi Valkeinen @ 2025-03-24  8:04 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Laurent Pinchart, Sakari Ailus
  Cc: linux-media, linux-kernel, Tomi Valkeinen

When writing the exact same code the third time for Renesas, I thought
we probably need a helper.

 Tomi

Signed-off-by: Tomi Valkeinen <tomi.valkeinen+renesas@ideasonboard.com>
---
Changes in v4:
- Update the helper name in commit descriptions too
- Link to v3: https://lore.kernel.org/r/20250324-frame-desc-passthrough-v3-0-993839a1f9b3@ideasonboard.com

Changes in v3:
- Rename the helper to v4l2_subdev_get_frame_desc_passthrough()
- Check for fd->entry[] array overflow
- Add error prints (with dev_dbg)
- Link to v2: https://lore.kernel.org/r/20250219-frame-desc-passthrough-v2-0-5135d57ecd6a@ideasonboard.com

Changes in v2:
- Fix "uninitialized symbol 'ret'"
- Reorder local variables
- Link to v1: https://lore.kernel.org/r/20250218-frame-desc-passthrough-v1-0-a32458f53714@ideasonboard.com

---
Tomi Valkeinen (3):
      media: subdev: Add v4l2_subdev_get_frame_desc_passthrough helper
      media: i2c: ds90ub953: Use v4l2_subdev_get_frame_desc_passthrough
      media: i2c: ds90ub913: Use v4l2_subdev_get_frame_desc_passthrough

 drivers/media/i2c/ds90ub913.c         |  59 +-----------------
 drivers/media/i2c/ds90ub953.c         |  61 +-----------------
 drivers/media/v4l2-core/v4l2-subdev.c | 113 ++++++++++++++++++++++++++++++++++
 include/media/v4l2-subdev.h           |  22 +++++++
 4 files changed, 137 insertions(+), 118 deletions(-)
---
base-commit: f2151613e040973c868d28c8b00885dfab69eb75
change-id: 20250218-frame-desc-passthrough-66805e413974

Best regards,
-- 
Tomi Valkeinen <tomi.valkeinen+renesas@ideasonboard.com>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v4 1/3] media: subdev: Add v4l2_subdev_get_frame_desc_passthrough helper
  2025-03-24  8:04 [PATCH v4 0/3] media: subdev: Add v4l2_subdev_get_frame_desc_passthrough and use it Tomi Valkeinen
@ 2025-03-24  8:04 ` Tomi Valkeinen
  2026-03-04 13:49   ` Sakari Ailus
  2025-03-24  8:04 ` [PATCH v4 2/3] media: i2c: ds90ub953: Use v4l2_subdev_get_frame_desc_passthrough Tomi Valkeinen
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Tomi Valkeinen @ 2025-03-24  8:04 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Laurent Pinchart, Sakari Ailus
  Cc: linux-media, linux-kernel, Tomi Valkeinen

Add a helper for v4l2_subdev_pad_ops.v4l2_get_frame_desc operation. The
helper can be used when the subdevice directly passes through the
streams.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen+renesas@ideasonboard.com>
---
 drivers/media/v4l2-core/v4l2-subdev.c | 113 ++++++++++++++++++++++++++++++++++
 include/media/v4l2-subdev.h           |  22 +++++++
 2 files changed, 135 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
index a3074f469b15..a415d3234ca6 100644
--- a/drivers/media/v4l2-core/v4l2-subdev.c
+++ b/drivers/media/v4l2-core/v4l2-subdev.c
@@ -2502,6 +2502,119 @@ int v4l2_subdev_s_stream_helper(struct v4l2_subdev *sd, int enable)
 }
 EXPORT_SYMBOL_GPL(v4l2_subdev_s_stream_helper);
 
+int v4l2_subdev_get_frame_desc_passthrough(struct v4l2_subdev *sd,
+					   unsigned int pad,
+					   struct v4l2_mbus_frame_desc *fd)
+{
+	const struct media_pad *pads = sd->entity.pads;
+	struct media_pad *local_sink_pad;
+	struct v4l2_subdev_route *route;
+	struct v4l2_subdev_state *state;
+	struct device *dev = sd->dev;
+	int ret = 0;
+
+	if (WARN_ON(!(pads[pad].flags & MEDIA_PAD_FL_SOURCE)))
+		return -EINVAL;
+
+	state = v4l2_subdev_lock_and_get_active_state(sd);
+
+	/* Iterate over sink pads */
+	media_entity_for_each_pad(&sd->entity, local_sink_pad) {
+		struct v4l2_mbus_frame_desc source_fd;
+		bool have_source_fd = false;
+
+		if (!(local_sink_pad->flags & MEDIA_PAD_FL_SINK))
+			continue;
+
+		/*
+		 * Copy frame desc entries for the streams going from the sink
+		 * pad to the requested pad
+		 */
+		for_each_active_route(&state->routing, route) {
+			struct v4l2_mbus_frame_desc_entry *source_entry = NULL;
+			struct media_pad *remote_source_pad;
+			struct v4l2_subdev *remote_sd;
+			unsigned int i;
+
+			if (route->source_pad != pad ||
+			    route->sink_pad != local_sink_pad->index)
+				continue;
+
+			if (!have_source_fd) {
+				remote_source_pad = media_pad_remote_pad_unique(local_sink_pad);
+				if (!remote_source_pad) {
+					dev_dbg(dev, "Failed to find remote pad for sink pad %u\n",
+						local_sink_pad->index);
+					ret = -EINVAL;
+					goto out_unlock;
+				}
+
+				remote_sd = media_entity_to_v4l2_subdev(remote_source_pad->entity);
+				if (!remote_sd) {
+					ret = -EINVAL;
+					goto out_unlock;
+				}
+
+				ret = v4l2_subdev_call(remote_sd, pad,
+						       get_frame_desc,
+						       remote_source_pad->index,
+						       &source_fd);
+				if (ret) {
+					dev_err(dev,
+						"Failed to get frame desc from remote subdev %s\n",
+						remote_sd->name);
+					goto out_unlock;
+				}
+
+				have_source_fd = true;
+
+				if (fd->num_entries == 0) {
+					fd->type = source_fd.type;
+				} else if (fd->type != source_fd.type) {
+					dev_err(dev,
+						"Frame desc type mismatch: %u != %u\n",
+						fd->type, source_fd.type);
+					ret = -EPIPE;
+					goto out_unlock;
+				}
+			}
+
+			for (i = 0; i < source_fd.num_entries; i++) {
+				if (source_fd.entry[i].stream == route->sink_stream) {
+					source_entry = &source_fd.entry[i];
+					break;
+				}
+			}
+
+			if (!source_entry) {
+				dev_dbg(sd->dev,
+					"Failed to find stream %u from source frame desc\n",
+					route->sink_stream);
+				ret = -EPIPE;
+				goto out_unlock;
+			}
+
+			if (fd->num_entries >= V4L2_FRAME_DESC_ENTRY_MAX) {
+				dev_dbg(sd->dev, "Frame desc entry limit reached\n");
+				ret = -ENOSPC;
+				goto out_unlock;
+			}
+
+			fd->entry[fd->num_entries] = *source_entry;
+
+			fd->entry[fd->num_entries].stream = route->source_stream;
+
+			fd->num_entries++;
+		}
+	}
+
+out_unlock:
+	v4l2_subdev_unlock_state(state);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(v4l2_subdev_get_frame_desc_passthrough);
+
 #endif /* CONFIG_VIDEO_V4L2_SUBDEV_API */
 
 #endif /* CONFIG_MEDIA_CONTROLLER */
diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
index 57f2bcb4eb16..7dc8625b131e 100644
--- a/include/media/v4l2-subdev.h
+++ b/include/media/v4l2-subdev.h
@@ -1748,6 +1748,28 @@ int v4l2_subdev_disable_streams(struct v4l2_subdev *sd, u32 pad,
  */
 int v4l2_subdev_s_stream_helper(struct v4l2_subdev *sd, int enable);
 
+/**
+ * v4l2_subdev_get_frame_desc_passthrough() - Helper to implement the subdev
+ *	v4l2_get_frame_desc operation in simple passthrough cases
+ * @sd: The subdevice
+ * @pad: The source pad index
+ * @fd: The mbus frame desc
+ *
+ * Subdevice drivers that only pass through the streams can use this helper
+ * to implement the &v4l2_subdev_pad_ops.v4l2_get_frame_desc operation.
+ *
+ * The helper will call get_frame_desc on the subdevice's sources, create a new
+ * frame desc which contains only the streams on the given source pad. The data
+ * for each frame desc entry is copied directly from the data provided from the
+ * calls to the subdevice's sources, with the exception of the 'stream' field
+ * which is set according to the subdevice's routing table.
+ *
+ * Return: 0 on success, or a negative error code otherwise.
+ */
+int v4l2_subdev_get_frame_desc_passthrough(struct v4l2_subdev *sd,
+					   unsigned int pad,
+					   struct v4l2_mbus_frame_desc *fd);
+
 #endif /* CONFIG_VIDEO_V4L2_SUBDEV_API */
 
 #endif /* CONFIG_MEDIA_CONTROLLER */

-- 
2.43.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v4 2/3] media: i2c: ds90ub953: Use v4l2_subdev_get_frame_desc_passthrough
  2025-03-24  8:04 [PATCH v4 0/3] media: subdev: Add v4l2_subdev_get_frame_desc_passthrough and use it Tomi Valkeinen
  2025-03-24  8:04 ` [PATCH v4 1/3] media: subdev: Add v4l2_subdev_get_frame_desc_passthrough helper Tomi Valkeinen
@ 2025-03-24  8:04 ` Tomi Valkeinen
  2025-03-24  8:04 ` [PATCH v4 3/3] media: i2c: ds90ub913: " Tomi Valkeinen
  2026-01-22 14:15 ` [PATCH v4 0/3] media: subdev: Add v4l2_subdev_get_frame_desc_passthrough and use it Tomi Valkeinen
  3 siblings, 0 replies; 6+ messages in thread
From: Tomi Valkeinen @ 2025-03-24  8:04 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Laurent Pinchart, Sakari Ailus
  Cc: linux-media, linux-kernel, Tomi Valkeinen

Use the new v4l2_subdev_get_frame_desc_passthrough helper for
.get_frame_desc.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen+renesas@ideasonboard.com>
---
 drivers/media/i2c/ds90ub953.c | 61 +------------------------------------------
 1 file changed, 1 insertion(+), 60 deletions(-)

diff --git a/drivers/media/i2c/ds90ub953.c b/drivers/media/i2c/ds90ub953.c
index 46569381b332..b5896d20f9c5 100644
--- a/drivers/media/i2c/ds90ub953.c
+++ b/drivers/media/i2c/ds90ub953.c
@@ -489,65 +489,6 @@ static int ub953_set_routing(struct v4l2_subdev *sd,
 	return _ub953_set_routing(sd, state, routing);
 }
 
-static int ub953_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad,
-				struct v4l2_mbus_frame_desc *fd)
-{
-	struct ub953_data *priv = sd_to_ub953(sd);
-	struct v4l2_mbus_frame_desc source_fd;
-	struct v4l2_subdev_route *route;
-	struct v4l2_subdev_state *state;
-	int ret;
-
-	if (pad != UB953_PAD_SOURCE)
-		return -EINVAL;
-
-	ret = v4l2_subdev_call(priv->source_sd, pad, get_frame_desc,
-			       priv->source_sd_pad, &source_fd);
-	if (ret)
-		return ret;
-
-	fd->type = V4L2_MBUS_FRAME_DESC_TYPE_CSI2;
-
-	state = v4l2_subdev_lock_and_get_active_state(sd);
-
-	for_each_active_route(&state->routing, route) {
-		struct v4l2_mbus_frame_desc_entry *source_entry = NULL;
-		unsigned int i;
-
-		if (route->source_pad != pad)
-			continue;
-
-		for (i = 0; i < source_fd.num_entries; i++) {
-			if (source_fd.entry[i].stream == route->sink_stream) {
-				source_entry = &source_fd.entry[i];
-				break;
-			}
-		}
-
-		if (!source_entry) {
-			dev_err(&priv->client->dev,
-				"Failed to find stream from source frame desc\n");
-			ret = -EPIPE;
-			goto out_unlock;
-		}
-
-		fd->entry[fd->num_entries].stream = route->source_stream;
-		fd->entry[fd->num_entries].flags = source_entry->flags;
-		fd->entry[fd->num_entries].length = source_entry->length;
-		fd->entry[fd->num_entries].pixelcode = source_entry->pixelcode;
-		fd->entry[fd->num_entries].bus.csi2.vc =
-			source_entry->bus.csi2.vc;
-		fd->entry[fd->num_entries].bus.csi2.dt =
-			source_entry->bus.csi2.dt;
-
-		fd->num_entries++;
-	}
-
-out_unlock:
-	v4l2_subdev_unlock_state(state);
-
-	return ret;
-}
 
 static int ub953_set_fmt(struct v4l2_subdev *sd,
 			 struct v4l2_subdev_state *state,
@@ -723,7 +664,7 @@ static const struct v4l2_subdev_pad_ops ub953_pad_ops = {
 	.enable_streams = ub953_enable_streams,
 	.disable_streams = ub953_disable_streams,
 	.set_routing = ub953_set_routing,
-	.get_frame_desc = ub953_get_frame_desc,
+	.get_frame_desc = v4l2_subdev_get_frame_desc_passthrough,
 	.get_fmt = v4l2_subdev_get_fmt,
 	.set_fmt = ub953_set_fmt,
 };

-- 
2.43.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v4 3/3] media: i2c: ds90ub913: Use v4l2_subdev_get_frame_desc_passthrough
  2025-03-24  8:04 [PATCH v4 0/3] media: subdev: Add v4l2_subdev_get_frame_desc_passthrough and use it Tomi Valkeinen
  2025-03-24  8:04 ` [PATCH v4 1/3] media: subdev: Add v4l2_subdev_get_frame_desc_passthrough helper Tomi Valkeinen
  2025-03-24  8:04 ` [PATCH v4 2/3] media: i2c: ds90ub953: Use v4l2_subdev_get_frame_desc_passthrough Tomi Valkeinen
@ 2025-03-24  8:04 ` Tomi Valkeinen
  2026-01-22 14:15 ` [PATCH v4 0/3] media: subdev: Add v4l2_subdev_get_frame_desc_passthrough and use it Tomi Valkeinen
  3 siblings, 0 replies; 6+ messages in thread
From: Tomi Valkeinen @ 2025-03-24  8:04 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Laurent Pinchart, Sakari Ailus
  Cc: linux-media, linux-kernel, Tomi Valkeinen

Use the new v4l2_subdev_get_frame_desc_passthrough helper for
.get_frame_desc.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen+renesas@ideasonboard.com>
---
 drivers/media/i2c/ds90ub913.c | 59 +------------------------------------------
 1 file changed, 1 insertion(+), 58 deletions(-)

diff --git a/drivers/media/i2c/ds90ub913.c b/drivers/media/i2c/ds90ub913.c
index fd2d2d5272bf..f3b9d2a84bad 100644
--- a/drivers/media/i2c/ds90ub913.c
+++ b/drivers/media/i2c/ds90ub913.c
@@ -358,63 +358,6 @@ static int ub913_set_routing(struct v4l2_subdev *sd,
 	return _ub913_set_routing(sd, state, routing);
 }
 
-static int ub913_get_frame_desc(struct v4l2_subdev *sd, unsigned int pad,
-				struct v4l2_mbus_frame_desc *fd)
-{
-	struct ub913_data *priv = sd_to_ub913(sd);
-	const struct v4l2_subdev_krouting *routing;
-	struct v4l2_mbus_frame_desc source_fd;
-	struct v4l2_subdev_route *route;
-	struct v4l2_subdev_state *state;
-	int ret;
-
-	if (pad != UB913_PAD_SOURCE)
-		return -EINVAL;
-
-	ret = v4l2_subdev_call(priv->source_sd, pad, get_frame_desc,
-			       priv->source_sd_pad, &source_fd);
-	if (ret)
-		return ret;
-
-	fd->type = V4L2_MBUS_FRAME_DESC_TYPE_PARALLEL;
-
-	state = v4l2_subdev_lock_and_get_active_state(sd);
-
-	routing = &state->routing;
-
-	for_each_active_route(routing, route) {
-		unsigned int i;
-
-		if (route->source_pad != pad)
-			continue;
-
-		for (i = 0; i < source_fd.num_entries; i++) {
-			if (source_fd.entry[i].stream == route->sink_stream)
-				break;
-		}
-
-		if (i == source_fd.num_entries) {
-			dev_err(&priv->client->dev,
-				"Failed to find stream from source frame desc\n");
-			ret = -EPIPE;
-			goto out_unlock;
-		}
-
-		fd->entry[fd->num_entries].stream = route->source_stream;
-		fd->entry[fd->num_entries].flags = source_fd.entry[i].flags;
-		fd->entry[fd->num_entries].length = source_fd.entry[i].length;
-		fd->entry[fd->num_entries].pixelcode =
-			source_fd.entry[i].pixelcode;
-
-		fd->num_entries++;
-	}
-
-out_unlock:
-	v4l2_subdev_unlock_state(state);
-
-	return ret;
-}
-
 static int ub913_set_fmt(struct v4l2_subdev *sd,
 			 struct v4l2_subdev_state *state,
 			 struct v4l2_subdev_format *format)
@@ -514,7 +457,7 @@ static const struct v4l2_subdev_pad_ops ub913_pad_ops = {
 	.enable_streams = ub913_enable_streams,
 	.disable_streams = ub913_disable_streams,
 	.set_routing = ub913_set_routing,
-	.get_frame_desc = ub913_get_frame_desc,
+	.get_frame_desc = v4l2_subdev_get_frame_desc_passthrough,
 	.get_fmt = v4l2_subdev_get_fmt,
 	.set_fmt = ub913_set_fmt,
 };

-- 
2.43.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v4 0/3] media: subdev: Add v4l2_subdev_get_frame_desc_passthrough and use it
  2025-03-24  8:04 [PATCH v4 0/3] media: subdev: Add v4l2_subdev_get_frame_desc_passthrough and use it Tomi Valkeinen
                   ` (2 preceding siblings ...)
  2025-03-24  8:04 ` [PATCH v4 3/3] media: i2c: ds90ub913: " Tomi Valkeinen
@ 2026-01-22 14:15 ` Tomi Valkeinen
  3 siblings, 0 replies; 6+ messages in thread
From: Tomi Valkeinen @ 2026-01-22 14:15 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Laurent Pinchart, Sakari Ailus, Jacopo Mondi
  Cc: linux-media, linux-kernel

Hi,

On 24/03/2025 10:04, Tomi Valkeinen wrote:
> When writing the exact same code the third time for Renesas, I thought
> we probably need a helper.
> 
>  Tomi

It's been a while, but the need for this series hasn't gone anywhere. I
will need to send a rebased version and re-test, but any comments before
I do that?

 Tomi

> Signed-off-by: Tomi Valkeinen <tomi.valkeinen+renesas@ideasonboard.com>
> ---
> Changes in v4:
> - Update the helper name in commit descriptions too
> - Link to v3: https://lore.kernel.org/r/20250324-frame-desc-passthrough-v3-0-993839a1f9b3@ideasonboard.com
> 
> Changes in v3:
> - Rename the helper to v4l2_subdev_get_frame_desc_passthrough()
> - Check for fd->entry[] array overflow
> - Add error prints (with dev_dbg)
> - Link to v2: https://lore.kernel.org/r/20250219-frame-desc-passthrough-v2-0-5135d57ecd6a@ideasonboard.com
> 
> Changes in v2:
> - Fix "uninitialized symbol 'ret'"
> - Reorder local variables
> - Link to v1: https://lore.kernel.org/r/20250218-frame-desc-passthrough-v1-0-a32458f53714@ideasonboard.com
> 
> ---
> Tomi Valkeinen (3):
>       media: subdev: Add v4l2_subdev_get_frame_desc_passthrough helper
>       media: i2c: ds90ub953: Use v4l2_subdev_get_frame_desc_passthrough
>       media: i2c: ds90ub913: Use v4l2_subdev_get_frame_desc_passthrough
> 
>  drivers/media/i2c/ds90ub913.c         |  59 +-----------------
>  drivers/media/i2c/ds90ub953.c         |  61 +-----------------
>  drivers/media/v4l2-core/v4l2-subdev.c | 113 ++++++++++++++++++++++++++++++++++
>  include/media/v4l2-subdev.h           |  22 +++++++
>  4 files changed, 137 insertions(+), 118 deletions(-)
> ---
> base-commit: f2151613e040973c868d28c8b00885dfab69eb75
> change-id: 20250218-frame-desc-passthrough-66805e413974
> 
> Best regards,


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v4 1/3] media: subdev: Add v4l2_subdev_get_frame_desc_passthrough helper
  2025-03-24  8:04 ` [PATCH v4 1/3] media: subdev: Add v4l2_subdev_get_frame_desc_passthrough helper Tomi Valkeinen
@ 2026-03-04 13:49   ` Sakari Ailus
  0 siblings, 0 replies; 6+ messages in thread
From: Sakari Ailus @ 2026-03-04 13:49 UTC (permalink / raw)
  To: Tomi Valkeinen
  Cc: Mauro Carvalho Chehab, Laurent Pinchart, linux-media, linux-kernel

Moi,

On Mon, Mar 24, 2025 at 10:04:44AM +0200, Tomi Valkeinen wrote:
> Add a helper for v4l2_subdev_pad_ops.v4l2_get_frame_desc operation. The
> helper can be used when the subdevice directly passes through the
> streams.
> 
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen+renesas@ideasonboard.com>
> ---
>  drivers/media/v4l2-core/v4l2-subdev.c | 113 ++++++++++++++++++++++++++++++++++
>  include/media/v4l2-subdev.h           |  22 +++++++
>  2 files changed, 135 insertions(+)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> index a3074f469b15..a415d3234ca6 100644
> --- a/drivers/media/v4l2-core/v4l2-subdev.c
> +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> @@ -2502,6 +2502,119 @@ int v4l2_subdev_s_stream_helper(struct v4l2_subdev *sd, int enable)
>  }
>  EXPORT_SYMBOL_GPL(v4l2_subdev_s_stream_helper);
>  
> +int v4l2_subdev_get_frame_desc_passthrough(struct v4l2_subdev *sd,
> +					   unsigned int pad,
> +					   struct v4l2_mbus_frame_desc *fd)
> +{
> +	const struct media_pad *pads = sd->entity.pads;
> +	struct media_pad *local_sink_pad;
> +	struct v4l2_subdev_route *route;
> +	struct v4l2_subdev_state *state;
> +	struct device *dev = sd->dev;
> +	int ret = 0;
> +
> +	if (WARN_ON(!(pads[pad].flags & MEDIA_PAD_FL_SOURCE)))
> +		return -EINVAL;
> +
> +	state = v4l2_subdev_lock_and_get_active_state(sd);
> +
> +	/* Iterate over sink pads */
> +	media_entity_for_each_pad(&sd->entity, local_sink_pad) {
> +		struct v4l2_mbus_frame_desc source_fd;
> +		bool have_source_fd = false;
> +
> +		if (!(local_sink_pad->flags & MEDIA_PAD_FL_SINK))
> +			continue;
> +
> +		/*
> +		 * Copy frame desc entries for the streams going from the sink
> +		 * pad to the requested pad
> +		 */
> +		for_each_active_route(&state->routing, route) {
> +			struct v4l2_mbus_frame_desc_entry *source_entry = NULL;
> +			struct media_pad *remote_source_pad;
> +			struct v4l2_subdev *remote_sd;
> +			unsigned int i;
> +
> +			if (route->source_pad != pad ||
> +			    route->sink_pad != local_sink_pad->index)
> +				continue;
> +
> +			if (!have_source_fd) {
> +				remote_source_pad = media_pad_remote_pad_unique(local_sink_pad);
> +				if (!remote_source_pad) {
> +					dev_dbg(dev, "Failed to find remote pad for sink pad %u\n",
> +						local_sink_pad->index);
> +					ret = -EINVAL;
> +					goto out_unlock;
> +				}
> +
> +				remote_sd = media_entity_to_v4l2_subdev(remote_source_pad->entity);
> +				if (!remote_sd) {
> +					ret = -EINVAL;
> +					goto out_unlock;
> +				}
> +
> +				ret = v4l2_subdev_call(remote_sd, pad,
> +						       get_frame_desc,
> +						       remote_source_pad->index,
> +						       &source_fd);
> +				if (ret) {
> +					dev_err(dev,
> +						"Failed to get frame desc from remote subdev %s\n",
> +						remote_sd->name);
> +					goto out_unlock;
> +				}
> +
> +				have_source_fd = true;
> +
> +				if (fd->num_entries == 0) {
> +					fd->type = source_fd.type;



> +				} else if (fd->type != source_fd.type) {
> +					dev_err(dev,
> +						"Frame desc type mismatch: %u != %u\n",
> +						fd->type, source_fd.type);
> +					ret = -EPIPE;
> +					goto out_unlock;
> +				}
> +			}
> +
> +			for (i = 0; i < source_fd.num_entries; i++) {

You could declare i here.

> +				if (source_fd.entry[i].stream == route->sink_stream) {
> +					source_entry = &source_fd.entry[i];
> +					break;
> +				}
> +			}
> +
> +			if (!source_entry) {
> +				dev_dbg(sd->dev,
> +					"Failed to find stream %u from source frame desc\n",
> +					route->sink_stream);
> +				ret = -EPIPE;
> +				goto out_unlock;
> +			}
> +
> +			if (fd->num_entries >= V4L2_FRAME_DESC_ENTRY_MAX) {

V4L2_FRAME_DESC_ENTRY_MAX is actually the size of the array. It'd be good
to rename the macro to reflect that. Of course that's out of scope right
now...

> +				dev_dbg(sd->dev, "Frame desc entry limit reached\n");
> +				ret = -ENOSPC;
> +				goto out_unlock;
> +			}
> +
> +			fd->entry[fd->num_entries] = *source_entry;
> +
> +			fd->entry[fd->num_entries].stream = route->source_stream;
> +
> +			fd->num_entries++;
> +		}
> +	}
> +
> +out_unlock:
> +	v4l2_subdev_unlock_state(state);
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(v4l2_subdev_get_frame_desc_passthrough);
> +
>  #endif /* CONFIG_VIDEO_V4L2_SUBDEV_API */
>  
>  #endif /* CONFIG_MEDIA_CONTROLLER */
> diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
> index 57f2bcb4eb16..7dc8625b131e 100644
> --- a/include/media/v4l2-subdev.h
> +++ b/include/media/v4l2-subdev.h
> @@ -1748,6 +1748,28 @@ int v4l2_subdev_disable_streams(struct v4l2_subdev *sd, u32 pad,
>   */
>  int v4l2_subdev_s_stream_helper(struct v4l2_subdev *sd, int enable);
>  
> +/**
> + * v4l2_subdev_get_frame_desc_passthrough() - Helper to implement the subdev
> + *	v4l2_get_frame_desc operation in simple passthrough cases
> + * @sd: The subdevice
> + * @pad: The source pad index
> + * @fd: The mbus frame desc
> + *
> + * Subdevice drivers that only pass through the streams can use this helper
> + * to implement the &v4l2_subdev_pad_ops.v4l2_get_frame_desc operation.
> + *
> + * The helper will call get_frame_desc on the subdevice's sources, create a new
> + * frame desc which contains only the streams on the given source pad. The data
> + * for each frame desc entry is copied directly from the data provided from the
> + * calls to the subdevice's sources, with the exception of the 'stream' field
> + * which is set according to the subdevice's routing table.

Could you add how different frame descriptor types are handled?

A follow-up patch would be nice.

> + *
> + * Return: 0 on success, or a negative error code otherwise.
> + */
> +int v4l2_subdev_get_frame_desc_passthrough(struct v4l2_subdev *sd,
> +					   unsigned int pad,
> +					   struct v4l2_mbus_frame_desc *fd);
> +
>  #endif /* CONFIG_VIDEO_V4L2_SUBDEV_API */
>  
>  #endif /* CONFIG_MEDIA_CONTROLLER */
> 

-- 
Kind regards,

Sakari Ailus

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-03-04 13:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-24  8:04 [PATCH v4 0/3] media: subdev: Add v4l2_subdev_get_frame_desc_passthrough and use it Tomi Valkeinen
2025-03-24  8:04 ` [PATCH v4 1/3] media: subdev: Add v4l2_subdev_get_frame_desc_passthrough helper Tomi Valkeinen
2026-03-04 13:49   ` Sakari Ailus
2025-03-24  8:04 ` [PATCH v4 2/3] media: i2c: ds90ub953: Use v4l2_subdev_get_frame_desc_passthrough Tomi Valkeinen
2025-03-24  8:04 ` [PATCH v4 3/3] media: i2c: ds90ub913: " Tomi Valkeinen
2026-01-22 14:15 ` [PATCH v4 0/3] media: subdev: Add v4l2_subdev_get_frame_desc_passthrough and use it Tomi Valkeinen

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®