9
9
#include <linux/gpio.h>
10
10
#include <linux/gpio/consumer.h>
11
11
#include <linux/platform_device.h>
12
+ #include <linux/regulator/consumer.h>
12
13
#include <linux/slab.h>
13
14
#include <linux/module.h>
14
15
#include <sound/core.h>
@@ -25,6 +26,7 @@ module_param(wakeup_delay, uint, 0644);
25
26
26
27
struct dmic {
27
28
struct gpio_desc * gpio_en ;
29
+ struct regulator * vref ;
28
30
int wakeup_delay ;
29
31
/* Delay after DMIC mode switch */
30
32
int modeswitch_delay ;
@@ -55,22 +57,33 @@ static int dmic_aif_event(struct snd_soc_dapm_widget *w,
55
57
struct snd_kcontrol * kcontrol , int event ) {
56
58
struct snd_soc_component * component = snd_soc_dapm_to_component (w -> dapm );
57
59
struct dmic * dmic = snd_soc_component_get_drvdata (component );
60
+ int ret = 0 ;
58
61
59
62
switch (event ) {
60
63
case SND_SOC_DAPM_POST_PMU :
61
64
if (dmic -> gpio_en )
62
65
gpiod_set_value_cansleep (dmic -> gpio_en , 1 );
63
66
67
+ if (dmic -> vref ) {
68
+ ret = regulator_enable (dmic -> vref );
69
+ if (ret )
70
+ return ret ;
71
+ }
72
+
64
73
if (dmic -> wakeup_delay )
65
74
msleep (dmic -> wakeup_delay );
66
75
break ;
67
76
case SND_SOC_DAPM_POST_PMD :
68
77
if (dmic -> gpio_en )
69
78
gpiod_set_value_cansleep (dmic -> gpio_en , 0 );
79
+
80
+ if (dmic -> vref )
81
+ ret = regulator_disable (dmic -> vref );
82
+
70
83
break ;
71
84
}
72
85
73
- return 0 ;
86
+ return ret ;
74
87
}
75
88
76
89
static struct snd_soc_dai_driver dmic_dai = {
@@ -100,6 +113,10 @@ static int dmic_component_probe(struct snd_soc_component *component)
100
113
if (!dmic )
101
114
return - ENOMEM ;
102
115
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
+
103
120
dmic -> gpio_en = devm_gpiod_get_optional (component -> dev ,
104
121
"dmicen" , GPIOD_OUT_LOW );
105
122
if (IS_ERR (dmic -> gpio_en ))
0 commit comments