diff mbox series

[1/2] media: rcar-csi2: Fix registering camera endpoint to VIN

Message ID 20200228165011.17898-2-prabhakar.mahadev-lad.rj@bp.renesas.com (mailing list archive)
State New
Delegated to: Kieran Bingham
Headers show
Series media: rcar-vin: feature enhancement and fixes | expand

Commit Message

Prabhakar Feb. 28, 2020, 4:50 p.m. UTC
CSI2 registers camera/sensor as v4l2 async sub device with fwnode is
remote endpoint and the camera/sensor register itself as v4l2 sub device
with fwnode is remote device as a result the match.fwnode should be
fwnode_graph_get_remote_port_parent and not
fwnode_graph_get_remote_endpoint.

This patch makes use of v4l2 helper function
v4l2_async_notifier_add_fwnode_remote_subdev() which uses
fwnode_graph_get_remote_port_parent as match.fwnode fixing the issue
of registering camera endpoint to the driver.

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
---
 drivers/media/platform/rcar-vin/rcar-csi2.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

Comments

Niklas Söderlund March 4, 2020, 8:47 p.m. UTC | #1
Hi Lad,

Thanks for your work.

On 2020-02-28 16:50:10 +0000, Lad Prabhakar wrote:
> CSI2 registers camera/sensor as v4l2 async sub device with fwnode is
> remote endpoint and the camera/sensor register itself as v4l2 sub device
> with fwnode is remote device as a result the match.fwnode should be
> fwnode_graph_get_remote_port_parent and not
> fwnode_graph_get_remote_endpoint.
> 
> This patch makes use of v4l2 helper function
> v4l2_async_notifier_add_fwnode_remote_subdev() which uses
> fwnode_graph_get_remote_port_parent as match.fwnode fixing the issue
> of registering camera endpoint to the driver.
> 
> Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>

I'm afraid this is not the right solution. 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 IIRC.

Without this patch the two CSI-2 receivers on R-Car M3-n registers the 
two following 'paths' in v4l2 to be able to find the two subdevice CSI-2 
transmitters created by the ADV748x.

rcar-csi2 fea80000.csi2: '/soc/i2c@e66d8000/video-receiver@70/port@b/endpoint'
rcar-csi2 feaa0000.csi2: '/soc/i2c@e66d8000/video-receiver@70/port@a/endpoint'

With this patch applied it registers the following which can't be found 
as they are not present in the v4l2-async list of subdevices (as they 
are registerd as above).

rcar-csi2 fea80000.csi2: '/soc/i2c@e66d8000/video-receiver@70'
rcar-csi2 feaa0000.csi2: '/soc/i2c@e66d8000/video-receiver@70'
rcar-csi2: probe of feaa0000.csi2 failed with error -17

This patch may unlock your use-case as it's a known problem that 
endpoint and node matching do not mix. But it will break the already 
upstream use-case and for that reason, I'm really sorry about this.

Nacked-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

The real solution to this problem IMHO is to make all of v4l2-async 
operate using endpoint matching or possibly some kind of fallback to 
node matching if no endpoint can be found. Never the less some work is 
required in the v4l2-async core to sort out node and endpoint matching 
coexistence.

