Bug 77901

Summary: center and lfe channels screwed up on suspend
Product: Drivers Reporter: Pierre Ossman (pierre-bugzilla)
Component: Sound(ALSA)Assignee: Jaroslav Kysela (perex)
Status: RESOLVED CODE_FIX    
Severity: normal CC: tiwai
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 3.14.5-200.fc20.x86_64 Subsystem:
Regression: No Bisected commit-id:
Attachments: Test patch
patch to call correct init

Description Pierre Ossman 2014-06-14 14:31:57 UTC
AMD HDMI audio output. Works fine until I suspend the machine. After resume, center channel is silent and LFE channel is sent as center.

Massive issue as the center channel is the most used one of all in multichannel audio sources. :/

Unloading just snd_hda_intel and reloading it seems to work around the issue.
Comment 1 Pierre Ossman 2014-06-14 14:43:59 UTC
Unfortunately it's difficult to automate a reload of snd_hda_intel as there will in general be processes keeping it open (and therefore used).

Any other way of forcing a reinit of the device?
Comment 2 Pierre Ossman 2014-06-14 14:45:23 UTC
Hardware:

00:01.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Richland [Radeon HD 8510G] [1002:9999]
00:01.1 Audio device [0403]: Advanced Micro Devices, Inc. [AMD/ATI] Trinity HDMI Audio Controller [1002:9902]
Comment 3 Takashi Iwai 2014-06-16 09:07:05 UTC
How about the patch below?
Comment 4 Takashi Iwai 2014-06-16 09:07:40 UTC
Created attachment 139891 [details]
Test patch
Comment 5 Pierre Ossman 2014-06-16 19:13:34 UTC
Afraid it had no effect. It rebuilt a whole bunch of modules, but generic_hdmi_resume() was only present in snd_hda_codec_hdmi.ko so I only replaced that module. I assume that was sufficient?
Comment 6 Pierre Ossman 2014-06-16 19:31:34 UTC
I hacked patch_hdmi.c so that the debug out in there would be enabled. I got this during boot:

