Merge tag 'ext4_for_linus_stable' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-block.git] / sound / soc / fsl / imx-spdif.c
CommitLineData
2a956ec0
NC
1/*
2 * Copyright (C) 2013 Freescale Semiconductor, Inc.
3 *
4 * The code contained herein is licensed under the GNU General Public
5 * License. You may obtain a copy of the GNU General Public License
6 * Version 2 or later at the following locations:
7 *
8 * http://www.opensource.org/licenses/gpl-license.html
9 * http://www.gnu.org/copyleft/gpl.html
10 */
11
12#include <linux/module.h>
13#include <linux/of_platform.h>
14#include <sound/soc.h>
15
16struct imx_spdif_data {
14c3aa98 17 struct snd_soc_dai_link dai;
2a956ec0 18 struct snd_soc_card card;
2a956ec0
NC
19};
20
21static int imx_spdif_audio_probe(struct platform_device *pdev)
22{
23 struct device_node *spdif_np, *np = pdev->dev.of_node;
24 struct imx_spdif_data *data;
14c3aa98 25 int ret = 0;
2a956ec0
NC
26
27 spdif_np = of_parse_phandle(np, "spdif-controller", 0);
28 if (!spdif_np) {
29 dev_err(&pdev->dev, "failed to find spdif-controller\n");
30 ret = -EINVAL;
31 goto end;
32 }
33
34 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
35 if (!data) {
2a956ec0
NC
36 ret = -ENOMEM;
37 goto end;
38 }
39
14c3aa98
NC
40 data->dai.name = "S/PDIF PCM";
41 data->dai.stream_name = "S/PDIF PCM";
42 data->dai.codec_dai_name = "snd-soc-dummy-dai";
43 data->dai.codec_name = "snd-soc-dummy";
44 data->dai.cpu_of_node = spdif_np;
45 data->dai.platform_of_node = spdif_np;
46 data->dai.playback_only = true;
47 data->dai.capture_only = true;
2a956ec0 48
14c3aa98
NC
49 if (of_property_read_bool(np, "spdif-out"))
50 data->dai.capture_only = false;
51
52 if (of_property_read_bool(np, "spdif-in"))
53 data->dai.playback_only = false;
2a956ec0 54
14c3aa98 55 if (data->dai.playback_only && data->dai.capture_only) {
2a956ec0 56 dev_err(&pdev->dev, "no enabled S/PDIF DAI link\n");
14c3aa98 57 goto end;
2a956ec0
NC
58 }
59
60 data->card.dev = &pdev->dev;
14c3aa98
NC
61 data->card.dai_link = &data->dai;
62 data->card.num_links = 1;
7a3a9070 63 data->card.owner = THIS_MODULE;
2a956ec0
NC
64
65 ret = snd_soc_of_parse_card_name(&data->card, "model");
66 if (ret)
14c3aa98 67 goto end;
2a956ec0 68
ff27d9b3 69 ret = devm_snd_soc_register_card(&pdev->dev, &data->card);
2a956ec0
NC
70 if (ret) {
71 dev_err(&pdev->dev, "snd_soc_register_card failed: %d\n", ret);
14c3aa98 72 goto end;
2a956ec0
NC
73 }
74
2a956ec0 75end:
aa4ac920 76 of_node_put(spdif_np);
2a956ec0
NC
77
78 return ret;
79}
80
2a956ec0
NC
81static const struct of_device_id imx_spdif_dt_ids[] = {
82 { .compatible = "fsl,imx-audio-spdif", },
83 { /* sentinel */ }
84};
85MODULE_DEVICE_TABLE(of, imx_spdif_dt_ids);
86
87static struct platform_driver imx_spdif_driver = {
88 .driver = {
89 .name = "imx-spdif",
43ac9469 90 .pm = &snd_soc_pm_ops,
2a956ec0
NC
91 .of_match_table = imx_spdif_dt_ids,
92 },
93 .probe = imx_spdif_audio_probe,
2a956ec0
NC
94};
95
96module_platform_driver(imx_spdif_driver);
97
98MODULE_AUTHOR("Freescale Semiconductor, Inc.");
99MODULE_DESCRIPTION("Freescale i.MX S/PDIF machine driver");
100MODULE_LICENSE("GPL v2");
101MODULE_ALIAS("platform:imx-spdif");