Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp330338ybg; Wed, 3 Jun 2020 01:49:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwCmTxkOeAHMrOgqceh/M96I0ATVKLYlayhiD70axpz3/jh/S7wwpFhotV7gZa2ndyO5eBj X-Received: by 2002:aa7:d6d0:: with SMTP id x16mr25114325edr.175.1591174152553; Wed, 03 Jun 2020 01:49:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591174152; cv=none; d=google.com; s=arc-20160816; b=AyBYLkjm3bWzGjjvqAY+4FVWy3MIg7EluZe3grmzmVa8+LHuzcOTegsWjqO9dg0Iyq HjRL1b5BeU4I69K/Tbbcw/a0I+UQ4/H3KeDAZ22EAI6lABOJWeGJuMbtdcffFBmfPw39 BUYwR5VqkfM9gsSk1z9nFKqo+dOkwnoEO0+lpVQC3tMJju3GX54KzKz1ifgN8tXIsxaQ +p29fcXBFk/DBNv8+ceyUULPPWVkGltpFUw1bkiL0dbVLRUlK1jtATjr2IIKA8c540yW k3/ppaSuB/gmQYTQegKOqXA1wq31rAnLB7KzCd0v8171KrPnmy0Udz17S+yw7EBrQMZb h7yg== 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:references :in-reply-to:subject:cc:to:from:message-id:date; bh=pxuyt5V9heLGD0xWN4Rgj56yksf9fVbYPulmqnmUVRk=; b=XFe1WVkHWC7FJeo2tmkgv7XBmb7SClVhVmMBcGVvfE7KyHVVBSKcFuJMb9R4KEX4sG xRkdPAfOPcbsNt3SAexMFyNPbR+hOoFKmDhbNOtZRf/nL7hvKWDVINY0NsZ34u52lcMB fb4Prcv7vv6gBxRgBofRWaub1NRYDcdY3rM92AXjFrboPPKJKMk9YOnz8vMIDdD6yC9b tik6Ey8/e1EKsM2GV1D6Xs0SE4SY1l53N8fD+DCtzgKyJ3F/wZSvX7j6NgKe5EdlQUOu pD2kEYbt+ttixhqs7dcTMqvNuFPqNvXzQAB/dD1bd2JQfMSFB/KE3SwgK4jPnG9RyDOr fzRw== 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 u2si810272edp.67.2020.06.03.01.48.49; Wed, 03 Jun 2020 01:49:12 -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 S1726419AbgFCIpp (ORCPT + 99 others); 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;