Bug 108301 - snd_hda_codec_realtek ALC1150 Background noise, CPU load dependent noise, possibly weird lockups
Summary: snd_hda_codec_realtek ALC1150 Background noise, CPU load dependent noise, pos...
Status: RESOLVED CODE_FIX
Alias: None
Product: Drivers
Classification: Unclassified
Component: Sound(ALSA) (show other bugs)
Hardware: x86-64 Linux
: P1 normal
Assignee: Jaroslav Kysela
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-22 10:08 UTC by Sverd Johnsen
Modified: 2016-02-05 21:58 UTC (History)
3 users (show)

See Also:
Kernel Version: 4.3.0
Subsystem:
Regression: No
Bisected commit-id:


Attachments
After muting stuff (48.43 KB, text/plain)
2015-11-22 10:08 UTC, Sverd Johnsen
Details
Generated hda_analyzer script (1.04 KB, text/x-python)
2015-11-22 10:12 UTC, Sverd Johnsen
Details

Description Sverd Johnsen 2015-11-22 10:08:37 UTC
Created attachment 195141 [details]
After muting stuff

I got a Z170 board Gigabyte Z170X-UD3 with Intel(R) Core(TM) i5-6600K CPU @ 3.50GHz

00:1f.3 Multimedia audio controller [0401]: Intel Corporation Sunrise Point-H HD Audio [8086:a170] (rev 31)

First thing I noticed was the constant background noise, I figured I would get rid of it by muting stuff via alsamixer but was unable to achieve this and had to use hda_analyzer

Second thing I noticed is CPU load dependent audio issues like crackling etc. Just moving the mouse in firefox is enough to get rid of it (almost?) completly. Not *that* bad really, it's mostly okay while listening to music.

Third thing I haven't figured out yet but I had occasional lockups from pulseaudio, not sure if they are related.

Broadly similar reports are not hard to find:

https://bbs.archlinux.org/viewtopic.php?id=195513
https://bbs.archlinux.org/viewtopic.php?id=191041
https://bbs.archlinux.org/viewtopic.php?id=181764
Comment 1 Sverd Johnsen 2015-11-22 10:12:48 UTC
Created attachment 195151 [details]
Generated hda_analyzer script
Comment 2 Raymond 2015-11-22 11:26:01 UTC
Node 0x0c [Audio Mixer] wcaps 0x20010b: Stereo Amp-In 
Amp-In caps: ofs=0x00, nsteps=0x00, stepsize=0x00, mute=1 
Amp-In vals: [0x00 0x00] [0x80 0x80] 
Connection: 2 0x02 0x0b


This is one of the analog loopback playback switch of the analog mixer 0x0b

The other HDA codecs have one switch but realtek codecs have this switch for all output pins
Comment 3 Raymond 2015-11-22 11:33:01 UTC

Do you mean noise only appear in line out and not affect headphone when you enable front mic playback volume? 

Node 0x0f [Audio Mixer] wcaps 0x20010b: Stereo Amp-In 
Amp-In caps: ofs=0x00, nsteps=0x00, stepsize=0x00, mute=1 
Amp-In vals: [0x00 0x00] [0x00 0x00] 
Connection: 2 0x05 0x0b
Comment 4 Sverd Johnsen 2015-11-22 18:24:20 UTC
Not sure I understand what you are asking. 

Background noise is there always unless is muted via hda_analyzer. I have pulseaudio set to "Analog Stereo Output" via pavucontrol. In "Output Devices" there is "Line Out" and "Headphones", from what I can there is no difference except that the settings are seperate (alsamixer values change when I pick one or the other, not sure I get why.)

When I enable (unmute) "Front Mic" (In Playback) there is *additional noise* and even more with "Front Mic Boost" but then it's slightly different.
Comment 5 Sverd Johnsen 2015-11-22 18:29:29 UTC
Obviously the noise is not *always* there, e.g when I actually mute "Front" it is gone. (But second issue still there)
Comment 6 Raymond 2015-11-23 00:53:23 UTC
The output is connected to different output pins through those audio mixers


The sources are system beep, mic, line in 

