Merge tag 'for-5.2/block-post-20190516' of git://git.kernel.dk/linux-block
[linux-2.6-block.git] / sound / soc / fsl / imx-spdif.c
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         int ret = 0;
19
20         spdif_np = of_parse_phandle(np, "spdif-controller", 0);
21         if (!spdif_np) {
22                 dev_err(&pdev->dev, "failed to find spdif-controller\n");
23                 ret = -EINVAL;
24                 goto end;
25         }
26
27         data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
28         if (!data) {
29                 ret = -ENOMEM;
30                 goto end;
31         }
32
33         data->dai.name = "S/PDIF PCM";
34         data->dai.stream_name = "S/PDIF PCM";
35         data->dai.codec_dai_name = "snd-soc-dummy-dai";
36         data->dai.codec_name = "snd-soc-dummy";
37         data->dai.cpu_of_node = spdif_np;
38         data->dai.platform_of_node = spdif_np;
39         data->dai.playback_only = true;
40         data->dai.capture_only = true;
41
42         if (of_property_read_bool(np, "spdif-out"))
43                 data->dai.capture_only = false;
44
45         if (of_property_read_bool(np, "spdif-in"))
46                 data->dai.playback_only = false;
47
48         if (data->dai.playback_only && data->dai.capture_only) {
49                 dev_err(&pdev->dev, "no enabled S/PDIF DAI link\n");
50                 goto end;
51         }
52
53         data->card.dev = &pdev->dev;
54         data->card.dai_link = &data->dai;
55         data->card.num_links = 1;
56         data->card.owner = THIS_MODULE;
57
58         ret = snd_soc_of_parse_card_name(&data->card, "model");
59         if (ret)
60                 goto end;
61
62         ret = devm_snd_soc_register_card(&pdev->dev, &data->card);
63         if (ret && ret != -EPROBE_DEFER)
64                 dev_err(&pdev->dev, "snd_soc_register_card failed: %d\n", ret);
65
66 end:
67         of_node_put(spdif_np);
68
69         return ret;
70 }
71
72 static const struct of_device_id imx_spdif_dt_ids[] = {
73         { .compatible = "fsl,imx-audio-spdif", },
74         { /* sentinel */ }
75 };
76 MODULE_DEVICE_TABLE(of, imx_spdif_dt_ids);
77
78 static struct platform_driver imx_spdif_driver = {
79         .driver = {
80                 .name = "imx-spdif",
81                 .pm = &snd_soc_pm_ops,
82                 .of_match_table = imx_spdif_dt_ids,
83         },
84         .probe = imx_spdif_audio_probe,
85 };
86
87 module_platform_driver(imx_spdif_driver);
88
89 MODULE_AUTHOR("Freescale Semiconductor, Inc.");
90 MODULE_DESCRIPTION("Freescale i.MX S/PDIF machine driver");
91 MODULE_LICENSE("GPL v2");
92 MODULE_ALIAS("platform:imx-spdif");