]> git.karo-electronics.de Git - karo-tx-linux.git/blob - sound/soc/imx/imx-spdif.c
885d8d58aee88373ceaea8fa0a29b1dfadf54812
[karo-tx-linux.git] / sound / soc / imx / imx-spdif.c
1 /*
2  * ASoC S/PDIF driver for IMX development boards
3  *
4  * Copyright (C) 2008-2011 Freescale Semiconductor, Inc.
5  *
6  * based on stmp3780_devb_spdif.c
7  *
8  * Vladimir Barinov <vbarinov@embeddedalley.com>
9  *
10  * Copyright 2008 SigmaTel, Inc
11  * Copyright 2008 Embedded Alley Solutions, Inc
12  *
13  * This file is licensed under the terms of the GNU General Public License
14  * version 2.  This program  is licensed "as is" without any warranty of any
15  * kind, whether express or implied.
16  */
17 #include <linux/module.h>
18 #include <linux/moduleparam.h>
19 #include <linux/timer.h>
20 #include <linux/interrupt.h>
21 #include <linux/platform_device.h>
22 #include <linux/slab.h>
23
24 #include <sound/core.h>
25 #include <sound/pcm.h>
26 #include <sound/soc.h>
27 #include <sound/soc-dapm.h>
28
29 #include <asm/mach-types.h>
30 #include <asm/dma.h>
31 #include <mach/hardware.h>
32
33 #include "imx-ssi.h"
34 #include "../codecs/mxc_spdif.h"
35
36 /* imx digital audio interface glue - connects codec <--> CPU */
37 static struct snd_soc_dai_link imx_spdif_dai_link = {
38         .name = "IMX SPDIF",
39         .stream_name = "IMX SPDIF",
40         .codec_dai_name = "mxc-spdif",
41         .codec_name = "mxc_spdif.0",
42         .cpu_dai_name = "imx-spdif-dai.0",
43         .platform_name = "imx-pcm-audio.2", /* imx-pcm-dma-mx2 */
44 };
45
46 static struct snd_soc_card snd_soc_card_imx_spdif = {
47         .name = "imx-spdif",
48         .dai_link = &imx_spdif_dai_link,
49         .num_links = 1,
50 };
51
52 static int __devinit imx_spdif_audio_probe(struct platform_device *pdev)
53 {
54         struct imx_ssi *ssi;
55         int ret;
56
57         ssi = kzalloc(sizeof(*ssi), GFP_KERNEL);
58         if (!ssi)
59                 return -ENOMEM;
60
61         dev_set_drvdata(&pdev->dev, ssi);
62
63         ssi->soc_platform_pdev = platform_device_alloc("imx-pcm-audio", 2);
64         if (!ssi->soc_platform_pdev) {
65                 pr_err("%s failed platform_device_alloc\n", __func__);
66                 return -ENOMEM;
67         }
68
69         /* It may seem weird to be using struct imx_ssi here because S/PDIF
70            doesn't use ssi.  We only use soc_platform_pdev in struct imx_ssi.
71            But we need it because imx-pcm-dma-mx2 initializes other fields. */
72         platform_set_drvdata(ssi->soc_platform_pdev, ssi);
73
74         ret = platform_device_add(ssi->soc_platform_pdev);
75         if (ret) {
76                 dev_err(&pdev->dev, "failed to add platform device\n");
77                 platform_device_put(ssi->soc_platform_pdev);
78                 return ret;
79         }
80
81         return 0;
82 }
83
84 static int __devexit imx_spdif_audio_remove(struct platform_device *pdev)
85 {
86         struct imx_ssi *ssi = platform_get_drvdata(pdev);
87
88         platform_device_unregister(ssi->soc_platform_pdev);
89         snd_soc_unregister_dai(&pdev->dev);
90         kfree(ssi);
91
92         return 0;
93 }
94
95 static struct platform_driver imx_spdif_audio_driver = {
96         .probe = imx_spdif_audio_probe,
97         .remove = __devexit_p(imx_spdif_audio_remove),
98         .driver = {
99                    .name = "imx-spdif-audio-device",
100                    .owner = THIS_MODULE,
101                    },
102 };
103
104 static struct platform_device *imx_spdif_snd_device;
105
106 static int __init imx_spdif_init(void)
107 {
108         int ret = 0;
109
110         ret = platform_driver_register(&imx_spdif_audio_driver);
111         if (ret) {
112                 pr_err("%s - failed platform_driver_register\n", __func__);
113                 return -ENOMEM;
114         }
115
116         imx_spdif_snd_device = platform_device_alloc("soc-audio", -1);
117         if (!imx_spdif_snd_device) {
118                 pr_err("%s - failed platform_device_alloc\n", __func__);
119                 return -ENOMEM;
120         }
121
122         platform_set_drvdata(imx_spdif_snd_device, &snd_soc_card_imx_spdif);
123
124         ret = platform_device_add(imx_spdif_snd_device);
125         if (ret) {
126                 pr_err("ASoC S/PDIF: Platform device allocation failed\n");
127                 platform_device_put(imx_spdif_snd_device);
128         }
129
130         return ret;
131 }
132
133 static void __exit imx_spdif_exit(void)
134 {
135         platform_driver_unregister(&imx_spdif_audio_driver);
136         platform_device_unregister(imx_spdif_snd_device);
137 }
138
139 module_init(imx_spdif_init);
140 module_exit(imx_spdif_exit);
141
142 MODULE_AUTHOR("Freescale Semiconductor, Inc.");
143 MODULE_DESCRIPTION("IMX EVK development board ASoC driver");
144 MODULE_LICENSE("GPL");