All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steve Longerbeam <slongerbeam@gmail.com>
To: linux-media@vger.kernel.org
Cc: Sakari Ailus <sakari.ailus@linux.intel.com>,
	Mauro Carvalho Chehab <mchehab+huawei@kernel.org>,
	Hans Verkuil <hverkuil-cisco@xs4all.nl>,
	Rui Miguel Silva <rmfrfs@gmail.com>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Philipp Zabel <p.zabel@pengutronix.de>,
	Steve Longerbeam <slongerbeam@gmail.com>
Subject: [PATCH v6 04/22] media: video-mux: Parse information from firmware without using callbacks
Date: Fri,  1 May 2020 10:15:38 -0700	[thread overview]
Message-ID: <20200501171556.14731-5-slongerbeam@gmail.com> (raw)
In-Reply-To: <20200501171556.14731-1-slongerbeam@gmail.com>

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: Steve Longerbeam <slongerbeam@gmail.com>
---
 drivers/media/platform/video-mux.c | 70 ++++++++++++++++++++----------
 1 file changed, 46 insertions(+), 24 deletions(-)

diff --git a/drivers/media/platform/video-mux.c b/drivers/media/platform/video-mux.c
index ddd0e338f9e4..7b6c96a29aa5 100644
--- a/drivers/media/platform/video-mux.c
+++ b/drivers/media/platform/video-mux.c
@@ -21,6 +21,7 @@
 
 struct video_mux {
 	struct v4l2_subdev subdev;
+	struct v4l2_async_notifier notifier;
 	struct media_pad *pads;
 	struct v4l2_mbus_framefmt *format_mbus;
 	struct mux_control *mux;
@@ -330,36 +331,49 @@ 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;
+	unsigned int i;
 	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;
+	v4l2_async_notifier_init(&vmux->notifier);
 
-	ret = v4l2_async_register_fwnode_subdev(
-		&vmux->subdev, sizeof(struct v4l2_async_subdev),
-		ports, num_input_pads, video_mux_parse_endpoint);
+	for (i = 0; i < num_input_pads; i++) {
+		struct v4l2_async_subdev *asd;
+		struct fwnode_handle *ep;
 
-	kfree(ports);
-	return ret;
+		ep = fwnode_graph_get_endpoint_by_id(
+			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)
@@ -434,7 +448,13 @@ static int video_mux_probe(struct platform_device *pdev)
 
 	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)
@@ -442,6 +462,8 @@ static int video_mux_remove(struct platform_device *pdev)
 	struct video_mux *vmux = platform_get_drvdata(pdev);
 	struct v4l2_subdev *sd = &vmux->subdev;
 
+	v4l2_async_notifier_unregister(&vmux->notifier);
+	v4l2_async_notifier_cleanup(&vmux->notifier);
 	v4l2_async_unregister_subdev(sd);
 	media_entity_cleanup(&sd->entity);
 
-- 
2.17.1


  parent reply	other threads:[~2020-05-01 17:16 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-01 17:15 [PATCH v6 00/22] media: imx: Create media links in bound notifiers Steve Longerbeam
2020-05-01 17:15 ` [PATCH v6 01/22] media: entity: Pass entity to get_fwnode_pad operation Steve Longerbeam
2020-05-01 17:15 ` [PATCH v6 02/22] media: v4l2-subdev: add v4l2_subdev_get_fwnode_pad_1_to_1 Steve Longerbeam
2020-05-01 17:15 ` [PATCH v6 03/22] media: v4l2-mc: add v4l2_create_fwnode_links helpers Steve Longerbeam
2020-05-01 17:15 ` Steve Longerbeam [this message]
2020-05-01 17:15 ` [PATCH v6 05/22] media: imx: Parse information from firmware without using callbacks Steve Longerbeam
2020-05-01 17:15 ` [PATCH v6 06/22] Revert "media: v4l2-fwnode: Add a convenience function for registering subdevs with notifiers" Steve Longerbeam
2020-05-01 17:15 ` [PATCH v6 07/22] media: imx: csi: Implement get_fwnode_pad op Steve Longerbeam
2020-05-01 17:15 ` [PATCH v6 08/22] media: video-mux: " Steve Longerbeam
2020-05-01 17:15 ` [PATCH v6 09/22] media: imx: mipi csi-2: " Steve Longerbeam
2020-05-01 17:15 ` [PATCH v6 10/22] media: imx: imx7-mipi-csis: " Steve Longerbeam
2020-05-04  9:14   ` Rui Miguel Silva
2020-05-01 17:15 ` [PATCH v6 11/22] media: imx: imx7-media-csi: " Steve Longerbeam
2020-05-04  9:14   ` Rui Miguel Silva
2020-05-01 17:15 ` [PATCH v6 12/22] media: video-mux: Create media links in bound notifier Steve Longerbeam
2020-05-01 17:15 ` [PATCH v6 13/22] media: imx: mipi csi-2: " Steve Longerbeam
2020-05-01 17:15 ` [PATCH v6 14/22] media: imx7: mipi csis: " Steve Longerbeam
2020-05-04  9:12   ` Rui Miguel Silva
2020-05-01 17:15 ` [PATCH v6 15/22] media: imx7: csi: " Steve Longerbeam
2020-05-01 17:15 ` [PATCH v6 16/22] media: imx: " Steve Longerbeam
2020-05-01 17:15 ` [PATCH v6 17/22] media: imx7: csi: Remove imx7_csi_get_upstream_endpoint() Steve Longerbeam
2020-05-04  9:10   ` Rui Miguel Silva
2020-05-01 17:15 ` [PATCH v6 18/22] media: imx5/6/7: csi: Mark a bound video mux as a CSI mux Steve Longerbeam
2020-05-04  9:12   ` Rui Miguel Silva
2020-05-01 17:15 ` [PATCH v6 19/22] media: imx: csi: Lookup upstream endpoint with imx_media_get_pad_fwnode Steve Longerbeam
2020-05-01 17:15 ` [PATCH v6 20/22] media: imx: Create missing links from CSI-2 receiver Steve Longerbeam
2020-05-01 17:15 ` [PATCH v6 21/22] media: imx: silence a couple debug messages Steve Longerbeam
2020-05-01 17:15 ` [PATCH v6 22/22] media: imx: TODO: Remove media link creation todos Steve Longerbeam

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200501171556.14731-5-slongerbeam@gmail.com \
    --to=slongerbeam@gmail.com \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab+huawei@kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=rmfrfs@gmail.com \
    --cc=sakari.ailus@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.