]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
[media] media: entity: Add media_entity_get_fwnode_pad() function
authorNiklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Thu, 15 Jun 2017 09:17:26 +0000 (06:17 -0300)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>
Tue, 20 Jun 2017 12:09:37 +0000 (09:09 -0300)
This is a wrapper around the media entity get_fwnode_pad operation.

Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
drivers/media/media-entity.c
include/media/media-entity.h

index bc44193efa4798b449bb0cd345fd4bdbd4c25b6e..82d6755bd5d0d5f0e6adcf3107931fa4c67fef77 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <linux/bitmap.h>
 #include <linux/module.h>
+#include <linux/property.h>
 #include <linux/slab.h>
 #include <media/media-entity.h>
 #include <media/media-device.h>
@@ -386,6 +387,41 @@ struct media_entity *media_graph_walk_next(struct media_graph *graph)
 }
 EXPORT_SYMBOL_GPL(media_graph_walk_next);
 
+int media_entity_get_fwnode_pad(struct media_entity *entity,
+                               struct fwnode_handle *fwnode,
+                               unsigned long direction_flags)
+{
+       struct fwnode_endpoint endpoint;
+       unsigned int i;
+       int ret;
+
+       if (!entity->ops || !entity->ops->get_fwnode_pad) {
+               for (i = 0; i < entity->num_pads; i++) {
+                       if (entity->pads[i].flags & direction_flags)
+                               return i;
+               }
+
+               return -ENXIO;
+       }
+
+       ret = fwnode_graph_parse_endpoint(fwnode, &endpoint);
+       if (ret)
+               return ret;
+
+       ret = entity->ops->get_fwnode_pad(&endpoint);
+       if (ret < 0)
+               return ret;
+
+       if (ret >= entity->num_pads)
+               return -ENXIO;
+
+       if (!(entity->pads[ret].flags & direction_flags))
+               return -ENXIO;
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(media_entity_get_fwnode_pad);
+
 /* -----------------------------------------------------------------------------
  * Pipeline management
  */
index 46eeb036aa33053413f1baf3ddad7e5fc939e05c..754182d296689675f0254c30c7de2adb00c8d0a1 100644 (file)
@@ -820,6 +820,29 @@ struct media_pad *media_entity_remote_pad(struct media_pad *pad);
  */
 struct media_entity *media_entity_get(struct media_entity *entity);
 
+/**
+ * media_entity_get_fwnode_pad - Get pad number from fwnode
+ *
+ * @entity: The entity
+ * @fwnode: Pointer to the fwnode_handle which should be used to find the pad
+ * @direction_flags: Expected direction of the pad, as defined in
+ *                  :ref:`include/uapi/linux/media.h <media_header>`
+ *                  (seek for ``MEDIA_PAD_FL_*``)
+ *
+ * This function can be used to resolve the media pad number from
+ * a fwnode. This is useful for devices which use more complex
+ * mappings of media pads.
+ *
+ * If the entity dose not implement the get_fwnode_pad() operation
+ * then this function searches the entity for the first pad that
+ * matches the @direction_flags.
+ *
+ * Return: returns the pad number on success or a negative error code.
+ */
+int media_entity_get_fwnode_pad(struct media_entity *entity,
+                               struct fwnode_handle *fwnode,
+                               unsigned long direction_flags);
+
 /**
  * media_graph_walk_init - Allocate resources used by graph walk.
  *