Bug 90608 - Headphone detection problems after power cycling
Summary: Headphone detection problems after power cycling
Status: RESOLVED NOTOURBUG
Alias: None
Product: PulseAudio
Classification: Unclassified
Component: core (show other bugs)
Version: unspecified
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: pulseaudio-bugs
QA Contact: pulseaudio-bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-05-23 21:34 UTC by Furkan
Modified: 2015-05-26 05:31 UTC (History)
2 users (show)

See Also:
i915 platform:
i915 features:


Attachments

Description Furkan 2015-05-23 21:34:25 UTC
Configuration summary: I have stereo speakers connected to the rear panel, and headphones connected to the front panel. Audio chipset is VIA VT2020 on a Gigabyte GA-970A-D3 motherboard.

Expected behaviour: Sound should play out of the headphones. Unplugging the headphones should result in fallback to main speakers.

Actual behaviour: If the system is booted up with only the speakers connected to the rear panel, and the headphones are later connected to the front panel, it works as expected. However:

1) After suspending/resuming (or shutting down and starting back up) the PC while both speakers/headphones are already plugged in, the headphones are no longer detected, and I am required to unplug the headphones and plug them back in to be detected again (or, although my headphones don't appear in the gnome sound settings, I can still go into alsamixer and manually mute the speakers and unmute the headphones to get them working again). Rebooting doesn't cause any problems, so the issue seems to be triggered by power cycling.

2) If only the headphones are plugged in to the front panel, everything works fine. Subsequently, if I plug speakers into the back panel, both the headphones and speakers become muted. To get sound out of the headphones again, I need to unplug them and plug them back in.

I originally reported this bug on Ubuntu launchpad: https://bugs.launchpad.net/ubuntu/+source/alsa-driver/+bug/1442428

I was originally using the Ubuntu package, but I have now built/installed pulseaudio from git, and the same problem persists. This problem was not present with pulseaudio 5.0, so I tried to do a git bisect, but ran into different problems with builds in between so I wasn't able to pinpoint the exact commit which broke it.

Another peculiarity I noticed (may or may not be related) is that alsamixer seems to think that I have a surround sound setup, when I only have a standard set of stereo speakers plugged in: https://www.dropbox.com/s/r2ahv3yvvpkzzn3/alsamixer.png?dl=0
Comment 1 Raymond 2015-05-24 03:48:53 UTC
1) After suspending/resuming (or shutting down and starting back up) the PC while both speakers/headphones are already plugged in, the headphones are no longer detected, and I am required to unplug the headphones and plug them back in to be detected again


https://bugzilla.kernel.org/enter_bug.cgi?product=Drivers

(Sound/ALSA)
Comment 2 Raymond 2015-05-24 03:56:27 UTC
ports:
		analog-output-lineout: Line Out (priority 9900, latency offset 0 usec, available: yes)
			properties:
				
		analog-output-headphones: Headphones (priority 9000, latency offset 0 usec, available: yes)
			properties:
				device.icon_name = "audio-headphones"
	active port: <analog-output-lineout>



headphone has lower priority when both line out and headphone are available

previously the availability of line out is unknown




http://cgit.freedesktop.org/pulseaudio/pulseaudio/commit/src/modules/alsa/mixer/paths/analog-output-lineout.conf?id=5598923b8e64de873a417b512d709c5674f3a96d
Comment 3 Raymond 2015-05-24 05:31:35 UTC
2) If only the headphones are plugged in to the front panel, everything works fine. Subsequently, if I plug speakers into the back panel, both the headphones and speakers become muted. To get sound out of the headphones again, I need to unplug them and plug them back in.

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


http://cgit.freedesktop.org/pulseaudio/pulseaudio/commit/src/modules/alsa/mixer/paths/analog-output-headphones.conf?id=31575f7766d6ff39665b64a3a04412eff1c39957

+[Element Front]
+switch = off
+volume = off
+
+[Element Rear]
+switch = off
+volume = off
+
+[Element Sourround]
+switch = off
+volume = off
+
+[Element Side]
+switch = off
+volume = off
+
+[Element Center]
+switch = off
+volume = off
+
+[Element LFE]
+switch = off
+volume = off
+

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


http://cgit.freedesktop.org/pulseaudio/pulseaudio/commit/src/modules/alsa/mixer/paths/analog-output-lineout.conf?id=9d0a5b5cb7ea3adc1b548a6e1e953ee20835e6b6



