linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] v4l: async: Switch to endpoint node matching
@ 2020-08-07 11:16 Niklas Söderlund
  2020-08-07 11:16 ` [PATCH 1/2] v4l: async: Use endpoint node, not device node, for fwnode match Niklas Söderlund
  2020-08-07 11:16 ` [PATCH 2/2] rcar-csi2: Use V4L2 async helpers to create the notifier Niklas Söderlund
  0 siblings, 2 replies; 7+ messages in thread
From: Niklas Söderlund @ 2020-08-07 11:16 UTC (permalink / raw)
  To: Sakari Ailus, linux-media; +Cc: linux-renesas-soc, Niklas Söderlund

Hi,

With the recent merger of [1] in the media-tree it is finally possible 
to resurrect the last pieces of the work that started in 2017 :-)

Patch 1/2 switches the default behavior of V4L2 async to use endpoint 
node matching instead of device node matching. This is made possible by 
[1] where the matching logic is already changed to allow for both 
possibilities.

Patch 2/2 removes the special case in R-Car CSI-2 driver which have 
always used endpoint node matching since it needed to work with ADV748x 
that register multiple sub-devices using endpoint nodes in the async 
framework.

With this small series the split between V4L2 drivers that use endpoint 
vs device node matching is finally closed \o/.

1. b98158d837efa0b2 ("media: v4l2-async: Accept endpoints and devices for fwnode matching")

Niklas Söderlund (1):
  rcar-csi2: Use V4L2 async helpers to create the notifier

Sakari Ailus (1):
  v4l: async: Use endpoint node, not device node, for fwnode match

 drivers/media/platform/rcar-vin/rcar-csi2.c | 48 +++++----------------
 drivers/media/v4l2-core/v4l2-async.c        |  8 +++-
 drivers/media/v4l2-core/v4l2-fwnode.c       |  2 +-
 3 files changed, 18 insertions(+), 40 deletions(-)

-- 
2.28.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/2] v4l: async: Use endpoint node, not device node, for fwnode match
  2020-08-07 11:16 [PATCH 0/2] v4l: async: Switch to endpoint node matching Niklas Söderlund
@ 2020-08-07 11:16 ` Niklas Söderlund
  2020-08-11 22:19   ` Laurent Pinchart
  2020-08-07 11:16 ` [PATCH 2/2] rcar-csi2: Use V4L2 async helpers to create the notifier Niklas Söderlund
  1 sibling, 1 reply; 7+ messages in thread
From: Niklas Söderlund @ 2020-08-07 11:16 UTC (permalink / raw)
  To: Sakari Ailus, linux-media; +Cc: linux-renesas-soc, Niklas Söderlund

From: Sakari Ailus <sakari.ailus@linux.intel.com>

V4L2 async framework can use both device's fwnode and endpoints's fwnode
for matching the async sub-device with the sub-device. In order to proceed
moving towards endpoint matching assign the endpoint to the async
sub-device.

As most async sub-device drivers (and the related hardware) only supports
a single endpoint, use the first endpoint found. This works for all
current drivers --- we only ever supported a single async sub-device per
device to begin with.

For async devices that have no endpoints, continue to use the fwnode
related to the device. This includes e.g. lens devices.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
---
 drivers/media/v4l2-core/v4l2-async.c  | 8 ++++++--
 drivers/media/v4l2-core/v4l2-fwnode.c | 2 +-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c
index e3ab003a6c851881..f3b0338718e0f0a9 100644
--- a/drivers/media/v4l2-core/v4l2-async.c
+++ b/drivers/media/v4l2-core/v4l2-async.c
@@ -758,8 +758,12 @@ int v4l2_async_register_subdev(struct v4l2_subdev *sd)
 	 * (struct v4l2_subdev.dev), and async sub-device does not
 	 * exist independently of the device at any point of time.
 	 */
-	if (!sd->fwnode && sd->dev)
-		sd->fwnode = dev_fwnode(sd->dev);
+	if (!sd->fwnode && sd->dev) {
+		sd->fwnode = fwnode_graph_get_next_endpoint(
+			dev_fwnode(sd->dev), NULL);
+		if (!sd->fwnode)
+			sd->fwnode = dev_fwnode(sd->dev);
+	}
 
 	mutex_lock(&list_lock);
 
diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c
index a4c3c77c1894648e..79706129e28b668a 100644
--- a/drivers/media/v4l2-core/v4l2-fwnode.c
+++ b/drivers/media/v4l2-core/v4l2-fwnode.c
@@ -815,7 +815,7 @@ v4l2_async_notifier_fwnode_parse_endpoint(struct device *dev,
 
 	asd->match_type = V4L2_ASYNC_MATCH_FWNODE;
 	asd->match.fwnode =
-		fwnode_graph_get_remote_port_parent(endpoint);
+		fwnode_graph_get_remote_endpoint(endpoint);
 	if (!asd->match.fwnode) {
 		dev_dbg(dev, "no remote endpoint found\n");
 		ret = -ENOTCONN;
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] rcar-csi2: Use V4L2 async helpers to create the notifier
  2020-08-07 11:16 [PATCH 0/2] v4l: async: Switch to endpoint node matching Niklas Söderlund
  2020-08-07 11:16 ` [PATCH 1/2] v4l: async: Use endpoint node, not device node, for fwnode match Niklas Söderlund
