Lines Matching +full:dai +full:- +full:channels

1 // SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (C) 2015 Texas Instruments Incorporated - https://www.ti.com/
16 #include <sound/hdmi-codec.h>
21 #define HDMI_CODEC_CHMAP_IDX_UNKNOWN -1
59 { .channels = 2,
64 /* Channel maps for multi-channel playbacks, up to 8 n_ch */
66 { .channels = 2, /* CA_ID 0x00 */
68 { .channels = 4, /* CA_ID 0x01 */
71 { .channels = 4, /* CA_ID 0x02 */
74 { .channels = 4, /* CA_ID 0x03 */
77 { .channels = 6, /* CA_ID 0x04 */
80 { .channels = 6, /* CA_ID 0x05 */
83 { .channels = 6, /* CA_ID 0x06 */
86 { .channels = 6, /* CA_ID 0x07 */
89 { .channels = 6, /* CA_ID 0x08 */
92 { .channels = 6, /* CA_ID 0x09 */
95 { .channels = 6, /* CA_ID 0x0A */
98 { .channels = 6, /* CA_ID 0x0B */
101 { .channels = 8, /* CA_ID 0x0C */
105 { .channels = 8, /* CA_ID 0x0D */
109 { .channels = 8, /* CA_ID 0x0E */
113 { .channels = 8, /* CA_ID 0x0F */
117 { .channels = 8, /* CA_ID 0x10 */
121 { .channels = 8, /* CA_ID 0x11 */
125 { .channels = 8, /* CA_ID 0x12 */
129 { .channels = 8, /* CA_ID 0x13 */
133 { .channels = 8, /* CA_ID 0x14 */
137 { .channels = 8, /* CA_ID 0x15 */
141 { .channels = 8, /* CA_ID 0x16 */
145 { .channels = 8, /* CA_ID 0x17 */
149 { .channels = 8, /* CA_ID 0x18 */
153 { .channels = 8, /* CA_ID 0x19 */
157 { .channels = 8, /* CA_ID 0x1A */
161 { .channels = 8, /* CA_ID 0x1B */
165 { .channels = 8, /* CA_ID 0x1C */
169 { .channels = 8, /* CA_ID 0x1D */
173 { .channels = 8, /* CA_ID 0x1E */
177 { .channels = 8, /* CA_ID 0x1F */
292 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; in hdmi_eld_ctl_info()
293 uinfo->count = sizeof_field(struct hdmi_codec_priv, eld); in hdmi_eld_ctl_info()
304 memcpy(ucontrol->value.bytes.data, hcp->eld, sizeof(hcp->eld)); in hdmi_eld_ctl_get()
331 spk_alloc = drm_eld_get_spk_alloc(hcp->eld); in hdmi_codec_eld_chmap()
334 /* Detect if only stereo supported, else return 8 channels mappings */ in hdmi_codec_eld_chmap()
335 if ((spk_mask & ~(FL | FR)) && hcp->chmap_info->max_channels > 2) in hdmi_codec_eld_chmap()
336 hcp->chmap_info->chmap = hdmi_codec_8ch_chmaps; in hdmi_codec_eld_chmap()
338 hcp->chmap_info->chmap = hdmi_codec_stereo_chmaps; in hdmi_codec_eld_chmap()
342 unsigned char channels) in hdmi_codec_get_ch_alloc_table_idx() argument
349 spk_alloc = drm_eld_get_spk_alloc(hcp->eld); in hdmi_codec_get_ch_alloc_table_idx()
354 if (!spk_alloc && cap->ca_id == 0) in hdmi_codec_get_ch_alloc_table_idx()
356 if (cap->n_ch != channels) in hdmi_codec_get_ch_alloc_table_idx()
358 if (!(cap->mask == (spk_mask & cap->mask))) in hdmi_codec_get_ch_alloc_table_idx()
363 return -EINVAL; in hdmi_codec_get_ch_alloc_table_idx()
371 struct hdmi_codec_priv *hcp = info->private_data; in hdmi_codec_chmap_ctl_get()
373 map = info->chmap[hcp->chmap_idx].map; in hdmi_codec_chmap_ctl_get()
375 for (i = 0; i < info->max_channels; i++) { in hdmi_codec_chmap_ctl_get()
376 if (hcp->chmap_idx == HDMI_CODEC_CHMAP_IDX_UNKNOWN) in hdmi_codec_chmap_ctl_get()
377 ucontrol->value.integer.value[i] = 0; in hdmi_codec_chmap_ctl_get()
379 ucontrol->value.integer.value[i] = map[i]; in hdmi_codec_chmap_ctl_get()
388 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; in hdmi_codec_iec958_info()
389 uinfo->count = 1; in hdmi_codec_iec958_info()
399 memcpy(ucontrol->value.iec958.status, hcp->iec_status, in hdmi_codec_iec958_default_get()
400 sizeof(hcp->iec_status)); in hdmi_codec_iec958_default_get()
411 memcpy(hcp->iec_status, ucontrol->value.iec958.status, in hdmi_codec_iec958_default_put()
412 sizeof(hcp->iec_status)); in hdmi_codec_iec958_default_put()
420 memset(ucontrol->value.iec958.status, 0xff, in hdmi_codec_iec958_mask_get()
427 struct snd_soc_dai *dai) in hdmi_codec_startup() argument
429 struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai); in hdmi_codec_startup()
430 bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; in hdmi_codec_startup()
433 mutex_lock(&hcp->lock); in hdmi_codec_startup()
434 if (hcp->busy) { in hdmi_codec_startup()
435 dev_err(dai->dev, "Only one simultaneous stream supported!\n"); in hdmi_codec_startup()
436 mutex_unlock(&hcp->lock); in hdmi_codec_startup()
437 return -EINVAL; in hdmi_codec_startup()
440 if (hcp->hcd.ops->audio_startup) { in hdmi_codec_startup()
441 ret = hcp->hcd.ops->audio_startup(dai->dev->parent, hcp->hcd.data); in hdmi_codec_startup()
446 if (tx && hcp->hcd.ops->get_eld) { in hdmi_codec_startup()
447 ret = hcp->hcd.ops->get_eld(dai->dev->parent, hcp->hcd.data, in hdmi_codec_startup()
448 hcp->eld, sizeof(hcp->eld)); in hdmi_codec_startup()
452 ret = snd_pcm_hw_constraint_eld(substream->runtime, hcp->eld); in hdmi_codec_startup()
460 hcp->busy = true; in hdmi_codec_startup()
463 mutex_unlock(&hcp->lock); in hdmi_codec_startup()
468 struct snd_soc_dai *dai) in hdmi_codec_shutdown() argument
470 struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai); in hdmi_codec_shutdown()
472 hcp->chmap_idx = HDMI_CODEC_CHMAP_IDX_UNKNOWN; in hdmi_codec_shutdown()
473 hcp->hcd.ops->audio_shutdown(dai->dev->parent, hcp->hcd.data); in hdmi_codec_shutdown()
475 mutex_lock(&hcp->lock); in hdmi_codec_shutdown()
476 hcp->busy = false; in hdmi_codec_shutdown()
477 mutex_unlock(&hcp->lock); in hdmi_codec_shutdown()
480 static int hdmi_codec_fill_codec_params(struct snd_soc_dai *dai, in hdmi_codec_fill_codec_params() argument
483 unsigned int channels, in hdmi_codec_fill_codec_params() argument
486 struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai); in hdmi_codec_fill_codec_params()
489 /* Select a channel allocation that matches with ELD and pcm channels */ in hdmi_codec_fill_codec_params()
490 idx = hdmi_codec_get_ch_alloc_table_idx(hcp, channels); in hdmi_codec_fill_codec_params()
492 dev_err(dai->dev, "Not able to map channels to speakers (%d)\n", in hdmi_codec_fill_codec_params()
494 hcp->chmap_idx = HDMI_CODEC_CHMAP_IDX_UNKNOWN; in hdmi_codec_fill_codec_params()
500 hdmi_audio_infoframe_init(&hp->cea); in hdmi_codec_fill_codec_params()
501 hp->cea.channels = channels; in hdmi_codec_fill_codec_params()
502 hp->cea.coding_type = HDMI_AUDIO_CODING_TYPE_STREAM; in hdmi_codec_fill_codec_params()
503 hp->cea.sample_size = HDMI_AUDIO_SAMPLE_SIZE_STREAM; in hdmi_codec_fill_codec_params()
504 hp->cea.sample_frequency = HDMI_AUDIO_SAMPLE_FREQUENCY_STREAM; in hdmi_codec_fill_codec_params()
505 hp->cea.channel_allocation = hdmi_codec_channel_alloc[idx].ca_id; in hdmi_codec_fill_codec_params()
507 hp->sample_width = sample_width; in hdmi_codec_fill_codec_params()
508 hp->sample_rate = sample_rate; in hdmi_codec_fill_codec_params()
509 hp->channels = channels; in hdmi_codec_fill_codec_params()
511 hcp->chmap_idx = hdmi_codec_channel_alloc[idx].ca_id; in hdmi_codec_fill_codec_params()
518 struct snd_soc_dai *dai) in hdmi_codec_hw_params() argument
520 struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai); in hdmi_codec_hw_params()
521 struct hdmi_codec_daifmt *cf = dai->playback_dma_data; in hdmi_codec_hw_params()
532 if (!hcp->hcd.ops->hw_params) in hdmi_codec_hw_params()
535 dev_dbg(dai->dev, "%s() width %d rate %d channels %d\n", __func__, in hdmi_codec_hw_params()
539 ret = hdmi_codec_fill_codec_params(dai, in hdmi_codec_hw_params()
547 memcpy(hp.iec.status, hcp->iec_status, sizeof(hp.iec.status)); in hdmi_codec_hw_params()
551 dev_err(dai->dev, "Creating IEC958 channel status failed %d\n", in hdmi_codec_hw_params()
556 cf->bit_fmt = params_format(params); in hdmi_codec_hw_params()
557 return hcp->hcd.ops->hw_params(dai->dev->parent, hcp->hcd.data, in hdmi_codec_hw_params()
562 struct snd_soc_dai *dai) in hdmi_codec_prepare() argument
564 struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai); in hdmi_codec_prepare()
565 struct hdmi_codec_daifmt *cf = dai->playback_dma_data; in hdmi_codec_prepare()
566 struct snd_pcm_runtime *runtime = substream->runtime; in hdmi_codec_prepare()
567 unsigned int channels = runtime->channels; in hdmi_codec_prepare() local
568 unsigned int width = snd_pcm_format_width(runtime->format); in hdmi_codec_prepare()
569 unsigned int rate = runtime->rate; in hdmi_codec_prepare()
573 if (!hcp->hcd.ops->prepare) in hdmi_codec_prepare()
576 dev_dbg(dai->dev, "%s() width %d rate %d channels %d\n", __func__, in hdmi_codec_prepare()
577 width, rate, channels); in hdmi_codec_prepare()
579 ret = hdmi_codec_fill_codec_params(dai, width, rate, channels, &hp); in hdmi_codec_prepare()
583 memcpy(hp.iec.status, hcp->iec_status, sizeof(hp.iec.status)); in hdmi_codec_prepare()
587 dev_err(dai->dev, "Creating IEC958 channel status failed %d\n", in hdmi_codec_prepare()
592 cf->bit_fmt = runtime->format; in hdmi_codec_prepare()
593 return hcp->hcd.ops->prepare(dai->dev->parent, hcp->hcd.data, in hdmi_codec_prepare()
597 static int hdmi_codec_i2s_set_fmt(struct snd_soc_dai *dai, in hdmi_codec_i2s_set_fmt() argument
600 struct hdmi_codec_daifmt *cf = dai->playback_dma_data; in hdmi_codec_i2s_set_fmt()
607 cf->bit_clk_provider = 1; in hdmi_codec_i2s_set_fmt()
608 cf->frame_clk_provider = 1; in hdmi_codec_i2s_set_fmt()
611 cf->frame_clk_provider = 1; in hdmi_codec_i2s_set_fmt()
614 cf->bit_clk_provider = 1; in hdmi_codec_i2s_set_fmt()
619 return -EINVAL; in hdmi_codec_i2s_set_fmt()
626 cf->frame_clk_inv = 1; in hdmi_codec_i2s_set_fmt()
629 cf->bit_clk_inv = 1; in hdmi_codec_i2s_set_fmt()
632 cf->frame_clk_inv = 1; in hdmi_codec_i2s_set_fmt()
633 cf->bit_clk_inv = 1; in hdmi_codec_i2s_set_fmt()
639 cf->fmt = HDMI_I2S; in hdmi_codec_i2s_set_fmt()
642 cf->fmt = HDMI_DSP_A; in hdmi_codec_i2s_set_fmt()
645 cf->fmt = HDMI_DSP_B; in hdmi_codec_i2s_set_fmt()
648 cf->fmt = HDMI_RIGHT_J; in hdmi_codec_i2s_set_fmt()
651 cf->fmt = HDMI_LEFT_J; in hdmi_codec_i2s_set_fmt()
654 cf->fmt = HDMI_AC97; in hdmi_codec_i2s_set_fmt()
657 dev_err(dai->dev, "Invalid DAI interface format\n"); in hdmi_codec_i2s_set_fmt()
658 return -EINVAL; in hdmi_codec_i2s_set_fmt()
664 static int hdmi_codec_mute(struct snd_soc_dai *dai, int mute, int direction) in hdmi_codec_mute() argument
666 struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai); in hdmi_codec_mute()
674 if (hcp->hcd.ops->mute_stream && in hdmi_codec_mute()
676 !hcp->hcd.ops->no_capture_mute)) in hdmi_codec_mute()
677 return hcp->hcd.ops->mute_stream(dai->dev->parent, in hdmi_codec_mute()
678 hcp->hcd.data, in hdmi_codec_mute()
681 return -ENOTSUPP; in hdmi_codec_mute()
689 * ${LINUX}/drivers/gpu/drm/bridge/synopsys/dw-hdmi-i2s-audio.c
732 * instance allowing the 32-bit formats enables 24-precision with CPU
733 * DAIs that do not support 24-bit formats. If the extra formats cause
767 struct snd_soc_dai *dai) in hdmi_codec_pcm_new() argument
769 struct snd_soc_dai_driver *drv = dai->driver; in hdmi_codec_pcm_new()
770 struct hdmi_codec_priv *hcp = snd_soc_dai_get_drvdata(dai); in hdmi_codec_pcm_new()
774 ret = snd_pcm_add_chmap_ctls(rtd->pcm, SNDRV_PCM_STREAM_PLAYBACK, in hdmi_codec_pcm_new()
775 NULL, drv->playback.channels_max, 0, in hdmi_codec_pcm_new()
776 &hcp->chmap_info); in hdmi_codec_pcm_new()
781 hcp->chmap_info->private_data = hcp; in hdmi_codec_pcm_new()
782 hcp->chmap_info->kctl->get = hdmi_codec_chmap_ctl_get; in hdmi_codec_pcm_new()
785 hcp->chmap_info->chmap = hdmi_codec_stereo_chmaps; in hdmi_codec_pcm_new()
786 hcp->chmap_idx = HDMI_CODEC_CHMAP_IDX_UNKNOWN; in hdmi_codec_pcm_new()
792 kctl = snd_ctl_new1(&hdmi_codec_controls[i], dai->component); in hdmi_codec_pcm_new()
794 return -ENOMEM; in hdmi_codec_pcm_new()
796 kctl->id.device = rtd->pcm->device; in hdmi_codec_pcm_new()
797 ret = snd_ctl_add(rtd->card->snd_card, kctl); in hdmi_codec_pcm_new()
805 static int hdmi_dai_probe(struct snd_soc_dai *dai) in hdmi_dai_probe() argument
812 .source = dai->driver->playback.stream_name, in hdmi_dai_probe()
815 .sink = dai->driver->capture.stream_name, in hdmi_dai_probe()
821 dapm = snd_soc_component_get_dapm(dai->component); in hdmi_dai_probe()
826 daifmt = devm_kzalloc(dai->dev, sizeof(*daifmt), GFP_KERNEL); in hdmi_dai_probe()
828 return -ENOMEM; in hdmi_dai_probe()
830 dai->playback_dma_data = daifmt; in hdmi_dai_probe()
837 if (hcp->jack && jack_status != hcp->jack_status) { in hdmi_codec_jack_report()
838 snd_soc_jack_report(hcp->jack, jack_status, SND_JACK_LINEOUT); in hdmi_codec_jack_report()
839 hcp->jack_status = jack_status; in hdmi_codec_jack_report()
848 if (hcp->hcd.ops->get_eld) { in plugged_cb()
849 hcp->hcd.ops->get_eld(dev->parent, hcp->hcd.data, in plugged_cb()
850 hcp->eld, sizeof(hcp->eld)); in plugged_cb()
855 memset(hcp->eld, 0, sizeof(hcp->eld)); in plugged_cb()
864 int ret = -ENOTSUPP; in hdmi_codec_set_jack()
866 if (hcp->hcd.ops->hook_plugged_cb) { in hdmi_codec_set_jack()
867 hcp->jack = jack; in hdmi_codec_set_jack()
868 ret = hcp->hcd.ops->hook_plugged_cb(component->dev->parent, in hdmi_codec_set_jack()
869 hcp->hcd.data, in hdmi_codec_set_jack()
871 component->dev); in hdmi_codec_set_jack()
873 hcp->jack = NULL; in hdmi_codec_set_jack()
878 static int hdmi_dai_spdif_probe(struct snd_soc_dai *dai) in hdmi_dai_spdif_probe() argument
883 ret = hdmi_dai_probe(dai); in hdmi_dai_spdif_probe()
887 cf = dai->playback_dma_data; in hdmi_dai_spdif_probe()
888 cf->fmt = HDMI_SPDIF; in hdmi_dai_spdif_probe()
894 .name = "i2s-hifi",
918 .name = "spdif-hifi",
943 int ret = -ENOTSUPP; /* see snd_soc_get_dai_id() */ in hdmi_of_xlate_dai_id()
945 if (hcp->hcd.ops->get_dai_id) in hdmi_of_xlate_dai_id()
946 ret = hcp->hcd.ops->get_dai_id(component, endpoint); in hdmi_of_xlate_dai_id()
955 if (hcp->hcd.ops->hook_plugged_cb) in hdmi_remove()
956 hcp->hcd.ops->hook_plugged_cb(component->dev->parent, in hdmi_remove()
957 hcp->hcd.data, NULL, NULL); in hdmi_remove()
973 struct hdmi_codec_pdata *hcd = pdev->dev.platform_data; in hdmi_codec_probe()
975 struct device *dev = &pdev->dev; in hdmi_codec_probe()
982 return -EINVAL; in hdmi_codec_probe()
985 dai_count = hcd->i2s + hcd->spdif; in hdmi_codec_probe()
986 if (dai_count < 1 || !hcd->ops || in hdmi_codec_probe()
987 (!hcd->ops->hw_params && !hcd->ops->prepare) || in hdmi_codec_probe()
988 !hcd->ops->audio_shutdown) { in hdmi_codec_probe()
990 return -EINVAL; in hdmi_codec_probe()
995 return -ENOMEM; in hdmi_codec_probe()
997 hcp->hcd = *hcd; in hdmi_codec_probe()
998 mutex_init(&hcp->lock); in hdmi_codec_probe()
1000 ret = snd_pcm_create_iec958_consumer_default(hcp->iec_status, in hdmi_codec_probe()
1001 sizeof(hcp->iec_status)); in hdmi_codec_probe()
1007 return -ENOMEM; in hdmi_codec_probe()
1009 if (hcd->i2s) { in hdmi_codec_probe()
1011 daidrv[i].playback.channels_max = hcd->max_i2s_channels; in hdmi_codec_probe()
1015 if (hcd->spdif) in hdmi_codec_probe()