Bug 116421 - ALC668 on ASUS N551VW problems: no sound from left speaker, squeaky sound on earphones and subwoofer not enabled by default
Summary: ALC668 on ASUS N551VW problems: no sound from left speaker, squeaky sound on ...
Status: NEW
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: 2016-04-15 14:12 UTC by Elias
Modified: 2017-05-01 10:42 UTC (History)
3 users (show)

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


Attachments
alsa_info.sh output on N551VW (38.88 KB, text/plain)
2016-04-15 14:12 UTC, Elias
Details
alsa_info.sh output on N551VW (no quirks) (34.81 KB, text/plain)
2016-04-15 14:43 UTC, Elias
Details
Test fix patch (774 bytes, patch)
2016-04-15 14:50 UTC, Takashi Iwai
Details | Diff
At boot, with dump of coefficients (39.95 KB, application/octet-stream)
2016-05-03 17:58 UTC, Elias
Details
After resuming, with dump of coefficients (39.96 KB, application/octet-stream)
2016-05-03 17:59 UTC, Elias
Details
At boot, with dump of coefficients (44.50 KB, application/octet-stream)
2016-05-04 09:01 UTC, Elias
Details
After resuming, with dump of coefficients (44.50 KB, application/octet-stream)
2016-05-04 09:02 UTC, Elias
Details

Description Elias 2016-04-15 14:12:53 UTC
Created attachment 212891 [details]
alsa_info.sh output on N551VW

The left speaker on my ASUS N551VW does not work. I've tried using hdajackretask and hda_analyzer with no success to date.
On the other hand the fix from: 

https://bugzilla.kernel.org/show_bug.cgi?id=70821

seems to apply for the squeaky sound on the earphones which does go away, but  the left speaker still doesn't work. 
The right speaker seems to be working properly.
Comment 1 Takashi Iwai 2016-04-15 14:24:54 UTC
Well, let's clarify what problems you have:
1. Noise on headphone output
2. No left speaker sound

Is this correct?

And, doesn't your machine have any bass speaker?  Other ASUS models seem to have a bass speaker, either in NID 0x16 or 0x1a.

1 seems fixed by alc_fixup_auto_mute_via_amp option.  And this itself doesn't cause any other regression?

So, the question is about 2.  Does the left speaker work on Windows?
Comment 2 Takashi Iwai 2016-04-15 14:32:04 UTC
Oh, also please give alsa-info.sh output without any quirks (no patch and model options), too.
Comment 3 Elias 2016-04-15 14:42:45 UTC
Yes. I rebooted with no quirks and:

1. Well, actually now it seems the earphones work at boot even without quirks or model settings. My fault. I had set those with kernel 4.3.3 and didn't remove the file with newer kernels. So this seems to be fixed on boot - not sure how that happened because it was very annoying. 
*However* it is still an issue if I suspend the laptop, after resuming the squeaky sound is back again.

2. The left speaker isn't working but never worked for me on Linux. I do not have windows anymore because I removed it very quickly *but* I had tried it under windows a few months ago before formatting and at the time it worked. I confirm it never worked under Linux though. 
It seems its volume setting is very low on boot but nothing seems to change if I increase it with alsamixer. No sound output.

3. Yes I have an external bass speaker which seems to be connected to 0x1a. I had made it work but I do not have it at hand now and will check again later. I quite positive I could make it work again via either hdajackretask or hda_analyzer, since I did in the past.
Comment 4 Elias 2016-04-15 14:43:07 UTC
Created attachment 212941 [details]
alsa_info.sh output on N551VW (no quirks)
Comment 5 Takashi Iwai 2016-04-15 14:48:58 UTC
(In reply to eliascarotti from comment #3)
> Yes. I rebooted with no quirks and:
> 
> 1. Well, actually now it seems the earphones work at boot even without
> quirks or model settings. My fault. I had set those with kernel 4.3.3 and
> didn't remove the file with newer kernels. So this seems to be fixed on boot
> - not sure how that happened because it was very annoying. 
> *However* it is still an issue if I suspend the laptop, after resuming the
> squeaky sound is back again.

OK, and the headphone issue doesn't appear even after resume when you apply alc_fixup_auto_mute_via_amp, I suppose?
 
> 2. The left speaker isn't working but never worked for me on Linux. I do not
> have windows anymore because I removed it very quickly *but* I had tried it
> under windows a few months ago before formatting and at the time it worked.
> I confirm it never worked under Linux though. 
> It seems its volume setting is very low on boot but nothing seems to change
> if I increase it with alsamixer. No sound output.

Hm.  Then it's a bit hard to guess.  Usually such an issue is due to some vendor-specific verb (coef) or using multiple pins.  But, looking at other ASUS machines, neither seems applied.
 
> 3. Yes I have an external bass speaker which seems to be connected to 0x1a.
> I had made it work but I do not have it at hand now and will check again
> later. I quite positive I could make it work again via either hdajackretask
> or hda_analyzer, since I did in the past.

Good, then we can likely reuse ALC662_FIXUP_ASUS_Nx50.
Check the patch below.  This should cover 1 and 3.  Then continue tracking 2.
Comment 6 Takashi Iwai 2016-04-15 14:50:01 UTC
Created attachment 212951 [details]
Test fix patch
Comment 7 Raymond 2016-04-15 16:37:44 UTC
if you do not specify any model, headset won't work


although model dell-headset-multi support headphone, headset and mic but codec cannot  detect what you plug in
Comment 8 Elias 2016-04-15 21:30:53 UTC
Ok, I recompiled the kernel and tested the patch as you suggested. Here's what I found:

1) the subwoofer works straight out of the box. No pin setting nor any hda-verb is needed. It just works.

