blob: 4446fba755b9afbac7b8a1cc254a65e54419aa7a [file] [log] [blame]
Andra Danciu58dbd102019-04-05 14:49:59 +03001// SPDX-License-Identifier: GPL-2.0+
2//
3// Copyright (C) 2013 Freescale Semiconductor, Inc.
Nicolin Chen2a956ec2013-08-28 12:04:46 +08004
5#include <linux/module.h>
6#include <linux/of_platform.h>
7#include <sound/soc.h>
8
9struct imx_spdif_data {
Nicolin Chen14c3aa92013-12-23 17:28:53 +080010 struct snd_soc_dai_link dai;
Nicolin Chen2a956ec2013-08-28 12:04:46 +080011 struct snd_soc_card card;
Nicolin Chen2a956ec2013-08-28 12:04:46 +080012};
13
14static 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;
Kuninori Morimoto8337ef42019-06-06 13:14:38 +090018 struct snd_soc_dai_link_component *comp;
Nicolin Chen14c3aa92013-12-23 17:28:53 +080019 int ret = 0;
Nicolin Chen2a956ec2013-08-28 12:04:46 +080020
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);
Kuninori Morimoto9e8f5292019-06-28 10:47:30 +090029 comp = devm_kzalloc(&pdev->dev, 3 * sizeof(*comp), GFP_KERNEL);
Kuninori Morimoto8337ef42019-06-06 13:14:38 +090030 if (!data || !comp) {
Nicolin Chen2a956ec2013-08-28 12:04:46 +080031 ret = -ENOMEM;
32 goto end;
33 }
34
Kuninori Morimoto8337ef42019-06-06 13:14:38 +090035 data->dai.cpus = &comp[0];
36 data->dai.codecs = &comp[1];
Kuninori Morimoto9e8f5292019-06-28 10:47:30 +090037 data->dai.platforms = &comp[2];
Kuninori Morimoto8337ef42019-06-06 13:14:38 +090038
39 data->dai.num_cpus = 1;
40 data->dai.num_codecs = 1;
Kuninori Morimoto9e8f5292019-06-28 10:47:30 +090041 data->dai.num_platforms = 1;
Kuninori Morimoto8337ef42019-06-06 13:14:38 +090042
Nicolin Chen14c3aa92013-12-23 17:28:53 +080043 data->dai.name = "S/PDIF PCM";
44 data->dai.stream_name = "S/PDIF PCM";
Kuninori Morimoto8337ef42019-06-06 13:14:38 +090045 data->dai.codecs->dai_name = "snd-soc-dummy-dai";
46 data->dai.codecs->name = "snd-soc-dummy";
47 data->dai.cpus->of_node = spdif_np;
Kuninori Morimoto9e8f5292019-06-28 10:47:30 +090048 data->dai.platforms->of_node = spdif_np;
Nicolin Chen14c3aa92013-12-23 17:28:53 +080049 data->dai.playback_only = true;
50 data->dai.capture_only = true;
Nicolin Chen2a956ec2013-08-28 12:04:46 +080051
Nicolin Chen14c3aa92013-12-23 17:28:53 +080052 if (of_property_read_bool(np, "spdif-out"))
53 data->dai.capture_only = false;
Nicolin Chen2a956ec2013-08-28 12:04:46 +080054
Nicolin Chen14c3aa92013-12-23 17:28:53 +080055 if (of_property_read_bool(np, "spdif-in"))
56 data->dai.playback_only = false;
Nicolin Chen2a956ec2013-08-28 12:04:46 +080057
Nicolin Chen14c3aa92013-12-23 17:28:53 +080058 if (data->dai.playback_only && data->dai.capture_only) {
Nicolin Chen2a956ec2013-08-28 12:04:46 +080059 dev_err(&pdev->dev, "no enabled S/PDIF DAI link\n");
Nicolin Chen14c3aa92013-12-23 17:28:53 +080060 goto end;
Nicolin Chen2a956ec2013-08-28 12:04:46 +080061 }
62
63 data->card.dev = &pdev->dev;
Nicolin Chen14c3aa92013-12-23 17:28:53 +080064 data->card.dai_link = &data->dai;
65 data->card.num_links = 1;
Fabio Estevam7a3a9072015-01-14 16:39:15 -020066 data->card.owner = THIS_MODULE;
Nicolin Chen2a956ec2013-08-28 12:04:46 +080067
68 ret = snd_soc_of_parse_card_name(&data->card, "model");
69 if (ret)
Nicolin Chen14c3aa92013-12-23 17:28:53 +080070 goto end;
Nicolin Chen2a956ec2013-08-28 12:04:46 +080071
Sachin Kamatff27d9b2013-09-17 09:42:47 +053072 ret = devm_snd_soc_register_card(&pdev->dev, &data->card);
Kuninori Morimoto2e6f5572021-12-14 11:08:34 +090073 if (ret)
74 dev_err_probe(&pdev->dev, ret, "snd_soc_register_card failed\n");
Nicolin Chen2a956ec2013-08-28 12:04:46 +080075
Nicolin Chen2a956ec2013-08-28 12:04:46 +080076end:
Fabio Estevamaa4ac922014-10-07 15:29:56 -030077 of_node_put(spdif_np);
Nicolin Chen2a956ec2013-08-28 12:04:46 +080078
79 return ret;
80}
81
Nicolin Chen2a956ec2013-08-28 12:04:46 +080082static const struct of_device_id imx_spdif_dt_ids[] = {
83 { .compatible = "fsl,imx-audio-spdif", },
84 { /* sentinel */ }
85};
86MODULE_DEVICE_TABLE(of, imx_spdif_dt_ids);
87
88static struct platform_driver imx_spdif_driver = {
89 .driver = {
90 .name = "imx-spdif",
Zidan Wang43ac9462015-09-18 17:18:48 +080091 .pm = &snd_soc_pm_ops,
Nicolin Chen2a956ec2013-08-28 12:04:46 +080092 .of_match_table = imx_spdif_dt_ids,
93 },
94 .probe = imx_spdif_audio_probe,
Nicolin Chen2a956ec2013-08-28 12:04:46 +080095};
96
97module_platform_driver(imx_spdif_driver);
98
99MODULE_AUTHOR("Freescale Semiconductor, Inc.");
100MODULE_DESCRIPTION("Freescale i.MX S/PDIF machine driver");
101MODULE_LICENSE("GPL v2");
102MODULE_ALIAS("platform:imx-spdif");