1*6575e5caSCezary Rojewski // SPDX-License-Identifier: GPL-2.0-only
2*6575e5caSCezary Rojewski //
3*6575e5caSCezary Rojewski // Copyright(c) 2021-2022 Intel Corporation. All rights reserved.
4*6575e5caSCezary Rojewski //
5*6575e5caSCezary Rojewski // Authors: Cezary Rojewski <cezary.rojewski@intel.com>
6*6575e5caSCezary Rojewski // Amadeusz Slawinski <amadeuszx.slawinski@linux.intel.com>
7*6575e5caSCezary Rojewski //
8*6575e5caSCezary Rojewski
9*6575e5caSCezary Rojewski #include <linux/device.h>
10*6575e5caSCezary Rojewski #include <linux/module.h>
11*6575e5caSCezary Rojewski #include <sound/soc.h>
12*6575e5caSCezary Rojewski #include <sound/soc-acpi.h>
13*6575e5caSCezary Rojewski
14*6575e5caSCezary Rojewski SND_SOC_DAILINK_DEF(dmic_pin, DAILINK_COMP_ARRAY(COMP_CPU("DMIC Pin")));
15*6575e5caSCezary Rojewski SND_SOC_DAILINK_DEF(dmic_wov_pin, DAILINK_COMP_ARRAY(COMP_CPU("DMIC WoV Pin")));
16*6575e5caSCezary Rojewski SND_SOC_DAILINK_DEF(dmic_codec, DAILINK_COMP_ARRAY(COMP_CODEC("dmic-codec", "dmic-hifi")));
17*6575e5caSCezary Rojewski /* Name overridden on probe */
18*6575e5caSCezary Rojewski SND_SOC_DAILINK_DEF(platform, DAILINK_COMP_ARRAY(COMP_PLATFORM("")));
19*6575e5caSCezary Rojewski
20*6575e5caSCezary Rojewski static struct snd_soc_dai_link card_dai_links[] = {
21*6575e5caSCezary Rojewski /* Back ends */
22*6575e5caSCezary Rojewski {
23*6575e5caSCezary Rojewski .name = "DMIC",
24*6575e5caSCezary Rojewski .id = 0,
25*6575e5caSCezary Rojewski .dpcm_capture = 1,
26*6575e5caSCezary Rojewski .nonatomic = 1,
27*6575e5caSCezary Rojewski .no_pcm = 1,
28*6575e5caSCezary Rojewski SND_SOC_DAILINK_REG(dmic_pin, dmic_codec, platform),
29*6575e5caSCezary Rojewski },
30*6575e5caSCezary Rojewski {
31*6575e5caSCezary Rojewski .name = "DMIC WoV",
32*6575e5caSCezary Rojewski .id = 1,
33*6575e5caSCezary Rojewski .dpcm_capture = 1,
34*6575e5caSCezary Rojewski .nonatomic = 1,
35*6575e5caSCezary Rojewski .no_pcm = 1,
36*6575e5caSCezary Rojewski .ignore_suspend = 1,
37*6575e5caSCezary Rojewski SND_SOC_DAILINK_REG(dmic_wov_pin, dmic_codec, platform),
38*6575e5caSCezary Rojewski },
39*6575e5caSCezary Rojewski };
40*6575e5caSCezary Rojewski
41*6575e5caSCezary Rojewski static const struct snd_soc_dapm_widget card_widgets[] = {
42*6575e5caSCezary Rojewski SND_SOC_DAPM_MIC("SoC DMIC", NULL),
43*6575e5caSCezary Rojewski };
44*6575e5caSCezary Rojewski
45*6575e5caSCezary Rojewski static const struct snd_soc_dapm_route card_routes[] = {
46*6575e5caSCezary Rojewski {"DMic", NULL, "SoC DMIC"},
47*6575e5caSCezary Rojewski };
48*6575e5caSCezary Rojewski
avs_dmic_probe(struct platform_device * pdev)49*6575e5caSCezary Rojewski static int avs_dmic_probe(struct platform_device *pdev)
50*6575e5caSCezary Rojewski {
51*6575e5caSCezary Rojewski struct snd_soc_acpi_mach *mach;
52*6575e5caSCezary Rojewski struct snd_soc_card *card;
53*6575e5caSCezary Rojewski struct device *dev = &pdev->dev;
54*6575e5caSCezary Rojewski int ret;
55*6575e5caSCezary Rojewski
56*6575e5caSCezary Rojewski mach = dev_get_platdata(dev);
57*6575e5caSCezary Rojewski
58*6575e5caSCezary Rojewski card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
59*6575e5caSCezary Rojewski if (!card)
60*6575e5caSCezary Rojewski return -ENOMEM;
61*6575e5caSCezary Rojewski
62*6575e5caSCezary Rojewski card->name = "avs_dmic";
63*6575e5caSCezary Rojewski card->dev = dev;
64*6575e5caSCezary Rojewski card->owner = THIS_MODULE;
65*6575e5caSCezary Rojewski card->dai_link = card_dai_links;
66*6575e5caSCezary Rojewski card->num_links = ARRAY_SIZE(card_dai_links);
67*6575e5caSCezary Rojewski card->dapm_widgets = card_widgets;
68*6575e5caSCezary Rojewski card->num_dapm_widgets = ARRAY_SIZE(card_widgets);
69*6575e5caSCezary Rojewski card->dapm_routes = card_routes;
70*6575e5caSCezary Rojewski card->num_dapm_routes = ARRAY_SIZE(card_routes);
71*6575e5caSCezary Rojewski card->fully_routed = true;
72*6575e5caSCezary Rojewski
73*6575e5caSCezary Rojewski ret = snd_soc_fixup_dai_links_platform_name(card, mach->mach_params.platform);
74*6575e5caSCezary Rojewski if (ret)
75*6575e5caSCezary Rojewski return ret;
76*6575e5caSCezary Rojewski
77*6575e5caSCezary Rojewski return devm_snd_soc_register_card(dev, card);
78*6575e5caSCezary Rojewski }
79*6575e5caSCezary Rojewski
80*6575e5caSCezary Rojewski static struct platform_driver avs_dmic_driver = {
81*6575e5caSCezary Rojewski .probe = avs_dmic_probe,
82*6575e5caSCezary Rojewski .driver = {
83*6575e5caSCezary Rojewski .name = "avs_dmic",
84*6575e5caSCezary Rojewski .pm = &snd_soc_pm_ops,
85*6575e5caSCezary Rojewski },
86*6575e5caSCezary Rojewski };
87*6575e5caSCezary Rojewski
88*6575e5caSCezary Rojewski module_platform_driver(avs_dmic_driver);
89*6575e5caSCezary Rojewski
90*6575e5caSCezary Rojewski MODULE_LICENSE("GPL");
91*6575e5caSCezary Rojewski MODULE_ALIAS("platform:avs_dmic");
92