Bug 64971

Summary: HDA Intel/AD1986A: regressions with Linux 3.12 on Lenovo 3000 N100
Product: Drivers Reporter: tfc.duke
Component: Sound(ALSA)Assignee: Jaroslav Kysela (perex)
Status: RESOLVED CODE_FIX    
Severity: normal CC: superquad.vortex2, tfc.duke, tiwai
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 3.12 Subsystem:
Regression: Yes Bisected commit-id:
Attachments: alsa-info output on Linux 3.12 (KO)
alsa-info output on Linux 3.11 (OK)
Patch #1
Patch #2
alsa-info output on Linux 3.13-rc1 (no headphones)
alsa-info output on Linux 3.13-rc1 (headphones)
alsa-info output on Linux 3.13-rc1 (no PulseAudio #1: no headphones)
alsa-info output on Linux 3.13-rc1 (no PulseAudio #2: headphones)
alsa-info output on Linux 3.13-rc1 (no PulseAudio #3: no headphones)
alsa-info output on Linux 3.13-rc1 (no PulseAudio #4: headphones)
alsa-info output on Linux 3.13-rc1 (no PulseAudio #5: broken after alsamixer)
alsa-info output on Linux 3.13-rc1 (no PulseAudio, asound.state removed, fresh boot)
Fix patch for 3.13-rc1
alsa-info output on Linux 3.13-rc2+patch (headphones)
alsa-info output on Linux 3.13-rc2+patch (no headphones)
Fix patch #1 on 3.13-rc3
Fix patch #2 on 3.13-rc3

Description tfc.duke 2013-11-14 17:27:18 UTC
Created attachment 114701 [details]
alsa-info output on Linux 3.12 (KO)

After switching from Linux 3.11 to 3.12, I encounter several sound regressions on Lenovo 3000 N100:

1) I can hear no sound from the speakers.

2) On the headphones, the output volume is low and when I increase it,
it quickly becomes saturated. It looks like it's no longer amplified. On
alsamixer, there is now an "Auto-Mute" control (boolean). When I enable
it, the saturation disappears but the volume is still quite low (much
more than with Linux <= 3.11).

I'm on Ubuntu 13.10. All was working fine with Linux 3.11. Those issues
have appeared since Linux 3.12-rc1.

I've seen there has been some changes around the AD1986A quirks for
Linux 3.12, maybe is it related?
Comment 1 tfc.duke 2013-11-14 17:28:08 UTC
Created attachment 114711 [details]
alsa-info output on Linux 3.11 (OK)
Comment 2 Takashi Iwai 2013-11-14 17:35:05 UTC
The EAPD seems controlling both outputs on this machine.  Try two patches attached below.  (These were already merged in the upstream tree for the upcoming 3.13-rc1 pull request.)

If this still doesn't work, please give alsa-info.sh outputs with the headphone plugged and unplugged.
Comment 3 Takashi Iwai 2013-11-14 17:35:32 UTC
Created attachment 114721 [details]
Patch #1
Comment 4 Takashi Iwai 2013-11-14 17:35:52 UTC
Created attachment 114731 [details]
Patch #2
Comment 5 tfc.duke 2013-11-23 11:17:40 UTC
I didn't tried the patches on 3.12 but directly tried the kernel 3.13-rc1 instead (since they should be included in this version). It was easier for me to wait for a .deb from Ubuntu, but if needed I'll take some time to rebuild the sound driver with patches for testing.

The situation is worse than before: there is no sound at all neither from speakers, nor headphones. I can just hear some background noise from headphones, and changing the volume doesn't seem to change the noise level.
Comment 6 tfc.duke 2013-11-23 11:18:21 UTC
Created attachment 115671 [details]
alsa-info output on Linux 3.13-rc1 (no headphones)
Comment 7 tfc.duke 2013-11-23 11:18:43 UTC
Created attachment 115681 [details]
alsa-info output on Linux 3.13-rc1 (headphones)
Comment 8 Takashi Iwai 2013-11-23 11:38:34 UTC
Hrm, interesting, someone must have muted the amp of the NID 0x1b, which is the speaker output, and toggled EAPD wrongly.  It doesn't happen with the emulator, so something really hardware-specific behavior.

Looking at the alsa-info.sh output, you're using PulseAudio.  Could you stop PA and try the raw playback via "aplay -Dplughw -vv foo.wav"?  At least, it makes debugging easier.

The next thing to test is to boot in runlevel 3, login there, and get the alsa-info.sh output.  (I assume that there is no pulseaudio daemon running at this point.)  This will be close to the bare state.

In alsa-info.sh output, check whether node 0x1b is muted (the amp 0x80 bit), and whether the EAPD value is 0x00 or 0x02.  The driver should have unmuted and clears EAPD.

If the node 0x1b is in a wrong state, we need a clean initialized driver state.  For that, unload snd-hda-intel module manually.  Then remove /var/lib/alsa/asound.state or /etc/asound.state file (depending on distro and version).  Then reboot the machine and again login in runlevel 3, and take alsa-info.sh.
At this time, the mixer should be uninitialized, that is, muted states as default, so you'd need to unmute and adjust Master volume manually.
Comment 9 tfc.duke 2013-11-23 14:24:04 UTC
Ok, without PulseAudio I can get some sound working, but correct amplification (I think), but there's still some issues.

1) First, I booted with PulseAudio disabled and no headphones. No sound from speakers (with the given aplay command).
2) Headphones plugged: I have sound from the right headphone only, on the left only background noise.
3) Headphones unplugged: I have sound from the speakers (right and left).
4) Headphones re-plugged: I have sound from both headphones and speakers. Still no sound from left headphone.
5) While playing some music with rhythmbox, I changed the PMC volume via alsamixer. As soon as I touched this parameter, sound disapeared and I could never get the sound back (until reboot). I don't know if this issue is related, though.

I'll attach an alsa-info.txt for each of those steps.

Then, I did unload snd-hda-intel and remove /var/lib/alsa/asound.state, rebooted (runlevel 3) without headphones, and took alsa-info.txt. But I experienced exactly the same behaviour than before (steps 1-5).

As soon as I started PulseAudio, I couldn't get any sound from speakers/headphones.
Comment 10 tfc.duke 2013-11-23 14:24:57 UTC
Created attachment 115691 [details]
alsa-info output on Linux 3.13-rc1 (no PulseAudio #1: no headphones)
Comment 11 tfc.duke 2013-11-23 14:25:18 UTC
Created attachment 115701 [details]
alsa-info output on Linux 3.13-rc1 (no PulseAudio #2: headphones)
Comment 12 tfc.duke 2013-11-23 14:25:46 UTC
Created attachment 115711 [details]
alsa-info output on Linux 3.13-rc1 (no PulseAudio #3: no headphones)
Comment 13 tfc.duke 2013-11-23 14:26:05 UTC
Created attachment 115721 [details]
alsa-info output on Linux 3.13-rc1 (no PulseAudio #4: headphones)
Comment 14 tfc.duke 2013-11-23 14:26:48 UTC
Created attachment 115731 [details]
alsa-info output on Linux 3.13-rc1 (no PulseAudio #5: broken after alsamixer)
Comment 15 tfc.duke 2013-11-23 14:27:42 UTC
Created attachment 115741 [details]
alsa-info output on Linux 3.13-rc1 (no PulseAudio, asound.state removed, fresh boot)
Comment 16 tfc.duke 2013-11-23 14:29:53 UTC
About step #5 where I broke sound with alsamixer, I just wanted to add that changing PCM volume with it while not running rhythmbox doesn't break anything.
Comment 17 tfc.duke 2013-11-23 14:32:04 UTC
For step #1, If I disable auto-mute before plugging headphones, I can get sound from speakers. But all other steps remain valid.
Comment 18 Raymond 2013-11-24 04:45:54 UTC
the headphone and speaker are connected to same DAC in previous version

-static const struct hda_verb ad1986a_init_verbs[] = {
- /* HP, Line-Out, Surround, CLFE selectors */
- {0x0a, AC_VERB_SET_CONNECT_SEL, 0x0},
- {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0},


https://git.kernel.org/cgit/linux/kernel/git/tiwai/sound.git/commit/?id=53eb1b85402f108d5151338cff4430f30fd9727f

[ALSA] hda-codec - Fix AD1986A Lenovo auto-mute
The jack detection bit on AD1986A Lenovo N100 seems inverse from the standard definition. Now fixed the detection properly.
Comment 19 Takashi Iwai 2013-11-25 10:03:17 UTC
My bad, the wrong EAPD was due to another patch in 3.13-rc1.  The two patches with 3.12 should have worked.

In anyway, try the patch below.  I guess AD1986A has a substantial problem with the pin control on/off, so we'd need to use the amp instead.
Comment 20 Takashi Iwai 2013-11-25 10:04:00 UTC
Created attachment 115871 [details]
Fix patch for 3.13-rc1
Comment 21 tfc.duke 2013-11-30 20:06:11 UTC
I tested the patch on 3.13-rc2, but it doesn't seem to change anything. I still have the same behaviour. I'll attach alsa-info outputs.

Also, I can hear sound from left headphone (I previously said than I could'nt hear anything from it) but at a volume level very low. It's possible that I did not hear it before because I hadn't adjusted master to 100%.
Comment 22 tfc.duke 2013-11-30 20:06:51 UTC
Created attachment 116911 [details]
alsa-info output on Linux 3.13-rc2+patch (headphones)
Comment 23 tfc.duke 2013-11-30 20:07:15 UTC
Created attachment 116921 [details]
alsa-info output on Linux 3.13-rc2+patch (no headphones)
Comment 24 Takashi Iwai 2013-12-02 13:46:22 UTC
In your alsa-info.sh output, "Speaker Playback Switch" is turned off.  Try to turn it on:
   amixer -c0 set Speaker unmute
Comment 25 tfc.duke 2013-12-02 18:48:18 UTC
I got the speakers working again. Nevertheless, there is still some issues:

1) The output volume is lower than in 3.11. In 3.13 I must set PCM volume to 100% to get something similar to what I have in 3.11 with a PCM volume of ~50%.

2) The left headphone volume is always very very low, whatever the volume I set. I also tried changing invidivually left/right volume.

3) When PulseAudio is running, I can hear no sound.
Comment 26 Takashi Iwai 2013-12-03 07:50:49 UTC
Thanks, at least, a little step forward now :)

About 1) it's because the old PCM volume provided the overloaded amp (+12dB) at 100%.  So, with 100%, you actually played in 150% volume without knowing.  So, the current behavior is actually a bug fix.

2 and 3 are real problems.  Now let's check with hda-verb.

With the patched 3.13 kernel, play without PulseAudio through the speaker (hp unplugged).  While playback, try the following:

   hda-verb /dev/snd/hwC0D0 0x0b SET_CONN 0

Do you get also lower volume now?  Or is it still same?

   hda-verb /dev/snd/hwC0D0 0x0b SET_CONN 1

should return to the original state.

Then, test with the headphone.  Play through a headphone, and while playback,

   hda-verb /dev/snd/hwC0D0 0x0a SET_CONN 1

Does this change the volume?

   hda-verb /dev/snd/hwC0D0 0x0a SET_CONN 0

should return to the original state.
Comment 27 Takashi Iwai 2013-12-03 07:58:38 UTC
Yet, another simpler test.
Try to turn on "Loopback Mixing" mixer switch via alsamixer -c0, and check whether the speaker output gets lower.
Comment 28 tfc.duke 2013-12-07 18:07:03 UTC
Ok, here are the results (I'm sorry for the long delay, I've been quite busy during the week).

1) hda-verb /dev/snd/hwC0D0 0x0b SET_CONN 0
Only speakers, no headphones: I don't see any difference.

2) hda-verb /dev/snd/hwC0D0 0x0a SET_CONN 1
With headphones plugged: Now I have correct sound volume on the left headphone!

