linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ji Sheng Teoh <jisheng.teoh@starfivetech.com>
To: <andi.shyti@kernel.org>
Cc: <jisheng.teoh@starfivetech.com>, <leyfoon.tan@starfivetech.com>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-i2c@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<michal.simek@amd.com>
Subject: Re: [PATCH v2] i2c: cadence: Add system suspend and resume PM support
Date: Mon, 11 Dec 2023 00:21:19 +0800	[thread overview]
Message-ID: <20231210162119.364-1-jisheng.teoh@starfivetech.com> (raw)
In-Reply-To: <20231210115412.hztjrubacnmenbvz@zenone.zhora.eu>

On Sun, 10 Dec 2023 12:54:12 +0100
Andi Shyti <andi.shyti@kernel.org> wrote:

> Hi Ji Sheng,
> 
> [...]
> 
> > > > +static int __maybe_unused cdns_i2c_resume(struct device *dev)
> > > > +{  
> > >
> > > I am not really understanding what you are trying to do here:
> > >  
> > > > +	struct cdns_i2c *xi2c = dev_get_drvdata(dev);
> > > > +	int err;
> > > > +
> > > > +	err = cdns_i2c_runtime_resume(dev);  
> > >
> > > First you try to resume...
> > >  
> > > > +	if (err)
> > > > +		return err;
> > > > +
> > > > +	if (pm_runtime_status_suspended(dev)) {  
> > >
> > > ... then you check if you are suspended ...  
> > 
> > This serves as a check and balance to ensure that when the system
> > resumes with device in runtime suspend state, we disable the clock
> > enabled in earlier cdns_i2c_runtime_resume() to ensure a balanced
> > clock reference count for subsequent runtime resume transition.
> > Similar implementation can be found in this commit:
> > https://github.com/torvalds/linux/commit/44c99904cf61f945d02ac9976ab10dd5ccaea393
> >  
> 
> OK, this is done purely for clock balancing, but then, I still
> don't understand the case. I expect the clock counter to be
> unbalanced when you suspend (because is moving towards '0').
> 
> While, if you check if the clock is unbalanced when resuming, it
> means that the clock had a negative counter (which is impossible
> because the clock counter is unsigned).
> 
> If there is any unbalancing at this stage, then I recommend you
> to check what has happened previously.
> 
> ... Or is there anything I am missing?
> 
> Thanks,
> Andi

You are right, the clock counter will move towards 0 during system
suspend.
Conversely during system resume, the clock counter is incremented to 1
early on in cdns_i2c_runtime_resume(). So the clock counter is not
negative to start with. 
At this point of time, clock counter is 1. If the device is in runtime
suspend, we decrement the clock counter back to 0, so the subsequent
runtime resume could increment it back to 1. In a sense, balancing the
clock counter.
Please help correct me if I've got it wrong.

> 
> > > > +		err = cdns_i2c_runtime_suspend(dev);  
> > >
> > > ... and suspend again? Shouldn't this be _resume()?
> > >
> > > Thanks,
> > > Andi
> > >  
> > > > +		if (err)
> > > > +			return err;
> > > > +	}
> > > > +
> > > > +	i2c_mark_adapter_resumed(&xi2c->adap);
> > > > +
> > > > +	return 0;
> > > > +}  



  reply	other threads:[~2023-12-10 16:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-09 13:15 [PATCH v2] i2c: cadence: Add system suspend and resume PM support Ji Sheng Teoh
2023-12-09 20:57 ` Andi Shyti
2023-12-10  5:20   ` Ji Sheng Teoh
2023-12-10 11:54     ` Andi Shyti
2023-12-10 16:21       ` Ji Sheng Teoh [this message]
2024-01-07 23:47         ` JiSheng Teoh

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=20231210162119.364-1-jisheng.teoh@starfivetech.com \
    --to=jisheng.teoh@starfivetech.com \
    --cc=andi.shyti@kernel.org \
    --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 NNTP newsgroup(s).