2021-03-10 12:22:17

by Prabhakar Mahadev Lad

[permalink] [raw]
Subject: [PATCH 0/3] media: i2c: imx219: Trivial Fixes

Hi All,

This patch series fixes trivial issues found in imx219 driver.

Cheers,
Prabhakar

Lad Prabhakar (3):
media: i2c: imx219: Enable vflip and hflip controls on stream stop
media: i2c: imx219: Serialize during stream start/stop
media: i2c: imx219: Balance runtime PM use-count in resume callback

drivers/media/i2c/imx219.c | 10 ++++++++++
1 file changed, 10 insertions(+)

--
2.17.1


2021-03-10 12:22:38

by Prabhakar Mahadev Lad

[permalink] [raw]
Subject: [PATCH 1/3] media: i2c: imx219: Enable vflip and hflip controls on stream stop

Enable vflip and hflip controls in resume error path when streaming
is stopped.

Fixes: 1283b3b8f82b9 ("media: i2c: Add driver for Sony IMX219 sensor")
Reported-by: Pavel Machek <[email protected]>
Signed-off-by: Lad Prabhakar <[email protected]>
---
drivers/media/i2c/imx219.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
index 6e3382b85a90..f0cf1985a4dc 100644
--- a/drivers/media/i2c/imx219.c
+++ b/drivers/media/i2c/imx219.c
@@ -1195,6 +1195,8 @@ static int __maybe_unused imx219_resume(struct device *dev)
error:
imx219_stop_streaming(imx219);
imx219->streaming = false;
+ __v4l2_ctrl_grab(imx219->vflip, false);
+ __v4l2_ctrl_grab(imx219->hflip, false);

return ret;
}
--
2.17.1

2021-03-10 12:23:43

by Prabhakar Mahadev Lad

[permalink] [raw]
Subject: [PATCH 3/3] media: i2c: imx219: Balance runtime PM use-count in resume callback

The runtime PM use-count gets incremented in imx219_set_stream() call
when streaming is started this needs to be balanced by calling
pm_runtime_put() upon failure to start stream in resume callback.

Fixes: 1283b3b8f82b9 ("media: i2c: Add driver for Sony IMX219 sensor")
Reported-by: Pavel Machek <[email protected]>
Signed-off-by: Lad Prabhakar <[email protected]>
---
drivers/media/i2c/imx219.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
index 87c021de1460..afffc85cd265 100644
--- a/drivers/media/i2c/imx219.c
+++ b/drivers/media/i2c/imx219.c
@@ -1184,6 +1184,7 @@ static int __maybe_unused imx219_resume(struct device *dev)
{
struct v4l2_subdev *sd = dev_get_drvdata(dev);
struct imx219 *imx219 = to_imx219(sd);
+ struct i2c_client *client;
int ret;

mutex_lock(&imx219->mutex);
@@ -1197,7 +1198,9 @@ static int __maybe_unused imx219_resume(struct device *dev)
return 0;

error:
+ client = v4l2_get_subdevdata(&imx219->sd);
imx219_stop_streaming(imx219);
+ pm_runtime_put(&client->dev);
imx219->streaming = false;
__v4l2_ctrl_grab(imx219->vflip, false);
__v4l2_ctrl_grab(imx219->hflip, false);
--
2.17.1

2021-03-10 12:24:56

by Prabhakar Mahadev Lad

[permalink] [raw]
Subject: [PATCH 2/3] media: i2c: imx219: Serialize during stream start/stop

Serialize during stream start/stop in suspend/resume callbacks.

Signed-off-by: Lad Prabhakar <[email protected]>
---
drivers/media/i2c/imx219.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
index f0cf1985a4dc..87c021de1460 100644
--- a/drivers/media/i2c/imx219.c
+++ b/drivers/media/i2c/imx219.c
@@ -1172,8 +1172,10 @@ static int __maybe_unused imx219_suspend(struct device *dev)
struct v4l2_subdev *sd = dev_get_drvdata(dev);
struct imx219 *imx219 = to_imx219(sd);

+ mutex_lock(&imx219->mutex);
if (imx219->streaming)
imx219_stop_streaming(imx219);
+ mutex_unlock(&imx219->mutex);

return 0;
}
@@ -1184,11 +1186,13 @@ static int __maybe_unused imx219_resume(struct device *dev)
struct imx219 *imx219 = to_imx219(sd);
int ret;

