]> Pileus Git - ~andy/linux/blob - sound/soc/fsl/imx-spdif.c
ASoC: fsl_ssi: Add DAI master mode support for SSI on i.MX series
[~andy/linux] / sound / soc / fsl / imx-spdif.c
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
16 struct imx_spdif_data {
17         struct snd_soc_dai_link dai[2];
18         struct snd_soc_card card;
19         struct platform_device *txdev;
20         struct platform_device *rxdev;
21 };
22
23 static int imx_spdif_audio_probe(struct platform_device *pdev)
24 {
25         struct device_node *spdif_np, *np = pdev->dev.of_node;
26         struct imx_spdif_data *data;
27         int ret = 0, num_links = 0;
28
29         spdif_np = of_parse_phandle(np, "spdif-controller", 0);
30         if (!spdif_np) {
31                 dev_err(&pdev->dev, "failed to find spdif-controller\n");
32                 ret = -EINVAL;
33                 goto end;
34         }
35
36         data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
37         if (!data) {
38                 ret = -ENOMEM;
39                 goto end;
40         }
41
42         if (of_property_read_bool(np, "spdif-out")) {
43                 data->dai[num_links].name = "S/PDIF TX";
44                 data->dai[num_links].stream_name = "S/PDIF PCM Playback";
45                 data->dai[num_links].codec_dai_name = "dit-hifi";
46                 data->dai[num_links].codec_name = "spdif-dit";
47                 data->dai[num_links].cpu_of_node = spdif_np;
48                 data->dai[num_links].platform_of_node = spdif_np;
49                 num_links++;
50
51                 data->txdev = platform_device_register_simple("spdif-dit", -1, NULL, 0);
52                 if (IS_ERR(data->txdev)) {
53                         ret = PTR_ERR(data->txdev);
54                         dev_err(&pdev->dev, "register dit failed: %d\n", ret);
55                         goto end;
56                 }
57         }
58
59         if (of_property_read_bool(np, "spdif-in")) {
60                 data->dai[num_links].name = "S/PDIF RX";
61                 data->dai[num_links].stream_name = "S/PDIF PCM Capture";
62                 data->dai[num_links].codec_dai_name = "dir-hifi";
63                 data->dai[num_links].codec_name = "spdif-dir";
64                 data->dai[num_links].cpu_of_node = spdif_np;
65                 data->dai[num_links].platform_of_node = spdif_np;
66                 num_links++;
67
68                 data->rxdev = platform_device_register_simple("spdif-dir", -1, NULL, 0);
69                 if (IS_ERR(data->rxdev)) {
70                         ret = PTR_ERR(data->rxdev);
71                         dev_err(&pdev->dev, "register dir failed: %d\n", ret);
72                         goto error_dit;
73                 }
74         }
75
76         if (!num_links) {
77                 dev_err(&pdev->dev, "no enabled S/PDIF DAI link\n");
78                 goto error_dir;
79         }
80
81         data->card.dev = &pdev->dev;
82         data->card.num_links = num_links;
83         data->card.dai_link = data->dai;
84
85         ret = snd_soc_of_parse_card_name(&data->card, "model");
86         if (ret)
87                 goto error_dir;
88
89         ret = devm_snd_soc_register_card(&pdev->dev, &data->card);
90         if (ret) {
91                 dev_err(&pdev->dev, "snd_soc_register_card failed: %d\n", ret);
92                 goto error_dir;
93         }
94
95         platform_set_drvdata(pdev, data);
96
97         goto end;
98
99 error_dir:
100         if (data->rxdev)
101                 platform_device_unregister(data->rxdev);
102 error_dit:
103         if (data->txdev)
104                 platform_device_unregister(data->txdev);
105 end:
106         if (spdif_np)
107                 of_node_put(spdif_np);
108
109         return ret;
110 }
111
112 static int imx_spdif_audio_remove(struct platform_device *pdev)
113 {
114         struct imx_spdif_data *data = platform_get_drvdata(pdev);
115
116         if (data->rxdev)
117                 platform_device_unregister(data->rxdev);
118         if (data->txdev)
119                 platform_device_unregister(data->txdev);
120
121         return 0;
122 }
123
124 static const struct of_device_id imx_spdif_dt_ids[] = {
125         { .compatible = "fsl,imx-audio-spdif", },
126         { /* sentinel */ }
127 };
128 MODULE_DEVICE_TABLE(of, imx_spdif_dt_ids);
129
130 static struct platform_driver imx_spdif_driver = {
131         .driver = {
132                 .name = "imx-spdif",
133                 .owner = THIS_MODULE,
134                 .of_match_table = imx_spdif_dt_ids,
135         },
136         .probe = imx_spdif_audio_probe,
137         .remove = imx_spdif_audio_remove,
138 };
139
140 module_platform_driver(imx_spdif_driver);
141
142 MODULE_AUTHOR("Freescale Semiconductor, Inc.");
143 MODULE_DESCRIPTION("Freescale i.MX S/PDIF machine driver");
144 MODULE_LICENSE("GPL v2");
145 MODULE_ALIAS("platform:imx-spdif");