Possible fix for snd-hda-intel model=no-jd failing since ~linux-3.9-rc1
Hi.
This is a bug and suggested temporary fix that I originally posted to the linux-sound mailing list about a month and a half ago. I am grateful to Takashi Awai for informing me after my follow-up inquiry about it today that I should submit it to the alsa-devel mailing list instead. Please feel free to redirect me further if appropriate. I did not notice any contact information for sound/pci/hda in linux-3.16-rc4/MAINATINERS.
Anyhow, here is the bug report and a one line proposed temporary fix.
The "model=no-jd" argument has not initialized the analog audio output jack correctly for me since linux-3.9-rc1 (if I recall correctly) through linux-3.17-rc4, although I have not tried every release candidate in between.
The symptom is that, on a computer with an analog audio output jack
that has incorrect jack sense (a hardware bug), audio output is completely muted until I physically replug the cable, even though I specified "model=no-jd" as an argument to the snd-hda-intel kernel module, which is supposed to cause the kernel to ignore the jack sense reported by hardware and just drive the audio output even if the hardware jack sense indicates nothing is plugged in. This problem did not occur until approximate Linux 3.9-rc1.
I have found a few single line workarounds that work, of which my favorite is the following (also attached to this email, in case any mailer subjects this message to reformatting), because it does not add code to anything that gets called frequently.
sound/pci/hda/hda_jack.c 2014-09-10 18:41:53.422900040 -0700 renamed from sound/pci/hda/hda_jack.c.orig 2014-09-07 16:09:43.000000000 -0700 +1 -0
@@ -106,6 +106,7 @@ snd_hda_jack_tbl_new(struct hda_codec *c jack->nid = nid; jack->jack_dirty = 1; jack->tag = codec->jacktbl.used; + jack->phantom_jack = codec->no_jack_detect; return jack; } EXPORT_SYMBOL_GPL(snd_hda_jack_tbl_new);
I consider this a workaround rather than than a perfect fix, because I think the underlying problem seems to be some kind of initialization order issue that I don't fully understand. Basically, by the time jack->phantom_jack was being set, some caller had already called jack_detect_update(), which loaded the incorrect jack sense result from hardware and cleared jack->jack_dirty, so the jack sense would not be set again. At least that is what I think the underlying problem probably is.
Also, if a change like this is to be integrated, I'd like to know if it might be better for the line that I added to be:
jack->phantom_jack = !is_jack_detectable(codec, nid);
...which is what add_jack_kctl does (not sure why add_jack_kctls does not, by the way, at the risk of making a spectacle of my ignorance). My doubt about this approach is that perhaps is_jack_detectable() relies on some initialization that has not occurred at that point.
Anyhow, I'd like to get the process started of either pushing this change upstream or quickly developing a more correct fix. If a more correct fix does not become apparent in the next few days, I would recommend pushing the workaround upstream now until some future code cleanup, so people will no longer be effected by the bug.
Any technical input or advice on how to proceed is welcome. Thanks for taking the time to consider this.
Adam Richter
sound/pci/hda/hda_jack.c renamed from sound/pci/hda/hda_jack.c.orig +1 -0
@@ -106,6 +106,7 @@ snd_hda_jack_tbl_new(struct hda_codec *c jack->nid = nid; jack->jack_dirty =1 ; jack->tag = codec->jacktbl.used; + jack->phantom_jack = codec->no_jack_detect;return jack; }EXPORT_SYMBOL_GPL (snd_hda_jack_tbl_new);
At Thu, 11 Sep 2014 00:47:19 -0700,
Quoted 53 lines · Adam Richter
Hi.
This is a bug and suggested temporary fix that I originally posted to the linux-sound mailing list about a month and a half ago. I am grateful to Takashi Awai for informing me after my follow-up inquiry about it today that I should submit it to the alsa-devel mailing list instead. Please feel free to redirect me further if appropriate. I did not notice any contact information for
sound/pci/hdain linux-3.16-rc4/MAINATINERS.Anyhow, here is the bug report and a one line proposed temporary fix.
The "model=no-jd" argument has not initialized the analog audio output jack correctly for me since linux-3.9-rc1 (if I recall correctly) through linux-3.17-rc4, although I have not tried every release candidate in between.
The symptom is that, on a computer with an analog audio output jack
that has incorrect jack sense (a hardware bug), audio output is completely muted until I physically replug the cable, even though I specified "model=no-jd" as an argument to the snd-hda-intel kernel module, which is supposed to cause the kernel to ignore the jack sense reported by hardware and just drive the audio output even if the hardware jack sense indicates nothing is plugged in. This problem did not occur until approximate Linux 3.9-rc1.I have found a few single line workarounds that work, of which my favorite is the following (also attached to this email, in case any mailer subjects this message to reformatting), because it does not add code to anything that gets called frequently.
sound/pci/hda/hda_jack.c 2014-09-10 18:41:53.422900040 -0700 renamed from sound/pci/hda/hda_jack.c.orig 2014-09-07 16:09:43.000000000 -0700 +1
-0@@ -106,6 +106,7 @@ snd_hda_jack_tbl_new(struct hda_codec *c jack->nid = nid; jack->jack_dirty = 1; jack->tag = codec->jacktbl.used; + jack->phantom_jack = codec->no_jack_detect; return jack; } EXPORT_SYMBOL_GPL(snd_hda_jack_tbl_new);Signed-off-by Adam J. Richter <[email protected]>I consider this a workaround rather than than a perfect fix, because I think the underlying problem seems to be some kind of initialization order issue that I don't fully understand. Basically, by the time
jack->phantom_jackwas being set, some caller had already calledjack_detect_update(), which loaded the incorrect jack sense result from hardware and clearedjack->jack_dirty, so the jack sense would not be set again. At least that is what I think the underlying problem probably is.Also, if a change like this is to be integrated, I'd like to know if it might be better for the line that I added to be:
jack->phantom_jack = !is_jack_detectable(codec, nid);...which is what
add_jack_kctldoes (not sure whyadd_jack_kctlsdoes not, by the way, at the risk of making a spectacle of my ignorance). My doubt about this approach is that perhapsis_jack_detectable()relies on some initialization that has not occurred at that point.
Quoted 8 lines
Anyhow, I'd like to get the process started of either pushing this change upstream or quickly developing a more correct fix. If a more correct fix does not become apparent in the next few days, I would recommend pushing the workaround upstream now until some future code cleanup, so people will no longer be effected by the bug.
Any technical input or advice on how to proceed is welcome. Thanks for taking the time to consider this.
Could you give alsa-info.sh output on your machine? Otherwise it's difficult to analyze.
Speaking of your patch: add_jack_kctl() itself has a check of is_jack_detectable() for phantom jacks, so basically this shouldn't make any difference. So we need to check more deeply why this change is really needed.
thanks,
Takashi
Quoted 17 lines
Adam Richter
sound/pci/hda/hda_jack.c renamed from sound/pci/hda/hda_jack.c.orig +1
-0@@ -106,6 +106,7 @@ snd_hda_jack_tbl_new(struct hda_codec *c jack->nid = nid; jack->jack_dirty =1 ; jack->tag = codec->jacktbl.used; + jack->phantom_jack = codec->no_jack_detect;return jack; }EXPORT_SYMBOL_GPL (snd_hda_jack_tbl_new);_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Quoted 1 line · Adam Richter
Hi.
Hi Adam,
Interesting problem. Could you submit alsa-info ( http://www.alsa-project.org/alsa-info.sh ) and point us to it? It makes it possible to run the code in an emulator.
Quoted 7 lines
This is a bug and suggested temporary fix that I originally posted to the linux-sound mailing list about a month and a half ago. I am grateful to Takashi Awai for informing me after my follow-up inquiry about it today that I should submit it to the alsa-devel mailing list instead. Please feel free to redirect me further if appropriate. I did not notice any contact information for
sound/pci/hdain linux-3.16-rc4/MAINATINERS.Anyhow, here is the bug report and a one line proposed temporary fix.
The "model=no-jd" argument has not initialized the analog audio output jack correctly for me since linux-3.9-rc1 (if I recall correctly) through linux-3.17-rc4, although I have not tried every release candidate in between.
A lot of things changed with 3.9, so that makes sense. Btw, "model=no-jd" works only for specific machines. You can use the hint "jack-detect=0" instead.
Quoted 32 lines
The symptom is that, on a computer with an analog audio output jack
that has incorrect jack sense (a hardware bug), audio output is completely muted until I physically replug the cable, even though I specified "model=no-jd" as an argument to the snd-hda-intel kernel module, which is supposed to cause the kernel to ignore the jack sense reported by hardware and just drive the audio output even if the hardware jack sense indicates nothing is plugged in. This problem did not occur until approximate Linux 3.9-rc1.I have found a few single line workarounds that work, of which my favorite is the following (also attached to this email, in case any mailer subjects this message to reformatting), because it does not add code to anything that gets called frequently.
sound/pci/hda/hda_jack.c 2014-09-10 18:41:53.422900040 -0700 renamed from sound/pci/hda/hda_jack.c.orig 2014-09-07 16:09:43.000000000 -0700 +1
-0@@ -106,6 +106,7 @@ snd_hda_jack_tbl_new(struct hda_codec *c jack->nid = nid; jack->jack_dirty = 1; jack->tag = codec->jacktbl.used; + jack->phantom_jack = codec->no_jack_detect; return jack; } EXPORT_SYMBOL_GPL(snd_hda_jack_tbl_new);Signed-off-by Adam J. Richter <[email protected]>I consider this a workaround rather than than a perfect fix, because I think the underlying problem seems to be some kind of initialization order issue that I don't fully understand. Basically, by the time
jack->phantom_jackwas being set, some caller had already calledjack_detect_update(), which loaded the incorrect jack sense result from hardware and clearedjack->jack_dirty, so the jack sense would not be set again. At least that is what I think the underlying problem probably is.
Quoted 4 lines
Also, if a change like this is to be integrated, I'd like to know if it might be better for the line that I added to be:
jack->phantom_jack = !is_jack_detectable(codec, nid);
Yes, this would probably be better.
I guess that somehow snd_hda_jack_enable_callback gets called for the phantom jack, but I'm not sure exactly how (alsa-info would help).
Nevertheless I'm attaching a patch. I assume it also resolves your problem?
Takashi, what do you think of the attached patch?
Quoted 25 lines
...which is what
add_jack_kctldoes (not sure whyadd_jack_kctlsdoes not, by the way, at the risk of making a spectacle of my ignorance). My doubt about this approach is that perhapsis_jack_detectable()relies on some initialization that has not occurred at that point.Anyhow, I'd like to get the process started of either pushing this change upstream or quickly developing a more correct fix. If a more correct fix does not become apparent in the next few days, I would recommend pushing the workaround upstream now until some future code cleanup, so people will no longer be effected by the bug.
Any technical input or advice on how to proceed is welcome. Thanks for taking the time to consider this.
Adam Richter
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Signature · 2 lines
David Henningsson, Canonical Ltd. https://launchpad.net/~diwic
Quoted 1 line
From
e5ce94c6156d1c588f29745ade06d1d76c87a0a1Mon Sep 17 00:00:00 2001
From: David Henningsson <[email protected]>
Date: Thu, 11 Sep 2014 11:04:42 +0200
Subject: [PATCH] ALSA: hda - Do not enable unsol events on phantom jacks
To make sure we don't enable unsol events on phantom jacks, we move the logic for determining what a phantom jack is to snd_hda_jack_tbl_new.
--- sound/pci/hda/hda_jack.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-)
sound/pci/hda/hda_jack.c +19 -16
@@ -105,6 +105,12 @@ snd_hda_jack_tbl_new(struct hda_codec *codec, hda_nid_t nid)return NULL ; jack->nid = nid; jack->jack_dirty =1 ; +if (get_wcaps_type (get_wcaps (codec, nid)) ==AC_WID_PIN ) { +unsigned int def_conf =snd_hda_codec_get_pincfg (codec, nid); +unsigned int conn =get_defcfg_connect (def_conf); +if ((conn !=AC_JACK_PORT_COMPLEX ) || !is_jack_detectable (codec, nid)) + jack->phantom_jack =1 ; + } jack->tag = codec->jacktbl.used;return jack; }
@@ -230,6 +236,8 @@ int snd_hda_jack_detect_enable_callback(struct hda_codec *codec, hda_nid_t nid, jack->action = action;if (cb) jack->callback = cb; +if (jack->phantom_jack) +return 0 ;if (codec->jackpoll_interval >0 )return 0 ;/* No unsol if we're polling instead */ return snd_hda_codec_write_cache(codec, nid, 0,
@@ -334,8 +342,8 @@ static void hda_free_jack_priv(struct snd_jack *jack)* This assigns a jack-detection kctl to the given pin. The kcontrol * will have the given name and index. */ -static int __snd_hda_jack_add_kctl (struct hda_codec *codec,hda_nid_t nid, -const char *name,int idx,bool phantom_jack) +int snd_hda_jack_add_kctl (struct hda_codec *codec,hda_nid_t nid, +const char *name,int idx) {struct hda_jack_tbl *jack;struct snd_kcontrol *kctl;
@@ -353,12 +361,11 @@ static int __snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid,if (err <0 )return err; jack->kctl = kctl; - jack->phantom_jack = !!phantom_jack; state =snd_hda_jack_detect (codec, nid);snd_kctl_jack_report (codec->bus->card, kctl, state);#ifdef CONFIG_SND_HDA_INPUT_JACK -if (!phantom_jack) { +if (!jack->phantom_jack) { jack->type =get_input_jack_type (codec, nid); err =snd_jack_new (codec->bus->card, name, jack->type, &jack->jack);
@@ -371,12 +378,6 @@ static int __snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid,#endif return 0 ; } - -int snd_hda_jack_add_kctl (struct hda_codec *codec,hda_nid_t nid, -const char *name,int idx) -{ -return __snd_hda_jack_add_kctl (codec, nid, name, idx, false); -}EXPORT_SYMBOL_GPL (snd_hda_jack_add_kctl);/* get the unique index number for the given kctl name */
@@ -406,7 +407,7 @@ static int add_jack_kctl(struct hda_codec *codec, hda_nid_t nid,unsigned int def_conf, conn;char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN ];int idx, err; -bool phantom_jack; +struct hda_jack_tbl *jack;if (!nid)return 0 ;
@@ -414,23 +415,25 @@ static int add_jack_kctl(struct hda_codec *codec, hda_nid_t nid, conn =get_defcfg_connect (def_conf);if (conn ==AC_JACK_PORT_NONE )return 0 ; - phantom_jack = (conn !=AC_JACK_PORT_COMPLEX ) || - !is_jack_detectable (codec, nid);if (base_name) {strlcpy (name, base_name,sizeof (name)); idx =0 ; }else snd_hda_get_pin_label (codec, nid, cfg, name,sizeof (name), &idx); -if (phantom_jack) + + jack =snd_hda_jack_tbl_new (codec, nid); +if (!jack) +return -ENOMEM ; +if (jack->phantom_jack)/* Example final name: "Internal Mic Phantom Jack" */ strncat (name," Phantom" ,sizeof (name) -strlen (name) -1 ); idx =get_unique_index (codec, name, idx); - err =__snd_hda_jack_add_kctl (codec, nid, name, idx, phantom_jack); + err =snd_hda_jack_add_kctl (codec, nid, name, idx);if (err <0 )return err; -if (!phantom_jack) +if (!jack->phantom_jack)return snd_hda_jack_detect_enable (codec, nid,0 );return 0 ; }
Signature · 1 line
1.9.1
At Thu, 11 Sep 2014 11:07:10 +0200,
Quoted 63 lines · David Henningsson
Quoted 1 line · Adam Richter
Hi.
Hi Adam,
Interesting problem. Could you submit alsa-info (
http://www.alsa-project.org/alsa-info.sh ) and point us to it? It makes it possible to run the code in an emulator.Quoted 7 lines
This is a bug and suggested temporary fix that I originally posted to the linux-sound mailing list about a month and a half ago. I am grateful to Takashi Awai for informing me after my follow-up inquiry about it today that I should submit it to the alsa-devel mailing list instead. Please feel free to redirect me further if appropriate. I did not notice any contact information for
sound/pci/hdain linux-3.16-rc4/MAINATINERS.Anyhow, here is the bug report and a one line proposed temporary fix.
The "model=no-jd" argument has not initialized the analog audio output jack correctly for me since linux-3.9-rc1 (if I recall correctly) through linux-3.17-rc4, although I have not tried every release candidate in between.
A lot of things changed with 3.9, so that makes sense. Btw, "model=no-jd" works only for specific machines. You can use the hint "jack-detect=0" instead.
Quoted 32 lines
The symptom is that, on a computer with an analog audio output jack
that has incorrect jack sense (a hardware bug), audio output is completely muted until I physically replug the cable, even though I specified "model=no-jd" as an argument to the snd-hda-intel kernel module, which is supposed to cause the kernel to ignore the jack sense reported by hardware and just drive the audio output even if the hardware jack sense indicates nothing is plugged in. This problem did not occur until approximate Linux 3.9-rc1.I have found a few single line workarounds that work, of which my favorite is the following (also attached to this email, in case any mailer subjects this message to reformatting), because it does not add code to anything that gets called frequently.
sound/pci/hda/hda_jack.c 2014-09-10 18:41:53.422900040 -0700 renamed from sound/pci/hda/hda_jack.c.orig 2014-09-07 16:09:43.000000000 -0700 +1
-0@@ -106,6 +106,7 @@ snd_hda_jack_tbl_new(struct hda_codec *c jack->nid = nid; jack->jack_dirty = 1; jack->tag = codec->jacktbl.used; + jack->phantom_jack = codec->no_jack_detect; return jack; } EXPORT_SYMBOL_GPL(snd_hda_jack_tbl_new);Signed-off-by Adam J. Richter <[email protected]>I consider this a workaround rather than than a perfect fix, because I think the underlying problem seems to be some kind of initialization order issue that I don't fully understand. Basically, by the time
jack->phantom_jackwas being set, some caller had already calledjack_detect_update(), which loaded the incorrect jack sense result from hardware and clearedjack->jack_dirty, so the jack sense would not be set again. At least that is what I think the underlying problem probably is.Quoted 4 lines
Also, if a change like this is to be integrated, I'd like to know if it might be better for the line that I added to be:
jack->phantom_jack = !is_jack_detectable(codec, nid);Yes, this would probably be better.
Quoted 6 lines
I guess that somehow
snd_hda_jack_enable_callbackgets called for the phantom jack, but I'm not sure exactly how (alsa-info would help).Nevertheless I'm attaching a patch. I assume it also resolves your problem?
Takashi, what do you think of the attached patch?
I'd comment only after I see alsa-info.sh output. The patch above just makes it phantom without changing the name suffix, which looks bogus. So, I prefer fixing in a better way.
Of course, more important to know why it happens and how.
Takashi
At Thu, 11 Sep 2014 11:07:10 +0200,
Quoted 63 lines · David Henningsson
Quoted 1 line · Adam Richter
Hi.
Hi Adam,
Interesting problem. Could you submit alsa-info (
http://www.alsa-project.org/alsa-info.sh ) and point us to it? It makes it possible to run the code in an emulator.Quoted 7 lines
This is a bug and suggested temporary fix that I originally posted to the linux-sound mailing list about a month and a half ago. I am grateful to Takashi Awai for informing me after my follow-up inquiry about it today that I should submit it to the alsa-devel mailing list instead. Please feel free to redirect me further if appropriate. I did not notice any contact information for
sound/pci/hdain linux-3.16-rc4/MAINATINERS.Anyhow, here is the bug report and a one line proposed temporary fix.
The "model=no-jd" argument has not initialized the analog audio output jack correctly for me since linux-3.9-rc1 (if I recall correctly) through linux-3.17-rc4, although I have not tried every release candidate in between.
A lot of things changed with 3.9, so that makes sense. Btw, "model=no-jd" works only for specific machines. You can use the hint "jack-detect=0" instead.
Quoted 32 lines
The symptom is that, on a computer with an analog audio output jack
that has incorrect jack sense (a hardware bug), audio output is completely muted until I physically replug the cable, even though I specified "model=no-jd" as an argument to the snd-hda-intel kernel module, which is supposed to cause the kernel to ignore the jack sense reported by hardware and just drive the audio output even if the hardware jack sense indicates nothing is plugged in. This problem did not occur until approximate Linux 3.9-rc1.I have found a few single line workarounds that work, of which my favorite is the following (also attached to this email, in case any mailer subjects this message to reformatting), because it does not add code to anything that gets called frequently.
sound/pci/hda/hda_jack.c 2014-09-10 18:41:53.422900040 -0700 renamed from sound/pci/hda/hda_jack.c.orig 2014-09-07 16:09:43.000000000 -0700 +1
-0@@ -106,6 +106,7 @@ snd_hda_jack_tbl_new(struct hda_codec *c jack->nid = nid; jack->jack_dirty = 1; jack->tag = codec->jacktbl.used; + jack->phantom_jack = codec->no_jack_detect; return jack; } EXPORT_SYMBOL_GPL(snd_hda_jack_tbl_new);Signed-off-by Adam J. Richter <[email protected]>I consider this a workaround rather than than a perfect fix, because I think the underlying problem seems to be some kind of initialization order issue that I don't fully understand. Basically, by the time
jack->phantom_jackwas being set, some caller had already calledjack_detect_update(), which loaded the incorrect jack sense result from hardware and clearedjack->jack_dirty, so the jack sense would not be set again. At least that is what I think the underlying problem probably is.Quoted 4 lines
Also, if a change like this is to be integrated, I'd like to know if it might be better for the line that I added to be:
jack->phantom_jack = !is_jack_detectable(codec, nid);Yes, this would probably be better.
Quoted 6 lines
I guess that somehow
snd_hda_jack_enable_callbackgets called for the phantom jack, but I'm not sure exactly how (alsa-info would help).Nevertheless I'm attaching a patch. I assume it also resolves your problem?
Takashi, what do you think of the attached patch?
Ah, "attached" was meant *your* attached patch. Let me see...
Quoted 20 lines
From
e5ce94c6156d1c588f29745ade06d1d76c87a0a1Mon Sep 17 00:00:00 2001
From: David Henningsson <[email protected]>
Date: Thu, 11 Sep 2014 11:04:42 +0200
Subject: [PATCH] ALSA: hda - Do not enable unsol events on phantom jacksTo make sure we don't enable unsol events on phantom jacks, we move the logic for determining what a phantom jack is to
snd_hda_jack_tbl_new.Reported-by Adam Richter <[email protected]>Signed-off-by David Henningsson <[email protected]>--- sound/pci/hda/hda_jack.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-)sound/pci/hda/hda_jack.c +0
-0
sound/pci/hda/hda_jack.c snd_hda_jack_tbl_new(struct hda_codec *codec, hda_nid_t nid) · line 113
Quoted 9 lines
sound/pci/hda/hda_jack.c +6
-0@@ -105,6 +105,12 @@ snd_hda_jack_tbl_new(struct hda_codec *codec, hda_nid_t nid)return NULL ; jack->nid = nid; jack->jack_dirty =1 ; +if (get_wcaps_type (get_wcaps (codec, nid)) ==AC_WID_PIN ) { +unsigned int def_conf =snd_hda_codec_get_pincfg (codec, nid); +unsigned int conn =get_defcfg_connect (def_conf); +if ((conn !=AC_JACK_PORT_COMPLEX ) || !is_jack_detectable (codec, nid)) + jack->phantom_jack =1 ; + }
This doesn't look good. The pincfg isn't always reliable at this point. The pin connection check is used in add_jack_kctl() in the current code just because its only caller is snd_hda_jack_add_kctls(), which takes the pincfg explicitly. But snd_hda_jakc_tbl_new() itself is neutral about the pincfg.
And, another problem is that it'll result in a phantom jack secretly without adding a proper name suffix.
In anyway, for catching such a bug, maybe we should put a WARN_ON() at snd_hda_jack_detect_enable_callback() like the patch below.
Takashi
--
sound/pci/hda/hda_jack.c +2 -0
@@ -225,6 +225,8 @@ int snd_hda_jack_detect_enable_callback(struct hda_codec *codec, hda_nid_t nid,return -ENOMEM ;if (jack->jack_detect)return 0 ;/* already registered */ +if (WARN_ON (!is_jack_detectable (codec, nid))) +return 0 ; jack->jack_detect =1 ;if (action) jack->action = action;
Quoted 101 lines · Takashi Iwai
At Thu, 11 Sep 2014 11:07:10 +0200,
Quoted 63 lines · David Henningsson
Quoted 1 line · Adam Richter
Hi.
Hi Adam,
Interesting problem. Could you submit alsa-info (
http://www.alsa-project.org/alsa-info.sh ) and point us to it? It makes it possible to run the code in an emulator.Quoted 7 lines
This is a bug and suggested temporary fix that I originally posted to the linux-sound mailing list about a month and a half ago. I am grateful to Takashi Awai for informing me after my follow-up inquiry about it today that I should submit it to the alsa-devel mailing list instead. Please feel free to redirect me further if appropriate. I did not notice any contact information for
sound/pci/hdain linux-3.16-rc4/MAINATINERS.Anyhow, here is the bug report and a one line proposed temporary fix.
The "model=no-jd" argument has not initialized the analog audio output jack correctly for me since linux-3.9-rc1 (if I recall correctly) through linux-3.17-rc4, although I have not tried every release candidate in between.
A lot of things changed with 3.9, so that makes sense. Btw, "model=no-jd" works only for specific machines. You can use the hint "jack-detect=0" instead.
Quoted 32 lines
The symptom is that, on a computer with an analog audio output jack
that has incorrect jack sense (a hardware bug), audio output is completely muted until I physically replug the cable, even though I specified "model=no-jd" as an argument to the snd-hda-intel kernel module, which is supposed to cause the kernel to ignore the jack sense reported by hardware and just drive the audio output even if the hardware jack sense indicates nothing is plugged in. This problem did not occur until approximate Linux 3.9-rc1.I have found a few single line workarounds that work, of which my favorite is the following (also attached to this email, in case any mailer subjects this message to reformatting), because it does not add code to anything that gets called frequently.
sound/pci/hda/hda_jack.c 2014-09-10 18:41:53.422900040 -0700 renamed from sound/pci/hda/hda_jack.c.orig 2014-09-07 16:09:43.000000000 -0700 +1
-0@@ -106,6 +106,7 @@ snd_hda_jack_tbl_new(struct hda_codec *c jack->nid = nid; jack->jack_dirty = 1; jack->tag = codec->jacktbl.used; + jack->phantom_jack = codec->no_jack_detect; return jack; } EXPORT_SYMBOL_GPL(snd_hda_jack_tbl_new);Signed-off-by Adam J. Richter <[email protected]>I consider this a workaround rather than than a perfect fix, because I think the underlying problem seems to be some kind of initialization order issue that I don't fully understand. Basically, by the time
jack->phantom_jackwas being set, some caller had already calledjack_detect_update(), which loaded the incorrect jack sense result from hardware and clearedjack->jack_dirty, so the jack sense would not be set again. At least that is what I think the underlying problem probably is.Quoted 4 lines
Also, if a change like this is to be integrated, I'd like to know if it might be better for the line that I added to be:
jack->phantom_jack = !is_jack_detectable(codec, nid);Yes, this would probably be better.
Quoted 6 lines
I guess that somehow
snd_hda_jack_enable_callbackgets called for the phantom jack, but I'm not sure exactly how (alsa-info would help).Nevertheless I'm attaching a patch. I assume it also resolves your problem?
Takashi, what do you think of the attached patch?
Ah, "attached" was meant *your* attached patch. Let me see...
Quoted 27 lines
From
e5ce94c6156d1c588f29745ade06d1d76c87a0a1Mon Sep 17 00:00:00 2001
From: David Henningsson <[email protected]>
Date: Thu, 11 Sep 2014 11:04:42 +0200
Subject: [PATCH] ALSA: hda - Do not enable unsol events on phantom jacksTo make sure we don't enable unsol events on phantom jacks, we move the logic for determining what a phantom jack is to
snd_hda_jack_tbl_new.Reported-by Adam Richter <[email protected]>Signed-off-by David Henningsson <[email protected]>--- sound/pci/hda/hda_jack.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-)sound/pci/hda/hda_jack.c +4
-0@@ -105,6 +105,12 @@ snd_hda_jack_tbl_new(struct hda_codec *codec, hda_nid_t nid)return NULL ; jack->nid = nid; jack->jack_dirty =1 ; +if (get_wcaps_type (get_wcaps (codec, nid)) ==AC_WID_PIN ) { +unsigned int def_conf =snd_hda_codec_get_pincfg (codec, nid); +unsigned int conn =get_defcfg_connect (def_conf); +if ((conn !=AC_JACK_PORT_COMPLEX ) || !is_jack_detectable (codec, nid))
Quoted 8 lines
sound/pci/hda/hda_jack.c snd_hda_jack_tbl_new(struct hda_codec *codec, hda_nid_t nid) · line 113
Quoted 2 lines
sound/pci/hda/hda_jack.c +2
-0+ jack->phantom_jack =1 ; + }This doesn't look good. The pincfg isn't always reliable at this point. The pin connection check is used in
add_jack_kctl()in the current code just because its only caller issnd_hda_jack_add_kctls(), which takes the pincfg explicitly. Butsnd_hda_jakc_tbl_new()itself is neutral about the pincfg.
Are you saying that codec->user_pins/driver_pins/init_pins might not be properly initialized at this point? If so, maybe we should instead warn on somebody calling snd_hda_jack_tbl_new too early?
Quoted 2 lines
And, another problem is that it'll result in a phantom jack secretly without adding a proper name suffix.
Are you sure?
snd_hda_jack_add_kctl is called from add_jack_kctl and the hdmi driver.Add_jack_kctl now uses the phantom_jack flag (as initialized by jack_new) to create a proper name, i e, no difference.generic_hdmi_build_jack should probably replace its "is_jack_detectable" call to check the phantom_jack flag for consistency, but for all common cases it's no change there either.
Quoted 12 lines
In anyway, for catching such a bug, maybe we should put a
WARN_ON()atsnd_hda_jack_detect_enable_callback()like the patch below.Takashi
--
sound/pci/hda/hda_jack.c +0
-0
sound/pci/hda/hda_jack.c int snd_hda_jack_detect_enable_callback(struct hda_codec *codec, hda_nid_t nid, · line 229
Quoted 5 lines
sound/pci/hda/hda_jack.c +2
-0@@ -225,6 +225,8 @@ int snd_hda_jack_detect_enable_callback(struct hda_codec *codec, hda_nid_t nid,return -ENOMEM ;if (jack->jack_detect)return 0 ;/* already registered */ +if (WARN_ON (!is_jack_detectable (codec, nid))) +return 0 ;
Remember that enable_callback is sometimes called for non-pin nodes, such as the afg node in the sigmatel driver. Calling is_jack_detectable on non-pin nodes seems wrong to me.
Quoted 4 lines
sound/pci/hda/hda_jack.c +0
-0jack->jack_detect =1 ;if (action) jack->action = action;
Signature · 2 lines
David Henningsson, Canonical Ltd. https://launchpad.net/~diwic
At Thu, 11 Sep 2014 11:42:41 +0200,
Quoted 114 lines · David Henningsson
Quoted 101 lines · Takashi Iwai
At Thu, 11 Sep 2014 11:07:10 +0200,
Quoted 63 lines · David Henningsson
Quoted 1 line · Adam Richter
Hi.
Hi Adam,
Interesting problem. Could you submit alsa-info (
http://www.alsa-project.org/alsa-info.sh ) and point us to it? It makes it possible to run the code in an emulator.Quoted 7 lines
This is a bug and suggested temporary fix that I originally posted to the linux-sound mailing list about a month and a half ago. I am grateful to Takashi Awai for informing me after my follow-up inquiry about it today that I should submit it to the alsa-devel mailing list instead. Please feel free to redirect me further if appropriate. I did not notice any contact information for
sound/pci/hdain linux-3.16-rc4/MAINATINERS.Anyhow, here is the bug report and a one line proposed temporary fix.
The "model=no-jd" argument has not initialized the analog audio output jack correctly for me since linux-3.9-rc1 (if I recall correctly) through linux-3.17-rc4, although I have not tried every release candidate in between.
A lot of things changed with 3.9, so that makes sense. Btw, "model=no-jd" works only for specific machines. You can use the hint "jack-detect=0" instead.
Quoted 32 lines
The symptom is that, on a computer with an analog audio output jack
that has incorrect jack sense (a hardware bug), audio output is completely muted until I physically replug the cable, even though I specified "model=no-jd" as an argument to the snd-hda-intel kernel module, which is supposed to cause the kernel to ignore the jack sense reported by hardware and just drive the audio output even if the hardware jack sense indicates nothing is plugged in. This problem did not occur until approximate Linux 3.9-rc1.I have found a few single line workarounds that work, of which my favorite is the following (also attached to this email, in case any mailer subjects this message to reformatting), because it does not add code to anything that gets called frequently.
sound/pci/hda/hda_jack.c 2014-09-10 18:41:53.422900040 -0700 renamed from sound/pci/hda/hda_jack.c.orig 2014-09-07 16:09:43.000000000 -0700 +1
-0@@ -106,6 +106,7 @@ snd_hda_jack_tbl_new(struct hda_codec *c jack->nid = nid; jack->jack_dirty = 1; jack->tag = codec->jacktbl.used; + jack->phantom_jack = codec->no_jack_detect; return jack; } EXPORT_SYMBOL_GPL(snd_hda_jack_tbl_new);Signed-off-by Adam J. Richter <[email protected]>I consider this a workaround rather than than a perfect fix, because I think the underlying problem seems to be some kind of initialization order issue that I don't fully understand. Basically, by the time
jack->phantom_jackwas being set, some caller had already calledjack_detect_update(), which loaded the incorrect jack sense result from hardware and clearedjack->jack_dirty, so the jack sense would not be set again. At least that is what I think the underlying problem probably is.Quoted 4 lines
Also, if a change like this is to be integrated, I'd like to know if it might be better for the line that I added to be:
jack->phantom_jack = !is_jack_detectable(codec, nid);Yes, this would probably be better.
Quoted 6 lines
I guess that somehow
snd_hda_jack_enable_callbackgets called for the phantom jack, but I'm not sure exactly how (alsa-info would help).Nevertheless I'm attaching a patch. I assume it also resolves your problem?
Takashi, what do you think of the attached patch?
Ah, "attached" was meant *your* attached patch. Let me see...
Quoted 27 lines
From
e5ce94c6156d1c588f29745ade06d1d76c87a0a1Mon Sep 17 00:00:00 2001
From: David Henningsson <[email protected]>
Date: Thu, 11 Sep 2014 11:04:42 +0200
Subject: [PATCH] ALSA: hda - Do not enable unsol events on phantom jacksTo make sure we don't enable unsol events on phantom jacks, we move the logic for determining what a phantom jack is to
snd_hda_jack_tbl_new.Reported-by Adam Richter <[email protected]>Signed-off-by David Henningsson <[email protected]>--- sound/pci/hda/hda_jack.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-)sound/pci/hda/hda_jack.c +4
-0@@ -105,6 +105,12 @@ snd_hda_jack_tbl_new(struct hda_codec *codec, hda_nid_t nid)return NULL ; jack->nid = nid; jack->jack_dirty =1 ; +if (get_wcaps_type (get_wcaps (codec, nid)) ==AC_WID_PIN ) { +unsigned int def_conf =snd_hda_codec_get_pincfg (codec, nid); +unsigned int conn =get_defcfg_connect (def_conf); +if ((conn !=AC_JACK_PORT_COMPLEX ) || !is_jack_detectable (codec, nid))Quoted 8 lines
sound/pci/hda/hda_jack.c snd_hda_jack_tbl_new(struct hda_codec *codec, hda_nid_t nid) · line 113
Quoted 2 lines
sound/pci/hda/hda_jack.c +2
-0+ jack->phantom_jack =1 ; + }This doesn't look good. The pincfg isn't always reliable at this point. The pin connection check is used in
add_jack_kctl()in the current code just because its only caller issnd_hda_jack_add_kctls(), which takes the pincfg explicitly. Butsnd_hda_jakc_tbl_new()itself is neutral about the pincfg.
Quoted 3 lines
Are you saying that codec->user_pins/driver_pins/init_pins might not be properly initialized at this point? If so, maybe we should instead warn on somebody calling
snd_hda_jack_tbl_newtoo early?
No, the hda_jack stuff itself isn't necessarily depending on the pincfg deeply. For example, is_jack_detectable() doesn't check the pin location (although it checks MISC_NO_PRESENCE bit as an exception).
Quoted 11 lines
Quoted 2 lines
And, another problem is that it'll result in a phantom jack secretly without adding a proper name suffix.
Are you sure?
snd_hda_jack_add_kctlis called fromadd_jack_kctland the hdmi driver.Add_jack_kctlnow uses thephantom_jackflag (as initialized byjack_new) to create a proper name, i e, no difference.generic_hdmi_build_jackshould probably replace its "is_jack_detectable" call to check thephantom_jackflag for consistency, but for all common cases it's no change there either.
Hm, OK, that won't happen. But my point is that it's wrong to check the phantom flag there.
Quoted 6 lines
Quoted 6 lines
In anyway, for catching such a bug, maybe we should put a
WARN_ON()atsnd_hda_jack_detect_enable_callback()like the patch below.Takashi
Quoted 15 lines
sound/pci/hda/hda_jack.c int snd_hda_jack_detect_enable_callback(struct hda_codec *codec, hda_nid_t nid, · line 229
Quoted 11 lines
--
sound/pci/hda/hda_jack.c +2
-0@@ -225,6 +225,8 @@ int snd_hda_jack_detect_enable_callback(struct hda_codec *codec, hda_nid_t nid,return -ENOMEM ;if (jack->jack_detect)return 0 ;/* already registered */ +if (WARN_ON (!is_jack_detectable (codec, nid))) +return 0 ;Remember that
enable_callbackis sometimes called for non-pin nodes, such as the afg node in the sigmatel driver. Callingis_jack_detectableon non-pin nodes seems wrong to me.
OK, then it's an overkill.
Looking at the alsa-info.sh output, the problem is that IDT codec parser creates jack detection for the power-control before the generic parser. There is also a wrong logic in stac_init_power_map()...
An untested fix is below.
Takashi
--
sound/pci/hda/patch_sigmatel.c +11 -5
@@ -565,8 +565,8 @@ static void stac_init_power_map(struct hda_codec *codec)if (snd_hda_jack_tbl_get (codec, nid))continue ;if (def_conf ==AC_JACK_PORT_COMPLEX && - !(spec->vref_mute_led_nid == nid || -is_jack_detectable (codec, nid))) { + spec->vref_mute_led_nid != nid && +is_jack_detectable (codec, nid)) {snd_hda_jack_detect_enable_callback (codec, nid,STAC_PWR_EVENT , jack_update_power);
@@ -4272,11 +4272,17 @@ static int stac_parse_auto_config(struct hda_codec *codec)return err; } -stac_init_power_map (codec); -return 0 ; } +static int stac_build_controls (struct hda_codec *codec) +{ +int err =snd_hda_gen_build_controls (codec); +if (err <0 ) +return err; +stac_init_power_map (codec); +return 0 ; +}static int stac_init (struct hda_codec *codec) {
@@ -4388,7 +4394,7 @@ static int stac_suspend(struct hda_codec *codec)#endif /* CONFIG_PM */ static const struct hda_codec_ops stac_patch_ops = { - .build_controls = snd_hda_gen_build_controls, + .build_controls = stac_build_controls, .build_pcms = snd_hda_gen_build_pcms, .init = stac_init, .free = stac_free,
Quoted 116 lines · Takashi Iwai
At Thu, 11 Sep 2014 11:42:41 +0200,
Quoted 114 lines · David Henningsson
Quoted 109 lines · Takashi Iwai
At Thu, 11 Sep 2014 11:07:10 +0200,
Quoted 63 lines · David Henningsson
Quoted 1 line · Adam Richter
Hi.
Hi Adam,
Interesting problem. Could you submit alsa-info (
http://www.alsa-project.org/alsa-info.sh ) and point us to it? It makes it possible to run the code in an emulator.Quoted 7 lines
This is a bug and suggested temporary fix that I originally posted to the linux-sound mailing list about a month and a half ago. I am grateful to Takashi Awai for informing me after my follow-up inquiry about it today that I should submit it to the alsa-devel mailing list instead. Please feel free to redirect me further if appropriate. I did not notice any contact information for
sound/pci/hdain linux-3.16-rc4/MAINATINERS.Anyhow, here is the bug report and a one line proposed temporary fix.
The "model=no-jd" argument has not initialized the analog audio output jack correctly for me since linux-3.9-rc1 (if I recall correctly) through linux-3.17-rc4, although I have not tried every release candidate in between.
A lot of things changed with 3.9, so that makes sense. Btw, "model=no-jd" works only for specific machines. You can use the hint "jack-detect=0" instead.
Quoted 32 lines
The symptom is that, on a computer with an analog audio output jack
that has incorrect jack sense (a hardware bug), audio output is completely muted until I physically replug the cable, even though I specified "model=no-jd" as an argument to the snd-hda-intel kernel module, which is supposed to cause the kernel to ignore the jack sense reported by hardware and just drive the audio output even if the hardware jack sense indicates nothing is plugged in. This problem did not occur until approximate Linux 3.9-rc1.I have found a few single line workarounds that work, of which my favorite is the following (also attached to this email, in case any mailer subjects this message to reformatting), because it does not add code to anything that gets called frequently.
sound/pci/hda/hda_jack.c 2014-09-10 18:41:53.422900040 -0700 renamed from sound/pci/hda/hda_jack.c.orig 2014-09-07 16:09:43.000000000 -0700 +1
-0@@ -106,6 +106,7 @@ snd_hda_jack_tbl_new(struct hda_codec *c jack->nid = nid; jack->jack_dirty = 1; jack->tag = codec->jacktbl.used; + jack->phantom_jack = codec->no_jack_detect; return jack; } EXPORT_SYMBOL_GPL(snd_hda_jack_tbl_new);Signed-off-by Adam J. Richter <[email protected]>I consider this a workaround rather than than a perfect fix, because I think the underlying problem seems to be some kind of initialization order issue that I don't fully understand. Basically, by the time
jack->phantom_jackwas being set, some caller had already calledjack_detect_update(), which loaded the incorrect jack sense result from hardware and clearedjack->jack_dirty, so the jack sense would not be set again. At least that is what I think the underlying problem probably is.Quoted 4 lines
Also, if a change like this is to be integrated, I'd like to know if it might be better for the line that I added to be:
jack->phantom_jack = !is_jack_detectable(codec, nid);Yes, this would probably be better.
Quoted 6 lines
I guess that somehow
snd_hda_jack_enable_callbackgets called for the phantom jack, but I'm not sure exactly how (alsa-info would help).Nevertheless I'm attaching a patch. I assume it also resolves your problem?
Takashi, what do you think of the attached patch?
Ah, "attached" was meant *your* attached patch. Let me see...
Quoted 20 lines
From
e5ce94c6156d1c588f29745ade06d1d76c87a0a1Mon Sep 17 00:00:00 2001
From: David Henningsson <[email protected]>
Date: Thu, 11 Sep 2014 11:04:42 +0200
Subject: [PATCH] ALSA: hda - Do not enable unsol events on phantom jacksTo make sure we don't enable unsol events on phantom jacks, we move the logic for determining what a phantom jack is to
snd_hda_jack_tbl_new.Reported-by Adam Richter <[email protected]>Signed-off-by David Henningsson <[email protected]>--- sound/pci/hda/hda_jack.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-)sound/pci/hda/hda_jack.c +0
-0sound/pci/hda/hda_jack.c snd_hda_jack_tbl_new(struct hda_codec *codec, hda_nid_t nid) · line 113
Quoted 9 lines
sound/pci/hda/hda_jack.c +6
-0@@ -105,6 +105,12 @@ snd_hda_jack_tbl_new(struct hda_codec *codec, hda_nid_t nid)return NULL ; jack->nid = nid; jack->jack_dirty =1 ; +if (get_wcaps_type (get_wcaps (codec, nid)) ==AC_WID_PIN ) { +unsigned int def_conf =snd_hda_codec_get_pincfg (codec, nid); +unsigned int conn =get_defcfg_connect (def_conf); +if ((conn !=AC_JACK_PORT_COMPLEX ) || !is_jack_detectable (codec, nid)) + jack->phantom_jack =1 ; + }This doesn't look good. The pincfg isn't always reliable at this point. The pin connection check is used in
add_jack_kctl()in the current code just because its only caller issnd_hda_jack_add_kctls(), which takes the pincfg explicitly. Butsnd_hda_jakc_tbl_new()itself is neutral about the pincfg.
Quoted 8 lines
Quoted 3 lines
Are you saying that codec->user_pins/driver_pins/init_pins might not be properly initialized at this point? If so, maybe we should instead warn on somebody calling
snd_hda_jack_tbl_newtoo early?No, the
hda_jackstuff itself isn't necessarily depending on the pincfg deeply. For example,is_jack_detectable()doesn't check the pin location (although it checksMISC_NO_PRESENCEbit as an exception).
Is there a good reason why the hda_jack stuff should not depend on pincfg?
Also, if we keep the detection in snd_hda_jack_tbl_new, we could change all other calls to is_jack_detectable to !jack->phantom_jack instead.
Quoted 37 lines
Quoted 11 lines
Quoted 2 lines
And, another problem is that it'll result in a phantom jack secretly without adding a proper name suffix.
Are you sure?
snd_hda_jack_add_kctlis called fromadd_jack_kctland the hdmi driver.Add_jack_kctlnow uses thephantom_jackflag (as initialized byjack_new) to create a proper name, i e, no difference.generic_hdmi_build_jackshould probably replace its "is_jack_detectable" call to check thephantom_jackflag for consistency, but for all common cases it's no change there either.Hm, OK, that won't happen. But my point is that it's wrong to check the phantom flag there.
Quoted 6 lines
Quoted 6 lines
In anyway, for catching such a bug, maybe we should put a
WARN_ON()atsnd_hda_jack_detect_enable_callback()like the patch below.Takashi
Quoted 15 lines
sound/pci/hda/hda_jack.c int snd_hda_jack_detect_enable_callback(struct hda_codec *codec, hda_nid_t nid, · line 229
Quoted 11 lines
--
sound/pci/hda/hda_jack.c +2
-0@@ -225,6 +225,8 @@ int snd_hda_jack_detect_enable_callback(struct hda_codec *codec, hda_nid_t nid,return -ENOMEM ;if (jack->jack_detect)return 0 ;/* already registered */ +if (WARN_ON (!is_jack_detectable (codec, nid))) +return 0 ;Remember that
enable_callbackis sometimes called for non-pin nodes, such as the afg node in the sigmatel driver. Callingis_jack_detectableon non-pin nodes seems wrong to me.
Quoted 7 lines
OK, then it's an overkill.
Looking at the
alsa-info.shoutput, the problem is that IDT codec parser creates jack detection for the power-control before the generic parser. There is also a wrong logic instac_init_power_map()...An untested fix is below.
Did you get any alsa-info output from Adam? Maybe he sent it privately to you.
Quoted 54 lines
Takashi
--
sound/pci/hda/patch_sigmatel.c +11
-5@@ -565,8 +565,8 @@ static void stac_init_power_map(struct hda_codec *codec)if (snd_hda_jack_tbl_get (codec, nid))continue ;if (def_conf ==AC_JACK_PORT_COMPLEX && - !(spec->vref_mute_led_nid == nid || -is_jack_detectable (codec, nid))) { + spec->vref_mute_led_nid != nid && +is_jack_detectable (codec, nid)) {snd_hda_jack_detect_enable_callback (codec, nid,STAC_PWR_EVENT , jack_update_power);@@ -4272,11 +4272,17 @@ static int stac_parse_auto_config(struct hda_codec *codec)return err; } -stac_init_power_map (codec); -return 0 ; } +static int stac_build_controls (struct hda_codec *codec) +{ +int err =snd_hda_gen_build_controls (codec); +if (err <0 ) +return err; +stac_init_power_map (codec); +return 0 ; +}static int stac_init (struct hda_codec *codec) {@@ -4388,7 +4394,7 @@ static int stac_suspend(struct hda_codec *codec)#endif /* CONFIG_PM */ static const struct hda_codec_ops stac_patch_ops = { - .build_controls = snd_hda_gen_build_controls, + .build_controls = stac_build_controls, .build_pcms = snd_hda_gen_build_pcms, .init = stac_init, .free = stac_free,_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Signature · 2 lines
David Henningsson, Canonical Ltd. https://launchpad.net/~diwic
At Thu, 11 Sep 2014 12:29:09 +0200,
Quoted 124 lines · David Henningsson
Quoted 120 lines · Takashi Iwai
At Thu, 11 Sep 2014 11:42:41 +0200,
Quoted 117 lines · David Henningsson
Quoted 101 lines · Takashi Iwai
At Thu, 11 Sep 2014 11:07:10 +0200,
Quoted 63 lines · David Henningsson
Quoted 1 line · Adam Richter
Hi.
Hi Adam,
Interesting problem. Could you submit alsa-info (
http://www.alsa-project.org/alsa-info.sh ) and point us to it? It makes it possible to run the code in an emulator.Quoted 7 lines
This is a bug and suggested temporary fix that I originally posted to the linux-sound mailing list about a month and a half ago. I am grateful to Takashi Awai for informing me after my follow-up inquiry about it today that I should submit it to the alsa-devel mailing list instead. Please feel free to redirect me further if appropriate. I did not notice any contact information for
sound/pci/hdain linux-3.16-rc4/MAINATINERS.Anyhow, here is the bug report and a one line proposed temporary fix.
The "model=no-jd" argument has not initialized the analog audio output jack correctly for me since linux-3.9-rc1 (if I recall correctly) through linux-3.17-rc4, although I have not tried every release candidate in between.
A lot of things changed with 3.9, so that makes sense. Btw, "model=no-jd" works only for specific machines. You can use the hint "jack-detect=0" instead.
Quoted 32 lines
The symptom is that, on a computer with an analog audio output jack
that has incorrect jack sense (a hardware bug), audio output is completely muted until I physically replug the cable, even though I specified "model=no-jd" as an argument to the snd-hda-intel kernel module, which is supposed to cause the kernel to ignore the jack sense reported by hardware and just drive the audio output even if the hardware jack sense indicates nothing is plugged in. This problem did not occur until approximate Linux 3.9-rc1.I have found a few single line workarounds that work, of which my favorite is the following (also attached to this email, in case any mailer subjects this message to reformatting), because it does not add code to anything that gets called frequently.
sound/pci/hda/hda_jack.c 2014-09-10 18:41:53.422900040 -0700 renamed from sound/pci/hda/hda_jack.c.orig 2014-09-07 16:09:43.000000000 -0700 +1
-0@@ -106,6 +106,7 @@ snd_hda_jack_tbl_new(struct hda_codec *c jack->nid = nid; jack->jack_dirty = 1; jack->tag = codec->jacktbl.used; + jack->phantom_jack = codec->no_jack_detect; return jack; } EXPORT_SYMBOL_GPL(snd_hda_jack_tbl_new);Signed-off-by Adam J. Richter <[email protected]>I consider this a workaround rather than than a perfect fix, because I think the underlying problem seems to be some kind of initialization order issue that I don't fully understand. Basically, by the time
jack->phantom_jackwas being set, some caller had already calledjack_detect_update(), which loaded the incorrect jack sense result from hardware and clearedjack->jack_dirty, so the jack sense would not be set again. At least that is what I think the underlying problem probably is.Quoted 4 lines
Also, if a change like this is to be integrated, I'd like to know if it might be better for the line that I added to be:
jack->phantom_jack = !is_jack_detectable(codec, nid);Yes, this would probably be better.
Quoted 6 lines
I guess that somehow
snd_hda_jack_enable_callbackgets called for the phantom jack, but I'm not sure exactly how (alsa-info would help).Nevertheless I'm attaching a patch. I assume it also resolves your problem?
Takashi, what do you think of the attached patch?
Ah, "attached" was meant *your* attached patch. Let me see...
Quoted 27 lines
From
e5ce94c6156d1c588f29745ade06d1d76c87a0a1Mon Sep 17 00:00:00 2001
From: David Henningsson <[email protected]>
Date: Thu, 11 Sep 2014 11:04:42 +0200
Subject: [PATCH] ALSA: hda - Do not enable unsol events on phantom jacksTo make sure we don't enable unsol events on phantom jacks, we move the logic for determining what a phantom jack is to
snd_hda_jack_tbl_new.Reported-by Adam Richter <[email protected]>Signed-off-by David Henningsson <[email protected]>--- sound/pci/hda/hda_jack.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-)sound/pci/hda/hda_jack.c +4
-0@@ -105,6 +105,12 @@ snd_hda_jack_tbl_new(struct hda_codec *codec, hda_nid_t nid)return NULL ; jack->nid = nid; jack->jack_dirty =1 ; +if (get_wcaps_type (get_wcaps (codec, nid)) ==AC_WID_PIN ) { +unsigned int def_conf =snd_hda_codec_get_pincfg (codec, nid); +unsigned int conn =get_defcfg_connect (def_conf); +if ((conn !=AC_JACK_PORT_COMPLEX ) || !is_jack_detectable (codec, nid))Quoted 8 lines
sound/pci/hda/hda_jack.c snd_hda_jack_tbl_new(struct hda_codec *codec, hda_nid_t nid) · line 113
Quoted 2 lines
sound/pci/hda/hda_jack.c +2
-0+ jack->phantom_jack =1 ; + }This doesn't look good. The pincfg isn't always reliable at this point. The pin connection check is used in
add_jack_kctl()in the current code just because its only caller issnd_hda_jack_add_kctls(), which takes the pincfg explicitly. Butsnd_hda_jakc_tbl_new()itself is neutral about the pincfg.Are you saying that codec->user_pins/driver_pins/init_pins might not be properly initialized at this point? If so, maybe we should instead warn on somebody calling
snd_hda_jack_tbl_newtoo early?
Quoted 6 lines
Quoted 4 lines
No, the
hda_jackstuff itself isn't necessarily depending on the pincfg deeply. For example,is_jack_detectable()doesn't check the pin location (although it checksMISC_NO_PRESENCEbit as an exception).Is there a good reason why the
hda_jackstuff should not depend on pincfg?
Because the pincfg isn't always reliable, as you know ;)
Quoted 2 lines
Also, if we keep the detection in
snd_hda_jack_tbl_new, we could change all other calls tois_jack_detectableto !jack->phantom_jack instead.
Well, I think is_jack_detectable() is rather a helper to be moved to hda_codec.c, i.e. its functionality is independent from what else in hda_jack.c. In other words, I don't think we want to tie it with hda_jack stuff (at least in the current form of hda_jack.c infrastructure).
Quoted 39 lines
Quoted 39 lines
Quoted 11 lines
Quoted 2 lines
And, another problem is that it'll result in a phantom jack secretly without adding a proper name suffix.
Are you sure?
snd_hda_jack_add_kctlis called fromadd_jack_kctland the hdmi driver.Add_jack_kctlnow uses thephantom_jackflag (as initialized byjack_new) to create a proper name, i e, no difference.generic_hdmi_build_jackshould probably replace its "is_jack_detectable" call to check thephantom_jackflag for consistency, but for all common cases it's no change there either.Hm, OK, that won't happen. But my point is that it's wrong to check the phantom flag there.
Quoted 6 lines
Quoted 6 lines
In anyway, for catching such a bug, maybe we should put a
WARN_ON()atsnd_hda_jack_detect_enable_callback()like the patch below.Takashi
Quoted 15 lines
sound/pci/hda/hda_jack.c int snd_hda_jack_detect_enable_callback(struct hda_codec *codec, hda_nid_t nid, · line 229
Quoted 11 lines
--
sound/pci/hda/hda_jack.c +2
-0@@ -225,6 +225,8 @@ int snd_hda_jack_detect_enable_callback(struct hda_codec *codec, hda_nid_t nid,return -ENOMEM ;if (jack->jack_detect)return 0 ;/* already registered */ +if (WARN_ON (!is_jack_detectable (codec, nid))) +return 0 ;Remember that
enable_callbackis sometimes called for non-pin nodes, such as the afg node in the sigmatel driver. Callingis_jack_detectableon non-pin nodes seems wrong to me.OK, then it's an overkill.
Quoted 8 lines
Quoted 5 lines
Looking at the
alsa-info.shoutput, the problem is that IDT codec parser creates jack detection for the power-control before the generic parser. There is also a wrong logic instac_init_power_map()...An untested fix is below.
Did you get any alsa-info output from Adam? Maybe he sent it privately to you.
I guess this was blocked by the mail server due to a too big attachment...
Takashi
At Thu, 11 Sep 2014 12:07:43 +0200,
Quoted 6 lines · Takashi Iwai
Looking at the
alsa-info.shoutput, the problem is that IDT codec parser creates jack detection for the power-control before the generic parser. There is also a wrong logic instac_init_power_map()...An untested fix is below.
BTW, a part of the messes is the restriction of hda_jack stuff:
currently it supports only one callback per jack. If we can add multiple callbacks and actions to a jack, the code in patch_sigmatel.c would be come much easier. But this is a step after fixing the bug quickly.
Takashi
Quoted 49 lines
Takashi
--
sound/pci/hda/patch_sigmatel.c +11
-5@@ -565,8 +565,8 @@ static void stac_init_power_map(struct hda_codec *codec)if (snd_hda_jack_tbl_get (codec, nid))continue ;if (def_conf ==AC_JACK_PORT_COMPLEX && - !(spec->vref_mute_led_nid == nid || -is_jack_detectable (codec, nid))) { + spec->vref_mute_led_nid != nid && +is_jack_detectable (codec, nid)) {snd_hda_jack_detect_enable_callback (codec, nid,STAC_PWR_EVENT , jack_update_power);@@ -4272,11 +4272,17 @@ static int stac_parse_auto_config(struct hda_codec *codec)return err; } -stac_init_power_map (codec); -return 0 ; } +static int stac_build_controls (struct hda_codec *codec) +{ +int err =snd_hda_gen_build_controls (codec); +if (err <0 ) +return err; +stac_init_power_map (codec); +return 0 ; +}static int stac_init (struct hda_codec *codec) {@@ -4388,7 +4394,7 @@ static int stac_suspend(struct hda_codec *codec)#endif /* CONFIG_PM */ static const struct hda_codec_ops stac_patch_ops = { - .build_controls = snd_hda_gen_build_controls, + .build_controls = stac_build_controls, .build_pcms = snd_hda_gen_build_pcms, .init = stac_init, .free = stac_free,
Hi, Takashi.
I confirm that your patch, quoted below, eliminated the symptom.
Please feel free to ask me to test other patches related to this problem.
Also, by the way, it appears that linux-3.17-rc4's Intel "high defintiion audio" driver, regardless of whether this patch is applied, no longer shows Linux input subsystem devices for analog audio jack sense, although it does provide such a device for HDMI jack sense. If that's a bug, it's completely separate, but I mention it here in case it's relevant to integrating a fix to this issue.
Thanks to you and David for your prompt and careful attention this bug once I brought it to this mailing list.
Adam Richter
At Thu, 11 Sep 2014 12:07:43 +0200,
sound/pci/hda/patch_sigmatel.c static int
Quoted 17 lines · Takashi Iwai
--
sound/pci/hda/patch_sigmatel.c +0
-0@@ -565,8 +565,8 @@ static void stac_init_power_map(struct hda_codec *codec) if (snd_hda_jack_tbl_get(codec, nid)) continue;if (
def_conf==AC_JACK_PORT_COMPLEX&& - !(spec->vref_mute_led_nid == nid || -is_jack_detectable(codec, nid))) { +spec->vref_mute_led_nid!= nid &&
+is_jack_detectable(codec, nid)) { snd_hda_jack_detect_enable_callback(codec, nid,STAC_PWR_EVENT,
jack_update_power);sound/pci/hda/patch_sigmatel.c +0
-0@@ -4272,11 +4272,17 @@ static int
stac_parse_auto_config(struct hda_codec *codec)
sound/pci/hda/patch_sigmatel.c static int stac_parse_auto_config(struct hda_codec *codec)
Quoted 11 lines
sound/pci/hda/patch_sigmatel.c +0
-0return err; }
-stac_init_power_map(codec);
-
return 0;
}sound/pci/hda/patch_sigmatel.c +3
-0+static int stac_build_controls (struct hda_codec *codec) +{ + int err =
snd_hda_gen_build_controls(codec);
Quoted 17 lines
+ if (err < 0)
+ return err;
+stac_init_power_map(codec);
+ return 0;
+}
static intstac_init(struct hda_codec *codec)
{sound/pci/hda/patch_sigmatel.c +0
-0@@ -4388,7 +4394,7 @@ static int stac_suspend(struct hda_codec *codec) #endif /* CONFIG_PM */
static const structhda_codec_opsstac_patch_ops= { - .build_controls =snd_hda_gen_build_controls, + .build_controls =stac_build_controls, .build_pcms =snd_hda_gen_build_pcms, .init =stac_init,
.free =stac_free,
Hi, again, Takashi.
A few minute ago, I wrote a side comment that you should ignore, which was the following:
Quoted 5 lines
Also, by the way, it appears that linux-3.17-rc4's Intel "high defintiion audio" driver, regardless of whether this patch is applied, no
longer shows Linux input subsystem devices for analog audio
jack sense, although it does provide such a device for HDMI
jack sense. [...]
In Linux 3.17-rc4, reloading the snd-hda-intel module without "model=no-jd" results in those input devices being created. So, it is not a bug. In fact, I think is completely correct and an improvement that mode=no-jd now causes the jack sense Linux input layer devices not to be created, which should make it easier for userspace to detect and adapt to this situation.
Sorry for the distraction.
Adam Richter
At Thu, 11 Sep 2014 21:30:25 -0700,
Quoted 10 lines · Adam Richter
Hi, Takashi.
I confirm that your patch, quoted below, eliminated the symptom.
Please feel free to ask me to test other patches related to this problem.
Also, by the way, it appears that linux-3.17-rc4's Intel "high defintiion audio" driver, regardless of whether this patch is applied, no longer shows Linux input subsystem devices for analog audio jack sense, although it does provide such a device for HDMI jack sense. If that's a bug, it's completely separate, but I mention it here in case it's relevant to integrating a fix to this issue.
Thanks to you and David for your prompt and careful attention this bug once I brought it to this mailing list.
Good to hear. I merged the patch now for-linus branch.
Takashi