1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include <linux/init.h>
19#include <linux/slab.h>
20#include <linux/module.h>
21#include <linux/kernel.h>
22#include <linux/device.h>
23#include <linux/regulator/consumer.h>
24#include <sound/core.h>
25#include <sound/pcm.h>
26#include <sound/ac97_codec.h>
27#include <sound/initval.h>
28#include <sound/soc.h>
29
30static const struct snd_soc_dapm_widget wm8782_dapm_widgets[] = {
31SND_SOC_DAPM_INPUT("AINL"),
32SND_SOC_DAPM_INPUT("AINR"),
33};
34
35static const struct snd_soc_dapm_route wm8782_dapm_routes[] = {
36 { "Capture", NULL, "AINL" },
37 { "Capture", NULL, "AINR" },
38};
39
40static struct snd_soc_dai_driver wm8782_dai = {
41 .name = "wm8782",
42 .capture = {
43 .stream_name = "Capture",
44 .channels_min = 2,
45 .channels_max = 2,
46
47 .rates = SNDRV_PCM_RATE_8000_48000,
48 .formats = SNDRV_PCM_FMTBIT_S16_LE |
49 SNDRV_PCM_FMTBIT_S20_3LE |
50 SNDRV_PCM_FMTBIT_S24_LE,
51 },
52};
53
54
55static const char *supply_names[] = {
56 "Vdda",
57 "Vdd",
58};
59
60struct wm8782_priv {
61 struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)];
62};
63
64static int wm8782_soc_probe(struct snd_soc_component *component)
65{
66 struct wm8782_priv *priv = snd_soc_component_get_drvdata(component);
67 return regulator_bulk_enable(ARRAY_SIZE(priv->supplies), priv->supplies);
68}
69
70static void wm8782_soc_remove(struct snd_soc_component *component)
71{
72 struct wm8782_priv *priv = snd_soc_component_get_drvdata(component);
73 regulator_bulk_disable(ARRAY_SIZE(priv->supplies), priv->supplies);
74}
75
76#ifdef CONFIG_PM
77static int wm8782_soc_suspend(struct snd_soc_component *component)
78{
79 struct wm8782_priv *priv = snd_soc_component_get_drvdata(component);
80 regulator_bulk_disable(ARRAY_SIZE(priv->supplies), priv->supplies);
81 return 0;
82}
83
84static int wm8782_soc_resume(struct snd_soc_component *component)
85{
86 struct wm8782_priv *priv = snd_soc_component_get_drvdata(component);
87 return regulator_bulk_enable(ARRAY_SIZE(priv->supplies), priv->supplies);
88}
89#else
90#define wm8782_soc_suspend NULL
91#define wm8782_soc_resume NULL
92#endif
93
94static const struct snd_soc_component_driver soc_component_dev_wm8782 = {
95 .probe = wm8782_soc_probe,
96 .remove = wm8782_soc_remove,
97 .suspend = wm8782_soc_suspend,
98 .resume = wm8782_soc_resume,
99 .dapm_widgets = wm8782_dapm_widgets,
100 .num_dapm_widgets = ARRAY_SIZE(wm8782_dapm_widgets),
101 .dapm_routes = wm8782_dapm_routes,
102 .num_dapm_routes = ARRAY_SIZE(wm8782_dapm_routes),
103 .idle_bias_on = 1,
104 .use_pmdown_time = 1,
105 .endianness = 1,
106 .non_legacy_dai_naming = 1,
107};
108
109static int wm8782_probe(struct platform_device *pdev)
110{
111 struct device *dev = &pdev->dev;
112 struct wm8782_priv *priv;
113 int ret, i;
114
115 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
116 if (!priv)
117 return -ENOMEM;
118
119 dev_set_drvdata(dev, priv);
120
121 for (i = 0; i < ARRAY_SIZE(supply_names); i++)
122 priv->supplies[i].supply = supply_names[i];
123
124 ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(priv->supplies),
125 priv->supplies);
126 if (ret < 0)
127 return ret;
128
129 return devm_snd_soc_register_component(&pdev->dev,
130 &soc_component_dev_wm8782, &wm8782_dai, 1);
131}
132
133#ifdef CONFIG_OF
134static const struct of_device_id wm8782_of_match[] = {
135 { .compatible = "wlf,wm8782", },
136 { }
137};
138MODULE_DEVICE_TABLE(of, wm8782_of_match);
139#endif
140
141static struct platform_driver wm8782_codec_driver = {
142 .driver = {
143 .name = "wm8782",
144 .of_match_table = of_match_ptr(wm8782_of_match),
145 },
146 .probe = wm8782_probe,
147};
148
149module_platform_driver(wm8782_codec_driver);
150
151MODULE_DESCRIPTION("ASoC WM8782 driver");
152MODULE_AUTHOR("Johannes Stezenbach <js@sig21.net>");
153MODULE_LICENSE("GPL");
154