-; This profile path is intended to control the default output, not the
-; headphones. But it should not hurt if we leave the headphone jack
-; enabled nonetheless.
+; This profile path is intended to control line out, let's mute headphones
+; else there will be a spike when plugging in headphones
 [Element Headphone]
-switch = mute
-volume = zero
+switch = off
+volume = off
 
 [Element Headphone2]
-switch = mute
-volume = zero
+switch = off
+volume = off
 
 [Element Speaker]
-switch = mute
+switch = off
 volume = off
Comment 4 Furkan 2015-05-24 05:54:13 UTC
>> headphone has lower priority when both line out and headphone are available
Are laptops' external speakers labelled as line out? I ask that since normally plugging in headphones results in the external speakers being muted?

I tried killing the pulseaudio process (I had to set autospawn = no in client.conf), and as a result, I can repeatedly suspend/resume and my headphones continue to work. The sound plays out of the speakers as well (not a major issue for me since I can turn them off).

I also tested on another machine, with a Realtek ALC1200 chipset, and couldn't reproduce the issue. Does that confirm that there is a problem on the kernel driver side?
Comment 5 Raymond 2015-05-24 11:35:59 UTC
Node 0x24 [Pin Complex] wcaps 0x40058d: Stereo Amp-Out
  Control: name="Front Playback Switch", index=0, device=0
    ControlAmp: chs=3, dir=Out, idx=0, ofs=0
  Control: name="Line Out Front Jack", index=0, device=0
  Amp-Out caps: ofs=0x00, nsteps=0x00, stepsize=0x00, mute=1
  Amp-Out vals:  [0x00 0x00]
  Pincap 0x0001001c: OUT HP EAPD Detect
  EAPD 0x2: EAPD
  Pin Default 0x01014010: [Jack] Line Out at Ext Rear
    Conn = 1/8, Color = Green
    DefAssociation = 0x1, Sequence = 0x0
  Pin-ctls: 0x00:
  Unsolicited: tag=02, enabled=1
  Power states:  D0 D1 D2 D3
  Power: setting=D0, actual=D0
  Connection: 1
     0x18
Node 0x25 [Pin Complex] wcaps 0x40058d: Stereo Amp-Out
  Control: name="Surround Playback Switch", index=0, device=0
    ControlAmp: chs=3, dir=Out, idx=0, ofs=0
  Control: name="Line Out Surround Jack", index=0, device=0
  Amp-Out caps: ofs=0x00, nsteps=0x00, stepsize=0x00, mute=1
  Amp-Out vals:  [0x00 0x00]
  Pincap 0x0000001c: OUT HP Detect
  Pin Default 0x01011012: [Jack] Line Out at Ext Rear
    Conn = 1/8, Color = Black
    DefAssociation = 0x1, Sequence = 0x2
  Pin-ctls: 0x00:
  Unsolicited: tag=03, enabled=1
  Power states:  D0 D1 D2 D3
  Power: setting=D0, actual=D0
  Connection: 1
     0x19
Node 0x26 [Pin Complex] wcaps 0x40058d: Stereo Amp-Out
  Control: name="Center Playback Switch", index=0, device=0
    ControlAmp: chs=1, dir=Out, idx=0, ofs=0
  Control: name="LFE Playback Switch", index=0, device=0
    ControlAmp: chs=2, dir=Out, idx=0, ofs=0
  Control: name="Line Out CLFE Jack", index=0, device=0
  Amp-Out caps: ofs=0x00, nsteps=0x00, stepsize=0x00, mute=1
  Amp-Out vals:  [0x00 0x00]
  Pincap 0x00000014: OUT Detect
  Pin Default 0x01016011: [Jack] Line Out at Ext Rear
    Conn = 1/8, Color = Orange
    DefAssociation = 0x1, Sequence = 0x1
  Pin-ctls: 0x00:
  Unsolicited: tag=04, enabled=1
  Power states:  D0 D1 D2 D3
  Power: setting=D0, actual=D0
  Connection: 1
     0x0a
Node 0x27 [Pin Complex] wcaps 0x40058d: Stereo Amp-Out
  Control: name="Side Playback Switch", index=0, device=0
    ControlAmp: chs=3, dir=Out, idx=0, ofs=0
  Control: name="Line Out Side Jack", index=0, device=0
  Amp-Out caps: ofs=0x00, nsteps=0x00, stepsize=0x00, mute=1
  Amp-Out vals:  [0x00 0x00]
  Pincap 0x00000014: OUT Detect
  Pin Default 0x01012014: [Jack] Line Out at Ext Rear
    Conn = 1/8, Color = Grey
    DefAssociation = 0x1, Sequence = 0x4
  Pin-ctls: 0x00:
  Unsolicited: tag=05, enabled=1
  Power states:  D0 D1 D2 D3
  Power: setting=D0, actual=D0
  Connection: 1
     0x1a


