Merge tag 'linux-kselftest-5.2-rc1-2' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-block.git] / sound / soc / fsl / imx-spdif.c
CommitLineData
58dbd101
AD
1// SPDX-License-Identifier: GPL-2.0+
2//
3// Copyright (C) 2013 Freescale Semiconductor, Inc.
2a956ec0
NC
4
5#include <linux/module.h>
6#include <linux/of_platform.h>
7#include <sound/soc.h>
8
9struct imx_spdif_data {
14c3aa98 10 struct snd_soc_dai_link dai;
2a956ec0 11 struct snd_soc_card card;
2a956ec0
NC
12};
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;
14c3aa98 18 int ret = 0;
2a956ec0
NC
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) {
2a956ec0
NC
29 ret = -ENOMEM;
30 goto end;
31 }
32
14c3aa98
NC
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;
2a956ec0 41
14c3aa98
NC
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;
2a956ec0 47
14c3aa98 48 if (data->dai.playback_only && data->dai.capture_only) {
2a956ec0 49 dev_err(&pdev->dev, "no enabled S/PDIF DAI link\n");
14c3aa98 50 goto end;
2a956ec0
NC
51 }
52
53 data->card.dev = &pdev->dev;
14c3aa98
NC
54 data->card.dai_link = &data->dai;
55 data->card.num_links = 1;
7a3a9070 56 data->card.owner = THIS_MODULE;
2a956ec0
NC
57
58 ret = snd_soc_of_parse_card_name(&data->card, "model");
59 if (ret)
14c3aa98 60 goto end;
2a956ec0 61
ff27d9b3 62 ret = devm_snd_soc_register_card(&pdev->dev, &data->card);
2363d85f 63 if (ret && ret != -EPROBE_DEFER)
2a956ec0 64 dev_err(&pdev->dev, "snd_soc_register_card failed: %d\n", ret);
2a956ec0 65
2a956ec0 66end:
aa4ac920 67 of_node_put(spdif_np);
2a956ec0
NC
68
69 return ret;
70}
71
2a956ec0
NC
72static const struct of_device_id imx_spdif_dt_ids[] = {
73 { .compatible = "fsl,imx-audio-spdif", },
74 { /* sentinel */ }
75};
76MODULE_DEVICE_TABLE(of, imx_spdif_dt_ids);
77
78static struct platform_driver imx_spdif_driver = {
79 .driver = {
80 .name = "imx-spdif",
43ac9469 81 .pm = &snd_soc_pm_ops,
2a956ec0
NC
82 .of_match_table = imx_spdif_dt_ids,
83 },
84 .probe = imx_spdif_audio_probe,
2a956ec0
NC
85};
86
87module_platform_driver(imx_spdif_driver);
88
89MODULE_AUTHOR("Freescale Semiconductor, Inc.");
90MODULE_DESCRIPTION("Freescale i.MX S/PDIF machine driver");
91MODULE_LICENSE("GPL v2");
92MODULE_ALIAS("platform:imx-spdif");