xref: /openbmc/linux/sound/soc/codecs/wm8782.c (revision 9b93eb47)
1 /*
2  * sound/soc/codecs/wm8782.c
3  * simple, strap-pin configured 24bit 2ch ADC
4  *
5  * Copyright: 2011 Raumfeld GmbH
6  * Author: Johannes Stezenbach <js@sig21.net>
7  *
8  * based on ad73311.c
9  * Copyright:	Analog Device Inc.
10  * 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.
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 
30 static const struct snd_soc_dapm_widget wm8782_dapm_widgets[] = {
31 SND_SOC_DAPM_INPUT("AINL"),
32 SND_SOC_DAPM_INPUT("AINR"),
33 };
34 
35 static const struct snd_soc_dapm_route wm8782_dapm_routes[] = {
36 	{ "Capture", NULL, "AINL" },
37 	{ "Capture", NULL, "AINR" },
38 };
39 
40 static 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 		/* For configurations with FSAMPEN=0 */
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 /* regulator power supply names */
55 static const char *supply_names[] = {
56 	"Vdda", /* analog supply, 2.7V - 3.6V */
57 	"Vdd",  /* digital supply, 2.7V - 5.5V */
58 };
59 
60 struct wm8782_priv {
61 	struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)];
62 };
63 
64 static 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 
70 static 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
77 static 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 
84 static 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 /* CONFIG_PM */
93 
94 static 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 
109 static 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
134 static const struct of_device_id wm8782_of_match[] = {
135 	{ .compatible = "wlf,wm8782", },
136 	{ }
137 };
138 MODULE_DEVICE_TABLE(of, wm8782_of_match);
139 #endif
140 
141 static 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 
149 module_platform_driver(wm8782_codec_driver);
150 
151 MODULE_DESCRIPTION("ASoC WM8782 driver");
152 MODULE_AUTHOR("Johannes Stezenbach <js@sig21.net>");
153 MODULE_LICENSE("GPL");
154