@ 2020-08-07 11:16 ` Niklas Söderlund
  2020-08-10  9:36   ` Jacopo Mondi
                     ` (2 more replies)
  1 sibling, 3 replies; 7+ messages in thread
From: Niklas Söderlund @ 2020-08-07 11:16 UTC (permalink / raw)
  To: Sakari Ailus, linux-media; +Cc: linux-renesas-soc, Niklas Söderlund

The V4L2 async framework helpers now populates the async notifier with
endpoint matching information and there is no need to do this manually
in the R-Car CSI-2 driver, switch to using the provided helper.

Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
---
 drivers/media/platform/rcar-vin/rcar-csi2.c | 48 +++++----------------
 1 file changed, 11 insertions(+), 37 deletions(-)

diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c
index c6cc4f473a077899..f0067ff21d5d9d33 100644
--- a/drivers/media/platform/rcar-vin/rcar-csi2.c
+++ b/drivers/media/platform/rcar-vin/rcar-csi2.c
@@ -362,7 +362,6 @@ struct rcar_csi2 {
 	struct media_pad pads[NR_OF_RCAR_CSI2_PAD];
 
 	struct v4l2_async_notifier notifier;
-	struct v4l2_async_subdev asd;
 	struct v4l2_subdev *remote;
 
 	struct v4l2_mbus_framefmt mf;
@@ -774,9 +773,11 @@ static const struct v4l2_async_notifier_operations rcar_csi2_notify_ops = {
 	.unbind = rcsi2_notify_unbind,
 };
 
-static int rcsi2_parse_v4l2(struct rcar_csi2 *priv,
-			    struct v4l2_fwnode_endpoint *vep)
+static int rcar_csi2_parse_v4l2(struct device *dev,
+				struct v4l2_fwnode_endpoint *vep,
+				struct v4l2_async_subdev *asd)
 {
+	struct rcar_csi2 *priv = dev_get_drvdata(dev);
 	unsigned int i;
 
 	/* Only port 0 endpoint 0 is valid. */
@@ -806,53 +807,26 @@ static int rcsi2_parse_v4l2(struct rcar_csi2 *priv,
 		}
 	}
 
+	dev_dbg(priv->dev, "Found '%pOF'\n", to_of_node(asd->match.fwnode));
+
 	return 0;
 }
 
 static int rcsi2_parse_dt(struct rcar_csi2 *priv)
 {
-	struct device_node *ep;
-	struct v4l2_fwnode_endpoint v4l2_ep = { .bus_type = 0 };
 	int ret;
 
-	ep = of_graph_get_endpoint_by_regs(priv->dev->of_node, 0, 0);
-	if (!ep) {
-		dev_err(priv->dev, "Not connected to subdevice\n");
-		return -EINVAL;
-	}
-
-	ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep), &v4l2_ep);
-	if (ret) {
-		dev_err(priv->dev, "Could not parse v4l2 endpoint\n");
-		of_node_put(ep);
-		return -EINVAL;
-	}
-
-	ret = rcsi2_parse_v4l2(priv, &v4l2_ep);
-	if (ret) {
-		of_node_put(ep);
-		return ret;
-	}
-
-	priv->asd.match.fwnode =
-		fwnode_graph_get_remote_endpoint(of_fwnode_handle(ep));
-	priv->asd.match_type = V4L2_ASYNC_MATCH_FWNODE;
-
-	of_node_put(ep);
-
 	v4l2_async_notifier_init(&priv->notifier);
 
-	ret = v4l2_async_notifier_add_subdev(&priv->notifier, &priv->asd);
-	if (ret) {
-		fwnode_handle_put(priv->asd.match.fwnode);
+	ret = v4l2_async_notifier_parse_fwnode_endpoints_by_port(
+			priv->dev, &priv->notifier,
+			sizeof(struct v4l2_async_subdev), 0,
+			rcar_csi2_parse_v4l2);
+	if (ret)
 		return ret;
-	}
 
 	priv->notifier.ops = &rcar_csi2_notify_ops;
 
-	dev_dbg(priv->dev, "Found '%pOF'\n",
-		to_of_node(priv->asd.match.fwnode));
-
 	ret = v4l2_async_subdev_notifier_register(&priv->subdev,
 						  &priv->notifier);
 	if (ret)
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] rcar-csi2: Use V4L2 async helpers to create the notifier
  2020-08-07 11:16 ` [PATCH 2/2] rcar-csi2: Use V4L2 async helpers to create the notifier Niklas Söderlund