Node 0x0b [Audio Mixer] wcaps 0x20010b: Stereo 
Amp-In Control: name="Front Mic Playback Volume", index=0, device=0 
ControlAmp: chs=3, dir=In, idx=1, ofs=0 
Control: name="Front Mic Playback Switch", index=0, device=0 
ControlAmp: chs=3, dir=In, idx=1, ofs=0 
Control: name="Rear Mic Playback Volume", index=0, device=0 
ControlAmp: chs=3, dir=In, idx=0, ofs=0 
Control: name="Rear Mic Playback Switch", index=0, device=0 
ControlAmp: chs=3, dir=In, idx=0, ofs=0 
Control: name="Line Playback Volume", index=0, device=0 
ControlAmp: chs=3, dir=In, idx=2, ofs=0 
Control: name="Line Playback Switch", index=0, device=0 
ControlAmp: chs=3, dir=In, idx=2, ofs=0 
Control: name="Beep Playback Volume", index=0, device=0 
ControlAmp: chs=3, dir=In, idx=5, ofs=0 
Control: name="Beep Playback Switch", index=0, device=0 
ControlAmp: chs=3, dir=In, idx=5, ofs=0 
Amp-In caps: ofs=0x17, nsteps=0x1f, stepsize=0x05, mute=1 
Amp-In vals: [0x80 0x80] [0x80 0x80] [0x80 0x80] [0x80 0x80] [0x80 0x80] [0x80 0x80] [0x80 0x80] [0x80 0x80] 
Connection: 8 
0x18 0x19 0x1a 0x1b 0x14 0x15 0x16 0x17
Comment 7 Raymond 2015-11-23 01:04:58 UTC
Do you mean you need a loopback mixing switch which control the mix of input from node 0x0b in those audio mixer node 0x0c, 0x0d,  0x0e and 0x0f


assshttps://git.kernel.org/cgit/linux/kernel/git/tiwai/sound.git/log/sound/pci/hda?qt=grep&q=loopback+mixing
Comment 8 Raymond 2015-11-23 02:36:51 UTC
they were unmuted by activate_amp_in() when set_output_and_unmute() call snd_hda_activate_path(codec, path, path->active,
			      aamix_default(codec->spec));


