Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/20] ASoC: propagate register restore failures
@ 2026-08-28 11:33 Pengpeng Hou
  2026-08-28 11:34 ` [PATCH 19/20] ASoC: mediatek: mt8186: Unwind runtime resume failures Pengpeng Hou
  2026-08-28 11:34 ` [PATCH 20/20] ASoC: mediatek: mt8196: Unwind register clock and cache restore failures Pengpeng Hou
  0 siblings, 2 replies; 3+ messages in thread
From: Pengpeng Hou @ 2026-08-28 11:33 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown
  Cc: Pengpeng Hou, AngeloGioacchino Del Regno, Baojun Xu,
	Cássio Gabriel, Cyril Chao, Darren Ye, David Rhodes,
	Kevin Lu, Kuninori Morimoto, Lars-Peter Clausen, linux-arm-kernel,
	linux-kernel, linux-mediatek, linux-mips, linux-sound,
	Matthias Brugger, Nuno Sá, patches, Paul Cercueil,
	Jaroslav Kysela, Richard Fitzgerald, Sen Wang, Shenghao Ding,
	Takashi Iwai

Several ASoC codec and AFE power transitions restore cached register state
after reset or power loss.  The callbacks in this series all have an effective
error consumer: component probe or hw_params, DAPM bias handling, device
runtime PM, or system PM.  They currently continue or publish success after a
required register operation failed.

Check the complete local restore transaction at each site and unwind clocks,
supplies, GPIOs, cache state or software publication where that transaction
acquired them.  For the Mediatek AFE drivers this also makes the clock helpers
unwind partial internal acquisition prefixes before returning to runtime PM.

This is a new set of sites, not a revision of the earlier 19-patch series at:

  https://lore.kernel.org/all/20260704034845.14291-1-pengpeng@iscas.ac.cn/

It intentionally excludes snd_soc_component_driver resume callbacks whose
return values are discarded by snd_soc_component_resume(); that shared policy
is being discussed separately.  The cs42l42 patch covers the shared system
resume helper and is distinct from the SoundWire runtime-resume path fixed by
commit a118fea777a2.

The issues were identified via static analysis and manually reviewed.

Assisted-by: LLM

Pengpeng Hou (20):
  ASoC: adau1372: Unwind failed power restoration
  ASoC: adau1701: Propagate register cache replay errors
  ASoC: cs35l56: Propagate register restore errors from runtime resume
  ASoC: cs42l42: Propagate system resume restore errors
  ASoC: es9356: Publish IRQ readiness after cache replay
  ASoC: jz4740: Propagate codec wake-up errors
  ASoC: max98088: Propagate cache replay errors from bias restore
  ASoC: ssm2518: Unwind failed power restoration
  ASoC: ssm4567: Unwind failed power restoration
  ASoC: tlv320aic3x: Propagate power restoration errors
  ASoC: wm8731: Unwind supplies on cache replay failure
  ASoC: wm8770: Unwind supplies on cache replay failure
  ASoC: wm8804: Propagate cache replay errors from runtime resume
  ASoC: wm8904: Unwind resources on cache replay failure
  ASoC: wm8985: Unwind supplies on cache replay failure
  ASoC: wm8991: Propagate cache replay errors from bias restore
  ASoC: wm8993: Unwind supplies on cache replay failure
  ASoC: wm8996: Unwind supplies on cache replay failure
  ASoC: mediatek: mt8186: Unwind runtime resume failures
  ASoC: mediatek: mt8196: Unwind register clock and cache restore
    failures

 sound/soc/codecs/adau1372.c                | 44 ++++++++++++++--------
 sound/soc/codecs/adau1701.c                |  4 +-
 sound/soc/codecs/cs35l56-shared.c          |  9 ++++-
 sound/soc/codecs/cs42l42-sdw.c             |  4 +-
 sound/soc/codecs/cs42l42.c                 | 27 +++++++++----
 sound/soc/codecs/cs42l42.h                 |  2 +-
 sound/soc/codecs/es9356.c                  | 14 +++++--
 sound/soc/codecs/jz4740.c                  | 25 ++++++++----
 sound/soc/codecs/max98088.c                |  9 ++++-
 sound/soc/codecs/ssm2518.c                 | 15 +++++++-
 sound/soc/codecs/ssm4567.c                 | 15 +++++++-
 sound/soc/codecs/tlv320aic3x.c             | 36 ++++++++++++++----
 sound/soc/codecs/wm8731.c                  |  7 +++-
 sound/soc/codecs/wm8770.c                  |  7 +++-
 sound/soc/codecs/wm8804.c                  |  6 ++-
 sound/soc/codecs/wm8904.c                  | 10 ++++-
 sound/soc/codecs/wm8985.c                  |  7 +++-
 sound/soc/codecs/wm8991.c                  |  7 +++-
 sound/soc/codecs/wm8993.c                  |  9 ++++-
 sound/soc/codecs/wm8996.c                  | 11 +++++-
 sound/soc/mediatek/mt8186/mt8186-afe-clk.c |  2 +
 sound/soc/mediatek/mt8186/mt8186-afe-pcm.c | 15 +++++++-
 sound/soc/mediatek/mt8196/mt8196-afe-clk.c | 27 ++++++++++---
 sound/soc/mediatek/mt8196/mt8196-afe-pcm.c |  8 +++-
 24 files changed, 251 insertions(+), 69 deletions(-)