the driver usually mute line out jacks by set pin-ctl to zero when headphone jack is plugged


pulseaudio just mute the lineout jacks by those front,surround? center/lfe and side playback switches when headphone jack control return true
Comment 6 Raymond 2015-05-24 14:20:49 UTC
(In reply to falaca from comment #4)
> >> headphone has lower priority when both line out and headphone are available
> Are laptops' external speakers labelled as line out? I ask that since
> normally plugging in headphones results in the external speakers being muted?


http://cgit.freedesktop.org/pulseaudio/pulseaudio/commit/src/modules/alsa/mixer/paths/analog-output-speaker.conf?id=e02cb7fb2e7865affed612693935c7fd698e3a6b


 
+[Jack Headphone]
+state.plugged = no
+state.unplugged = unknown
+
Comment 7 Furkan 2015-05-24 18:49:45 UTC
After further searching online, I found this bug report, where the reporter has the same audio chipset (VIA VT2020) and had a very similar issue with the microphone jack (had to unplug and plug it back in after rebooting):
https://bugs.launchpad.net/ubuntu/+source/alsa-driver/+bug/1365769

I followed David Henningsson's suggestion, which was to add "options snd-hda-intel jackpoll_ms=400" to /etc/modprobe.d/alsa-base.conf, and that fixes my problem too:
https://bugs.launchpad.net/ubuntu/+source/alsa-driver/+bug/1365769/comments/29

Does that give any further indication as to what is going wrong?
Comment 9 Raymond 2015-05-24 22:57:56 UTC
driver auto mic switch is only enabled for notebook, 

since desktop has three detectable input pins (e.g. front mic, rear mic and line in), 

some motherboards have CD input source and

some codecs support stereio mix

https://git.kernel.org/cgit/linux/kernel/git/tiwai/sound.git/log/sound/pci/hda?qt=grep&q=stereo+mix


it create two or more capture devices  for desktop when there is enough ADC
Comment 10 Furkan 2015-05-24 23:05:11 UTC
I didn't know what stereo mix was, so I looked it up. I don't have any need for it, so that's not what this bug report was about. As far as I can understand, the other bug report isn't related to stereo mix either.

To summarize:
1. My problem is that my headphones don't work on a cold boot if they were already plugged in _before_ the PC was turned on.
2. The other bug report reported the same issue except his problem was with his microphone instead of his headphones. The reporter is using the same audio chipset (VIA VT2020).
3. Both of our problems appear to be fixed by David's workaround.

Is there any explanation for how David's workaround fixes the problem?
Comment 11 Furkan 2015-05-25 00:04:50 UTC
Also, just to clarify again, the headphone jack detection works perfectly fine while the OS is live. I can plug my headphones in and out, and the OS switches between headphones and external speakers as expected.

The issue happens when my headphones are plugged in, and then I turn off my PC, and turn it back on. That results in the headphones disappearing until the next time I unplug/plug them back in again.

And also as mentioned above, I do not have this problem with another desktop with a Realtek audio chipset (same configuration: stereo speakers plugged into line out, headphones plugged into front panel). So the problem lies squarely with this VIA chipset. Does that help to narrow down where the buggy code is? If it is not pulseaudio's problem, I can submit the report elsewhere.
Comment 12 Raymond 2015-05-25 00:44:45 UTC
the analog mixer node 0x21 can be powered down for power saving 

APLAY Simple mixer control 'Loopback Mixing',0
  Capabilities: enum
  Items: 'Disabled' 'Enabled'
  Item0: 'Disabled'

Simple mixer control 'PCM Loopback',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 31
  Mono:
  Front Left: Playback 23 [74%] [0.00dB] [off]
  Front Right: Playback 23 [74%] [0.00dB] [off]


Simple mixer control 'Dynamic Power-Control',0
  Capabilities: enum
  Items: 'Disabled' 'Enabled'
  Item0: 'Disabled'
Simple mixer control 'Independent HP',0
  Capabilities: enum
  Items: 'OFF' 'ON'
  Item0: 'OFF'


**** List of PLAYBACK Hardware Devices ****
card 0: Intel [HDA Intel], device 0: VT2020 Analog [VT2020 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: Intel [HDA Intel], device 2: VT2020 HP [VT2020 HP]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
Comment 13 Raymond 2015-05-25 00:49:10 UTC
jack_poll was dsesigned  for vt1708 which does not support unsol event


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


you have to ask the author why it has any effect on vt2020 which support unsol event
Comment 14 Furkan 2015-05-25 00:57:03 UTC
Thanks Raymond, I've added Takashi (the author of that commit) to the CC list. If this is the source of the problem, are you suggesting that I submit a kernel bug report?
Comment 15 Raymond 2015-05-25 00:59:47 UTC
Unsolicited: tag=01, enabled=1

for those codec which support unsol event, the hardware generate unsol event when jack is plugged and unplugged

vt1708 does not support unsolicited event, the driver need to poll the jack state periodically 


Codec: VIA VT1708
Address: 0
Function Id: 0x1
Vendor Id: 0x11061708
Subsystem Id: 0x10191708
Revision Id: 0x100500


Node 0x20 [Pin Complex] wcaps 0x40010d: Stereo Amp-Out
  Control: name="Headphone Playback Volume", index=0, device=0
    ControlAmp: chs=3, dir=Out, idx=0, ofs=0
  Control: name="Headphone Playback Switch", index=0, device=0
    ControlAmp: chs=3, dir=Out, idx=0, ofs=0
  Amp-Out caps: ofs=0x1b, nsteps=0x1b, stepsize=0x06, mute=1
  Amp-Out vals:  [0x1b 0x1b]
  Pincap 0x0000001c: OUT HP Detect
  Pin Default 0x022140f0: [Jack] HP Out at Ext Front
    Conn = 1/8, Color = Green
    DefAssociation = 0xf, Sequence = 0x0
  Pin-ctls: 0xc0: OUT HP
  Connection: 1
     0x17



Codec: VIA VT2020
Address: 0
AFG Function Id: 0x1 (unsol 0)
Vendor Id: 0x11060441
Subsystem Id: 0x1458a014
Revision Id: 0x100100

Node 0x28 [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
  Control: name="Front Headphone Jack", index=0, device=0
  Amp-Out caps: ofs=0x00, nsteps=0x00, stepsize=0x00, mute=1
  Amp-Out vals:  [0x80 0x80]
  Pincap 0x0000233c: IN OUT HP Detect
    Vref caps: HIZ 50 100
  Pin Default 0x022140f0: [Jack] HP Out at Ext Front
    Conn = 1/8, Color = Green
    DefAssociation = 0xf, Sequence = 0x0
  Pin-ctls: 0xc0: OUT HP VREF_HIZ
  Unsolicited: tag=01, enabled=1
  Power states:  D0 D1 D2 D3
  Power: setting=D0, actual=D0
  Connection: 1
     0x1b
Comment 16 Raymond 2015-05-25 04:58:48 UTC
(In reply to Furkan from comment #7)
> After further searching online, I found this bug report, where the reporter
> has the same audio chipset (VIA VT2020) and had a very similar issue with
> the microphone jack (had to unplug and plug it back in after rebooting):
> https://bugs.launchpad.net/ubuntu/+source/alsa-driver/+bug/1365769
> 
> I followed David Henningsson's suggestion, which was to add "options
> snd-hda-intel jackpoll_ms=400" to /etc/modprobe.d/alsa-base.conf, and that
> fixes my problem too:
> https://bugs.launchpad.net/ubuntu/+source/alsa-driver/+bug/1365769/comments/
> 29
> 
> Does that give any further indication as to what is going wrong?

for desktop with three jacks arpt rear panel, blue jack and pink jack can be retasked as output

it is strange that unsol event are not enabled since the driver also check pin ctl is IN  or OUT


Node 0x2a [Pin Complex] wcaps 0x40058d: Stereo Amp-Out
  Control: name="Surround Playback Switch", index=0, device=0
    ControlAmp: chs=3, dir=Out, idx=0, ofs=0
  Control: name="Line Jack", index=0, device=0
  Amp-Out caps: ofs=0x00, nsteps=0x00, stepsize=0x00, mute=1
  Amp-Out vals:  [0x00 0x00]
  Pincap 0x00002334: IN OUT Detect
    Vref caps: HIZ 50 100
  Pin Default 0x0181303e: [Jack] Line In at Ext Rear
    Conn = 1/8, Color = Blue
    DefAssociation = 0x3, Sequence = 0xe
  Pin-ctls: 0x20: IN VREF_HIZ
  Unsolicited: tag=00, enabled=0
  Power states:  D0 D1 D2 D3
  Power: setting=D0, actual=D0
  Connection: 2
     0x09* 0x0c
Node 0x2b [Pin Complex] wcaps 0x40058d: Stereo Amp-Out
  Control: name="Center Playback Switch", index=0, device=0
    ControlAmp: chs=1, dir=Out, idx=0, ofs=0
  Control: name="LFE Playback Switch", index=0, device=0
    ControlAmp: chs=2, dir=Out, idx=0, ofs=0
  Control: name="Rear Mic Boost Volume", index=0, device=0
    ControlAmp: chs=3, dir=In, idx=0, ofs=0
  Control: name="Rear Mic Jack", index=0, device=0
  Amp-Out caps: ofs=0x00, nsteps=0x00, stepsize=0x00, mute=1
  Amp-Out vals:  [0x00 0x00]
  Pincap 0x00002334: IN OUT Detect
    Vref caps: HIZ 50 100
  Pin Default 0x01a19036: [Jack] Mic at Ext Rear
    Conn = 1/8, Color = Pink
    DefAssociation = 0x3, Sequence = 0x6
  Pin-ctls: 0x21: IN VREF_50
  Unsolicited: tag=00, enabled=0
  Power states:  D0 D1 D2 D3
  Power: setting=D0, actual=D0
  Connection: 2
     0x0a* 0x0c
Comment 17 Raymond 2015-05-25 05:15:09 UTC
you need to open bug report at kernel bugzilla 



https://git.kernel.org/cgit/linux/kernel/git/tiwai/sound.git/tree/Documentation/sound/alsa/HD-Audio.txt

ask the author how to enable  tracepoint for those unsol event and codec write after boot



https://git.kernel.org/cgit/linux/kernel/git/tiwai/sound.git/commit/sound/pci/hda/hda_jack.c?id=34a9318772d00efc5c1af00639526232050c49b8

this look like workaround by disable unsol event
Comment 18 David Henningsson 2015-05-25 08:03:40 UTC
If jackpoll_ms can solve your problem, then this looks like a bug on the ALSA level rather than the Pulseaudio level.
Comment 19 Furkan 2015-05-25 15:40:39 UTC
Thanks Raymond (and David), I submitted the bug here as you suggested: https://bugzilla.kernel.org/show_bug.cgi?id=98921
Comment 20 Raymond 2015-05-26 03:21:42 UTC
http://cgit.freedesktop.org/pulseaudio/pulseaudio/commit/src/modules/alsa/mixer/paths/analog-output-lineout.conf?id=9d0a5b5cb7ea3adc1b548a6e1e953ee20835e6b6


alsa-mixer: Mute headphones and speakers on line out path
When line out path is active, we want to mute speakers for obvious
reasons, and headphones to avoid volume spikes.



diff --git a/src/modules/alsa/mixer/paths/analog-output-lineout.conf b/src/modules/alsa/mixer/paths/analog-output-lineout.conf
index a110c26..16752a3 100644
--- a/src/modules/alsa/mixer/paths/analog-output-lineout.conf
+++ b/src/modules/alsa/mixer/paths/analog-output-lineout.conf
@@ -102,23 +102,22 @@ volume = off
 switch = off
 required-any = any
 
-; This profile path is intended to control the default output, not the
-; headphones. But it should not hurt if we leave the headphone jack
-; enabled nonetheless.
+; This profile path is intended to control line out, let's mute headphones
+; else there will be a spike when plugging in headphones
 [Element Headphone]
-switch = mute
-volume = zero
+switch = off
+volume = off

are you sure the headphone is not swirched off by this patch since the availability of line out is yes ?

try remove these lines 

-; This profile path is intended to control line out, let's mute headphones
-; else there will be a spike when plugging in headphones
-[Element Headphone]
-switch = off
-volume = off
Comment 21 Furkan 2015-05-26 05:20:00 UTC
I tried removing those lines, and also temporarily commented out the jackpoll_ms workaround to run the test. After restarting my PC and then plugging in the headphones (after the OS is finished booting), my results are:

Before suspend: Sound plays out of headphones, speakers are muted.

After suspend/resume: Sound plays out of BOTH headphones and speakers.

That must have been why I didn't notice the issue before pulseaudio 6.0 (my speakers are turned off 90% of the time).
Comment 22 Furkan 2015-05-26 05:31:26 UTC
Just to further clarify the results from above:

1) Before suspend: Sound plays out of headphones, speakers are muted. In Unity sound settings, "Headphones" is selected as the output device.


2) After suspend/resume: Sound plays out of BOTH headphones and speakers. In Unity sound settings, "Line Out" is selected as the output device.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.