]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
media: v4l2-subdev: add v4l2_subdev_get_fwnode_pad_1_to_1
authorSteve Longerbeam <slongerbeam@gmail.com>
Fri, 1 May 2020 17:15:36 +0000 (19:15 +0200)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Mon, 18 May 2020 09:12:52 +0000 (11:12 +0200)
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>
drivers/media/v4l2-core/v4l2-subdev.c
include/media/v4l2-subdev.h

index 665b0c0f74cf8f937b7929d5d4b698fca9f5325a..6b989fe5a0a9ae970743d673d03463c59fd72437 100644 (file)
@@ -749,6 +749,28 @@ const struct v4l2_file_operations v4l2_subdev_fops = {
 };
 
 #ifdef CONFIG_MEDIA_CONTROLLER
+
+int v4l2_subdev_get_fwnode_pad_1_to_1(struct media_entity *entity,
+                                     struct fwnode_endpoint *endpoint)
+{
+       struct fwnode_handle *fwnode;
+       struct v4l2_subdev *sd;
+
+       if (!is_media_entity_v4l2_subdev(entity))
+               return -EINVAL;
+
+       sd = media_entity_to_v4l2_subdev(entity);
+
+       fwnode = fwnode_graph_get_port_parent(endpoint->local_fwnode);
+       fwnode_handle_put(fwnode);
+
+       if (dev_fwnode(sd->dev) == fwnode)
+               return endpoint->port;
+
+       return -ENXIO;
+}
+EXPORT_SYMBOL_GPL(v4l2_subdev_get_fwnode_pad_1_to_1);
+
 int v4l2_subdev_link_validate_default(struct v4l2_subdev *sd,
                                      struct media_link *link,
                                      struct v4l2_subdev_format *source_fmt,
index a4848de598521cece646f2b023009044b18c5726..f7fe78a6f65a9247a52eae90cca33a1d8a9342d6 100644 (file)
@@ -1027,6 +1027,23 @@ static inline void *v4l2_get_subdev_hostdata(const struct v4l2_subdev *sd)
 
 #ifdef CONFIG_MEDIA_CONTROLLER
 
+/**
+ * v4l2_subdev_get_fwnode_pad_1_to_1 - Get pad number from a subdev fwnode
+ *                                     endpoint, assuming 1:1 port:pad
+ *
+ * @entity - Pointer to the subdev entity
+ * @endpoint - Pointer to a parsed fwnode endpoint
+ *
+ * This function can be used as the .get_fwnode_pad operation for
+ * subdevices that map port numbers and pad indexes 1:1. If the endpoint
+ * is owned by the subdevice, the function returns the endpoint port
+ * number.
+ *
+ * Returns the endpoint port number on success or a negative error code.
+ */
+int v4l2_subdev_get_fwnode_pad_1_to_1(struct media_entity *entity,
+                                     struct fwnode_endpoint *endpoint);
+
 /**
  * v4l2_subdev_link_validate_default - validates a media link
  *