-- 
2.43.0



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

* [PATCH 19/20] ASoC: mediatek: mt8186: Unwind runtime resume failures
  2026-08-28 11:33 [PATCH 00/20] ASoC: propagate register restore failures Pengpeng Hou
@ 2026-08-28 11:34 ` Pengpeng Hou
  2026-08-28 11:34 ` [PATCH 20/20] ASoC: mediatek: mt8196: Unwind register clock and cache restore failures Pengpeng Hou
  1 sibling, 0 replies; 3+ messages in thread
From: Pengpeng Hou @ 2026-08-28 11:34 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown
  Cc: Pengpeng Hou, Jaroslav Kysela, Takashi Iwai, Matthias Brugger,
	AngeloGioacchino Del Regno, linux-sound, linux-kernel,
	linux-arm-kernel, linux-mediatek, Kuninori Morimoto

mt8186_afe_runtime_resume() enables the base clocks and then a range of
clock gates before replaying the register cache.
mt8186_afe_enable_cgs() returns on the first failed gate without
disabling gates from the successful prefix, and runtime resume also
ignores regcache_sync().

Make the gate helper unwind its own partial prefix.  Route gate setup
failure through base-clock cleanup, and on cache replay failure restore
cache-only and dirty state before disabling all gates and base clocks.

The issue was identified via static analysis and manually reviewed.

Fixes: 097e874ad3fc ("ASoC: mediatek: mt8186: add platform driver")

Assisted-by: LLM
Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
---
 sound/soc/mediatek/mt8186/mt8186-afe-clk.c |  2 ++
 sound/soc/mediatek/mt8186/mt8186-afe-pcm.c | 15 +++++++++++++--
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/sound/soc/mediatek/mt8186/mt8186-afe-clk.c b/sound/soc/mediatek/mt8186/mt8186-afe-clk.c
index daaca36a2d08..a7034aea2678 100644
--- a/sound/soc/mediatek/mt8186/mt8186-afe-clk.c
+++ b/sound/soc/mediatek/mt8186/mt8186-afe-clk.c
@@ -221,6 +221,8 @@ int mt8186_afe_enable_cgs(struct mtk_base_afe *afe)
 		if (ret) {
 			dev_err(afe->dev, "%s clk_prepare_enable %s fail %d\n",
 				__func__, aud_clks[i], ret);
+			while (--i >= CLK_I2S1_BCLK)
+				clk_disable_unprepare(afe_priv->clk[i]);
 			return ret;
 		}
 	}
