WIP FPC-III support
[linux/fpc-iii.git] / sound / soc / sof / nocodec.c
blob3b9bb2e83a8693a0698bf38abc0f12c8c91ff94d
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 //
11 #include <linux/module.h>
12 #include <sound/sof.h>
13 #include "sof-audio.h"
14 #include "sof-priv.h"
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
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))
29 struct snd_soc_dai_link_component *dlc;
30 int i;
32 if (!ops || !links || !card)
33 return -EINVAL;
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;
41 links[i].name = devm_kasprintf(dev, GFP_KERNEL,
42 "NoCodec-%d", i);
43 if (!links[i].name)
44 return -ENOMEM;
46 links[i].stream_name = links[i].name;
48 links[i].cpus = &dlc[0];
49 links[i].codecs = &dlc[1];
50 links[i].platforms = &dlc[2];
52 links[i].num_cpus = 1;
53 links[i].num_codecs = 1;
54 links[i].num_platforms = 1;
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;
67 links[i].be_hw_params_fixup = pcm_dai_link_fixup;
70 card->dai_link = links;
71 card->num_links = link_num;
73 return 0;
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))
80 struct snd_soc_dai_link *links;
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;
88 return sof_nocodec_bes_setup(dev, ops, links, ops->num_drv,
89 &sof_nocodec_card, pcm_dai_link_fixup);
91 EXPORT_SYMBOL(sof_nocodec_setup);
93 static int sof_nocodec_probe(struct platform_device *pdev)
95 struct snd_soc_card *card = &sof_nocodec_card;
97 card->dev = &pdev->dev;
98 card->topology_shortname_created = true;
100 return devm_snd_soc_register_card(&pdev->dev, card);
103 static int sof_nocodec_remove(struct platform_device *pdev)
105 return 0;
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,
116 module_platform_driver(sof_nocodec_audio)
118 MODULE_DESCRIPTION("ASoC sof nocodec");
119 MODULE_AUTHOR("Liam Girdwood");
120 MODULE_LICENSE("Dual BSD/GPL");
121 MODULE_ALIAS("platform:sof-nocodec");