Commit f4d7a681 authored by Steve Longerbeam's avatar Steve Longerbeam Committed by Mauro Carvalho Chehab

media: video-mux: Parse information from firmware without using callbacks

Instead of using the convenience function
v4l2_async_register_fwnode_subdev(), parse the video-mux input endpoints
and set up the async sub-devices without using callbacks. The video-mux
knows which ports it must parse (the input ports) and how to handle
unconnected remotes, so it makes the code simpler to transfer control
of endpoint parsing to the driver.
Signed-off-by: default avatarSteve Longerbeam <slongerbeam@gmail.com>
Signed-off-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent 0d3c81e8
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
struct video_mux { struct video_mux {
struct v4l2_subdev subdev; struct v4l2_subdev subdev;
struct v4l2_async_notifier notifier;
struct media_pad *pads; struct media_pad *pads;
struct v4l2_mbus_framefmt *format_mbus; struct v4l2_mbus_framefmt *format_mbus;
struct mux_control *mux; struct mux_control *mux;
...@@ -330,36 +331,49 @@ static const struct v4l2_subdev_ops video_mux_subdev_ops = { ...@@ -330,36 +331,49 @@ static const struct v4l2_subdev_ops video_mux_subdev_ops = {
.video = &video_mux_subdev_video_ops, .video = &video_mux_subdev_video_ops,
}; };
static int video_mux_parse_endpoint(struct device *dev,
struct v4l2_fwnode_endpoint *vep,
struct v4l2_async_subdev *asd)
{
/*
* it's not an error if remote is missing on a video-mux
* input port, return -ENOTCONN to skip this endpoint with
* no error.
*/
return fwnode_device_is_available(asd->match.fwnode) ? 0 : -ENOTCONN;
}
static int video_mux_async_register(struct video_mux *vmux, static int video_mux_async_register(struct video_mux *vmux,
unsigned int num_input_pads) unsigned int num_input_pads)
{ {
unsigned int i, *ports; unsigned int i;
int ret; int ret;
ports = kcalloc(num_input_pads, sizeof(*ports), GFP_KERNEL); v4l2_async_notifier_init(&vmux->notifier);
if (!ports)
return -ENOMEM;
for (i = 0; i < num_input_pads; i++)
ports[i] = i;
ret = v4l2_async_register_fwnode_subdev( for (i = 0; i < num_input_pads; i++) {
&vmux->subdev, sizeof(struct v4l2_async_subdev), struct v4l2_async_subdev *asd;
ports, num_input_pads, video_mux_parse_endpoint); struct fwnode_handle *ep;
kfree(ports); ep = fwnode_graph_get_endpoint_by_id(
return ret; dev_fwnode(vmux->subdev.dev), i, 0,
FWNODE_GRAPH_ENDPOINT_NEXT);
if (!ep)
continue;
asd = kzalloc(sizeof(*asd), GFP_KERNEL);
if (!asd) {
fwnode_handle_put(ep);
return -ENOMEM;
}
ret = v4l2_async_notifier_add_fwnode_remote_subdev(
&vmux->notifier, ep, asd);
fwnode_handle_put(ep);
if (ret) {
kfree(asd);
/* OK if asd already exists */
if (ret != -EEXIST)
return ret;
}
}
ret = v4l2_async_subdev_notifier_register(&vmux->subdev,
&vmux->notifier);
if (ret)
return ret;
return v4l2_async_register_subdev(&vmux->subdev);
} }
static int video_mux_probe(struct platform_device *pdev) static int video_mux_probe(struct platform_device *pdev)
...@@ -434,7 +448,13 @@ static int video_mux_probe(struct platform_device *pdev) ...@@ -434,7 +448,13 @@ static int video_mux_probe(struct platform_device *pdev)
vmux->subdev.entity.ops = &video_mux_ops; vmux->subdev.entity.ops = &video_mux_ops;
return video_mux_async_register(vmux, num_pads - 1); ret = video_mux_async_register(vmux, num_pads - 1);
if (ret) {
v4l2_async_notifier_unregister(&vmux->notifier);
v4l2_async_notifier_cleanup(&vmux->notifier);
}
return ret;
} }
static int video_mux_remove(struct platform_device *pdev) static int video_mux_remove(struct platform_device *pdev)
...@@ -442,6 +462,8 @@ static int video_mux_remove(struct platform_device *pdev) ...@@ -442,6 +462,8 @@ static int video_mux_remove(struct platform_device *pdev)
struct video_mux *vmux = platform_get_drvdata(pdev); struct video_mux *vmux = platform_get_drvdata(pdev);
struct v4l2_subdev *sd = &vmux->subdev; struct v4l2_subdev *sd = &vmux->subdev;
v4l2_async_notifier_unregister(&vmux->notifier);
v4l2_async_notifier_cleanup(&vmux->notifier);
v4l2_async_unregister_subdev(sd); v4l2_async_unregister_subdev(sd);
media_entity_cleanup(&sd->entity); media_entity_cleanup(&sd->entity);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment