reset sound after suspend to memory (deep sleep) - Printable Version +- PINE64 (https://forum.pine64.org) +-- Forum: Pinebook Pro (https://forum.pine64.org/forumdisplay.php?fid=111) +--- Forum: Linux on Pinebook Pro (https://forum.pine64.org/forumdisplay.php?fid=114) +--- Thread: reset sound after suspend to memory (deep sleep) (/showthread.php?tid=10268) Pages:
1
2
|
reset sound after suspend to memory (deep sleep) - Der Geist der Maschine - 06-16-2020 After a suspend from memory, sound does not work. On my machine (Manjaro ARM XFCE 20.06 Kernel 5.7), the sound driver snd_soc_es8316 needs to reset the sound chip. The problem is the kernel is preventing unloading and reloading of the sound driver snd_soc_es8316. My first attempt was initializing the sound chip from the shell mimicking what the es8316 driver is doing in its probe function: Code: # modprobe i2c-dev I got some static noise making me believe I talked to the right device It has not helped. The es8316 driver can't be un- and reloaded but un- and rebound. Execute this line after returning from suspend: Code: $ sudo tee /sys/bus/i2c/drivers/es8316/{un,}bind <<< 1-0011 It's quite easy to crash the kernel. I suspect the sound driver should not be accessed in the split-second between its unbinding and binding. So far, I have only seen kernel crashes when executing the unbind/bind command while playing music. I have not seen any kernel crashes otherwise. You never know what happens on a modern Linux in the background, so YMMV. I have some vague ideas for a proper solution. Will not happen any time soon. Hope others will step in. RE: reset sound after suspend to memory (deep sleep) - Syonyk - 06-16-2020 I've been able to reset audio (on Ubuntu 20.04, mainline 5.7 kernel) after a deep sleep with the following: Code: pulseaudio -k && sudo alsa force-reload I believe it accomplishes similar things. On the other hand, it doesn't work if something is trying to play music, but neither does it crash the kernel. RE: reset sound after suspend to memory (deep sleep) - Der Geist der Maschine - 06-16-2020 Hello Syonyk (06-16-2020, 09:05 AM)Syonyk Wrote: I've been able to reset audio (on Ubuntu 20.04, mainline 5.7 kernel) after a deep sleep with the following: Ubuntu's alsa script is unloading and then reloading all sound related drivers. That does not work for me on stock Manjaro 20.06. Great that the alsa script works for you. I assume ubuntu uses systemd , so you should not run pulseaudio -k, but something along these lines Code: $ systemctl --user stop pulseaudio.socket You can check with lsof if the sound device is in use (maybe there is a better way?) Code: $ lsof /dev/snd/* Your command pulseaudio -k is killing pulseaudio, but systemd monitors it and restarts it. So maybe your alsa command is sometimes too slow. Try my systemd commands. I expect its not necessary to stop playing audio. The systemd commands will take care of it and stop playing audio. RE: reset sound after suspend to memory (deep sleep) - Syonyk - 06-16-2020 Thanks, that's useful - I'll poke with some of that. My hope is to put something in the "restore from sleep" scripts that takes care of it automatically, or figure out what isn't handling sleep right in the kernel drivers. RE: reset sound after suspend to memory (deep sleep) - moonwalkers - 03-08-2021 Today I got a bit fed up by the sound not working after deep sleep, so until the driver itself is capable of handling sleep I hacked together a workaround that seems to work well enough. I haven't packaged it yet or anything, but I wanted to share with community what I got so far. Right now I have two pieces. First is a script: Code: $ cat /usr/local/sbin/sndreset Second is a systemd service unit: Code: $ cat /etc/systemd/system/pinebookpro-sleep.service Make sure the script is executable and the service unit is enabled. How does it work: Service unit plugs itself to run the script after suspend is done. I think I should be able to remove `hibernate.target` from it, but I decided to keep it around just in case. The meat is in the script itself, and here is what it does: 1. it removes all permissions from the /dev/snd/pcm* files, thus making sure no new process will be able to open them. 2. it enters a loop where for as long as the above files are still open it will send a message to all active sessions hinting at what to do to restore sound playback. Said message will be active for 10 seconds, and it is sent every 11 seconds. Loop iterates every second. 3. once whatever holds the above files open is stopped the loop will end. If one is using PulseAudio it should close those files too once no application is trying to play any sound. Since the files are set to permissions 000 no new process, including PulseAudio, should be able to open them again. 4. the device is re-initialized 5. finally, after a bit of a delay, restore asound.state to raise the volume in ALSA mixer - without this the sound volume may be stuck too low. Note that this script doesn't need PulseAudio to be stopped in any way, it only needs that nothing tries to play any sound. Finally about asound.state - I used one from Manjaro as a basis, but I: a) edited it to set both instances of 'Headphone Playback Volume' and both instances of 'Headphone Mixer Volume' to max value (3 and 11) - four places to change total; and b) set immutable flag on the file once it's copied to /var/lib/alsa/asound.state - otherwise I had it reset to values less than max volume. Something I still haven't figured out yet - how to call `alsactl restore` automatically at the right time on boot, because if it's called too early - the volume will not be restored properly, and sound will be stuck being very quiet. So far the best I was able to do is call it using systemd timer at `OnBootSec=1min`. RE: reset sound after suspend to memory (deep sleep) - moonwalkers - 03-10-2021 OK, so it's been couple days now and two reboots, after I figured out the issue I reported earlier with OS coming up without sound card (left-over configuration from one of the earlier experiments) things seem to work well so far. I have sound after boot, and I have sound after deep sleep. If the laptop went to sleep while playing some sounds it will not reset until the playback stops, but as soon as it stops it reset within few seconds. I may even be able to get around that block eventually, but for now it doesn't bother me enough to spend more time on it. RE: reset sound after suspend to memory (deep sleep) - Der Geist der Maschine - 03-10-2021 (03-08-2021, 11:48 PM)moonwalkers Wrote: until the driver itself is capable of handling sleep I hacked together a workaround that seems to work well enough.Syonyk was on the right track in https://forum.pine64.org/showthread.php?tid=10496 but we never heard back from him, again. RE: reset sound after suspend to memory (deep sleep) - moonwalkers - 03-10-2021 K, with some more modifications I was able to get the script working pretty well with sleep/resume cycles, with only caveat being applications that use sound may either quit/crash or lose sound until restart, or just pause playback - the exact behavior depends on a particular app. Here is the updated script: Code: $ cat /usr/local/sbin/sndreset RE: reset sound after suspend to memory (deep sleep) - Syonyk - 03-11-2021 Sorry... life got in the way. I really should get that set of patches bundled up for submission, I just haven't been liking computers much lately and have been avoiding them as much as possible outside work. My set of patches isn't very good, I'm certain it's not entirely correct. but it does work (mostly). Code: diff --git a/sound/soc/codecs/es8316.c b/sound/soc/codecs/es8316.c RE: reset sound after suspend to memory (deep sleep) - JGkn - 08-28-2021 (03-10-2021, 11:31 PM)moonwalkers Wrote: K, with some more modifications I was able to get the script working pretty well with sleep/resume cycles, with only caveat being applications that use sound may either quit/crash or lose sound until restart, or just pause playback - the exact behavior depends on a particular app. Here is the updated script: Perhaps you can help me or give some hints - I can't get your solution to work. I am on Kernel 5.7.19-1-MANJARO-ARM, coming from an installation with manjaro-arm-installer (encrypted) last week, then did Code: pacman -S uboot-pinebookpro-bsp If I use your script and systemd-unit unchanged, system hangs on waking up from sleep. If I use the command Code: sudo tee /sys/bus/i2c/drivers/es8316/{un,}bind <<< 1-0011 > /dev/null |