2) At first the squeaky sound was not present, *however* after suspending the laptop it came back and persisted even after power cycling the laptop. This is very strange since it seems to be some sort of persistent setting.  
As soon as the sound module was being loaded the squeaky sound started. 

After resuming, when the noisy sound (it's really like tinnitus - *very* annoying) appeared I ran again alsa_info, just in case it could help debug the problem. I can attach it again if you deem it useful.


Now I rebooted again with the dell-inv-headset and the squeaky sound isn't there, the headset works *but* the subwoofer doesn't (I think this is somewhat to be expected though).
I haven't tried yet but I guess if I reboot again, without the dell-inv-headset setting the "squeaky sound" won't be there, until I suspend again the laptop.


Not sure if it helps, but I used to get rid of that noise with the following verbs:

set(0x15, 0x701,   0x00) # 0x15070100 (SET_CONNECT_SEL)
set(0x15, 0x701,   0x01) # 0x15070100 (SET_CONNECT_SEL)
set(0x15, 0x707,   0x80) # 0x15070780 (SET_PIN_WIDGET_CONTROL)

but that also resulted in poorer quality sound (less basses) from my headset.



3) the left speaker ìs still not working, no matter what setting I try.
Comment 9 Raymond 2016-04-16 01:08:13 UTC
http://voices.canonical.com/david.henningsson/2014/03/07/headset-jacks-on-newer-laptops/

https://git.kernel.org/cgit/linux/kernel/git/tiwai/sound.git/commit/sound/pci/hda?id=73bdd597823e2231dc882577dbbaf8df92fe1775


using asus-mode8 and early patching to fix headset mic and headphone won't work since it need alc_fixup_headset_mode_alc668
Comment 10 Raymond 2016-04-16 01:13:31 UTC
do the user manual mention that the combo jack support headphone , headset or mic ?
Comment 11 Elias 2016-04-16 07:56:50 UTC
Yes, that is clearly stated in the user manual:

"Headphone/Headset/Microphone jack
This port allows you to connect amplified speakers or
headphones. You can also use this port to connect your headset
or an external microphone."
Comment 12 Raymond 2016-04-16 08:50:34 UTC
the drawback of dell-multi-headset is you need to manually switch capture source to determine the type is headphone, headset or mic 

control.11 {
		iface MIXER
		name 'Capture Source'
		value 'Internal Mic'
		comment {
			access 'read write'
			type ENUMERATED
			count 1
			item.0 'Headphone Mic'
			item.1 'Headset Mic'
			item.2 'Internal Mic'
		}
	}

some user with headset prefer auto mic selection by give up the support of headphone and mic

http://mailman.alsa-project.org/pipermail/alsa-devel/2015-September/097754.html

http://mailman.alsa-project.org/pipermail/alsa-devel/2015-September/097755.html
Comment 13 Elias 2016-04-16 08:54:48 UTC
I see. To be honest I would be more interested in having the left speaker working and getting rid of the "squeaky sound" once for all, which is why I tried that model setting in the first place. 
I need to check if the microphone on the headset works (the microphone on the lid does work).
Comment 14 Raymond 2016-04-16 11:58:54 UTC
what do you mean when you say subwoofer work since the other user mention that subwoofer use only one channel instead of both ?

do your external subwoofer use both left and right channel ?
Comment 15 Raymond 2016-04-16 16:17:23 UTC
although you disanle auto mute mode , it is pulseaudio base on Headphone Jack state to switch off your speaker

Simple mixer control 'Speaker',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 87
  Mono:
  Front Left: Playback 0 [0%] [-65.25dB] [off]
  Front Right: Playback 0 [0%] [-65.25dB] [off]


control.6 {
		iface MIXER
		name 'Auto-Mute Mode'
		value Disabled
		comment {
			access 'read write'
			type ENUMERATED
			count 1
			item.0 Disabled
			item.1 Enabled
		}
	}
	control.12 {
		iface CARD
		name 'Headphone Jack'
		value true
		comment {
			access read
			type BOOLEAN
			count 1
		}
	}
Comment 16 Elias 2016-04-16 20:45:35 UTC
(In reply to Raymond from comment #14)
> what do you mean when you say subwoofer work since the other user mention
> that subwoofer use only one channel instead of both ?
> 
> do your external subwoofer use both left and right channel ?

Ok, you were right, the subwoofer seems to be using only the right channel. If I completely shut off the left channel of the subwoofer with alsamixer nothing changes, while if I turn down the right channel the volume goes down accordingly.
Comment 17 Elias 2016-04-16 20:50:15 UTC
(In reply to Raymond from comment #15)
> although you disanle auto mute mode , it is pulseaudio base on Headphone
> Jack state to switch off your speaker
> 
> Simple mixer control 'Speaker',0
>   Capabilities: pvolume pswitch
>   Playback channels: Front Left - Front Right
>   Limits: Playback 0 - 87
>   Mono:
>   Front Left: Playback 0 [0%] [-65.25dB] [off]
>   Front Right: Playback 0 [0%] [-65.25dB] [off]
> 
> 
> control.6 {
>               iface MIXER
>               name 'Auto-Mute Mode'
>               value Disabled
>               comment {
>                       access 'read write'
>                       type ENUMERATED
>                       count 1
>                       item.0 Disabled
>                       item.1 Enabled
>               }
>       }
>       control.12 {
>               iface CARD
>               name 'Headphone Jack'
>               value true
>               comment {
>                       access read
>                       type BOOLEAN
>                       count 1
>               }
>       }

I am not sure I fully understand what you mean here. 


Moreover, I do not seem to have a control for the headset mic despite not setting a model, not even dell-headset-multi....
Comment 18 Raymond 2016-04-17 08:16:32 UTC
https://git.kernel.org/cgit/linux/kernel/git/tiwai/sound.git/commit/sound/pci/hda?id=ee81abb623cb5e03c182d16871bb4fb34fdc9b4f

+const struct snd_pcm_chmap_elem snd_pcm_2_1_chmaps[] = {
+	{ .channels = 2,
+	  .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR } },
+	{ .channels = 4,
+	  .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR,
+		   SNDRV_CHMAP_LFE, SNDRV_CHMAP_LFE } },
+	{ }
+};

