Skip to contentSkip to conversation

ASoC: codecs: lpass-macro: release macro and dcodec clocks in runtime suspend

PATCH In review Ramón Jesús Miranda 3 participants 4 messages Oct 23 – Oct 28

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ASoC: codecs: lpass-macro: release macro and dcodec clocks in runtime suspend

The LPASS rx, tx, wsa, and va macro codec drivers prepare and enable their "macro" and "dcodec" clocks (which correspond to q6prm LPASS_HW_MACRO and LPASS_HW_DCODEC clock votes to the ADSP) in probe() and only release them in remove(). Their runtime PM callbacks only toggle mclk, npl, and fsgen.

On Qualcomm X1E80100 systems where the ADSP is booted by Linux (such as running at EL2 on the Microsoft Surface Pro 11), keeping the LPASS_HW_MACRO and LPASS_HW_DCODEC votes active while audio is idle prevents the ADSP from entering low-power sleep during s2idle, which in turn blocks the SoC from reaching CX collapse (CXSD) and AOSS sleep (AOSD) (both counters remain at 0). Also, calling clk_disable_unprepare() unconditionally in remove() on clocks already disabled by runtime_suspend() causes clock enable count underflows if the driver is unloaded while runtime-suspended.

Disable "dcodec" and "macro" in runtime_suspend(), re-enable them in runtime_resume(), and guard the clock teardown in remove() with !pm_runtime_status_suspended(). With this change, ADSP, CXSD, and AOSD reach >99.9% residency during s2idle (~0.20 W system sleep power on a Microsoft Surface Pro 11 OLED).

Assisted-by Claude:claude-opus-5-5
Assisted-by Antigravity:gemini-2.5-pro
---
 sound/soc/codecs/lpass-rx-macro.c  | 28 +++++++++++++++++++-----
 sound/soc/codecs/lpass-tx-macro.c  | 28 +++++++++++++++++++-----
 sound/soc/codecs/lpass-va-macro.c  | 35 +++++++++++++++++++++++-------
 sound/soc/codecs/lpass-wsa-macro.c | 28 +++++++++++++++++++-----
 4 files changed, 93 insertions(+), 26 deletions(-)
sound/soc/codecs/lpass-rx-macro.c +22 -6
index 6233aa9..9afebf6 100644
@@ -3935,11 +3935,13 @@ static void rx_macro_remove(struct platform_device *pdev)
 {
 	struct rx_macro *rx = dev_get_drvdata(&pdev->dev);
 
-	clk_disable_unprepare(rx->mclk);
-	clk_disable_unprepare(rx->npl);
-	clk_disable_unprepare(rx->fsgen);
-	clk_disable_unprepare(rx->macro);
-	clk_disable_unprepare(rx->dcodec);
+	if (!pm_runtime_status_suspended(&pdev->dev)) {
+		clk_disable_unprepare(rx->mclk);
+		clk_disable_unprepare(rx->npl);
+		clk_disable_unprepare(rx->fsgen);
+		clk_disable_unprepare(rx->macro);
+		clk_disable_unprepare(rx->dcodec);
+	}
 }
 
 static const struct of_device_id rx_macro_dt_match[] = {
@@ -3976,6 +3978,8 @@ static int rx_macro_runtime_suspend(struct device *dev)
 	clk_disable_unprepare(rx->fsgen);
 	clk_disable_unprepare(rx->npl);
 	clk_disable_unprepare(rx->mclk);
+	clk_disable_unprepare(rx->dcodec);
+	clk_disable_unprepare(rx->macro);
 
 	return 0;
 }
@@ -3985,10 +3989,18 @@ static int rx_macro_runtime_resume(struct device *dev)
 	struct rx_macro *rx = dev_get_drvdata(dev);
 	int ret;
 
+	ret = clk_prepare_enable(rx->macro);
+	if (ret)
+		return ret;
+
+	ret = clk_prepare_enable(rx->dcodec);
+	if (ret)
+		goto err_dcodec;
+
 	ret = clk_prepare_enable(rx->mclk);
 	if (ret) {
 		dev_err(dev, "unable to prepare mclk\n");
-		return ret;
+		goto err_mclk;
 	}
 
 	ret = clk_prepare_enable(rx->npl);
