blob: ff6132a9b7e827c12ab3d695e1daf72eab908ad1 [file] [log] [blame]
Ricardo Neribca2e412011-06-02 15:44:45 -05001/*
2 * omap-hdmi.c
3 *
4 * OMAP ALSA SoC DAI driver for HDMI audio on OMAP4 processors.
5 * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com/
6 * Authors: Jorge Candelaria <jorge.candelaria@ti.com>
7 * Ricardo Neri <ricardo.neri@ti.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
25#include <linux/init.h>
26#include <linux/module.h>
27#include <linux/device.h>
28#include <sound/core.h>
29#include <sound/pcm.h>
30#include <sound/pcm_params.h>
31#include <sound/initval.h>
32#include <sound/soc.h>
Ricardo Neria48d9b72012-05-18 01:42:37 -050033#include <video/omapdss.h>
Ricardo Neribca2e412011-06-02 15:44:45 -050034
35#include <plat/dma.h>
36#include "omap-pcm.h"
37#include "omap-hdmi.h"
38
Ricardo Nerie412ec62012-05-18 01:42:34 -050039#define DRV_NAME "omap-hdmi-audio-dai"
Ricardo Neribca2e412011-06-02 15:44:45 -050040
Ricardo Neri26039152012-05-18 01:42:36 -050041struct hdmi_priv {
42 struct omap_pcm_dma_data dma_params;
Ricardo Neria48d9b72012-05-18 01:42:37 -050043 struct omap_dss_device *dssdev;
Ricardo Neribca2e412011-06-02 15:44:45 -050044};
45
46static int omap_hdmi_dai_startup(struct snd_pcm_substream *substream,
47 struct snd_soc_dai *dai)
48{
49 int err;
50 /*
51 * Make sure that the period bytes are multiple of the DMA packet size.
52 * Largest packet size we use is 32 32-bit words = 128 bytes
53 */
54 err = snd_pcm_hw_constraint_step(substream->runtime, 0,
55 SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 128);
56 if (err < 0)
57 return err;
58
59 return 0;
60}
61
Ricardo Neria48d9b72012-05-18 01:42:37 -050062static int omap_hdmi_dai_prepare(struct snd_pcm_substream *substream,
63 struct snd_soc_dai *dai)
64{
65 struct hdmi_priv *priv = snd_soc_dai_get_drvdata(dai);
66
67 return priv->dssdev->driver->audio_enable(priv->dssdev);
68}
69
Ricardo Neribca2e412011-06-02 15:44:45 -050070static int omap_hdmi_dai_hw_params(struct snd_pcm_substream *substream,
71 struct snd_pcm_hw_params *params,
72 struct snd_soc_dai *dai)
73{
Ricardo Neri26039152012-05-18 01:42:36 -050074 struct hdmi_priv *priv = snd_soc_dai_get_drvdata(dai);
Ricardo Neribca2e412011-06-02 15:44:45 -050075 int err = 0;
76
77 switch (params_format(params)) {
78 case SNDRV_PCM_FORMAT_S16_LE:
Ricardo Neri26039152012-05-18 01:42:36 -050079 priv->dma_params.packet_size = 16;
Ricardo Neribca2e412011-06-02 15:44:45 -050080 break;
81 case SNDRV_PCM_FORMAT_S24_LE:
Ricardo Neri26039152012-05-18 01:42:36 -050082 priv->dma_params.packet_size = 32;
Ricardo Neribca2e412011-06-02 15:44:45 -050083 break;
84 default:
85 err = -EINVAL;
86 }
87
Ricardo Neri26039152012-05-18 01:42:36 -050088 priv->dma_params.data_type = OMAP_DMA_DATA_TYPE_S32;
Ricardo Neribca2e412011-06-02 15:44:45 -050089
90 snd_soc_dai_set_dma_data(dai, substream,
Ricardo Neri26039152012-05-18 01:42:36 -050091 &priv->dma_params);
Ricardo Neribca2e412011-06-02 15:44:45 -050092
93 return err;
94}
95
Ricardo Neria48d9b72012-05-18 01:42:37 -050096static int omap_hdmi_dai_trigger(struct snd_pcm_substream *substream, int cmd,
97 struct snd_soc_dai *dai)
98{
99 struct hdmi_priv *priv = snd_soc_dai_get_drvdata(dai);
100 int err = 0;
101
102 switch (cmd) {
103 case SNDRV_PCM_TRIGGER_START:
104 case SNDRV_PCM_TRIGGER_RESUME:
105 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
106 err = priv->dssdev->driver->audio_start(priv->dssdev);
107 break;
108 case SNDRV_PCM_TRIGGER_STOP:
109 case SNDRV_PCM_TRIGGER_SUSPEND:
110 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
111 priv->dssdev->driver->audio_stop(priv->dssdev);
112 break;
113 default:
114 err = -EINVAL;
115 }
116 return err;
117}
118
119static void omap_hdmi_dai_shutdown(struct snd_pcm_substream *substream,
120 struct snd_soc_dai *dai)
121{
122 struct hdmi_priv *priv = snd_soc_dai_get_drvdata(dai);
123
124 priv->dssdev->driver->audio_disable(priv->dssdev);
125}
126
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100127static const struct snd_soc_dai_ops omap_hdmi_dai_ops = {
Ricardo Neribca2e412011-06-02 15:44:45 -0500128 .startup = omap_hdmi_dai_startup,
129 .hw_params = omap_hdmi_dai_hw_params,
130};
131
132static struct snd_soc_dai_driver omap_hdmi_dai = {
133 .playback = {
134 .channels_min = 2,
135 .channels_max = 2,
136 .rates = OMAP_HDMI_RATES,
137 .formats = OMAP_HDMI_FORMATS,
138 },
139 .ops = &omap_hdmi_dai_ops,
140};
141
142static __devinit int omap_hdmi_probe(struct platform_device *pdev)
143{
144 int ret;
145 struct resource *hdmi_rsrc;
Ricardo Neri26039152012-05-18 01:42:36 -0500146 struct hdmi_priv *hdmi_data;
Ricardo Neria48d9b72012-05-18 01:42:37 -0500147 bool hdmi_dev_found = false;
Ricardo Neri26039152012-05-18 01:42:36 -0500148
149 hdmi_data = devm_kzalloc(&pdev->dev, sizeof(*hdmi_data), GFP_KERNEL);
150 if (hdmi_data == NULL) {
151 dev_err(&pdev->dev, "Cannot allocate memory for HDMI data\n");
152 return -ENOMEM;
153 }
Ricardo Neribca2e412011-06-02 15:44:45 -0500154
155 hdmi_rsrc = platform_get_resource(pdev, IORESOURCE_MEM, 0);
156 if (!hdmi_rsrc) {
157 dev_err(&pdev->dev, "Cannot obtain IORESOURCE_MEM HDMI\n");
Ricardo Neri0ff5ee82012-05-18 01:42:35 -0500158 return -ENODEV;
Ricardo Neribca2e412011-06-02 15:44:45 -0500159 }
160
Ricardo Neri26039152012-05-18 01:42:36 -0500161 hdmi_data->dma_params.port_addr = hdmi_rsrc->start
Ricardo Neribca2e412011-06-02 15:44:45 -0500162 + OMAP_HDMI_AUDIO_DMA_PORT;
163
164 hdmi_rsrc = platform_get_resource(pdev, IORESOURCE_DMA, 0);
165 if (!hdmi_rsrc) {
166 dev_err(&pdev->dev, "Cannot obtain IORESOURCE_DMA HDMI\n");
Ricardo Neri0ff5ee82012-05-18 01:42:35 -0500167 return -ENODEV;
Ricardo Neribca2e412011-06-02 15:44:45 -0500168 }
169
Ricardo Neri26039152012-05-18 01:42:36 -0500170 hdmi_data->dma_params.dma_req = hdmi_rsrc->start;
171 hdmi_data->dma_params.name = "HDMI playback";
172 hdmi_data->dma_params.sync_mode = OMAP_DMA_SYNC_PACKET;
Ricardo Neribca2e412011-06-02 15:44:45 -0500173
Ricardo Neria48d9b72012-05-18 01:42:37 -0500174 /*
175 * TODO: We assume that there is only one DSS HDMI device. Future
176 * OMAP implementations may support more than one HDMI devices and
177 * we should provided separate audio support for all of them.
178 */
179 /* Find an HDMI device. */
180 for_each_dss_dev(hdmi_data->dssdev) {
181 omap_dss_get_device(hdmi_data->dssdev);
182
183 if (!hdmi_data->dssdev->driver) {
184 omap_dss_put_device(hdmi_data->dssdev);
185 continue;
186 }
187
188 if (hdmi_data->dssdev->type == OMAP_DISPLAY_TYPE_HDMI) {
189 hdmi_dev_found = true;
190 break;
191 }
192 }
193
194 if (!hdmi_dev_found) {
195 dev_err(&pdev->dev, "no driver for HDMI display found\n");
196 return -ENODEV;
197 }
198
Ricardo Neri26039152012-05-18 01:42:36 -0500199 dev_set_drvdata(&pdev->dev, hdmi_data);
Ricardo Neribca2e412011-06-02 15:44:45 -0500200 ret = snd_soc_register_dai(&pdev->dev, &omap_hdmi_dai);
Ricardo Neria48d9b72012-05-18 01:42:37 -0500201
Ricardo Neribca2e412011-06-02 15:44:45 -0500202 return ret;
203}
204
205static int __devexit omap_hdmi_remove(struct platform_device *pdev)
206{
Ricardo Neria48d9b72012-05-18 01:42:37 -0500207 struct hdmi_priv *hdmi_data = dev_get_drvdata(&pdev->dev);
208
Ricardo Neribca2e412011-06-02 15:44:45 -0500209 snd_soc_unregister_dai(&pdev->dev);
Ricardo Neria48d9b72012-05-18 01:42:37 -0500210
211 if (hdmi_data == NULL) {
212 dev_err(&pdev->dev, "cannot obtain HDMi data\n");
213 return -ENODEV;
214 }
215
216 omap_dss_put_device(hdmi_data->dssdev);
Ricardo Neribca2e412011-06-02 15:44:45 -0500217 return 0;
218}
219
220static struct platform_driver hdmi_dai_driver = {
221 .driver = {
222 .name = DRV_NAME,
223 .owner = THIS_MODULE,
224 },
225 .probe = omap_hdmi_probe,
226 .remove = __devexit_p(omap_hdmi_remove),
227};
228
Axel Linbeda5bf52011-11-25 10:12:16 +0800229module_platform_driver(hdmi_dai_driver);
Ricardo Neribca2e412011-06-02 15:44:45 -0500230
231MODULE_AUTHOR("Jorge Candelaria <jorge.candelaria@ti.com>");
232MODULE_AUTHOR("Ricardo Neri <ricardo.neri@ti.com>");
233MODULE_DESCRIPTION("OMAP HDMI SoC Interface");
234MODULE_LICENSE("GPL");
235MODULE_ALIAS("platform:" DRV_NAME);