Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 637DFC433E0 for ; Tue, 16 Mar 2021 14:19:09 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BDB6A6506E for ; Tue, 16 Mar 2021 14:19:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BDB6A6506E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id AF2E217E5; Tue, 16 Mar 2021 15:18:15 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz AF2E217E5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1615904345; bh=Mctc11llbtI/Amm7uTR3ySmPfrm4opUYn85OeZa+yqg=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=GUediTGkXtrYygtAuUZfwqzgCNyPvfZWeiWK5BlhYCfw8m4/S4aH3/p3UNQbWIrLg +bkJlphsoQD2fnhyLiUi2ExJZALj6wl3Y33oEsh44eyXDv82YjqVNdNSSTbwvvnxXu KAw9CEDnAuk6FXWXJP3mZKsJf7dg9LLwHP3Zjf60= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 0A195F80156; Tue, 16 Mar 2021 15:18:15 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 45DF5F80137; Tue, 16 Mar 2021 15:18:12 +0100 (CET) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 6A6B5F80137 for ; Tue, 16 Mar 2021 15:18:00 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 6A6B5F80137 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id F340CABD7; Tue, 16 Mar 2021 14:17:59 +0000 (UTC) Date: Tue, 16 Mar 2021 15:17:59 +0100 Message-ID: From: Takashi Iwai To: Hui Wang Subject: Re: [PATCH] ALSA: hda/realtek: add more delay time before determine_headset_type In-Reply-To: <20210316115549.240014-1-hui.wang@canonical.com> References: <20210316115549.240014-1-hui.wang@canonical.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Cc: alsa-devel@alsa-project.org, kailang@realtek.com X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" On Tue, 16 Mar 2021 12:55:49 +0100, Hui Wang wrote: > > We found a recording issue on the headset-mic recently, sometimes > users plug a headset and select headset-mic from UI, but can't record > any sound from headset-mic. The root cause is the > determine_headset_type() returns a wrong type, e.g. users plug a ctia > type headset, but that function returns omtp type. > > In the past, determine_headset_type() worked well because the internal > mic is connected to the codec, so the "Input Source" or > "Capture Source" is internal mic by default when users plug a headset, > the determine_headset_type() will not be called unless users select > headset-mic from UI, when users select headset-mic, the plugging > action already finished and the headset is completely plugged into the > jack, so determine_headset_type() could return a correct type. > > But more and more machines connect the internal mic to the PCH now, > and the "Input Source" is headset mic by default, when users plug a > headset, the determine_headset_type() will be called immediately, if > the headset is not completely plugged in, it will return a wrong type. > > Here add 2s delay before calling determine_headset_type(), and since > there is a pop-up dialogue when users do plugging action, to avoid > freezing the UI, use the deleyed_work to call that function. Hm, two seconds are quite long, IMHO. How is this delay determined? Takashi > > Signed-off-by: Hui Wang > --- > sound/pci/hda/patch_realtek.c | 31 ++++++++++++++++++++++++------- > 1 file changed, 24 insertions(+), 7 deletions(-) > > diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c > index b47504fa8dfd..1f6fc8addf3e 100644 > --- a/sound/pci/hda/patch_realtek.c > +++ b/sound/pci/hda/patch_realtek.c > @@ -127,6 +127,8 @@ struct alc_spec { > unsigned int coef0; > struct input_dev *kb_dev; > u8 alc_mute_keycode_map[1]; > + struct hda_codec *codec; > + struct delayed_work headset_set_work; > }; > > /* > @@ -1160,6 +1162,7 @@ static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid) > kfree(spec); > return err; > } > + spec->codec = codec; > return 0; > } > > @@ -5363,6 +5366,21 @@ static void alc_determine_headset_type(struct hda_codec *codec) > spec->current_headset_type = is_ctia ? ALC_HEADSET_TYPE_CTIA : ALC_HEADSET_TYPE_OMTP; > } > > +static void alc_headset_check_and_set(struct work_struct *work) > +{ > + struct alc_spec *spec = container_of(work, struct alc_spec, > + headset_set_work.work); > + struct hda_codec *codec = spec->codec; > + > + if (spec->current_headset_type == ALC_HEADSET_TYPE_UNKNOWN) > + alc_determine_headset_type(codec); > + if (spec->current_headset_type == ALC_HEADSET_TYPE_CTIA) > + alc_headset_mode_ctia(codec); > + else if (spec->current_headset_type == ALC_HEADSET_TYPE_OMTP) > + alc_headset_mode_omtp(codec); > + spec->gen.hp_jack_present = true; > +} > + > static void alc_update_headset_mode(struct hda_codec *codec) > { > struct alc_spec *spec = codec->spec; > @@ -5386,6 +5404,7 @@ static void alc_update_headset_mode(struct hda_codec *codec) > return; > } > > + cancel_delayed_work_sync(&spec->headset_set_work); > switch (new_headset_mode) { > case ALC_HEADSET_MODE_UNPLUGGED: > alc_headset_mode_unplugged(codec); > @@ -5394,13 +5413,7 @@ static void alc_update_headset_mode(struct hda_codec *codec) > spec->gen.hp_jack_present = false; > break; > case ALC_HEADSET_MODE_HEADSET: > - if (spec->current_headset_type == ALC_HEADSET_TYPE_UNKNOWN) > - alc_determine_headset_type(codec); > - if (spec->current_headset_type == ALC_HEADSET_TYPE_CTIA) > - alc_headset_mode_ctia(codec); > - else if (spec->current_headset_type == ALC_HEADSET_TYPE_OMTP) > - alc_headset_mode_omtp(codec); > - spec->gen.hp_jack_present = true; > + schedule_delayed_work(&spec->headset_set_work, msecs_to_jiffies(2000)); > break; > case ALC_HEADSET_MODE_MIC: > alc_headset_mode_mic_in(codec, hp_pin, spec->headphone_mic_pin); > @@ -5466,6 +5479,7 @@ static void alc_fixup_headset_mode(struct hda_codec *codec, > spec->parse_flags |= HDA_PINCFG_HEADSET_MIC | HDA_PINCFG_HEADPHONE_MIC; > break; > case HDA_FIXUP_ACT_PROBE: > + INIT_DELAYED_WORK(&spec->headset_set_work, alc_headset_check_and_set); > alc_probe_headset_mode(codec); > break; > case HDA_FIXUP_ACT_INIT: > @@ -5475,6 +5489,9 @@ static void alc_fixup_headset_mode(struct hda_codec *codec, > } > alc_update_headset_mode(codec); > break; > + case HDA_FIXUP_ACT_FREE: > + cancel_delayed_work_sync(&spec->headset_set_work); > + break; > } > } > > -- > 2.25.1 >