Skip to content

Commit d3321a2

Browse files
Olivier Moysanbroonie
authored andcommitted
ASoC: dmic: add regulator support
Allow management of the regulator that may be used to supply the digital microphone. Signed-off-by: Olivier Moysan <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent a8fed0b commit d3321a2

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

sound/soc/codecs/dmic.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/gpio.h>
1010
#include <linux/gpio/consumer.h>
1111
#include <linux/platform_device.h>
12+
#include <linux/regulator/consumer.h>
1213
#include <linux/slab.h>
1314
#include <linux/module.h>
1415
#include <sound/core.h>
@@ -25,6 +26,7 @@ module_param(wakeup_delay, uint, 0644);
2526

2627
struct dmic {
2728
struct gpio_desc *gpio_en;
29+
struct regulator *vref;
2830
int wakeup_delay;
2931
/* Delay after DMIC mode switch */
3032
int modeswitch_delay;
@@ -55,22 +57,33 @@ static int dmic_aif_event(struct snd_soc_dapm_widget *w,
5557
struct snd_kcontrol *kcontrol, int event) {
5658
struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
5759
struct dmic *dmic = snd_soc_component_get_drvdata(component);
60+
int ret = 0;
5861

5962
switch (event) {
6063
case SND_SOC_DAPM_POST_PMU:
6164
if (dmic->gpio_en)
6265
gpiod_set_value_cansleep(dmic->gpio_en, 1);
6366

67+
if (dmic->vref) {
68+
ret = regulator_enable(dmic->vref);
69+
if (ret)
70+
return ret;
71+
}
72+
6473
if (dmic->wakeup_delay)
6574
msleep(dmic->wakeup_delay);
6675
break;
6776
case SND_SOC_DAPM_POST_PMD:
6877
if (dmic->gpio_en)
6978
gpiod_set_value_cansleep(dmic->gpio_en, 0);
79+
80+
if (dmic->vref)
81+
ret = regulator_disable(dmic->vref);
82+
7083
break;
7184
}
7285

73-
return 0;
86+
return ret;
7487
}
7588

7689
static struct snd_soc_dai_driver dmic_dai = {
@@ -100,6 +113,10 @@ static int dmic_component_probe(struct snd_soc_component *component)
100113
if (!dmic)
101114
return -ENOMEM;
102115

116+
dmic->vref = devm_regulator_get_optional(component->dev, "vref");
117+
if (IS_ERR(dmic->vref) && PTR_ERR(dmic->vref) != -ENODEV)
118+
return dev_err_probe(component->dev, PTR_ERR(dmic->vref), "Failed to get vref\n");
119+
103120
dmic->gpio_en = devm_gpiod_get_optional(component->dev,
104121
"dmicen", GPIOD_OUT_LOW);
105122
if (IS_ERR(dmic->gpio_en))

0 commit comments

Comments
 (0)