summaryrefslogtreecommitdiff
path: root/sound/soc/codecs/es8316.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/codecs/es8316.c')
-rw-r--r--sound/soc/codecs/es8316.c44
1 files changed, 26 insertions, 18 deletions
diff --git a/sound/soc/codecs/es8316.c b/sound/soc/codecs/es8316.c
index 3abe77423f29..24ec8b211cdb 100644
--- a/sound/soc/codecs/es8316.c
+++ b/sound/soc/codecs/es8316.c
@@ -9,11 +9,13 @@
#include <linux/module.h>
#include <linux/acpi.h>
+#include <linux/cleanup.h>
#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/i2c.h>
#include <linux/mutex.h>
#include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
@@ -30,6 +32,13 @@ static const unsigned int supported_mclk_lrck_ratios[] = {
256, 384, 400, 500, 512, 768, 1024
};
+static const char * const es8316_supply_names[] = {
+ "avdd",
+ "cpvdd",
+ "dvdd",
+ "pvdd",
+};
+
struct es8316_priv {
struct mutex lock;
struct clk *mclk;
@@ -620,15 +629,15 @@ static irqreturn_t es8316_irq(int irq, void *data)
struct snd_soc_component *comp = es8316->component;
unsigned int flags;
- mutex_lock(&es8316->lock);
+ guard(mutex)(&es8316->lock);
regmap_read(es8316->regmap, ES8316_GPIO_FLAG, &flags);
if (flags == 0x00)
- goto out; /* Powered-down / reset */
+ return IRQ_HANDLED; /* Powered-down / reset */
/* Catch spurious IRQ before set_jack is called */
if (!es8316->jack)
- goto out;
+ return IRQ_HANDLED;
if (es8316->jd_inverted)
flags ^= ES8316_GPIO_FLAG_HP_NOT_INSERTED;
@@ -681,8 +690,6 @@ static irqreturn_t es8316_irq(int irq, void *data)
}
}
-out:
- mutex_unlock(&es8316->lock);
return IRQ_HANDLED;
}
@@ -699,18 +706,16 @@ static void es8316_enable_jack_detect(struct snd_soc_component *component,
es8316->jd_inverted = device_property_read_bool(component->dev,
"everest,jack-detect-inverted");
- mutex_lock(&es8316->lock);
-
- es8316->jack = jack;
+ scoped_guard(mutex, &es8316->lock) {
+ es8316->jack = jack;
- if (es8316->jack->status & SND_JACK_MICROPHONE)
- es8316_enable_micbias_for_mic_gnd_short_detect(component);
-
- snd_soc_component_update_bits(component, ES8316_GPIO_DEBOUNCE,
- ES8316_GPIO_ENABLE_INTERRUPT,
- ES8316_GPIO_ENABLE_INTERRUPT);
+ if (es8316->jack->status & SND_JACK_MICROPHONE)
+ es8316_enable_micbias_for_mic_gnd_short_detect(component);
- mutex_unlock(&es8316->lock);
+ snd_soc_component_update_bits(component, ES8316_GPIO_DEBOUNCE,
+ ES8316_GPIO_ENABLE_INTERRUPT,
+ ES8316_GPIO_ENABLE_INTERRUPT);
+ }
/* Enable irq and sync initial jack state */
enable_irq(es8316->irq);
@@ -726,7 +731,7 @@ static void es8316_disable_jack_detect(struct snd_soc_component *component)
disable_irq(es8316->irq);
- mutex_lock(&es8316->lock);
+ guard(mutex)(&es8316->lock);
snd_soc_component_update_bits(component, ES8316_GPIO_DEBOUNCE,
ES8316_GPIO_ENABLE_INTERRUPT, 0);
@@ -737,8 +742,6 @@ static void es8316_disable_jack_detect(struct snd_soc_component *component)
}
es8316->jack = NULL;
-
- mutex_unlock(&es8316->lock);
}
static int es8316_set_jack(struct snd_soc_component *component,
@@ -871,6 +874,11 @@ static int es8316_i2c_probe(struct i2c_client *i2c_client)
i2c_set_clientdata(i2c_client, es8316);
+ ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(es8316_supply_names),
+ es8316_supply_names);
+ if (ret)
+ return dev_err_probe(dev, ret, "unable to enable supplies\n");
+
es8316->regmap = devm_regmap_init_i2c(i2c_client, &es8316_regmap);
if (IS_ERR(es8316->regmap))
return PTR_ERR(es8316->regmap);