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=-3.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 90378C433E0 for ; Wed, 3 Jun 2020 08:45:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 720622074B for ; Wed, 3 Jun 2020 08:45:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726441AbgFCIpp (ORCPT ); Wed, 3 Jun 2020 04:45:45 -0400 Received: from mx2.suse.de ([195.135.220.15]:51046 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726243AbgFCIpp (ORCPT ); Wed, 3 Jun 2020 04:45:45 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 77D98ACCC; Wed, 3 Jun 2020 08:45:45 +0000 (UTC) Date: Wed, 03 Jun 2020 10:45:41 +0200 Message-ID: From: Takashi Iwai To: Macpaul Lin Cc: Jaroslav Kysela , Takashi Iwai , Matthias Brugger , Alexander Tsoy , Johan Hovold , Hui Wang , Szabolcs =?UTF-8?B?U3rFkWtl?= , , , Mediatek WSD Upstream , Macpaul Lin , , , , Greg Kroah-Hartman Subject: Re: [PATCH] sound: usb: pcm: fix incorrect power state when playing sound after PM_AUTO suspend In-Reply-To: References: <1591153515.23525.50.camel@mtkswgap22> 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 03 Jun 2020 08:54:51 +0200, Takashi Iwai wrote: > > On Wed, 03 Jun 2020 08:28:09 +0200, > Takashi Iwai wrote: > > > > And, the most suspicious case is the last one, > > chip->num_suspended-intf. It means that the device has multiple > > USB interfaces and they went to suspend, while the resume isn't > > performed for the all suspended interfaces in return. > > If this is the cause, a patch like below might help. > It gets/puts the all assigned interfaced instead of only the primary > one. ... and considering of the problem again, rather the patch below might be the right answer. Now the driver tries to remember at which state it entered into the system-suspend. Upon resume, in return, when the state reaches back to that point, set the card state to D0. The previous patch can be applied on the top, too, and it might be worth to apply both. Let me know if any of those actually helps. Takashi --- diff --git a/sound/usb/card.c b/sound/usb/card.c --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -843,9 +843,6 @@ static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message) if (chip == (void *)-1L) return 0; - chip->autosuspended = !!PMSG_IS_AUTO(message); - if (!chip->autosuspended) - snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot); if (!chip->num_suspended_intf++) { list_for_each_entry(as, &chip->pcm_list, list) { snd_usb_pcm_suspend(as); @@ -858,6 +855,11 @@ static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message) snd_usb_mixer_suspend(mixer); } + if (!PMSG_IS_AUTO(message) && !chip->system_suspend) { + snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot); + chip->system_suspend = chip->num_suspended_intf; + } + return 0; } @@ -871,10 +873,10 @@ static int __usb_audio_resume(struct usb_interface *intf, bool reset_resume) if (chip == (void *)-1L) return 0; - if (--chip->num_suspended_intf) - return 0; atomic_inc(&chip->active); /* avoid autopm */ + if (chip->num_suspended_intf > 1) + goto out; list_for_each_entry(as, &chip->pcm_list, list) { err = snd_usb_pcm_resume(as); @@ -896,9 +898,12 @@ static int __usb_audio_resume(struct usb_interface *intf, bool reset_resume) snd_usbmidi_resume(p); } - if (!chip->autosuspended) + out: + if (chip->num_suspended_intf == chip->system_suspend) { snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0); - chip->autosuspended = 0; + chip->system_suspend = 0; + } + chip->num_suspended_intf--; err_out: atomic_dec(&chip->active); /* allow autopm after this point */ diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h index 1c892c7f14d7..e0ebfb25fbd5 100644 --- a/sound/usb/usbaudio.h +++ b/sound/usb/usbaudio.h @@ -26,7 +26,7 @@ struct snd_usb_audio { struct usb_interface *pm_intf; u32 usb_id; struct mutex mutex; - unsigned int autosuspended:1; + unsigned int system_suspend; atomic_t active; atomic_t shutdown; atomic_t usage_count; 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=-3.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no 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 A1C56C433E0 for ; Wed, 3 Jun 2020 08:46:41 +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 2C2DC20674 for ; Wed, 3 Jun 2020 08:46:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="NvGUdhjz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2C2DC20674 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 B727A1614; Wed, 3 Jun 2020 10:45:49 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz B727A1614 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1591173999; bh=n9w9ORwApA/8x/dYuNowh98IrjSTn6cYNMs6+LqglyE=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=NvGUdhjzNBpIIkz1BVQAIEKlxTQ9EvJfD3409roDEOnLQr25RKrKYmLDZAAGfud/4 zpm/iUioiheDEv7bsKMPENYNGGpdQblRG51/TFwr+rAArP7ZD73wcbPeuGA7P+eKHf B2/mTArWIWKvMES1mFCb/JHimnV8Q2AY18mc8Ai8= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 37542F801EC; Wed, 3 Jun 2020 10:45:49 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 637B5F801ED; Wed, 3 Jun 2020 10:45:47 +0200 (CEST) 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 F102EF800BC for ; Wed, 3 Jun 2020 10:45:43 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz F102EF800BC X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 77D98ACCC; Wed, 3 Jun 2020 08:45:45 +0000 (UTC) Date: Wed, 03 Jun 2020 10:45:41 +0200 Message-ID: From: Takashi Iwai To: Macpaul Lin Subject: Re: [PATCH] sound: usb: pcm: fix incorrect power state when playing sound after PM_AUTO suspend In-Reply-To: References: <1591153515.23525.50.camel@mtkswgap22> 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, Mediatek WSD Upstream , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, Johan Hovold , Takashi Iwai , Hui Wang , Alexander Tsoy , linux-mediatek@lists.infradead.org, Greg Kroah-Hartman , Matthias Brugger , Macpaul Lin , Szabolcs =?UTF-8?B?U3rFkWtl?= , linux-arm-kernel@lists.infradead.org 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 Wed, 03 Jun 2020 08:54:51 +0200, Takashi Iwai wrote: > > On Wed, 03 Jun 2020 08:28:09 +0200, > Takashi Iwai wrote: > > > > And, the most suspicious case is the last one, > > chip->num_suspended-intf. It means that the device has multiple > > USB interfaces and they went to suspend, while the resume isn't > > performed for the all suspended interfaces in return. > > If this is the cause, a patch like below might help. > It gets/puts the all assigned interfaced instead of only the primary > one. ... and considering of the problem again, rather the patch below might be the right answer. Now the driver tries to remember at which state it entered into the system-suspend. Upon resume, in return, when the state reaches back to that point, set the card state to D0. The previous patch can be applied on the top, too, and it might be worth to apply both. Let me know if any of those actually helps. Takashi --- diff --git a/sound/usb/card.c b/sound/usb/card.c --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -843,9 +843,6 @@ static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message) if (chip == (void *)-1L) return 0; - chip->autosuspended = !!PMSG_IS_AUTO(message); - if (!chip->autosuspended) - snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot); if (!chip->num_suspended_intf++) { list_for_each_entry(as, &chip->pcm_list, list) { snd_usb_pcm_suspend(as); @@ -858,6 +855,11 @@ static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message) snd_usb_mixer_suspend(mixer); } + if (!PMSG_IS_AUTO(message) && !chip->system_suspend) { + snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot); + chip->system_suspend = chip->num_suspended_intf; + } + return 0; } @@ -871,10 +873,10 @@ static int __usb_audio_resume(struct usb_interface *intf, bool reset_resume) if (chip == (void *)-1L) return 0; - if (--chip->num_suspended_intf) - return 0; atomic_inc(&chip->active); /* avoid autopm */ + if (chip->num_suspended_intf > 1) + goto out; list_for_each_entry(as, &chip->pcm_list, list) { err = snd_usb_pcm_resume(as); @@ -896,9 +898,12 @@ static int __usb_audio_resume(struct usb_interface *intf, bool reset_resume) snd_usbmidi_resume(p); } - if (!chip->autosuspended) + out: + if (chip->num_suspended_intf == chip->system_suspend) { snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0); - chip->autosuspended = 0; + chip->system_suspend = 0; + } + chip->num_suspended_intf--; err_out: atomic_dec(&chip->active); /* allow autopm after this point */ diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h index 1c892c7f14d7..e0ebfb25fbd5 100644 --- a/sound/usb/usbaudio.h +++ b/sound/usb/usbaudio.h @@ -26,7 +26,7 @@ struct snd_usb_audio { struct usb_interface *pm_intf; u32 usb_id; struct mutex mutex; - unsigned int autosuspended:1; + unsigned int system_suspend; atomic_t active; atomic_t shutdown; atomic_t usage_count; 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=-3.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no 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 D8080C433DF for ; Wed, 3 Jun 2020 08:46:08 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 A953820734 for ; Wed, 3 Jun 2020 08:46:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="eIn4zw0X" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A953820734 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Subject:To:From:Message-ID:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=gMfCmVSWNM2WOGsTfyhBtqlg21WfXB5a1Gh8553Z9C4=; b=eIn4zw0XSe+ZW9 KYporqkFa/QkT08ZUjod8M3G1Ttgar4w15LSOftsVsj0lwAeHmZ7mORBMWKEWkY6PBeJ+iTZ9iFjX 3c3guwmgVa2jwCt5W6J8dgn46ybLsRmbhAw12y/KWVZ0DdvCt5v9yj+ZoYNc5Z20tcaFE/Ri5uEKp SNjWqkA1hjC0DyUdf6wY+3bvynDriyiY2YmINpyU+8Xw6pNpZOvivcjksYEmoi/XpiacU091n+5I6 UxCckTj318MFj4G18siQFo0pReQPFviytHfvoZTA4thlpzpj9O0WMX+1Y4vvQPIPecV1DhH0QAeUi nZp0g9T5DXL/OxZK07mw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jgP25-0005Lw-Mg; Wed, 03 Jun 2020 08:45:57 +0000 Received: from mx2.suse.de ([195.135.220.15]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jgP1s-0005Av-Ci; Wed, 03 Jun 2020 08:45:46 +0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 77D98ACCC; Wed, 3 Jun 2020 08:45:45 +0000 (UTC) Date: Wed, 03 Jun 2020 10:45:41 +0200 Message-ID: From: Takashi Iwai To: Macpaul Lin Subject: Re: [PATCH] sound: usb: pcm: fix incorrect power state when playing sound after PM_AUTO suspend In-Reply-To: References: <1591153515.23525.50.camel@mtkswgap22> 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") X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200603_014544_722210_4CEF0B90 X-CRM114-Status: GOOD ( 20.21 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alsa-devel@alsa-project.org, Mediatek WSD Upstream , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, Johan Hovold , Takashi Iwai , Hui Wang , Alexander Tsoy , linux-mediatek@lists.infradead.org, Greg Kroah-Hartman , Matthias Brugger , Macpaul Lin , Jaroslav Kysela , Szabolcs =?UTF-8?B?U3rFkWtl?= , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org On Wed, 03 Jun 2020 08:54:51 +0200, Takashi Iwai wrote: > > On Wed, 03 Jun 2020 08:28:09 +0200, > Takashi Iwai wrote: > > > > And, the most suspicious case is the last one, > > chip->num_suspended-intf. It means that the device has multiple > > USB interfaces and they went to suspend, while the resume isn't > > performed for the all suspended interfaces in return. > > If this is the cause, a patch like below might help. > It gets/puts the all assigned interfaced instead of only the primary > one. ... and considering of the problem again, rather the patch below might be the right answer. Now the driver tries to remember at which state it entered into the system-suspend. Upon resume, in return, when the state reaches back to that point, set the card state to D0. The previous patch can be applied on the top, too, and it might be worth to apply both. Let me know if any of those actually helps. Takashi --- diff --git a/sound/usb/card.c b/sound/usb/card.c --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -843,9 +843,6 @@ static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message) if (chip == (void *)-1L) return 0; - chip->autosuspended = !!PMSG_IS_AUTO(message); - if (!chip->autosuspended) - snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot); if (!chip->num_suspended_intf++) { list_for_each_entry(as, &chip->pcm_list, list) { snd_usb_pcm_suspend(as); @@ -858,6 +855,11 @@ static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message) snd_usb_mixer_suspend(mixer); } + if (!PMSG_IS_AUTO(message) && !chip->system_suspend) { + snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot); + chip->system_suspend = chip->num_suspended_intf; + } + return 0; } @@ -871,10 +873,10 @@ static int __usb_audio_resume(struct usb_interface *intf, bool reset_resume) if (chip == (void *)-1L) return 0; - if (--chip->num_suspended_intf) - return 0; atomic_inc(&chip->active); /* avoid autopm */ + if (chip->num_suspended_intf > 1) + goto out; list_for_each_entry(as, &chip->pcm_list, list) { err = snd_usb_pcm_resume(as); @@ -896,9 +898,12 @@ static int __usb_audio_resume(struct usb_interface *intf, bool reset_resume) snd_usbmidi_resume(p); } - if (!chip->autosuspended) + out: + if (chip->num_suspended_intf == chip->system_suspend) { snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0); - chip->autosuspended = 0; + chip->system_suspend = 0; + } + chip->num_suspended_intf--; err_out: atomic_dec(&chip->active); /* allow autopm after this point */ diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h index 1c892c7f14d7..e0ebfb25fbd5 100644 --- a/sound/usb/usbaudio.h +++ b/sound/usb/usbaudio.h @@ -26,7 +26,7 @@ struct snd_usb_audio { struct usb_interface *pm_intf; u32 usb_id; struct mutex mutex; - unsigned int autosuspended:1; + unsigned int system_suspend; atomic_t active; atomic_t shutdown; atomic_t usage_count; _______________________________________________ Linux-mediatek mailing list Linux-mediatek@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-mediatek 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=-3.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no 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 91FE7C433DF for ; Wed, 3 Jun 2020 08:45:49 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 5120020674 for ; Wed, 3 Jun 2020 08:45:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="CVLagfuO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5120020674 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Subject:To:From:Message-ID:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mLOmpc+rOCbiwA7mdc67NlB6wfTsoZSN3qI9RWm5jHE=; b=CVLagfuObrr/+x Qhq5KI/UlcyV0AxB+mSeUpSBjgCB8ZjhpzCbdtJwMny3OBEXez6ApTcviK8I/H5DigrJrIrEo1e+A SLYYhukmPFBMWeGAo1QZ3O/D8zCsbFg4yZrsHcebJIk+WDz8pPrwnVln4SHzZGnYhdWbWBAPx+Ly8 quO9VYXsGHaS6Xc1fDfCHaCxJD/3sTU+v4ZmlrHPLmg7SmeJvObZtW61wknIah+TdXKNOgw5G0CSZ sXQUGFuGTybCPP13p3/4sMyNYgAwkjflBplpUG80tl14xdE5QSqoy6fwtXbCAXzstOkELXy66vc/w qnQ7Z7EqFaXJNvrT4Dcw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jgP1v-0005BW-GX; Wed, 03 Jun 2020 08:45:47 +0000 Received: from mx2.suse.de ([195.135.220.15]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jgP1s-0005Av-Ci; Wed, 03 Jun 2020 08:45:46 +0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 77D98ACCC; Wed, 3 Jun 2020 08:45:45 +0000 (UTC) Date: Wed, 03 Jun 2020 10:45:41 +0200 Message-ID: From: Takashi Iwai To: Macpaul Lin Subject: Re: [PATCH] sound: usb: pcm: fix incorrect power state when playing sound after PM_AUTO suspend In-Reply-To: References: <1591153515.23525.50.camel@mtkswgap22> 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") X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200603_014544_722210_4CEF0B90 X-CRM114-Status: GOOD ( 20.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alsa-devel@alsa-project.org, Mediatek WSD Upstream , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, Johan Hovold , Takashi Iwai , Hui Wang , Alexander Tsoy , linux-mediatek@lists.infradead.org, Greg Kroah-Hartman , Matthias Brugger , Macpaul Lin , Jaroslav Kysela , Szabolcs =?UTF-8?B?U3rFkWtl?= , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, 03 Jun 2020 08:54:51 +0200, Takashi Iwai wrote: > > On Wed, 03 Jun 2020 08:28:09 +0200, > Takashi Iwai wrote: > > > > And, the most suspicious case is the last one, > > chip->num_suspended-intf. It means that the device has multiple > > USB interfaces and they went to suspend, while the resume isn't > > performed for the all suspended interfaces in return. > > If this is the cause, a patch like below might help. > It gets/puts the all assigned interfaced instead of only the primary > one. ... and considering of the problem again, rather the patch below might be the right answer. Now the driver tries to remember at which state it entered into the system-suspend. Upon resume, in return, when the state reaches back to that point, set the card state to D0. The previous patch can be applied on the top, too, and it might be worth to apply both. Let me know if any of those actually helps. Takashi --- diff --git a/sound/usb/card.c b/sound/usb/card.c --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -843,9 +843,6 @@ static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message) if (chip == (void *)-1L) return 0; - chip->autosuspended = !!PMSG_IS_AUTO(message); - if (!chip->autosuspended) - snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot); if (!chip->num_suspended_intf++) { list_for_each_entry(as, &chip->pcm_list, list) { snd_usb_pcm_suspend(as); @@ -858,6 +855,11 @@ static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message) snd_usb_mixer_suspend(mixer); } + if (!PMSG_IS_AUTO(message) && !chip->system_suspend) { + snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot); + chip->system_suspend = chip->num_suspended_intf; + } + return 0; } @@ -871,10 +873,10 @@ static int __usb_audio_resume(struct usb_interface *intf, bool reset_resume) if (chip == (void *)-1L) return 0; - if (--chip->num_suspended_intf) - return 0; atomic_inc(&chip->active); /* avoid autopm */ + if (chip->num_suspended_intf > 1) + goto out; list_for_each_entry(as, &chip->pcm_list, list) { err = snd_usb_pcm_resume(as); @@ -896,9 +898,12 @@ static int __usb_audio_resume(struct usb_interface *intf, bool reset_resume) snd_usbmidi_resume(p); } - if (!chip->autosuspended) + out: + if (chip->num_suspended_intf == chip->system_suspend) { snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0); - chip->autosuspended = 0; + chip->system_suspend = 0; + } + chip->num_suspended_intf--; err_out: atomic_dec(&chip->active); /* allow autopm after this point */ diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h index 1c892c7f14d7..e0ebfb25fbd5 100644 --- a/sound/usb/usbaudio.h +++ b/sound/usb/usbaudio.h @@ -26,7 +26,7 @@ struct snd_usb_audio { struct usb_interface *pm_intf; u32 usb_id; struct mutex mutex; - unsigned int autosuspended:1; + unsigned int system_suspend; atomic_t active; atomic_t shutdown; atomic_t usage_count; _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel