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
Subject: Re: [PATCH] sound: usb: pcm: fix incorrect power state when playing sound after PM_AUTO suspend
Date: Tue, 02 Jun 2020 14:46:19 +0200	[thread overview]
Message-ID: <s5hpnahhbz8.wl-tiwai@suse.de> (raw)
In-Reply-To: <1591098821-17910-1-git-send-email-macpaul.lin@mediatek.com>

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 <macpaul.lin@mediatek.com>
> ---
>  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

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,
	"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: Tue, 02 Jun 2020 14:46:19 +0200	[thread overview]
Message-ID: <s5hpnahhbz8.wl-tiwai@suse.de> (raw)
In-Reply-To: <1591098821-17910-1-git-send-email-macpaul.lin@mediatek.com>

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 <macpaul.lin@mediatek.com>
> ---
>  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

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,
	"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: Tue, 02 Jun 2020 14:46:19 +0200	[thread overview]
Message-ID: <s5hpnahhbz8.wl-tiwai@suse.de> (raw)
In-Reply-To: <1591098821-17910-1-git-send-email-macpaul.lin@mediatek.com>

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 <macpaul.lin@mediatek.com>
> ---
>  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

_______________________________________________
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,
	"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: Tue, 02 Jun 2020 14:46:19 +0200	[thread overview]
Message-ID: <s5hpnahhbz8.wl-tiwai@suse.de> (raw)
In-Reply-To: <1591098821-17910-1-git-send-email-macpaul.lin@mediatek.com>

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 <macpaul.lin@mediatek.com>
> ---
>  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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2020-06-02 12:46 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 [this message]
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
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=s5hpnahhbz8.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alexander@tsoy.me \
    --cc=alsa-devel@alsa-project.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.