]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
media: platform: video-mux: Register a subdev notifier
authorSteve Longerbeam <slongerbeam@gmail.com>
Sat, 29 Sep 2018 19:54:10 +0000 (15:54 -0400)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Thu, 4 Oct 2018 19:35:08 +0000 (15:35 -0400)
Parse neighbor remote devices on the video muxes input ports, add them to a
subdev notifier, and register the subdev notifier for the video mux, by
calling v4l2_async_register_fwnode_subdev().

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+samsung@kernel.org>
drivers/media/platform/Kconfig
drivers/media/platform/video-mux.c

index f6275874ec9ef4057fc718e70b802744b2c0170a..0edacfb01f3acba249df031789bdb14a45ed921b 100644 (file)
@@ -58,6 +58,7 @@ config VIDEO_MUX
        select MULTIPLEXER
        depends on VIDEO_V4L2 && OF && VIDEO_V4L2_SUBDEV_API && MEDIA_CONTROLLER
        select REGMAP
+       select V4L2_FWNODE
        help
          This driver provides support for N:1 video bus multiplexers.
 
index 61a9bf716a05292f2cbda43cf19f5fcc3f36b7ba..c33900e3c23ef4472374a0678eb175e6668d349a 100644 (file)
 #include <linux/of.h>
 #include <linux/of_graph.h>
 #include <linux/platform_device.h>
+#include <linux/slab.h>
 #include <media/v4l2-async.h>
 #include <media/v4l2-device.h>
+#include <media/v4l2-fwnode.h>
 #include <media/v4l2-subdev.h>
 
 struct video_mux {
@@ -316,6 +318,38 @@ static const struct v4l2_subdev_ops video_mux_subdev_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,
+                                   unsigned int num_input_pads)
+{
+       unsigned int i, *ports;
+       int ret;
+
+       ports = kcalloc(num_input_pads, sizeof(*ports), GFP_KERNEL);
+       if (!ports)
+               return -ENOMEM;
+       for (i = 0; i < num_input_pads; i++)
+               ports[i] = i;
+
+       ret = v4l2_async_register_fwnode_subdev(
+               &vmux->subdev, sizeof(struct v4l2_async_subdev),
+               ports, num_input_pads, video_mux_parse_endpoint);
+
+       kfree(ports);
+       return ret;
+}
+
 static int video_mux_probe(struct platform_device *pdev)
 {
        struct device_node *np = pdev->dev.of_node;
@@ -383,7 +417,7 @@ static int video_mux_probe(struct platform_device *pdev)
 
        vmux->subdev.entity.ops = &video_mux_ops;
 
-       return v4l2_async_register_subdev(&vmux->subdev);
+       return video_mux_async_register(vmux, num_pads - 1);
 }
 
 static int video_mux_remove(struct platform_device *pdev)