@@ -4010,6 +4022,10 @@ err_fsgen:
 	clk_disable_unprepare(rx->npl);
 err_npl:
 	clk_disable_unprepare(rx->mclk);
+err_mclk:
+	clk_disable_unprepare(rx->dcodec);
+err_dcodec:
+	clk_disable_unprepare(rx->macro);
 
 	return ret;
 }
sound/soc/codecs/lpass-tx-macro.c +22 -6
index 0cbf506..fc4630c 100644
@@ -2390,11 +2390,13 @@ static void tx_macro_remove(struct platform_device *pdev)
 {
 	struct tx_macro *tx = dev_get_drvdata(&pdev->dev);
 
-	clk_disable_unprepare(tx->macro);
-	clk_disable_unprepare(tx->dcodec);
-	clk_disable_unprepare(tx->mclk);
-	clk_disable_unprepare(tx->npl);
-	clk_disable_unprepare(tx->fsgen);
+	if (!pm_runtime_status_suspended(&pdev->dev)) {
+		clk_disable_unprepare(tx->macro);
+		clk_disable_unprepare(tx->dcodec);
+		clk_disable_unprepare(tx->mclk);
+		clk_disable_unprepare(tx->npl);
+		clk_disable_unprepare(tx->fsgen);
+	}
 
 	lpass_macro_pds_exit(tx->pds);
 }
@@ -2409,6 +2411,8 @@ static int tx_macro_runtime_suspend(struct device *dev)
 	clk_disable_unprepare(tx->fsgen);
 	clk_disable_unprepare(tx->npl);
 	clk_disable_unprepare(tx->mclk);
+	clk_disable_unprepare(tx->dcodec);
+	clk_disable_unprepare(tx->macro);
 
 	return 0;
 }
@@ -2418,10 +2422,18 @@ static int tx_macro_runtime_resume(struct device *dev)
 	struct tx_macro *tx = dev_get_drvdata(dev);
 	int ret;
 
+	ret = clk_prepare_enable(tx->macro);
+	if (ret)
+		return ret;
+
+	ret = clk_prepare_enable(tx->dcodec);
+	if (ret)
+		goto err_dcodec;
+
 	ret = clk_prepare_enable(tx->mclk);
 	if (ret) {
 		dev_err(dev, "unable to prepare mclk\n");
-		return ret;
+		goto err_mclk;
 	}
 
 	ret = clk_prepare_enable(tx->npl);
@@ -2444,6 +2456,10 @@ err_fsgen:
 	clk_disable_unprepare(tx->npl);
 err_npl:
 	clk_disable_unprepare(tx->mclk);
+err_mclk:
+	clk_disable_unprepare(tx->dcodec);
+err_dcodec:
+	clk_disable_unprepare(tx->macro);
 
 	return ret;
 }
sound/soc/codecs/lpass-va-macro.c +27 -8
index 58a5798..16f0d44 100644
@@ -1703,12 +1703,14 @@ static void va_macro_remove(struct platform_device *pdev)
 {
 	struct va_macro *va = dev_get_drvdata(&pdev->dev);
 
-	if (va->has_npl_clk)
-		clk_disable_unprepare(va->npl);
+	if (!pm_runtime_status_suspended(&pdev->dev)) {
+		if (va->has_npl_clk)
+			clk_disable_unprepare(va->npl);
 
-	clk_disable_unprepare(va->mclk);
-	clk_disable_unprepare(va->dcodec);
-	clk_disable_unprepare(va->macro);
+		clk_disable_unprepare(va->mclk);
+		clk_disable_unprepare(va->dcodec);
+		clk_disable_unprepare(va->macro);
+	}
 
 	lpass_macro_pds_exit(va->pds);
 }
@@ -1725,6 +1727,8 @@ static int va_macro_runtime_suspend(struct device *dev)
 
 	clk_disable_unprepare(va->mclk);
 
