Merge git://git.jan-o-sch.net/btrfs-unstable into for-linus
[firefly-linux-kernel-4.4.55.git] / sound / soc / omap / omap4-hdmi-card.c
1 /*
2  * omap4-hdmi-card.c
3  *
4  * OMAP ALSA SoC machine driver for TI OMAP4 HDMI
5  * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
6  * Author: Ricardo Neri <ricardo.neri@ti.com>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * version 2 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  *
22  */
23
24 #include <linux/module.h>
25 #include <sound/pcm.h>
26 #include <sound/soc.h>
27 #include <asm/mach-types.h>
28 #include <video/omapdss.h>
29
30 #define DRV_NAME "omap4-hdmi-audio"
31
32 static int omap4_hdmi_dai_hw_params(struct snd_pcm_substream *substream,
33                 struct snd_pcm_hw_params *params)
34 {
35         int i;
36         struct omap_overlay_manager *mgr = NULL;
37         struct device *dev = substream->pcm->card->dev;
38
39         /* Find DSS HDMI device */
40         for (i = 0; i < omap_dss_get_num_overlay_managers(); i++) {
41                 mgr = omap_dss_get_overlay_manager(i);
42                 if (mgr && mgr->device
43                         && mgr->device->type == OMAP_DISPLAY_TYPE_HDMI)
44                         break;
45         }
46
47         if (i == omap_dss_get_num_overlay_managers()) {
48                 dev_err(dev, "HDMI display device not found!\n");
49                 return -ENODEV;
50         }
51
52         /* Make sure HDMI is power-on to avoid L3 interconnect errors */
53         if (mgr->device->state != OMAP_DSS_DISPLAY_ACTIVE) {
54                 dev_err(dev, "HDMI display is not active!\n");
55                 return -EIO;
56         }
57
58         return 0;
59 }
60
61 static struct snd_soc_ops omap4_hdmi_dai_ops = {
62         .hw_params = omap4_hdmi_dai_hw_params,
63 };
64
65 static struct snd_soc_dai_link omap4_hdmi_dai = {
66         .name = "HDMI",
67         .stream_name = "HDMI",
68         .cpu_dai_name = "hdmi-audio-dai",
69         .platform_name = "omap-pcm-audio",
70         .codec_name = "omapdss_hdmi",
71         .codec_dai_name = "hdmi-audio-codec",
72         .ops = &omap4_hdmi_dai_ops,
73 };
74
75 static struct snd_soc_card snd_soc_omap4_hdmi = {
76         .name = "OMAP4HDMI",
77         .owner = THIS_MODULE,
78         .dai_link = &omap4_hdmi_dai,
79         .num_links = 1,
80 };
81
82 static __devinit int omap4_hdmi_probe(struct platform_device *pdev)
83 {
84         struct snd_soc_card *card = &snd_soc_omap4_hdmi;
85         int ret;
86
87         card->dev = &pdev->dev;
88
89         ret = snd_soc_register_card(card);
90         if (ret) {
91                 dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret);
92                 card->dev = NULL;
93                 return ret;
94         }
95         return 0;
96 }
97
98 static int __devexit omap4_hdmi_remove(struct platform_device *pdev)
99 {
100         struct snd_soc_card *card = platform_get_drvdata(pdev);
101
102         snd_soc_unregister_card(card);
103         card->dev = NULL;
104         return 0;
105 }
106
107 static struct platform_driver omap4_hdmi_driver = {
108         .driver = {
109                 .name = "omap4-hdmi-audio",
110                 .owner = THIS_MODULE,
111         },
112         .probe = omap4_hdmi_probe,
113         .remove = __devexit_p(omap4_hdmi_remove),
114 };
115
116 module_platform_driver(omap4_hdmi_driver);
117
118 MODULE_AUTHOR("Ricardo Neri <ricardo.neri@ti.com>");
119 MODULE_DESCRIPTION("OMAP4 HDMI machine ASoC driver");
120 MODULE_LICENSE("GPL");
121 MODULE_ALIAS("platform:" DRV_NAME);