set output and unmute
send: NID=0x14, VERB=0x707(set_pin_ctl), PARM=0x40
activate path
send: NID=0x14, VERB=0xba0(get_amp_gain_mute,O:L#0), PARM=0x0
receive: 0x0
send: NID=0x14, VERB=0x3a0(set_amp_gain_mute,O:L#0), PARM=0x80
send: NID=0x14, VERB=0xb80(get_amp_gain_mute,O:R#0), PARM=0x0
receive: 0x0
send: NID=0x14, VERB=0x390(set_amp_gain_mute,O:R#0), PARM=0x80
activate amp in c
send: NID=0xc, VERB=0xf00(get_parameters), PARM=0xd(amp_in_cap)
receive: 0x80000000
send: NID=0xc, VERB=0xb20(get_amp_gain_mute,I:L#0), PARM=0x0
receive: 0x0
send: NID=0xc, VERB=0x360(set_amp_gain_mute,I:L#0), PARM=0x80
send: NID=0xc, VERB=0xb00(get_amp_gain_mute,I:R#0), PARM=0x0
receive: 0x0
send: NID=0xc, VERB=0x350(set_amp_gain_mute,I:R#0), PARM=0x80
send: NID=0xc, VERB=0xb20(get_amp_gain_mute,I:L#0), PARM=0x1
receive: 0x80
send: NID=0xc, VERB=0xb00(get_amp_gain_mute,I:R#0), PARM=0x1
receive: 0x80
send: NID=0xc, VERB=0x360(set_amp_gain_mute,I:L#0), PARM=0x0
send: NID=0xc, VERB=0x350(set_amp_gain_mute,I:R#0), PARM=0x0
send: NID=0xc, VERB=0x361(set_amp_gain_mute,I:L#1), PARM=0x0
send: NID=0xc, VERB=0x351(set_amp_gain_mute,I:R#1), PARM=0x0
end of activate amp in
Comment 9 Takashi Iwai 2015-11-23 13:57:41 UTC
Could you try just to disable the whole analog loopback?  As an easy solution, create a patch firmware file, e.g. /lib/firmware/alsa/disable-aamix, containing the following lines:

[codec]
0x10ec0900 0x1458a182 0

[hint]
mixer_nid = 0

Then add a module option in some file in /etc/modprobe.d/*, containing the line:

options snd-hda-intel patch=alsa/disable-aamix

And reboot.  This will remove the whole loopback (e.g. "Front Mic Playback Switch", etc), but such a feature is rarely needed in anyway.

And, the PA lockup is likely irrelevant with the loopback noise itself.
Comment 10 Raymond 2015-11-23 15:10:22 UTC
/* here is a little bit tricky in comparison with activate_amp_out(); * when aa-mixer is available, we need to enable the path as well */ 

for (n = 0; n < nums; n++) { 
  if (n != idx && (!add_aamix || conn[n] != spec->mixer_merge_nid)) 
    continue; 
  activate_amp(codec, nid, HDA_INPUT, n, idx, enable); 
}

This part explicity unmute the connection of those output pins to loopback mixer node 0x0b through the four audio mixer nodes 0xc 0xd, 0xe and 0xf

It is not easy to create a loopback mixing switch to mute four amp in at the same time
Comment 11 Takashi Iwai 2015-11-23 15:15:22 UTC
Yeah, but we need to identify whether the problem really comes from the aamix.  There are already quirks just disabling aamix for these codecs, so it's easy to add one more, as the easiest fix, if it's really the cause.

We may improve the aamix enable/disable switch later.
Comment 12 Sverd Johnsen 2015-11-24 16:50:47 UTC
(In reply to Takashi Iwai from comment #9)
> Could you try just to disable the whole analog loopback?  As an easy
> solution, create a patch firmware file, e.g.
> /lib/firmware/alsa/disable-aamix, containing the following lines:
> 
> [codec]
> 0x10ec0900 0x1458a182 0
> 
> [hint]
> mixer_nid = 0
> 
> Then add a module option in some file in /etc/modprobe.d/*, containing the
> line:
> 
> options snd-hda-intel patch=alsa/disable-aamix
> 
> And reboot.  This will remove the whole loopback (e.g. "Front Mic Playback
> Switch", etc), but such a feature is rarely needed in anyway.

That worked to fix the constant background noise.

> And, the PA lockup is likely irrelevant with the loopback noise itself.

Yes it was completly unrelated and is fixed now.
Comment 13 Takashi Iwai 2015-11-24 18:56:50 UTC
OK, then we know that the loopback is actually the cause.
Now, another question is whether muting the loopback path suffices.

Could you revert the previous change (just dropping patch option should be enough), make the system noisy.  Then try hda-verb to mute aamix paths like:

hda-verb /dev/snd/hwC0D0 0x0c SET_AMP 0x7180
hda-verb /dev/snd/hwC0D0 0x0d SET_AMP 0x7180
hda-verb /dev/snd/hwC0D0 0x0e SET_AMP 0x7180
hda-verb /dev/snd/hwC0D0 0x0f SET_AMP 0x7180
hda-verb /dev/snd/hwC0D0 0x26 SET_AMP 0x7180

The first three are for the rear line-outs, the fourth is for the headphone, and the last one is unused, but just to be sure.  Does this shut up noises?
Comment 14 Takashi Iwai 2015-11-24 19:08:28 UTC
Meanwhile I submitted a fix patch to disable the aamix paths, which has the very same effect like the firmware patch file you used but done statically in the driver.  It'll be included in 4.4-rc3, then backported to stable kernels later.

I asked the previous question just for future work -- whether it's worth to implement a mixer switch for enabling/disabling loopback paths.
Comment 15 Sverd Johnsen 2015-11-24 20:34:59 UTC
(In reply to Takashi Iwai from comment #13)
> OK, then we know that the loopback is actually the cause.
> Now, another question is whether muting the loopback path suffices.
> 
> Could you revert the previous change (just dropping patch option should be
> enough), make the system noisy.  Then try hda-verb to mute aamix paths like:
> 
> hda-verb /dev/snd/hwC0D0 0x0c SET_AMP 0x7180

This seems to do the trick.

> hda-verb /dev/snd/hwC0D0 0x0d SET_AMP 0x7180
> hda-verb /dev/snd/hwC0D0 0x0e SET_AMP 0x7180
> hda-verb /dev/snd/hwC0D0 0x0f SET_AMP 0x7180
> hda-verb /dev/snd/hwC0D0 0x26 SET_AMP 0x7180
> 

No changes from what I can tell.

> The first three are for the rear line-outs, the fourth is for the headphone,
> and the last one is unused, but just to be sure.  Does this shut up noises?

Obviously issue #2 (CPU load stuff) still exists altough I'm not sure whats going on anymore. I confirmed this with two different headphones a few days ago but now I have a new one where I don't hear them _at all_. Might not be driver related. Unfortunately I don't have a Windows install to compare against right now. 

Honestly I'm just happy I found hda-analyzer.
Comment 17 Takashi Iwai 2016-01-20 11:33:08 UTC
OK, the patch was merged to 4.5-rc1.
Comment 18 mutedbytes 2016-02-05 05:58:40 UTC
I have a Gigabyte Z97 system that uses ALC1150 audio, and think that I have lost functionality due to the patch. With the "Line-in" mixer previously set at reasonable levels, I believe I do not have a noise problem on my particular system (in comparing between 4.1.16 and 4.1.17), though in my case I have the Line-in jack terminated with input from a secondary sound card. Actually, I was using this mixer loopback functionality to have a single audio output for a host + VM guest system, and have lost this use case due to the patch. If possible, please allow an option to enable or disable the mixer.
Comment 19 Takashi Iwai 2016-02-05 21:58:50 UTC
OK, I queued the patch to revert the quirk now.  I'm going to ask Greg to cherry-pick the commit e7fdd52779a6.  This will add the dynamic loopback enablement via mixer element that has been added to 4.5-rc1, too.

Note You need to log in before you can comment on or make changes to this bug.