Lines Matching +full:be +full:- +full:dai +full:- +full:link
1 // SPDX-License-Identifier: GPL-2.0+
3 // soc-topology.c -- ALSA SoC Topology
17 // topology data can contain kcontrols, DAPM graphs, widgets, DAIs, DAI links,
29 #include <sound/soc-dapm.h>
30 #include <sound/soc-topology.h>
36 * We make several passes over the data (since it wont necessarily be ordered)
38 * drivers will be ready with any vendor data before the mixers and DAPM objects
83 const u8 *end = tplg->pos + elem_size * count; in soc_tplg_check_elem_count()
85 if (end > tplg->fw->data + tplg->fw->size) { in soc_tplg_check_elem_count()
86 dev_err(tplg->dev, "ASoC: %s overflow end of data\n", in soc_tplg_check_elem_count()
88 return -EINVAL; in soc_tplg_check_elem_count()
94 dev_err(tplg->dev, in soc_tplg_check_elem_count()
97 return -EINVAL; in soc_tplg_check_elem_count()
105 const u8 *end = tplg->hdr_pos; in soc_tplg_is_eof()
107 if (end >= tplg->fw->data + tplg->fw->size) in soc_tplg_is_eof()
114 return (unsigned long)(tplg->hdr_pos - tplg->fw->data); in soc_tplg_get_hdr_offset()
119 return (unsigned long)(tplg->pos - tplg->fw->data); in soc_tplg_get_offset()
195 return -EINVAL; in tplg_chan_get_reg()
208 return -EINVAL; in tplg_chan_get_shift()
220 return -EINVAL; in get_widget_id()
226 dev_err(tplg->dev, in soc_bind_err()
228 hdr->ops.get, hdr->ops.put, hdr->ops.info, index, in soc_bind_err()
235 dev_err(tplg->dev, in soc_control_err()
237 name, hdr->ops.get, hdr->ops.put, hdr->ops.info, in soc_control_err()
247 if (tplg->ops && tplg->ops->vendor_load) in soc_tplg_vendor_load()
248 ret = tplg->ops->vendor_load(tplg->comp, tplg->index, hdr); in soc_tplg_vendor_load()
250 dev_err(tplg->dev, "ASoC: no vendor load callback for ID %d\n", in soc_tplg_vendor_load()
251 hdr->vendor_type); in soc_tplg_vendor_load()
252 return -EINVAL; in soc_tplg_vendor_load()
256 dev_err(tplg->dev, in soc_tplg_vendor_load()
260 hdr->type, hdr->vendor_type); in soc_tplg_vendor_load()
269 if (tplg->ops && tplg->ops->widget_load) in soc_tplg_widget_load()
270 return tplg->ops->widget_load(tplg->comp, tplg->index, w, in soc_tplg_widget_load()
281 if (tplg->ops && tplg->ops->widget_ready) in soc_tplg_widget_ready()
282 return tplg->ops->widget_ready(tplg->comp, tplg->index, w, in soc_tplg_widget_ready()
288 /* pass DAI configurations to component driver for extra initialization */
291 struct snd_soc_tplg_pcm *pcm, struct snd_soc_dai *dai) in soc_tplg_dai_load() argument
293 if (tplg->ops && tplg->ops->dai_load) in soc_tplg_dai_load()
294 return tplg->ops->dai_load(tplg->comp, tplg->index, dai_drv, in soc_tplg_dai_load()
295 pcm, dai); in soc_tplg_dai_load()
300 /* pass link configurations to component driver for extra initialization */
302 struct snd_soc_dai_link *link, struct snd_soc_tplg_link_config *cfg) in soc_tplg_dai_link_load() argument
304 if (tplg->ops && tplg->ops->link_load) in soc_tplg_dai_link_load()
305 return tplg->ops->link_load(tplg->comp, tplg->index, link, cfg); in soc_tplg_dai_link_load()
313 if (tplg->ops && tplg->ops->complete) in soc_tplg_complete()
314 return tplg->ops->complete(tplg->comp); in soc_tplg_complete()
326 *kcontrol = snd_soc_cnew(control_new, data, control_new->name, prefix); in soc_tplg_add_dcontrol()
329 control_new->name); in soc_tplg_add_dcontrol()
330 return -ENOMEM; in soc_tplg_add_dcontrol()
336 control_new->name, err); in soc_tplg_add_dcontrol()
347 struct snd_soc_component *comp = tplg->comp; in soc_tplg_add_kcontrol()
349 return soc_tplg_add_dcontrol(comp->card->snd_card, in soc_tplg_add_kcontrol()
350 tplg->dev, k, comp->name_prefix, comp, kcontrol); in soc_tplg_add_kcontrol()
357 struct snd_card *card = comp->card->snd_card; in soc_tplg_remove_kcontrol()
362 if (dobj->unload) in soc_tplg_remove_kcontrol()
363 dobj->unload(comp, dobj); in soc_tplg_remove_kcontrol()
365 snd_ctl_remove(card, dobj->control.kcontrol); in soc_tplg_remove_kcontrol()
366 list_del(&dobj->list); in soc_tplg_remove_kcontrol()
376 if (dobj->unload) in soc_tplg_remove_route()
377 dobj->unload(comp, dobj); in soc_tplg_remove_route()
379 list_del(&dobj->list); in soc_tplg_remove_route()
382 /* remove a widget and it's kcontrols - routes must be removed first */
386 struct snd_card *card = comp->card->snd_card; in soc_tplg_remove_widget()
394 if (dobj->unload) in soc_tplg_remove_widget()
395 dobj->unload(comp, dobj); in soc_tplg_remove_widget()
397 if (w->kcontrols) in soc_tplg_remove_widget()
398 for (i = 0; i < w->num_kcontrols; i++) in soc_tplg_remove_widget()
399 snd_ctl_remove(card, w->kcontrols[i]); in soc_tplg_remove_widget()
401 list_del(&dobj->list); in soc_tplg_remove_widget()
403 /* widget w is freed by soc-dapm.c */ in soc_tplg_remove_widget()
406 /* remove DAI configurations */
412 struct snd_soc_dai *dai, *_dai; in soc_tplg_remove_dai() local
417 if (dobj->unload) in soc_tplg_remove_dai()
418 dobj->unload(comp, dobj); in soc_tplg_remove_dai()
420 for_each_component_dais_safe(comp, dai, _dai) in soc_tplg_remove_dai()
421 if (dai->driver == dai_drv) in soc_tplg_remove_dai()
422 snd_soc_unregister_dai(dai); in soc_tplg_remove_dai()
424 list_del(&dobj->list); in soc_tplg_remove_dai()
427 /* remove link configurations */
431 struct snd_soc_dai_link *link = in soc_tplg_remove_link() local
437 if (dobj->unload) in soc_tplg_remove_link()
438 dobj->unload(comp, dobj); in soc_tplg_remove_link()
440 list_del(&dobj->list); in soc_tplg_remove_link()
441 snd_soc_remove_pcm_runtime(comp->card, in soc_tplg_remove_link()
442 snd_soc_get_pcm_runtime(comp->card, link)); in soc_tplg_remove_link()
445 /* unload dai link */
452 if (dobj->unload) in remove_backend_link()
453 dobj->unload(comp, dobj); in remove_backend_link()
456 * We don't free the link here as what soc_tplg_remove_link() do since BE in remove_backend_link()
460 dobj->type = SND_SOC_DOBJ_NONE; in remove_backend_link()
461 list_del(&dobj->list); in remove_backend_link()
473 if (le32_to_cpu(hdr->ops.info) == SND_SOC_TPLG_CTL_BYTES in soc_tplg_kcontrol_bind_io()
474 && k->iface & SNDRV_CTL_ELEM_IFACE_MIXER in soc_tplg_kcontrol_bind_io()
475 && (k->access & SNDRV_CTL_ELEM_ACCESS_TLV_READ in soc_tplg_kcontrol_bind_io()
476 || k->access & SNDRV_CTL_ELEM_ACCESS_TLV_WRITE) in soc_tplg_kcontrol_bind_io()
477 && k->access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK) { in soc_tplg_kcontrol_bind_io()
479 struct snd_soc_tplg_bytes_control *be; in soc_tplg_kcontrol_bind_io() local
481 sbe = (struct soc_bytes_ext *)k->private_value; in soc_tplg_kcontrol_bind_io()
482 be = container_of(hdr, struct snd_soc_tplg_bytes_control, hdr); in soc_tplg_kcontrol_bind_io()
487 k->info = snd_soc_bytes_info_ext; in soc_tplg_kcontrol_bind_io()
488 k->tlv.c = snd_soc_bytes_tlv_callback; in soc_tplg_kcontrol_bind_io()
491 * When a topology-based implementation abuses the in soc_tplg_kcontrol_bind_io()
495 * return an -EINVAL error and prevent the card from in soc_tplg_kcontrol_bind_io()
498 if (sbe->max > 512) in soc_tplg_kcontrol_bind_io()
499 k->access |= SNDRV_CTL_ELEM_ACCESS_SKIP_CHECK; in soc_tplg_kcontrol_bind_io()
501 ext_ops = tplg->bytes_ext_ops; in soc_tplg_kcontrol_bind_io()
502 num_ops = tplg->bytes_ext_ops_count; in soc_tplg_kcontrol_bind_io()
504 if (!sbe->put && in soc_tplg_kcontrol_bind_io()
505 ext_ops[i].id == le32_to_cpu(be->ext_ops.put)) in soc_tplg_kcontrol_bind_io()
506 sbe->put = ext_ops[i].put; in soc_tplg_kcontrol_bind_io()
507 if (!sbe->get && in soc_tplg_kcontrol_bind_io()
508 ext_ops[i].id == le32_to_cpu(be->ext_ops.get)) in soc_tplg_kcontrol_bind_io()
509 sbe->get = ext_ops[i].get; in soc_tplg_kcontrol_bind_io()
512 if ((k->access & SNDRV_CTL_ELEM_ACCESS_TLV_READ) && !sbe->get) in soc_tplg_kcontrol_bind_io()
513 return -EINVAL; in soc_tplg_kcontrol_bind_io()
514 if ((k->access & SNDRV_CTL_ELEM_ACCESS_TLV_WRITE) && !sbe->put) in soc_tplg_kcontrol_bind_io()
515 return -EINVAL; in soc_tplg_kcontrol_bind_io()
520 ops = tplg->io_ops; in soc_tplg_kcontrol_bind_io()
521 num_ops = tplg->io_ops_count; in soc_tplg_kcontrol_bind_io()
524 if (k->put == NULL && ops[i].id == le32_to_cpu(hdr->ops.put)) in soc_tplg_kcontrol_bind_io()
525 k->put = ops[i].put; in soc_tplg_kcontrol_bind_io()
526 if (k->get == NULL && ops[i].id == le32_to_cpu(hdr->ops.get)) in soc_tplg_kcontrol_bind_io()
527 k->get = ops[i].get; in soc_tplg_kcontrol_bind_io()
528 if (k->info == NULL && ops[i].id == le32_to_cpu(hdr->ops.info)) in soc_tplg_kcontrol_bind_io()
529 k->info = ops[i].info; in soc_tplg_kcontrol_bind_io()
533 if (k->put && k->get && k->info) in soc_tplg_kcontrol_bind_io()
541 if (k->put == NULL && ops[i].id == le32_to_cpu(hdr->ops.put)) in soc_tplg_kcontrol_bind_io()
542 k->put = ops[i].put; in soc_tplg_kcontrol_bind_io()
543 if (k->get == NULL && ops[i].id == le32_to_cpu(hdr->ops.get)) in soc_tplg_kcontrol_bind_io()
544 k->get = ops[i].get; in soc_tplg_kcontrol_bind_io()
545 if (k->info == NULL && ops[i].id == le32_to_cpu(hdr->ops.info)) in soc_tplg_kcontrol_bind_io()
546 k->info = ops[i].info; in soc_tplg_kcontrol_bind_io()
550 if (k->put && k->get && k->info) in soc_tplg_kcontrol_bind_io()
554 return -EINVAL; in soc_tplg_kcontrol_bind_io()
564 w->event = NULL; in snd_soc_tplg_widget_bind_event()
569 /* found - so assign event */ in snd_soc_tplg_widget_bind_event()
570 w->event = events[i].event_handler; in snd_soc_tplg_widget_bind_event()
576 return -EINVAL; in snd_soc_tplg_widget_bind_event()
586 if (tplg->ops && tplg->ops->control_load) in soc_tplg_control_load()
587 ret = tplg->ops->control_load(tplg->comp, tplg->index, k, hdr); in soc_tplg_control_load()
590 dev_err(tplg->dev, "ASoC: failed to init %s\n", hdr->name); in soc_tplg_control_load()
602 p = devm_kzalloc(tplg->dev, item_len + 2 * sizeof(unsigned int), GFP_KERNEL); in soc_tplg_create_tlv_db_scale()
604 return -ENOMEM; in soc_tplg_create_tlv_db_scale()
608 p[2] = le32_to_cpu(scale->min); in soc_tplg_create_tlv_db_scale()
609 p[3] = (le32_to_cpu(scale->step) & TLV_DB_SCALE_MASK) in soc_tplg_create_tlv_db_scale()
610 | (le32_to_cpu(scale->mute) ? TLV_DB_SCALE_MUTE : 0); in soc_tplg_create_tlv_db_scale()
612 kc->tlv.p = (void *)p; in soc_tplg_create_tlv_db_scale()
620 u32 access = le32_to_cpu(tc->access); in soc_tplg_create_tlv()
626 tplg_tlv = &tc->tlv; in soc_tplg_create_tlv()
627 switch (le32_to_cpu(tplg_tlv->type)) { in soc_tplg_create_tlv()
630 &tplg_tlv->scale); in soc_tplg_create_tlv()
634 dev_dbg(tplg->dev, "Unsupported TLV type %d\n", in soc_tplg_create_tlv()
635 tplg_tlv->type); in soc_tplg_create_tlv()
636 return -EINVAL; in soc_tplg_create_tlv()
649 mc = (struct snd_soc_tplg_mixer_control *)tplg->pos; in soc_tplg_control_dmixer_create()
652 if (strnlen(mc->hdr.name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == SNDRV_CTL_ELEM_ID_NAME_MAXLEN) in soc_tplg_control_dmixer_create()
653 return -EINVAL; in soc_tplg_control_dmixer_create()
655 sm = devm_kzalloc(tplg->dev, sizeof(*sm), GFP_KERNEL); in soc_tplg_control_dmixer_create()
657 return -ENOMEM; in soc_tplg_control_dmixer_create()
659 tplg->pos += sizeof(struct snd_soc_tplg_mixer_control) + le32_to_cpu(mc->priv.size); in soc_tplg_control_dmixer_create()
661 dev_dbg(tplg->dev, "ASoC: adding mixer kcontrol %s with access 0x%x\n", in soc_tplg_control_dmixer_create()
662 mc->hdr.name, mc->hdr.access); in soc_tplg_control_dmixer_create()
664 kc->name = devm_kstrdup(tplg->dev, mc->hdr.name, GFP_KERNEL); in soc_tplg_control_dmixer_create()
665 if (!kc->name) in soc_tplg_control_dmixer_create()
666 return -ENOMEM; in soc_tplg_control_dmixer_create()
667 kc->private_value = (long)sm; in soc_tplg_control_dmixer_create()
668 kc->iface = SNDRV_CTL_ELEM_IFACE_MIXER; in soc_tplg_control_dmixer_create()
669 kc->access = le32_to_cpu(mc->hdr.access); in soc_tplg_control_dmixer_create()
672 sm->reg = tplg_chan_get_reg(tplg, mc->channel, SNDRV_CHMAP_FL); in soc_tplg_control_dmixer_create()
673 sm->rreg = tplg_chan_get_reg(tplg, mc->channel, SNDRV_CHMAP_FR); in soc_tplg_control_dmixer_create()
674 sm->shift = tplg_chan_get_shift(tplg, mc->channel, SNDRV_CHMAP_FL); in soc_tplg_control_dmixer_create()
675 sm->rshift = tplg_chan_get_shift(tplg, mc->channel, SNDRV_CHMAP_FR); in soc_tplg_control_dmixer_create()
677 sm->max = le32_to_cpu(mc->max); in soc_tplg_control_dmixer_create()
678 sm->min = le32_to_cpu(mc->min); in soc_tplg_control_dmixer_create()
679 sm->invert = le32_to_cpu(mc->invert); in soc_tplg_control_dmixer_create()
680 sm->platform_max = le32_to_cpu(mc->platform_max); in soc_tplg_control_dmixer_create()
683 err = soc_tplg_kcontrol_bind_io(&mc->hdr, kc, tplg); in soc_tplg_control_dmixer_create()
685 soc_control_err(tplg, &mc->hdr, mc->hdr.name); in soc_tplg_control_dmixer_create()
690 err = soc_tplg_create_tlv(tplg, kc, &mc->hdr); in soc_tplg_control_dmixer_create()
692 dev_err(tplg->dev, "ASoC: failed to create TLV %s\n", mc->hdr.name); in soc_tplg_control_dmixer_create()
697 return soc_tplg_control_load(tplg, kc, &mc->hdr); in soc_tplg_control_dmixer_create()
705 if (le32_to_cpu(ec->items) > ARRAY_SIZE(ec->texts)) in soc_tplg_denum_create_texts()
706 return -EINVAL; in soc_tplg_denum_create_texts()
708 se->dobj.control.dtexts = in soc_tplg_denum_create_texts()
709 devm_kcalloc(tplg->dev, le32_to_cpu(ec->items), sizeof(char *), GFP_KERNEL); in soc_tplg_denum_create_texts()
710 if (se->dobj.control.dtexts == NULL) in soc_tplg_denum_create_texts()
711 return -ENOMEM; in soc_tplg_denum_create_texts()
713 for (i = 0; i < le32_to_cpu(ec->items); i++) { in soc_tplg_denum_create_texts()
715 if (strnlen(ec->texts[i], SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == in soc_tplg_denum_create_texts()
717 ret = -EINVAL; in soc_tplg_denum_create_texts()
721 se->dobj.control.dtexts[i] = devm_kstrdup(tplg->dev, ec->texts[i], GFP_KERNEL); in soc_tplg_denum_create_texts()
722 if (!se->dobj.control.dtexts[i]) { in soc_tplg_denum_create_texts()
723 ret = -ENOMEM; in soc_tplg_denum_create_texts()
728 se->items = le32_to_cpu(ec->items); in soc_tplg_denum_create_texts()
729 se->texts = (const char * const *)se->dobj.control.dtexts; in soc_tplg_denum_create_texts()
743 * values instead of using ARRAY_SIZE(ec->values) due to the fact that in soc_tplg_denum_create_values()
745 * it is defined in UAPI header where it can't be easily changed. in soc_tplg_denum_create_values()
747 if (le32_to_cpu(ec->items) > SND_SOC_TPLG_NUM_TEXTS) in soc_tplg_denum_create_values()
748 return -EINVAL; in soc_tplg_denum_create_values()
750 se->dobj.control.dvalues = devm_kcalloc(tplg->dev, le32_to_cpu(ec->items), in soc_tplg_denum_create_values()
751 sizeof(*se->dobj.control.dvalues), in soc_tplg_denum_create_values()
753 if (!se->dobj.control.dvalues) in soc_tplg_denum_create_values()
754 return -ENOMEM; in soc_tplg_denum_create_values()
756 /* convert from little-endian */ in soc_tplg_denum_create_values()
757 for (i = 0; i < le32_to_cpu(ec->items); i++) { in soc_tplg_denum_create_values()
758 se->dobj.control.dvalues[i] = le32_to_cpu(ec->values[i]); in soc_tplg_denum_create_values()
761 se->items = le32_to_cpu(ec->items); in soc_tplg_denum_create_values()
762 se->values = (const unsigned int *)se->dobj.control.dvalues; in soc_tplg_denum_create_values()
772 ec = (struct snd_soc_tplg_enum_control *)tplg->pos; in soc_tplg_control_denum_create()
775 if (strnlen(ec->hdr.name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == SNDRV_CTL_ELEM_ID_NAME_MAXLEN) in soc_tplg_control_denum_create()
776 return -EINVAL; in soc_tplg_control_denum_create()
778 se = devm_kzalloc(tplg->dev, sizeof(*se), GFP_KERNEL); in soc_tplg_control_denum_create()
780 return -ENOMEM; in soc_tplg_control_denum_create()
782 tplg->pos += (sizeof(struct snd_soc_tplg_enum_control) + le32_to_cpu(ec->priv.size)); in soc_tplg_control_denum_create()
784 dev_dbg(tplg->dev, "ASoC: adding enum kcontrol %s size %d\n", ec->hdr.name, ec->items); in soc_tplg_control_denum_create()
786 kc->name = devm_kstrdup(tplg->dev, ec->hdr.name, GFP_KERNEL); in soc_tplg_control_denum_create()
787 if (!kc->name) in soc_tplg_control_denum_create()
788 return -ENOMEM; in soc_tplg_control_denum_create()
789 kc->private_value = (long)se; in soc_tplg_control_denum_create()
790 kc->iface = SNDRV_CTL_ELEM_IFACE_MIXER; in soc_tplg_control_denum_create()
791 kc->access = le32_to_cpu(ec->hdr.access); in soc_tplg_control_denum_create()
794 se->reg = tplg_chan_get_reg(tplg, ec->channel, SNDRV_CHMAP_FL); in soc_tplg_control_denum_create()
795 se->shift_l = tplg_chan_get_shift(tplg, ec->channel, SNDRV_CHMAP_FL); in soc_tplg_control_denum_create()
796 se->shift_r = tplg_chan_get_shift(tplg, ec->channel, SNDRV_CHMAP_FR); in soc_tplg_control_denum_create()
798 se->mask = le32_to_cpu(ec->mask); in soc_tplg_control_denum_create()
800 switch (le32_to_cpu(ec->hdr.ops.info)) { in soc_tplg_control_denum_create()
805 dev_err(tplg->dev, "ASoC: could not create values for %s\n", ec->hdr.name); in soc_tplg_control_denum_create()
814 dev_err(tplg->dev, "ASoC: could not create texts for %s\n", ec->hdr.name); in soc_tplg_control_denum_create()
819 dev_err(tplg->dev, "ASoC: invalid enum control type %d for %s\n", in soc_tplg_control_denum_create()
820 ec->hdr.ops.info, ec->hdr.name); in soc_tplg_control_denum_create()
821 return -EINVAL; in soc_tplg_control_denum_create()
825 err = soc_tplg_kcontrol_bind_io(&ec->hdr, kc, tplg); in soc_tplg_control_denum_create()
827 soc_control_err(tplg, &ec->hdr, ec->hdr.name); in soc_tplg_control_denum_create()
832 return soc_tplg_control_load(tplg, kc, &ec->hdr); in soc_tplg_control_denum_create()
837 struct snd_soc_tplg_bytes_control *be; in soc_tplg_control_dbytes_create() local
841 be = (struct snd_soc_tplg_bytes_control *)tplg->pos; in soc_tplg_control_dbytes_create()
844 if (strnlen(be->hdr.name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == SNDRV_CTL_ELEM_ID_NAME_MAXLEN) in soc_tplg_control_dbytes_create()
845 return -EINVAL; in soc_tplg_control_dbytes_create()
847 sbe = devm_kzalloc(tplg->dev, sizeof(*sbe), GFP_KERNEL); in soc_tplg_control_dbytes_create()
849 return -ENOMEM; in soc_tplg_control_dbytes_create()
851 tplg->pos += (sizeof(struct snd_soc_tplg_bytes_control) + le32_to_cpu(be->priv.size)); in soc_tplg_control_dbytes_create()
853 dev_dbg(tplg->dev, "ASoC: adding bytes kcontrol %s with access 0x%x\n", in soc_tplg_control_dbytes_create()
854 be->hdr.name, be->hdr.access); in soc_tplg_control_dbytes_create()
856 kc->name = devm_kstrdup(tplg->dev, be->hdr.name, GFP_KERNEL); in soc_tplg_control_dbytes_create()
857 if (!kc->name) in soc_tplg_control_dbytes_create()
858 return -ENOMEM; in soc_tplg_control_dbytes_create()
859 kc->private_value = (long)sbe; in soc_tplg_control_dbytes_create()
860 kc->iface = SNDRV_CTL_ELEM_IFACE_MIXER; in soc_tplg_control_dbytes_create()
861 kc->access = le32_to_cpu(be->hdr.access); in soc_tplg_control_dbytes_create()
863 sbe->max = le32_to_cpu(be->max); in soc_tplg_control_dbytes_create()
866 err = soc_tplg_kcontrol_bind_io(&be->hdr, kc, tplg); in soc_tplg_control_dbytes_create()
868 soc_control_err(tplg, &be->hdr, be->hdr.name); in soc_tplg_control_dbytes_create()
873 return soc_tplg_control_load(tplg, kc, &be->hdr); in soc_tplg_control_dbytes_create()
885 return -EINVAL; in soc_tplg_dbytes_create()
894 INIT_LIST_HEAD(&sbe->dobj.list); in soc_tplg_dbytes_create()
895 sbe->dobj.type = SND_SOC_DOBJ_BYTES; in soc_tplg_dbytes_create()
896 sbe->dobj.index = tplg->index; in soc_tplg_dbytes_create()
897 if (tplg->ops) in soc_tplg_dbytes_create()
898 sbe->dobj.unload = tplg->ops->control_unload; in soc_tplg_dbytes_create()
901 ret = soc_tplg_add_kcontrol(tplg, &kc, &sbe->dobj.control.kcontrol); in soc_tplg_dbytes_create()
905 list_add(&sbe->dobj.list, &tplg->comp->dobj_list); in soc_tplg_dbytes_create()
919 return -EINVAL; in soc_tplg_dmixer_create()
928 INIT_LIST_HEAD(&sm->dobj.list); in soc_tplg_dmixer_create()
929 sm->dobj.type = SND_SOC_DOBJ_MIXER; in soc_tplg_dmixer_create()
930 sm->dobj.index = tplg->index; in soc_tplg_dmixer_create()
931 if (tplg->ops) in soc_tplg_dmixer_create()
932 sm->dobj.unload = tplg->ops->control_unload; in soc_tplg_dmixer_create()
935 ret = soc_tplg_add_kcontrol(tplg, &kc, &sm->dobj.control.kcontrol); in soc_tplg_dmixer_create()
939 list_add(&sm->dobj.list, &tplg->comp->dobj_list); in soc_tplg_dmixer_create()
953 return -EINVAL; in soc_tplg_denum_create()
962 INIT_LIST_HEAD(&se->dobj.list); in soc_tplg_denum_create()
963 se->dobj.type = SND_SOC_DOBJ_ENUM; in soc_tplg_denum_create()
964 se->dobj.index = tplg->index; in soc_tplg_denum_create()
965 if (tplg->ops) in soc_tplg_denum_create()
966 se->dobj.unload = tplg->ops->control_unload; in soc_tplg_denum_create()
969 ret = soc_tplg_add_kcontrol(tplg, &kc, &se->dobj.control.kcontrol); in soc_tplg_denum_create()
973 list_add(&se->dobj.list, &tplg->comp->dobj_list); in soc_tplg_denum_create()
984 dev_dbg(tplg->dev, "ASoC: adding %d kcontrols at 0x%lx\n", hdr->count, in soc_tplg_kcontrol_elems_load()
987 for (i = 0; i < le32_to_cpu(hdr->count); i++) { in soc_tplg_kcontrol_elems_load()
988 struct snd_soc_tplg_ctl_hdr *control_hdr = (struct snd_soc_tplg_ctl_hdr *)tplg->pos; in soc_tplg_kcontrol_elems_load()
990 if (le32_to_cpu(control_hdr->size) != sizeof(*control_hdr)) { in soc_tplg_kcontrol_elems_load()
991 dev_err(tplg->dev, "ASoC: invalid control size\n"); in soc_tplg_kcontrol_elems_load()
992 return -EINVAL; in soc_tplg_kcontrol_elems_load()
995 switch (le32_to_cpu(control_hdr->ops.info)) { in soc_tplg_kcontrol_elems_load()
1003 ret = soc_tplg_dmixer_create(tplg, le32_to_cpu(hdr->payload_size)); in soc_tplg_kcontrol_elems_load()
1010 ret = soc_tplg_denum_create(tplg, le32_to_cpu(hdr->payload_size)); in soc_tplg_kcontrol_elems_load()
1013 ret = soc_tplg_dbytes_create(tplg, le32_to_cpu(hdr->payload_size)); in soc_tplg_kcontrol_elems_load()
1017 return -EINVAL; in soc_tplg_kcontrol_elems_load()
1020 dev_err(tplg->dev, "ASoC: invalid control\n"); in soc_tplg_kcontrol_elems_load()
1033 if (tplg->ops && tplg->ops->dapm_route_load) in soc_tplg_add_route()
1034 return tplg->ops->dapm_route_load(tplg->comp, tplg->index, in soc_tplg_add_route()
1043 struct snd_soc_dapm_context *dapm = &tplg->comp->dapm; in soc_tplg_dapm_graph_elems_load()
1050 count = le32_to_cpu(hdr->count); in soc_tplg_dapm_graph_elems_load()
1054 count, le32_to_cpu(hdr->payload_size), "graph")) in soc_tplg_dapm_graph_elems_load()
1055 return -EINVAL; in soc_tplg_dapm_graph_elems_load()
1057 dev_dbg(tplg->dev, "ASoC: adding %d DAPM routes for index %d\n", count, in soc_tplg_dapm_graph_elems_load()
1058 hdr->index); in soc_tplg_dapm_graph_elems_load()
1061 route = devm_kzalloc(tplg->dev, sizeof(*route), GFP_KERNEL); in soc_tplg_dapm_graph_elems_load()
1063 return -ENOMEM; in soc_tplg_dapm_graph_elems_load()
1064 elem = (struct snd_soc_tplg_dapm_graph_elem *)tplg->pos; in soc_tplg_dapm_graph_elems_load()
1065 tplg->pos += sizeof(struct snd_soc_tplg_dapm_graph_elem); in soc_tplg_dapm_graph_elems_load()
1068 if ((strnlen(elem->source, maxlen) == maxlen) || in soc_tplg_dapm_graph_elems_load()
1069 (strnlen(elem->sink, maxlen) == maxlen) || in soc_tplg_dapm_graph_elems_load()
1070 (strnlen(elem->control, maxlen) == maxlen)) { in soc_tplg_dapm_graph_elems_load()
1071 ret = -EINVAL; in soc_tplg_dapm_graph_elems_load()
1075 route->source = devm_kstrdup(tplg->dev, elem->source, GFP_KERNEL); in soc_tplg_dapm_graph_elems_load()
1076 route->sink = devm_kstrdup(tplg->dev, elem->sink, GFP_KERNEL); in soc_tplg_dapm_graph_elems_load()
1077 if (!route->source || !route->sink) { in soc_tplg_dapm_graph_elems_load()
1078 ret = -ENOMEM; in soc_tplg_dapm_graph_elems_load()
1082 if (strnlen(elem->control, maxlen) != 0) { in soc_tplg_dapm_graph_elems_load()
1083 route->control = devm_kstrdup(tplg->dev, elem->control, GFP_KERNEL); in soc_tplg_dapm_graph_elems_load()
1084 if (!route->control) { in soc_tplg_dapm_graph_elems_load()
1085 ret = -ENOMEM; in soc_tplg_dapm_graph_elems_load()
1091 route->dobj.type = SND_SOC_DOBJ_GRAPH; in soc_tplg_dapm_graph_elems_load()
1092 if (tplg->ops) in soc_tplg_dapm_graph_elems_load()
1093 route->dobj.unload = tplg->ops->dapm_route_unload; in soc_tplg_dapm_graph_elems_load()
1094 route->dobj.index = tplg->index; in soc_tplg_dapm_graph_elems_load()
1095 list_add(&route->dobj.list, &tplg->comp->dobj_list); in soc_tplg_dapm_graph_elems_load()
1099 dev_err(tplg->dev, "ASoC: topology: add_route failed: %d\n", ret); in soc_tplg_dapm_graph_elems_load()
1105 if (!dapm->card->disable_route_checks) { in soc_tplg_dapm_graph_elems_load()
1106 dev_err(tplg->dev, "ASoC: dapm_add_routes failed: %d\n", ret); in soc_tplg_dapm_graph_elems_load()
1109 dev_info(tplg->dev, in soc_tplg_dapm_graph_elems_load()
1120 struct snd_soc_dapm_context *dapm = &tplg->comp->dapm; in soc_tplg_dapm_widget_create()
1123 struct snd_soc_card *card = tplg->comp->card; in soc_tplg_dapm_widget_create()
1132 if (strnlen(w->name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == in soc_tplg_dapm_widget_create()
1134 return -EINVAL; in soc_tplg_dapm_widget_create()
1135 if (strnlen(w->sname, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == in soc_tplg_dapm_widget_create()
1137 return -EINVAL; in soc_tplg_dapm_widget_create()
1139 dev_dbg(tplg->dev, "ASoC: creating DAPM widget %s id %d\n", in soc_tplg_dapm_widget_create()
1140 w->name, w->id); in soc_tplg_dapm_widget_create()
1145 template.id = get_widget_id(le32_to_cpu(w->id)); in soc_tplg_dapm_widget_create()
1150 template.name = kstrdup(w->name, GFP_KERNEL); in soc_tplg_dapm_widget_create()
1152 return -ENOMEM; in soc_tplg_dapm_widget_create()
1153 template.sname = kstrdup(w->sname, GFP_KERNEL); in soc_tplg_dapm_widget_create()
1155 ret = -ENOMEM; in soc_tplg_dapm_widget_create()
1158 template.reg = le32_to_cpu(w->reg); in soc_tplg_dapm_widget_create()
1159 template.shift = le32_to_cpu(w->shift); in soc_tplg_dapm_widget_create()
1160 template.mask = le32_to_cpu(w->mask); in soc_tplg_dapm_widget_create()
1161 template.subseq = le32_to_cpu(w->subseq); in soc_tplg_dapm_widget_create()
1162 template.on_val = w->invert ? 0 : 1; in soc_tplg_dapm_widget_create()
1163 template.off_val = w->invert ? 1 : 0; in soc_tplg_dapm_widget_create()
1164 template.ignore_suspend = le32_to_cpu(w->ignore_suspend); in soc_tplg_dapm_widget_create()
1165 template.event_flags = le16_to_cpu(w->event_flags); in soc_tplg_dapm_widget_create()
1166 template.dobj.index = tplg->index; in soc_tplg_dapm_widget_create()
1168 tplg->pos += in soc_tplg_dapm_widget_create()
1170 le32_to_cpu(w->priv.size)); in soc_tplg_dapm_widget_create()
1172 if (w->num_kcontrols == 0) { in soc_tplg_dapm_widget_create()
1177 template.num_kcontrols = le32_to_cpu(w->num_kcontrols); in soc_tplg_dapm_widget_create()
1178 kc = devm_kcalloc(tplg->dev, le32_to_cpu(w->num_kcontrols), sizeof(*kc), GFP_KERNEL); in soc_tplg_dapm_widget_create()
1180 ret = -ENOMEM; in soc_tplg_dapm_widget_create()
1184 kcontrol_type = devm_kcalloc(tplg->dev, le32_to_cpu(w->num_kcontrols), sizeof(unsigned int), in soc_tplg_dapm_widget_create()
1187 ret = -ENOMEM; in soc_tplg_dapm_widget_create()
1191 for (i = 0; i < le32_to_cpu(w->num_kcontrols); i++) { in soc_tplg_dapm_widget_create()
1192 control_hdr = (struct snd_soc_tplg_ctl_hdr *)tplg->pos; in soc_tplg_dapm_widget_create()
1193 switch (le32_to_cpu(control_hdr->ops.info)) { in soc_tplg_dapm_widget_create()
1231 dev_err(tplg->dev, "ASoC: invalid widget control type %d:%d:%d\n", in soc_tplg_dapm_widget_create()
1232 control_hdr->ops.get, control_hdr->ops.put, in soc_tplg_dapm_widget_create()
1233 le32_to_cpu(control_hdr->ops.info)); in soc_tplg_dapm_widget_create()
1234 ret = -EINVAL; in soc_tplg_dapm_widget_create()
1240 dev_dbg(tplg->dev, "ASoC: template %s with %d/%d/%d (mixer/enum/bytes) control\n", in soc_tplg_dapm_widget_create()
1241 w->name, mixer_count, enum_count, bytes_count); in soc_tplg_dapm_widget_create()
1259 widget->dobj.type = SND_SOC_DOBJ_WIDGET; in soc_tplg_dapm_widget_create()
1260 widget->dobj.widget.kcontrol_type = kcontrol_type; in soc_tplg_dapm_widget_create()
1261 if (tplg->ops) in soc_tplg_dapm_widget_create()
1262 widget->dobj.unload = tplg->ops->widget_unload; in soc_tplg_dapm_widget_create()
1263 widget->dobj.index = tplg->index; in soc_tplg_dapm_widget_create()
1264 list_add(&widget->dobj.list, &tplg->comp->dobj_list); in soc_tplg_dapm_widget_create()
1276 soc_tplg_remove_widget(widget->dapm->component, &widget->dobj, SOC_TPLG_PASS_WIDGET); in soc_tplg_dapm_widget_create()
1290 count = le32_to_cpu(hdr->count); in soc_tplg_dapm_widget_elems_load()
1292 dev_dbg(tplg->dev, "ASoC: adding %d DAPM widgets\n", count); in soc_tplg_dapm_widget_elems_load()
1295 struct snd_soc_tplg_dapm_widget *widget = (struct snd_soc_tplg_dapm_widget *) tplg->pos; in soc_tplg_dapm_widget_elems_load()
1300 * use sizeof instead of widget->size, as we can't be sure in soc_tplg_dapm_widget_elems_load()
1303 if (soc_tplg_get_offset(tplg) + sizeof(*widget) >= tplg->fw->size) { in soc_tplg_dapm_widget_elems_load()
1304 dev_err(tplg->dev, "ASoC: invalid widget data size\n"); in soc_tplg_dapm_widget_elems_load()
1305 return -EINVAL; in soc_tplg_dapm_widget_elems_load()
1309 if (le32_to_cpu(widget->size) != sizeof(*widget)) { in soc_tplg_dapm_widget_elems_load()
1310 dev_err(tplg->dev, "ASoC: invalid widget size\n"); in soc_tplg_dapm_widget_elems_load()
1311 return -EINVAL; in soc_tplg_dapm_widget_elems_load()
1315 if (soc_tplg_get_offset(tplg) + le32_to_cpu(widget->priv.size) >= tplg->fw->size) { in soc_tplg_dapm_widget_elems_load()
1316 dev_err(tplg->dev, "ASoC: invalid widget private data size\n"); in soc_tplg_dapm_widget_elems_load()
1317 return -EINVAL; in soc_tplg_dapm_widget_elems_load()
1322 dev_err(tplg->dev, "ASoC: failed to load widget %s\n", in soc_tplg_dapm_widget_elems_load()
1323 widget->name); in soc_tplg_dapm_widget_elems_load()
1333 struct snd_soc_card *card = tplg->comp->card; in soc_tplg_dapm_complete()
1340 dev_warn(tplg->dev, "ASoC: Parent card not yet available, widget card binding deferred\n"); in soc_tplg_dapm_complete()
1346 dev_err(tplg->dev, "ASoC: failed to create new widgets %d\n", ret); in soc_tplg_dapm_complete()
1354 stream->stream_name = devm_kstrdup(tplg->dev, caps->name, GFP_KERNEL); in set_stream_info()
1355 if (!stream->stream_name) in set_stream_info()
1356 return -ENOMEM; in set_stream_info()
1358 stream->channels_min = le32_to_cpu(caps->channels_min); in set_stream_info()
1359 stream->channels_max = le32_to_cpu(caps->channels_max); in set_stream_info()
1360 stream->rates = le32_to_cpu(caps->rates); in set_stream_info()
1361 stream->rate_min = le32_to_cpu(caps->rate_min); in set_stream_info()
1362 stream->rate_max = le32_to_cpu(caps->rate_max); in set_stream_info()
1363 stream->formats = le64_to_cpu(caps->formats); in set_stream_info()
1364 stream->sig_bits = le32_to_cpu(caps->sig_bits); in set_stream_info()
1373 dai_drv->symmetric_rate = in set_dai_flags()
1377 dai_drv->symmetric_channels = in set_dai_flags()
1382 dai_drv->symmetric_sample_bits = in set_dai_flags()
1397 struct snd_soc_dai *dai; in soc_tplg_dai_create() local
1399 snd_soc_component_get_dapm(tplg->comp); in soc_tplg_dai_create()
1402 dai_drv = devm_kzalloc(tplg->dev, sizeof(struct snd_soc_dai_driver), GFP_KERNEL); in soc_tplg_dai_create()
1404 return -ENOMEM; in soc_tplg_dai_create()
1406 if (strlen(pcm->dai_name)) { in soc_tplg_dai_create()
1407 dai_drv->name = devm_kstrdup(tplg->dev, pcm->dai_name, GFP_KERNEL); in soc_tplg_dai_create()
1408 if (!dai_drv->name) { in soc_tplg_dai_create()
1409 ret = -ENOMEM; in soc_tplg_dai_create()
1413 dai_drv->id = le32_to_cpu(pcm->dai_id); in soc_tplg_dai_create()
1415 if (pcm->playback) { in soc_tplg_dai_create()
1416 stream = &dai_drv->playback; in soc_tplg_dai_create()
1417 caps = &pcm->caps[SND_SOC_TPLG_STREAM_PLAYBACK]; in soc_tplg_dai_create()
1423 if (pcm->capture) { in soc_tplg_dai_create()
1424 stream = &dai_drv->capture; in soc_tplg_dai_create()
1425 caps = &pcm->caps[SND_SOC_TPLG_STREAM_CAPTURE]; in soc_tplg_dai_create()
1431 if (pcm->compress) in soc_tplg_dai_create()
1432 dai_drv->ops = &tplg_dai_ops; in soc_tplg_dai_create()
1437 dev_err(tplg->dev, "ASoC: DAI loading failed\n"); in soc_tplg_dai_create()
1441 dai_drv->dobj.index = tplg->index; in soc_tplg_dai_create()
1442 dai_drv->dobj.type = SND_SOC_DOBJ_PCM; in soc_tplg_dai_create()
1443 if (tplg->ops) in soc_tplg_dai_create()
1444 dai_drv->dobj.unload = tplg->ops->dai_unload; in soc_tplg_dai_create()
1445 list_add(&dai_drv->dobj.list, &tplg->comp->dobj_list); in soc_tplg_dai_create()
1447 /* register the DAI to the component */ in soc_tplg_dai_create()
1448 dai = snd_soc_register_dai(tplg->comp, dai_drv, false); in soc_tplg_dai_create()
1449 if (!dai) in soc_tplg_dai_create()
1450 return -ENOMEM; in soc_tplg_dai_create()
1452 /* Create the DAI widgets here */ in soc_tplg_dai_create()
1453 ret = snd_soc_dapm_new_dai_widgets(dapm, dai); in soc_tplg_dai_create()
1455 dev_err(dai->dev, "Failed to create DAI widgets %d\n", ret); in soc_tplg_dai_create()
1456 snd_soc_unregister_dai(dai); in soc_tplg_dai_create()
1466 static void set_link_flags(struct snd_soc_dai_link *link, in set_link_flags() argument
1470 link->symmetric_rate = in set_link_flags()
1474 link->symmetric_channels = in set_link_flags()
1479 link->symmetric_sample_bits = in set_link_flags()
1484 link->ignore_suspend = in set_link_flags()
1489 /* create the FE DAI link */
1493 struct snd_soc_dai_link *link; in soc_tplg_fe_link_create() local
1497 /* link + cpu + codec + platform */ in soc_tplg_fe_link_create()
1498 link = devm_kzalloc(tplg->dev, sizeof(*link) + (3 * sizeof(*dlc)), GFP_KERNEL); in soc_tplg_fe_link_create()
1499 if (link == NULL) in soc_tplg_fe_link_create()
1500 return -ENOMEM; in soc_tplg_fe_link_create()
1502 dlc = (struct snd_soc_dai_link_component *)(link + 1); in soc_tplg_fe_link_create()
1504 link->cpus = &dlc[0]; in soc_tplg_fe_link_create()
1505 link->num_cpus = 1; in soc_tplg_fe_link_create()
1507 link->dobj.index = tplg->index; in soc_tplg_fe_link_create()
1508 link->dobj.type = SND_SOC_DOBJ_DAI_LINK; in soc_tplg_fe_link_create()
1509 if (tplg->ops) in soc_tplg_fe_link_create()
1510 link->dobj.unload = tplg->ops->link_unload; in soc_tplg_fe_link_create()
1512 if (strlen(pcm->pcm_name)) { in soc_tplg_fe_link_create()
1513 link->name = devm_kstrdup(tplg->dev, pcm->pcm_name, GFP_KERNEL); in soc_tplg_fe_link_create()
1514 link->stream_name = devm_kstrdup(tplg->dev, pcm->pcm_name, GFP_KERNEL); in soc_tplg_fe_link_create()
1515 if (!link->name || !link->stream_name) { in soc_tplg_fe_link_create()
1516 ret = -ENOMEM; in soc_tplg_fe_link_create()
1520 link->id = le32_to_cpu(pcm->pcm_id); in soc_tplg_fe_link_create()
1522 if (strlen(pcm->dai_name)) { in soc_tplg_fe_link_create()
1523 link->cpus->dai_name = devm_kstrdup(tplg->dev, pcm->dai_name, GFP_KERNEL); in soc_tplg_fe_link_create()
1524 if (!link->cpus->dai_name) { in soc_tplg_fe_link_create()
1525 ret = -ENOMEM; in soc_tplg_fe_link_create()
1531 * Many topology are assuming link has Codec / Platform, and in soc_tplg_fe_link_create()
1532 * these might be overwritten at soc_tplg_dai_link_load(). in soc_tplg_fe_link_create()
1535 link->codecs = &dlc[1]; /* Don't use &snd_soc_dummy_dlc here */ in soc_tplg_fe_link_create()
1536 link->codecs->name = "snd-soc-dummy"; in soc_tplg_fe_link_create()
1537 link->codecs->dai_name = "snd-soc-dummy-dai"; in soc_tplg_fe_link_create()
1538 link->num_codecs = 1; in soc_tplg_fe_link_create()
1540 link->platforms = &dlc[2]; /* Don't use &snd_soc_dummy_dlc here */ in soc_tplg_fe_link_create()
1541 link->platforms->name = "snd-soc-dummy"; in soc_tplg_fe_link_create()
1542 link->num_platforms = 1; in soc_tplg_fe_link_create()
1545 link->dynamic = 1; in soc_tplg_fe_link_create()
1546 link->ignore_pmdown_time = 1; in soc_tplg_fe_link_create()
1547 link->playback_only = le32_to_cpu(pcm->playback) && !le32_to_cpu(pcm->capture); in soc_tplg_fe_link_create()
1548 link->capture_only = !le32_to_cpu(pcm->playback) && le32_to_cpu(pcm->capture); in soc_tplg_fe_link_create()
1549 if (pcm->flag_mask) in soc_tplg_fe_link_create()
1550 set_link_flags(link, in soc_tplg_fe_link_create()
1551 le32_to_cpu(pcm->flag_mask), in soc_tplg_fe_link_create()
1552 le32_to_cpu(pcm->flags)); in soc_tplg_fe_link_create()
1555 ret = soc_tplg_dai_link_load(tplg, link, NULL); in soc_tplg_fe_link_create()
1557 dev_err(tplg->dev, "ASoC: FE link loading failed\n"); in soc_tplg_fe_link_create()
1561 ret = snd_soc_add_pcm_runtimes(tplg->comp->card, link, 1); in soc_tplg_fe_link_create()
1563 if (ret != -EPROBE_DEFER) in soc_tplg_fe_link_create()
1564 dev_err(tplg->dev, "ASoC: adding FE link failed\n"); in soc_tplg_fe_link_create()
1568 list_add(&link->dobj.list, &tplg->comp->dobj_list); in soc_tplg_fe_link_create()
1575 /* create a FE DAI and DAI link from the PCM object */
1597 count = le32_to_cpu(hdr->count); in soc_tplg_pcm_elems_load()
1600 pcm = (struct snd_soc_tplg_pcm *)tplg->pos; in soc_tplg_pcm_elems_load()
1601 size = le32_to_cpu(pcm->size); in soc_tplg_pcm_elems_load()
1603 dev_err(tplg->dev, "ASoC: invalid size %d for PCM elems\n", in soc_tplg_pcm_elems_load()
1605 return -EINVAL; in soc_tplg_pcm_elems_load()
1610 le32_to_cpu(hdr->payload_size), in soc_tplg_pcm_elems_load()
1611 "PCM DAI")) in soc_tplg_pcm_elems_load()
1612 return -EINVAL; in soc_tplg_pcm_elems_load()
1615 pcm = (struct snd_soc_tplg_pcm *)tplg->pos; in soc_tplg_pcm_elems_load()
1616 size = le32_to_cpu(pcm->size); in soc_tplg_pcm_elems_load()
1622 return -EINVAL; in soc_tplg_pcm_elems_load()
1624 /* create the FE DAIs and DAI links */ in soc_tplg_pcm_elems_load()
1629 /* offset by version-specific struct size and in soc_tplg_pcm_elems_load()
1632 tplg->pos += size + le32_to_cpu(pcm->priv.size); in soc_tplg_pcm_elems_load()
1635 dev_dbg(tplg->dev, "ASoC: adding %d PCM DAIs\n", count); in soc_tplg_pcm_elems_load()
1641 * set_link_hw_format - Set the HW audio format of the physical DAI link.
1642 * @link: &snd_soc_dai_link which should be updated
1643 * @cfg: physical link configs.
1646 * a default format ID for the physical link. This function will use this
1647 * default ID to choose the HW format to set the link's DAI format for init.
1649 static void set_link_hw_format(struct snd_soc_dai_link *link, in set_link_hw_format() argument
1657 for (i = 0; i < le32_to_cpu(cfg->num_hw_configs); i++) { in set_link_hw_format()
1658 hw_config = &cfg->hw_config[i]; in set_link_hw_format()
1659 if (hw_config->id != cfg->default_hw_config_id) in set_link_hw_format()
1662 link->dai_fmt = le32_to_cpu(hw_config->fmt) & in set_link_hw_format()
1666 switch (hw_config->clock_gated) { in set_link_hw_format()
1668 link->dai_fmt |= SND_SOC_DAIFMT_GATED; in set_link_hw_format()
1672 link->dai_fmt |= SND_SOC_DAIFMT_CONT; in set_link_hw_format()
1681 invert_bclk = hw_config->invert_bclk; in set_link_hw_format()
1682 invert_fsync = hw_config->invert_fsync; in set_link_hw_format()
1684 link->dai_fmt |= SND_SOC_DAIFMT_NB_NF; in set_link_hw_format()
1686 link->dai_fmt |= SND_SOC_DAIFMT_NB_IF; in set_link_hw_format()
1688 link->dai_fmt |= SND_SOC_DAIFMT_IB_NF; in set_link_hw_format()
1690 link->dai_fmt |= SND_SOC_DAIFMT_IB_IF; in set_link_hw_format()
1693 bclk_provider = (hw_config->bclk_provider == in set_link_hw_format()
1695 fsync_provider = (hw_config->fsync_provider == in set_link_hw_format()
1698 link->dai_fmt |= SND_SOC_DAIFMT_CBP_CFP; in set_link_hw_format()
1700 link->dai_fmt |= SND_SOC_DAIFMT_CBC_CFP; in set_link_hw_format()
1702 link->dai_fmt |= SND_SOC_DAIFMT_CBP_CFC; in set_link_hw_format()
1704 link->dai_fmt |= SND_SOC_DAIFMT_CBC_CFC; in set_link_hw_format()
1709 * snd_soc_find_dai_link - Find a DAI link
1712 * @id: DAI link ID to match
1713 * @name: DAI link name to match, optional
1714 * @stream_name: DAI link stream name to match, optional
1716 * This function will search all existing DAI links of the soc card to
1717 * find the link of the same ID. Since DAI links may not have their
1721 * Return: pointer of DAI link, or NULL if not found.
1730 struct snd_soc_dai_link *link = rtd->dai_link; in snd_soc_find_dai_link() local
1732 if (link->id != id) in snd_soc_find_dai_link()
1735 if (name && (!link->name || !strstr(link->name, name))) in snd_soc_find_dai_link()
1738 if (stream_name && (!link->stream_name || in snd_soc_find_dai_link()
1739 !strstr(link->stream_name, stream_name))) in snd_soc_find_dai_link()
1742 return link; in snd_soc_find_dai_link()
1748 /* Find and configure an existing physical DAI link */
1752 struct snd_soc_dai_link *link; in soc_tplg_link_config() local
1757 len = strnlen(cfg->name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN); in soc_tplg_link_config()
1759 return -EINVAL; in soc_tplg_link_config()
1761 name = cfg->name; in soc_tplg_link_config()
1765 len = strnlen(cfg->stream_name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN); in soc_tplg_link_config()
1767 return -EINVAL; in soc_tplg_link_config()
1769 stream_name = cfg->stream_name; in soc_tplg_link_config()
1773 link = snd_soc_find_dai_link(tplg->comp->card, le32_to_cpu(cfg->id), in soc_tplg_link_config()
1775 if (!link) { in soc_tplg_link_config()
1776 dev_err(tplg->dev, "ASoC: physical link %s (id %d) not exist\n", in soc_tplg_link_config()
1777 name, cfg->id); in soc_tplg_link_config()
1778 return -EINVAL; in soc_tplg_link_config()
1782 if (cfg->num_hw_configs) in soc_tplg_link_config()
1783 set_link_hw_format(link, cfg); in soc_tplg_link_config()
1786 if (cfg->flag_mask) in soc_tplg_link_config()
1787 set_link_flags(link, in soc_tplg_link_config()
1788 le32_to_cpu(cfg->flag_mask), in soc_tplg_link_config()
1789 le32_to_cpu(cfg->flags)); in soc_tplg_link_config()
1792 ret = soc_tplg_dai_link_load(tplg, link, cfg); in soc_tplg_link_config()
1794 dev_err(tplg->dev, "ASoC: physical link loading failed\n"); in soc_tplg_link_config()
1799 link->dobj.index = tplg->index; in soc_tplg_link_config()
1800 link->dobj.type = SND_SOC_DOBJ_BACKEND_LINK; in soc_tplg_link_config()
1801 if (tplg->ops) in soc_tplg_link_config()
1802 link->dobj.unload = tplg->ops->link_unload; in soc_tplg_link_config()
1803 list_add(&link->dobj.list, &tplg->comp->dobj_list); in soc_tplg_link_config()
1809 /* Load physical link config elements from the topology context */
1813 struct snd_soc_tplg_link_config *link; in soc_tplg_link_elems_load() local
1818 count = le32_to_cpu(hdr->count); in soc_tplg_link_elems_load()
1821 link = (struct snd_soc_tplg_link_config *)tplg->pos; in soc_tplg_link_elems_load()
1822 size = le32_to_cpu(link->size); in soc_tplg_link_elems_load()
1824 dev_err(tplg->dev, "ASoC: invalid size %d for physical link elems\n", in soc_tplg_link_elems_load()
1826 return -EINVAL; in soc_tplg_link_elems_load()
1830 le32_to_cpu(hdr->payload_size), in soc_tplg_link_elems_load()
1831 "physical link config")) in soc_tplg_link_elems_load()
1832 return -EINVAL; in soc_tplg_link_elems_load()
1834 /* config physical DAI links */ in soc_tplg_link_elems_load()
1836 link = (struct snd_soc_tplg_link_config *)tplg->pos; in soc_tplg_link_elems_load()
1837 size = le32_to_cpu(link->size); in soc_tplg_link_elems_load()
1838 if (size != sizeof(*link)) in soc_tplg_link_elems_load()
1839 return -EINVAL; in soc_tplg_link_elems_load()
1841 ret = soc_tplg_link_config(tplg, link); in soc_tplg_link_elems_load()
1845 /* offset by version-specific struct size and in soc_tplg_link_elems_load()
1848 tplg->pos += size + le32_to_cpu(link->priv.size); in soc_tplg_link_elems_load()
1855 * soc_tplg_dai_config - Find and configure an existing physical DAI.
1857 * @d: physical DAI configs.
1859 * The physical dai should already be registered by the platform driver.
1860 * The platform driver should specify the DAI name and ID for matching.
1866 struct snd_soc_dai *dai; in soc_tplg_dai_config() local
1874 dai_component.dai_name = d->dai_name; in soc_tplg_dai_config()
1875 dai = snd_soc_find_dai(&dai_component); in soc_tplg_dai_config()
1876 if (!dai) { in soc_tplg_dai_config()
1877 dev_err(tplg->dev, "ASoC: physical DAI %s not registered\n", in soc_tplg_dai_config()
1878 d->dai_name); in soc_tplg_dai_config()
1879 return -EINVAL; in soc_tplg_dai_config()
1882 if (le32_to_cpu(d->dai_id) != dai->id) { in soc_tplg_dai_config()
1883 dev_err(tplg->dev, "ASoC: physical DAI %s id mismatch\n", in soc_tplg_dai_config()
1884 d->dai_name); in soc_tplg_dai_config()
1885 return -EINVAL; in soc_tplg_dai_config()
1888 dai_drv = dai->driver; in soc_tplg_dai_config()
1890 return -EINVAL; in soc_tplg_dai_config()
1892 if (d->playback) { in soc_tplg_dai_config()
1893 stream = &dai_drv->playback; in soc_tplg_dai_config()
1894 caps = &d->caps[SND_SOC_TPLG_STREAM_PLAYBACK]; in soc_tplg_dai_config()
1900 if (d->capture) { in soc_tplg_dai_config()
1901 stream = &dai_drv->capture; in soc_tplg_dai_config()
1902 caps = &d->caps[SND_SOC_TPLG_STREAM_CAPTURE]; in soc_tplg_dai_config()
1908 if (d->flag_mask) in soc_tplg_dai_config()
1910 le32_to_cpu(d->flag_mask), in soc_tplg_dai_config()
1911 le32_to_cpu(d->flags)); in soc_tplg_dai_config()
1914 ret = soc_tplg_dai_load(tplg, dai_drv, NULL, dai); in soc_tplg_dai_config()
1916 dev_err(tplg->dev, "ASoC: DAI loading failed\n"); in soc_tplg_dai_config()
1923 /* load physical DAI elements */
1930 count = le32_to_cpu(hdr->count); in soc_tplg_dai_elems_load()
1932 /* config the existing BE DAIs */ in soc_tplg_dai_elems_load()
1934 struct snd_soc_tplg_dai *dai = (struct snd_soc_tplg_dai *)tplg->pos; in soc_tplg_dai_elems_load() local
1937 if (le32_to_cpu(dai->size) != sizeof(*dai)) { in soc_tplg_dai_elems_load()
1938 dev_err(tplg->dev, "ASoC: invalid physical DAI size\n"); in soc_tplg_dai_elems_load()
1939 return -EINVAL; in soc_tplg_dai_elems_load()
1942 ret = soc_tplg_dai_config(tplg, dai); in soc_tplg_dai_elems_load()
1944 dev_err(tplg->dev, "ASoC: failed to configure DAI\n"); in soc_tplg_dai_elems_load()
1948 tplg->pos += (sizeof(*dai) + le32_to_cpu(dai->priv.size)); in soc_tplg_dai_elems_load()
1951 dev_dbg(tplg->dev, "ASoC: Configure %d BE DAIs\n", count); in soc_tplg_dai_elems_load()
1961 manifest = (struct snd_soc_tplg_manifest *)tplg->pos; in soc_tplg_manifest_load()
1964 if (le32_to_cpu(manifest->size) != sizeof(*manifest)) in soc_tplg_manifest_load()
1965 return -EINVAL; in soc_tplg_manifest_load()
1968 if (tplg->ops && tplg->ops->manifest) in soc_tplg_manifest_load()
1969 ret = tplg->ops->manifest(tplg->comp, tplg->index, manifest); in soc_tplg_manifest_load()
1978 if (le32_to_cpu(hdr->size) != sizeof(*hdr)) { in soc_tplg_valid_header()
1979 dev_err(tplg->dev, in soc_tplg_valid_header()
1981 le32_to_cpu(hdr->type), soc_tplg_get_hdr_offset(tplg), in soc_tplg_valid_header()
1982 tplg->fw->size); in soc_tplg_valid_header()
1983 return -EINVAL; in soc_tplg_valid_header()
1986 if (soc_tplg_get_hdr_offset(tplg) + le32_to_cpu(hdr->payload_size) >= tplg->fw->size) { in soc_tplg_valid_header()
1987 dev_err(tplg->dev, in soc_tplg_valid_header()
1989 le32_to_cpu(hdr->type), soc_tplg_get_hdr_offset(tplg), in soc_tplg_valid_header()
1990 hdr->payload_size); in soc_tplg_valid_header()
1991 return -EINVAL; in soc_tplg_valid_header()
1995 if (le32_to_cpu(hdr->magic) == SOC_TPLG_MAGIC_BIG_ENDIAN) { in soc_tplg_valid_header()
1996 dev_err(tplg->dev, in soc_tplg_valid_header()
1998 tplg->pass, hdr->magic, in soc_tplg_valid_header()
1999 soc_tplg_get_hdr_offset(tplg), tplg->fw->size); in soc_tplg_valid_header()
2000 return -EINVAL; in soc_tplg_valid_header()
2003 if (le32_to_cpu(hdr->magic) != SND_SOC_TPLG_MAGIC) { in soc_tplg_valid_header()
2004 dev_err(tplg->dev, in soc_tplg_valid_header()
2006 tplg->pass, hdr->magic, in soc_tplg_valid_header()
2007 soc_tplg_get_hdr_offset(tplg), tplg->fw->size); in soc_tplg_valid_header()
2008 return -EINVAL; in soc_tplg_valid_header()
2012 if (le32_to_cpu(hdr->abi) > SND_SOC_TPLG_ABI_VERSION || in soc_tplg_valid_header()
2013 le32_to_cpu(hdr->abi) < SND_SOC_TPLG_ABI_VERSION_MIN) { in soc_tplg_valid_header()
2014 dev_err(tplg->dev, in soc_tplg_valid_header()
2016 tplg->pass, hdr->abi, in soc_tplg_valid_header()
2018 tplg->fw->size); in soc_tplg_valid_header()
2019 return -EINVAL; in soc_tplg_valid_header()
2022 if (hdr->payload_size == 0) { in soc_tplg_valid_header()
2023 dev_err(tplg->dev, "ASoC: header has 0 size at offset 0x%lx.\n", in soc_tplg_valid_header()
2025 return -EINVAL; in soc_tplg_valid_header()
2039 tplg->pos = tplg->hdr_pos + sizeof(struct snd_soc_tplg_hdr); in soc_tplg_load_header()
2041 tplg->index = le32_to_cpu(hdr->index); in soc_tplg_load_header()
2043 switch (le32_to_cpu(hdr->type)) { in soc_tplg_load_header()
2068 /* physical link configurations */ in soc_tplg_load_header()
2083 if (tplg->pass == hdr_pass) { in soc_tplg_load_header()
2084 dev_dbg(tplg->dev, in soc_tplg_load_header()
2086 hdr->payload_size, hdr->type, hdr->version, in soc_tplg_load_header()
2087 hdr->vendor_type, tplg->pass); in soc_tplg_load_header()
2100 for (tplg->pass = SOC_TPLG_PASS_START; tplg->pass <= SOC_TPLG_PASS_END; tplg->pass++) { in soc_tplg_process_headers()
2103 tplg->hdr_pos = tplg->fw->data; in soc_tplg_process_headers()
2104 hdr = (struct snd_soc_tplg_hdr *)tplg->hdr_pos; in soc_tplg_process_headers()
2116 if (ret != -EPROBE_DEFER) { in soc_tplg_process_headers()
2117 dev_err(tplg->dev, in soc_tplg_process_headers()
2125 tplg->hdr_pos += le32_to_cpu(hdr->payload_size) + in soc_tplg_process_headers()
2127 hdr = (struct snd_soc_tplg_hdr *)tplg->hdr_pos; in soc_tplg_process_headers()
2158 * comp - needs to exist to keep and reference data while parsing in snd_soc_tplg_component_load()
2159 * comp->card - used for setting card related parameters in snd_soc_tplg_component_load()
2160 * comp->card->dev - used for resource management and prints in snd_soc_tplg_component_load()
2161 * fw - we need it, as it is the very thing we parse in snd_soc_tplg_component_load()
2163 if (!comp || !comp->card || !comp->card->dev || !fw) in snd_soc_tplg_component_load()
2164 return -EINVAL; in snd_soc_tplg_component_load()
2169 tplg.dev = comp->card->dev; in snd_soc_tplg_component_load()
2173 tplg.io_ops = ops->io_ops; in snd_soc_tplg_component_load()
2174 tplg.io_ops_count = ops->io_ops_count; in snd_soc_tplg_component_load()
2175 tplg.bytes_ext_ops = ops->bytes_ext_ops; in snd_soc_tplg_component_load()
2176 tplg.bytes_ext_ops_count = ops->bytes_ext_ops_count; in snd_soc_tplg_component_load()
2195 for (pass = SOC_TPLG_PASS_END; pass >= SOC_TPLG_PASS_START; pass--) { in snd_soc_tplg_component_remove()
2198 list_for_each_entry_safe(dobj, next_dobj, &comp->dobj_list, in snd_soc_tplg_component_remove()
2201 switch (dobj->type) { in snd_soc_tplg_component_remove()
2227 dev_err(comp->dev, "ASoC: invalid component type %d for removal\n", in snd_soc_tplg_component_remove()
2228 dobj->type); in snd_soc_tplg_component_remove()
2234 /* let caller know if FW can be freed when no objects are left */ in snd_soc_tplg_component_remove()
2235 return !list_empty(&comp->dobj_list); in snd_soc_tplg_component_remove()