+ mutex_lock(&imx219->mutex);
if (imx219->streaming) {
ret = imx219_start_streaming(imx219);
if (ret)
goto error;
}
+ mutex_unlock(&imx219->mutex);

return 0;

@@ -1197,6 +1201,7 @@ static int __maybe_unused imx219_resume(struct device *dev)
imx219->streaming = false;
__v4l2_ctrl_grab(imx219->vflip, false);
__v4l2_ctrl_grab(imx219->hflip, false);
+ mutex_unlock(&imx219->mutex);

return ret;
}
--
2.17.1

2021-03-10 12:42:08

by Laurent Pinchart

[permalink] [raw]
Subject: Re: [PATCH 2/3] media: i2c: imx219: Serialize during stream start/stop

Hi Prabhakar,

Thank you for the patch.

On Wed, Mar 10, 2021 at 12:20:13PM +0000, Lad Prabhakar wrote:
> Serialize during stream start/stop in suspend/resume callbacks.

Could you please explain why this is needed ?

> Signed-off-by: Lad Prabhakar <[email protected]>
> ---
> drivers/media/i2c/imx219.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
> index f0cf1985a4dc..87c021de1460 100644
> --- a/drivers/media/i2c/imx219.c
> +++ b/drivers/media/i2c/imx219.c
> @@ -1172,8 +1172,10 @@ static int __maybe_unused imx219_suspend(struct device *dev)
> struct v4l2_subdev *sd = dev_get_drvdata(dev);
> struct imx219 *imx219 = to_imx219(sd);
>
> + mutex_lock(&imx219->mutex);
> if (imx219->streaming)
> imx219_stop_streaming(imx219);
> + mutex_unlock(&imx219->mutex);
>
> return 0;
> }
> @@ -1184,11 +1186,13 @@ static int __maybe_unused imx219_resume(struct device *dev)
> struct imx219 *imx219 = to_imx219(sd);
> int ret;
>
> + mutex_lock(&imx219->mutex);
> if (imx219->streaming) {
> ret = imx219_start_streaming(imx219);
> if (ret)
> goto error;
> }
> + mutex_unlock(&imx219->mutex);
>
> return 0;
>
> @@ -1197,6 +1201,7 @@ static int __maybe_unused imx219_resume(struct device *dev)
> imx219->streaming = false;
> __v4l2_ctrl_grab(imx219->vflip, false);
> __v4l2_ctrl_grab(imx219->hflip, false);
> + mutex_unlock(&imx219->mutex);
>
> return ret;
> }

--
Regards,

Laurent Pinchart

2021-03-10 12:46:31

by Laurent Pinchart

[permalink] [raw]
Subject: Re: [PATCH 1/3] media: i2c: imx219: Enable vflip and hflip controls on stream stop

Hi Prabhakar,

Thank you for the patch.

On Wed, Mar 10, 2021 at 12:20:12PM +0000, Lad Prabhakar wrote:
> Enable vflip and hflip controls in resume error path when streaming
> is stopped.
>
> Fixes: 1283b3b8f82b9 ("media: i2c: Add driver for Sony IMX219 sensor")
> Reported-by: Pavel Machek <[email protected]>
> Signed-off-by: Lad Prabhakar <[email protected]>
> ---
> drivers/media/i2c/imx219.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
> index 6e3382b85a90..f0cf1985a4dc 100644
> --- a/drivers/media/i2c/imx219.c
> +++ b/drivers/media/i2c/imx219.c
> @@ -1195,6 +1195,8 @@ static int __maybe_unused imx219_resume(struct device *dev)
> error:
> imx219_stop_streaming(imx219);
> imx219->streaming = false;
> + __v4l2_ctrl_grab(imx219->vflip, false);
> + __v4l2_ctrl_grab(imx219->hflip, false);

