linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ASoC: tpa6130a2: fix volume setting when no stream is running
@ 2016-09-22 10:10 Nikita Yushchenko
  2016-09-24 18:31 ` Mark Brown
  0 siblings, 1 reply; 6+ messages in thread
From: Nikita Yushchenko @ 2016-09-22 10:10 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Helen Koike, Lars-Peter Clausen, Sebastian Reichel, alsa-devel,
	linux-kernel
  Cc: Chris Healy, Nikita Yushchenko

After moving tpa6130a2 power management to DAPM, if chip can be physically
powered off (either reset_gpio is defined, or regulator indeed removes
power), then volume change no longer works unless chip is on due to
a running stream.

Fix that by entering regcache cache_only mode while chip is off.

Move regcache calls to tpa6130a2_power() to get them at driver init time
as well.

Signed-off-by: Nikita Yushchenko <nikita.yoush@cogentembedded.com>
---
 sound/soc/codecs/tpa6130a2.c | 49 +++++++++++++++++++++++---------------------
 1 file changed, 26 insertions(+), 23 deletions(-)

diff --git a/sound/soc/codecs/tpa6130a2.c b/sound/soc/codecs/tpa6130a2.c
index f1ea052..3b6faed 100644
--- a/sound/soc/codecs/tpa6130a2.c
+++ b/sound/soc/codecs/tpa6130a2.c
@@ -52,7 +52,7 @@ struct tpa6130a2_data {
 
 static int tpa6130a2_power(struct tpa6130a2_data *data, bool enable)
 {
-	int ret;
+	int ret = 0, ret2;
 
 	if (enable) {
 		ret = regulator_enable(data->supply);
@@ -64,20 +64,34 @@ static int tpa6130a2_power(struct tpa6130a2_data *data, bool enable)
 		/* Power on */
 		if (data->power_gpio >= 0)
 			gpio_set_value(data->power_gpio, 1);
+
+		/* Sync registers */
+		regcache_cache_only(data->regmap, false);
+		ret = regcache_sync(data->regmap);
+		if (ret != 0) {
+			dev_err(data->dev,
+				"Failed to sync registers: %d\n", ret);
+			goto regcache_sync_failed;
+		}
 	} else {
+		/* Powered off device does not retain registers. While device
+		 * is off, any register updates (i.e. volume changes) should
+		 * happen in cache only.
+		 */
+		regcache_mark_dirty(data->regmap);
+regcache_sync_failed:
+		regcache_cache_only(data->regmap, true);
+
 		/* Power off */
 		if (data->power_gpio >= 0)
 			gpio_set_value(data->power_gpio, 0);
 
-		ret = regulator_disable(data->supply);
-		if (ret != 0) {
+		ret2 = regulator_disable(data->supply);
+		if (ret2 != 0) {
 			dev_err(data->dev,
-				"Failed to disable supply: %d\n", ret);
-			return ret;
+				"Failed to disable supply: %d\n", ret2);
+			return ret ? ret : ret2;
 		}
-
-		/* device regs does not match the cache state anymore */
-		regcache_mark_dirty(data->regmap);
 	}
 
 	return ret;
@@ -88,25 +102,14 @@ static int tpa6130a2_power_event(struct snd_soc_dapm_widget *w,
 {
 	struct snd_soc_component *c = snd_soc_dapm_to_component(w->dapm);
 	struct tpa6130a2_data *data = snd_soc_component_get_drvdata(c);
-	int ret;
 
-	/* before widget power up */
 	if (SND_SOC_DAPM_EVENT_ON(event)) {
-		/* Turn on the chip */
-		tpa6130a2_power(data, true);
-		/* Sync the registers */
-		ret = regcache_sync(data->regmap);
-		if (ret < 0) {
-			dev_err(c->dev, "Failed to initialize chip\n");
-			tpa6130a2_power(data, false);
-			return ret;
-		}
-	/* after widget power down */
+		/* Before widget power up: turn chip on, sync registers */
+		return tpa6130a2_power(data, true);
 	} else {
-		tpa6130a2_power(data, false);
+		/* After widget power down: turn chip off */
+		return tpa6130a2_power(data, false);
 	}
-
-	return 0;
 }
 
 /*
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] ASoC: tpa6130a2: fix volume setting when no stream is running
  2016-09-22 10:10 [PATCH] ASoC: tpa6130a2: fix volume setting when no stream is running Nikita Yushchenko
@ 2016-09-24 18:31 ` Mark Brown
  2016-09-26 10:35   ` [PATCH] ASoC: tpa6130a2: unmerge power enable error path from power disable path Nikita Yushchenko
  0 siblings, 1 reply; 6+ messages in thread
From: Mark Brown @ 2016-09-24 18:31 UTC (permalink / raw)
  To: Nikita Yushchenko
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Helen Koike,
	Lars-Peter Clausen, Sebastian Reichel, alsa-devel, linux-kernel,
	Chris Healy

[-- Attachment #1: Type: text/plain, Size: 564 bytes --]

On Thu, Sep 22, 2016 at 01:10:40PM +0300, Nikita Yushchenko wrote:

> -		ret = regulator_disable(data->supply);
> -		if (ret != 0) {
> +		ret2 = regulator_disable(data->supply);
> +		if (ret2 != 0) {
>  			dev_err(data->dev,
> -				"Failed to disable supply: %d\n", ret);
> -			return ret;
> +				"Failed to disable supply: %d\n", ret2);
> +			return ret ? ret : ret2;
>  		}

The ternery operator to save the error handling block is a bit too cute
to be clear, it'd be better to just handle each error directly.  Can you
please send a followup patch fixing this?

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] ASoC: tpa6130a2: unmerge power enable error path from power disable path
  2016-09-24 18:31 ` Mark Brown
