hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/sound/soc/codecs/wm8782.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * sound/soc/codecs/wm8782.c
34 * simple, strap-pin configured 24bit 2ch ADC
....@@ -6,13 +7,8 @@
67 * Author: Johannes Stezenbach <js@sig21.net>
78 *
89 * based on ad73311.c
9
- * Copyright: Analog Device Inc.
10
+ * Copyright: Analog Devices Inc.
1011 * Author: Cliff Cai <cliff.cai@analog.com>
11
- *
12
- * This program is free software; you can redistribute it and/or modify it
13
- * under the terms of the GNU General Public License as published by the
14
- * Free Software Foundation; either version 2 of the License, or (at your
15
- * option) any later version.
1612 */
1713
1814 #include <linux/init.h>
....@@ -20,6 +16,7 @@
2016 #include <linux/module.h>
2117 #include <linux/kernel.h>
2218 #include <linux/device.h>
19
+#include <linux/regulator/consumer.h>
2320 #include <sound/core.h>
2421 #include <sound/pcm.h>
2522 #include <sound/ac97_codec.h>
....@@ -50,7 +47,51 @@
5047 },
5148 };
5249
50
+/* regulator power supply names */
51
+static const char *supply_names[] = {
52
+ "Vdda", /* analog supply, 2.7V - 3.6V */
53
+ "Vdd", /* digital supply, 2.7V - 5.5V */
54
+};
55
+
56
+struct wm8782_priv {
57
+ struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)];
58
+};
59
+
60
+static int wm8782_soc_probe(struct snd_soc_component *component)
61
+{
62
+ struct wm8782_priv *priv = snd_soc_component_get_drvdata(component);
63
+ return regulator_bulk_enable(ARRAY_SIZE(priv->supplies), priv->supplies);
64
+}
65
+
66
+static void wm8782_soc_remove(struct snd_soc_component *component)
67
+{
68
+ struct wm8782_priv *priv = snd_soc_component_get_drvdata(component);
69
+ regulator_bulk_disable(ARRAY_SIZE(priv->supplies), priv->supplies);
70
+}
71
+
72
+#ifdef CONFIG_PM
73
+static int wm8782_soc_suspend(struct snd_soc_component *component)
74
+{
75
+ struct wm8782_priv *priv = snd_soc_component_get_drvdata(component);
76
+ regulator_bulk_disable(ARRAY_SIZE(priv->supplies), priv->supplies);
77
+ return 0;
78
+}
79
+
80
+static int wm8782_soc_resume(struct snd_soc_component *component)
81
+{
82
+ struct wm8782_priv *priv = snd_soc_component_get_drvdata(component);
83
+ return regulator_bulk_enable(ARRAY_SIZE(priv->supplies), priv->supplies);
84
+}
85
+#else
86
+#define wm8782_soc_suspend NULL
87
+#define wm8782_soc_resume NULL
88
+#endif /* CONFIG_PM */
89
+
5390 static const struct snd_soc_component_driver soc_component_dev_wm8782 = {
91
+ .probe = wm8782_soc_probe,
92
+ .remove = wm8782_soc_remove,
93
+ .suspend = wm8782_soc_suspend,
94
+ .resume = wm8782_soc_resume,
5495 .dapm_widgets = wm8782_dapm_widgets,
5596 .num_dapm_widgets = ARRAY_SIZE(wm8782_dapm_widgets),
5697 .dapm_routes = wm8782_dapm_routes,
....@@ -63,6 +104,24 @@
63104
64105 static int wm8782_probe(struct platform_device *pdev)
65106 {
107
+ struct device *dev = &pdev->dev;
108
+ struct wm8782_priv *priv;
109
+ int ret, i;
110
+
111
+ priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
112
+ if (!priv)
113
+ return -ENOMEM;
114
+
115
+ dev_set_drvdata(dev, priv);
116
+
117
+ for (i = 0; i < ARRAY_SIZE(supply_names); i++)
118
+ priv->supplies[i].supply = supply_names[i];
119
+
120
+ ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(priv->supplies),
121
+ priv->supplies);
122
+ if (ret < 0)
123
+ return ret;
124
+
66125 return devm_snd_soc_register_component(&pdev->dev,
67126 &soc_component_dev_wm8782, &wm8782_dai, 1);
68127 }