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