1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * sound/soc/codecs/wm8782.c
4 * simple, strap-pin configured 24bit 2ch ADC
6 * Copyright: 2011 Raumfeld GmbH
10 * Copyright: Analog Devices Inc.
14 #include <linux/init.h>
15 #include <linux/slab.h>
16 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/device.h>
19 #include <linux/regulator/consumer.h>
20 #include <sound/core.h>
21 #include <sound/pcm.h>
22 #include <sound/ac97_codec.h>
23 #include <sound/initval.h>
24 #include <sound/soc.h>
26 /* regulator power supply names */
27 static const char *supply_names[] = {
28 "Vdda", /* analog supply, 2.7V - 3.6V */
29 "Vdd", /* digital supply, 2.7V - 5.5V */
33 struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)];
37 static int wm8782_dai_startup(struct snd_pcm_substream *sub, struct snd_soc_dai *dai)
39 struct snd_pcm_runtime *runtime = sub->runtime;
40 struct wm8782_priv *priv =
41 snd_soc_component_get_drvdata(dai->component);
43 return snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_RATE,
44 8000, priv->max_rate);
47 static const struct snd_soc_dapm_widget wm8782_dapm_widgets[] = {
48 SND_SOC_DAPM_INPUT("AINL"),
49 SND_SOC_DAPM_INPUT("AINR"),
52 static const struct snd_soc_dapm_route wm8782_dapm_routes[] = {
53 { "Capture", NULL, "AINL" },
54 { "Capture", NULL, "AINR" },
57 static const struct snd_soc_dai_ops wm8782_dai_ops = {
58 .startup = &wm8782_dai_startup,
61 static struct snd_soc_dai_driver wm8782_dai = {
64 .stream_name = "Capture",
67 .rates = SNDRV_PCM_RATE_8000_192000,
68 .formats = SNDRV_PCM_FMTBIT_S16_LE |
69 SNDRV_PCM_FMTBIT_S20_3LE |
70 SNDRV_PCM_FMTBIT_S24_LE,
72 .ops = &wm8782_dai_ops,
75 static int wm8782_soc_probe(struct snd_soc_component *component)
77 struct wm8782_priv *priv = snd_soc_component_get_drvdata(component);
78 return regulator_bulk_enable(ARRAY_SIZE(priv->supplies), priv->supplies);
81 static void wm8782_soc_remove(struct snd_soc_component *component)
83 struct wm8782_priv *priv = snd_soc_component_get_drvdata(component);
84 regulator_bulk_disable(ARRAY_SIZE(priv->supplies), priv->supplies);
88 static int wm8782_soc_suspend(struct snd_soc_component *component)
90 struct wm8782_priv *priv = snd_soc_component_get_drvdata(component);
91 regulator_bulk_disable(ARRAY_SIZE(priv->supplies), priv->supplies);
95 static int wm8782_soc_resume(struct snd_soc_component *component)
97 struct wm8782_priv *priv = snd_soc_component_get_drvdata(component);
98 return regulator_bulk_enable(ARRAY_SIZE(priv->supplies), priv->supplies);
101 #define wm8782_soc_suspend NULL
102 #define wm8782_soc_resume NULL
103 #endif /* CONFIG_PM */
105 static const struct snd_soc_component_driver soc_component_dev_wm8782 = {
106 .probe = wm8782_soc_probe,
107 .remove = wm8782_soc_remove,
108 .suspend = wm8782_soc_suspend,
109 .resume = wm8782_soc_resume,
110 .dapm_widgets = wm8782_dapm_widgets,
111 .num_dapm_widgets = ARRAY_SIZE(wm8782_dapm_widgets),
112 .dapm_routes = wm8782_dapm_routes,
113 .num_dapm_routes = ARRAY_SIZE(wm8782_dapm_routes),
115 .use_pmdown_time = 1,
119 static int wm8782_probe(struct platform_device *pdev)
121 struct device *dev = &pdev->dev;
122 struct device_node *np = dev->of_node;
123 struct wm8782_priv *priv;
126 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
130 dev_set_drvdata(dev, priv);
132 for (i = 0; i < ARRAY_SIZE(supply_names); i++)
133 priv->supplies[i].supply = supply_names[i];
135 ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(priv->supplies),
140 // Assume lowest value by default to avoid inadvertent overclocking
144 of_property_read_u32(np, "wlf,fsampen", &fsampen);
148 priv->max_rate = 48000;
151 priv->max_rate = 96000;
154 priv->max_rate = 192000;
157 dev_err(dev, "Invalid wlf,fsampen value");
161 return devm_snd_soc_register_component(&pdev->dev,
162 &soc_component_dev_wm8782, &wm8782_dai, 1);
166 static const struct of_device_id wm8782_of_match[] = {
167 { .compatible = "wlf,wm8782", },
170 MODULE_DEVICE_TABLE(of, wm8782_of_match);
173 static struct platform_driver wm8782_codec_driver = {
176 .of_match_table = of_match_ptr(wm8782_of_match),
178 .probe = wm8782_probe,
181 module_platform_driver(wm8782_codec_driver);
183 MODULE_DESCRIPTION("ASoC WM8782 driver");
185 MODULE_LICENSE("GPL");