3) Loopback Mixing turned on (off by default)
Only speakers, no headphones: I lost sound from the left speaker (or maybe it's very very low, it's hard to tell).
With headphones plugged (0x0a SET_CONN 0): No difference (left headphone still very very low)
With headphones plugged (0x0a SET_CONN 1): No sound at all.

When I run hda-verb commands during playback, it seems that the change is not applied. I have to stop playback, re-run hda-verb, and then restart playback to see a change.

Also, when I change volume other than PCM (master, headphones or speakers) during playback, or when I plug/unplug headphones, sound stops playing immediately and I have to unload and reload snd_hda_intel and snd_hda_codec_analog modules in order to get some sound again.
Comment 29 Takashi Iwai 2013-12-10 16:46:27 UTC
OK, thanks for testing.  It seems that AD1986A behaves in a really weird way and has many hidden restrictions (no wonder, it's one of the oldest HD-audio codec chip).

Could you try two patches below on top of 3.13-rc3?
Comment 30 Takashi Iwai 2013-12-10 16:46:58 UTC
Created attachment 117971 [details]
Fix patch #1 on 3.13-rc3
Comment 31 Takashi Iwai 2013-12-10 16:47:18 UTC
Created attachment 117981 [details]
Fix patch #2 on 3.13-rc3
Comment 32 tfc.duke 2013-12-10 21:29:45 UTC
Good news today, with the patched 3.13-rc3, everything seems to be working as expected!

(I just have to increase a bit the sound volume but you explained above that it's a bugfix.)
Comment 33 Raymond 2013-12-11 03:33:40 UTC
FEATURES 
Supports both AC ’97 and HD audio interfaces

so it just work like ac97

if headphone can only shared with front , spec->indep_hp should be zero

	static hda_nid_t preferred_pairs[] = {

		0x1a, 0x03,
		0x1b, 0x03,
		0x1c, 0x04,
		0x1d, 0x05,
		0x1e, 0x03,
		0
	};
Comment 34 Takashi Iwai 2013-12-11 06:31:15 UTC
spec->indep_hp doesn't matter in this case since the generic parser is smart enough and creates the instance only when it's really available.

The patch is now merged to upstream, so let's close the bug.
Thanks for your patient testing!
Comment 35 Raymond 2013-12-18 23:20:54 UTC
do the internal mic and external mic work as expected ?

seem only one mic pin at node 0x1f (Mic1/Mic2) pin 

do [Both] mean this situation since phanton jack is created even when Misc bit is clear and pincap support Detect ?


Node 0x1f [Pin Complex] wcaps 0x400081: Stereo
  Control: name="Mic Phantom Jack", index=0, device=0
  Pincap 0x00001727: IN Detect Trigger ImpSense
    Vref caps: HIZ 50 GRD 80
  Pin Default 0xc2a190f0: [Both] Mic at Ext Front
    Conn = 1/8, Color = Pink
    DefAssociation = 0xf, Sequence = 0x0
  Pin-ctls: 0x24: IN VREF_80
  Unsolicited: tag=00, enabled=0
Comment 36 tfc.duke 2013-12-21 16:11:59 UTC
The internal mic seems to be working as expected.
For external mic, I can't test right now (because I don't have one), but I'll try during the next week.
Comment 37 tfc.duke 2013-12-29 09:43:15 UTC
Ok, I found an external mic for testing. It seems to be working as before.

However, I noticed a little change:
- in 3.11 I had two "mic" entries, but only one was working (I had to use the same entry for both internal and external mic).
- Now with 3.13rc5 I only have one mic entry. It's cleaner this way.
Comment 38 Raymond 2013-12-31 06:29:55 UTC
how did you test ?

Did you recording in stereo or mono ?

do the left channel for internal mic and right channel for external mic jack ?

or

Do the mic1 and mic2 (internal mic and external mic) are mixed together ?

https://git.kernel.org/cgit/linux/kernel/git/tiwai/sound.git/commit/?id=8ab78c7424588c6b1600dcfd70418617a09326b8

the driver previously used LineInAmp at node 0x17 and MicMixAmp at node 0x13 for the Internal Mic playback volume and Mic Playback Volume

+ HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x0, HDA_OUTPUT),
+ HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x0, HDA_OUTPUT),
+ HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
+ HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
Comment 39 tfc.duke 2014-01-01 13:57:09 UTC
I tried both recording in stereo and mono (with audacity), and I coulnd't get any difference between left and right channels, therefore I assume that mic1 and mic2 are mixed together.
Comment 40 Raymond 2014-01-02 06:04:43 UTC
try hda_jack_sense_test.py when you plugged the external mic jack is node 0x1f or not 

