mirror of https://lore.kernel.org/linux-amlogic/
 help / color / mirror / Atom feed
* [PATCH] spi: amlogic-spisg: fix managed clock ownership
@ 2026-11-29 12:40 Jiawen Liu
  2026-11-30 13:43 ` Mark Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Jiawen Liu @ 2026-11-29 12:40 UTC (permalink / raw)
  To: Sunny Luo, Xianwei Zhao, Mark Brown
  Cc: linux-amlogic, linux-spi, linux-kernel

devm_clk_get_enabled() registers automatic cleanup for core and pclk,
but the driver also disables both clocks manually during initialization,
runtime PM, and removal. Devres later releases the original managed
enable again.

Obtain both clock handles with devm_clk_get(). Enable core at the start
of clock initialization and disable it on all later setup errors. Enable
pclk explicitly only while configuring the divider, and balance that
temporary enable. The divider-derived sclk now owns the parent enable,
so disable sclk before core in probe error and active-remove cleanup.

Fixes: cef9991e04ae ("spi: Add Amlogic SPISG driver")
Signed-off-by: Jiawen Liu <1298662399@qq.com>
---
 drivers/spi/spi-amlogic-spisg.c | 46 ++++++++++++++++++++++++---------
 1 file changed, 34 insertions(+), 12 deletions(-)

diff --git a/drivers/spi/spi-amlogic-spisg.c b/drivers/spi/spi-amlogic-spisg.c
index c59df9b115eed..0b44875628858 100644
--- a/drivers/spi/spi-amlogic-spisg.c
+++ b/drivers/spi/spi-amlogic-spisg.c
@@ -692,16 +692,29 @@ static int aml_spisg_clk_init(struct spisg_device *spisg, void __iomem *base)
 	char name[32];
 	int ret, i;
 
-	spisg->core = devm_clk_get_enabled(dev, "core");
+	spisg->core = devm_clk_get(dev, "core");
 	if (IS_ERR(spisg->core)) {
 		dev_err(dev, "core clock request failed\n");
 		return PTR_ERR(spisg->core);
 	}
 
-	spisg->pclk = devm_clk_get_enabled(dev, "pclk");
+	ret = clk_prepare_enable(spisg->core);
+	if (ret) {
+		dev_err(dev, "core clock enable failed\n");
+		return ret;
+	}
+
+	spisg->pclk = devm_clk_get(dev, "pclk");
 	if (IS_ERR(spisg->pclk)) {
 		dev_err(dev, "pclk clock request failed\n");
-		return PTR_ERR(spisg->pclk);
+		ret = PTR_ERR(spisg->pclk);
+		goto err_disable_core;
+	}
+
+	ret = clk_prepare_enable(spisg->pclk);
+	if (ret) {
+		dev_err(dev, "pclk clock enable failed\n");
+		goto err_disable_core;
 	}
 
 	clk_set_min_rate(spisg->pclk, SPISG_PCLK_RATE_MIN);
@@ -709,8 +722,10 @@ static int aml_spisg_clk_init(struct spisg_device *spisg, void __iomem *base)
 	clk_disable_unprepare(spisg->pclk);
 
 	tbl = devm_kzalloc_objs(dev, *tbl, (DIV_NUM + 1));
-	if (!tbl)
-		return -ENOMEM;
+	if (!tbl) {
+		ret = -ENOMEM;
+		goto err_disable_core;
+	}
 
 	for (i = 0; i < DIV_NUM; i++) {
 		tbl[i].val = i + SPISG_CLK_DIV_MIN - 1;
@@ -719,8 +734,10 @@ static int aml_spisg_clk_init(struct spisg_device *spisg, void __iomem *base)
 	spisg->tbl = tbl;
 
 	div = devm_kzalloc_obj(dev, *div);
-	if (!div)
-		return -ENOMEM;
+	if (!div) {
+		ret = -ENOMEM;
+		goto err_disable_core;
+	}
 
 	div->flags = CLK_DIVIDER_ROUND_CLOSEST;
 	div->reg = base + SPISG_REG_CFG_BUS;
@@ -745,20 +762,25 @@ static int aml_spisg_clk_init(struct spisg_device *spisg, void __iomem *base)
 	ret = devm_clk_hw_register(dev, &div->hw);
 	if (ret) {
 		dev_err(dev, "clock registration failed\n");
-		return ret;
+		goto err_disable_core;
 	}
 
 	spisg->sclk = devm_clk_hw_get_clk(dev, &div->hw, NULL);
 	if (IS_ERR(spisg->sclk)) {
 		dev_err(dev, "get clock failed\n");
-		return PTR_ERR(spisg->sclk);
+		ret = PTR_ERR(spisg->sclk);
+		goto err_disable_core;
 	}
 
 	ret = clk_prepare_enable(spisg->sclk);
 	if (ret)
-		return ret;
+		goto err_disable_core;
 
 	return 0;
+
+err_disable_core:
+	clk_disable_unprepare(spisg->core);
+	return ret;
 }
 
 static int aml_spisg_probe(struct platform_device *pdev)
@@ -869,9 +891,9 @@ static int aml_spisg_probe(struct platform_device *pdev)
 
 	return 0;
 out_clk:
+	clk_disable_unprepare(spisg->sclk);
 	if (spisg->core)
 		clk_disable_unprepare(spisg->core);
-	clk_disable_unprepare(spisg->pclk);
 
 	return ret;
 }
@@ -884,8 +906,8 @@ static void aml_spisg_remove(struct platform_device *pdev)
 
 	if (!pm_runtime_suspended(&pdev->dev)) {
 		pinctrl_pm_select_sleep_state(&spisg->pdev->dev);
+		clk_disable_unprepare(spisg->sclk);
 		clk_disable_unprepare(spisg->core);
-		clk_disable_unprepare(spisg->pclk);
 	}
 }
 
-- 
2.34.1


_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

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

* Re: [PATCH] spi: amlogic-spisg: fix managed clock ownership
  2026-11-29 12:40 [PATCH] spi: amlogic-spisg: fix managed clock ownership Jiawen Liu
@ 2026-11-30 13:43 ` Mark Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2026-11-30 13:43 UTC (permalink / raw)
  To: Jiawen Liu
  Cc: Sunny Luo, Xianwei Zhao, linux-amlogic, linux-spi, linux-kernel


[-- Attachment #1.1: Type: text/plain, Size: 360 bytes --]

On Sun, Nov 29, 2026 at 04:40:13PM +0400, Jiawen Liu wrote:
> devm_clk_get_enabled() registers automatic cleanup for core and pclk,
> but the driver also disables both clocks manually during initialization,
> runtime PM, and removal. Devres later releases the original managed
> enable again.

This doesn't apply against current code, please check and resend.

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

[-- Attachment #2: Type: text/plain, Size: 167 bytes --]

_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

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

end of thread, other threads:[~2026-11-30 13:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-29 12:40 [PATCH] spi: amlogic-spisg: fix managed clock ownership Jiawen Liu
2026-11-30 13:43 ` Mark Brown

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

all inboxes | Powered by JetHome®