Lines Matching +full:link +full:- +full:trigger +full:- +full:order +full:- +full:stop

1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
12 #include "sof-priv.h"
13 #include "sof-audio.h"
14 #include "ipc3-priv.h"
92 /* BE DAI link */
337 [SOF_DAI_LINK_TOKENS] = {"DAI link tokens", dai_link_tokens, ARRAY_SIZE(dai_link_tokens)},
354 * sof_comp_alloc - allocate and initialize buffer for a new component
367 size_t ext_size = sizeof(swidget->uuid);
369 /* only non-zero UUID is valid */
370 if (!guid_is_null(&swidget->uuid))
378 comp->hdr.size = total_size;
379 comp->hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_COMP_NEW;
380 comp->id = swidget->comp_id;
381 comp->pipeline_id = index;
382 comp->core = swidget->core;
387 memcpy((u8 *)comp + *ipc_size, &swidget->uuid, ext_size);
388 comp->ext_data_length = ext_size;
398 dev_dbg(scomp->dev, " config: periods snk %d src %d fmt %d\n",
399 config->periods_sink, config->periods_source,
400 config->frame_fmt);
405 struct snd_soc_component *scomp = swidget->scomp;
410 host = sof_comp_alloc(swidget, &ipc_size, swidget->pipeline_id);
412 return -ENOMEM;
413 swidget->private = host;
416 host->comp.type = SOF_COMP_HOST;
417 host->config.hdr.size = sizeof(host->config);
419 if (swidget->id == snd_soc_dapm_aif_out)
420 host->direction = SOF_IPC_STREAM_CAPTURE;
422 host->direction = SOF_IPC_STREAM_PLAYBACK;
425 ret = sof_update_ipc_object(scomp, host, SOF_PCM_TOKENS, swidget->tuples,
426 swidget->num_tuples, sizeof(*host), 1);
431 ret = sof_update_ipc_object(scomp, &host->config, SOF_COMP_TOKENS, swidget->tuples,
432 swidget->num_tuples, sizeof(host->config), 1);
436 dev_dbg(scomp->dev, "loaded host %s\n", swidget->widget->name);
437 sof_dbg_comp_config(scomp, &host->config);
441 kfree(swidget->private);
442 swidget->private = NULL;
449 kfree(swidget->private);
454 struct snd_soc_component *scomp = swidget->scomp;
459 tone = sof_comp_alloc(swidget, &ipc_size, swidget->pipeline_id);
461 return -ENOMEM;
463 swidget->private = tone;
466 tone->comp.type = SOF_COMP_TONE;
467 tone->config.hdr.size = sizeof(tone->config);
470 ret = sof_update_ipc_object(scomp, &tone->config, SOF_COMP_TOKENS, swidget->tuples,
471 swidget->num_tuples, sizeof(tone->config), 1);
473 kfree(swidget->private);
474 swidget->private = NULL;
478 dev_dbg(scomp->dev, "tone %s: frequency %d amplitude %d\n",
479 swidget->widget->name, tone->frequency, tone->amplitude);
480 sof_dbg_comp_config(scomp, &tone->config);
487 struct snd_soc_component *scomp = swidget->scomp;
492 mixer = sof_comp_alloc(swidget, &ipc_size, swidget->pipeline_id);
494 return -ENOMEM;
496 swidget->private = mixer;
499 mixer->comp.type = SOF_COMP_MIXER;
500 mixer->config.hdr.size = sizeof(mixer->config);
503 ret = sof_update_ipc_object(scomp, &mixer->config, SOF_COMP_TOKENS,
504 swidget->tuples, swidget->num_tuples,
505 sizeof(mixer->config), 1);
507 kfree(swidget->private);
508 swidget->private = NULL;
513 dev_dbg(scomp->dev, "loaded mixer %s\n", swidget->widget->name);
514 sof_dbg_comp_config(scomp, &mixer->config);
521 struct snd_soc_component *scomp = swidget->scomp;
522 struct snd_sof_pipeline *spipe = swidget->spipe;
529 return -ENOMEM;
532 pipeline->hdr.size = sizeof(*pipeline);
533 pipeline->hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_PIPE_NEW;
534 pipeline->pipeline_id = swidget->pipeline_id;
535 pipeline->comp_id = swidget->comp_id;
537 swidget->private = pipeline;
540 comp_swidget = snd_sof_find_swidget(scomp, swidget->widget->sname);
542 dev_err(scomp->dev, "scheduler %s refers to non existent widget %s\n",
543 swidget->widget->name, swidget->widget->sname);
544 ret = -EINVAL;
548 pipeline->sched_id = comp_swidget->comp_id;
551 ret = sof_update_ipc_object(scomp, pipeline, SOF_SCHED_TOKENS, swidget->tuples,
552 swidget->num_tuples, sizeof(*pipeline), 1);
557 ret = sof_update_ipc_object(scomp, swidget, SOF_PIPELINE_TOKENS, swidget->tuples,
558 swidget->num_tuples, sizeof(*swidget), 1);
563 pipeline->core = SOF_DSP_PRIMARY_CORE;
566 swidget->dynamic_pipeline_widget =
569 dev_dbg(scomp->dev, "pipeline %s: period %d pri %d mips %d core %d frames %d dynamic %d\n",
570 swidget->widget->name, pipeline->period, pipeline->priority,
571 pipeline->period_mips, pipeline->core, pipeline->frames_per_sched,
572 swidget->dynamic_pipeline_widget);
574 swidget->core = pipeline->core;
575 spipe->core_mask |= BIT(pipeline->core);
580 kfree(swidget->private);
581 swidget->private = NULL;
588 struct snd_soc_component *scomp = swidget->scomp;
594 return -ENOMEM;
596 swidget->private = buffer;
599 buffer->comp.hdr.size = sizeof(*buffer);
600 buffer->comp.hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_BUFFER_NEW;
601 buffer->comp.id = swidget->comp_id;
602 buffer->comp.type = SOF_COMP_BUFFER;
603 buffer->comp.pipeline_id = swidget->pipeline_id;
604 buffer->comp.core = swidget->core;
607 ret = sof_update_ipc_object(scomp, buffer, SOF_BUFFER_TOKENS, swidget->tuples,
608 swidget->num_tuples, sizeof(*buffer), 1);
610 kfree(swidget->private);
611 swidget->private = NULL;
615 dev_dbg(scomp->dev, "buffer %s: size %d caps 0x%x\n",
616 swidget->widget->name, buffer->size, buffer->caps);
623 struct snd_soc_component *scomp = swidget->scomp;
628 src = sof_comp_alloc(swidget, &ipc_size, swidget->pipeline_id);
630 return -ENOMEM;
632 swidget->private = src;
635 src->comp.type = SOF_COMP_SRC;
636 src->config.hdr.size = sizeof(src->config);
639 ret = sof_update_ipc_object(scomp, src, SOF_SRC_TOKENS, swidget->tuples,
640 swidget->num_tuples, sizeof(*src), 1);
645 ret = sof_update_ipc_object(scomp, &src->config, SOF_COMP_TOKENS,
646 swidget->tuples, swidget->num_tuples, sizeof(src->config), 1);
650 dev_dbg(scomp->dev, "src %s: source rate %d sink rate %d\n",
651 swidget->widget->name, src->source_rate, src->sink_rate);
652 sof_dbg_comp_config(scomp, &src->config);
656 kfree(swidget->private);
657 swidget->private = NULL;
664 struct snd_soc_component *scomp = swidget->scomp;
669 asrc = sof_comp_alloc(swidget, &ipc_size, swidget->pipeline_id);
671 return -ENOMEM;
673 swidget->private = asrc;
676 asrc->comp.type = SOF_COMP_ASRC;
677 asrc->config.hdr.size = sizeof(asrc->config);
680 ret = sof_update_ipc_object(scomp, asrc, SOF_ASRC_TOKENS, swidget->tuples,
681 swidget->num_tuples, sizeof(*asrc), 1);
686 ret = sof_update_ipc_object(scomp, &asrc->config, SOF_COMP_TOKENS,
687 swidget->tuples, swidget->num_tuples, sizeof(asrc->config), 1);
691 dev_dbg(scomp->dev, "asrc %s: source rate %d sink rate %d asynch %d operation %d\n",
692 swidget->widget->name, asrc->source_rate, asrc->sink_rate,
693 asrc->asynchronous_mode, asrc->operation_mode);
695 sof_dbg_comp_config(scomp, &asrc->config);
699 kfree(swidget->private);
700 swidget->private = NULL;
710 struct snd_soc_component *scomp = swidget->scomp;
715 mux = sof_comp_alloc(swidget, &ipc_size, swidget->pipeline_id);
717 return -ENOMEM;
719 swidget->private = mux;
722 mux->comp.type = SOF_COMP_MUX;
723 mux->config.hdr.size = sizeof(mux->config);
726 ret = sof_update_ipc_object(scomp, &mux->config, SOF_COMP_TOKENS,
727 swidget->tuples, swidget->num_tuples, sizeof(mux->config), 1);
729 kfree(swidget->private);
730 swidget->private = NULL;
734 dev_dbg(scomp->dev, "loaded mux %s\n", swidget->widget->name);
735 sof_dbg_comp_config(scomp, &mux->config);
746 struct snd_soc_component *scomp = swidget->scomp;
754 volume = sof_comp_alloc(swidget, &ipc_size, swidget->pipeline_id);
756 return -ENOMEM;
758 swidget->private = volume;
761 volume->comp.type = SOF_COMP_VOLUME;
762 volume->config.hdr.size = sizeof(volume->config);
765 ret = sof_update_ipc_object(scomp, volume, SOF_VOLUME_TOKENS, swidget->tuples,
766 swidget->num_tuples, sizeof(*volume), 1);
771 ret = sof_update_ipc_object(scomp, &volume->config, SOF_COMP_TOKENS,
772 swidget->tuples, swidget->num_tuples,
773 sizeof(volume->config), 1);
777 dev_dbg(scomp->dev, "loaded PGA %s\n", swidget->widget->name);
778 sof_dbg_comp_config(scomp, &volume->config);
780 list_for_each_entry(scontrol, &sdev->kcontrol_list, list) {
781 if (scontrol->comp_id == swidget->comp_id &&
782 scontrol->volume_table) {
783 min_step = scontrol->min_volume_step;
784 max_step = scontrol->max_volume_step;
785 volume->min_value = scontrol->volume_table[min_step];
786 volume->max_value = scontrol->volume_table[max_step];
787 volume->channels = scontrol->num_channels;
794 kfree(swidget->private);
795 swidget->private = NULL;
813 for (i = 0; i < widget->num_kcontrols; i++) {
814 kc = &widget->kcontrol_news[i];
816 switch (widget->dobj.widget.kcontrol_type[i]) {
818 sm = (struct soc_mixer_control *)kc->private_value;
819 wdata[i].control = sm->dobj.private;
822 sbe = (struct soc_bytes_ext *)kc->private_value;
823 wdata[i].control = sbe->dobj.private;
826 se = (struct soc_enum *)kc->private_value;
827 wdata[i].control = se->dobj.private;
830 dev_err(scomp->dev, "Unknown kcontrol type %u in widget %s\n",
831 widget->dobj.widget.kcontrol_type[i], widget->name);
832 return -EINVAL;
836 dev_err(scomp->dev, "No scontrol for widget %s\n", widget->name);
837 return -EINVAL;
840 cdata = wdata[i].control->ipc_control_data;
842 if (widget->dobj.widget.kcontrol_type[i] == SND_SOC_TPLG_TYPE_BYTES) {
843 /* make sure data is valid - data can be updated at runtime */
844 if (cdata->data->magic != SOF_ABI_MAGIC)
845 return -EINVAL;
847 wdata[i].pdata = cdata->data->data;
848 wdata[i].pdata_size = cdata->data->size;
851 wdata[i].pdata = cdata->chanv;
853 * wdata[i].control->size is calculated with struct_size
856 wdata[i].pdata_size = wdata[i].control->size -
863 switch (cdata->cmd) {
885 struct snd_soc_dapm_widget *widget = swidget->widget;
895 if (widget->num_kcontrols) {
896 wdata = kcalloc(widget->num_kcontrols, sizeof(*wdata), GFP_KERNEL);
898 return -ENOMEM;
910 ipc_size -= ipc_data_size;
914 process = sof_comp_alloc(swidget, &ipc_size, swidget->pipeline_id);
916 ret = -ENOMEM;
920 swidget->private = process;
923 process->comp.type = type;
924 process->config.hdr.size = sizeof(process->config);
927 ret = sof_update_ipc_object(scomp, &process->config, SOF_COMP_TOKENS,
928 swidget->tuples, swidget->num_tuples,
929 sizeof(process->config), 1);
933 dev_dbg(scomp->dev, "loaded process %s\n", swidget->widget->name);
934 sof_dbg_comp_config(scomp, &process->config);
938 * get possible component controls - get size of all pdata,
942 for (i = 0; i < widget->num_kcontrols; i++) {
946 memcpy(&process->data[offset], wdata[i].pdata,
952 process->size = ipc_data_size;
958 kfree(swidget->private);
959 swidget->private = NULL;
978 * Processing Component Topology - can be "effect", "codec", or general
984 struct snd_soc_component *scomp = swidget->scomp;
989 config.comp.core = swidget->core;
992 ret = sof_update_ipc_object(scomp, &config, SOF_PROCESS_TOKENS, swidget->tuples,
993 swidget->num_tuples, sizeof(config), 1);
1004 struct sof_dai_private_data *private = dai->private;
1009 memset(&config->hda, 0, sizeof(config->hda));
1010 config->hdr.size = size;
1013 ret = sof_update_ipc_object(scomp, &config->hda, SOF_HDA_TOKENS, slink->tuples,
1014 slink->num_tuples, size, 1);
1018 dev_dbg(scomp->dev, "HDA config rate %d channels %d\n",
1019 config->hda.rate, config->hda.channels);
1021 config->hda.link_dma_ch = DMA_CHAN_INVALID;
1023 dai->number_configs = 1;
1024 dai->current_config = 0;
1025 private->dai_config = kmemdup(config, size, GFP_KERNEL);
1026 if (!private->dai_config)
1027 return -ENOMEM;
1036 config->format &= ~SOF_DAI_FMT_CLOCK_PROVIDER_MASK;
1037 if (hw_config->bclk_provider == SND_SOC_TPLG_BCLK_CP) {
1039 if (hw_config->fsync_provider == SND_SOC_TPLG_FSYNC_CP)
1040 config->format |= SOF_DAI_FMT_CBP_CFP;
1042 config->format |= SOF_DAI_FMT_CBP_CFC;
1045 if (hw_config->fsync_provider == SND_SOC_TPLG_FSYNC_CP)
1046 config->format |= SOF_DAI_FMT_CBC_CFP;
1048 config->format |= SOF_DAI_FMT_CBC_CFC;
1052 config->format &= ~SOF_DAI_FMT_INV_MASK;
1053 if (hw_config->invert_bclk) {
1054 if (hw_config->invert_fsync)
1055 config->format |= SOF_DAI_FMT_IB_IF;
1057 config->format |= SOF_DAI_FMT_IB_NF;
1059 if (hw_config->invert_fsync)
1060 config->format |= SOF_DAI_FMT_NB_IF;
1062 config->format |= SOF_DAI_FMT_NB_NF;
1069 struct snd_soc_tplg_hw_config *hw_config = slink->hw_configs;
1070 struct sof_dai_private_data *private = dai->private;
1078 memset(&config->sai, 0, sizeof(config->sai));
1079 config->hdr.size = size;
1082 ret = sof_update_ipc_object(scomp, &config->sai, SOF_SAI_TOKENS, slink->tuples,
1083 slink->num_tuples, size, 1);
1087 config->sai.mclk_rate = le32_to_cpu(hw_config->mclk_rate);
1088 config->sai.bclk_rate = le32_to_cpu(hw_config->bclk_rate);
1089 config->sai.fsync_rate = le32_to_cpu(hw_config->fsync_rate);
1090 config->sai.mclk_direction = hw_config->mclk_direction;
1092 config->sai.tdm_slots = le32_to_cpu(hw_config->tdm_slots);
1093 config->sai.tdm_slot_width = le32_to_cpu(hw_config->tdm_slot_width);
1094 config->sai.rx_slots = le32_to_cpu(hw_config->rx_slots);
1095 config->sai.tx_slots = le32_to_cpu(hw_config->tx_slots);
1097 dev_info(scomp->dev,
1099 config->dai_index, config->format,
1100 config->sai.mclk_rate, config->sai.tdm_slot_width,
1101 config->sai.tdm_slots, config->sai.mclk_id);
1103 if (config->sai.tdm_slots < 1 || config->sai.tdm_slots > 8) {
1104 dev_err(scomp->dev, "Invalid channel count for SAI%d\n", config->dai_index);
1105 return -EINVAL;
1108 dai->number_configs = 1;
1109 dai->current_config = 0;
1110 private->dai_config = kmemdup(config, size, GFP_KERNEL);
1111 if (!private->dai_config)
1112 return -ENOMEM;
1120 struct snd_soc_tplg_hw_config *hw_config = slink->hw_configs;
1121 struct sof_dai_private_data *private = dai->private;
1129 memset(&config->esai, 0, sizeof(config->esai));
1130 config->hdr.size = size;
1133 ret = sof_update_ipc_object(scomp, &config->esai, SOF_ESAI_TOKENS, slink->tuples,
1134 slink->num_tuples, size, 1);
1138 config->esai.mclk_rate = le32_to_cpu(hw_config->mclk_rate);
1139 config->esai.bclk_rate = le32_to_cpu(hw_config->bclk_rate);
1140 config->esai.fsync_rate = le32_to_cpu(hw_config->fsync_rate);
1141 config->esai.mclk_direction = hw_config->mclk_direction;
1142 config->esai.tdm_slots = le32_to_cpu(hw_config->tdm_slots);
1143 config->esai.tdm_slot_width = le32_to_cpu(hw_config->tdm_slot_width);
1144 config->esai.rx_slots = le32_to_cpu(hw_config->rx_slots);
1145 config->esai.tx_slots = le32_to_cpu(hw_config->tx_slots);
1147 dev_info(scomp->dev,
1149 config->dai_index, config->format,
1150 config->esai.mclk_rate, config->esai.tdm_slot_width,
1151 config->esai.tdm_slots, config->esai.mclk_id);
1153 if (config->esai.tdm_slots < 1 || config->esai.tdm_slots > 8) {
1154 dev_err(scomp->dev, "Invalid channel count for ESAI%d\n", config->dai_index);
1155 return -EINVAL;
1158 dai->number_configs = 1;
1159 dai->current_config = 0;
1160 private->dai_config = kmemdup(config, size, GFP_KERNEL);
1161 if (!private->dai_config)
1162 return -ENOMEM;
1170 struct snd_soc_tplg_hw_config *hw_config = slink->hw_configs;
1171 struct sof_dai_private_data *private = dai->private;
1178 config->hdr.size = size;
1181 ret = sof_update_ipc_object(scomp, &config->micfil, SOF_MICFIL_TOKENS, slink->tuples,
1182 slink->num_tuples, size, slink->num_hw_configs);
1186 dev_info(scomp->dev, "MICFIL PDM config dai_index %d channel %d rate %d\n",
1187 config->dai_index, config->micfil.pdm_ch, config->micfil.pdm_rate);
1189 dai->number_configs = 1;
1190 dai->current_config = 0;
1191 private->dai_config = kmemdup(config, size, GFP_KERNEL);
1192 if (!private->dai_config)
1193 return -ENOMEM;
1201 struct snd_soc_tplg_hw_config *hw_config = slink->hw_configs;
1202 struct sof_dai_private_data *private = dai->private;
1209 config->hdr.size = size;
1212 ret = sof_update_ipc_object(scomp, &config->acpdmic, SOF_ACPDMIC_TOKENS, slink->tuples,
1213 slink->num_tuples, size, slink->num_hw_configs);
1217 dev_info(scomp->dev, "ACP_DMIC config ACP%d channel %d rate %d\n",
1218 config->dai_index, config->acpdmic.pdm_ch,
1219 config->acpdmic.pdm_rate);
1221 dai->number_configs = 1;
1222 dai->current_config = 0;
1223 private->dai_config = kmemdup(config, size, GFP_KERNEL);
1224 if (!private->dai_config)
1225 return -ENOMEM;
1233 struct snd_soc_tplg_hw_config *hw_config = slink->hw_configs;
1234 struct sof_dai_private_data *private = dai->private;
1242 memset(&config->acpbt, 0, sizeof(config->acpbt));
1243 config->hdr.size = size;
1245 ret = sof_update_ipc_object(scomp, &config->acpbt, SOF_ACPI2S_TOKENS, slink->tuples,
1246 slink->num_tuples, size, slink->num_hw_configs);
1250 dev_info(scomp->dev, "ACP_BT config ACP%d channel %d rate %d tdm_mode %d\n",
1251 config->dai_index, config->acpbt.tdm_slots,
1252 config->acpbt.fsync_rate, config->acpbt.tdm_mode);
1254 dai->number_configs = 1;
1255 dai->current_config = 0;
1256 private->dai_config = kmemdup(config, size, GFP_KERNEL);
1257 if (!private->dai_config)
1258 return -ENOMEM;
1266 struct snd_soc_tplg_hw_config *hw_config = slink->hw_configs;
1267 struct sof_dai_private_data *private = dai->private;
1275 memset(&config->acpsp, 0, sizeof(config->acpsp));
1276 config->hdr.size = size;
1278 ret = sof_update_ipc_object(scomp, &config->acpsp, SOF_ACPI2S_TOKENS, slink->tuples,
1279 slink->num_tuples, size, slink->num_hw_configs);
1284 dev_info(scomp->dev, "ACP_SP config ACP%d channel %d rate %d tdm_mode %d\n",
1285 config->dai_index, config->acpsp.tdm_slots,
1286 config->acpsp.fsync_rate, config->acpsp.tdm_mode);
1288 dai->number_configs = 1;
1289 dai->current_config = 0;
1290 private->dai_config = kmemdup(config, size, GFP_KERNEL);
1291 if (!private->dai_config)
1292 return -ENOMEM;
1300 struct snd_soc_tplg_hw_config *hw_config = slink->hw_configs;
1301 struct sof_dai_private_data *private = dai->private;
1309 memset(&config->acphs, 0, sizeof(config->acphs));
1310 config->hdr.size = size;
1312 ret = sof_update_ipc_object(scomp, &config->acphs, SOF_ACPI2S_TOKENS, slink->tuples,
1313 slink->num_tuples, size, slink->num_hw_configs);
1317 dev_info(scomp->dev, "ACP_HS config ACP%d channel %d rate %d tdm_mode %d\n",
1318 config->dai_index, config->acphs.tdm_slots,
1319 config->acphs.fsync_rate, config->acphs.tdm_mode);
1321 dai->number_configs = 1;
1322 dai->current_config = 0;
1323 private->dai_config = kmemdup(config, size, GFP_KERNEL);
1324 if (!private->dai_config)
1325 return -ENOMEM;
1333 struct sof_dai_private_data *private = dai->private;
1338 ret = sof_update_ipc_object(scomp, &config->acp_sdw, SOF_ACP_SDW_TOKENS, slink->tuples,
1339 slink->num_tuples, size, slink->num_hw_configs);
1344 config->hdr.size = size;
1345 dev_dbg(scomp->dev, "ACP SDW config rate %d channels %d\n",
1346 config->acp_sdw.rate, config->acp_sdw.channels);
1348 /* set config for all DAI's with name matching the link name */
1349 dai->number_configs = 1;
1350 dai->current_config = 0;
1351 private->dai_config = kmemdup(config, size, GFP_KERNEL);
1352 if (!private->dai_config)
1353 return -ENOMEM;
1361 struct sof_dai_private_data *private = dai->private;
1365 config->hdr.size = size;
1368 ret = sof_update_ipc_object(scomp, &config->afe, SOF_AFE_TOKENS, slink->tuples,
1369 slink->num_tuples, size, slink->num_hw_configs);
1373 dev_dbg(scomp->dev, "AFE config rate %d channels %d format:%d\n",
1374 config->afe.rate, config->afe.channels, config->afe.format);
1376 config->afe.stream_id = DMA_CHAN_INVALID;
1378 dai->number_configs = 1;
1379 dai->current_config = 0;
1380 private->dai_config = kmemdup(config, size, GFP_KERNEL);
1381 if (!private->dai_config)
1382 return -ENOMEM;
1391 struct snd_soc_tplg_hw_config *hw_config = slink->hw_configs;
1392 struct sof_dai_private_data *private = dai->private;
1400 ret = sof_update_ipc_object(scomp, &config->ssp, SOF_SSP_TOKENS, slink->tuples,
1401 slink->num_tuples, size, slink->num_hw_configs);
1406 for (i = 0; i < slink->num_hw_configs; i++) {
1407 if (le32_to_cpu(hw_config[i].id) == slink->default_hw_cfg_id)
1415 if (sdev->mclk_id_override) {
1416 dev_dbg(scomp->dev, "tplg: overriding topology mclk_id %d by quirk %d\n",
1417 config[i].ssp.mclk_id, sdev->mclk_id_quirk);
1418 config[i].ssp.mclk_id = sdev->mclk_id_quirk;
1431 dev_dbg(scomp->dev, "tplg: config SSP%d fmt %#x mclk %d bclk %d fclk %d width (%d)%d slots %d mclk id %d quirks %d clks_control %#x\n",
1440 dev_err(scomp->dev, "Invalid fsync rate for SSP%d\n", config[i].dai_index);
1441 return -EINVAL;
1445 dev_err(scomp->dev, "Invalid channel count for SSP%d\n",
1447 return -EINVAL;
1451 dai->number_configs = slink->num_hw_configs;
1452 dai->current_config = current_config;
1453 private->dai_config = kmemdup(config, size * slink->num_hw_configs, GFP_KERNEL);
1454 if (!private->dai_config)
1455 return -ENOMEM;
1464 struct sof_dai_private_data *private = dai->private;
1465 struct sof_ipc_fw_ready *ready = &sdev->fw_ready;
1466 struct sof_ipc_fw_version *v = &ready->version;
1471 memset(&config->dmic, 0, sizeof(config->dmic));
1474 ret = sof_update_ipc_object(scomp, &config->dmic, SOF_DMIC_TOKENS, slink->tuples,
1475 slink->num_tuples, size, slink->num_hw_configs);
1480 ret = sof_update_ipc_object(scomp, &config->dmic.pdm[0], SOF_DMIC_PDM_TOKENS,
1481 slink->tuples, slink->num_tuples,
1483 config->dmic.num_pdm_active);
1488 config->hdr.size = size;
1491 dev_dbg(scomp->dev, "tplg: config DMIC%d driver version %d\n",
1492 config->dai_index, config->dmic.driver_ipc_version);
1493 dev_dbg(scomp->dev, "pdmclk_min %d pdm_clkmax %d duty_min %d\n",
1494 config->dmic.pdmclk_min, config->dmic.pdmclk_max,
1495 config->dmic.duty_min);
1496 dev_dbg(scomp->dev, "duty_max %d fifo_fs %d num_pdms active %d\n",
1497 config->dmic.duty_max, config->dmic.fifo_fs,
1498 config->dmic.num_pdm_active);
1499 dev_dbg(scomp->dev, "fifo word length %d\n", config->dmic.fifo_bits);
1501 for (i = 0; i < config->dmic.num_pdm_active; i++) {
1502 dev_dbg(scomp->dev, "pdm %d mic a %d mic b %d\n",
1503 config->dmic.pdm[i].id,
1504 config->dmic.pdm[i].enable_mic_a,
1505 config->dmic.pdm[i].enable_mic_b);
1506 dev_dbg(scomp->dev, "pdm %d polarity a %d polarity b %d\n",
1507 config->dmic.pdm[i].id,
1508 config->dmic.pdm[i].polarity_mic_a,
1509 config->dmic.pdm[i].polarity_mic_b);
1510 dev_dbg(scomp->dev, "pdm %d clk_edge %d skew %d\n",
1511 config->dmic.pdm[i].id,
1512 config->dmic.pdm[i].clk_edge,
1513 config->dmic.pdm[i].skew);
1520 if (SOF_ABI_VER(v->major, v->minor, v->micro) < SOF_ABI_VER(3, 0, 1))
1521 config->dmic.fifo_bits_b = config->dmic.fifo_bits;
1523 dai->number_configs = 1;
1524 dai->current_config = 0;
1525 private->dai_config = kmemdup(config, size, GFP_KERNEL);
1526 if (!private->dai_config)
1527 return -ENOMEM;
1535 struct sof_dai_private_data *private = dai->private;
1540 ret = sof_update_ipc_object(scomp, &config->alh, SOF_ALH_TOKENS, slink->tuples,
1541 slink->num_tuples, size, slink->num_hw_configs);
1546 config->hdr.size = size;
1548 /* set config for all DAI's with name matching the link name */
1549 dai->number_configs = 1;
1550 dai->current_config = 0;
1551 private->dai_config = kmemdup(config, size, GFP_KERNEL);
1552 if (!private->dai_config)
1553 return -ENOMEM;
1560 struct snd_soc_component *scomp = swidget->scomp;
1562 struct snd_sof_dai *dai = swidget->private;
1572 return -ENOMEM;
1574 dai->private = private;
1576 private->comp_dai = sof_comp_alloc(swidget, &ipc_size, swidget->pipeline_id);
1577 if (!private->comp_dai) {
1578 ret = -ENOMEM;
1583 comp_dai = private->comp_dai;
1584 comp_dai->comp.type = SOF_COMP_DAI;
1585 comp_dai->config.hdr.size = sizeof(comp_dai->config);
1588 ret = sof_update_ipc_object(scomp, comp_dai, SOF_DAI_TOKENS, swidget->tuples,
1589 swidget->num_tuples, sizeof(*comp_dai), 1);
1594 ret = sof_update_ipc_object(scomp, &comp_dai->config, SOF_COMP_TOKENS,
1595 swidget->tuples, swidget->num_tuples,
1596 sizeof(comp_dai->config), 1);
1601 if (comp_dai->type == SOF_DAI_INTEL_ALH) {
1602 if (comp_dai->dai_index < INTEL_ALH_DAI_INDEX_BASE) {
1603 dev_err(sdev->dev,
1605 comp_dai->dai_index, INTEL_ALH_DAI_INDEX_BASE);
1606 ret = -EINVAL;
1609 comp_dai->dai_index -= INTEL_ALH_DAI_INDEX_BASE;
1612 dev_dbg(scomp->dev, "dai %s: type %d index %d\n",
1613 swidget->widget->name, comp_dai->type, comp_dai->dai_index);
1614 sof_dbg_comp_config(scomp, &comp_dai->config);
1617 list_for_each_entry(slink, &sdev->dai_link_list, list) {
1621 if (strcmp(slink->link->name, dai->name))
1625 config = kcalloc(slink->num_hw_configs, sizeof(*config), GFP_KERNEL);
1627 ret = -ENOMEM;
1631 /* parse one set of DAI link tokens */
1633 slink->tuples, slink->num_tuples,
1638 for (i = 0; i < slink->num_hw_configs; i++) {
1640 config[i].format = le32_to_cpu(slink->hw_configs[i].fmt);
1642 config[i].dai_index = comp_dai->dai_index;
1691 dev_err(scomp->dev, "failed to load config for dai %s\n", dai->name);
1705 dai->private = NULL;
1711 switch (swidget->id) {
1715 struct snd_sof_dai *dai = swidget->private;
1721 dai_data = dai->private;
1723 kfree(dai_data->comp_dai);
1724 kfree(dai_data->dai_config);
1742 connect.source_id = sroute->src_widget->comp_id;
1743 connect.sink_id = sroute->sink_widget->comp_id;
1745 dev_dbg(sdev->dev, "setting up route %s -> %s\n",
1746 sroute->src_widget->widget->name,
1747 sroute->sink_widget->widget->name);
1750 ret = sof_ipc_tx_message_no_reply(sdev->ipc, &connect, sizeof(connect));
1752 dev_err(sdev->dev, "%s: route %s -> %s failed\n", __func__,
1753 sroute->src_widget->widget->name, sroute->sink_widget->widget->name);
1764 if (scontrol->max_size < (sizeof(*cdata) + sizeof(struct sof_abi_hdr))) {
1765 dev_err(sdev->dev, "%s: insufficient size for a bytes control: %zu.\n",
1766 __func__, scontrol->max_size);
1767 return -EINVAL;
1770 if (scontrol->priv_size > scontrol->max_size - sizeof(*cdata)) {
1771 dev_err(sdev->dev,
1773 scontrol->priv_size, scontrol->max_size - sizeof(*cdata));
1774 return -EINVAL;
1777 scontrol->ipc_control_data = kzalloc(scontrol->max_size, GFP_KERNEL);
1778 if (!scontrol->ipc_control_data)
1779 return -ENOMEM;
1781 scontrol->size = sizeof(struct sof_ipc_ctrl_data) + scontrol->priv_size;
1783 cdata = scontrol->ipc_control_data;
1784 cdata->cmd = SOF_CTRL_CMD_BINARY;
1785 cdata->index = scontrol->index;
1787 if (scontrol->priv_size > 0) {
1788 memcpy(cdata->data, scontrol->priv, scontrol->priv_size);
1789 kfree(scontrol->priv);
1790 scontrol->priv = NULL;
1792 if (cdata->data->magic != SOF_ABI_MAGIC) {
1793 dev_err(sdev->dev, "Wrong ABI magic 0x%08x.\n", cdata->data->magic);
1794 ret = -EINVAL;
1798 if (SOF_ABI_VERSION_INCOMPATIBLE(SOF_ABI_VERSION, cdata->data->abi)) {
1799 dev_err(sdev->dev, "Incompatible ABI version 0x%08x.\n",
1800 cdata->data->abi);
1801 ret = -EINVAL;
1805 priv_size_check = cdata->data->size + sizeof(struct sof_abi_hdr);
1806 if (priv_size_check != scontrol->priv_size) {
1807 dev_err(sdev->dev, "Conflict in bytes (%zu) vs. priv size (%zu).\n",
1808 priv_size_check, scontrol->priv_size);
1809 ret = -EINVAL;
1816 kfree(scontrol->ipc_control_data);
1817 scontrol->ipc_control_data = NULL;
1827 scontrol->size = struct_size(cdata, chanv, scontrol->num_channels);
1829 scontrol->ipc_control_data = kzalloc(scontrol->size, GFP_KERNEL);
1830 if (!scontrol->ipc_control_data)
1831 return -ENOMEM;
1833 cdata = scontrol->ipc_control_data;
1834 cdata->index = scontrol->index;
1837 if (scontrol->max == 1) {
1838 cdata->cmd = SOF_CTRL_CMD_SWITCH;
1842 cdata->cmd = SOF_CTRL_CMD_VOLUME;
1845 for (i = 0; i < scontrol->num_channels; i++) {
1846 cdata->chanv[i].channel = i;
1847 cdata->chanv[i].value = VOL_ZERO_DB;
1858 scontrol->size = struct_size(cdata, chanv, scontrol->num_channels);
1860 scontrol->ipc_control_data = kzalloc(scontrol->size, GFP_KERNEL);
1861 if (!scontrol->ipc_control_data)
1862 return -ENOMEM;
1864 cdata = scontrol->ipc_control_data;
1865 cdata->index = scontrol->index;
1866 cdata->cmd = SOF_CTRL_CMD_ENUM;
1873 switch (scontrol->info_type) {
1896 fcomp.id = scontrol->comp_id;
1899 return sof_ipc_tx_message_no_reply(sdev->ipc, &fcomp, sizeof(fcomp));
1905 struct snd_soc_component *scomp = swidget->scomp;
1913 spcm = snd_sof_find_spcm_name(scomp, swidget->widget->sname);
1915 dev_err(scomp->dev, "Cannot find PCM for %s\n", swidget->widget->name);
1916 return -EINVAL;
1919 params = &spcm->params[dir];
1925 pcm.comp_id = swidget->comp_id;
1946 return -EINVAL;
1950 ret = sof_ipc_tx_message_no_reply(sdev->ipc, &pcm, sizeof(pcm));
1952 dev_err(scomp->dev, "%s: PCM params failed for %s\n", __func__,
1953 swidget->widget->name);
1958 /* send stream trigger ipc */
1961 struct snd_soc_component *scomp = swidget->scomp;
1969 stream.comp_id = swidget->comp_id;
1972 ret = sof_ipc_tx_message_no_reply(sdev->ipc, &stream, sizeof(stream));
1974 dev_err(scomp->dev, "%s: Failed to trigger %s\n", __func__, swidget->widget->name);
1982 struct snd_sof_widget *swidget = w->dobj.private;
1991 scomp = swidget->scomp;
1993 dev_dbg(scomp->dev, "received event %d for widget %s\n",
1994 event, w->name);
1997 spcm = snd_sof_find_spcm_name(scomp, swidget->widget->sname);
1999 dev_err(scomp->dev, "%s: Cannot find PCM for %s\n", __func__,
2000 swidget->widget->name);
2001 return -EINVAL;
2007 if (spcm->stream[stream].suspend_ignored) {
2008 dev_dbg(scomp->dev, "PRE_PMU event ignored, KWD pipeline is already RUNNING\n");
2015 dev_err(scomp->dev, "%s: Failed to set pcm params for widget %s\n",
2016 __func__, swidget->widget->name);
2020 /* start trigger */
2023 dev_err(scomp->dev, "%s: Failed to trigger widget %s\n", __func__,
2024 swidget->widget->name);
2027 if (spcm->stream[stream].suspend_ignored) {
2028 dev_dbg(scomp->dev,
2033 /* stop trigger */
2036 dev_err(scomp->dev, "%s: Failed to trigger widget %s\n", __func__,
2037 swidget->widget->name);
2042 dev_err(scomp->dev, "%s: Failed to free PCM for widget %s\n", __func__,
2043 swidget->widget->name);
2066 if (swidget->id != snd_soc_dapm_effect)
2069 ipc_comp = swidget->private;
2070 if (ipc_comp && ipc_comp->type != SOF_COMP_KEYWORD_DETECT)
2074 return snd_soc_tplg_widget_bind_event(swidget->widget, sof_kwd_events,
2080 dev_err(scomp->dev, "Invalid event type %d for widget %s\n", event_type,
2081 swidget->widget->name);
2083 return -EINVAL;
2091 dev_dbg(sdev->dev, "tplg: complete pipeline %s id %d\n",
2092 swidget->widget->name, swidget->comp_id);
2097 ready.comp_id = swidget->comp_id;
2099 ret = sof_ipc_tx_message_no_reply(sdev->ipc, &ready, sizeof(ready));
2113 .id = swidget->comp_id,
2117 if (!swidget->private)
2120 switch (swidget->id) {
2134 ret = sof_ipc_tx_message_no_reply(sdev->ipc, &ipc_free, sizeof(ipc_free));
2136 dev_err(sdev->dev, "failed to free widget %s\n", swidget->widget->name);
2144 struct sof_ipc_fw_version *v = &sdev->fw_ready.version;
2145 struct snd_sof_dai *dai = swidget->private;
2150 if (!dai || !dai->private) {
2151 dev_err(sdev->dev, "No private data for DAI %s\n", swidget->widget->name);
2152 return -EINVAL;
2155 private = dai->private;
2156 if (!private->dai_config) {
2157 dev_err(sdev->dev, "No config for DAI %s\n", dai->name);
2158 return -EINVAL;
2161 config = &private->dai_config[dai->current_config];
2163 dev_err(sdev->dev, "Invalid current config for DAI %s\n", dai->name);
2164 return -EINVAL;
2167 switch (config->type) {
2173 if (v->abi_version < SOF_ABI_VER(3, 18, 0) &&
2180 config->hda.link_dma_ch = data->dai_data;
2187 if (data->dai_index < INTEL_ALH_DAI_INDEX_BASE) {
2188 dev_err(sdev->dev,
2190 config->dai_index, INTEL_ALH_DAI_INDEX_BASE);
2191 return -EINVAL;
2193 config->dai_index = data->dai_index - INTEL_ALH_DAI_INDEX_BASE;
2195 config->alh.stream_id = data->dai_data;
2209 * BE DAI trigger: When invoked during the BE DAI trigger, flags is set to
2224 config->flags &= ~SOF_DAI_CONFIG_FLAGS_CMD_MASK;
2225 config->flags |= flags;
2227 config->flags = flags;
2231 if (swidget->use_count > 0) {
2232 ret = sof_ipc_tx_message_no_reply(sdev->ipc, config, config->hdr.size);
2234 dev_err(sdev->dev, "Failed to set dai config for %s\n", dai->name);
2237 config->flags = SOF_DAI_CONFIG_FLAGS_NONE;
2247 if (!swidget->private)
2250 switch (swidget->id) {
2254 struct snd_sof_dai *dai = swidget->private;
2255 struct sof_dai_private_data *dai_data = dai->private;
2256 struct sof_ipc_comp *comp = &dai_data->comp_dai->comp;
2258 ret = sof_ipc_tx_message_no_reply(sdev->ipc, dai_data->comp_dai, comp->hdr.size);
2265 pipeline = swidget->private;
2266 ret = sof_ipc_tx_message_no_reply(sdev->ipc, pipeline, sizeof(*pipeline));
2273 hdr = swidget->private;
2274 ret = sof_ipc_tx_message_no_reply(sdev->ipc, swidget->private, hdr->size);
2279 dev_err(sdev->dev, "Failed to setup widget %s\n", swidget->widget->name);
2286 struct sof_ipc_fw_version *v = &sdev->fw_ready.version;
2292 list_for_each_entry(swidget, &sdev->widget_list, list) {
2294 if (!verify && swidget->dynamic_pipeline_widget)
2301 if (v->abi_version < SOF_ABI_VER(3, 19, 0) &&
2302 swidget->id == snd_soc_dapm_scheduler)
2306 if (WIDGET_IS_DAI(swidget->id)) {
2307 struct snd_sof_dai *dai = swidget->private;
2311 if (!dai || !dai->private)
2313 private = dai->private;
2314 if (!private->dai_config)
2317 config = private->dai_config;
2319 * The link DMA channel would be invalidated for running
2324 if (config->type == SOF_DAI_INTEL_HDA)
2325 config->hda.link_dma_ch = DMA_CHAN_INVALID;
2334 list_for_each_entry(sroute, &sdev->route_list, list) {
2336 if (!verify && (sroute->src_widget->dynamic_pipeline_widget ||
2337 sroute->sink_widget->dynamic_pipeline_widget))
2344 if (sroute->src_widget->id != snd_soc_dapm_buffer &&
2345 sroute->sink_widget->id != snd_soc_dapm_buffer)
2348 ret = sof_route_setup(sdev, sroute->src_widget->widget,
2349 sroute->sink_widget->widget);
2351 dev_err(sdev->dev, "%s: route set up failed\n", __func__);
2357 list_for_each_entry(swidget, &sdev->widget_list, list) {
2358 switch (swidget->id) {
2361 if (!verify && swidget->dynamic_pipeline_widget)
2364 if (v->abi_version < SOF_ABI_VER(3, 19, 0)) {
2370 swidget->spipe->complete = sof_ipc3_complete_pipeline(sdev, swidget);
2371 if (swidget->spipe->complete < 0)
2372 return swidget->spipe->complete;
2395 * This is equivalent to the handling of FE DAI suspend trigger for running streams.
2397 list_for_each_entry(spcm, &sdev->pcm_list, list) {
2399 struct snd_pcm_substream *substream = spcm->stream[dir].substream;
2401 if (!substream || !substream->runtime || spcm->stream[dir].suspend_ignored)
2404 if (spcm->stream[dir].list) {
2413 * free any left over DAI widgets. This is equivalent to the handling of suspend trigger
2416 list_for_each_entry(swidget, &sdev->widget_list, list)
2417 if (WIDGET_IS_DAI(swidget->id) && swidget->use_count == 1) {
2429 struct sof_ipc_fw_version *v = &sdev->fw_ready.version;
2433 list_for_each_entry(swidget, &sdev->widget_list, list) {
2434 if (swidget->dynamic_pipeline_widget) {
2440 if (!verify && !swidget->dynamic_pipeline_widget &&
2441 SOF_FW_VER(v->major, v->minor, v->micro) < SOF_FW_VER(2, 2, 0)) {
2442 mutex_lock(&swidget->setup_mutex);
2443 swidget->use_count = 0;
2444 mutex_unlock(&swidget->setup_mutex);
2445 if (swidget->spipe)
2446 swidget->spipe->complete = 0;
2450 if (include_scheduler && swidget->id != snd_soc_dapm_scheduler)
2453 if (!include_scheduler && swidget->id == snd_soc_dapm_scheduler)
2470 struct sof_ipc_fw_version *v = &sdev->fw_ready.version;
2477 * This function is called during suspend and for one-time topology verification during
2478 * first boot. In both cases, there is no need to protect swidget->use_count and
2479 * sroute->setup because during suspend all running streams are suspended and during
2499 if (!verify && (dyn_widgets || SOF_FW_VER(v->major, v->minor, v->micro) >=
2503 dev_err(sdev->dev, "failed to tear down paused pipelines\n");
2508 list_for_each_entry(sroute, &sdev->route_list, list)
2509 sroute->setup = false;
2516 list_for_each_entry(swidget, &sdev->widget_list, list) {
2517 if (swidget->use_count != 0) {
2518 dev_err(sdev->dev, "%s: widget %s is still in use: count %d\n",
2519 __func__, swidget->widget->name, swidget->use_count);
2528 struct sof_dai_private_data *private = dai->private;
2530 if (!private || !private->dai_config)
2533 switch (private->dai_config->type) {
2537 return private->dai_config->ssp.mclk_rate;
2539 return private->dai_config->ssp.bclk_rate;
2541 return private->dai_config->ssp.tdm_slots;
2543 dev_err(sdev->dev, "invalid SSP param %d\n", param_type);
2549 dev_err(sdev->dev, "DAI type %d not supported yet!\n", private->dai_config->type);
2553 return -EINVAL;
2559 u32 size = le32_to_cpu(man->priv.size);
2564 dev_dbg(scomp->dev, "No topology ABI info\n");
2569 dev_err(scomp->dev, "%s: Invalid topology ABI size: %u\n",
2571 return -EINVAL;
2574 dev_info(scomp->dev,
2576 man->priv.data[0], man->priv.data[1], man->priv.data[2],
2579 abi_version = SOF_ABI_VER(man->priv.data[0], man->priv.data[1], man->priv.data[2]);
2582 dev_err(scomp->dev, "%s: Incompatible topology ABI version\n", __func__);
2583 return -EINVAL;
2588 dev_err(scomp->dev, "%s: Topology ABI is more recent than kernel\n", __func__);
2589 return -EINVAL;
2595 static int sof_ipc3_link_setup(struct snd_sof_dev *sdev, struct snd_soc_dai_link *link)
2597 if (link->no_pcm)
2601 * set default trigger order for all links. Exceptions to
2604 * start BE, stop BE, stop FE; for Capture the sequence is
2605 * inverted start BE, start FE, stop FE, stop BE
2607 link->trigger[SNDRV_PCM_STREAM_PLAYBACK] = SND_SOC_DPCM_TRIGGER_PRE;
2608 link->trigger[SNDRV_PCM_STREAM_CAPTURE] = SND_SOC_DPCM_TRIGGER_POST;