the default 2.1 channel require pulseaudio/application mix left and right and add LFE channel to the remain two channels
Comment 19 Raymond 2016-04-17 10:59:38 UTC
how do you test ?

https://git.kernel.org/cgit/linux/kernel/git/tiwai/sound.git/tree/sound/pci/hda/hda_codec.c#n3785

if you play stereo, the driver just copy front channel to subwoofer


/* front */
	snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
				   0, format);
	if (!mout->no_share_stream &&
	    mout->hp_nid && mout->hp_nid != nids[HDA_FRONT])
		/* headphone out will just decode front left/right (stereo) */
		snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
					   0, format);
	/* extra outputs copied from front */
	for (i = 0; i < ARRAY_SIZE(mout->hp_out_nid); i++)
		if (!mout->no_share_stream && mout->hp_out_nid[i])
			snd_hda_codec_setup_stream(codec,
						   mout->hp_out_nid[i],
						   stream_tag, 0, format);

	/* surrounds */
	for (i = 1; i < mout->num_dacs; i++) {
		if (chs >= (i + 1) * 2) /* independent out */
			snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
						   i * 2, format);
		else if (!mout->no_share_stream) /* copy front */
			snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
						   0, format);
	}
Comment 20 Elias 2016-04-17 12:22:42 UTC
To be honest I'm beginning to feel a bit confused as I don't fully understand what's going on here.

To date:
1) the only effective means to remove the noisy sound seems to set model=dell-headset-multi. I could also use hda-verbs on 0x15 but that results in poorer quality sound

2) once the noisy sound is off, I can reboot the laptop even without the model setting and the squeaky sound stays off. I though this might be related to alsa state but things do not change irrespective of the alsa state. 

3) If I suspend to ram and resume the laptop, the squeaky sound comes back. 

4) I quickly browsed the source code and it seems to me that dell-headset-multi only sets two pins 0x19 and 0x1A. However if I set those pins through early patching they do not seem to affect the squeaky sound. Again, the only way to get rid of it seems to be 1). I am probably missing something here...

5) plugging in the subwoofer *does* affect the squeaky sound in the earphones by adding a subtle lower frequency component (the higher frequency component seems to be unaffected though). If I plug out the subwoofer only the higher frequency tone remains.

6) I only see the integrated microphone but from what you wrote before this seems to be somewhat expected.
Comment 21 Raymond 2016-04-17 12:50:39 UTC
https://git.kernel.org/cgit/linux/kernel/git/tiwai/sound.git/commit/sound/pci/hda?id=cd262518a3ae4465e8e51c29641d98c4ed0651a1


the difference are those processing coefficients written by alc_fixup_headset_mode_alc668 and you can dump those coefficient
Comment 22 Raymond 2016-04-17 12:52:14 UTC
Node 0x20 [Vendor Defined Widget] wcaps 0xf00040: Mono
  Processing caps: benign=0, ncoeff=197
Comment 23 Elias 2016-04-17 12:59:03 UTC
Oh, no, I was wrong. dell-headset-multi sets pins 0x19 and 0x1b, not 0x1a, in any case this seems to have nothing to do with the squeaky sound so I still confirm the above.

However, I checked again patch_realtek.c and saw that dell-headset-multi does something else besides setting those two pins. Since I do not know if I needed to set those two pins anyways I tried adding

        [ALC668_FIXUP_HEADSET_MODE_ASUS_N551] = {
                .type = HDA_FIXUP_FUNC,
                .v.func = alc_fixup_headset_mode_alc668,
                .chained = true,
                .chain_id = ALC662_FIXUP_ASUS_Nx50,
        },

and, of course:
        SND_PCI_QUIRK(0x1043, 0x158f, "Asus N551VW", ALC668_FIXUP_HEADSET_MODE_ASUS_N551),


and this effectively removes the squeaky noise (which, however, comes back upon suspending and then resuming - but in this case rebooting fixes it with no early patching nor model setting).

