No sound after sleep - Ubuntu 20.04

i have same problem. And i find a solution, but it dosn't work in kde i don't known why.

Solution:

echo 1 > /sys/bus/pci/devices/<device_address>/remove
sleep 1
echo 1 > /sys/bus/pci/rescan

To search the device address: lspci | grep Audio

Update:

Solution to apply commands after wakeup:

You can create new file: /lib/systemd/system-sleep/99_restart_sound and insert the following source code:

#!/bin/sh
  
case "$1" in
    post)
        DEVICE_ID=`lspci -D |grep Audio|awk '{print $1}'`
        echo 1 > /sys/bus/pci/devices/${DEVICE_ID}/remove
        sleep 1
        echo 1 > /sys/bus/pci/rescan
esac

The file must be executable:

sudo chmod +x /lib/systemd/system-sleep/99_restart_sound

I have a success story (thank to Night Str)!

The same hardware. The same situation after sleep mode. First of all get root privileges:

$ sudo su -

Than discover your devices:

# lspci -vvv
...
00:1f.3 Audio device: Intel Corporation Device 02c8 (prog-if 80)
        Subsystem: Xiaomi Device 1963
        Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx+
        Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
        Latency: 32, Cache Line Size: 64 bytes
        Interrupt: pin A routed to IRQ 148
        Region 0: Memory at c4214000 (64-bit, non-prefetchable) [size=16K]
        Region 4: Memory at c4000000 (64-bit, non-prefetchable) [size=1M]
        Capabilities: <access denied>
        Kernel driver in use: snd_hda_intel
        Kernel modules: snd_hda_intel, snd_sof_pci
...

So, my device id is 00:1f.3. Let`s check it:

# ls /sys/bus/pci/devices/ | grep 00:1f.3
0000:00:1f.3

Here is the trick:

# echo 1 > /sys/bus/pci/devices/0000:00:1f.3/remove
# echo 1 > /sys/bus/pci/rescan

The first command disconnects the driver from the device and detaches the device from the tree. The driver (snd_hda_intel) is not unloaded, just disconnected. The second command rescans pci devices.

As result, sound appears back.