All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mukesh Kumar Savaliya <quic_msavaliy@quicinc.com>
To: Andi Shyti <andi.shyti@kernel.org>
Cc: <konrad.dybcio@linaro.org>, <andersson@kernel.org>,
	<linux-arm-msm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<linux-i2c@vger.kernel.org>, <quic_vdadhani@quicinc.com>,
	Vinod Koul <vkoul@kernel.org>
Subject: Re: [PATCH v1] i2c: i2c-qcom-geni: Serve transfer during early resume stage
Date: Tue, 2 Apr 2024 15:56:47 +0530	[thread overview]
Message-ID: <1b247a4b-a260-4f89-bdcb-e821a47914d3@quicinc.com> (raw)
In-Reply-To: <j5zai7pw7pxe2owjsoq2ncwhsmwe2llmcvb7vp46xi757eamub@inefovgffgpp>

Thanks Andi !

On 3/30/2024 3:24 AM, Andi Shyti wrote:
> Hi Mukesh,
> 
> On Thu, Mar 28, 2024 at 06:07:43PM +0530, Mukesh Kumar Savaliya wrote:
>> pm_runtime_get_sync() function fails during PM early resume and returning
>> -EACCES because runtime PM for the device is disabled at the early stage
>> causing i2c transfer to fail. Make changes to serve transfer with force
>> resume.
>>
>> 1. Register interrupt with IRQF_EARLY_RESUME and IRQF_NO_SUSPEND flags
>>     to avoid timeout of transfer when IRQ is not enabled during early stage.
>> 2. Do force resume if pm_runtime_get_sync() is failing after system
>>     suspend when runtime PM is not enabled.
>> 3. Increment power usage count after forced resume to balance
>>     it against regular runtime suspend.
>>
>> Co-developed-by: Viken Dadhaniya <quic_vdadhani@quicinc.com>
>> Signed-off-by: Viken Dadhaniya <quic_vdadhani@quicinc.com>
>> Signed-off-by: Mukesh Kumar Savaliya <quic_msavaliy@quicinc.com>
> 
> Is this a fix? O mostly an improvement?
It's an improvement to serve transfer during early resume time. Doesn't 
fix any crash issue.
> 
> ...
> 
>>   	gi2c->err = 0;
>>   	reinit_completion(&gi2c->done);
>> -	ret = pm_runtime_get_sync(gi2c->se.dev);
>> -	if (ret < 0) {
>> -		dev_err(gi2c->se.dev, "error turning SE resources:%d\n", ret);
>> -		pm_runtime_put_noidle(gi2c->se.dev);
>> -		/* Set device in suspended since resume failed */
>> -		pm_runtime_set_suspended(gi2c->se.dev);
>> -		return ret;
>> +
>> +	if (!pm_runtime_enabled(dev) && gi2c->suspended) {
>> +		dev_dbg(gi2c->se.dev, "RT_PM disabled, Do force resume, usage_count:%d\n",
> 
> dev
> 
Sure, Done.

> nit: you could leave a space after the ':'.
> 
Sure, Done.

>> +			atomic_read(&dev->power.usage_count));
>> +		ret = geni_i2c_force_resume(gi2c);
>> +		if (ret)
>> +			return ret;
>> +	} else {
>> +		ret = pm_runtime_get_sync(dev);
>> +		if (ret == -EACCES && gi2c->suspended) {
>> +			dev_dbg(gi2c->se.dev, "PM get_sync() failed-%d, force resume\n", ret);
> 
> dev
> 
Done.
>> +			ret = geni_i2c_force_resume(gi2c);
>> +			if (ret)
>> +				return ret;
>> +		}
> 
> Are we missing some cases here? Do we need a few more else's?
> 
> Andi
> 
No More else cases required.
>>   	}
>>   
>>   	qcom_geni_i2c_conf(gi2c);
>> @@ -702,8 +730,15 @@ static int geni_i2c_xfer(struct i2c_adapter *adap,
>>   	else
>>   		ret = geni_i2c_fifo_xfer(gi2c, msgs, num);
>>   
>> -	pm_runtime_mark_last_busy(gi2c->se.dev);
>> -	pm_runtime_put_autosuspend(gi2c->se.dev);
>> +	if (!pm_runtime_enabled(dev) && !gi2c->suspended) {
>> +		pm_runtime_put_noidle(dev);
>> +		pm_runtime_set_suspended(dev);
> 
> this looks like repeated code, how about making it a function?
> 
Checked it, but seems we need additional flag too to be added at one 
place where as common part is 2 lines of code. If this code continues to 
be repeated, i can think of keeping under a wrapper function. Please let 
me know if still needed to make a separate function.
>> +		gi2c->suspended = 0;
>> +	} else {
>> +		pm_runtime_mark_last_busy(gi2c->se.dev);
>> +		pm_runtime_put_autosuspend(gi2c->se.dev);
>> +	}
>> +
>>   	gi2c->cur = NULL;
>>   	gi2c->err = 0;
>>   	return ret;
>> @@ -820,7 +855,7 @@ static int geni_i2c_probe(struct platform_device *pdev)
>>   	init_completion(&gi2c->done);
>>   	spin_lock_init(&gi2c->lock);
>>   	platform_set_drvdata(pdev, gi2c);
>> -	ret = devm_request_irq(dev, gi2c->irq, geni_i2c_irq, 0,
>> +	ret = devm_request_irq(dev, gi2c->irq, geni_i2c_irq, IRQF_EARLY_RESUME | IRQF_NO_SUSPEND,
> 
> Can you provide a bit more information on how an early interrupt
> would be handled once the device is resumed?
> 
Sure, Let me go little descriptive here.
Post system suspend when system resume starts (because of PCI/touch 
device wakeup interrupt or anything else).

1.That time i2c client device handler will directly start i2c transfer, 
but we could not serve transfer because device is runtime suspended and 
runtime PM remains disabled. This happens during early_resume callback 
time, hence we have added forced_resume()

Basically system is still suspended and not reached to the point of 
enabling runtime PM of the i2c master.

2. If the IRQF_EARLY_RESUME is not registered, then we get timeout as 
the interrupt is not enabled. kernel/irq/pm.c has function which Enables 
interrupt lines having IRQF_EARLY_RESUME set during syscore instead of 
device resume time.

irq_pm_syscore_resume() => resume_irqs() => __enable_irq()

> Thanks,
> Andi
> 
>>   			       dev_name(dev), gi2c);
>>   	if (ret) {
>>   		dev_err(dev, "Request_irq failed:%d: err:%d\n",
>> -- 
>> 2.25.1
>>

  reply	other threads:[~2024-04-02 10:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-28 12:37 [PATCH v1] i2c: i2c-qcom-geni: Serve transfer during early resume stage Mukesh Kumar Savaliya
2024-03-29 21:54 ` Andi Shyti
2024-04-02 10:26   ` Mukesh Kumar Savaliya [this message]
2024-04-05  3:10 ` Bjorn Andersson

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=1b247a4b-a260-4f89-bdcb-e821a47914d3@quicinc.com \
    --to=quic_msavaliy@quicinc.com \
    --cc=andersson@kernel.org \
    --cc=andi.shyti@kernel.org \
    --cc=konrad.dybcio@linaro.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=quic_vdadhani@quicinc.com \
    --cc=vkoul@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.