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 (mcfg
->in_fmt
->channels
) *
314 (mcfg
->in_fmt
->bit_depth
>> 3) *
317 mcfg
->obs
= DIV_ROUND_UP(mcfg
->out_fmt
->s_freq
, 1000) *
318 (mcfg
->out_fmt
->channels
) *
319 (mcfg
->out_fmt
->bit_depth
>> 3) *
323 static u8
skl_tplg_be_dev_type(int dev_type
)
329 ret
= NHLT_DEVICE_BT
;
332 case SKL_DEVICE_DMIC
:
333 ret
= NHLT_DEVICE_DMIC
;
337 ret
= NHLT_DEVICE_I2S
;
341 ret
= NHLT_DEVICE_INVALID
;
348 static int skl_tplg_update_be_blob(struct snd_soc_dapm_widget
*w
,
351 struct skl_module_cfg
*m_cfg
= w
->priv
;
353 u32 ch
, s_freq
, s_fmt
;
354 struct nhlt_specific_cfg
*cfg
;
355 struct skl
*skl
= get_skl_ctx(ctx
->dev
);
356 u8 dev_type
= skl_tplg_be_dev_type(m_cfg
->dev_type
);
358 /* check if we already have blob */
359 if (m_cfg
->formats_config
.caps_size
> 0)
362 dev_dbg(ctx
->dev
, "Applying default cfg blob\n");
363 switch (m_cfg
->dev_type
) {
364 case SKL_DEVICE_DMIC
:
365 link_type
= NHLT_LINK_DMIC
;
366 dir
= SNDRV_PCM_STREAM_CAPTURE
;
367 s_freq
= m_cfg
->in_fmt
[0].s_freq
;
368 s_fmt
= m_cfg
->in_fmt
[0].bit_depth
;
369 ch
= m_cfg
->in_fmt
[0].channels
;
373 link_type
= NHLT_LINK_SSP
;
374 if (m_cfg
->hw_conn_type
== SKL_CONN_SOURCE
) {
375 dir
= SNDRV_PCM_STREAM_PLAYBACK
;
376 s_freq
= m_cfg
->out_fmt
[0].s_freq
;
377 s_fmt
= m_cfg
->out_fmt
[0].bit_depth
;
378 ch
= m_cfg
->out_fmt
[0].channels
;
380 dir
= SNDRV_PCM_STREAM_CAPTURE
;
381 s_freq
= m_cfg
->in_fmt
[0].s_freq
;
382 s_fmt
= m_cfg
->in_fmt
[0].bit_depth
;
383 ch
= m_cfg
->in_fmt
[0].channels
;
391 /* update the blob based on virtual bus_id and default params */
392 cfg
= skl_get_ep_blob(skl
, m_cfg
->vbus_id
, link_type
,
393 s_fmt
, ch
, s_freq
, dir
, dev_type
);
395 m_cfg
->formats_config
.caps_size
= cfg
->size
;
396 m_cfg
->formats_config
.caps
= (u32
*) &cfg
->caps
;
398 dev_err(ctx
->dev
, "Blob NULL for id %x type %d dirn %d\n",
399 m_cfg
->vbus_id
, link_type
, dir
);
400 dev_err(ctx
->dev
, "PCM: ch %d, freq %d, fmt %d\n",
408 static void skl_tplg_update_module_params(struct snd_soc_dapm_widget
*w
,
411 struct skl_module_cfg
*m_cfg
= w
->priv
;
412 struct skl_pipe_params
*params
= m_cfg
->pipe
->p_params
;
413 int p_conn_type
= m_cfg
->pipe
->conn_type
;
416 if (!m_cfg
->params_fixup
)
419 dev_dbg(ctx
->dev
, "Mconfig for widget=%s BEFORE updation\n",
422 skl_dump_mconfig(ctx
, m_cfg
);
424 if (p_conn_type
== SKL_PIPE_CONN_TYPE_FE
)
429 skl_tplg_update_params_fixup(m_cfg
, params
, is_fe
);
430 skl_tplg_update_buffer_size(ctx
, m_cfg
);
432 dev_dbg(ctx
->dev
, "Mconfig for widget=%s AFTER updation\n",
435 skl_dump_mconfig(ctx
, m_cfg
);
439 * some modules can have multiple params set from user control and
440 * need to be set after module is initialized. If set_param flag is
441 * set module params will be done after module is initialised.
443 static int skl_tplg_set_module_params(struct snd_soc_dapm_widget
*w
,
447 struct skl_module_cfg
*mconfig
= w
->priv
;
448 const struct snd_kcontrol_new
*k
;
449 struct soc_bytes_ext
*sb
;
450 struct skl_algo_data
*bc
;
451 struct skl_specific_cfg
*sp_cfg
;
453 if (mconfig
->formats_config
.caps_size
> 0 &&
454 mconfig
->formats_config
.set_params
== SKL_PARAM_SET
) {
455 sp_cfg
= &mconfig
->formats_config
;
456 ret
= skl_set_module_params(ctx
, sp_cfg
->caps
,
458 sp_cfg
->param_id
, mconfig
);
463 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
464 k
= &w
->kcontrol_news
[i
];
465 if (k
->access
& SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK
) {
466 sb
= (void *) k
->private_value
;
467 bc
= (struct skl_algo_data
*)sb
->dobj
.private;
469 if (bc
->set_params
== SKL_PARAM_SET
) {
470 ret
= skl_set_module_params(ctx
,
471 (u32
*)bc
->params
, bc
->size
,
472 bc
->param_id
, mconfig
);
483 * some module param can set from user control and this is required as
484 * when module is initailzed. if module param is required in init it is
485 * identifed by set_param flag. if set_param flag is not set, then this
486 * parameter needs to set as part of module init.
488 static int skl_tplg_set_module_init_data(struct snd_soc_dapm_widget
*w
)
490 const struct snd_kcontrol_new
*k
;
491 struct soc_bytes_ext
*sb
;
492 struct skl_algo_data
*bc
;
493 struct skl_module_cfg
*mconfig
= w
->priv
;
496 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
497 k
= &w
->kcontrol_news
[i
];
498 if (k
->access
& SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK
) {
499 sb
= (struct soc_bytes_ext
*)k
->private_value
;
500 bc
= (struct skl_algo_data
*)sb
->dobj
.private;
502 if (bc
->set_params
!= SKL_PARAM_INIT
)
505 mconfig
->formats_config
.caps
= (u32
*)&bc
->params
;
506 mconfig
->formats_config
.caps_size
= bc
->size
;
515 static int skl_tplg_module_prepare(struct skl_sst
*ctx
, struct skl_pipe
*pipe
,
516 struct snd_soc_dapm_widget
*w
, struct skl_module_cfg
*mcfg
)
518 switch (mcfg
->dev_type
) {
519 case SKL_DEVICE_HDAHOST
:
520 return skl_pcm_host_dma_prepare(ctx
->dev
, pipe
->p_params
);
522 case SKL_DEVICE_HDALINK
:
523 return skl_pcm_link_dma_prepare(ctx
->dev
, pipe
->p_params
);
530 * Inside a pipe instance, we can have various modules. These modules need
531 * to instantiated in DSP by invoking INIT_MODULE IPC, which is achieved by
532 * skl_init_module() routine, so invoke that for all modules in a pipeline
535 skl_tplg_init_pipe_modules(struct skl
*skl
, struct skl_pipe
*pipe
)
537 struct skl_pipe_module
*w_module
;
538 struct snd_soc_dapm_widget
*w
;
539 struct skl_module_cfg
*mconfig
;
540 struct skl_sst
*ctx
= skl
->skl_sst
;
543 list_for_each_entry(w_module
, &pipe
->w_list
, node
) {
547 /* check if module ids are populated */
548 if (mconfig
->id
.module_id
< 0) {
549 dev_err(skl
->skl_sst
->dev
,
550 "module %pUL id not populated\n",
551 (uuid_le
*)mconfig
->guid
);
555 /* check resource available */
556 if (!skl_is_pipe_mcps_avail(skl
, mconfig
))
559 if (mconfig
->is_loadable
&& ctx
->dsp
->fw_ops
.load_mod
) {
560 ret
= ctx
->dsp
->fw_ops
.load_mod(ctx
->dsp
,
561 mconfig
->id
.module_id
, mconfig
->guid
);
565 mconfig
->m_state
= SKL_MODULE_LOADED
;
568 /* prepare the DMA if the module is gateway cpr */
569 ret
= skl_tplg_module_prepare(ctx
, pipe
, w
, mconfig
);
573 /* update blob if blob is null for be with default value */
574 skl_tplg_update_be_blob(w
, ctx
);
577 * apply fix/conversion to module params based on
580 skl_tplg_update_module_params(w
, ctx
);
581 mconfig
->id
.pvt_id
= skl_get_pvt_id(ctx
, mconfig
);
582 if (mconfig
->id
.pvt_id
< 0)
584 skl_tplg_set_module_init_data(w
);
585 ret
= skl_init_module(ctx
, mconfig
);
587 skl_put_pvt_id(ctx
, mconfig
);
590 skl_tplg_alloc_pipe_mcps(skl
, mconfig
);
591 ret
= skl_tplg_set_module_params(w
, ctx
);
599 static int skl_tplg_unload_pipe_modules(struct skl_sst
*ctx
,
600 struct skl_pipe
*pipe
)
603 struct skl_pipe_module
*w_module
= NULL
;
604 struct skl_module_cfg
*mconfig
= NULL
;
606 list_for_each_entry(w_module
, &pipe
->w_list
, node
) {
607 mconfig
= w_module
->w
->priv
;
609 if (mconfig
->is_loadable
&& ctx
->dsp
->fw_ops
.unload_mod
&&
610 mconfig
->m_state
> SKL_MODULE_UNINIT
) {
611 ret
= ctx
->dsp
->fw_ops
.unload_mod(ctx
->dsp
,
612 mconfig
->id
.module_id
);
616 skl_put_pvt_id(ctx
, mconfig
);
619 /* no modules to unload in this path, so return */
624 * Mixer module represents a pipeline. So in the Pre-PMU event of mixer we
625 * need create the pipeline. So we do following:
626 * - check the resources
627 * - Create the pipeline
628 * - Initialize the modules in pipeline
629 * - finally bind all modules together
631 static int skl_tplg_mixer_dapm_pre_pmu_event(struct snd_soc_dapm_widget
*w
,
635 struct skl_module_cfg
*mconfig
= w
->priv
;
636 struct skl_pipe_module
*w_module
;
637 struct skl_pipe
*s_pipe
= mconfig
->pipe
;
638 struct skl_module_cfg
*src_module
= NULL
, *dst_module
;
639 struct skl_sst
*ctx
= skl
->skl_sst
;
641 /* check resource available */
642 if (!skl_is_pipe_mcps_avail(skl
, mconfig
))
645 if (!skl_is_pipe_mem_avail(skl
, mconfig
))
649 * Create a list of modules for pipe.
650 * This list contains modules from source to sink
652 ret
= skl_create_pipeline(ctx
, mconfig
->pipe
);
656 skl_tplg_alloc_pipe_mem(skl
, mconfig
);
657 skl_tplg_alloc_pipe_mcps(skl
, mconfig
);
659 /* Init all pipe modules from source to sink */
660 ret
= skl_tplg_init_pipe_modules(skl
, s_pipe
);
664 /* Bind modules from source to sink */
665 list_for_each_entry(w_module
, &s_pipe
->w_list
, node
) {
666 dst_module
= w_module
->w
->priv
;
668 if (src_module
== NULL
) {
669 src_module
= dst_module
;
673 ret
= skl_bind_modules(ctx
, src_module
, dst_module
);
677 src_module
= dst_module
;
683 static int skl_fill_sink_instance_id(struct skl_sst
*ctx
,
684 struct skl_algo_data
*alg_data
)
686 struct skl_kpb_params
*params
= (struct skl_kpb_params
*)alg_data
->params
;
687 struct skl_mod_inst_map
*inst
;
692 for (i
= 0; i
< params
->num_modules
; i
++) {
693 pvt_id
= skl_get_pvt_instance_id_map(ctx
,
694 inst
->mod_id
, inst
->inst_id
);
697 inst
->inst_id
= pvt_id
;
704 * Some modules require params to be set after the module is bound to
705 * all pins connected.
707 * The module provider initializes set_param flag for such modules and we
708 * send params after binding
710 static int skl_tplg_set_module_bind_params(struct snd_soc_dapm_widget
*w
,
711 struct skl_module_cfg
*mcfg
, struct skl_sst
*ctx
)
714 struct skl_module_cfg
*mconfig
= w
->priv
;
715 const struct snd_kcontrol_new
*k
;
716 struct soc_bytes_ext
*sb
;
717 struct skl_algo_data
*bc
;
718 struct skl_specific_cfg
*sp_cfg
;
721 * check all out/in pins are in bind state.
722 * if so set the module param
724 for (i
= 0; i
< mcfg
->max_out_queue
; i
++) {
725 if (mcfg
->m_out_pin
[i
].pin_state
!= SKL_PIN_BIND_DONE
)
729 for (i
= 0; i
< mcfg
->max_in_queue
; i
++) {
730 if (mcfg
->m_in_pin
[i
].pin_state
!= SKL_PIN_BIND_DONE
)
734 if (mconfig
->formats_config
.caps_size
> 0 &&
735 mconfig
->formats_config
.set_params
== SKL_PARAM_BIND
) {
736 sp_cfg
= &mconfig
->formats_config
;
737 ret
= skl_set_module_params(ctx
, sp_cfg
->caps
,
739 sp_cfg
->param_id
, mconfig
);
744 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
745 k
= &w
->kcontrol_news
[i
];
746 if (k
->access
& SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK
) {
747 sb
= (void *) k
->private_value
;
748 bc
= (struct skl_algo_data
*)sb
->dobj
.private;
750 if (bc
->set_params
== SKL_PARAM_BIND
) {
751 if (mconfig
->m_type
== SKL_MODULE_TYPE_KPB
)
752 skl_fill_sink_instance_id(ctx
, bc
);
753 ret
= skl_set_module_params(ctx
,
754 (u32
*)bc
->params
, bc
->max
,
755 bc
->param_id
, mconfig
);
765 static int skl_tplg_bind_sinks(struct snd_soc_dapm_widget
*w
,
767 struct snd_soc_dapm_widget
*src_w
,
768 struct skl_module_cfg
*src_mconfig
)
770 struct snd_soc_dapm_path
*p
;
771 struct snd_soc_dapm_widget
*sink
= NULL
, *next_sink
= NULL
;
772 struct skl_module_cfg
*sink_mconfig
;
773 struct skl_sst
*ctx
= skl
->skl_sst
;
776 snd_soc_dapm_widget_for_each_sink_path(w
, p
) {
780 dev_dbg(ctx
->dev
, "%s: src widget=%s\n", __func__
, w
->name
);
781 dev_dbg(ctx
->dev
, "%s: sink widget=%s\n", __func__
, p
->sink
->name
);
785 if (!is_skl_dsp_widget_type(p
->sink
))
786 return skl_tplg_bind_sinks(p
->sink
, skl
, src_w
, src_mconfig
);
789 * here we will check widgets in sink pipelines, so that
790 * can be any widgets type and we are only interested if
791 * they are ones used for SKL so check that first
793 if ((p
->sink
->priv
!= NULL
) &&
794 is_skl_dsp_widget_type(p
->sink
)) {
797 sink_mconfig
= sink
->priv
;
799 if (src_mconfig
->m_state
== SKL_MODULE_UNINIT
||
800 sink_mconfig
->m_state
== SKL_MODULE_UNINIT
)
803 /* Bind source to sink, mixin is always source */
804 ret
= skl_bind_modules(ctx
, src_mconfig
, sink_mconfig
);
808 /* set module params after bind */
809 skl_tplg_set_module_bind_params(src_w
, src_mconfig
, ctx
);
810 skl_tplg_set_module_bind_params(sink
, sink_mconfig
, ctx
);
812 /* Start sinks pipe first */
813 if (sink_mconfig
->pipe
->state
!= SKL_PIPE_STARTED
) {
814 if (sink_mconfig
->pipe
->conn_type
!=
815 SKL_PIPE_CONN_TYPE_FE
)
816 ret
= skl_run_pipe(ctx
,
825 return skl_tplg_bind_sinks(next_sink
, skl
, src_w
, src_mconfig
);
831 * A PGA represents a module in a pipeline. So in the Pre-PMU event of PGA
832 * we need to do following:
833 * - Bind to sink pipeline
834 * Since the sink pipes can be running and we don't get mixer event on
835 * connect for already running mixer, we need to find the sink pipes
836 * here and bind to them. This way dynamic connect works.
837 * - Start sink pipeline, if not running
838 * - Then run current pipe
840 static int skl_tplg_pga_dapm_pre_pmu_event(struct snd_soc_dapm_widget
*w
,
843 struct skl_module_cfg
*src_mconfig
;
844 struct skl_sst
*ctx
= skl
->skl_sst
;
847 src_mconfig
= w
->priv
;
850 * find which sink it is connected to, bind with the sink,
851 * if sink is not started, start sink pipe first, then start
854 ret
= skl_tplg_bind_sinks(w
, skl
, w
, src_mconfig
);
858 /* Start source pipe last after starting all sinks */
859 if (src_mconfig
->pipe
->conn_type
!= SKL_PIPE_CONN_TYPE_FE
)
860 return skl_run_pipe(ctx
, src_mconfig
->pipe
);
865 static struct snd_soc_dapm_widget
*skl_get_src_dsp_widget(
866 struct snd_soc_dapm_widget
*w
, struct skl
*skl
)
868 struct snd_soc_dapm_path
*p
;
869 struct snd_soc_dapm_widget
*src_w
= NULL
;
870 struct skl_sst
*ctx
= skl
->skl_sst
;
872 snd_soc_dapm_widget_for_each_source_path(w
, p
) {
877 dev_dbg(ctx
->dev
, "sink widget=%s\n", w
->name
);
878 dev_dbg(ctx
->dev
, "src widget=%s\n", p
->source
->name
);
881 * here we will check widgets in sink pipelines, so that can
882 * be any widgets type and we are only interested if they are
883 * ones used for SKL so check that first
885 if ((p
->source
->priv
!= NULL
) &&
886 is_skl_dsp_widget_type(p
->source
)) {
892 return skl_get_src_dsp_widget(src_w
, skl
);
898 * in the Post-PMU event of mixer we need to do following:
899 * - Check if this pipe is running
901 * - bind this pipeline to its source pipeline
902 * if source pipe is already running, this means it is a dynamic
903 * connection and we need to bind only to that pipe
904 * - start this pipeline
906 static int skl_tplg_mixer_dapm_post_pmu_event(struct snd_soc_dapm_widget
*w
,
910 struct snd_soc_dapm_widget
*source
, *sink
;
911 struct skl_module_cfg
*src_mconfig
, *sink_mconfig
;
912 struct skl_sst
*ctx
= skl
->skl_sst
;
913 int src_pipe_started
= 0;
916 sink_mconfig
= sink
->priv
;
919 * If source pipe is already started, that means source is driving
920 * one more sink before this sink got connected, Since source is
921 * started, bind this sink to source and start this pipe.
923 source
= skl_get_src_dsp_widget(w
, skl
);
924 if (source
!= NULL
) {
925 src_mconfig
= source
->priv
;
926 sink_mconfig
= sink
->priv
;
927 src_pipe_started
= 1;
930 * check pipe state, then no need to bind or start the
933 if (src_mconfig
->pipe
->state
!= SKL_PIPE_STARTED
)
934 src_pipe_started
= 0;
937 if (src_pipe_started
) {
938 ret
= skl_bind_modules(ctx
, src_mconfig
, sink_mconfig
);
942 /* set module params after bind */
943 skl_tplg_set_module_bind_params(source
, src_mconfig
, ctx
);
944 skl_tplg_set_module_bind_params(sink
, sink_mconfig
, ctx
);
946 if (sink_mconfig
->pipe
->conn_type
!= SKL_PIPE_CONN_TYPE_FE
)
947 ret
= skl_run_pipe(ctx
, sink_mconfig
->pipe
);
954 * in the Pre-PMD event of mixer we need to do following:
956 * - find the source connections and remove that from dapm_path_list
957 * - unbind with source pipelines if still connected
959 static int skl_tplg_mixer_dapm_pre_pmd_event(struct snd_soc_dapm_widget
*w
,
962 struct skl_module_cfg
*src_mconfig
, *sink_mconfig
;
964 struct skl_sst
*ctx
= skl
->skl_sst
;
966 sink_mconfig
= w
->priv
;
969 ret
= skl_stop_pipe(ctx
, sink_mconfig
->pipe
);
973 for (i
= 0; i
< sink_mconfig
->max_in_queue
; i
++) {
974 if (sink_mconfig
->m_in_pin
[i
].pin_state
== SKL_PIN_BIND_DONE
) {
975 src_mconfig
= sink_mconfig
->m_in_pin
[i
].tgt_mcfg
;
979 * If path_found == 1, that means pmd for source
980 * pipe has not occurred, source is connected to
981 * some other sink. so its responsibility of sink
982 * to unbind itself from source.
984 ret
= skl_stop_pipe(ctx
, src_mconfig
->pipe
);
988 ret
= skl_unbind_modules(ctx
,
989 src_mconfig
, sink_mconfig
);
997 * in the Post-PMD event of mixer we need to do following:
998 * - Free the mcps used
999 * - Free the mem used
1000 * - Unbind the modules within the pipeline
1001 * - Delete the pipeline (modules are not required to be explicitly
1002 * deleted, pipeline delete is enough here
1004 static int skl_tplg_mixer_dapm_post_pmd_event(struct snd_soc_dapm_widget
*w
,
1007 struct skl_module_cfg
*mconfig
= w
->priv
;
1008 struct skl_pipe_module
*w_module
;
1009 struct skl_module_cfg
*src_module
= NULL
, *dst_module
;
1010 struct skl_sst
*ctx
= skl
->skl_sst
;
1011 struct skl_pipe
*s_pipe
= mconfig
->pipe
;
1013 if (s_pipe
->state
== SKL_PIPE_INVALID
)
1016 skl_tplg_free_pipe_mcps(skl
, mconfig
);
1017 skl_tplg_free_pipe_mem(skl
, mconfig
);
1019 list_for_each_entry(w_module
, &s_pipe
->w_list
, node
) {
1020 dst_module
= w_module
->w
->priv
;
1022 if (mconfig
->m_state
>= SKL_MODULE_INIT_DONE
)
1023 skl_tplg_free_pipe_mcps(skl
, dst_module
);
1024 if (src_module
== NULL
) {
1025 src_module
= dst_module
;
1029 skl_unbind_modules(ctx
, src_module
, dst_module
);
1030 src_module
= dst_module
;
1033 skl_delete_pipe(ctx
, mconfig
->pipe
);
1035 return skl_tplg_unload_pipe_modules(ctx
, s_pipe
);
1039 * in the Post-PMD event of PGA we need to do following:
1040 * - Free the mcps used
1041 * - Stop the pipeline
1042 * - In source pipe is connected, unbind with source pipelines
1044 static int skl_tplg_pga_dapm_post_pmd_event(struct snd_soc_dapm_widget
*w
,
1047 struct skl_module_cfg
*src_mconfig
, *sink_mconfig
;
1049 struct skl_sst
*ctx
= skl
->skl_sst
;
1051 src_mconfig
= w
->priv
;
1053 /* Stop the pipe since this is a mixin module */
1054 ret
= skl_stop_pipe(ctx
, src_mconfig
->pipe
);
1058 for (i
= 0; i
< src_mconfig
->max_out_queue
; i
++) {
1059 if (src_mconfig
->m_out_pin
[i
].pin_state
== SKL_PIN_BIND_DONE
) {
1060 sink_mconfig
= src_mconfig
->m_out_pin
[i
].tgt_mcfg
;
1064 * This is a connecter and if path is found that means
1065 * unbind between source and sink has not happened yet
1067 ret
= skl_unbind_modules(ctx
, src_mconfig
,
1076 * In modelling, we assume there will be ONLY one mixer in a pipeline. If
1077 * mixer is not required then it is treated as static mixer aka vmixer with
1078 * a hard path to source module
1079 * So we don't need to check if source is started or not as hard path puts
1080 * dependency on each other
1082 static int skl_tplg_vmixer_event(struct snd_soc_dapm_widget
*w
,
1083 struct snd_kcontrol
*k
, int event
)
1085 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
1086 struct skl
*skl
= get_skl_ctx(dapm
->dev
);
1089 case SND_SOC_DAPM_PRE_PMU
:
1090 return skl_tplg_mixer_dapm_pre_pmu_event(w
, skl
);
1092 case SND_SOC_DAPM_POST_PMU
:
1093 return skl_tplg_mixer_dapm_post_pmu_event(w
, skl
);
1095 case SND_SOC_DAPM_PRE_PMD
:
1096 return skl_tplg_mixer_dapm_pre_pmd_event(w
, skl
);
1098 case SND_SOC_DAPM_POST_PMD
:
1099 return skl_tplg_mixer_dapm_post_pmd_event(w
, skl
);
1106 * In modelling, we assume there will be ONLY one mixer in a pipeline. If a
1107 * second one is required that is created as another pipe entity.
1108 * The mixer is responsible for pipe management and represent a pipeline
1111 static int skl_tplg_mixer_event(struct snd_soc_dapm_widget
*w
,
1112 struct snd_kcontrol
*k
, int event
)
1114 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
1115 struct skl
*skl
= get_skl_ctx(dapm
->dev
);
1118 case SND_SOC_DAPM_PRE_PMU
:
1119 return skl_tplg_mixer_dapm_pre_pmu_event(w
, skl
);
1121 case SND_SOC_DAPM_POST_PMU
:
1122 return skl_tplg_mixer_dapm_post_pmu_event(w
, skl
);
1124 case SND_SOC_DAPM_PRE_PMD
:
1125 return skl_tplg_mixer_dapm_pre_pmd_event(w
, skl
);
1127 case SND_SOC_DAPM_POST_PMD
:
1128 return skl_tplg_mixer_dapm_post_pmd_event(w
, skl
);
1135 * In modelling, we assumed rest of the modules in pipeline are PGA. But we
1136 * are interested in last PGA (leaf PGA) in a pipeline to disconnect with
1137 * the sink when it is running (two FE to one BE or one FE to two BE)
1140 static int skl_tplg_pga_event(struct snd_soc_dapm_widget
*w
,
1141 struct snd_kcontrol
*k
, int event
)
1144 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
1145 struct skl
*skl
= get_skl_ctx(dapm
->dev
);
1148 case SND_SOC_DAPM_PRE_PMU
:
1149 return skl_tplg_pga_dapm_pre_pmu_event(w
, skl
);
1151 case SND_SOC_DAPM_POST_PMD
:
1152 return skl_tplg_pga_dapm_post_pmd_event(w
, skl
);
1158 static int skl_tplg_tlv_control_get(struct snd_kcontrol
*kcontrol
,
1159 unsigned int __user
*data
, unsigned int size
)
1161 struct soc_bytes_ext
*sb
=
1162 (struct soc_bytes_ext
*)kcontrol
->private_value
;
1163 struct skl_algo_data
*bc
= (struct skl_algo_data
*)sb
->dobj
.private;
1164 struct snd_soc_dapm_widget
*w
= snd_soc_dapm_kcontrol_widget(kcontrol
);
1165 struct skl_module_cfg
*mconfig
= w
->priv
;
1166 struct skl
*skl
= get_skl_ctx(w
->dapm
->dev
);
1169 skl_get_module_params(skl
->skl_sst
, (u32
*)bc
->params
,
1170 bc
->size
, bc
->param_id
, mconfig
);
1172 /* decrement size for TLV header */
1173 size
-= 2 * sizeof(u32
);
1175 /* check size as we don't want to send kernel data */
1180 if (copy_to_user(data
, &bc
->param_id
, sizeof(u32
)))
1182 if (copy_to_user(data
+ 1, &size
, sizeof(u32
)))
1184 if (copy_to_user(data
+ 2, bc
->params
, size
))
1191 #define SKL_PARAM_VENDOR_ID 0xff
1193 static int skl_tplg_tlv_control_set(struct snd_kcontrol
*kcontrol
,
1194 const unsigned int __user
*data
, unsigned int size
)
1196 struct snd_soc_dapm_widget
*w
= snd_soc_dapm_kcontrol_widget(kcontrol
);
1197 struct skl_module_cfg
*mconfig
= w
->priv
;
1198 struct soc_bytes_ext
*sb
=
1199 (struct soc_bytes_ext
*)kcontrol
->private_value
;
1200 struct skl_algo_data
*ac
= (struct skl_algo_data
*)sb
->dobj
.private;
1201 struct skl
*skl
= get_skl_ctx(w
->dapm
->dev
);
1209 * if the param_is is of type Vendor, firmware expects actual
1210 * parameter id and size from the control.
1212 if (ac
->param_id
== SKL_PARAM_VENDOR_ID
) {
1213 if (copy_from_user(ac
->params
, data
, size
))
1216 if (copy_from_user(ac
->params
,
1222 return skl_set_module_params(skl
->skl_sst
,
1223 (u32
*)ac
->params
, ac
->size
,
1224 ac
->param_id
, mconfig
);
1231 * Fill the dma id for host and link. In case of passthrough
1232 * pipeline, this will both host and link in the same
1233 * pipeline, so need to copy the link and host based on dev_type
1235 static void skl_tplg_fill_dma_id(struct skl_module_cfg
*mcfg
,
1236 struct skl_pipe_params
*params
)
1238 struct skl_pipe
*pipe
= mcfg
->pipe
;
1240 if (pipe
->passthru
) {
1241 switch (mcfg
->dev_type
) {
1242 case SKL_DEVICE_HDALINK
:
1243 pipe
->p_params
->link_dma_id
= params
->link_dma_id
;
1244 pipe
->p_params
->link_index
= params
->link_index
;
1247 case SKL_DEVICE_HDAHOST
:
1248 pipe
->p_params
->host_dma_id
= params
->host_dma_id
;
1254 pipe
->p_params
->s_fmt
= params
->s_fmt
;
1255 pipe
->p_params
->ch
= params
->ch
;
1256 pipe
->p_params
->s_freq
= params
->s_freq
;
1257 pipe
->p_params
->stream
= params
->stream
;
1258 pipe
->p_params
->format
= params
->format
;
1261 memcpy(pipe
->p_params
, params
, sizeof(*params
));
1266 * The FE params are passed by hw_params of the DAI.
1267 * On hw_params, the params are stored in Gateway module of the FE and we
1268 * need to calculate the format in DSP module configuration, that
1269 * conversion is done here
1271 int skl_tplg_update_pipe_params(struct device
*dev
,
1272 struct skl_module_cfg
*mconfig
,
1273 struct skl_pipe_params
*params
)
1275 struct skl_module_fmt
*format
= NULL
;
1277 skl_tplg_fill_dma_id(mconfig
, params
);
1279 if (params
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
1280 format
= &mconfig
->in_fmt
[0];
1282 format
= &mconfig
->out_fmt
[0];
1284 /* set the hw_params */
1285 format
->s_freq
= params
->s_freq
;
1286 format
->channels
= params
->ch
;
1287 format
->valid_bit_depth
= skl_get_bit_depth(params
->s_fmt
);
1290 * 16 bit is 16 bit container whereas 24 bit is in 32 bit
1291 * container so update bit depth accordingly
1293 switch (format
->valid_bit_depth
) {
1294 case SKL_DEPTH_16BIT
:
1295 format
->bit_depth
= format
->valid_bit_depth
;
1298 case SKL_DEPTH_24BIT
:
1299 case SKL_DEPTH_32BIT
:
1300 format
->bit_depth
= SKL_DEPTH_32BIT
;
1304 dev_err(dev
, "Invalid bit depth %x for pipe\n",
1305 format
->valid_bit_depth
);
1309 if (params
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
1310 mconfig
->ibs
= (format
->s_freq
/ 1000) *
1311 (format
->channels
) *
1312 (format
->bit_depth
>> 3);
1314 mconfig
->obs
= (format
->s_freq
/ 1000) *
1315 (format
->channels
) *
1316 (format
->bit_depth
>> 3);
1323 * Query the module config for the FE DAI
1324 * This is used to find the hw_params set for that DAI and apply to FE
1327 struct skl_module_cfg
*
1328 skl_tplg_fe_get_cpr_module(struct snd_soc_dai
*dai
, int stream
)
1330 struct snd_soc_dapm_widget
*w
;
1331 struct snd_soc_dapm_path
*p
= NULL
;
1333 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
1334 w
= dai
->playback_widget
;
1335 snd_soc_dapm_widget_for_each_sink_path(w
, p
) {
1336 if (p
->connect
&& p
->sink
->power
&&
1337 !is_skl_dsp_widget_type(p
->sink
))
1340 if (p
->sink
->priv
) {
1341 dev_dbg(dai
->dev
, "set params for %s\n",
1343 return p
->sink
->priv
;
1347 w
= dai
->capture_widget
;
1348 snd_soc_dapm_widget_for_each_source_path(w
, p
) {
1349 if (p
->connect
&& p
->source
->power
&&
1350 !is_skl_dsp_widget_type(p
->source
))
1353 if (p
->source
->priv
) {
1354 dev_dbg(dai
->dev
, "set params for %s\n",
1356 return p
->source
->priv
;
1364 static struct skl_module_cfg
*skl_get_mconfig_pb_cpr(
1365 struct snd_soc_dai
*dai
, struct snd_soc_dapm_widget
*w
)
1367 struct snd_soc_dapm_path
*p
;
1368 struct skl_module_cfg
*mconfig
= NULL
;
1370 snd_soc_dapm_widget_for_each_source_path(w
, p
) {
1371 if (w
->endpoints
[SND_SOC_DAPM_DIR_OUT
] > 0) {
1373 (p
->sink
->id
== snd_soc_dapm_aif_out
) &&
1375 mconfig
= p
->source
->priv
;
1378 mconfig
= skl_get_mconfig_pb_cpr(dai
, p
->source
);
1386 static struct skl_module_cfg
*skl_get_mconfig_cap_cpr(
1387 struct snd_soc_dai
*dai
, struct snd_soc_dapm_widget
*w
)
1389 struct snd_soc_dapm_path
*p
;
1390 struct skl_module_cfg
*mconfig
= NULL
;
1392 snd_soc_dapm_widget_for_each_sink_path(w
, p
) {
1393 if (w
->endpoints
[SND_SOC_DAPM_DIR_IN
] > 0) {
1395 (p
->source
->id
== snd_soc_dapm_aif_in
) &&
1397 mconfig
= p
->sink
->priv
;
1400 mconfig
= skl_get_mconfig_cap_cpr(dai
, p
->sink
);
1408 struct skl_module_cfg
*
1409 skl_tplg_be_get_cpr_module(struct snd_soc_dai
*dai
, int stream
)
1411 struct snd_soc_dapm_widget
*w
;
1412 struct skl_module_cfg
*mconfig
;
1414 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
1415 w
= dai
->playback_widget
;
1416 mconfig
= skl_get_mconfig_pb_cpr(dai
, w
);
1418 w
= dai
->capture_widget
;
1419 mconfig
= skl_get_mconfig_cap_cpr(dai
, w
);
1424 static u8
skl_tplg_be_link_type(int dev_type
)
1430 ret
= NHLT_LINK_SSP
;
1433 case SKL_DEVICE_DMIC
:
1434 ret
= NHLT_LINK_DMIC
;
1437 case SKL_DEVICE_I2S
:
1438 ret
= NHLT_LINK_SSP
;
1441 case SKL_DEVICE_HDALINK
:
1442 ret
= NHLT_LINK_HDA
;
1446 ret
= NHLT_LINK_INVALID
;
1454 * Fill the BE gateway parameters
1455 * The BE gateway expects a blob of parameters which are kept in the ACPI
1456 * NHLT blob, so query the blob for interface type (i2s/pdm) and instance.
1457 * The port can have multiple settings so pick based on the PCM
1460 static int skl_tplg_be_fill_pipe_params(struct snd_soc_dai
*dai
,
1461 struct skl_module_cfg
*mconfig
,
1462 struct skl_pipe_params
*params
)
1464 struct nhlt_specific_cfg
*cfg
;
1465 struct skl
*skl
= get_skl_ctx(dai
->dev
);
1466 int link_type
= skl_tplg_be_link_type(mconfig
->dev_type
);
1467 u8 dev_type
= skl_tplg_be_dev_type(mconfig
->dev_type
);
1469 skl_tplg_fill_dma_id(mconfig
, params
);
1471 if (link_type
== NHLT_LINK_HDA
)
1474 /* update the blob based on virtual bus_id*/
1475 cfg
= skl_get_ep_blob(skl
, mconfig
->vbus_id
, link_type
,
1476 params
->s_fmt
, params
->ch
,
1477 params
->s_freq
, params
->stream
,
1480 mconfig
->formats_config
.caps_size
= cfg
->size
;
1481 mconfig
->formats_config
.caps
= (u32
*) &cfg
->caps
;
1483 dev_err(dai
->dev
, "Blob NULL for id %x type %d dirn %d\n",
1484 mconfig
->vbus_id
, link_type
,
1486 dev_err(dai
->dev
, "PCM: ch %d, freq %d, fmt %d\n",
1487 params
->ch
, params
->s_freq
, params
->s_fmt
);
1494 static int skl_tplg_be_set_src_pipe_params(struct snd_soc_dai
*dai
,
1495 struct snd_soc_dapm_widget
*w
,
1496 struct skl_pipe_params
*params
)
1498 struct snd_soc_dapm_path
*p
;
1501 snd_soc_dapm_widget_for_each_source_path(w
, p
) {
1502 if (p
->connect
&& is_skl_dsp_widget_type(p
->source
) &&
1505 ret
= skl_tplg_be_fill_pipe_params(dai
,
1506 p
->source
->priv
, params
);
1510 ret
= skl_tplg_be_set_src_pipe_params(dai
,
1520 static int skl_tplg_be_set_sink_pipe_params(struct snd_soc_dai
*dai
,
1521 struct snd_soc_dapm_widget
*w
, struct skl_pipe_params
*params
)
1523 struct snd_soc_dapm_path
*p
= NULL
;
1526 snd_soc_dapm_widget_for_each_sink_path(w
, p
) {
1527 if (p
->connect
&& is_skl_dsp_widget_type(p
->sink
) &&
1530 ret
= skl_tplg_be_fill_pipe_params(dai
,
1531 p
->sink
->priv
, params
);
1535 ret
= skl_tplg_be_set_sink_pipe_params(
1536 dai
, p
->sink
, params
);
1546 * BE hw_params can be a source parameters (capture) or sink parameters
1547 * (playback). Based on sink and source we need to either find the source
1548 * list or the sink list and set the pipeline parameters
1550 int skl_tplg_be_update_params(struct snd_soc_dai
*dai
,
1551 struct skl_pipe_params
*params
)
1553 struct snd_soc_dapm_widget
*w
;
1555 if (params
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
1556 w
= dai
->playback_widget
;
1558 return skl_tplg_be_set_src_pipe_params(dai
, w
, params
);
1561 w
= dai
->capture_widget
;
1563 return skl_tplg_be_set_sink_pipe_params(dai
, w
, params
);
1569 static const struct snd_soc_tplg_widget_events skl_tplg_widget_ops
[] = {
1570 {SKL_MIXER_EVENT
, skl_tplg_mixer_event
},
1571 {SKL_VMIXER_EVENT
, skl_tplg_vmixer_event
},
1572 {SKL_PGA_EVENT
, skl_tplg_pga_event
},
1575 static const struct snd_soc_tplg_bytes_ext_ops skl_tlv_ops
[] = {
1576 {SKL_CONTROL_TYPE_BYTE_TLV
, skl_tplg_tlv_control_get
,
1577 skl_tplg_tlv_control_set
},
1580 static int skl_tplg_fill_pipe_tkn(struct device
*dev
,
1581 struct skl_pipe
*pipe
, u32 tkn
,
1586 case SKL_TKN_U32_PIPE_CONN_TYPE
:
1587 pipe
->conn_type
= tkn_val
;
1590 case SKL_TKN_U32_PIPE_PRIORITY
:
1591 pipe
->pipe_priority
= tkn_val
;
1594 case SKL_TKN_U32_PIPE_MEM_PGS
:
1595 pipe
->memory_pages
= tkn_val
;
1598 case SKL_TKN_U32_PMODE
:
1599 pipe
->lp_mode
= tkn_val
;
1603 dev_err(dev
, "Token not handled %d\n", tkn
);
1611 * Add pipeline by parsing the relevant tokens
1612 * Return an existing pipe if the pipe already exists.
1614 static int skl_tplg_add_pipe(struct device
*dev
,
1615 struct skl_module_cfg
*mconfig
, struct skl
*skl
,
1616 struct snd_soc_tplg_vendor_value_elem
*tkn_elem
)
1618 struct skl_pipeline
*ppl
;
1619 struct skl_pipe
*pipe
;
1620 struct skl_pipe_params
*params
;
1622 list_for_each_entry(ppl
, &skl
->ppl_list
, node
) {
1623 if (ppl
->pipe
->ppl_id
== tkn_elem
->value
) {
1624 mconfig
->pipe
= ppl
->pipe
;
1629 ppl
= devm_kzalloc(dev
, sizeof(*ppl
), GFP_KERNEL
);
1633 pipe
= devm_kzalloc(dev
, sizeof(*pipe
), GFP_KERNEL
);
1637 params
= devm_kzalloc(dev
, sizeof(*params
), GFP_KERNEL
);
1641 pipe
->p_params
= params
;
1642 pipe
->ppl_id
= tkn_elem
->value
;
1643 INIT_LIST_HEAD(&pipe
->w_list
);
1646 list_add(&ppl
->node
, &skl
->ppl_list
);
1648 mconfig
->pipe
= pipe
;
1649 mconfig
->pipe
->state
= SKL_PIPE_INVALID
;
1654 static int skl_tplg_fill_pin(struct device
*dev
, u32 tkn
,
1655 struct skl_module_pin
*m_pin
,
1656 int pin_index
, u32 value
)
1659 case SKL_TKN_U32_PIN_MOD_ID
:
1660 m_pin
[pin_index
].id
.module_id
= value
;
1663 case SKL_TKN_U32_PIN_INST_ID
:
1664 m_pin
[pin_index
].id
.instance_id
= value
;
1668 dev_err(dev
, "%d Not a pin token\n", value
);
1676 * Parse for pin config specific tokens to fill up the
1677 * module private data
1679 static int skl_tplg_fill_pins_info(struct device
*dev
,
1680 struct skl_module_cfg
*mconfig
,
1681 struct snd_soc_tplg_vendor_value_elem
*tkn_elem
,
1682 int dir
, int pin_count
)
1685 struct skl_module_pin
*m_pin
;
1689 m_pin
= mconfig
->m_in_pin
;
1693 m_pin
= mconfig
->m_out_pin
;
1697 dev_err(dev
, "Invalid direction value\n");
1701 ret
= skl_tplg_fill_pin(dev
, tkn_elem
->token
,
1702 m_pin
, pin_count
, tkn_elem
->value
);
1707 m_pin
[pin_count
].in_use
= false;
1708 m_pin
[pin_count
].pin_state
= SKL_PIN_UNBIND
;
1714 * Fill up input/output module config format based
1717 static int skl_tplg_fill_fmt(struct device
*dev
,
1718 struct skl_module_cfg
*mconfig
, u32 tkn
,
1719 u32 value
, u32 dir
, u32 pin_count
)
1721 struct skl_module_fmt
*dst_fmt
;
1725 dst_fmt
= mconfig
->in_fmt
;
1726 dst_fmt
+= pin_count
;
1730 dst_fmt
= mconfig
->out_fmt
;
1731 dst_fmt
+= pin_count
;
1735 dev_err(dev
, "Invalid direction value\n");
1740 case SKL_TKN_U32_FMT_CH
:
1741 dst_fmt
->channels
= value
;
1744 case SKL_TKN_U32_FMT_FREQ
:
1745 dst_fmt
->s_freq
= value
;
1748 case SKL_TKN_U32_FMT_BIT_DEPTH
:
1749 dst_fmt
->bit_depth
= value
;
1752 case SKL_TKN_U32_FMT_SAMPLE_SIZE
:
1753 dst_fmt
->valid_bit_depth
= value
;
1756 case SKL_TKN_U32_FMT_CH_CONFIG
:
1757 dst_fmt
->ch_cfg
= value
;
1760 case SKL_TKN_U32_FMT_INTERLEAVE
:
1761 dst_fmt
->interleaving_style
= value
;
1764 case SKL_TKN_U32_FMT_SAMPLE_TYPE
:
1765 dst_fmt
->sample_type
= value
;
1768 case SKL_TKN_U32_FMT_CH_MAP
:
1769 dst_fmt
->ch_map
= value
;
1773 dev_err(dev
, "Invalid token %d\n", tkn
);
1780 static int skl_tplg_get_uuid(struct device
*dev
, struct skl_module_cfg
*mconfig
,
1781 struct snd_soc_tplg_vendor_uuid_elem
*uuid_tkn
)
1783 if (uuid_tkn
->token
== SKL_TKN_UUID
)
1784 memcpy(&mconfig
->guid
, &uuid_tkn
->uuid
, 16);
1786 dev_err(dev
, "Not an UUID token tkn %d\n", uuid_tkn
->token
);
1793 static void skl_tplg_fill_pin_dynamic_val(
1794 struct skl_module_pin
*mpin
, u32 pin_count
, u32 value
)
1798 for (i
= 0; i
< pin_count
; i
++)
1799 mpin
[i
].is_dynamic
= value
;
1803 * Parse tokens to fill up the module private data
1805 static int skl_tplg_get_token(struct device
*dev
,
1806 struct snd_soc_tplg_vendor_value_elem
*tkn_elem
,
1807 struct skl
*skl
, struct skl_module_cfg
*mconfig
)
1811 static int is_pipe_exists
;
1812 static int pin_index
, dir
;
1814 if (tkn_elem
->token
> SKL_TKN_MAX
)
1817 switch (tkn_elem
->token
) {
1818 case SKL_TKN_U8_IN_QUEUE_COUNT
:
1819 mconfig
->max_in_queue
= tkn_elem
->value
;
1820 mconfig
->m_in_pin
= devm_kzalloc(dev
, mconfig
->max_in_queue
*
1821 sizeof(*mconfig
->m_in_pin
),
1823 if (!mconfig
->m_in_pin
)
1828 case SKL_TKN_U8_OUT_QUEUE_COUNT
:
1829 mconfig
->max_out_queue
= tkn_elem
->value
;
1830 mconfig
->m_out_pin
= devm_kzalloc(dev
, mconfig
->max_out_queue
*
1831 sizeof(*mconfig
->m_out_pin
),
1834 if (!mconfig
->m_out_pin
)
1839 case SKL_TKN_U8_DYN_IN_PIN
:
1840 if (!mconfig
->m_in_pin
)
1843 skl_tplg_fill_pin_dynamic_val(mconfig
->m_in_pin
,
1844 mconfig
->max_in_queue
, tkn_elem
->value
);
1848 case SKL_TKN_U8_DYN_OUT_PIN
:
1849 if (!mconfig
->m_out_pin
)
1852 skl_tplg_fill_pin_dynamic_val(mconfig
->m_out_pin
,
1853 mconfig
->max_out_queue
, tkn_elem
->value
);
1857 case SKL_TKN_U8_TIME_SLOT
:
1858 mconfig
->time_slot
= tkn_elem
->value
;
1861 case SKL_TKN_U8_CORE_ID
:
1862 mconfig
->core_id
= tkn_elem
->value
;
1864 case SKL_TKN_U8_MOD_TYPE
:
1865 mconfig
->m_type
= tkn_elem
->value
;
1868 case SKL_TKN_U8_DEV_TYPE
:
1869 mconfig
->dev_type
= tkn_elem
->value
;
1872 case SKL_TKN_U8_HW_CONN_TYPE
:
1873 mconfig
->hw_conn_type
= tkn_elem
->value
;
1876 case SKL_TKN_U16_MOD_INST_ID
:
1877 mconfig
->id
.instance_id
=
1881 case SKL_TKN_U32_MEM_PAGES
:
1882 mconfig
->mem_pages
= tkn_elem
->value
;
1885 case SKL_TKN_U32_MAX_MCPS
:
1886 mconfig
->mcps
= tkn_elem
->value
;
1889 case SKL_TKN_U32_OBS
:
1890 mconfig
->obs
= tkn_elem
->value
;
1893 case SKL_TKN_U32_IBS
:
1894 mconfig
->ibs
= tkn_elem
->value
;
1897 case SKL_TKN_U32_VBUS_ID
:
1898 mconfig
->vbus_id
= tkn_elem
->value
;
1901 case SKL_TKN_U32_PARAMS_FIXUP
:
1902 mconfig
->params_fixup
= tkn_elem
->value
;
1905 case SKL_TKN_U32_CONVERTER
:
1906 mconfig
->converter
= tkn_elem
->value
;
1909 case SKL_TKL_U32_D0I3_CAPS
:
1910 mconfig
->d0i3_caps
= tkn_elem
->value
;
1913 case SKL_TKN_U32_PIPE_ID
:
1914 ret
= skl_tplg_add_pipe(dev
,
1915 mconfig
, skl
, tkn_elem
);
1918 return is_pipe_exists
;
1925 case SKL_TKN_U32_PIPE_CONN_TYPE
:
1926 case SKL_TKN_U32_PIPE_PRIORITY
:
1927 case SKL_TKN_U32_PIPE_MEM_PGS
:
1928 case SKL_TKN_U32_PMODE
:
1929 if (is_pipe_exists
) {
1930 ret
= skl_tplg_fill_pipe_tkn(dev
, mconfig
->pipe
,
1931 tkn_elem
->token
, tkn_elem
->value
);
1939 * SKL_TKN_U32_DIR_PIN_COUNT token has the value for both
1940 * direction and the pin count. The first four bits represent
1941 * direction and next four the pin count.
1943 case SKL_TKN_U32_DIR_PIN_COUNT
:
1944 dir
= tkn_elem
->value
& SKL_IN_DIR_BIT_MASK
;
1945 pin_index
= (tkn_elem
->value
&
1946 SKL_PIN_COUNT_MASK
) >> 4;
1950 case SKL_TKN_U32_FMT_CH
:
1951 case SKL_TKN_U32_FMT_FREQ
:
1952 case SKL_TKN_U32_FMT_BIT_DEPTH
:
1953 case SKL_TKN_U32_FMT_SAMPLE_SIZE
:
1954 case SKL_TKN_U32_FMT_CH_CONFIG
:
1955 case SKL_TKN_U32_FMT_INTERLEAVE
:
1956 case SKL_TKN_U32_FMT_SAMPLE_TYPE
:
1957 case SKL_TKN_U32_FMT_CH_MAP
:
1958 ret
= skl_tplg_fill_fmt(dev
, mconfig
, tkn_elem
->token
,
1959 tkn_elem
->value
, dir
, pin_index
);
1966 case SKL_TKN_U32_PIN_MOD_ID
:
1967 case SKL_TKN_U32_PIN_INST_ID
:
1968 ret
= skl_tplg_fill_pins_info(dev
,
1969 mconfig
, tkn_elem
, dir
,
1976 case SKL_TKN_U32_CAPS_SIZE
:
1977 mconfig
->formats_config
.caps_size
=
1982 case SKL_TKN_U32_PROC_DOMAIN
:
1988 case SKL_TKN_U8_IN_PIN_TYPE
:
1989 case SKL_TKN_U8_OUT_PIN_TYPE
:
1990 case SKL_TKN_U8_CONN_TYPE
:
1994 dev_err(dev
, "Token %d not handled\n",
2005 * Parse the vendor array for specific tokens to construct
2006 * module private data
2008 static int skl_tplg_get_tokens(struct device
*dev
,
2009 char *pvt_data
, struct skl
*skl
,
2010 struct skl_module_cfg
*mconfig
, int block_size
)
2012 struct snd_soc_tplg_vendor_array
*array
;
2013 struct snd_soc_tplg_vendor_value_elem
*tkn_elem
;
2014 int tkn_count
= 0, ret
;
2015 int off
= 0, tuple_size
= 0;
2017 if (block_size
<= 0)
2020 while (tuple_size
< block_size
) {
2021 array
= (struct snd_soc_tplg_vendor_array
*)(pvt_data
+ off
);
2025 switch (array
->type
) {
2026 case SND_SOC_TPLG_TUPLE_TYPE_STRING
:
2027 dev_warn(dev
, "no string tokens expected for skl tplg\n");
2030 case SND_SOC_TPLG_TUPLE_TYPE_UUID
:
2031 ret
= skl_tplg_get_uuid(dev
, mconfig
, array
->uuid
);
2035 tuple_size
+= sizeof(*array
->uuid
);
2040 tkn_elem
= array
->value
;
2045 while (tkn_count
<= (array
->num_elems
- 1)) {
2046 ret
= skl_tplg_get_token(dev
, tkn_elem
,
2052 tkn_count
= tkn_count
+ ret
;
2056 tuple_size
+= tkn_count
* sizeof(*tkn_elem
);
2063 * Every data block is preceded by a descriptor to read the number
2064 * of data blocks, they type of the block and it's size
2066 static int skl_tplg_get_desc_blocks(struct device
*dev
,
2067 struct snd_soc_tplg_vendor_array
*array
)
2069 struct snd_soc_tplg_vendor_value_elem
*tkn_elem
;
2071 tkn_elem
= array
->value
;
2073 switch (tkn_elem
->token
) {
2074 case SKL_TKN_U8_NUM_BLOCKS
:
2075 case SKL_TKN_U8_BLOCK_TYPE
:
2076 case SKL_TKN_U16_BLOCK_SIZE
:
2077 return tkn_elem
->value
;
2080 dev_err(dev
, "Invalid descriptor token %d\n", tkn_elem
->token
);
2088 * Parse the private data for the token and corresponding value.
2089 * The private data can have multiple data blocks. So, a data block
2090 * is preceded by a descriptor for number of blocks and a descriptor
2091 * for the type and size of the suceeding data block.
2093 static int skl_tplg_get_pvt_data(struct snd_soc_tplg_dapm_widget
*tplg_w
,
2094 struct skl
*skl
, struct device
*dev
,
2095 struct skl_module_cfg
*mconfig
)
2097 struct snd_soc_tplg_vendor_array
*array
;
2098 int num_blocks
, block_size
= 0, block_type
, off
= 0;
2102 /* Read the NUM_DATA_BLOCKS descriptor */
2103 array
= (struct snd_soc_tplg_vendor_array
*)tplg_w
->priv
.data
;
2104 ret
= skl_tplg_get_desc_blocks(dev
, array
);
2110 array
= (struct snd_soc_tplg_vendor_array
*)(tplg_w
->priv
.data
+ off
);
2112 /* Read the BLOCK_TYPE and BLOCK_SIZE descriptor */
2113 while (num_blocks
> 0) {
2114 ret
= skl_tplg_get_desc_blocks(dev
, array
);
2121 array
= (struct snd_soc_tplg_vendor_array
*)
2122 (tplg_w
->priv
.data
+ off
);
2124 ret
= skl_tplg_get_desc_blocks(dev
, array
);
2131 array
= (struct snd_soc_tplg_vendor_array
*)
2132 (tplg_w
->priv
.data
+ off
);
2134 data
= (tplg_w
->priv
.data
+ off
);
2136 if (block_type
== SKL_TYPE_TUPLE
) {
2137 ret
= skl_tplg_get_tokens(dev
, data
,
2138 skl
, mconfig
, block_size
);
2145 if (mconfig
->formats_config
.caps_size
> 0)
2146 memcpy(mconfig
->formats_config
.caps
, data
,
2147 mconfig
->formats_config
.caps_size
);
2155 static void skl_clear_pin_config(struct snd_soc_platform
*platform
,
2156 struct snd_soc_dapm_widget
*w
)
2159 struct skl_module_cfg
*mconfig
;
2160 struct skl_pipe
*pipe
;
2162 if (!strncmp(w
->dapm
->component
->name
, platform
->component
.name
,
2163 strlen(platform
->component
.name
))) {
2165 pipe
= mconfig
->pipe
;
2166 for (i
= 0; i
< mconfig
->max_in_queue
; i
++) {
2167 mconfig
->m_in_pin
[i
].in_use
= false;
2168 mconfig
->m_in_pin
[i
].pin_state
= SKL_PIN_UNBIND
;
2170 for (i
= 0; i
< mconfig
->max_out_queue
; i
++) {
2171 mconfig
->m_out_pin
[i
].in_use
= false;
2172 mconfig
->m_out_pin
[i
].pin_state
= SKL_PIN_UNBIND
;
2174 pipe
->state
= SKL_PIPE_INVALID
;
2175 mconfig
->m_state
= SKL_MODULE_UNINIT
;
2179 void skl_cleanup_resources(struct skl
*skl
)
2181 struct skl_sst
*ctx
= skl
->skl_sst
;
2182 struct snd_soc_platform
*soc_platform
= skl
->platform
;
2183 struct snd_soc_dapm_widget
*w
;
2184 struct snd_soc_card
*card
;
2186 if (soc_platform
== NULL
)
2189 card
= soc_platform
->component
.card
;
2190 if (!card
|| !card
->instantiated
)
2193 skl
->resource
.mem
= 0;
2194 skl
->resource
.mcps
= 0;
2196 list_for_each_entry(w
, &card
->widgets
, list
) {
2197 if (is_skl_dsp_widget_type(w
) && (w
->priv
!= NULL
))
2198 skl_clear_pin_config(soc_platform
, w
);
2201 skl_clear_module_cnt(ctx
->dsp
);
2205 * Topology core widget load callback
2207 * This is used to save the private data for each widget which gives
2208 * information to the driver about module and pipeline parameters which DSP
2209 * FW expects like ids, resource values, formats etc
2211 static int skl_tplg_widget_load(struct snd_soc_component
*cmpnt
,
2212 struct snd_soc_dapm_widget
*w
,
2213 struct snd_soc_tplg_dapm_widget
*tplg_w
)
2216 struct hdac_ext_bus
*ebus
= snd_soc_component_get_drvdata(cmpnt
);
2217 struct skl
*skl
= ebus_to_skl(ebus
);
2218 struct hdac_bus
*bus
= ebus_to_hbus(ebus
);
2219 struct skl_module_cfg
*mconfig
;
2221 if (!tplg_w
->priv
.size
)
2224 mconfig
= devm_kzalloc(bus
->dev
, sizeof(*mconfig
), GFP_KERNEL
);
2232 * module binary can be loaded later, so set it to query when
2233 * module is load for a use case
2235 mconfig
->id
.module_id
= -1;
2237 /* Parse private data for tuples */
2238 ret
= skl_tplg_get_pvt_data(tplg_w
, skl
, bus
->dev
, mconfig
);
2242 if (tplg_w
->event_type
== 0) {
2243 dev_dbg(bus
->dev
, "ASoC: No event handler required\n");
2247 ret
= snd_soc_tplg_widget_bind_event(w
, skl_tplg_widget_ops
,
2248 ARRAY_SIZE(skl_tplg_widget_ops
),
2249 tplg_w
->event_type
);
2252 dev_err(bus
->dev
, "%s: No matching event handlers found for %d\n",
2253 __func__
, tplg_w
->event_type
);
2260 static int skl_init_algo_data(struct device
*dev
, struct soc_bytes_ext
*be
,
2261 struct snd_soc_tplg_bytes_control
*bc
)
2263 struct skl_algo_data
*ac
;
2264 struct skl_dfw_algo_data
*dfw_ac
=
2265 (struct skl_dfw_algo_data
*)bc
->priv
.data
;
2267 ac
= devm_kzalloc(dev
, sizeof(*ac
), GFP_KERNEL
);
2271 /* Fill private data */
2272 ac
->max
= dfw_ac
->max
;
2273 ac
->param_id
= dfw_ac
->param_id
;
2274 ac
->set_params
= dfw_ac
->set_params
;
2275 ac
->size
= dfw_ac
->max
;
2278 ac
->params
= (char *) devm_kzalloc(dev
, ac
->max
, GFP_KERNEL
);
2282 memcpy(ac
->params
, dfw_ac
->params
, ac
->max
);
2285 be
->dobj
.private = ac
;
2289 static int skl_tplg_control_load(struct snd_soc_component
*cmpnt
,
2290 struct snd_kcontrol_new
*kctl
,
2291 struct snd_soc_tplg_ctl_hdr
*hdr
)
2293 struct soc_bytes_ext
*sb
;
2294 struct snd_soc_tplg_bytes_control
*tplg_bc
;
2295 struct hdac_ext_bus
*ebus
= snd_soc_component_get_drvdata(cmpnt
);
2296 struct hdac_bus
*bus
= ebus_to_hbus(ebus
);
2298 switch (hdr
->ops
.info
) {
2299 case SND_SOC_TPLG_CTL_BYTES
:
2300 tplg_bc
= container_of(hdr
,
2301 struct snd_soc_tplg_bytes_control
, hdr
);
2302 if (kctl
->access
& SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK
) {
2303 sb
= (struct soc_bytes_ext
*)kctl
->private_value
;
2304 if (tplg_bc
->priv
.size
)
2305 return skl_init_algo_data(
2306 bus
->dev
, sb
, tplg_bc
);
2311 dev_warn(bus
->dev
, "Control load not supported %d:%d:%d\n",
2312 hdr
->ops
.get
, hdr
->ops
.put
, hdr
->ops
.info
);
2319 static int skl_tplg_fill_str_mfest_tkn(struct device
*dev
,
2320 struct snd_soc_tplg_vendor_string_elem
*str_elem
,
2324 static int ref_count
;
2326 switch (str_elem
->token
) {
2327 case SKL_TKN_STR_LIB_NAME
:
2328 if (ref_count
> skl
->skl_sst
->lib_count
- 1) {
2333 strncpy(skl
->skl_sst
->lib_info
[ref_count
].name
,
2335 ARRAY_SIZE(skl
->skl_sst
->lib_info
[ref_count
].name
));
2341 dev_err(dev
, "Not a string token %d\n", str_elem
->token
);
2348 static int skl_tplg_get_str_tkn(struct device
*dev
,
2349 struct snd_soc_tplg_vendor_array
*array
,
2352 int tkn_count
= 0, ret
;
2353 struct snd_soc_tplg_vendor_string_elem
*str_elem
;
2355 str_elem
= (struct snd_soc_tplg_vendor_string_elem
*)array
->value
;
2356 while (tkn_count
< array
->num_elems
) {
2357 ret
= skl_tplg_fill_str_mfest_tkn(dev
, str_elem
, skl
);
2363 tkn_count
= tkn_count
+ ret
;
2369 static int skl_tplg_get_int_tkn(struct device
*dev
,
2370 struct snd_soc_tplg_vendor_value_elem
*tkn_elem
,
2375 switch (tkn_elem
->token
) {
2376 case SKL_TKN_U32_LIB_COUNT
:
2377 skl
->skl_sst
->lib_count
= tkn_elem
->value
;
2382 dev_err(dev
, "Not a manifest token %d\n", tkn_elem
->token
);
2390 * Fill the manifest structure by parsing the tokens based on the
2393 static int skl_tplg_get_manifest_tkn(struct device
*dev
,
2394 char *pvt_data
, struct skl
*skl
,
2397 int tkn_count
= 0, ret
;
2398 int off
= 0, tuple_size
= 0;
2399 struct snd_soc_tplg_vendor_array
*array
;
2400 struct snd_soc_tplg_vendor_value_elem
*tkn_elem
;
2402 if (block_size
<= 0)
2405 while (tuple_size
< block_size
) {
2406 array
= (struct snd_soc_tplg_vendor_array
*)(pvt_data
+ off
);
2408 switch (array
->type
) {
2409 case SND_SOC_TPLG_TUPLE_TYPE_STRING
:
2410 ret
= skl_tplg_get_str_tkn(dev
, array
, skl
);
2416 tuple_size
+= tkn_count
*
2417 sizeof(struct snd_soc_tplg_vendor_string_elem
);
2420 case SND_SOC_TPLG_TUPLE_TYPE_UUID
:
2421 dev_warn(dev
, "no uuid tokens for skl tplf manifest\n");
2425 tkn_elem
= array
->value
;
2430 while (tkn_count
<= array
->num_elems
- 1) {
2431 ret
= skl_tplg_get_int_tkn(dev
,
2436 tkn_count
= tkn_count
+ ret
;
2438 tuple_size
+= tkn_count
*
2439 sizeof(struct snd_soc_tplg_vendor_value_elem
);
2449 * Parse manifest private data for tokens. The private data block is
2450 * preceded by descriptors for type and size of data block.
2452 static int skl_tplg_get_manifest_data(struct snd_soc_tplg_manifest
*manifest
,
2453 struct device
*dev
, struct skl
*skl
)
2455 struct snd_soc_tplg_vendor_array
*array
;
2456 int num_blocks
, block_size
= 0, block_type
, off
= 0;
2460 /* Read the NUM_DATA_BLOCKS descriptor */
2461 array
= (struct snd_soc_tplg_vendor_array
*)manifest
->priv
.data
;
2462 ret
= skl_tplg_get_desc_blocks(dev
, array
);
2468 array
= (struct snd_soc_tplg_vendor_array
*)
2469 (manifest
->priv
.data
+ off
);
2471 /* Read the BLOCK_TYPE and BLOCK_SIZE descriptor */
2472 while (num_blocks
> 0) {
2473 ret
= skl_tplg_get_desc_blocks(dev
, array
);
2480 array
= (struct snd_soc_tplg_vendor_array
*)
2481 (manifest
->priv
.data
+ off
);
2483 ret
= skl_tplg_get_desc_blocks(dev
, array
);
2490 array
= (struct snd_soc_tplg_vendor_array
*)
2491 (manifest
->priv
.data
+ off
);
2493 data
= (manifest
->priv
.data
+ off
);
2495 if (block_type
== SKL_TYPE_TUPLE
) {
2496 ret
= skl_tplg_get_manifest_tkn(dev
, data
, skl
,
2511 static int skl_manifest_load(struct snd_soc_component
*cmpnt
,
2512 struct snd_soc_tplg_manifest
*manifest
)
2514 struct hdac_ext_bus
*ebus
= snd_soc_component_get_drvdata(cmpnt
);
2515 struct hdac_bus
*bus
= ebus_to_hbus(ebus
);
2516 struct skl
*skl
= ebus_to_skl(ebus
);
2518 /* proceed only if we have private data defined */
2519 if (manifest
->priv
.size
== 0)
2522 skl_tplg_get_manifest_data(manifest
, bus
->dev
, skl
);
2524 if (skl
->skl_sst
->lib_count
> SKL_MAX_LIB
) {
2525 dev_err(bus
->dev
, "Exceeding max Library count. Got:%d\n",
2526 skl
->skl_sst
->lib_count
);
2533 static struct snd_soc_tplg_ops skl_tplg_ops
= {
2534 .widget_load
= skl_tplg_widget_load
,
2535 .control_load
= skl_tplg_control_load
,
2536 .bytes_ext_ops
= skl_tlv_ops
,
2537 .bytes_ext_ops_count
= ARRAY_SIZE(skl_tlv_ops
),
2538 .manifest
= skl_manifest_load
,
2542 * A pipe can have multiple modules, each of them will be a DAPM widget as
2543 * well. While managing a pipeline we need to get the list of all the
2544 * widgets in a pipelines, so this helper - skl_tplg_create_pipe_widget_list()
2545 * helps to get the SKL type widgets in that pipeline
2547 static int skl_tplg_create_pipe_widget_list(struct snd_soc_platform
*platform
)
2549 struct snd_soc_dapm_widget
*w
;
2550 struct skl_module_cfg
*mcfg
= NULL
;
2551 struct skl_pipe_module
*p_module
= NULL
;
2552 struct skl_pipe
*pipe
;
2554 list_for_each_entry(w
, &platform
->component
.card
->widgets
, list
) {
2555 if (is_skl_dsp_widget_type(w
) && w
->priv
!= NULL
) {
2559 p_module
= devm_kzalloc(platform
->dev
,
2560 sizeof(*p_module
), GFP_KERNEL
);
2565 list_add_tail(&p_module
->node
, &pipe
->w_list
);
2572 static void skl_tplg_set_pipe_type(struct skl
*skl
, struct skl_pipe
*pipe
)
2574 struct skl_pipe_module
*w_module
;
2575 struct snd_soc_dapm_widget
*w
;
2576 struct skl_module_cfg
*mconfig
;
2577 bool host_found
= false, link_found
= false;
2579 list_for_each_entry(w_module
, &pipe
->w_list
, node
) {
2583 if (mconfig
->dev_type
== SKL_DEVICE_HDAHOST
)
2585 else if (mconfig
->dev_type
!= SKL_DEVICE_NONE
)
2589 if (host_found
&& link_found
)
2590 pipe
->passthru
= true;
2592 pipe
->passthru
= false;
2595 /* This will be read from topology manifest, currently defined here */
2596 #define SKL_MAX_MCPS 30000000
2597 #define SKL_FW_MAX_MEM 1000000
2600 * SKL topology init routine
2602 int skl_tplg_init(struct snd_soc_platform
*platform
, struct hdac_ext_bus
*ebus
)
2605 const struct firmware
*fw
;
2606 struct hdac_bus
*bus
= ebus_to_hbus(ebus
);
2607 struct skl
*skl
= ebus_to_skl(ebus
);
2608 struct skl_pipeline
*ppl
;
2610 ret
= request_firmware(&fw
, skl
->tplg_name
, bus
->dev
);
2612 dev_err(bus
->dev
, "tplg fw %s load failed with %d\n",
2613 skl
->tplg_name
, ret
);
2614 ret
= request_firmware(&fw
, "dfw_sst.bin", bus
->dev
);
2616 dev_err(bus
->dev
, "Fallback tplg fw %s load failed with %d\n",
2617 "dfw_sst.bin", ret
);
2623 * The complete tplg for SKL is loaded as index 0, we don't use
2626 ret
= snd_soc_tplg_component_load(&platform
->component
,
2627 &skl_tplg_ops
, fw
, 0);
2629 dev_err(bus
->dev
, "tplg component load failed%d\n", ret
);
2630 release_firmware(fw
);
2634 skl
->resource
.max_mcps
= SKL_MAX_MCPS
;
2635 skl
->resource
.max_mem
= SKL_FW_MAX_MEM
;
2638 ret
= skl_tplg_create_pipe_widget_list(platform
);
2642 list_for_each_entry(ppl
, &skl
->ppl_list
, node
)
2643 skl_tplg_set_pipe_type(skl
, ppl
->pipe
);