https://bugzilla.kernel.org/show_bug.cgi?id=66621
this require hda_codec.py of alsa-tools/hda-analyzer



do your n100 really use CD ?

	control.12 {
		iface MIXER
		name 'Capture Source'
		value Mic
		comment {
			access 'read write'
			type ENUMERATED
			count 1
			item.0 Mic
 			item.1 CD
		}
    	}



Figure 3. Microphone Selection/Mixing Block Diagram

MMIX    2CMIC    MS      
MSWP2   MSWP1    MSWP0   Right    Left
0       0        0       MIC 1    MIC 1
0       0        1       MIC 2    MIC 2
0       1        0       MIC 2    MIC 1
0       1        1       MIC 1    MIC 2
1       x        x       MIC 1+2  MIC 1+2


Table 45. MIC_1/2 Swap
NID  Name         Description
0x11 MIC_1/2 Swap Swaps the left/right association of MIC_1/2 on the input pins
only. Allows up mix, spreading one microphone to both left and right output channels.


Node 0x11 [Audio Selector] wcaps 0x300941: Stereo R/L
  Connection: 2
     0x0f* 0x2b
  Processing caps: benign=1, ncoeff=0
Comment 41 tfc.duke 2014-01-02 17:58:03 UTC
Here are hda_jack_sense_test.py results.

When no mic plugged:
Pin 0x1f [Both] Mic Ext at Front (Pink) [] : PD=0 Imp=1400

When external mic is plugged:
Pin 0x1f [Both] Mic Ext at Front (Pink) [] : PD=0 Imp=1700

...but sometimes:
Pin 0x1f [Both] Mic Ext at Front (Pink) [] : PD=0 Imp=1800

Is it what you wanted?
Comment 42 tfc.duke 2014-01-02 17:58:14 UTC
About the CD, what is it exactly? is it the CD-Rom line in? How am I supposed to use it? If I try to record from it, I get nothing. hda_jack_sense_test.py gives:

Pin 0x22 [Fixed] CD Int at N/A (Unknown) [] :
Comment 43 Raymond 2014-01-02 23:21:07 UTC
Table 46. ADI Specific Verb Support    


Processing State  

Get 0xF03 N/A (0)  Processing State 
Controls the up-mix function of the MIC_1/2 swap widget. Up-Mix will spread the selected left channel (see the left/right swap feature of the enable EAPD/BTL verb description) to both the left and right channel outputs of this stereo widget.       

Value Processing State Up-Mix Spreading       
0x00 Off Off       
0x01 Benign On       
0x02 Benign On  

Set 0x703 Processing State 8 N/A (0) 

Note that the AD1986 considers both on and benign states as benign. If the on state is set, the AD1986 will set and return the benign state
Comment 44 Raymond 2014-01-03 03:21:24 UTC
PD should be 1 when you plug the mic or headphone and 0 when unpluuged

is it rare to connect CD to the analog mixer of the codec in laptop ?

you can use hda-analyzer to swap the left and right channel of node 0x11

and use hda_verb to turn on/off the up-mixing by ADI specific verb