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