Since I do not have full understanding of all the driver code (which I haven't read) or the inner workings of the audio hardware I do not know if that's a proper fix. I am just posting it here in case it helps you have some more insight.
Comment 24 Elias 2016-04-17 12:59:43 UTC
Oh, ok, it seems you preceded me.
Comment 25 Raymond 2016-04-17 13:09:43 UTC
+	case 0x10ec0668:
+		alc_write_coef_idx(codec, 0x11, 0x0001);
+		alc_write_coef_idx(codec, 0xb7, 0x802b);
+		alc_write_coef_idx(codec, 0x15, 0x0d60);
+		alc_write_coef_idx(codec, 0xc3, 0x0c00);
+		msleep(300);
+		val = alc_read_coef_idx(codec, 0xbe);
+		is_ctia = (val & 0x1c02) == 0x1c02;
+		break;
+	}
+
+	snd_printdd("Headset jack detected iPhone-style headset: %s\n",
+		    is_ctia ? "yes" : "no");

are you using CTIA or OMTP headset or headphone ?

did the codec detect correctly ?
Comment 26 Raymond 2016-04-18 13:01:09 UTC
hdajacksensetest -a 

can the jack sense of subwoofer work ?


+	[ALC668_FIXUP_ASUS_N551VW] = {
+		.type = HDA_FIXUP_PINS,
+		.v.pins = (const struct hda_pintbl[]) {
+			{ 0x19, 0x03a1913d }, /* use as headphone mic, without its own jack detect */
+                       { 0x1a, 0x04110011 }, /* external subwoofer */
+			{ 0x1b, 0x03a1113c }, /* use as headset mic, without its own jack detect */
+			{ }
+		},
+		.chained = true,
+		.chain_id = ALC668_FIXUP_HEADSET_MODE
+	},
Comment 27 Elias 2016-04-18 17:23:33 UTC
Yes, it does work:

Pin 0x12 (Internal Mic): present = No
Pin 0x14 (Internal Speaker): present = No
Pin 0x15 (Black Headphone, Right side): present = Yes
Pin 0x16 (Not connected): present = No
Pin 0x18 (Not connected): present = No
Pin 0x19 (Not connected): present = No
Pin 0x1a (Not connected): present = Yes
Pin 0x1b (Not connected): present = No
Pin 0x1d (Not connected): present = No
Pin 0x1e (Not connected): present = No
Pin 0x1f (Not connected): present = No

0x1a is the subwoofer and 0x15 the headphone.
Comment 28 Raymond 2016-04-19 02:32:30 UTC
http://bazaar.launchpad.net/~unity-settings-daemon-team/unity-settings-daemon/trunk/view/head:/plugins/media-keys/what-did-you-plug-in/pa-backend.c

 Headphone Mic Jack - indicates headphone and mic-in mode share the same jack,
     i e, not two separate jacks. Hardware cannot distinguish between a
     headphone and a mic.
   Headset Mic Phantom Jack - indicates headset jack where hardware can not
     distinguish between headphones and headsets
   Headset Mic Jack - indicates headset jack where hardware can distinguish
     between headphones and headsets. There is no use popping up a dialog in
     this case, unless we already need to do this for the mic-in mode.


for alc668 dell-headset-multi, codec assume the jack is headphone by default and change the type according to mux pin

        hda_nid_t mux_pin = spec->gen.imux_pins[spec->gen.cur_mux[0]];
+	hda_nid_t hp_pin = spec->gen.autocfg.hp_pins[0];
+
+	int new_headset_mode;
+
+	if (!snd_hda_jack_detect(codec, hp_pin))
+		new_headset_mode = ALC_HEADSET_MODE_UNPLUGGED;
+	else if (mux_pin == spec->headset_mic_pin)
+		new_headset_mode = ALC_HEADSET_MODE_HEADSET;
+	else if (mux_pin == spec->headphone_mic_pin)
+		new_headset_mode = ALC_HEADSET_MODE_MIC;
+	else
+		new_headset_mode = ALC_HEADSET_MODE_HEADPHONE;


	if (new_headset_mode == spec->current_headset_mode)
+		return;
+
+	switch (new_headset_mode) {
+	case ALC_HEADSET_MODE_UNPLUGGED:
+		alc_headset_mode_unplugged(codec);
+		spec->gen.hp_jack_present = false;
+		break;
+	case ALC_HEADSET_MODE_HEADSET:
+		if (spec->current_headset_type == ALC_HEADSET_TYPE_UNKNOWN)
+			alc_determine_headset_type(codec);
+		if (spec->current_headset_type == ALC_HEADSET_TYPE_CTIA)
+			alc_headset_mode_ctia(codec);
+		else if (spec->current_headset_type == ALC_HEADSET_TYPE_OMTP)
+			alc_headset_mode_omtp(codec);
+		spec->gen.hp_jack_present = true;
+		break;
+	case ALC_HEADSET_MODE_MIC:
+		alc_headset_mode_mic_in(codec, hp_pin, spec->headphone_mic_pin);
+		spec->gen.hp_jack_present = false;
+		break;
+	case ALC_HEADSET_MODE_HEADPHONE:
+		alc_headset_mode_default(codec);
+		spec->gen.hp_jack_present = true;
+		break;
+	}
+	if (new_headset_mode != ALC_HEADSET_MODE_MIC) {
+		snd_hda_set_pin_ctl_cache(codec, hp_pin,
+					  AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
+		if (spec->headphone_mic_pin)
+			snd_hda_set_pin_ctl_cache(codec, spec->headphone_mic_pin,
+						  PIN_VREFHIZ);
+	}
+	spec->current_headset_mode = new_headset_mode;
+
+	snd_hda_gen_update_outputs(codec);
+}
Comment 29 Elias 2016-04-28 17:36:25 UTC
It seems it doesn't properly restore the settings after suspend. In fact there is some fairly loud white noise in the headphones, and, sometime, even the squeaky sound...
Comment 30 Raymond 2016-04-28 23:10:02 UTC
https://cgit.freedesktop.org/pulseaudio/pulseaudio/commit/?id=f3ebf6b667b155f5fe6526bd70881c79e07d7874

