1
2
3
4
5
6
7
8
9
10
11#include <linux/module.h>
12#include <sound/sof.h>
13#include "sof-audio.h"
14#include "sof-priv.h"
15
16static struct snd_soc_card sof_nocodec_card = {
17 .name = "nocodec",
18 .topology_shortname = "sof-nocodec",
19 .owner = THIS_MODULE
20};
21
22static int sof_nocodec_bes_setup(struct device *dev,
23 struct snd_soc_dai_driver *drv,
24 struct snd_soc_dai_link *links,
25 int link_num, struct snd_soc_card *card)
26{
27 struct snd_soc_dai_link_component *dlc;
28 int i;
29
30 if (!drv || !links || !card)
31 return -EINVAL;
32
33
34 for (i = 0; i < link_num; i++) {
35 dlc = devm_kzalloc(dev, 3 * sizeof(*dlc), GFP_KERNEL);
36 if (!dlc)
37 return -ENOMEM;
38
39 links[i].name = devm_kasprintf(dev, GFP_KERNEL,
40 "NoCodec-%d", i);
41 if (!links[i].name)
42 return -ENOMEM;
43
44 links[i].stream_name = links[i].name;
45
46 links[i].cpus = &dlc[0];
47 links[i].codecs = &dlc[1];
48 links[i].platforms = &dlc[2];
49
50 links[i].num_cpus = 1;
51 links[i].num_codecs = 1;
52 links[i].num_platforms = 1;
53
54 links[i].id = i;
55 links[i].no_pcm = 1;
56 links[i].cpus->dai_name = drv[i].name;
57 links[i].platforms->name = dev_name(dev->parent);
58 links[i].codecs->dai_name = "snd-soc-dummy-dai";
59 links[i].codecs->name = "snd-soc-dummy";
60 if (drv[i].playback.channels_min)
61 links[i].dpcm_playback = 1;
62 if (drv[i].capture.channels_min)
63 links[i].dpcm_capture = 1;
64
65 links[i].be_hw_params_fixup = sof_pcm_dai_link_fixup;
66 }
67
68 card->dai_link = links;
69 card->num_links = link_num;
70
71 return 0;
72}
73
74static int sof_nocodec_setup(struct device *dev,
75 u32 num_dai_drivers,
76 struct snd_soc_dai_driver *dai_drivers)
77{
78 struct snd_soc_dai_link *links;
79
80
81 links = devm_kzalloc(dev, sizeof(struct snd_soc_dai_link) * num_dai_drivers, GFP_KERNEL);
82 if (!links)
83 return -ENOMEM;
84
85 return sof_nocodec_bes_setup(dev, dai_drivers, links, num_dai_drivers, &sof_nocodec_card);
86}
87
88static int sof_nocodec_probe(struct platform_device *pdev)
89{
90 struct snd_soc_card *card = &sof_nocodec_card;
91 struct snd_soc_acpi_mach *mach;
92 int ret;
93
94 card->dev = &pdev->dev;
95 card->topology_shortname_created = true;
96 mach = pdev->dev.platform_data;
97
98 ret = sof_nocodec_setup(card->dev, mach->mach_params.num_dai_drivers,
99 mach->mach_params.dai_drivers);
100 if (ret < 0)
101 return ret;
102
103 return devm_snd_soc_register_card(&pdev->dev, card);
104}
105
106static int sof_nocodec_remove(struct platform_device *pdev)
107{
108 return 0;
109}
110
111static struct platform_driver sof_nocodec_audio = {
112 .probe = sof_nocodec_probe,
113 .remove = sof_nocodec_remove,
114 .driver = {
115 .name = "sof-nocodec",
116 .pm = &snd_soc_pm_ops,
117 },
118};
119module_platform_driver(sof_nocodec_audio)
120
121MODULE_DESCRIPTION("ASoC sof nocodec");
122MODULE_AUTHOR("Liam Girdwood");
123MODULE_LICENSE("Dual BSD/GPL");
124MODULE_ALIAS("platform:sof-nocodec");
125