From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Martin Kepplinger <martin.kepplinger@puri.sm>
Cc: mchehab@kernel.org, kernel@puri.sm, linux-media@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 2/2] media: hi846: preserve the streaming state during system suspend
Date: Tue, 11 Apr 2023 14:15:12 +0300 [thread overview]
Message-ID: <20230411111512.GH11253@pendragon.ideasonboard.com> (raw)
In-Reply-To: <9ad81a9b2806272c715784985a3e0f52cda159c7.camel@puri.sm>
Hi Martin,
On Tue, Apr 11, 2023 at 11:39:32AM +0200, Martin Kepplinger wrote:
> Am Donnerstag, dem 06.04.2023 um 04:35 +0300 schrieb Laurent Pinchart:
> > On Wed, Apr 05, 2023 at 11:29:04AM +0200, Martin Kepplinger wrote:
> > > The hi846 driver changed the "streaming" state inside of "start/stop_streaming".
> > > The problem is that inside of the (system) suspend callback, it calls
> > > "stop_streaming" unconditionally. So streaming would always be stopped
> > > when suspending.
> > >
> > > That makes sense with runtime pm for example, after s_stream(..., 0) but
> > > does not preserve the "streaming" state during system suspend when
> > > currently streaming.
> >
> > The driver shouldn't need to stop streaming at system suspend time. It
> > should have had its .s_stream(0) operation called and shouldn't be
> > streaming anymore. If that's not the case, there's an issue somewhere
> > else, which should be fixed. The code that stops streaming at system
> > suspend and restarts it at system resume should then be dropped from
> > this driver.
> >
> > > Fix this by simply setting the streaming state outside of "start/stop_streaming"
> > > which is s_stream().
> > >
> > > While at it, improve things a bit by not assigning "1", but the "enable"
> > > value we later compare against, and fix one error handling path in
> > > resume().
> > >
> > > Signed-off-by: Martin Kepplinger <martin.kepplinger@puri.sm>
> > > ---
> > > drivers/media/i2c/hi846.c | 8 ++++----
> > > 1 file changed, 4 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/drivers/media/i2c/hi846.c b/drivers/media/i2c/hi846.c
> > > index 0b0eda2e223cd..1ca6e9407d618 100644
> > > --- a/drivers/media/i2c/hi846.c
> > > +++ b/drivers/media/i2c/hi846.c
> > > @@ -1780,8 +1780,6 @@ static int hi846_start_streaming(struct hi846 *hi846)
> > > return ret;
> > > }
> > >
> > > - hi846->streaming = 1;
> > > -
> > > dev_dbg(&client->dev, "%s: started streaming successfully\n", __func__);
> > >
> > > return ret;
> > > @@ -1793,8 +1791,6 @@ static void hi846_stop_streaming(struct hi846 *hi846)
> > >
> > > if (hi846_write_reg(hi846, HI846_REG_MODE_SELECT, HI846_MODE_STANDBY))
> > > dev_err(&client->dev, "failed to stop stream");
> > > -
> > > - hi846->streaming = 0;
> > > }
> > >
> > > static int hi846_set_stream(struct v4l2_subdev *sd, int enable)
> > > @@ -1816,10 +1812,12 @@ static int hi846_set_stream(struct v4l2_subdev *sd, int enable)
> > > }
> > >
> > > ret = hi846_start_streaming(hi846);
> > > + hi846->streaming = enable;
> > > }
> > >
> > > if (!enable || ret) {
> > > hi846_stop_streaming(hi846);
> > > + hi846->streaming = 0;
> > > pm_runtime_put(&client->dev);
> > > }
> > >
> > > @@ -1898,6 +1896,8 @@ static int __maybe_unused hi846_resume(struct device *dev)
> > > if (ret) {
> > > dev_err(dev, "%s: start streaming failed: %d\n",
> > > __func__, ret);
> > > + hi846_stop_streaming(hi846);
> > > + hi846->streaming = 0;
> > > goto error;
> > > }
> > > }
>
> hi Laurent,
>
> ok I see. My first test without any streaming-state handling in
> suspend/resume doesn't succeed. But now I know that's the goal and I'll
> put this on my list to do.
>
> Since this driver *already* tracks "streaming", would you be ok with
> this fix in the meantime?
I'd rather get a patch that drops streaming handling :-) It's fine
carrying a local patch in the Librem5 kernel to work around the problem
until a proper fix is available, but do we have a need to get the
workaround in mainline too ?
When it comes to a proper fix, it may be as simple as manually calling
device_link_add() in consumer (e.g. the CSI-2 receiver) drivers to
create links to suppliers(e.g. the camera sensor). The PM core should
then guarantee that the consumer gets suspended before the producer.
Would you be able to test that ?
--
Regards,
Laurent Pinchart
prev parent reply other threads:[~2023-04-11 11:15 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-05 9:29 [PATCH v1 0/2] media: hi846: support system suspend while streaming Martin Kepplinger
2023-04-05 9:29 ` [PATCH v1 1/2] media: hi846: fix usage of pm_runtime_get_if_in_use() Martin Kepplinger
2023-04-05 12:52 ` Sakari Ailus
2023-04-06 1:33 ` Laurent Pinchart
2023-04-06 13:36 ` Sakari Ailus
2023-04-07 4:32 ` Laurent Pinchart
2023-04-07 13:31 ` Martin Kepplinger
2023-04-07 18:37 ` Sakari Ailus
2023-04-06 1:32 ` Laurent Pinchart
2023-04-05 9:29 ` [PATCH v1 2/2] media: hi846: preserve the streaming state during system suspend Martin Kepplinger
2023-04-06 1:35 ` Laurent Pinchart
2023-04-11 9:39 ` Martin Kepplinger
2023-04-11 11:15 ` Laurent Pinchart [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230411111512.GH11253@pendragon.ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--cc=kernel@puri.sm \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=martin.kepplinger@puri.sm \
--cc=mchehab@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®