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: 214958 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=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MIME_BASE64_TEXT, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, URIBL_BLOCKED, USER_AGENT_GIT 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 58A2AC433E0 for ; Tue, 2 Jun 2020 11:54:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2ADEE206E2 for ; Tue, 2 Jun 2020 11:54:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="k9mn8oVK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726664AbgFBLyP (ORCPT ); Tue, 2 Jun 2020 07:54:15 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:62304 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726267AbgFBLyP (ORCPT ); Tue, 2 Jun 2020 07:54:15 -0400 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 , , CC: Mediatek WSD Upstream , 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 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org 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(+) -- 1.7.9.5 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); }