xref: /linux/sound/soc/intel/avs/boards/probe.c (revision 05a54fa773284d1a7923cdfdd8f0c8dabb98bd26)
1 // SPDX-License-Identifier: GPL-2.0-only
2 //
3 // Copyright(c) 2021-2022 Intel Corporation
4 //
5 // Authors: Cezary Rojewski <cezary.rojewski@intel.com>
6 //          Amadeusz Slawinski <amadeuszx.slawinski@linux.intel.com>
7 //
8 
9 #include <linux/device.h>
10 #include <linux/module.h>
11 #include <sound/soc.h>
12 
13 static int avs_create_dai_links(struct device *dev, struct snd_soc_dai_link **links, int *num_links)
14 {
15 	struct snd_soc_dai_link *dl;
16 
17 	dl = devm_kzalloc(dev, sizeof(*dl), GFP_KERNEL);
18 	if (!dl)
19 		return -ENOMEM;
20 
21 	dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL);
22 	dl->platforms = devm_kzalloc(dev, sizeof(*dl->platforms), GFP_KERNEL);
23 	if (!dl->cpus || !dl->platforms)
24 		return -ENOMEM;
25 
26 	dl->name = "Compress Probe Capture";
27 	dl->cpus->dai_name = "Probe Extraction CPU DAI";
28 	dl->num_cpus = 1;
29 	dl->codecs = &snd_soc_dummy_dlc;
30 	dl->num_codecs = 1;
31 	dl->platforms->name = dev_name(dev);
32 	dl->num_platforms = 1;
33 	dl->nonatomic = 1;
34 
35 	*links = dl;
36 	*num_links = 1;
37 	return 0;
38 }
39 
40 static int avs_probe_mb_probe(struct platform_device *pdev)
41 {
42 	struct device *dev = &pdev->dev;
43 	struct snd_soc_card *card;
44 	int ret;
45 
46 	card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
47 	if (!card)
48 		return -ENOMEM;
49 
50 	ret = avs_create_dai_links(dev, &card->dai_link, &card->num_links);
51 	if (ret)
52 		return ret;
53 
54 	card->driver_name = "avs_probe_mb";
55 	card->long_name = card->name = "AVS PROBE";
56 	card->dev = dev;
57 	card->owner = THIS_MODULE;
58 	card->fully_routed = true;
59 
60 	return devm_snd_soc_register_deferrable_card(dev, card);
61 }
62 
63 static const struct platform_device_id avs_probe_mb_driver_ids[] = {
64 	{
65 		.name = "avs_probe_mb",
66 	},
67 	{},
68 };
69 MODULE_DEVICE_TABLE(platform, avs_probe_mb_driver_ids);
70 
71 static struct platform_driver avs_probe_mb_driver = {
72 	.probe = avs_probe_mb_probe,
73 	.driver = {
74 		.name = "avs_probe_mb",
75 		.pm = &snd_soc_pm_ops,
76 	},
77 	.id_table = avs_probe_mb_driver_ids,
78 };
79 
80 module_platform_driver(avs_probe_mb_driver);
81 
82 MODULE_DESCRIPTION("Intel probe machine driver");
83 MODULE_LICENSE("GPL");
84