xref: /openbmc/linux/sound/soc/sof/nocodec.c (revision f66501dc)
1 // SPDX-License-Identifier: (GPL-2.0 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 	int i;
25 
26 	if (!ops || !links || !card)
27 		return -EINVAL;
28 
29 	/* set up BE dai_links */
30 	for (i = 0; i < link_num; i++) {
31 		links[i].name = devm_kasprintf(dev, GFP_KERNEL,
32 					       "NoCodec-%d", i);
33 		if (!links[i].name)
34 			return -ENOMEM;
35 
36 		links[i].id = i;
37 		links[i].no_pcm = 1;
38 		links[i].cpu_dai_name = ops->drv[i].name;
39 		links[i].platform_name = dev_name(dev);
40 		links[i].codec_dai_name = "snd-soc-dummy-dai";
41 		links[i].codec_name = "snd-soc-dummy";
42 		links[i].dpcm_playback = 1;
43 		links[i].dpcm_capture = 1;
44 	}
45 
46 	card->dai_link = links;
47 	card->num_links = link_num;
48 
49 	return 0;
50 }
51 
52 int sof_nocodec_setup(struct device *dev,
53 		      struct snd_sof_pdata *sof_pdata,
54 		      struct snd_soc_acpi_mach *mach,
55 		      const struct sof_dev_desc *desc,
56 		      const struct snd_sof_dsp_ops *ops)
57 {
58 	struct snd_soc_dai_link *links;
59 	int ret;
60 
61 	if (!mach)
62 		return -EINVAL;
63 
64 	sof_pdata->drv_name = "sof-nocodec";
65 
66 	mach->drv_name = "sof-nocodec";
67 	sof_pdata->fw_filename = desc->nocodec_fw_filename;
68 	sof_pdata->tplg_filename = desc->nocodec_tplg_filename;
69 
70 	/* create dummy BE dai_links */
71 	links = devm_kzalloc(dev, sizeof(struct snd_soc_dai_link) *
72 			     ops->num_drv, GFP_KERNEL);
73 	if (!links)
74 		return -ENOMEM;
75 
76 	ret = sof_nocodec_bes_setup(dev, ops, links, ops->num_drv,
77 				    &sof_nocodec_card);
78 	return ret;
79 }
80 EXPORT_SYMBOL(sof_nocodec_setup);
81 
82 static int sof_nocodec_probe(struct platform_device *pdev)
83 {
84 	struct snd_soc_card *card = &sof_nocodec_card;
85 
86 	card->dev = &pdev->dev;
87 
88 	return devm_snd_soc_register_card(&pdev->dev, card);
89 }
90 
91 static int sof_nocodec_remove(struct platform_device *pdev)
92 {
93 	return 0;
94 }
95 
96 static struct platform_driver sof_nocodec_audio = {
97 	.probe = sof_nocodec_probe,
98 	.remove = sof_nocodec_remove,
99 	.driver = {
100 		.name = "sof-nocodec",
101 		.pm = &snd_soc_pm_ops,
102 	},
103 };
104 module_platform_driver(sof_nocodec_audio)
105 
106 MODULE_DESCRIPTION("ASoC sof nocodec");
107 MODULE_AUTHOR("Liam Girdwood");
108 MODULE_LICENSE("Dual BSD/GPL");
109 MODULE_ALIAS("platform:sof-nocodec");
110