ASoC: stop dependent resume work after restore failures
Subsystems (4)
v2 cover ASoC: stop dependent resume work after restore failures
This revision addresses Mark's cache-mode concern and Charles's WM8978 bias rollback question. It also accounts for the next suspend after a failed resume: the ASoC wrapper reports the callback error but marks the component resumed, so leaving an IRQ disabled needs driver-local ownership tracking to avoid disabling it a second time in the next suspend.
All nine changes retain best-effort card resume. They do not add framework rollback or automatic retries. The RT5682 SoundWire branch and RT5677 retained VAD path keep their existing behavior. RT5640 handles both IRQ producers of jack work and clears ownership when either IRQ is freed. RT5677 also propagates normal-mode transport write errors and remembers pending restoration across later changes to the requested VAD mode.
These issues were found by our static-analysis tool and manually reviewed. The code and descriptions were prepared with gpt 5 assistance; the patches carry the corresponding Assisted-by trailers.
Changes since v1:
- restore cache-only mode and preserve dirty state on replay errors
- avoid repeated suspend-owned IRQ disables after failed resume
- return WM8978 bias to OFF on failure, without claiming hardware rollback is guaranteed when the bias callback itself ignores register errors
- clear WM8978 PLL power as system suspend does
- quiesce both RT5640 jack IRQs and reject fresh setup while unrestored
- fix RT5677's normal-mode write error propagation and pending-restore state
- preserve the per-driver power, SoundWire and DSP VAD distinctions
- resend all members as one series rather than separate unthreaded posts
Previous series:
https://lore.kernel.org/all/[email protected]/
Base: 8ef28aef33f2d5da6959ad6b579ec3cfccc009f6 (sound/for-next)
1. ASoC: nau8821: restore safe state after resume errors
2. ASoC: nau8824: restore safe state after resume errors
3. ASoC: nau8825: restore safe state after resume errors
4. ASoC: rt5663: restore safe state after resume errors
5. ASoC: rt5682s: restore safe state after resume errors
6. ASoC: rt5682: restore safe state after resume errors
7. ASoC: wm8978: restore safe state after resume errors
8. ASoC: rt5640: restore safe state after resume errors
9. ASoC: rt5677: restore safe state after resume errors
PATCH v2 1/9 ASoC: nau8821: restore safe state after resume errors
nau8821_resume() ignores regcache_sync() failure before continuing dependent resume operations. Restore cache-only mode, leave the cache dirty, and return the replay error before those operations.
Leave jack-detection IRQs disabled after a failed replay.
ASoC still marks the component resumed when the callback reports failure. Track the suspend-owned IRQ disable so another suspend does not increment the disable depth again after a failed resume. A later successful resume releases that one disable reference. This does not add automatic retry or change the framework's best-effort card resume policy.
The issue was found by our static-analysis tool and manually reviewed.
---
Changes since v1:
- restore cache-only mode and dirty state on replay failure
- keep suspend-owned IRQ disables balanced across failed resume cycles
- send as one correctly threaded series, as Mark requested
Previous series:
https://lore.kernel.org/all/[email protected]/
sound/soc/codecs/nau8821.c | 16 +++++++++++++--- sound/soc/codecs/nau8821.h | 1 + 2 files changed, 14 insertions(+), 3 deletions(-)
sound/soc/codecs/nau8821.c +13 -3
@@ -1620,8 +1620,10 @@ static int __maybe_unused nau8821_suspend(struct snd_soc_component *component) {struct nau8821 *nau8821 =snd_soc_component_get_drvdata (component); -if (nau8821->irq) +if (nau8821->irq && !nau8821->suspend_irq_disabled) {disable_irq (nau8821->irq); + nau8821->suspend_irq_disabled = true; + }if (nau8821->jdet_active)cancel_delayed_work_sync (&nau8821->jdet_work);
@@ -1639,11 +1641,19 @@ static int __maybe_unused nau8821_suspend(struct snd_soc_component *component)static int __maybe_unused nau8821_resume (struct snd_soc_component *component) {struct nau8821 *nau8821 =snd_soc_component_get_drvdata (component); +int ret;regcache_cache_only (nau8821->regmap, false); -regcache_sync (nau8821->regmap); -if (nau8821->irq) + ret =regcache_sync (nau8821->regmap); +if (ret) { +regcache_cache_only (nau8821->regmap, true); +regcache_mark_dirty (nau8821->regmap); +return ret; + } +if (nau8821->suspend_irq_disabled) { + nau8821->suspend_irq_disabled = false;enable_irq (nau8821->irq); + }return 0 ; }
sound/soc/codecs/nau8821.h +1 -0
@@ -563,6 +563,7 @@ struct nau8821 {struct snd_soc_jack *jack;struct delayed_work jdet_work;bool jdet_active; +bool suspend_irq_disabled;int irq;int clk_id;int micbias_voltage;
base-commit: 8ef28aef33f2d5da6959ad6b579ec3cfccc009f6
PATCH v2 2/9 ASoC: nau8824: restore safe state after resume errors
In reply to Pengpeng Hounau8824_resume() ignores regcache_sync() failure before continuing dependent resume operations. Restore cache-only mode, leave the cache dirty, and return the replay error before those operations.
Do not acquire the jack-detection semaphore or enable its IRQ after a failed replay.
ASoC still marks the component resumed when the callback reports failure. Track the suspend-owned IRQ disable so another suspend does not increment the disable depth again after a failed resume. A later successful resume releases that one disable reference. This does not add automatic retry or change the framework's best-effort card resume policy.
The issue was found by our static-analysis tool and manually reviewed.
---
Changes since v1:
- restore cache-only mode and dirty state on replay failure
- keep suspend-owned IRQ disables balanced across failed resume cycles
- send as one correctly threaded series, as Mark requested
Previous series:
https://lore.kernel.org/all/[email protected]/
sound/soc/codecs/nau8824.c | 17 ++++++++++++++--- sound/soc/codecs/nau8824.h | 1 + 2 files changed, 15 insertions(+), 3 deletions(-)
sound/soc/codecs/nau8824.c +14 -3
@@ -1531,7 +1531,10 @@ static int __maybe_unused nau8824_suspend(struct snd_soc_component *component)struct nau8824 *nau8824 =snd_soc_component_get_drvdata (component);if (nau8824->irq) { -disable_irq (nau8824->irq); +if (!nau8824->suspend_irq_disabled) { +disable_irq (nau8824->irq); + nau8824->suspend_irq_disabled = true; + }snd_soc_dapm_force_bias_level (nau8824->dapm,SND_SOC_BIAS_OFF ); }regcache_cache_only (nau8824->regmap, true);
@@ -1546,7 +1549,12 @@ static int __maybe_unused nau8824_resume(struct snd_soc_component *component)int ret;regcache_cache_only (nau8824->regmap, false); -regcache_sync (nau8824->regmap); + ret =regcache_sync (nau8824->regmap); +if (ret) { +regcache_cache_only (nau8824->regmap, true); +regcache_mark_dirty (nau8824->regmap); +return ret; + }if (nau8824->irq) {/* Hold semaphore to postpone playback happening * until jack detection done.
@@ -1555,7 +1563,10 @@ static int __maybe_unused nau8824_resume(struct snd_soc_component *component) ret =nau8824_sema_acquire (nau8824,0 );if (ret) nau8824->resume_lock = false; -enable_irq (nau8824->irq); +if (nau8824->suspend_irq_disabled) { + nau8824->suspend_irq_disabled = false; +enable_irq (nau8824->irq); + } }return 0 ;
sound/soc/codecs/nau8824.h +1 -0
@@ -437,6 +437,7 @@ struct nau8824 {struct clk *mclk;int fs;int irq; +bool suspend_irq_disabled;int resume_lock;int micbias_voltage;int vref_impedance;
base-commit: 8ef28aef33f2d5da6959ad6b579ec3cfccc009f6
PATCH v2 3/9 ASoC: nau8825: restore safe state after resume errors
In reply to Pengpeng Hounau8825_resume() ignores regcache_sync() failure before continuing dependent resume operations. Restore cache-only mode, leave the cache dirty, and return the replay error before those operations.
Do not start crosstalk protection or enable its IRQ after a failed replay.
ASoC still marks the component resumed when the callback reports failure. Track the suspend-owned IRQ disable so another suspend does not increment the disable depth again after a failed resume. A later successful resume releases that one disable reference. This does not add automatic retry or change the framework's best-effort card resume policy.
The issue was found by our static-analysis tool and manually reviewed.
---
Changes since v1:
- restore cache-only mode and dirty state on replay failure
- keep suspend-owned IRQ disables balanced across failed resume cycles
- send as one correctly threaded series, as Mark requested
Previous series:
https://lore.kernel.org/all/[email protected]/
sound/soc/codecs/nau8825.c | 17 ++++++++++++++--- sound/soc/codecs/nau8825.h | 1 + 2 files changed, 15 insertions(+), 3 deletions(-)
sound/soc/codecs/nau8825.c +14 -3
@@ -2683,7 +2683,10 @@ static int __maybe_unused nau8825_suspend(struct snd_soc_component *component) {struct nau8825 *nau8825 =snd_soc_component_get_drvdata (component); -disable_irq (nau8825->irq); +if (!nau8825->suspend_irq_disabled) { +disable_irq (nau8825->irq); + nau8825->suspend_irq_disabled = true; + }snd_soc_dapm_force_bias_level (nau8825->dapm,SND_SOC_BIAS_OFF );/* Power down codec power; don't suppoet button wakeup */ snd_soc_dapm_disable_pin (nau8825->dapm,"SAR" );
@@ -2701,12 +2704,20 @@ static int __maybe_unused nau8825_resume(struct snd_soc_component *component)int ret;regcache_cache_only (nau8825->regmap, false); -regcache_sync (nau8825->regmap); + ret =regcache_sync (nau8825->regmap); +if (ret) { +regcache_cache_only (nau8825->regmap, true); +regcache_mark_dirty (nau8825->regmap); +return ret; + } nau8825->xtalk_protect = true; ret =nau8825_sema_acquire (nau8825,0 );if (ret) nau8825->xtalk_protect = false; -enable_irq (nau8825->irq); +if (nau8825->suspend_irq_disabled) { + nau8825->suspend_irq_disabled = false; +enable_irq (nau8825->irq); + }return 0 ; }
sound/soc/codecs/nau8825.h +1 -0
@@ -502,6 +502,7 @@ struct nau8825 {struct semaphore xtalk_sem;int sw_id;int irq; +bool suspend_irq_disabled;int mclk_freq;/* 0 - mclk is disabled */ int button_pressed;int micbias_voltage;
base-commit: 8ef28aef33f2d5da6959ad6b579ec3cfccc009f6
Re: [PATCH v2 3/9] ASoC: nau8825: restore safe state after resume errors
Quoted 36 lines · Pengpeng Hou
nau8825_resume()ignoresregcache_sync()failure before continuing dependent resume operations. Restore cache-only mode, leave the cache dirty, and return the replay error before those operations.Do not start crosstalk protection or enable its IRQ after a failed replay.
ASoC still marks the component resumed when the callback reports failure. Track the suspend-owned IRQ disable so another suspend does not increment the disable depth again after a failed resume. A later successful resume releases that one disable reference. This does not add automatic retry or change the framework's best-effort card resume policy.
The issue was found by our static-analysis tool and manually reviewed.
Fixes 4454a8378be5 ("ASoC: nau8825: add pm function")Assisted-by gpt 5Signed-off-by Pengpeng Hou <[email protected]>---
Changes since v1:
- restore cache-only mode and dirty state on replay failure
- keep suspend-owned IRQ disables balanced across failed resume cycles
- send as one correctly threaded series, as Mark requestedPrevious series:
https://lore.kernel.org/all/[email protected]/sound/soc/codecs/nau8825.c | 17 ++++++++++++++--- sound/soc/codecs/nau8825.h | 1 + 2 files changed, 15 insertions(+), 3 deletions(-)sound/soc/codecs/nau8825.c +0
-0
sound/soc/codecs/nau8825.c static int __maybe_unused nau8825_suspend(struct snd_soc_component *component) · line 2689
Quoted 8 lines
sound/soc/codecs/nau8825.c +4
-1@@ -2683,7 +2683,10 @@ static int __maybe_unused nau8825_suspend(struct snd_soc_component *component) {struct nau8825 *nau8825 =snd_soc_component_get_drvdata (component); -disable_irq (nau8825->irq); +if (!nau8825->suspend_irq_disabled) { +disable_irq (nau8825->irq); + nau8825->suspend_irq_disabled = true; + }
With this new 'suspend_irq_disabled' state, should the IRQ suspend/resume tracking also be tied to whether 'nau8825_setup_irq()' succeeded?
Thanks
Ajay Kumar Nandam
Quoted 42 lines
sound/soc/codecs/nau8825.c +10
-2snd_soc_dapm_force_bias_level (nau8825->dapm,SND_SOC_BIAS_OFF );/* Power down codec power; don't suppoet button wakeup */ snd_soc_dapm_disable_pin (nau8825->dapm,"SAR" );@@ -2701,12 +2704,20 @@ static int __maybe_unused nau8825_resume(struct snd_soc_component *component)int ret;regcache_cache_only (nau8825->regmap, false); -regcache_sync (nau8825->regmap); + ret =regcache_sync (nau8825->regmap); +if (ret) { +regcache_cache_only (nau8825->regmap, true); +regcache_mark_dirty (nau8825->regmap); +return ret; + } nau8825->xtalk_protect = true; ret =nau8825_sema_acquire (nau8825,0 );if (ret) nau8825->xtalk_protect = false; -enable_irq (nau8825->irq); +if (nau8825->suspend_irq_disabled) { + nau8825->suspend_irq_disabled = false; +enable_irq (nau8825->irq); + }return 0 ; }sound/soc/codecs/nau8825.h +1
-0@@ -502,6 +502,7 @@ struct nau8825 {struct semaphore xtalk_sem;int sw_id;int irq; +bool suspend_irq_disabled;int mclk_freq;/* 0 - mclk is disabled */ int button_pressed;int micbias_voltage;base-commit:
8ef28aef33f2d5da6959ad6b579ec3cfccc009f6
PATCH v2 4/9 ASoC: rt5663: restore safe state after resume errors
In reply to Pengpeng Hourt5663_resume() ignores regcache_sync() failure before continuing dependent resume operations. Restore cache-only mode, leave the cache dirty, and return the replay error before those operations.
Do not schedule jack-detection work or enable its IRQ after a failed replay.
ASoC still marks the component resumed when the callback reports failure. Track the suspend-owned IRQ disable so another suspend does not increment the disable depth again after a failed resume. A later successful resume releases that one disable reference. This does not add automatic retry or change the framework's best-effort card resume policy.
The issue was found by our static-analysis tool and manually reviewed.
---
Changes since v1:
- restore cache-only mode and dirty state on replay failure
- keep suspend-owned IRQ disables balanced across failed resume cycles
- send as one correctly threaded series, as Mark requested
Previous series:
https://lore.kernel.org/all/[email protected]/
sound/soc/codecs/rt5663.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
sound/soc/codecs/rt5663.c +14 -3
@@ -75,6 +75,7 @@ struct rt5663_priv {int jack_type;unsigned int irq; +bool suspend_irq_disabled; };static const struct reg_sequence rt5663_patch_list[] = {
@@ -3187,8 +3188,10 @@ static int rt5663_suspend(struct snd_soc_component *component) {struct rt5663_priv *rt5663 =snd_soc_component_get_drvdata (component); -if (rt5663->irq) +if (rt5663->irq && !rt5663->suspend_irq_disabled) {disable_irq (rt5663->irq); + rt5663->suspend_irq_disabled = true; + }cancel_delayed_work_sync (&rt5663->jack_detect_work);cancel_delayed_work_sync (&rt5663->jd_unplug_work);
@@ -3202,14 +3205,22 @@ static int rt5663_suspend(struct snd_soc_component *component)static int rt5663_resume (struct snd_soc_component *component) {struct rt5663_priv *rt5663 =snd_soc_component_get_drvdata (component); +int ret;regcache_cache_only (rt5663->regmap, false); -regcache_sync (rt5663->regmap); + ret =regcache_sync (rt5663->regmap); +if (ret) { +regcache_cache_only (rt5663->regmap, true); +regcache_mark_dirty (rt5663->regmap); +return ret; + }rt5663_irq (0 , rt5663); -if (rt5663->irq) +if (rt5663->suspend_irq_disabled) { + rt5663->suspend_irq_disabled = false;enable_irq (rt5663->irq); + }return 0 ; }
base-commit: 8ef28aef33f2d5da6959ad6b579ec3cfccc009f6
PATCH v2 5/9 ASoC: rt5682s: restore safe state after resume errors
In reply to Pengpeng Hourt5682s_resume() ignores regcache_sync() failure before continuing dependent resume operations. Restore cache-only mode, leave the cache dirty, and return the replay error before those operations.
Do not schedule jack-detection work or enable its IRQ after a failed replay.
ASoC still marks the component resumed when the callback reports failure. Track the suspend-owned IRQ disable so another suspend does not increment the disable depth again after a failed resume. A later successful resume releases that one disable reference. This does not add automatic retry or change the framework's best-effort card resume policy.
The issue was found by our static-analysis tool and manually reviewed.
---
Changes since v1:
- restore cache-only mode and dirty state on replay failure
- keep suspend-owned IRQ disables balanced across failed resume cycles
- send as one correctly threaded series, as Mark requested
Previous series:
https://lore.kernel.org/all/[email protected]/
sound/soc/codecs/rt5682s.c | 16 +++++++++++++--- sound/soc/codecs/rt5682s.h | 1 + 2 files changed, 14 insertions(+), 3 deletions(-)
sound/soc/codecs/rt5682s.c +13 -3
@@ -2884,8 +2884,10 @@ static int rt5682s_suspend(struct snd_soc_component *component) {struct rt5682s_priv *rt5682s =snd_soc_component_get_drvdata (component); -if (rt5682s->irq) +if (rt5682s->irq && !rt5682s->suspend_irq_disabled) {disable_irq (rt5682s->irq); + rt5682s->suspend_irq_disabled = true; + }cancel_delayed_work_sync (&rt5682s->jack_detect_work);cancel_delayed_work_sync (&rt5682s->jd_check_work);
@@ -2902,17 +2904,25 @@ static int rt5682s_suspend(struct snd_soc_component *component)static int rt5682s_resume (struct snd_soc_component *component) {struct rt5682s_priv *rt5682s =snd_soc_component_get_drvdata (component); +int ret;regcache_cache_only (rt5682s->regmap, false); -regcache_sync (rt5682s->regmap); + ret =regcache_sync (rt5682s->regmap); +if (ret) { +regcache_cache_only (rt5682s->regmap, true); +regcache_mark_dirty (rt5682s->regmap); +return ret; + }if (rt5682s->hs_jack) {mod_delayed_work (system_power_efficient_wq, &rt5682s->jack_detect_work,msecs_to_jiffies (0 )); } -if (rt5682s->irq) +if (rt5682s->suspend_irq_disabled) { + rt5682s->suspend_irq_disabled = false;enable_irq (rt5682s->irq); + }return 0 ; }
sound/soc/codecs/rt5682s.h +1 -0
@@ -1482,6 +1482,7 @@ struct rt5682s_priv {int jack_type;unsigned int irq; +bool suspend_irq_disabled;int irq_work_delay_time;int wclk_enabled; };
base-commit: 8ef28aef33f2d5da6959ad6b579ec3cfccc009f6
PATCH v2 6/9 ASoC: rt5682: restore safe state after resume errors
In reply to Pengpeng Hourt5682_resume() ignores regcache_sync() failure before continuing dependent resume operations. Restore cache-only mode, leave the cache dirty, and return the replay error before those operations.
Leave the SoundWire no-op branch unchanged; stop the I2C jack restore path on replay failure.
ASoC still marks the component resumed when the callback reports failure. Track the suspend-owned IRQ disable so another suspend does not increment the disable depth again after a failed resume. A later successful resume releases that one disable reference. This does not add automatic retry or change the framework's best-effort card resume policy.
The issue was found by our static-analysis tool and manually reviewed.
---
Changes since v1:
- restore cache-only mode and dirty state on replay failure
- keep suspend-owned IRQ disables balanced across failed resume cycles
- send as one correctly threaded series, as Mark requested
Previous series:
https://lore.kernel.org/all/[email protected]/
sound/soc/codecs/rt5682.c | 16 +++++++++++++--- sound/soc/codecs/rt5682.h | 1 + 2 files changed, 14 insertions(+), 3 deletions(-)
sound/soc/codecs/rt5682.c +13 -3
@@ -2962,8 +2962,10 @@ static int rt5682_suspend(struct snd_soc_component *component)if (rt5682->is_sdw)return 0 ; -if (rt5682->irq) +if (rt5682->irq && !rt5682->suspend_irq_disabled) {disable_irq (rt5682->irq); + rt5682->suspend_irq_disabled = true; + }cancel_delayed_work_sync (&rt5682->jack_detect_work);cancel_delayed_work_sync (&rt5682->jd_check_work);
@@ -3010,12 +3012,18 @@ static int rt5682_suspend(struct snd_soc_component *component)static int rt5682_resume (struct snd_soc_component *component) {struct rt5682_priv *rt5682 =snd_soc_component_get_drvdata (component); +int ret;if (rt5682->is_sdw)return 0 ;regcache_cache_only (rt5682->regmap, false); -regcache_sync (rt5682->regmap); + ret =regcache_sync (rt5682->regmap); +if (ret) { +regcache_cache_only (rt5682->regmap, true); +regcache_mark_dirty (rt5682->regmap); +return ret; + }if (rt5682->hs_jack && (rt5682->jack_type &SND_JACK_HEADSET ) ==SND_JACK_HEADSET ) { snd_soc_component_update_bits(component, RT5682_SAR_IL_CMD_1,
@@ -3033,8 +3041,10 @@ static int rt5682_resume(struct snd_soc_component *component)mod_delayed_work (system_power_efficient_wq, &rt5682->jack_detect_work,msecs_to_jiffies (0 )); -if (rt5682->irq) +if (rt5682->suspend_irq_disabled) { + rt5682->suspend_irq_disabled = false;enable_irq (rt5682->irq); + }return 0 ; }
sound/soc/codecs/rt5682.h +1 -0
@@ -1466,6 +1466,7 @@ struct rt5682_priv {int jack_type;int irq; +bool suspend_irq_disabled;int irq_work_delay_time; };
base-commit: 8ef28aef33f2d5da6959ad6b579ec3cfccc009f6
PATCH v2 7/9 ASoC: wm8978: restore safe state after resume errors
In reply to Pengpeng Houwm8978_resume() ignores cache replay, bias restoration and PLL update results, allowing subsequent resume steps to run after a failed operation.
Stop at the first failure and request SND_SOC_BIAS_OFF on the error path. Bias OFF intentionally preserves PLL power, so also clear the power register as system suspend does. Keep the original failure if rollback reports another error. Restore cache-only mode and mark the cache dirty so later accesses do not write through a partially restored device. Re-enable write-through before a later replay attempt. A positive update_bits() result means that
bits changed, not an error.
The bias callback currently does not propagate every register write error; the rollback is therefore best-effort, not a claim of verified hardware power-down. The ASoC wrapper continues its established best-effort resume.
The issue was found by our static-analysis tool and manually reviewed.
---
Changes since v1:
- restore cache-only mode and dirty state on replay failure
- restore bias OFF on the error path, as Charles requested
- also turn off PLL power, matching system suspend rather than bias OFF alone
- preserve positive update_bits() success
- send as one correctly threaded series, as Mark requested
Previous series:
https://lore.kernel.org/all/[email protected]/
sound/soc/codecs/wm8978.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-)
sound/soc/codecs/wm8978.c +27 -4
@@ -952,17 +952,40 @@ static int wm8978_resume(struct snd_soc_component *component) {struct wm8978_priv *wm8978 =snd_soc_component_get_drvdata (component);struct snd_soc_dapm_context *dapm =snd_soc_component_to_dapm (component); +int ret, err;/* Sync reg_cache with the hardware */ -regcache_sync (wm8978->regmap); +regcache_cache_only (wm8978->regmap, false); + ret =regcache_sync (wm8978->regmap); +if (ret) + goto restore_off; -snd_soc_dapm_force_bias_level (dapm,SND_SOC_BIAS_STANDBY ); + ret =snd_soc_dapm_force_bias_level (dapm,SND_SOC_BIAS_STANDBY ); +if (ret) + goto restore_off; -if (wm8978->f_pllout) +if (wm8978->f_pllout) {/* Switch PLL on */ -snd_soc_component_update_bits (component,WM8978_POWER_MANAGEMENT_1 ,0x20 ,0x20 ); + ret =snd_soc_component_update_bits (component, +WM8978_POWER_MANAGEMENT_1 , +0x20 ,0x20 ); +if (ret <0 ) + goto restore_off; + }return 0 ; + +restore_off: + err =snd_soc_dapm_force_bias_level (dapm,SND_SOC_BIAS_OFF ); +if (err) +dev_err (component->dev,"Failed to restore bias OFF: %d\n" , err); +/* Bias OFF preserves PLL; system suspend turns it off as well. */ + err =snd_soc_component_write (component,WM8978_POWER_MANAGEMENT_1 ,0 ); +if (err) +dev_err (component->dev,"Failed to disable PLL: %d\n" , err); +regcache_cache_only (wm8978->regmap, true); +regcache_mark_dirty (wm8978->regmap); +return ret; }/*
base-commit: 8ef28aef33f2d5da6959ad6b579ec3cfccc009f6
Re: [PATCH v2 7/9] ASoC: wm8978: restore safe state after resume errors
Quoted 18 lines · Pengpeng Hou
wm8978_resume()ignores cache replay, bias restoration and PLL update results, allowing subsequent resume steps to run after a failed operation.Stop at the first failure and request
SND_SOC_BIAS_OFFon the error path. Bias OFF intentionally preserves PLL power, so also clear the power register as system suspend does. Keep the original failure if rollback reports another error. Restore cache-only mode and mark the cache dirty so later accesses do not write through a partially restored device. Re-enable write-through before a later replay attempt. A positiveupdate_bits()result means that
bits changed, not an error.The bias callback currently does not propagate every register write error; the rollback is therefore best-effort, not a claim of verified hardware power-down. The ASoC wrapper continues its established best-effort resume.
The issue was found by our static-analysis tool and manually reviewed.
Quoted 7 lines
Fixes 0d34e91596ef ("ASoC: add a WM8978 codec driver")Assisted-by gpt 5Signed-off-by Pengpeng Hou <[email protected]>---
Changes since v1:
- restore cache-only mode and dirty state on replay failure
- restore bias OFF on the error path, as Charles requested
I was more interested in a rational for either approach. But probably adding it seems more logical to me.
Quoted 15 lines
- also turn off PLL power, matching system suspend rather than bias OFF alone
- preserve positiveupdate_bits()success
- send as one correctly threaded series, as Mark requestedPrevious series:
https://lore.kernel.org/all/[email protected]/sound/soc/codecs/wm8978.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-)sound/soc/codecs/wm8978.c +0
-0
sound/soc/codecs/wm8978.c static int wm8978_resume(struct snd_soc_component *component) · line 958
Quoted 8 lines
sound/soc/codecs/wm8978.c +2
-1@@ -952,17 +952,40 @@ static int wm8978_resume(struct snd_soc_component *component) {struct wm8978_priv *wm8978 =snd_soc_component_get_drvdata (component);struct snd_soc_dapm_context *dapm =snd_soc_component_to_dapm (component); +int ret, err;/* Sync reg_cache with the hardware */ -regcache_sync (wm8978->regmap); +regcache_cache_only (wm8978->regmap, false);
Nothing ever set cache_only true? Surely you either want a separate patch to add cache_only support, or to not do this. Although given the driver appears to only support system suspend I would assume there isn't much point in cache only.
Thanks,
Charles
PATCH v2 8/9 ASoC: rt5640: restore safe state after resume errors
In reply to Pengpeng Hourt5640_resume() ignores regcache_sync() failure before continuing dependent resume operations. Restore cache-only mode, leave the cache dirty, and return the replay error before those operations.
Both the codec IRQ and the optional GPIO jack IRQ can queue jack work. Quiesce both before cancelling that work, retain their disable references on replay failure, and clear each reference if jack teardown frees that IRQ. Restore the optional LDO GPIO on failure and reject new jack setup until a later replay succeeds; teardown remains allowed.
ASoC still marks the component resumed when the callback reports failure. Track the suspend-owned IRQ disable so another suspend does not increment the disable depth again after a failed resume. A later successful resume releases that one disable reference. This does not add automatic retry or change the framework's best-effort card resume policy.
The issue was found by our static-analysis tool and manually reviewed.
---
Changes since v1:
- restore cache-only mode and dirty state on replay failure
- keep suspend-owned IRQ disables balanced across failed resume cycles
- cover both IRQ producers and jack teardown/re-registration after failure
- send as one correctly threaded series, as Mark requested
Previous series:
https://lore.kernel.org/all/[email protected]/
sound/soc/codecs/rt5640.c | 37 ++++++++++++++++++++++++++++++++++--- sound/soc/codecs/rt5640.h | 3 +++ 2 files changed, 37 insertions(+), 3 deletions(-)
sound/soc/codecs/rt5640.c +34 -3
@@ -2433,11 +2433,13 @@ static void rt5640_disable_irq_and_cancel_work(void *data)if (rt5640->jd_gpio_irq_requested) {free_irq (rt5640->jd_gpio_irq, rt5640); rt5640->jd_gpio_irq_requested = false; + rt5640->suspend_jd_gpio_irq_disabled = false; }if (rt5640->irq_requested) {free_irq (rt5640->irq, rt5640); rt5640->irq_requested = false; + rt5640->suspend_irq_disabled = false; }cancel_delayed_work_sync (&rt5640->jack_work);
@@ -2646,6 +2648,10 @@ static int rt5640_set_jack(struct snd_soc_component *component, {struct rt5640_priv *rt5640 =snd_soc_component_get_drvdata (component); +/* Do not publish fresh IRQs while the register cache is unrestored. */ +if (jack && rt5640->resume_failed) +return -EIO ; +if (jack) {if (rt5640->jd_src ==RT5640_JD_SRC_HDA_HEADER )rt5640_enable_hda_jack_detect (component, jack);
@@ -2803,7 +2809,15 @@ static int rt5640_suspend(struct snd_soc_component *component)if (rt5640->jack) {/* disable jack interrupts during system suspend */ -disable_irq (rt5640->irq); +if (rt5640->irq_requested && !rt5640->suspend_irq_disabled) { +disable_irq (rt5640->irq); + rt5640->suspend_irq_disabled = true; + } +if (rt5640->jd_gpio_irq_requested && + !rt5640->suspend_jd_gpio_irq_disabled) { +disable_irq (rt5640->jd_gpio_irq); + rt5640->suspend_jd_gpio_irq_disabled = true; + }cancel_delayed_work_sync (&rt5640->jack_work);cancel_delayed_work_sync (&rt5640->bp_work); }
@@ -2821,6 +2835,7 @@ static int rt5640_suspend(struct snd_soc_component *component)static int rt5640_resume (struct snd_soc_component *component) {struct rt5640_priv *rt5640 =snd_soc_component_get_drvdata (component); +int ret;if (rt5640->ldo1_en) {gpiod_set_value_cansleep (rt5640->ldo1_en,1 );
@@ -2828,7 +2843,16 @@ static int rt5640_resume(struct snd_soc_component *component) }regcache_cache_only (rt5640->regmap, false); -regcache_sync (rt5640->regmap); + ret =regcache_sync (rt5640->regmap); +if (ret) { + rt5640->resume_failed = true; +regcache_cache_only (rt5640->regmap, true); +regcache_mark_dirty (rt5640->regmap); +if (rt5640->ldo1_en) +gpiod_set_value_cansleep (rt5640->ldo1_en,0 ); +return ret; + } + rt5640->resume_failed = false;if (rt5640->jack) {if (rt5640->jd_src ==RT5640_JD_SRC_HDA_HEADER ) {
@@ -2857,7 +2881,14 @@ static int rt5640_resume(struct snd_soc_component *component) } } -enable_irq (rt5640->irq); +if (rt5640->suspend_irq_disabled) { + rt5640->suspend_irq_disabled = false; +enable_irq (rt5640->irq); + } +if (rt5640->suspend_jd_gpio_irq_disabled) { + rt5640->suspend_jd_gpio_irq_disabled = false; +enable_irq (rt5640->jd_gpio_irq); + }queue_delayed_work (system_dfl_long_wq, &rt5640->jack_work,0 ); }
sound/soc/codecs/rt5640.h +3 -0
@@ -2154,7 +2154,10 @@ struct rt5640_priv {bool hp_mute;bool asrc_en;bool irq_requested; +bool suspend_irq_disabled;bool jd_gpio_irq_requested; +bool suspend_jd_gpio_irq_disabled; +bool resume_failed;/* Jack and button detect data */ bool ovcd_irq_enabled;
base-commit: 8ef28aef33f2d5da6959ad6b579ec3cfccc009f6
PATCH v2 9/9 ASoC: rt5677: restore safe state after resume errors
In reply to Pengpeng Hourt5677_resume() ignores regcache_sync() failure before continuing dependent resume operations. Restore cache-only mode, leave the cache dirty, and return the replay error before those operations.
First return physical regmap write errors from the normal-mode write wrapper, which currently discards them, so cache replay can observe bus failures. Restore reset and the optional LDO GPIO on replay failure. Remember that cache restoration is still pending independently of the requested DSP VAD mode: DAPM or controls can change that mode after failed resume. Suppress DSP work while restoration is pending and require replay on the next resume even if VAD has since been requested. After successful replay, preserve the existing MCLK settling delay before restarting requested DSP work. The already-running, retained VAD path and DSP-mode transport are unchanged.
ASoC still marks the component resumed when the callback reports failure. Track the suspend-owned IRQ disable so another suspend does not increment the disable depth again after a failed resume. A later successful resume releases that one disable reference. This does not add automatic retry or change the framework's best-effort card resume policy.
The issue was found by our static-analysis tool and manually reviewed.
---
Changes since v1:
- restore cache-only mode and dirty state on replay failure
- keep suspend-owned IRQ disables balanced across failed resume cycles
- propagate the normal-mode transport write result to cache replay
- preserve pending cache restoration across changes to the VAD request
- keep DSP work paused until replay succeeds, retaining the MCLK delay
- send as one correctly threaded series, as Mark requested
Previous series:
https://lore.kernel.org/all/[email protected]/
sound/soc/codecs/rt5677.c | 37 ++++++++++++++++++++++++++++++++----- sound/soc/codecs/rt5677.h | 2 ++ 2 files changed, 34 insertions(+), 5 deletions(-)
sound/soc/codecs/rt5677.c +32 -5
@@ -885,6 +885,9 @@ static void rt5677_dsp_work(struct work_struct *work)bool enable = rt5677->dsp_vad_en;int i, val; +/* DAPM may request VAD even after component resume has failed. */ +if (READ_ONCE (rt5677->cache_restore_pending)) +return ;dev_info (rt5677->component->dev,"DSP VAD: enable=%d, activity=%d\n" , enable, activity);
@@ -4939,10 +4942,14 @@ static int rt5677_suspend(struct snd_soc_component *component)if (rt5677->irq) {cancel_delayed_work_sync (&rt5677->resume_irq_check); -disable_irq (rt5677->irq); +if (!rt5677->suspend_irq_disabled) { +disable_irq (rt5677->irq); + rt5677->suspend_irq_disabled = true; + } }if (!rt5677->dsp_vad_en) { +WRITE_ONCE (rt5677->cache_restore_pending, true);regcache_cache_only (rt5677->regmap, true);regcache_mark_dirty (rt5677->regmap);
@@ -4956,8 +4963,11 @@ static int rt5677_suspend(struct snd_soc_component *component)static int rt5677_resume (struct snd_soc_component *component) {struct rt5677_priv *rt5677 =snd_soc_component_get_drvdata (component); +bool restore_cache = !rt5677->dsp_vad_en || +READ_ONCE (rt5677->cache_restore_pending); +int ret; -if (!rt5677->dsp_vad_en) { +if (restore_cache) { rt5677->pll_src =0 ; rt5677->pll_in =0 ; rt5677->pll_out =0 ;
@@ -4967,11 +4977,28 @@ static int rt5677_resume(struct snd_soc_component *component)msleep (10 );regcache_cache_only (rt5677->regmap, false); -regcache_sync (rt5677->regmap); + ret =regcache_sync (rt5677->regmap); +if (ret) { +WRITE_ONCE (rt5677->cache_restore_pending, true); +regcache_cache_only (rt5677->regmap, true); +regcache_mark_dirty (rt5677->regmap); +gpiod_set_value_cansleep (rt5677->reset_pin,1 ); +gpiod_set_value_cansleep (rt5677->pow_ldo2,0 ); +return ret; + } +WRITE_ONCE (rt5677->cache_restore_pending, false); +if (rt5677->dsp_vad_en) { +/* Allow MCLK to settle, as when leaving bias OFF. */ +schedule_delayed_work (&rt5677->dsp_work, +msecs_to_jiffies (1000 )); + } }if (rt5677->irq) { -enable_irq (rt5677->irq); +if (rt5677->suspend_irq_disabled) { + rt5677->suspend_irq_disabled = false; +enable_irq (rt5677->irq); + }schedule_delayed_work (&rt5677->resume_irq_check,0 ); }
@@ -5021,7 +5048,7 @@ static int rt5677_write(void *context, unsigned int reg, unsigned int val)rt5677_dsp_mode_i2c_write (rt5677, reg, val); } }else { -regmap_write (rt5677->regmap_physical, reg, val); +return regmap_write (rt5677->regmap_physical, reg, val); }return 0 ;
sound/soc/codecs/rt5677.h +2 -0
@@ -1788,6 +1788,7 @@ struct rt5677_priv {#endif bool dsp_vad_en_request;/* DSP VAD enable/disable request */ bool dsp_vad_en;/* dsp_work parameter */ +bool cache_restore_pending;bool is_dsp_mode;bool is_vref_slow;struct delayed_work dsp_work;
@@ -1798,6 +1799,7 @@ struct rt5677_priv {unsigned int irq_en;struct delayed_work resume_irq_check;int irq; +bool suspend_irq_disabled;int (*set_dsp_vad)(struct snd_soc_component *component,bool on); };
base-commit: 8ef28aef33f2d5da6959ad6b579ec3cfccc009f6
Re: [PATCH v2 9/9] ASoC: rt5677: restore safe state after resume errors
Quoted 57 lines · Pengpeng Hou
rt5677_resume()ignoresregcache_sync()failure before continuing dependent resume operations. Restore cache-only mode, leave the cache dirty, and return the replay error before those operations.First return physical regmap write errors from the normal-mode write wrapper, which currently discards them, so cache replay can observe bus failures. Restore reset and the optional LDO GPIO on replay failure. Remember that cache restoration is still pending independently of the requested DSP VAD mode: DAPM or controls can change that mode after failed resume. Suppress DSP work while restoration is pending and require replay on the next resume even if VAD has since been requested. After successful replay, preserve the existing MCLK settling delay before restarting requested DSP work. The already-running, retained VAD path and DSP-mode transport are unchanged.
ASoC still marks the component resumed when the callback reports failure. Track the suspend-owned IRQ disable so another suspend does not increment the disable depth again after a failed resume. A later successful resume releases that one disable reference. This does not add automatic retry or change the framework's best-effort card resume policy.
The issue was found by our static-analysis tool and manually reviewed.
Fixes 0e826e867264 ("ASoC: add RT5677 CODEC driver")Assisted-by gpt 5Signed-off-by Pengpeng Hou <[email protected]>---
Changes since v1:
- restore cache-only mode and dirty state on replay failure
- keep suspend-owned IRQ disables balanced across failed resume cycles
- propagate the normal-mode transport write result to cache replay
- preserve pending cache restoration across changes to the VAD request
- keep DSP work paused until replay succeeds, retaining the MCLK delay
- send as one correctly threaded series, as Mark requestedPrevious series:
https://lore.kernel.org/all/[email protected]/sound/soc/codecs/rt5677.c | 37 ++++++++++++++++++++++++++++++++----- sound/soc/codecs/rt5677.h | 2 ++ 2 files changed, 34 insertions(+), 5 deletions(-)sound/soc/codecs/rt5677.c +3
-0@@ -885,6 +885,9 @@ static void rt5677_dsp_work(struct work_struct *work)bool enable = rt5677->dsp_vad_en;int i, val; +/* DAPM may request VAD even after component resume has failed. */ +if (READ_ONCE (rt5677->cache_restore_pending)) +return ;dev_info (rt5677->component->dev,"DSP VAD: enable=%d, activity=%d\n" , enable, activity);
sound/soc/codecs/rt5677.c static int rt5677_suspend(struct snd_soc_component *component) · line 4948
Quoted 8 lines
sound/soc/codecs/rt5677.c +4
-1@@ -4939,10 +4942,14 @@ static int rt5677_suspend(struct snd_soc_component *component)if (rt5677->irq) {cancel_delayed_work_sync (&rt5677->resume_irq_check); -disable_irq (rt5677->irq); +if (!rt5677->suspend_irq_disabled) { +disable_irq (rt5677->irq); + rt5677->suspend_irq_disabled = true; + }
Similar to the nau8825 case, should this new suspend_irq_disabled tracking be based on whether the IRQ was successfully requested?
rt5677_init_irq() still sets rt5677->irq = i2c->irq even when devm_request_threaded_irq() fails, and probe continues after only logging that error.
Thanks
Ajay Kumar Nandam
Quoted 84 lines
sound/soc/codecs/rt5677.c +25
-4}if (!rt5677->dsp_vad_en) { +WRITE_ONCE (rt5677->cache_restore_pending, true);regcache_cache_only (rt5677->regmap, true);regcache_mark_dirty (rt5677->regmap);@@ -4956,8 +4963,11 @@ static int rt5677_suspend(struct snd_soc_component *component)static int rt5677_resume (struct snd_soc_component *component) {struct rt5677_priv *rt5677 =snd_soc_component_get_drvdata (component); +bool restore_cache = !rt5677->dsp_vad_en || +READ_ONCE (rt5677->cache_restore_pending); +int ret; -if (!rt5677->dsp_vad_en) { +if (restore_cache) { rt5677->pll_src =0 ; rt5677->pll_in =0 ; rt5677->pll_out =0 ;@@ -4967,11 +4977,28 @@ static int rt5677_resume(struct snd_soc_component *component)msleep (10 );regcache_cache_only (rt5677->regmap, false); -regcache_sync (rt5677->regmap); + ret =regcache_sync (rt5677->regmap); +if (ret) { +WRITE_ONCE (rt5677->cache_restore_pending, true); +regcache_cache_only (rt5677->regmap, true); +regcache_mark_dirty (rt5677->regmap); +gpiod_set_value_cansleep (rt5677->reset_pin,1 ); +gpiod_set_value_cansleep (rt5677->pow_ldo2,0 ); +return ret; + } +WRITE_ONCE (rt5677->cache_restore_pending, false); +if (rt5677->dsp_vad_en) { +/* Allow MCLK to settle, as when leaving bias OFF. */ +schedule_delayed_work (&rt5677->dsp_work, +msecs_to_jiffies (1000 )); + } }if (rt5677->irq) { -enable_irq (rt5677->irq); +if (rt5677->suspend_irq_disabled) { + rt5677->suspend_irq_disabled = false; +enable_irq (rt5677->irq); + }schedule_delayed_work (&rt5677->resume_irq_check,0 ); }@@ -5021,7 +5048,7 @@ static int rt5677_write(void *context, unsigned int reg, unsigned int val)rt5677_dsp_mode_i2c_write (rt5677, reg, val); } }else { -regmap_write (rt5677->regmap_physical, reg, val); +return regmap_write (rt5677->regmap_physical, reg, val); }return 0 ;sound/soc/codecs/rt5677.h +2
-0@@ -1788,6 +1788,7 @@ struct rt5677_priv {#endif bool dsp_vad_en_request;/* DSP VAD enable/disable request */ bool dsp_vad_en;/* dsp_work parameter */ +bool cache_restore_pending;bool is_dsp_mode;bool is_vref_slow;struct delayed_work dsp_work;@@ -1798,6 +1799,7 @@ struct rt5677_priv {unsigned int irq_en;struct delayed_work resume_irq_check;int irq; +bool suspend_irq_disabled;int (*set_dsp_vad)(struct snd_soc_component *component,bool on); };base-commit:
8ef28aef33f2d5da6959ad6b579ec3cfccc009f6
Mark Brown
maintainerQuoted 9 lines · Pengpeng Hou
ASoC: stop dependent resume work after restore failures
This revision addresses Mark's cache-mode concern and Charles's WM8978 bias rollback question. It also accounts for the next suspend after a failed resume: the ASoC wrapper reports the callback error but marks the component resumed, so leaving an IRQ disabled needs driver-local ownership tracking to avoid disabling it a second time in the next suspend.
[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.5
Thanks!
[1/9] ASoC: nau8821: restore safe state after resume errors
https://git.kernel.org/broonie/sound/c/924b88cec6b5 [2/9] ASoC: nau8824: restore safe state after resume errors https://git.kernel.org/broonie/sound/c/230d0320971f [3/9] ASoC: nau8825: restore safe state after resume errors https://git.kernel.org/broonie/sound/c/6bfb1abeee3b [4/9] ASoC: rt5663: restore safe state after resume errors https://git.kernel.org/broonie/sound/c/7cd349171991 [5/9] ASoC: rt5682s: restore safe state after resume errors https://git.kernel.org/broonie/sound/c/9561e9be8996 [6/9] ASoC: rt5682: restore safe state after resume errors https://git.kernel.org/broonie/sound/c/083dbbdfee9e [7/9] ASoC: wm8978: restore safe state after resume errors https://git.kernel.org/broonie/sound/c/947f7c8b9728 [8/9] ASoC: rt5640: restore safe state after resume errors https://git.kernel.org/broonie/sound/c/de80fa166b95 [9/9] ASoC: rt5677: restore safe state after resume errors https://git.kernel.org/broonie/sound/c/d9dd3f68d6be
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