Add a v4l2_subdev_has_route() helper function which can be used for media_entity_operations.has_route op. Signed-off-by: Tomi Valkeinen <tomi.valkeinen@xxxxxxxxxxxxxxxx> --- drivers/media/v4l2-core/v4l2-subdev.c | 30 +++++++++++++++++++++++++++ include/media/v4l2-subdev.h | 16 ++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index 0e1f325b3159..7497ad0f6024 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -999,6 +999,36 @@ int v4l2_subdev_link_validate(struct media_link *link) } EXPORT_SYMBOL_GPL(v4l2_subdev_link_validate); +bool v4l2_subdev_has_route(struct media_entity *entity, unsigned int pad0, unsigned int pad1) +{ + struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity); + struct v4l2_subdev_krouting *routing; + unsigned int i; + struct v4l2_subdev_state *state; + + state = v4l2_subdev_lock_active_state(sd); + + routing = &state->routing; + + for (i = 0; i < routing->num_routes; ++i) { + struct v4l2_subdev_route *route = &routing->routes[i]; + + if (!(route->flags & V4L2_SUBDEV_ROUTE_FL_ACTIVE)) + continue; + + if ((route->sink_pad == pad0 && route->source_pad == pad1) || + (route->source_pad == pad0 && route->sink_pad == pad1)) { + v4l2_subdev_unlock_state(state); + return true; + } + } + + v4l2_subdev_unlock_state(state); + + return false; +} +EXPORT_SYMBOL_GPL(v4l2_subdev_has_route); + struct v4l2_subdev_state * __v4l2_alloc_subdev_state(struct v4l2_subdev *sd, enum v4l2_subdev_format_whence which, diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h index cd6aad21ae0c..858e18aa5b20 100644 --- a/include/media/v4l2-subdev.h +++ b/include/media/v4l2-subdev.h @@ -1213,6 +1213,22 @@ int v4l2_subdev_link_validate_default(struct v4l2_subdev *sd, */ int v4l2_subdev_link_validate(struct media_link *link); +/** + * v4l2_subdev_has_route - MC has_route implementation for subdevs + * + * @entity: pointer to &struct media_entity + * @pad0: pad number for the first pad + * @pad1: pad number for the second pad + * + * This function looks at the routing in subdev's active state and returns if + * there is a route connecting pad0 and pad1. + * + * This function can be used as implementation for + * media_entity_operations.has_route. + */ +bool v4l2_subdev_has_route(struct media_entity *entity, unsigned int pad0, + unsigned int pad1); + /** * v4l2_alloc_subdev_state - allocate v4l2_subdev_state * -- 2.25.1