It's not very nice to do this manually in imx219_resume(). Shouldn't we
move the __v4l2_ctrl_grab() calls from imx219_set_stream() to
imx219_start_streaming() and imx219_stop_streaming() instead ?

>
> return ret;
> }

--
Regards,

Laurent Pinchart

2021-03-10 12:48:46

by Lad, Prabhakar

[permalink] [raw]
Subject: Re: [PATCH 2/3] media: i2c: imx219: Serialize during stream start/stop

Hi Laurent,

Thank you for the review.

On Wed, Mar 10, 2021 at 12:40 PM Laurent Pinchart
<[email protected]> wrote:
>
> Hi Prabhakar,
>
> Thank you for the patch.
>
> On Wed, Mar 10, 2021 at 12:20:13PM +0000, Lad Prabhakar wrote:
> > Serialize during stream start/stop in suspend/resume callbacks.
>
> Could you please explain why this is needed ?
>
The streaming variable in this driver has serialized access, but this
wasn't taken care during suspend/resume callbacks.

Cheers,
Prabhakar

> > Signed-off-by: Lad Prabhakar <[email protected]>
> > ---
> > drivers/media/i2c/imx219.c | 5 +++++
> > 1 file changed, 5 insertions(+)
> >
> > diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
> > index f0cf1985a4dc..87c021de1460 100644
> > --- a/drivers/media/i2c/imx219.c
> > +++ b/drivers/media/i2c/imx219.c
> > @@ -1172,8 +1172,10 @@ static int __maybe_unused imx219_suspend(struct device *dev)
> > struct v4l2_subdev *sd = dev_get_drvdata(dev);
> > struct imx219 *imx219 = to_imx219(sd);
> >
> > + mutex_lock(&imx219->mutex);
> > if (imx219->streaming)
> > imx219_stop_streaming(imx219);
> > + mutex_unlock(&imx219->mutex);
> >
> > return 0;
> > }
> > @@ -1184,11 +1186,13 @@ static int __maybe_unused imx219_resume(struct device *dev)
> > struct imx219 *imx219 = to_imx219(sd);
> > int ret;
> >
> > + mutex_lock(&imx219->mutex);
> > if (imx219->streaming) {
> > ret = imx219_start_streaming(imx219);
> > if (ret)
> > goto error;
> > }
> > + mutex_unlock(&imx219->mutex);
> >
> > return 0;
> >
> > @@ -1197,6 +1201,7 @@ static int __maybe_unused imx219_resume(struct device *dev)
> > imx219->streaming = false;
> > __v4l2_ctrl_grab(imx219->vflip, false);
> > __v4l2_ctrl_grab(imx219->hflip, false);
> > + mutex_unlock(&imx219->mutex);
> >
> > return ret;
> > }
>
> --
> Regards,
>
> Laurent Pinchart

2021-03-10 12:53:03

by Laurent Pinchart

[permalink] [raw]
Subject: Re: [PATCH 3/3] media: i2c: imx219: Balance runtime PM use-count in resume callback

Hi Prabhakar,

Thank you for the patch.