@ 2020-08-10  9:36   ` Jacopo Mondi
  2020-08-11 22:42   ` Laurent Pinchart
  2020-08-18  7:51   ` Sakari Ailus
  2 siblings, 0 replies; 7+ messages in thread
From: Jacopo Mondi @ 2020-08-10  9:36 UTC (permalink / raw)
  To: Niklas Söderlund; +Cc: Sakari Ailus, linux-media, linux-renesas-soc

Hi Niklas,

On Fri, Aug 07, 2020 at 01:16:19PM +0200, Niklas Söderlund wrote:
> The V4L2 async framework helpers now populates the async notifier with

helpers -> populate

> endpoint matching information and there is no need to do this manually

"with endpoint matching information" sounds weird.

What about

The V4L2 async framework helpers have now moved to match async
subdevices matching on endpoints. There is not need anymore to do this
manually...

> in the R-Car CSI-2 driver, switch to using the provided helper.
>
> Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> ---
>  drivers/media/platform/rcar-vin/rcar-csi2.c | 48 +++++----------------
>  1 file changed, 11 insertions(+), 37 deletions(-)
>
> diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c
> index c6cc4f473a077899..f0067ff21d5d9d33 100644
> --- a/drivers/media/platform/rcar-vin/rcar-csi2.c
> +++ b/drivers/media/platform/rcar-vin/rcar-csi2.c
> @@ -362,7 +362,6 @@ struct rcar_csi2 {
>  	struct media_pad pads[NR_OF_RCAR_CSI2_PAD];
>
>  	struct v4l2_async_notifier notifier;
> -	struct v4l2_async_subdev asd;
>  	struct v4l2_subdev *remote;
>
>  	struct v4l2_mbus_framefmt mf;
> @@ -774,9 +773,11 @@ static const struct v4l2_async_notifier_operations rcar_csi2_notify_ops = {
>  	.unbind = rcsi2_notify_unbind,
>  };
>
> -static int rcsi2_parse_v4l2(struct rcar_csi2 *priv,
> -			    struct v4l2_fwnode_endpoint *vep)
> +static int rcar_csi2_parse_v4l2(struct device *dev,
> +				struct v4l2_fwnode_endpoint *vep,
> +				struct v4l2_async_subdev *asd)
>  {
> +	struct rcar_csi2 *priv = dev_get_drvdata(dev);
>  	unsigned int i;
>
>  	/* Only port 0 endpoint 0 is valid. */
> @@ -806,53 +807,26 @@ static int rcsi2_parse_v4l2(struct rcar_csi2 *priv,
>  		}
>  	}
>
> +	dev_dbg(priv->dev, "Found '%pOF'\n", to_of_node(asd->match.fwnode));
> +
>  	return 0;
>  }
>
>  static int rcsi2_parse_dt(struct rcar_csi2 *priv)
>  {
> -	struct device_node *ep;
> -	struct v4l2_fwnode_endpoint v4l2_ep = { .bus_type = 0 };
>  	int ret;
>
> -	ep = of_graph_get_endpoint_by_regs(priv->dev->of_node, 0, 0);
> -	if (!ep) {
> -		dev_err(priv->dev, "Not connected to subdevice\n");
> -		return -EINVAL;
> -	}
> -
> -	ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep), &v4l2_ep);
> -	if (ret) {
> -		dev_err(priv->dev, "Could not parse v4l2 endpoint\n");
> -		of_node_put(ep);
> -		return -EINVAL;
> -	}
> -
> -	ret = rcsi2_parse_v4l2(priv, &v4l2_ep);
> -	if (ret) {
> -		of_node_put(ep);
> -		return ret;
> -	}
> -
> -	priv->asd.match.fwnode =
> -		fwnode_graph_get_remote_endpoint(of_fwnode_handle(ep));
> -	priv->asd.match_type = V4L2_ASYNC_MATCH_FWNODE;
> -
> -	of_node_put(ep);
> -
>  	v4l2_async_notifier_init(&priv->notifier);
>
> -	ret = v4l2_async_notifier_add_subdev(&priv->notifier, &priv->asd);
> -	if (ret) {
> -		fwnode_handle_put(priv->asd.match.fwnode);
> +	ret = v4l2_async_notifier_parse_fwnode_endpoints_by_port(
> +			priv->dev, &priv->notifier,
> +			sizeof(struct v4l2_async_subdev), 0,
> +			rcar_csi2_parse_v4l2);
> +	if (ret)

I have not really followed the whole call chain, but I presume
v4l2_async_notifier_parse_fwnode_endpoints_by_port() could fail after
having added the async subdev ? Is it worth calling notifier_cleanup()
if we fail here ?

This apart, the patch looks really nice, finally we're not the black
sheeps anymore!

Reviewed-by: Jacopo Mondi <jacopo+renesas@jmondi.org>

Thanks
   j

>  		return ret;
> -	}
>
>  	priv->notifier.ops = &rcar_csi2_notify_ops;
>
> -	dev_dbg(priv->dev, "Found '%pOF'\n",
> -		to_of_node(priv->asd.match.fwnode));
> -
>  	ret = v4l2_async_subdev_notifier_register(&priv->subdev,
>  						  &priv->notifier);
>  	if (ret)
> --
> 2.28.0
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] v4l: async: Use endpoint node, not device node, for fwnode match
  2020-08-07 11:16 ` [PATCH 1/2] v4l: async: Use endpoint node, not device node, for fwnode match Niklas Söderlund
