All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Henningsson <david.henningsson@canonical.com>
To: Takashi Iwai <tiwai@suse.de>
Cc: Adam Richter <adam_richter2004@yahoo.com>,
	"alsa-devel@alsa-project.org" <alsa-devel@alsa-project.org>
Subject: Re: Possible fix for snd-hda-intel model=no-jd failing since ~linux-3.9-rc1
Date: Thu, 11 Sep 2014 11:42:41 +0200	[thread overview]
Message-ID: <54116E91.6010705@canonical.com> (raw)
In-Reply-To: <s5hsijyy0i1.wl-tiwai@suse.de>



On 2014-09-11 11:23, Takashi Iwai wrote:
> At Thu, 11 Sep 2014 11:07:10 +0200,
> David Henningsson wrote:
>>
>>
>>
>> On 2014-09-11 09:47, Adam Richter wrote:
>>> 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.
>>
>>> 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.
>>
>> 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.
>>
>>> 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.
>>>
>>> --- linux-3.17.0-rc4-64bit/sound/pci/hda/hda_jack.c.orig    2014-09-07 16:09:43.000000000 -0700
>>> +++ linux-3.17.0-rc4-64bit/sound/pci/hda/hda_jack.c    2014-09-10 18:41:53.422900040 -0700
>>> @@ -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 <adam_richter2004@yahoo.com>
>>>
>>>
>>> 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);
>>
>> 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?
>
> Ah, "attached" was meant *your* attached patch.  Let me see...
>
>>  From e5ce94c6156d1c588f29745ade06d1d76c87a0a1 Mon Sep 17 00:00:00 2001
>> From: David Henningsson <david.henningsson@canonical.com>
>> 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.
>>
>> Reported-by: Adam Richter <adam_richter2004@yahoo.com>
>> Signed-off-by: David Henningsson <david.henningsson@canonical.com>
>> ---
>>   sound/pci/hda/hda_jack.c | 35 +++++++++++++++++++----------------
>>   1 file changed, 19 insertions(+), 16 deletions(-)
>>
>> diff --git a/sound/pci/hda/hda_jack.c b/sound/pci/hda/hda_jack.c
>> index 9746d73..376ce8f 100644
>> --- a/sound/pci/hda/hda_jack.c
>> +++ b/sound/pci/hda/hda_jack.c
>> @@ -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.

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?

> 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.

> 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
>
> --
> diff --git a/sound/pci/hda/hda_jack.c b/sound/pci/hda/hda_jack.c
> index 9746d73cec52..0645735e196d 100644
> --- a/sound/pci/hda/hda_jack.c
> +++ b/sound/pci/hda/hda_jack.c
> @@ -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.

>   	jack->jack_detect = 1;
>   	if (action)
>   		jack->action = action;
>

-- 
David Henningsson, Canonical Ltd.
https://launchpad.net/~diwic

  reply	other threads:[~2014-09-11  9:42 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-11  7:47 Possible fix for snd-hda-intel model=no-jd failing since ~linux-3.9-rc1 Adam Richter
2014-09-11  8:42 ` Takashi Iwai
2014-09-11  9:07 ` David Henningsson
2014-09-11  9:09   ` Takashi Iwai
2014-09-11  9:23   ` Takashi Iwai
2014-09-11  9:42     ` David Henningsson [this message]
2014-09-11 10:07       ` Takashi Iwai
2014-09-11 10:29         ` David Henningsson
2014-09-11 10:51           ` Takashi Iwai
2014-09-11 10:55         ` Takashi Iwai
2014-09-12  4:30           ` Adam Richter
2014-09-12  4:40             ` Adam Richter
2014-09-15  8:39             ` Takashi Iwai
  -- strict thread matches above, loose matches on Subject: below --
2014-09-11  9:32 Adam Richter
2014-09-11 11:48 ` Raymond Yau
2014-09-11 19:14   ` Adam Richter
2014-09-12  7:17     ` Raymond Yau
2014-07-09 23:07 adam richter
2014-09-11  3:48 ` adam richter
2014-09-11  7:17 ` Takashi Iwai
2014-09-11  7:22 ` Adam Richter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54116E91.6010705@canonical.com \
    --to=david.henningsson@canonical.com \
    --cc=adam_richter2004@yahoo.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.