18

I have a Xioami notebook pro laptop on Ubuntu 20.04 (same issue on 18.04).

After the laptop goes in sleep/hibernate mode, there is no sound that comes out of the speakers. The system settings (settings>sounds) are detecting music is being played and the headphones are working fine after sleep. The issue is only related to the speakers integrated in the laptop. As a quick fix, I need to reboot to have the speakers to work again.

I have tried the options below without success:

  1. Open alsamixer and do not see any "muted speaker"
  2. Enter in the terminal: sudo alsa force-reload
  3. Set up the script that reload alsa after sleep as indicated on the Ubuntu help page
  4. pavucontrol is also install on my laptop
  5. Tried to kill and restart pulseaudio

Let me know if you have any ideas to fix the issue.
I believe it is driver related, but I'm not sure how to resolve this.


Please find below the information mentioned on the hardware.

aplay -l:

**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC256 Analog [ALC256 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 7: HDMI 1 [HDMI 1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 8: HDMI 2 [HDMI 2]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 9: HDMI 3 [HDMI 3]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 10: HDMI 4 [HDMI 4]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

cat /proc/asound/cards:

 0 [PCH            ]: HDA-Intel - HDA Intel PCH
                      HDA Intel PCH at 0xb4214000 irq 147

lspci -nnk | grep -A2 Audio:

00:1f.3 Audio device [0403]: Intel Corporation Device [8086:02c8]
    Subsystem: Xiaomi Device [1d72:1905]
    Kernel driver in use: snd_hda_intel

pacmd list-cards:

1 card(s) available.
    index: 0
    name: <alsa_card.pci-0000_00_1f.3>
    driver: <module-alsa-card.c>
    owner module: 7
    properties:
        alsa.card = "0"
        alsa.card_name = "HDA Intel PCH"
        alsa.long_card_name = "HDA Intel PCH at 0xb4214000 irq 147"
        alsa.driver_name = "snd_hda_intel"
        device.bus_path = "pci-0000:00:1f.3"
        sysfs.path = "/devices/pci0000:00/0000:00:1f.3/sound/card0"
        device.bus = "pci"
        device.vendor.id = "8086"
        device.vendor.name = "Intel Corporation"
        device.product.id = "02c8"
        device.form_factor = "internal"
        device.string = "0"
        device.description = "Built-in Audio"
        module-udev-detect.discovered = "1"
        device.icon_name = "audio-card-pci"

Thanks.

Zanna
  • 72,312

6 Answers6

22

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.

GHopper
  • 446
  • 1
  • 5
  • 10
11

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
Jan S.
  • 3
Night Str
  • 111
8

type this command:

pulseaudio -k

each time your computer out of sleep.

could be related to this bug: https://bugs.launchpad.net/ubuntu/+source/pulseaudio/+bug/1888598

2

This command worked for me
amixer -q -D pulse sset Master toggle

Seems it mutes then unmutes the master audio device

0

After figuring out all the audio device IDs from lspci -vvv (please replace device id according in the below mentioned commands) :

sudo echo 1 |sudo tee /sys/bus/pci/devices/0000:00:03.0/remove
sudo echo 1 |sudo tee /sys/bus/pci/devices/0000:03:00.0/remove
sudo echo 1 |sudo tee /sys/bus/pci/devices/0000:00:1b.0/remove
sleep 10
sudo echo 1 |sudo tee /sys/bus/pci/rescan
sleep 10
pulseaudio --kill; pulseaudio --start
Greenonline
  • 2,182
0

So, I see that a proper answer is already here. But there is no proper answer to how to automate this process.

The script in the /lib/systemd/system-sleep/restart_sound works, but the system is starting 10 times slower.

For me, proper solution looks like this:

  1. Create a service that will run on the resume event:
touch /etc/systemd/system/restart_sound.service
[Unit]
Description=Restart Sound Device After Login On Resume
After=suspend.target

[Service] User=root Type=oneshot ExecStart=sudo /local/restart_sound

[Install] WantedBy=suspend.target

  1. Run this service
systemctl enable restart_sound.service

Script itself:

# PCI device to remove
PCI_DEVICE="0000:00:1f.3"

Function to restart sound device

restart_sound_device() {

Remove PCI device

Sleep not to interfere with other processes

sleep 3 if [[ -e "/sys/bus/pci/devices/$PCI_DEVICE" ]]; then echo "$(date)Removing PCI device $PCI_DEVICE..." >> /local/resume.log echo 1 | tee "/sys/bus/pci/devices/$PCI_DEVICE/remove" > /dev/null sleep 1 else echo "$(date)PCI device $PCI_DEVICE does not exist. Skipping removal." >> /local/resume.log fi

Rescan PCI bus

echo "$(date)Rescanning PCI bus..." >> /local/resume.log echo 1 | tee /sys/bus/pci/rescan > /dev/null }

Run as root

if [[ $EUID -ne 0 ]]; then echo "$(date)This script must be run as root. Use sudo." >> /local/resume.log exit 1 fi

restart_sound_device

Done!