Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
0002 //
0003 // This file is provided under a dual BSD/GPLv2 license.  When using or
0004 // redistributing this file, you may do so under either license.
0005 //
0006 // Copyright(c) 2018 Intel Corporation. All rights reserved.
0007 //
0008 // Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
0009 //
0010 
0011 #include <linux/module.h>
0012 #include <sound/sof.h>
0013 #include "sof-audio.h"
0014 #include "sof-priv.h"
0015 
0016 static struct snd_soc_card sof_nocodec_card = {
0017     .name = "nocodec", /* the sof- prefix is added by the core */
0018     .topology_shortname = "sof-nocodec",
0019     .owner = THIS_MODULE
0020 };
0021 
0022 static int sof_nocodec_bes_setup(struct device *dev,
0023                  struct snd_soc_dai_driver *drv,
0024                  struct snd_soc_dai_link *links,
0025                  int link_num, struct snd_soc_card *card)
0026 {
0027     struct snd_soc_dai_link_component *dlc;
0028     int i;
0029 
0030     if (!drv || !links || !card)
0031         return -EINVAL;
0032 
0033     /* set up BE dai_links */
0034     for (i = 0; i < link_num; i++) {
0035         dlc = devm_kzalloc(dev, 3 * sizeof(*dlc), GFP_KERNEL);
0036         if (!dlc)
0037             return -ENOMEM;
0038 
0039         links[i].name = devm_kasprintf(dev, GFP_KERNEL,
0040                            "NoCodec-%d", i);
0041         if (!links[i].name)
0042             return -ENOMEM;
0043 
0044         links[i].stream_name = links[i].name;
0045 
0046         links[i].cpus = &dlc[0];
0047         links[i].codecs = &dlc[1];
0048         links[i].platforms = &dlc[2];
0049 
0050         links[i].num_cpus = 1;
0051         links[i].num_codecs = 1;
0052         links[i].num_platforms = 1;
0053 
0054         links[i].id = i;
0055         links[i].no_pcm = 1;
0056         links[i].cpus->dai_name = drv[i].name;
0057         links[i].platforms->name = dev_name(dev->parent);
0058         links[i].codecs->dai_name = "snd-soc-dummy-dai";
0059         links[i].codecs->name = "snd-soc-dummy";
0060         if (drv[i].playback.channels_min)
0061             links[i].dpcm_playback = 1;
0062         if (drv[i].capture.channels_min)
0063             links[i].dpcm_capture = 1;
0064 
0065         links[i].be_hw_params_fixup = sof_pcm_dai_link_fixup;
0066     }
0067 
0068     card->dai_link = links;
0069     card->num_links = link_num;
0070 
0071     return 0;
0072 }
0073 
0074 static int sof_nocodec_setup(struct device *dev,
0075                  u32 num_dai_drivers,
0076                  struct snd_soc_dai_driver *dai_drivers)
0077 {
0078     struct snd_soc_dai_link *links;
0079 
0080     /* create dummy BE dai_links */
0081     links = devm_kzalloc(dev, sizeof(struct snd_soc_dai_link) * num_dai_drivers, GFP_KERNEL);
0082     if (!links)
0083         return -ENOMEM;
0084 
0085     return sof_nocodec_bes_setup(dev, dai_drivers, links, num_dai_drivers, &sof_nocodec_card);
0086 }
0087 
0088 static int sof_nocodec_probe(struct platform_device *pdev)
0089 {
0090     struct snd_soc_card *card = &sof_nocodec_card;
0091     struct snd_soc_acpi_mach *mach;
0092     int ret;
0093 
0094     card->dev = &pdev->dev;
0095     card->topology_shortname_created = true;
0096     mach = pdev->dev.platform_data;
0097 
0098     ret = sof_nocodec_setup(card->dev, mach->mach_params.num_dai_drivers,
0099                 mach->mach_params.dai_drivers);
0100     if (ret < 0)
0101         return ret;
0102 
0103     return devm_snd_soc_register_card(&pdev->dev, card);
0104 }
0105 
0106 static int sof_nocodec_remove(struct platform_device *pdev)
0107 {
0108     return 0;
0109 }
0110 
0111 static struct platform_driver sof_nocodec_audio = {
0112     .probe = sof_nocodec_probe,
0113     .remove = sof_nocodec_remove,
0114     .driver = {
0115         .name = "sof-nocodec",
0116         .pm = &snd_soc_pm_ops,
0117     },
0118 };
0119 module_platform_driver(sof_nocodec_audio)
0120 
0121 MODULE_DESCRIPTION("ASoC sof nocodec");
0122 MODULE_AUTHOR("Liam Girdwood");
0123 MODULE_LICENSE("Dual BSD/GPL");
0124 MODULE_ALIAS("platform:sof-nocodec");