+	clk_disable_unprepare(va->dcodec);
+	clk_disable_unprepare(va->macro);
 	return 0;
 }
 
@@ -1733,18 +1737,25 @@ static int va_macro_runtime_resume(struct device *dev)
 	struct va_macro *va = dev_get_drvdata(dev);
 	int ret;
 
+	ret = clk_prepare_enable(va->macro);
+	if (ret)
+		return ret;
+
+	ret = clk_prepare_enable(va->dcodec);
+	if (ret)
+		goto err_dcodec;
+
 	ret = clk_prepare_enable(va->mclk);
 	if (ret) {
 		dev_err(va->dev, "unable to prepare mclk\n");
-		return ret;
+		goto err_mclk;
 	}
 
 	if (va->has_npl_clk) {
 		ret = clk_prepare_enable(va->npl);
 		if (ret) {
-			clk_disable_unprepare(va->mclk);
 			dev_err(va->dev, "unable to prepare npl\n");
-			return ret;
+			goto err_npl;
 		}
 	}
 
@@ -1752,6 +1763,14 @@ static int va_macro_runtime_resume(struct device *dev)
 	regcache_sync(va->regmap);
 
 	return 0;
+err_npl:
+	clk_disable_unprepare(va->mclk);
+err_mclk:
+	clk_disable_unprepare(va->dcodec);
+err_dcodec:
+	clk_disable_unprepare(va->macro);
+
+	return ret;
 }
 
 
sound/soc/codecs/lpass-wsa-macro.c +22 -6
index af521e0..7579eab 100644
@@ -2842,11 +2842,13 @@ static void wsa_macro_remove(struct platform_device *pdev)
 {
 	struct wsa_macro *wsa = dev_get_drvdata(&pdev->dev);
 
-	clk_disable_unprepare(wsa->macro);
-	clk_disable_unprepare(wsa->dcodec);
-	clk_disable_unprepare(wsa->mclk);
-	clk_disable_unprepare(wsa->npl);
-	clk_disable_unprepare(wsa->fsgen);
+	if (!pm_runtime_status_suspended(&pdev->dev)) {
+		clk_disable_unprepare(wsa->macro);
+		clk_disable_unprepare(wsa->dcodec);
+		clk_disable_unprepare(wsa->mclk);
+		clk_disable_unprepare(wsa->npl);
+		clk_disable_unprepare(wsa->fsgen);
+	}
 }
 
 static int wsa_macro_runtime_suspend(struct device *dev)
@@ -2860,6 +2862,8 @@ static int wsa_macro_runtime_suspend(struct device *dev)
 	clk_disable_unprepare(wsa->npl);
 	clk_disable_unprepare(wsa->mclk);
 
+	clk_disable_unprepare(wsa->dcodec);
+	clk_disable_unprepare(wsa->macro);
 	return 0;
 }
 
@@ -2868,10 +2872,18 @@ static int wsa_macro_runtime_resume(struct device *dev)
 	struct wsa_macro *wsa = dev_get_drvdata(dev);
 	int ret;
 
+	ret = clk_prepare_enable(wsa->macro);
+	if (ret)
+		return ret;
+
+	ret = clk_prepare_enable(wsa->dcodec);
+	if (ret)
+		goto err_dcodec;
+
 	ret = clk_prepare_enable(wsa->mclk);
 	if (ret) {
 		dev_err(dev, "unable to prepare mclk\n");
-		return ret;
+		goto err_mclk;
 	}
 
 	ret = clk_prepare_enable(wsa->npl);
@@ -2894,6 +2906,10 @@ err_fsgen:
 	clk_disable_unprepare(wsa->npl);
 err_npl:
 	clk_disable_unprepare(wsa->mclk);
+err_mclk:
+	clk_disable_unprepare(wsa->dcodec);
+err_dcodec:
+	clk_disable_unprepare(wsa->macro);
 
 	return ret;
 }
Signature · 1 line
2.56.0
#1 lore raw
Quoted 14 lines · Ramón Jesús Miranda

