* Re: [PATCH] ASoC: dapm: Fix the unpaired runtime_get/put cases
2012-12-19 10:36 [PATCH] ASoC: dapm: Fix the unpaired runtime_get/put cases Chuansheng Liu
@ 2012-12-19 9:11 ` Mark Brown
2012-12-20 6:37 ` Liu, Chuansheng
2012-12-21 10:17 ` [PATCH] ASoC: core: giving WARN when device starting from non-off bias with idle_bias_off Chuansheng Liu
1 sibling, 1 reply; 7+ messages in thread
From: Mark Brown @ 2012-12-19 9:11 UTC (permalink / raw)
To: Chuansheng Liu; +Cc: tiwai, linux-kernel, alsa-devel, lrg
[-- Attachment #1.1: Type: text/plain, Size: 938 bytes --]
On Wed, Dec 19, 2012 at 06:36:37PM +0800, Chuansheng Liu wrote:
> But some devices has been set to STANDY bias directly during device probing,
> such as cs42l73_probe():
> cs42l73_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
> Then it will cause runtime_get() not be called but laterly runtime_put() will
> be called. Also found some other uppaired cases.
This is just a bug in the driver, if it's idle_bias_off then it really
should be starting in _OFF or at the very least starting actually in
_STANDBY (including taking the runtime reference) rather than partially
in _STANDBY.
> So here add new flag get_runtime, and the logic will be:
> 1/ when device is from off to non-off bias, runtime_get() will be called if not yet;
> 2/ When device is off bias, runtime_put() will be called if runtime_get() has
> been called;
This is really not a good idea at all, it's just adding new special
cases and making the code more obscure.
[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
[-- Attachment #2: Type: text/plain, Size: 0 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] ASoC: dapm: Fix the unpaired runtime_get/put cases
@ 2012-12-19 10:36 Chuansheng Liu
2012-12-19 9:11 ` Mark Brown
2012-12-21 10:17 ` [PATCH] ASoC: core: giving WARN when device starting from non-off bias with idle_bias_off Chuansheng Liu
0 siblings, 2 replies; 7+ messages in thread
From: Chuansheng Liu @ 2012-12-19 10:36 UTC (permalink / raw)
To: broonie, lrg, perex, tiwai; +Cc: alsa-devel, linux-kernel, chuansheng.liu
Commit f1aac484f7(Take a pm_runtime reference on DAPM devices that are enabled)
introduced runtime_get/put calling when devices are in off/non-off bias.
It is based on:
1/ device from off to non-off bias is called thru dapm_pre_sequence_async;
2/ device from non-off to off bias is called thru dapm_post_sequence_async;
There are the above conditions which then make sure runtime_get/put() are pairs.
But some devices has been set to STANDY bias directly during device probing,
such as cs42l73_probe():
cs42l73_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
Then it will cause runtime_get() not be called but laterly runtime_put() will
be called. Also found some other uppaired cases.
So here add new flag get_runtime, and the logic will be:
1/ when device is from off to non-off bias, runtime_get() will be called if not yet;
2/ When device is off bias, runtime_put() will be called if runtime_get() has
been called;
Signed-off-by: liu chuansheng <chuansheng.liu@intel.com>
---
include/sound/soc-dapm.h | 1 +
sound/soc/soc-dapm.c | 18 ++++++++++++------
2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h
index e1ef63d..e52fdcc 100644
--- a/include/sound/soc-dapm.h
+++ b/include/sound/soc-dapm.h
@@ -586,6 +586,7 @@ struct snd_soc_dapm_context {
struct list_head list;
int (*stream_event)(struct snd_soc_dapm_context *dapm, int event);
+ bool get_runtime;
#ifdef CONFIG_DEBUG_FS
struct dentry *debugfs_dapm;
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 1e36bc8..e6d030a 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -1460,12 +1460,15 @@ static void dapm_pre_sequence_async(void *data, async_cookie_t cookie)
struct snd_soc_dapm_context *d = data;
int ret;
+ if ((d->target_bias_level != SND_SOC_BIAS_OFF) &&
+ (d->dev) && !(d->get_runtime)) {
+ pm_runtime_get_sync(d->dev);
+ d->get_runtime = true;
+ }
+
/* If we're off and we're not supposed to be go into STANDBY */
if (d->bias_level == SND_SOC_BIAS_OFF &&
d->target_bias_level != SND_SOC_BIAS_OFF) {
- if (d->dev)
- pm_runtime_get_sync(d->dev);
-
ret = snd_soc_dapm_set_bias_level(d, SND_SOC_BIAS_STANDBY);
if (ret != 0)
dev_err(d->dev,
@@ -1506,9 +1509,6 @@ static void dapm_post_sequence_async(void *data, async_cookie_t cookie)
if (ret != 0)
dev_err(d->dev, "ASoC: Failed to turn off bias: %d\n",
ret);
-
- if (d->dev)
- pm_runtime_put(d->dev);
}
/* If we just powered up then move to active bias */
@@ -1519,6 +1519,12 @@ static void dapm_post_sequence_async(void *data, async_cookie_t cookie)
dev_err(d->dev, "ASoC: Failed to apply active bias: %d\n",
ret);
}
+
+ if ((d->bias_level == SND_SOC_BIAS_OFF) &&
+ (d->dev) && (d->get_runtime)) {
+ pm_runtime_put(d->dev);
+ d->get_runtime = false;
+ }
}
static void dapm_widget_set_peer_power(struct snd_soc_dapm_widget *peer,
--
1.7.0.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* RE: [PATCH] ASoC: dapm: Fix the unpaired runtime_get/put cases
2012-12-19 9:11 ` Mark Brown
@ 2012-12-20 6:37 ` Liu, Chuansheng
2012-12-20 13:51 ` Mark Brown
0 siblings, 1 reply; 7+ messages in thread
From: Liu, Chuansheng @ 2012-12-20 6:37 UTC (permalink / raw)
To: Mark Brown
Cc: lrg@ti.com, perex@perex.cz, tiwai@suse.de,
alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org,
Liu, Chuansheng
> -----Original Message-----
> From: Mark Brown [mailto:broonie@opensource.wolfsonmicro.com]
> Sent: Wednesday, December 19, 2012 5:11 PM
> To: Liu, Chuansheng
> Cc: lrg@ti.com; perex@perex.cz; tiwai@suse.de; alsa-devel@alsa-project.org;
> linux-kernel@vger.kernel.org
> Subject: Re: [PATCH] ASoC: dapm: Fix the unpaired runtime_get/put cases
>
> On Wed, Dec 19, 2012 at 06:36:37PM +0800, Chuansheng Liu wrote:
>
> > But some devices has been set to STANDY bias directly during device probing,
> > such as cs42l73_probe():
> > cs42l73_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
>
> > Then it will cause runtime_get() not be called but laterly runtime_put() will
> > be called. Also found some other uppaired cases.
>
> This is just a bug in the driver, if it's idle_bias_off then it really
> should be starting in _OFF or at the very least starting actually in
> _STANDBY (including taking the runtime reference) rather than partially
> in _STANDBY.
Thanks your pointing out. You are totally right.
Rechecked the related driver code, there is one place which starting from _STANDBY with idle_bias_off.
It should be the main reason of bringing unpaired issue.
Meanwhile, is it useful to add one warning there for that case?
After all, in probing, set the bias to _STANDBY even idle_bias_off == 1, and calling get_runtime_sync(), it
will let the code more obscure. So giving a warning there to indicate the driver:
it is not suggested that in probing, set the bias to _STANDBY even idle_bias_off == 1.
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 9c768bc..d6adaec 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -1102,6 +1102,8 @@ static int soc_probe_codec(struct snd_soc_card *card,
if (driver->probe) {
ret = driver->probe(codec);
+ WARN_ON(codec->dapm.idle_bias_off &&
+ codec->dapm.bias_level != SND_SOC_BIAS_OFF);
if (ret < 0) {
dev_err(codec->dev,
"ASoC: failed to probe CODEC %d\n", ret);
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] ASoC: dapm: Fix the unpaired runtime_get/put cases
2012-12-20 6:37 ` Liu, Chuansheng
@ 2012-12-20 13:51 ` Mark Brown
2012-12-21 1:34 ` Liu, Chuansheng
0 siblings, 1 reply; 7+ messages in thread
From: Mark Brown @ 2012-12-20 13:51 UTC (permalink / raw)
To: Liu, Chuansheng
Cc: tiwai@suse.de, linux-kernel@vger.kernel.org,
alsa-devel@alsa-project.org, lrg@ti.com
[-- Attachment #1.1: Type: text/plain, Size: 633 bytes --]
On Thu, Dec 20, 2012 at 06:37:26AM +0000, Liu, Chuansheng wrote:
> Meanwhile, is it useful to add one warning there for that case?
> After all, in probing, set the bias to _STANDBY even idle_bias_off == 1, and calling get_runtime_sync(), it
> will let the code more obscure. So giving a warning there to indicate the driver:
> it is not suggested that in probing, set the bias to _STANDBY even idle_bias_off == 1.
Probably, send a patch please. Like I say it is possible to start off
in _STANDBY providing the driver grabs the runtime PM reference too but
I can't think of any reason for doing that so the warning seems sensible.
[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
[-- Attachment #2: Type: text/plain, Size: 0 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: [PATCH] ASoC: dapm: Fix the unpaired runtime_get/put cases
2012-12-20 13:51 ` Mark Brown
@ 2012-12-21 1:34 ` Liu, Chuansheng
0 siblings, 0 replies; 7+ messages in thread
From: Liu, Chuansheng @ 2012-12-21 1:34 UTC (permalink / raw)
To: Mark Brown
Cc: lrg@ti.com, perex@perex.cz, tiwai@suse.de,
alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org
> -----Original Message-----
> From: Mark Brown [mailto:broonie@opensource.wolfsonmicro.com]
> Sent: Thursday, December 20, 2012 9:51 PM
> To: Liu, Chuansheng
> Cc: lrg@ti.com; perex@perex.cz; tiwai@suse.de; alsa-devel@alsa-project.org;
> linux-kernel@vger.kernel.org
> Subject: Re: [PATCH] ASoC: dapm: Fix the unpaired runtime_get/put cases
>
> On Thu, Dec 20, 2012 at 06:37:26AM +0000, Liu, Chuansheng wrote:
>
> > Meanwhile, is it useful to add one warning there for that case?
> > After all, in probing, set the bias to _STANDBY even idle_bias_off == 1, and
> calling get_runtime_sync(), it
> > will let the code more obscure. So giving a warning there to indicate the
> driver:
> > it is not suggested that in probing, set the bias to _STANDBY even
> idle_bias_off == 1.
>
> Probably, send a patch please. Like I say it is possible to start off
> in _STANDBY providing the driver grabs the runtime PM reference too but
> I can't think of any reason for doing that so the warning seems sensible.
The patch https://lkml.org/lkml/2012/12/20/506 has been sent for giving warning
in that case. Thanks your reviewing.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] ASoC: core: giving WARN when device starting from non-off bias with idle_bias_off
2012-12-19 10:36 [PATCH] ASoC: dapm: Fix the unpaired runtime_get/put cases Chuansheng Liu
2012-12-19 9:11 ` Mark Brown
@ 2012-12-21 10:17 ` Chuansheng Liu
2012-12-24 15:35 ` Mark Brown
1 sibling, 1 reply; 7+ messages in thread
From: Chuansheng Liu @ 2012-12-21 10:17 UTC (permalink / raw)
To: broonie; +Cc: lrg, perex, tiwai, alsa-devel, linux-kernel, chuansheng.liu
Just found some cases that some codec drivers set the bias to _STANDBY and
set idle_bias_off to 1 during probing.
It will cause unpaired runtime_get_sync/put() issue. Also as Mark suggested,
there is no reason to start from _STANDBY bias with idle_bias_off == 1.
So here giving one warning when detected (dapm.idle_bias_off == 1) and
(dapm.bias_level != SND_SOC_BIAS_OFF) just after driver->probe().
Signed-off-by: liu chuansheng <chuansheng.liu@intel.com>
---
sound/soc/soc-core.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 9c768bc..d7ec007 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -1107,6 +1107,10 @@ static int soc_probe_codec(struct snd_soc_card *card,
"ASoC: failed to probe CODEC %d\n", ret);
goto err_probe;
}
+ WARN(codec->dapm.idle_bias_off &&
+ codec->dapm.bias_level != SND_SOC_BIAS_OFF,
+ "codec %s can not start from non-off bias"
+ " with idle_bias_off==1\n", codec->name);
}
/* If the driver didn't set I/O up try regmap */
--
1.7.0.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] ASoC: core: giving WARN when device starting from non-off bias with idle_bias_off
2012-12-21 10:17 ` [PATCH] ASoC: core: giving WARN when device starting from non-off bias with idle_bias_off Chuansheng Liu
@ 2012-12-24 15:35 ` Mark Brown
0 siblings, 0 replies; 7+ messages in thread
From: Mark Brown @ 2012-12-24 15:35 UTC (permalink / raw)
To: Chuansheng Liu; +Cc: lrg, perex, tiwai, alsa-devel, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 364 bytes --]
On Fri, Dec 21, 2012 at 06:17:12PM +0800, Chuansheng Liu wrote:
>
> Just found some cases that some codec drivers set the bias to _STANDBY and
> set idle_bias_off to 1 during probing.
> It will cause unpaired runtime_get_sync/put() issue. Also as Mark suggested,
> there is no reason to start from _STANDBY bias with idle_bias_off == 1.
Applied, thanks.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-12-24 15:35 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-19 10:36 [PATCH] ASoC: dapm: Fix the unpaired runtime_get/put cases Chuansheng Liu
2012-12-19 9:11 ` Mark Brown
2012-12-20 6:37 ` Liu, Chuansheng
2012-12-20 13:51 ` Mark Brown
2012-12-21 1:34 ` Liu, Chuansheng
2012-12-21 10:17 ` [PATCH] ASoC: core: giving WARN when device starting from non-off bias with idle_bias_off Chuansheng Liu
2012-12-24 15:35 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).