Lines Matching +full:memcpy +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>
22 #define HDMI_CODEC_CHMAP_IDX_UNKNOWN -1
60 { .channels = 2,
65 /* Channel maps for multi-channel playbacks, up to 8 n_ch */
67 { .channels = 2, /* CA_ID 0x00 */
69 { .channels = 4, /* CA_ID 0x01 */
72 { .channels = 4, /* CA_ID 0x02 */
75 { .channels = 4, /* CA_ID 0x03 */
78 { .channels = 6, /* CA_ID 0x04 */
81 { .channels = 6, /* CA_ID 0x05 */
84 { .channels = 6, /* CA_ID 0x06 */
87 { .channels = 6, /* CA_ID 0x07 */
90 { .channels = 6, /* CA_ID 0x08 */
93 { .channels = 6, /* CA_ID 0x09 */
96 { .channels = 6, /* CA_ID 0x0A */
99 { .channels = 6, /* CA_ID 0x0B */
102 { .channels = 8, /* CA_ID 0x0C */
106 { .channels = 8, /* CA_ID 0x0D */
110 { .channels = 8, /* CA_ID 0x0E */
114 { .channels = 8, /* CA_ID 0x0F */
118 { .channels = 8, /* CA_ID 0x10 */
122 { .channels = 8, /* CA_ID 0x11 */
126 { .channels = 8, /* CA_ID 0x12 */
130 { .channels = 8, /* CA_ID 0x13 */
134 { .channels = 8, /* CA_ID 0x14 */
138 { .channels = 8, /* CA_ID 0x15 */
142 { .channels = 8, /* CA_ID 0x16 */
146 { .channels = 8, /* CA_ID 0x17 */
150 { .channels = 8, /* CA_ID 0x18 */
154 { .channels = 8, /* CA_ID 0x19 */
158 { .channels = 8, /* CA_ID 0x1A */
162 { .channels = 8, /* CA_ID 0x1B */
166 { .channels = 8, /* CA_ID 0x1C */
170 { .channels = 8, /* CA_ID 0x1D */
174 { .channels = 8, /* CA_ID 0x1E */
178 { .channels = 8, /* CA_ID 0x1F */
293 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; in hdmi_eld_ctl_info()
294 uinfo->count = sizeof_field(struct hdmi_codec_priv, eld); in hdmi_eld_ctl_info()
305 memcpy(ucontrol->value.bytes.data, hcp->eld, sizeof(hcp->eld)); in hdmi_eld_ctl_get()
332 spk_alloc = drm_eld_get_spk_alloc(hcp->eld); in hdmi_codec_eld_chmap()
335 /* Detect if only stereo supported, else return 8 channels mappings */ in hdmi_codec_eld_chmap()
336 if ((spk_mask & ~(FL | FR)) && hcp->chmap_info->max_channels > 2) in hdmi_codec_eld_chmap()
337 hcp->chmap_info->chmap = hdmi_codec_8ch_chmaps; in hdmi_codec_eld_chmap()
339 hcp->chmap_info->chmap = hdmi_codec_stereo_chmaps; in hdmi_codec_eld_chmap()
343 unsigned char channels) in hdmi_codec_get_ch_alloc_table_idx() argument
350 spk_alloc = drm_eld_get_spk_alloc(hcp->eld); in hdmi_codec_get_ch_alloc_table_idx()
355 if (!spk_alloc && cap->ca_id == 0) in hdmi_codec_get_ch_alloc_table_idx()
357 if (cap->n_ch != channels) in hdmi_codec_get_ch_alloc_table_idx()
359 if (!(cap->mask == (spk_mask & cap->mask))) in hdmi_codec_get_ch_alloc_table_idx()
364 return -EINVAL; in hdmi_codec_get_ch_alloc_table_idx()
372 struct hdmi_codec_priv *hcp = info->private_data; in hdmi_codec_chmap_ctl_get()
374 map = info->chmap[hcp->chmap_idx].map; in hdmi_codec_chmap_ctl_get()
376 for (i = 0; i < info->max_channels; i++) { in hdmi_codec_chmap_ctl_get()
377 if (hcp->chmap_idx == HDMI_CODEC_CHMAP_IDX_UNKNOWN) in hdmi_codec_chmap_ctl_get()
378 ucontrol->value.integer.value[i] = 0; in hdmi_codec_chmap_ctl_get()
380 ucontrol->value.integer.value[i] = map[i]; in hdmi_codec_chmap_ctl_get()
389 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; in hdmi_codec_iec958_info()
390 uinfo->count = 1; in hdmi_codec_iec958_info()
400 memcpy(ucontrol->value.iec958.status, hcp->iec_status, in hdmi_codec_iec958_default_get()
401 sizeof(hcp->iec_status)); in hdmi_codec_iec958_default_get()
412 memcpy(hcp->iec_status, ucontrol->value.iec958.status, in hdmi_codec_iec958_default_put()
413 sizeof(hcp->iec_status)); in hdmi_codec_iec958_default_put()
421 memset(ucontrol->value.iec958.status, 0xff, in hdmi_codec_iec958_mask_get()
431 bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; in hdmi_codec_startup()
432 bool has_capture = !hcp->hcd.no_i2s_capture; in hdmi_codec_startup()
433 bool has_playback = !hcp->hcd.no_i2s_playback; in hdmi_codec_startup()
439 mutex_lock(&hcp->lock); in hdmi_codec_startup()
440 if (hcp->busy) { in hdmi_codec_startup()
441 dev_err(dai->dev, "Only one simultaneous stream supported!\n"); in hdmi_codec_startup()
442 mutex_unlock(&hcp->lock); in hdmi_codec_startup()
443 return -EINVAL; in hdmi_codec_startup()
446 if (hcp->hcd.ops->audio_startup) { in hdmi_codec_startup()
447 ret = hcp->hcd.ops->audio_startup(dai->dev->parent, hcp->hcd.data); in hdmi_codec_startup()
452 if (tx && hcp->hcd.ops->get_eld) { in hdmi_codec_startup()
453 ret = hcp->hcd.ops->get_eld(dai->dev->parent, hcp->hcd.data, in hdmi_codec_startup()
454 hcp->eld, sizeof(hcp->eld)); in hdmi_codec_startup()
458 ret = snd_pcm_hw_constraint_eld(substream->runtime, hcp->eld); in hdmi_codec_startup()
466 hcp->busy = true; in hdmi_codec_startup()
469 mutex_unlock(&hcp->lock); in hdmi_codec_startup()
477 bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; in hdmi_codec_shutdown()
478 bool has_capture = !hcp->hcd.no_i2s_capture; in hdmi_codec_shutdown()
479 bool has_playback = !hcp->hcd.no_i2s_playback; in hdmi_codec_shutdown()
484 hcp->chmap_idx = HDMI_CODEC_CHMAP_IDX_UNKNOWN; in hdmi_codec_shutdown()
485 hcp->hcd.ops->audio_shutdown(dai->dev->parent, hcp->hcd.data); in hdmi_codec_shutdown()
487 mutex_lock(&hcp->lock); in hdmi_codec_shutdown()
488 hcp->busy = false; in hdmi_codec_shutdown()
489 mutex_unlock(&hcp->lock); in hdmi_codec_shutdown()
495 unsigned int channels, in hdmi_codec_fill_codec_params() argument
501 bool pcm_audio = !(hcp->iec_status[0] & IEC958_AES0_NONAUDIO); in hdmi_codec_fill_codec_params()
504 /* Select a channel allocation that matches with ELD and pcm channels */ in hdmi_codec_fill_codec_params()
505 idx = hdmi_codec_get_ch_alloc_table_idx(hcp, channels); in hdmi_codec_fill_codec_params()
508 dev_err(dai->dev, "Not able to map channels to speakers (%d)\n", in hdmi_codec_fill_codec_params()
510 hcp->chmap_idx = HDMI_CODEC_CHMAP_IDX_UNKNOWN; in hdmi_codec_fill_codec_params()
519 hdmi_audio_infoframe_init(&hp->cea); in hdmi_codec_fill_codec_params()
522 hp->cea.channels = channels; in hdmi_codec_fill_codec_params()
524 hp->cea.channels = 0; in hdmi_codec_fill_codec_params()
526 hp->cea.coding_type = HDMI_AUDIO_CODING_TYPE_STREAM; in hdmi_codec_fill_codec_params()
527 hp->cea.sample_size = HDMI_AUDIO_SAMPLE_SIZE_STREAM; in hdmi_codec_fill_codec_params()
528 hp->cea.sample_frequency = HDMI_AUDIO_SAMPLE_FREQUENCY_STREAM; in hdmi_codec_fill_codec_params()
529 hp->cea.channel_allocation = ca_id; in hdmi_codec_fill_codec_params()
531 hp->sample_width = sample_width; in hdmi_codec_fill_codec_params()
532 hp->sample_rate = sample_rate; in hdmi_codec_fill_codec_params()
533 hp->channels = channels; in hdmi_codec_fill_codec_params()
536 hcp->chmap_idx = ca_id; in hdmi_codec_fill_codec_params()
538 hcp->chmap_idx = HDMI_CODEC_CHMAP_IDX_UNKNOWN; in hdmi_codec_fill_codec_params()
559 if (!hcp->hcd.ops->hw_params) in hdmi_codec_hw_params()
562 dev_dbg(dai->dev, "%s() width %d rate %d channels %d\n", __func__, in hdmi_codec_hw_params()
574 memcpy(hp.iec.status, hcp->iec_status, sizeof(hp.iec.status)); in hdmi_codec_hw_params()
578 dev_err(dai->dev, "Creating IEC958 channel status failed %d\n", in hdmi_codec_hw_params()
583 cf->bit_fmt = params_format(params); in hdmi_codec_hw_params()
584 return hcp->hcd.ops->hw_params(dai->dev->parent, hcp->hcd.data, in hdmi_codec_hw_params()
593 struct snd_pcm_runtime *runtime = substream->runtime; in hdmi_codec_prepare()
594 unsigned int channels = runtime->channels; in hdmi_codec_prepare() local
595 unsigned int width = snd_pcm_format_width(runtime->format); in hdmi_codec_prepare()
596 unsigned int rate = runtime->rate; in hdmi_codec_prepare()
600 if (!hcp->hcd.ops->prepare) in hdmi_codec_prepare()
603 dev_dbg(dai->dev, "%s() width %d rate %d channels %d\n", __func__, in hdmi_codec_prepare()
604 width, rate, channels); in hdmi_codec_prepare()
606 ret = hdmi_codec_fill_codec_params(dai, width, rate, channels, &hp); in hdmi_codec_prepare()
610 memcpy(hp.iec.status, hcp->iec_status, sizeof(hp.iec.status)); in hdmi_codec_prepare()
614 dev_err(dai->dev, "Creating IEC958 channel status failed %d\n", in hdmi_codec_prepare()
619 cf->bit_fmt = runtime->format; in hdmi_codec_prepare()
620 return hcp->hcd.ops->prepare(dai->dev->parent, hcp->hcd.data, in hdmi_codec_prepare()
634 cf->bit_clk_provider = 1; in hdmi_codec_i2s_set_fmt()
635 cf->frame_clk_provider = 1; in hdmi_codec_i2s_set_fmt()
638 cf->frame_clk_provider = 1; in hdmi_codec_i2s_set_fmt()
641 cf->bit_clk_provider = 1; in hdmi_codec_i2s_set_fmt()
646 return -EINVAL; in hdmi_codec_i2s_set_fmt()
653 cf->frame_clk_inv = 1; in hdmi_codec_i2s_set_fmt()
656 cf->bit_clk_inv = 1; in hdmi_codec_i2s_set_fmt()
659 cf->frame_clk_inv = 1; in hdmi_codec_i2s_set_fmt()
660 cf->bit_clk_inv = 1; in hdmi_codec_i2s_set_fmt()
666 cf->fmt = HDMI_I2S; in hdmi_codec_i2s_set_fmt()
669 cf->fmt = HDMI_DSP_A; in hdmi_codec_i2s_set_fmt()
672 cf->fmt = HDMI_DSP_B; in hdmi_codec_i2s_set_fmt()
675 cf->fmt = HDMI_RIGHT_J; in hdmi_codec_i2s_set_fmt()
678 cf->fmt = HDMI_LEFT_J; in hdmi_codec_i2s_set_fmt()
681 cf->fmt = HDMI_AC97; in hdmi_codec_i2s_set_fmt()
684 dev_err(dai->dev, "Invalid DAI interface format\n"); in hdmi_codec_i2s_set_fmt()
685 return -EINVAL; in hdmi_codec_i2s_set_fmt()
701 if (hcp->hcd.ops->mute_stream && in hdmi_codec_mute()
703 !hcp->hcd.ops->no_capture_mute)) in hdmi_codec_mute()
704 return hcp->hcd.ops->mute_stream(dai->dev->parent, in hdmi_codec_mute()
705 hcp->hcd.data, in hdmi_codec_mute()
708 return -ENOTSUPP; in hdmi_codec_mute()
716 * ${LINUX}/drivers/gpu/drm/bridge/synopsys/dw-hdmi-i2s-audio.c
741 * instance allowing the 32-bit formats enables 24-precision with CPU
742 * DAIs that do not support 24-bit formats. If the extra formats cause
778 struct snd_soc_dai_driver *drv = dai->driver; in hdmi_codec_pcm_new()
783 ret = snd_pcm_add_chmap_ctls(rtd->pcm, SNDRV_PCM_STREAM_PLAYBACK, in hdmi_codec_pcm_new()
784 NULL, drv->playback.channels_max, 0, in hdmi_codec_pcm_new()
785 &hcp->chmap_info); in hdmi_codec_pcm_new()
790 hcp->chmap_info->private_data = hcp; in hdmi_codec_pcm_new()
791 hcp->chmap_info->kctl->get = hdmi_codec_chmap_ctl_get; in hdmi_codec_pcm_new()
794 hcp->chmap_info->chmap = hdmi_codec_stereo_chmaps; in hdmi_codec_pcm_new()
795 hcp->chmap_idx = HDMI_CODEC_CHMAP_IDX_UNKNOWN; in hdmi_codec_pcm_new()
801 kctl = snd_ctl_new1(&hdmi_codec_controls[i], dai->component); in hdmi_codec_pcm_new()
803 return -ENOMEM; in hdmi_codec_pcm_new()
805 kctl->id.device = rtd->pcm->device; in hdmi_codec_pcm_new()
806 ret = snd_ctl_add(rtd->card->snd_card, kctl); in hdmi_codec_pcm_new()
821 .source = dai->driver->playback.stream_name, in hdmi_dai_probe()
824 .sink = dai->driver->capture.stream_name, in hdmi_dai_probe()
830 dapm = snd_soc_component_get_dapm(dai->component); in hdmi_dai_probe()
842 daifmt = devm_kzalloc(dai->dev, sizeof(*daifmt), GFP_KERNEL); in hdmi_dai_probe()
844 return -ENOMEM; in hdmi_dai_probe()
854 if (jack_status != hcp->jack_status) { in hdmi_codec_jack_report()
855 if (hcp->jack) in hdmi_codec_jack_report()
856 snd_soc_jack_report(hcp->jack, jack_status, SND_JACK_LINEOUT); in hdmi_codec_jack_report()
857 hcp->jack_status = jack_status; in hdmi_codec_jack_report()
866 if (hcp->hcd.ops->get_eld) { in plugged_cb()
867 hcp->hcd.ops->get_eld(dev->parent, hcp->hcd.data, in plugged_cb()
868 hcp->eld, sizeof(hcp->eld)); in plugged_cb()
873 memset(hcp->eld, 0, sizeof(hcp->eld)); in plugged_cb()
883 if (hcp->hcd.ops->hook_plugged_cb) { in hdmi_codec_set_jack()
884 hcp->jack = jack; in hdmi_codec_set_jack()
890 snd_soc_jack_report(jack, hcp->jack_status, SND_JACK_LINEOUT); in hdmi_codec_set_jack()
895 return -ENOTSUPP; in hdmi_codec_set_jack()
908 cf->fmt = HDMI_SPDIF; in hdmi_dai_spdif_probe()
936 .name = "i2s-hifi",
958 .name = "spdif-hifi",
981 int ret = -ENOTSUPP; /* see snd_soc_get_dai_id() */ in hdmi_of_xlate_dai_id()
983 if (hcp->hcd.ops->get_dai_id) in hdmi_of_xlate_dai_id()
984 ret = hcp->hcd.ops->get_dai_id(component, endpoint); in hdmi_of_xlate_dai_id()
994 if (hcp->hcd.ops->hook_plugged_cb) { in hdmi_probe()
995 ret = hcp->hcd.ops->hook_plugged_cb(component->dev->parent, in hdmi_probe()
996 hcp->hcd.data, in hdmi_probe()
998 component->dev); in hdmi_probe()
1008 if (hcp->hcd.ops->hook_plugged_cb) in hdmi_remove()
1009 hcp->hcd.ops->hook_plugged_cb(component->dev->parent, in hdmi_remove()
1010 hcp->hcd.data, NULL, NULL); in hdmi_remove()
1027 struct hdmi_codec_pdata *hcd = pdev->dev.platform_data; in hdmi_codec_probe()
1029 struct device *dev = &pdev->dev; in hdmi_codec_probe()
1036 return -EINVAL; in hdmi_codec_probe()
1039 dai_count = hcd->i2s + hcd->spdif; in hdmi_codec_probe()
1040 if (dai_count < 1 || !hcd->ops || in hdmi_codec_probe()
1041 (!hcd->ops->hw_params && !hcd->ops->prepare) || in hdmi_codec_probe()
1042 !hcd->ops->audio_shutdown) { in hdmi_codec_probe()
1044 return -EINVAL; in hdmi_codec_probe()
1049 return -ENOMEM; in hdmi_codec_probe()
1051 hcp->hcd = *hcd; in hdmi_codec_probe()
1052 mutex_init(&hcp->lock); in hdmi_codec_probe()
1054 ret = snd_pcm_create_iec958_consumer_default(hcp->iec_status, in hdmi_codec_probe()
1055 sizeof(hcp->iec_status)); in hdmi_codec_probe()
1061 return -ENOMEM; in hdmi_codec_probe()
1063 if (hcd->i2s) { in hdmi_codec_probe()
1065 daidrv[i].playback.channels_max = hcd->max_i2s_channels; in hdmi_codec_probe()
1066 if (hcd->no_i2s_playback) in hdmi_codec_probe()
1069 if (hcd->no_i2s_capture) in hdmi_codec_probe()
1075 if (hcd->spdif) { in hdmi_codec_probe()
1077 if (hcd->no_spdif_playback) in hdmi_codec_probe()
1080 if (hcd->no_spdif_capture) in hdmi_codec_probe()