The LPASS rx, tx, wsa, and va macro codec drivers prepare and enable their "macro" and "dcodec" clocks (which correspond to q6prm LPASS_HW_MACRO and LPASS_HW_DCODEC clock votes to the ADSP) in probe() and only release them in remove(). Their runtime PM callbacks only toggle mclk, npl, and fsgen.

On Qualcomm X1E80100 systems where the ADSP is booted by Linux (such as running at EL2 on the Microsoft Surface Pro 11), keeping the LPASS_HW_MACRO and LPASS_HW_DCODEC votes active while audio is idle prevents the ADSP from entering low-power sleep during s2idle, which in turn blocks the SoC from reaching CX collapse (CXSD) and AOSS sleep (AOSD) (both counters remain at 0). Also, calling clk_disable_unprepare() unconditionally in remove() on clocks already disabled by runtime_suspend() causes clock enable count underflows if the driver is unloaded while runtime-suspended.

Quoted 8 lines

Disable "dcodec" and "macro" in runtime_suspend(), re-enable them in runtime_resume(), and guard the clock teardown in remove() with !pm_runtime_status_suspended(). With this change, ADSP, CXSD, and AOSD reach >99.9% residency during s2idle (~0.20 W system sleep power on a Microsoft Surface Pro 11 OLED).

Assisted-by Claude:claude-opus-5-5
Assisted-by Antigravity:gemini-2.5-pro

Advertisements for particular slop-generators are discouraged since 816d9992d9ed ("coding-assistants: simplify attribution") btw, and the tag is no longer required since 1e035297ffda ("docs: remove Assisted-by references").

Quoted 13 lines

[..]

sound/soc/codecs/lpass-tx-macro.c +1 -5
@@ -2390,11 +2390,13 @@ static void tx_macro_remove(struct platform_device *pdev)
  {
  	struct tx_macro *tx = dev_get_drvdata(&pdev->dev);
 
-	clk_disable_unprepare(tx->macro);
-	clk_disable_unprepare(tx->dcodec);
-	clk_disable_unprepare(tx->mclk);
-	clk_disable_unprepare(tx->npl);
-	clk_disable_unprepare(tx->fsgen);
+	if (!pm_runtime_status_suspended(&pdev->dev)) {

sound/soc/codecs/lpass-tx-macro.c static void tx_macro_remove(struct platform_device *pdev) · line 2402

Quoted 10 lines
sound/soc/codecs/lpass-tx-macro.c +6 -0
+		clk_disable_unprepare(tx->macro);
+		clk_disable_unprepare(tx->dcodec);
+		clk_disable_unprepare(tx->mclk);
+		clk_disable_unprepare(tx->npl);
+		clk_disable_unprepare(tx->fsgen);
+	}
 
  	lpass_macro_pds_exit(tx->pds);
  }
[..]

You're working with a tree that's months out of date! This does not apply to linux-next at all.

Commit a5ee3180a2a7 ("ASoC: codecs: lpass-{tx,rx}-macro: switch to PM clock framework") back in July removed all of these calls, and the clocks are now automatically managed by the framework, which has solved the issue.

Several people in #aarch64-laptops have gotten CXSD state working recently, and no one touched sound/soc/codecs.

~val

#2 lore raw
Quoted 5 lines · On 10/24/26 Val Packett wrote:

You're working with a tree that's months out of date! This does not apply to linux-next at all.

Commit a5ee3180a2a7 ("ASoC: codecs: lpass-{tx,rx}-macro: switch to PM clock framework")

Thanks, you are right: I was on a 7.2-based downstream tree. With the PM clock framework in all four macros this patch is not needed, so please consider it withdrawn. I will check against linux-next before sending anything else, and I will drop the attribution tags.

Ramón

maintainer
#3 lore raw
In reply to Ramón Jesús Miranda
Quoted 4 lines · Ramón Jesús Miranda

The LPASS rx, tx, wsa, and va macro codec drivers prepare and enable their "macro" and "dcodec" clocks (which correspond to q6prm LPASS_HW_MACRO and LPASS_HW_DCODEC clock votes to the ADSP) in probe() and only release them in remove(). Their runtime PM callbacks only toggle mclk, npl, and fsgen.

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