You need software low pass filter if you still hear high frequency from subwoofer

How do you test ?

Pulseaudio use high pass filter for speaker,


Do the audio output of subwoofer still has different channel tag after resume?
Comment 31 Elias 2016-05-01 23:27:08 UTC
No, no, I didn't mean high frequency from the subwoofer (which I still need to check).

I really meant the earphones. After boot, with the above patch, the earphones work well, with almost no noise and a pleasant sound.
If I suspend and resume the laptop, *then* the squeaky sound is back on the earphones *and* some white noise. The only way to get rid of that sound is then to either reboot the laptop or play around with hda-verb.

So it seems that the soundcard state isn't restored properly on resume or something like that.
Comment 32 Raymond 2016-05-02 07:39:04 UTC
you have to post output of alsa-io.sh including coeff dump before suspend and after resume

take a diff of the working and non-working alsa-info
Comment 33 Elias 2016-05-03 17:31:18 UTC
The only difference seems to be this:

diff n551vw_boot n551vw_restart 
6c6
< !!Script ran on: Tue May  3 16:33:52 UTC 2016
---
> !!Script ran on: Tue May  3 17:28:56 UTC 2016
181c181
<   Converter: stream=1, channel=0
---
>   Converter: stream=0, channel=0
1319a1320
> cmac


Headphones were plugged in both cases, yet in the first case everything was fine, while in the second case (after suspending to ram and restarting), the annoying sound was back and loud....
Comment 34 Elias 2016-05-03 17:58:59 UTC
Created attachment 215231 [details]
At boot, with  dump of coefficients
Comment 35 Elias 2016-05-03 17:59:34 UTC
Created attachment 215241 [details]
After resuming, with dump of coefficients
Comment 36 Elias 2016-05-03 18:01:50 UTC
Sorry, the previous diff was wrong.
This is from the attached files:

6c6
< !!Script ran on: Tue May  3 17:54:38 UTC 2016
---
> !!Script ran on: Tue May  3 17:55:26 UTC 2016
140c140
<   Converter: stream=1, channel=0
---
>   Converter: stream=0, channel=0
152c152
<   Converter: stream=1, channel=0
---
>   Converter: stream=0, channel=0
164c164
<   Converter: stream=1, channel=0
---
>   Converter: stream=0, channel=0
187c187
<   Converter: stream=1, channel=0
---
>   Converter: stream=0, channel=0
1325a1326
> cmac
Comment 37 Raymond 2016-05-04 07:32:41 UTC
Node 0x03 [Audio Output] wcaps 0x41d: Stereo Amp-Out
  Control: name="Bass Speaker Playback Volume", index=0, device=0
    ControlAmp: chs=3, dir=Out, idx=0, ofs=0
  Amp-Out caps: ofs=0x57, nsteps=0x57, stepsize=0x02, mute=0
  Amp-Out vals:  [0x00 0x00]
  Converter: stream=1, channel=0

channel should be 2 if you are using  surround 21 profile


do you mean pulseaudio switch from 2.1 to stereo after headphone is plugged

your alsa info are strange since playback device are not open but stream tag is non zero



APLAY

