Merge tag 'strlcpy-removal-v6.8-rc1' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-block.git] / sound / soc / sof / nocodec.c
CommitLineData
e149ca29 1// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
8017b8fd
LG
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>
f805e7e0 13#include "sof-audio.h"
8017b8fd
LG
14#include "sof-priv.h"
15
16static struct snd_soc_card sof_nocodec_card = {
17 .name = "nocodec", /* the sof- prefix is added by the core */
f805e7e0 18 .topology_shortname = "sof-nocodec",
8753889e 19 .owner = THIS_MODULE
8017b8fd
LG
20};
21
22static int sof_nocodec_bes_setup(struct device *dev,
4c1cc83f 23 struct snd_soc_dai_driver *drv,
8017b8fd 24 struct snd_soc_dai_link *links,
4c1cc83f 25 int link_num, struct snd_soc_card *card)
8017b8fd 26{
7ba06110 27 struct snd_soc_dai_link_component *dlc;
8017b8fd
LG
28 int i;
29
4c1cc83f 30 if (!drv || !links || !card)
8017b8fd
LG
31 return -EINVAL;
32
33 /* set up BE dai_links */
34 for (i = 0; i < link_num; i++) {
91cd742b 35 dlc = devm_kcalloc(dev, 2, sizeof(*dlc), GFP_KERNEL);
7ba06110
KM
36 if (!dlc)
37 return -ENOMEM;
38
8017b8fd
LG
39 links[i].name = devm_kasprintf(dev, GFP_KERNEL,
40 "NoCodec-%d", i);
41 if (!links[i].name)
42 return -ENOMEM;
43
f805e7e0
RS
44 links[i].stream_name = links[i].name;
45
7ba06110 46 links[i].cpus = &dlc[0];
4d5f4119 47 links[i].codecs = &snd_soc_dummy_dlc;
91cd742b 48 links[i].platforms = &dlc[1];
7ba06110
KM
49
50 links[i].num_cpus = 1;
51 links[i].num_codecs = 1;
52 links[i].num_platforms = 1;
53
8017b8fd
LG
54 links[i].id = i;
55 links[i].no_pcm = 1;
4c1cc83f
PLB
56 links[i].cpus->dai_name = drv[i].name;
57 links[i].platforms->name = dev_name(dev->parent);
4c1cc83f 58 if (drv[i].playback.channels_min)
ba4e5abc 59 links[i].dpcm_playback = 1;
4c1cc83f 60 if (drv[i].capture.channels_min)
ba4e5abc 61 links[i].dpcm_capture = 1;
f805e7e0 62
4c1cc83f 63 links[i].be_hw_params_fixup = sof_pcm_dai_link_fixup;
8017b8fd
LG
64 }
65
66 card->dai_link = links;
67 card->num_links = link_num;
68
69 return 0;
70}
71
4c1cc83f
PLB
72static int sof_nocodec_setup(struct device *dev,
73 u32 num_dai_drivers,
74 struct snd_soc_dai_driver *dai_drivers)
8017b8fd
LG
75{
76 struct snd_soc_dai_link *links;
8017b8fd 77
8017b8fd 78 /* create dummy BE dai_links */
7b88552c 79 links = devm_kcalloc(dev, num_dai_drivers, sizeof(struct snd_soc_dai_link), GFP_KERNEL);
8017b8fd
LG
80 if (!links)
81 return -ENOMEM;
82
4c1cc83f 83 return sof_nocodec_bes_setup(dev, dai_drivers, links, num_dai_drivers, &sof_nocodec_card);
8017b8fd 84}
8017b8fd
LG
85
86static int sof_nocodec_probe(struct platform_device *pdev)
87{
88 struct snd_soc_card *card = &sof_nocodec_card;
4c1cc83f
PLB
89 struct snd_soc_acpi_mach *mach;
90 int ret;
8017b8fd
LG
91
92 card->dev = &pdev->dev;
f805e7e0 93 card->topology_shortname_created = true;
4c1cc83f
PLB
94 mach = pdev->dev.platform_data;
95
96 ret = sof_nocodec_setup(card->dev, mach->mach_params.num_dai_drivers,
97 mach->mach_params.dai_drivers);
98 if (ret < 0)
99 return ret;
8017b8fd
LG
100
101 return devm_snd_soc_register_card(&pdev->dev, card);
102}
103
8017b8fd
LG
104static struct platform_driver sof_nocodec_audio = {
105 .probe = sof_nocodec_probe,
8017b8fd
LG
106 .driver = {
107 .name = "sof-nocodec",
108 .pm = &snd_soc_pm_ops,
109 },
110};
111module_platform_driver(sof_nocodec_audio)
112
113MODULE_DESCRIPTION("ASoC sof nocodec");
114MODULE_AUTHOR("Liam Girdwood");
115MODULE_LICENSE("Dual BSD/GPL");
116MODULE_ALIAS("platform:sof-nocodec");