1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) 2 // 3 // This file is provided under a dual BSD/GPLv2 license. When using or 4 // redistributing this file, you may do so under either license. 5 // 6 // Copyright(c) 2018 Intel Corporation 7 // 8 // Author: Liam Girdwood <liam.r.girdwood@linux.intel.com> 9 // 10 11 #include <linux/module.h> 12 #include <sound/sof.h> 13 #include "sof-audio.h" 14 #include "sof-priv.h" 15 16 static struct snd_soc_card sof_nocodec_card = { 17 .name = "nocodec", /* the sof- prefix is added by the core */ 18 .owner = THIS_MODULE 19 }; 20 21 static int sof_nocodec_bes_setup(struct device *dev, 22 struct snd_soc_dai_driver *drv, 23 struct snd_soc_dai_link *links, 24 int link_num, struct snd_soc_card *card) 25 { 26 struct snd_soc_dai_link_component *dlc; 27 int i; 28 29 if (!drv || !links || !card) 30 return -EINVAL; 31 32 /* set up BE dai_links */ 33 for (i = 0; i < link_num; i++) { 34 dlc = devm_kcalloc(dev, 2, sizeof(*dlc), GFP_KERNEL); 35 if (!dlc) 36 return -ENOMEM; 37 38 links[i].name = devm_kasprintf(dev, GFP_KERNEL, 39 "NoCodec-%d", i); 40 if (!links[i].name) 41 return -ENOMEM; 42 43 links[i].stream_name = links[i].name; 44 45 links[i].cpus = &dlc[0]; 46 links[i].codecs = &snd_soc_dummy_dlc; 47 links[i].platforms = &dlc[1]; 48 49 links[i].num_cpus = 1; 50 links[i].num_codecs = 1; 51 links[i].num_platforms = 1; 52 53 links[i].id = i; 54 links[i].no_pcm = 1; 55 links[i].cpus->dai_name = drv[i].name; 56 links[i].platforms->name = dev_name(dev->parent); 57 58 links[i].playback_only = drv[i].playback.channels_min && !drv[i].capture.channels_min; 59 links[i].capture_only = !drv[i].playback.channels_min && drv[i].capture.channels_min; 60 61 links[i].be_hw_params_fixup = sof_pcm_dai_link_fixup; 62 } 63 64 card->dai_link = links; 65 card->num_links = link_num; 66 67 return 0; 68 } 69 70 static int sof_nocodec_setup(struct device *dev, 71 u32 num_dai_drivers, 72 struct snd_soc_dai_driver *dai_drivers) 73 { 74 struct snd_soc_dai_link *links; 75 76 /* create dummy BE dai_links */ 77 links = devm_kcalloc(dev, num_dai_drivers, sizeof(struct snd_soc_dai_link), GFP_KERNEL); 78 if (!links) 79 return -ENOMEM; 80 81 return sof_nocodec_bes_setup(dev, dai_drivers, links, num_dai_drivers, &sof_nocodec_card); 82 } 83 84 static int sof_nocodec_probe(struct platform_device *pdev) 85 { 86 struct snd_soc_card *card = &sof_nocodec_card; 87 struct snd_soc_acpi_mach *mach; 88 int ret; 89 90 card->dev = &pdev->dev; 91 mach = pdev->dev.platform_data; 92 93 snd_soc_card_set_topology_name(card, "sof"); 94 95 ret = sof_nocodec_setup(card->dev, mach->mach_params.num_dai_drivers, 96 mach->mach_params.dai_drivers); 97 if (ret < 0) 98 return ret; 99 100 return devm_snd_soc_register_card(&pdev->dev, card); 101 } 102 103 static struct platform_driver sof_nocodec_audio = { 104 .probe = sof_nocodec_probe, 105 .driver = { 106 .name = "sof-nocodec", 107 .pm = &snd_soc_pm_ops, 108 }, 109 }; 110 module_platform_driver(sof_nocodec_audio) 111 112 MODULE_LICENSE("Dual BSD/GPL"); 113 MODULE_DESCRIPTION("ASoC sof nocodec"); 114 MODULE_AUTHOR("Liam Girdwood"); 115 MODULE_ALIAS("platform:sof-nocodec"); 116