diff options
-rw-r--r-- | sound/soc/codecs/ak5386.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/sound/soc/codecs/ak5386.c b/sound/soc/codecs/ak5386.c index 72e953b2cb41..a30be5ce3fa4 100644 --- a/sound/soc/codecs/ak5386.c +++ b/sound/soc/codecs/ak5386.c | |||
@@ -14,12 +14,18 @@ | |||
14 | #include <linux/of.h> | 14 | #include <linux/of.h> |
15 | #include <linux/of_gpio.h> | 15 | #include <linux/of_gpio.h> |
16 | #include <linux/of_device.h> | 16 | #include <linux/of_device.h> |
17 | #include <linux/regulator/consumer.h> | ||
17 | #include <sound/soc.h> | 18 | #include <sound/soc.h> |
18 | #include <sound/pcm.h> | 19 | #include <sound/pcm.h> |
19 | #include <sound/initval.h> | 20 | #include <sound/initval.h> |
20 | 21 | ||
22 | static const char const *supply_names[] = { | ||
23 | "va", "vd" | ||
24 | }; | ||
25 | |||
21 | struct ak5386_priv { | 26 | struct ak5386_priv { |
22 | int reset_gpio; | 27 | int reset_gpio; |
28 | struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)]; | ||
23 | }; | 29 | }; |
24 | 30 | ||
25 | static const struct snd_soc_dapm_widget ak5386_dapm_widgets[] = { | 31 | static const struct snd_soc_dapm_widget ak5386_dapm_widgets[] = { |
@@ -32,7 +38,42 @@ static const struct snd_soc_dapm_route ak5386_dapm_routes[] = { | |||
32 | { "Capture", NULL, "AINR" }, | 38 | { "Capture", NULL, "AINR" }, |
33 | }; | 39 | }; |
34 | 40 | ||
41 | static int ak5386_soc_probe(struct snd_soc_codec *codec) | ||
42 | { | ||
43 | struct ak5386_priv *priv = snd_soc_codec_get_drvdata(codec); | ||
44 | return regulator_bulk_enable(ARRAY_SIZE(priv->supplies), priv->supplies); | ||
45 | } | ||
46 | |||
47 | static int ak5386_soc_remove(struct snd_soc_codec *codec) | ||
48 | { | ||
49 | struct ak5386_priv *priv = snd_soc_codec_get_drvdata(codec); | ||
50 | regulator_bulk_disable(ARRAY_SIZE(priv->supplies), priv->supplies); | ||
51 | return 0; | ||
52 | } | ||
53 | |||
54 | #ifdef CONFIG_PM | ||
55 | static int ak5386_soc_suspend(struct snd_soc_codec *codec) | ||
56 | { | ||
57 | struct ak5386_priv *priv = snd_soc_codec_get_drvdata(codec); | ||
58 | regulator_bulk_disable(ARRAY_SIZE(priv->supplies), priv->supplies); | ||
59 | return 0; | ||
60 | } | ||
61 | |||
62 | static int ak5386_soc_resume(struct snd_soc_codec *codec) | ||
63 | { | ||
64 | struct ak5386_priv *priv = snd_soc_codec_get_drvdata(codec); | ||
65 | return regulator_bulk_enable(ARRAY_SIZE(priv->supplies), priv->supplies); | ||
66 | } | ||
67 | #else | ||
68 | #define ak5386_soc_suspend NULL | ||
69 | #define ak5386_soc_resume NULL | ||
70 | #endif /* CONFIG_PM */ | ||
71 | |||
35 | static struct snd_soc_codec_driver soc_codec_ak5386 = { | 72 | static struct snd_soc_codec_driver soc_codec_ak5386 = { |
73 | .probe = ak5386_soc_probe, | ||
74 | .remove = ak5386_soc_remove, | ||
75 | .suspend = ak5386_soc_suspend, | ||
76 | .resume = ak5386_soc_resume, | ||
36 | .dapm_widgets = ak5386_dapm_widgets, | 77 | .dapm_widgets = ak5386_dapm_widgets, |
37 | .num_dapm_widgets = ARRAY_SIZE(ak5386_dapm_widgets), | 78 | .num_dapm_widgets = ARRAY_SIZE(ak5386_dapm_widgets), |
38 | .dapm_routes = ak5386_dapm_routes, | 79 | .dapm_routes = ak5386_dapm_routes, |
@@ -122,6 +163,7 @@ static int ak5386_probe(struct platform_device *pdev) | |||
122 | { | 163 | { |
123 | struct device *dev = &pdev->dev; | 164 | struct device *dev = &pdev->dev; |
124 | struct ak5386_priv *priv; | 165 | struct ak5386_priv *priv; |
166 | int ret, i; | ||
125 | 167 | ||
126 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); | 168 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
127 | if (!priv) | 169 | if (!priv) |
@@ -130,6 +172,14 @@ static int ak5386_probe(struct platform_device *pdev) | |||
130 | priv->reset_gpio = -EINVAL; | 172 | priv->reset_gpio = -EINVAL; |
131 | dev_set_drvdata(dev, priv); | 173 | dev_set_drvdata(dev, priv); |
132 | 174 | ||
175 | for (i = 0; i < ARRAY_SIZE(supply_names); i++) | ||
176 | priv->supplies[i].supply = supply_names[i]; | ||
177 | |||
178 | ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(priv->supplies), | ||
179 | priv->supplies); | ||
180 | if (ret < 0) | ||
181 | return ret; | ||
182 | |||
133 | if (of_match_device(of_match_ptr(ak5386_dt_ids), dev)) | 183 | if (of_match_device(of_match_ptr(ak5386_dt_ids), dev)) |
134 | priv->reset_gpio = of_get_named_gpio(dev->of_node, | 184 | priv->reset_gpio = of_get_named_gpio(dev->of_node, |
135 | "reset-gpio", 0); | 185 | "reset-gpio", 0); |