@ 2020-08-11 22:19   ` Laurent Pinchart
  0 siblings, 0 replies; 7+ messages in thread
From: Laurent Pinchart @ 2020-08-11 22:19 UTC (permalink / raw)
  To: Niklas Söderlund; +Cc: Sakari Ailus, linux-media, linux-renesas-soc

Hi Niklas and Sakari,

Thank you for the patch.

On Fri, Aug 07, 2020 at 01:16:18PM +0200, Niklas Söderlund wrote:
> From: Sakari Ailus <sakari.ailus@linux.intel.com>
> 
> V4L2 async framework can use both device's fwnode and endpoints's fwnode
> for matching the async sub-device with the sub-device. In order to proceed
> moving towards endpoint matching assign the endpoint to the async
> sub-device.
> 
> As most async sub-device drivers (and the related hardware) only supports
> a single endpoint, use the first endpoint found. This works for all
> current drivers --- we only ever supported a single async sub-device per
> device to begin with.
> 
> For async devices that have no endpoints, continue to use the fwnode
> related to the device. This includes e.g. lens devices.
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> ---
>  drivers/media/v4l2-core/v4l2-async.c  | 8 ++++++--
>  drivers/media/v4l2-core/v4l2-fwnode.c | 2 +-
>  2 files changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c
> index e3ab003a6c851881..f3b0338718e0f0a9 100644
> --- a/drivers/media/v4l2-core/v4l2-async.c
> +++ b/drivers/media/v4l2-core/v4l2-async.c
> @@ -758,8 +758,12 @@ int v4l2_async_register_subdev(struct v4l2_subdev *sd)
>  	 * (struct v4l2_subdev.dev), and async sub-device does not
>  	 * exist independently of the device at any point of time.
>  	 */
> -	if (!sd->fwnode && sd->dev)
> -		sd->fwnode = dev_fwnode(sd->dev);
> +	if (!sd->fwnode && sd->dev) {
> +		sd->fwnode = fwnode_graph_get_next_endpoint(
> +			dev_fwnode(sd->dev), NULL);
> +		if (!sd->fwnode)
> +			sd->fwnode = dev_fwnode(sd->dev);

dev_fwnode() returns a borrowed reference, while
fwnode_graph_get_next_endpoint() returns a new reference. This will
cause a reference count issue, one way or another.

Otherwise, I think the change is good.

> +	}
>  
>  	mutex_lock(&list_lock);
>  
> diff --git a/drivers/media/v4l2-core/v4l2-fwnode.c b/drivers/media/v4l2-core/v4l2-fwnode.c
> index a4c3c77c1894648e..79706129e28b668a 100644
> --- a/drivers/media/v4l2-core/v4l2-fwnode.c
> +++ b/drivers/media/v4l2-core/v4l2-fwnode.c
> @@ -815,7 +815,7 @@ v4l2_async_notifier_fwnode_parse_endpoint(struct device *dev,
>  
>  	asd->match_type = V4L2_ASYNC_MATCH_FWNODE;
>  	asd->match.fwnode =
> -		fwnode_graph_get_remote_port_parent(endpoint);
> +		fwnode_graph_get_remote_endpoint(endpoint);
>  	if (!asd->match.fwnode) {
>  		dev_dbg(dev, "no remote endpoint found\n");
>  		ret = -ENOTCONN;

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] rcar-csi2: Use V4L2 async helpers to create the notifier
  2020-08-07 11:16 ` [PATCH 2/2] rcar-csi2: Use V4L2 async helpers to create the notifier Niklas Söderlund
  2020-08-10  9:36   ` Jacopo Mondi
@ 2020-08-11 22:42   ` Laurent Pinchart
  2020-08-18  7:51   ` Sakari Ailus
  2 siblings, 0 replies; 7+ messages in thread
From: Laurent Pinchart @ 2020-08-11 22:42 UTC (permalink / raw)
  To: Niklas Söderlund; +Cc: Sakari Ailus, linux-media, linux-renesas-soc

Hi Niklas,

Thank you for the patch.

On Fri, Aug 07, 2020 at 01:16:19PM +0200, Niklas Söderlund wrote:
> The V4L2 async framework helpers now populates the async notifier with
> endpoint matching information and there is no need to do this manually
> in the R-Car CSI-2 driver, switch to using the provided helper.
> 
> Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> ---
>  drivers/media/platform/rcar-vin/rcar-csi2.c | 48 +++++----------------
>  1 file changed, 11 insertions(+), 37 deletions(-)
> 
> diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c
> index c6cc4f473a077899..f0067ff21d5d9d33 100644
> --- a/drivers/media/platform/rcar-vin/rcar-csi2.c
> +++ b/drivers/media/platform/rcar-vin/rcar-csi2.c
> @@ -362,7 +362,6 @@ struct rcar_csi2 {
>  	struct media_pad pads[NR_OF_RCAR_CSI2_PAD];
>  
>  	struct v4l2_async_notifier notifier;
> -	struct v4l2_async_subdev asd;
>  	struct v4l2_subdev *remote;
>  
>  	struct v4l2_mbus_framefmt mf;
> @@ -774,9 +773,11 @@ static const struct v4l2_async_notifier_operations rcar_csi2_notify_ops = {
>  	.unbind = rcsi2_notify_unbind,
>  };
>  
> -static int rcsi2_parse_v4l2(struct rcar_csi2 *priv,
> -			    struct v4l2_fwnode_endpoint *vep)
> +static int rcar_csi2_parse_v4l2(struct device *dev,
> +				struct v4l2_fwnode_endpoint *vep,
> +				struct v4l2_async_subdev *asd)
>  {
> +	struct rcar_csi2 *priv = dev_get_drvdata(dev);
>  	unsigned int i;
>  
>  	/* Only port 0 endpoint 0 is valid. */
> @@ -806,53 +807,26 @@ static int rcsi2_parse_v4l2(struct rcar_csi2 *priv,
>  		}
>  	}
>  
> +	dev_dbg(priv->dev, "Found '%pOF'\n", to_of_node(asd->match.fwnode));
> +
>  	return 0;
>  }
>  
>  static int rcsi2_parse_dt(struct rcar_csi2 *priv)
>  {
> -	struct device_node *ep;
> -	struct v4l2_fwnode_endpoint v4l2_ep = { .bus_type = 0 };
>  	int ret;
>  
> -	ep = of_graph_get_endpoint_by_regs(priv->dev->of_node, 0, 0);
> -	if (!ep) {
> -		dev_err(priv->dev, "Not connected to subdevice\n");
> -		return -EINVAL;
> -	}
> -
> -	ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep), &v4l2_ep);
> -	if (ret) {
> -		dev_err(priv->dev, "Could not parse v4l2 endpoint\n");
> -		of_node_put(ep);
> -		return -EINVAL;
> -	}
> -
> -	ret = rcsi2_parse_v4l2(priv, &v4l2_ep);
> -	if (ret) {
> -		of_node_put(ep);
> -		return ret;
> -	}
> -
> -	priv->asd.match.fwnode =
> -		fwnode_graph_get_remote_endpoint(of_fwnode_handle(ep));
> -	priv->asd.match_type = V4L2_ASYNC_MATCH_FWNODE;
> -
> -	of_node_put(ep);
> -
>  	v4l2_async_notifier_init(&priv->notifier);
>  
> -	ret = v4l2_async_notifier_add_subdev(&priv->notifier, &priv->asd);
> -	if (ret) {
> -		fwnode_handle_put(priv->asd.match.fwnode);
> +	ret = v4l2_async_notifier_parse_fwnode_endpoints_by_port(
> +			priv->dev, &priv->notifier,
> +			sizeof(struct v4l2_async_subdev), 0,
> +			rcar_csi2_parse_v4l2);

It seems a bit expensive to go through a complex logic of iterating over
all endpoints when rcar_csi2_parse_v4l2() will only accept port 0,
endpoint 0, but there's a clear benefit from not having to maintain this
code in the driver.

With Jacopo's comments addressed,

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

If anyone has time to spend on it, I think
__v4l2_async_notifier_parse_fwnode_ep() should be duplicated in
v4l2_async_notifier_parse_fwnode_endpoints() and
v4l2_async_notifier_parse_fwnode_endpoints_by_port(), with the latter
only iterating over the endpoints of the requested port.

I also wonder if the !is_available check needs to be inside the loop:

	fwnode_graph_for_each_endpoint(dev_fwnode(dev), fwnode) {
		struct fwnode_handle *dev_fwnode;
		bool is_available;

		dev_fwnode = fwnode_graph_get_port_parent(fwnode);
		is_available = fwnode_device_is_available(dev_fwnode);
		fwnode_handle_put(dev_fwnode);
		if (!is_available)
			continue;

		...
	}

Isn't dev_fwnode == dev_fwnode(dev) and thus constant ?

> +	if (ret)
>  		return ret;
> -	}
>  
>  	priv->notifier.ops = &rcar_csi2_notify_ops;
>  
> -	dev_dbg(priv->dev, "Found '%pOF'\n",
> -		to_of_node(priv->asd.match.fwnode));
> -
>  	ret = v4l2_async_subdev_notifier_register(&priv->subdev,
>  						  &priv->notifier);
>  	if (ret)

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] rcar-csi2: Use V4L2 async helpers to create the notifier
  2020-08-07 11:16 ` [PATCH 2/2] rcar-csi2: Use V4L2 async helpers to create the notifier Niklas Söderlund
  2020-08-10  9:36   ` Jacopo Mondi
  2020-08-11 22:42   ` Laurent Pinchart
