@@ -243,6 +243,20 @@ static bool media_entity_has_route(struct media_entity *entity,
return entity->ops->has_route(entity, pad0, pad1);
}
+struct media_pad *__media_entity_next_routed_pad(struct media_pad *root,
+ struct media_pad *iter)
+{
+ struct media_entity *entity = root->entity;
+
+ for (; iter < &entity->pads[entity->num_pads]; iter++) {
+ if (media_entity_has_route(entity, root->index, iter->index))
+ return iter;
+ }
+
+ return NULL;
+}
+EXPORT_SYMBOL_GPL(__media_entity_next_routed_pad);
+
/* push an entity to traversal stack */
static void stack_push(struct media_graph *graph, struct media_pad *pad)
{
@@ -904,6 +904,33 @@ int media_entity_get_fwnode_pad(struct media_entity *entity,
__must_check int media_graph_walk_init(
struct media_graph *graph, struct media_device *mdev);
+/**
+ * __media_entity_next_routed_pad - Get next pad connected to @root
+ *
+ * @root: The root pad to which the iterated pads have a route
+ * @iter: The iterator pad
+ *
+ * Get next pad which has a route to @root.
+ */
+struct media_pad *__media_entity_next_routed_pad(struct media_pad *root,
+ struct media_pad *iter);
+
+/**
+ * media_entity_for_each_routed_pad - Iterate over entity pads connected by
+ * routes
+ *
+ * @root: The root pad to which the iterated pads have a route
+ * @iter: The iterator pad
+ *
+ * Iterate over all pads of an entity which have an internal route to @root pad.
+ * The iteration will include the @root pad itself.
+ */
+#define media_entity_for_each_routed_pad(root, iter) \
+ for (iter = __media_entity_next_routed_pad(root, \
+ (root)->entity->pads); \
+ iter != NULL; \
+ iter = __media_entity_next_routed_pad(root, iter + 1))
+
/**
* media_graph_walk_cleanup - Release resources used by graph walk.
*