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