Bug 219697

Summary: Sound from 3.5mm headphone output is mono after deep suspend on Dell Venue 11 Pro 7130
Product: Drivers Reporter: andrewthompson1878 (andrewthompson1878)
Component: Sound(ALSA)Assignee: Jaroslav Kysela (perex)
Status: RESOLVED CODE_FIX    
Severity: low CC: andrewthompson1878, kailang, tiwai
Priority: P3    
Hardware: Intel   
OS: Linux   
URL: https://bugzilla.opensuse.org/show_bug.cgi?id=1235686
Kernel Version: 6.12.8 Subsystem:
Regression: No Bisected commit-id:
Attachments: alsa-info.sh output, before suspend (with coef)
alsa-info.sh output, after suspend (with coef)
0000-dell-7130.patch
alsa-info.sh output - before suspend, kernel 6.13.0-1.gdadfebc-default
alsa-info.sh output - after suspend, kernel 6.13.0-1.gdadfebc-default
Test fix patch

Description andrewthompson1878@gmail.com 2025-01-15 23:42:02 UTC
Created attachment 307490 [details]
alsa-info.sh output, before suspend (with coef)

Sound works properly from both the internal speakers and 3.5mm headphone output prior to suspend. But after resuming from suspend, the sound from the 3.5mm (wired) headphone output is no longer stereo. It sounds like mono when each channel is tested individually, but actually one channel is also out of phase. This is on a Dell Venue 11 Pro 7130 (with i3-4020Y CPU).

It only affects 3.5mm headphone output; internal speakers continue to work properly. The problem only occurs after resuming from deep suspend, not s2idle. (I use deep suspend (kernel option mem_sleep_default=deep) because it consumes too much battery in s2idle standby.) It does not return to normal until a reboot.

It also makes no difference whether using Pipewire or Pulse Audio, and all programs using sound are affected, including GNOME or KDE Plasma's Settings "Test Speakers".

I used these tests to reproduce the problem at the ALSA level, all using 3.5mm headphone output:
speaker-test -c2 -t wav
 - Before suspend "front left" is heard in left ear and "front right" is heard in the right ear as expected.
 - After resuming from suspend, "front left" is heard in both the left & right ear, and "front right" is heard in both left and right ear.
 
play a mono wav file (so that the same sound in both channels to test for out of phase i.e. cancellation):
aplay /usr/share/sounds/alsa/Noise.wav
 - Before suspend, this is heard in both left and right ears as expected.
 - After suspend, this is heard only very quietly and only in the right ear, i.e. consistent with out-of-phase cancellation.

