xref: /linux/sound/soc/ti/omap-hdmi.c (revision 3b785a63ee3d2bc9eb6473ca9490d5a268c88c3e)
1f2055e14SPeter Ujfalusi /*
2f2055e14SPeter Ujfalusi  * omap-hdmi-audio.c -- OMAP4+ DSS HDMI audio support library
3f2055e14SPeter Ujfalusi  *
4f2055e14SPeter Ujfalusi  * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com
5f2055e14SPeter Ujfalusi  *
6f2055e14SPeter Ujfalusi  * Author: Jyri Sarha <jsarha@ti.com>
7f2055e14SPeter Ujfalusi  *
8f2055e14SPeter Ujfalusi  * This program is free software; you can redistribute it and/or
9f2055e14SPeter Ujfalusi  * modify it under the terms of the GNU General Public License
10f2055e14SPeter Ujfalusi  * version 2 as published by the Free Software Foundation.
11f2055e14SPeter Ujfalusi  *
12f2055e14SPeter Ujfalusi  * This program is distributed in the hope that it will be useful, but
13f2055e14SPeter Ujfalusi  * WITHOUT ANY WARRANTY; without even the implied warranty of
14f2055e14SPeter Ujfalusi  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15f2055e14SPeter Ujfalusi  * General Public License for more details.
16f2055e14SPeter Ujfalusi  *
17f2055e14SPeter Ujfalusi  */
18f2055e14SPeter Ujfalusi 
19f2055e14SPeter Ujfalusi #include <linux/kernel.h>
20f2055e14SPeter Ujfalusi #include <linux/module.h>
21f2055e14SPeter Ujfalusi #include <linux/err.h>
22f2055e14SPeter Ujfalusi #include <linux/string.h>
23f2055e14SPeter Ujfalusi #include <linux/platform_device.h>
24f2055e14SPeter Ujfalusi #include <sound/soc.h>
25f2055e14SPeter Ujfalusi #include <sound/pcm_params.h>
26f2055e14SPeter Ujfalusi #include <sound/dmaengine_pcm.h>
27f2055e14SPeter Ujfalusi #include <uapi/sound/asound.h>
28f2055e14SPeter Ujfalusi #include <sound/asoundef.h>
29f2055e14SPeter Ujfalusi #include <sound/omap-hdmi-audio.h>
30f2055e14SPeter Ujfalusi 
31f2055e14SPeter Ujfalusi #include "sdma-pcm.h"
32f2055e14SPeter Ujfalusi 
33f2055e14SPeter Ujfalusi #define DRV_NAME "omap-hdmi-audio"
34f2055e14SPeter Ujfalusi 
35f2055e14SPeter Ujfalusi struct hdmi_audio_data {
36f2055e14SPeter Ujfalusi 	struct snd_soc_card *card;
37f2055e14SPeter Ujfalusi 
38f2055e14SPeter Ujfalusi 	const struct omap_hdmi_audio_ops *ops;
39f2055e14SPeter Ujfalusi 	struct device *dssdev;
40f2055e14SPeter Ujfalusi 	struct snd_dmaengine_dai_dma_data dma_data;
41f2055e14SPeter Ujfalusi 	struct omap_dss_audio dss_audio;
42f2055e14SPeter Ujfalusi 	struct snd_aes_iec958 iec;
43f2055e14SPeter Ujfalusi 	struct snd_cea_861_aud_if cea;
44f2055e14SPeter Ujfalusi 
45f2055e14SPeter Ujfalusi 	struct mutex current_stream_lock;
46f2055e14SPeter Ujfalusi 	struct snd_pcm_substream *current_stream;
47f2055e14SPeter Ujfalusi };
48f2055e14SPeter Ujfalusi 
49f2055e14SPeter Ujfalusi static
50f2055e14SPeter Ujfalusi struct hdmi_audio_data *card_drvdata_substream(struct snd_pcm_substream *ss)
51f2055e14SPeter Ujfalusi {
52f2055e14SPeter Ujfalusi 	struct snd_soc_pcm_runtime *rtd = ss->private_data;
53f2055e14SPeter Ujfalusi 
54f2055e14SPeter Ujfalusi 	return snd_soc_card_get_drvdata(rtd->card);
55f2055e14SPeter Ujfalusi }
56f2055e14SPeter Ujfalusi 
57f2055e14SPeter Ujfalusi static void hdmi_dai_abort(struct device *dev)
58f2055e14SPeter Ujfalusi {
59f2055e14SPeter Ujfalusi 	struct hdmi_audio_data *ad = dev_get_drvdata(dev);
60f2055e14SPeter Ujfalusi 
61f2055e14SPeter Ujfalusi 	mutex_lock(&ad->current_stream_lock);
62f2055e14SPeter Ujfalusi 	if (ad->current_stream && ad->current_stream->runtime &&
63f2055e14SPeter Ujfalusi 	    snd_pcm_running(ad->current_stream)) {
64f2055e14SPeter Ujfalusi 		dev_err(dev, "HDMI display disabled, aborting playback\n");
65f2055e14SPeter Ujfalusi 		snd_pcm_stream_lock_irq(ad->current_stream);
66f2055e14SPeter Ujfalusi 		snd_pcm_stop(ad->current_stream, SNDRV_PCM_STATE_DISCONNECTED);
67f2055e14SPeter Ujfalusi 		snd_pcm_stream_unlock_irq(ad->current_stream);
68f2055e14SPeter Ujfalusi 	}
69f2055e14SPeter Ujfalusi 	mutex_unlock(&ad->current_stream_lock);
70f2055e14SPeter Ujfalusi }
71f2055e14SPeter Ujfalusi 
72f2055e14SPeter Ujfalusi static int hdmi_dai_startup(struct snd_pcm_substream *substream,
73f2055e14SPeter Ujfalusi 			    struct snd_soc_dai *dai)
74f2055e14SPeter Ujfalusi {
75f2055e14SPeter Ujfalusi 	struct hdmi_audio_data *ad = card_drvdata_substream(substream);
76f2055e14SPeter Ujfalusi 	int ret;
77f2055e14SPeter Ujfalusi 	/*
78f2055e14SPeter Ujfalusi 	 * Make sure that the period bytes are multiple of the DMA packet size.
79f2055e14SPeter Ujfalusi 	 * Largest packet size we use is 32 32-bit words = 128 bytes
80f2055e14SPeter Ujfalusi 	 */
81f2055e14SPeter Ujfalusi 	ret = snd_pcm_hw_constraint_step(substream->runtime, 0,
82f2055e14SPeter Ujfalusi 					 SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 128);
83f2055e14SPeter Ujfalusi 	if (ret < 0) {
84f2055e14SPeter Ujfalusi 		dev_err(dai->dev, "Could not apply period constraint: %d\n",
85f2055e14SPeter Ujfalusi 			ret);
86f2055e14SPeter Ujfalusi 		return ret;
87f2055e14SPeter Ujfalusi 	}
88f2055e14SPeter Ujfalusi 	ret = snd_pcm_hw_constraint_step(substream->runtime, 0,
89f2055e14SPeter Ujfalusi 					 SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 128);
90f2055e14SPeter Ujfalusi 	if (ret < 0) {
91f2055e14SPeter Ujfalusi 		dev_err(dai->dev, "Could not apply buffer constraint: %d\n",
92f2055e14SPeter Ujfalusi 			ret);
93f2055e14SPeter Ujfalusi 		return ret;
94f2055e14SPeter Ujfalusi 	}
95f2055e14SPeter Ujfalusi 
96f2055e14SPeter Ujfalusi 	snd_soc_dai_set_dma_data(dai, substream, &ad->dma_data);
97f2055e14SPeter Ujfalusi 
98f2055e14SPeter Ujfalusi 	mutex_lock(&ad->current_stream_lock);
99f2055e14SPeter Ujfalusi 	ad->current_stream = substream;
100f2055e14SPeter Ujfalusi 	mutex_unlock(&ad->current_stream_lock);
101f2055e14SPeter Ujfalusi 
102f2055e14SPeter Ujfalusi 	ret = ad->ops->audio_startup(ad->dssdev, hdmi_dai_abort);
103f2055e14SPeter Ujfalusi 
104f2055e14SPeter Ujfalusi 	if (ret) {
105f2055e14SPeter Ujfalusi 		mutex_lock(&ad->current_stream_lock);
106f2055e14SPeter Ujfalusi 		ad->current_stream = NULL;
107f2055e14SPeter Ujfalusi 		mutex_unlock(&ad->current_stream_lock);
108f2055e14SPeter Ujfalusi 	}
109f2055e14SPeter Ujfalusi 
110f2055e14SPeter Ujfalusi 	return ret;
111f2055e14SPeter Ujfalusi }
112f2055e14SPeter Ujfalusi 
113f2055e14SPeter Ujfalusi static int hdmi_dai_hw_params(struct snd_pcm_substream *substream,
114f2055e14SPeter Ujfalusi 			      struct snd_pcm_hw_params *params,
115f2055e14SPeter Ujfalusi 			      struct snd_soc_dai *dai)
116f2055e14SPeter Ujfalusi {
117f2055e14SPeter Ujfalusi 	struct hdmi_audio_data *ad = card_drvdata_substream(substream);
118f2055e14SPeter Ujfalusi 	struct snd_aes_iec958 *iec = &ad->iec;
119f2055e14SPeter Ujfalusi 	struct snd_cea_861_aud_if *cea = &ad->cea;
120f2055e14SPeter Ujfalusi 
121f2055e14SPeter Ujfalusi 	WARN_ON(ad->current_stream != substream);
122f2055e14SPeter Ujfalusi 
123f2055e14SPeter Ujfalusi 	switch (params_format(params)) {
124f2055e14SPeter Ujfalusi 	case SNDRV_PCM_FORMAT_S16_LE:
125f2055e14SPeter Ujfalusi 		ad->dma_data.maxburst = 16;
126f2055e14SPeter Ujfalusi 		break;
127f2055e14SPeter Ujfalusi 	case SNDRV_PCM_FORMAT_S24_LE:
128f2055e14SPeter Ujfalusi 		ad->dma_data.maxburst = 32;
129f2055e14SPeter Ujfalusi 		break;
130f2055e14SPeter Ujfalusi 	default:
131f2055e14SPeter Ujfalusi 		dev_err(dai->dev, "format not supported!\n");
132f2055e14SPeter Ujfalusi 		return -EINVAL;
133f2055e14SPeter Ujfalusi 	}
134f2055e14SPeter Ujfalusi 
135f2055e14SPeter Ujfalusi 	ad->dss_audio.iec = iec;
136f2055e14SPeter Ujfalusi 	ad->dss_audio.cea = cea;
137f2055e14SPeter Ujfalusi 	/*
138f2055e14SPeter Ujfalusi 	 * fill the IEC-60958 channel status word
139f2055e14SPeter Ujfalusi 	 */
140f2055e14SPeter Ujfalusi 	/* initialize the word bytes */
141f2055e14SPeter Ujfalusi 	memset(iec->status, 0, sizeof(iec->status));
142f2055e14SPeter Ujfalusi 
143f2055e14SPeter Ujfalusi 	/* specify IEC-60958-3 (commercial use) */
144f2055e14SPeter Ujfalusi 	iec->status[0] &= ~IEC958_AES0_PROFESSIONAL;
145f2055e14SPeter Ujfalusi 
146f2055e14SPeter Ujfalusi 	/* specify that the audio is LPCM*/
147f2055e14SPeter Ujfalusi 	iec->status[0] &= ~IEC958_AES0_NONAUDIO;
148f2055e14SPeter Ujfalusi 
149f2055e14SPeter Ujfalusi 	iec->status[0] |= IEC958_AES0_CON_NOT_COPYRIGHT;
150f2055e14SPeter Ujfalusi 
151f2055e14SPeter Ujfalusi 	iec->status[0] |= IEC958_AES0_CON_EMPHASIS_NONE;
152f2055e14SPeter Ujfalusi 
153f2055e14SPeter Ujfalusi 	iec->status[1] = IEC958_AES1_CON_GENERAL;
154f2055e14SPeter Ujfalusi 
155f2055e14SPeter Ujfalusi 	iec->status[2] |= IEC958_AES2_CON_SOURCE_UNSPEC;
156f2055e14SPeter Ujfalusi 
157f2055e14SPeter Ujfalusi 	iec->status[2] |= IEC958_AES2_CON_CHANNEL_UNSPEC;
158f2055e14SPeter Ujfalusi 
159f2055e14SPeter Ujfalusi 	switch (params_rate(params)) {
160f2055e14SPeter Ujfalusi 	case 32000:
161f2055e14SPeter Ujfalusi 		iec->status[3] |= IEC958_AES3_CON_FS_32000;
162f2055e14SPeter Ujfalusi 		break;
163f2055e14SPeter Ujfalusi 	case 44100:
164f2055e14SPeter Ujfalusi 		iec->status[3] |= IEC958_AES3_CON_FS_44100;
165f2055e14SPeter Ujfalusi 		break;
166f2055e14SPeter Ujfalusi 	case 48000:
167f2055e14SPeter Ujfalusi 		iec->status[3] |= IEC958_AES3_CON_FS_48000;
168f2055e14SPeter Ujfalusi 		break;
169f2055e14SPeter Ujfalusi 	case 88200:
170f2055e14SPeter Ujfalusi 		iec->status[3] |= IEC958_AES3_CON_FS_88200;
171f2055e14SPeter Ujfalusi 		break;
172f2055e14SPeter Ujfalusi 	case 96000:
173f2055e14SPeter Ujfalusi 		iec->status[3] |= IEC958_AES3_CON_FS_96000;
174f2055e14SPeter Ujfalusi 		break;
175f2055e14SPeter Ujfalusi 	case 176400:
176f2055e14SPeter Ujfalusi 		iec->status[3] |= IEC958_AES3_CON_FS_176400;
177f2055e14SPeter Ujfalusi 		break;
178f2055e14SPeter Ujfalusi 	case 192000:
179f2055e14SPeter Ujfalusi 		iec->status[3] |= IEC958_AES3_CON_FS_192000;
180f2055e14SPeter Ujfalusi 		break;
181f2055e14SPeter Ujfalusi 	default:
182f2055e14SPeter Ujfalusi 		dev_err(dai->dev, "rate not supported!\n");
183f2055e14SPeter Ujfalusi 		return -EINVAL;
184f2055e14SPeter Ujfalusi 	}
185f2055e14SPeter Ujfalusi 
186f2055e14SPeter Ujfalusi 	/* specify the clock accuracy */
187f2055e14SPeter Ujfalusi 	iec->status[3] |= IEC958_AES3_CON_CLOCK_1000PPM;
188f2055e14SPeter Ujfalusi 
189f2055e14SPeter Ujfalusi 	/*
190f2055e14SPeter Ujfalusi 	 * specify the word length. The same word length value can mean
191f2055e14SPeter Ujfalusi 	 * two different lengths. Hence, we need to specify the maximum
192f2055e14SPeter Ujfalusi 	 * word length as well.
193f2055e14SPeter Ujfalusi 	 */
194f2055e14SPeter Ujfalusi 	switch (params_format(params)) {
195f2055e14SPeter Ujfalusi 	case SNDRV_PCM_FORMAT_S16_LE:
196f2055e14SPeter Ujfalusi 		iec->status[4] |= IEC958_AES4_CON_WORDLEN_20_16;
197f2055e14SPeter Ujfalusi 		iec->status[4] &= ~IEC958_AES4_CON_MAX_WORDLEN_24;
198f2055e14SPeter Ujfalusi 		break;
199f2055e14SPeter Ujfalusi 	case SNDRV_PCM_FORMAT_S24_LE:
200f2055e14SPeter Ujfalusi 		iec->status[4] |= IEC958_AES4_CON_WORDLEN_24_20;
201f2055e14SPeter Ujfalusi 		iec->status[4] |= IEC958_AES4_CON_MAX_WORDLEN_24;
202f2055e14SPeter Ujfalusi 		break;
203f2055e14SPeter Ujfalusi 	default:
204f2055e14SPeter Ujfalusi 		dev_err(dai->dev, "format not supported!\n");
205f2055e14SPeter Ujfalusi 		return -EINVAL;
206f2055e14SPeter Ujfalusi 	}
207f2055e14SPeter Ujfalusi 
208f2055e14SPeter Ujfalusi 	/*
209f2055e14SPeter Ujfalusi 	 * Fill the CEA-861 audio infoframe (see spec for details)
210f2055e14SPeter Ujfalusi 	 */
211f2055e14SPeter Ujfalusi 
212f2055e14SPeter Ujfalusi 	cea->db1_ct_cc = (params_channels(params) - 1)
213f2055e14SPeter Ujfalusi 		& CEA861_AUDIO_INFOFRAME_DB1CC;
214f2055e14SPeter Ujfalusi 	cea->db1_ct_cc |= CEA861_AUDIO_INFOFRAME_DB1CT_FROM_STREAM;
215f2055e14SPeter Ujfalusi 
216f2055e14SPeter Ujfalusi 	cea->db2_sf_ss = CEA861_AUDIO_INFOFRAME_DB2SF_FROM_STREAM;
217f2055e14SPeter Ujfalusi 	cea->db2_sf_ss |= CEA861_AUDIO_INFOFRAME_DB2SS_FROM_STREAM;
218f2055e14SPeter Ujfalusi 
219f2055e14SPeter Ujfalusi 	cea->db3 = 0; /* not used, all zeros */
220f2055e14SPeter Ujfalusi 
221f2055e14SPeter Ujfalusi 	if (params_channels(params) == 2)
222f2055e14SPeter Ujfalusi 		cea->db4_ca = 0x0;
223f2055e14SPeter Ujfalusi 	else if (params_channels(params) == 6)
224f2055e14SPeter Ujfalusi 		cea->db4_ca = 0xb;
225f2055e14SPeter Ujfalusi 	else
226f2055e14SPeter Ujfalusi 		cea->db4_ca = 0x13;
227f2055e14SPeter Ujfalusi 
228f2055e14SPeter Ujfalusi 	if (cea->db4_ca == 0x00)
229f2055e14SPeter Ujfalusi 		cea->db5_dminh_lsv = CEA861_AUDIO_INFOFRAME_DB5_DM_INH_PERMITTED;
230f2055e14SPeter Ujfalusi 	else
231f2055e14SPeter Ujfalusi 		cea->db5_dminh_lsv = CEA861_AUDIO_INFOFRAME_DB5_DM_INH_PROHIBITED;
232f2055e14SPeter Ujfalusi 
233f2055e14SPeter Ujfalusi 	/* the expression is trivial but makes clear what we are doing */
234f2055e14SPeter Ujfalusi 	cea->db5_dminh_lsv |= (0 & CEA861_AUDIO_INFOFRAME_DB5_LSV);
235f2055e14SPeter Ujfalusi 
236f2055e14SPeter Ujfalusi 	return ad->ops->audio_config(ad->dssdev, &ad->dss_audio);
237f2055e14SPeter Ujfalusi }
238f2055e14SPeter Ujfalusi 
239f2055e14SPeter Ujfalusi static int hdmi_dai_trigger(struct snd_pcm_substream *substream, int cmd,
240f2055e14SPeter Ujfalusi 			    struct snd_soc_dai *dai)
241f2055e14SPeter Ujfalusi {
242f2055e14SPeter Ujfalusi 	struct hdmi_audio_data *ad = card_drvdata_substream(substream);
243f2055e14SPeter Ujfalusi 	int err = 0;
244f2055e14SPeter Ujfalusi 
245f2055e14SPeter Ujfalusi 	WARN_ON(ad->current_stream != substream);
246f2055e14SPeter Ujfalusi 
247f2055e14SPeter Ujfalusi 	switch (cmd) {
248f2055e14SPeter Ujfalusi 	case SNDRV_PCM_TRIGGER_START:
249f2055e14SPeter Ujfalusi 	case SNDRV_PCM_TRIGGER_RESUME:
250f2055e14SPeter Ujfalusi 	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
251f2055e14SPeter Ujfalusi 		err = ad->ops->audio_start(ad->dssdev);
252f2055e14SPeter Ujfalusi 		break;
253f2055e14SPeter Ujfalusi 	case SNDRV_PCM_TRIGGER_STOP:
254f2055e14SPeter Ujfalusi 	case SNDRV_PCM_TRIGGER_SUSPEND:
255f2055e14SPeter Ujfalusi 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
256f2055e14SPeter Ujfalusi 		ad->ops->audio_stop(ad->dssdev);
257f2055e14SPeter Ujfalusi 		break;
258f2055e14SPeter Ujfalusi 	default:
259f2055e14SPeter Ujfalusi 		err = -EINVAL;
260f2055e14SPeter Ujfalusi 	}
261f2055e14SPeter Ujfalusi 	return err;
262f2055e14SPeter Ujfalusi }
263f2055e14SPeter Ujfalusi 
264f2055e14SPeter Ujfalusi static void hdmi_dai_shutdown(struct snd_pcm_substream *substream,
265f2055e14SPeter Ujfalusi 			      struct snd_soc_dai *dai)
266f2055e14SPeter Ujfalusi {
267f2055e14SPeter Ujfalusi 	struct hdmi_audio_data *ad = card_drvdata_substream(substream);
268f2055e14SPeter Ujfalusi 
269f2055e14SPeter Ujfalusi 	WARN_ON(ad->current_stream != substream);
270f2055e14SPeter Ujfalusi 
271f2055e14SPeter Ujfalusi 	ad->ops->audio_shutdown(ad->dssdev);
272f2055e14SPeter Ujfalusi 
273f2055e14SPeter Ujfalusi 	mutex_lock(&ad->current_stream_lock);
274f2055e14SPeter Ujfalusi 	ad->current_stream = NULL;
275f2055e14SPeter Ujfalusi 	mutex_unlock(&ad->current_stream_lock);
276f2055e14SPeter Ujfalusi }
277f2055e14SPeter Ujfalusi 
278f2055e14SPeter Ujfalusi static const struct snd_soc_dai_ops hdmi_dai_ops = {
279f2055e14SPeter Ujfalusi 	.startup	= hdmi_dai_startup,
280f2055e14SPeter Ujfalusi 	.hw_params	= hdmi_dai_hw_params,
281f2055e14SPeter Ujfalusi 	.trigger	= hdmi_dai_trigger,
282f2055e14SPeter Ujfalusi 	.shutdown	= hdmi_dai_shutdown,
283f2055e14SPeter Ujfalusi };
284f2055e14SPeter Ujfalusi 
285f2055e14SPeter Ujfalusi static const struct snd_soc_component_driver omap_hdmi_component = {
286f2055e14SPeter Ujfalusi 	.name = "omapdss_hdmi",
287f2055e14SPeter Ujfalusi };
288f2055e14SPeter Ujfalusi 
289f2055e14SPeter Ujfalusi static struct snd_soc_dai_driver omap5_hdmi_dai = {
290f2055e14SPeter Ujfalusi 	.name = "omap5-hdmi-dai",
291f2055e14SPeter Ujfalusi 	.playback = {
292f2055e14SPeter Ujfalusi 		.channels_min = 2,
293f2055e14SPeter Ujfalusi 		.channels_max = 8,
294f2055e14SPeter Ujfalusi 		.rates = (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |
295f2055e14SPeter Ujfalusi 			  SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 |
296f2055e14SPeter Ujfalusi 			  SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 |
297f2055e14SPeter Ujfalusi 			  SNDRV_PCM_RATE_192000),
298f2055e14SPeter Ujfalusi 		.formats = SNDRV_PCM_FMTBIT_S16_LE,
299f2055e14SPeter Ujfalusi 	},
300f2055e14SPeter Ujfalusi 	.ops = &hdmi_dai_ops,
301f2055e14SPeter Ujfalusi };
302f2055e14SPeter Ujfalusi 
303f2055e14SPeter Ujfalusi static struct snd_soc_dai_driver omap4_hdmi_dai = {
304f2055e14SPeter Ujfalusi 	.name = "omap4-hdmi-dai",
305f2055e14SPeter Ujfalusi 	.playback = {
306f2055e14SPeter Ujfalusi 		.channels_min = 2,
307f2055e14SPeter Ujfalusi 		.channels_max = 8,
308f2055e14SPeter Ujfalusi 		.rates = (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |
309f2055e14SPeter Ujfalusi 			  SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 |
310f2055e14SPeter Ujfalusi 			  SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 |
311f2055e14SPeter Ujfalusi 			  SNDRV_PCM_RATE_192000),
312f2055e14SPeter Ujfalusi 		.formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE,
313f2055e14SPeter Ujfalusi 	},
314f2055e14SPeter Ujfalusi 	.ops = &hdmi_dai_ops,
315f2055e14SPeter Ujfalusi };
316f2055e14SPeter Ujfalusi 
317f2055e14SPeter Ujfalusi static int omap_hdmi_audio_probe(struct platform_device *pdev)
318f2055e14SPeter Ujfalusi {
319f2055e14SPeter Ujfalusi 	struct omap_hdmi_audio_pdata *ha = pdev->dev.platform_data;
320f2055e14SPeter Ujfalusi 	struct device *dev = &pdev->dev;
321f2055e14SPeter Ujfalusi 	struct hdmi_audio_data *ad;
322f2055e14SPeter Ujfalusi 	struct snd_soc_dai_driver *dai_drv;
323f2055e14SPeter Ujfalusi 	struct snd_soc_card *card;
324*3b785a63SKuninori Morimoto 	struct snd_soc_dai_link_component *compnent;
325f2055e14SPeter Ujfalusi 	int ret;
326f2055e14SPeter Ujfalusi 
327f2055e14SPeter Ujfalusi 	if (!ha) {
328f2055e14SPeter Ujfalusi 		dev_err(dev, "No platform data\n");
329f2055e14SPeter Ujfalusi 		return -EINVAL;
330f2055e14SPeter Ujfalusi 	}
331f2055e14SPeter Ujfalusi 
332f2055e14SPeter Ujfalusi 	ad = devm_kzalloc(dev, sizeof(*ad), GFP_KERNEL);
333f2055e14SPeter Ujfalusi 	if (!ad)
334f2055e14SPeter Ujfalusi 		return -ENOMEM;
335f2055e14SPeter Ujfalusi 	ad->dssdev = ha->dev;
336f2055e14SPeter Ujfalusi 	ad->ops = ha->ops;
337f2055e14SPeter Ujfalusi 	ad->dma_data.addr = ha->audio_dma_addr;
338f2055e14SPeter Ujfalusi 	ad->dma_data.filter_data = "audio_tx";
339f2055e14SPeter Ujfalusi 	ad->dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
340f2055e14SPeter Ujfalusi 	mutex_init(&ad->current_stream_lock);
341f2055e14SPeter Ujfalusi 
342f2055e14SPeter Ujfalusi 	switch (ha->version) {
343f2055e14SPeter Ujfalusi 	case 4:
344f2055e14SPeter Ujfalusi 		dai_drv = &omap4_hdmi_dai;
345f2055e14SPeter Ujfalusi 		break;
346f2055e14SPeter Ujfalusi 	case 5:
347f2055e14SPeter Ujfalusi 		dai_drv = &omap5_hdmi_dai;
348f2055e14SPeter Ujfalusi 		break;
349f2055e14SPeter Ujfalusi 	default:
350f2055e14SPeter Ujfalusi 		return -EINVAL;
351f2055e14SPeter Ujfalusi 	}
352f2055e14SPeter Ujfalusi 	ret = devm_snd_soc_register_component(ad->dssdev, &omap_hdmi_component,
353f2055e14SPeter Ujfalusi 					 dai_drv, 1);
354f2055e14SPeter Ujfalusi 	if (ret)
355f2055e14SPeter Ujfalusi 		return ret;
356f2055e14SPeter Ujfalusi 
357f2055e14SPeter Ujfalusi 	ret = sdma_pcm_platform_register(ad->dssdev, "audio_tx", NULL);
358f2055e14SPeter Ujfalusi 	if (ret)
359f2055e14SPeter Ujfalusi 		return ret;
360f2055e14SPeter Ujfalusi 
361f2055e14SPeter Ujfalusi 	card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
362f2055e14SPeter Ujfalusi 	if (!card)
363f2055e14SPeter Ujfalusi 		return -ENOMEM;
364f2055e14SPeter Ujfalusi 
365f2055e14SPeter Ujfalusi 	card->name = devm_kasprintf(dev, GFP_KERNEL,
366f2055e14SPeter Ujfalusi 				    "HDMI %s", dev_name(ad->dssdev));
367f2055e14SPeter Ujfalusi 	if (!card->name)
368f2055e14SPeter Ujfalusi 		return -ENOMEM;
369f2055e14SPeter Ujfalusi 
370f2055e14SPeter Ujfalusi 	card->owner = THIS_MODULE;
371f2055e14SPeter Ujfalusi 	card->dai_link =
372f2055e14SPeter Ujfalusi 		devm_kzalloc(dev, sizeof(*(card->dai_link)), GFP_KERNEL);
373f2055e14SPeter Ujfalusi 	if (!card->dai_link)
374f2055e14SPeter Ujfalusi 		return -ENOMEM;
375*3b785a63SKuninori Morimoto 
376*3b785a63SKuninori Morimoto 	compnent = devm_kzalloc(dev, 3 * sizeof(*compnent), GFP_KERNEL);
377*3b785a63SKuninori Morimoto 	if (!compnent)
378*3b785a63SKuninori Morimoto 		return -ENOMEM;
379*3b785a63SKuninori Morimoto 	card->dai_link->cpus		= &compnent[0];
380*3b785a63SKuninori Morimoto 	card->dai_link->num_cpus	= 1;
381*3b785a63SKuninori Morimoto 	card->dai_link->codecs		= &compnent[1];
382*3b785a63SKuninori Morimoto 	card->dai_link->num_codecs	= 1;
383*3b785a63SKuninori Morimoto 	card->dai_link->platforms	= &compnent[2];
384*3b785a63SKuninori Morimoto 	card->dai_link->num_platforms	= 1;
385*3b785a63SKuninori Morimoto 
386f2055e14SPeter Ujfalusi 	card->dai_link->name = card->name;
387f2055e14SPeter Ujfalusi 	card->dai_link->stream_name = card->name;
388*3b785a63SKuninori Morimoto 	card->dai_link->cpus->dai_name = dev_name(ad->dssdev);
389*3b785a63SKuninori Morimoto 	card->dai_link->platforms->name = dev_name(ad->dssdev);
390*3b785a63SKuninori Morimoto 	card->dai_link->codecs->name = "snd-soc-dummy";
391*3b785a63SKuninori Morimoto 	card->dai_link->codecs->dai_name = "snd-soc-dummy-dai";
392f2055e14SPeter Ujfalusi 	card->num_links = 1;
393f2055e14SPeter Ujfalusi 	card->dev = dev;
394f2055e14SPeter Ujfalusi 
395f2055e14SPeter Ujfalusi 	ret = snd_soc_register_card(card);
396f2055e14SPeter Ujfalusi 	if (ret) {
397f2055e14SPeter Ujfalusi 		dev_err(dev, "snd_soc_register_card failed (%d)\n", ret);
398f2055e14SPeter Ujfalusi 		return ret;
399f2055e14SPeter Ujfalusi 	}
400f2055e14SPeter Ujfalusi 
401f2055e14SPeter Ujfalusi 	ad->card = card;
402f2055e14SPeter Ujfalusi 	snd_soc_card_set_drvdata(card, ad);
403f2055e14SPeter Ujfalusi 
404f2055e14SPeter Ujfalusi 	dev_set_drvdata(dev, ad);
405f2055e14SPeter Ujfalusi 
406f2055e14SPeter Ujfalusi 	return 0;
407f2055e14SPeter Ujfalusi }
408f2055e14SPeter Ujfalusi 
409f2055e14SPeter Ujfalusi static int omap_hdmi_audio_remove(struct platform_device *pdev)
410f2055e14SPeter Ujfalusi {
411f2055e14SPeter Ujfalusi 	struct hdmi_audio_data *ad = platform_get_drvdata(pdev);
412f2055e14SPeter Ujfalusi 
413f2055e14SPeter Ujfalusi 	snd_soc_unregister_card(ad->card);
414f2055e14SPeter Ujfalusi 	return 0;
415f2055e14SPeter Ujfalusi }
416f2055e14SPeter Ujfalusi 
417f2055e14SPeter Ujfalusi static struct platform_driver hdmi_audio_driver = {
418f2055e14SPeter Ujfalusi 	.driver = {
419f2055e14SPeter Ujfalusi 		.name = DRV_NAME,
420f2055e14SPeter Ujfalusi 	},
421f2055e14SPeter Ujfalusi 	.probe = omap_hdmi_audio_probe,
422f2055e14SPeter Ujfalusi 	.remove = omap_hdmi_audio_remove,
423f2055e14SPeter Ujfalusi };
424f2055e14SPeter Ujfalusi 
425f2055e14SPeter Ujfalusi module_platform_driver(hdmi_audio_driver);
426f2055e14SPeter Ujfalusi 
427f2055e14SPeter Ujfalusi MODULE_AUTHOR("Jyri Sarha <jsarha@ti.com>");
428f2055e14SPeter Ujfalusi MODULE_DESCRIPTION("OMAP HDMI Audio Driver");
429f2055e14SPeter Ujfalusi MODULE_LICENSE("GPL");
430f2055e14SPeter Ujfalusi MODULE_ALIAS("platform:" DRV_NAME);
431