Linux-i2c Archive mirror
 help / color / mirror / Atom feed
From: Andi Shyti <andi.shyti@kernel.org>
To: JiSheng Teoh <jisheng.teoh@starfivetech.com>
Cc: Michal Simek <michal.simek@amd.com>,
	 Leyfoon Tan <leyfoon.tan@starfivetech.com>,
	 "linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"linux-i2c@vger.kernel.org" <linux-i2c@vger.kernel.org>,
	 "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 RESEND] i2c: cadence: Add system suspend and resume PM support
Date: Wed, 24 Jan 2024 13:53:07 +0100	[thread overview]
Message-ID: <y2sxh2jkvujnaxeknbunogkumywjlohp3hi6dkf5dkc3qko27s@vg2qggq7lzrz> (raw)
In-Reply-To: <ZQ0PR01MB1160DC63A1CC70F79036057EEB7BA@ZQ0PR01MB1160.CHNPR01.prod.partner.outlook.cn>

Hi Jisheng,

On Wed, Jan 24, 2024 at 04:46:43AM +0000, JiSheng Teoh wrote:
> Hi Andi,
> > 
> > ...
> > 
> > > > > +static int __maybe_unused cdns_i2c_resume(struct device *dev) {
> > > > > +	struct cdns_i2c *xi2c = dev_get_drvdata(dev);
> > > > > +	int err;
> > > > > +
> > > > > +	err = cdns_i2c_runtime_resume(dev);
> > > > > +	if (err)
> > > > > +		return err;
> > > > > +
> > > > > +	if (pm_runtime_status_suspended(dev)) {
> > > > > +		err = cdns_i2c_runtime_suspend(dev);
> > > > > +		if (err)
> > > > > +			return err;
> > > >
> > > > We call the cdns_i2c_resume() functions to come up from a suspended
> > > > state. But, if we fail to resume, we call the suspend and return '0' (because this always returns '0').
> > > >
> > > > In other words, if we take this path, we call resume, but we still end up suspended and return success.
> > > >
> > > > Andi
> > > >
> > >
> > > My understanding is that during system level resume 'cdns_i2c_resume()', the i2c device itself can still be held in runtime suspend
> > regardless of the change in system level PM.
> > > Looking back at this, we invoke cdns_i2c_runtime_resume() to enable clock and init the i2c device, the runtime PM state is still
> > unchanged and kept suspended.
> > > pm_runtime_status_suspended() will be evaluated as true, and runtime suspend 'cdns_i2c_runtime_suspend()' is invoked to
> > disable the clock. This balances the clock count enabled earlier.
> > 
> > If this is your issue, what if we do not enable the clock during resume? and we just mark the device as resumed?
> > 
> That will work as well. The i2c device will be runtime resumed again during cdns_i2c_master_xfer() anyway, but thought that it
> would be a good idea to check if the i2c device is able runtime resume during a system level resume.

That's fine, I think it might work this way, as well, so let's
keept it at your original implementation.

If we save here, we add complication somewhere else.

Reviewed-by: Andi Shyti <andi.shyti@kernel.org>

Before applying the patch I will read it again to make sure all
is balanced.

Thanks,
Andi

> > > The runtime PM state is only resumed during cdns_i2c_master_xfer() through pm_runtime_resume_and_get(), and subsequently
> > kept suspended through pm_runtime_put_autosuspend().
> > > Since the cdns_i2c_runtime_suspend() always return '0', I will simplify them as follow:
> > > +if (pm_runtime_status_suspended(dev))
> > > +	cdns_i2c_runtime_suspend(dev);
> > 
> > I'd prefer checking the error value, even though we are sure on the expected return. It's more future proof.
> > 
> > Andi
> > 
> Ok, I will keep the original changes.
> 
> > > > > +	}
> > > > > +
> > > > > +	i2c_mark_adapter_resumed(&xi2c->adap);
> > > > > +
> > > > > +	return 0;
> > > > > +}

  reply	other threads:[~2024-01-24 12:53 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-19  1:33 [PATCH v2 RESEND] i2c: cadence: Add system suspend and resume PM support Ji Sheng Teoh
2024-01-21 20:35 ` Andi Shyti
2024-01-22 16:23   ` JiSheng Teoh
2024-01-23 20:32     ` Andi Shyti
2024-01-24  4:46       ` JiSheng Teoh
2024-01-24 12:53         ` Andi Shyti [this message]
2024-01-25 15:30           ` JiSheng Teoh
2024-03-06 15:43 ` Andi Shyti

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=y2sxh2jkvujnaxeknbunogkumywjlohp3hi6dkf5dkc3qko27s@vg2qggq7lzrz \
    --to=andi.shyti@kernel.org \
    --cc=jisheng.teoh@starfivetech.com \
    --cc=leyfoon.tan@starfivetech.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michal.simek@amd.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).