@ 2020-08-18  7:51   ` Sakari Ailus
  2 siblings, 0 replies; 7+ messages in thread
From: Sakari Ailus @ 2020-08-18  7:51 UTC (permalink / raw)
  To: Niklas Söderlund; +Cc: linux-media, linux-renesas-soc

Hi Niklas,

On Fri, Aug 07, 2020 at 01:16:19PM +0200, Niklas Söderlund wrote:
> The V4L2 async framework helpers now populates the async notifier with
> endpoint matching information and there is no need to do this manually
> in the R-Car CSI-2 driver, switch to using the provided helper.
> 
> Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> ---
>  drivers/media/platform/rcar-vin/rcar-csi2.c | 48 +++++----------------
>  1 file changed, 11 insertions(+), 37 deletions(-)
> 
> diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c
> index c6cc4f473a077899..f0067ff21d5d9d33 100644
> --- a/drivers/media/platform/rcar-vin/rcar-csi2.c
> +++ b/drivers/media/platform/rcar-vin/rcar-csi2.c
> @@ -362,7 +362,6 @@ struct rcar_csi2 {
>  	struct media_pad pads[NR_OF_RCAR_CSI2_PAD];
>  
>  	struct v4l2_async_notifier notifier;
> -	struct v4l2_async_subdev asd;
>  	struct v4l2_subdev *remote;
>  
>  	struct v4l2_mbus_framefmt mf;
> @@ -774,9 +773,11 @@ static const struct v4l2_async_notifier_operations rcar_csi2_notify_ops = {
>  	.unbind = rcsi2_notify_unbind,
>  };
>  
> -static int rcsi2_parse_v4l2(struct rcar_csi2 *priv,
> -			    struct v4l2_fwnode_endpoint *vep)
> +static int rcar_csi2_parse_v4l2(struct device *dev,
> +				struct v4l2_fwnode_endpoint *vep,
> +				struct v4l2_async_subdev *asd)
>  {
> +	struct rcar_csi2 *priv = dev_get_drvdata(dev);
>  	unsigned int i;
>  
>  	/* Only port 0 endpoint 0 is valid. */
> @@ -806,53 +807,26 @@ static int rcsi2_parse_v4l2(struct rcar_csi2 *priv,
>  		}
>  	}
>  
> +	dev_dbg(priv->dev, "Found '%pOF'\n", to_of_node(asd->match.fwnode));
> +
>  	return 0;
>  }
>  
>  static int rcsi2_parse_dt(struct rcar_csi2 *priv)
>  {
> -	struct device_node *ep;
> -	struct v4l2_fwnode_endpoint v4l2_ep = { .bus_type = 0 };
>  	int ret;
>  
> -	ep = of_graph_get_endpoint_by_regs(priv->dev->of_node, 0, 0);
> -	if (!ep) {
> -		dev_err(priv->dev, "Not connected to subdevice\n");
> -		return -EINVAL;
> -	}
> -
> -	ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep), &v4l2_ep);
> -	if (ret) {
> -		dev_err(priv->dev, "Could not parse v4l2 endpoint\n");
> -		of_node_put(ep);
> -		return -EINVAL;
> -	}
> -
> -	ret = rcsi2_parse_v4l2(priv, &v4l2_ep);
> -	if (ret) {
> -		of_node_put(ep);
> -		return ret;
> -	}
> -
> -	priv->asd.match.fwnode =
> -		fwnode_graph_get_remote_endpoint(of_fwnode_handle(ep));
> -	priv->asd.match_type = V4L2_ASYNC_MATCH_FWNODE;
> -
> -	of_node_put(ep);
> -
>  	v4l2_async_notifier_init(&priv->notifier);
>  
> -	ret = v4l2_async_notifier_add_subdev(&priv->notifier, &priv->asd);
> -	if (ret) {
> -		fwnode_handle_put(priv->asd.match.fwnode);
> +	ret = v4l2_async_notifier_parse_fwnode_endpoints_by_port(
> +			priv->dev, &priv->notifier,
> +			sizeof(struct v4l2_async_subdev), 0,
> +			rcar_csi2_parse_v4l2);

Please don't. We'd rather like to remove that helper that necessitates the
use of deprecated behaviour. This driver is the last user left actually.

Could you see an example in drivers/media/pci/intel/ipu3/ipu3-cio2.c on how
to make this more condensed?

There's more code left than with that helper as there are multiple things
done here, and a few of these things interact at least in the general case:

- setting binding defaults (missing here),

- parsing the DT as well as storing the configuration you need (should you
  not use the V4L2 EP as such),

- getting the remote and

- registration of the subdev in the notifier.

You should also set the bus_type field if you know that in advance --- I
believe you do.

> +	if (ret)
>  		return ret;
> -	}
>  
>  	priv->notifier.ops = &rcar_csi2_notify_ops;
>  
> -	dev_dbg(priv->dev, "Found '%pOF'\n",
> -		to_of_node(priv->asd.match.fwnode));
> -
>  	ret = v4l2_async_subdev_notifier_register(&priv->subdev,
>  						  &priv->notifier);
>  	if (ret)

-- 
Kind regards,

Sakari Ailus

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-08-18  7:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-07 11:16 [PATCH 0/2] v4l: async: Switch to endpoint node matching Niklas Söderlund
2020-08-07 11:16 ` [PATCH 1/2] v4l: async: Use endpoint node, not device node, for fwnode match Niklas Söderlund
2020-08-11 22:19   ` Laurent Pinchart
2020-08-07 11:16 ` [PATCH 2/2] rcar-csi2: Use V4L2 async helpers to create the notifier Niklas Söderlund
2020-08-10  9:36   ` Jacopo Mondi
2020-08-11 22:42   ` Laurent Pinchart
2020-08-18  7:51   ` Sakari Ailus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).