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. All rights reserved. 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 .topology_shortname = "sof-nocodec", 19 .owner = THIS_MODULE 20 }; 21 22 static int sof_nocodec_bes_setup(struct device *dev, 23 const struct snd_sof_dsp_ops *ops, 24 struct snd_soc_dai_link *links, 25 int link_num, struct snd_soc_card *card, 26 int (*pcm_dai_link_fixup)(struct snd_soc_pcm_runtime *rtd, 27 struct snd_pcm_hw_params *params)) 28 { 29 struct snd_soc_dai_link_component *dlc; 30 int i; 31 32 if (!ops || !links || !card) 33 return -EINVAL; 34 35 /* set up BE dai_links */ 36 for (i = 0; i < link_num; i++) { 37 dlc = devm_kzalloc(dev, 3 * sizeof(*dlc), GFP_KERNEL); 38 if (!dlc) 39 return -ENOMEM; 40 41 links[i].name = devm_kasprintf(dev, GFP_KERNEL, 42 "NoCodec-%d", i); 43 if (!links[i].name) 44 return -ENOMEM; 45 46 links[i].stream_name = links[i].name; 47 48 links[i].cpus = &dlc[0]; 49 links[i].codecs = &dlc[1]; 50 links[i].platforms = &dlc[2]; 51 52 links[i].num_cpus = 1; 53 links[i].num_codecs = 1; 54 links[i].num_platforms = 1; 55 56 links[i].id = i; 57 links[i].no_pcm = 1; 58 links[i].cpus->dai_name = ops->drv[i].name; 59 links[i].platforms->name = dev_name(dev); 60 links[i].codecs->dai_name = "snd-soc-dummy-dai"; 61 links[i].codecs->name = "snd-soc-dummy"; 62 if (ops->drv[i].playback.channels_min) 63 links[i].dpcm_playback = 1; 64 if (ops->drv[i].capture.channels_min) 65 links[i].dpcm_capture = 1; 66 67 links[i].be_hw_params_fixup = pcm_dai_link_fixup; 68 } 69 70 card->dai_link = links; 71 card->num_links = link_num; 72 73 return 0; 74 } 75 76 int sof_nocodec_setup(struct device *dev, const struct snd_sof_dsp_ops *ops, 77 int (*pcm_dai_link_fixup)(struct snd_soc_pcm_runtime *rtd, 78 struct snd_pcm_hw_params *params)) 79 { 80 struct snd_soc_dai_link *links; 81 82 /* create dummy BE dai_links */ 83 links = devm_kzalloc(dev, sizeof(struct snd_soc_dai_link) * 84 ops->num_drv, GFP_KERNEL); 85 if (!links) 86 return -ENOMEM; 87 88 return sof_nocodec_bes_setup(dev, ops, links, ops->num_drv, 89 &sof_nocodec_card, pcm_dai_link_fixup); 90 } 91 EXPORT_SYMBOL(sof_nocodec_setup); 92 93 static int sof_nocodec_probe(struct platform_device *pdev) 94 { 95 struct snd_soc_card *card = &sof_nocodec_card; 96 97 card->dev = &pdev->dev; 98 card->topology_shortname_created = true; 99 100 return devm_snd_soc_register_card(&pdev->dev, card); 101 } 102 103 static int sof_nocodec_remove(struct platform_device *pdev) 104 { 105 return 0; 106 } 107 108 static struct platform_driver sof_nocodec_audio = { 109 .probe = sof_nocodec_probe, 110 .remove = sof_nocodec_remove, 111 .driver = { 112 .name = "sof-nocodec", 113 .pm = &snd_soc_pm_ops, 114 }, 115 }; 116 module_platform_driver(sof_nocodec_audio) 117 118 MODULE_DESCRIPTION("ASoC sof nocodec"); 119 MODULE_AUTHOR("Liam Girdwood"); 120 MODULE_LICENSE("Dual BSD/GPL"); 121 MODULE_ALIAS("platform:sof-nocodec"); 122