Merge tag 'for-linus-20190706' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / sound / soc / fsl / imx-spdif.c
blob4f7f210beb18426f62240d544484bb96a7f53f1b
1 // SPDX-License-Identifier: GPL-2.0+
2 //
3 // Copyright (C) 2013 Freescale Semiconductor, Inc.
5 #include <linux/module.h>
6 #include <linux/of_platform.h>
7 #include <sound/soc.h>
9 struct imx_spdif_data {
10 struct snd_soc_dai_link dai;
11 struct snd_soc_card card;
14 static int imx_spdif_audio_probe(struct platform_device *pdev)
16 struct device_node *spdif_np, *np = pdev->dev.of_node;
17 struct imx_spdif_data *data;
18 int ret = 0;
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;
27 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
28 if (!data) {
29 ret = -ENOMEM;
30 goto end;
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;
42 if (of_property_read_bool(np, "spdif-out"))
43 data->dai.capture_only = false;
45 if (of_property_read_bool(np, "spdif-in"))
46 data->dai.playback_only = false;
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;
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;
58 ret = snd_soc_of_parse_card_name(&data->card, "model");
59 if (ret)
60 goto end;
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);
66 end:
67 of_node_put(spdif_np);
69 return ret;
72 static const struct of_device_id imx_spdif_dt_ids[] = {
73 { .compatible = "fsl,imx-audio-spdif", },
74 { /* sentinel */ }
76 MODULE_DEVICE_TABLE(of, imx_spdif_dt_ids);
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,
84 .probe = imx_spdif_audio_probe,
87 module_platform_driver(imx_spdif_driver);
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");