Skip to content

Commit 8fe784b

Browse files
slongerbeammchehab
authored andcommitted
media: v4l2-subdev: add v4l2_subdev_get_fwnode_pad_1_to_1
Add a convenience function that can be used as the .get_fwnode_pad operation for subdevices that map port numbers and pad indexes 1:1. The function verifies the endpoint is owned by the subdevice, and if so returns the endpoint port number. Signed-off-by: Steve Longerbeam <slongerbeam@gmail.com> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
1 parent 70d4a9e commit 8fe784b

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

‎drivers/media/v4l2-core/v4l2-subdev.c‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,28 @@ const struct v4l2_file_operations v4l2_subdev_fops = {
749749
};
750750

751751
#ifdef CONFIG_MEDIA_CONTROLLER
752+
753+
int v4l2_subdev_get_fwnode_pad_1_to_1(struct media_entity *entity,
754+
struct fwnode_endpoint *endpoint)
755+
{
756+
struct fwnode_handle *fwnode;
757+
struct v4l2_subdev *sd;
758+
759+
if (!is_media_entity_v4l2_subdev(entity))
760+
return -EINVAL;
761+
762+
sd = media_entity_to_v4l2_subdev(entity);
763+
764+
fwnode = fwnode_graph_get_port_parent(endpoint->local_fwnode);
765+
fwnode_handle_put(fwnode);
766+
767+
if (dev_fwnode(sd->dev) == fwnode)
768+
return endpoint->port;
769+
770+
return -ENXIO;
771+
}
772+
EXPORT_SYMBOL_GPL(v4l2_subdev_get_fwnode_pad_1_to_1);
773+
752774
int v4l2_subdev_link_validate_default(struct v4l2_subdev *sd,
753775
struct media_link *link,
754776
struct v4l2_subdev_format *source_fmt,

‎include/media/v4l2-subdev.h‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,23 @@ static inline void *v4l2_get_subdev_hostdata(const struct v4l2_subdev *sd)
10271027

10281028
#ifdef CONFIG_MEDIA_CONTROLLER
10291029

1030+
/**
1031+
* v4l2_subdev_get_fwnode_pad_1_to_1 - Get pad number from a subdev fwnode
1032+
* endpoint, assuming 1:1 port:pad
1033+
*
1034+
* @entity - Pointer to the subdev entity
1035+
* @endpoint - Pointer to a parsed fwnode endpoint
1036+
*
1037+
* This function can be used as the .get_fwnode_pad operation for
1038+
* subdevices that map port numbers and pad indexes 1:1. If the endpoint
1039+
* is owned by the subdevice, the function returns the endpoint port
1040+
* number.
1041+
*
1042+
* Returns the endpoint port number on success or a negative error code.
1043+
*/
1044+
int v4l2_subdev_get_fwnode_pad_1_to_1(struct media_entity *entity,
1045+
struct fwnode_endpoint *endpoint);
1046+
10301047
/**
10311048
* v4l2_subdev_link_validate_default - validates a media link
10321049
*

0 commit comments

Comments
 (0)