From mboxrd@z Thu Jan 1 00:00:00 1970 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=-8.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS 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 796CFC4332D for ; Tue, 12 Jan 2021 13:18:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2B06B22CAF for ; Tue, 12 Jan 2021 13:18:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732288AbhALNRs (ORCPT ); Tue, 12 Jan 2021 08:17:48 -0500 Received: from mx2.suse.de ([195.135.220.15]:47132 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727200AbhALNRo (ORCPT ); Tue, 12 Jan 2021 08:17:44 -0500 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 409A7B92B; Tue, 12 Jan 2021 13:17:01 +0000 (UTC) Date: Tue, 12 Jan 2021 14:16:56 +0100 Message-ID: From: Takashi Iwai To: Kai-Heng Feng Cc: tiwai@suse.com, pierre-louis.bossart@linux.intel.com, lgirdwood@gmail.com, ranjani.sridharan@linux.intel.com, kai.vehmanen@linux.intel.com, daniel.baluta@nxp.com, broonie@kernel.org, Jaroslav Kysela , Kailang Yang , Jian-Hong Pan , Hui Wang , Huacai Chen , Thomas Hebb , alsa-devel@alsa-project.org (moderated list:SOUND), linux-kernel@vger.kernel.org (open list) Subject: Re: [PATCH v3 1/4] ALSA: hda/realtek: Power up codec when setting LED via COEF and GPIO In-Reply-To: <20210112130704.1201406-1-kai.heng.feng@canonical.com> References: <20210112130704.1201406-1-kai.heng.feng@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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 12 Jan 2021 14:06:59 +0100, Kai-Heng Feng wrote: > > System takes a very long time to suspend after commit 215a22ed31a1 > ("ALSA: hda: Refactor codec PM to use direct-complete optimization"): > [ 90.065964] PM: suspend entry (s2idle) > [ 90.067337] Filesystems sync: 0.001 seconds > [ 90.185758] Freezing user space processes ... (elapsed 0.002 seconds) done. > [ 90.188713] OOM killer disabled. > [ 90.188714] Freezing remaining freezable tasks ... (elapsed 0.001 seconds) done. > [ 90.190024] printk: Suspending console(s) (use no_console_suspend to debug) > [ 90.904912] intel_pch_thermal 0000:00:12.0: CPU-PCH is cool [49C], continue to suspend > [ 321.262505] snd_hda_codec_realtek ehdaudio0D0: Unable to sync register 0x2b8000. -5 > [ 328.426919] snd_hda_codec_realtek ehdaudio0D0: Unable to sync register 0x2b8000. -5 > [ 329.490933] ACPI: EC: interrupt blocked > > That commit keeps the codec suspended during the system suspend. However, > led_suspend() for mute and micmute led writes codec register, triggers > a pending wake up. The wakeup is then handled in __device_suspend() by > the following: > - pm_runtime_disable() to handle the wakeup event. > - device is no longer is suspended state, direct-complete isn't taken. > - pm_runtime_enable() to balance disable_depth. > > if (dev->power.direct_complete) { > if (pm_runtime_status_suspended(dev)) { > pm_runtime_disable(dev); > if (pm_runtime_status_suspended(dev)) { > pm_dev_dbg(dev, state, "direct-complete "); > goto Complete; > } > > pm_runtime_enable(dev); > } > dev->power.direct_complete = false; > } > > Since direct-complete doens't apply anymore, the codec's system suspend > routine is used. > > This doesn't play well with SOF driver. When its runtime resume is > called for system suspend, hda_codec_jack_check() schedules > jackpoll_work which uses snd_hdac_is_power_on() to check whether codec > is suspended. Because of the previous pm_runtime_enable(), > snd_hdac_is_power_on() returns false and jackpoll continues to run, and > snd_hda_power_up_pm() cannot power up an already suspended codec in > multiple attempts, causes the long delay on system suspend. > > When direct-complete path is taken, snd_hdac_is_power_on() returns true > and hda_jackpoll_work() is skipped by accident. This is still not > correct, and it will be addressed by later patch. > > Explicitly runtime resume codec on setting LED to solve the issue. > > Fixes: 215a22ed31a1 ("ALSA: hda: Refactor codec PM to use direct-complete optimization") Hmm, I really don't get this. alc_update_gpio_data() calls snd_hda_codec_write() in the end, and this function goes over bus->exec_verb call. And for the legacy HDA codec, it's codec_exec_verb in hda_codec.c, which has already snd_hda_power_up_pm(). What's the missing piece? thanks, Takashi > --- > v3: > New patch. > > sound/pci/hda/patch_realtek.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c > index 3c1d2a3fb1a4..304a7bc89fcd 100644 > --- a/sound/pci/hda/patch_realtek.c > +++ b/sound/pci/hda/patch_realtek.c > @@ -4164,7 +4164,10 @@ static void alc_update_gpio_led(struct hda_codec *codec, unsigned int mask, > { > if (polarity) > enabled = !enabled; > + /* temporarily power up/down for setting GPIO */ > + snd_hda_power_up_pm(codec); > alc_update_gpio_data(codec, mask, !enabled); /* muted -> LED on */ > + snd_hda_power_down_pm(codec); > } > > /* turn on/off mute LED via GPIO per vmaster hook */ > @@ -4287,8 +4290,10 @@ static void alc_update_coef_led(struct hda_codec *codec, > if (polarity) > on = !on; > /* temporarily power up/down for setting COEF bit */ > + snd_hda_power_up_pm(codec); > alc_update_coef_idx(codec, led->idx, led->mask, > on ? led->on : led->off); > + snd_hda_power_down_pm(codec); > } > > /* update mute-LED according to the speaker mute state via COEF bit */ > -- > 2.29.2 > From mboxrd@z Thu Jan 1 00:00:00 1970 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=-8.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 0CEDFC43332 for ; Tue, 12 Jan 2021 13:18:03 +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 5258722D58 for ; Tue, 12 Jan 2021 13:18:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5258722D58 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 158011691; Tue, 12 Jan 2021 14:17:09 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 158011691 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1610457479; bh=W56/B74/gC6pExy31JCtQMJNSOHpQh1XtamkSWm971o=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=HJAPRJdcsSPu98+ly/Rrqx0YrMvUVJiXPEJy0IWYFP/zHMyMe4bxNwkva9aYzCN3F GZU5SJMY9rztbfAr2bG0v3kQkJYsoLTDKJviam44pMjjtBovEZnp30T5WtzK/lcOy+ /fhB0kEm67I5VKCaNmEpsnpiJLx77Zm4vAZik4jY= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 4B32CF80249; Tue, 12 Jan 2021 14:17:08 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id D5045F8025E; Tue, 12 Jan 2021 14:17:06 +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 3EE3DF800B9 for ; Tue, 12 Jan 2021 14:17:02 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 3EE3DF800B9 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 409A7B92B; Tue, 12 Jan 2021 13:17:01 +0000 (UTC) Date: Tue, 12 Jan 2021 14:16:56 +0100 Message-ID: From: Takashi Iwai To: Kai-Heng Feng Subject: Re: [PATCH v3 1/4] ALSA: hda/realtek: Power up codec when setting LED via COEF and GPIO In-Reply-To: <20210112130704.1201406-1-kai.heng.feng@canonical.com> References: <20210112130704.1201406-1-kai.heng.feng@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: "moderated list:SOUND" , pierre-louis.bossart@linux.intel.com, Jian-Hong Pan , Kailang Yang , Thomas Hebb , kai.vehmanen@linux.intel.com, open list , tiwai@suse.com, lgirdwood@gmail.com, ranjani.sridharan@linux.intel.com, Hui Wang , broonie@kernel.org, Huacai Chen , daniel.baluta@nxp.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, 12 Jan 2021 14:06:59 +0100, Kai-Heng Feng wrote: > > System takes a very long time to suspend after commit 215a22ed31a1 > ("ALSA: hda: Refactor codec PM to use direct-complete optimization"): > [ 90.065964] PM: suspend entry (s2idle) > [ 90.067337] Filesystems sync: 0.001 seconds > [ 90.185758] Freezing user space processes ... (elapsed 0.002 seconds) done. > [ 90.188713] OOM killer disabled. > [ 90.188714] Freezing remaining freezable tasks ... (elapsed 0.001 seconds) done. > [ 90.190024] printk: Suspending console(s) (use no_console_suspend to debug) > [ 90.904912] intel_pch_thermal 0000:00:12.0: CPU-PCH is cool [49C], continue to suspend > [ 321.262505] snd_hda_codec_realtek ehdaudio0D0: Unable to sync register 0x2b8000. -5 > [ 328.426919] snd_hda_codec_realtek ehdaudio0D0: Unable to sync register 0x2b8000. -5 > [ 329.490933] ACPI: EC: interrupt blocked > > That commit keeps the codec suspended during the system suspend. However, > led_suspend() for mute and micmute led writes codec register, triggers > a pending wake up. The wakeup is then handled in __device_suspend() by > the following: > - pm_runtime_disable() to handle the wakeup event. > - device is no longer is suspended state, direct-complete isn't taken. > - pm_runtime_enable() to balance disable_depth. > > if (dev->power.direct_complete) { > if (pm_runtime_status_suspended(dev)) { > pm_runtime_disable(dev); > if (pm_runtime_status_suspended(dev)) { > pm_dev_dbg(dev, state, "direct-complete "); > goto Complete; > } > > pm_runtime_enable(dev); > } > dev->power.direct_complete = false; > } > > Since direct-complete doens't apply anymore, the codec's system suspend > routine is used. > > This doesn't play well with SOF driver. When its runtime resume is > called for system suspend, hda_codec_jack_check() schedules > jackpoll_work which uses snd_hdac_is_power_on() to check whether codec > is suspended. Because of the previous pm_runtime_enable(), > snd_hdac_is_power_on() returns false and jackpoll continues to run, and > snd_hda_power_up_pm() cannot power up an already suspended codec in > multiple attempts, causes the long delay on system suspend. > > When direct-complete path is taken, snd_hdac_is_power_on() returns true > and hda_jackpoll_work() is skipped by accident. This is still not > correct, and it will be addressed by later patch. > > Explicitly runtime resume codec on setting LED to solve the issue. > > Fixes: 215a22ed31a1 ("ALSA: hda: Refactor codec PM to use direct-complete optimization") Hmm, I really don't get this. alc_update_gpio_data() calls snd_hda_codec_write() in the end, and this function goes over bus->exec_verb call. And for the legacy HDA codec, it's codec_exec_verb in hda_codec.c, which has already snd_hda_power_up_pm(). What's the missing piece? thanks, Takashi > --- > v3: > New patch. > > sound/pci/hda/patch_realtek.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c > index 3c1d2a3fb1a4..304a7bc89fcd 100644 > --- a/sound/pci/hda/patch_realtek.c > +++ b/sound/pci/hda/patch_realtek.c > @@ -4164,7 +4164,10 @@ static void alc_update_gpio_led(struct hda_codec *codec, unsigned int mask, > { > if (polarity) > enabled = !enabled; > + /* temporarily power up/down for setting GPIO */ > + snd_hda_power_up_pm(codec); > alc_update_gpio_data(codec, mask, !enabled); /* muted -> LED on */ > + snd_hda_power_down_pm(codec); > } > > /* turn on/off mute LED via GPIO per vmaster hook */ > @@ -4287,8 +4290,10 @@ static void alc_update_coef_led(struct hda_codec *codec, > if (polarity) > on = !on; > /* temporarily power up/down for setting COEF bit */ > + snd_hda_power_up_pm(codec); > alc_update_coef_idx(codec, led->idx, led->mask, > on ? led->on : led->off); > + snd_hda_power_down_pm(codec); > } > > /* update mute-LED according to the speaker mute state via COEF bit */ > -- > 2.29.2 >