2 * skl-topology.c - Implements Platform component ALSA controls/widget
5 * Copyright (C) 2014-2015 Intel Corp
6 * Author: Jeeja KP <jeeja.kp@intel.com>
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as version 2, as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
19 #include <linux/slab.h>
20 #include <linux/types.h>
21 #include <linux/firmware.h>
22 #include <sound/soc.h>
23 #include <sound/soc-topology.h>
24 #include <uapi/sound/snd_sst_tokens.h>
25 #include "skl-sst-dsp.h"
26 #include "skl-sst-ipc.h"
27 #include "skl-topology.h"
29 #include "skl-tplg-interface.h"
30 #include "../common/sst-dsp.h"
31 #include "../common/sst-dsp-priv.h"
33 #define SKL_CH_FIXUP_MASK (1 << 0)
34 #define SKL_RATE_FIXUP_MASK (1 << 1)
35 #define SKL_FMT_FIXUP_MASK (1 << 2)
36 #define SKL_IN_DIR_BIT_MASK BIT(0)
37 #define SKL_PIN_COUNT_MASK GENMASK(7, 4)
39 void skl_tplg_d0i3_get(struct skl *skl, enum d0i3_capability caps)
41 struct skl_d0i3_data *d0i3 = &skl->skl_sst->d0i3;
48 case SKL_D0I3_STREAMING:
52 case SKL_D0I3_NON_STREAMING:
53 d0i3->non_streaming++;
58 void skl_tplg_d0i3_put(struct skl *skl, enum d0i3_capability caps)
60 struct skl_d0i3_data *d0i3 = &skl->skl_sst->d0i3;
67 case SKL_D0I3_STREAMING:
71 case SKL_D0I3_NON_STREAMING:
72 d0i3->non_streaming--;
78 * SKL DSP driver modelling uses only few DAPM widgets so for rest we will
79 * ignore. This helpers checks if the SKL driver handles this widget type
81 static int is_skl_dsp_widget_type(struct snd_soc_dapm_widget *w)
84 case snd_soc_dapm_dai_link:
85 case snd_soc_dapm_dai_in:
86 case snd_soc_dapm_aif_in:
87 case snd_soc_dapm_aif_out:
88 case snd_soc_dapm_dai_out:
89 case snd_soc_dapm_switch:
97 * Each pipelines needs memory to be allocated. Check if we have free memory
98 * from available pool.
100 static bool skl_is_pipe_mem_avail(struct skl *skl,
101 struct skl_module_cfg *mconfig)
103 struct skl_sst *ctx = skl->skl_sst;
105 if (skl->resource.mem + mconfig->pipe->memory_pages >
106 skl->resource.max_mem) {
108 "%s: module_id %d instance %d\n", __func__,
109 mconfig->id.module_id,
110 mconfig->id.instance_id);
112 "exceeds ppl memory available %d mem %d\n",
113 skl->resource.max_mem, skl->resource.mem);
121 * Add the mem to the mem pool. This is freed when pipe is deleted.
122 * Note: DSP does actual memory management we only keep track for complete
125 static void skl_tplg_alloc_pipe_mem(struct skl *skl,
126 struct skl_module_cfg *mconfig)
128 skl->resource.mem += mconfig->pipe->memory_pages;
132 * Pipeline needs needs DSP CPU resources for computation, this is
133 * quantified in MCPS (Million Clocks Per Second) required for module/pipe
135 * Each pipelines needs mcps to be allocated. Check if we have mcps for this
139 static bool skl_is_pipe_mcps_avail(struct skl *skl,
140 struct skl_module_cfg *mconfig)
142 struct skl_sst *ctx = skl->skl_sst;
144 if (skl->resource.mcps + mconfig->mcps > skl->resource.max_mcps) {
146 "%s: module_id %d instance %d\n", __func__,
147 mconfig->id.module_id, mconfig->id.instance_id);
149 "exceeds ppl mcps available %d > mem %d\n",
150 skl->resource.max_mcps, skl->resource.mcps);
157 static void skl_tplg_alloc_pipe_mcps(struct skl *skl,
158 struct skl_module_cfg *mconfig)
160 skl->resource.mcps += mconfig->mcps;
164 * Free the mcps when tearing down
167 skl_tplg_free_pipe_mcps(struct skl *skl, struct skl_module_cfg *mconfig)
169 skl->resource.mcps -= mconfig->mcps;
173 * Free the memory when tearing down
176 skl_tplg_free_pipe_mem(struct skl *skl, struct skl_module_cfg *mconfig)
178 skl->resource.mem -= mconfig->pipe->memory_pages;
182 static void skl_dump_mconfig(struct skl_sst *ctx,
183 struct skl_module_cfg *mcfg)
185 dev_dbg(ctx->dev, "Dumping config\n");
186 dev_dbg(ctx->dev, "Input Format:\n");
187 dev_dbg(ctx->dev, "channels = %d\n", mcfg->in_fmt[0].channels);
188 dev_dbg(ctx->dev, "s_freq = %d\n", mcfg->in_fmt[0].s_freq);
189 dev_dbg(ctx->dev, "ch_cfg = %d\n", mcfg->in_fmt[0].ch_cfg);
190 dev_dbg(ctx->dev, "valid bit depth = %d\n", mcfg->in_fmt[0].valid_bit_depth);
191 dev_dbg(ctx->dev, "Output Format:\n");
192 dev_dbg(ctx->dev, "channels = %d\n", mcfg->out_fmt[0].channels);
193 dev_dbg(ctx->dev, "s_freq = %d\n", mcfg->out_fmt[0].s_freq);
194 dev_dbg(ctx->dev, "valid bit depth = %d\n", mcfg->out_fmt[0].valid_bit_depth);
195 dev_dbg(ctx->dev, "ch_cfg = %d\n", mcfg->out_fmt[0].ch_cfg);
198 static void skl_tplg_update_chmap(struct skl_module_fmt *fmt, int chs)
200 int slot_map = 0xFFFFFFFF;
204 for (i = 0; i < chs; i++) {
206 * For 2 channels with starting slot as 0, slot map will
207 * look like 0xFFFFFF10.
209 slot_map &= (~(0xF << (4 * i)) | (start_slot << (4 * i)));
212 fmt->ch_map = slot_map;
215 static void skl_tplg_update_params(struct skl_module_fmt *fmt,
216 struct skl_pipe_params *params, int fixup)
218 if (fixup & SKL_RATE_FIXUP_MASK)
219 fmt->s_freq = params->s_freq;
220 if (fixup & SKL_CH_FIXUP_MASK) {
221 fmt->channels = params->ch;
222 skl_tplg_update_chmap(fmt, fmt->channels);
224 if (fixup & SKL_FMT_FIXUP_MASK) {
225 fmt->valid_bit_depth = skl_get_bit_depth(params->s_fmt);
228 * 16 bit is 16 bit container whereas 24 bit is in 32 bit
229 * container so update bit depth accordingly
231 switch (fmt->valid_bit_depth) {
232 case SKL_DEPTH_16BIT:
233 fmt->bit_depth = fmt->valid_bit_depth;
237 fmt->bit_depth = SKL_DEPTH_32BIT;
245 * A pipeline may have modules which impact the pcm parameters, like SRC,
246 * channel converter, format converter.
247 * We need to calculate the output params by applying the 'fixup'
248 * Topology will tell driver which type of fixup is to be applied by
249 * supplying the fixup mask, so based on that we calculate the output
251 * Now In FE the pcm hw_params is source/target format. Same is applicable
252 * for BE with its hw_params invoked.
253 * here based on FE, BE pipeline and direction we calculate the input and
254 * outfix and then apply that for a module
256 static void skl_tplg_update_params_fixup(struct skl_module_cfg *m_cfg,
257 struct skl_pipe_params *params, bool is_fe)
259 int in_fixup, out_fixup;
260 struct skl_module_fmt *in_fmt, *out_fmt;
262 /* Fixups will be applied to pin 0 only */
263 in_fmt = &m_cfg->in_fmt[0];
264 out_fmt = &m_cfg->out_fmt[0];
266 if (params->stream == SNDRV_PCM_STREAM_PLAYBACK) {
268 in_fixup = m_cfg->params_fixup;
269 out_fixup = (~m_cfg->converter) &
272 out_fixup = m_cfg->params_fixup;
273 in_fixup = (~m_cfg->converter) &
278 out_fixup = m_cfg->params_fixup;
279 in_fixup = (~m_cfg->converter) &
282 in_fixup = m_cfg->params_fixup;
283 out_fixup = (~m_cfg->converter) &
288 skl_tplg_update_params(in_fmt, params, in_fixup);
289 skl_tplg_update_params(out_fmt, params, out_fixup);
293 * A module needs input and output buffers, which are dependent upon pcm
294 * params, so once we have calculate params, we need buffer calculation as
297 static void skl_tplg_update_buffer_size(struct skl_sst *ctx,
298 struct skl_module_cfg *mcfg)
301 struct skl_module_fmt *in_fmt, *out_fmt;
303 /* Since fixups is applied to pin 0 only, ibs, obs needs
304 * change for pin 0 only
306 in_fmt = &mcfg->in_fmt[0];
307 out_fmt = &mcfg->out_fmt[0];
309 if (mcfg->m_type == SKL_MODULE_TYPE_SRCINT)
312 mcfg->ibs = DIV_ROUND_UP(in_fmt->s_freq, 1000) *
313 in_fmt->channels * (in_fmt->bit_depth >> 3) *
316 mcfg->obs = DIV_ROUND_UP(out_fmt->s_freq, 1000) *
317 out_fmt->channels * (out_fmt->bit_depth >> 3) *
321 static u8 skl_tplg_be_dev_type(int dev_type)
327 ret = NHLT_DEVICE_BT;
330 case SKL_DEVICE_DMIC:
331 ret = NHLT_DEVICE_DMIC;
335 ret = NHLT_DEVICE_I2S;
339 ret = NHLT_DEVICE_INVALID;
346 static int skl_tplg_update_be_blob(struct snd_soc_dapm_widget *w,
349 struct skl_module_cfg *m_cfg = w->priv;
351 u32 ch, s_freq, s_fmt;
352 struct nhlt_specific_cfg *cfg;
353 struct skl *skl = get_skl_ctx(ctx->dev);
354 u8 dev_type = skl_tplg_be_dev_type(m_cfg->dev_type);
356 /* check if we already have blob */
357 if (m_cfg->formats_config.caps_size > 0)
360 dev_dbg(ctx->dev, "Applying default cfg blob\n");
361 switch (m_cfg->dev_type) {
362 case SKL_DEVICE_DMIC:
363 link_type = NHLT_LINK_DMIC;
364 dir = SNDRV_PCM_STREAM_CAPTURE;
365 s_freq = m_cfg->in_fmt[0].s_freq;
366 s_fmt = m_cfg->in_fmt[0].bit_depth;
367 ch = m_cfg->in_fmt[0].channels;
371 link_type = NHLT_LINK_SSP;
372 if (m_cfg->hw_conn_type == SKL_CONN_SOURCE) {
373 dir = SNDRV_PCM_STREAM_PLAYBACK;
374 s_freq = m_cfg->out_fmt[0].s_freq;
375 s_fmt = m_cfg->out_fmt[0].bit_depth;
376 ch = m_cfg->out_fmt[0].channels;
378 dir = SNDRV_PCM_STREAM_CAPTURE;
379 s_freq = m_cfg->in_fmt[0].s_freq;
380 s_fmt = m_cfg->in_fmt[0].bit_depth;
381 ch = m_cfg->in_fmt[0].channels;
389 /* update the blob based on virtual bus_id and default params */
390 cfg = skl_get_ep_blob(skl, m_cfg->vbus_id, link_type,
391 s_fmt, ch, s_freq, dir, dev_type);
393 m_cfg->formats_config.caps_size = cfg->size;
394 m_cfg->formats_config.caps = (u32 *) &cfg->caps;
396 dev_err(ctx->dev, "Blob NULL for id %x type %d dirn %d\n",
397 m_cfg->vbus_id, link_type, dir);
398 dev_err(ctx->dev, "PCM: ch %d, freq %d, fmt %d\n",
406 static void skl_tplg_update_module_params(struct snd_soc_dapm_widget *w,
409 struct skl_module_cfg *m_cfg = w->priv;
410 struct skl_pipe_params *params = m_cfg->pipe->p_params;
411 int p_conn_type = m_cfg->pipe->conn_type;
414 if (!m_cfg->params_fixup)
417 dev_dbg(ctx->dev, "Mconfig for widget=%s BEFORE updation\n",
420 skl_dump_mconfig(ctx, m_cfg);
422 if (p_conn_type == SKL_PIPE_CONN_TYPE_FE)
427 skl_tplg_update_params_fixup(m_cfg, params, is_fe);
428 skl_tplg_update_buffer_size(ctx, m_cfg);
430 dev_dbg(ctx->dev, "Mconfig for widget=%s AFTER updation\n",
433 skl_dump_mconfig(ctx, m_cfg);
437 * some modules can have multiple params set from user control and
438 * need to be set after module is initialized. If set_param flag is
439 * set module params will be done after module is initialised.
441 static int skl_tplg_set_module_params(struct snd_soc_dapm_widget *w,
445 struct skl_module_cfg *mconfig = w->priv;
446 const struct snd_kcontrol_new *k;
447 struct soc_bytes_ext *sb;
448 struct skl_algo_data *bc;
449 struct skl_specific_cfg *sp_cfg;
451 if (mconfig->formats_config.caps_size > 0 &&
452 mconfig->formats_config.set_params == SKL_PARAM_SET) {
453 sp_cfg = &mconfig->formats_config;
454 ret = skl_set_module_params(ctx, sp_cfg->caps,
456 sp_cfg->param_id, mconfig);
461 for (i = 0; i < w->num_kcontrols; i++) {
462 k = &w->kcontrol_news[i];
463 if (k->access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK) {
464 sb = (void *) k->private_value;
465 bc = (struct skl_algo_data *)sb->dobj.private;
467 if (bc->set_params == SKL_PARAM_SET) {
468 ret = skl_set_module_params(ctx,
469 (u32 *)bc->params, bc->size,
470 bc->param_id, mconfig);
481 * some module param can set from user control and this is required as
482 * when module is initailzed. if module param is required in init it is
483 * identifed by set_param flag. if set_param flag is not set, then this
484 * parameter needs to set as part of module init.
486 static int skl_tplg_set_module_init_data(struct snd_soc_dapm_widget *w)
488 const struct snd_kcontrol_new *k;
489 struct soc_bytes_ext *sb;
490 struct skl_algo_data *bc;
491 struct skl_module_cfg *mconfig = w->priv;
494 for (i = 0; i < w->num_kcontrols; i++) {
495 k = &w->kcontrol_news[i];
496 if (k->access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK) {
497 sb = (struct soc_bytes_ext *)k->private_value;
498 bc = (struct skl_algo_data *)sb->dobj.private;
500 if (bc->set_params != SKL_PARAM_INIT)
503 mconfig->formats_config.caps = (u32 *)bc->params;
504 mconfig->formats_config.caps_size = bc->size;
513 static int skl_tplg_module_prepare(struct skl_sst *ctx, struct skl_pipe *pipe,
514 struct snd_soc_dapm_widget *w, struct skl_module_cfg *mcfg)
516 switch (mcfg->dev_type) {
517 case SKL_DEVICE_HDAHOST:
518 return skl_pcm_host_dma_prepare(ctx->dev, pipe->p_params);
520 case SKL_DEVICE_HDALINK:
521 return skl_pcm_link_dma_prepare(ctx->dev, pipe->p_params);
528 * Inside a pipe instance, we can have various modules. These modules need
529 * to instantiated in DSP by invoking INIT_MODULE IPC, which is achieved by
530 * skl_init_module() routine, so invoke that for all modules in a pipeline
533 skl_tplg_init_pipe_modules(struct skl *skl, struct skl_pipe *pipe)
535 struct skl_pipe_module *w_module;
536 struct snd_soc_dapm_widget *w;
537 struct skl_module_cfg *mconfig;
538 struct skl_sst *ctx = skl->skl_sst;
541 list_for_each_entry(w_module, &pipe->w_list, node) {
546 /* check if module ids are populated */
547 if (mconfig->id.module_id < 0) {
548 dev_err(skl->skl_sst->dev,
549 "module %pUL id not populated\n",
550 (uuid_le *)mconfig->guid);
554 /* check resource available */
555 if (!skl_is_pipe_mcps_avail(skl, mconfig))
558 if (mconfig->is_loadable && ctx->dsp->fw_ops.load_mod) {
559 ret = ctx->dsp->fw_ops.load_mod(ctx->dsp,
560 mconfig->id.module_id, mconfig->guid);
564 mconfig->m_state = SKL_MODULE_LOADED;
567 /* prepare the DMA if the module is gateway cpr */
568 ret = skl_tplg_module_prepare(ctx, pipe, w, mconfig);
572 /* update blob if blob is null for be with default value */
573 skl_tplg_update_be_blob(w, ctx);
576 * apply fix/conversion to module params based on
579 skl_tplg_update_module_params(w, ctx);
580 uuid_mod = (uuid_le *)mconfig->guid;
581 mconfig->id.pvt_id = skl_get_pvt_id(ctx, uuid_mod,
582 mconfig->id.instance_id);
583 if (mconfig->id.pvt_id < 0)
585 skl_tplg_set_module_init_data(w);
586 ret = skl_init_module(ctx, mconfig);
588 skl_put_pvt_id(ctx, uuid_mod, &mconfig->id.pvt_id);
591 skl_tplg_alloc_pipe_mcps(skl, mconfig);
592 ret = skl_tplg_set_module_params(w, ctx);
600 static int skl_tplg_unload_pipe_modules(struct skl_sst *ctx,
601 struct skl_pipe *pipe)
604 struct skl_pipe_module *w_module = NULL;
605 struct skl_module_cfg *mconfig = NULL;
607 list_for_each_entry(w_module, &pipe->w_list, node) {
609 mconfig = w_module->w->priv;
610 uuid_mod = (uuid_le *)mconfig->guid;
612 if (mconfig->is_loadable && ctx->dsp->fw_ops.unload_mod &&
613 mconfig->m_state > SKL_MODULE_UNINIT) {
614 ret = ctx->dsp->fw_ops.unload_mod(ctx->dsp,
615 mconfig->id.module_id);
619 skl_put_pvt_id(ctx, uuid_mod, &mconfig->id.pvt_id);
622 /* no modules to unload in this path, so return */
627 * Mixer module represents a pipeline. So in the Pre-PMU event of mixer we
628 * need create the pipeline. So we do following:
629 * - check the resources
630 * - Create the pipeline
631 * - Initialize the modules in pipeline
632 * - finally bind all modules together
634 static int skl_tplg_mixer_dapm_pre_pmu_event(struct snd_soc_dapm_widget *w,
638 struct skl_module_cfg *mconfig = w->priv;
639 struct skl_pipe_module *w_module;
640 struct skl_pipe *s_pipe = mconfig->pipe;
641 struct skl_module_cfg *src_module = NULL, *dst_module, *module;
642 struct skl_sst *ctx = skl->skl_sst;
643 struct skl_module_deferred_bind *modules;
645 /* check resource available */
646 if (!skl_is_pipe_mcps_avail(skl, mconfig))
649 if (!skl_is_pipe_mem_avail(skl, mconfig))
653 * Create a list of modules for pipe.
654 * This list contains modules from source to sink
656 ret = skl_create_pipeline(ctx, mconfig->pipe);
660 skl_tplg_alloc_pipe_mem(skl, mconfig);
661 skl_tplg_alloc_pipe_mcps(skl, mconfig);
663 /* Init all pipe modules from source to sink */
664 ret = skl_tplg_init_pipe_modules(skl, s_pipe);
668 /* Bind modules from source to sink */
669 list_for_each_entry(w_module, &s_pipe->w_list, node) {
670 dst_module = w_module->w->priv;
672 if (src_module == NULL) {
673 src_module = dst_module;
677 ret = skl_bind_modules(ctx, src_module, dst_module);
681 src_module = dst_module;
685 * When the destination module is initialized, check for these modules
686 * in deferred bind list. If found, bind them.
688 list_for_each_entry(w_module, &s_pipe->w_list, node) {
689 if (list_empty(&skl->bind_list))
692 list_for_each_entry(modules, &skl->bind_list, node) {
693 module = w_module->w->priv;
694 if (modules->dst == module)
695 skl_bind_modules(ctx, modules->src,
703 static int skl_fill_sink_instance_id(struct skl_sst *ctx, u32 *params,
704 int size, struct skl_module_cfg *mcfg)
708 if (mcfg->m_type == SKL_MODULE_TYPE_KPB) {
709 struct skl_kpb_params *kpb_params =
710 (struct skl_kpb_params *)params;
711 struct skl_mod_inst_map *inst = kpb_params->map;
713 for (i = 0; i < kpb_params->num_modules; i++) {
714 pvt_id = skl_get_pvt_instance_id_map(ctx, inst->mod_id,
719 inst->inst_id = pvt_id;
727 * Some modules require params to be set after the module is bound to
728 * all pins connected.
730 * The module provider initializes set_param flag for such modules and we
731 * send params after binding
733 static int skl_tplg_set_module_bind_params(struct snd_soc_dapm_widget *w,
734 struct skl_module_cfg *mcfg, struct skl_sst *ctx)
737 struct skl_module_cfg *mconfig = w->priv;
738 const struct snd_kcontrol_new *k;
739 struct soc_bytes_ext *sb;
740 struct skl_algo_data *bc;
741 struct skl_specific_cfg *sp_cfg;
745 * check all out/in pins are in bind state.
746 * if so set the module param
748 for (i = 0; i < mcfg->max_out_queue; i++) {
749 if (mcfg->m_out_pin[i].pin_state != SKL_PIN_BIND_DONE)
753 for (i = 0; i < mcfg->max_in_queue; i++) {
754 if (mcfg->m_in_pin[i].pin_state != SKL_PIN_BIND_DONE)
758 if (mconfig->formats_config.caps_size > 0 &&
759 mconfig->formats_config.set_params == SKL_PARAM_BIND) {
760 sp_cfg = &mconfig->formats_config;
761 ret = skl_set_module_params(ctx, sp_cfg->caps,
763 sp_cfg->param_id, mconfig);
768 for (i = 0; i < w->num_kcontrols; i++) {
769 k = &w->kcontrol_news[i];
770 if (k->access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK) {
771 sb = (void *) k->private_value;
772 bc = (struct skl_algo_data *)sb->dobj.private;
774 if (bc->set_params == SKL_PARAM_BIND) {
775 params = kzalloc(bc->max, GFP_KERNEL);
779 memcpy(params, bc->params, bc->max);
780 skl_fill_sink_instance_id(ctx, params, bc->max,
783 ret = skl_set_module_params(ctx, params,
784 bc->max, bc->param_id, mconfig);
797 static int skl_tplg_module_add_deferred_bind(struct skl *skl,
798 struct skl_module_cfg *src, struct skl_module_cfg *dst)
800 struct skl_module_deferred_bind *m_list, *modules;
803 /* only supported for module with static pin connection */
804 for (i = 0; i < dst->max_in_queue; i++) {
805 struct skl_module_pin *pin = &dst->m_in_pin[i];
810 if ((pin->id.module_id == src->id.module_id) &&
811 (pin->id.instance_id == src->id.instance_id)) {
813 if (!list_empty(&skl->bind_list)) {
814 list_for_each_entry(modules, &skl->bind_list, node) {
815 if (modules->src == src && modules->dst == dst)
820 m_list = kzalloc(sizeof(*m_list), GFP_KERNEL);
827 list_add(&m_list->node, &skl->bind_list);
834 static int skl_tplg_bind_sinks(struct snd_soc_dapm_widget *w,
836 struct snd_soc_dapm_widget *src_w,
837 struct skl_module_cfg *src_mconfig)
839 struct snd_soc_dapm_path *p;
840 struct snd_soc_dapm_widget *sink = NULL, *next_sink = NULL;
841 struct skl_module_cfg *sink_mconfig;
842 struct skl_sst *ctx = skl->skl_sst;
845 snd_soc_dapm_widget_for_each_sink_path(w, p) {
849 dev_dbg(ctx->dev, "%s: src widget=%s\n", __func__, w->name);
850 dev_dbg(ctx->dev, "%s: sink widget=%s\n", __func__, p->sink->name);
854 if (!is_skl_dsp_widget_type(p->sink))
855 return skl_tplg_bind_sinks(p->sink, skl, src_w, src_mconfig);
858 * here we will check widgets in sink pipelines, so that
859 * can be any widgets type and we are only interested if
860 * they are ones used for SKL so check that first
862 if ((p->sink->priv != NULL) &&
863 is_skl_dsp_widget_type(p->sink)) {
866 sink_mconfig = sink->priv;
869 * Modules other than PGA leaf can be connected
870 * directly or via switch to a module in another
871 * pipeline. EX: reference path
872 * when the path is enabled, the dst module that needs
873 * to be bound may not be initialized. if the module is
874 * not initialized, add these modules in the deferred
875 * bind list and when the dst module is initialised,
876 * bind this module to the dst_module in deferred list.
878 if (((src_mconfig->m_state == SKL_MODULE_INIT_DONE)
879 && (sink_mconfig->m_state == SKL_MODULE_UNINIT))) {
881 ret = skl_tplg_module_add_deferred_bind(skl,
882 src_mconfig, sink_mconfig);
890 if (src_mconfig->m_state == SKL_MODULE_UNINIT ||
891 sink_mconfig->m_state == SKL_MODULE_UNINIT)
894 /* Bind source to sink, mixin is always source */
895 ret = skl_bind_modules(ctx, src_mconfig, sink_mconfig);
899 /* set module params after bind */
900 skl_tplg_set_module_bind_params(src_w, src_mconfig, ctx);
901 skl_tplg_set_module_bind_params(sink, sink_mconfig, ctx);
903 /* Start sinks pipe first */
904 if (sink_mconfig->pipe->state != SKL_PIPE_STARTED) {
905 if (sink_mconfig->pipe->conn_type !=
906 SKL_PIPE_CONN_TYPE_FE)
907 ret = skl_run_pipe(ctx,
916 return skl_tplg_bind_sinks(next_sink, skl, src_w, src_mconfig);
922 * A PGA represents a module in a pipeline. So in the Pre-PMU event of PGA
923 * we need to do following:
924 * - Bind to sink pipeline
925 * Since the sink pipes can be running and we don't get mixer event on
926 * connect for already running mixer, we need to find the sink pipes
927 * here and bind to them. This way dynamic connect works.
928 * - Start sink pipeline, if not running
929 * - Then run current pipe
931 static int skl_tplg_pga_dapm_pre_pmu_event(struct snd_soc_dapm_widget *w,
934 struct skl_module_cfg *src_mconfig;
935 struct skl_sst *ctx = skl->skl_sst;
938 src_mconfig = w->priv;
941 * find which sink it is connected to, bind with the sink,
942 * if sink is not started, start sink pipe first, then start
945 ret = skl_tplg_bind_sinks(w, skl, w, src_mconfig);
949 /* Start source pipe last after starting all sinks */
950 if (src_mconfig->pipe->conn_type != SKL_PIPE_CONN_TYPE_FE)
951 return skl_run_pipe(ctx, src_mconfig->pipe);
956 static struct snd_soc_dapm_widget *skl_get_src_dsp_widget(
957 struct snd_soc_dapm_widget *w, struct skl *skl)
959 struct snd_soc_dapm_path *p;
960 struct snd_soc_dapm_widget *src_w = NULL;
961 struct skl_sst *ctx = skl->skl_sst;
963 snd_soc_dapm_widget_for_each_source_path(w, p) {
968 dev_dbg(ctx->dev, "sink widget=%s\n", w->name);
969 dev_dbg(ctx->dev, "src widget=%s\n", p->source->name);
972 * here we will check widgets in sink pipelines, so that can
973 * be any widgets type and we are only interested if they are
974 * ones used for SKL so check that first
976 if ((p->source->priv != NULL) &&
977 is_skl_dsp_widget_type(p->source)) {
983 return skl_get_src_dsp_widget(src_w, skl);
989 * in the Post-PMU event of mixer we need to do following:
990 * - Check if this pipe is running
992 * - bind this pipeline to its source pipeline
993 * if source pipe is already running, this means it is a dynamic
994 * connection and we need to bind only to that pipe
995 * - start this pipeline
997 static int skl_tplg_mixer_dapm_post_pmu_event(struct snd_soc_dapm_widget *w,
1001 struct snd_soc_dapm_widget *source, *sink;
1002 struct skl_module_cfg *src_mconfig, *sink_mconfig;
1003 struct skl_sst *ctx = skl->skl_sst;
1004 int src_pipe_started = 0;
1007 sink_mconfig = sink->priv;
1010 * If source pipe is already started, that means source is driving
1011 * one more sink before this sink got connected, Since source is
1012 * started, bind this sink to source and start this pipe.
1014 source = skl_get_src_dsp_widget(w, skl);
1015 if (source != NULL) {
1016 src_mconfig = source->priv;
1017 sink_mconfig = sink->priv;
1018 src_pipe_started = 1;
1021 * check pipe state, then no need to bind or start the
1024 if (src_mconfig->pipe->state != SKL_PIPE_STARTED)
1025 src_pipe_started = 0;
1028 if (src_pipe_started) {
1029 ret = skl_bind_modules(ctx, src_mconfig, sink_mconfig);
1033 /* set module params after bind */
1034 skl_tplg_set_module_bind_params(source, src_mconfig, ctx);
1035 skl_tplg_set_module_bind_params(sink, sink_mconfig, ctx);
1037 if (sink_mconfig->pipe->conn_type != SKL_PIPE_CONN_TYPE_FE)
1038 ret = skl_run_pipe(ctx, sink_mconfig->pipe);
1045 * in the Pre-PMD event of mixer we need to do following:
1047 * - find the source connections and remove that from dapm_path_list
1048 * - unbind with source pipelines if still connected
1050 static int skl_tplg_mixer_dapm_pre_pmd_event(struct snd_soc_dapm_widget *w,
1053 struct skl_module_cfg *src_mconfig, *sink_mconfig;
1055 struct skl_sst *ctx = skl->skl_sst;
1057 sink_mconfig = w->priv;
1060 ret = skl_stop_pipe(ctx, sink_mconfig->pipe);
1064 for (i = 0; i < sink_mconfig->max_in_queue; i++) {
1065 if (sink_mconfig->m_in_pin[i].pin_state == SKL_PIN_BIND_DONE) {
1066 src_mconfig = sink_mconfig->m_in_pin[i].tgt_mcfg;
1070 ret = skl_unbind_modules(ctx,
1071 src_mconfig, sink_mconfig);
1079 * in the Post-PMD event of mixer we need to do following:
1080 * - Free the mcps used
1081 * - Free the mem used
1082 * - Unbind the modules within the pipeline
1083 * - Delete the pipeline (modules are not required to be explicitly
1084 * deleted, pipeline delete is enough here
1086 static int skl_tplg_mixer_dapm_post_pmd_event(struct snd_soc_dapm_widget *w,
1089 struct skl_module_cfg *mconfig = w->priv;
1090 struct skl_pipe_module *w_module;
1091 struct skl_module_cfg *src_module = NULL, *dst_module;
1092 struct skl_sst *ctx = skl->skl_sst;
1093 struct skl_pipe *s_pipe = mconfig->pipe;
1094 struct skl_module_deferred_bind *modules, *tmp;
1096 if (s_pipe->state == SKL_PIPE_INVALID)
1099 skl_tplg_free_pipe_mcps(skl, mconfig);
1100 skl_tplg_free_pipe_mem(skl, mconfig);
1102 list_for_each_entry(w_module, &s_pipe->w_list, node) {
1103 if (list_empty(&skl->bind_list))
1106 src_module = w_module->w->priv;
1108 list_for_each_entry_safe(modules, tmp, &skl->bind_list, node) {
1110 * When the destination module is deleted, Unbind the
1111 * modules from deferred bind list.
1113 if (modules->dst == src_module) {
1114 skl_unbind_modules(ctx, modules->src,
1119 * When the source module is deleted, remove this entry
1120 * from the deferred bind list.
1122 if (modules->src == src_module) {
1123 list_del(&modules->node);
1124 modules->src = NULL;
1125 modules->dst = NULL;
1131 list_for_each_entry(w_module, &s_pipe->w_list, node) {
1132 dst_module = w_module->w->priv;
1134 if (mconfig->m_state >= SKL_MODULE_INIT_DONE)
1135 skl_tplg_free_pipe_mcps(skl, dst_module);
1136 if (src_module == NULL) {
1137 src_module = dst_module;
1141 skl_unbind_modules(ctx, src_module, dst_module);
1142 src_module = dst_module;
1145 skl_delete_pipe(ctx, mconfig->pipe);
1147 list_for_each_entry(w_module, &s_pipe->w_list, node) {
1148 src_module = w_module->w->priv;
1149 src_module->m_state = SKL_MODULE_UNINIT;
1152 return skl_tplg_unload_pipe_modules(ctx, s_pipe);
1156 * in the Post-PMD event of PGA we need to do following:
1157 * - Free the mcps used
1158 * - Stop the pipeline
1159 * - In source pipe is connected, unbind with source pipelines
1161 static int skl_tplg_pga_dapm_post_pmd_event(struct snd_soc_dapm_widget *w,
1164 struct skl_module_cfg *src_mconfig, *sink_mconfig;
1166 struct skl_sst *ctx = skl->skl_sst;
1168 src_mconfig = w->priv;
1170 /* Stop the pipe since this is a mixin module */
1171 ret = skl_stop_pipe(ctx, src_mconfig->pipe);
1175 for (i = 0; i < src_mconfig->max_out_queue; i++) {
1176 if (src_mconfig->m_out_pin[i].pin_state == SKL_PIN_BIND_DONE) {
1177 sink_mconfig = src_mconfig->m_out_pin[i].tgt_mcfg;
1181 * This is a connecter and if path is found that means
1182 * unbind between source and sink has not happened yet
1184 ret = skl_unbind_modules(ctx, src_mconfig,
1193 * In modelling, we assume there will be ONLY one mixer in a pipeline. If a
1194 * second one is required that is created as another pipe entity.
1195 * The mixer is responsible for pipe management and represent a pipeline
1198 static int skl_tplg_mixer_event(struct snd_soc_dapm_widget *w,
1199 struct snd_kcontrol *k, int event)
1201 struct snd_soc_dapm_context *dapm = w->dapm;
1202 struct skl *skl = get_skl_ctx(dapm->dev);
1205 case SND_SOC_DAPM_PRE_PMU:
1206 return skl_tplg_mixer_dapm_pre_pmu_event(w, skl);
1208 case SND_SOC_DAPM_POST_PMU:
1209 return skl_tplg_mixer_dapm_post_pmu_event(w, skl);
1211 case SND_SOC_DAPM_PRE_PMD:
1212 return skl_tplg_mixer_dapm_pre_pmd_event(w, skl);
1214 case SND_SOC_DAPM_POST_PMD:
1215 return skl_tplg_mixer_dapm_post_pmd_event(w, skl);
1222 * In modelling, we assumed rest of the modules in pipeline are PGA. But we
1223 * are interested in last PGA (leaf PGA) in a pipeline to disconnect with
1224 * the sink when it is running (two FE to one BE or one FE to two BE)
1227 static int skl_tplg_pga_event(struct snd_soc_dapm_widget *w,
1228 struct snd_kcontrol *k, int event)
1231 struct snd_soc_dapm_context *dapm = w->dapm;
1232 struct skl *skl = get_skl_ctx(dapm->dev);
1235 case SND_SOC_DAPM_PRE_PMU:
1236 return skl_tplg_pga_dapm_pre_pmu_event(w, skl);
1238 case SND_SOC_DAPM_POST_PMD:
1239 return skl_tplg_pga_dapm_post_pmd_event(w, skl);
1245 static int skl_tplg_tlv_control_get(struct snd_kcontrol *kcontrol,
1246 unsigned int __user *data, unsigned int size)
1248 struct soc_bytes_ext *sb =
1249 (struct soc_bytes_ext *)kcontrol->private_value;
1250 struct skl_algo_data *bc = (struct skl_algo_data *)sb->dobj.private;
1251 struct snd_soc_dapm_widget *w = snd_soc_dapm_kcontrol_widget(kcontrol);
1252 struct skl_module_cfg *mconfig = w->priv;
1253 struct skl *skl = get_skl_ctx(w->dapm->dev);
1256 skl_get_module_params(skl->skl_sst, (u32 *)bc->params,
1257 bc->size, bc->param_id, mconfig);
1259 /* decrement size for TLV header */
1260 size -= 2 * sizeof(u32);
1262 /* check size as we don't want to send kernel data */
1267 if (copy_to_user(data, &bc->param_id, sizeof(u32)))
1269 if (copy_to_user(data + 1, &size, sizeof(u32)))
1271 if (copy_to_user(data + 2, bc->params, size))
1278 #define SKL_PARAM_VENDOR_ID 0xff
1280 static int skl_tplg_tlv_control_set(struct snd_kcontrol *kcontrol,
1281 const unsigned int __user *data, unsigned int size)
1283 struct snd_soc_dapm_widget *w = snd_soc_dapm_kcontrol_widget(kcontrol);
1284 struct skl_module_cfg *mconfig = w->priv;
1285 struct soc_bytes_ext *sb =
1286 (struct soc_bytes_ext *)kcontrol->private_value;
1287 struct skl_algo_data *ac = (struct skl_algo_data *)sb->dobj.private;
1288 struct skl *skl = get_skl_ctx(w->dapm->dev);
1296 * if the param_is is of type Vendor, firmware expects actual
1297 * parameter id and size from the control.
1299 if (ac->param_id == SKL_PARAM_VENDOR_ID) {
1300 if (copy_from_user(ac->params, data, size))
1303 if (copy_from_user(ac->params,
1309 return skl_set_module_params(skl->skl_sst,
1310 (u32 *)ac->params, ac->size,
1311 ac->param_id, mconfig);
1318 * Fill the dma id for host and link. In case of passthrough
1319 * pipeline, this will both host and link in the same
1320 * pipeline, so need to copy the link and host based on dev_type
1322 static void skl_tplg_fill_dma_id(struct skl_module_cfg *mcfg,
1323 struct skl_pipe_params *params)
1325 struct skl_pipe *pipe = mcfg->pipe;
1327 if (pipe->passthru) {
1328 switch (mcfg->dev_type) {
1329 case SKL_DEVICE_HDALINK:
1330 pipe->p_params->link_dma_id = params->link_dma_id;
1331 pipe->p_params->link_index = params->link_index;
1332 pipe->p_params->link_bps = params->link_bps;
1335 case SKL_DEVICE_HDAHOST:
1336 pipe->p_params->host_dma_id = params->host_dma_id;
1337 pipe->p_params->host_bps = params->host_bps;
1343 pipe->p_params->s_fmt = params->s_fmt;
1344 pipe->p_params->ch = params->ch;
1345 pipe->p_params->s_freq = params->s_freq;
1346 pipe->p_params->stream = params->stream;
1347 pipe->p_params->format = params->format;
1350 memcpy(pipe->p_params, params, sizeof(*params));
1355 * The FE params are passed by hw_params of the DAI.
1356 * On hw_params, the params are stored in Gateway module of the FE and we
1357 * need to calculate the format in DSP module configuration, that
1358 * conversion is done here
1360 int skl_tplg_update_pipe_params(struct device *dev,
1361 struct skl_module_cfg *mconfig,
1362 struct skl_pipe_params *params)
1364 struct skl_module_fmt *format = NULL;
1366 skl_tplg_fill_dma_id(mconfig, params);
1368 if (params->stream == SNDRV_PCM_STREAM_PLAYBACK)
1369 format = &mconfig->in_fmt[0];
1371 format = &mconfig->out_fmt[0];
1373 /* set the hw_params */
1374 format->s_freq = params->s_freq;
1375 format->channels = params->ch;
1376 format->valid_bit_depth = skl_get_bit_depth(params->s_fmt);
1379 * 16 bit is 16 bit container whereas 24 bit is in 32 bit
1380 * container so update bit depth accordingly
1382 switch (format->valid_bit_depth) {
1383 case SKL_DEPTH_16BIT:
1384 format->bit_depth = format->valid_bit_depth;
1387 case SKL_DEPTH_24BIT:
1388 case SKL_DEPTH_32BIT:
1389 format->bit_depth = SKL_DEPTH_32BIT;
1393 dev_err(dev, "Invalid bit depth %x for pipe\n",
1394 format->valid_bit_depth);
1398 if (params->stream == SNDRV_PCM_STREAM_PLAYBACK) {
1399 mconfig->ibs = (format->s_freq / 1000) *
1400 (format->channels) *
1401 (format->bit_depth >> 3);
1403 mconfig->obs = (format->s_freq / 1000) *
1404 (format->channels) *
1405 (format->bit_depth >> 3);
1412 * Query the module config for the FE DAI
1413 * This is used to find the hw_params set for that DAI and apply to FE
1416 struct skl_module_cfg *
1417 skl_tplg_fe_get_cpr_module(struct snd_soc_dai *dai, int stream)
1419 struct snd_soc_dapm_widget *w;
1420 struct snd_soc_dapm_path *p = NULL;
1422 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
1423 w = dai->playback_widget;
1424 snd_soc_dapm_widget_for_each_sink_path(w, p) {
1425 if (p->connect && p->sink->power &&
1426 !is_skl_dsp_widget_type(p->sink))
1429 if (p->sink->priv) {
1430 dev_dbg(dai->dev, "set params for %s\n",
1432 return p->sink->priv;
1436 w = dai->capture_widget;
1437 snd_soc_dapm_widget_for_each_source_path(w, p) {
1438 if (p->connect && p->source->power &&
1439 !is_skl_dsp_widget_type(p->source))
1442 if (p->source->priv) {
1443 dev_dbg(dai->dev, "set params for %s\n",
1445 return p->source->priv;
1453 static struct skl_module_cfg *skl_get_mconfig_pb_cpr(
1454 struct snd_soc_dai *dai, struct snd_soc_dapm_widget *w)
1456 struct snd_soc_dapm_path *p;
1457 struct skl_module_cfg *mconfig = NULL;
1459 snd_soc_dapm_widget_for_each_source_path(w, p) {
1460 if (w->endpoints[SND_SOC_DAPM_DIR_OUT] > 0) {
1462 (p->sink->id == snd_soc_dapm_aif_out) &&
1464 mconfig = p->source->priv;
1467 mconfig = skl_get_mconfig_pb_cpr(dai, p->source);
1475 static struct skl_module_cfg *skl_get_mconfig_cap_cpr(
1476 struct snd_soc_dai *dai, struct snd_soc_dapm_widget *w)
1478 struct snd_soc_dapm_path *p;
1479 struct skl_module_cfg *mconfig = NULL;
1481 snd_soc_dapm_widget_for_each_sink_path(w, p) {
1482 if (w->endpoints[SND_SOC_DAPM_DIR_IN] > 0) {
1484 (p->source->id == snd_soc_dapm_aif_in) &&
1486 mconfig = p->sink->priv;
1489 mconfig = skl_get_mconfig_cap_cpr(dai, p->sink);
1497 struct skl_module_cfg *
1498 skl_tplg_be_get_cpr_module(struct snd_soc_dai *dai, int stream)
1500 struct snd_soc_dapm_widget *w;
1501 struct skl_module_cfg *mconfig;
1503 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
1504 w = dai->playback_widget;
1505 mconfig = skl_get_mconfig_pb_cpr(dai, w);
1507 w = dai->capture_widget;
1508 mconfig = skl_get_mconfig_cap_cpr(dai, w);
1513 static u8 skl_tplg_be_link_type(int dev_type)
1519 ret = NHLT_LINK_SSP;
1522 case SKL_DEVICE_DMIC:
1523 ret = NHLT_LINK_DMIC;
1526 case SKL_DEVICE_I2S:
1527 ret = NHLT_LINK_SSP;
1530 case SKL_DEVICE_HDALINK:
1531 ret = NHLT_LINK_HDA;
1535 ret = NHLT_LINK_INVALID;
1543 * Fill the BE gateway parameters
1544 * The BE gateway expects a blob of parameters which are kept in the ACPI
1545 * NHLT blob, so query the blob for interface type (i2s/pdm) and instance.
1546 * The port can have multiple settings so pick based on the PCM
1549 static int skl_tplg_be_fill_pipe_params(struct snd_soc_dai *dai,
1550 struct skl_module_cfg *mconfig,
1551 struct skl_pipe_params *params)
1553 struct nhlt_specific_cfg *cfg;
1554 struct skl *skl = get_skl_ctx(dai->dev);
1555 int link_type = skl_tplg_be_link_type(mconfig->dev_type);
1556 u8 dev_type = skl_tplg_be_dev_type(mconfig->dev_type);
1558 skl_tplg_fill_dma_id(mconfig, params);
1560 if (link_type == NHLT_LINK_HDA)
1563 /* update the blob based on virtual bus_id*/
1564 cfg = skl_get_ep_blob(skl, mconfig->vbus_id, link_type,
1565 params->s_fmt, params->ch,
1566 params->s_freq, params->stream,
1569 mconfig->formats_config.caps_size = cfg->size;
1570 mconfig->formats_config.caps = (u32 *) &cfg->caps;
1572 dev_err(dai->dev, "Blob NULL for id %x type %d dirn %d\n",
1573 mconfig->vbus_id, link_type,
1575 dev_err(dai->dev, "PCM: ch %d, freq %d, fmt %d\n",
1576 params->ch, params->s_freq, params->s_fmt);
1583 static int skl_tplg_be_set_src_pipe_params(struct snd_soc_dai *dai,
1584 struct snd_soc_dapm_widget *w,
1585 struct skl_pipe_params *params)
1587 struct snd_soc_dapm_path *p;
1590 snd_soc_dapm_widget_for_each_source_path(w, p) {
1591 if (p->connect && is_skl_dsp_widget_type(p->source) &&
1594 ret = skl_tplg_be_fill_pipe_params(dai,
1595 p->source->priv, params);
1599 ret = skl_tplg_be_set_src_pipe_params(dai,
1609 static int skl_tplg_be_set_sink_pipe_params(struct snd_soc_dai *dai,
1610 struct snd_soc_dapm_widget *w, struct skl_pipe_params *params)
1612 struct snd_soc_dapm_path *p = NULL;
1615 snd_soc_dapm_widget_for_each_sink_path(w, p) {
1616 if (p->connect && is_skl_dsp_widget_type(p->sink) &&
1619 ret = skl_tplg_be_fill_pipe_params(dai,
1620 p->sink->priv, params);
1624 ret = skl_tplg_be_set_sink_pipe_params(
1625 dai, p->sink, params);
1635 * BE hw_params can be a source parameters (capture) or sink parameters
1636 * (playback). Based on sink and source we need to either find the source
1637 * list or the sink list and set the pipeline parameters
1639 int skl_tplg_be_update_params(struct snd_soc_dai *dai,
1640 struct skl_pipe_params *params)
1642 struct snd_soc_dapm_widget *w;
1644 if (params->stream == SNDRV_PCM_STREAM_PLAYBACK) {
1645 w = dai->playback_widget;
1647 return skl_tplg_be_set_src_pipe_params(dai, w, params);
1650 w = dai->capture_widget;
1652 return skl_tplg_be_set_sink_pipe_params(dai, w, params);
1658 static const struct snd_soc_tplg_widget_events skl_tplg_widget_ops[] = {
1659 {SKL_MIXER_EVENT, skl_tplg_mixer_event},
1660 {SKL_VMIXER_EVENT, skl_tplg_mixer_event},
1661 {SKL_PGA_EVENT, skl_tplg_pga_event},
1664 static const struct snd_soc_tplg_bytes_ext_ops skl_tlv_ops[] = {
1665 {SKL_CONTROL_TYPE_BYTE_TLV, skl_tplg_tlv_control_get,
1666 skl_tplg_tlv_control_set},
1669 static int skl_tplg_fill_pipe_tkn(struct device *dev,
1670 struct skl_pipe *pipe, u32 tkn,
1675 case SKL_TKN_U32_PIPE_CONN_TYPE:
1676 pipe->conn_type = tkn_val;
1679 case SKL_TKN_U32_PIPE_PRIORITY:
1680 pipe->pipe_priority = tkn_val;
1683 case SKL_TKN_U32_PIPE_MEM_PGS:
1684 pipe->memory_pages = tkn_val;
1687 case SKL_TKN_U32_PMODE:
1688 pipe->lp_mode = tkn_val;
1692 dev_err(dev, "Token not handled %d\n", tkn);
1700 * Add pipeline by parsing the relevant tokens
1701 * Return an existing pipe if the pipe already exists.
1703 static int skl_tplg_add_pipe(struct device *dev,
1704 struct skl_module_cfg *mconfig, struct skl *skl,
1705 struct snd_soc_tplg_vendor_value_elem *tkn_elem)
1707 struct skl_pipeline *ppl;
1708 struct skl_pipe *pipe;
1709 struct skl_pipe_params *params;
1711 list_for_each_entry(ppl, &skl->ppl_list, node) {
1712 if (ppl->pipe->ppl_id == tkn_elem->value) {
1713 mconfig->pipe = ppl->pipe;
1718 ppl = devm_kzalloc(dev, sizeof(*ppl), GFP_KERNEL);
1722 pipe = devm_kzalloc(dev, sizeof(*pipe), GFP_KERNEL);
1726 params = devm_kzalloc(dev, sizeof(*params), GFP_KERNEL);
1730 pipe->p_params = params;
1731 pipe->ppl_id = tkn_elem->value;
1732 INIT_LIST_HEAD(&pipe->w_list);
1735 list_add(&ppl->node, &skl->ppl_list);
1737 mconfig->pipe = pipe;
1738 mconfig->pipe->state = SKL_PIPE_INVALID;
1743 static int skl_tplg_fill_pin(struct device *dev, u32 tkn,
1744 struct skl_module_pin *m_pin,
1745 int pin_index, u32 value)
1748 case SKL_TKN_U32_PIN_MOD_ID:
1749 m_pin[pin_index].id.module_id = value;
1752 case SKL_TKN_U32_PIN_INST_ID:
1753 m_pin[pin_index].id.instance_id = value;
1757 dev_err(dev, "%d Not a pin token\n", value);
1765 * Parse for pin config specific tokens to fill up the
1766 * module private data
1768 static int skl_tplg_fill_pins_info(struct device *dev,
1769 struct skl_module_cfg *mconfig,
1770 struct snd_soc_tplg_vendor_value_elem *tkn_elem,
1771 int dir, int pin_count)
1774 struct skl_module_pin *m_pin;
1778 m_pin = mconfig->m_in_pin;
1782 m_pin = mconfig->m_out_pin;
1786 dev_err(dev, "Invalid direction value\n");
1790 ret = skl_tplg_fill_pin(dev, tkn_elem->token,
1791 m_pin, pin_count, tkn_elem->value);
1796 m_pin[pin_count].in_use = false;
1797 m_pin[pin_count].pin_state = SKL_PIN_UNBIND;
1803 * Fill up input/output module config format based
1806 static int skl_tplg_fill_fmt(struct device *dev,
1807 struct skl_module_cfg *mconfig, u32 tkn,
1808 u32 value, u32 dir, u32 pin_count)
1810 struct skl_module_fmt *dst_fmt;
1814 dst_fmt = mconfig->in_fmt;
1815 dst_fmt += pin_count;
1819 dst_fmt = mconfig->out_fmt;
1820 dst_fmt += pin_count;
1824 dev_err(dev, "Invalid direction value\n");
1829 case SKL_TKN_U32_FMT_CH:
1830 dst_fmt->channels = value;
1833 case SKL_TKN_U32_FMT_FREQ:
1834 dst_fmt->s_freq = value;
1837 case SKL_TKN_U32_FMT_BIT_DEPTH:
1838 dst_fmt->bit_depth = value;
1841 case SKL_TKN_U32_FMT_SAMPLE_SIZE:
1842 dst_fmt->valid_bit_depth = value;
1845 case SKL_TKN_U32_FMT_CH_CONFIG:
1846 dst_fmt->ch_cfg = value;
1849 case SKL_TKN_U32_FMT_INTERLEAVE:
1850 dst_fmt->interleaving_style = value;
1853 case SKL_TKN_U32_FMT_SAMPLE_TYPE:
1854 dst_fmt->sample_type = value;
1857 case SKL_TKN_U32_FMT_CH_MAP:
1858 dst_fmt->ch_map = value;
1862 dev_err(dev, "Invalid token %d\n", tkn);
1869 static int skl_tplg_get_uuid(struct device *dev, struct skl_module_cfg *mconfig,
1870 struct snd_soc_tplg_vendor_uuid_elem *uuid_tkn)
1872 if (uuid_tkn->token == SKL_TKN_UUID)
1873 memcpy(&mconfig->guid, &uuid_tkn->uuid, 16);
1875 dev_err(dev, "Not an UUID token tkn %d\n", uuid_tkn->token);
1882 static void skl_tplg_fill_pin_dynamic_val(
1883 struct skl_module_pin *mpin, u32 pin_count, u32 value)
1887 for (i = 0; i < pin_count; i++)
1888 mpin[i].is_dynamic = value;
1892 * Parse tokens to fill up the module private data
1894 static int skl_tplg_get_token(struct device *dev,
1895 struct snd_soc_tplg_vendor_value_elem *tkn_elem,
1896 struct skl *skl, struct skl_module_cfg *mconfig)
1900 static int is_pipe_exists;
1901 static int pin_index, dir;
1903 if (tkn_elem->token > SKL_TKN_MAX)
1906 switch (tkn_elem->token) {
1907 case SKL_TKN_U8_IN_QUEUE_COUNT:
1908 mconfig->max_in_queue = tkn_elem->value;
1909 mconfig->m_in_pin = devm_kzalloc(dev, mconfig->max_in_queue *
1910 sizeof(*mconfig->m_in_pin),
1912 if (!mconfig->m_in_pin)
1917 case SKL_TKN_U8_OUT_QUEUE_COUNT:
1918 mconfig->max_out_queue = tkn_elem->value;
1919 mconfig->m_out_pin = devm_kzalloc(dev, mconfig->max_out_queue *
1920 sizeof(*mconfig->m_out_pin),
1923 if (!mconfig->m_out_pin)
1928 case SKL_TKN_U8_DYN_IN_PIN:
1929 if (!mconfig->m_in_pin)
1932 skl_tplg_fill_pin_dynamic_val(mconfig->m_in_pin,
1933 mconfig->max_in_queue, tkn_elem->value);
1937 case SKL_TKN_U8_DYN_OUT_PIN:
1938 if (!mconfig->m_out_pin)
1941 skl_tplg_fill_pin_dynamic_val(mconfig->m_out_pin,
1942 mconfig->max_out_queue, tkn_elem->value);
1946 case SKL_TKN_U8_TIME_SLOT:
1947 mconfig->time_slot = tkn_elem->value;
1950 case SKL_TKN_U8_CORE_ID:
1951 mconfig->core_id = tkn_elem->value;
1953 case SKL_TKN_U8_MOD_TYPE:
1954 mconfig->m_type = tkn_elem->value;
1957 case SKL_TKN_U8_DEV_TYPE:
1958 mconfig->dev_type = tkn_elem->value;
1961 case SKL_TKN_U8_HW_CONN_TYPE:
1962 mconfig->hw_conn_type = tkn_elem->value;
1965 case SKL_TKN_U16_MOD_INST_ID:
1966 mconfig->id.instance_id =
1970 case SKL_TKN_U32_MEM_PAGES:
1971 mconfig->mem_pages = tkn_elem->value;
1974 case SKL_TKN_U32_MAX_MCPS:
1975 mconfig->mcps = tkn_elem->value;
1978 case SKL_TKN_U32_OBS:
1979 mconfig->obs = tkn_elem->value;
1982 case SKL_TKN_U32_IBS:
1983 mconfig->ibs = tkn_elem->value;
1986 case SKL_TKN_U32_VBUS_ID:
1987 mconfig->vbus_id = tkn_elem->value;
1990 case SKL_TKN_U32_PARAMS_FIXUP:
1991 mconfig->params_fixup = tkn_elem->value;
1994 case SKL_TKN_U32_CONVERTER:
1995 mconfig->converter = tkn_elem->value;
1998 case SKL_TKL_U32_D0I3_CAPS:
1999 mconfig->d0i3_caps = tkn_elem->value;
2002 case SKL_TKN_U32_PIPE_ID:
2003 ret = skl_tplg_add_pipe(dev,
2004 mconfig, skl, tkn_elem);
2007 if (ret == -EEXIST) {
2011 return is_pipe_exists;
2016 case SKL_TKN_U32_PIPE_CONN_TYPE:
2017 case SKL_TKN_U32_PIPE_PRIORITY:
2018 case SKL_TKN_U32_PIPE_MEM_PGS:
2019 case SKL_TKN_U32_PMODE:
2020 if (is_pipe_exists) {
2021 ret = skl_tplg_fill_pipe_tkn(dev, mconfig->pipe,
2022 tkn_elem->token, tkn_elem->value);
2030 * SKL_TKN_U32_DIR_PIN_COUNT token has the value for both
2031 * direction and the pin count. The first four bits represent
2032 * direction and next four the pin count.
2034 case SKL_TKN_U32_DIR_PIN_COUNT:
2035 dir = tkn_elem->value & SKL_IN_DIR_BIT_MASK;
2036 pin_index = (tkn_elem->value &
2037 SKL_PIN_COUNT_MASK) >> 4;
2041 case SKL_TKN_U32_FMT_CH:
2042 case SKL_TKN_U32_FMT_FREQ:
2043 case SKL_TKN_U32_FMT_BIT_DEPTH:
2044 case SKL_TKN_U32_FMT_SAMPLE_SIZE:
2045 case SKL_TKN_U32_FMT_CH_CONFIG:
2046 case SKL_TKN_U32_FMT_INTERLEAVE:
2047 case SKL_TKN_U32_FMT_SAMPLE_TYPE:
2048 case SKL_TKN_U32_FMT_CH_MAP:
2049 ret = skl_tplg_fill_fmt(dev, mconfig, tkn_elem->token,
2050 tkn_elem->value, dir, pin_index);
2057 case SKL_TKN_U32_PIN_MOD_ID:
2058 case SKL_TKN_U32_PIN_INST_ID:
2059 ret = skl_tplg_fill_pins_info(dev,
2060 mconfig, tkn_elem, dir,
2067 case SKL_TKN_U32_CAPS_SIZE:
2068 mconfig->formats_config.caps_size =
2073 case SKL_TKN_U32_PROC_DOMAIN:
2079 case SKL_TKN_U8_IN_PIN_TYPE:
2080 case SKL_TKN_U8_OUT_PIN_TYPE:
2081 case SKL_TKN_U8_CONN_TYPE:
2085 dev_err(dev, "Token %d not handled\n",
2096 * Parse the vendor array for specific tokens to construct
2097 * module private data
2099 static int skl_tplg_get_tokens(struct device *dev,
2100 char *pvt_data, struct skl *skl,
2101 struct skl_module_cfg *mconfig, int block_size)
2103 struct snd_soc_tplg_vendor_array *array;
2104 struct snd_soc_tplg_vendor_value_elem *tkn_elem;
2105 int tkn_count = 0, ret;
2106 int off = 0, tuple_size = 0;
2108 if (block_size <= 0)
2111 while (tuple_size < block_size) {
2112 array = (struct snd_soc_tplg_vendor_array *)(pvt_data + off);
2116 switch (array->type) {
2117 case SND_SOC_TPLG_TUPLE_TYPE_STRING:
2118 dev_warn(dev, "no string tokens expected for skl tplg\n");
2121 case SND_SOC_TPLG_TUPLE_TYPE_UUID:
2122 ret = skl_tplg_get_uuid(dev, mconfig, array->uuid);
2126 tuple_size += sizeof(*array->uuid);
2131 tkn_elem = array->value;
2136 while (tkn_count <= (array->num_elems - 1)) {
2137 ret = skl_tplg_get_token(dev, tkn_elem,
2143 tkn_count = tkn_count + ret;
2147 tuple_size += tkn_count * sizeof(*tkn_elem);
2154 * Every data block is preceded by a descriptor to read the number
2155 * of data blocks, they type of the block and it's size
2157 static int skl_tplg_get_desc_blocks(struct device *dev,
2158 struct snd_soc_tplg_vendor_array *array)
2160 struct snd_soc_tplg_vendor_value_elem *tkn_elem;
2162 tkn_elem = array->value;
2164 switch (tkn_elem->token) {
2165 case SKL_TKN_U8_NUM_BLOCKS:
2166 case SKL_TKN_U8_BLOCK_TYPE:
2167 case SKL_TKN_U16_BLOCK_SIZE:
2168 return tkn_elem->value;
2171 dev_err(dev, "Invalid descriptor token %d\n", tkn_elem->token);
2179 * Parse the private data for the token and corresponding value.
2180 * The private data can have multiple data blocks. So, a data block
2181 * is preceded by a descriptor for number of blocks and a descriptor
2182 * for the type and size of the suceeding data block.
2184 static int skl_tplg_get_pvt_data(struct snd_soc_tplg_dapm_widget *tplg_w,
2185 struct skl *skl, struct device *dev,
2186 struct skl_module_cfg *mconfig)
2188 struct snd_soc_tplg_vendor_array *array;
2189 int num_blocks, block_size = 0, block_type, off = 0;
2193 /* Read the NUM_DATA_BLOCKS descriptor */
2194 array = (struct snd_soc_tplg_vendor_array *)tplg_w->priv.data;
2195 ret = skl_tplg_get_desc_blocks(dev, array);
2201 array = (struct snd_soc_tplg_vendor_array *)(tplg_w->priv.data + off);
2203 /* Read the BLOCK_TYPE and BLOCK_SIZE descriptor */
2204 while (num_blocks > 0) {
2205 ret = skl_tplg_get_desc_blocks(dev, array);
2212 array = (struct snd_soc_tplg_vendor_array *)
2213 (tplg_w->priv.data + off);
2215 ret = skl_tplg_get_desc_blocks(dev, array);
2222 array = (struct snd_soc_tplg_vendor_array *)
2223 (tplg_w->priv.data + off);
2225 data = (tplg_w->priv.data + off);
2227 if (block_type == SKL_TYPE_TUPLE) {
2228 ret = skl_tplg_get_tokens(dev, data,
2229 skl, mconfig, block_size);
2236 if (mconfig->formats_config.caps_size > 0)
2237 memcpy(mconfig->formats_config.caps, data,
2238 mconfig->formats_config.caps_size);
2246 static void skl_clear_pin_config(struct snd_soc_platform *platform,
2247 struct snd_soc_dapm_widget *w)
2250 struct skl_module_cfg *mconfig;
2251 struct skl_pipe *pipe;
2253 if (!strncmp(w->dapm->component->name, platform->component.name,
2254 strlen(platform->component.name))) {
2256 pipe = mconfig->pipe;
2257 for (i = 0; i < mconfig->max_in_queue; i++) {
2258 mconfig->m_in_pin[i].in_use = false;
2259 mconfig->m_in_pin[i].pin_state = SKL_PIN_UNBIND;
2261 for (i = 0; i < mconfig->max_out_queue; i++) {
2262 mconfig->m_out_pin[i].in_use = false;
2263 mconfig->m_out_pin[i].pin_state = SKL_PIN_UNBIND;
2265 pipe->state = SKL_PIPE_INVALID;
2266 mconfig->m_state = SKL_MODULE_UNINIT;
2270 void skl_cleanup_resources(struct skl *skl)
2272 struct skl_sst *ctx = skl->skl_sst;
2273 struct snd_soc_platform *soc_platform = skl->platform;
2274 struct snd_soc_dapm_widget *w;
2275 struct snd_soc_card *card;
2277 if (soc_platform == NULL)
2280 card = soc_platform->component.card;
2281 if (!card || !card->instantiated)
2284 skl->resource.mem = 0;
2285 skl->resource.mcps = 0;
2287 list_for_each_entry(w, &card->widgets, list) {
2288 if (is_skl_dsp_widget_type(w) && (w->priv != NULL))
2289 skl_clear_pin_config(soc_platform, w);
2292 skl_clear_module_cnt(ctx->dsp);
2296 * Topology core widget load callback
2298 * This is used to save the private data for each widget which gives
2299 * information to the driver about module and pipeline parameters which DSP
2300 * FW expects like ids, resource values, formats etc
2302 static int skl_tplg_widget_load(struct snd_soc_component *cmpnt,
2303 struct snd_soc_dapm_widget *w,
2304 struct snd_soc_tplg_dapm_widget *tplg_w)
2307 struct hdac_ext_bus *ebus = snd_soc_component_get_drvdata(cmpnt);
2308 struct skl *skl = ebus_to_skl(ebus);
2309 struct hdac_bus *bus = ebus_to_hbus(ebus);
2310 struct skl_module_cfg *mconfig;
2312 if (!tplg_w->priv.size)
2315 mconfig = devm_kzalloc(bus->dev, sizeof(*mconfig), GFP_KERNEL);
2323 * module binary can be loaded later, so set it to query when
2324 * module is load for a use case
2326 mconfig->id.module_id = -1;
2328 /* Parse private data for tuples */
2329 ret = skl_tplg_get_pvt_data(tplg_w, skl, bus->dev, mconfig);
2333 if (tplg_w->event_type == 0) {
2334 dev_dbg(bus->dev, "ASoC: No event handler required\n");
2338 ret = snd_soc_tplg_widget_bind_event(w, skl_tplg_widget_ops,
2339 ARRAY_SIZE(skl_tplg_widget_ops),
2340 tplg_w->event_type);
2343 dev_err(bus->dev, "%s: No matching event handlers found for %d\n",
2344 __func__, tplg_w->event_type);
2351 static int skl_init_algo_data(struct device *dev, struct soc_bytes_ext *be,
2352 struct snd_soc_tplg_bytes_control *bc)
2354 struct skl_algo_data *ac;
2355 struct skl_dfw_algo_data *dfw_ac =
2356 (struct skl_dfw_algo_data *)bc->priv.data;
2358 ac = devm_kzalloc(dev, sizeof(*ac), GFP_KERNEL);
2362 /* Fill private data */
2363 ac->max = dfw_ac->max;
2364 ac->param_id = dfw_ac->param_id;
2365 ac->set_params = dfw_ac->set_params;
2366 ac->size = dfw_ac->max;
2369 ac->params = (char *) devm_kzalloc(dev, ac->max, GFP_KERNEL);
2373 memcpy(ac->params, dfw_ac->params, ac->max);
2376 be->dobj.private = ac;
2380 static int skl_tplg_control_load(struct snd_soc_component *cmpnt,
2381 struct snd_kcontrol_new *kctl,
2382 struct snd_soc_tplg_ctl_hdr *hdr)
2384 struct soc_bytes_ext *sb;
2385 struct snd_soc_tplg_bytes_control *tplg_bc;
2386 struct hdac_ext_bus *ebus = snd_soc_component_get_drvdata(cmpnt);
2387 struct hdac_bus *bus = ebus_to_hbus(ebus);
2389 switch (hdr->ops.info) {
2390 case SND_SOC_TPLG_CTL_BYTES:
2391 tplg_bc = container_of(hdr,
2392 struct snd_soc_tplg_bytes_control, hdr);
2393 if (kctl->access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK) {
2394 sb = (struct soc_bytes_ext *)kctl->private_value;
2395 if (tplg_bc->priv.size)
2396 return skl_init_algo_data(
2397 bus->dev, sb, tplg_bc);
2402 dev_warn(bus->dev, "Control load not supported %d:%d:%d\n",
2403 hdr->ops.get, hdr->ops.put, hdr->ops.info);
2410 static int skl_tplg_fill_str_mfest_tkn(struct device *dev,
2411 struct snd_soc_tplg_vendor_string_elem *str_elem,
2415 static int ref_count;
2417 switch (str_elem->token) {
2418 case SKL_TKN_STR_LIB_NAME:
2419 if (ref_count > skl->skl_sst->lib_count - 1) {
2424 strncpy(skl->skl_sst->lib_info[ref_count].name,
2426 ARRAY_SIZE(skl->skl_sst->lib_info[ref_count].name));
2432 dev_err(dev, "Not a string token %d\n", str_elem->token);
2439 static int skl_tplg_get_str_tkn(struct device *dev,
2440 struct snd_soc_tplg_vendor_array *array,
2443 int tkn_count = 0, ret;
2444 struct snd_soc_tplg_vendor_string_elem *str_elem;
2446 str_elem = (struct snd_soc_tplg_vendor_string_elem *)array->value;
2447 while (tkn_count < array->num_elems) {
2448 ret = skl_tplg_fill_str_mfest_tkn(dev, str_elem, skl);
2454 tkn_count = tkn_count + ret;
2460 static int skl_tplg_get_int_tkn(struct device *dev,
2461 struct snd_soc_tplg_vendor_value_elem *tkn_elem,
2466 switch (tkn_elem->token) {
2467 case SKL_TKN_U32_LIB_COUNT:
2468 skl->skl_sst->lib_count = tkn_elem->value;
2473 dev_err(dev, "Not a manifest token %d\n", tkn_elem->token);
2481 * Fill the manifest structure by parsing the tokens based on the
2484 static int skl_tplg_get_manifest_tkn(struct device *dev,
2485 char *pvt_data, struct skl *skl,
2488 int tkn_count = 0, ret;
2489 int off = 0, tuple_size = 0;
2490 struct snd_soc_tplg_vendor_array *array;
2491 struct snd_soc_tplg_vendor_value_elem *tkn_elem;
2493 if (block_size <= 0)
2496 while (tuple_size < block_size) {
2497 array = (struct snd_soc_tplg_vendor_array *)(pvt_data + off);
2499 switch (array->type) {
2500 case SND_SOC_TPLG_TUPLE_TYPE_STRING:
2501 ret = skl_tplg_get_str_tkn(dev, array, skl);
2507 tuple_size += tkn_count *
2508 sizeof(struct snd_soc_tplg_vendor_string_elem);
2511 case SND_SOC_TPLG_TUPLE_TYPE_UUID:
2512 dev_warn(dev, "no uuid tokens for skl tplf manifest\n");
2516 tkn_elem = array->value;
2521 while (tkn_count <= array->num_elems - 1) {
2522 ret = skl_tplg_get_int_tkn(dev,
2527 tkn_count = tkn_count + ret;
2529 tuple_size += tkn_count *
2530 sizeof(struct snd_soc_tplg_vendor_value_elem);
2540 * Parse manifest private data for tokens. The private data block is
2541 * preceded by descriptors for type and size of data block.
2543 static int skl_tplg_get_manifest_data(struct snd_soc_tplg_manifest *manifest,
2544 struct device *dev, struct skl *skl)
2546 struct snd_soc_tplg_vendor_array *array;
2547 int num_blocks, block_size = 0, block_type, off = 0;
2551 /* Read the NUM_DATA_BLOCKS descriptor */
2552 array = (struct snd_soc_tplg_vendor_array *)manifest->priv.data;
2553 ret = skl_tplg_get_desc_blocks(dev, array);
2559 array = (struct snd_soc_tplg_vendor_array *)
2560 (manifest->priv.data + off);
2562 /* Read the BLOCK_TYPE and BLOCK_SIZE descriptor */
2563 while (num_blocks > 0) {
2564 ret = skl_tplg_get_desc_blocks(dev, array);
2571 array = (struct snd_soc_tplg_vendor_array *)
2572 (manifest->priv.data + off);
2574 ret = skl_tplg_get_desc_blocks(dev, array);
2581 array = (struct snd_soc_tplg_vendor_array *)
2582 (manifest->priv.data + off);
2584 data = (manifest->priv.data + off);
2586 if (block_type == SKL_TYPE_TUPLE) {
2587 ret = skl_tplg_get_manifest_tkn(dev, data, skl,
2602 static int skl_manifest_load(struct snd_soc_component *cmpnt,
2603 struct snd_soc_tplg_manifest *manifest)
2605 struct hdac_ext_bus *ebus = snd_soc_component_get_drvdata(cmpnt);
2606 struct hdac_bus *bus = ebus_to_hbus(ebus);
2607 struct skl *skl = ebus_to_skl(ebus);
2609 /* proceed only if we have private data defined */
2610 if (manifest->priv.size == 0)
2613 skl_tplg_get_manifest_data(manifest, bus->dev, skl);
2615 if (skl->skl_sst->lib_count > SKL_MAX_LIB) {
2616 dev_err(bus->dev, "Exceeding max Library count. Got:%d\n",
2617 skl->skl_sst->lib_count);
2624 static struct snd_soc_tplg_ops skl_tplg_ops = {
2625 .widget_load = skl_tplg_widget_load,
2626 .control_load = skl_tplg_control_load,
2627 .bytes_ext_ops = skl_tlv_ops,
2628 .bytes_ext_ops_count = ARRAY_SIZE(skl_tlv_ops),
2629 .manifest = skl_manifest_load,
2633 * A pipe can have multiple modules, each of them will be a DAPM widget as
2634 * well. While managing a pipeline we need to get the list of all the
2635 * widgets in a pipelines, so this helper - skl_tplg_create_pipe_widget_list()
2636 * helps to get the SKL type widgets in that pipeline
2638 static int skl_tplg_create_pipe_widget_list(struct snd_soc_platform *platform)
2640 struct snd_soc_dapm_widget *w;
2641 struct skl_module_cfg *mcfg = NULL;
2642 struct skl_pipe_module *p_module = NULL;
2643 struct skl_pipe *pipe;
2645 list_for_each_entry(w, &platform->component.card->widgets, list) {
2646 if (is_skl_dsp_widget_type(w) && w->priv != NULL) {
2650 p_module = devm_kzalloc(platform->dev,
2651 sizeof(*p_module), GFP_KERNEL);
2656 list_add_tail(&p_module->node, &pipe->w_list);
2663 static void skl_tplg_set_pipe_type(struct skl *skl, struct skl_pipe *pipe)
2665 struct skl_pipe_module *w_module;
2666 struct snd_soc_dapm_widget *w;
2667 struct skl_module_cfg *mconfig;
2668 bool host_found = false, link_found = false;
2670 list_for_each_entry(w_module, &pipe->w_list, node) {
2674 if (mconfig->dev_type == SKL_DEVICE_HDAHOST)
2676 else if (mconfig->dev_type != SKL_DEVICE_NONE)
2680 if (host_found && link_found)
2681 pipe->passthru = true;
2683 pipe->passthru = false;
2686 /* This will be read from topology manifest, currently defined here */
2687 #define SKL_MAX_MCPS 30000000
2688 #define SKL_FW_MAX_MEM 1000000
2691 * SKL topology init routine
2693 int skl_tplg_init(struct snd_soc_platform *platform, struct hdac_ext_bus *ebus)
2696 const struct firmware *fw;
2697 struct hdac_bus *bus = ebus_to_hbus(ebus);
2698 struct skl *skl = ebus_to_skl(ebus);
2699 struct skl_pipeline *ppl;
2701 ret = request_firmware(&fw, skl->tplg_name, bus->dev);
2703 dev_err(bus->dev, "tplg fw %s load failed with %d\n",
2704 skl->tplg_name, ret);
2705 ret = request_firmware(&fw, "dfw_sst.bin", bus->dev);
2707 dev_err(bus->dev, "Fallback tplg fw %s load failed with %d\n",
2708 "dfw_sst.bin", ret);
2714 * The complete tplg for SKL is loaded as index 0, we don't use
2717 ret = snd_soc_tplg_component_load(&platform->component,
2718 &skl_tplg_ops, fw, 0);
2720 dev_err(bus->dev, "tplg component load failed%d\n", ret);
2721 release_firmware(fw);
2725 skl->resource.max_mcps = SKL_MAX_MCPS;
2726 skl->resource.max_mem = SKL_FW_MAX_MEM;
2729 ret = skl_tplg_create_pipe_widget_list(platform);
2733 list_for_each_entry(ppl, &skl->ppl_list, node)
2734 skl_tplg_set_pipe_type(skl, ppl->pipe);