diff --git a/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c b/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c
index 44a521c3a610..2888a49e9db2 100644
--- a/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c
+++ b/sound/soc/mediatek/mt8186/mt8186-afe-pcm.c
@@ -2737,13 +2737,18 @@ static int mt8186_afe_runtime_resume(struct device *dev)
 
 	ret = mt8186_afe_enable_cgs(afe);
 	if (ret)
-		return ret;
+		goto disable_clock;
 
 	if (!afe->regmap || afe_priv->pm_runtime_bypass_reg_ctl)
 		goto skip_regmap;
 
 	regcache_cache_only(afe->regmap, false);
-	regcache_sync(afe->regmap);
+	ret = regcache_sync(afe->regmap);
+	if (ret) {
+		regcache_cache_only(afe->regmap, true);
+		regcache_mark_dirty(afe->regmap);
+		goto disable_cgs;
+	}
 
 	/* enable audio sys DCM for power saving */
 	regmap_update_bits(afe_priv->infracfg, PERI_BUS_DCM_CTRL, BIT(29), BIT(29));
@@ -2761,6 +2766,12 @@ static int mt8186_afe_runtime_resume(struct device *dev)
 
 skip_regmap:
 	return 0;
+
+disable_cgs:
+	mt8186_afe_disable_cgs(afe);
+disable_clock:
+	mt8186_afe_disable_clock(afe);
+	return ret;
 }
 
 static int mt8186_afe_component_probe(struct snd_soc_component *component)
-- 
2.43.0



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

* [PATCH 20/20] ASoC: mediatek: mt8196: Unwind register clock and cache restore failures
  2026-08-28 11:33 [PATCH 00/20] ASoC: propagate register restore failures Pengpeng Hou
  2026-08-28 11:34 ` [PATCH 19/20] ASoC: mediatek: mt8186: Unwind runtime resume failures Pengpeng Hou
@ 2026-08-28 11:34 ` Pengpeng Hou
  1 sibling, 0 replies; 3+ messages in thread
From: Pengpeng Hou @ 2026-08-28 11:34 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown
  Cc: Pengpeng Hou, Jaroslav Kysela, Takashi Iwai, Matthias Brugger,
	AngeloGioacchino Del Regno, linux-sound, linux-kernel,
	linux-arm-kernel, linux-mediatek, Cyril Chao, Darren Ye,
	Cássio Gabriel

mt8196_afe_runtime_resume() first acquires three register-access clocks
and then replays the register cache.  mt8196_afe_enable_reg_rw_clk()
ignores each clock-enable result and leaks already enabled clocks when a
later rate change fails.  Runtime resume also ignores regcache_sync()
and proceeds with 26 MHz requests and main-clock enable.

Make the register-clock helper acquire transactionally and unwind the
successful prefix on every failure.  Return cache replay errors after
restoring cache-only and dirty state and disabling the three
register-access clocks.

The issue was identified via static analysis and manually reviewed.

Fixes: 7384ecab34eb ("ASoC: mediatek: mt8196: support audio clock control")
Fixes: 57513aabfe5b ("ASoC: mediatek: mt8196: add platform driver")

Assisted-by: LLM
Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
---
 sound/soc/mediatek/mt8196/mt8196-afe-clk.c | 27 ++++++++++++++++++----
 sound/soc/mediatek/mt8196/mt8196-afe-pcm.c |  8 ++++++-
 2 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/sound/soc/mediatek/mt8196/mt8196-afe-clk.c b/sound/soc/mediatek/mt8196/mt8196-afe-clk.c
index 286e39f53ae0..ea0835e73510 100644
--- a/sound/soc/mediatek/mt8196/mt8196-afe-clk.c
+++ b/sound/soc/mediatek/mt8196/mt8196-afe-clk.c
@@ -511,26 +511,43 @@ int mt8196_afe_enable_reg_rw_clk(struct mtk_base_afe *afe)
 	int ret;
 
 	/* bus clock for AFE external access, like DRAM */
