diff mbox series

[v2,27/66] media: sun6i-csi: Add media ops with link notify callback

Message ID 20220205185429.2278860-28-paul.kocialkowski@bootlin.com (mailing list archive)
State New, archived
Headers show
Series Allwinner A31/A83T MIPI CSI-2 Support and A31 ISP Support | expand

Commit Message

Paul Kocialkowski Feb. 5, 2022, 6:53 p.m. UTC
In order to keep the power use count fields balanced when link changes
happen between v4l2_pipeline_pm_get/set calls (in open/close),
the link_notify media operation callback needs to be registered.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
---
 drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Sakari Ailus Feb. 14, 2022, 4:40 p.m. UTC | #1
Hi Paul,

Thanks for the update.

On Sat, Feb 05, 2022 at 07:53:50PM +0100, Paul Kocialkowski wrote:
> In order to keep the power use count fields balanced when link changes
> happen between v4l2_pipeline_pm_get/set calls (in open/close),
> the link_notify media operation callback needs to be registered.
> 
> Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
> ---
>  drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c
> index 6f04f86504bf..c8fe31cc38b5 100644
> --- a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c
> +++ b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c
> @@ -23,6 +23,7 @@
>  #include <linux/sched.h>
>  #include <linux/sizes.h>
>  #include <linux/slab.h>
> +#include <media/v4l2-mc.h>
>  
>  #include "sun6i_csi.h"
>  #include "sun6i_csi_reg.h"
> @@ -574,6 +575,12 @@ void sun6i_csi_set_stream(struct sun6i_csi_device *csi_dev, bool enable)
>  			   CSI_CAP_CH0_VCAP_ON);
>  }
>  
> +/* Media */
> +
> +static const struct media_device_ops sun6i_csi_media_ops = {
> +	.link_notify = v4l2_pipeline_link_notify,

Do you really need this?

Drivers should instead rely on runtime PM nowadays.

<URL:https://hverkuil.home.xs4all.nl/spec/driver-api/camera-sensor.html#power-management>

> +};
> +
>  /* V4L2 */
>  
>  static int sun6i_csi_link_entity(struct sun6i_csi_device *csi_dev,
> @@ -683,6 +690,7 @@ static int sun6i_csi_v4l2_setup(struct sun6i_csi_device *csi_dev)
>  	snprintf(media_dev->bus_info, sizeof(media_dev->bus_info),
>  		 "platform:%s", dev_name(dev));
>  	media_dev->hw_revision = 0;
> +	media_dev->ops = &sun6i_csi_media_ops;
>  	media_dev->dev = dev;
>  
>  	media_device_init(media_dev);
Paul Kocialkowski Feb. 15, 2022, 10:01 a.m. UTC | #2
Hi Sakari,

On Mon 14 Feb 22, 18:40, Sakari Ailus wrote:
> Hi Paul,
> 
> Thanks for the update.
> 
> On Sat, Feb 05, 2022 at 07:53:50PM +0100, Paul Kocialkowski wrote:
> > In order to keep the power use count fields balanced when link changes
> > happen between v4l2_pipeline_pm_get/set calls (in open/close),
> > the link_notify media operation callback needs to be registered.
> > 
> > Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
> > ---
> >  drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c | 8 ++++++++
> >  1 file changed, 8 insertions(+)
> > 
> > diff --git a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c
> > index 6f04f86504bf..c8fe31cc38b5 100644
> > --- a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c
> > +++ b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c
> > @@ -23,6 +23,7 @@
> >  #include <linux/sched.h>
> >  #include <linux/sizes.h>
> >  #include <linux/slab.h>
> > +#include <media/v4l2-mc.h>
> >  
> >  #include "sun6i_csi.h"
> >  #include "sun6i_csi_reg.h"
> > @@ -574,6 +575,12 @@ void sun6i_csi_set_stream(struct sun6i_csi_device *csi_dev, bool enable)
> >  			   CSI_CAP_CH0_VCAP_ON);
> >  }
> >  
> > +/* Media */
> > +
> > +static const struct media_device_ops sun6i_csi_media_ops = {
> > +	.link_notify = v4l2_pipeline_link_notify,
> 
> Do you really need this?
> 
> Drivers should instead rely on runtime PM nowadays.
> 
> <URL:https://hverkuil.home.xs4all.nl/spec/driver-api/camera-sensor.html#power-management>

See my remark on the patch adding support for runtime pm.

My understanding is that the callback is required when v4l2_pipeline_pm_get/set
is used, to keep the use count balanced (as mentionned in this commit message):
<https://hverkuil.home.xs4all.nl/spec/driver-api/v4l2-mc.html#c.v4l2_pipeline_pm_get>

Cheers,

Paul

> > +};
> > +
> >  /* V4L2 */
> >  
> >  static int sun6i_csi_link_entity(struct sun6i_csi_device *csi_dev,
> > @@ -683,6 +690,7 @@ static int sun6i_csi_v4l2_setup(struct sun6i_csi_device *csi_dev)
> >  	snprintf(media_dev->bus_info, sizeof(media_dev->bus_info),
> >  		 "platform:%s", dev_name(dev));
> >  	media_dev->hw_revision = 0;
> > +	media_dev->ops = &sun6i_csi_media_ops;
> >  	media_dev->dev = dev;
> >  
> >  	media_device_init(media_dev);
> 
> -- 
> Kind regards,
> 
> Sakari Ailus
diff mbox series

Patch

diff --git a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c
index 6f04f86504bf..c8fe31cc38b5 100644
--- a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c
+++ b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c
@@ -23,6 +23,7 @@ 
 #include <linux/sched.h>
 #include <linux/sizes.h>
 #include <linux/slab.h>
+#include <media/v4l2-mc.h>
 
 #include "sun6i_csi.h"
 #include "sun6i_csi_reg.h"
@@ -574,6 +575,12 @@  void sun6i_csi_set_stream(struct sun6i_csi_device *csi_dev, bool enable)
 			   CSI_CAP_CH0_VCAP_ON);
 }
 
+/* Media */
+
+static const struct media_device_ops sun6i_csi_media_ops = {
+	.link_notify = v4l2_pipeline_link_notify,
+};
+
 /* V4L2 */
 
 static int sun6i_csi_link_entity(struct sun6i_csi_device *csi_dev,
@@ -683,6 +690,7 @@  static int sun6i_csi_v4l2_setup(struct sun6i_csi_device *csi_dev)
 	snprintf(media_dev->bus_info, sizeof(media_dev->bus_info),
 		 "platform:%s", dev_name(dev));
 	media_dev->hw_revision = 0;
+	media_dev->ops = &sun6i_csi_media_ops;
 	media_dev->dev = dev;
 
 	media_device_init(media_dev);