> [    9.986083] HDMI: ASP channel 0 => slot 0
> [    9.986104] HDMI: ASP channel 1 => slot 1
> [    9.986120] HDMI: ASP channel 15 => slot 2
> [    9.986136] HDMI: ASP channel 15 => slot 3
> [    9.986151] HDMI: ASP channel 15 => slot 4
> [    9.986166] HDMI: ASP channel 15 => slot 5
> [    9.986181] HDMI: ASP channel 15 => slot 6
> [    9.986196] HDMI: ASP channel 15 => slot 7
> [    9.986301] ALSA DEBUG: atihdmi_pin_hbr_setup: NID=0x3, hbr-ctl=0x1
> [    9.988422] HDMI: ASP channel 0 => slot 0
> [    9.988438] HDMI: ASP channel 1 => slot 1
> [    9.988452] HDMI: ASP channel 15 => slot 2
> [    9.988497] HDMI: ASP channel 15 => slot 3
> [    9.988511] HDMI: ASP channel 15 => slot 4
> [    9.988525] HDMI: ASP channel 15 => slot 5
> [    9.988600] HDMI: ASP channel 15 => slot 6
> [    9.988614] HDMI: ASP channel 15 => slot 7
> [    9.988654] ALSA DEBUG: atihdmi_pin_hbr_setup: NID=0x3, hbr-ctl=0x1
> [    9.993335] ALSA DEBUG: HDMI: select CA 0xb for 6-channel allocation: 
> FL/FR LFE FC RL/RR RC RLC/RRC
> [    9.993542] HDMI: ASP channel 0 => slot 0
> [    9.993556] HDMI: ASP channel 1 => slot 1
> [    9.993570] HDMI: ASP channel 5 => slot 2
> [    9.993583] HDMI: ASP channel 4 => slot 3
> [    9.993628] HDMI: ASP channel 2 => slot 4
> [    9.993642] HDMI: ASP channel 3 => slot 5
> [    9.993656] HDMI: ASP channel 15 => slot 6
> [    9.993670] HDMI: ASP channel 15 => slot 7
> [    9.993708] ALSA DEBUG: atihdmi_pin_hbr_setup: NID=0x3, hbr-ctl=0x1
> [    9.995318] ALSA DEBUG: HDMI: select CA 0xb for 6-channel allocation: 
> FL/FR LFE FC RL/RR RC RLC/RRC
> [    9.995571] HDMI: ASP channel 0 => slot 0
> [    9.995648] HDMI: ASP channel 1 => slot 1
> [    9.995664] HDMI: ASP channel 5 => slot 2
> [    9.995678] HDMI: ASP channel 4 => slot 3
> [    9.995691] HDMI: ASP channel 2 => slot 4
> [    9.995777] HDMI: ASP channel 3 => slot 5
> [    9.995792] HDMI: ASP channel 15 => slot 6
> [    9.995805] HDMI: ASP channel 15 => slot 7
> [    9.995844] ALSA DEBUG: atihdmi_pin_hbr_setup: NID=0x3, hbr-ctl=0x1
> [   10.000753] ALSA DEBUG: atihdmi_pin_hbr_setup: NID=0x5, hbr-ctl=0x1
> [   10.002536] ALSA DEBUG: atihdmi_pin_hbr_setup: NID=0x5, hbr-ctl=0x1
> [   10.007472] ALSA DEBUG: atihdmi_pin_hbr_setup: NID=0x5, hbr-ctl=0x1
> [   10.009510] ALSA DEBUG: atihdmi_pin_hbr_setup: NID=0x5, hbr-ctl=0x1
> [   10.013004] ALSA DEBUG: atihdmi_pin_hbr_setup: NID=0x7, hbr-ctl=0x1
> [   10.014409] ALSA DEBUG: atihdmi_pin_hbr_setup: NID=0x7, hbr-ctl=0x1
> [   10.019068] ALSA DEBUG: atihdmi_pin_hbr_setup: NID=0x7, hbr-ctl=0x1
> [   10.020536] ALSA DEBUG: atihdmi_pin_hbr_setup: NID=0x7, hbr-ctl=0x1
> [   10.024550] ALSA DEBUG: atihdmi_pin_hbr_setup: NID=0x9, hbr-ctl=0x1
> [   10.026473] ALSA DEBUG: atihdmi_pin_hbr_setup: NID=0x9, hbr-ctl=0x1
> [   10.030653] ALSA DEBUG: atihdmi_pin_hbr_setup: NID=0x9, hbr-ctl=0x1
> [   10.032346] ALSA DEBUG: atihdmi_pin_hbr_setup: NID=0x9, hbr-ctl=0x1
> [   10.040570] ALSA DEBUG: HDMI: select CA 0xb for 6-channel allocation: 
> FL/FR LFE FC RL/RR RC RLC/RRC
> [   10.040729] HDMI: ASP channel 0 => slot 0
> [   10.040747] HDMI: ASP channel 1 => slot 1
> [   10.040826] HDMI: ASP channel 5 => slot 2
> [   10.040842] HDMI: ASP channel 4 => slot 3
> [   10.040860] HDMI: ASP channel 2 => slot 4
> [   10.040875] HDMI: ASP channel 3 => slot 5
> [   10.040955] HDMI: ASP channel 15 => slot 6
> [   10.040970] HDMI: ASP channel 15 => slot 7
> [   10.041073] ALSA DEBUG: atihdmi_pin_hbr_setup: NID=0x3, hbr-ctl=0x1
> [   10.042343] ALSA DEBUG: HDMI: select CA 0xb for 6-channel allocation: 
> FL/FR LFE FC RL/RR RC RLC/RRC
> [   10.042477] HDMI: ASP channel 0 => slot 0
> [   10.042492] HDMI: ASP channel 1 => slot 1
> [   10.042506] HDMI: ASP channel 5 => slot 2
> [   10.042520] HDMI: ASP channel 4 => slot 3
> [   10.042535] HDMI: ASP channel 2 => slot 4
> [   10.042549] HDMI: ASP channel 3 => slot 5
> [   10.042563] HDMI: ASP channel 15 => slot 6
> [   10.042577] HDMI: ASP channel 15 => slot 7
> [   10.042616] ALSA DEBUG: atihdmi_pin_hbr_setup: NID=0x3, hbr-ctl=0x1

Then I ran speaker-test, which worked fine:

> [   65.086623] ALSA DEBUG: HDMI: select CA 0xb for 6-channel allocation: 
> FL/FR LFE FC RL/RR RC RLC/RRC
> [   65.086871] HDMI: ASP channel 0 => slot 0
> [   65.086887] HDMI: ASP channel 1 => slot 1
> [   65.086903] HDMI: ASP channel 5 => slot 2
> [   65.086920] HDMI: ASP channel 4 => slot 3
> [   65.086935] HDMI: ASP channel 2 => slot 4
> [   65.086950] HDMI: ASP channel 3 => slot 5
> [   65.086965] HDMI: ASP channel 15 => slot 6
> [   65.086981] HDMI: ASP channel 15 => slot 7
> [   65.087022] ALSA DEBUG: atihdmi_pin_hbr_setup: NID=0x3, hbr-ctl=0x1
> [   65.088344] ALSA DEBUG: HDMI: select CA 0xb for 6-channel allocation: 
> FL/FR LFE FC RL/RR RC RLC/RRC
> [   65.088493] HDMI: ASP channel 0 => slot 0
> [   65.088510] HDMI: ASP channel 1 => slot 1
> [   65.088526] HDMI: ASP channel 5 => slot 2
> [   65.088541] HDMI: ASP channel 4 => slot 3
> [   65.088567] HDMI: ASP channel 2 => slot 4
> [   65.088582] HDMI: ASP channel 3 => slot 5
> [   65.088598] HDMI: ASP channel 15 => slot 6
> [   65.088612] HDMI: ASP channel 15 => slot 7
> [   65.088654] ALSA DEBUG: atihdmi_pin_hbr_setup: NID=0x3, hbr-ctl=0x1

Suspended and resumed. Nothing new in dmesg. Re-ran speaker-test, this time with broken channels:

> [   99.689167] ALSA DEBUG: HDMI: select CA 0xb for 6-channel allocation: 
> FL/FR LFE FC RL/RR RC RLC/RRC
> [   99.689325] HDMI: ASP channel 0 => slot 0
> [   99.689340] HDMI: ASP channel 1 => slot 1
> [   99.689354] HDMI: ASP channel 5 => slot 2
> [   99.689367] HDMI: ASP channel 4 => slot 3
> [   99.689382] HDMI: ASP channel 2 => slot 4
> [   99.689395] HDMI: ASP channel 3 => slot 5
> [   99.689409] HDMI: ASP channel 15 => slot 6
> [   99.689422] HDMI: ASP channel 15 => slot 7
> [   99.689462] ALSA DEBUG: atihdmi_pin_hbr_setup: NID=0x3, hbr-ctl=0x1
> [   99.690626] ALSA DEBUG: HDMI: select CA 0xb for 6-channel allocation: 
> FL/FR LFE FC RL/RR RC RLC/RRC
> [   99.690771] HDMI: ASP channel 0 => slot 0
> [   99.690786] HDMI: ASP channel 1 => slot 1
> [   99.690801] HDMI: ASP channel 5 => slot 2
> [   99.690815] HDMI: ASP channel 4 => slot 3
> [   99.690829] HDMI: ASP channel 2 => slot 4
> [   99.690843] HDMI: ASP channel 3 => slot 5
> [   99.690857] HDMI: ASP channel 15 => slot 6
> [   99.690871] HDMI: ASP channel 15 => slot 7
> [   99.690911] ALSA DEBUG: atihdmi_pin_hbr_setup: NID=0x3, hbr-ctl=0x1
Comment 7 Takashi Iwai 2014-06-17 10:10:50 UTC
You should check whether atihdmi_pin_setup_infoframe() and atihdmi_pin_set_slot_channel() whether all registers are set same in both before and after suspend.  If all are same, the problem is likely in the video driver instead of the audio driver.
Comment 8 Pierre Ossman 2014-06-17 20:06:16 UTC
I added debug prints to those two functions and they set the verbs in identical manner before and after suspend. So graphics driver bug I guess.
Comment 9 Pierre Ossman 2014-06-17 20:06:50 UTC
Hmm... seems I'm not allowed to reset assignee to default in this bugzilla?
Comment 10 Pierre Ossman 2014-06-17 20:10:08 UTC
Reported this in the freedesktop bugzilla, as that's usually where the graphics people hang out:

https://bugs.freedesktop.org/show_bug.cgi?id=80162
Comment 11 Pierre Ossman 2014-06-18 19:46:38 UTC
Bug found, and it is in the ALSA driver. MULTICHANNEL_MODE is not set to its proper value after resume, which is what screws up the mappings. I'll prepare a patch.
Comment 12 Pierre Ossman 2014-06-18 19:53:00 UTC
Created attachment 140271 [details]
patch to call correct init

Attached patch fixes the issue here. MULTICHANNEL_MODE is set in atihdmi_init(), so make sure the proper init function is called on resume instead of only the generic one.

I considered overriding .resume instead, but the orde would be a bit weird as you'd then set MULTICHANNEL_MODE after you'd already started fiddling with the channel settings.

Hopefully this change is safe and correct.
Comment 13 Takashi Iwai 2014-06-23 10:34:23 UTC
Nice catch, I applied the patch now.  It should be included in 3.16-rc3.