1 // SPDX-License-Identifier: GPL-2.0+
3 // soc-topology.c -- ALSA SoC Topology
5 // Copyright (C) 2012 Texas Instruments Inc.
6 // Copyright (C) 2015 Intel Corporation.
8 // Authors: Liam Girdwood <liam.r.girdwood@linux.intel.com>
9 // K, Mythri P <mythri.p.k@intel.com>
10 // Prusty, Subhransu S <subhransu.s.prusty@intel.com>
11 // B, Jayachandran <jayachandran.b@intel.com>
12 // Abdullah, Omair M <omair.m.abdullah@intel.com>
13 // Jin, Yao <yao.jin@intel.com>
14 // Lin, Mengdong <mengdong.lin@intel.com>
16 // Add support to read audio firmware topology alongside firmware text. The
17 // topology data can contain kcontrols, DAPM graphs, widgets, DAIs, DAI links,
18 // equalizers, firmware, coefficients etc.
20 // This file only manages the core ALSA and ASoC components, all other bespoke
21 // firmware topology data is passed to component drivers for bespoke handling.
23 #include <linux/kernel.h>
24 #include <linux/export.h>
25 #include <linux/list.h>
26 #include <linux/firmware.h>
27 #include <linux/slab.h>
28 #include <sound/soc.h>
29 #include <sound/soc-dapm.h>
30 #include <sound/soc-topology.h>
31 #include <sound/tlv.h>
33 #define SOC_TPLG_MAGIC_BIG_ENDIAN 0x436F5341 /* ASoC in reverse */
36 * We make several passes over the data (since it wont necessarily be ordered)
37 * and process objects in the following order. This guarantees the component
38 * drivers will be ready with any vendor data before the mixers and DAPM objects
39 * are loaded (that may make use of the vendor data).
41 #define SOC_TPLG_PASS_MANIFEST 0
42 #define SOC_TPLG_PASS_VENDOR 1
43 #define SOC_TPLG_PASS_CONTROL 2
44 #define SOC_TPLG_PASS_WIDGET 3
45 #define SOC_TPLG_PASS_PCM_DAI 4
46 #define SOC_TPLG_PASS_GRAPH 5
47 #define SOC_TPLG_PASS_BE_DAI 6
48 #define SOC_TPLG_PASS_LINK 7
50 #define SOC_TPLG_PASS_START SOC_TPLG_PASS_MANIFEST
51 #define SOC_TPLG_PASS_END SOC_TPLG_PASS_LINK
53 /* topology context */
55 const struct firmware *fw;
57 /* runtime FW parsing */
58 const u8 *pos; /* read position */
59 const u8 *hdr_pos; /* header position */
60 unsigned int pass; /* pass number */
62 /* component caller */
64 struct snd_soc_component *comp;
65 u32 index; /* current block index */
67 /* vendor specific kcontrol operations */
68 const struct snd_soc_tplg_kcontrol_ops *io_ops;
71 /* vendor specific bytes ext handlers, for TLV bytes controls */
72 const struct snd_soc_tplg_bytes_ext_ops *bytes_ext_ops;
73 int bytes_ext_ops_count;
75 /* optional fw loading callbacks to component drivers */
76 const struct snd_soc_tplg_ops *ops;
79 /* check we dont overflow the data for this control chunk */
80 static int soc_tplg_check_elem_count(struct soc_tplg *tplg, size_t elem_size,
81 unsigned int count, size_t bytes, const char *elem_type)
83 const u8 *end = tplg->pos + elem_size * count;
85 if (end > tplg->fw->data + tplg->fw->size) {
86 dev_err(tplg->dev, "ASoC: %s overflow end of data\n",
91 /* check there is enough room in chunk for control.
92 extra bytes at the end of control are for vendor data here */
93 if (elem_size * count > bytes) {
95 "ASoC: %s count %d of size %zu is bigger than chunk %zu\n",
96 elem_type, count, elem_size, bytes);
103 static inline bool soc_tplg_is_eof(struct soc_tplg *tplg)
105 const u8 *end = tplg->hdr_pos;
107 if (end >= tplg->fw->data + tplg->fw->size)
112 static inline unsigned long soc_tplg_get_hdr_offset(struct soc_tplg *tplg)
114 return (unsigned long)(tplg->hdr_pos - tplg->fw->data);
117 static inline unsigned long soc_tplg_get_offset(struct soc_tplg *tplg)
119 return (unsigned long)(tplg->pos - tplg->fw->data);
122 /* mapping of Kcontrol types and associated operations. */
123 static const struct snd_soc_tplg_kcontrol_ops io_ops[] = {
124 {SND_SOC_TPLG_CTL_VOLSW, snd_soc_get_volsw,
125 snd_soc_put_volsw, snd_soc_info_volsw},
126 {SND_SOC_TPLG_CTL_VOLSW_SX, snd_soc_get_volsw_sx,
127 snd_soc_put_volsw_sx, NULL},
128 {SND_SOC_TPLG_CTL_ENUM, snd_soc_get_enum_double,
129 snd_soc_put_enum_double, snd_soc_info_enum_double},
130 {SND_SOC_TPLG_CTL_ENUM_VALUE, snd_soc_get_enum_double,
131 snd_soc_put_enum_double, NULL},
132 {SND_SOC_TPLG_CTL_BYTES, snd_soc_bytes_get,
133 snd_soc_bytes_put, snd_soc_bytes_info},
134 {SND_SOC_TPLG_CTL_RANGE, snd_soc_get_volsw,
135 snd_soc_put_volsw, snd_soc_info_volsw},
136 {SND_SOC_TPLG_CTL_VOLSW_XR_SX, snd_soc_get_xr_sx,
137 snd_soc_put_xr_sx, snd_soc_info_xr_sx},
138 {SND_SOC_TPLG_CTL_STROBE, snd_soc_get_strobe,
139 snd_soc_put_strobe, NULL},
140 {SND_SOC_TPLG_DAPM_CTL_VOLSW, snd_soc_dapm_get_volsw,
141 snd_soc_dapm_put_volsw, snd_soc_info_volsw},
142 {SND_SOC_TPLG_DAPM_CTL_ENUM_DOUBLE, snd_soc_dapm_get_enum_double,
143 snd_soc_dapm_put_enum_double, snd_soc_info_enum_double},
144 {SND_SOC_TPLG_DAPM_CTL_ENUM_VIRT, snd_soc_dapm_get_enum_double,
145 snd_soc_dapm_put_enum_double, NULL},
146 {SND_SOC_TPLG_DAPM_CTL_ENUM_VALUE, snd_soc_dapm_get_enum_double,
147 snd_soc_dapm_put_enum_double, NULL},
148 {SND_SOC_TPLG_DAPM_CTL_PIN, snd_soc_dapm_get_pin_switch,
149 snd_soc_dapm_put_pin_switch, snd_soc_dapm_info_pin_switch},
152 struct soc_tplg_map {
157 /* mapping of widget types from UAPI IDs to kernel IDs */
158 static const struct soc_tplg_map dapm_map[] = {
159 {SND_SOC_TPLG_DAPM_INPUT, snd_soc_dapm_input},
160 {SND_SOC_TPLG_DAPM_OUTPUT, snd_soc_dapm_output},
161 {SND_SOC_TPLG_DAPM_MUX, snd_soc_dapm_mux},
162 {SND_SOC_TPLG_DAPM_MIXER, snd_soc_dapm_mixer},
163 {SND_SOC_TPLG_DAPM_PGA, snd_soc_dapm_pga},
164 {SND_SOC_TPLG_DAPM_OUT_DRV, snd_soc_dapm_out_drv},
165 {SND_SOC_TPLG_DAPM_ADC, snd_soc_dapm_adc},
166 {SND_SOC_TPLG_DAPM_DAC, snd_soc_dapm_dac},
167 {SND_SOC_TPLG_DAPM_SWITCH, snd_soc_dapm_switch},
168 {SND_SOC_TPLG_DAPM_PRE, snd_soc_dapm_pre},
169 {SND_SOC_TPLG_DAPM_POST, snd_soc_dapm_post},
170 {SND_SOC_TPLG_DAPM_AIF_IN, snd_soc_dapm_aif_in},
171 {SND_SOC_TPLG_DAPM_AIF_OUT, snd_soc_dapm_aif_out},
172 {SND_SOC_TPLG_DAPM_DAI_IN, snd_soc_dapm_dai_in},
173 {SND_SOC_TPLG_DAPM_DAI_OUT, snd_soc_dapm_dai_out},
174 {SND_SOC_TPLG_DAPM_DAI_LINK, snd_soc_dapm_dai_link},
175 {SND_SOC_TPLG_DAPM_BUFFER, snd_soc_dapm_buffer},
176 {SND_SOC_TPLG_DAPM_SCHEDULER, snd_soc_dapm_scheduler},
177 {SND_SOC_TPLG_DAPM_EFFECT, snd_soc_dapm_effect},
178 {SND_SOC_TPLG_DAPM_SIGGEN, snd_soc_dapm_siggen},
179 {SND_SOC_TPLG_DAPM_SRC, snd_soc_dapm_src},
180 {SND_SOC_TPLG_DAPM_ASRC, snd_soc_dapm_asrc},
181 {SND_SOC_TPLG_DAPM_ENCODER, snd_soc_dapm_encoder},
182 {SND_SOC_TPLG_DAPM_DECODER, snd_soc_dapm_decoder},
185 static int tplg_chan_get_reg(struct soc_tplg *tplg,
186 struct snd_soc_tplg_channel *chan, int map)
190 for (i = 0; i < SND_SOC_TPLG_MAX_CHAN; i++) {
191 if (le32_to_cpu(chan[i].id) == map)
192 return le32_to_cpu(chan[i].reg);
198 static int tplg_chan_get_shift(struct soc_tplg *tplg,
199 struct snd_soc_tplg_channel *chan, int map)
203 for (i = 0; i < SND_SOC_TPLG_MAX_CHAN; i++) {
204 if (le32_to_cpu(chan[i].id) == map)
205 return le32_to_cpu(chan[i].shift);
211 static int get_widget_id(int tplg_type)
215 for (i = 0; i < ARRAY_SIZE(dapm_map); i++) {
216 if (tplg_type == dapm_map[i].uid)
217 return dapm_map[i].kid;
223 static inline void soc_control_err(struct soc_tplg *tplg,
224 struct snd_soc_tplg_ctl_hdr *hdr, const char *name)
227 "ASoC: no complete control IO handler for %s type (g,p,i) %d:%d:%d at 0x%lx\n",
228 name, hdr->ops.get, hdr->ops.put, hdr->ops.info,
229 soc_tplg_get_offset(tplg));
232 /* pass vendor data to component driver for processing */
233 static int soc_tplg_vendor_load(struct soc_tplg *tplg,
234 struct snd_soc_tplg_hdr *hdr)
238 if (tplg->ops && tplg->ops->vendor_load)
239 ret = tplg->ops->vendor_load(tplg->comp, tplg->index, hdr);
241 dev_err(tplg->dev, "ASoC: no vendor load callback for ID %d\n",
248 "ASoC: vendor load failed at hdr offset %ld/0x%lx for type %d:%d\n",
249 soc_tplg_get_hdr_offset(tplg),
250 soc_tplg_get_hdr_offset(tplg),
251 hdr->type, hdr->vendor_type);
255 /* optionally pass new dynamic widget to component driver. This is mainly for
256 * external widgets where we can assign private data/ops */
257 static int soc_tplg_widget_load(struct soc_tplg *tplg,
258 struct snd_soc_dapm_widget *w, struct snd_soc_tplg_dapm_widget *tplg_w)
260 if (tplg->ops && tplg->ops->widget_load)
261 return tplg->ops->widget_load(tplg->comp, tplg->index, w,
267 /* optionally pass new dynamic widget to component driver. This is mainly for
268 * external widgets where we can assign private data/ops */
269 static int soc_tplg_widget_ready(struct soc_tplg *tplg,
270 struct snd_soc_dapm_widget *w, struct snd_soc_tplg_dapm_widget *tplg_w)
272 if (tplg->ops && tplg->ops->widget_ready)
273 return tplg->ops->widget_ready(tplg->comp, tplg->index, w,
279 /* pass DAI configurations to component driver for extra initialization */
280 static int soc_tplg_dai_load(struct soc_tplg *tplg,
281 struct snd_soc_dai_driver *dai_drv,
282 struct snd_soc_tplg_pcm *pcm, struct snd_soc_dai *dai)
284 if (tplg->ops && tplg->ops->dai_load)
285 return tplg->ops->dai_load(tplg->comp, tplg->index, dai_drv,
291 /* pass link configurations to component driver for extra initialization */
292 static int soc_tplg_dai_link_load(struct soc_tplg *tplg,
293 struct snd_soc_dai_link *link, struct snd_soc_tplg_link_config *cfg)
295 if (tplg->ops && tplg->ops->link_load)
296 return tplg->ops->link_load(tplg->comp, tplg->index, link, cfg);
301 /* tell the component driver that all firmware has been loaded in this request */
302 static int soc_tplg_complete(struct soc_tplg *tplg)
304 if (tplg->ops && tplg->ops->complete)
305 return tplg->ops->complete(tplg->comp);
310 /* add a dynamic kcontrol */
311 static int soc_tplg_add_dcontrol(struct snd_card *card, struct device *dev,
312 const struct snd_kcontrol_new *control_new, const char *prefix,
313 void *data, struct snd_kcontrol **kcontrol)
317 *kcontrol = snd_soc_cnew(control_new, data, control_new->name, prefix);
318 if (*kcontrol == NULL) {
319 dev_err(dev, "ASoC: Failed to create new kcontrol %s\n",
324 err = snd_ctl_add(card, *kcontrol);
326 dev_err(dev, "ASoC: Failed to add %s: %d\n",
327 control_new->name, err);
334 /* add a dynamic kcontrol for component driver */
335 static int soc_tplg_add_kcontrol(struct soc_tplg *tplg,
336 struct snd_kcontrol_new *k, struct snd_kcontrol **kcontrol)
338 struct snd_soc_component *comp = tplg->comp;
340 return soc_tplg_add_dcontrol(comp->card->snd_card,
341 tplg->dev, k, comp->name_prefix, comp, kcontrol);
344 /* remove kcontrol */
345 static void soc_tplg_remove_kcontrol(struct snd_soc_component *comp, struct snd_soc_dobj *dobj,
348 struct snd_card *card = comp->card->snd_card;
350 if (pass != SOC_TPLG_PASS_CONTROL)
354 dobj->unload(comp, dobj);
356 snd_ctl_remove(card, dobj->control.kcontrol);
357 list_del(&dobj->list);
361 static void soc_tplg_remove_route(struct snd_soc_component *comp,
362 struct snd_soc_dobj *dobj, int pass)
364 if (pass != SOC_TPLG_PASS_GRAPH)
368 dobj->unload(comp, dobj);
370 list_del(&dobj->list);
373 /* remove a widget and it's kcontrols - routes must be removed first */
374 static void soc_tplg_remove_widget(struct snd_soc_component *comp,
375 struct snd_soc_dobj *dobj, int pass)
377 struct snd_card *card = comp->card->snd_card;
378 struct snd_soc_dapm_widget *w =
379 container_of(dobj, struct snd_soc_dapm_widget, dobj);
382 if (pass != SOC_TPLG_PASS_WIDGET)
386 dobj->unload(comp, dobj);
389 for (i = 0; i < w->num_kcontrols; i++)
390 snd_ctl_remove(card, w->kcontrols[i]);
392 list_del(&dobj->list);
394 /* widget w is freed by soc-dapm.c */
397 /* remove DAI configurations */
398 static void soc_tplg_remove_dai(struct snd_soc_component *comp,
399 struct snd_soc_dobj *dobj, int pass)
401 struct snd_soc_dai_driver *dai_drv =
402 container_of(dobj, struct snd_soc_dai_driver, dobj);
403 struct snd_soc_dai *dai, *_dai;
405 if (pass != SOC_TPLG_PASS_PCM_DAI)
409 dobj->unload(comp, dobj);
411 for_each_component_dais_safe(comp, dai, _dai)
412 if (dai->driver == dai_drv)
413 snd_soc_unregister_dai(dai);
415 list_del(&dobj->list);
418 /* remove link configurations */
419 static void soc_tplg_remove_link(struct snd_soc_component *comp,
420 struct snd_soc_dobj *dobj, int pass)
422 struct snd_soc_dai_link *link =
423 container_of(dobj, struct snd_soc_dai_link, dobj);
425 if (pass != SOC_TPLG_PASS_PCM_DAI)
429 dobj->unload(comp, dobj);
431 list_del(&dobj->list);
432 snd_soc_remove_pcm_runtime(comp->card,
433 snd_soc_get_pcm_runtime(comp->card, link));
436 /* unload dai link */
437 static void remove_backend_link(struct snd_soc_component *comp,
438 struct snd_soc_dobj *dobj, int pass)
440 if (pass != SOC_TPLG_PASS_LINK)
444 dobj->unload(comp, dobj);
447 * We don't free the link here as what soc_tplg_remove_link() do since BE
448 * links are not allocated by topology.
449 * We however need to reset the dobj type to its initial values
451 dobj->type = SND_SOC_DOBJ_NONE;
452 list_del(&dobj->list);
455 /* bind a kcontrol to it's IO handlers */
456 static int soc_tplg_kcontrol_bind_io(struct snd_soc_tplg_ctl_hdr *hdr,
457 struct snd_kcontrol_new *k,
458 const struct soc_tplg *tplg)
460 const struct snd_soc_tplg_kcontrol_ops *ops;
461 const struct snd_soc_tplg_bytes_ext_ops *ext_ops;
464 if (le32_to_cpu(hdr->ops.info) == SND_SOC_TPLG_CTL_BYTES
465 && k->iface & SNDRV_CTL_ELEM_IFACE_MIXER
466 && (k->access & SNDRV_CTL_ELEM_ACCESS_TLV_READ
467 || k->access & SNDRV_CTL_ELEM_ACCESS_TLV_WRITE)
468 && k->access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK) {
469 struct soc_bytes_ext *sbe;
470 struct snd_soc_tplg_bytes_control *be;
472 sbe = (struct soc_bytes_ext *)k->private_value;
473 be = container_of(hdr, struct snd_soc_tplg_bytes_control, hdr);
475 /* TLV bytes controls need standard kcontrol info handler,
476 * TLV callback and extended put/get handlers.
478 k->info = snd_soc_bytes_info_ext;
479 k->tlv.c = snd_soc_bytes_tlv_callback;
482 * When a topology-based implementation abuses the
483 * control interface and uses bytes_ext controls of
484 * more than 512 bytes, we need to disable the size
485 * checks, otherwise accesses to such controls will
486 * return an -EINVAL error and prevent the card from
490 k->access |= SNDRV_CTL_ELEM_ACCESS_SKIP_CHECK;
492 ext_ops = tplg->bytes_ext_ops;
493 num_ops = tplg->bytes_ext_ops_count;
494 for (i = 0; i < num_ops; i++) {
496 ext_ops[i].id == le32_to_cpu(be->ext_ops.put))
497 sbe->put = ext_ops[i].put;
499 ext_ops[i].id == le32_to_cpu(be->ext_ops.get))
500 sbe->get = ext_ops[i].get;
503 if ((k->access & SNDRV_CTL_ELEM_ACCESS_TLV_READ) && !sbe->get)
505 if ((k->access & SNDRV_CTL_ELEM_ACCESS_TLV_WRITE) && !sbe->put)
510 /* try and map vendor specific kcontrol handlers first */
512 num_ops = tplg->io_ops_count;
513 for (i = 0; i < num_ops; i++) {
515 if (k->put == NULL && ops[i].id == le32_to_cpu(hdr->ops.put))
517 if (k->get == NULL && ops[i].id == le32_to_cpu(hdr->ops.get))
519 if (k->info == NULL && ops[i].id == le32_to_cpu(hdr->ops.info))
520 k->info = ops[i].info;
523 /* vendor specific handlers found ? */
524 if (k->put && k->get && k->info)
527 /* none found so try standard kcontrol handlers */
529 num_ops = ARRAY_SIZE(io_ops);
530 for (i = 0; i < num_ops; i++) {
532 if (k->put == NULL && ops[i].id == le32_to_cpu(hdr->ops.put))
534 if (k->get == NULL && ops[i].id == le32_to_cpu(hdr->ops.get))
536 if (k->info == NULL && ops[i].id == le32_to_cpu(hdr->ops.info))
537 k->info = ops[i].info;
540 /* standard handlers found ? */
541 if (k->put && k->get && k->info)
544 /* nothing to bind */
548 /* bind a widgets to it's evnt handlers */
549 int snd_soc_tplg_widget_bind_event(struct snd_soc_dapm_widget *w,
550 const struct snd_soc_tplg_widget_events *events,
551 int num_events, u16 event_type)
557 for (i = 0; i < num_events; i++) {
558 if (event_type == events[i].type) {
560 /* found - so assign event */
561 w->event = events[i].event_handler;
569 EXPORT_SYMBOL_GPL(snd_soc_tplg_widget_bind_event);
571 /* optionally pass new dynamic kcontrol to component driver. */
572 static int soc_tplg_control_load(struct soc_tplg *tplg,
573 struct snd_kcontrol_new *k, struct snd_soc_tplg_ctl_hdr *hdr)
577 if (tplg->ops && tplg->ops->control_load)
578 ret = tplg->ops->control_load(tplg->comp, tplg->index, k, hdr);
581 dev_err(tplg->dev, "ASoC: failed to init %s\n", hdr->name);
587 static int soc_tplg_create_tlv_db_scale(struct soc_tplg *tplg,
588 struct snd_kcontrol_new *kc, struct snd_soc_tplg_tlv_dbscale *scale)
590 unsigned int item_len = 2 * sizeof(unsigned int);
593 p = devm_kzalloc(tplg->dev, item_len + 2 * sizeof(unsigned int), GFP_KERNEL);
597 p[0] = SNDRV_CTL_TLVT_DB_SCALE;
599 p[2] = le32_to_cpu(scale->min);
600 p[3] = (le32_to_cpu(scale->step) & TLV_DB_SCALE_MASK)
601 | (le32_to_cpu(scale->mute) ? TLV_DB_SCALE_MUTE : 0);
603 kc->tlv.p = (void *)p;
607 static int soc_tplg_create_tlv(struct soc_tplg *tplg,
608 struct snd_kcontrol_new *kc, struct snd_soc_tplg_ctl_hdr *tc)
610 struct snd_soc_tplg_ctl_tlv *tplg_tlv;
611 u32 access = le32_to_cpu(tc->access);
613 if (!(access & SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE))
616 if (!(access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK)) {
618 switch (le32_to_cpu(tplg_tlv->type)) {
619 case SNDRV_CTL_TLVT_DB_SCALE:
620 return soc_tplg_create_tlv_db_scale(tplg, kc,
623 /* TODO: add support for other TLV types */
625 dev_dbg(tplg->dev, "Unsupported TLV type %d\n",
634 static int soc_tplg_control_dmixer_create(struct soc_tplg *tplg, struct snd_kcontrol_new *kc)
636 struct snd_soc_tplg_mixer_control *mc;
637 struct soc_mixer_control *sm;
640 mc = (struct snd_soc_tplg_mixer_control *)tplg->pos;
642 /* validate kcontrol */
643 if (strnlen(mc->hdr.name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == SNDRV_CTL_ELEM_ID_NAME_MAXLEN)
646 sm = devm_kzalloc(tplg->dev, sizeof(*sm), GFP_KERNEL);
650 tplg->pos += sizeof(struct snd_soc_tplg_mixer_control) + le32_to_cpu(mc->priv.size);
652 dev_dbg(tplg->dev, "ASoC: adding mixer kcontrol %s with access 0x%x\n",
653 mc->hdr.name, mc->hdr.access);
655 kc->name = devm_kstrdup(tplg->dev, mc->hdr.name, GFP_KERNEL);
658 kc->private_value = (long)sm;
659 kc->iface = SNDRV_CTL_ELEM_IFACE_MIXER;
660 kc->access = le32_to_cpu(mc->hdr.access);
662 /* we only support FL/FR channel mapping atm */
663 sm->reg = tplg_chan_get_reg(tplg, mc->channel, SNDRV_CHMAP_FL);
664 sm->rreg = tplg_chan_get_reg(tplg, mc->channel, SNDRV_CHMAP_FR);
665 sm->shift = tplg_chan_get_shift(tplg, mc->channel, SNDRV_CHMAP_FL);
666 sm->rshift = tplg_chan_get_shift(tplg, mc->channel, SNDRV_CHMAP_FR);
668 sm->max = le32_to_cpu(mc->max);
669 sm->min = le32_to_cpu(mc->min);
670 sm->invert = le32_to_cpu(mc->invert);
671 sm->platform_max = le32_to_cpu(mc->platform_max);
672 sm->num_channels = le32_to_cpu(mc->num_channels);
674 /* map io handlers */
675 err = soc_tplg_kcontrol_bind_io(&mc->hdr, kc, tplg);
677 soc_control_err(tplg, &mc->hdr, mc->hdr.name);
681 /* create any TLV data */
682 err = soc_tplg_create_tlv(tplg, kc, &mc->hdr);
684 dev_err(tplg->dev, "ASoC: failed to create TLV %s\n", mc->hdr.name);
688 /* pass control to driver for optional further init */
689 return soc_tplg_control_load(tplg, kc, &mc->hdr);
692 static int soc_tplg_denum_create_texts(struct soc_tplg *tplg, struct soc_enum *se,
693 struct snd_soc_tplg_enum_control *ec)
697 if (le32_to_cpu(ec->items) > ARRAY_SIZE(ec->texts))
700 se->dobj.control.dtexts =
701 devm_kcalloc(tplg->dev, le32_to_cpu(ec->items), sizeof(char *), GFP_KERNEL);
702 if (se->dobj.control.dtexts == NULL)
705 for (i = 0; i < le32_to_cpu(ec->items); i++) {
707 if (strnlen(ec->texts[i], SNDRV_CTL_ELEM_ID_NAME_MAXLEN) ==
708 SNDRV_CTL_ELEM_ID_NAME_MAXLEN) {
713 se->dobj.control.dtexts[i] = devm_kstrdup(tplg->dev, ec->texts[i], GFP_KERNEL);
714 if (!se->dobj.control.dtexts[i]) {
720 se->items = le32_to_cpu(ec->items);
721 se->texts = (const char * const *)se->dobj.control.dtexts;
728 static int soc_tplg_denum_create_values(struct soc_tplg *tplg, struct soc_enum *se,
729 struct snd_soc_tplg_enum_control *ec)
734 * Following "if" checks if we have at most SND_SOC_TPLG_NUM_TEXTS
735 * values instead of using ARRAY_SIZE(ec->values) due to the fact that
736 * it is oversized for its purpose. Additionally it is done so because
737 * it is defined in UAPI header where it can't be easily changed.
739 if (le32_to_cpu(ec->items) > SND_SOC_TPLG_NUM_TEXTS)
742 se->dobj.control.dvalues = devm_kcalloc(tplg->dev, le32_to_cpu(ec->items),
743 sizeof(*se->dobj.control.dvalues),
745 if (!se->dobj.control.dvalues)
748 /* convert from little-endian */
749 for (i = 0; i < le32_to_cpu(ec->items); i++) {
750 se->dobj.control.dvalues[i] = le32_to_cpu(ec->values[i]);
753 se->items = le32_to_cpu(ec->items);
754 se->values = (const unsigned int *)se->dobj.control.dvalues;
758 static int soc_tplg_control_denum_create(struct soc_tplg *tplg, struct snd_kcontrol_new *kc)
760 struct snd_soc_tplg_enum_control *ec;
764 ec = (struct snd_soc_tplg_enum_control *)tplg->pos;
766 /* validate kcontrol */
767 if (strnlen(ec->hdr.name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == SNDRV_CTL_ELEM_ID_NAME_MAXLEN)
770 se = devm_kzalloc(tplg->dev, sizeof(*se), GFP_KERNEL);
774 tplg->pos += (sizeof(struct snd_soc_tplg_enum_control) + le32_to_cpu(ec->priv.size));
776 dev_dbg(tplg->dev, "ASoC: adding enum kcontrol %s size %d\n", ec->hdr.name, ec->items);
778 kc->name = devm_kstrdup(tplg->dev, ec->hdr.name, GFP_KERNEL);
781 kc->private_value = (long)se;
782 kc->iface = SNDRV_CTL_ELEM_IFACE_MIXER;
783 kc->access = le32_to_cpu(ec->hdr.access);
785 /* we only support FL/FR channel mapping atm */
786 se->reg = tplg_chan_get_reg(tplg, ec->channel, SNDRV_CHMAP_FL);
787 se->shift_l = tplg_chan_get_shift(tplg, ec->channel, SNDRV_CHMAP_FL);
788 se->shift_r = tplg_chan_get_shift(tplg, ec->channel, SNDRV_CHMAP_FR);
790 se->mask = le32_to_cpu(ec->mask);
792 switch (le32_to_cpu(ec->hdr.ops.info)) {
793 case SND_SOC_TPLG_CTL_ENUM_VALUE:
794 case SND_SOC_TPLG_DAPM_CTL_ENUM_VALUE:
795 err = soc_tplg_denum_create_values(tplg, se, ec);
797 dev_err(tplg->dev, "ASoC: could not create values for %s\n", ec->hdr.name);
801 case SND_SOC_TPLG_CTL_ENUM:
802 case SND_SOC_TPLG_DAPM_CTL_ENUM_DOUBLE:
803 case SND_SOC_TPLG_DAPM_CTL_ENUM_VIRT:
804 err = soc_tplg_denum_create_texts(tplg, se, ec);
806 dev_err(tplg->dev, "ASoC: could not create texts for %s\n", ec->hdr.name);
811 dev_err(tplg->dev, "ASoC: invalid enum control type %d for %s\n",
812 ec->hdr.ops.info, ec->hdr.name);
816 /* map io handlers */
817 err = soc_tplg_kcontrol_bind_io(&ec->hdr, kc, tplg);
819 soc_control_err(tplg, &ec->hdr, ec->hdr.name);
823 /* pass control to driver for optional further init */
824 return soc_tplg_control_load(tplg, kc, &ec->hdr);
827 static int soc_tplg_control_dbytes_create(struct soc_tplg *tplg, struct snd_kcontrol_new *kc)
829 struct snd_soc_tplg_bytes_control *be;
830 struct soc_bytes_ext *sbe;
833 be = (struct snd_soc_tplg_bytes_control *)tplg->pos;
835 /* validate kcontrol */
836 if (strnlen(be->hdr.name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == SNDRV_CTL_ELEM_ID_NAME_MAXLEN)
839 sbe = devm_kzalloc(tplg->dev, sizeof(*sbe), GFP_KERNEL);
843 tplg->pos += (sizeof(struct snd_soc_tplg_bytes_control) + le32_to_cpu(be->priv.size));
845 dev_dbg(tplg->dev, "ASoC: adding bytes kcontrol %s with access 0x%x\n",
846 be->hdr.name, be->hdr.access);
848 kc->name = devm_kstrdup(tplg->dev, be->hdr.name, GFP_KERNEL);
851 kc->private_value = (long)sbe;
852 kc->iface = SNDRV_CTL_ELEM_IFACE_MIXER;
853 kc->access = le32_to_cpu(be->hdr.access);
855 sbe->max = le32_to_cpu(be->max);
857 /* map standard io handlers and check for external handlers */
858 err = soc_tplg_kcontrol_bind_io(&be->hdr, kc, tplg);
860 soc_control_err(tplg, &be->hdr, be->hdr.name);
864 /* pass control to driver for optional further init */
865 return soc_tplg_control_load(tplg, kc, &be->hdr);
868 static int soc_tplg_dbytes_create(struct soc_tplg *tplg, size_t size)
870 struct snd_kcontrol_new kc = {0};
871 struct soc_bytes_ext *sbe;
874 if (soc_tplg_check_elem_count(tplg,
875 sizeof(struct snd_soc_tplg_bytes_control),
876 1, size, "mixer bytes"))
879 ret = soc_tplg_control_dbytes_create(tplg, &kc);
883 /* register dynamic object */
884 sbe = (struct soc_bytes_ext *)kc.private_value;
886 INIT_LIST_HEAD(&sbe->dobj.list);
887 sbe->dobj.type = SND_SOC_DOBJ_BYTES;
888 sbe->dobj.index = tplg->index;
890 sbe->dobj.unload = tplg->ops->control_unload;
892 /* create control directly */
893 ret = soc_tplg_add_kcontrol(tplg, &kc, &sbe->dobj.control.kcontrol);
897 list_add(&sbe->dobj.list, &tplg->comp->dobj_list);
902 static int soc_tplg_dmixer_create(struct soc_tplg *tplg, size_t size)
904 struct snd_kcontrol_new kc = {0};
905 struct soc_mixer_control *sm;
908 if (soc_tplg_check_elem_count(tplg,
909 sizeof(struct snd_soc_tplg_mixer_control),
913 ret = soc_tplg_control_dmixer_create(tplg, &kc);
917 /* register dynamic object */
918 sm = (struct soc_mixer_control *)kc.private_value;
920 INIT_LIST_HEAD(&sm->dobj.list);
921 sm->dobj.type = SND_SOC_DOBJ_MIXER;
922 sm->dobj.index = tplg->index;
924 sm->dobj.unload = tplg->ops->control_unload;
926 /* create control directly */
927 ret = soc_tplg_add_kcontrol(tplg, &kc, &sm->dobj.control.kcontrol);
931 list_add(&sm->dobj.list, &tplg->comp->dobj_list);
936 static int soc_tplg_denum_create(struct soc_tplg *tplg, size_t size)
938 struct snd_kcontrol_new kc = {0};
942 if (soc_tplg_check_elem_count(tplg,
943 sizeof(struct snd_soc_tplg_enum_control),
947 ret = soc_tplg_control_denum_create(tplg, &kc);
951 /* register dynamic object */
952 se = (struct soc_enum *)kc.private_value;
954 INIT_LIST_HEAD(&se->dobj.list);
955 se->dobj.type = SND_SOC_DOBJ_ENUM;
956 se->dobj.index = tplg->index;
958 se->dobj.unload = tplg->ops->control_unload;
960 /* create control directly */
961 ret = soc_tplg_add_kcontrol(tplg, &kc, &se->dobj.control.kcontrol);
965 list_add(&se->dobj.list, &tplg->comp->dobj_list);
970 static int soc_tplg_kcontrol_elems_load(struct soc_tplg *tplg,
971 struct snd_soc_tplg_hdr *hdr)
976 dev_dbg(tplg->dev, "ASoC: adding %d kcontrols at 0x%lx\n", hdr->count,
977 soc_tplg_get_offset(tplg));
979 for (i = 0; i < le32_to_cpu(hdr->count); i++) {
980 struct snd_soc_tplg_ctl_hdr *control_hdr = (struct snd_soc_tplg_ctl_hdr *)tplg->pos;
982 if (le32_to_cpu(control_hdr->size) != sizeof(*control_hdr)) {
983 dev_err(tplg->dev, "ASoC: invalid control size\n");
987 switch (le32_to_cpu(control_hdr->type)) {
988 case SND_SOC_TPLG_TYPE_MIXER:
989 ret = soc_tplg_dmixer_create(tplg, le32_to_cpu(hdr->payload_size));
991 case SND_SOC_TPLG_TYPE_ENUM:
992 ret = soc_tplg_denum_create(tplg, le32_to_cpu(hdr->payload_size));
994 case SND_SOC_TPLG_TYPE_BYTES:
995 ret = soc_tplg_dbytes_create(tplg, le32_to_cpu(hdr->payload_size));
1003 dev_err(tplg->dev, "ASoC: invalid control type: %d, index: %d at 0x%lx\n",
1004 control_hdr->type, i, soc_tplg_get_offset(tplg));
1012 /* optionally pass new dynamic kcontrol to component driver. */
1013 static int soc_tplg_add_route(struct soc_tplg *tplg,
1014 struct snd_soc_dapm_route *route)
1016 if (tplg->ops && tplg->ops->dapm_route_load)
1017 return tplg->ops->dapm_route_load(tplg->comp, tplg->index,
1023 static int soc_tplg_dapm_graph_elems_load(struct soc_tplg *tplg,
1024 struct snd_soc_tplg_hdr *hdr)
1026 struct snd_soc_dapm_context *dapm = &tplg->comp->dapm;
1027 const size_t maxlen = SNDRV_CTL_ELEM_ID_NAME_MAXLEN;
1028 struct snd_soc_tplg_dapm_graph_elem *elem;
1029 struct snd_soc_dapm_route *route;
1033 count = le32_to_cpu(hdr->count);
1035 if (soc_tplg_check_elem_count(tplg,
1036 sizeof(struct snd_soc_tplg_dapm_graph_elem),
1037 count, le32_to_cpu(hdr->payload_size), "graph"))
1040 dev_dbg(tplg->dev, "ASoC: adding %d DAPM routes for index %d\n", count,
1043 for (i = 0; i < count; i++) {
1044 route = devm_kzalloc(tplg->dev, sizeof(*route), GFP_KERNEL);
1047 elem = (struct snd_soc_tplg_dapm_graph_elem *)tplg->pos;
1048 tplg->pos += sizeof(struct snd_soc_tplg_dapm_graph_elem);
1050 /* validate routes */
1051 if ((strnlen(elem->source, maxlen) == maxlen) ||
1052 (strnlen(elem->sink, maxlen) == maxlen) ||
1053 (strnlen(elem->control, maxlen) == maxlen)) {
1058 route->source = devm_kstrdup(tplg->dev, elem->source, GFP_KERNEL);
1059 route->sink = devm_kstrdup(tplg->dev, elem->sink, GFP_KERNEL);
1060 if (!route->source || !route->sink) {
1065 if (strnlen(elem->control, maxlen) != 0) {
1066 route->control = devm_kstrdup(tplg->dev, elem->control, GFP_KERNEL);
1067 if (!route->control) {
1073 /* add route dobj to dobj_list */
1074 route->dobj.type = SND_SOC_DOBJ_GRAPH;
1076 route->dobj.unload = tplg->ops->dapm_route_unload;
1077 route->dobj.index = tplg->index;
1078 list_add(&route->dobj.list, &tplg->comp->dobj_list);
1080 ret = soc_tplg_add_route(tplg, route);
1082 dev_err(tplg->dev, "ASoC: topology: add_route failed: %d\n", ret);
1086 ret = snd_soc_dapm_add_routes(dapm, route, 1);
1094 static int soc_tplg_dapm_widget_create(struct soc_tplg *tplg,
1095 struct snd_soc_tplg_dapm_widget *w)
1097 struct snd_soc_dapm_context *dapm = &tplg->comp->dapm;
1098 struct snd_soc_dapm_widget template, *widget;
1099 struct snd_soc_tplg_ctl_hdr *control_hdr;
1100 struct snd_soc_card *card = tplg->comp->card;
1101 unsigned int *kcontrol_type = NULL;
1102 struct snd_kcontrol_new *kc;
1103 int mixer_count = 0;
1104 int bytes_count = 0;
1109 if (strnlen(w->name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) ==
1110 SNDRV_CTL_ELEM_ID_NAME_MAXLEN)
1112 if (strnlen(w->sname, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) ==
1113 SNDRV_CTL_ELEM_ID_NAME_MAXLEN)
1116 dev_dbg(tplg->dev, "ASoC: creating DAPM widget %s id %d\n",
1119 memset(&template, 0, sizeof(template));
1121 /* map user to kernel widget ID */
1122 template.id = get_widget_id(le32_to_cpu(w->id));
1123 if ((int)template.id < 0)
1126 /* strings are allocated here, but used and freed by the widget */
1127 template.name = kstrdup(w->name, GFP_KERNEL);
1130 template.sname = kstrdup(w->sname, GFP_KERNEL);
1131 if (!template.sname) {
1135 template.reg = le32_to_cpu(w->reg);
1136 template.shift = le32_to_cpu(w->shift);
1137 template.mask = le32_to_cpu(w->mask);
1138 template.subseq = le32_to_cpu(w->subseq);
1139 template.on_val = w->invert ? 0 : 1;
1140 template.off_val = w->invert ? 1 : 0;
1141 template.ignore_suspend = le32_to_cpu(w->ignore_suspend);
1142 template.event_flags = le16_to_cpu(w->event_flags);
1143 template.dobj.index = tplg->index;
1146 (sizeof(struct snd_soc_tplg_dapm_widget) +
1147 le32_to_cpu(w->priv.size));
1149 if (w->num_kcontrols == 0) {
1150 template.num_kcontrols = 0;
1154 template.num_kcontrols = le32_to_cpu(w->num_kcontrols);
1155 kc = devm_kcalloc(tplg->dev, le32_to_cpu(w->num_kcontrols), sizeof(*kc), GFP_KERNEL);
1161 kcontrol_type = devm_kcalloc(tplg->dev, le32_to_cpu(w->num_kcontrols), sizeof(unsigned int),
1163 if (!kcontrol_type) {
1168 for (i = 0; i < le32_to_cpu(w->num_kcontrols); i++) {
1169 control_hdr = (struct snd_soc_tplg_ctl_hdr *)tplg->pos;
1171 switch (le32_to_cpu(control_hdr->type)) {
1172 case SND_SOC_TPLG_TYPE_MIXER:
1174 kc[i].index = mixer_count;
1175 kcontrol_type[i] = SND_SOC_TPLG_TYPE_MIXER;
1177 ret = soc_tplg_control_dmixer_create(tplg, &kc[i]);
1181 case SND_SOC_TPLG_TYPE_ENUM:
1182 /* enumerated mixer */
1183 kc[i].index = enum_count;
1184 kcontrol_type[i] = SND_SOC_TPLG_TYPE_ENUM;
1186 ret = soc_tplg_control_denum_create(tplg, &kc[i]);
1190 case SND_SOC_TPLG_TYPE_BYTES:
1192 kc[i].index = bytes_count;
1193 kcontrol_type[i] = SND_SOC_TPLG_TYPE_BYTES;
1195 ret = soc_tplg_control_dbytes_create(tplg, &kc[i]);
1200 dev_err(tplg->dev, "ASoC: invalid widget control type %d:%d:%d\n",
1201 control_hdr->ops.get, control_hdr->ops.put,
1202 le32_to_cpu(control_hdr->ops.info));
1208 template.kcontrol_news = kc;
1209 dev_dbg(tplg->dev, "ASoC: template %s with %d/%d/%d (mixer/enum/bytes) control\n",
1210 w->name, mixer_count, enum_count, bytes_count);
1213 ret = soc_tplg_widget_load(tplg, &template, w);
1217 /* card dapm mutex is held by the core if we are loading topology
1218 * data during sound card init. */
1219 if (snd_soc_card_is_instantiated(card))
1220 widget = snd_soc_dapm_new_control(dapm, &template);
1222 widget = snd_soc_dapm_new_control_unlocked(dapm, &template);
1223 if (IS_ERR(widget)) {
1224 ret = PTR_ERR(widget);
1228 widget->dobj.type = SND_SOC_DOBJ_WIDGET;
1229 widget->dobj.widget.kcontrol_type = kcontrol_type;
1231 widget->dobj.unload = tplg->ops->widget_unload;
1232 widget->dobj.index = tplg->index;
1233 list_add(&widget->dobj.list, &tplg->comp->dobj_list);
1235 ret = soc_tplg_widget_ready(tplg, widget, w);
1239 kfree(template.sname);
1240 kfree(template.name);
1245 soc_tplg_remove_widget(widget->dapm->component, &widget->dobj, SOC_TPLG_PASS_WIDGET);
1246 snd_soc_dapm_free_widget(widget);
1248 kfree(template.sname);
1250 kfree(template.name);
1254 static int soc_tplg_dapm_widget_elems_load(struct soc_tplg *tplg,
1255 struct snd_soc_tplg_hdr *hdr)
1259 count = le32_to_cpu(hdr->count);
1261 dev_dbg(tplg->dev, "ASoC: adding %d DAPM widgets\n", count);
1263 for (i = 0; i < count; i++) {
1264 struct snd_soc_tplg_dapm_widget *widget = (struct snd_soc_tplg_dapm_widget *) tplg->pos;
1268 * check if widget itself fits within topology file
1269 * use sizeof instead of widget->size, as we can't be sure
1270 * it is set properly yet (file may end before it is present)
1272 if (soc_tplg_get_offset(tplg) + sizeof(*widget) >= tplg->fw->size) {
1273 dev_err(tplg->dev, "ASoC: invalid widget data size\n");
1277 /* check if widget has proper size */
1278 if (le32_to_cpu(widget->size) != sizeof(*widget)) {
1279 dev_err(tplg->dev, "ASoC: invalid widget size\n");
1283 /* check if widget private data fits within topology file */
1284 if (soc_tplg_get_offset(tplg) + le32_to_cpu(widget->priv.size) >= tplg->fw->size) {
1285 dev_err(tplg->dev, "ASoC: invalid widget private data size\n");
1289 ret = soc_tplg_dapm_widget_create(tplg, widget);
1291 dev_err(tplg->dev, "ASoC: failed to load widget %s\n",
1300 static int soc_tplg_dapm_complete(struct soc_tplg *tplg)
1302 struct snd_soc_card *card = tplg->comp->card;
1305 /* Card might not have been registered at this point.
1306 * If so, just return success.
1308 if (!snd_soc_card_is_instantiated(card)) {
1309 dev_warn(tplg->dev, "ASoC: Parent card not yet available, widget card binding deferred\n");
1313 ret = snd_soc_dapm_new_widgets(card);
1315 dev_err(tplg->dev, "ASoC: failed to create new widgets %d\n", ret);
1320 static int set_stream_info(struct soc_tplg *tplg, struct snd_soc_pcm_stream *stream,
1321 struct snd_soc_tplg_stream_caps *caps)
1323 stream->stream_name = devm_kstrdup(tplg->dev, caps->name, GFP_KERNEL);
1324 if (!stream->stream_name)
1327 stream->channels_min = le32_to_cpu(caps->channels_min);
1328 stream->channels_max = le32_to_cpu(caps->channels_max);
1329 stream->rates = le32_to_cpu(caps->rates);
1330 stream->rate_min = le32_to_cpu(caps->rate_min);
1331 stream->rate_max = le32_to_cpu(caps->rate_max);
1332 stream->formats = le64_to_cpu(caps->formats);
1333 stream->sig_bits = le32_to_cpu(caps->sig_bits);
1338 static void set_dai_flags(struct snd_soc_dai_driver *dai_drv,
1339 unsigned int flag_mask, unsigned int flags)
1341 if (flag_mask & SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_RATES)
1342 dai_drv->symmetric_rate =
1343 (flags & SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_RATES) ? 1 : 0;
1345 if (flag_mask & SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_CHANNELS)
1346 dai_drv->symmetric_channels =
1347 (flags & SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_CHANNELS) ?
1350 if (flag_mask & SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_SAMPLEBITS)
1351 dai_drv->symmetric_sample_bits =
1352 (flags & SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_SAMPLEBITS) ?
1356 static const struct snd_soc_dai_ops tplg_dai_ops = {
1357 .compress_new = snd_soc_new_compress,
1360 static int soc_tplg_dai_create(struct soc_tplg *tplg,
1361 struct snd_soc_tplg_pcm *pcm)
1363 struct snd_soc_dai_driver *dai_drv;
1364 struct snd_soc_pcm_stream *stream;
1365 struct snd_soc_tplg_stream_caps *caps;
1366 struct snd_soc_dai *dai;
1367 struct snd_soc_dapm_context *dapm =
1368 snd_soc_component_get_dapm(tplg->comp);
1371 dai_drv = devm_kzalloc(tplg->dev, sizeof(struct snd_soc_dai_driver), GFP_KERNEL);
1372 if (dai_drv == NULL)
1375 if (strlen(pcm->dai_name)) {
1376 dai_drv->name = devm_kstrdup(tplg->dev, pcm->dai_name, GFP_KERNEL);
1377 if (!dai_drv->name) {
1382 dai_drv->id = le32_to_cpu(pcm->dai_id);
1384 if (pcm->playback) {
1385 stream = &dai_drv->playback;
1386 caps = &pcm->caps[SND_SOC_TPLG_STREAM_PLAYBACK];
1387 ret = set_stream_info(tplg, stream, caps);
1393 stream = &dai_drv->capture;
1394 caps = &pcm->caps[SND_SOC_TPLG_STREAM_CAPTURE];
1395 ret = set_stream_info(tplg, stream, caps);
1401 dai_drv->ops = &tplg_dai_ops;
1403 /* pass control to component driver for optional further init */
1404 ret = soc_tplg_dai_load(tplg, dai_drv, pcm, NULL);
1406 dev_err(tplg->dev, "ASoC: DAI loading failed\n");
1410 dai_drv->dobj.index = tplg->index;
1411 dai_drv->dobj.type = SND_SOC_DOBJ_PCM;
1413 dai_drv->dobj.unload = tplg->ops->dai_unload;
1414 list_add(&dai_drv->dobj.list, &tplg->comp->dobj_list);
1416 /* register the DAI to the component */
1417 dai = snd_soc_register_dai(tplg->comp, dai_drv, false);
1421 /* Create the DAI widgets here */
1422 ret = snd_soc_dapm_new_dai_widgets(dapm, dai);
1424 dev_err(dai->dev, "Failed to create DAI widgets %d\n", ret);
1425 snd_soc_unregister_dai(dai);
1435 static void set_link_flags(struct snd_soc_dai_link *link,
1436 unsigned int flag_mask, unsigned int flags)
1438 if (flag_mask & SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_RATES)
1439 link->symmetric_rate =
1440 (flags & SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_RATES) ? 1 : 0;
1442 if (flag_mask & SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_CHANNELS)
1443 link->symmetric_channels =
1444 (flags & SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_CHANNELS) ?
1447 if (flag_mask & SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_SAMPLEBITS)
1448 link->symmetric_sample_bits =
1449 (flags & SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_SAMPLEBITS) ?
1452 if (flag_mask & SND_SOC_TPLG_LNK_FLGBIT_VOICE_WAKEUP)
1453 link->ignore_suspend =
1454 (flags & SND_SOC_TPLG_LNK_FLGBIT_VOICE_WAKEUP) ?
1458 /* create the FE DAI link */
1459 static int soc_tplg_fe_link_create(struct soc_tplg *tplg,
1460 struct snd_soc_tplg_pcm *pcm)
1462 struct snd_soc_dai_link *link;
1463 struct snd_soc_dai_link_component *dlc;
1466 /* link + cpu + codec + platform */
1467 link = devm_kzalloc(tplg->dev, sizeof(*link) + (3 * sizeof(*dlc)), GFP_KERNEL);
1471 dlc = (struct snd_soc_dai_link_component *)(link + 1);
1473 link->cpus = &dlc[0];
1476 link->dobj.index = tplg->index;
1477 link->dobj.type = SND_SOC_DOBJ_DAI_LINK;
1479 link->dobj.unload = tplg->ops->link_unload;
1481 if (strlen(pcm->pcm_name)) {
1482 link->name = devm_kstrdup(tplg->dev, pcm->pcm_name, GFP_KERNEL);
1483 link->stream_name = devm_kstrdup(tplg->dev, pcm->pcm_name, GFP_KERNEL);
1484 if (!link->name || !link->stream_name) {
1489 link->id = le32_to_cpu(pcm->pcm_id);
1491 if (strlen(pcm->dai_name)) {
1492 link->cpus->dai_name = devm_kstrdup(tplg->dev, pcm->dai_name, GFP_KERNEL);
1493 if (!link->cpus->dai_name) {
1500 * Many topology are assuming link has Codec / Platform, and
1501 * these might be overwritten at soc_tplg_dai_link_load().
1502 * Don't use &snd_soc_dummy_dlc here.
1504 link->codecs = &dlc[1]; /* Don't use &snd_soc_dummy_dlc here */
1505 link->codecs->name = "snd-soc-dummy";
1506 link->codecs->dai_name = "snd-soc-dummy-dai";
1507 link->num_codecs = 1;
1509 link->platforms = &dlc[2]; /* Don't use &snd_soc_dummy_dlc here */
1510 link->platforms->name = "snd-soc-dummy";
1511 link->num_platforms = 1;
1515 link->ignore_pmdown_time = 1;
1516 link->playback_only = le32_to_cpu(pcm->playback) && !le32_to_cpu(pcm->capture);
1517 link->capture_only = !le32_to_cpu(pcm->playback) && le32_to_cpu(pcm->capture);
1519 set_link_flags(link,
1520 le32_to_cpu(pcm->flag_mask),
1521 le32_to_cpu(pcm->flags));
1523 /* pass control to component driver for optional further init */
1524 ret = soc_tplg_dai_link_load(tplg, link, NULL);
1526 dev_err(tplg->dev, "ASoC: FE link loading failed\n");
1530 ret = snd_soc_add_pcm_runtimes(tplg->comp->card, link, 1);
1532 if (ret != -EPROBE_DEFER)
1533 dev_err(tplg->dev, "ASoC: adding FE link failed\n");
1537 list_add(&link->dobj.list, &tplg->comp->dobj_list);
1544 /* create a FE DAI and DAI link from the PCM object */
1545 static int soc_tplg_pcm_create(struct soc_tplg *tplg,
1546 struct snd_soc_tplg_pcm *pcm)
1550 ret = soc_tplg_dai_create(tplg, pcm);
1554 return soc_tplg_fe_link_create(tplg, pcm);
1557 static int soc_tplg_pcm_elems_load(struct soc_tplg *tplg,
1558 struct snd_soc_tplg_hdr *hdr)
1560 struct snd_soc_tplg_pcm *pcm;
1566 count = le32_to_cpu(hdr->count);
1568 /* check the element size and count */
1569 pcm = (struct snd_soc_tplg_pcm *)tplg->pos;
1570 size = le32_to_cpu(pcm->size);
1571 if (size > sizeof(struct snd_soc_tplg_pcm)) {
1572 dev_err(tplg->dev, "ASoC: invalid size %d for PCM elems\n",
1577 if (soc_tplg_check_elem_count(tplg,
1579 le32_to_cpu(hdr->payload_size),
1583 for (i = 0; i < count; i++) {
1584 pcm = (struct snd_soc_tplg_pcm *)tplg->pos;
1585 size = le32_to_cpu(pcm->size);
1587 /* check ABI version by size, create a new version of pcm
1590 if (size != sizeof(*pcm))
1593 /* create the FE DAIs and DAI links */
1594 ret = soc_tplg_pcm_create(tplg, pcm);
1598 /* offset by version-specific struct size and
1599 * real priv data size
1601 tplg->pos += size + le32_to_cpu(pcm->priv.size);
1604 dev_dbg(tplg->dev, "ASoC: adding %d PCM DAIs\n", count);
1610 * set_link_hw_format - Set the HW audio format of the physical DAI link.
1611 * @link: &snd_soc_dai_link which should be updated
1612 * @cfg: physical link configs.
1614 * Topology context contains a list of supported HW formats (configs) and
1615 * a default format ID for the physical link. This function will use this
1616 * default ID to choose the HW format to set the link's DAI format for init.
1618 static void set_link_hw_format(struct snd_soc_dai_link *link,
1619 struct snd_soc_tplg_link_config *cfg)
1621 struct snd_soc_tplg_hw_config *hw_config;
1622 unsigned char bclk_provider, fsync_provider;
1623 unsigned char invert_bclk, invert_fsync;
1626 for (i = 0; i < le32_to_cpu(cfg->num_hw_configs); i++) {
1627 hw_config = &cfg->hw_config[i];
1628 if (hw_config->id != cfg->default_hw_config_id)
1631 link->dai_fmt = le32_to_cpu(hw_config->fmt) &
1632 SND_SOC_DAIFMT_FORMAT_MASK;
1635 switch (hw_config->clock_gated) {
1636 case SND_SOC_TPLG_DAI_CLK_GATE_GATED:
1637 link->dai_fmt |= SND_SOC_DAIFMT_GATED;
1640 case SND_SOC_TPLG_DAI_CLK_GATE_CONT:
1641 link->dai_fmt |= SND_SOC_DAIFMT_CONT;
1645 /* ignore the value */
1649 /* clock signal polarity */
1650 invert_bclk = hw_config->invert_bclk;
1651 invert_fsync = hw_config->invert_fsync;
1652 if (!invert_bclk && !invert_fsync)
1653 link->dai_fmt |= SND_SOC_DAIFMT_NB_NF;
1654 else if (!invert_bclk && invert_fsync)
1655 link->dai_fmt |= SND_SOC_DAIFMT_NB_IF;
1656 else if (invert_bclk && !invert_fsync)
1657 link->dai_fmt |= SND_SOC_DAIFMT_IB_NF;
1659 link->dai_fmt |= SND_SOC_DAIFMT_IB_IF;
1662 bclk_provider = (hw_config->bclk_provider ==
1663 SND_SOC_TPLG_BCLK_CP);
1664 fsync_provider = (hw_config->fsync_provider ==
1665 SND_SOC_TPLG_FSYNC_CP);
1666 if (bclk_provider && fsync_provider)
1667 link->dai_fmt |= SND_SOC_DAIFMT_CBP_CFP;
1668 else if (!bclk_provider && fsync_provider)
1669 link->dai_fmt |= SND_SOC_DAIFMT_CBC_CFP;
1670 else if (bclk_provider && !fsync_provider)
1671 link->dai_fmt |= SND_SOC_DAIFMT_CBP_CFC;
1673 link->dai_fmt |= SND_SOC_DAIFMT_CBC_CFC;
1678 * snd_soc_find_dai_link - Find a DAI link
1681 * @id: DAI link ID to match
1682 * @name: DAI link name to match, optional
1683 * @stream_name: DAI link stream name to match, optional
1685 * This function will search all existing DAI links of the soc card to
1686 * find the link of the same ID. Since DAI links may not have their
1687 * unique ID, so name and stream name should also match if being
1690 * Return: pointer of DAI link, or NULL if not found.
1692 static struct snd_soc_dai_link *snd_soc_find_dai_link(struct snd_soc_card *card,
1693 int id, const char *name,
1694 const char *stream_name)
1696 struct snd_soc_pcm_runtime *rtd;
1698 for_each_card_rtds(card, rtd) {
1699 struct snd_soc_dai_link *link = rtd->dai_link;
1704 if (name && (!link->name || !strstr(link->name, name)))
1707 if (stream_name && (!link->stream_name ||
1708 !strstr(link->stream_name, stream_name)))
1717 /* Find and configure an existing physical DAI link */
1718 static int soc_tplg_link_config(struct soc_tplg *tplg,
1719 struct snd_soc_tplg_link_config *cfg)
1721 struct snd_soc_dai_link *link;
1722 const char *name, *stream_name;
1726 len = strnlen(cfg->name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
1727 if (len == SNDRV_CTL_ELEM_ID_NAME_MAXLEN)
1734 len = strnlen(cfg->stream_name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN);
1735 if (len == SNDRV_CTL_ELEM_ID_NAME_MAXLEN)
1738 stream_name = cfg->stream_name;
1742 link = snd_soc_find_dai_link(tplg->comp->card, le32_to_cpu(cfg->id),
1745 dev_err(tplg->dev, "ASoC: physical link %s (id %d) not exist\n",
1751 if (cfg->num_hw_configs)
1752 set_link_hw_format(link, cfg);
1756 set_link_flags(link,
1757 le32_to_cpu(cfg->flag_mask),
1758 le32_to_cpu(cfg->flags));
1760 /* pass control to component driver for optional further init */
1761 ret = soc_tplg_dai_link_load(tplg, link, cfg);
1763 dev_err(tplg->dev, "ASoC: physical link loading failed\n");
1767 /* for unloading it in snd_soc_tplg_component_remove */
1768 link->dobj.index = tplg->index;
1769 link->dobj.type = SND_SOC_DOBJ_BACKEND_LINK;
1771 link->dobj.unload = tplg->ops->link_unload;
1772 list_add(&link->dobj.list, &tplg->comp->dobj_list);
1778 /* Load physical link config elements from the topology context */
1779 static int soc_tplg_link_elems_load(struct soc_tplg *tplg,
1780 struct snd_soc_tplg_hdr *hdr)
1782 struct snd_soc_tplg_link_config *link;
1787 count = le32_to_cpu(hdr->count);
1789 /* check the element size and count */
1790 link = (struct snd_soc_tplg_link_config *)tplg->pos;
1791 size = le32_to_cpu(link->size);
1792 if (size > sizeof(struct snd_soc_tplg_link_config)) {
1793 dev_err(tplg->dev, "ASoC: invalid size %d for physical link elems\n",
1798 if (soc_tplg_check_elem_count(tplg, size, count,
1799 le32_to_cpu(hdr->payload_size),
1800 "physical link config"))
1803 /* config physical DAI links */
1804 for (i = 0; i < count; i++) {
1805 link = (struct snd_soc_tplg_link_config *)tplg->pos;
1806 size = le32_to_cpu(link->size);
1807 if (size != sizeof(*link))
1810 ret = soc_tplg_link_config(tplg, link);
1814 /* offset by version-specific struct size and
1815 * real priv data size
1817 tplg->pos += size + le32_to_cpu(link->priv.size);
1824 * soc_tplg_dai_config - Find and configure an existing physical DAI.
1825 * @tplg: topology context
1826 * @d: physical DAI configs.
1828 * The physical dai should already be registered by the platform driver.
1829 * The platform driver should specify the DAI name and ID for matching.
1831 static int soc_tplg_dai_config(struct soc_tplg *tplg,
1832 struct snd_soc_tplg_dai *d)
1834 struct snd_soc_dai_link_component dai_component;
1835 struct snd_soc_dai *dai;
1836 struct snd_soc_dai_driver *dai_drv;
1837 struct snd_soc_pcm_stream *stream;
1838 struct snd_soc_tplg_stream_caps *caps;
1841 memset(&dai_component, 0, sizeof(dai_component));
1843 dai_component.dai_name = d->dai_name;
1844 dai = snd_soc_find_dai(&dai_component);
1846 dev_err(tplg->dev, "ASoC: physical DAI %s not registered\n",
1851 if (le32_to_cpu(d->dai_id) != dai->id) {
1852 dev_err(tplg->dev, "ASoC: physical DAI %s id mismatch\n",
1857 dai_drv = dai->driver;
1862 stream = &dai_drv->playback;
1863 caps = &d->caps[SND_SOC_TPLG_STREAM_PLAYBACK];
1864 ret = set_stream_info(tplg, stream, caps);
1870 stream = &dai_drv->capture;
1871 caps = &d->caps[SND_SOC_TPLG_STREAM_CAPTURE];
1872 ret = set_stream_info(tplg, stream, caps);
1878 set_dai_flags(dai_drv,
1879 le32_to_cpu(d->flag_mask),
1880 le32_to_cpu(d->flags));
1882 /* pass control to component driver for optional further init */
1883 ret = soc_tplg_dai_load(tplg, dai_drv, NULL, dai);
1885 dev_err(tplg->dev, "ASoC: DAI loading failed\n");
1892 /* load physical DAI elements */
1893 static int soc_tplg_dai_elems_load(struct soc_tplg *tplg,
1894 struct snd_soc_tplg_hdr *hdr)
1899 count = le32_to_cpu(hdr->count);
1901 /* config the existing BE DAIs */
1902 for (i = 0; i < count; i++) {
1903 struct snd_soc_tplg_dai *dai = (struct snd_soc_tplg_dai *)tplg->pos;
1906 if (le32_to_cpu(dai->size) != sizeof(*dai)) {
1907 dev_err(tplg->dev, "ASoC: invalid physical DAI size\n");
1911 ret = soc_tplg_dai_config(tplg, dai);
1913 dev_err(tplg->dev, "ASoC: failed to configure DAI\n");
1917 tplg->pos += (sizeof(*dai) + le32_to_cpu(dai->priv.size));
1920 dev_dbg(tplg->dev, "ASoC: Configure %d BE DAIs\n", count);
1924 static int soc_tplg_manifest_load(struct soc_tplg *tplg,
1925 struct snd_soc_tplg_hdr *hdr)
1927 struct snd_soc_tplg_manifest *manifest;
1930 manifest = (struct snd_soc_tplg_manifest *)tplg->pos;
1932 /* check ABI version by size, create a new manifest if abi not match */
1933 if (le32_to_cpu(manifest->size) != sizeof(*manifest))
1936 /* pass control to component driver for optional further init */
1937 if (tplg->ops && tplg->ops->manifest)
1938 ret = tplg->ops->manifest(tplg->comp, tplg->index, manifest);
1943 /* validate header magic, size and type */
1944 static int soc_tplg_valid_header(struct soc_tplg *tplg,
1945 struct snd_soc_tplg_hdr *hdr)
1947 if (le32_to_cpu(hdr->size) != sizeof(*hdr)) {
1949 "ASoC: invalid header size for type %d at offset 0x%lx size 0x%zx.\n",
1950 le32_to_cpu(hdr->type), soc_tplg_get_hdr_offset(tplg),
1955 if (soc_tplg_get_hdr_offset(tplg) + le32_to_cpu(hdr->payload_size) >= tplg->fw->size) {
1957 "ASoC: invalid header of type %d at offset %ld payload_size %d\n",
1958 le32_to_cpu(hdr->type), soc_tplg_get_hdr_offset(tplg),
1963 /* big endian firmware objects not supported atm */
1964 if (le32_to_cpu(hdr->magic) == SOC_TPLG_MAGIC_BIG_ENDIAN) {
1966 "ASoC: pass %d big endian not supported header got %x at offset 0x%lx size 0x%zx.\n",
1967 tplg->pass, hdr->magic,
1968 soc_tplg_get_hdr_offset(tplg), tplg->fw->size);
1972 if (le32_to_cpu(hdr->magic) != SND_SOC_TPLG_MAGIC) {
1974 "ASoC: pass %d does not have a valid header got %x at offset 0x%lx size 0x%zx.\n",
1975 tplg->pass, hdr->magic,
1976 soc_tplg_get_hdr_offset(tplg), tplg->fw->size);
1980 /* Support ABI from version 4 */
1981 if (le32_to_cpu(hdr->abi) > SND_SOC_TPLG_ABI_VERSION ||
1982 le32_to_cpu(hdr->abi) < SND_SOC_TPLG_ABI_VERSION_MIN) {
1984 "ASoC: pass %d invalid ABI version got 0x%x need 0x%x at offset 0x%lx size 0x%zx.\n",
1985 tplg->pass, hdr->abi,
1986 SND_SOC_TPLG_ABI_VERSION, soc_tplg_get_hdr_offset(tplg),
1991 if (hdr->payload_size == 0) {
1992 dev_err(tplg->dev, "ASoC: header has 0 size at offset 0x%lx.\n",
1993 soc_tplg_get_hdr_offset(tplg));
2000 /* check header type and call appropriate handler */
2001 static int soc_tplg_load_header(struct soc_tplg *tplg,
2002 struct snd_soc_tplg_hdr *hdr)
2004 int (*elem_load)(struct soc_tplg *tplg,
2005 struct snd_soc_tplg_hdr *hdr);
2006 unsigned int hdr_pass;
2008 tplg->pos = tplg->hdr_pos + sizeof(struct snd_soc_tplg_hdr);
2010 tplg->index = le32_to_cpu(hdr->index);
2012 switch (le32_to_cpu(hdr->type)) {
2013 case SND_SOC_TPLG_TYPE_MIXER:
2014 case SND_SOC_TPLG_TYPE_ENUM:
2015 case SND_SOC_TPLG_TYPE_BYTES:
2016 hdr_pass = SOC_TPLG_PASS_CONTROL;
2017 elem_load = soc_tplg_kcontrol_elems_load;
2019 case SND_SOC_TPLG_TYPE_DAPM_GRAPH:
2020 hdr_pass = SOC_TPLG_PASS_GRAPH;
2021 elem_load = soc_tplg_dapm_graph_elems_load;
2023 case SND_SOC_TPLG_TYPE_DAPM_WIDGET:
2024 hdr_pass = SOC_TPLG_PASS_WIDGET;
2025 elem_load = soc_tplg_dapm_widget_elems_load;
2027 case SND_SOC_TPLG_TYPE_PCM:
2028 hdr_pass = SOC_TPLG_PASS_PCM_DAI;
2029 elem_load = soc_tplg_pcm_elems_load;
2031 case SND_SOC_TPLG_TYPE_DAI:
2032 hdr_pass = SOC_TPLG_PASS_BE_DAI;
2033 elem_load = soc_tplg_dai_elems_load;
2035 case SND_SOC_TPLG_TYPE_DAI_LINK:
2036 case SND_SOC_TPLG_TYPE_BACKEND_LINK:
2037 /* physical link configurations */
2038 hdr_pass = SOC_TPLG_PASS_LINK;
2039 elem_load = soc_tplg_link_elems_load;
2041 case SND_SOC_TPLG_TYPE_MANIFEST:
2042 hdr_pass = SOC_TPLG_PASS_MANIFEST;
2043 elem_load = soc_tplg_manifest_load;
2046 /* bespoke vendor data object */
2047 hdr_pass = SOC_TPLG_PASS_VENDOR;
2048 elem_load = soc_tplg_vendor_load;
2052 if (tplg->pass == hdr_pass) {
2054 "ASoC: Got 0x%x bytes of type %d version %d vendor %d at pass %d\n",
2055 hdr->payload_size, hdr->type, hdr->version,
2056 hdr->vendor_type, tplg->pass);
2057 return elem_load(tplg, hdr);
2063 /* process the topology file headers */
2064 static int soc_tplg_process_headers(struct soc_tplg *tplg)
2068 /* process the header types from start to end */
2069 for (tplg->pass = SOC_TPLG_PASS_START; tplg->pass <= SOC_TPLG_PASS_END; tplg->pass++) {
2070 struct snd_soc_tplg_hdr *hdr;
2072 tplg->hdr_pos = tplg->fw->data;
2073 hdr = (struct snd_soc_tplg_hdr *)tplg->hdr_pos;
2075 while (!soc_tplg_is_eof(tplg)) {
2077 /* make sure header is valid before loading */
2078 ret = soc_tplg_valid_header(tplg, hdr);
2082 /* load the header object */
2083 ret = soc_tplg_load_header(tplg, hdr);
2085 if (ret != -EPROBE_DEFER) {
2087 "ASoC: topology: could not load header: %d\n",
2093 /* goto next header */
2094 tplg->hdr_pos += le32_to_cpu(hdr->payload_size) +
2095 sizeof(struct snd_soc_tplg_hdr);
2096 hdr = (struct snd_soc_tplg_hdr *)tplg->hdr_pos;
2101 /* signal DAPM we are complete */
2102 ret = soc_tplg_dapm_complete(tplg);
2107 static int soc_tplg_load(struct soc_tplg *tplg)
2111 ret = soc_tplg_process_headers(tplg);
2113 return soc_tplg_complete(tplg);
2118 /* load audio component topology from "firmware" file */
2119 int snd_soc_tplg_component_load(struct snd_soc_component *comp,
2120 const struct snd_soc_tplg_ops *ops, const struct firmware *fw)
2122 struct soc_tplg tplg;
2126 * check if we have sane parameters:
2127 * comp - needs to exist to keep and reference data while parsing
2128 * comp->card - used for setting card related parameters
2129 * comp->card->dev - used for resource management and prints
2130 * fw - we need it, as it is the very thing we parse
2132 if (!comp || !comp->card || !comp->card->dev || !fw)
2135 /* setup parsing context */
2136 memset(&tplg, 0, sizeof(tplg));
2138 tplg.dev = comp->card->dev;
2142 tplg.io_ops = ops->io_ops;
2143 tplg.io_ops_count = ops->io_ops_count;
2144 tplg.bytes_ext_ops = ops->bytes_ext_ops;
2145 tplg.bytes_ext_ops_count = ops->bytes_ext_ops_count;
2148 ret = soc_tplg_load(&tplg);
2149 /* free the created components if fail to load topology */
2151 snd_soc_tplg_component_remove(comp);
2155 EXPORT_SYMBOL_GPL(snd_soc_tplg_component_load);
2157 /* remove dynamic controls from the component driver */
2158 int snd_soc_tplg_component_remove(struct snd_soc_component *comp)
2160 struct snd_soc_dobj *dobj, *next_dobj;
2163 /* process the header types from end to start */
2164 for (pass = SOC_TPLG_PASS_END; pass >= SOC_TPLG_PASS_START; pass--) {
2166 /* remove mixer controls */
2167 list_for_each_entry_safe(dobj, next_dobj, &comp->dobj_list,
2170 switch (dobj->type) {
2171 case SND_SOC_DOBJ_BYTES:
2172 case SND_SOC_DOBJ_ENUM:
2173 case SND_SOC_DOBJ_MIXER:
2174 soc_tplg_remove_kcontrol(comp, dobj, pass);
2176 case SND_SOC_DOBJ_GRAPH:
2177 soc_tplg_remove_route(comp, dobj, pass);
2179 case SND_SOC_DOBJ_WIDGET:
2180 soc_tplg_remove_widget(comp, dobj, pass);
2182 case SND_SOC_DOBJ_PCM:
2183 soc_tplg_remove_dai(comp, dobj, pass);
2185 case SND_SOC_DOBJ_DAI_LINK:
2186 soc_tplg_remove_link(comp, dobj, pass);
2188 case SND_SOC_DOBJ_BACKEND_LINK:
2190 * call link_unload ops if extra
2191 * deinitialization is needed.
2193 remove_backend_link(comp, dobj, pass);
2196 dev_err(comp->dev, "ASoC: invalid component type %d for removal\n",
2203 /* let caller know if FW can be freed when no objects are left */
2204 return !list_empty(&comp->dobj_list);
2206 EXPORT_SYMBOL_GPL(snd_soc_tplg_component_remove);