diff mbox

[02/10] ASoC: sta32x: make sta32x a gpio consumer for the reset GPIO

Message ID 1421881322-27806-3-git-send-email-niederp@physik.uni-kl.de (mailing list archive)
State Accepted
Commit b66a29808e1fac7fc5c8174e3ec0f014bd418280
Headers show

Commit Message

Thomas Niederprüm Jan. 21, 2015, 11:01 p.m. UTC
The reset GPIO on the STA32X Codecs is used to reset the Codec and clear
all registers. Also taking it down puts the IC in power save mode, so
we put the device in reset mode when we go to sleep.

Signed-off-by: Thomas Niederprüm <niederp@physik.uni-kl.de>
---
 sound/soc/codecs/sta32x.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

Comments

Mark Brown Jan. 27, 2015, 5 p.m. UTC | #1
On Thu, Jan 22, 2015 at 12:01:54AM +0100, Thomas Niederprüm wrote:

> +	/* GPIOs */
> +	sta32x->gpiod_nreset = devm_gpiod_get(dev, "reset");
> +	if (IS_ERR(sta32x->gpiod_nreset)) {
> +		ret = PTR_ERR(sta32x->gpiod_nreset);
> +		if (ret != -ENOENT && ret != -ENOSYS)
> +			return ret;
> +
> +		sta32x->gpiod_nreset = NULL;

I'll apply this but in general this pattern of replacing error pointers
with NULL is a bit suspect - if the way you test for failure is IS_ERR()
then just carry on using IS_ERR() all through the code to check if you
got something valid, it's less likely for GPIOs but most other things
can substitute in dummies and NULL can be a good way of specifying a
dummy.
diff mbox

Patch

diff --git a/sound/soc/codecs/sta32x.c b/sound/soc/codecs/sta32x.c
index 03175fe..78f2009 100644
--- a/sound/soc/codecs/sta32x.c
+++ b/sound/soc/codecs/sta32x.c
@@ -26,6 +26,7 @@ 
 #include <linux/i2c.h>
 #include <linux/regmap.h>
 #include <linux/regulator/consumer.h>
+#include <linux/gpio/consumer.h>
 #include <linux/slab.h>
 #include <linux/workqueue.h>
 #include <sound/core.h>
@@ -151,6 +152,7 @@  struct sta32x_priv {
 	u32 coef_shadow[STA32X_COEF_COUNT];
 	struct delayed_work watchdog_work;
 	int shutdown;
+	struct gpio_desc *gpiod_nreset;
 	struct mutex coeff_lock;
 };
 
@@ -804,6 +806,16 @@  static int sta32x_hw_params(struct snd_pcm_substream *substream,
 
 	return 0;
 }
+
+static int sta32x_startup_sequence(struct sta32x_priv *sta32x)
+{
+	if (sta32x->gpiod_nreset) {
+		gpiod_set_value(sta32x->gpiod_nreset, 0);
+		mdelay(1);
+		gpiod_set_value(sta32x->gpiod_nreset, 1);
+		mdelay(1);
+	}
+
 	return 0;
 }
 
@@ -844,6 +856,7 @@  static int sta32x_set_bias_level(struct snd_soc_codec *codec,
 				return ret;
 			}
 
+			sta32x_startup_sequence(sta32x);
 			sta32x_cache_sync(codec);
 			sta32x_watchdog_start(sta32x);
 		}
@@ -861,6 +874,10 @@  static int sta32x_set_bias_level(struct snd_soc_codec *codec,
 				   STA32X_CONFF_PWDN | STA32X_CONFF_EAPD, 0);
 		msleep(300);
 		sta32x_watchdog_stop(sta32x);
+
+		if (sta32x->gpiod_nreset)
+			gpiod_set_value(sta32x->gpiod_nreset, 0);
+
 		regulator_bulk_disable(ARRAY_SIZE(sta32x->supplies),
 				       sta32x->supplies);
 		break;
@@ -916,6 +933,11 @@  static int sta32x_probe(struct snd_soc_codec *codec)
 		return ret;
 	}
 
+	ret = sta32x_startup_sequence(sta32x);
+	if (ret < 0) {
+		dev_err(codec->dev, "Failed to startup device\n");
+		return ret;
+	}
 	/* set thermal warning adjustment and recovery */
 	if (!pdata->thermal_warning_recovery)
 		thermal |= STA32X_CONFA_TWAB;
@@ -1018,6 +1040,19 @@  static int sta32x_i2c_probe(struct i2c_client *i2c,
 
 	mutex_init(&sta32x->coeff_lock);
 	sta32x->pdata = dev_get_platdata(dev);
+
+	/* GPIOs */
+	sta32x->gpiod_nreset = devm_gpiod_get(dev, "reset");
+	if (IS_ERR(sta32x->gpiod_nreset)) {
+		ret = PTR_ERR(sta32x->gpiod_nreset);
+		if (ret != -ENOENT && ret != -ENOSYS)
+			return ret;
+
+		sta32x->gpiod_nreset = NULL;
+	} else {
+		gpiod_direction_output(sta32x->gpiod_nreset, 0);
+	}
+
 	/* regulators */
 	for (i = 0; i < ARRAY_SIZE(sta32x->supplies); i++)
 		sta32x->supplies[i].supply = sta32x_supply_names[i];