xref: /openbmc/linux/sound/soc/fsl/imx-spdif.c (revision 66c98360)
1 // SPDX-License-Identifier: GPL-2.0+
2 //
3 // Copyright (C) 2013 Freescale Semiconductor, Inc.
4 
5 #include <linux/module.h>
6 #include <linux/of_platform.h>
7 #include <sound/soc.h>
8 
9 struct imx_spdif_data {
10 	struct snd_soc_dai_link dai;
11 	struct snd_soc_card card;
12 };
13 
14 static int imx_spdif_audio_probe(struct platform_device *pdev)
15 {
16 	struct device_node *spdif_np, *np = pdev->dev.of_node;
17 	struct imx_spdif_data *data;
18 	struct snd_soc_dai_link_component *comp;
19 	int ret = 0;
20 
21 	spdif_np = of_parse_phandle(np, "spdif-controller", 0);
22 	if (!spdif_np) {
23 		dev_err(&pdev->dev, "failed to find spdif-controller\n");
24 		ret = -EINVAL;
25 		goto end;
26 	}
27 
28 	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
29 	comp = devm_kzalloc(&pdev->dev, 2 * sizeof(*comp), GFP_KERNEL);
30 	if (!data || !comp) {
31 		ret = -ENOMEM;
32 		goto end;
33 	}
34 
35 	/*
36 	 * CPU == Platform
37 	 * platform is using soc-generic-dmaengine-pcm
38 	 */
39 	data->dai.cpus		=
40 	data->dai.platforms	= &comp[0];
41 	data->dai.codecs	= &comp[1];
42 
43 	data->dai.num_cpus	= 1;
44 	data->dai.num_codecs	= 1;
45 	data->dai.num_platforms	= 1;
46 
47 	data->dai.name = "S/PDIF PCM";
48 	data->dai.stream_name = "S/PDIF PCM";
49 	data->dai.codecs->dai_name = "snd-soc-dummy-dai";
50 	data->dai.codecs->name = "snd-soc-dummy";
51 	data->dai.cpus->of_node = spdif_np;
52 	data->dai.playback_only = true;
53 	data->dai.capture_only = true;
54 
55 	if (of_property_read_bool(np, "spdif-out"))
56 		data->dai.capture_only = false;
57 
58 	if (of_property_read_bool(np, "spdif-in"))
59 		data->dai.playback_only = false;
60 
61 	if (data->dai.playback_only && data->dai.capture_only) {
62 		dev_err(&pdev->dev, "no enabled S/PDIF DAI link\n");
63 		goto end;
64 	}
65 
66 	data->card.dev = &pdev->dev;
67 	data->card.dai_link = &data->dai;
68 	data->card.num_links = 1;
69 	data->card.owner = THIS_MODULE;
70 
71 	ret = snd_soc_of_parse_card_name(&data->card, "model");
72 	if (ret)
73 		goto end;
74 
75 	ret = devm_snd_soc_register_card(&pdev->dev, &data->card);
76 	if (ret)
77 		dev_err_probe(&pdev->dev, ret, "snd_soc_register_card failed\n");
78 
79 end:
80 	of_node_put(spdif_np);
81 
82 	return ret;
83 }
84 
85 static const struct of_device_id imx_spdif_dt_ids[] = {
86 	{ .compatible = "fsl,imx-audio-spdif", },
87 	{ /* sentinel */ }
88 };
89 MODULE_DEVICE_TABLE(of, imx_spdif_dt_ids);
90 
91 static struct platform_driver imx_spdif_driver = {
92 	.driver = {
93 		.name = "imx-spdif",
94 		.pm = &snd_soc_pm_ops,
95 		.of_match_table = imx_spdif_dt_ids,
96 	},
97 	.probe = imx_spdif_audio_probe,
98 };
99 
100 module_platform_driver(imx_spdif_driver);
101 
102 MODULE_AUTHOR("Freescale Semiconductor, Inc.");
103 MODULE_DESCRIPTION("Freescale i.MX S/PDIF machine driver");
104 MODULE_LICENSE("GPL v2");
105 MODULE_ALIAS("platform:imx-spdif");
106