Commit | Line | Data |
---|---|---|
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 | ||
9 | struct imx_spdif_data { | |
14c3aa98 | 10 | struct snd_soc_dai_link dai; |
2a956ec0 | 11 | struct snd_soc_card card; |
2a956ec0 NC |
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; | |
8337ef4f | 18 | struct snd_soc_dai_link_component *comp; |
14c3aa98 | 19 | int ret = 0; |
2a956ec0 NC |
20 | |
21 | spdif_np = of_parse_phandle(np, "spdif-controller", 0); | |
22 | if (!spdif_np) { | |
23 | dev_err(&pdev->dev, "failed to find spdif-controller\n"); | |
24 | ret = -EINVAL; | |
25 | goto end; | |
26 | } | |
27 | ||
28 | data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); | |
9e8f5299 | 29 | comp = devm_kzalloc(&pdev->dev, 3 * sizeof(*comp), GFP_KERNEL); |
8337ef4f | 30 | if (!data || !comp) { |
2a956ec0 NC |
31 | ret = -ENOMEM; |
32 | goto end; | |
33 | } | |
34 | ||
8337ef4f KM |
35 | data->dai.cpus = &comp[0]; |
36 | data->dai.codecs = &comp[1]; | |
9e8f5299 | 37 | data->dai.platforms = &comp[2]; |
8337ef4f KM |
38 | |
39 | data->dai.num_cpus = 1; | |
40 | data->dai.num_codecs = 1; | |
9e8f5299 | 41 | data->dai.num_platforms = 1; |
8337ef4f | 42 | |
14c3aa98 NC |
43 | data->dai.name = "S/PDIF PCM"; |
44 | data->dai.stream_name = "S/PDIF PCM"; | |
8337ef4f KM |
45 | data->dai.codecs->dai_name = "snd-soc-dummy-dai"; |
46 | data->dai.codecs->name = "snd-soc-dummy"; | |
47 | data->dai.cpus->of_node = spdif_np; | |
9e8f5299 | 48 | data->dai.platforms->of_node = spdif_np; |
14c3aa98 NC |
49 | data->dai.playback_only = true; |
50 | data->dai.capture_only = true; | |
2a956ec0 | 51 | |
14c3aa98 NC |
52 | if (of_property_read_bool(np, "spdif-out")) |
53 | data->dai.capture_only = false; | |
54 | ||
55 | if (of_property_read_bool(np, "spdif-in")) | |
56 | data->dai.playback_only = false; | |
2a956ec0 | 57 | |
14c3aa98 | 58 | if (data->dai.playback_only && data->dai.capture_only) { |
2a956ec0 | 59 | dev_err(&pdev->dev, "no enabled S/PDIF DAI link\n"); |
14c3aa98 | 60 | goto end; |
2a956ec0 NC |
61 | } |
62 | ||
63 | data->card.dev = &pdev->dev; | |
14c3aa98 NC |
64 | data->card.dai_link = &data->dai; |
65 | data->card.num_links = 1; | |
7a3a9070 | 66 | data->card.owner = THIS_MODULE; |
2a956ec0 NC |
67 | |
68 | ret = snd_soc_of_parse_card_name(&data->card, "model"); | |
69 | if (ret) | |
14c3aa98 | 70 | goto end; |
2a956ec0 | 71 | |
ff27d9b3 | 72 | ret = devm_snd_soc_register_card(&pdev->dev, &data->card); |
2363d85f | 73 | if (ret && ret != -EPROBE_DEFER) |
2a956ec0 | 74 | dev_err(&pdev->dev, "snd_soc_register_card failed: %d\n", ret); |
2a956ec0 | 75 | |
2a956ec0 | 76 | end: |
aa4ac920 | 77 | of_node_put(spdif_np); |
2a956ec0 NC |
78 | |
79 | return ret; | |
80 | } | |
81 | ||
2a956ec0 NC |
82 | static const struct of_device_id imx_spdif_dt_ids[] = { |
83 | { .compatible = "fsl,imx-audio-spdif", }, | |
84 | { /* sentinel */ } | |
85 | }; | |
86 | MODULE_DEVICE_TABLE(of, imx_spdif_dt_ids); | |
87 | ||
88 | static struct platform_driver imx_spdif_driver = { | |
89 | .driver = { | |
90 | .name = "imx-spdif", | |
43ac9469 | 91 | .pm = &snd_soc_pm_ops, |
2a956ec0 NC |
92 | .of_match_table = imx_spdif_dt_ids, |
93 | }, | |
94 | .probe = imx_spdif_audio_probe, | |
2a956ec0 NC |
95 | }; |
96 | ||
97 | module_platform_driver(imx_spdif_driver); | |
98 | ||
99 | MODULE_AUTHOR("Freescale Semiconductor, Inc."); | |
100 | MODULE_DESCRIPTION("Freescale i.MX S/PDIF machine driver"); | |
101 | MODULE_LICENSE("GPL v2"); | |
102 | MODULE_ALIAS("platform:imx-spdif"); |