]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - sound/soc/fsl/imx-hdmi.c
ARM: dts: imx6-tx6*: fix 'flexcan' labels
[karo-tx-linux.git] / sound / soc / fsl / imx-hdmi.c
1 /*
2  * ASoC HDMI Transmitter driver for IMX development boards
3  *
4  * Copyright (C) 2011-2013 Freescale Semiconductor, Inc.
5  *
6  * based on stmp3780_devb_hdmi.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
18 #include <linux/module.h>
19 #include <linux/of_platform.h>
20 #include <linux/mfd/mxc-hdmi-core.h>
21 #include <sound/soc.h>
22
23 #include "imx-hdmi.h"
24
25 /* imx digital audio interface glue - connects codec <--> CPU */
26 static struct snd_soc_dai_link imx_hdmi_dai_link = {
27         .name = "i.MX HDMI Audio Tx",
28         .stream_name = "i.MX HDMI Audio Tx",
29         .codec_dai_name = "hdmi-hifi",
30         .codec_name = "hdmi-audio-codec",
31         .platform_name = "imx-hdmi-audio",
32 };
33
34 static struct snd_soc_card snd_soc_card_imx_hdmi = {
35         .name = "imx-hdmi-soc",
36         .dai_link = &imx_hdmi_dai_link,
37         .num_links = 1,
38 };
39
40 static struct platform_device *codec_dev;
41
42 static int imx_hdmi_audio_probe(struct platform_device *pdev)
43 {
44         struct device_node *hdmi_np, *np = pdev->dev.of_node;
45         struct snd_soc_card *card = &snd_soc_card_imx_hdmi;
46         struct platform_device *hdmi_pdev;
47         int ret = 0;
48
49         if (!hdmi_get_registered()) {
50                 dev_err(&pdev->dev, "initialize HDMI-audio failed. load HDMI-video first!\n");
51                 return -ENODEV;
52         }
53
54         hdmi_np = of_parse_phandle(np, "hdmi-controller", 0);
55         if (!hdmi_np) {
56                 dev_err(&pdev->dev, "failed to find hdmi-audio cpudai\n");
57                 ret = -EINVAL;
58                 goto end;
59         }
60
61         hdmi_pdev = of_find_device_by_node(hdmi_np);
62         if (!hdmi_pdev) {
63                 dev_err(&pdev->dev, "failed to find SSI platform device\n");
64                 ret = -EINVAL;
65                 goto end;
66         }
67
68         codec_dev = platform_device_register_simple("hdmi-audio-codec", -1, NULL, 0);
69         if (IS_ERR(codec_dev)) {
70                 dev_err(&pdev->dev, "failed to register HDMI audio codec\n");
71                 ret = PTR_ERR(codec_dev);
72                 goto end;
73         }
74
75         card->dev = &pdev->dev;
76         card->dai_link->cpu_dai_name = dev_name(&hdmi_pdev->dev);
77
78         ret = snd_soc_register_card(card);
79         if (ret) {
80                 dev_err(&pdev->dev, "failed to register card: %d\n", ret);
81                 goto err_card;
82         }
83
84         goto end;
85
86 err_card:
87         platform_device_unregister(codec_dev);
88 end:
89         if (hdmi_np)
90                 of_node_put(hdmi_np);
91
92         return ret;
93 }
94
95 static int imx_hdmi_audio_remove(struct platform_device *pdev)
96 {
97         struct snd_soc_card *card = &snd_soc_card_imx_hdmi;
98
99         platform_device_unregister(codec_dev);
100         snd_soc_unregister_card(card);
101
102         return 0;
103 }
104
105 static const struct of_device_id imx_hdmi_dt_ids[] = {
106         { .compatible = "fsl,imx-audio-hdmi", },
107         { /* sentinel */ }
108 };
109 MODULE_DEVICE_TABLE(of, imx_hdmi_dt_ids);
110
111 static struct platform_driver imx_hdmi_audio_driver = {
112         .probe = imx_hdmi_audio_probe,
113         .remove = imx_hdmi_audio_remove,
114         .driver = {
115                 .of_match_table = imx_hdmi_dt_ids,
116                 .name = "imx-audio-hdmi",
117                 .owner = THIS_MODULE,
118         },
119 };
120
121 module_platform_driver(imx_hdmi_audio_driver);
122
123 MODULE_AUTHOR("Freescale Semiconductor, Inc.");
124 MODULE_DESCRIPTION("IMX HDMI TX ASoC driver");
125 MODULE_LICENSE("GPL");
126 MODULE_ALIAS("platform:imx-audio-hdmi");