The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Nishanth Menon <nm@ti.com>
To: Mark Brown <broonie@kernel.org>
Cc: Francesco Dolcini <francesco@dolcini.it>,
	Siddharth Vadapalli <s-vadapalli@ti.com>,
	Anurag Dutta <a-dutta@ti.com>, <linux-spi@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <stable@vger.kernel.org>
Subject: Re: [PATCH] spi: cadence-quadspi: Fix clock enable underflows due to runtime PM
Date: Thu, 4 Dec 2025 08:05:30 -0600	[thread overview]
Message-ID: <20251204140530.xax5didvuc7auzcd@problem> (raw)
In-Reply-To: <555e9f6b-b8b6-4cc5-900b-63aaff8b4e6c@sirena.org.uk>

On 13:28-20251204, Mark Brown wrote:
> On Thu, Dec 04, 2025 at 10:13:35AM +0100, Francesco Dolcini wrote:
> 
> > Unless I did some stupid mistake testing the patch, it does not fix the issue.
> > Here the log with v6.18 + this patch
> 
> Yeah, I'm pretty sure it didn't work.  I've managed to find a system
> which instantiates the IP so hopefully I can modify it to trigger the
> issue and test directly rather than working blind, I've also noticed
> that we're getting
> 
> [   15.430306] cadence-qspi 13010000.spi: Runtime PM usage count underflow!
> 
> even in normal operation (on that system anyway) so the runtime PM
> handling is definitely unhappy.

Hit the same issue on J721E platform [1], the following seems to help in
my local testing [2]. I am no expert.. but do see if this makes sense

The clock is already turned off by the runtime-PM suspend callback, so an
extra clk_disable*_unprepare() is only correct when runtime-PM support is
not in use.

[1] https://dashboard.kernelci.org/log-viewer?itemId=ti%3A4db11a5806594ef99c7c2828&org=ti&type=test&url=http%3A%2F%2Ffiles.kernelci.org%2F%2Fti%2Fmainline%2Fmaster%2Fv6.18-763-g4a26e7032d7d5%2Farm64%2Fdefconfig%2Blab-setup%2Bkselftest%2Fgcc-14%2Fbaseline-nfs-boot.nfs-j721e-idk-gw.txt.gz

[2] https://gist.github.com/nmenon/1ebaa7cf18e7df49ab59aaa7eb798a68

diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c
index af6d050da1c8..3678e971d6d9 100644
--- a/drivers/spi/spi-cadence-quadspi.c
+++ b/drivers/spi/spi-cadence-quadspi.c
@@ -2024,7 +2024,9 @@ static int cqspi_probe(struct platform_device *pdev)
 probe_reset_failed:
 	if (cqspi->is_jh7110)
 		cqspi_jh7110_disable_clk(pdev, cqspi);
-	clk_disable_unprepare(cqspi->clk);
+	/* Runtime-PM suspend already disables the core clock. */
+	if (ddata && (ddata->quirks & CQSPI_DISABLE_RUNTIME_PM))
+		clk_disable_unprepare(cqspi->clk);
 probe_clk_failed:
 	return ret;
 }
@@ -2048,9 +2050,11 @@ static void cqspi_remove(struct platform_device *pdev)
 	if (cqspi->rx_chan)
 		dma_release_channel(cqspi->rx_chan);
 
-	if (!(ddata && (ddata->quirks & CQSPI_DISABLE_RUNTIME_PM)))
-		if (pm_runtime_get_sync(&pdev->dev) >= 0)
-			clk_disable(cqspi->clk);
+	if (ddata && (ddata->quirks & CQSPI_DISABLE_RUNTIME_PM))
+		clk_disable_unprepare(cqspi->clk);
+	else
+		/* Balance the later pm_runtime_put_sync() */
+		pm_runtime_get_sync(&pdev->dev);
 
 	if (cqspi->is_jh7110)
 		cqspi_jh7110_disable_clk(pdev, cqspi);
-- 
2.47.0

-- 
Regards,
Nishanth Menon
Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3  1A34 DDB5 849D 1736 249D
https://ti.com/opensource

  parent reply	other threads:[~2025-12-04 14:05 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-02 22:53 [PATCH] spi: cadence-quadspi: Fix clock enable underflows due to runtime PM Mark Brown
2025-12-03 10:42 ` Siddharth Vadapalli
2025-12-03 11:58   ` Mark Brown
2025-12-04  9:13 ` Francesco Dolcini
2025-12-04 13:28   ` Mark Brown
2025-12-04 13:44     ` Mark Brown
2025-12-04 14:05     ` Nishanth Menon [this message]
2025-12-04 15:11       ` Mark Brown
2025-12-04 17:05         ` Mark Brown
2025-12-05 12:54           ` Dutta, Anurag
2025-12-05 12:58           ` Dutta, Anurag
2025-12-05 13:25             ` Mark Brown
2025-12-09  5:43               ` Dutta, Anurag
2025-12-09  9:52                 ` Dutta, Anurag
2025-12-09 10:30                   ` Mark Brown
2025-12-12  4:34                     ` Dutta, Anurag
2025-12-12  6:04                       ` Mark Brown
2025-12-12  6:07                       ` Mark Brown
2025-12-12  7:14                         ` Dutta, Anurag

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=20251204140530.xax5didvuc7auzcd@problem \
    --to=nm@ti.com \
    --cc=a-dutta@ti.com \
    --cc=broonie@kernel.org \
    --cc=francesco@dolcini.it \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=s-vadapalli@ti.com \
    --cc=stable@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox