ASoC: omap-pcm, omap-dmic: Change the use of omap_pcm_dma_data->data_type
[deliverable/linux.git] / sound / soc / omap / omap-hdmi.c
CommitLineData
bca2e41d
RN
1/*
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>
7e6aa220
RN
33#include <sound/asound.h>
34#include <sound/asoundef.h>
a48d9b75 35#include <video/omapdss.h>
bca2e41d 36
bca2e41d
RN
37#include "omap-pcm.h"
38#include "omap-hdmi.h"
39
e412ec64 40#define DRV_NAME "omap-hdmi-audio-dai"
bca2e41d 41
26039153
RN
42struct hdmi_priv {
43 struct omap_pcm_dma_data dma_params;
7e6aa220
RN
44 struct omap_dss_audio dss_audio;
45 struct snd_aes_iec958 iec;
46 struct snd_cea_861_aud_if cea;
a48d9b75 47 struct omap_dss_device *dssdev;
bca2e41d
RN
48};
49
50static int omap_hdmi_dai_startup(struct snd_pcm_substream *substream,
51 struct snd_soc_dai *dai)
52{
a0534e3b 53 struct hdmi_priv *priv = snd_soc_dai_get_drvdata(dai);
bca2e41d
RN
54 int err;
55 /*
56 * Make sure that the period bytes are multiple of the DMA packet size.
57 * Largest packet size we use is 32 32-bit words = 128 bytes
58 */
59 err = snd_pcm_hw_constraint_step(substream->runtime, 0,
60 SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 128);
a0534e3b
RN
61 if (err < 0) {
62 dev_err(dai->dev, "could not apply constraint\n");
bca2e41d 63 return err;
a0534e3b 64 }
bca2e41d 65
a0534e3b
RN
66 if (!priv->dssdev->driver->audio_supported(priv->dssdev)) {
67 dev_err(dai->dev, "audio not supported\n");
68 return -ENODEV;
69 }
bca2e41d
RN
70 return 0;
71}
72
a48d9b75
RN
73static int omap_hdmi_dai_prepare(struct snd_pcm_substream *substream,
74 struct snd_soc_dai *dai)
75{
76 struct hdmi_priv *priv = snd_soc_dai_get_drvdata(dai);
77
78 return priv->dssdev->driver->audio_enable(priv->dssdev);
79}
80
bca2e41d
RN
81static int omap_hdmi_dai_hw_params(struct snd_pcm_substream *substream,
82 struct snd_pcm_hw_params *params,
83 struct snd_soc_dai *dai)
84{
26039153 85 struct hdmi_priv *priv = snd_soc_dai_get_drvdata(dai);
7e6aa220
RN
86 struct snd_aes_iec958 *iec = &priv->iec;
87 struct snd_cea_861_aud_if *cea = &priv->cea;
bca2e41d
RN
88 int err = 0;
89
90 switch (params_format(params)) {
91 case SNDRV_PCM_FORMAT_S16_LE:
26039153 92 priv->dma_params.packet_size = 16;
bca2e41d
RN
93 break;
94 case SNDRV_PCM_FORMAT_S24_LE:
26039153 95 priv->dma_params.packet_size = 32;
bca2e41d
RN
96 break;
97 default:
7e6aa220
RN
98 dev_err(dai->dev, "format not supported!\n");
99 return -EINVAL;
bca2e41d
RN
100 }
101
f05cc9da 102 priv->dma_params.data_type = 32;
bca2e41d
RN
103
104 snd_soc_dai_set_dma_data(dai, substream,
26039153 105 &priv->dma_params);
bca2e41d 106
7e6aa220
RN
107 /*
108 * fill the IEC-60958 channel status word
109 */
110
111 /* specify IEC-60958-3 (commercial use) */
112 iec->status[0] &= ~IEC958_AES0_PROFESSIONAL;
113
114 /* specify that the audio is LPCM*/
115 iec->status[0] &= ~IEC958_AES0_NONAUDIO;
116
117 iec->status[0] |= IEC958_AES0_CON_NOT_COPYRIGHT;
118
119 iec->status[0] |= IEC958_AES0_CON_EMPHASIS_NONE;
120
121 iec->status[0] |= IEC958_AES1_PRO_MODE_NOTID;
122
123 iec->status[1] = IEC958_AES1_CON_GENERAL;
124
125 iec->status[2] |= IEC958_AES2_CON_SOURCE_UNSPEC;
126
127 iec->status[2] |= IEC958_AES2_CON_CHANNEL_UNSPEC;
128
129 switch (params_rate(params)) {
130 case 32000:
131 iec->status[3] |= IEC958_AES3_CON_FS_32000;
132 break;
133 case 44100:
134 iec->status[3] |= IEC958_AES3_CON_FS_44100;
135 break;
136 case 48000:
137 iec->status[3] |= IEC958_AES3_CON_FS_48000;
138 break;
139 case 88200:
140 iec->status[3] |= IEC958_AES3_CON_FS_88200;
141 break;
142 case 96000:
143 iec->status[3] |= IEC958_AES3_CON_FS_96000;
144 break;
145 case 176400:
146 iec->status[3] |= IEC958_AES3_CON_FS_176400;
147 break;
148 case 192000:
149 iec->status[3] |= IEC958_AES3_CON_FS_192000;
150 break;
151 default:
152 dev_err(dai->dev, "rate not supported!\n");
153 return -EINVAL;
154 }
155
156 /* specify the clock accuracy */
157 iec->status[3] |= IEC958_AES3_CON_CLOCK_1000PPM;
158
159 /*
160 * specify the word length. The same word length value can mean
161 * two different lengths. Hence, we need to specify the maximum
162 * word length as well.
163 */
164 switch (params_format(params)) {
165 case SNDRV_PCM_FORMAT_S16_LE:
166 iec->status[4] |= IEC958_AES4_CON_WORDLEN_20_16;
167 iec->status[4] &= ~IEC958_AES4_CON_MAX_WORDLEN_24;
168 break;
169 case SNDRV_PCM_FORMAT_S24_LE:
170 iec->status[4] |= IEC958_AES4_CON_WORDLEN_24_20;
171 iec->status[4] |= IEC958_AES4_CON_MAX_WORDLEN_24;
172 break;
173 default:
174 dev_err(dai->dev, "format not supported!\n");
175 return -EINVAL;
176 }
177
178 /*
179 * Fill the CEA-861 audio infoframe (see spec for details)
180 */
181
182 cea->db1_ct_cc = (params_channels(params) - 1)
183 & CEA861_AUDIO_INFOFRAME_DB1CC;
184 cea->db1_ct_cc |= CEA861_AUDIO_INFOFRAME_DB1CT_FROM_STREAM;
185
186 cea->db2_sf_ss = CEA861_AUDIO_INFOFRAME_DB2SF_FROM_STREAM;
187 cea->db2_sf_ss |= CEA861_AUDIO_INFOFRAME_DB2SS_FROM_STREAM;
188
189 cea->db3 = 0; /* not used, all zeros */
190
191 /*
192 * The OMAP HDMI IP requires to use the 8-channel channel code when
193 * transmitting more than two channels.
194 */
195 if (params_channels(params) == 2)
196 cea->db4_ca = 0x0;
197 else
198 cea->db4_ca = 0x13;
199
200 cea->db5_dminh_lsv = CEA861_AUDIO_INFOFRAME_DB5_DM_INH_PROHIBITED;
201 /* the expression is trivial but makes clear what we are doing */
202 cea->db5_dminh_lsv |= (0 & CEA861_AUDIO_INFOFRAME_DB5_LSV);
203
204 priv->dss_audio.iec = iec;
205 priv->dss_audio.cea = cea;
206
207 err = priv->dssdev->driver->audio_config(priv->dssdev,
208 &priv->dss_audio);
209
bca2e41d
RN
210 return err;
211}
212
a48d9b75
RN
213static int omap_hdmi_dai_trigger(struct snd_pcm_substream *substream, int cmd,
214 struct snd_soc_dai *dai)
215{
216 struct hdmi_priv *priv = snd_soc_dai_get_drvdata(dai);
217 int err = 0;
218
219 switch (cmd) {
220 case SNDRV_PCM_TRIGGER_START:
221 case SNDRV_PCM_TRIGGER_RESUME:
222 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
223 err = priv->dssdev->driver->audio_start(priv->dssdev);
224 break;
225 case SNDRV_PCM_TRIGGER_STOP:
226 case SNDRV_PCM_TRIGGER_SUSPEND:
227 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
228 priv->dssdev->driver->audio_stop(priv->dssdev);
229 break;
230 default:
231 err = -EINVAL;
232 }
233 return err;
234}
235
236static void omap_hdmi_dai_shutdown(struct snd_pcm_substream *substream,
237 struct snd_soc_dai *dai)
238{
239 struct hdmi_priv *priv = snd_soc_dai_get_drvdata(dai);
240
241 priv->dssdev->driver->audio_disable(priv->dssdev);
242}
243
85e7652d 244static const struct snd_soc_dai_ops omap_hdmi_dai_ops = {
bca2e41d
RN
245 .startup = omap_hdmi_dai_startup,
246 .hw_params = omap_hdmi_dai_hw_params,
7e6aa220
RN
247 .prepare = omap_hdmi_dai_prepare,
248 .trigger = omap_hdmi_dai_trigger,
249 .shutdown = omap_hdmi_dai_shutdown,
bca2e41d
RN
250};
251
252static struct snd_soc_dai_driver omap_hdmi_dai = {
253 .playback = {
254 .channels_min = 2,
a1ab92da 255 .channels_max = 8,
bca2e41d
RN
256 .rates = OMAP_HDMI_RATES,
257 .formats = OMAP_HDMI_FORMATS,
258 },
259 .ops = &omap_hdmi_dai_ops,
260};
261
262static __devinit int omap_hdmi_probe(struct platform_device *pdev)
263{
264 int ret;
265 struct resource *hdmi_rsrc;
26039153 266 struct hdmi_priv *hdmi_data;
a48d9b75 267 bool hdmi_dev_found = false;
26039153
RN
268
269 hdmi_data = devm_kzalloc(&pdev->dev, sizeof(*hdmi_data), GFP_KERNEL);
270 if (hdmi_data == NULL) {
271 dev_err(&pdev->dev, "Cannot allocate memory for HDMI data\n");
272 return -ENOMEM;
273 }
bca2e41d
RN
274
275 hdmi_rsrc = platform_get_resource(pdev, IORESOURCE_MEM, 0);
276 if (!hdmi_rsrc) {
277 dev_err(&pdev->dev, "Cannot obtain IORESOURCE_MEM HDMI\n");
0ff5ee87 278 return -ENODEV;
bca2e41d
RN
279 }
280
26039153 281 hdmi_data->dma_params.port_addr = hdmi_rsrc->start
bca2e41d
RN
282 + OMAP_HDMI_AUDIO_DMA_PORT;
283
284 hdmi_rsrc = platform_get_resource(pdev, IORESOURCE_DMA, 0);
285 if (!hdmi_rsrc) {
286 dev_err(&pdev->dev, "Cannot obtain IORESOURCE_DMA HDMI\n");
0ff5ee87 287 return -ENODEV;
bca2e41d
RN
288 }
289
26039153
RN
290 hdmi_data->dma_params.dma_req = hdmi_rsrc->start;
291 hdmi_data->dma_params.name = "HDMI playback";
bca2e41d 292
a48d9b75
RN
293 /*
294 * TODO: We assume that there is only one DSS HDMI device. Future
295 * OMAP implementations may support more than one HDMI devices and
296 * we should provided separate audio support for all of them.
297 */
298 /* Find an HDMI device. */
299 for_each_dss_dev(hdmi_data->dssdev) {
300 omap_dss_get_device(hdmi_data->dssdev);
301
302 if (!hdmi_data->dssdev->driver) {
303 omap_dss_put_device(hdmi_data->dssdev);
304 continue;
305 }
306
307 if (hdmi_data->dssdev->type == OMAP_DISPLAY_TYPE_HDMI) {
308 hdmi_dev_found = true;
309 break;
310 }
311 }
312
313 if (!hdmi_dev_found) {
314 dev_err(&pdev->dev, "no driver for HDMI display found\n");
315 return -ENODEV;
316 }
317
26039153 318 dev_set_drvdata(&pdev->dev, hdmi_data);
bca2e41d 319 ret = snd_soc_register_dai(&pdev->dev, &omap_hdmi_dai);
a48d9b75 320
bca2e41d
RN
321 return ret;
322}
323
324static int __devexit omap_hdmi_remove(struct platform_device *pdev)
325{
a48d9b75
RN
326 struct hdmi_priv *hdmi_data = dev_get_drvdata(&pdev->dev);
327
bca2e41d 328 snd_soc_unregister_dai(&pdev->dev);
a48d9b75
RN
329
330 if (hdmi_data == NULL) {
331 dev_err(&pdev->dev, "cannot obtain HDMi data\n");
332 return -ENODEV;
333 }
334
335 omap_dss_put_device(hdmi_data->dssdev);
bca2e41d
RN
336 return 0;
337}
338
339static struct platform_driver hdmi_dai_driver = {
340 .driver = {
341 .name = DRV_NAME,
342 .owner = THIS_MODULE,
343 },
344 .probe = omap_hdmi_probe,
345 .remove = __devexit_p(omap_hdmi_remove),
346};
347
beda5bf5 348module_platform_driver(hdmi_dai_driver);
bca2e41d
RN
349
350MODULE_AUTHOR("Jorge Candelaria <jorge.candelaria@ti.com>");
351MODULE_AUTHOR("Ricardo Neri <ricardo.neri@ti.com>");
352MODULE_DESCRIPTION("OMAP HDMI SoC Interface");
353MODULE_LICENSE("GPL");
354MODULE_ALIAS("platform:" DRV_NAME);
This page took 0.085791 seconds and 5 git commands to generate.