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 {"DMIC Rx", NULL, "Capture"}, 48 {"DMIC WoV Rx", NULL, "Capture"}, 49 }; 50 51 static int avs_dmic_probe(struct platform_device *pdev) 52 { 53 struct snd_soc_acpi_mach *mach; 54 struct snd_soc_card *card; 55 struct device *dev = &pdev->dev; 56 int ret; 57 58 mach = dev_get_platdata(dev); 59 60 card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL); 61 if (!card) 62 return -ENOMEM; 63 64 card->name = "avs_dmic"; 65 card->dev = dev; 66 card->owner = THIS_MODULE; 67 card->dai_link = card_dai_links; 68 card->num_links = ARRAY_SIZE(card_dai_links); 69 card->dapm_widgets = card_widgets; 70 card->num_dapm_widgets = ARRAY_SIZE(card_widgets); 71 card->dapm_routes = card_routes; 72 card->num_dapm_routes = ARRAY_SIZE(card_routes); 73 card->fully_routed = true; 74 75 ret = snd_soc_fixup_dai_links_platform_name(card, mach->mach_params.platform); 76 if (ret) 77 return ret; 78 79 return devm_snd_soc_register_card(dev, card); 80 } 81 82 static struct platform_driver avs_dmic_driver = { 83 .probe = avs_dmic_probe, 84 .driver = { 85 .name = "avs_dmic", 86 .pm = &snd_soc_pm_ops, 87 }, 88 }; 89 90 module_platform_driver(avs_dmic_driver); 91 92 MODULE_LICENSE("GPL"); 93 MODULE_ALIAS("platform:avs_dmic"); 94