Re: [PATCH 2/9] media: rzg2l-cru: csi2: Add device_link from CSI-2 to sensor

Tommaso Merciai <[email protected]> Mon, 27 Jul 2026 17:41:42 +0200
Newsgroups org.kernel.vger.linux-renesas-soc,org.kernel.vger.linux-kernel,org.kernel.vger.linux-media
Message-ID <amd7-AqdfO33dpnu@tom-desktop>
Hi Jacopo,
Thanks for your review.

On Mon, Jul 27, 2026 at 11:48:59AM +0200, Jacopo Mondi wrote:
> Hi Tommaso
> 
> On Tue, Jun 16, 2026 at 07:05:32PM +0200, Tommaso Merciai wrote:
> > The CSI-2 receiver depends on its remote sensor being powered and
> > configured before it can receive data. Without an explicit device_link
> > the PM core has no knowledge of this dependency and may suspend the
> > sensor while CSI-2 is still active, or resume CSI-2 before the sensor
> > is ready.
> >
> > Add a DL_FLAG_STATELESS device_link from the CSI-2 device to the sensor
> > device when the sensor subdev binds. This instructs the PM core to
> > suspend CSI-2 before the sensor and to resume the sensor before CSI-2.
> > The link is deleted on unbind.
> >
> > Move csi2->remote_source assignment to the end of the function.
> >
> > Signed-off-by: Tommaso Merciai <[email protected]>
> > ---
> >  .../platform/renesas/rzg2l-cru/rzg2l-csi2.c   | 24 +++++++++++++++----
> >  1 file changed, 19 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c
> > index 6dc4b53607b4..3a4bc4ef72fc 100644
> > --- a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c
> > +++ b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c
> > @@ -773,15 +773,28 @@ static int rzg2l_csi2_notify_bound(struct v4l2_async_notifier *notifier,
> >  				   struct v4l2_async_connection *asd)
> >  {
> >  	struct rzg2l_csi2 *csi2 = notifier_to_csi2(notifier);
> > +	int ret;
> >
> > -	csi2->remote_source = subdev;
> > +	if (!device_link_add(csi2->dev, subdev->dev, DL_FLAG_STATELESS)) {
> 
> As cru-csi2 supports runtime suspend/resume, should you also add
> DL_FLAG_PM_RUNTIME ?

You are correct, as this driver supports runtime suspend/resume it
makes sense to also add DL_FLAG_PM_RUNTIME. Thanks for checking.
Will fix in v2.

Kind Regards,
Tommaso

> 
> > +		dev_err(csi2->dev, "Failed to create device link to sensor %s\n",
> > +			subdev->name);
> > +		return -EINVAL;
> > +	}
> >
> >  	dev_dbg(csi2->dev, "Bound subdev: %s pad\n", subdev->name);
> >
> > -	return media_create_pad_link(&subdev->entity, RZG2L_CSI2_SINK,
> > -				     &csi2->subdev.entity, 0,
> > -				     MEDIA_LNK_FL_ENABLED |
> > -				     MEDIA_LNK_FL_IMMUTABLE);
> > +	ret = media_create_pad_link(&subdev->entity, RZG2L_CSI2_SINK,
> > +				    &csi2->subdev.entity, 0,
> > +				    MEDIA_LNK_FL_ENABLED |
> > +				    MEDIA_LNK_FL_IMMUTABLE);
> > +	if (ret) {
> > +		device_link_remove(csi2->dev, subdev->dev);
> > +		return ret;
> > +	}
> > +
> > +	csi2->remote_source = subdev;
> > +
> > +	return 0;
> >  }
> >
> >  static void rzg2l_csi2_notify_unbind(struct v4l2_async_notifier *notifier,
> > @@ -790,6 +803,7 @@ static void rzg2l_csi2_notify_unbind(struct v4l2_async_notifier *notifier,
> >  {
> >  	struct rzg2l_csi2 *csi2 = notifier_to_csi2(notifier);
> >
> > +	device_link_remove(csi2->dev, subdev->dev);
> >  	csi2->remote_source = NULL;
> >
> >  	dev_dbg(csi2->dev, "Unbind subdev %s\n", subdev->name);
> > --
> > 2.54.0
> >