On Thu, 06 Jun 2013 11:49:00 +0200, Takashi Iwai tiwai@suse.de wrote :
At Wed, 5 Jun 2013 17:36:43 +0200, Anisse Astier wrote:
On Wed, 05 Jun 2013 12:26:59 +0200, Takashi Iwai tiwai@suse.de wrote :
I'm on a dead end on this computer, I can't seem to find how the mic jack presence works. It's always on(presence detected whatever the status) on NID 0x18, the one used for the external mic. I have tried every NID, manually enabling pin_sense on each, but only the headphone jack detection works. The mic sense is nowhere to be seen.
I also don't know any other method for Realtek. For IDT codecs, there are some devices with GPIO unsol events, but Realtek codecs seem to use only the normal pin detection unsol events.
So, on your device, GET_PIN_SENSE doesn't return the detection bit set? You tried setting SET_PIN_SENSE before GET_PIN_SENSE, right?
I did more tests, this time using hda-verb directly instead of hda-analyzer tools. And GET_PIN_SENSE does return the correct value… sometimes. (without the need for SET_PIN_SENSE) It seems the value is correct only if queried once every 10 to 15 seconds.
Does this mean that it gives a wrong result (i.e. no detect bit although plugged, or vice versa)? Also, is the unsol event issued per
It means it gives detect bit (most of the time) although unplugged.
jack plug/unplug? If so, is the detection correct just after the unsol event?
I don't know yet. From what I observed for now: - there are multiple events in a row. - the event is issued for unplugs, everytime. For plugs, it's only issued sometimes, if we wait long enough. - when unpluged, we get unsol events every 10 seconds or so, even when doing nothing.
To gather more information I added some printfs:
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 55108b5..f6b0592 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -271,6 +271,9 @@ unsigned int snd_hda_codec_read(struct hda_codec *codec, hda_nid_t nid, unsigned int res; if (codec_exec_verb(codec, cmd, &res)) return -1; + if (verb == AC_VERB_GET_PIN_SENSE) { + snd_printd("hda_codec: Getting PIN Sense on nid 0x%x: %08x\n", nid, res); + } return res; } EXPORT_SYMBOL_HDA(snd_hda_codec_read); @@ -292,6 +295,9 @@ int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int direct, { unsigned int cmd = make_codec_cmd(codec, nid, direct, verb, parm); unsigned int res; + if (verb == AC_VERB_SET_UNSOLICITED_ENABLE) { + snd_printd("hda_codec: Enabling unsolicited on nid 0x%x: %08x\n", nid, parm); + } return codec_exec_verb(codec, cmd, codec->bus->sync_write ? &res : NULL); } @@ -723,7 +729,10 @@ static void process_unsol_events(struct work_struct *work) continue; codec = bus->caddr_tbl[caddr & 0x0f]; if (codec && codec->patch_ops.unsol_event) + { + snd_printd("hda_codec: Unsol event with res 0x%x", res); codec->patch_ops.unsol_event(codec, res); + } } }
Here's an annotated log I collected with this patch:
Mic is NID 0x18, and headphones 0x21. Headphones are unplugged the entire time.
Mic jack is plugged. I unplug it.
[ 444.059100] ALSA sound/pci/hda/hda_codec.c:733 hda_codec: Unsol event with res 0x8000000 [ 445.063294] ALSA sound/pci/hda/hda_intel.c:948 0000:00:1b.0: azx_get_response timeout, polling the codec once: last cmd=0x020c0000 [ 445.063656] ALSA sound/pci/hda/hda_codec.c:275 hda_codec: Getting PIN Sense on nid 0x21: 00000000 [ 445.063739] ALSA sound/pci/hda/hda_codec.c:275 hda_codec: Getting PIN Sense on nid 0x18: 00000000 [ 445.064050] ALSA sound/pci/hda/hda_codec.c:299 hda_codec: Enabling unsolicited on nid 0x21: 00000081 [ 445.064072] ALSA sound/pci/hda/hda_codec.c:299 hda_codec: Enabling unsolicited on nid 0x18: 00000082 [ 445.065180] ALSA sound/pci/hda/hda_codec.c:275 hda_codec: Getting PIN Sense on nid 0x18: 00000000 [ 445.083919] ALSA sound/pci/hda/hda_codec.c:733 hda_codec: Unsol event with res 0x8000010 [ 445.084043] ALSA sound/pci/hda/hda_codec.c:275 hda_codec: Getting PIN Sense on nid 0x18: 80000000
10 seconds later, an unsol events while I did nothing [ 456.097023] ALSA sound/pci/hda/hda_intel.c:948 0000:00:1b.0: azx_get_response timeout, polling the codec once: last cmd=0x020c0000 [ 456.111282] ALSA sound/pci/hda/hda_codec.c:733 hda_codec: Unsol event with res 0x8000000 [ 456.112267] ALSA sound/pci/hda/hda_codec.c:275 hda_codec: Getting PIN Sense on nid 0x21: 00000000 [ 456.112367] ALSA sound/pci/hda/hda_codec.c:275 hda_codec: Getting PIN Sense on nid 0x18: 00000000 [ 456.112677] ALSA sound/pci/hda/hda_codec.c:299 hda_codec: Enabling unsolicited on nid 0x21: 00000081 [ 456.112700] ALSA sound/pci/hda/hda_codec.c:299 hda_codec: Enabling unsolicited on nid 0x18: 00000082 [ 456.113792] ALSA sound/pci/hda/hda_codec.c:275 hda_codec: Getting PIN Sense on nid 0x18: 00000000 [ 456.132647] ALSA sound/pci/hda/hda_codec.c:733 hda_codec: Unsol event with res 0x8000010 [ 456.132722] ALSA sound/pci/hda/hda_codec.c:275 hda_codec: Getting PIN Sense on nid 0x18: 80000000
again [ 466.156558] ALSA sound/pci/hda/hda_codec.c:733 hda_codec: Unsol event with res 0x8000000 [ 466.157490] ALSA sound/pci/hda/hda_codec.c:275 hda_codec: Getting PIN Sense on nid 0x21: 00000000 [ 466.157584] ALSA sound/pci/hda/hda_codec.c:275 hda_codec: Getting PIN Sense on nid 0x18: 00000000 [ 466.157873] ALSA sound/pci/hda/hda_codec.c:299 hda_codec: Enabling unsolicited on nid 0x21: 00000081 [ 466.157959] ALSA sound/pci/hda/hda_codec.c:299 hda_codec: Enabling unsolicited on nid 0x18: 00000082 [ 466.159033] ALSA sound/pci/hda/hda_codec.c:275 hda_codec: Getting PIN Sense on nid 0x18: 00000000 [ 466.177922] ALSA sound/pci/hda/hda_codec.c:733 hda_codec: Unsol event with res 0x8000010 [ 466.178088] ALSA sound/pci/hda/hda_codec.c:275 hda_codec: Getting PIN Sense on nid 0x18: 80000000
and again [ 476.212512] ALSA sound/pci/hda/hda_codec.c:733 hda_codec: Unsol event with res 0x8000000 [ 477.214751] ALSA sound/pci/hda/hda_intel.c:948 0000:00:1b.0: azx_get_response timeout, polling the codec once: last cmd=0x020c0000 [ 477.215049] ALSA sound/pci/hda/hda_codec.c:275 hda_codec: Getting PIN Sense on nid 0x21: 00000000 [ 477.215158] ALSA sound/pci/hda/hda_codec.c:275 hda_codec: Getting PIN Sense on nid 0x18: 00000000 [ 477.215519] ALSA sound/pci/hda/hda_codec.c:299 hda_codec: Enabling unsolicited on nid 0x21: 00000081 [ 477.215553] ALSA sound/pci/hda/hda_codec.c:299 hda_codec: Enabling unsolicited on nid 0x18: 00000082 [ 477.216926] ALSA sound/pci/hda/hda_codec.c:275 hda_codec: Getting PIN Sense on nid 0x18: 00000000 [ 477.237333] ALSA sound/pci/hda/hda_codec.c:733 hda_codec: Unsol event with res 0x8000010 [ 477.237404] ALSA sound/pci/hda/hda_codec.c:275 hda_codec: Getting PIN Sense on nid 0x18: 80000000
here I plug the mic [ 480.215725] ALSA sound/pci/hda/hda_codec.c:733 hda_codec: Unsol event with res 0x8000000 [ 480.215824] ALSA sound/pci/hda/hda_codec.c:275 hda_codec: Getting PIN Sense on nid 0x18: 00000000 [ 480.279747] ALSA sound/pci/hda/hda_codec.c:733 hda_codec: Unsol event with res 0x8000010 [ 480.279809] ALSA sound/pci/hda/hda_codec.c:275 hda_codec: Getting PIN Sense on nid 0x18: 80000000
and unplug it [ 506.284318] ALSA sound/pci/hda/hda_codec.c:733 hda_codec: Unsol event with res 0x8000000 [ 506.285313] ALSA sound/pci/hda/hda_codec.c:275 hda_codec: Getting PIN Sense on nid 0x21: 00000000 [ 506.285413] ALSA sound/pci/hda/hda_codec.c:275 hda_codec: Getting PIN Sense on nid 0x18: 00000000 [ 506.285853] ALSA sound/pci/hda/hda_codec.c:299 hda_codec: Enabling unsolicited on nid 0x21: 00000081 [ 506.285888] ALSA sound/pci/hda/hda_codec.c:299 hda_codec: Enabling unsolicited on nid 0x18: 00000082 [ 506.286878] ALSA sound/pci/hda/hda_codec.c:275 hda_codec: Getting PIN Sense on nid 0x18: 00000000 [ 506.305697] ALSA sound/pci/hda/hda_codec.c:733 hda_codec: Unsol event with res 0x8000010 [ 506.305779] ALSA sound/pci/hda/hda_codec.c:275 hda_codec: Getting PIN Sense on nid 0x18: 80000000
10 seconds later, an automatic unsolicited event [ 516.308248] ALSA sound/pci/hda/hda_codec.c:733 hda_codec: Unsol event with res 0x8000000 [ 516.309285] ALSA sound/pci/hda/hda_codec.c:275 hda_codec: Getting PIN Sense on nid 0x21: 00000000 [ 516.309384] ALSA sound/pci/hda/hda_codec.c:275 hda_codec: Getting PIN Sense on nid 0x18: 00000000 [ 516.309779] ALSA sound/pci/hda/hda_codec.c:299 hda_codec: Enabling unsolicited on nid 0x21: 00000081 [ 516.309813] ALSA sound/pci/hda/hda_codec.c:299 hda_codec: Enabling unsolicited on nid 0x18: 00000082 [ 516.310837] ALSA sound/pci/hda/hda_codec.c:275 hda_codec: Getting PIN Sense on nid 0x18: 00000000 [ 516.329607] ALSA sound/pci/hda/hda_codec.c:733 hda_codec: Unsol event with res 0x8000010 [ 516.329682] ALSA sound/pci/hda/hda_codec.c:275 hda_codec: Getting PIN Sense on nid 0x18: 80000000
I plug it again [ 520.674375] ALSA sound/pci/hda/hda_codec.c:733 hda_codec: Unsol event with res 0x8000008 [ 520.674512] ALSA sound/pci/hda/hda_codec.c:275 hda_codec: Getting PIN Sense on nid 0x18: 00000000 [ 520.674665] ALSA sound/pci/hda/hda_codec.c:733 hda_codec: Unsol event with res 0x4000008 [ 520.674741] ALSA sound/pci/hda/hda_codec.c:275 hda_codec: Getting PIN Sense on nid 0x21: 80000000 [ 520.695707] ALSA sound/pci/hda/hda_codec.c:733 hda_codec: Unsol event with res 0x8000010 [ 520.695791] ALSA sound/pci/hda/hda_codec.c:275 hda_codec: Getting PIN Sense on nid 0x18: 80000000 [ 520.695863] ALSA sound/pci/hda/hda_codec.c:733 hda_codec: Unsol event with res 0x4000010 [ 520.695923] ALSA sound/pci/hda/hda_codec.c:275 hda_codec: Getting PIN Sense on nid 0x21: 00000000
Currently we don't need to issue the real GET_PIN_SENSE at every inquiry but only when demanded (e.g. after unsol event, init and resume). If the detection works reliably at these moments, it should be enough in theory.
I'm not sure that would be enough according to what I'm observing.
Anisse