From patchwork Tue Jun 2 11:53:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Macpaul Lin X-Patchwork-Id: 11583855 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7225E912 for ; Tue, 2 Jun 2020 13:17:04 +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 03AF62074B for ; Tue, 2 Jun 2020 13:17:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="BQPeA+Zq"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="k9mn8oVK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 03AF62074B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=mediatek.com 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 917711696; Tue, 2 Jun 2020 15:16:15 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 917711696 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1591103822; bh=L8W+8mcW7tehoLHNruKxathHioAmFWgzPfCM36oBzVI=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=BQPeA+ZqYXnSR2s5ag1eDlDcesjy3dY/14A1O0l/CsW7zPu954aUKTmoiGYTiNeIr uHMS5GzPDETpfcLsePP/teQMYESgVHRWdGnEP54vB77reYAH58WNYJRNCcZ6aDI15n wz4PnGBBVDrnYkkk3vyzwld8T0ThGUP6aCz2ff28= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 31121F802E9; Tue, 2 Jun 2020 15:10:59 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id 1DF7FF8026F; Tue, 2 Jun 2020 13:54:28 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on alsa1.perex.cz X-Spam-Level: X-Spam-Status: No, score=0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MIME_BASE64_TEXT,RDNS_NONE,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by alsa1.perex.cz (Postfix) with ESMTP id 4D949F800BC for ; Tue, 2 Jun 2020 13:54:19 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 4D949F800BC Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="k9mn8oVK" X-UUID: db722be8915d4774a20434feec800d44-20200602 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=L8W+8mcW7tehoLHNruKxathHioAmFWgzPfCM36oBzVI=; b=k9mn8oVKytEFmfU9V9wfE7bOeHl582gKVvTUdOLHqqCH7lSp7cflofcwSgaHQ0ZeaoDugr6BF/FB6eHeRMa4ma2CVUniQg21aktdRPhztGUzRTYCM7UqUwSZOh1PjvKZdklXygr7vZ8rdF/qyB5qTjsL4yEYpKiAmqrxOacpFw0=; X-UUID: db722be8915d4774a20434feec800d44-20200602 Received: from mtkcas10.mediatek.inc [(172.21.101.39)] by mailgw02.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0809 with TLS) with ESMTP id 723940935; Tue, 02 Jun 2020 19:54:12 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs08n1.mediatek.inc (172.21.101.55) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 2 Jun 2020 19:54:01 +0800 Received: from mtkswgap22.mediatek.inc (172.21.77.33) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 2 Jun 2020 19:54:01 +0800 From: Macpaul Lin To: Jaroslav Kysela , Takashi Iwai , "Matthias Brugger" , Alexander Tsoy , "Johan Hovold" , Hui Wang , =?utf-8?q?Szabolcs_Sz=C5=91ke?= , Macpaul Lin , , Subject: [PATCH] sound: usb: pcm: fix incorrect power state when playing sound after PM_AUTO suspend Date: Tue, 2 Jun 2020 19:53:41 +0800 Message-ID: <1591098821-17910-1-git-send-email-macpaul.lin@mediatek.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: MIME-Version: 1.0 X-MTK: N X-Mailman-Approved-At: Tue, 02 Jun 2020 15:10:44 +0200 Cc: linux-arm-kernel@lists.infradead.org, Macpaul Lin , linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Mediatek WSD Upstream 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" This patch fix incorrect power state changed by usb_audio_suspend() when CONFIG_PM is enabled. After receiving suspend PM message with auto flag, usb_audio_suspend() change card's power state to SNDRV_CTL_POWER_D3hot. Only when the other resume PM message with auto flag can change power state to SNDRV_CTL_POWER_D0 in __usb_audio_resume(). However, when system is not under auto suspend, resume PM message with auto flag might not be able to receive on time which cause the power state was incorrect. At this time, if a player starts to play sound, will cause snd_usb_pcm_open() to access the card and setup_hw_info() will resume the card. But even the card is back to work and all function normal, the power state is still in SNDRV_CTL_POWER_D3hot. Which cause the infinite loop happened in snd_power_wait() to check the power state. Thus the successive setting ioctl cannot be passed to card. Hence we suggest to change power state to SNDRV_CTL_POWER_D0 when card has been resumed successfully. Signed-off-by: Macpaul Lin --- sound/usb/pcm.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c index a4e4064..d667ecb 100644 --- a/sound/usb/pcm.c +++ b/sound/usb/pcm.c @@ -1322,6 +1322,17 @@ static int setup_hw_info(struct snd_pcm_runtime *runtime, struct snd_usb_substre if (err < 0) return err; + /* fix incorrect power state when resuming by open and later ioctls */ + if (IS_ENABLED(CONFIG_PM) && + snd_power_get_state(subs->stream->chip->card) + == SNDRV_CTL_POWER_D3hot) { + /* set these variables for power state correction */ + subs->stream->chip->autosuspended = 0; + subs->stream->chip->num_suspended_intf = 1; + dev_info(&subs->dev->dev, + "change power state from D3hot to D0\n"); + } + return snd_usb_autoresume(subs->stream->chip); }