diff mbox

[v2,15/19] ASoC: tlv320aic31xx: Reset registers during power up

Message ID 20171129213300.20021-16-afd@ti.com (mailing list archive)
State New, archived
Headers show

Commit Message

Andrew Davis Nov. 29, 2017, 9:32 p.m. UTC
Add a reset function that toggles the reset line if available or uses
the software reset command otherwise. Use this in power up to ensure the
registers are in a sane state. This is useful when the driver module
is reloaded, or after Kexec, warm-reboots, etc..

Signed-off-by: Andrew F. Davis <afd@ti.com>
---
 sound/soc/codecs/tlv320aic31xx.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

Comments

Mark Brown Dec. 1, 2017, 1:37 p.m. UTC | #1
On Wed, Nov 29, 2017 at 03:32:56PM -0600, Andrew F. Davis wrote:

> +		gpiod_set_value(aic31xx->gpio_reset, 1);
> +		ndelay(10); /* At least 10ns */
> +		gpiod_set_value(aic31xx->gpio_reset, 0);

_cansleep(), this isn't being done from interrupt context.

> +	} else {
> +		ret = regmap_write(aic31xx->regmap, AIC31XX_RESET, 1);
> +		if (ret < 0)
> +			dev_err(aic31xx->dev, "Could not reset device\n");

Print the error to help people doing debug.
Andrew Davis Dec. 1, 2017, 3:04 p.m. UTC | #2
On 12/01/2017 07:37 AM, Mark Brown wrote:
> On Wed, Nov 29, 2017 at 03:32:56PM -0600, Andrew F. Davis wrote:
> 
>> +		gpiod_set_value(aic31xx->gpio_reset, 1);
>> +		ndelay(10); /* At least 10ns */
>> +		gpiod_set_value(aic31xx->gpio_reset, 0);
> 
> _cansleep(), this isn't being done from interrupt context.
> 

will fix

>> +	} else {
>> +		ret = regmap_write(aic31xx->regmap, AIC31XX_RESET, 1);
>> +		if (ret < 0)
>> +			dev_err(aic31xx->dev, "Could not reset device\n");
> 
> Print the error to help people doing debug.
> 

Do you mean by adding the ret code to the print?
Mark Brown Dec. 1, 2017, 3:55 p.m. UTC | #3
On Fri, Dec 01, 2017 at 09:04:41AM -0600, Andrew F. Davis wrote:
> On 12/01/2017 07:37 AM, Mark Brown wrote:
> > On Wed, Nov 29, 2017 at 03:32:56PM -0600, Andrew F. Davis wrote:

> >> +	} else {
> >> +		ret = regmap_write(aic31xx->regmap, AIC31XX_RESET, 1);
> >> +		if (ret < 0)
> >> +			dev_err(aic31xx->dev, "Could not reset device\n");

> > Print the error to help people doing debug.

> Do you mean by adding the ret code to the print?

Yes.
diff mbox

Patch

diff --git a/sound/soc/codecs/tlv320aic31xx.c b/sound/soc/codecs/tlv320aic31xx.c
index b51c2777e8d1..77ae8f36a943 100644
--- a/sound/soc/codecs/tlv320aic31xx.c
+++ b/sound/soc/codecs/tlv320aic31xx.c
@@ -1031,6 +1031,24 @@  static int aic31xx_set_dai_sysclk(struct snd_soc_dai *codec_dai,
 	return 0;
 }
 
+static int aic31xx_reset(struct aic31xx_priv *aic31xx)
+{
+	int ret = 0;
+
+	if (aic31xx->gpio_reset) {
+		gpiod_set_value(aic31xx->gpio_reset, 1);
+		ndelay(10); /* At least 10ns */
+		gpiod_set_value(aic31xx->gpio_reset, 0);
+	} else {
+		ret = regmap_write(aic31xx->regmap, AIC31XX_RESET, 1);
+		if (ret < 0)
+			dev_err(aic31xx->dev, "Could not reset device\n");
+	}
+	mdelay(1); /* At least 1ms */
+
+	return ret;
+}
+
 static void aic31xx_clk_on(struct snd_soc_codec *codec)
 {
 	struct aic31xx_priv *aic31xx = snd_soc_codec_get_drvdata(codec);
@@ -1074,11 +1092,11 @@  static int aic31xx_power_on(struct snd_soc_codec *codec)
 	if (ret)
 		return ret;
 
-	if (aic31xx->gpio_reset) {
-		gpiod_set_value(aic31xx->gpio_reset, 0);
-		udelay(100);
-	}
 	regcache_cache_only(aic31xx->regmap, false);
+
+	/* Reset device registers for a consistent power-on like state */
+	aic31xx_reset(aic31xx);
+
 	ret = regcache_sync(aic31xx->regmap);
 	if (ret) {
 		dev_err(codec->dev,