Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp158574rwb; Wed, 28 Sep 2022 00:26:51 -0700 (PDT) X-Google-Smtp-Source: AMsMyM44agDX9xhmK0ARYJU1E1QTUzCqm/zpnn4/tSnPOWn1APG7LqvBpfSRcV69qTM5WK44EOdv X-Received: by 2002:a05:6402:520c:b0:451:4213:49db with SMTP id s12-20020a056402520c00b00451421349dbmr31854646edd.130.1664350011043; Wed, 28 Sep 2022 00:26:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664350011; cv=none; d=google.com; s=arc-20160816; b=gBk1A/G441SuJXAbweg4USxK3HITnvLXwuwS/zVIv05yfsIvoTFVboEXqa103RtKeg +q0EfzRbbF4qvJY4Vxmpvy0Py3xLOcEkHrh8GY2MYMwiu0x0094+dE0FnReuXIntAVvT OEOMy4gS4eLLVb3VDxehI4J42nRPP681CoX6XuskTZfWytagn0c7nKyYG5zKS9fRT/C/ Phs8WbScIYhaD5PLba4ZcjhmYS0RTVop/xNr7sZ11Rcw6TUd7SBIEB/Gm2HAotvMA/ik r72fyTCqIRYcYsqpPlxfpbPyjyQoFo6jB+TdiSjin8SKcxyE7BiNy0PLYg1pRu4MyTov g1+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature:dkim-signature; bh=1yCtZixpV6onXF1GBilOFs92gXFQP22w5hamvmLEPjc=; b=P07pUx/3yvGhKc86oHB/P4DoHoOYtyORL1ibcOBxsxG1PhCLtrmamjX3MMqnnFyEXu Sp88sqNTfdRZsKLrSBfLyWULXZjjqPOy8JtQGSZ32aDxRbg2Z/WveaFfag0lzm1oThlc Iw/7sOQTACPKSZb0J1KADTMj/O0f3KDz+4W01qbAUN0EOaRtpaAPgkDS2jCxhfmfpP5i UBw1HApjcl5w7lcUv49j//Q94QZRR4QvRp6OvGCdQ8vrT3ltr4lQx4sdIz5Q4WF6PAQ9 yuOqneiahrKTBkgr57ILCF2c+NQoaKd7vty8ELNzVbuVQsy8pUQsxcm8mCMezOiq9EdJ JkWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=uPKVUEz7; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l19-20020a056402255300b00445e20bc95bsi4257684edb.428.2022.09.28.00.26.24; Wed, 28 Sep 2022 00:26:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=uPKVUEz7; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233352AbiI1HOj (ORCPT + 99 others); Wed, 28 Sep 2022 03:14:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232396AbiI1HOf (ORCPT ); Wed, 28 Sep 2022 03:14:35 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F01C3A0 for ; Wed, 28 Sep 2022 00:14:32 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 1DAAB21B20; Wed, 28 Sep 2022 07:14:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1664349271; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1yCtZixpV6onXF1GBilOFs92gXFQP22w5hamvmLEPjc=; b=uPKVUEz7eG5Khx6zvP0/lc4oxNAsP3mU5PB9QtTwmzeVplZrpGwrp/Xwj7mS0/+Y+99obB UHnsV3OHrJtV/E15o6vxknyG4QXCij8pcH1TeJFaEHMRzZXT0RqLScriw/5PskE7qcTlrT kWRSgjHgSCoMdVJ2w41Qt1D42DYQPqQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1664349271; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1yCtZixpV6onXF1GBilOFs92gXFQP22w5hamvmLEPjc=; b=svPb4dPJzVchJpw0uwl9Dv97hMXxwEw1xXfZJ5dammhVwbFBLWCqHY4t/iLUzAlxNy9PvF 8LK045xqMxsIKcBg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D9D7713677; Wed, 28 Sep 2022 07:14:30 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Fi9hNFb0M2PpMwAAMHmgww (envelope-from ); Wed, 28 Sep 2022 07:14:30 +0000 Date: Wed, 28 Sep 2022 09:14:30 +0200 Message-ID: <875yh8ezs9.wl-tiwai@suse.de> From: Takashi Iwai To: "Lu, Brent" Cc: "alsa-devel@alsa-project.org" , "Jaroslav Kysela" , Takashi Iwai , Kai Vehmanen , Pierre-Louis Bossart , Mohan Kumar , Ville =?ISO-8859-1?Q?Syrj=E4l=E4?= , "Zhi, Yong" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] ALSA: hda/hdmi: run eld notify in delay work In-Reply-To: References: <20220927135807.4097052-1-brent.lu@intel.com> <87ill8gb5c.wl-tiwai@suse.de> User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/27.2 Mule/6.0 MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 28 Sep 2022 04:06:45 +0200, Lu, Brent wrote: > > > > > > > During resolution change, display driver would disable HDMI audio then > > > enable it in a short time. There is possibility that eld notify for > > > HDMI audio enable is called when previous runtime suspend is still > > > running. In this case, the elf nofity just returns and not updating > > > the status of corresponding HDMI pin/port. Here we move the eld nofity > > > to a delay work so we don't lose it. > > > > > > Signed-off-by: Brent Lu > > > > We have already a dedicated per-pin work for the delayed ELD check. > > Can we reuse it instead of inventing yet another work? > > More work needs more cares, and better to avoid unless really needed (e.g. > > you forgot cleanup at suspend/removal in this patch). > > > > > > thanks, > > > > Takashi > > Hi Takashi, > > I've checked the hdmi_repoll_eld() and check_presence_and_report() function to see > if we can reuse the per-pin work. I've some questions about reusing the per-pin work: > > 1. hdmi_repoll_eld() calls snd_hda_jack_tbl_get_mst() function while > check_presence_and_report() doesn't. Is it ok? For the system with the audio component, there is no jack entry, hence this will be ignored. > 2. snd_hdac_i915_set_bclk() is called in intel_pin_eld_notify() function. Since it's > skipped, we need to call it in the per-pin work. Need to add a flag in hdmi_spec_per_pin > to indicate this situation. Yeah, I guess this was already a bug. It implies that the set_bclk() call is missing in the suspend/resume case, too. We need to call it more consistently. > 3. We can schedule the per-pin work in intel_pin_eld_notify() when snd_hdac_is_in_pm() > returns true but there is no guarantee the runtime suspend will finished when the per-pin > work is schedule to run. On the second thought, we may simply proceed the notification if it's in a valid context. The only period to prohibit the update is during the suspend/resume until the ELD is updated by the resume itself. So, something like below may work instead. Could you give it a try? Takashi -- 8< -- --- a/sound/pci/hda/patch_hdmi.c +++ b/sound/pci/hda/patch_hdmi.c @@ -83,6 +83,7 @@ struct hdmi_spec_per_pin { int pcm_idx; /* which pcm is attached. -1 means no pcm is attached */ int repoll_count; bool setup; /* the stream has been set up by prepare callback */ + bool eld_update_frozen; bool silent_stream; int channels; /* current number of channels */ bool non_pcm; @@ -788,16 +789,28 @@ static void hdmi_setup_audio_infoframe(struct hda_codec *codec, static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll); -static void check_presence_and_report(struct hda_codec *codec, hda_nid_t nid, - int dev_id) +static struct hdmi_spec_per_pin * +get_pin_from_nid(struct hda_codec *codec, hda_nid_t nid, int dev_id) { struct hdmi_spec *spec = codec->spec; int pin_idx = pin_id_to_pin_index(codec, nid, dev_id); if (pin_idx < 0) + return NULL; + return get_pin(spec, pin_idx); +} + +static void check_presence_and_report(struct hda_codec *codec, hda_nid_t nid, + int dev_id) +{ + struct hdmi_spec *spec = codec->spec; + struct hdmi_spec_per_pin *per_pin; + + per_pin = get_pin_from_nid(codec, nid, dev_id); + if (!per_pin) return; mutex_lock(&spec->pcm_lock); - hdmi_present_sense(get_pin(spec, pin_idx), 1); + hdmi_present_sense(per_pin, 1); mutex_unlock(&spec->pcm_lock); } @@ -1582,6 +1595,7 @@ static void update_eld(struct hda_codec *codec, snd_jack_report(pcm_jack, (eld->monitor_present && eld->eld_valid) ? SND_JACK_AVOUT : 0); + per_pin->eld_update_frozen = false; } /* update ELD and jack state via HD-audio verbs */ @@ -2494,6 +2508,7 @@ static int generic_hdmi_suspend(struct hda_codec *codec) for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); cancel_delayed_work_sync(&per_pin->work); + per_pin->eld_update_frozen = true; } return 0; } @@ -2656,6 +2671,7 @@ static void generic_acomp_pin_eld_notify(void *audio_ptr, int port, int dev_id) struct hda_codec *codec = audio_ptr; struct hdmi_spec *spec = codec->spec; hda_nid_t pin_nid = spec->port2pin(codec, port); + struct hdmi_spec_per_pin *per_pin; if (!pin_nid) return; @@ -2667,7 +2683,8 @@ static void generic_acomp_pin_eld_notify(void *audio_ptr, int port, int dev_id) if (codec->core.dev.power.power_state.event == PM_EVENT_SUSPEND) return; /* ditto during suspend/resume process itself */ - if (snd_hdac_is_in_pm(&codec->core)) + per_pin = get_pin_from_nid(codec, pin_nid, dev_id); + if (!per_pin || per_pin->eld_update_frozen) return; check_presence_and_report(codec, pin_nid, dev_id); @@ -2841,6 +2858,7 @@ static int intel_port2pin(struct hda_codec *codec, int port) static void intel_pin_eld_notify(void *audio_ptr, int port, int pipe) { struct hda_codec *codec = audio_ptr; + struct hdmi_spec_per_pin *per_pin; int pin_nid; int dev_id = pipe; @@ -2853,7 +2871,8 @@ static void intel_pin_eld_notify(void *audio_ptr, int port, int pipe) if (codec->core.dev.power.power_state.event == PM_EVENT_SUSPEND) return; /* ditto during suspend/resume process itself */ - if (snd_hdac_is_in_pm(&codec->core)) + per_pin = get_pin_from_nid(codec, pin_nid, dev_id); + if (!per_pin || per_pin->eld_update_frozen) return; snd_hdac_i915_set_bclk(&codec->bus->core);