Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] spi: atmel-quadspi: balance runtime PM and pclk across system sleep
@ 2026-09-23  1:29 Karl Mehltretter
  2026-10-04 19:39 ` Mark Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Karl Mehltretter @ 2026-09-23  1:29 UTC (permalink / raw)
  To: Mark Brown
  Cc: Karl Mehltretter, Nicolas Ferre, Alexandre Belloni,
	Claudiu Beznea, Tudor Ambarus, Varshini Rajendran,
	Bence Csókás, Robert Marko, linux-spi, linux-arm-kernel,
	linux-kernel, Sashiko

On the controllers with a generic clock (SAMA7G5, SAMA7D65, SAM9X7 and
LAN969x), atmel_qspi_suspend() takes a runtime PM reference and returns
without dropping it or suspending the device. It disables the peripheral
clock directly. atmel_qspi_resume() only prepares the peripheral clock
and then reinitializes the controller with that clock still off.

On a SAM9X75 Curiosity board, the tested standby and mem resumes
failed:

  atmel_qspi f0014000.spi: PM: failed to resume: error -110
  spi-nor spi0.0: resume() failed

Reading the flash afterwards returned no data. The runtime usage count
grew by one with each cycle, and the second suspend disabled the
peripheral clock again:

  WARNING: drivers/clk/clk.c:1257 at clk_core_disable+0x6c/0xcc
  qspi_clk already disabled

Use the same runtime PM sequence as the other variants. Suspend disables
the controller and forces a runtime suspend. Resume forces a runtime
resume, which enables the peripheral clock, before it runs the init
callback, and drops the reference afterwards. With this change the
tested resumes succeed on the board in both modes, the controller
returns to runtime suspend, and the flash reads back.

Fixes: 5af42209a4d2 ("spi: atmel-quadspi: Add support for sama7g5 QSPI")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/patchset/20260709112006.390742-1-robert.marko%40sartura.hr?part=3
Cc: stable@vger.kernel.org
Assisted-by: LLM
Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
---
A/B tested on a SAM9X75 Curiosity board, two real suspend cycles each
in standby and mem, woken by the RTC, with a read of the on-board
SST26VF064B after every resume:

                           without patch          with patch
  resume                   error -110             ok
  runtime status / usage   active / 1, then 2     suspended / 0
  second suspend           WARNING, qspi_clk      clean
                           already disabled
  flash read               no data                matches

pm_test=devices gives the same result. QEMU's sam9x75-curiosity model
shows the same runtime PM and clock state. Its OSPI does not depend on
pclk, so there reads succeed in both cases.

Not tested: SAMA7G5, SAMA7D65 and LAN969x.

Unrelated to this patch: with and without it, each tested OSPI flash
read on SAM9X75 printed "BUG: sleeping function called from invalid
context" from at_xdmac_issue_pending().

 drivers/spi/atmel-quadspi.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/spi/atmel-quadspi.c b/drivers/spi/atmel-quadspi.c
index ec19fa0180f00..96ed734b56218 100644
--- a/drivers/spi/atmel-quadspi.c
+++ b/drivers/spi/atmel-quadspi.c
@@ -1590,12 +1590,14 @@ static int atmel_qspi_suspend(struct device *dev)
 
 	if (aq->caps->has_gclk) {
 		ret = atmel_qspi_sama7g5_suspend(aq);
-		clk_disable_unprepare(aq->pclk);
-		return ret;
+		if (ret) {
+			pm_runtime_put_autosuspend(dev);
+			return ret;
+		}
+	} else {
+		atmel_qspi_write(QSPI_CR_QSPIDIS, aq, QSPI_CR);
 	}
 
-	atmel_qspi_write(QSPI_CR_QSPIDIS, aq, QSPI_CR);
-
 	pm_runtime_mark_last_busy(dev);
 	pm_runtime_force_suspend(dev);
 
@@ -1621,20 +1623,20 @@ static int atmel_qspi_resume(struct device *dev)
 		return ret;
 	}
 
-	if (aq->caps->has_gclk)
-		return aq->caps->init(aq);
-
 	ret = pm_runtime_force_resume(dev);
 	if (ret < 0)
 		return ret;
 
-	atmel_qspi_init(aq);
-
-	atmel_qspi_write(aq->scr, aq, QSPI_SCR);
+	if (aq->caps->has_gclk) {
+		ret = aq->caps->init(aq);
+	} else {
+		atmel_qspi_init(aq);
+		atmel_qspi_write(aq->scr, aq, QSPI_SCR);
+	}
 
 	pm_runtime_put_autosuspend(dev);
 
-	return 0;
+	return ret;
 }
 
 static int atmel_qspi_runtime_suspend(struct device *dev)
-- 
2.53.0



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

* Re: [PATCH] spi: atmel-quadspi: balance runtime PM and pclk across system sleep
  2026-09-23  1:29 [PATCH] spi: atmel-quadspi: balance runtime PM and pclk across system sleep Karl Mehltretter
@ 2026-10-04 19:39 ` Mark Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2026-10-04 19:39 UTC (permalink / raw)
  To: Karl Mehltretter
  Cc: Nicolas Ferre, Alexandre Belloni, Claudiu Beznea, Tudor Ambarus,
	Varshini Rajendran, Bence Csókás, Robert Marko,
	linux-spi, linux-arm-kernel, linux-kernel, Sashiko

On Wed, 23 Sep 2026 03:29:50 +0200, Karl Mehltretter wrote:
> spi: atmel-quadspi: balance runtime PM and pclk across system sleep

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-7.4

Thanks!

[1/1] spi: atmel-quadspi: balance runtime PM and pclk across system sleep
      https://git.kernel.org/broonie/spi/c/717e45f97246

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark



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

end of thread, other threads:[~2026-10-05 16:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-23  1:29 [PATCH] spi: atmel-quadspi: balance runtime PM and pclk across system sleep Karl Mehltretter
2026-10-04 19:39 ` Mark Brown

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