On Wed, Mar 10, 2021 at 12:20:14PM +0000, Lad Prabhakar wrote:
> The runtime PM use-count gets incremented in imx219_set_stream() call
> when streaming is started this needs to be balanced by calling
> pm_runtime_put() upon failure to start stream in resume callback.
>
> Fixes: 1283b3b8f82b9 ("media: i2c: Add driver for Sony IMX219 sensor")
> Reported-by: Pavel Machek <[email protected]>
> Signed-off-by: Lad Prabhakar <[email protected]>
> ---
> drivers/media/i2c/imx219.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
> index 87c021de1460..afffc85cd265 100644
> --- a/drivers/media/i2c/imx219.c
> +++ b/drivers/media/i2c/imx219.c
> @@ -1184,6 +1184,7 @@ static int __maybe_unused imx219_resume(struct device *dev)
> {
> struct v4l2_subdev *sd = dev_get_drvdata(dev);
> struct imx219 *imx219 = to_imx219(sd);
> + struct i2c_client *client;
> int ret;
>
> mutex_lock(&imx219->mutex);
> @@ -1197,7 +1198,9 @@ static int __maybe_unused imx219_resume(struct device *dev)
> return 0;
>
> error:
> + client = v4l2_get_subdevdata(&imx219->sd);
> imx219_stop_streaming(imx219);
> + pm_runtime_put(&client->dev);
> imx219->streaming = false;
> __v4l2_ctrl_grab(imx219->vflip, false);
> __v4l2_ctrl_grab(imx219->hflip, false);

Similarly to the __v4l2_ctrl_grab(), it could be better to move
pm_runtime_put() to imx219_stop_streaming().

--
Regards,

Laurent Pinchart

2021-03-10 12:56:18

by Laurent Pinchart

[permalink] [raw]
Subject: Re: [PATCH 2/3] media: i2c: imx219: Serialize during stream start/stop

Hi Prabhakar,

On Wed, Mar 10, 2021 at 12:46:39PM +0000, Lad, Prabhakar wrote:
> On Wed, Mar 10, 2021 at 12:40 PM Laurent Pinchart wrote:
> > On Wed, Mar 10, 2021 at 12:20:13PM +0000, Lad Prabhakar wrote:
> > > Serialize during stream start/stop in suspend/resume callbacks.
> >
> > Could you please explain why this is needed ?
> >
> The streaming variable in this driver has serialized access, but this
> wasn't taken care during suspend/resume callbacks.

But nothing that touches the streaming variable can run concurrently to
suspend/resume, isn't it ?

I'm actually even quite dubious about the need to start and stop
streaming during resume and suspend, the driver using the subdev should
start/stop the whole video pipeline at suspend/resume time.

> > > Signed-off-by: Lad Prabhakar <[email protected]>
> > > ---
> > > drivers/media/i2c/imx219.c | 5 +++++
> > > 1 file changed, 5 insertions(+)
> > >
> > > diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
> > > index f0cf1985a4dc..87c021de1460 100644
> > > --- a/drivers/media/i2c/imx219.c
> > > +++ b/drivers/media/i2c/imx219.c
> > > @@ -1172,8 +1172,10 @@ static int __maybe_unused imx219_suspend(struct device *dev)
> > > struct v4l2_subdev *sd = dev_get_drvdata(dev);
> > > struct imx219 *imx219 = to_imx219(sd);
> > >
> > > + mutex_lock(&imx219->mutex);
> > > if (imx219->streaming)
> > > imx219_stop_streaming(imx219);
> > > + mutex_unlock(&imx219->mutex);
> > >
> > > return 0;
> > > }
> > > @@ -1184,11 +1186,13 @@ static int __maybe_unused imx219_resume(struct device *dev)
> > > struct imx219 *imx219 = to_imx219(sd);
> > > int ret;
> > >
> > > + mutex_lock(&imx219->mutex);
> > > if (imx219->streaming) {
> > > ret = imx219_start_streaming(imx219);
> > > if (ret)
> > > goto error;
> > > }
> > > + mutex_unlock(&imx219->mutex);
> > >
> > > return 0;
> > >
> > > @@ -1197,6 +1201,7 @@ static int __maybe_unused imx219_resume(struct device *dev)
> > > imx219->streaming = false;
> > > __v4l2_ctrl_grab(imx219->vflip, false);
> > > __v4l2_ctrl_grab(imx219->hflip, false);
> > > + mutex_unlock(&imx219->mutex);
> > >
> > > return ret;
> > > }

--
Regards,

Laurent Pinchart

2021-03-10 13:10:40

by Lad, Prabhakar

[permalink] [raw]
Subject: Re: [PATCH 2/3] media: i2c: imx219: Serialize during stream start/stop

Hi Laurent,

On Wed, Mar 10, 2021 at 12:54 PM Laurent Pinchart
<[email protected]> wrote:
>
> Hi Prabhakar,
>
> On Wed, Mar 10, 2021 at 12:46:39PM +0000, Lad, Prabhakar wrote:
> > On Wed, Mar 10, 2021 at 12:40 PM Laurent Pinchart wrote:
> > > On Wed, Mar 10, 2021 at 12:20:13PM +0000, Lad Prabhakar wrote:
> > > > Serialize during stream start/stop in suspend/resume callbacks.
> > >
> > > Could you please explain why this is needed ?
> > >
> > The streaming variable in this driver has serialized access, but this
> > wasn't taken care during suspend/resume callbacks.
>
> But nothing that touches the streaming variable can run concurrently to
> suspend/resume, isn't it ?
>
You are right, we could drop this patch.

> I'm actually even quite dubious about the need to start and stop
> streaming during resume and suspend, the driver using the subdev should
> start/stop the whole video pipeline at suspend/resume time.
>
I see, do we have any documentation on how bridge/subdevs should
behave on suspend/resume ?

I did have a quick look at the omp3isp bridge driver and it does
start/stop on resume/suspend callbacks.

Cheers,
Prabhakar

> > > > Signed-off-by: Lad Prabhakar <[email protected]>
> > > > ---
> > > > drivers/media/i2c/imx219.c | 5 +++++
> > > > 1 file changed, 5 insertions(+)
> > > >
> > > > diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
> > > > index f0cf1985a4dc..87c021de1460 100644
> > > > --- a/drivers/media/i2c/imx219.c
> > > > +++ b/drivers/media/i2c/imx219.c
> > > > @@ -1172,8 +1172,10 @@ static int __maybe_unused imx219_suspend(struct device *dev)
> > > > struct v4l2_subdev *sd = dev_get_drvdata(dev);
> > > > struct imx219 *imx219 = to_imx219(sd);
> > > >
> > > > + mutex_lock(&imx219->mutex);
> > > > if (imx219->streaming)
> > > > imx219_stop_streaming(imx219);
> > > > + mutex_unlock(&imx219->mutex);
> > > >
> > > > return 0;
> > > > }
> > > > @@ -1184,11 +1186,13 @@ static int __maybe_unused imx219_resume(struct device *dev)
> > > > struct imx219 *imx219 = to_imx219(sd);
> > > > int ret;
> > > >
> > > > + mutex_lock(&imx219->mutex);
> > > > if (imx219->streaming) {
> > > > ret = imx219_start_streaming(imx219);
> > > > if (ret)
> > > > goto error;
> > > > }
> > > > + mutex_unlock(&imx219->mutex);
> > > >
> > > > return 0;
> > > >
> > > > @@ -1197,6 +1201,7 @@ static int __maybe_unused imx219_resume(struct device *dev)
> > > > imx219->streaming = false;
> > > > __v4l2_ctrl_grab(imx219->vflip, false);
> > > > __v4l2_ctrl_grab(imx219->hflip, false);
> > > > + mutex_unlock(&imx219->mutex);
> > > >
> > > > return ret;
> > > > }
>
> --
> Regards,
>
> Laurent Pinchart

2021-03-10 14:03:28

by Lad, Prabhakar

[permalink] [raw]
Subject: Re: [PATCH 3/3] media: i2c: imx219: Balance runtime PM use-count in resume callback

Hi Laurent,

Thank you for the review.

On Wed, Mar 10, 2021 at 12:49 PM Laurent Pinchart
<[email protected]> wrote:
>
> Hi Prabhakar,
>
> Thank you for the patch.
>
> On Wed, Mar 10, 2021 at 12:20:14PM +0000, Lad Prabhakar wrote:
> > The runtime PM use-count gets incremented in imx219_set_stream() call
> > when streaming is started this needs to be balanced by calling
> > pm_runtime_put() upon failure to start stream in resume callback.
> >
> > Fixes: 1283b3b8f82b9 ("media: i2c: Add driver for Sony IMX219 sensor")
> > Reported-by: Pavel Machek <[email protected]>
> > Signed-off-by: Lad Prabhakar <[email protected]>
> > ---
> > drivers/media/i2c/imx219.c | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
> > index 87c021de1460..afffc85cd265 100644
> > --- a/drivers/media/i2c/imx219.c
> > +++ b/drivers/media/i2c/imx219.c
> > @@ -1184,6 +1184,7 @@ static int __maybe_unused imx219_resume(struct device *dev)
> > {
> > struct v4l2_subdev *sd = dev_get_drvdata(dev);
> > struct imx219 *imx219 = to_imx219(sd);
> > + struct i2c_client *client;
> > int ret;
> >
> > mutex_lock(&imx219->mutex);
> > @@ -1197,7 +1198,9 @@ static int __maybe_unused imx219_resume(struct device *dev)
> > return 0;
> >
> > error:
> > + client = v4l2_get_subdevdata(&imx219->sd);
> > imx219_stop_streaming(imx219);
> > + pm_runtime_put(&client->dev);
> > imx219->streaming = false;
> > __v4l2_ctrl_grab(imx219->vflip, false);
> > __v4l2_ctrl_grab(imx219->hflip, false);
>
> Similarly to the __v4l2_ctrl_grab(), it could be better to move
> pm_runtime_put() to imx219_stop_streaming().
>
Agreed, moved this to imx219_stop_streaming().

Cheers,
Prabhakar

> --
> Regards,
>
> Laurent Pinchart

2021-03-10 14:05:53

by Lad, Prabhakar

[permalink] [raw]
Subject: Re: [PATCH 1/3] media: i2c: imx219: Enable vflip and hflip controls on stream stop

Hi Laurent,

Thank you for the review.

On Wed, Mar 10, 2021 at 12:45 PM Laurent Pinchart
<[email protected]> wrote:
>
> Hi Prabhakar,
>
> Thank you for the patch.
>
> On Wed, Mar 10, 2021 at 12:20:12PM +0000, Lad Prabhakar wrote:
> > Enable vflip and hflip controls in resume error path when streaming
> > is stopped.
> >
> > Fixes: 1283b3b8f82b9 ("media: i2c: Add driver for Sony IMX219 sensor")
> > Reported-by: Pavel Machek <[email protected]>
> > Signed-off-by: Lad Prabhakar <[email protected]>
> > ---
> > drivers/media/i2c/imx219.c | 2 ++
> > 1 file changed, 2 insertions(+)
> >
> > diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
> > index 6e3382b85a90..f0cf1985a4dc 100644
> > --- a/drivers/media/i2c/imx219.c
> > +++ b/drivers/media/i2c/imx219.c
> > @@ -1195,6 +1195,8 @@ static int __maybe_unused imx219_resume(struct device *dev)
> > error:
> > imx219_stop_streaming(imx219);
> > imx219->streaming = false;
> > + __v4l2_ctrl_grab(imx219->vflip, false);
> > + __v4l2_ctrl_grab(imx219->hflip, false);
>
> It's not very nice to do this manually in imx219_resume(). Shouldn't we
> move the __v4l2_ctrl_grab() calls from imx219_set_stream() to
> imx219_start_streaming() and imx219_stop_streaming() instead ?
>
Agreed, moved to respective functions.

Cheers,
Prabhakar

> >
> > return ret;
> > }
>
> --
> Regards,
>
> Laurent Pinchart