@ 2016-09-26 10:35   ` Nikita Yushchenko
  2016-09-26 16:08     ` Mark Brown
  2016-09-26 16:15     ` Applied "ASoC: tpa6130a2: unmerge power enable error path from power disable path" to the asoc tree Mark Brown
  0 siblings, 2 replies; 6+ messages in thread
From: Nikita Yushchenko @ 2016-09-26 10:35 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Helen Koike, Lars-Peter Clausen, Sebastian Reichel, alsa-devel,
	linux-kernel
  Cc: Chris Healy, Nikita Yushchenko

Code undo operations in power enable errror path explicitly, instead of
reusing power disable path and playing with return values there.

Signed-off-by: Nikita Yushchenko <nikita.yoush@cogentembedded.com>
---
I doubt that copying 7 lines into error path is better than having a tiny
logic with return values, but still here it is.

 sound/soc/codecs/tpa6130a2.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/sound/soc/codecs/tpa6130a2.c b/sound/soc/codecs/tpa6130a2.c
index 3b6faed91d7e..3712db0881d0 100644
--- a/sound/soc/codecs/tpa6130a2.c
+++ b/sound/soc/codecs/tpa6130a2.c
@@ -71,7 +71,14 @@ static int tpa6130a2_power(struct tpa6130a2_data *data, bool enable)
 		if (ret != 0) {
 			dev_err(data->dev,
 				"Failed to sync registers: %d\n", ret);
-			goto regcache_sync_failed;
+			regcache_cache_only(data->regmap, true);
+			if (data->power_gpio >= 0)
+				gpio_set_value(data->power_gpio, 0);
+			ret2 = regulator_disable(data->supply);
+			if (ret2 != 0)
+				dev_err(data->dev,
+					"Failed to disable supply: %d\n", ret2);
+			return ret;
 		}
 	} else {
 		/* Powered off device does not retain registers. While device
@@ -79,18 +86,17 @@ static int tpa6130a2_power(struct tpa6130a2_data *data, bool enable)
 		 * happen in cache only.
 		 */
 		regcache_mark_dirty(data->regmap);
-regcache_sync_failed:
 		regcache_cache_only(data->regmap, true);
 
 		/* Power off */
 		if (data->power_gpio >= 0)
 			gpio_set_value(data->power_gpio, 0);
 
-		ret2 = regulator_disable(data->supply);
-		if (ret2 != 0) {
+		ret = regulator_disable(data->supply);
+		if (ret != 0) {
 			dev_err(data->dev,
-				"Failed to disable supply: %d\n", ret2);
-			return ret ? ret : ret2;
+				"Failed to disable supply: %d\n", ret);
+			return ret;
 		}
 	}
 
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] ASoC: tpa6130a2: unmerge power enable error path from power disable path
  2016-09-26 10:35   ` [PATCH] ASoC: tpa6130a2: unmerge power enable error path from power disable path Nikita Yushchenko
@ 2016-09-26 16:08     ` Mark Brown
  2016-09-26 16:14       ` Nikita Yushchenko
  2016-09-26 16:15     ` Applied "ASoC: tpa6130a2: unmerge power enable error path from power disable path" to the asoc tree Mark Brown
  1 sibling, 1 reply; 6+ messages in thread
From: Mark Brown @ 2016-09-26 16:08 UTC (permalink / raw)
  To: Nikita Yushchenko
  Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Helen Koike,
	Lars-Peter Clausen, Sebastian Reichel, alsa-devel, linux-kernel,
	Chris Healy

[-- Attachment #1: Type: text/plain, Size: 263 bytes --]

On Mon, Sep 26, 2016 at 01:35:50PM +0300, Nikita Yushchenko wrote:

> I doubt that copying 7 lines into error path is better than having a tiny
> logic with return values, but still here it is.

Consider what happens if someone wants to change the code... 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] ASoC: tpa6130a2: unmerge power enable error path from power disable path
  2016-09-26 16:08     ` Mark Brown
@ 2016-09-26 16:14       ` Nikita Yushchenko
  0 siblings, 0 replies; 6+ messages in thread
From: Nikita Yushchenko @ 2016-09-26 16:14 UTC (permalink / raw)
  To: linux-kernel

>> I doubt that copying 7 lines into error path is better than having a tiny
>> logic with return values, but still here it is.
> 
> Consider what happens if someone wants to change the code... 

I believe that "undo poweron" and "poweroff" sequences still will have
to remain the same. This having two copies of code is more error-prone
than having one.

Nikita

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Applied "ASoC: tpa6130a2: unmerge power enable error path from power disable path" to the asoc tree
  2016-09-26 10:35   ` [PATCH] ASoC: tpa6130a2: unmerge power enable error path from power disable path Nikita Yushchenko
  2016-09-26 16:08     ` Mark Brown
@ 2016-09-26 16:15     ` Mark Brown
  1 sibling, 0 replies; 6+ messages in thread
From: Mark Brown @ 2016-09-26 16:15 UTC (permalink / raw)
  To: Nikita Yushchenko
  Cc: Mark Brown, Liam Girdwood, Mark Brown, Jaroslav Kysela,
	Takashi Iwai, Helen Koike, Lars-Peter Clausen, Sebastian Reichel,
	alsa-devel, linux-kernel, Chris Healy, alsa-devel

The patch

   ASoC: tpa6130a2: unmerge power enable error path from power disable path

has been applied to the asoc tree at

   git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git 

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

>From 020eab35390b976e6b93b61805002d3e2cd195de Mon Sep 17 00:00:00 2001
From: Nikita Yushchenko <nikita.yoush@cogentembedded.com>
Date: Mon, 26 Sep 2016 13:35:50 +0300
Subject: [PATCH] ASoC: tpa6130a2: unmerge power enable error path from power
 disable path

Code undo operations in power enable errror path explicitly, instead of
reusing power disable path and playing with return values there.

Signed-off-by: Nikita Yushchenko <nikita.yoush@cogentembedded.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 sound/soc/codecs/tpa6130a2.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/sound/soc/codecs/tpa6130a2.c b/sound/soc/codecs/tpa6130a2.c
index 3b6faed91d7e..3712db0881d0 100644
--- a/sound/soc/codecs/tpa6130a2.c
+++ b/sound/soc/codecs/tpa6130a2.c
@@ -71,7 +71,14 @@ static int tpa6130a2_power(struct tpa6130a2_data *data, bool enable)
 		if (ret != 0) {
 			dev_err(data->dev,
 				"Failed to sync registers: %d\n", ret);
-			goto regcache_sync_failed;
+			regcache_cache_only(data->regmap, true);
+			if (data->power_gpio >= 0)
+				gpio_set_value(data->power_gpio, 0);
+			ret2 = regulator_disable(data->supply);
+			if (ret2 != 0)
+				dev_err(data->dev,
+					"Failed to disable supply: %d\n", ret2);
+			return ret;
 		}
 	} else {
 		/* Powered off device does not retain registers. While device
@@ -79,18 +86,17 @@ static int tpa6130a2_power(struct tpa6130a2_data *data, bool enable)
 		 * happen in cache only.
 		 */
 		regcache_mark_dirty(data->regmap);
-regcache_sync_failed:
 		regcache_cache_only(data->regmap, true);
 
 		/* Power off */
 		if (data->power_gpio >= 0)
 			gpio_set_value(data->power_gpio, 0);
 
-		ret2 = regulator_disable(data->supply);
-		if (ret2 != 0) {
+		ret = regulator_disable(data->supply);
+		if (ret != 0) {
 			dev_err(data->dev,
-				"Failed to disable supply: %d\n", ret2);
-			return ret ? ret : ret2;
+				"Failed to disable supply: %d\n", ret);
+			return ret;
 		}
 	}
 
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-09-26 16:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-22 10:10 [PATCH] ASoC: tpa6130a2: fix volume setting when no stream is running Nikita Yushchenko
2016-09-24 18:31 ` Mark Brown
2016-09-26 10:35   ` [PATCH] ASoC: tpa6130a2: unmerge power enable error path from power disable path Nikita Yushchenko
2016-09-26 16:08     ` Mark Brown
2016-09-26 16:14       ` Nikita Yushchenko
2016-09-26 16:15     ` Applied "ASoC: tpa6130a2: unmerge power enable error path from power disable path" to the asoc tree 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).