Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1268459ybg; Tue, 2 Jun 2020 05:50:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxp3LcRs1Mw0eW8My7v8IdGJPb2SYWxOtNDcPbwI1WXI03NHfJyFcaw6BQDYbOtbKRAf/Su X-Received: by 2002:a17:906:1947:: with SMTP id b7mr9435286eje.320.1591102253613; Tue, 02 Jun 2020 05:50:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591102253; cv=none; d=google.com; s=arc-20160816; b=tR6tCTN4kQ5ie6MVw32jdVHevs26i5faLu9Sj06pEeWX4n1HDpcoXOl0lc/9cMMQUC oDMRhEHu25ZEMIeYbcv1P0G6IiLaCUUYxrfwqYXpwJwV0/wKMlV2/V4bP4TU5r6nTmJ5 CZZwPi2K1duEP18vAxubDDGl7z8o6ruh+WF0G5t6dM7EE9875fvcJK58aELhjIfuO/vK RmCx4TdUv8LO939HSWAQUNNRw68RSmanvM1eFUlV8C1fbf4+w7dl8Ld76GcW9ZbegvcX B6d6zoMzMyPD9Lfx2ntMF4zpp4jQh3q0N0FMQkZuDYlc+liCTJTfrzXYBw3Dt9xfd1Xb uZzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:in-reply-to :subject:cc:to:from:message-id:date; bh=/T2L6xdsHvjcLszbVV4esgB219m4mddxdSgBN+kDAdA=; b=jsThkwnjp6Jmo+S5ycOUSnvx0YIg5gGLziJZGn2qMz1yxdhXo9Vuf0VWgZJX/AanPL 2jRs5+E+oSupKg7/4wWcA0mrHsjdTcH7/8iF8hVAwlVqLvQD1leN7oGY56Ci7MZ+i7QP z6Xg/n/fd5KLLMtLEZi/5dzPgBaLorHfO27dZDwI30ItP0yFOn+nF3Bd5Zn9caUlwZWZ adopn19KEZCMI4q1u+IQAMzRiHKeTZoq8vsgFWR8ZfjwMgyLPajemSIthknh9ade54AU eLVWRLb4kg6QqYZmZx+0WvAKo9t4rZjldCvCcni14bM3m7w9kYUz/eRZA2AU95JjYAOF /0tw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dr4si1673178ejc.239.2020.06.02.05.50.30; Tue, 02 Jun 2020 05:50:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726937AbgFBMqW (ORCPT + 99 others); Tue, 2 Jun 2020 08:46:22 -0400 Received: from mx2.suse.de ([195.135.220.15]:50626 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725940AbgFBMqV (ORCPT ); Tue, 2 Jun 2020 08:46:21 -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 17CF8ABD1; Tue, 2 Jun 2020 12:46:22 +0000 (UTC) Date: Tue, 02 Jun 2020 14:46:19 +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 , , , Subject: Re: [PATCH] sound: usb: pcm: fix incorrect power state when playing sound after PM_AUTO suspend In-Reply-To: <1591098821-17910-1-git-send-email-macpaul.lin@mediatek.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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 02 Jun 2020 13:53:41 +0200, Macpaul Lin wrote: > > 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. Hm, in exactly which situation does this happen? I still don't get it. Could you elaborate how to trigger this? > 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. This doesn't look like a right solution for the problem, sorry. The card PM status must be recovered to D0 when the autoresume succeeds. If not, something is broken there, and it must be fixed instead of fiddling the status flag externally. thanks, Takashi > > 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); > } > > -- > 1.7.9.5