1*fda8d26eSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2a0d3546cSLars-Peter Clausen /*
3a0d3546cSLars-Peter Clausen * ADAU7002 Stereo PDM-to-I2S/TDM converter driver
4a0d3546cSLars-Peter Clausen *
5a0d3546cSLars-Peter Clausen * Copyright 2014-2016 Analog Devices
6a0d3546cSLars-Peter Clausen * Author: Lars-Peter Clausen <lars@metafoo.de>
7a0d3546cSLars-Peter Clausen */
8a0d3546cSLars-Peter Clausen
9ba7a3a97SAkshu Agrawal #include <linux/acpi.h>
107b57085aSAgrawal, Akshu #include <linux/delay.h>
11a0d3546cSLars-Peter Clausen #include <linux/init.h>
12a0d3546cSLars-Peter Clausen #include <linux/module.h>
13a0d3546cSLars-Peter Clausen #include <linux/of.h>
14a0d3546cSLars-Peter Clausen #include <linux/platform_device.h>
15a0d3546cSLars-Peter Clausen
16a0d3546cSLars-Peter Clausen #include <sound/soc.h>
17a0d3546cSLars-Peter Clausen
187b57085aSAgrawal, Akshu struct adau7002_priv {
197b57085aSAgrawal, Akshu int wakeup_delay;
207b57085aSAgrawal, Akshu };
217b57085aSAgrawal, Akshu
adau7002_aif_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)227b57085aSAgrawal, Akshu static int adau7002_aif_event(struct snd_soc_dapm_widget *w,
237b57085aSAgrawal, Akshu struct snd_kcontrol *kcontrol, int event)
247b57085aSAgrawal, Akshu {
257b57085aSAgrawal, Akshu struct snd_soc_component *component =
267b57085aSAgrawal, Akshu snd_soc_dapm_to_component(w->dapm);
277b57085aSAgrawal, Akshu struct adau7002_priv *adau7002 =
287b57085aSAgrawal, Akshu snd_soc_component_get_drvdata(component);
297b57085aSAgrawal, Akshu
307b57085aSAgrawal, Akshu switch (event) {
317b57085aSAgrawal, Akshu case SND_SOC_DAPM_POST_PMU:
327b57085aSAgrawal, Akshu if (adau7002->wakeup_delay)
337b57085aSAgrawal, Akshu msleep(adau7002->wakeup_delay);
347b57085aSAgrawal, Akshu break;
357b57085aSAgrawal, Akshu }
367b57085aSAgrawal, Akshu
377b57085aSAgrawal, Akshu return 0;
387b57085aSAgrawal, Akshu }
397b57085aSAgrawal, Akshu
adau7002_component_probe(struct snd_soc_component * component)407b57085aSAgrawal, Akshu static int adau7002_component_probe(struct snd_soc_component *component)
417b57085aSAgrawal, Akshu {
427b57085aSAgrawal, Akshu struct adau7002_priv *adau7002;
437b57085aSAgrawal, Akshu
447b57085aSAgrawal, Akshu adau7002 = devm_kzalloc(component->dev, sizeof(*adau7002),
457b57085aSAgrawal, Akshu GFP_KERNEL);
467b57085aSAgrawal, Akshu if (!adau7002)
477b57085aSAgrawal, Akshu return -ENOMEM;
487b57085aSAgrawal, Akshu
497b57085aSAgrawal, Akshu device_property_read_u32(component->dev, "wakeup-delay-ms",
507b57085aSAgrawal, Akshu &adau7002->wakeup_delay);
517b57085aSAgrawal, Akshu
527b57085aSAgrawal, Akshu snd_soc_component_set_drvdata(component, adau7002);
537b57085aSAgrawal, Akshu
547b57085aSAgrawal, Akshu return 0;
557b57085aSAgrawal, Akshu }
567b57085aSAgrawal, Akshu
57a0d3546cSLars-Peter Clausen static const struct snd_soc_dapm_widget adau7002_widgets[] = {
587b57085aSAgrawal, Akshu SND_SOC_DAPM_AIF_OUT_E("ADAU AIF", "Capture", 0,
597b57085aSAgrawal, Akshu SND_SOC_NOPM, 0, 0, adau7002_aif_event,
607b57085aSAgrawal, Akshu SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
61a0d3546cSLars-Peter Clausen SND_SOC_DAPM_INPUT("PDM_DAT"),
62a0d3546cSLars-Peter Clausen SND_SOC_DAPM_REGULATOR_SUPPLY("IOVDD", 0, 0),
63a0d3546cSLars-Peter Clausen };
64a0d3546cSLars-Peter Clausen
65a0d3546cSLars-Peter Clausen static const struct snd_soc_dapm_route adau7002_routes[] = {
667b57085aSAgrawal, Akshu { "ADAU AIF", NULL, "PDM_DAT"},
67a0d3546cSLars-Peter Clausen { "Capture", NULL, "PDM_DAT" },
68a0d3546cSLars-Peter Clausen { "Capture", NULL, "IOVDD" },
69a0d3546cSLars-Peter Clausen };
70a0d3546cSLars-Peter Clausen
71a0d3546cSLars-Peter Clausen static struct snd_soc_dai_driver adau7002_dai = {
72a0d3546cSLars-Peter Clausen .name = "adau7002-hifi",
73a0d3546cSLars-Peter Clausen .capture = {
74a0d3546cSLars-Peter Clausen .stream_name = "Capture",
75a0d3546cSLars-Peter Clausen .channels_min = 2,
76a0d3546cSLars-Peter Clausen .channels_max = 2,
77a0d3546cSLars-Peter Clausen .rates = SNDRV_PCM_RATE_8000_96000,
78a0d3546cSLars-Peter Clausen .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S18_3LE |
79a0d3546cSLars-Peter Clausen SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE |
80a0d3546cSLars-Peter Clausen SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE,
81a0d3546cSLars-Peter Clausen .sig_bits = 20,
82a0d3546cSLars-Peter Clausen },
83a0d3546cSLars-Peter Clausen };
84a0d3546cSLars-Peter Clausen
85d5bc5484SKuninori Morimoto static const struct snd_soc_component_driver adau7002_component_driver = {
867b57085aSAgrawal, Akshu .probe = adau7002_component_probe,
87a0d3546cSLars-Peter Clausen .dapm_widgets = adau7002_widgets,
88a0d3546cSLars-Peter Clausen .num_dapm_widgets = ARRAY_SIZE(adau7002_widgets),
89a0d3546cSLars-Peter Clausen .dapm_routes = adau7002_routes,
90a0d3546cSLars-Peter Clausen .num_dapm_routes = ARRAY_SIZE(adau7002_routes),
91d5bc5484SKuninori Morimoto .idle_bias_on = 1,
92d5bc5484SKuninori Morimoto .use_pmdown_time = 1,
93d5bc5484SKuninori Morimoto .endianness = 1,
94a0d3546cSLars-Peter Clausen };
95a0d3546cSLars-Peter Clausen
adau7002_probe(struct platform_device * pdev)96a0d3546cSLars-Peter Clausen static int adau7002_probe(struct platform_device *pdev)
97a0d3546cSLars-Peter Clausen {
98d5bc5484SKuninori Morimoto return devm_snd_soc_register_component(&pdev->dev,
99d5bc5484SKuninori Morimoto &adau7002_component_driver,
100a0d3546cSLars-Peter Clausen &adau7002_dai, 1);
101a0d3546cSLars-Peter Clausen }
102a0d3546cSLars-Peter Clausen
103a0d3546cSLars-Peter Clausen #ifdef CONFIG_OF
104a0d3546cSLars-Peter Clausen static const struct of_device_id adau7002_dt_ids[] = {
105a0d3546cSLars-Peter Clausen { .compatible = "adi,adau7002", },
106a0d3546cSLars-Peter Clausen { }
107a0d3546cSLars-Peter Clausen };
108a0d3546cSLars-Peter Clausen MODULE_DEVICE_TABLE(of, adau7002_dt_ids);
109a0d3546cSLars-Peter Clausen #endif
110a0d3546cSLars-Peter Clausen
111ba7a3a97SAkshu Agrawal #ifdef CONFIG_ACPI
112ba7a3a97SAkshu Agrawal static const struct acpi_device_id adau7002_acpi_match[] = {
113ba7a3a97SAkshu Agrawal { "ADAU7002", 0 },
114ba7a3a97SAkshu Agrawal {},
115ba7a3a97SAkshu Agrawal };
116ba7a3a97SAkshu Agrawal MODULE_DEVICE_TABLE(acpi, adau7002_acpi_match);
117ba7a3a97SAkshu Agrawal #endif
118ba7a3a97SAkshu Agrawal
119a0d3546cSLars-Peter Clausen static struct platform_driver adau7002_driver = {
120a0d3546cSLars-Peter Clausen .driver = {
121a0d3546cSLars-Peter Clausen .name = "adau7002",
122a0d3546cSLars-Peter Clausen .of_match_table = of_match_ptr(adau7002_dt_ids),
123ba7a3a97SAkshu Agrawal .acpi_match_table = ACPI_PTR(adau7002_acpi_match),
124a0d3546cSLars-Peter Clausen },
125a0d3546cSLars-Peter Clausen .probe = adau7002_probe,
126a0d3546cSLars-Peter Clausen };
127a0d3546cSLars-Peter Clausen module_platform_driver(adau7002_driver);
128a0d3546cSLars-Peter Clausen
129a0d3546cSLars-Peter Clausen MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
130a0d3546cSLars-Peter Clausen MODULE_DESCRIPTION("ADAU7002 Stereo PDM-to-I2S/TDM Converter driver");
131a0d3546cSLars-Peter Clausen MODULE_LICENSE("GPL v2");
132