-	mt8196_afe_enable_clk(afe, afe_priv->clk[MT8196_CLK_TOP_ADSP_SEL]);
+	ret = mt8196_afe_enable_clk(afe, afe_priv->clk[MT8196_CLK_TOP_ADSP_SEL]);
+	if (ret)
+		return ret;
 
 	/* bus clock for AFE internal access, like AFE SRAM */
-	mt8196_afe_enable_clk(afe, afe_priv->clk[MT8196_CLK_VLP_MUX_AUDIOINTBUS]);
+	ret = mt8196_afe_enable_clk(afe,
+				    afe_priv->clk[MT8196_CLK_VLP_MUX_AUDIOINTBUS]);
+	if (ret)
+		goto disable_adsp;
+
 	ret = mt8196_afe_set_clk_rate(afe, afe_priv->clk[MT8196_CLK_VLP_MUX_AUDIOINTBUS],
 				      MT8196_AFE_26M);
 	if (ret)
-		return ret;
+		goto disable_intbus;
 
 	/* enable audio h clock */
-	mt8196_afe_enable_clk(afe, afe_priv->clk[MT8196_CLK_VLP_MUX_AUDIO_H]);
+	ret = mt8196_afe_enable_clk(afe, afe_priv->clk[MT8196_CLK_VLP_MUX_AUDIO_H]);
+	if (ret)
+		goto disable_intbus;
+
 	ret = mt8196_afe_set_clk_rate(afe, afe_priv->clk[MT8196_CLK_VLP_MUX_AUDIO_H],
 				      MT8196_AFE_26M);
 	if (ret)
-		return ret;
+		goto disable_audio_h;
 
 	/* AFE hw clock */
 	/* IPM2.0: USE HOPPING & 26M */
 	/* set in the regmap_register_patch */
 	return 0;
+
+disable_audio_h:
+	mt8196_afe_disable_clk(afe, afe_priv->clk[MT8196_CLK_VLP_MUX_AUDIO_H]);
+disable_intbus:
+	mt8196_afe_disable_clk(afe, afe_priv->clk[MT8196_CLK_VLP_MUX_AUDIOINTBUS]);
+disable_adsp:
+	mt8196_afe_disable_clk(afe, afe_priv->clk[MT8196_CLK_TOP_ADSP_SEL]);
+	return ret;
 }
 
 int mt8196_afe_disable_reg_rw_clk(struct mtk_base_afe *afe)
diff --git a/sound/soc/mediatek/mt8196/mt8196-afe-pcm.c b/sound/soc/mediatek/mt8196/mt8196-afe-pcm.c
index a1ae8322d8b6..49283f242c00 100644
--- a/sound/soc/mediatek/mt8196/mt8196-afe-pcm.c
+++ b/sound/soc/mediatek/mt8196/mt8196-afe-pcm.c
@@ -2222,7 +2222,13 @@ static int mt8196_afe_runtime_resume(struct device *dev)
 		goto skip_regmap;
 	}
 	regcache_cache_only(afe->regmap, false);
-	regcache_sync(afe->regmap);
+	ret = regcache_sync(afe->regmap);
+	if (ret) {
+		regcache_cache_only(afe->regmap, true);
+		regcache_mark_dirty(afe->regmap);
+		mt8196_afe_disable_reg_rw_clk(afe);
+		return ret;
+	}
 
 	/* set audio 26M request */
 	regmap_update_bits(afe->regmap, AFE_SPM_CONTROL_REQ, 0x1, 0x1);
-- 
2.43.0



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

end of thread, other threads:[~2026-08-28 11:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-28 11:33 [PATCH 00/20] ASoC: propagate register restore failures Pengpeng Hou
2026-08-28 11:34 ` [PATCH 19/20] ASoC: mediatek: mt8186: Unwind runtime resume failures Pengpeng Hou
2026-08-28 11:34 ` [PATCH 20/20] ASoC: mediatek: mt8196: Unwind register clock and cache restore failures Pengpeng Hou

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