xref: /openbmc/linux/sound/soc/codecs/adau7002.c (revision dff03381)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * ADAU7002 Stereo PDM-to-I2S/TDM converter driver
4  *
5  * Copyright 2014-2016 Analog Devices
6  *  Author: Lars-Peter Clausen <lars@metafoo.de>
7  */
8 
9 #include <linux/acpi.h>
10 #include <linux/delay.h>
11 #include <linux/init.h>
12 #include <linux/module.h>
13 #include <linux/of.h>
14 #include <linux/platform_device.h>
15 
16 #include <sound/soc.h>
17 
18 struct adau7002_priv {
19 	int wakeup_delay;
20 };
21 
22 static int adau7002_aif_event(struct snd_soc_dapm_widget *w,
23 			      struct snd_kcontrol *kcontrol, int event)
24 {
25 	struct snd_soc_component *component =
26 			snd_soc_dapm_to_component(w->dapm);
27 	struct adau7002_priv *adau7002 =
28 			snd_soc_component_get_drvdata(component);
29 
30 	switch (event) {
31 	case SND_SOC_DAPM_POST_PMU:
32 		if (adau7002->wakeup_delay)
33 			msleep(adau7002->wakeup_delay);
34 		break;
35 	}
36 
37 	return 0;
38 }
39 
40 static int adau7002_component_probe(struct snd_soc_component *component)
41 {
42 	struct adau7002_priv *adau7002;
43 
44 	adau7002 = devm_kzalloc(component->dev, sizeof(*adau7002),
45 				GFP_KERNEL);
46 	if (!adau7002)
47 		return -ENOMEM;
48 
49 	device_property_read_u32(component->dev, "wakeup-delay-ms",
50 				 &adau7002->wakeup_delay);
51 
52 	snd_soc_component_set_drvdata(component, adau7002);
53 
54 	return 0;
55 }
56 
57 static const struct snd_soc_dapm_widget adau7002_widgets[] = {
58 	SND_SOC_DAPM_AIF_OUT_E("ADAU AIF", "Capture", 0,
59 			       SND_SOC_NOPM, 0, 0, adau7002_aif_event,
60 			       SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
61 	SND_SOC_DAPM_INPUT("PDM_DAT"),
62 	SND_SOC_DAPM_REGULATOR_SUPPLY("IOVDD", 0, 0),
63 };
64 
65 static const struct snd_soc_dapm_route adau7002_routes[] = {
66 	{ "ADAU AIF", NULL, "PDM_DAT"},
67 	{ "Capture", NULL, "PDM_DAT" },
68 	{ "Capture", NULL, "IOVDD" },
69 };
70 
71 static struct snd_soc_dai_driver adau7002_dai = {
72 	.name = "adau7002-hifi",
73 	.capture = {
74 		.stream_name = "Capture",
75 		.channels_min = 2,
76 		.channels_max = 2,
77 		.rates = SNDRV_PCM_RATE_8000_96000,
78 		.formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S18_3LE |
79 			SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE |
80 			SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE,
81 		.sig_bits = 20,
82 	},
83 };
84 
85 static const struct snd_soc_component_driver adau7002_component_driver = {
86 	.probe			= adau7002_component_probe,
87 	.dapm_widgets		= adau7002_widgets,
88 	.num_dapm_widgets	= ARRAY_SIZE(adau7002_widgets),
89 	.dapm_routes		= adau7002_routes,
90 	.num_dapm_routes	= ARRAY_SIZE(adau7002_routes),
91 	.idle_bias_on		= 1,
92 	.use_pmdown_time	= 1,
93 	.endianness		= 1,
94 };
95 
96 static int adau7002_probe(struct platform_device *pdev)
97 {
98 	return devm_snd_soc_register_component(&pdev->dev,
99 			&adau7002_component_driver,
100 			&adau7002_dai, 1);
101 }
102 
103 static int adau7002_remove(struct platform_device *pdev)
104 {
105 	return 0;
106 }
107 
108 #ifdef CONFIG_OF
109 static const struct of_device_id adau7002_dt_ids[] = {
110 	{ .compatible = "adi,adau7002", },
111 	{ }
112 };
113 MODULE_DEVICE_TABLE(of, adau7002_dt_ids);
114 #endif
115 
116 #ifdef CONFIG_ACPI
117 static const struct acpi_device_id adau7002_acpi_match[] = {
118 	{ "ADAU7002", 0 },
119 	{},
120 };
121 MODULE_DEVICE_TABLE(acpi, adau7002_acpi_match);
122 #endif
123 
124 static struct platform_driver adau7002_driver = {
125 	.driver = {
126 		.name = "adau7002",
127 		.of_match_table	= of_match_ptr(adau7002_dt_ids),
128 		.acpi_match_table = ACPI_PTR(adau7002_acpi_match),
129 	},
130 	.probe = adau7002_probe,
131 	.remove = adau7002_remove,
132 };
133 module_platform_driver(adau7002_driver);
134 
135 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
136 MODULE_DESCRIPTION("ADAU7002 Stereo PDM-to-I2S/TDM Converter driver");
137 MODULE_LICENSE("GPL v2");
138