**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC668 Analog [ALC668 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
Comment 38 Raymond 2016-05-04 07:39:45 UTC
 Converter: stream=1, channel=0 for audio output of speaker . bass speaker and headphone mean stereo is copy to both speaker, bass speaker and headphone

but your subwoofer only pick the right channel


you need pulseaudio mix left and right and a low pass filter
Comment 39 Raymond 2016-05-04 07:44:38 UTC
+	{ .channels = 4,
+	  .map = { SNDRV_CHMAP_FL, SNDRV_CHMAP_FR,
+		   SNDRV_CHMAP_LFE, SNDRV_CHMAP_LFE } },
+	{ }

the driver expect to receive LFE in the last two channels
Comment 40 Elias 2016-05-04 08:12:36 UTC
(In reply to Raymond from comment #37)
> Node 0x03 [Audio Output] wcaps 0x41d: Stereo Amp-Out
>   Control: name="Bass Speaker Playback Volume", index=0, device=0
>     ControlAmp: chs=3, dir=Out, idx=0, ofs=0
>   Amp-Out caps: ofs=0x57, nsteps=0x57, stepsize=0x02, mute=0
>   Amp-Out vals:  [0x00 0x00]
>   Converter: stream=1, channel=0
> 
> channel should be 2 if you are using  surround 21 profile
> 
> 
> do you mean pulseaudio switch from 2.1 to stereo after headphone is plugged
> 
> your alsa info are strange since playback device are not open but stream tag
> is non zero
> 
> 
> 
> APLAY
> 
> **** List of PLAYBACK Hardware Devices ****
> card 0: PCH [HDA Intel PCH], device 0: ALC668 Analog [ALC668 Analog]
>   Subdevices: 1/1
>   Subdevice #0: subdevice #0

I am not sure I do understand what you mean here. I was just testing the headphones which were plugged in both for the first alsa-info and for the second. However, after resuming (when I collected the second alsa-info.sh output) the squeaky annoying sound in the *headphones* was back....
Comment 41 Raymond 2016-05-04 08:32:58 UTC
the headphone was plugged

control.20 {
		iface CARD
		name 'Headphone Mic Jack'
		value true
		comment {
			access read
			type BOOLEAN
			count 1
		}
	}

automute was disabled

control.12 {
		iface MIXER
		name 'Auto-Mute Mode'
		value Disabled
		comment {
			access 'read write'
			type ENUMERATED
			count 1
			item.0 Disabled
			item.1 Enabled
		}
	}


you need pulseaudio to use headphone mic jack to mute the speaker and bass speaker using playback switch



control.2 {
		iface MIXER
		name 'Speaker Playback Switch'
		value.0 false
		value.1 false
		comment {
			access 'read write'
			type BOOLEAN
			count 2
		}
	}
	
	control.4 {
		iface MIXER
		name 'Bass Speaker Playback Switch'
		value.0 false
		value.1 false
		comment {
			access 'read write'
			type BOOLEAN
			count 2
		}
	}




control.7 {
		iface MIXER
		name 'Loopback Mixing'
		value Enabled
		comment {
			access 'read write'
			type ENUMERATED
			count 1
			item.0 Disabled
			item.1 Enabled
		}
	}

there is still no coeff dump 

Node 0x20 [Vendor Defined Widget] wcaps 0xf00040: Mono
  Processing caps: benign=0, ncoeff=197
Comment 42 Raymond 2016-05-04 08:43:08 UTC
when playback device is open, the number of available subdevice is zero instead of one


APLAY

**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC668 Analog [ALC668 Analog]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
Comment 43 Elias 2016-05-04 09:00:37 UTC
Sorry you're right. Here is the correct diff:

6c6
< !!Script ran on: Wed May  4 08:57:45 UTC 2016
---
> !!Script ran on: Wed May  4 08:58:39 UTC 2016
140c140
<   Converter: stream=1, channel=0
---
>   Converter: stream=0, channel=0
152c152
<   Converter: stream=1, channel=0
---
>   Converter: stream=0, channel=0
164c164
<   Converter: stream=1, channel=0
---
>   Converter: stream=0, channel=0
187c187
<   Converter: stream=1, channel=0
---
>   Converter: stream=0, channel=0
453c453
<     Coeff 0x11: 0x0001
---
>     Coeff 0x11: 0x0041
626c626
<     Coeff 0xbe: 0x0002
---
>     Coeff 0xbe: 0x0802
630c630
<     Coeff 0xc2: 0x0000
---
>     Coeff 0xc2: 0x5000
632c632
<     Coeff 0xc4: 0x8000
---
>     Coeff 0xc4: 0x0000
1522a1523
> cmac
Comment 44 Elias 2016-05-04 09:01:51 UTC
Created attachment 215271 [details]
At boot, with  dump of coefficients
Comment 45 Elias 2016-05-04 09:02:14 UTC
Created attachment 215281 [details]
After resuming, with dump of coefficients
Comment 46 Raymond 2016-05-04 16:25:48 UTC
(In reply to Elias from comment #43)
> Sorry you're right. Here is the correct diff:
> 

> 453c453
> <     Coeff 0x11: 0x0001
> ---
> >     Coeff 0x11: 0x0041


this mean combo jack change from headphone default mode to mic in




+static void alc_headset_mode_mic_in(struct hda_codec *codec, hda_nid_t hp_pin,
+				    hda_nid_t mic_pin)
+{
+	int val;
+
+	switch (codec->vendor_id) {

+	case 0x10ec0668:
+		alc_write_coef_idx(codec, 0x11, 0x0001);
+		snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
+		alc_write_coef_idx(codec, 0xb7, 0x802b);
+		alc_write_coef_idx(codec, 0xb5, 0x1040);
+		val = alc_read_coef_idx(codec, 0xc3);
+		alc_write_coef_idx(codec, 0xc3, val | 1<<12);
+		snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50);
+		break;
+	}
+	snd_printdd("Headset jack set to mic-in mode.\n");
+}
+
+static void alc_headset_mode_default(struct hda_codec *codec)
+{
+	switch (codec->vendor_id) {

+	case 0x10ec0668:
+		alc_write_coef_idx(codec, 0x11, 0x0041);
+		alc_write_coef_idx(codec, 0x15, 0x0d40);
+		alc_write_coef_idx(codec, 0xb7, 0x802b);
+		break;
+	}
+	snd_printdd("Headset jack set to headphone (default) mode.\n");
+}
+
Comment 47 Raymond 2016-05-04 16:51:17 UTC
https://cgit.freedesktop.org/pulseaudio/pulseaudio/tree/src/modules/alsa/mixer/paths/analog-input-headphone-mic.conf

[Jack Headphone Mic]
required-any = any
state.plugged = unknown

[Option Capture Source:Headphone Mic]
name = analog-input-microphone
required-any = any



https://cgit.freedesktop.org/pulseaudio/pulseaudio/tree/src/modules/alsa/mixer/paths/analog-input-headset-mic.conf


[Option Capture Source:Headset Mic]
name = Headset Microphone
required-any = any

https://cgit.freedesktop.org/pulseaudio/pulseaudio/tree/src/modules/alsa/mixer/paths/analog-input-internal-mic.conf

[Option Capture Source:Internal Mic]
name = analog-input-microphone-internal
required-any = any
Comment 48 Raymond 2016-05-05 01:44:35 UTC
(In reply to Elias from comment #43)

> <     Coeff 0xbe: 0x0002
> ---
> >     Coeff 0xbe: 0x0802
> 630c630


static void alc_determine_headset_type(struct hda_codec *codec)
{

case 0x10ec0668:
		alc_process_coef_fw(codec, coef0688);
		msleep(300);
		val = alc_read_coef_idx(codec, 0xbe);
		is_ctia = (val & 0x1c02) == 0x1c02;
		break;



> <     Coeff 0xc2: 0x0000
> ---
> >     Coeff 0xc2: 0x5000
> 632c632
> <     Coeff 0xc4: 0x8000
> ---
> >     Coeff 0xc4: 0x0000
> 1522a1523



static void alc_fixup_headset_mode_alc668(struct hda_codec *codec,
				const struct hda_fixup *fix, int action)
{
	if (action == HDA_FIXUP_ACT_PRE_PROBE) {
		alc_write_coef_idx(codec, 0xc4, 0x8000);
		alc_update_coef_idx(codec, 0xc2, ~0xfe, 0);
		snd_hda_set_pin_ctl_cache(codec, 0x18, 0);
	}
	alc_fixup_headset_mode(codec, fix, action);
}
Comment 49 Raymond 2016-05-05 02:05:28 UTC
https://cgit.freedesktop.org/pulseaudio/pulseaudio/tree/src/modules/alsa/mixer/paths/analog-output-speaker.conf

https://cgit.freedesktop.org/pulseaudio/pulseaudio/tree/src/modules/alsa/mixer/paths/analog-output-headphones.conf


as there is no headphone jack for model dell-headset-multi and headphone mic jack cannot determine the combo jack type

control.20 {
		iface CARD
		name 'Headphone Mic Jack'
		value true
		comment {
			access read
			type BOOLEAN
			count 1
		}
	}

this only mean some jack is plugged into combo jack

pulseaudio need to use the capture source to find out whether it is a headphone, headset or mic jack
Comment 50 Raymond 2016-05-05 02:19:41 UTC
the logic assume the pin ctl of headphone or headphone mic is zero, it cannot be OUT HP and IN at the same time


Node 0x15 [Pin Complex] wcaps 0x40058d: Stereo Amp-Out
  Control: name="Headphone Playback Switch", index=0, device=0
    ControlAmp: chs=3, dir=Out, idx=0, ofs=0
  Amp-Out caps: ofs=0x00, nsteps=0x00, stepsize=0x00, mute=1
  Amp-Out vals:  [0x80 0x80]
  Pincap 0x0001001c: OUT HP EAPD Detect
  EAPD 0x2: EAPD
  Pin Default 0x04211020: [Jack] HP Out at Ext Right
    Conn = 1/8, Color = Black
    DefAssociation = 0x2, Sequence = 0x0
  Pin-ctls: 0xc0: OUT HP
  Unsolicited: tag=01, enabled=1
  Power states:  D0 D1 D2 D3 EPSS
  Power: setting=D0, actual=D0
  Connection: 3
     0x0c 0x0d 0x0e*

Node 0x19 [Pin Complex] wcaps 0x40058f: Stereo Amp-In Amp-Out
  Control: name="Headphone Mic Boost Volume", index=0, device=0
    ControlAmp: chs=3, dir=In, idx=0, ofs=0
  Amp-In caps: ofs=0x00, nsteps=0x03, stepsize=0x27, mute=0
  Amp-In vals:  [0x00 0x00]
  Amp-Out caps: ofs=0x00, nsteps=0x00, stepsize=0x00, mute=1
  Amp-Out vals:  [0x80 0x80]
  Pincap 0x0000373c: IN OUT HP Detect
    Vref caps: HIZ 50 GRD 80 100
  Pin Default 0x411111f0: [N/A] Speaker at Ext Rear
    Conn = 1/8, Color = Black
    DefAssociation = 0xf, Sequence = 0x0
    Misc = NO_PRESENCE
  Pin-ctls: 0x20: IN VREF_HIZ
  Unsolicited: tag=00, enabled=0
  Power states:  D0 D1 D2 D3 EPSS
  Power: setting=D0, actual=D0
  Connection: 3
     0x0c* 0x0d 0x0e
Comment 51 Elias 2016-05-05 10:26:54 UTC
This is more or less what I found in the source code. Should I do something with it or is this just an example of what's going on?


(In reply to Raymond from comment #46)
> (In reply to Elias from comment #43)
> > Sorry you're right. Here is the correct diff:
> > 
> 
> > 453c453
> > <     Coeff 0x11: 0x0001
> > ---
> > >     Coeff 0x11: 0x0041
> 
> 
> this mean combo jack change from headphone default mode to mic in
> 
> 
> 
> 
> +static void alc_headset_mode_mic_in(struct hda_codec *codec, hda_nid_t
> hp_pin,
> +                                 hda_nid_t mic_pin)
> +{
> +     int val;
> +
> +     switch (codec->vendor_id) {
> 
> +     case 0x10ec0668:
> +             alc_write_coef_idx(codec, 0x11, 0x0001);
> +             snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
> +             alc_write_coef_idx(codec, 0xb7, 0x802b);
> +             alc_write_coef_idx(codec, 0xb5, 0x1040);
> +             val = alc_read_coef_idx(codec, 0xc3);
> +             alc_write_coef_idx(codec, 0xc3, val | 1<<12);
> +             snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50);
> +             break;
> +     }
> +     snd_printdd("Headset jack set to mic-in mode.\n");
> +}
> +
> +static void alc_headset_mode_default(struct hda_codec *codec)
> +{
> +     switch (codec->vendor_id) {
> 
> +     case 0x10ec0668:
> +             alc_write_coef_idx(codec, 0x11, 0x0041);
> +             alc_write_coef_idx(codec, 0x15, 0x0d40);
> +             alc_write_coef_idx(codec, 0xb7, 0x802b);
> +             break;
> +     }
> +     snd_printdd("Headset jack set to headphone (default) mode.\n");
> +}
> +
Comment 52 Raymond 2016-05-05 15:47:06 UTC
you have to ask Kailang Yang any hint for the noise ?

do the codec need to disable headphone mic pin ctl when unplugged ?

static void alc_headset_mode_unplugged(struct hda_codec *codec)
{
	int val;

	switch (codec->vendor_id) {
	
	case 0x10ec0668:
		alc_write_coef_idx(codec, 0x15, 0x0d40);
		alc_write_coef_idx(codec, 0xb7, 0x802b);
		break;
	}
	snd_printdd("Headset jack set to unplugged mode.\n");
}
Comment 53 Raymond 2016-05-05 15:56:05 UTC
do the noise still exist if you do not fix the headphone mic pin ? (i.e. only fix headset mic pin )
Comment 54 Elias 2016-05-06 10:15:40 UTC
(In reply to Raymond from comment #53)
> do the noise still exist if you do not fix the headphone mic pin ? (i.e.
> only fix headset mic pin )

How do I do that? 
The only way to get rid of the noise for me is to mess with pin 0x15 on hda_analyzer. More specifically if I disable OUT the noise goes away but so do the basses... Or at least, sound seems to be poorer. However I can't play with the vendor pins on hda_analyzer and I have no clue on setting them anyways...
Comment 55 Raymond 2016-05-06 15:01:37 UTC
(In reply to Elias from comment #35)
> Created attachment 215241 [details]
> After resuming, with dump of coefficients

   16.009587] snd_hda_codec_realtek: module_layout: kernel tainted.
[   16.009589] snd_hda_codec_realtek: module_layout: kernel tainted.
[   16.009589] Disabling lock debugging due to kernel taint
Comment 56 Raymond 2016-05-06 23:48:03 UTC
when combo jack switch to mic in , 

		snd_hda_set_pin_ctl_cache(codec, hp_pin, 0);
	        snd_hda_set_pin_ctl_cache(codec, mic_pin, PIN_VREF50);


this mean that when combo jack switch from mic in to headset or headphone.  need to revert the above change


if you don't applu headphone mic pin fixup


+		.v.pins = (const struct hda_pintbl[]) {
+			{ 0x19, 0x03a1913d }, /* use as headphone mic, without its own jack detect */



only fixup headset and subwoofer it won't change to mic in


+                       { 0x1a, 0x04110011 }, /* external subwoofer */
+			{ 0x1b, 0x03a1113c }, /* use as headset mic, without its own jack detect */
Comment 57 Raymond 2016-05-07 08:13:30 UTC
the revert is supposed to be perform by these codec

+	if (new_headset_mode != ALC_HEADSET_MODE_MIC) {
+		snd_hda_set_pin_ctl_cache(codec, hp_pin,
+					  AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
+		if (spec->headphone_mic_pin)
+			snd_hda_set_pin_ctl_cache(codec, spec->headphone_mic_pin,
+						  PIN_VREFHIZ);
+	}
Comment 58 Raymond 2016-05-07 15:35:14 UTC
wbat you need to ask is why 0x18 js used in   alc_fixup_headset_mode_alc668() since node 0x18 is not headset mic, headphone mic 

		snd_hda_set_pin_ctl_cache(codec, 0x18, 0);
Comment 59 Elias 2017-01-17 09:00:01 UTC
I experimented a bit and it seems that simply adding:
        SND_PCI_QUIRK(0x1043, 0x158f, "Asus N551VW", ALC668_FIXUP_HEADSET_MODE),
just like the Asus UX501VW does the trick: sound works properly and the noise is gone.
However if I suspend and resume settings seem not to be restored properly since the  noise is back until a power cycle or a reboot.
Comment 60 Elias 2017-01-25 10:54:15 UTC
Ok, it seems that something like this

        [ALC668_FIXUP_HEADSET_MODE_ASUS_Nx51] = {
                .type = HDA_FIXUP_PINS,
                .v.pins = (const struct hda_pintbl[]) {
                        {0x1a, 0x90170151}, /* bass speaker */
                        {}
                },
                .chained = true,
                .chain_id = ALC668_FIXUP_HEADSET_MODE,
        },

seems to make both the bass speaker work properly and removes the noise from the headset (I copied the setting for the bass speaker from ALC668_FIXUP_ASUS_Nx51, which applies to me as well and chained the HEADSET MODE fixup).
The other microphone on top of the display works properly.
Not sure what's going on because I found it through trial and error.
 
However, the microphone on the headset isn't working at all (it seems not to be detected) and if I suspend and resume the noise is back again, so the setting, whatever it is, it seems not to be retained.
Comment 61 Mikhail Paulyshka 2017-05-01 10:42:30 UTC
Looks like it should be fixed in 
https://bugzilla.kernel.org/show_bug.cgi?id=195437

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