ASoC: sta32x: make sta32x a gpio consumer for the reset GPIO

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>
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Thomas Niederprüm 2015-01-22 00:01:54 +01:00 committed by Mark Brown
parent a1be4cead9
commit b66a29808e
1 changed files with 35 additions and 0 deletions

View File

@ -26,6 +26,7 @@
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/regmap.h> #include <linux/regmap.h>
#include <linux/regulator/consumer.h> #include <linux/regulator/consumer.h>
#include <linux/gpio/consumer.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/workqueue.h> #include <linux/workqueue.h>
#include <sound/core.h> #include <sound/core.h>
@ -151,6 +152,7 @@ struct sta32x_priv {
u32 coef_shadow[STA32X_COEF_COUNT]; u32 coef_shadow[STA32X_COEF_COUNT];
struct delayed_work watchdog_work; struct delayed_work watchdog_work;
int shutdown; int shutdown;
struct gpio_desc *gpiod_nreset;
struct mutex coeff_lock; struct mutex coeff_lock;
}; };
@ -804,6 +806,16 @@ static int sta32x_hw_params(struct snd_pcm_substream *substream,
return 0; 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; return 0;
} }
@ -844,6 +856,7 @@ static int sta32x_set_bias_level(struct snd_soc_codec *codec,
return ret; return ret;
} }
sta32x_startup_sequence(sta32x);
sta32x_cache_sync(codec); sta32x_cache_sync(codec);
sta32x_watchdog_start(sta32x); 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); STA32X_CONFF_PWDN | STA32X_CONFF_EAPD, 0);
msleep(300); msleep(300);
sta32x_watchdog_stop(sta32x); sta32x_watchdog_stop(sta32x);
if (sta32x->gpiod_nreset)
gpiod_set_value(sta32x->gpiod_nreset, 0);
regulator_bulk_disable(ARRAY_SIZE(sta32x->supplies), regulator_bulk_disable(ARRAY_SIZE(sta32x->supplies),
sta32x->supplies); sta32x->supplies);
break; break;
@ -899,6 +916,11 @@ static int sta32x_probe(struct snd_soc_codec *codec)
return ret; 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 */ /* set thermal warning adjustment and recovery */
if (!pdata->thermal_warning_recovery) if (!pdata->thermal_warning_recovery)
thermal |= STA32X_CONFA_TWAB; thermal |= STA32X_CONFA_TWAB;
@ -999,6 +1021,19 @@ static int sta32x_i2c_probe(struct i2c_client *i2c,
mutex_init(&sta32x->coeff_lock); mutex_init(&sta32x->coeff_lock);
sta32x->pdata = dev_get_platdata(dev); 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 */ /* regulators */
for (i = 0; i < ARRAY_SIZE(sta32x->supplies); i++) for (i = 0; i < ARRAY_SIZE(sta32x->supplies); i++)
sta32x->supplies[i].supply = sta32x_supply_names[i]; sta32x->supplies[i].supply = sta32x_supply_names[i];