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