I originally reported this bug at OpenSUSE (ref: https://bugzilla.opensuse.org/show_bug.cgi?id=1235686) where Takashi Iwai has kindly assisted.

A diff of alsa-info.sh output (with dump_coef) before and after deep suspend showed the following COEF discrepancies:

-    Coeff 0x06: 0x2100
+    Coeff 0x06: 0x2104

-    Coeff 0x0d: 0x2800
+    Coeff 0x0d: 0x2840

-    Coeff 0x16: 0x2250
+    Coeff 0x16: 0x0250

-    Coeff 0x43: 0x9614
+    Coeff 0x43: 0xa614

-    Coeff 0x46: 0x3004
+    Coeff 0x46: 0x0004

When the problem is occurring (after every resume from deep suspend) I can fix it by setting the COEF back to its pre-suspend values with hda-verb. I observed that COEF index 0x16 does not retain its value.

So I performed some testing using the following commands (excluding COEF index 0x16) when the headphone output is in the bad state and it successfully fixes it every time:

hda-verb /dev/snd/hwC1D0 0x20 SET_COEF_INDEX 0x06
hda-verb /dev/snd/hwC1D0 0x20 SET_PROC_COEF 0x2100

hda-verb /dev/snd/hwC1D0 0x20 SET_COEF_INDEX 0x0d
hda-verb /dev/snd/hwC1D0 0x20 SET_PROC_COEF 0x2800

hda-verb /dev/snd/hwC1D0 0x20 SET_COEF_INDEX 0x43
hda-verb /dev/snd/hwC1D0 0x20 SET_PROC_COEF 0x9614

hda-verb /dev/snd/hwC1D0 0x20 SET_COEF_INDEX 0x46
hda-verb /dev/snd/hwC1D0 0x20 SET_PROC_COEF 0x3004


Testing them one-by-one showed that just COEF index 0x0d on its own will also fix it, i.e. these commands alone also work:

hda-verb /dev/snd/hwC1D0 0x20 SET_COEF_INDEX 0x0d
hda-verb /dev/snd/hwC1D0 0x20 SET_PROC_COEF 0x2800

Also I found that setting 0x0d to 0x2840 will recreate the problem anytime, including without suspending.

The internal speakers output continued to work normally and was unaffected by any of the above tests.
Comment 1 andrewthompson1878@gmail.com 2025-01-15 23:42:40 UTC
Created attachment 307491 [details]
alsa-info.sh output, after suspend (with coef)
Comment 2 Takashi Iwai 2025-01-16 07:46:37 UTC
Kailang, is this COEF bit safe to toggle at resume, right?
Any other COEF bits to be restored at resume?
Comment 3 Kailiang Yang 2025-01-17 08:17:30 UTC
Yes.
Maybe need to add 0x0d to restore alc283_coefs table.

> -----Original Message-----
> From: bugzilla-daemon@kernel.org <bugzilla-daemon@kernel.org>
> Sent: Thursday, January 16, 2025 3:47 PM
> To: Kailang <kailang@realtek.com>
> Subject: [Bug 219697] Sound from 3.5mm headphone output is mono after
> deep suspend on Dell Venue 11 Pro 7130
> 
> 
> External mail.
> 
> 
> 
> https://bugzilla.kernel.org/show_bug.cgi?id=219697
> 
> Takashi Iwai (tiwai@suse.de) changed:
> 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>                  CC|
> |kailang@realtek.com
> 
> --- Comment #2 from Takashi Iwai (tiwai@suse.de) --- Kailang, is this COEF
> bit
> safe to toggle at resume, right?
> Any other COEF bits to be restored at resume?
> 
> --
> You may reply to this email to add a comment.
> 
> You are receiving this mail because:
> You are on the CC list for the bug.
Comment 4 Takashi Iwai 2025-01-17 10:04:15 UTC
Thanks for confirmation.  It'd be great if you can submit a fix patch, too ;)
Comment 5 Kailiang Yang 2025-01-21 09:06:57 UTC
Created attachment 307514 [details]
0000-dell-7130.patch

Please test attach patch.

> -----Original Message-----
> From: bugzilla-daemon@kernel.org <bugzilla-daemon@kernel.org>
> Sent: Friday, January 17, 2025 6:04 PM
> To: Kailang <kailang@realtek.com>
> Subject: [Bug 219697] Sound from 3.5mm headphone output is mono after
> deep suspend on Dell Venue 11 Pro 7130
> 
> 
> External mail.
> 
> 
> 
> https://bugzilla.kernel.org/show_bug.cgi?id=219697
> 
> --- Comment #4 from Takashi Iwai (tiwai@suse.de) --- Thanks for confirmation.
> It'd be great if you can submit a fix patch, too ;)
> 
> --
> You may reply to this email to add a comment.
> 
> You are receiving this mail because:
> You are on the CC list for the bug.
Comment 6 Takashi Iwai 2025-01-21 09:27:02 UTC
FWIW, openSUSE Tumbleweed kernel based on 6.13 with the patch is being built in OBS home:tiwai:bsc1235686 repo.  Once after the build finishes, it'll appear at
  https://download.opensuse.org/repositories/home:/tiwai:/bsc1235686/standard/
Comment 7 andrewthompson1878@gmail.com 2025-01-22 01:02:44 UTC
Thanks for the patch. I will test it from the OBS build in the next few days.
Comment 8 andrewthompson1878@gmail.com 2025-01-29 09:27:26 UTC
I have now tested this patch (using Takashi's OBS repo). It has not fixed the problem unfortunately.
Comment 9 Takashi Iwai 2025-01-29 09:52:12 UTC
Hm, could you verify that COEF 0xd isn't updated to 0x2800?

In anyway, please give alsa-info.sh output with the broken kernel (after suspend).
Comment 10 andrewthompson1878@gmail.com 2025-01-29 11:16:10 UTC
I have checked and COEF 0xd is not being set to 0x2800 after resuming. It remains at 0x2840. I am attaching alsa-info.sh output before and after suspend.
Comment 11 andrewthompson1878@gmail.com 2025-01-29 11:18:26 UTC
Created attachment 307547 [details]
alsa-info.sh output - before suspend, kernel 6.13.0-1.gdadfebc-default
Comment 12 andrewthompson1878@gmail.com 2025-01-29 11:19:03 UTC
Created attachment 307548 [details]
alsa-info.sh output - after suspend, kernel 6.13.0-1.gdadfebc-default
Comment 13 Takashi Iwai 2025-01-29 13:55:52 UTC
OK, then let's try more idiomatic, explicit quirk setup with the COEF 0x0d write.  The patch is below.

A new kernel is being built in OBS home:tiwai:bsc1235686-2 repo.  Once after the build finishes, it'll appear at
  https://download.opensuse.org/repositories/home:/tiwai:/bsc1235686-2/standard/

Please give it a try later.
Comment 14 Takashi Iwai 2025-01-29 13:56:19 UTC
Created attachment 307550 [details]
Test fix patch
Comment 15 andrewthompson1878@gmail.com 2025-01-30 10:55:18 UTC
Success. I have tested Takashi's latest patch and it works for me. COEF index 0x0d is correctly set to 0x2800 upon each resume. And headphone out now works correctly after resume. I also confirmed internal speakers have not been adversely affected.
Comment 16 Takashi Iwai 2025-01-30 12:19:53 UTC
Good to hear.  Then I'm going to submit it.  Hopefully it'll be included in 6.14-rc1 and backported to stable kernels.

It's an idiomatic change.  If it works, it's fine enough