[PATCH 2/2] media: rcar-csi2: Let the driver handle fwnode matching using match_custom callback

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The rcar-csi2 driver uses the v4l2-async framework to do endpoint matching
instead of node matching. This is needed as it needs to work with the
adv748x driver which register it self in v4l2-async using endpoints
instead of nodes. The reason for this is that from a single DT node it
creates multiple subdevices, one for each endpoint.

But when using subdevs which register itself in v4l2-async using nodes,
the rcar-csi2 driver failed to find the matching endpoint because the
match.fwnode was pointing to remote endpoint instead of remote parent
port.

This commit adds support in rcar-csi2 driver to handle both the cases
where subdev registers in v4l2-async using endpoints/nodes, by using
match_type as V4L2_ASYNC_MATCH_CUSTOM and implementing the match()
callback to compare the fwnode of either remote/parent.

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@xxxxxxxxxxxxxx>
---
 drivers/media/platform/rcar-vin/rcar-csi2.c | 46 +++++++++++++++++++--
 1 file changed, 43 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c
index faa9fb23a2e9..1bbf05e9f025 100644
--- a/drivers/media/platform/rcar-vin/rcar-csi2.c
+++ b/drivers/media/platform/rcar-vin/rcar-csi2.c
@@ -808,6 +808,46 @@ static int rcsi2_parse_v4l2(struct rcar_csi2 *priv,
 	return 0;
 }
 
+static bool rcsi2_asd_match(struct v4l2_subdev *sd,
+			    struct v4l2_async_subdev *asd)
+{
+	struct rcar_csi2 *priv = (struct rcar_csi2 *)asd->match.custom.priv;
+	struct fwnode_handle *remote_endpoint;
+	struct fwnode_handle *subdev_endpoint;
+	struct device_node *np;
+	bool matched = false;
+
+	np = of_graph_get_endpoint_by_regs(priv->dev->of_node, 0, 0);
+	if (!np) {
+		dev_err(priv->dev, "Not connected to subdevice\n");
+		return matched;
+	}
+
+	remote_endpoint =
+		fwnode_graph_get_remote_endpoint(of_fwnode_handle(np));
+	if (!remote_endpoint) {
+		dev_err(priv->dev, "Failed to get remote endpoint\n");
+		of_node_put(np);
+		return matched;
+	}
+	of_node_put(np);
+
+	if (sd->fwnode != dev_fwnode(sd->dev)) {
+		if (remote_endpoint == sd->fwnode)
+			matched = true;
+	} else {
+		subdev_endpoint =
+		      fwnode_graph_get_next_endpoint(dev_fwnode(sd->dev), NULL);
+		if (remote_endpoint == subdev_endpoint)
+			matched = true;
+		fwnode_handle_put(subdev_endpoint);
+	}
+
+	fwnode_handle_put(remote_endpoint);
+
+	return matched;
+}
+
 static int rcsi2_parse_dt(struct rcar_csi2 *priv)
 {
 	struct device_node *ep;
@@ -833,9 +873,9 @@ static int rcsi2_parse_dt(struct rcar_csi2 *priv)
 		return ret;
 	}
 
-	priv->asd.match.fwnode =
-		fwnode_graph_get_remote_endpoint(of_fwnode_handle(ep));
-	priv->asd.match_type = V4L2_ASYNC_MATCH_FWNODE;
+	priv->asd.match.custom.match = &rcsi2_asd_match;
+	priv->asd.match.custom.priv = priv;
+	priv->asd.match_type = V4L2_ASYNC_MATCH_CUSTOM;
 
 	of_node_put(ep);
 
-- 
2.20.1




[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux