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
;
302 int in_rate
, out_rate
;
305 /* Since fixups is applied to pin 0 only, ibs, obs needs
306 * change for pin 0 only
308 in_fmt
= &mcfg
->in_fmt
[0];
309 out_fmt
= &mcfg
->out_fmt
[0];
311 if (mcfg
->m_type
== SKL_MODULE_TYPE_SRCINT
)
314 if (in_fmt
->s_freq
% 1000)
315 in_rate
= (in_fmt
->s_freq
/ 1000) + 1;
317 in_rate
= (in_fmt
->s_freq
/ 1000);
319 mcfg
->ibs
= in_rate
* (mcfg
->in_fmt
->channels
) *
320 (mcfg
->in_fmt
->bit_depth
>> 3) *
323 if (mcfg
->out_fmt
->s_freq
% 1000)
324 out_rate
= (mcfg
->out_fmt
->s_freq
/ 1000) + 1;
326 out_rate
= (mcfg
->out_fmt
->s_freq
/ 1000);
328 mcfg
->obs
= out_rate
* (mcfg
->out_fmt
->channels
) *
329 (mcfg
->out_fmt
->bit_depth
>> 3) *
333 static int skl_tplg_update_be_blob(struct snd_soc_dapm_widget
*w
,
336 struct skl_module_cfg
*m_cfg
= w
->priv
;
338 u32 ch
, s_freq
, s_fmt
;
339 struct nhlt_specific_cfg
*cfg
;
340 struct skl
*skl
= get_skl_ctx(ctx
->dev
);
342 /* check if we already have blob */
343 if (m_cfg
->formats_config
.caps_size
> 0)
346 dev_dbg(ctx
->dev
, "Applying default cfg blob\n");
347 switch (m_cfg
->dev_type
) {
348 case SKL_DEVICE_DMIC
:
349 link_type
= NHLT_LINK_DMIC
;
350 dir
= SNDRV_PCM_STREAM_CAPTURE
;
351 s_freq
= m_cfg
->in_fmt
[0].s_freq
;
352 s_fmt
= m_cfg
->in_fmt
[0].bit_depth
;
353 ch
= m_cfg
->in_fmt
[0].channels
;
357 link_type
= NHLT_LINK_SSP
;
358 if (m_cfg
->hw_conn_type
== SKL_CONN_SOURCE
) {
359 dir
= SNDRV_PCM_STREAM_PLAYBACK
;
360 s_freq
= m_cfg
->out_fmt
[0].s_freq
;
361 s_fmt
= m_cfg
->out_fmt
[0].bit_depth
;
362 ch
= m_cfg
->out_fmt
[0].channels
;
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
;
375 /* update the blob based on virtual bus_id and default params */
376 cfg
= skl_get_ep_blob(skl
, m_cfg
->vbus_id
, link_type
,
377 s_fmt
, ch
, s_freq
, dir
);
379 m_cfg
->formats_config
.caps_size
= cfg
->size
;
380 m_cfg
->formats_config
.caps
= (u32
*) &cfg
->caps
;
382 dev_err(ctx
->dev
, "Blob NULL for id %x type %d dirn %d\n",
383 m_cfg
->vbus_id
, link_type
, dir
);
384 dev_err(ctx
->dev
, "PCM: ch %d, freq %d, fmt %d\n",
392 static void skl_tplg_update_module_params(struct snd_soc_dapm_widget
*w
,
395 struct skl_module_cfg
*m_cfg
= w
->priv
;
396 struct skl_pipe_params
*params
= m_cfg
->pipe
->p_params
;
397 int p_conn_type
= m_cfg
->pipe
->conn_type
;
400 if (!m_cfg
->params_fixup
)
403 dev_dbg(ctx
->dev
, "Mconfig for widget=%s BEFORE updation\n",
406 skl_dump_mconfig(ctx
, m_cfg
);
408 if (p_conn_type
== SKL_PIPE_CONN_TYPE_FE
)
413 skl_tplg_update_params_fixup(m_cfg
, params
, is_fe
);
414 skl_tplg_update_buffer_size(ctx
, m_cfg
);
416 dev_dbg(ctx
->dev
, "Mconfig for widget=%s AFTER updation\n",
419 skl_dump_mconfig(ctx
, m_cfg
);
423 * some modules can have multiple params set from user control and
424 * need to be set after module is initialized. If set_param flag is
425 * set module params will be done after module is initialised.
427 static int skl_tplg_set_module_params(struct snd_soc_dapm_widget
*w
,
431 struct skl_module_cfg
*mconfig
= w
->priv
;
432 const struct snd_kcontrol_new
*k
;
433 struct soc_bytes_ext
*sb
;
434 struct skl_algo_data
*bc
;
435 struct skl_specific_cfg
*sp_cfg
;
437 if (mconfig
->formats_config
.caps_size
> 0 &&
438 mconfig
->formats_config
.set_params
== SKL_PARAM_SET
) {
439 sp_cfg
= &mconfig
->formats_config
;
440 ret
= skl_set_module_params(ctx
, sp_cfg
->caps
,
442 sp_cfg
->param_id
, mconfig
);
447 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
448 k
= &w
->kcontrol_news
[i
];
449 if (k
->access
& SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK
) {
450 sb
= (void *) k
->private_value
;
451 bc
= (struct skl_algo_data
*)sb
->dobj
.private;
453 if (bc
->set_params
== SKL_PARAM_SET
) {
454 ret
= skl_set_module_params(ctx
,
455 (u32
*)bc
->params
, bc
->size
,
456 bc
->param_id
, mconfig
);
467 * some module param can set from user control and this is required as
468 * when module is initailzed. if module param is required in init it is
469 * identifed by set_param flag. if set_param flag is not set, then this
470 * parameter needs to set as part of module init.
472 static int skl_tplg_set_module_init_data(struct snd_soc_dapm_widget
*w
)
474 const struct snd_kcontrol_new
*k
;
475 struct soc_bytes_ext
*sb
;
476 struct skl_algo_data
*bc
;
477 struct skl_module_cfg
*mconfig
= w
->priv
;
480 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
481 k
= &w
->kcontrol_news
[i
];
482 if (k
->access
& SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK
) {
483 sb
= (struct soc_bytes_ext
*)k
->private_value
;
484 bc
= (struct skl_algo_data
*)sb
->dobj
.private;
486 if (bc
->set_params
!= SKL_PARAM_INIT
)
489 mconfig
->formats_config
.caps
= (u32
*)&bc
->params
;
490 mconfig
->formats_config
.caps_size
= bc
->size
;
500 * Inside a pipe instance, we can have various modules. These modules need
501 * to instantiated in DSP by invoking INIT_MODULE IPC, which is achieved by
502 * skl_init_module() routine, so invoke that for all modules in a pipeline
505 skl_tplg_init_pipe_modules(struct skl
*skl
, struct skl_pipe
*pipe
)
507 struct skl_pipe_module
*w_module
;
508 struct snd_soc_dapm_widget
*w
;
509 struct skl_module_cfg
*mconfig
;
510 struct skl_sst
*ctx
= skl
->skl_sst
;
513 list_for_each_entry(w_module
, &pipe
->w_list
, node
) {
517 /* check if module ids are populated */
518 if (mconfig
->id
.module_id
< 0) {
519 dev_err(skl
->skl_sst
->dev
,
520 "module %pUL id not populated\n",
521 (uuid_le
*)mconfig
->guid
);
525 /* check resource available */
526 if (!skl_is_pipe_mcps_avail(skl
, mconfig
))
529 if (mconfig
->is_loadable
&& ctx
->dsp
->fw_ops
.load_mod
) {
530 ret
= ctx
->dsp
->fw_ops
.load_mod(ctx
->dsp
,
531 mconfig
->id
.module_id
, mconfig
->guid
);
535 mconfig
->m_state
= SKL_MODULE_LOADED
;
538 /* update blob if blob is null for be with default value */
539 skl_tplg_update_be_blob(w
, ctx
);
542 * apply fix/conversion to module params based on
545 skl_tplg_update_module_params(w
, ctx
);
546 mconfig
->id
.pvt_id
= skl_get_pvt_id(ctx
, mconfig
);
547 if (mconfig
->id
.pvt_id
< 0)
549 skl_tplg_set_module_init_data(w
);
550 ret
= skl_init_module(ctx
, mconfig
);
552 skl_put_pvt_id(ctx
, mconfig
);
555 skl_tplg_alloc_pipe_mcps(skl
, mconfig
);
556 ret
= skl_tplg_set_module_params(w
, ctx
);
564 static int skl_tplg_unload_pipe_modules(struct skl_sst
*ctx
,
565 struct skl_pipe
*pipe
)
568 struct skl_pipe_module
*w_module
= NULL
;
569 struct skl_module_cfg
*mconfig
= NULL
;
571 list_for_each_entry(w_module
, &pipe
->w_list
, node
) {
572 mconfig
= w_module
->w
->priv
;
574 if (mconfig
->is_loadable
&& ctx
->dsp
->fw_ops
.unload_mod
&&
575 mconfig
->m_state
> SKL_MODULE_UNINIT
) {
576 ret
= ctx
->dsp
->fw_ops
.unload_mod(ctx
->dsp
,
577 mconfig
->id
.module_id
);
581 skl_put_pvt_id(ctx
, mconfig
);
584 /* no modules to unload in this path, so return */
589 * Mixer module represents a pipeline. So in the Pre-PMU event of mixer we
590 * need create the pipeline. So we do following:
591 * - check the resources
592 * - Create the pipeline
593 * - Initialize the modules in pipeline
594 * - finally bind all modules together
596 static int skl_tplg_mixer_dapm_pre_pmu_event(struct snd_soc_dapm_widget
*w
,
600 struct skl_module_cfg
*mconfig
= w
->priv
;
601 struct skl_pipe_module
*w_module
;
602 struct skl_pipe
*s_pipe
= mconfig
->pipe
;
603 struct skl_module_cfg
*src_module
= NULL
, *dst_module
;
604 struct skl_sst
*ctx
= skl
->skl_sst
;
606 /* check resource available */
607 if (!skl_is_pipe_mcps_avail(skl
, mconfig
))
610 if (!skl_is_pipe_mem_avail(skl
, mconfig
))
614 * Create a list of modules for pipe.
615 * This list contains modules from source to sink
617 ret
= skl_create_pipeline(ctx
, mconfig
->pipe
);
621 skl_tplg_alloc_pipe_mem(skl
, mconfig
);
622 skl_tplg_alloc_pipe_mcps(skl
, mconfig
);
624 /* Init all pipe modules from source to sink */
625 ret
= skl_tplg_init_pipe_modules(skl
, s_pipe
);
629 /* Bind modules from source to sink */
630 list_for_each_entry(w_module
, &s_pipe
->w_list
, node
) {
631 dst_module
= w_module
->w
->priv
;
633 if (src_module
== NULL
) {
634 src_module
= dst_module
;
638 ret
= skl_bind_modules(ctx
, src_module
, dst_module
);
642 src_module
= dst_module
;
648 static int skl_fill_sink_instance_id(struct skl_sst
*ctx
,
649 struct skl_algo_data
*alg_data
)
651 struct skl_kpb_params
*params
= (struct skl_kpb_params
*)alg_data
->params
;
652 struct skl_mod_inst_map
*inst
;
657 for (i
= 0; i
< params
->num_modules
; i
++) {
658 pvt_id
= skl_get_pvt_instance_id_map(ctx
,
659 inst
->mod_id
, inst
->inst_id
);
662 inst
->inst_id
= pvt_id
;
669 * Some modules require params to be set after the module is bound to
670 * all pins connected.
672 * The module provider initializes set_param flag for such modules and we
673 * send params after binding
675 static int skl_tplg_set_module_bind_params(struct snd_soc_dapm_widget
*w
,
676 struct skl_module_cfg
*mcfg
, struct skl_sst
*ctx
)
679 struct skl_module_cfg
*mconfig
= w
->priv
;
680 const struct snd_kcontrol_new
*k
;
681 struct soc_bytes_ext
*sb
;
682 struct skl_algo_data
*bc
;
683 struct skl_specific_cfg
*sp_cfg
;
686 * check all out/in pins are in bind state.
687 * if so set the module param
689 for (i
= 0; i
< mcfg
->max_out_queue
; i
++) {
690 if (mcfg
->m_out_pin
[i
].pin_state
!= SKL_PIN_BIND_DONE
)
694 for (i
= 0; i
< mcfg
->max_in_queue
; i
++) {
695 if (mcfg
->m_in_pin
[i
].pin_state
!= SKL_PIN_BIND_DONE
)
699 if (mconfig
->formats_config
.caps_size
> 0 &&
700 mconfig
->formats_config
.set_params
== SKL_PARAM_BIND
) {
701 sp_cfg
= &mconfig
->formats_config
;
702 ret
= skl_set_module_params(ctx
, sp_cfg
->caps
,
704 sp_cfg
->param_id
, mconfig
);
709 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
710 k
= &w
->kcontrol_news
[i
];
711 if (k
->access
& SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK
) {
712 sb
= (void *) k
->private_value
;
713 bc
= (struct skl_algo_data
*)sb
->dobj
.private;
715 if (bc
->set_params
== SKL_PARAM_BIND
) {
716 if (mconfig
->m_type
== SKL_MODULE_TYPE_KPB
)
717 skl_fill_sink_instance_id(ctx
, bc
);
718 ret
= skl_set_module_params(ctx
,
719 (u32
*)bc
->params
, bc
->max
,
720 bc
->param_id
, mconfig
);
730 static int skl_tplg_bind_sinks(struct snd_soc_dapm_widget
*w
,
732 struct snd_soc_dapm_widget
*src_w
,
733 struct skl_module_cfg
*src_mconfig
)
735 struct snd_soc_dapm_path
*p
;
736 struct snd_soc_dapm_widget
*sink
= NULL
, *next_sink
= NULL
;
737 struct skl_module_cfg
*sink_mconfig
;
738 struct skl_sst
*ctx
= skl
->skl_sst
;
741 snd_soc_dapm_widget_for_each_sink_path(w
, p
) {
745 dev_dbg(ctx
->dev
, "%s: src widget=%s\n", __func__
, w
->name
);
746 dev_dbg(ctx
->dev
, "%s: sink widget=%s\n", __func__
, p
->sink
->name
);
750 if (!is_skl_dsp_widget_type(p
->sink
))
751 return skl_tplg_bind_sinks(p
->sink
, skl
, src_w
, src_mconfig
);
754 * here we will check widgets in sink pipelines, so that
755 * can be any widgets type and we are only interested if
756 * they are ones used for SKL so check that first
758 if ((p
->sink
->priv
!= NULL
) &&
759 is_skl_dsp_widget_type(p
->sink
)) {
762 sink_mconfig
= sink
->priv
;
764 if (src_mconfig
->m_state
== SKL_MODULE_UNINIT
||
765 sink_mconfig
->m_state
== SKL_MODULE_UNINIT
)
768 /* Bind source to sink, mixin is always source */
769 ret
= skl_bind_modules(ctx
, src_mconfig
, sink_mconfig
);
773 /* set module params after bind */
774 skl_tplg_set_module_bind_params(src_w
, src_mconfig
, ctx
);
775 skl_tplg_set_module_bind_params(sink
, sink_mconfig
, ctx
);
777 /* Start sinks pipe first */
778 if (sink_mconfig
->pipe
->state
!= SKL_PIPE_STARTED
) {
779 if (sink_mconfig
->pipe
->conn_type
!=
780 SKL_PIPE_CONN_TYPE_FE
)
781 ret
= skl_run_pipe(ctx
,
790 return skl_tplg_bind_sinks(next_sink
, skl
, src_w
, src_mconfig
);
796 * A PGA represents a module in a pipeline. So in the Pre-PMU event of PGA
797 * we need to do following:
798 * - Bind to sink pipeline
799 * Since the sink pipes can be running and we don't get mixer event on
800 * connect for already running mixer, we need to find the sink pipes
801 * here and bind to them. This way dynamic connect works.
802 * - Start sink pipeline, if not running
803 * - Then run current pipe
805 static int skl_tplg_pga_dapm_pre_pmu_event(struct snd_soc_dapm_widget
*w
,
808 struct skl_module_cfg
*src_mconfig
;
809 struct skl_sst
*ctx
= skl
->skl_sst
;
812 src_mconfig
= w
->priv
;
815 * find which sink it is connected to, bind with the sink,
816 * if sink is not started, start sink pipe first, then start
819 ret
= skl_tplg_bind_sinks(w
, skl
, w
, src_mconfig
);
823 /* Start source pipe last after starting all sinks */
824 if (src_mconfig
->pipe
->conn_type
!= SKL_PIPE_CONN_TYPE_FE
)
825 return skl_run_pipe(ctx
, src_mconfig
->pipe
);
830 static struct snd_soc_dapm_widget
*skl_get_src_dsp_widget(
831 struct snd_soc_dapm_widget
*w
, struct skl
*skl
)
833 struct snd_soc_dapm_path
*p
;
834 struct snd_soc_dapm_widget
*src_w
= NULL
;
835 struct skl_sst
*ctx
= skl
->skl_sst
;
837 snd_soc_dapm_widget_for_each_source_path(w
, p
) {
842 dev_dbg(ctx
->dev
, "sink widget=%s\n", w
->name
);
843 dev_dbg(ctx
->dev
, "src widget=%s\n", p
->source
->name
);
846 * here we will check widgets in sink pipelines, so that can
847 * be any widgets type and we are only interested if they are
848 * ones used for SKL so check that first
850 if ((p
->source
->priv
!= NULL
) &&
851 is_skl_dsp_widget_type(p
->source
)) {
857 return skl_get_src_dsp_widget(src_w
, skl
);
863 * in the Post-PMU event of mixer we need to do following:
864 * - Check if this pipe is running
866 * - bind this pipeline to its source pipeline
867 * if source pipe is already running, this means it is a dynamic
868 * connection and we need to bind only to that pipe
869 * - start this pipeline
871 static int skl_tplg_mixer_dapm_post_pmu_event(struct snd_soc_dapm_widget
*w
,
875 struct snd_soc_dapm_widget
*source
, *sink
;
876 struct skl_module_cfg
*src_mconfig
, *sink_mconfig
;
877 struct skl_sst
*ctx
= skl
->skl_sst
;
878 int src_pipe_started
= 0;
881 sink_mconfig
= sink
->priv
;
884 * If source pipe is already started, that means source is driving
885 * one more sink before this sink got connected, Since source is
886 * started, bind this sink to source and start this pipe.
888 source
= skl_get_src_dsp_widget(w
, skl
);
889 if (source
!= NULL
) {
890 src_mconfig
= source
->priv
;
891 sink_mconfig
= sink
->priv
;
892 src_pipe_started
= 1;
895 * check pipe state, then no need to bind or start the
898 if (src_mconfig
->pipe
->state
!= SKL_PIPE_STARTED
)
899 src_pipe_started
= 0;
902 if (src_pipe_started
) {
903 ret
= skl_bind_modules(ctx
, src_mconfig
, sink_mconfig
);
907 /* set module params after bind */
908 skl_tplg_set_module_bind_params(source
, src_mconfig
, ctx
);
909 skl_tplg_set_module_bind_params(sink
, sink_mconfig
, ctx
);
911 if (sink_mconfig
->pipe
->conn_type
!= SKL_PIPE_CONN_TYPE_FE
)
912 ret
= skl_run_pipe(ctx
, sink_mconfig
->pipe
);
919 * in the Pre-PMD event of mixer we need to do following:
921 * - find the source connections and remove that from dapm_path_list
922 * - unbind with source pipelines if still connected
924 static int skl_tplg_mixer_dapm_pre_pmd_event(struct snd_soc_dapm_widget
*w
,
927 struct skl_module_cfg
*src_mconfig
, *sink_mconfig
;
929 struct skl_sst
*ctx
= skl
->skl_sst
;
931 sink_mconfig
= w
->priv
;
934 ret
= skl_stop_pipe(ctx
, sink_mconfig
->pipe
);
938 for (i
= 0; i
< sink_mconfig
->max_in_queue
; i
++) {
939 if (sink_mconfig
->m_in_pin
[i
].pin_state
== SKL_PIN_BIND_DONE
) {
940 src_mconfig
= sink_mconfig
->m_in_pin
[i
].tgt_mcfg
;
944 * If path_found == 1, that means pmd for source
945 * pipe has not occurred, source is connected to
946 * some other sink. so its responsibility of sink
947 * to unbind itself from source.
949 ret
= skl_stop_pipe(ctx
, src_mconfig
->pipe
);
953 ret
= skl_unbind_modules(ctx
,
954 src_mconfig
, sink_mconfig
);
962 * in the Post-PMD event of mixer we need to do following:
963 * - Free the mcps used
964 * - Free the mem used
965 * - Unbind the modules within the pipeline
966 * - Delete the pipeline (modules are not required to be explicitly
967 * deleted, pipeline delete is enough here
969 static int skl_tplg_mixer_dapm_post_pmd_event(struct snd_soc_dapm_widget
*w
,
972 struct skl_module_cfg
*mconfig
= w
->priv
;
973 struct skl_pipe_module
*w_module
;
974 struct skl_module_cfg
*src_module
= NULL
, *dst_module
;
975 struct skl_sst
*ctx
= skl
->skl_sst
;
976 struct skl_pipe
*s_pipe
= mconfig
->pipe
;
979 if (s_pipe
->state
== SKL_PIPE_INVALID
)
982 skl_tplg_free_pipe_mcps(skl
, mconfig
);
983 skl_tplg_free_pipe_mem(skl
, mconfig
);
985 list_for_each_entry(w_module
, &s_pipe
->w_list
, node
) {
986 dst_module
= w_module
->w
->priv
;
988 if (mconfig
->m_state
>= SKL_MODULE_INIT_DONE
)
989 skl_tplg_free_pipe_mcps(skl
, dst_module
);
990 if (src_module
== NULL
) {
991 src_module
= dst_module
;
995 skl_unbind_modules(ctx
, src_module
, dst_module
);
996 src_module
= dst_module
;
999 ret
= skl_delete_pipe(ctx
, mconfig
->pipe
);
1001 return skl_tplg_unload_pipe_modules(ctx
, s_pipe
);
1005 * in the Post-PMD event of PGA we need to do following:
1006 * - Free the mcps used
1007 * - Stop the pipeline
1008 * - In source pipe is connected, unbind with source pipelines
1010 static int skl_tplg_pga_dapm_post_pmd_event(struct snd_soc_dapm_widget
*w
,
1013 struct skl_module_cfg
*src_mconfig
, *sink_mconfig
;
1015 struct skl_sst
*ctx
= skl
->skl_sst
;
1017 src_mconfig
= w
->priv
;
1019 /* Stop the pipe since this is a mixin module */
1020 ret
= skl_stop_pipe(ctx
, src_mconfig
->pipe
);
1024 for (i
= 0; i
< src_mconfig
->max_out_queue
; i
++) {
1025 if (src_mconfig
->m_out_pin
[i
].pin_state
== SKL_PIN_BIND_DONE
) {
1026 sink_mconfig
= src_mconfig
->m_out_pin
[i
].tgt_mcfg
;
1030 * This is a connecter and if path is found that means
1031 * unbind between source and sink has not happened yet
1033 ret
= skl_unbind_modules(ctx
, src_mconfig
,
1042 * In modelling, we assume there will be ONLY one mixer in a pipeline. If
1043 * mixer is not required then it is treated as static mixer aka vmixer with
1044 * a hard path to source module
1045 * So we don't need to check if source is started or not as hard path puts
1046 * dependency on each other
1048 static int skl_tplg_vmixer_event(struct snd_soc_dapm_widget
*w
,
1049 struct snd_kcontrol
*k
, int event
)
1051 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
1052 struct skl
*skl
= get_skl_ctx(dapm
->dev
);
1055 case SND_SOC_DAPM_PRE_PMU
:
1056 return skl_tplg_mixer_dapm_pre_pmu_event(w
, skl
);
1058 case SND_SOC_DAPM_POST_PMU
:
1059 return skl_tplg_mixer_dapm_post_pmu_event(w
, skl
);
1061 case SND_SOC_DAPM_PRE_PMD
:
1062 return skl_tplg_mixer_dapm_pre_pmd_event(w
, skl
);
1064 case SND_SOC_DAPM_POST_PMD
:
1065 return skl_tplg_mixer_dapm_post_pmd_event(w
, skl
);
1072 * In modelling, we assume there will be ONLY one mixer in a pipeline. If a
1073 * second one is required that is created as another pipe entity.
1074 * The mixer is responsible for pipe management and represent a pipeline
1077 static int skl_tplg_mixer_event(struct snd_soc_dapm_widget
*w
,
1078 struct snd_kcontrol
*k
, int event
)
1080 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
1081 struct skl
*skl
= get_skl_ctx(dapm
->dev
);
1084 case SND_SOC_DAPM_PRE_PMU
:
1085 return skl_tplg_mixer_dapm_pre_pmu_event(w
, skl
);
1087 case SND_SOC_DAPM_POST_PMU
:
1088 return skl_tplg_mixer_dapm_post_pmu_event(w
, skl
);
1090 case SND_SOC_DAPM_PRE_PMD
:
1091 return skl_tplg_mixer_dapm_pre_pmd_event(w
, skl
);
1093 case SND_SOC_DAPM_POST_PMD
:
1094 return skl_tplg_mixer_dapm_post_pmd_event(w
, skl
);
1101 * In modelling, we assumed rest of the modules in pipeline are PGA. But we
1102 * are interested in last PGA (leaf PGA) in a pipeline to disconnect with
1103 * the sink when it is running (two FE to one BE or one FE to two BE)
1106 static int skl_tplg_pga_event(struct snd_soc_dapm_widget
*w
,
1107 struct snd_kcontrol
*k
, int event
)
1110 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
1111 struct skl
*skl
= get_skl_ctx(dapm
->dev
);
1114 case SND_SOC_DAPM_PRE_PMU
:
1115 return skl_tplg_pga_dapm_pre_pmu_event(w
, skl
);
1117 case SND_SOC_DAPM_POST_PMD
:
1118 return skl_tplg_pga_dapm_post_pmd_event(w
, skl
);
1124 static int skl_tplg_tlv_control_get(struct snd_kcontrol
*kcontrol
,
1125 unsigned int __user
*data
, unsigned int size
)
1127 struct soc_bytes_ext
*sb
=
1128 (struct soc_bytes_ext
*)kcontrol
->private_value
;
1129 struct skl_algo_data
*bc
= (struct skl_algo_data
*)sb
->dobj
.private;
1130 struct snd_soc_dapm_widget
*w
= snd_soc_dapm_kcontrol_widget(kcontrol
);
1131 struct skl_module_cfg
*mconfig
= w
->priv
;
1132 struct skl
*skl
= get_skl_ctx(w
->dapm
->dev
);
1135 skl_get_module_params(skl
->skl_sst
, (u32
*)bc
->params
,
1136 bc
->size
, bc
->param_id
, mconfig
);
1138 /* decrement size for TLV header */
1139 size
-= 2 * sizeof(u32
);
1141 /* check size as we don't want to send kernel data */
1146 if (copy_to_user(data
, &bc
->param_id
, sizeof(u32
)))
1148 if (copy_to_user(data
+ 1, &size
, sizeof(u32
)))
1150 if (copy_to_user(data
+ 2, bc
->params
, size
))
1157 #define SKL_PARAM_VENDOR_ID 0xff
1159 static int skl_tplg_tlv_control_set(struct snd_kcontrol
*kcontrol
,
1160 const unsigned int __user
*data
, unsigned int size
)
1162 struct snd_soc_dapm_widget
*w
= snd_soc_dapm_kcontrol_widget(kcontrol
);
1163 struct skl_module_cfg
*mconfig
= w
->priv
;
1164 struct soc_bytes_ext
*sb
=
1165 (struct soc_bytes_ext
*)kcontrol
->private_value
;
1166 struct skl_algo_data
*ac
= (struct skl_algo_data
*)sb
->dobj
.private;
1167 struct skl
*skl
= get_skl_ctx(w
->dapm
->dev
);
1175 * if the param_is is of type Vendor, firmware expects actual
1176 * parameter id and size from the control.
1178 if (ac
->param_id
== SKL_PARAM_VENDOR_ID
) {
1179 if (copy_from_user(ac
->params
, data
, size
))
1182 if (copy_from_user(ac
->params
,
1188 return skl_set_module_params(skl
->skl_sst
,
1189 (u32
*)ac
->params
, ac
->size
,
1190 ac
->param_id
, mconfig
);
1197 * Fill the dma id for host and link. In case of passthrough
1198 * pipeline, this will both host and link in the same
1199 * pipeline, so need to copy the link and host based on dev_type
1201 static void skl_tplg_fill_dma_id(struct skl_module_cfg
*mcfg
,
1202 struct skl_pipe_params
*params
)
1204 struct skl_pipe
*pipe
= mcfg
->pipe
;
1206 if (pipe
->passthru
) {
1207 switch (mcfg
->dev_type
) {
1208 case SKL_DEVICE_HDALINK
:
1209 pipe
->p_params
->link_dma_id
= params
->link_dma_id
;
1212 case SKL_DEVICE_HDAHOST
:
1213 pipe
->p_params
->host_dma_id
= params
->host_dma_id
;
1219 pipe
->p_params
->s_fmt
= params
->s_fmt
;
1220 pipe
->p_params
->ch
= params
->ch
;
1221 pipe
->p_params
->s_freq
= params
->s_freq
;
1222 pipe
->p_params
->stream
= params
->stream
;
1225 memcpy(pipe
->p_params
, params
, sizeof(*params
));
1230 * The FE params are passed by hw_params of the DAI.
1231 * On hw_params, the params are stored in Gateway module of the FE and we
1232 * need to calculate the format in DSP module configuration, that
1233 * conversion is done here
1235 int skl_tplg_update_pipe_params(struct device
*dev
,
1236 struct skl_module_cfg
*mconfig
,
1237 struct skl_pipe_params
*params
)
1239 struct skl_module_fmt
*format
= NULL
;
1241 skl_tplg_fill_dma_id(mconfig
, params
);
1243 if (params
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
1244 format
= &mconfig
->in_fmt
[0];
1246 format
= &mconfig
->out_fmt
[0];
1248 /* set the hw_params */
1249 format
->s_freq
= params
->s_freq
;
1250 format
->channels
= params
->ch
;
1251 format
->valid_bit_depth
= skl_get_bit_depth(params
->s_fmt
);
1254 * 16 bit is 16 bit container whereas 24 bit is in 32 bit
1255 * container so update bit depth accordingly
1257 switch (format
->valid_bit_depth
) {
1258 case SKL_DEPTH_16BIT
:
1259 format
->bit_depth
= format
->valid_bit_depth
;
1262 case SKL_DEPTH_24BIT
:
1263 case SKL_DEPTH_32BIT
:
1264 format
->bit_depth
= SKL_DEPTH_32BIT
;
1268 dev_err(dev
, "Invalid bit depth %x for pipe\n",
1269 format
->valid_bit_depth
);
1273 if (params
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
1274 mconfig
->ibs
= (format
->s_freq
/ 1000) *
1275 (format
->channels
) *
1276 (format
->bit_depth
>> 3);
1278 mconfig
->obs
= (format
->s_freq
/ 1000) *
1279 (format
->channels
) *
1280 (format
->bit_depth
>> 3);
1287 * Query the module config for the FE DAI
1288 * This is used to find the hw_params set for that DAI and apply to FE
1291 struct skl_module_cfg
*
1292 skl_tplg_fe_get_cpr_module(struct snd_soc_dai
*dai
, int stream
)
1294 struct snd_soc_dapm_widget
*w
;
1295 struct snd_soc_dapm_path
*p
= NULL
;
1297 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
1298 w
= dai
->playback_widget
;
1299 snd_soc_dapm_widget_for_each_sink_path(w
, p
) {
1300 if (p
->connect
&& p
->sink
->power
&&
1301 !is_skl_dsp_widget_type(p
->sink
))
1304 if (p
->sink
->priv
) {
1305 dev_dbg(dai
->dev
, "set params for %s\n",
1307 return p
->sink
->priv
;
1311 w
= dai
->capture_widget
;
1312 snd_soc_dapm_widget_for_each_source_path(w
, p
) {
1313 if (p
->connect
&& p
->source
->power
&&
1314 !is_skl_dsp_widget_type(p
->source
))
1317 if (p
->source
->priv
) {
1318 dev_dbg(dai
->dev
, "set params for %s\n",
1320 return p
->source
->priv
;
1328 static struct skl_module_cfg
*skl_get_mconfig_pb_cpr(
1329 struct snd_soc_dai
*dai
, struct snd_soc_dapm_widget
*w
)
1331 struct snd_soc_dapm_path
*p
;
1332 struct skl_module_cfg
*mconfig
= NULL
;
1334 snd_soc_dapm_widget_for_each_source_path(w
, p
) {
1335 if (w
->endpoints
[SND_SOC_DAPM_DIR_OUT
] > 0) {
1337 (p
->sink
->id
== snd_soc_dapm_aif_out
) &&
1339 mconfig
= p
->source
->priv
;
1342 mconfig
= skl_get_mconfig_pb_cpr(dai
, p
->source
);
1350 static struct skl_module_cfg
*skl_get_mconfig_cap_cpr(
1351 struct snd_soc_dai
*dai
, struct snd_soc_dapm_widget
*w
)
1353 struct snd_soc_dapm_path
*p
;
1354 struct skl_module_cfg
*mconfig
= NULL
;
1356 snd_soc_dapm_widget_for_each_sink_path(w
, p
) {
1357 if (w
->endpoints
[SND_SOC_DAPM_DIR_IN
] > 0) {
1359 (p
->source
->id
== snd_soc_dapm_aif_in
) &&
1361 mconfig
= p
->sink
->priv
;
1364 mconfig
= skl_get_mconfig_cap_cpr(dai
, p
->sink
);
1372 struct skl_module_cfg
*
1373 skl_tplg_be_get_cpr_module(struct snd_soc_dai
*dai
, int stream
)
1375 struct snd_soc_dapm_widget
*w
;
1376 struct skl_module_cfg
*mconfig
;
1378 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
1379 w
= dai
->playback_widget
;
1380 mconfig
= skl_get_mconfig_pb_cpr(dai
, w
);
1382 w
= dai
->capture_widget
;
1383 mconfig
= skl_get_mconfig_cap_cpr(dai
, w
);
1388 static u8
skl_tplg_be_link_type(int dev_type
)
1394 ret
= NHLT_LINK_SSP
;
1397 case SKL_DEVICE_DMIC
:
1398 ret
= NHLT_LINK_DMIC
;
1401 case SKL_DEVICE_I2S
:
1402 ret
= NHLT_LINK_SSP
;
1405 case SKL_DEVICE_HDALINK
:
1406 ret
= NHLT_LINK_HDA
;
1410 ret
= NHLT_LINK_INVALID
;
1418 * Fill the BE gateway parameters
1419 * The BE gateway expects a blob of parameters which are kept in the ACPI
1420 * NHLT blob, so query the blob for interface type (i2s/pdm) and instance.
1421 * The port can have multiple settings so pick based on the PCM
1424 static int skl_tplg_be_fill_pipe_params(struct snd_soc_dai
*dai
,
1425 struct skl_module_cfg
*mconfig
,
1426 struct skl_pipe_params
*params
)
1428 struct nhlt_specific_cfg
*cfg
;
1429 struct skl
*skl
= get_skl_ctx(dai
->dev
);
1430 int link_type
= skl_tplg_be_link_type(mconfig
->dev_type
);
1432 skl_tplg_fill_dma_id(mconfig
, params
);
1434 if (link_type
== NHLT_LINK_HDA
)
1437 /* update the blob based on virtual bus_id*/
1438 cfg
= skl_get_ep_blob(skl
, mconfig
->vbus_id
, link_type
,
1439 params
->s_fmt
, params
->ch
,
1440 params
->s_freq
, params
->stream
);
1442 mconfig
->formats_config
.caps_size
= cfg
->size
;
1443 mconfig
->formats_config
.caps
= (u32
*) &cfg
->caps
;
1445 dev_err(dai
->dev
, "Blob NULL for id %x type %d dirn %d\n",
1446 mconfig
->vbus_id
, link_type
,
1448 dev_err(dai
->dev
, "PCM: ch %d, freq %d, fmt %d\n",
1449 params
->ch
, params
->s_freq
, params
->s_fmt
);
1456 static int skl_tplg_be_set_src_pipe_params(struct snd_soc_dai
*dai
,
1457 struct snd_soc_dapm_widget
*w
,
1458 struct skl_pipe_params
*params
)
1460 struct snd_soc_dapm_path
*p
;
1463 snd_soc_dapm_widget_for_each_source_path(w
, p
) {
1464 if (p
->connect
&& is_skl_dsp_widget_type(p
->source
) &&
1467 ret
= skl_tplg_be_fill_pipe_params(dai
,
1468 p
->source
->priv
, params
);
1472 ret
= skl_tplg_be_set_src_pipe_params(dai
,
1482 static int skl_tplg_be_set_sink_pipe_params(struct snd_soc_dai
*dai
,
1483 struct snd_soc_dapm_widget
*w
, struct skl_pipe_params
*params
)
1485 struct snd_soc_dapm_path
*p
= NULL
;
1488 snd_soc_dapm_widget_for_each_sink_path(w
, p
) {
1489 if (p
->connect
&& is_skl_dsp_widget_type(p
->sink
) &&
1492 ret
= skl_tplg_be_fill_pipe_params(dai
,
1493 p
->sink
->priv
, params
);
1497 ret
= skl_tplg_be_set_sink_pipe_params(
1498 dai
, p
->sink
, params
);
1508 * BE hw_params can be a source parameters (capture) or sink parameters
1509 * (playback). Based on sink and source we need to either find the source
1510 * list or the sink list and set the pipeline parameters
1512 int skl_tplg_be_update_params(struct snd_soc_dai
*dai
,
1513 struct skl_pipe_params
*params
)
1515 struct snd_soc_dapm_widget
*w
;
1517 if (params
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
1518 w
= dai
->playback_widget
;
1520 return skl_tplg_be_set_src_pipe_params(dai
, w
, params
);
1523 w
= dai
->capture_widget
;
1525 return skl_tplg_be_set_sink_pipe_params(dai
, w
, params
);
1531 static const struct snd_soc_tplg_widget_events skl_tplg_widget_ops
[] = {
1532 {SKL_MIXER_EVENT
, skl_tplg_mixer_event
},
1533 {SKL_VMIXER_EVENT
, skl_tplg_vmixer_event
},
1534 {SKL_PGA_EVENT
, skl_tplg_pga_event
},
1537 static const struct snd_soc_tplg_bytes_ext_ops skl_tlv_ops
[] = {
1538 {SKL_CONTROL_TYPE_BYTE_TLV
, skl_tplg_tlv_control_get
,
1539 skl_tplg_tlv_control_set
},
1542 static int skl_tplg_fill_pipe_tkn(struct device
*dev
,
1543 struct skl_pipe
*pipe
, u32 tkn
,
1548 case SKL_TKN_U32_PIPE_CONN_TYPE
:
1549 pipe
->conn_type
= tkn_val
;
1552 case SKL_TKN_U32_PIPE_PRIORITY
:
1553 pipe
->pipe_priority
= tkn_val
;
1556 case SKL_TKN_U32_PIPE_MEM_PGS
:
1557 pipe
->memory_pages
= tkn_val
;
1560 case SKL_TKN_U32_PMODE
:
1561 pipe
->lp_mode
= tkn_val
;
1565 dev_err(dev
, "Token not handled %d\n", tkn
);
1573 * Add pipeline by parsing the relevant tokens
1574 * Return an existing pipe if the pipe already exists.
1576 static int skl_tplg_add_pipe(struct device
*dev
,
1577 struct skl_module_cfg
*mconfig
, struct skl
*skl
,
1578 struct snd_soc_tplg_vendor_value_elem
*tkn_elem
)
1580 struct skl_pipeline
*ppl
;
1581 struct skl_pipe
*pipe
;
1582 struct skl_pipe_params
*params
;
1584 list_for_each_entry(ppl
, &skl
->ppl_list
, node
) {
1585 if (ppl
->pipe
->ppl_id
== tkn_elem
->value
) {
1586 mconfig
->pipe
= ppl
->pipe
;
1591 ppl
= devm_kzalloc(dev
, sizeof(*ppl
), GFP_KERNEL
);
1595 pipe
= devm_kzalloc(dev
, sizeof(*pipe
), GFP_KERNEL
);
1599 params
= devm_kzalloc(dev
, sizeof(*params
), GFP_KERNEL
);
1603 pipe
->p_params
= params
;
1604 pipe
->ppl_id
= tkn_elem
->value
;
1605 INIT_LIST_HEAD(&pipe
->w_list
);
1608 list_add(&ppl
->node
, &skl
->ppl_list
);
1610 mconfig
->pipe
= pipe
;
1611 mconfig
->pipe
->state
= SKL_PIPE_INVALID
;
1616 static int skl_tplg_fill_pin(struct device
*dev
, u32 tkn
,
1617 struct skl_module_pin
*m_pin
,
1618 int pin_index
, u32 value
)
1621 case SKL_TKN_U32_PIN_MOD_ID
:
1622 m_pin
[pin_index
].id
.module_id
= value
;
1625 case SKL_TKN_U32_PIN_INST_ID
:
1626 m_pin
[pin_index
].id
.instance_id
= value
;
1630 dev_err(dev
, "%d Not a pin token\n", value
);
1638 * Parse for pin config specific tokens to fill up the
1639 * module private data
1641 static int skl_tplg_fill_pins_info(struct device
*dev
,
1642 struct skl_module_cfg
*mconfig
,
1643 struct snd_soc_tplg_vendor_value_elem
*tkn_elem
,
1644 int dir
, int pin_count
)
1647 struct skl_module_pin
*m_pin
;
1651 m_pin
= mconfig
->m_in_pin
;
1655 m_pin
= mconfig
->m_out_pin
;
1659 dev_err(dev
, "Invalid direction value\n");
1663 ret
= skl_tplg_fill_pin(dev
, tkn_elem
->token
,
1664 m_pin
, pin_count
, tkn_elem
->value
);
1669 m_pin
[pin_count
].in_use
= false;
1670 m_pin
[pin_count
].pin_state
= SKL_PIN_UNBIND
;
1676 * Fill up input/output module config format based
1679 static int skl_tplg_fill_fmt(struct device
*dev
,
1680 struct skl_module_cfg
*mconfig
, u32 tkn
,
1681 u32 value
, u32 dir
, u32 pin_count
)
1683 struct skl_module_fmt
*dst_fmt
;
1687 dst_fmt
= mconfig
->in_fmt
;
1688 dst_fmt
+= pin_count
;
1692 dst_fmt
= mconfig
->out_fmt
;
1693 dst_fmt
+= pin_count
;
1697 dev_err(dev
, "Invalid direction value\n");
1702 case SKL_TKN_U32_FMT_CH
:
1703 dst_fmt
->channels
= value
;
1706 case SKL_TKN_U32_FMT_FREQ
:
1707 dst_fmt
->s_freq
= value
;
1710 case SKL_TKN_U32_FMT_BIT_DEPTH
:
1711 dst_fmt
->bit_depth
= value
;
1714 case SKL_TKN_U32_FMT_SAMPLE_SIZE
:
1715 dst_fmt
->valid_bit_depth
= value
;
1718 case SKL_TKN_U32_FMT_CH_CONFIG
:
1719 dst_fmt
->ch_cfg
= value
;
1722 case SKL_TKN_U32_FMT_INTERLEAVE
:
1723 dst_fmt
->interleaving_style
= value
;
1726 case SKL_TKN_U32_FMT_SAMPLE_TYPE
:
1727 dst_fmt
->sample_type
= value
;
1730 case SKL_TKN_U32_FMT_CH_MAP
:
1731 dst_fmt
->ch_map
= value
;
1735 dev_err(dev
, "Invalid token %d\n", tkn
);
1742 static int skl_tplg_get_uuid(struct device
*dev
, struct skl_module_cfg
*mconfig
,
1743 struct snd_soc_tplg_vendor_uuid_elem
*uuid_tkn
)
1745 if (uuid_tkn
->token
== SKL_TKN_UUID
)
1746 memcpy(&mconfig
->guid
, &uuid_tkn
->uuid
, 16);
1748 dev_err(dev
, "Not an UUID token tkn %d\n", uuid_tkn
->token
);
1755 static void skl_tplg_fill_pin_dynamic_val(
1756 struct skl_module_pin
*mpin
, u32 pin_count
, u32 value
)
1760 for (i
= 0; i
< pin_count
; i
++)
1761 mpin
[i
].is_dynamic
= value
;
1765 * Parse tokens to fill up the module private data
1767 static int skl_tplg_get_token(struct device
*dev
,
1768 struct snd_soc_tplg_vendor_value_elem
*tkn_elem
,
1769 struct skl
*skl
, struct skl_module_cfg
*mconfig
)
1773 static int is_pipe_exists
;
1774 static int pin_index
, dir
;
1776 if (tkn_elem
->token
> SKL_TKN_MAX
)
1779 switch (tkn_elem
->token
) {
1780 case SKL_TKN_U8_IN_QUEUE_COUNT
:
1781 mconfig
->max_in_queue
= tkn_elem
->value
;
1782 mconfig
->m_in_pin
= devm_kzalloc(dev
, mconfig
->max_in_queue
*
1783 sizeof(*mconfig
->m_in_pin
),
1785 if (!mconfig
->m_in_pin
)
1790 case SKL_TKN_U8_OUT_QUEUE_COUNT
:
1791 mconfig
->max_out_queue
= tkn_elem
->value
;
1792 mconfig
->m_out_pin
= devm_kzalloc(dev
, mconfig
->max_out_queue
*
1793 sizeof(*mconfig
->m_out_pin
),
1796 if (!mconfig
->m_out_pin
)
1801 case SKL_TKN_U8_DYN_IN_PIN
:
1802 if (!mconfig
->m_in_pin
)
1805 skl_tplg_fill_pin_dynamic_val(mconfig
->m_in_pin
,
1806 mconfig
->max_in_queue
, tkn_elem
->value
);
1810 case SKL_TKN_U8_DYN_OUT_PIN
:
1811 if (!mconfig
->m_out_pin
)
1814 skl_tplg_fill_pin_dynamic_val(mconfig
->m_out_pin
,
1815 mconfig
->max_out_queue
, tkn_elem
->value
);
1819 case SKL_TKN_U8_TIME_SLOT
:
1820 mconfig
->time_slot
= tkn_elem
->value
;
1823 case SKL_TKN_U8_CORE_ID
:
1824 mconfig
->core_id
= tkn_elem
->value
;
1826 case SKL_TKN_U8_MOD_TYPE
:
1827 mconfig
->m_type
= tkn_elem
->value
;
1830 case SKL_TKN_U8_DEV_TYPE
:
1831 mconfig
->dev_type
= tkn_elem
->value
;
1834 case SKL_TKN_U8_HW_CONN_TYPE
:
1835 mconfig
->hw_conn_type
= tkn_elem
->value
;
1838 case SKL_TKN_U16_MOD_INST_ID
:
1839 mconfig
->id
.instance_id
=
1843 case SKL_TKN_U32_MEM_PAGES
:
1844 mconfig
->mem_pages
= tkn_elem
->value
;
1847 case SKL_TKN_U32_MAX_MCPS
:
1848 mconfig
->mcps
= tkn_elem
->value
;
1851 case SKL_TKN_U32_OBS
:
1852 mconfig
->obs
= tkn_elem
->value
;
1855 case SKL_TKN_U32_IBS
:
1856 mconfig
->ibs
= tkn_elem
->value
;
1859 case SKL_TKN_U32_VBUS_ID
:
1860 mconfig
->vbus_id
= tkn_elem
->value
;
1863 case SKL_TKN_U32_PARAMS_FIXUP
:
1864 mconfig
->params_fixup
= tkn_elem
->value
;
1867 case SKL_TKN_U32_CONVERTER
:
1868 mconfig
->converter
= tkn_elem
->value
;
1871 case SKL_TKL_U32_D0I3_CAPS
:
1872 mconfig
->d0i3_caps
= tkn_elem
->value
;
1875 case SKL_TKN_U32_PIPE_ID
:
1876 ret
= skl_tplg_add_pipe(dev
,
1877 mconfig
, skl
, tkn_elem
);
1880 return is_pipe_exists
;
1887 case SKL_TKN_U32_PIPE_CONN_TYPE
:
1888 case SKL_TKN_U32_PIPE_PRIORITY
:
1889 case SKL_TKN_U32_PIPE_MEM_PGS
:
1890 case SKL_TKN_U32_PMODE
:
1891 if (is_pipe_exists
) {
1892 ret
= skl_tplg_fill_pipe_tkn(dev
, mconfig
->pipe
,
1893 tkn_elem
->token
, tkn_elem
->value
);
1901 * SKL_TKN_U32_DIR_PIN_COUNT token has the value for both
1902 * direction and the pin count. The first four bits represent
1903 * direction and next four the pin count.
1905 case SKL_TKN_U32_DIR_PIN_COUNT
:
1906 dir
= tkn_elem
->value
& SKL_IN_DIR_BIT_MASK
;
1907 pin_index
= (tkn_elem
->value
&
1908 SKL_PIN_COUNT_MASK
) >> 4;
1912 case SKL_TKN_U32_FMT_CH
:
1913 case SKL_TKN_U32_FMT_FREQ
:
1914 case SKL_TKN_U32_FMT_BIT_DEPTH
:
1915 case SKL_TKN_U32_FMT_SAMPLE_SIZE
:
1916 case SKL_TKN_U32_FMT_CH_CONFIG
:
1917 case SKL_TKN_U32_FMT_INTERLEAVE
:
1918 case SKL_TKN_U32_FMT_SAMPLE_TYPE
:
1919 case SKL_TKN_U32_FMT_CH_MAP
:
1920 ret
= skl_tplg_fill_fmt(dev
, mconfig
, tkn_elem
->token
,
1921 tkn_elem
->value
, dir
, pin_index
);
1928 case SKL_TKN_U32_PIN_MOD_ID
:
1929 case SKL_TKN_U32_PIN_INST_ID
:
1930 ret
= skl_tplg_fill_pins_info(dev
,
1931 mconfig
, tkn_elem
, dir
,
1938 case SKL_TKN_U32_CAPS_SIZE
:
1939 mconfig
->formats_config
.caps_size
=
1944 case SKL_TKN_U32_PROC_DOMAIN
:
1950 case SKL_TKN_U8_IN_PIN_TYPE
:
1951 case SKL_TKN_U8_OUT_PIN_TYPE
:
1952 case SKL_TKN_U8_CONN_TYPE
:
1956 dev_err(dev
, "Token %d not handled\n",
1967 * Parse the vendor array for specific tokens to construct
1968 * module private data
1970 static int skl_tplg_get_tokens(struct device
*dev
,
1971 char *pvt_data
, struct skl
*skl
,
1972 struct skl_module_cfg
*mconfig
, int block_size
)
1974 struct snd_soc_tplg_vendor_array
*array
;
1975 struct snd_soc_tplg_vendor_value_elem
*tkn_elem
;
1976 int tkn_count
= 0, ret
;
1977 int off
= 0, tuple_size
= 0;
1979 if (block_size
<= 0)
1982 while (tuple_size
< block_size
) {
1983 array
= (struct snd_soc_tplg_vendor_array
*)(pvt_data
+ off
);
1987 switch (array
->type
) {
1988 case SND_SOC_TPLG_TUPLE_TYPE_STRING
:
1989 dev_warn(dev
, "no string tokens expected for skl tplg\n");
1992 case SND_SOC_TPLG_TUPLE_TYPE_UUID
:
1993 ret
= skl_tplg_get_uuid(dev
, mconfig
, array
->uuid
);
1997 tuple_size
+= sizeof(*array
->uuid
);
2002 tkn_elem
= array
->value
;
2007 while (tkn_count
<= (array
->num_elems
- 1)) {
2008 ret
= skl_tplg_get_token(dev
, tkn_elem
,
2014 tkn_count
= tkn_count
+ ret
;
2018 tuple_size
+= tkn_count
* sizeof(*tkn_elem
);
2025 * Every data block is preceded by a descriptor to read the number
2026 * of data blocks, they type of the block and it's size
2028 static int skl_tplg_get_desc_blocks(struct device
*dev
,
2029 struct snd_soc_tplg_vendor_array
*array
)
2031 struct snd_soc_tplg_vendor_value_elem
*tkn_elem
;
2033 tkn_elem
= array
->value
;
2035 switch (tkn_elem
->token
) {
2036 case SKL_TKN_U8_NUM_BLOCKS
:
2037 case SKL_TKN_U8_BLOCK_TYPE
:
2038 case SKL_TKN_U16_BLOCK_SIZE
:
2039 return tkn_elem
->value
;
2042 dev_err(dev
, "Invalid descriptor token %d\n", tkn_elem
->token
);
2050 * Parse the private data for the token and corresponding value.
2051 * The private data can have multiple data blocks. So, a data block
2052 * is preceded by a descriptor for number of blocks and a descriptor
2053 * for the type and size of the suceeding data block.
2055 static int skl_tplg_get_pvt_data(struct snd_soc_tplg_dapm_widget
*tplg_w
,
2056 struct skl
*skl
, struct device
*dev
,
2057 struct skl_module_cfg
*mconfig
)
2059 struct snd_soc_tplg_vendor_array
*array
;
2060 int num_blocks
, block_size
= 0, block_type
, off
= 0;
2064 /* Read the NUM_DATA_BLOCKS descriptor */
2065 array
= (struct snd_soc_tplg_vendor_array
*)tplg_w
->priv
.data
;
2066 ret
= skl_tplg_get_desc_blocks(dev
, array
);
2072 array
= (struct snd_soc_tplg_vendor_array
*)(tplg_w
->priv
.data
+ off
);
2074 /* Read the BLOCK_TYPE and BLOCK_SIZE descriptor */
2075 while (num_blocks
> 0) {
2076 ret
= skl_tplg_get_desc_blocks(dev
, array
);
2083 array
= (struct snd_soc_tplg_vendor_array
*)
2084 (tplg_w
->priv
.data
+ off
);
2086 ret
= skl_tplg_get_desc_blocks(dev
, array
);
2093 array
= (struct snd_soc_tplg_vendor_array
*)
2094 (tplg_w
->priv
.data
+ off
);
2096 data
= (tplg_w
->priv
.data
+ off
);
2098 if (block_type
== SKL_TYPE_TUPLE
) {
2099 ret
= skl_tplg_get_tokens(dev
, data
,
2100 skl
, mconfig
, block_size
);
2107 if (mconfig
->formats_config
.caps_size
> 0)
2108 memcpy(mconfig
->formats_config
.caps
, data
,
2109 mconfig
->formats_config
.caps_size
);
2117 static void skl_clear_pin_config(struct snd_soc_platform
*platform
,
2118 struct snd_soc_dapm_widget
*w
)
2121 struct skl_module_cfg
*mconfig
;
2122 struct skl_pipe
*pipe
;
2124 if (!strncmp(w
->dapm
->component
->name
, platform
->component
.name
,
2125 strlen(platform
->component
.name
))) {
2127 pipe
= mconfig
->pipe
;
2128 for (i
= 0; i
< mconfig
->max_in_queue
; i
++) {
2129 mconfig
->m_in_pin
[i
].in_use
= false;
2130 mconfig
->m_in_pin
[i
].pin_state
= SKL_PIN_UNBIND
;
2132 for (i
= 0; i
< mconfig
->max_out_queue
; i
++) {
2133 mconfig
->m_out_pin
[i
].in_use
= false;
2134 mconfig
->m_out_pin
[i
].pin_state
= SKL_PIN_UNBIND
;
2136 pipe
->state
= SKL_PIPE_INVALID
;
2137 mconfig
->m_state
= SKL_MODULE_UNINIT
;
2141 void skl_cleanup_resources(struct skl
*skl
)
2143 struct skl_sst
*ctx
= skl
->skl_sst
;
2144 struct snd_soc_platform
*soc_platform
= skl
->platform
;
2145 struct snd_soc_dapm_widget
*w
;
2146 struct snd_soc_card
*card
;
2148 if (soc_platform
== NULL
)
2151 card
= soc_platform
->component
.card
;
2152 if (!card
|| !card
->instantiated
)
2155 skl
->resource
.mem
= 0;
2156 skl
->resource
.mcps
= 0;
2158 list_for_each_entry(w
, &card
->widgets
, list
) {
2159 if (is_skl_dsp_widget_type(w
) && (w
->priv
!= NULL
))
2160 skl_clear_pin_config(soc_platform
, w
);
2163 skl_clear_module_cnt(ctx
->dsp
);
2167 * Topology core widget load callback
2169 * This is used to save the private data for each widget which gives
2170 * information to the driver about module and pipeline parameters which DSP
2171 * FW expects like ids, resource values, formats etc
2173 static int skl_tplg_widget_load(struct snd_soc_component
*cmpnt
,
2174 struct snd_soc_dapm_widget
*w
,
2175 struct snd_soc_tplg_dapm_widget
*tplg_w
)
2178 struct hdac_ext_bus
*ebus
= snd_soc_component_get_drvdata(cmpnt
);
2179 struct skl
*skl
= ebus_to_skl(ebus
);
2180 struct hdac_bus
*bus
= ebus_to_hbus(ebus
);
2181 struct skl_module_cfg
*mconfig
;
2183 if (!tplg_w
->priv
.size
)
2186 mconfig
= devm_kzalloc(bus
->dev
, sizeof(*mconfig
), GFP_KERNEL
);
2194 * module binary can be loaded later, so set it to query when
2195 * module is load for a use case
2197 mconfig
->id
.module_id
= -1;
2199 /* Parse private data for tuples */
2200 ret
= skl_tplg_get_pvt_data(tplg_w
, skl
, bus
->dev
, mconfig
);
2204 if (tplg_w
->event_type
== 0) {
2205 dev_dbg(bus
->dev
, "ASoC: No event handler required\n");
2209 ret
= snd_soc_tplg_widget_bind_event(w
, skl_tplg_widget_ops
,
2210 ARRAY_SIZE(skl_tplg_widget_ops
),
2211 tplg_w
->event_type
);
2214 dev_err(bus
->dev
, "%s: No matching event handlers found for %d\n",
2215 __func__
, tplg_w
->event_type
);
2222 static int skl_init_algo_data(struct device
*dev
, struct soc_bytes_ext
*be
,
2223 struct snd_soc_tplg_bytes_control
*bc
)
2225 struct skl_algo_data
*ac
;
2226 struct skl_dfw_algo_data
*dfw_ac
=
2227 (struct skl_dfw_algo_data
*)bc
->priv
.data
;
2229 ac
= devm_kzalloc(dev
, sizeof(*ac
), GFP_KERNEL
);
2233 /* Fill private data */
2234 ac
->max
= dfw_ac
->max
;
2235 ac
->param_id
= dfw_ac
->param_id
;
2236 ac
->set_params
= dfw_ac
->set_params
;
2237 ac
->size
= dfw_ac
->max
;
2240 ac
->params
= (char *) devm_kzalloc(dev
, ac
->max
, GFP_KERNEL
);
2244 memcpy(ac
->params
, dfw_ac
->params
, ac
->max
);
2247 be
->dobj
.private = ac
;
2251 static int skl_tplg_control_load(struct snd_soc_component
*cmpnt
,
2252 struct snd_kcontrol_new
*kctl
,
2253 struct snd_soc_tplg_ctl_hdr
*hdr
)
2255 struct soc_bytes_ext
*sb
;
2256 struct snd_soc_tplg_bytes_control
*tplg_bc
;
2257 struct hdac_ext_bus
*ebus
= snd_soc_component_get_drvdata(cmpnt
);
2258 struct hdac_bus
*bus
= ebus_to_hbus(ebus
);
2260 switch (hdr
->ops
.info
) {
2261 case SND_SOC_TPLG_CTL_BYTES
:
2262 tplg_bc
= container_of(hdr
,
2263 struct snd_soc_tplg_bytes_control
, hdr
);
2264 if (kctl
->access
& SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK
) {
2265 sb
= (struct soc_bytes_ext
*)kctl
->private_value
;
2266 if (tplg_bc
->priv
.size
)
2267 return skl_init_algo_data(
2268 bus
->dev
, sb
, tplg_bc
);
2273 dev_warn(bus
->dev
, "Control load not supported %d:%d:%d\n",
2274 hdr
->ops
.get
, hdr
->ops
.put
, hdr
->ops
.info
);
2281 static int skl_tplg_fill_str_mfest_tkn(struct device
*dev
,
2282 struct snd_soc_tplg_vendor_string_elem
*str_elem
,
2283 struct skl_dfw_manifest
*minfo
)
2286 static int ref_count
;
2288 switch (str_elem
->token
) {
2289 case SKL_TKN_STR_LIB_NAME
:
2290 if (ref_count
> minfo
->lib_count
- 1) {
2295 strncpy(minfo
->lib
[ref_count
].name
, str_elem
->string
,
2296 ARRAY_SIZE(minfo
->lib
[ref_count
].name
));
2302 dev_err(dev
, "Not a string token %d\n", str_elem
->token
);
2309 static int skl_tplg_get_str_tkn(struct device
*dev
,
2310 struct snd_soc_tplg_vendor_array
*array
,
2311 struct skl_dfw_manifest
*minfo
)
2313 int tkn_count
= 0, ret
;
2314 struct snd_soc_tplg_vendor_string_elem
*str_elem
;
2316 str_elem
= (struct snd_soc_tplg_vendor_string_elem
*)array
->value
;
2317 while (tkn_count
< array
->num_elems
) {
2318 ret
= skl_tplg_fill_str_mfest_tkn(dev
, str_elem
, minfo
);
2324 tkn_count
= tkn_count
+ ret
;
2330 static int skl_tplg_get_int_tkn(struct device
*dev
,
2331 struct snd_soc_tplg_vendor_value_elem
*tkn_elem
,
2332 struct skl_dfw_manifest
*minfo
)
2336 switch (tkn_elem
->token
) {
2337 case SKL_TKN_U32_LIB_COUNT
:
2338 minfo
->lib_count
= tkn_elem
->value
;
2343 dev_err(dev
, "Not a manifest token %d\n", tkn_elem
->token
);
2351 * Fill the manifest structure by parsing the tokens based on the
2354 static int skl_tplg_get_manifest_tkn(struct device
*dev
,
2355 char *pvt_data
, struct skl_dfw_manifest
*minfo
,
2358 int tkn_count
= 0, ret
;
2359 int off
= 0, tuple_size
= 0;
2360 struct snd_soc_tplg_vendor_array
*array
;
2361 struct snd_soc_tplg_vendor_value_elem
*tkn_elem
;
2363 if (block_size
<= 0)
2366 while (tuple_size
< block_size
) {
2367 array
= (struct snd_soc_tplg_vendor_array
*)(pvt_data
+ off
);
2369 switch (array
->type
) {
2370 case SND_SOC_TPLG_TUPLE_TYPE_STRING
:
2371 ret
= skl_tplg_get_str_tkn(dev
, array
, minfo
);
2377 tuple_size
+= tkn_count
*
2378 sizeof(struct snd_soc_tplg_vendor_string_elem
);
2381 case SND_SOC_TPLG_TUPLE_TYPE_UUID
:
2382 dev_warn(dev
, "no uuid tokens for skl tplf manifest\n");
2386 tkn_elem
= array
->value
;
2391 while (tkn_count
<= array
->num_elems
- 1) {
2392 ret
= skl_tplg_get_int_tkn(dev
,
2397 tkn_count
= tkn_count
+ ret
;
2399 tuple_size
+= tkn_count
*
2400 sizeof(struct snd_soc_tplg_vendor_value_elem
);
2410 * Parse manifest private data for tokens. The private data block is
2411 * preceded by descriptors for type and size of data block.
2413 static int skl_tplg_get_manifest_data(struct snd_soc_tplg_manifest
*manifest
,
2414 struct device
*dev
, struct skl_dfw_manifest
*minfo
)
2416 struct snd_soc_tplg_vendor_array
*array
;
2417 int num_blocks
, block_size
= 0, block_type
, off
= 0;
2421 /* Read the NUM_DATA_BLOCKS descriptor */
2422 array
= (struct snd_soc_tplg_vendor_array
*)manifest
->priv
.data
;
2423 ret
= skl_tplg_get_desc_blocks(dev
, array
);
2429 array
= (struct snd_soc_tplg_vendor_array
*)
2430 (manifest
->priv
.data
+ off
);
2432 /* Read the BLOCK_TYPE and BLOCK_SIZE descriptor */
2433 while (num_blocks
> 0) {
2434 ret
= skl_tplg_get_desc_blocks(dev
, array
);
2441 array
= (struct snd_soc_tplg_vendor_array
*)
2442 (manifest
->priv
.data
+ off
);
2444 ret
= skl_tplg_get_desc_blocks(dev
, array
);
2451 array
= (struct snd_soc_tplg_vendor_array
*)
2452 (manifest
->priv
.data
+ off
);
2454 data
= (manifest
->priv
.data
+ off
);
2456 if (block_type
== SKL_TYPE_TUPLE
) {
2457 ret
= skl_tplg_get_manifest_tkn(dev
, data
, minfo
,
2472 static int skl_manifest_load(struct snd_soc_component
*cmpnt
,
2473 struct snd_soc_tplg_manifest
*manifest
)
2475 struct skl_dfw_manifest
*minfo
;
2476 struct hdac_ext_bus
*ebus
= snd_soc_component_get_drvdata(cmpnt
);
2477 struct hdac_bus
*bus
= ebus_to_hbus(ebus
);
2478 struct skl
*skl
= ebus_to_skl(ebus
);
2481 /* proceed only if we have private data defined */
2482 if (manifest
->priv
.size
== 0)
2485 minfo
= &skl
->skl_sst
->manifest
;
2487 skl_tplg_get_manifest_data(manifest
, bus
->dev
, minfo
);
2489 if (minfo
->lib_count
> HDA_MAX_LIB
) {
2490 dev_err(bus
->dev
, "Exceeding max Library count. Got:%d\n",
2498 static struct snd_soc_tplg_ops skl_tplg_ops
= {
2499 .widget_load
= skl_tplg_widget_load
,
2500 .control_load
= skl_tplg_control_load
,
2501 .bytes_ext_ops
= skl_tlv_ops
,
2502 .bytes_ext_ops_count
= ARRAY_SIZE(skl_tlv_ops
),
2503 .manifest
= skl_manifest_load
,
2507 * A pipe can have multiple modules, each of them will be a DAPM widget as
2508 * well. While managing a pipeline we need to get the list of all the
2509 * widgets in a pipelines, so this helper - skl_tplg_create_pipe_widget_list()
2510 * helps to get the SKL type widgets in that pipeline
2512 static int skl_tplg_create_pipe_widget_list(struct snd_soc_platform
*platform
)
2514 struct snd_soc_dapm_widget
*w
;
2515 struct skl_module_cfg
*mcfg
= NULL
;
2516 struct skl_pipe_module
*p_module
= NULL
;
2517 struct skl_pipe
*pipe
;
2519 list_for_each_entry(w
, &platform
->component
.card
->widgets
, list
) {
2520 if (is_skl_dsp_widget_type(w
) && w
->priv
!= NULL
) {
2524 p_module
= devm_kzalloc(platform
->dev
,
2525 sizeof(*p_module
), GFP_KERNEL
);
2530 list_add_tail(&p_module
->node
, &pipe
->w_list
);
2537 static void skl_tplg_set_pipe_type(struct skl
*skl
, struct skl_pipe
*pipe
)
2539 struct skl_pipe_module
*w_module
;
2540 struct snd_soc_dapm_widget
*w
;
2541 struct skl_module_cfg
*mconfig
;
2542 bool host_found
= false, link_found
= false;
2544 list_for_each_entry(w_module
, &pipe
->w_list
, node
) {
2548 if (mconfig
->dev_type
== SKL_DEVICE_HDAHOST
)
2550 else if (mconfig
->dev_type
!= SKL_DEVICE_NONE
)
2554 if (host_found
&& link_found
)
2555 pipe
->passthru
= true;
2557 pipe
->passthru
= false;
2560 /* This will be read from topology manifest, currently defined here */
2561 #define SKL_MAX_MCPS 30000000
2562 #define SKL_FW_MAX_MEM 1000000
2565 * SKL topology init routine
2567 int skl_tplg_init(struct snd_soc_platform
*platform
, struct hdac_ext_bus
*ebus
)
2570 const struct firmware
*fw
;
2571 struct hdac_bus
*bus
= ebus_to_hbus(ebus
);
2572 struct skl
*skl
= ebus_to_skl(ebus
);
2573 struct skl_pipeline
*ppl
;
2575 ret
= request_firmware(&fw
, skl
->tplg_name
, bus
->dev
);
2577 dev_err(bus
->dev
, "tplg fw %s load failed with %d\n",
2578 skl
->tplg_name
, ret
);
2579 ret
= request_firmware(&fw
, "dfw_sst.bin", bus
->dev
);
2581 dev_err(bus
->dev
, "Fallback tplg fw %s load failed with %d\n",
2582 "dfw_sst.bin", ret
);
2588 * The complete tplg for SKL is loaded as index 0, we don't use
2591 ret
= snd_soc_tplg_component_load(&platform
->component
,
2592 &skl_tplg_ops
, fw
, 0);
2594 dev_err(bus
->dev
, "tplg component load failed%d\n", ret
);
2595 release_firmware(fw
);
2599 skl
->resource
.max_mcps
= SKL_MAX_MCPS
;
2600 skl
->resource
.max_mem
= SKL_FW_MAX_MEM
;
2603 ret
= skl_tplg_create_pipe_widget_list(platform
);
2607 list_for_each_entry(ppl
, &skl
->ppl_list
, node
)
2608 skl_tplg_set_pipe_type(skl
, ppl
->pipe
);