media: Accept non-subdev sinks in v4l2_create_fwnode_links_to_pad()

The v4l2_create_fwnode_links_to_pad() helper requires the sink pad
passed to it to belong to a subdev. This requirement can be lifted
easily. Make the function usable for non-subdev sinks, which allows
using it with video_device sinks.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
This commit is contained in:
Laurent Pinchart 2023-03-24 12:35:29 +02:00 committed by Hans Verkuil
parent 68a9ca452a
commit bd5a03bc5b
2 changed files with 10 additions and 13 deletions

View File

@ -313,14 +313,11 @@ int v4l2_create_fwnode_links_to_pad(struct v4l2_subdev *src_sd,
struct media_pad *sink, u32 flags) struct media_pad *sink, u32 flags)
{ {
struct fwnode_handle *endpoint; struct fwnode_handle *endpoint;
struct v4l2_subdev *sink_sd;
if (!(sink->flags & MEDIA_PAD_FL_SINK) || if (!(sink->flags & MEDIA_PAD_FL_SINK) ||
!is_media_entity_v4l2_subdev(sink->entity)) !is_media_entity_v4l2_subdev(sink->entity))
return -EINVAL; return -EINVAL;
sink_sd = media_entity_to_v4l2_subdev(sink->entity);
fwnode_graph_for_each_endpoint(dev_fwnode(src_sd->dev), endpoint) { fwnode_graph_for_each_endpoint(dev_fwnode(src_sd->dev), endpoint) {
struct fwnode_handle *remote_ep; struct fwnode_handle *remote_ep;
int src_idx, sink_idx, ret; int src_idx, sink_idx, ret;
@ -340,7 +337,7 @@ int v4l2_create_fwnode_links_to_pad(struct v4l2_subdev *src_sd,
* ask the sink to verify it owns the remote endpoint, * ask the sink to verify it owns the remote endpoint,
* and translate to a sink pad. * and translate to a sink pad.
*/ */
sink_idx = media_entity_get_fwnode_pad(&sink_sd->entity, sink_idx = media_entity_get_fwnode_pad(sink->entity,
remote_ep, remote_ep,
MEDIA_PAD_FL_SINK); MEDIA_PAD_FL_SINK);
fwnode_handle_put(remote_ep); fwnode_handle_put(remote_ep);
@ -362,17 +359,17 @@ int v4l2_create_fwnode_links_to_pad(struct v4l2_subdev *src_sd,
if (media_entity_find_link(src, sink)) if (media_entity_find_link(src, sink))
continue; continue;
dev_dbg(sink_sd->dev, "creating link %s:%d -> %s:%d\n", dev_dbg(src_sd->dev, "creating link %s:%d -> %s:%d\n",
src_sd->entity.name, src_idx, src_sd->entity.name, src_idx,
sink_sd->entity.name, sink_idx); sink->entity->name, sink_idx);
ret = media_create_pad_link(&src_sd->entity, src_idx, ret = media_create_pad_link(&src_sd->entity, src_idx,
&sink_sd->entity, sink_idx, flags); sink->entity, sink_idx, flags);
if (ret) { if (ret) {
dev_err(sink_sd->dev, dev_err(src_sd->dev,
"link %s:%d -> %s:%d failed with %d\n", "link %s:%d -> %s:%d failed with %d\n",
src_sd->entity.name, src_idx, src_sd->entity.name, src_idx,
sink_sd->entity.name, sink_idx, ret); sink->entity->name, sink_idx, ret);
fwnode_handle_put(endpoint); fwnode_handle_put(endpoint);
return ret; return ret;

View File

@ -87,17 +87,17 @@ int v4l_vb2q_enable_media_source(struct vb2_queue *q);
/** /**
* v4l2_create_fwnode_links_to_pad - Create fwnode-based links from a * v4l2_create_fwnode_links_to_pad - Create fwnode-based links from a
* source subdev to a sink subdev pad. * source subdev to a sink pad.
* *
* @src_sd: pointer to a source subdev * @src_sd: pointer to a source subdev
* @sink: pointer to a subdev sink pad * @sink: pointer to a sink pad
* @flags: the link flags * @flags: the link flags
* *
* This function searches for fwnode endpoint connections from a source * This function searches for fwnode endpoint connections from a source
* subdevice to a single sink pad, and if suitable connections are found, * subdevice to a single sink pad, and if suitable connections are found,
* translates them into media links to that pad. The function can be * translates them into media links to that pad. The function can be
* called by the sink subdevice, in its v4l2-async notifier subdev bound * called by the sink, in its v4l2-async notifier bound callback, to create
* callback, to create links from a bound source subdevice. * links from a bound source subdevice.
* *
* The @flags argument specifies the link flags. The caller shall ensure that * The @flags argument specifies the link flags. The caller shall ensure that
* the flags are valid regardless of the number of links that may be created. * the flags are valid regardless of the number of links that may be created.