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