> ---
>  drivers/media/platform/rcar-vin/rcar-csi2.c | 14 ++++++--------
>  1 file changed, 6 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c
> index faa9fb23a2e9..5b04e4768eb1 100644
> --- a/drivers/media/platform/rcar-vin/rcar-csi2.c
> +++ b/drivers/media/platform/rcar-vin/rcar-csi2.c
> @@ -833,20 +833,18 @@ 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;
> -
> -	of_node_put(ep);
> -
>  	v4l2_async_notifier_init(&priv->notifier);
>  
> -	ret = v4l2_async_notifier_add_subdev(&priv->notifier, &priv->asd);
> +	ret = v4l2_async_notifier_add_fwnode_remote_subdev(&priv->notifier,
> +							   of_fwnode_handle(ep),
> +							   &priv->asd);
>  	if (ret) {
> -		fwnode_handle_put(priv->asd.match.fwnode);
> +		of_node_put(ep);
>  		return ret;
>  	}
>  
> +	of_node_put(ep);
> +
>  	priv->notifier.ops = &rcar_csi2_notify_ops;
>  
>  	dev_dbg(priv->dev, "Found '%pOF'\n",
> -- 
> 2.20.1
>
Prabhakar March 7, 2020, 1:03 p.m. UTC | #2
Hi Niklas,

Thank you for the review.

On Wed, Mar 4, 2020 at 8:47 PM Niklas <niklas.soderlund@ragnatech.se> wrote:
>
> Hi Lad,
>
> Thanks for your work.
>
> On 2020-02-28 16:50:10 +0000, Lad Prabhakar wrote:
> > CSI2 registers camera/sensor as v4l2 async sub device with fwnode is
> > remote endpoint and the camera/sensor register itself as v4l2 sub device
> > with fwnode is remote device as a result the match.fwnode should be
> > fwnode_graph_get_remote_port_parent and not
> > fwnode_graph_get_remote_endpoint.
> >
> > This patch makes use of v4l2 helper function
> > v4l2_async_notifier_add_fwnode_remote_subdev() which uses
> > fwnode_graph_get_remote_port_parent as match.fwnode fixing the issue
> > of registering camera endpoint to the driver.
> >
> > Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
>
> I'm afraid this is not the right solution. 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 IIRC.
>
> Without this patch the two CSI-2 receivers on R-Car M3-n registers the
> two following 'paths' in v4l2 to be able to find the two subdevice CSI-2
> transmitters created by the ADV748x.
>
> rcar-csi2 fea80000.csi2: '/soc/i2c@e66d8000/video-receiver@70/port@b/endpoint'
> rcar-csi2 feaa0000.csi2: '/soc/i2c@e66d8000/video-receiver@70/port@a/endpoint'
>
> With this patch applied it registers the following which can't be found
> as they are not present in the v4l2-async list of subdevices (as they
> are registerd as above).
>
> rcar-csi2 fea80000.csi2: '/soc/i2c@e66d8000/video-receiver@70'
> rcar-csi2 feaa0000.csi2: '/soc/i2c@e66d8000/video-receiver@70'
> rcar-csi2: probe of feaa0000.csi2 failed with error -17
>
> This patch may unlock your use-case as it's a known problem that
> endpoint and node matching do not mix. But it will break the already
> upstream use-case and for that reason, I'm really sorry about this.
>
Completely missed it, thank you for pointing out.

> Nacked-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
>
> The real solution to this problem IMHO is to make all of v4l2-async
> operate using endpoint matching or possibly some kind of fallback to
> node matching if no endpoint can be found. Never the less some work is
> required in the v4l2-async core to sort out node and endpoint matching
> coexistence.
>
Thank you for the pointers, I shall do some digging in v4l2-asyn.

Cheers,
--Prabhakar

> > ---
> >  drivers/media/platform/rcar-vin/rcar-csi2.c | 14 ++++++--------
> >  1 file changed, 6 insertions(+), 8 deletions(-)
> >
> > diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c
> > index faa9fb23a2e9..5b04e4768eb1 100644
> > --- a/drivers/media/platform/rcar-vin/rcar-csi2.c
> > +++ b/drivers/media/platform/rcar-vin/rcar-csi2.c
> > @@ -833,20 +833,18 @@ 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;
> > -
> > -     of_node_put(ep);
> > -
> >       v4l2_async_notifier_init(&priv->notifier);
> >
> > -     ret = v4l2_async_notifier_add_subdev(&priv->notifier, &priv->asd);
> > +     ret = v4l2_async_notifier_add_fwnode_remote_subdev(&priv->notifier,
> > +                                                        of_fwnode_handle(ep),
> > +                                                        &priv->asd);
> >       if (ret) {
> > -             fwnode_handle_put(priv->asd.match.fwnode);
> > +             of_node_put(ep);
> >               return ret;
> >       }
> >
> > +     of_node_put(ep);
> > +
> >       priv->notifier.ops = &rcar_csi2_notify_ops;
> >
> >       dev_dbg(priv->dev, "Found '%pOF'\n",
> > --
> > 2.20.1
> >
>
> --
> Regards,
> Niklas Söderlund
diff mbox series

Patch

diff --git a/drivers/media/platform/rcar-vin/rcar-csi2.c b/drivers/media/platform/rcar-vin/rcar-csi2.c
index faa9fb23a2e9..5b04e4768eb1 100644
--- a/drivers/media/platform/rcar-vin/rcar-csi2.c
+++ b/drivers/media/platform/rcar-vin/rcar-csi2.c
@@ -833,20 +833,18 @@  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;
-
-	of_node_put(ep);
-
 	v4l2_async_notifier_init(&priv->notifier);
 
-	ret = v4l2_async_notifier_add_subdev(&priv->notifier, &priv->asd);
+	ret = v4l2_async_notifier_add_fwnode_remote_subdev(&priv->notifier,
+							   of_fwnode_handle(ep),
+							   &priv->asd);
 	if (ret) {
-		fwnode_handle_put(priv->asd.match.fwnode);
+		of_node_put(ep);
 		return ret;
 	}
 
+	of_node_put(ep);
+
 	priv->notifier.ops = &rcar_csi2_notify_ops;
 
 	dev_dbg(priv->dev, "Found '%pOF'\n",