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 D6B5BC433DF for ; Wed, 3 Jun 2020 12:47:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B206020678 for ; Wed, 3 Jun 2020 12:47:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726118AbgFCMrf (ORCPT ); Wed, 3 Jun 2020 08:47:35 -0400 Received: from mx2.suse.de ([195.135.220.15]:46494 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725906AbgFCMre (ORCPT ); Wed, 3 Jun 2020 08:47:34 -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 8C9F0AE38; Wed, 3 Jun 2020 12:47:35 +0000 (UTC) Date: Wed, 03 Jun 2020 14:47:31 +0200 Message-ID: From: Takashi Iwai To: Macpaul Lin Cc: , Mediatek WSD Upstream , , , Johan Hovold , Takashi Iwai , Hui Wang , Alexander Tsoy , , Greg Kroah-Hartman , Matthias Brugger , Macpaul Lin , Jaroslav Kysela , Szabolcs =?UTF-8?B?U3rFkWtl?= , , Subject: Re: [PATCH] sound: usb: pcm: fix incorrect power state when playing sound after PM_AUTO suspend In-Reply-To: <1591187964.23525.61.camel@mtkswgap22> References: <1591153515.23525.50.camel@mtkswgap22> <1591187964.23525.61.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 14:39:24 +0200, Macpaul Lin wrote: > > On Wed, 2020-06-03 at 10:45 +0200, Takashi Iwai wrote: > > 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 > > Thanks for your response so quickly. > I've just test this patch since it looks like enough for the issue. Good to hear! > This patch worked since the flag system_suspend will be set at the same > time when power state has been changed. I have 2 interface with the head > set. But actually the problem happened when primary one is suspended. Currently the autosuspend is set only to the primary interface; IOW, the other interfaces will never get autosuspend, and the another suspend-all-intf patch should improve that situation. But it won't fix your actual bug, obviously :) > So I didn't test the earlier patch "suspend all interface instead of > only the primary one." Could you try it one on top of the last patch? At least I'd like to see whether it causes any regression. > Will you resend this patch officially later? I think this solution is > required to send to stable, too. It's better to have it for other stable > kernel versions include android's. Yes, that's a general bug and worth to be merged quickly. I'm going to submit a proper patch soon later. thanks, 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; > > > > _______________________________________________ > > Thank you very much! > > Best regards, > Macpaul Lin > > 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 4A814C433DF for ; Wed, 3 Jun 2020 12:48:33 +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 CB3EF20738 for ; Wed, 3 Jun 2020 12:48:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="so3ccgxf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CB3EF20738 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 4AB8B845; Wed, 3 Jun 2020 14:47:41 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 4AB8B845 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1591188511; bh=n7ILkXbXp1MW9a6MoDWj7q32wvi4j1aKgnkqQjmmehU=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=so3ccgxfBVnCd2mkH0M+Fu9bmLSK7SswlBDEU840csN8AmtYadG8SmvDNW+5ugFMY S1bYe28QOxPxWrrTX9AnvVMp5luxUGBzISosKEGhOzVc3uHSD97XUfrHasjd+C/OAj 616F6VHaWaMIqFFtiyKqH3zpEmUKCfgQ8HqKQEMw= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 9CAB4F801EC; Wed, 3 Jun 2020 14:47:40 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id DE846F801ED; Wed, 3 Jun 2020 14:47:37 +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 11310F800BC for ; Wed, 3 Jun 2020 14:47:33 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 11310F800BC 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 8C9F0AE38; Wed, 3 Jun 2020 12:47:35 +0000 (UTC) Date: Wed, 03 Jun 2020 14:47:31 +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: <1591187964.23525.61.camel@mtkswgap22> References: <1591153515.23525.50.camel@mtkswgap22> <1591187964.23525.61.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, Szabolcs =?UTF-8?B?U3rFkWtl?= , Mediatek WSD Upstream , Greg Kroah-Hartman , linux-usb@vger.kernel.org, Takashi Iwai , stable@vger.kernel.org, linux-kernel@vger.kernel.org, Hui Wang , Alexander Tsoy , linux-mediatek@lists.infradead.org, Matthias Brugger , Johan Hovold , Macpaul Lin , 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 14:39:24 +0200, Macpaul Lin wrote: > > On Wed, 2020-06-03 at 10:45 +0200, Takashi Iwai wrote: > > 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 > > Thanks for your response so quickly. > I've just test this patch since it looks like enough for the issue. Good to hear! > This patch worked since the flag system_suspend will be set at the same > time when power state has been changed. I have 2 interface with the head > set. But actually the problem happened when primary one is suspended. Currently the autosuspend is set only to the primary interface; IOW, the other interfaces will never get autosuspend, and the another suspend-all-intf patch should improve that situation. But it won't fix your actual bug, obviously :) > So I didn't test the earlier patch "suspend all interface instead of > only the primary one." Could you try it one on top of the last patch? At least I'd like to see whether it causes any regression. > Will you resend this patch officially later? I think this solution is > required to send to stable, too. It's better to have it for other stable > kernel versions include android's. Yes, that's a general bug and worth to be merged quickly. I'm going to submit a proper patch soon later. thanks, 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; > > > > _______________________________________________ > > Thank you very much! > > Best regards, > Macpaul Lin > > 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,URIBL_BLOCKED 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 A120FC433E0 for ; Wed, 3 Jun 2020 12:47:51 +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 6CC6620678 for ; Wed, 3 Jun 2020 12:47:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="rObXWxwR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6CC6620678 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=BF2eFZOoW+VpUp4Pk4mJy5NS0f6X5LaKD2sbluEp++Y=; b=rObXWxwReu3BxU fiRT5M9y2GOrhMZgORA0va2mnHzUmDJ/ZPz17ggAv5KoHLkfmUThdq/lp4D6zlPm0QNYUW4piJ8d4 ABVQjgjOet/VYcfbkPmcU3JJkmu/irvbgul6NPGd1vsFOsf2bOvsJjVc7QBDGKQqrYFM/zOihHfL5 HtQCKxF05lzPNG9QSlc/bxSKZJpkB7/8xCdnNsR65Jds57eY8dFYxBjwfvhfoT/7hTelTdLaQUqCk B0EJdxoPlNq1tkT9PkQ64KPxUkiIPggggg4hVg2fpI+Ww5P4txRay15GVWGah0mL2szY54tGcWROG OeWkGIWSj/9SxX1bk9NA==; 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 1jgSo4-0000Lu-KW; Wed, 03 Jun 2020 12:47:44 +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 1jgSnw-0000D3-20; Wed, 03 Jun 2020 12:47:37 +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 8C9F0AE38; Wed, 3 Jun 2020 12:47:35 +0000 (UTC) Date: Wed, 03 Jun 2020 14:47:31 +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: <1591187964.23525.61.camel@mtkswgap22> References: <1591153515.23525.50.camel@mtkswgap22> <1591187964.23525.61.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_054736_385237_0C265BD4 X-CRM114-Status: GOOD ( 33.22 ) 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, Szabolcs =?UTF-8?B?U3rFkWtl?= , Mediatek WSD Upstream , Greg Kroah-Hartman , linux-usb@vger.kernel.org, Takashi Iwai , stable@vger.kernel.org, linux-kernel@vger.kernel.org, Hui Wang , Alexander Tsoy , linux-mediatek@lists.infradead.org, Matthias Brugger , Johan Hovold , Jaroslav Kysela , Macpaul Lin , 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 14:39:24 +0200, Macpaul Lin wrote: > > On Wed, 2020-06-03 at 10:45 +0200, Takashi Iwai wrote: > > 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 > > Thanks for your response so quickly. > I've just test this patch since it looks like enough for the issue. Good to hear! > This patch worked since the flag system_suspend will be set at the same > time when power state has been changed. I have 2 interface with the head > set. But actually the problem happened when primary one is suspended. Currently the autosuspend is set only to the primary interface; IOW, the other interfaces will never get autosuspend, and the another suspend-all-intf patch should improve that situation. But it won't fix your actual bug, obviously :) > So I didn't test the earlier patch "suspend all interface instead of > only the primary one." Could you try it one on top of the last patch? At least I'd like to see whether it causes any regression. > Will you resend this patch officially later? I think this solution is > required to send to stable, too. It's better to have it for other stable > kernel versions include android's. Yes, that's a general bug and worth to be merged quickly. I'm going to submit a proper patch soon later. thanks, 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; > > > > _______________________________________________ > > Thank you very much! > > Best regards, > Macpaul Lin > > _______________________________________________ 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,URIBL_BLOCKED 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 74448C433E0 for ; Wed, 3 Jun 2020 12:47:39 +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 39AFC207DF for ; Wed, 3 Jun 2020 12:47:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="MAt4DGby" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 39AFC207DF 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=Gy/RySV7knz6Mfesf3+sB97prMRlYdQL9uupTCAYvls=; b=MAt4DGbyZLFNGm NtMUvYUGL6S+fNI418PfdoCKCKDmcDL9BV/7KlpFpV/dRF/5EC6F8sbugBXRaUPkIDGC+XAARJX/9 nMKseTkCxwXMUrvVYRKA55WwbvsfZ67sYkra/u7w1KYaVQCmNeYn4yUNOocENFNRNw6pnK82KAUL3 kTpxB7svrTl0dtwQ+3uMZLP3g/KKKZiBUTwaS0W9u5xr/ah1+DixWx7PdiTXPx3Lbyu/kNLNRnyz1 phHpd/EfNBq4DUsMvrsyOGOAf3h7XtVfIHGMt6mo2m1Xso+2ry71uW7N2XYKRAW1f6wkYbt/tOTPw m2Oa/Tf8RfmMLpeZOw5Q==; 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 1jgSny-0000Ds-Rc; Wed, 03 Jun 2020 12:47:38 +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 1jgSnw-0000D3-20; Wed, 03 Jun 2020 12:47:37 +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 8C9F0AE38; Wed, 3 Jun 2020 12:47:35 +0000 (UTC) Date: Wed, 03 Jun 2020 14:47:31 +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: <1591187964.23525.61.camel@mtkswgap22> References: <1591153515.23525.50.camel@mtkswgap22> <1591187964.23525.61.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_054736_385237_0C265BD4 X-CRM114-Status: GOOD ( 33.22 ) 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, Szabolcs =?UTF-8?B?U3rFkWtl?= , Mediatek WSD Upstream , Greg Kroah-Hartman , linux-usb@vger.kernel.org, Takashi Iwai , stable@vger.kernel.org, linux-kernel@vger.kernel.org, Hui Wang , Alexander Tsoy , linux-mediatek@lists.infradead.org, Matthias Brugger , Johan Hovold , Jaroslav Kysela , Macpaul Lin , 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 14:39:24 +0200, Macpaul Lin wrote: > > On Wed, 2020-06-03 at 10:45 +0200, Takashi Iwai wrote: > > 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 > > Thanks for your response so quickly. > I've just test this patch since it looks like enough for the issue. Good to hear! > This patch worked since the flag system_suspend will be set at the same > time when power state has been changed. I have 2 interface with the head > set. But actually the problem happened when primary one is suspended. Currently the autosuspend is set only to the primary interface; IOW, the other interfaces will never get autosuspend, and the another suspend-all-intf patch should improve that situation. But it won't fix your actual bug, obviously :) > So I didn't test the earlier patch "suspend all interface instead of > only the primary one." Could you try it one on top of the last patch? At least I'd like to see whether it causes any regression. > Will you resend this patch officially later? I think this solution is > required to send to stable, too. It's better to have it for other stable > kernel versions include android's. Yes, that's a general bug and worth to be merged quickly. I'm going to submit a proper patch soon later. thanks, 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; > > > > _______________________________________________ > > Thank you very much! > > Best regards, > Macpaul Lin > > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel