All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Macpaul Lin <macpaul.lin@mediatek.com>
Cc: "Jaroslav Kysela" <perex@perex.cz>,
	"Takashi Iwai" <tiwai@suse.com>,
	"Matthias Brugger" <matthias.bgg@gmail.com>,
	"Alexander Tsoy" <alexander@tsoy.me>,
	"Johan Hovold" <johan@kernel.org>,
	"Hui Wang" <hui.wang@canonical.com>,
	"Szabolcs Szőke" <szszoke.code@gmail.com>,
	alsa-devel@alsa-project.org, linux-usb@vger.kernel.org,
	"Mediatek WSD Upstream" <wsd_upstream@mediatek.com>,
	"Macpaul Lin" <macpaul.lin@gmail.com>,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>
Subject: Re: [PATCH] sound: usb: pcm: fix incorrect power state when playing sound after PM_AUTO suspend
Date: Wed, 03 Jun 2020 10:45:41 +0200	[thread overview]
Message-ID: <s5h367cfsga.wl-tiwai@suse.de> (raw)
In-Reply-To: <s5hblm0fxl0.wl-tiwai@suse.de>

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;

WARNING: multiple messages have this Message-ID (diff)
From: Takashi Iwai <tiwai@suse.de>
To: Macpaul Lin <macpaul.lin@mediatek.com>
Cc: alsa-devel@alsa-project.org,
	"Mediatek WSD Upstream" <wsd_upstream@mediatek.com>,
	linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org,
	"Johan Hovold" <johan@kernel.org>,
	"Takashi Iwai" <tiwai@suse.com>,
	"Hui Wang" <hui.wang@canonical.com>,
	"Alexander Tsoy" <alexander@tsoy.me>,
	linux-mediatek@lists.infradead.org,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Matthias Brugger" <matthias.bgg@gmail.com>,
	"Macpaul Lin" <macpaul.lin@gmail.com>,
	"Szabolcs Szőke" <szszoke.code@gmail.com>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] sound: usb: pcm: fix incorrect power state when playing sound after PM_AUTO suspend
Date: Wed, 03 Jun 2020 10:45:41 +0200	[thread overview]
Message-ID: <s5h367cfsga.wl-tiwai@suse.de> (raw)
In-Reply-To: <s5hblm0fxl0.wl-tiwai@suse.de>

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;

WARNING: multiple messages have this Message-ID (diff)
From: Takashi Iwai <tiwai@suse.de>
To: Macpaul Lin <macpaul.lin@mediatek.com>
Cc: alsa-devel@alsa-project.org,
	"Mediatek WSD Upstream" <wsd_upstream@mediatek.com>,
	linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org,
	"Johan Hovold" <johan@kernel.org>,
	"Takashi Iwai" <tiwai@suse.com>,
	"Hui Wang" <hui.wang@canonical.com>,
	"Alexander Tsoy" <alexander@tsoy.me>,
	linux-mediatek@lists.infradead.org,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Matthias Brugger" <matthias.bgg@gmail.com>,
	"Macpaul Lin" <macpaul.lin@gmail.com>,
	"Jaroslav Kysela" <perex@perex.cz>,
	"Szabolcs Szőke" <szszoke.code@gmail.com>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] sound: usb: pcm: fix incorrect power state when playing sound after PM_AUTO suspend
Date: Wed, 03 Jun 2020 10:45:41 +0200	[thread overview]
Message-ID: <s5h367cfsga.wl-tiwai@suse.de> (raw)
In-Reply-To: <s5hblm0fxl0.wl-tiwai@suse.de>

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

WARNING: multiple messages have this Message-ID (diff)
From: Takashi Iwai <tiwai@suse.de>
To: Macpaul Lin <macpaul.lin@mediatek.com>
Cc: alsa-devel@alsa-project.org,
	"Mediatek WSD Upstream" <wsd_upstream@mediatek.com>,
	linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org,
	"Johan Hovold" <johan@kernel.org>,
	"Takashi Iwai" <tiwai@suse.com>,
	"Hui Wang" <hui.wang@canonical.com>,
	"Alexander Tsoy" <alexander@tsoy.me>,
	linux-mediatek@lists.infradead.org,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Matthias Brugger" <matthias.bgg@gmail.com>,
	"Macpaul Lin" <macpaul.lin@gmail.com>,
	"Jaroslav Kysela" <perex@perex.cz>,
	"Szabolcs Szőke" <szszoke.code@gmail.com>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] sound: usb: pcm: fix incorrect power state when playing sound after PM_AUTO suspend
Date: Wed, 03 Jun 2020 10:45:41 +0200	[thread overview]
Message-ID: <s5h367cfsga.wl-tiwai@suse.de> (raw)
In-Reply-To: <s5hblm0fxl0.wl-tiwai@suse.de>

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

  reply	other threads:[~2020-06-03  8:45 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org>
2020-06-02 11:53 ` [PATCH] sound: usb: pcm: fix incorrect power state when playing sound after PM_AUTO suspend Macpaul Lin
2020-06-02 11:53   ` Macpaul Lin
2020-06-02 11:53   ` Macpaul Lin
2020-06-02 11:53   ` Macpaul Lin
2020-06-02 12:19   ` Macpaul Lin
2020-06-02 12:19     ` Macpaul Lin
2020-06-02 12:19     ` Macpaul Lin
2020-06-02 12:46   ` Takashi Iwai
2020-06-02 12:46     ` Takashi Iwai
2020-06-02 12:46     ` Takashi Iwai
2020-06-02 12:46     ` Takashi Iwai
2020-06-03  3:05     ` Macpaul Lin
2020-06-03  3:05       ` Macpaul Lin
2020-06-03  3:05       ` Macpaul Lin
2020-06-03  3:05       ` Macpaul Lin
2020-06-03  6:28       ` Takashi Iwai
2020-06-03  6:28         ` Takashi Iwai
2020-06-03  6:28         ` Takashi Iwai
2020-06-03  6:28         ` Takashi Iwai
2020-06-03  6:54         ` Takashi Iwai
2020-06-03  6:54           ` Takashi Iwai
2020-06-03  6:54           ` Takashi Iwai
2020-06-03  6:54           ` Takashi Iwai
2020-06-03  8:45           ` Takashi Iwai [this message]
2020-06-03  8:45             ` Takashi Iwai
2020-06-03  8:45             ` Takashi Iwai
2020-06-03  8:45             ` Takashi Iwai
2020-06-03 12:39             ` Macpaul Lin
2020-06-03 12:39               ` Macpaul Lin
2020-06-03 12:39               ` Macpaul Lin
2020-06-03 12:39               ` Macpaul Lin
2020-06-03 12:47               ` Takashi Iwai
2020-06-03 12:47                 ` Takashi Iwai
2020-06-03 12:47                 ` Takashi Iwai
2020-06-03 12:47                 ` Takashi Iwai
2020-06-03 13:50                 ` Macpaul Lin
2020-06-03 13:50                   ` Macpaul Lin
2020-06-03 13:50                   ` Macpaul Lin
2020-06-03 13:50                   ` Macpaul Lin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=s5h367cfsga.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alexander@tsoy.me \
    --cc=alsa-devel@alsa-project.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hui.wang@canonical.com \
    --cc=johan@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=macpaul.lin@gmail.com \
    --cc=macpaul.lin@mediatek.com \
    --cc=matthias.bgg@gmail.com \
    --cc=perex@perex.cz \
    --cc=szszoke.code@gmail.com \
    --cc=tiwai@suse.com \
    --cc=wsd_upstream@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.