public inbox for linux-spi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] spi: cadence: runtime PM fixes
@ 2026-04-21 12:36 Johan Hovold
  2026-04-21 12:36 ` [PATCH 1/4] spi: cadence: fix unclocked access on unbind Johan Hovold
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Johan Hovold @ 2026-04-21 12:36 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-spi, linux-kernel, Johan Hovold

This series fixes some runtime PM related issues in the cadence driver.

Included is also a couple of related cleanups.

Johan



Johan Hovold (4):
  spi: cadence: fix unclocked access on unbind
  spi: cadence: fix clock imbalance on probe failure
  spi: cadence: rename probe error labels
  spi: cadence: clean up probe return value

 drivers/spi/spi-cadence.c | 37 ++++++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 13 deletions(-)

-- 
2.52.0


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

* [PATCH 1/4] spi: cadence: fix unclocked access on unbind
  2026-04-21 12:36 [PATCH 0/4] spi: cadence: runtime PM fixes Johan Hovold
@ 2026-04-21 12:36 ` Johan Hovold
  2026-04-21 12:36 ` [PATCH 2/4] spi: cadence: fix clock imbalance on probe failure Johan Hovold
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Johan Hovold @ 2026-04-21 12:36 UTC (permalink / raw)
  To: Mark Brown
  Cc: linux-spi, linux-kernel, Johan Hovold, stable, Shubhrajyoti Datta

Make sure that the controller is runtime resumed before disabling it
during driver unbind to avoid unclocked register access and unbalanced
clock disable.

Also restore the autosuspend setting.

This issue was flagged by Sashiko when reviewing a controller
deregistration fix.

Fixes: d36ccd9f7ea4 ("spi: cadence: Runtime pm adaptation")
Cc: stable@vger.kernel.org	# 4.7
Cc: Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
Link: https://sashiko.dev/#/patchset/20260414134319.978196-1-johan%40kernel.org?part=1
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/spi/spi-cadence.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi-cadence.c b/drivers/spi/spi-cadence.c
index 08d7dabe818d..bf4a7cf6b142 100644
--- a/drivers/spi/spi-cadence.c
+++ b/drivers/spi/spi-cadence.c
@@ -776,16 +776,23 @@ static void cdns_spi_remove(struct platform_device *pdev)
 {
 	struct spi_controller *ctlr = platform_get_drvdata(pdev);
 	struct cdns_spi *xspi = spi_controller_get_devdata(ctlr);
+	int ret = 0;
+
+	if (!spi_controller_is_target(ctlr))
+		ret = pm_runtime_get_sync(&pdev->dev);
 
 	spi_controller_get(ctlr);
 
 	spi_unregister_controller(ctlr);
 
-	cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_DISABLE);
+	if (ret >= 0)
+		cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_DISABLE);
 
 	if (!spi_controller_is_target(ctlr)) {
 		pm_runtime_disable(&pdev->dev);
 		pm_runtime_set_suspended(&pdev->dev);
+		pm_runtime_put_noidle(&pdev->dev);
+		pm_runtime_dont_use_autosuspend(&pdev->dev);
 	}
 
 	spi_controller_put(ctlr);
-- 
2.52.0


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

* [PATCH 2/4] spi: cadence: fix clock imbalance on probe failure
  2026-04-21 12:36 [PATCH 0/4] spi: cadence: runtime PM fixes Johan Hovold
  2026-04-21 12:36 ` [PATCH 1/4] spi: cadence: fix unclocked access on unbind Johan Hovold
@ 2026-04-21 12:36 ` Johan Hovold
  2026-04-21 12:36 ` [PATCH 3/4] spi: cadence: rename probe error labels Johan Hovold
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Johan Hovold @ 2026-04-21 12:36 UTC (permalink / raw)
  To: Mark Brown
  Cc: linux-spi, linux-kernel, Johan Hovold, stable, Shubhrajyoti Datta

Make sure that the controller is active before disabling clocks on probe
failure to avoid unbalanced clock disable.

Also drop the usage count before returning (so that the controller can
be suspended after a probe deferral) and restore the autosuspend
setting.

Fixes: d36ccd9f7ea4 ("spi: cadence: Runtime pm adaptation")
Cc: stable@vger.kernel.org	# 4.7
Cc: Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/spi/spi-cadence.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi-cadence.c b/drivers/spi/spi-cadence.c
index bf4a7cf6b142..891e2ba36958 100644
--- a/drivers/spi/spi-cadence.c
+++ b/drivers/spi/spi-cadence.c
@@ -741,7 +741,6 @@ static int cdns_spi_probe(struct platform_device *pdev)
 		/* Set to default valid value */
 		ctlr->max_speed_hz = xspi->clk_rate / 4;
 		xspi->speed_hz = ctlr->max_speed_hz;
-		pm_runtime_put_autosuspend(&pdev->dev);
 	} else {
 		ctlr->mode_bits |= SPI_NO_CS;
 		ctlr->target_abort = cdns_target_abort;
@@ -752,12 +751,17 @@ static int cdns_spi_probe(struct platform_device *pdev)
 		goto clk_dis_all;
 	}
 
+	if (!spi_controller_is_target(ctlr))
+		pm_runtime_put_autosuspend(&pdev->dev);
+
 	return ret;
 
 clk_dis_all:
 	if (!spi_controller_is_target(ctlr)) {
 		pm_runtime_disable(&pdev->dev);
 		pm_runtime_set_suspended(&pdev->dev);
+		pm_runtime_put_noidle(&pdev->dev);
+		pm_runtime_dont_use_autosuspend(&pdev->dev);
 	}
 remove_ctlr:
 	spi_controller_put(ctlr);
-- 
2.52.0


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

* [PATCH 3/4] spi: cadence: rename probe error labels
  2026-04-21 12:36 [PATCH 0/4] spi: cadence: runtime PM fixes Johan Hovold
  2026-04-21 12:36 ` [PATCH 1/4] spi: cadence: fix unclocked access on unbind Johan Hovold
  2026-04-21 12:36 ` [PATCH 2/4] spi: cadence: fix clock imbalance on probe failure Johan Hovold
@ 2026-04-21 12:36 ` Johan Hovold
  2026-04-21 12:36 ` [PATCH 4/4] spi: cadence: clean up probe return value Johan Hovold
  2026-04-26 23:25 ` [PATCH 0/4] spi: cadence: runtime PM fixes Mark Brown
  4 siblings, 0 replies; 6+ messages in thread
From: Johan Hovold @ 2026-04-21 12:36 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-spi, linux-kernel, Johan Hovold

The "clk_dis_all" error label is not used to disable clocks since commit
f64b1600f92e ("spi: spi-cadence: Use helper function
devm_clk_get_enabled()").

Similarly, "remove_ctlr" drops a reference rather than deregisters the
controller.

Rename the labels after what they do.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/spi/spi-cadence.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/spi/spi-cadence.c b/drivers/spi/spi-cadence.c
index 891e2ba36958..f27586151ca9 100644
--- a/drivers/spi/spi-cadence.c
+++ b/drivers/spi/spi-cadence.c
@@ -656,21 +656,21 @@ static int cdns_spi_probe(struct platform_device *pdev)
 	xspi->regs = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(xspi->regs)) {
 		ret = PTR_ERR(xspi->regs);
-		goto remove_ctlr;
+		goto err_put_ctlr;
 	}
 
 	xspi->pclk = devm_clk_get_enabled(&pdev->dev, "pclk");
 	if (IS_ERR(xspi->pclk)) {
 		dev_err(&pdev->dev, "pclk clock not found.\n");
 		ret = PTR_ERR(xspi->pclk);
-		goto remove_ctlr;
+		goto err_put_ctlr;
 	}
 
 	xspi->rstc = devm_reset_control_get_optional_exclusive(&pdev->dev, "spi");
 	if (IS_ERR(xspi->rstc)) {
 		ret = dev_err_probe(&pdev->dev, PTR_ERR(xspi->rstc),
 				    "Cannot get SPI reset.\n");
-		goto remove_ctlr;
+		goto err_put_ctlr;
 	}
 
 	reset_control_assert(xspi->rstc);
@@ -680,7 +680,7 @@ static int cdns_spi_probe(struct platform_device *pdev)
 	if (IS_ERR(xspi->ref_clk)) {
 		dev_err(&pdev->dev, "ref_clk clock not found.\n");
 		ret = PTR_ERR(xspi->ref_clk);
-		goto remove_ctlr;
+		goto err_put_ctlr;
 	}
 
 	if (!spi_controller_is_target(ctlr)) {
@@ -710,7 +710,7 @@ static int cdns_spi_probe(struct platform_device *pdev)
 	irq = platform_get_irq(pdev, 0);
 	if (irq < 0) {
 		ret = irq;
-		goto clk_dis_all;
+		goto err_disable_rpm;
 	}
 
 	ret = devm_request_irq(&pdev->dev, irq, cdns_spi_irq,
@@ -718,7 +718,7 @@ static int cdns_spi_probe(struct platform_device *pdev)
 	if (ret != 0) {
 		ret = -ENXIO;
 		dev_err(&pdev->dev, "request_irq failed\n");
-		goto clk_dis_all;
+		goto err_disable_rpm;
 	}
 
 	ctlr->use_gpio_descriptors = true;
@@ -748,7 +748,7 @@ static int cdns_spi_probe(struct platform_device *pdev)
 	ret = spi_register_controller(ctlr);
 	if (ret) {
 		dev_err(&pdev->dev, "spi_register_controller failed\n");
-		goto clk_dis_all;
+		goto err_disable_rpm;
 	}
 
 	if (!spi_controller_is_target(ctlr))
@@ -756,14 +756,14 @@ static int cdns_spi_probe(struct platform_device *pdev)
 
 	return ret;
 
-clk_dis_all:
+err_disable_rpm:
 	if (!spi_controller_is_target(ctlr)) {
 		pm_runtime_disable(&pdev->dev);
 		pm_runtime_set_suspended(&pdev->dev);
 		pm_runtime_put_noidle(&pdev->dev);
 		pm_runtime_dont_use_autosuspend(&pdev->dev);
 	}
-remove_ctlr:
+err_put_ctlr:
 	spi_controller_put(ctlr);
 	return ret;
 }
-- 
2.52.0


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

* [PATCH 4/4] spi: cadence: clean up probe return value
  2026-04-21 12:36 [PATCH 0/4] spi: cadence: runtime PM fixes Johan Hovold
                   ` (2 preceding siblings ...)
  2026-04-21 12:36 ` [PATCH 3/4] spi: cadence: rename probe error labels Johan Hovold
@ 2026-04-21 12:36 ` Johan Hovold
  2026-04-26 23:25 ` [PATCH 0/4] spi: cadence: runtime PM fixes Mark Brown
  4 siblings, 0 replies; 6+ messages in thread
From: Johan Hovold @ 2026-04-21 12:36 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-spi, linux-kernel, Johan Hovold

Drop the redundant initialisation and return explicit zero on successful
probe to make the code more readable.

Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/spi/spi-cadence.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi-cadence.c b/drivers/spi/spi-cadence.c
index f27586151ca9..d108e89fda22 100644
--- a/drivers/spi/spi-cadence.c
+++ b/drivers/spi/spi-cadence.c
@@ -635,7 +635,7 @@ static int cdns_target_abort(struct spi_controller *ctlr)
  */
 static int cdns_spi_probe(struct platform_device *pdev)
 {
-	int ret = 0, irq;
+	int ret, irq;
 	struct spi_controller *ctlr;
 	struct cdns_spi *xspi;
 	u32 num_cs;
@@ -754,7 +754,7 @@ static int cdns_spi_probe(struct platform_device *pdev)
 	if (!spi_controller_is_target(ctlr))
 		pm_runtime_put_autosuspend(&pdev->dev);
 
-	return ret;
+	return 0;
 
 err_disable_rpm:
 	if (!spi_controller_is_target(ctlr)) {
-- 
2.52.0


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

* Re: [PATCH 0/4] spi: cadence: runtime PM fixes
  2026-04-21 12:36 [PATCH 0/4] spi: cadence: runtime PM fixes Johan Hovold
                   ` (3 preceding siblings ...)
  2026-04-21 12:36 ` [PATCH 4/4] spi: cadence: clean up probe return value Johan Hovold
@ 2026-04-26 23:25 ` Mark Brown
  4 siblings, 0 replies; 6+ messages in thread
From: Mark Brown @ 2026-04-26 23:25 UTC (permalink / raw)
  To: Johan Hovold; +Cc: linux-spi, linux-kernel

On Tue, 21 Apr 2026 14:36:11 +0200, Johan Hovold wrote:
> spi: cadence: runtime PM fixes
> 
> This series fixes some runtime PM related issues in the cadence driver.
> 
> Included is also a couple of related cleanups.
> 
> Johan
> 
> [...]

Applied to

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

Thanks!

[1/4] spi: cadence: fix unclocked access on unbind
      https://git.kernel.org/broonie/spi/c/5b1689a41f02
[2/4] spi: cadence: fix clock imbalance on probe failure
      https://git.kernel.org/broonie/spi/c/ecea4f0e9db2
[3/4] spi: cadence: rename probe error labels
      https://git.kernel.org/broonie/spi/c/63f34e35f87f
[4/4] spi: cadence: clean up probe return value
      https://git.kernel.org/broonie/spi/c/bf7b648acd48

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] 6+ messages in thread

end of thread, other threads:[~2026-04-27 10:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-21 12:36 [PATCH 0/4] spi: cadence: runtime PM fixes Johan Hovold
2026-04-21 12:36 ` [PATCH 1/4] spi: cadence: fix unclocked access on unbind Johan Hovold
2026-04-21 12:36 ` [PATCH 2/4] spi: cadence: fix clock imbalance on probe failure Johan Hovold
2026-04-21 12:36 ` [PATCH 3/4] spi: cadence: rename probe error labels Johan Hovold
2026-04-21 12:36 ` [PATCH 4/4] spi: cadence: clean up probe return value Johan Hovold
2026-04-26 23:25 ` [PATCH 0/4] spi: cadence: runtime PM fixes Mark Brown

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