public inbox for cip-dev@lists.cip-project.org
 help / color / mirror / Atom feed
* [PATCH 5.10.y-cip] i2c: riic: Move suspend handling to NOIRQ phase
@ 2026-02-10 10:26 Tommaso Merciai
  2026-02-16 11:55 ` [cip-dev] " Pavel Machek
  0 siblings, 1 reply; 4+ messages in thread
From: Tommaso Merciai @ 2026-02-10 10:26 UTC (permalink / raw)
  To: cip-dev, Nobuhiro Iwamatsu, Pavel Machek
  Cc: Biju Das, Lad Prabhakar, tomm.merciai

commit e383f0961422f983451ac4dd6aed1a3d3311f2be upstream.

Commit 53326135d0e0 ("i2c: riic: Add suspend/resume support") added
suspend support for the Renesas I2C driver and following this change
on RZ/G3E the following WARNING is seen on entering suspend ...

[  134.275704] Freezing remaining freezable tasks completed (elapsed 0.001 seconds)
[  134.285536] ------------[ cut here ]------------
[  134.290298] i2c i2c-2: Transfer while suspended
[  134.295174] WARNING: drivers/i2c/i2c-core.h:56 at __i2c_smbus_xfer+0x1e4/0x214, CPU#0: systemd-sleep/388
[  134.365507] Tainted: [W]=WARN
[  134.368485] Hardware name: Renesas SMARC EVK version 2 based on r9a09g047e57 (DT)
[  134.375961] pstate: 60400005 (nZCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
[  134.382935] pc : __i2c_smbus_xfer+0x1e4/0x214
[  134.387329] lr : __i2c_smbus_xfer+0x1e4/0x214
[  134.391717] sp : ffff800083f23860
[  134.395040] x29: ffff800083f23860 x28: 0000000000000000 x27: ffff800082ed5d60
[  134.402226] x26: 0000001f4395fd74 x25: 0000000000000007 x24: 0000000000000001
[  134.409408] x23: 0000000000000000 x22: 000000000000006f x21: ffff800083f23936
[  134.416589] x20: ffff0000c090e140 x19: ffff0000c090e0d0 x18: 0000000000000006
[  134.423771] x17: 6f63657320313030 x16: 2e30206465737061 x15: ffff800083f23280
[  134.430953] x14: 0000000000000000 x13: ffff800082b16ce8 x12: 0000000000000f09
[  134.438134] x11: 0000000000000503 x10: ffff800082b6ece8 x9 : ffff800082b16ce8
[  134.445315] x8 : 00000000ffffefff x7 : ffff800082b6ece8 x6 : 80000000fffff000
[  134.452495] x5 : 0000000000000504 x4 : 0000000000000000 x3 : 0000000000000000
[  134.459672] x2 : 0000000000000000 x1 : 0000000000000000 x0 : ffff0000c9ee9e80
[  134.466851] Call trace:
[  134.469311]  __i2c_smbus_xfer+0x1e4/0x214 (P)
[  134.473715]  i2c_smbus_xfer+0xbc/0x120
[  134.477507]  i2c_smbus_read_byte_data+0x4c/0x84
[  134.482077]  isl1208_i2c_read_time+0x44/0x178 [rtc_isl1208]
[  134.487703]  isl1208_rtc_read_time+0x14/0x20 [rtc_isl1208]
[  134.493226]  __rtc_read_time+0x44/0x88
[  134.497012]  rtc_read_time+0x3c/0x68
[  134.500622]  rtc_suspend+0x9c/0x170

The warning is triggered because I2C transfers can still be attempted
while the controller is already suspended, due to inappropriate ordering
of the system sleep callbacks.

If the controller is autosuspended, there is no way to wake it up once
runtime PM disabled (in suspend_late()). During system resume, the I2C
controller will be available only after runtime PM is re-enabled
(in resume_early()). However, this may be too late for some devices.

Wake up the controller in the suspend() callback while runtime PM is
still enabled. The I2C controller will remain available until the
suspend_noirq() callback (pm_runtime_force_suspend()) is called. During
resume, the I2C controller can be restored by the resume_noirq() callback
(pm_runtime_force_resume()). Finally, the resume() callback re-enables
autosuspend. As a result, the I2C controller can remain available until
the system enters suspend_noirq() and from resume_noirq().

Cc: stable@vger.kernel.org
Fixes: 53326135d0e0 ("i2c: riic: Add suspend/resume support")
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
Reviewed-by: Biju Das <biju.das.jz@bp.renesas.com>
Tested-by: Biju Das <biju.das.jz@bp.renesas.com>
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
[tm: Used SET_NOIRQ_SYSTEM_SLEEP_PM_OPS, SET_SYSTEM_SLEEP_PM_OPS and
 CONFIG_PM_SLEEP ifdef for backward compatibility]
Signed-off-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
---
 drivers/i2c/busses/i2c-riic.c | 48 ++++++++++++++++++++++++++++++-----
 1 file changed, 41 insertions(+), 7 deletions(-)

diff --git a/drivers/i2c/busses/i2c-riic.c b/drivers/i2c/busses/i2c-riic.c
index 1528912d7a13..4d76f066dd4c 100644
--- a/drivers/i2c/busses/i2c-riic.c
+++ b/drivers/i2c/busses/i2c-riic.c
@@ -577,14 +577,42 @@ static const struct riic_of_data riic_rz_v2h_info = {
 	.fast_mode_plus = true,
 };
 
+#ifdef CONFIG_PM_SLEEP
 static int riic_i2c_suspend(struct device *dev)
 {
-	struct riic_dev *riic = dev_get_drvdata(dev);
-	int ret;
+	/*
+	 * Some I2C devices may need the I2C controller to remain active
+	 * during resume_noirq() or suspend_noirq(). If the controller is
+	 * autosuspended, there is no way to wake it up once runtime PM is
+	 * disabled (in suspend_late()).
+	 *
+	 * During system resume, the I2C controller will be available only
+	 * after runtime PM is re-enabled (in resume_early()). However, this
+	 * may be too late for some devices.
+	 *
+	 * Wake up the controller in the suspend() callback while runtime PM
+	 * is still enabled. The I2C controller will remain available until
+	 * the suspend_noirq() callback (pm_runtime_force_suspend()) is
+	 * called. During resume, the I2C controller can be restored by the
+	 * resume_noirq() callback (pm_runtime_force_resume()).
+	 *
+	 * Finally, the resume() callback re-enables autosuspend, ensuring
+	 * the I2C controller remains available until the system enters
+	 * suspend_noirq() and from resume_noirq().
+	 */
+	return pm_runtime_resume_and_get(dev);
+}
 
-	ret = pm_runtime_resume_and_get(dev);
-	if (ret)
-		return ret;
+static int riic_i2c_resume(struct device *dev)
+{
+	pm_runtime_put_autosuspend(dev);
+
+	return 0;
+}
+
+static int riic_i2c_suspend_noirq(struct device *dev)
+{
+	struct riic_dev *riic = dev_get_drvdata(dev);
 
 	i2c_mark_adapter_suspended(&riic->adapter);
 
@@ -592,12 +620,12 @@ static int riic_i2c_suspend(struct device *dev)
 	riic_clear_set_bit(riic, ICCR1_ICE, 0, RIIC_ICCR1);
 
 	pm_runtime_mark_last_busy(dev);
-	pm_runtime_put_sync(dev);
+	pm_runtime_force_suspend(dev);
 
 	return reset_control_assert(riic->rstc);
 }
 
-static int riic_i2c_resume(struct device *dev)
+static int riic_i2c_resume_noirq(struct device *dev)
 {
 	struct riic_dev *riic = dev_get_drvdata(dev);
 	int ret;
@@ -606,6 +634,10 @@ static int riic_i2c_resume(struct device *dev)
 	if (ret)
 		return ret;
 
+	ret = pm_runtime_force_resume(dev);
+	if (ret)
+		return ret;
+
 	ret = riic_init_hw(riic);
 	if (ret) {
 		/*
@@ -621,8 +653,10 @@ static int riic_i2c_resume(struct device *dev)
 
 	return 0;
 }
+#endif /* CONFIG_PM_SLEEP */
 
 static const struct dev_pm_ops riic_i2c_pm_ops = {
+	SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(riic_i2c_suspend_noirq, riic_i2c_resume_noirq)
 	SET_SYSTEM_SLEEP_PM_OPS(riic_i2c_suspend, riic_i2c_resume)
 };
 
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [cip-dev] [PATCH 5.10.y-cip] i2c: riic: Move suspend handling to NOIRQ phase
  2026-02-10 10:26 [PATCH 5.10.y-cip] i2c: riic: Move suspend handling to NOIRQ phase Tommaso Merciai
@ 2026-02-16 11:55 ` Pavel Machek
  2026-02-16 11:57   ` Pavel Machek
  0 siblings, 1 reply; 4+ messages in thread
From: Pavel Machek @ 2026-02-16 11:55 UTC (permalink / raw)
  To: tommaso.merciai.xr
  Cc: cip-dev, Nobuhiro Iwamatsu, Pavel Machek, Biju Das, Lad Prabhakar,
	tomm.merciai

[-- Attachment #1: Type: text/plain, Size: 1024 bytes --]

Hi!

> Wake up the controller in the suspend() callback while runtime PM is
> still enabled. The I2C controller will remain available until the
> suspend_noirq() callback (pm_runtime_force_suspend()) is called. During
> resume, the I2C controller can be restored by the resume_noirq() callback
> (pm_runtime_force_resume()). Finally, the resume() callback re-enables
> autosuspend. As a result, the I2C controller can remain available until
> the system enters suspend_noirq() and from resume_noirq().

> +++ b/drivers/i2c/busses/i2c-riic.c
> @@ -606,6 +634,10 @@ static int riic_i2c_resume(struct device *dev)
>  	if (ret)
>  		return ret;
>  
> +	ret = pm_runtime_force_resume(dev);
> +	if (ret)
> +		return ret;
> +
>  	ret = riic_init_hw(riic);
>  	if (ret) {
>  		/*

Similar to the next error return, this likely should do
"reset_control_assert(riic->rstc);" before returning. I guess fixed
patch would be best here.

Thanks and best regards,
							Pavel
-- 
In cooperation with Nabla.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [cip-dev] [PATCH 5.10.y-cip] i2c: riic: Move suspend handling to NOIRQ phase
  2026-02-16 11:55 ` [cip-dev] " Pavel Machek
@ 2026-02-16 11:57   ` Pavel Machek
  2026-02-18  5:07     ` nobuhiro.iwamatsu.x90
  0 siblings, 1 reply; 4+ messages in thread
From: Pavel Machek @ 2026-02-16 11:57 UTC (permalink / raw)
  To: Pavel Machek
  Cc: tommaso.merciai.xr, cip-dev, Nobuhiro Iwamatsu, Biju Das,
	Lad Prabhakar, tomm.merciai

[-- Attachment #1: Type: text/plain, Size: 1463 bytes --]

On Mon 2026-02-16 12:55:30, Pavel Machek wrote:
> Hi!
> 
> > Wake up the controller in the suspend() callback while runtime PM is
> > still enabled. The I2C controller will remain available until the
> > suspend_noirq() callback (pm_runtime_force_suspend()) is called. During
> > resume, the I2C controller can be restored by the resume_noirq() callback
> > (pm_runtime_force_resume()). Finally, the resume() callback re-enables
> > autosuspend. As a result, the I2C controller can remain available until
> > the system enters suspend_noirq() and from resume_noirq().
> 
> > +++ b/drivers/i2c/busses/i2c-riic.c
> > @@ -606,6 +634,10 @@ static int riic_i2c_resume(struct device *dev)
> >  	if (ret)
> >  		return ret;
> >  
> > +	ret = pm_runtime_force_resume(dev);
> > +	if (ret)
> > +		return ret;
> > +
> >  	ret = riic_init_hw(riic);
> >  	if (ret) {
> >  		/*
> 
> Similar to the next error return, this likely should do
> "reset_control_assert(riic->rstc);" before returning. I guess fixed
> patch would be best here.

Hmm, maybe that's not the best way forward.

It appears that same problem exists in mainline, too? So probably we
should merge this and let you fix it in the mainline.

Reviewed-by: Pavel Machek <pavel@nabladev.com>

I can this if it passes testing and there are no other comments.

Best regards,
                                                                Pavel
-- 
In cooperation with Nabla.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [cip-dev] [PATCH 5.10.y-cip] i2c: riic: Move suspend handling to NOIRQ phase
  2026-02-16 11:57   ` Pavel Machek
@ 2026-02-18  5:07     ` nobuhiro.iwamatsu.x90
  0 siblings, 0 replies; 4+ messages in thread
From: nobuhiro.iwamatsu.x90 @ 2026-02-18  5:07 UTC (permalink / raw)
  To: pavel
  Cc: tommaso.merciai.xr, cip-dev, biju.das.jz,
	prabhakar.mahadev-lad.rj, tomm.merciai

Hi all,

> -----Original Message-----
> From: cip-dev@lists.cip-project.org <cip-dev@lists.cip-project.org> On Behalf Of Pavel Machek via lists.cip-project.org
> Sent: Monday, February 16, 2026 8:58 PM
> To: Pavel Machek <pavel@nabladev.com>
> Cc: tommaso.merciai.xr@bp.renesas.com; cip-dev@lists.cip-project.org; iwamatsu nobuhiro(岩松 信洋 □DITC○C
> PT) <nobuhiro.iwamatsu.x90@mail.toshiba>; Biju Das <biju.das.jz@bp.renesas.com>; Lad Prabhakar
> <prabhakar.mahadev-lad.rj@bp.renesas.com>; tomm.merciai@gmail.com
> Subject: Re: [cip-dev] [PATCH 5.10.y-cip] i2c: riic: Move suspend handling to NOIRQ phase
> 
> On Mon 2026-02-16 12:55:30, Pavel Machek wrote:
> > Hi!
> >
> > > Wake up the controller in the suspend() callback while runtime PM is
> > > still enabled. The I2C controller will remain available until the
> > > suspend_noirq() callback (pm_runtime_force_suspend()) is called.
> > > During resume, the I2C controller can be restored by the
> > > resume_noirq() callback (pm_runtime_force_resume()). Finally, the
> > > resume() callback re-enables autosuspend. As a result, the I2C
> > > controller can remain available until the system enters suspend_noirq() and from resume_noirq().
> >
> > > +++ b/drivers/i2c/busses/i2c-riic.c
> > > @@ -606,6 +634,10 @@ static int riic_i2c_resume(struct device *dev)
> > >  	if (ret)
> > >  		return ret;
> > >
> > > +	ret = pm_runtime_force_resume(dev);
> > > +	if (ret)
> > > +		return ret;
> > > +
> > >  	ret = riic_init_hw(riic);
> > >  	if (ret) {
> > >  		/*
> >
> > Similar to the next error return, this likely should do
> > "reset_control_assert(riic->rstc);" before returning. I guess fixed
> > patch would be best here.
> 
> Hmm, maybe that's not the best way forward.
> 
> It appears that same problem exists in mainline, too? So probably we should merge this and let you fix it in the mainline.
> 
> Reviewed-by: Pavel Machek <pavel@nabladev.com>
> 
> I can this if it passes testing and there are no other comments.
> 

I reviewed this and for other kernels , looks good to me too.
I will apply and push with Pavel's Reviewed-by tag.

> Best regards,
>                                                                 Pavel


Best regards,
  Nobuhiro



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-02-18  5:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-10 10:26 [PATCH 5.10.y-cip] i2c: riic: Move suspend handling to NOIRQ phase Tommaso Merciai
2026-02-16 11:55 ` [cip-dev] " Pavel Machek
2026-02-16 11:57   ` Pavel Machek
2026-02-18  5:07     ` nobuhiro.iwamatsu.x90

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox