Lines Matching +full:is +full:- +full:compress +full:- +full:dai

1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
3 // This file is provided under a dual BSD/GPLv2 license. When using or
18 #include "sof-priv.h"
19 #include "sof-audio.h"
25 * from dB gain 20th root of 10 in Q1.16 fixed-point notation
28 /* 40th root of 10 in Q1.16 fixed-point notation*/
40 * sof_update_ipc_object - Parse multiple sets of tokens within the token array associated with the
62 token_list = tplg_ops ? tplg_ops->token_list : NULL; in sof_update_ipc_object()
63 /* nothing to do if token_list is NULL */ in sof_update_ipc_object()
68 dev_err(scomp->dev, "Invalid token count for token ID: %d\n", token_id); in sof_update_ipc_object()
69 return -EINVAL; in sof_update_ipc_object()
78 dev_err(scomp->dev, "Invalid tokens for token id: %d\n", token_id); in sof_update_ipc_object()
79 return -EINVAL; in sof_update_ipc_object()
109 dev_err(scomp->dev, in sof_update_ipc_object()
112 return -EINVAL; in sof_update_ipc_object()
142 return -EINVAL; in get_tlv_data()
144 /* min value in topology tlv data is multiplied by 100 */ in get_tlv_data()
162 * Function to truncate an unsigned 64-bit number
163 * by x bits and return 32-bit unsigned number. This
175 return (u32)(((i >> (x - 1)) + 1) >> 1); in vol_shift_64()
180 * a is a fractional number represented by a fixed-point
182 * exp is an integer
183 * fwl is the fractional word length
184 * Return value is a fractional number represented by a
185 * fixed-point integer with a fractional word length of "fwl"
193 /* if exponent is 0, return 1 */ in vol_pow32()
199 iter = exp * -1; in vol_pow32()
206 * Product of 2 Qx.fwl fixed-point numbers yields a Q2*x.2*fwl in vol_pow32()
213 /* if exp is positive, return the result */ in vol_pow32()
217 /* if exp is negative, return the multiplicative inverse */ in vol_pow32()
240 * in topology is multiplied by 100 in vol_compute_gain()
245 * compute linear gain represented by fixed-point in vol_compute_gain()
251 f_step = tlv[TLV_STEP] - (tlv[TLV_STEP] / 100); in vol_compute_gain()
253 /* if volume step is an odd multiple of 0.5 dB */ in vol_compute_gain()
269 struct snd_soc_component *scomp = scontrol->scomp; in set_up_volume_table()
273 if (tplg_ops && tplg_ops->control && tplg_ops->control->set_up_volume_table) in set_up_volume_table()
274 return tplg_ops->control->set_up_volume_table(scontrol, tlv, size); in set_up_volume_table()
276 dev_err(scomp->dev, "Mandatory op %s not set\n", __func__); in set_up_volume_table()
277 return -EINVAL; in set_up_volume_table()
341 /* use s32le if nothing is specified */ in find_format()
350 *val = le32_to_cpu(velem->value); in get_token_u32()
359 *val = (u16)le32_to_cpu(velem->value); in get_token_u16()
368 memcpy(dst, velem->uuid, UUID_SIZE); in get_token_uuid()
384 return -ENOMEM; in get_token_string()
438 * sof_parse_uuid_tokens - Parse multiple sets of UUID tokens
458 for (i = 0; i < le32_to_cpu(array->num_elems); i++) { in sof_parse_uuid_tokens()
459 elem = &array->uuid[i]; in sof_parse_uuid_tokens()
468 if (tokens[j].token != le32_to_cpu(elem->token)) in sof_parse_uuid_tokens()
471 /* matched - now load token */ in sof_parse_uuid_tokens()
483 * sof_copy_tuples - Parse tokens and copy them to the @tuples array
507 token_list = tplg_ops ? tplg_ops->token_list : NULL; in sof_copy_tuples()
508 /* nothing to do if token_list is NULL */ in sof_copy_tuples()
513 dev_err(sdev->dev, "Invalid tuples array\n"); in sof_copy_tuples()
514 return -EINVAL; in sof_copy_tuples()
521 dev_err(sdev->dev, "No token array defined for token ID: %d\n", token_id); in sof_copy_tuples()
522 return -EINVAL; in sof_copy_tuples()
527 dev_err(sdev->dev, "No space in tuples array for new tokens from %s", in sof_copy_tuples()
529 return -EINVAL; in sof_copy_tuples()
533 asize = le32_to_cpu(array->size); in sof_copy_tuples()
537 dev_err(sdev->dev, "Invalid array size 0x%x\n", asize); in sof_copy_tuples()
538 return -EINVAL; in sof_copy_tuples()
541 /* make sure there is enough data before parsing */ in sof_copy_tuples()
542 array_size -= asize; in sof_copy_tuples()
544 dev_err(sdev->dev, "Invalid array size 0x%x\n", asize); in sof_copy_tuples()
545 return -EINVAL; in sof_copy_tuples()
549 for (i = 0; i < le32_to_cpu(array->num_elems); i++) { in sof_copy_tuples()
563 elem = &array->string[i]; in sof_copy_tuples()
566 if (tokens[j].token != le32_to_cpu(elem->token)) in sof_copy_tuples()
570 tuples[*num_copied_tuples].value.s = elem->string; in sof_copy_tuples()
574 elem = &array->value[i]; in sof_copy_tuples()
577 if (tokens[j].token != le32_to_cpu(elem->token)) in sof_copy_tuples()
582 le32_to_cpu(elem->value); in sof_copy_tuples()
605 * sof_parse_string_tokens - Parse multiple sets of tokens
625 for (i = 0; i < le32_to_cpu(array->num_elems); i++) { in sof_parse_string_tokens()
626 elem = &array->string[i]; in sof_parse_string_tokens()
635 if (tokens[j].token != le32_to_cpu(elem->token)) in sof_parse_string_tokens()
638 /* matched - now load token */ in sof_parse_string_tokens()
639 ret = tokens[j].get_token(elem->string, object, offset + tokens[j].offset); in sof_parse_string_tokens()
651 * sof_parse_word_tokens - Parse multiple sets of tokens
671 for (i = 0; i < le32_to_cpu(array->num_elems); i++) { in sof_parse_word_tokens()
672 elem = &array->value[i]; in sof_parse_word_tokens()
684 if (tokens[j].token != le32_to_cpu(elem->token)) in sof_parse_word_tokens()
698 * sof_parse_token_sets - Parse multiple sets of tokens
724 asize = le32_to_cpu(array->size); in sof_parse_token_sets()
727 if (asize < 0) { /* FIXME: A zero-size array makes no sense */ in sof_parse_token_sets()
728 dev_err(scomp->dev, "error: invalid array size 0x%x\n", in sof_parse_token_sets()
730 return -EINVAL; in sof_parse_token_sets()
733 /* make sure there is enough data before parsing */ in sof_parse_token_sets()
734 array_size -= asize; in sof_parse_token_sets()
736 dev_err(scomp->dev, "error: invalid array size 0x%x\n", in sof_parse_token_sets()
738 return -EINVAL; in sof_parse_token_sets()
742 switch (le32_to_cpu(array->type)) { in sof_parse_token_sets()
752 dev_err(scomp->dev, "error: no memory to copy string token\n"); in sof_parse_token_sets()
766 dev_err(scomp->dev, "error: unknown token type %d\n", in sof_parse_token_sets()
767 array->type); in sof_parse_token_sets()
768 return -EINVAL; in sof_parse_token_sets()
787 * sof_parse_tokens - Parse one set of tokens
805 * sof_parse_tokens is used when topology contains only a single set of in sof_parse_tokens()
831 if (le32_to_cpu(mc->num_channels) > SND_SOC_TPLG_MAX_CHAN) in sof_control_load_volume()
832 return -EINVAL; in sof_control_load_volume()
835 * If control has more than 2 channels we need to override the info. This is because even if in sof_control_load_volume()
837 * pre-defined dapm control types (and related functions) creating the actual control in sof_control_load_volume()
840 if (le32_to_cpu(mc->num_channels) > 2) in sof_control_load_volume()
841 kc->info = snd_sof_volume_info; in sof_control_load_volume()
843 scontrol->comp_id = sdev->next_comp_id; in sof_control_load_volume()
844 scontrol->min_volume_step = le32_to_cpu(mc->min); in sof_control_load_volume()
845 scontrol->max_volume_step = le32_to_cpu(mc->max); in sof_control_load_volume()
846 scontrol->num_channels = le32_to_cpu(mc->num_channels); in sof_control_load_volume()
848 scontrol->max = le32_to_cpu(mc->max); in sof_control_load_volume()
849 if (le32_to_cpu(mc->max) == 1) in sof_control_load_volume()
853 if (!kc->tlv.p || get_tlv_data(kc->tlv.p, tlv) < 0) { in sof_control_load_volume()
854 dev_err(scomp->dev, "error: invalid TLV data\n"); in sof_control_load_volume()
855 return -EINVAL; in sof_control_load_volume()
859 ret = set_up_volume_table(scontrol, tlv, le32_to_cpu(mc->max) + 1); in sof_control_load_volume()
861 dev_err(scomp->dev, "error: setting up volume table\n"); in sof_control_load_volume()
867 ret = sof_parse_tokens(scomp, &scontrol->led_ctl, led_tokens, in sof_control_load_volume()
868 ARRAY_SIZE(led_tokens), mc->priv.array, in sof_control_load_volume()
869 le32_to_cpu(mc->priv.size)); in sof_control_load_volume()
871 dev_err(scomp->dev, "error: parse led tokens failed %d\n", in sof_control_load_volume()
872 le32_to_cpu(mc->priv.size)); in sof_control_load_volume()
876 if (scontrol->led_ctl.use_led) { in sof_control_load_volume()
877 mask = scontrol->led_ctl.direction ? SNDRV_CTL_ELEM_ACCESS_MIC_LED : in sof_control_load_volume()
879 scontrol->access &= ~SNDRV_CTL_ELEM_ACCESS_LED_MASK; in sof_control_load_volume()
880 scontrol->access |= mask; in sof_control_load_volume()
881 kc->access &= ~SNDRV_CTL_ELEM_ACCESS_LED_MASK; in sof_control_load_volume()
882 kc->access |= mask; in sof_control_load_volume()
883 sdev->led_present = true; in sof_control_load_volume()
886 dev_dbg(scomp->dev, "tplg: load kcontrol index %d chans %d\n", in sof_control_load_volume()
887 scontrol->comp_id, scontrol->num_channels); in sof_control_load_volume()
892 if (le32_to_cpu(mc->max) > 1) in sof_control_load_volume()
893 kfree(scontrol->volume_table); in sof_control_load_volume()
908 if (le32_to_cpu(ec->num_channels) > SND_SOC_TPLG_MAX_CHAN) in sof_control_load_enum()
909 return -EINVAL; in sof_control_load_enum()
911 scontrol->comp_id = sdev->next_comp_id; in sof_control_load_enum()
912 scontrol->num_channels = le32_to_cpu(ec->num_channels); in sof_control_load_enum()
914 dev_dbg(scomp->dev, "tplg: load kcontrol index %d chans %d comp_id %d\n", in sof_control_load_enum()
915 scontrol->comp_id, scontrol->num_channels, scontrol->comp_id); in sof_control_load_enum()
928 struct soc_bytes_ext *sbe = (struct soc_bytes_ext *)kc->private_value; in sof_control_load_bytes()
929 size_t priv_size = le32_to_cpu(control->priv.size); in sof_control_load_bytes()
931 scontrol->max_size = sbe->max; in sof_control_load_bytes()
932 scontrol->comp_id = sdev->next_comp_id; in sof_control_load_bytes()
934 dev_dbg(scomp->dev, "tplg: load kcontrol index %d\n", scontrol->comp_id); in sof_control_load_bytes()
938 scontrol->priv = kmemdup(control->priv.data, priv_size, GFP_KERNEL); in sof_control_load_bytes()
939 if (!scontrol->priv) in sof_control_load_bytes()
940 return -ENOMEM; in sof_control_load_bytes()
942 scontrol->priv_size = priv_size; in sof_control_load_bytes()
948 /* external kcontrol init - used for any driver specific init */
961 dev_dbg(scomp->dev, "tplg: load control type %d name : %s\n", in sof_control_load()
962 hdr->type, hdr->name); in sof_control_load()
966 return -ENOMEM; in sof_control_load()
968 scontrol->name = kstrdup(hdr->name, GFP_KERNEL); in sof_control_load()
969 if (!scontrol->name) { in sof_control_load()
971 return -ENOMEM; in sof_control_load()
974 scontrol->scomp = scomp; in sof_control_load()
975 scontrol->access = kc->access; in sof_control_load()
976 scontrol->info_type = le32_to_cpu(hdr->ops.info); in sof_control_load()
977 scontrol->index = kc->index; in sof_control_load()
979 switch (le32_to_cpu(hdr->ops.info)) { in sof_control_load()
983 sm = (struct soc_mixer_control *)kc->private_value; in sof_control_load()
984 dobj = &sm->dobj; in sof_control_load()
988 sbe = (struct soc_bytes_ext *)kc->private_value; in sof_control_load()
989 dobj = &sbe->dobj; in sof_control_load()
994 se = (struct soc_enum *)kc->private_value; in sof_control_load()
995 dobj = &se->dobj; in sof_control_load()
1006 dev_warn(scomp->dev, "control type not supported %d:%d:%d\n", in sof_control_load()
1007 hdr->ops.get, hdr->ops.put, hdr->ops.info); in sof_control_load()
1008 kfree(scontrol->name); in sof_control_load()
1014 kfree(scontrol->name); in sof_control_load()
1019 scontrol->led_ctl.led_value = -1; in sof_control_load()
1021 dobj->private = scontrol; in sof_control_load()
1022 list_add(&scontrol->list, &sdev->kcontrol_list); in sof_control_load()
1031 struct snd_sof_control *scontrol = dobj->private; in sof_control_unload()
1034 dev_dbg(scomp->dev, "tplg: unload control name : %s\n", scontrol->name); in sof_control_unload()
1036 if (tplg_ops && tplg_ops->control_free) { in sof_control_unload()
1037 ret = tplg_ops->control_free(sdev, scontrol); in sof_control_unload()
1039 dev_err(scomp->dev, "failed to free control: %s\n", scontrol->name); in sof_control_unload()
1043 kfree(scontrol->ipc_control_data); in sof_control_unload()
1044 kfree(scontrol->priv); in sof_control_unload()
1045 kfree(scontrol->name); in sof_control_unload()
1046 list_del(&scontrol->list); in sof_control_unload()
1053 * DAI Topology
1059 struct snd_sof_dai *dai) in sof_connect_dai_widget() argument
1061 struct snd_soc_card *card = scomp->card; in sof_connect_dai_widget()
1067 if (!w->sname) { in sof_connect_dai_widget()
1068 dev_err(scomp->dev, "Widget %s does not have stream\n", w->name); in sof_connect_dai_widget()
1069 return -EINVAL; in sof_connect_dai_widget()
1072 if (w->id == snd_soc_dapm_dai_out) in sof_connect_dai_widget()
1074 else if (w->id == snd_soc_dapm_dai_in) in sof_connect_dai_widget()
1079 list_for_each_entry(rtd, &card->rtd_list, list) { in sof_connect_dai_widget()
1080 /* does stream match DAI link ? */ in sof_connect_dai_widget()
1081 if (!rtd->dai_link->stream_name || in sof_connect_dai_widget()
1082 !strstr(rtd->dai_link->stream_name, w->sname)) in sof_connect_dai_widget()
1087 * Please create DAI widget in the right order in sof_connect_dai_widget()
1088 * to ensure BE will connect to the right DAI in sof_connect_dai_widget()
1096 if (i == rtd->dai_link->num_cpus) { in sof_connect_dai_widget()
1097 dev_err(scomp->dev, "error: can't find BE for DAI %s\n", w->name); in sof_connect_dai_widget()
1099 return -EINVAL; in sof_connect_dai_widget()
1102 dai->name = rtd->dai_link->name; in sof_connect_dai_widget()
1103 dev_dbg(scomp->dev, "tplg: connected widget %s -> DAI link %s\n", in sof_connect_dai_widget()
1104 w->name, rtd->dai_link->name); in sof_connect_dai_widget()
1108 if (!dai->name) { in sof_connect_dai_widget()
1109 dev_err(scomp->dev, "error: can't connect DAI %s stream %s\n", in sof_connect_dai_widget()
1110 w->name, w->sname); in sof_connect_dai_widget()
1111 return -EINVAL; in sof_connect_dai_widget()
1120 struct snd_soc_card *card = scomp->card; in sof_disconnect_dai_widget()
1122 const char *sname = w->sname; in sof_disconnect_dai_widget()
1129 if (w->id == snd_soc_dapm_dai_out) in sof_disconnect_dai_widget()
1131 else if (w->id == snd_soc_dapm_dai_in) in sof_disconnect_dai_widget()
1136 list_for_each_entry(rtd, &card->rtd_list, list) { in sof_disconnect_dai_widget()
1137 /* does stream match DAI link ? */ in sof_disconnect_dai_widget()
1138 if (!rtd->dai_link->stream_name || in sof_disconnect_dai_widget()
1139 !strstr(rtd->dai_link->stream_name, sname)) in sof_disconnect_dai_widget()
1157 if (sdev->dspless_mode_selected) in spcm_bind()
1161 spcm->pcm.caps[dir].name, in spcm_bind()
1164 dev_err(scomp->dev, "can't find host comp to bind pcm\n"); in spcm_bind()
1165 return -EINVAL; in spcm_bind()
1168 spcm->stream[dir].comp_id = host_widget->comp_id; in spcm_bind()
1178 return -EINVAL; in sof_get_token_value()
1185 return -EINVAL; in sof_get_token_value()
1194 struct snd_soc_tplg_private *private = &tw->priv; in sof_widget_parse_tokens()
1199 token_list = tplg_ops ? tplg_ops->token_list : NULL; in sof_widget_parse_tokens()
1200 /* nothing to do if token_list is NULL */ in sof_widget_parse_tokens()
1205 dev_err(scomp->dev, "No token list for widget %s\n", swidget->widget->name); in sof_widget_parse_tokens()
1206 return -EINVAL; in sof_widget_parse_tokens()
1214 swidget->tuples = kcalloc(num_tuples, sizeof(*swidget->tuples), GFP_KERNEL); in sof_widget_parse_tokens()
1215 if (!swidget->tuples) in sof_widget_parse_tokens()
1216 return -ENOMEM; in sof_widget_parse_tokens()
1223 dev_err(scomp->dev, "Invalid token id %d for widget %s\n", in sof_widget_parse_tokens()
1224 object_token_list[i], swidget->widget->name); in sof_widget_parse_tokens()
1225 ret = -EINVAL; in sof_widget_parse_tokens()
1235 private->array, le32_to_cpu(private->size)); in sof_widget_parse_tokens()
1237 dev_err(scomp->dev, "Failed parsing %s for widget %s\n", in sof_widget_parse_tokens()
1239 swidget->widget->name); in sof_widget_parse_tokens()
1246 swidget->tuples, swidget->num_tuples); in sof_widget_parse_tokens()
1248 dev_err(sdev->dev, "Invalid input audio format count for %s\n", in sof_widget_parse_tokens()
1249 swidget->widget->name); in sof_widget_parse_tokens()
1256 swidget->tuples, swidget->num_tuples); in sof_widget_parse_tokens()
1258 dev_err(sdev->dev, "Invalid output audio format count for %s\n", in sof_widget_parse_tokens()
1259 swidget->widget->name); in sof_widget_parse_tokens()
1271 num_tuples += token_list[object_token_list[i]].count * (num_sets - 1); in sof_widget_parse_tokens()
1272 new_tuples = krealloc(swidget->tuples, in sof_widget_parse_tokens()
1275 ret = -ENOMEM; in sof_widget_parse_tokens()
1279 swidget->tuples = new_tuples; in sof_widget_parse_tokens()
1282 /* copy one set of tuples per token ID into swidget->tuples */ in sof_widget_parse_tokens()
1283 ret = sof_copy_tuples(sdev, private->array, le32_to_cpu(private->size), in sof_widget_parse_tokens()
1284 object_token_list[i], num_sets, swidget->tuples, in sof_widget_parse_tokens()
1285 num_tuples, &swidget->num_tuples); in sof_widget_parse_tokens()
1287 dev_err(scomp->dev, "Failed parsing %s for widget %s err: %d\n", in sof_widget_parse_tokens()
1288 token_list[object_token_list[i]].name, swidget->widget->name, ret); in sof_widget_parse_tokens()
1295 kfree(swidget->tuples); in sof_widget_parse_tokens()
1307 pin_binding = swidget->input_pin_binding; in sof_free_pin_binding()
1308 num_pins = swidget->num_input_pins; in sof_free_pin_binding()
1310 pin_binding = swidget->output_pin_binding; in sof_free_pin_binding()
1311 num_pins = swidget->num_output_pins; in sof_free_pin_binding()
1334 num_pins = swidget->num_input_pins; in sof_parse_pin_binding()
1338 num_pins = swidget->num_output_pins; in sof_parse_pin_binding()
1344 ret = sof_parse_token_sets(swidget->scomp, pin_binding, pin_binding_token, in sof_parse_pin_binding()
1345 token_count, priv->array, le32_to_cpu(priv->size), in sof_parse_pin_binding()
1350 /* copy pin binding array to swidget only if it is defined in topology */ in sof_parse_pin_binding()
1354 ret = -ENOMEM; in sof_parse_pin_binding()
1358 swidget->input_pin_binding = pb; in sof_parse_pin_binding()
1360 swidget->output_pin_binding = pb; in sof_parse_pin_binding()
1377 w->no_wname_in_kcontrol_name = !!le32_to_cpu(velem->value); in get_w_no_wname_in_long_name()
1386 /* external widget init - used for any driver specific init */
1394 struct snd_soc_tplg_private *priv = &tw->priv; in sof_widget_ready()
1397 struct snd_sof_dai *dai; in sof_widget_ready() local
1403 return -ENOMEM; in sof_widget_ready()
1405 swidget->scomp = scomp; in sof_widget_ready()
1406 swidget->widget = w; in sof_widget_ready()
1407 swidget->comp_id = sdev->next_comp_id++; in sof_widget_ready()
1408 swidget->id = w->id; in sof_widget_ready()
1409 swidget->pipeline_id = index; in sof_widget_ready()
1410 swidget->private = NULL; in sof_widget_ready()
1411 mutex_init(&swidget->setup_mutex); in sof_widget_ready()
1413 ida_init(&swidget->output_queue_ida); in sof_widget_ready()
1414 ida_init(&swidget->input_queue_ida); in sof_widget_ready()
1417 priv->array, le32_to_cpu(priv->size)); in sof_widget_ready()
1419 dev_err(scomp->dev, "failed to parse dapm widget tokens for %s\n", in sof_widget_ready()
1420 w->name); in sof_widget_ready()
1425 ARRAY_SIZE(comp_pin_tokens), priv->array, in sof_widget_ready()
1426 le32_to_cpu(priv->size)); in sof_widget_ready()
1428 dev_err(scomp->dev, "failed to parse component pin tokens for %s\n", in sof_widget_ready()
1429 w->name); in sof_widget_ready()
1433 if (swidget->num_input_pins > SOF_WIDGET_MAX_NUM_PINS || in sof_widget_ready()
1434 swidget->num_output_pins > SOF_WIDGET_MAX_NUM_PINS) { in sof_widget_ready()
1435 dev_err(scomp->dev, "invalid pins for %s: [input: %d, output: %d]\n", in sof_widget_ready()
1436 swidget->widget->name, swidget->num_input_pins, swidget->num_output_pins); in sof_widget_ready()
1437 ret = -EINVAL; in sof_widget_ready()
1441 if (swidget->num_input_pins > 1) { in sof_widget_ready()
1443 /* on parsing error, pin binding is not allocated, nothing to free. */ in sof_widget_ready()
1445 dev_err(scomp->dev, "failed to parse input pin binding for %s\n", in sof_widget_ready()
1446 w->name); in sof_widget_ready()
1451 if (swidget->num_output_pins > 1) { in sof_widget_ready()
1453 /* on parsing error, pin binding is not allocated, nothing to free. */ in sof_widget_ready()
1455 dev_err(scomp->dev, "failed to parse output pin binding for %s\n", in sof_widget_ready()
1456 w->name); in sof_widget_ready()
1461 dev_dbg(scomp->dev, in sof_widget_ready()
1462 "tplg: widget %d (%s) is ready [type: %d, pipe: %d, pins: %d / %d, stream: %s]\n", in sof_widget_ready()
1463 swidget->comp_id, w->name, swidget->id, index, in sof_widget_ready()
1464 swidget->num_input_pins, swidget->num_output_pins, in sof_widget_ready()
1465 strnlen(w->sname, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) > 0 ? w->sname : "none"); in sof_widget_ready()
1467 widget_ops = tplg_ops ? tplg_ops->widget : NULL; in sof_widget_ready()
1469 token_list = widget_ops[w->id].token_list; in sof_widget_ready()
1470 token_list_size = widget_ops[w->id].token_list_size; in sof_widget_ready()
1474 switch (w->id) { in sof_widget_ready()
1477 dai = kzalloc(sizeof(*dai), GFP_KERNEL); in sof_widget_ready()
1478 if (!dai) { in sof_widget_ready()
1479 ret = -ENOMEM; in sof_widget_ready()
1485 ret = sof_connect_dai_widget(scomp, w, tw, dai); in sof_widget_ready()
1487 kfree(dai); in sof_widget_ready()
1490 list_add(&dai->list, &sdev->dai_list); in sof_widget_ready()
1491 swidget->private = dai; in sof_widget_ready()
1494 /* check we have some tokens - we need at least process type */ in sof_widget_ready()
1495 if (le32_to_cpu(tw->priv.size) == 0) { in sof_widget_ready()
1496 dev_err(scomp->dev, "error: process tokens not found\n"); in sof_widget_ready()
1497 ret = -EINVAL; in sof_widget_ready()
1503 if (!le32_to_cpu(tw->num_kcontrols)) { in sof_widget_ready()
1504 dev_err(scomp->dev, "invalid kcontrol count %d for volume\n", in sof_widget_ready()
1505 tw->num_kcontrols); in sof_widget_ready()
1506 ret = -EINVAL; in sof_widget_ready()
1527 dev_dbg(scomp->dev, "widget type %d name %s not handled\n", swidget->id, tw->name); in sof_widget_ready()
1533 dev_err(scomp->dev, in sof_widget_ready()
1535 swidget->id, tw->name, strnlen(tw->sname, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) > 0 in sof_widget_ready()
1536 ? tw->sname : "none"); in sof_widget_ready()
1541 swidget->core = SOF_DSP_PRIMARY_CORE; in sof_widget_ready()
1543 int core = sof_get_token_value(SOF_TKN_COMP_CORE_ID, swidget->tuples, in sof_widget_ready()
1544 swidget->num_tuples); in sof_widget_ready()
1547 swidget->core = core; in sof_widget_ready()
1551 if (tw->event_type) { in sof_widget_ready()
1552 if (widget_ops && widget_ops[w->id].bind_event) { in sof_widget_ready()
1553 ret = widget_ops[w->id].bind_event(scomp, swidget, in sof_widget_ready()
1554 le16_to_cpu(tw->event_type)); in sof_widget_ready()
1556 dev_err(scomp->dev, "widget event binding failed for %s\n", in sof_widget_ready()
1557 swidget->widget->name); in sof_widget_ready()
1564 if (w->id == snd_soc_dapm_scheduler) { in sof_widget_ready()
1569 ret = -ENOMEM; in sof_widget_ready()
1573 spipe->pipe_widget = swidget; in sof_widget_ready()
1574 swidget->spipe = spipe; in sof_widget_ready()
1575 list_add(&spipe->list, &sdev->pipeline_list); in sof_widget_ready()
1578 w->dobj.private = swidget; in sof_widget_ready()
1579 list_add(&swidget->list, &sdev->widget_list); in sof_widget_ready()
1582 kfree(swidget->private); in sof_widget_ready()
1583 kfree(swidget->tuples); in sof_widget_ready()
1594 sroute = dobj->private; in sof_route_unload()
1599 kfree(sroute->private); in sof_route_unload()
1600 list_del(&sroute->list); in sof_route_unload()
1618 struct snd_sof_dai *dai; in sof_widget_unload() local
1622 swidget = dobj->private; in sof_widget_unload()
1626 widget = swidget->widget; in sof_widget_unload()
1628 switch (swidget->id) { in sof_widget_unload()
1631 dai = swidget->private; in sof_widget_unload()
1633 if (dai) in sof_widget_unload()
1634 list_del(&dai->list); in sof_widget_unload()
1641 struct snd_sof_pipeline *spipe = swidget->spipe; in sof_widget_unload()
1643 list_del(&spipe->list); in sof_widget_unload()
1645 swidget->spipe = NULL; in sof_widget_unload()
1651 for (i = 0; i < widget->num_kcontrols; i++) { in sof_widget_unload()
1652 kc = &widget->kcontrol_news[i]; in sof_widget_unload()
1653 switch (widget->dobj.widget.kcontrol_type[i]) { in sof_widget_unload()
1655 sm = (struct soc_mixer_control *)kc->private_value; in sof_widget_unload()
1656 scontrol = sm->dobj.private; in sof_widget_unload()
1657 if (sm->max > 1) in sof_widget_unload()
1658 kfree(scontrol->volume_table); in sof_widget_unload()
1661 se = (struct soc_enum *)kc->private_value; in sof_widget_unload()
1662 scontrol = se->dobj.private; in sof_widget_unload()
1665 sbe = (struct soc_bytes_ext *)kc->private_value; in sof_widget_unload()
1666 scontrol = sbe->dobj.private; in sof_widget_unload()
1669 dev_warn(scomp->dev, "unsupported kcontrol_type\n"); in sof_widget_unload()
1672 kfree(scontrol->ipc_control_data); in sof_widget_unload()
1673 list_del(&scontrol->list); in sof_widget_unload()
1674 kfree(scontrol->name); in sof_widget_unload()
1680 widget_ops = tplg_ops ? tplg_ops->widget : NULL; in sof_widget_unload()
1681 if (widget_ops && widget_ops[swidget->id].ipc_free) in sof_widget_unload()
1682 widget_ops[swidget->id].ipc_free(swidget); in sof_widget_unload()
1684 ida_destroy(&swidget->output_queue_ida); in sof_widget_unload()
1685 ida_destroy(&swidget->input_queue_ida); in sof_widget_unload()
1690 kfree(swidget->tuples); in sof_widget_unload()
1693 list_del(&swidget->list); in sof_widget_unload()
1700 * DAI HW configuration.
1703 /* FE DAI - used for any driver specific init */
1706 struct snd_soc_tplg_pcm *pcm, struct snd_soc_dai *dai) in sof_dai_load() argument
1711 struct snd_soc_tplg_private *private = &pcm->priv; in sof_dai_load()
1722 return -ENOMEM; in sof_dai_load()
1724 spcm->scomp = scomp; in sof_dai_load()
1727 spcm->stream[stream].comp_id = COMP_ID_UNASSIGNED; in sof_dai_load()
1728 if (pcm->compress) in sof_dai_load()
1729 snd_sof_compr_init_elapsed_work(&spcm->stream[stream].period_elapsed_work); in sof_dai_load()
1731 snd_sof_pcm_init_elapsed_work(&spcm->stream[stream].period_elapsed_work); in sof_dai_load()
1734 spcm->pcm = *pcm; in sof_dai_load()
1735 dev_dbg(scomp->dev, "tplg: load pcm %s\n", pcm->dai_name); in sof_dai_load()
1738 if (ipc_pcm_ops && ipc_pcm_ops->pcm_setup) { in sof_dai_load()
1739 ret = ipc_pcm_ops->pcm_setup(sdev, spcm); in sof_dai_load()
1746 dai_drv->dobj.private = spcm; in sof_dai_load()
1747 list_add(&spcm->list, &sdev->pcm_list); in sof_dai_load()
1750 ARRAY_SIZE(stream_tokens), private->array, in sof_dai_load()
1751 le32_to_cpu(private->size)); in sof_dai_load()
1753 dev_err(scomp->dev, "error: parse stream tokens failed %d\n", in sof_dai_load()
1754 le32_to_cpu(private->size)); in sof_dai_load()
1759 if (!spcm->pcm.playback) in sof_dai_load()
1764 caps = &spcm->pcm.caps[stream]; in sof_dai_load()
1767 ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, sdev->dev, in sof_dai_load()
1768 PAGE_SIZE, &spcm->stream[stream].page_table); in sof_dai_load()
1770 dev_err(scomp->dev, "error: can't alloc page table for %s %d\n", in sof_dai_load()
1771 caps->name, ret); in sof_dai_load()
1779 dev_err(scomp->dev, in sof_dai_load()
1788 if (!spcm->pcm.capture) in sof_dai_load()
1791 caps = &spcm->pcm.caps[stream]; in sof_dai_load()
1794 ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, sdev->dev, in sof_dai_load()
1795 PAGE_SIZE, &spcm->stream[stream].page_table); in sof_dai_load()
1797 dev_err(scomp->dev, "error: can't alloc page table for %s %d\n", in sof_dai_load()
1798 caps->name, ret); in sof_dai_load()
1805 dev_err(scomp->dev, in sof_dai_load()
1807 snd_dma_free_pages(&spcm->stream[stream].page_table); in sof_dai_load()
1814 if (spcm->pcm.playback) in sof_dai_load()
1815 snd_dma_free_pages(&spcm->stream[SNDRV_PCM_STREAM_PLAYBACK].page_table); in sof_dai_load()
1825 struct snd_sof_pcm *spcm = dobj->private; in sof_dai_unload()
1828 if (spcm->pcm.playback) in sof_dai_unload()
1829 snd_dma_free_pages(&spcm->stream[SNDRV_PCM_STREAM_PLAYBACK].page_table); in sof_dai_unload()
1831 if (spcm->pcm.capture) in sof_dai_unload()
1832 snd_dma_free_pages(&spcm->stream[SNDRV_PCM_STREAM_CAPTURE].page_table); in sof_dai_unload()
1835 if (ipc_pcm_ops && ipc_pcm_ops->pcm_free) in sof_dai_unload()
1836 ipc_pcm_ops->pcm_free(sdev, spcm); in sof_dai_unload()
1839 list_del(&spcm->list); in sof_dai_unload()
1850 /* DAI link - used for any driver specific init */
1856 struct snd_soc_tplg_private *private = &cfg->priv; in sof_link_load()
1863 if (!link->platforms) { in sof_link_load()
1864 dev_err(scomp->dev, "error: no platforms\n"); in sof_link_load()
1865 return -EINVAL; in sof_link_load()
1867 link->platforms->name = dev_name(scomp->dev); in sof_link_load()
1869 if (tplg_ops && tplg_ops->link_setup) { in sof_link_load()
1870 ret = tplg_ops->link_setup(sdev, link); in sof_link_load()
1875 /* Set nonatomic property for FE dai links as their trigger action involves IPC's */ in sof_link_load()
1876 if (!link->no_pcm) { in sof_link_load()
1877 link->nonatomic = true; in sof_link_load()
1881 /* check we have some tokens - we need at least DAI type */ in sof_link_load()
1882 if (le32_to_cpu(private->size) == 0) { in sof_link_load()
1883 dev_err(scomp->dev, "error: expected tokens for DAI, none found\n"); in sof_link_load()
1884 return -EINVAL; in sof_link_load()
1889 return -ENOMEM; in sof_link_load()
1891 slink->num_hw_configs = le32_to_cpu(cfg->num_hw_configs); in sof_link_load()
1892 slink->hw_configs = kmemdup_array(cfg->hw_config, in sof_link_load()
1893 slink->num_hw_configs, sizeof(*slink->hw_configs), in sof_link_load()
1895 if (!slink->hw_configs) { in sof_link_load()
1897 return -ENOMEM; in sof_link_load()
1900 slink->default_hw_cfg_id = le32_to_cpu(cfg->default_hw_config_id); in sof_link_load()
1901 slink->link = link; in sof_link_load()
1903 dev_dbg(scomp->dev, "tplg: %d hw_configs found, default id: %d for dai link %s!\n", in sof_link_load()
1904 slink->num_hw_configs, slink->default_hw_cfg_id, link->name); in sof_link_load()
1908 private->array, le32_to_cpu(private->size)); in sof_link_load()
1910 dev_err(scomp->dev, "Failed tp parse common DAI link tokens\n"); in sof_link_load()
1911 kfree(slink->hw_configs); in sof_link_load()
1916 token_list = tplg_ops ? tplg_ops->token_list : NULL; in sof_link_load()
1922 num_sets = slink->num_hw_configs; in sof_link_load()
1923 switch (slink->type) { in sof_link_load()
1926 num_tuples += token_list[SOF_SSP_TOKENS].count * slink->num_hw_configs; in sof_link_load()
1980 slink->tuples = kcalloc(num_tuples, sizeof(*slink->tuples), GFP_KERNEL); in sof_link_load()
1981 if (!slink->tuples) { in sof_link_load()
1982 kfree(slink->hw_configs); in sof_link_load()
1984 return -ENOMEM; in sof_link_load()
1988 /* parse one set of DAI link tokens */ in sof_link_load()
1989 ret = sof_copy_tuples(sdev, private->array, le32_to_cpu(private->size), in sof_link_load()
1990 SOF_DAI_LINK_TOKENS, 1, slink->tuples, in sof_link_load()
1991 num_tuples, &slink->num_tuples); in sof_link_load()
1993 dev_err(scomp->dev, "failed to parse %s for dai link %s\n", in sof_link_load()
1994 token_list[SOF_DAI_LINK_TOKENS].name, link->name); in sof_link_load()
1999 /* nothing more to do if there are no DAI type-specific tokens defined */ in sof_link_load()
2003 /* parse "num_sets" sets of DAI-specific tokens */ in sof_link_load()
2004 ret = sof_copy_tuples(sdev, private->array, le32_to_cpu(private->size), in sof_link_load()
2005 token_id, num_sets, slink->tuples, num_tuples, &slink->num_tuples); in sof_link_load()
2007 dev_err(scomp->dev, "failed to parse %s for dai link %s\n", in sof_link_load()
2008 token_list[token_id].name, link->name); in sof_link_load()
2015 slink->tuples, slink->num_tuples); in sof_link_load()
2018 dev_err(sdev->dev, "Invalid active PDM count for %s\n", link->name); in sof_link_load()
2023 ret = sof_copy_tuples(sdev, private->array, le32_to_cpu(private->size), in sof_link_load()
2024 SOF_DMIC_PDM_TOKENS, num_sets, slink->tuples, in sof_link_load()
2025 num_tuples, &slink->num_tuples); in sof_link_load()
2027 dev_err(scomp->dev, "failed to parse %s for dai link %s\n", in sof_link_load()
2028 token_list[SOF_DMIC_PDM_TOKENS].name, link->name); in sof_link_load()
2033 link->dobj.private = slink; in sof_link_load()
2034 list_add(&slink->list, &sdev->dai_link_list); in sof_link_load()
2039 kfree(slink->tuples); in sof_link_load()
2040 kfree(slink->hw_configs); in sof_link_load()
2048 struct snd_sof_dai_link *slink = dobj->private; in sof_link_unload()
2053 slink->link->platforms->name = NULL; in sof_link_unload()
2055 kfree(slink->tuples); in sof_link_unload()
2056 list_del(&slink->list); in sof_link_unload()
2057 kfree(slink->hw_configs); in sof_link_unload()
2059 dobj->private = NULL; in sof_link_unload()
2064 /* DAI link - used for any driver specific init */
2070 struct snd_soc_dobj *dobj = &route->dobj; in sof_route_load()
2077 return -ENOMEM; in sof_route_load()
2079 sroute->scomp = scomp; in sof_route_load()
2080 dev_dbg(scomp->dev, "sink %s control %s source %s\n", in sof_route_load()
2081 route->sink, route->control ? route->control : "none", in sof_route_load()
2082 route->source); in sof_route_load()
2085 source_swidget = snd_sof_find_swidget(scomp, (char *)route->source); in sof_route_load()
2087 dev_err(scomp->dev, "error: source %s not found\n", in sof_route_load()
2088 route->source); in sof_route_load()
2089 ret = -EINVAL; in sof_route_load()
2096 * So, don't send routes whose source/sink widget is of such types in sof_route_load()
2099 if (source_swidget->id == snd_soc_dapm_out_drv || in sof_route_load()
2100 source_swidget->id == snd_soc_dapm_output) in sof_route_load()
2104 sink_swidget = snd_sof_find_swidget(scomp, (char *)route->sink); in sof_route_load()
2106 dev_err(scomp->dev, "error: sink %s not found\n", in sof_route_load()
2107 route->sink); in sof_route_load()
2108 ret = -EINVAL; in sof_route_load()
2113 * Don't send routes whose sink widget is of type in sof_route_load()
2116 if (sink_swidget->id == snd_soc_dapm_out_drv || in sof_route_load()
2117 sink_swidget->id == snd_soc_dapm_output) in sof_route_load()
2120 sroute->route = route; in sof_route_load()
2121 dobj->private = sroute; in sof_route_load()
2122 sroute->src_widget = source_swidget; in sof_route_load()
2123 sroute->sink_widget = sink_swidget; in sof_route_load()
2126 list_add(&sroute->list, &sdev->route_list); in sof_route_load()
2135 * sof_set_widget_pipeline - Set pipeline for a component
2140 * Return: 0 if successful, -EINVAL on error.
2141 * The function checks if @swidget is associated with any volatile controls. If so, setting
2142 * the dynamic_pipeline_widget is disallowed.
2147 struct snd_sof_widget *pipe_widget = spipe->pipe_widget; in sof_set_widget_pipeline()
2150 if (pipe_widget->dynamic_pipeline_widget) { in sof_set_widget_pipeline()
2152 list_for_each_entry(scontrol, &sdev->kcontrol_list, list) in sof_set_widget_pipeline()
2153 if (scontrol->comp_id == swidget->comp_id && in sof_set_widget_pipeline()
2154 (scontrol->access & SNDRV_CTL_ELEM_ACCESS_VOLATILE)) { in sof_set_widget_pipeline()
2155 dev_err(sdev->dev, in sof_set_widget_pipeline()
2157 swidget->widget->name); in sof_set_widget_pipeline()
2158 return -EINVAL; in sof_set_widget_pipeline()
2163 swidget->spipe = spipe; in sof_set_widget_pipeline()
2164 swidget->dynamic_pipeline_widget = pipe_widget->dynamic_pipeline_widget; in sof_set_widget_pipeline()
2169 /* completion - called at completion of firmware loading */
2179 widget_ops = tplg_ops ? tplg_ops->widget : NULL; in sof_complete()
2182 if (tplg_ops && tplg_ops->control_setup) in sof_complete()
2183 list_for_each_entry(scontrol, &sdev->kcontrol_list, list) { in sof_complete()
2184 ret = tplg_ops->control_setup(sdev, scontrol); in sof_complete()
2186 dev_err(sdev->dev, "failed updating IPC struct for control %s\n", in sof_complete()
2187 scontrol->name); in sof_complete()
2193 list_for_each_entry(spipe, &sdev->pipeline_list, list) { in sof_complete()
2194 struct snd_sof_widget *pipe_widget = spipe->pipe_widget; in sof_complete()
2197 pipe_widget->instance_id = -EINVAL; in sof_complete()
2200 if (widget_ops && widget_ops[pipe_widget->id].ipc_setup) { in sof_complete()
2201 ret = widget_ops[pipe_widget->id].ipc_setup(pipe_widget); in sof_complete()
2203 dev_err(sdev->dev, "failed updating IPC struct for %s\n", in sof_complete()
2204 pipe_widget->widget->name); in sof_complete()
2210 list_for_each_entry(swidget, &sdev->widget_list, list) in sof_complete()
2211 if (swidget->widget->id != snd_soc_dapm_scheduler && in sof_complete()
2212 swidget->pipeline_id == pipe_widget->pipeline_id) { in sof_complete()
2217 if (widget_ops && widget_ops[swidget->id].ipc_setup) { in sof_complete()
2218 ret = widget_ops[swidget->id].ipc_setup(swidget); in sof_complete()
2220 dev_err(sdev->dev, in sof_complete()
2222 swidget->widget->name); in sof_complete()
2231 if (tplg_ops && tplg_ops->set_up_all_pipelines && in sof_complete()
2232 tplg_ops->tear_down_all_pipelines) { in sof_complete()
2233 ret = tplg_ops->set_up_all_pipelines(sdev, true); in sof_complete()
2235 dev_err(sdev->dev, "Failed to set up all topology pipelines: %d\n", in sof_complete()
2240 ret = tplg_ops->tear_down_all_pipelines(sdev, true); in sof_complete()
2242 dev_err(sdev->dev, "Failed to tear down topology pipelines: %d\n", in sof_complete()
2250 if (tplg_ops && tplg_ops->set_up_all_pipelines) in sof_complete()
2251 return tplg_ops->set_up_all_pipelines(sdev, false); in sof_complete()
2256 /* manifest - optional to inform component of manifest */
2263 if (tplg_ops && tplg_ops->parse_manifest) in sof_manifest()
2264 return tplg_ops->parse_manifest(scomp, index, man); in sof_manifest()
2284 /* external kcontrol init - used for any driver specific init */
2288 /* external kcontrol init - used for any driver specific init */
2292 /* external widget init - used for any driver specific init */
2293 /* .widget_load is not currently used */
2297 /* FE DAI - used for any driver specific init */
2301 /* DAI link - used for any driver specific init */
2305 /* completion - called at completion of firmware loading */
2308 /* manifest - optional to inform component of manifest */
2352 /* external widget init - used for any driver specific init */
2357 if (WIDGET_IS_DAI(w->id)) { in sof_dspless_widget_ready()
2361 struct snd_soc_tplg_private *priv = &tw->priv; in sof_dspless_widget_ready()
2368 return -ENOMEM; in sof_dspless_widget_ready()
2373 return -ENOMEM; in sof_dspless_widget_ready()
2376 ret = sof_parse_tokens(scomp, &sdai->type, dai_tokens, ARRAY_SIZE(dai_tokens), in sof_dspless_widget_ready()
2377 priv->array, le32_to_cpu(priv->size)); in sof_dspless_widget_ready()
2379 dev_err(scomp->dev, "Failed to parse DAI tokens for %s\n", tw->name); in sof_dspless_widget_ready()
2392 swidget->scomp = scomp; in sof_dspless_widget_ready()
2393 swidget->widget = w; in sof_dspless_widget_ready()
2394 swidget->private = sdai; in sof_dspless_widget_ready()
2395 mutex_init(&swidget->setup_mutex); in sof_dspless_widget_ready()
2396 w->dobj.private = swidget; in sof_dspless_widget_ready()
2397 list_add(&swidget->list, &sdev->widget_list); in sof_dspless_widget_ready()
2408 if (WIDGET_IS_DAI(w->id)) { in sof_dspless_widget_unload()
2409 struct snd_sof_widget *swidget = dobj->private; in sof_dspless_widget_unload()
2417 list_del(&swidget->list); in sof_dspless_widget_unload()
2418 kfree(swidget->private); in sof_dspless_widget_unload()
2429 link->platforms->name = dev_name(scomp->dev); in sof_dspless_link_load()
2431 /* Set nonatomic property for FE dai links for FE-BE compatibility */ in sof_dspless_link_load()
2432 if (!link->no_pcm) in sof_dspless_link_load()
2433 link->nonatomic = true; in sof_dspless_link_load()
2439 /* external widget init - used for any driver specific init */
2443 /* FE DAI - used for any driver specific init */
2447 /* DAI link - used for any driver specific init */
2465 dev_dbg(scomp->dev, "loading topology:%s\n", file); in snd_sof_load_topology()
2467 ret = request_firmware(&fw, file, scomp->dev); in snd_sof_load_topology()
2469 dev_err(scomp->dev, "error: tplg request firmware %s failed err: %d\n", in snd_sof_load_topology()
2471 dev_err(scomp->dev, in snd_sof_load_topology()
2472 "you may need to download the firmware from https://github.com/thesofproject/sof-bin/\n"); in snd_sof_load_topology()
2476 if (sdev->dspless_mode_selected) in snd_sof_load_topology()
2482 dev_err(scomp->dev, "error: tplg component load failed %d\n", in snd_sof_load_topology()
2484 ret = -EINVAL; in snd_sof_load_topology()
2489 if (ret >= 0 && sdev->led_present) in snd_sof_load_topology()