[BUG] ASoC: Intel: sof_es8336: speaker amp GPIO stays off after stream stop/restart (no sound until "Speaker Switch" is toggled)
Hello, Resending this report in plain text: my first attempt was rejected by vger because it contained an HTML part. Sorry for any duplicate. I am a user of an Adreamer Leobook 13 laptop (Intel Gemini Lake, ES8336 codec on SSP2, board name PN1308P) running Linux Mint 22 with the Ubuntu kernel 6.8.0-139-generic (based on v6.8), SOF firmware sof-glk.ri 2.2.0, topology sof-glk-es8336-ssp2.tplg, PipeWire 1.0.5, WirePlumber 0.4.17. Problem ------- The speaker randomly goes silent, typically when a browser stops and restarts playback (for example YouTube ad transitions). While it is silent the PCM is RUNNING and hw_ptr advances at 48 kHz, PipeWire reports no errors, the ALSA mixer is unchanged and nothing is logged in dmesg. Toggling "Speaker Switch" off and on restores the sound without closing the PCM. Before I worked around it, this happened 15 times in about 10 hours of use on one day. Evidence -------- I captured the full DAPM debugfs tree, the ES8336 regmap registers and /sys/kernel/debug/gpio in the broken and in the working state. Everything is identical (including "Speaker Power: On" and "Speaker: On") except the speaker enable GPIO: broken: gpio-541 (speakers-enable) out lo ACTIVE LOW working: gpio-541 (speakers-enable) out hi ACTIVE LOW Setting pmdown_time to 0 on the codec and BE links did not prevent it. Analysis -------- In sound/soc/intel/boards/sof_es8336.c, sof_8336_trigger() drives the speaker GPIO to the "off" level on PAUSE_PUSH, SUSPEND and STOP without updating priv->speaker_en, while START, PAUSE_RELEASE and RESUME do nothing. The GPIO is only restored by sof_es8316_speaker_power_event() when DAPM actually powers the "Speaker Power" supply down and up again. If the stream is stopped and started again without that full power cycle, nothing re-enables the amplifier: the GPIO stays off while DAPM still considers the speaker on. I have not determined which exact path triggers it on my machine (pause/resume, xrun recovery, or a restart within pmdown_time). Proposed change (sketch, not a formal patch) -------------------------------------------- Re-enable the amplifier on resume when the driver believes it is on: case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: case SNDRV_PCM_TRIGGER_RESUME: + if (substream->stream == 0 && priv->speaker_en == false) + schedule_delayed_work(&priv->pcm_pop_work, + msecs_to_jiffies(70)); break; Result ------ I tested this change (with an extra dev_info message to count the occurrences) on 6.8.0-139, built out-of-tree as a replacement for the module. In about 42 hours of YouTube and Netflix use it caught and fixed the condition 6 times, with no audible dropouts and no interventions from a userspace watchdog that I kept running as a safety net. Before loading the patched module, the same watchdog had to intervene 15 times in about 10 hours on one day. From reading a recent mainline tree, sof_8336_trigger() looks unchanged there, but I have not tested mainline. I am happy to test other proposals, to provide the full debugfs dumps, or to turn this into a formal patch if the approach looks acceptable. Thank you, David Marquez Fernandez
Problem ------- The speaker randomly goes silent, typically when a browser stops and restarts playback (for example YouTube ad transitions). While it is silent the PCM is RUNNING and hw_ptr advances at 48 kHz, PipeWire reports no errors, the ALSA mixer is unchanged and nothing is logged in dmesg. Toggling "Speaker Switch" off and on restores the sound without closing the PCM. Before I worked around it, this happened 15 times in about 10 hours of use on one day. my money is on the asymmetric code structure which mixes DAPM and stream
triggers, see below.
Evidence -------- I captured the full DAPM debugfs tree, the ES8336 regmap registers and /sys/kernel/debug/gpio in the broken and in the working state. Everything is identical (including "Speaker Power: On" and "Speaker: On") except the speaker enable GPIO:
broken: gpio-541 (speakers-enable) out lo ACTIVE LOW working: gpio-541 (speakers-enable) out hi ACTIVE LOW
Setting pmdown_time to 0 on the codec and BE links did not prevent it.
Analysis -------- In sound/soc/intel/boards/sof_es8336.c, sof_8336_trigger() drives the speaker GPIO to the "off" level on PAUSE_PUSH, SUSPEND and STOP without updating priv->speaker_en, while START, PAUSE_RELEASE and RESUME do nothing. The GPIO is only restored by sof_es8316_speaker_power_event() when DAPM actually powers the "Speaker Power" supply down and up again. If the stream is stopped and started again without that full power cycle, nothing re-enables the amplifier: the GPIO stays off while DAPM still considers the speaker on. I have not determined which exact path triggers it on my machine (pause/resume, xrun recovery, or a restart within pmdown_time).
Does this happen if the time between stop and restart is greater than 3s, or only when the delta is really short? In the latter case, IIRC there's a DAPM feature where the power down happens with a delay, to avoid unnecessary power transitions. so if the new stream starts immediately, then the power-up transition will never happen.
Proposed change (sketch, not a formal patch) -------------------------------------------- Re-enable the amplifier on resume when the driver believes it is on:
case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: case SNDRV_PCM_TRIGGER_RESUME: + if (substream->stream == 0 && priv->speaker_en == false) + schedule_delayed_work(&priv->pcm_pop_work, + msecs_to_jiffies(70)); break;
alternatively you could deal with power management only in sof_es8316_speaker_power_event(), and completely remove the transitions on trigger start/stop/pause. In general it's a bad idea to add delays to the trigger, it's supposed to be real fast.
participants (2)
-
David Márquez -
Pierre-Louis Bossart