1 // SPDX-License-Identifier: GPL-2.0-only
3 * skl-topology.c - Implements Platform component ALSA controls/widget
6 * Copyright (C) 2014-2015 Intel Corp
7 * Author: Jeeja KP <jeeja.kp@intel.com>
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11 #include <linux/slab.h>
12 #include <linux/types.h>
13 #include <linux/firmware.h>
14 #include <linux/uuid.h>
15 #include <sound/intel-nhlt.h>
16 #include <sound/soc.h>
17 #include <sound/soc-topology.h>
18 #include <uapi/sound/snd_sst_tokens.h>
19 #include <uapi/sound/skl-tplg-interface.h>
20 #include "skl-sst-dsp.h"
21 #include "skl-sst-ipc.h"
22 #include "skl-topology.h"
24 #include "../common/sst-dsp.h"
25 #include "../common/sst-dsp-priv.h"
27 #define SKL_CH_FIXUP_MASK (1 << 0)
28 #define SKL_RATE_FIXUP_MASK (1 << 1)
29 #define SKL_FMT_FIXUP_MASK (1 << 2)
30 #define SKL_IN_DIR_BIT_MASK BIT(0)
31 #define SKL_PIN_COUNT_MASK GENMASK(7, 4)
33 static const int mic_mono_list
[] = {
36 static const int mic_stereo_list
[][SKL_CH_STEREO
] = {
37 {0, 1}, {0, 2}, {0, 3}, {1, 2}, {1, 3}, {2, 3},
39 static const int mic_trio_list
[][SKL_CH_TRIO
] = {
40 {0, 1, 2}, {0, 1, 3}, {0, 2, 3}, {1, 2, 3},
42 static const int mic_quatro_list
[][SKL_CH_QUATRO
] = {
46 #define CHECK_HW_PARAMS(ch, freq, bps, prm_ch, prm_freq, prm_bps) \
47 ((ch == prm_ch) && (bps == prm_bps) && (freq == prm_freq))
49 void skl_tplg_d0i3_get(struct skl_dev
*skl
, enum d0i3_capability caps
)
51 struct skl_d0i3_data
*d0i3
= &skl
->d0i3
;
58 case SKL_D0I3_STREAMING
:
62 case SKL_D0I3_NON_STREAMING
:
63 d0i3
->non_streaming
++;
68 void skl_tplg_d0i3_put(struct skl_dev
*skl
, enum d0i3_capability caps
)
70 struct skl_d0i3_data
*d0i3
= &skl
->d0i3
;
77 case SKL_D0I3_STREAMING
:
81 case SKL_D0I3_NON_STREAMING
:
82 d0i3
->non_streaming
--;
88 * SKL DSP driver modelling uses only few DAPM widgets so for rest we will
89 * ignore. This helpers checks if the SKL driver handles this widget type
91 static int is_skl_dsp_widget_type(struct snd_soc_dapm_widget
*w
,
94 if (w
->dapm
->dev
!= dev
)
98 case snd_soc_dapm_dai_link
:
99 case snd_soc_dapm_dai_in
:
100 case snd_soc_dapm_aif_in
:
101 case snd_soc_dapm_aif_out
:
102 case snd_soc_dapm_dai_out
:
103 case snd_soc_dapm_switch
:
104 case snd_soc_dapm_output
:
105 case snd_soc_dapm_mux
:
113 static void skl_dump_mconfig(struct skl_dev
*skl
, struct skl_module_cfg
*mcfg
)
115 struct skl_module_iface
*iface
= &mcfg
->module
->formats
[0];
117 dev_dbg(skl
->dev
, "Dumping config\n");
118 dev_dbg(skl
->dev
, "Input Format:\n");
119 dev_dbg(skl
->dev
, "channels = %d\n", iface
->inputs
[0].fmt
.channels
);
120 dev_dbg(skl
->dev
, "s_freq = %d\n", iface
->inputs
[0].fmt
.s_freq
);
121 dev_dbg(skl
->dev
, "ch_cfg = %d\n", iface
->inputs
[0].fmt
.ch_cfg
);
122 dev_dbg(skl
->dev
, "valid bit depth = %d\n",
123 iface
->inputs
[0].fmt
.valid_bit_depth
);
124 dev_dbg(skl
->dev
, "Output Format:\n");
125 dev_dbg(skl
->dev
, "channels = %d\n", iface
->outputs
[0].fmt
.channels
);
126 dev_dbg(skl
->dev
, "s_freq = %d\n", iface
->outputs
[0].fmt
.s_freq
);
127 dev_dbg(skl
->dev
, "valid bit depth = %d\n",
128 iface
->outputs
[0].fmt
.valid_bit_depth
);
129 dev_dbg(skl
->dev
, "ch_cfg = %d\n", iface
->outputs
[0].fmt
.ch_cfg
);
132 static void skl_tplg_update_chmap(struct skl_module_fmt
*fmt
, int chs
)
134 int slot_map
= 0xFFFFFFFF;
138 for (i
= 0; i
< chs
; i
++) {
140 * For 2 channels with starting slot as 0, slot map will
141 * look like 0xFFFFFF10.
143 slot_map
&= (~(0xF << (4 * i
)) | (start_slot
<< (4 * i
)));
146 fmt
->ch_map
= slot_map
;
149 static void skl_tplg_update_params(struct skl_module_fmt
*fmt
,
150 struct skl_pipe_params
*params
, int fixup
)
152 if (fixup
& SKL_RATE_FIXUP_MASK
)
153 fmt
->s_freq
= params
->s_freq
;
154 if (fixup
& SKL_CH_FIXUP_MASK
) {
155 fmt
->channels
= params
->ch
;
156 skl_tplg_update_chmap(fmt
, fmt
->channels
);
158 if (fixup
& SKL_FMT_FIXUP_MASK
) {
159 fmt
->valid_bit_depth
= skl_get_bit_depth(params
->s_fmt
);
162 * 16 bit is 16 bit container whereas 24 bit is in 32 bit
163 * container so update bit depth accordingly
165 switch (fmt
->valid_bit_depth
) {
166 case SKL_DEPTH_16BIT
:
167 fmt
->bit_depth
= fmt
->valid_bit_depth
;
171 fmt
->bit_depth
= SKL_DEPTH_32BIT
;
179 * A pipeline may have modules which impact the pcm parameters, like SRC,
180 * channel converter, format converter.
181 * We need to calculate the output params by applying the 'fixup'
182 * Topology will tell driver which type of fixup is to be applied by
183 * supplying the fixup mask, so based on that we calculate the output
185 * Now In FE the pcm hw_params is source/target format. Same is applicable
186 * for BE with its hw_params invoked.
187 * here based on FE, BE pipeline and direction we calculate the input and
188 * outfix and then apply that for a module
190 static void skl_tplg_update_params_fixup(struct skl_module_cfg
*m_cfg
,
191 struct skl_pipe_params
*params
, bool is_fe
)
193 int in_fixup
, out_fixup
;
194 struct skl_module_fmt
*in_fmt
, *out_fmt
;
196 /* Fixups will be applied to pin 0 only */
197 in_fmt
= &m_cfg
->module
->formats
[0].inputs
[0].fmt
;
198 out_fmt
= &m_cfg
->module
->formats
[0].outputs
[0].fmt
;
200 if (params
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
202 in_fixup
= m_cfg
->params_fixup
;
203 out_fixup
= (~m_cfg
->converter
) &
206 out_fixup
= m_cfg
->params_fixup
;
207 in_fixup
= (~m_cfg
->converter
) &
212 out_fixup
= m_cfg
->params_fixup
;
213 in_fixup
= (~m_cfg
->converter
) &
216 in_fixup
= m_cfg
->params_fixup
;
217 out_fixup
= (~m_cfg
->converter
) &
222 skl_tplg_update_params(in_fmt
, params
, in_fixup
);
223 skl_tplg_update_params(out_fmt
, params
, out_fixup
);
227 * A module needs input and output buffers, which are dependent upon pcm
228 * params, so once we have calculate params, we need buffer calculation as
231 static void skl_tplg_update_buffer_size(struct skl_dev
*skl
,
232 struct skl_module_cfg
*mcfg
)
235 struct skl_module_fmt
*in_fmt
, *out_fmt
;
236 struct skl_module_res
*res
;
238 /* Since fixups is applied to pin 0 only, ibs, obs needs
239 * change for pin 0 only
241 res
= &mcfg
->module
->resources
[0];
242 in_fmt
= &mcfg
->module
->formats
[0].inputs
[0].fmt
;
243 out_fmt
= &mcfg
->module
->formats
[0].outputs
[0].fmt
;
245 if (mcfg
->m_type
== SKL_MODULE_TYPE_SRCINT
)
248 res
->ibs
= DIV_ROUND_UP(in_fmt
->s_freq
, 1000) *
249 in_fmt
->channels
* (in_fmt
->bit_depth
>> 3) *
252 res
->obs
= DIV_ROUND_UP(out_fmt
->s_freq
, 1000) *
253 out_fmt
->channels
* (out_fmt
->bit_depth
>> 3) *
257 static u8
skl_tplg_be_dev_type(int dev_type
)
263 ret
= NHLT_DEVICE_BT
;
266 case SKL_DEVICE_DMIC
:
267 ret
= NHLT_DEVICE_DMIC
;
271 ret
= NHLT_DEVICE_I2S
;
275 ret
= NHLT_DEVICE_INVALID
;
282 static int skl_tplg_update_be_blob(struct snd_soc_dapm_widget
*w
,
285 struct skl_module_cfg
*m_cfg
= w
->priv
;
287 u32 ch
, s_freq
, s_fmt
;
288 struct nhlt_specific_cfg
*cfg
;
289 u8 dev_type
= skl_tplg_be_dev_type(m_cfg
->dev_type
);
290 int fmt_idx
= m_cfg
->fmt_idx
;
291 struct skl_module_iface
*m_iface
= &m_cfg
->module
->formats
[fmt_idx
];
293 /* check if we already have blob */
294 if (m_cfg
->formats_config
.caps_size
> 0)
297 dev_dbg(skl
->dev
, "Applying default cfg blob\n");
298 switch (m_cfg
->dev_type
) {
299 case SKL_DEVICE_DMIC
:
300 link_type
= NHLT_LINK_DMIC
;
301 dir
= SNDRV_PCM_STREAM_CAPTURE
;
302 s_freq
= m_iface
->inputs
[0].fmt
.s_freq
;
303 s_fmt
= m_iface
->inputs
[0].fmt
.bit_depth
;
304 ch
= m_iface
->inputs
[0].fmt
.channels
;
308 link_type
= NHLT_LINK_SSP
;
309 if (m_cfg
->hw_conn_type
== SKL_CONN_SOURCE
) {
310 dir
= SNDRV_PCM_STREAM_PLAYBACK
;
311 s_freq
= m_iface
->outputs
[0].fmt
.s_freq
;
312 s_fmt
= m_iface
->outputs
[0].fmt
.bit_depth
;
313 ch
= m_iface
->outputs
[0].fmt
.channels
;
315 dir
= SNDRV_PCM_STREAM_CAPTURE
;
316 s_freq
= m_iface
->inputs
[0].fmt
.s_freq
;
317 s_fmt
= m_iface
->inputs
[0].fmt
.bit_depth
;
318 ch
= m_iface
->inputs
[0].fmt
.channels
;
326 /* update the blob based on virtual bus_id and default params */
327 cfg
= skl_get_ep_blob(skl
, m_cfg
->vbus_id
, link_type
,
328 s_fmt
, ch
, s_freq
, dir
, dev_type
);
330 m_cfg
->formats_config
.caps_size
= cfg
->size
;
331 m_cfg
->formats_config
.caps
= (u32
*) &cfg
->caps
;
333 dev_err(skl
->dev
, "Blob NULL for id %x type %d dirn %d\n",
334 m_cfg
->vbus_id
, link_type
, dir
);
335 dev_err(skl
->dev
, "PCM: ch %d, freq %d, fmt %d\n",
343 static void skl_tplg_update_module_params(struct snd_soc_dapm_widget
*w
,
346 struct skl_module_cfg
*m_cfg
= w
->priv
;
347 struct skl_pipe_params
*params
= m_cfg
->pipe
->p_params
;
348 int p_conn_type
= m_cfg
->pipe
->conn_type
;
351 if (!m_cfg
->params_fixup
)
354 dev_dbg(skl
->dev
, "Mconfig for widget=%s BEFORE updation\n",
357 skl_dump_mconfig(skl
, m_cfg
);
359 if (p_conn_type
== SKL_PIPE_CONN_TYPE_FE
)
364 skl_tplg_update_params_fixup(m_cfg
, params
, is_fe
);
365 skl_tplg_update_buffer_size(skl
, m_cfg
);
367 dev_dbg(skl
->dev
, "Mconfig for widget=%s AFTER updation\n",
370 skl_dump_mconfig(skl
, m_cfg
);
374 * some modules can have multiple params set from user control and
375 * need to be set after module is initialized. If set_param flag is
376 * set module params will be done after module is initialised.
378 static int skl_tplg_set_module_params(struct snd_soc_dapm_widget
*w
,
382 struct skl_module_cfg
*mconfig
= w
->priv
;
383 const struct snd_kcontrol_new
*k
;
384 struct soc_bytes_ext
*sb
;
385 struct skl_algo_data
*bc
;
386 struct skl_specific_cfg
*sp_cfg
;
388 if (mconfig
->formats_config
.caps_size
> 0 &&
389 mconfig
->formats_config
.set_params
== SKL_PARAM_SET
) {
390 sp_cfg
= &mconfig
->formats_config
;
391 ret
= skl_set_module_params(skl
, sp_cfg
->caps
,
393 sp_cfg
->param_id
, mconfig
);
398 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
399 k
= &w
->kcontrol_news
[i
];
400 if (k
->access
& SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK
) {
401 sb
= (void *) k
->private_value
;
402 bc
= (struct skl_algo_data
*)sb
->dobj
.private;
404 if (bc
->set_params
== SKL_PARAM_SET
) {
405 ret
= skl_set_module_params(skl
,
406 (u32
*)bc
->params
, bc
->size
,
407 bc
->param_id
, mconfig
);
418 * some module param can set from user control and this is required as
419 * when module is initailzed. if module param is required in init it is
420 * identifed by set_param flag. if set_param flag is not set, then this
421 * parameter needs to set as part of module init.
423 static int skl_tplg_set_module_init_data(struct snd_soc_dapm_widget
*w
)
425 const struct snd_kcontrol_new
*k
;
426 struct soc_bytes_ext
*sb
;
427 struct skl_algo_data
*bc
;
428 struct skl_module_cfg
*mconfig
= w
->priv
;
431 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
432 k
= &w
->kcontrol_news
[i
];
433 if (k
->access
& SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK
) {
434 sb
= (struct soc_bytes_ext
*)k
->private_value
;
435 bc
= (struct skl_algo_data
*)sb
->dobj
.private;
437 if (bc
->set_params
!= SKL_PARAM_INIT
)
440 mconfig
->formats_config
.caps
= (u32
*)bc
->params
;
441 mconfig
->formats_config
.caps_size
= bc
->size
;
450 static int skl_tplg_module_prepare(struct skl_dev
*skl
, struct skl_pipe
*pipe
,
451 struct snd_soc_dapm_widget
*w
, struct skl_module_cfg
*mcfg
)
453 switch (mcfg
->dev_type
) {
454 case SKL_DEVICE_HDAHOST
:
455 return skl_pcm_host_dma_prepare(skl
->dev
, pipe
->p_params
);
457 case SKL_DEVICE_HDALINK
:
458 return skl_pcm_link_dma_prepare(skl
->dev
, pipe
->p_params
);
465 * Inside a pipe instance, we can have various modules. These modules need
466 * to instantiated in DSP by invoking INIT_MODULE IPC, which is achieved by
467 * skl_init_module() routine, so invoke that for all modules in a pipeline
470 skl_tplg_init_pipe_modules(struct skl_dev
*skl
, struct skl_pipe
*pipe
)
472 struct skl_pipe_module
*w_module
;
473 struct snd_soc_dapm_widget
*w
;
474 struct skl_module_cfg
*mconfig
;
478 list_for_each_entry(w_module
, &pipe
->w_list
, node
) {
483 /* check if module ids are populated */
484 if (mconfig
->id
.module_id
< 0) {
486 "module %pUL id not populated\n",
487 (guid_t
*)mconfig
->guid
);
491 cfg_idx
= mconfig
->pipe
->cur_config_idx
;
492 mconfig
->fmt_idx
= mconfig
->mod_cfg
[cfg_idx
].fmt_idx
;
493 mconfig
->res_idx
= mconfig
->mod_cfg
[cfg_idx
].res_idx
;
495 if (mconfig
->module
->loadable
&& skl
->dsp
->fw_ops
.load_mod
) {
496 ret
= skl
->dsp
->fw_ops
.load_mod(skl
->dsp
,
497 mconfig
->id
.module_id
, mconfig
->guid
);
501 mconfig
->m_state
= SKL_MODULE_LOADED
;
504 /* prepare the DMA if the module is gateway cpr */
505 ret
= skl_tplg_module_prepare(skl
, pipe
, w
, mconfig
);
509 /* update blob if blob is null for be with default value */
510 skl_tplg_update_be_blob(w
, skl
);
513 * apply fix/conversion to module params based on
516 skl_tplg_update_module_params(w
, skl
);
517 uuid_mod
= (guid_t
*)mconfig
->guid
;
518 mconfig
->id
.pvt_id
= skl_get_pvt_id(skl
, uuid_mod
,
519 mconfig
->id
.instance_id
);
520 if (mconfig
->id
.pvt_id
< 0)
522 skl_tplg_set_module_init_data(w
);
524 ret
= skl_dsp_get_core(skl
->dsp
, mconfig
->core_id
);
526 dev_err(skl
->dev
, "Failed to wake up core %d ret=%d\n",
527 mconfig
->core_id
, ret
);
531 ret
= skl_init_module(skl
, mconfig
);
533 skl_put_pvt_id(skl
, uuid_mod
, &mconfig
->id
.pvt_id
);
537 ret
= skl_tplg_set_module_params(w
, skl
);
544 skl_dsp_put_core(skl
->dsp
, mconfig
->core_id
);
548 static int skl_tplg_unload_pipe_modules(struct skl_dev
*skl
,
549 struct skl_pipe
*pipe
)
552 struct skl_pipe_module
*w_module
= NULL
;
553 struct skl_module_cfg
*mconfig
= NULL
;
555 list_for_each_entry(w_module
, &pipe
->w_list
, node
) {
557 mconfig
= w_module
->w
->priv
;
558 uuid_mod
= (guid_t
*)mconfig
->guid
;
560 if (mconfig
->module
->loadable
&& skl
->dsp
->fw_ops
.unload_mod
&&
561 mconfig
->m_state
> SKL_MODULE_UNINIT
) {
562 ret
= skl
->dsp
->fw_ops
.unload_mod(skl
->dsp
,
563 mconfig
->id
.module_id
);
567 skl_put_pvt_id(skl
, uuid_mod
, &mconfig
->id
.pvt_id
);
569 ret
= skl_dsp_put_core(skl
->dsp
, mconfig
->core_id
);
571 /* don't return; continue with other modules */
572 dev_err(skl
->dev
, "Failed to sleep core %d ret=%d\n",
573 mconfig
->core_id
, ret
);
577 /* no modules to unload in this path, so return */
582 * Here, we select pipe format based on the pipe type and pipe
583 * direction to determine the current config index for the pipeline.
584 * The config index is then used to select proper module resources.
585 * Intermediate pipes currently have a fixed format hence we select the
586 * 0th configuratation by default for such pipes.
589 skl_tplg_get_pipe_config(struct skl_dev
*skl
, struct skl_module_cfg
*mconfig
)
591 struct skl_pipe
*pipe
= mconfig
->pipe
;
592 struct skl_pipe_params
*params
= pipe
->p_params
;
593 struct skl_path_config
*pconfig
= &pipe
->configs
[0];
594 struct skl_pipe_fmt
*fmt
= NULL
;
598 if (pipe
->nr_cfgs
== 0) {
599 pipe
->cur_config_idx
= 0;
603 if (pipe
->conn_type
== SKL_PIPE_CONN_TYPE_NONE
) {
604 dev_dbg(skl
->dev
, "No conn_type detected, take 0th config\n");
605 pipe
->cur_config_idx
= 0;
606 pipe
->memory_pages
= pconfig
->mem_pages
;
611 if ((pipe
->conn_type
== SKL_PIPE_CONN_TYPE_FE
&&
612 pipe
->direction
== SNDRV_PCM_STREAM_PLAYBACK
) ||
613 (pipe
->conn_type
== SKL_PIPE_CONN_TYPE_BE
&&
614 pipe
->direction
== SNDRV_PCM_STREAM_CAPTURE
))
617 for (i
= 0; i
< pipe
->nr_cfgs
; i
++) {
618 pconfig
= &pipe
->configs
[i
];
620 fmt
= &pconfig
->in_fmt
;
622 fmt
= &pconfig
->out_fmt
;
624 if (CHECK_HW_PARAMS(params
->ch
, params
->s_freq
, params
->s_fmt
,
625 fmt
->channels
, fmt
->freq
, fmt
->bps
)) {
626 pipe
->cur_config_idx
= i
;
627 pipe
->memory_pages
= pconfig
->mem_pages
;
628 dev_dbg(skl
->dev
, "Using pipe config: %d\n", i
);
634 dev_err(skl
->dev
, "Invalid pipe config: %d %d %d for pipe: %d\n",
635 params
->ch
, params
->s_freq
, params
->s_fmt
, pipe
->ppl_id
);
640 * Mixer module represents a pipeline. So in the Pre-PMU event of mixer we
641 * need create the pipeline. So we do following:
642 * - Create the pipeline
643 * - Initialize the modules in pipeline
644 * - finally bind all modules together
646 static int skl_tplg_mixer_dapm_pre_pmu_event(struct snd_soc_dapm_widget
*w
,
650 struct skl_module_cfg
*mconfig
= w
->priv
;
651 struct skl_pipe_module
*w_module
;
652 struct skl_pipe
*s_pipe
= mconfig
->pipe
;
653 struct skl_module_cfg
*src_module
= NULL
, *dst_module
, *module
;
654 struct skl_module_deferred_bind
*modules
;
656 ret
= skl_tplg_get_pipe_config(skl
, mconfig
);
661 * Create a list of modules for pipe.
662 * This list contains modules from source to sink
664 ret
= skl_create_pipeline(skl
, mconfig
->pipe
);
668 /* Init all pipe modules from source to sink */
669 ret
= skl_tplg_init_pipe_modules(skl
, s_pipe
);
673 /* Bind modules from source to sink */
674 list_for_each_entry(w_module
, &s_pipe
->w_list
, node
) {
675 dst_module
= w_module
->w
->priv
;
677 if (src_module
== NULL
) {
678 src_module
= dst_module
;
682 ret
= skl_bind_modules(skl
, src_module
, dst_module
);
686 src_module
= dst_module
;
690 * When the destination module is initialized, check for these modules
691 * in deferred bind list. If found, bind them.
693 list_for_each_entry(w_module
, &s_pipe
->w_list
, node
) {
694 if (list_empty(&skl
->bind_list
))
697 list_for_each_entry(modules
, &skl
->bind_list
, node
) {
698 module
= w_module
->w
->priv
;
699 if (modules
->dst
== module
)
700 skl_bind_modules(skl
, modules
->src
,
708 static int skl_fill_sink_instance_id(struct skl_dev
*skl
, u32
*params
,
709 int size
, struct skl_module_cfg
*mcfg
)
713 if (mcfg
->m_type
== SKL_MODULE_TYPE_KPB
) {
714 struct skl_kpb_params
*kpb_params
=
715 (struct skl_kpb_params
*)params
;
716 struct skl_mod_inst_map
*inst
= kpb_params
->u
.map
;
718 for (i
= 0; i
< kpb_params
->num_modules
; i
++) {
719 pvt_id
= skl_get_pvt_instance_id_map(skl
, inst
->mod_id
,
724 inst
->inst_id
= pvt_id
;
732 * Some modules require params to be set after the module is bound to
733 * all pins connected.
735 * The module provider initializes set_param flag for such modules and we
736 * send params after binding
738 static int skl_tplg_set_module_bind_params(struct snd_soc_dapm_widget
*w
,
739 struct skl_module_cfg
*mcfg
, struct skl_dev
*skl
)
742 struct skl_module_cfg
*mconfig
= w
->priv
;
743 const struct snd_kcontrol_new
*k
;
744 struct soc_bytes_ext
*sb
;
745 struct skl_algo_data
*bc
;
746 struct skl_specific_cfg
*sp_cfg
;
750 * check all out/in pins are in bind state.
751 * if so set the module param
753 for (i
= 0; i
< mcfg
->module
->max_output_pins
; i
++) {
754 if (mcfg
->m_out_pin
[i
].pin_state
!= SKL_PIN_BIND_DONE
)
758 for (i
= 0; i
< mcfg
->module
->max_input_pins
; i
++) {
759 if (mcfg
->m_in_pin
[i
].pin_state
!= SKL_PIN_BIND_DONE
)
763 if (mconfig
->formats_config
.caps_size
> 0 &&
764 mconfig
->formats_config
.set_params
== SKL_PARAM_BIND
) {
765 sp_cfg
= &mconfig
->formats_config
;
766 ret
= skl_set_module_params(skl
, sp_cfg
->caps
,
768 sp_cfg
->param_id
, mconfig
);
773 for (i
= 0; i
< w
->num_kcontrols
; i
++) {
774 k
= &w
->kcontrol_news
[i
];
775 if (k
->access
& SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK
) {
776 sb
= (void *) k
->private_value
;
777 bc
= (struct skl_algo_data
*)sb
->dobj
.private;
779 if (bc
->set_params
== SKL_PARAM_BIND
) {
780 params
= kmemdup(bc
->params
, bc
->max
, GFP_KERNEL
);
784 skl_fill_sink_instance_id(skl
, params
, bc
->max
,
787 ret
= skl_set_module_params(skl
, params
,
788 bc
->max
, bc
->param_id
, mconfig
);
800 static int skl_get_module_id(struct skl_dev
*skl
, guid_t
*uuid
)
802 struct uuid_module
*module
;
804 list_for_each_entry(module
, &skl
->uuid_list
, list
) {
805 if (guid_equal(uuid
, &module
->uuid
))
812 static int skl_tplg_find_moduleid_from_uuid(struct skl_dev
*skl
,
813 const struct snd_kcontrol_new
*k
)
815 struct soc_bytes_ext
*sb
= (void *) k
->private_value
;
816 struct skl_algo_data
*bc
= (struct skl_algo_data
*)sb
->dobj
.private;
817 struct skl_kpb_params
*uuid_params
, *params
;
818 struct hdac_bus
*bus
= skl_to_bus(skl
);
819 int i
, size
, module_id
;
821 if (bc
->set_params
== SKL_PARAM_BIND
&& bc
->max
) {
822 uuid_params
= (struct skl_kpb_params
*)bc
->params
;
823 size
= struct_size(params
, u
.map
, uuid_params
->num_modules
);
825 params
= devm_kzalloc(bus
->dev
, size
, GFP_KERNEL
);
829 params
->num_modules
= uuid_params
->num_modules
;
831 for (i
= 0; i
< uuid_params
->num_modules
; i
++) {
832 module_id
= skl_get_module_id(skl
,
833 &uuid_params
->u
.map_uuid
[i
].mod_uuid
);
835 devm_kfree(bus
->dev
, params
);
839 params
->u
.map
[i
].mod_id
= module_id
;
840 params
->u
.map
[i
].inst_id
=
841 uuid_params
->u
.map_uuid
[i
].inst_id
;
844 devm_kfree(bus
->dev
, bc
->params
);
845 bc
->params
= (char *)params
;
853 * Retrieve the module id from UUID mentioned in the
856 void skl_tplg_add_moduleid_in_bind_params(struct skl_dev
*skl
,
857 struct snd_soc_dapm_widget
*w
)
859 struct skl_module_cfg
*mconfig
= w
->priv
;
863 * Post bind params are used for only for KPB
864 * to set copier instances to drain the data
867 if (mconfig
->m_type
!= SKL_MODULE_TYPE_KPB
)
870 for (i
= 0; i
< w
->num_kcontrols
; i
++)
871 if ((w
->kcontrol_news
[i
].access
&
872 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK
) &&
873 (skl_tplg_find_moduleid_from_uuid(skl
,
874 &w
->kcontrol_news
[i
]) < 0))
876 "%s: invalid kpb post bind params\n",
880 static int skl_tplg_module_add_deferred_bind(struct skl_dev
*skl
,
881 struct skl_module_cfg
*src
, struct skl_module_cfg
*dst
)
883 struct skl_module_deferred_bind
*m_list
, *modules
;
886 /* only supported for module with static pin connection */
887 for (i
= 0; i
< dst
->module
->max_input_pins
; i
++) {
888 struct skl_module_pin
*pin
= &dst
->m_in_pin
[i
];
893 if ((pin
->id
.module_id
== src
->id
.module_id
) &&
894 (pin
->id
.instance_id
== src
->id
.instance_id
)) {
896 if (!list_empty(&skl
->bind_list
)) {
897 list_for_each_entry(modules
, &skl
->bind_list
, node
) {
898 if (modules
->src
== src
&& modules
->dst
== dst
)
903 m_list
= kzalloc(sizeof(*m_list
), GFP_KERNEL
);
910 list_add(&m_list
->node
, &skl
->bind_list
);
917 static int skl_tplg_bind_sinks(struct snd_soc_dapm_widget
*w
,
919 struct snd_soc_dapm_widget
*src_w
,
920 struct skl_module_cfg
*src_mconfig
)
922 struct snd_soc_dapm_path
*p
;
923 struct snd_soc_dapm_widget
*sink
= NULL
, *next_sink
= NULL
;
924 struct skl_module_cfg
*sink_mconfig
;
927 snd_soc_dapm_widget_for_each_sink_path(w
, p
) {
932 "%s: src widget=%s\n", __func__
, w
->name
);
934 "%s: sink widget=%s\n", __func__
, p
->sink
->name
);
938 if (!is_skl_dsp_widget_type(p
->sink
, skl
->dev
))
939 return skl_tplg_bind_sinks(p
->sink
, skl
, src_w
, src_mconfig
);
942 * here we will check widgets in sink pipelines, so that
943 * can be any widgets type and we are only interested if
944 * they are ones used for SKL so check that first
946 if ((p
->sink
->priv
!= NULL
) &&
947 is_skl_dsp_widget_type(p
->sink
, skl
->dev
)) {
950 sink_mconfig
= sink
->priv
;
953 * Modules other than PGA leaf can be connected
954 * directly or via switch to a module in another
955 * pipeline. EX: reference path
956 * when the path is enabled, the dst module that needs
957 * to be bound may not be initialized. if the module is
958 * not initialized, add these modules in the deferred
959 * bind list and when the dst module is initialised,
960 * bind this module to the dst_module in deferred list.
962 if (((src_mconfig
->m_state
== SKL_MODULE_INIT_DONE
)
963 && (sink_mconfig
->m_state
== SKL_MODULE_UNINIT
))) {
965 ret
= skl_tplg_module_add_deferred_bind(skl
,
966 src_mconfig
, sink_mconfig
);
974 if (src_mconfig
->m_state
== SKL_MODULE_UNINIT
||
975 sink_mconfig
->m_state
== SKL_MODULE_UNINIT
)
978 /* Bind source to sink, mixin is always source */
979 ret
= skl_bind_modules(skl
, src_mconfig
, sink_mconfig
);
983 /* set module params after bind */
984 skl_tplg_set_module_bind_params(src_w
,
986 skl_tplg_set_module_bind_params(sink
,
989 /* Start sinks pipe first */
990 if (sink_mconfig
->pipe
->state
!= SKL_PIPE_STARTED
) {
991 if (sink_mconfig
->pipe
->conn_type
!=
992 SKL_PIPE_CONN_TYPE_FE
)
993 ret
= skl_run_pipe(skl
,
1001 if (!sink
&& next_sink
)
1002 return skl_tplg_bind_sinks(next_sink
, skl
, src_w
, src_mconfig
);
1008 * A PGA represents a module in a pipeline. So in the Pre-PMU event of PGA
1009 * we need to do following:
1010 * - Bind to sink pipeline
1011 * Since the sink pipes can be running and we don't get mixer event on
1012 * connect for already running mixer, we need to find the sink pipes
1013 * here and bind to them. This way dynamic connect works.
1014 * - Start sink pipeline, if not running
1015 * - Then run current pipe
1017 static int skl_tplg_pga_dapm_pre_pmu_event(struct snd_soc_dapm_widget
*w
,
1018 struct skl_dev
*skl
)
1020 struct skl_module_cfg
*src_mconfig
;
1023 src_mconfig
= w
->priv
;
1026 * find which sink it is connected to, bind with the sink,
1027 * if sink is not started, start sink pipe first, then start
1030 ret
= skl_tplg_bind_sinks(w
, skl
, w
, src_mconfig
);
1034 /* Start source pipe last after starting all sinks */
1035 if (src_mconfig
->pipe
->conn_type
!= SKL_PIPE_CONN_TYPE_FE
)
1036 return skl_run_pipe(skl
, src_mconfig
->pipe
);
1041 static struct snd_soc_dapm_widget
*skl_get_src_dsp_widget(
1042 struct snd_soc_dapm_widget
*w
, struct skl_dev
*skl
)
1044 struct snd_soc_dapm_path
*p
;
1045 struct snd_soc_dapm_widget
*src_w
= NULL
;
1047 snd_soc_dapm_widget_for_each_source_path(w
, p
) {
1052 dev_dbg(skl
->dev
, "sink widget=%s\n", w
->name
);
1053 dev_dbg(skl
->dev
, "src widget=%s\n", p
->source
->name
);
1056 * here we will check widgets in sink pipelines, so that can
1057 * be any widgets type and we are only interested if they are
1058 * ones used for SKL so check that first
1060 if ((p
->source
->priv
!= NULL
) &&
1061 is_skl_dsp_widget_type(p
->source
, skl
->dev
)) {
1067 return skl_get_src_dsp_widget(src_w
, skl
);
1073 * in the Post-PMU event of mixer we need to do following:
1074 * - Check if this pipe is running
1076 * - bind this pipeline to its source pipeline
1077 * if source pipe is already running, this means it is a dynamic
1078 * connection and we need to bind only to that pipe
1079 * - start this pipeline
1081 static int skl_tplg_mixer_dapm_post_pmu_event(struct snd_soc_dapm_widget
*w
,
1082 struct skl_dev
*skl
)
1085 struct snd_soc_dapm_widget
*source
, *sink
;
1086 struct skl_module_cfg
*src_mconfig
, *sink_mconfig
;
1087 int src_pipe_started
= 0;
1090 sink_mconfig
= sink
->priv
;
1093 * If source pipe is already started, that means source is driving
1094 * one more sink before this sink got connected, Since source is
1095 * started, bind this sink to source and start this pipe.
1097 source
= skl_get_src_dsp_widget(w
, skl
);
1098 if (source
!= NULL
) {
1099 src_mconfig
= source
->priv
;
1100 sink_mconfig
= sink
->priv
;
1101 src_pipe_started
= 1;
1104 * check pipe state, then no need to bind or start the
1107 if (src_mconfig
->pipe
->state
!= SKL_PIPE_STARTED
)
1108 src_pipe_started
= 0;
1111 if (src_pipe_started
) {
1112 ret
= skl_bind_modules(skl
, src_mconfig
, sink_mconfig
);
1116 /* set module params after bind */
1117 skl_tplg_set_module_bind_params(source
, src_mconfig
, skl
);
1118 skl_tplg_set_module_bind_params(sink
, sink_mconfig
, skl
);
1120 if (sink_mconfig
->pipe
->conn_type
!= SKL_PIPE_CONN_TYPE_FE
)
1121 ret
= skl_run_pipe(skl
, sink_mconfig
->pipe
);
1128 * in the Pre-PMD event of mixer we need to do following:
1130 * - find the source connections and remove that from dapm_path_list
1131 * - unbind with source pipelines if still connected
1133 static int skl_tplg_mixer_dapm_pre_pmd_event(struct snd_soc_dapm_widget
*w
,
1134 struct skl_dev
*skl
)
1136 struct skl_module_cfg
*src_mconfig
, *sink_mconfig
;
1139 sink_mconfig
= w
->priv
;
1142 ret
= skl_stop_pipe(skl
, sink_mconfig
->pipe
);
1146 for (i
= 0; i
< sink_mconfig
->module
->max_input_pins
; i
++) {
1147 if (sink_mconfig
->m_in_pin
[i
].pin_state
== SKL_PIN_BIND_DONE
) {
1148 src_mconfig
= sink_mconfig
->m_in_pin
[i
].tgt_mcfg
;
1152 ret
= skl_unbind_modules(skl
,
1153 src_mconfig
, sink_mconfig
);
1161 * in the Post-PMD event of mixer we need to do following:
1162 * - Unbind the modules within the pipeline
1163 * - Delete the pipeline (modules are not required to be explicitly
1164 * deleted, pipeline delete is enough here
1166 static int skl_tplg_mixer_dapm_post_pmd_event(struct snd_soc_dapm_widget
*w
,
1167 struct skl_dev
*skl
)
1169 struct skl_module_cfg
*mconfig
= w
->priv
;
1170 struct skl_pipe_module
*w_module
;
1171 struct skl_module_cfg
*src_module
= NULL
, *dst_module
;
1172 struct skl_pipe
*s_pipe
= mconfig
->pipe
;
1173 struct skl_module_deferred_bind
*modules
, *tmp
;
1175 if (s_pipe
->state
== SKL_PIPE_INVALID
)
1178 list_for_each_entry(w_module
, &s_pipe
->w_list
, node
) {
1179 if (list_empty(&skl
->bind_list
))
1182 src_module
= w_module
->w
->priv
;
1184 list_for_each_entry_safe(modules
, tmp
, &skl
->bind_list
, node
) {
1186 * When the destination module is deleted, Unbind the
1187 * modules from deferred bind list.
1189 if (modules
->dst
== src_module
) {
1190 skl_unbind_modules(skl
, modules
->src
,
1195 * When the source module is deleted, remove this entry
1196 * from the deferred bind list.
1198 if (modules
->src
== src_module
) {
1199 list_del(&modules
->node
);
1200 modules
->src
= NULL
;
1201 modules
->dst
= NULL
;
1207 list_for_each_entry(w_module
, &s_pipe
->w_list
, node
) {
1208 dst_module
= w_module
->w
->priv
;
1210 if (src_module
== NULL
) {
1211 src_module
= dst_module
;
1215 skl_unbind_modules(skl
, src_module
, dst_module
);
1216 src_module
= dst_module
;
1219 skl_delete_pipe(skl
, mconfig
->pipe
);
1221 list_for_each_entry(w_module
, &s_pipe
->w_list
, node
) {
1222 src_module
= w_module
->w
->priv
;
1223 src_module
->m_state
= SKL_MODULE_UNINIT
;
1226 return skl_tplg_unload_pipe_modules(skl
, s_pipe
);
1230 * in the Post-PMD event of PGA we need to do following:
1231 * - Stop the pipeline
1232 * - In source pipe is connected, unbind with source pipelines
1234 static int skl_tplg_pga_dapm_post_pmd_event(struct snd_soc_dapm_widget
*w
,
1235 struct skl_dev
*skl
)
1237 struct skl_module_cfg
*src_mconfig
, *sink_mconfig
;
1240 src_mconfig
= w
->priv
;
1242 /* Stop the pipe since this is a mixin module */
1243 ret
= skl_stop_pipe(skl
, src_mconfig
->pipe
);
1247 for (i
= 0; i
< src_mconfig
->module
->max_output_pins
; i
++) {
1248 if (src_mconfig
->m_out_pin
[i
].pin_state
== SKL_PIN_BIND_DONE
) {
1249 sink_mconfig
= src_mconfig
->m_out_pin
[i
].tgt_mcfg
;
1253 * This is a connecter and if path is found that means
1254 * unbind between source and sink has not happened yet
1256 ret
= skl_unbind_modules(skl
, src_mconfig
,
1265 * In modelling, we assume there will be ONLY one mixer in a pipeline. If a
1266 * second one is required that is created as another pipe entity.
1267 * The mixer is responsible for pipe management and represent a pipeline
1270 static int skl_tplg_mixer_event(struct snd_soc_dapm_widget
*w
,
1271 struct snd_kcontrol
*k
, int event
)
1273 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
1274 struct skl_dev
*skl
= get_skl_ctx(dapm
->dev
);
1277 case SND_SOC_DAPM_PRE_PMU
:
1278 return skl_tplg_mixer_dapm_pre_pmu_event(w
, skl
);
1280 case SND_SOC_DAPM_POST_PMU
:
1281 return skl_tplg_mixer_dapm_post_pmu_event(w
, skl
);
1283 case SND_SOC_DAPM_PRE_PMD
:
1284 return skl_tplg_mixer_dapm_pre_pmd_event(w
, skl
);
1286 case SND_SOC_DAPM_POST_PMD
:
1287 return skl_tplg_mixer_dapm_post_pmd_event(w
, skl
);
1294 * In modelling, we assumed rest of the modules in pipeline are PGA. But we
1295 * are interested in last PGA (leaf PGA) in a pipeline to disconnect with
1296 * the sink when it is running (two FE to one BE or one FE to two BE)
1299 static int skl_tplg_pga_event(struct snd_soc_dapm_widget
*w
,
1300 struct snd_kcontrol
*k
, int event
)
1303 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
1304 struct skl_dev
*skl
= get_skl_ctx(dapm
->dev
);
1307 case SND_SOC_DAPM_PRE_PMU
:
1308 return skl_tplg_pga_dapm_pre_pmu_event(w
, skl
);
1310 case SND_SOC_DAPM_POST_PMD
:
1311 return skl_tplg_pga_dapm_post_pmd_event(w
, skl
);
1317 static int skl_tplg_tlv_control_get(struct snd_kcontrol
*kcontrol
,
1318 unsigned int __user
*data
, unsigned int size
)
1320 struct soc_bytes_ext
*sb
=
1321 (struct soc_bytes_ext
*)kcontrol
->private_value
;
1322 struct skl_algo_data
*bc
= (struct skl_algo_data
*)sb
->dobj
.private;
1323 struct snd_soc_dapm_widget
*w
= snd_soc_dapm_kcontrol_widget(kcontrol
);
1324 struct skl_module_cfg
*mconfig
= w
->priv
;
1325 struct skl_dev
*skl
= get_skl_ctx(w
->dapm
->dev
);
1328 skl_get_module_params(skl
, (u32
*)bc
->params
,
1329 bc
->size
, bc
->param_id
, mconfig
);
1331 /* decrement size for TLV header */
1332 size
-= 2 * sizeof(u32
);
1334 /* check size as we don't want to send kernel data */
1339 if (copy_to_user(data
, &bc
->param_id
, sizeof(u32
)))
1341 if (copy_to_user(data
+ 1, &size
, sizeof(u32
)))
1343 if (copy_to_user(data
+ 2, bc
->params
, size
))
1350 #define SKL_PARAM_VENDOR_ID 0xff
1352 static int skl_tplg_tlv_control_set(struct snd_kcontrol
*kcontrol
,
1353 const unsigned int __user
*data
, unsigned int size
)
1355 struct snd_soc_dapm_widget
*w
= snd_soc_dapm_kcontrol_widget(kcontrol
);
1356 struct skl_module_cfg
*mconfig
= w
->priv
;
1357 struct soc_bytes_ext
*sb
=
1358 (struct soc_bytes_ext
*)kcontrol
->private_value
;
1359 struct skl_algo_data
*ac
= (struct skl_algo_data
*)sb
->dobj
.private;
1360 struct skl_dev
*skl
= get_skl_ctx(w
->dapm
->dev
);
1364 * Widget data is expected to be stripped of T and L
1366 size
-= 2 * sizeof(unsigned int);
1373 if (copy_from_user(ac
->params
, data
, size
))
1377 return skl_set_module_params(skl
,
1378 (u32
*)ac
->params
, ac
->size
,
1379 ac
->param_id
, mconfig
);
1385 static int skl_tplg_mic_control_get(struct snd_kcontrol
*kcontrol
,
1386 struct snd_ctl_elem_value
*ucontrol
)
1388 struct snd_soc_dapm_widget
*w
= snd_soc_dapm_kcontrol_widget(kcontrol
);
1389 struct skl_module_cfg
*mconfig
= w
->priv
;
1390 struct soc_enum
*ec
= (struct soc_enum
*)kcontrol
->private_value
;
1391 u32 ch_type
= *((u32
*)ec
->dobj
.private);
1393 if (mconfig
->dmic_ch_type
== ch_type
)
1394 ucontrol
->value
.enumerated
.item
[0] =
1395 mconfig
->dmic_ch_combo_index
;
1397 ucontrol
->value
.enumerated
.item
[0] = 0;
1402 static int skl_fill_mic_sel_params(struct skl_module_cfg
*mconfig
,
1403 struct skl_mic_sel_config
*mic_cfg
, struct device
*dev
)
1405 struct skl_specific_cfg
*sp_cfg
= &mconfig
->formats_config
;
1407 sp_cfg
->caps_size
= sizeof(struct skl_mic_sel_config
);
1408 sp_cfg
->set_params
= SKL_PARAM_SET
;
1409 sp_cfg
->param_id
= 0x00;
1410 if (!sp_cfg
->caps
) {
1411 sp_cfg
->caps
= devm_kzalloc(dev
, sp_cfg
->caps_size
, GFP_KERNEL
);
1416 mic_cfg
->mic_switch
= SKL_MIC_SEL_SWITCH
;
1418 memcpy(sp_cfg
->caps
, mic_cfg
, sp_cfg
->caps_size
);
1423 static int skl_tplg_mic_control_set(struct snd_kcontrol
*kcontrol
,
1424 struct snd_ctl_elem_value
*ucontrol
)
1426 struct snd_soc_dapm_widget
*w
= snd_soc_dapm_kcontrol_widget(kcontrol
);
1427 struct skl_module_cfg
*mconfig
= w
->priv
;
1428 struct skl_mic_sel_config mic_cfg
= {0};
1429 struct soc_enum
*ec
= (struct soc_enum
*)kcontrol
->private_value
;
1430 u32 ch_type
= *((u32
*)ec
->dobj
.private);
1432 u8 in_ch
, out_ch
, index
;
1434 mconfig
->dmic_ch_type
= ch_type
;
1435 mconfig
->dmic_ch_combo_index
= ucontrol
->value
.enumerated
.item
[0];
1437 /* enum control index 0 is INVALID, so no channels to be set */
1438 if (mconfig
->dmic_ch_combo_index
== 0)
1441 /* No valid channel selection map for index 0, so offset by 1 */
1442 index
= mconfig
->dmic_ch_combo_index
- 1;
1446 if (mconfig
->dmic_ch_combo_index
> ARRAY_SIZE(mic_mono_list
))
1449 list
= &mic_mono_list
[index
];
1453 if (mconfig
->dmic_ch_combo_index
> ARRAY_SIZE(mic_stereo_list
))
1456 list
= mic_stereo_list
[index
];
1460 if (mconfig
->dmic_ch_combo_index
> ARRAY_SIZE(mic_trio_list
))
1463 list
= mic_trio_list
[index
];
1467 if (mconfig
->dmic_ch_combo_index
> ARRAY_SIZE(mic_quatro_list
))
1470 list
= mic_quatro_list
[index
];
1474 dev_err(w
->dapm
->dev
,
1475 "Invalid channel %d for mic_select module\n",
1481 /* channel type enum map to number of chanels for that type */
1482 for (out_ch
= 0; out_ch
< ch_type
; out_ch
++) {
1483 in_ch
= list
[out_ch
];
1484 mic_cfg
.blob
[out_ch
][in_ch
] = SKL_DEFAULT_MIC_SEL_GAIN
;
1487 return skl_fill_mic_sel_params(mconfig
, &mic_cfg
, w
->dapm
->dev
);
1491 * Fill the dma id for host and link. In case of passthrough
1492 * pipeline, this will both host and link in the same
1493 * pipeline, so need to copy the link and host based on dev_type
1495 static void skl_tplg_fill_dma_id(struct skl_module_cfg
*mcfg
,
1496 struct skl_pipe_params
*params
)
1498 struct skl_pipe
*pipe
= mcfg
->pipe
;
1500 if (pipe
->passthru
) {
1501 switch (mcfg
->dev_type
) {
1502 case SKL_DEVICE_HDALINK
:
1503 pipe
->p_params
->link_dma_id
= params
->link_dma_id
;
1504 pipe
->p_params
->link_index
= params
->link_index
;
1505 pipe
->p_params
->link_bps
= params
->link_bps
;
1508 case SKL_DEVICE_HDAHOST
:
1509 pipe
->p_params
->host_dma_id
= params
->host_dma_id
;
1510 pipe
->p_params
->host_bps
= params
->host_bps
;
1516 pipe
->p_params
->s_fmt
= params
->s_fmt
;
1517 pipe
->p_params
->ch
= params
->ch
;
1518 pipe
->p_params
->s_freq
= params
->s_freq
;
1519 pipe
->p_params
->stream
= params
->stream
;
1520 pipe
->p_params
->format
= params
->format
;
1523 memcpy(pipe
->p_params
, params
, sizeof(*params
));
1528 * The FE params are passed by hw_params of the DAI.
1529 * On hw_params, the params are stored in Gateway module of the FE and we
1530 * need to calculate the format in DSP module configuration, that
1531 * conversion is done here
1533 int skl_tplg_update_pipe_params(struct device
*dev
,
1534 struct skl_module_cfg
*mconfig
,
1535 struct skl_pipe_params
*params
)
1537 struct skl_module_res
*res
= &mconfig
->module
->resources
[0];
1538 struct skl_dev
*skl
= get_skl_ctx(dev
);
1539 struct skl_module_fmt
*format
= NULL
;
1540 u8 cfg_idx
= mconfig
->pipe
->cur_config_idx
;
1542 skl_tplg_fill_dma_id(mconfig
, params
);
1543 mconfig
->fmt_idx
= mconfig
->mod_cfg
[cfg_idx
].fmt_idx
;
1544 mconfig
->res_idx
= mconfig
->mod_cfg
[cfg_idx
].res_idx
;
1546 if (skl
->nr_modules
)
1549 if (params
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
1550 format
= &mconfig
->module
->formats
[0].inputs
[0].fmt
;
1552 format
= &mconfig
->module
->formats
[0].outputs
[0].fmt
;
1554 /* set the hw_params */
1555 format
->s_freq
= params
->s_freq
;
1556 format
->channels
= params
->ch
;
1557 format
->valid_bit_depth
= skl_get_bit_depth(params
->s_fmt
);
1560 * 16 bit is 16 bit container whereas 24 bit is in 32 bit
1561 * container so update bit depth accordingly
1563 switch (format
->valid_bit_depth
) {
1564 case SKL_DEPTH_16BIT
:
1565 format
->bit_depth
= format
->valid_bit_depth
;
1568 case SKL_DEPTH_24BIT
:
1569 case SKL_DEPTH_32BIT
:
1570 format
->bit_depth
= SKL_DEPTH_32BIT
;
1574 dev_err(dev
, "Invalid bit depth %x for pipe\n",
1575 format
->valid_bit_depth
);
1579 if (params
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
1580 res
->ibs
= (format
->s_freq
/ 1000) *
1581 (format
->channels
) *
1582 (format
->bit_depth
>> 3);
1584 res
->obs
= (format
->s_freq
/ 1000) *
1585 (format
->channels
) *
1586 (format
->bit_depth
>> 3);
1593 * Query the module config for the FE DAI
1594 * This is used to find the hw_params set for that DAI and apply to FE
1597 struct skl_module_cfg
*
1598 skl_tplg_fe_get_cpr_module(struct snd_soc_dai
*dai
, int stream
)
1600 struct snd_soc_dapm_widget
*w
;
1601 struct snd_soc_dapm_path
*p
= NULL
;
1603 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
1604 w
= dai
->playback_widget
;
1605 snd_soc_dapm_widget_for_each_sink_path(w
, p
) {
1606 if (p
->connect
&& p
->sink
->power
&&
1607 !is_skl_dsp_widget_type(p
->sink
, dai
->dev
))
1610 if (p
->sink
->priv
) {
1611 dev_dbg(dai
->dev
, "set params for %s\n",
1613 return p
->sink
->priv
;
1617 w
= dai
->capture_widget
;
1618 snd_soc_dapm_widget_for_each_source_path(w
, p
) {
1619 if (p
->connect
&& p
->source
->power
&&
1620 !is_skl_dsp_widget_type(p
->source
, dai
->dev
))
1623 if (p
->source
->priv
) {
1624 dev_dbg(dai
->dev
, "set params for %s\n",
1626 return p
->source
->priv
;
1634 static struct skl_module_cfg
*skl_get_mconfig_pb_cpr(
1635 struct snd_soc_dai
*dai
, struct snd_soc_dapm_widget
*w
)
1637 struct snd_soc_dapm_path
*p
;
1638 struct skl_module_cfg
*mconfig
= NULL
;
1640 snd_soc_dapm_widget_for_each_source_path(w
, p
) {
1641 if (w
->endpoints
[SND_SOC_DAPM_DIR_OUT
] > 0) {
1643 (p
->sink
->id
== snd_soc_dapm_aif_out
) &&
1645 mconfig
= p
->source
->priv
;
1648 mconfig
= skl_get_mconfig_pb_cpr(dai
, p
->source
);
1656 static struct skl_module_cfg
*skl_get_mconfig_cap_cpr(
1657 struct snd_soc_dai
*dai
, struct snd_soc_dapm_widget
*w
)
1659 struct snd_soc_dapm_path
*p
;
1660 struct skl_module_cfg
*mconfig
= NULL
;
1662 snd_soc_dapm_widget_for_each_sink_path(w
, p
) {
1663 if (w
->endpoints
[SND_SOC_DAPM_DIR_IN
] > 0) {
1665 (p
->source
->id
== snd_soc_dapm_aif_in
) &&
1667 mconfig
= p
->sink
->priv
;
1670 mconfig
= skl_get_mconfig_cap_cpr(dai
, p
->sink
);
1678 struct skl_module_cfg
*
1679 skl_tplg_be_get_cpr_module(struct snd_soc_dai
*dai
, int stream
)
1681 struct snd_soc_dapm_widget
*w
;
1682 struct skl_module_cfg
*mconfig
;
1684 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
1685 w
= dai
->playback_widget
;
1686 mconfig
= skl_get_mconfig_pb_cpr(dai
, w
);
1688 w
= dai
->capture_widget
;
1689 mconfig
= skl_get_mconfig_cap_cpr(dai
, w
);
1694 static u8
skl_tplg_be_link_type(int dev_type
)
1700 ret
= NHLT_LINK_SSP
;
1703 case SKL_DEVICE_DMIC
:
1704 ret
= NHLT_LINK_DMIC
;
1707 case SKL_DEVICE_I2S
:
1708 ret
= NHLT_LINK_SSP
;
1711 case SKL_DEVICE_HDALINK
:
1712 ret
= NHLT_LINK_HDA
;
1716 ret
= NHLT_LINK_INVALID
;
1724 * Fill the BE gateway parameters
1725 * The BE gateway expects a blob of parameters which are kept in the ACPI
1726 * NHLT blob, so query the blob for interface type (i2s/pdm) and instance.
1727 * The port can have multiple settings so pick based on the PCM
1730 static int skl_tplg_be_fill_pipe_params(struct snd_soc_dai
*dai
,
1731 struct skl_module_cfg
*mconfig
,
1732 struct skl_pipe_params
*params
)
1734 struct nhlt_specific_cfg
*cfg
;
1735 struct skl_dev
*skl
= get_skl_ctx(dai
->dev
);
1736 int link_type
= skl_tplg_be_link_type(mconfig
->dev_type
);
1737 u8 dev_type
= skl_tplg_be_dev_type(mconfig
->dev_type
);
1739 skl_tplg_fill_dma_id(mconfig
, params
);
1741 if (link_type
== NHLT_LINK_HDA
)
1744 /* update the blob based on virtual bus_id*/
1745 cfg
= skl_get_ep_blob(skl
, mconfig
->vbus_id
, link_type
,
1746 params
->s_fmt
, params
->ch
,
1747 params
->s_freq
, params
->stream
,
1750 mconfig
->formats_config
.caps_size
= cfg
->size
;
1751 mconfig
->formats_config
.caps
= (u32
*) &cfg
->caps
;
1753 dev_err(dai
->dev
, "Blob NULL for id %x type %d dirn %d\n",
1754 mconfig
->vbus_id
, link_type
,
1756 dev_err(dai
->dev
, "PCM: ch %d, freq %d, fmt %d\n",
1757 params
->ch
, params
->s_freq
, params
->s_fmt
);
1764 static int skl_tplg_be_set_src_pipe_params(struct snd_soc_dai
*dai
,
1765 struct snd_soc_dapm_widget
*w
,
1766 struct skl_pipe_params
*params
)
1768 struct snd_soc_dapm_path
*p
;
1771 snd_soc_dapm_widget_for_each_source_path(w
, p
) {
1772 if (p
->connect
&& is_skl_dsp_widget_type(p
->source
, dai
->dev
) &&
1775 ret
= skl_tplg_be_fill_pipe_params(dai
,
1776 p
->source
->priv
, params
);
1780 ret
= skl_tplg_be_set_src_pipe_params(dai
,
1790 static int skl_tplg_be_set_sink_pipe_params(struct snd_soc_dai
*dai
,
1791 struct snd_soc_dapm_widget
*w
, struct skl_pipe_params
*params
)
1793 struct snd_soc_dapm_path
*p
= NULL
;
1796 snd_soc_dapm_widget_for_each_sink_path(w
, p
) {
1797 if (p
->connect
&& is_skl_dsp_widget_type(p
->sink
, dai
->dev
) &&
1800 ret
= skl_tplg_be_fill_pipe_params(dai
,
1801 p
->sink
->priv
, params
);
1805 ret
= skl_tplg_be_set_sink_pipe_params(
1806 dai
, p
->sink
, params
);
1816 * BE hw_params can be a source parameters (capture) or sink parameters
1817 * (playback). Based on sink and source we need to either find the source
1818 * list or the sink list and set the pipeline parameters
1820 int skl_tplg_be_update_params(struct snd_soc_dai
*dai
,
1821 struct skl_pipe_params
*params
)
1823 struct snd_soc_dapm_widget
*w
;
1825 if (params
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
1826 w
= dai
->playback_widget
;
1828 return skl_tplg_be_set_src_pipe_params(dai
, w
, params
);
1831 w
= dai
->capture_widget
;
1833 return skl_tplg_be_set_sink_pipe_params(dai
, w
, params
);
1839 static const struct snd_soc_tplg_widget_events skl_tplg_widget_ops
[] = {
1840 {SKL_MIXER_EVENT
, skl_tplg_mixer_event
},
1841 {SKL_VMIXER_EVENT
, skl_tplg_mixer_event
},
1842 {SKL_PGA_EVENT
, skl_tplg_pga_event
},
1845 static const struct snd_soc_tplg_bytes_ext_ops skl_tlv_ops
[] = {
1846 {SKL_CONTROL_TYPE_BYTE_TLV
, skl_tplg_tlv_control_get
,
1847 skl_tplg_tlv_control_set
},
1850 static const struct snd_soc_tplg_kcontrol_ops skl_tplg_kcontrol_ops
[] = {
1852 .id
= SKL_CONTROL_TYPE_MIC_SELECT
,
1853 .get
= skl_tplg_mic_control_get
,
1854 .put
= skl_tplg_mic_control_set
,
1858 static int skl_tplg_fill_pipe_cfg(struct device
*dev
,
1859 struct skl_pipe
*pipe
, u32 tkn
,
1860 u32 tkn_val
, int conf_idx
, int dir
)
1862 struct skl_pipe_fmt
*fmt
;
1863 struct skl_path_config
*config
;
1867 fmt
= &pipe
->configs
[conf_idx
].in_fmt
;
1871 fmt
= &pipe
->configs
[conf_idx
].out_fmt
;
1875 dev_err(dev
, "Invalid direction: %d\n", dir
);
1879 config
= &pipe
->configs
[conf_idx
];
1882 case SKL_TKN_U32_CFG_FREQ
:
1883 fmt
->freq
= tkn_val
;
1886 case SKL_TKN_U8_CFG_CHAN
:
1887 fmt
->channels
= tkn_val
;
1890 case SKL_TKN_U8_CFG_BPS
:
1894 case SKL_TKN_U32_PATH_MEM_PGS
:
1895 config
->mem_pages
= tkn_val
;
1899 dev_err(dev
, "Invalid token config: %d\n", tkn
);
1906 static int skl_tplg_fill_pipe_tkn(struct device
*dev
,
1907 struct skl_pipe
*pipe
, u32 tkn
,
1912 case SKL_TKN_U32_PIPE_CONN_TYPE
:
1913 pipe
->conn_type
= tkn_val
;
1916 case SKL_TKN_U32_PIPE_PRIORITY
:
1917 pipe
->pipe_priority
= tkn_val
;
1920 case SKL_TKN_U32_PIPE_MEM_PGS
:
1921 pipe
->memory_pages
= tkn_val
;
1924 case SKL_TKN_U32_PMODE
:
1925 pipe
->lp_mode
= tkn_val
;
1928 case SKL_TKN_U32_PIPE_DIRECTION
:
1929 pipe
->direction
= tkn_val
;
1932 case SKL_TKN_U32_NUM_CONFIGS
:
1933 pipe
->nr_cfgs
= tkn_val
;
1937 dev_err(dev
, "Token not handled %d\n", tkn
);
1945 * Add pipeline by parsing the relevant tokens
1946 * Return an existing pipe if the pipe already exists.
1948 static int skl_tplg_add_pipe(struct device
*dev
,
1949 struct skl_module_cfg
*mconfig
, struct skl_dev
*skl
,
1950 struct snd_soc_tplg_vendor_value_elem
*tkn_elem
)
1952 struct skl_pipeline
*ppl
;
1953 struct skl_pipe
*pipe
;
1954 struct skl_pipe_params
*params
;
1956 list_for_each_entry(ppl
, &skl
->ppl_list
, node
) {
1957 if (ppl
->pipe
->ppl_id
== tkn_elem
->value
) {
1958 mconfig
->pipe
= ppl
->pipe
;
1963 ppl
= devm_kzalloc(dev
, sizeof(*ppl
), GFP_KERNEL
);
1967 pipe
= devm_kzalloc(dev
, sizeof(*pipe
), GFP_KERNEL
);
1971 params
= devm_kzalloc(dev
, sizeof(*params
), GFP_KERNEL
);
1975 pipe
->p_params
= params
;
1976 pipe
->ppl_id
= tkn_elem
->value
;
1977 INIT_LIST_HEAD(&pipe
->w_list
);
1980 list_add(&ppl
->node
, &skl
->ppl_list
);
1982 mconfig
->pipe
= pipe
;
1983 mconfig
->pipe
->state
= SKL_PIPE_INVALID
;
1988 static int skl_tplg_get_uuid(struct device
*dev
, guid_t
*guid
,
1989 struct snd_soc_tplg_vendor_uuid_elem
*uuid_tkn
)
1991 if (uuid_tkn
->token
== SKL_TKN_UUID
) {
1992 guid_copy(guid
, (guid_t
*)&uuid_tkn
->uuid
);
1996 dev_err(dev
, "Not an UUID token %d\n", uuid_tkn
->token
);
2001 static int skl_tplg_fill_pin(struct device
*dev
,
2002 struct snd_soc_tplg_vendor_value_elem
*tkn_elem
,
2003 struct skl_module_pin
*m_pin
,
2008 switch (tkn_elem
->token
) {
2009 case SKL_TKN_U32_PIN_MOD_ID
:
2010 m_pin
[pin_index
].id
.module_id
= tkn_elem
->value
;
2013 case SKL_TKN_U32_PIN_INST_ID
:
2014 m_pin
[pin_index
].id
.instance_id
= tkn_elem
->value
;
2018 ret
= skl_tplg_get_uuid(dev
, &m_pin
[pin_index
].id
.mod_uuid
,
2019 (struct snd_soc_tplg_vendor_uuid_elem
*)tkn_elem
);
2026 dev_err(dev
, "%d Not a pin token\n", tkn_elem
->token
);
2034 * Parse for pin config specific tokens to fill up the
2035 * module private data
2037 static int skl_tplg_fill_pins_info(struct device
*dev
,
2038 struct skl_module_cfg
*mconfig
,
2039 struct snd_soc_tplg_vendor_value_elem
*tkn_elem
,
2040 int dir
, int pin_count
)
2043 struct skl_module_pin
*m_pin
;
2047 m_pin
= mconfig
->m_in_pin
;
2051 m_pin
= mconfig
->m_out_pin
;
2055 dev_err(dev
, "Invalid direction value\n");
2059 ret
= skl_tplg_fill_pin(dev
, tkn_elem
, m_pin
, pin_count
);
2063 m_pin
[pin_count
].in_use
= false;
2064 m_pin
[pin_count
].pin_state
= SKL_PIN_UNBIND
;
2070 * Fill up input/output module config format based
2073 static int skl_tplg_fill_fmt(struct device
*dev
,
2074 struct skl_module_fmt
*dst_fmt
,
2078 case SKL_TKN_U32_FMT_CH
:
2079 dst_fmt
->channels
= value
;
2082 case SKL_TKN_U32_FMT_FREQ
:
2083 dst_fmt
->s_freq
= value
;
2086 case SKL_TKN_U32_FMT_BIT_DEPTH
:
2087 dst_fmt
->bit_depth
= value
;
2090 case SKL_TKN_U32_FMT_SAMPLE_SIZE
:
2091 dst_fmt
->valid_bit_depth
= value
;
2094 case SKL_TKN_U32_FMT_CH_CONFIG
:
2095 dst_fmt
->ch_cfg
= value
;
2098 case SKL_TKN_U32_FMT_INTERLEAVE
:
2099 dst_fmt
->interleaving_style
= value
;
2102 case SKL_TKN_U32_FMT_SAMPLE_TYPE
:
2103 dst_fmt
->sample_type
= value
;
2106 case SKL_TKN_U32_FMT_CH_MAP
:
2107 dst_fmt
->ch_map
= value
;
2111 dev_err(dev
, "Invalid token %d\n", tkn
);
2118 static int skl_tplg_widget_fill_fmt(struct device
*dev
,
2119 struct skl_module_iface
*fmt
,
2120 u32 tkn
, u32 val
, u32 dir
, int fmt_idx
)
2122 struct skl_module_fmt
*dst_fmt
;
2129 dst_fmt
= &fmt
->inputs
[fmt_idx
].fmt
;
2133 dst_fmt
= &fmt
->outputs
[fmt_idx
].fmt
;
2137 dev_err(dev
, "Invalid direction: %d\n", dir
);
2141 return skl_tplg_fill_fmt(dev
, dst_fmt
, tkn
, val
);
2144 static void skl_tplg_fill_pin_dynamic_val(
2145 struct skl_module_pin
*mpin
, u32 pin_count
, u32 value
)
2149 for (i
= 0; i
< pin_count
; i
++)
2150 mpin
[i
].is_dynamic
= value
;
2154 * Resource table in the manifest has pin specific resources
2155 * like pin and pin buffer size
2157 static int skl_tplg_manifest_pin_res_tkn(struct device
*dev
,
2158 struct snd_soc_tplg_vendor_value_elem
*tkn_elem
,
2159 struct skl_module_res
*res
, int pin_idx
, int dir
)
2161 struct skl_module_pin_resources
*m_pin
;
2165 m_pin
= &res
->input
[pin_idx
];
2169 m_pin
= &res
->output
[pin_idx
];
2173 dev_err(dev
, "Invalid pin direction: %d\n", dir
);
2177 switch (tkn_elem
->token
) {
2178 case SKL_TKN_MM_U32_RES_PIN_ID
:
2179 m_pin
->pin_index
= tkn_elem
->value
;
2182 case SKL_TKN_MM_U32_PIN_BUF
:
2183 m_pin
->buf_size
= tkn_elem
->value
;
2187 dev_err(dev
, "Invalid token: %d\n", tkn_elem
->token
);
2195 * Fill module specific resources from the manifest's resource
2196 * table like CPS, DMA size, mem_pages.
2198 static int skl_tplg_fill_res_tkn(struct device
*dev
,
2199 struct snd_soc_tplg_vendor_value_elem
*tkn_elem
,
2200 struct skl_module_res
*res
,
2201 int pin_idx
, int dir
)
2203 int ret
, tkn_count
= 0;
2208 switch (tkn_elem
->token
) {
2209 case SKL_TKN_MM_U32_DMA_SIZE
:
2210 res
->dma_buffer_size
= tkn_elem
->value
;
2213 case SKL_TKN_MM_U32_CPC
:
2214 res
->cpc
= tkn_elem
->value
;
2217 case SKL_TKN_U32_MEM_PAGES
:
2218 res
->is_pages
= tkn_elem
->value
;
2221 case SKL_TKN_U32_OBS
:
2222 res
->obs
= tkn_elem
->value
;
2225 case SKL_TKN_U32_IBS
:
2226 res
->ibs
= tkn_elem
->value
;
2229 case SKL_TKN_MM_U32_RES_PIN_ID
:
2230 case SKL_TKN_MM_U32_PIN_BUF
:
2231 ret
= skl_tplg_manifest_pin_res_tkn(dev
, tkn_elem
, res
,
2237 case SKL_TKN_MM_U32_CPS
:
2238 case SKL_TKN_U32_MAX_MCPS
:
2239 /* ignore unused tokens */
2243 dev_err(dev
, "Not a res type token: %d", tkn_elem
->token
);
2253 * Parse tokens to fill up the module private data
2255 static int skl_tplg_get_token(struct device
*dev
,
2256 struct snd_soc_tplg_vendor_value_elem
*tkn_elem
,
2257 struct skl_dev
*skl
, struct skl_module_cfg
*mconfig
)
2261 static int is_pipe_exists
;
2262 static int pin_index
, dir
, conf_idx
;
2263 struct skl_module_iface
*iface
= NULL
;
2264 struct skl_module_res
*res
= NULL
;
2265 int res_idx
= mconfig
->res_idx
;
2266 int fmt_idx
= mconfig
->fmt_idx
;
2269 * If the manifest structure contains no modules, fill all
2270 * the module data to 0th index.
2271 * res_idx and fmt_idx are default set to 0.
2273 if (skl
->nr_modules
== 0) {
2274 res
= &mconfig
->module
->resources
[res_idx
];
2275 iface
= &mconfig
->module
->formats
[fmt_idx
];
2278 if (tkn_elem
->token
> SKL_TKN_MAX
)
2281 switch (tkn_elem
->token
) {
2282 case SKL_TKN_U8_IN_QUEUE_COUNT
:
2283 mconfig
->module
->max_input_pins
= tkn_elem
->value
;
2286 case SKL_TKN_U8_OUT_QUEUE_COUNT
:
2287 mconfig
->module
->max_output_pins
= tkn_elem
->value
;
2290 case SKL_TKN_U8_DYN_IN_PIN
:
2291 if (!mconfig
->m_in_pin
)
2293 devm_kcalloc(dev
, MAX_IN_QUEUE
,
2294 sizeof(*mconfig
->m_in_pin
),
2296 if (!mconfig
->m_in_pin
)
2299 skl_tplg_fill_pin_dynamic_val(mconfig
->m_in_pin
, MAX_IN_QUEUE
,
2303 case SKL_TKN_U8_DYN_OUT_PIN
:
2304 if (!mconfig
->m_out_pin
)
2305 mconfig
->m_out_pin
=
2306 devm_kcalloc(dev
, MAX_IN_QUEUE
,
2307 sizeof(*mconfig
->m_in_pin
),
2309 if (!mconfig
->m_out_pin
)
2312 skl_tplg_fill_pin_dynamic_val(mconfig
->m_out_pin
, MAX_OUT_QUEUE
,
2316 case SKL_TKN_U8_TIME_SLOT
:
2317 mconfig
->time_slot
= tkn_elem
->value
;
2320 case SKL_TKN_U8_CORE_ID
:
2321 mconfig
->core_id
= tkn_elem
->value
;
2324 case SKL_TKN_U8_MOD_TYPE
:
2325 mconfig
->m_type
= tkn_elem
->value
;
2328 case SKL_TKN_U8_DEV_TYPE
:
2329 mconfig
->dev_type
= tkn_elem
->value
;
2332 case SKL_TKN_U8_HW_CONN_TYPE
:
2333 mconfig
->hw_conn_type
= tkn_elem
->value
;
2336 case SKL_TKN_U16_MOD_INST_ID
:
2337 mconfig
->id
.instance_id
=
2341 case SKL_TKN_U32_MEM_PAGES
:
2342 case SKL_TKN_U32_MAX_MCPS
:
2343 case SKL_TKN_U32_OBS
:
2344 case SKL_TKN_U32_IBS
:
2345 ret
= skl_tplg_fill_res_tkn(dev
, tkn_elem
, res
, pin_index
, dir
);
2351 case SKL_TKN_U32_VBUS_ID
:
2352 mconfig
->vbus_id
= tkn_elem
->value
;
2355 case SKL_TKN_U32_PARAMS_FIXUP
:
2356 mconfig
->params_fixup
= tkn_elem
->value
;
2359 case SKL_TKN_U32_CONVERTER
:
2360 mconfig
->converter
= tkn_elem
->value
;
2363 case SKL_TKN_U32_D0I3_CAPS
:
2364 mconfig
->d0i3_caps
= tkn_elem
->value
;
2367 case SKL_TKN_U32_PIPE_ID
:
2368 ret
= skl_tplg_add_pipe(dev
,
2369 mconfig
, skl
, tkn_elem
);
2372 if (ret
== -EEXIST
) {
2376 return is_pipe_exists
;
2381 case SKL_TKN_U32_PIPE_CONFIG_ID
:
2382 conf_idx
= tkn_elem
->value
;
2385 case SKL_TKN_U32_PIPE_CONN_TYPE
:
2386 case SKL_TKN_U32_PIPE_PRIORITY
:
2387 case SKL_TKN_U32_PIPE_MEM_PGS
:
2388 case SKL_TKN_U32_PMODE
:
2389 case SKL_TKN_U32_PIPE_DIRECTION
:
2390 case SKL_TKN_U32_NUM_CONFIGS
:
2391 if (is_pipe_exists
) {
2392 ret
= skl_tplg_fill_pipe_tkn(dev
, mconfig
->pipe
,
2393 tkn_elem
->token
, tkn_elem
->value
);
2400 case SKL_TKN_U32_PATH_MEM_PGS
:
2401 case SKL_TKN_U32_CFG_FREQ
:
2402 case SKL_TKN_U8_CFG_CHAN
:
2403 case SKL_TKN_U8_CFG_BPS
:
2404 if (mconfig
->pipe
->nr_cfgs
) {
2405 ret
= skl_tplg_fill_pipe_cfg(dev
, mconfig
->pipe
,
2406 tkn_elem
->token
, tkn_elem
->value
,
2413 case SKL_TKN_CFG_MOD_RES_ID
:
2414 mconfig
->mod_cfg
[conf_idx
].res_idx
= tkn_elem
->value
;
2417 case SKL_TKN_CFG_MOD_FMT_ID
:
2418 mconfig
->mod_cfg
[conf_idx
].fmt_idx
= tkn_elem
->value
;
2422 * SKL_TKN_U32_DIR_PIN_COUNT token has the value for both
2423 * direction and the pin count. The first four bits represent
2424 * direction and next four the pin count.
2426 case SKL_TKN_U32_DIR_PIN_COUNT
:
2427 dir
= tkn_elem
->value
& SKL_IN_DIR_BIT_MASK
;
2428 pin_index
= (tkn_elem
->value
&
2429 SKL_PIN_COUNT_MASK
) >> 4;
2433 case SKL_TKN_U32_FMT_CH
:
2434 case SKL_TKN_U32_FMT_FREQ
:
2435 case SKL_TKN_U32_FMT_BIT_DEPTH
:
2436 case SKL_TKN_U32_FMT_SAMPLE_SIZE
:
2437 case SKL_TKN_U32_FMT_CH_CONFIG
:
2438 case SKL_TKN_U32_FMT_INTERLEAVE
:
2439 case SKL_TKN_U32_FMT_SAMPLE_TYPE
:
2440 case SKL_TKN_U32_FMT_CH_MAP
:
2441 ret
= skl_tplg_widget_fill_fmt(dev
, iface
, tkn_elem
->token
,
2442 tkn_elem
->value
, dir
, pin_index
);
2449 case SKL_TKN_U32_PIN_MOD_ID
:
2450 case SKL_TKN_U32_PIN_INST_ID
:
2452 ret
= skl_tplg_fill_pins_info(dev
,
2453 mconfig
, tkn_elem
, dir
,
2460 case SKL_TKN_U32_CAPS_SIZE
:
2461 mconfig
->formats_config
.caps_size
=
2466 case SKL_TKN_U32_CAPS_SET_PARAMS
:
2467 mconfig
->formats_config
.set_params
=
2471 case SKL_TKN_U32_CAPS_PARAMS_ID
:
2472 mconfig
->formats_config
.param_id
=
2476 case SKL_TKN_U32_PROC_DOMAIN
:
2482 case SKL_TKN_U32_DMA_BUF_SIZE
:
2483 mconfig
->dma_buffer_size
= tkn_elem
->value
;
2486 case SKL_TKN_U8_IN_PIN_TYPE
:
2487 case SKL_TKN_U8_OUT_PIN_TYPE
:
2488 case SKL_TKN_U8_CONN_TYPE
:
2492 dev_err(dev
, "Token %d not handled\n",
2503 * Parse the vendor array for specific tokens to construct
2504 * module private data
2506 static int skl_tplg_get_tokens(struct device
*dev
,
2507 char *pvt_data
, struct skl_dev
*skl
,
2508 struct skl_module_cfg
*mconfig
, int block_size
)
2510 struct snd_soc_tplg_vendor_array
*array
;
2511 struct snd_soc_tplg_vendor_value_elem
*tkn_elem
;
2512 int tkn_count
= 0, ret
;
2513 int off
= 0, tuple_size
= 0;
2514 bool is_module_guid
= true;
2516 if (block_size
<= 0)
2519 while (tuple_size
< block_size
) {
2520 array
= (struct snd_soc_tplg_vendor_array
*)(pvt_data
+ off
);
2524 switch (array
->type
) {
2525 case SND_SOC_TPLG_TUPLE_TYPE_STRING
:
2526 dev_warn(dev
, "no string tokens expected for skl tplg\n");
2529 case SND_SOC_TPLG_TUPLE_TYPE_UUID
:
2530 if (is_module_guid
) {
2531 ret
= skl_tplg_get_uuid(dev
, (guid_t
*)mconfig
->guid
,
2533 is_module_guid
= false;
2535 ret
= skl_tplg_get_token(dev
, array
->value
, skl
,
2542 tuple_size
+= sizeof(*array
->uuid
);
2547 tkn_elem
= array
->value
;
2552 while (tkn_count
<= (array
->num_elems
- 1)) {
2553 ret
= skl_tplg_get_token(dev
, tkn_elem
,
2559 tkn_count
= tkn_count
+ ret
;
2563 tuple_size
+= tkn_count
* sizeof(*tkn_elem
);
2570 * Every data block is preceded by a descriptor to read the number
2571 * of data blocks, they type of the block and it's size
2573 static int skl_tplg_get_desc_blocks(struct device
*dev
,
2574 struct snd_soc_tplg_vendor_array
*array
)
2576 struct snd_soc_tplg_vendor_value_elem
*tkn_elem
;
2578 tkn_elem
= array
->value
;
2580 switch (tkn_elem
->token
) {
2581 case SKL_TKN_U8_NUM_BLOCKS
:
2582 case SKL_TKN_U8_BLOCK_TYPE
:
2583 case SKL_TKN_U16_BLOCK_SIZE
:
2584 return tkn_elem
->value
;
2587 dev_err(dev
, "Invalid descriptor token %d\n", tkn_elem
->token
);
2594 /* Functions to parse private data from configuration file format v4 */
2597 * Add pipeline from topology binary into driver pipeline list
2599 * If already added we return that instance
2600 * Otherwise we create a new instance and add into driver list
2602 static int skl_tplg_add_pipe_v4(struct device
*dev
,
2603 struct skl_module_cfg
*mconfig
, struct skl_dev
*skl
,
2604 struct skl_dfw_v4_pipe
*dfw_pipe
)
2606 struct skl_pipeline
*ppl
;
2607 struct skl_pipe
*pipe
;
2608 struct skl_pipe_params
*params
;
2610 list_for_each_entry(ppl
, &skl
->ppl_list
, node
) {
2611 if (ppl
->pipe
->ppl_id
== dfw_pipe
->pipe_id
) {
2612 mconfig
->pipe
= ppl
->pipe
;
2617 ppl
= devm_kzalloc(dev
, sizeof(*ppl
), GFP_KERNEL
);
2621 pipe
= devm_kzalloc(dev
, sizeof(*pipe
), GFP_KERNEL
);
2625 params
= devm_kzalloc(dev
, sizeof(*params
), GFP_KERNEL
);
2629 pipe
->ppl_id
= dfw_pipe
->pipe_id
;
2630 pipe
->memory_pages
= dfw_pipe
->memory_pages
;
2631 pipe
->pipe_priority
= dfw_pipe
->pipe_priority
;
2632 pipe
->conn_type
= dfw_pipe
->conn_type
;
2633 pipe
->state
= SKL_PIPE_INVALID
;
2634 pipe
->p_params
= params
;
2635 INIT_LIST_HEAD(&pipe
->w_list
);
2638 list_add(&ppl
->node
, &skl
->ppl_list
);
2640 mconfig
->pipe
= pipe
;
2645 static void skl_fill_module_pin_info_v4(struct skl_dfw_v4_module_pin
*dfw_pin
,
2646 struct skl_module_pin
*m_pin
,
2647 bool is_dynamic
, int max_pin
)
2651 for (i
= 0; i
< max_pin
; i
++) {
2652 m_pin
[i
].id
.module_id
= dfw_pin
[i
].module_id
;
2653 m_pin
[i
].id
.instance_id
= dfw_pin
[i
].instance_id
;
2654 m_pin
[i
].in_use
= false;
2655 m_pin
[i
].is_dynamic
= is_dynamic
;
2656 m_pin
[i
].pin_state
= SKL_PIN_UNBIND
;
2660 static void skl_tplg_fill_fmt_v4(struct skl_module_pin_fmt
*dst_fmt
,
2661 struct skl_dfw_v4_module_fmt
*src_fmt
,
2666 for (i
= 0; i
< pins
; i
++) {
2667 dst_fmt
[i
].fmt
.channels
= src_fmt
[i
].channels
;
2668 dst_fmt
[i
].fmt
.s_freq
= src_fmt
[i
].freq
;
2669 dst_fmt
[i
].fmt
.bit_depth
= src_fmt
[i
].bit_depth
;
2670 dst_fmt
[i
].fmt
.valid_bit_depth
= src_fmt
[i
].valid_bit_depth
;
2671 dst_fmt
[i
].fmt
.ch_cfg
= src_fmt
[i
].ch_cfg
;
2672 dst_fmt
[i
].fmt
.ch_map
= src_fmt
[i
].ch_map
;
2673 dst_fmt
[i
].fmt
.interleaving_style
=
2674 src_fmt
[i
].interleaving_style
;
2675 dst_fmt
[i
].fmt
.sample_type
= src_fmt
[i
].sample_type
;
2679 static int skl_tplg_get_pvt_data_v4(struct snd_soc_tplg_dapm_widget
*tplg_w
,
2680 struct skl_dev
*skl
, struct device
*dev
,
2681 struct skl_module_cfg
*mconfig
)
2683 struct skl_dfw_v4_module
*dfw
=
2684 (struct skl_dfw_v4_module
*)tplg_w
->priv
.data
;
2687 dev_dbg(dev
, "Parsing Skylake v4 widget topology data\n");
2689 ret
= guid_parse(dfw
->uuid
, (guid_t
*)mconfig
->guid
);
2692 mconfig
->id
.module_id
= -1;
2693 mconfig
->id
.instance_id
= dfw
->instance_id
;
2694 mconfig
->module
->resources
[0].cpc
= dfw
->max_mcps
/ 1000;
2695 mconfig
->module
->resources
[0].ibs
= dfw
->ibs
;
2696 mconfig
->module
->resources
[0].obs
= dfw
->obs
;
2697 mconfig
->core_id
= dfw
->core_id
;
2698 mconfig
->module
->max_input_pins
= dfw
->max_in_queue
;
2699 mconfig
->module
->max_output_pins
= dfw
->max_out_queue
;
2700 mconfig
->module
->loadable
= dfw
->is_loadable
;
2701 skl_tplg_fill_fmt_v4(mconfig
->module
->formats
[0].inputs
, dfw
->in_fmt
,
2703 skl_tplg_fill_fmt_v4(mconfig
->module
->formats
[0].outputs
, dfw
->out_fmt
,
2706 mconfig
->params_fixup
= dfw
->params_fixup
;
2707 mconfig
->converter
= dfw
->converter
;
2708 mconfig
->m_type
= dfw
->module_type
;
2709 mconfig
->vbus_id
= dfw
->vbus_id
;
2710 mconfig
->module
->resources
[0].is_pages
= dfw
->mem_pages
;
2712 ret
= skl_tplg_add_pipe_v4(dev
, mconfig
, skl
, &dfw
->pipe
);
2716 mconfig
->dev_type
= dfw
->dev_type
;
2717 mconfig
->hw_conn_type
= dfw
->hw_conn_type
;
2718 mconfig
->time_slot
= dfw
->time_slot
;
2719 mconfig
->formats_config
.caps_size
= dfw
->caps
.caps_size
;
2721 mconfig
->m_in_pin
= devm_kcalloc(dev
,
2722 MAX_IN_QUEUE
, sizeof(*mconfig
->m_in_pin
),
2724 if (!mconfig
->m_in_pin
)
2727 mconfig
->m_out_pin
= devm_kcalloc(dev
,
2728 MAX_OUT_QUEUE
, sizeof(*mconfig
->m_out_pin
),
2730 if (!mconfig
->m_out_pin
)
2733 skl_fill_module_pin_info_v4(dfw
->in_pin
, mconfig
->m_in_pin
,
2734 dfw
->is_dynamic_in_pin
,
2735 mconfig
->module
->max_input_pins
);
2736 skl_fill_module_pin_info_v4(dfw
->out_pin
, mconfig
->m_out_pin
,
2737 dfw
->is_dynamic_out_pin
,
2738 mconfig
->module
->max_output_pins
);
2740 if (mconfig
->formats_config
.caps_size
) {
2741 mconfig
->formats_config
.set_params
= dfw
->caps
.set_params
;
2742 mconfig
->formats_config
.param_id
= dfw
->caps
.param_id
;
2743 mconfig
->formats_config
.caps
=
2744 devm_kzalloc(dev
, mconfig
->formats_config
.caps_size
,
2746 if (!mconfig
->formats_config
.caps
)
2748 memcpy(mconfig
->formats_config
.caps
, dfw
->caps
.caps
,
2749 dfw
->caps
.caps_size
);
2756 * Parse the private data for the token and corresponding value.
2757 * The private data can have multiple data blocks. So, a data block
2758 * is preceded by a descriptor for number of blocks and a descriptor
2759 * for the type and size of the suceeding data block.
2761 static int skl_tplg_get_pvt_data(struct snd_soc_tplg_dapm_widget
*tplg_w
,
2762 struct skl_dev
*skl
, struct device
*dev
,
2763 struct skl_module_cfg
*mconfig
)
2765 struct snd_soc_tplg_vendor_array
*array
;
2766 int num_blocks
, block_size
= 0, block_type
, off
= 0;
2771 * v4 configuration files have a valid UUID at the start of
2772 * the widget's private data.
2774 if (uuid_is_valid((char *)tplg_w
->priv
.data
))
2775 return skl_tplg_get_pvt_data_v4(tplg_w
, skl
, dev
, mconfig
);
2777 /* Read the NUM_DATA_BLOCKS descriptor */
2778 array
= (struct snd_soc_tplg_vendor_array
*)tplg_w
->priv
.data
;
2779 ret
= skl_tplg_get_desc_blocks(dev
, array
);
2785 /* Read the BLOCK_TYPE and BLOCK_SIZE descriptor */
2786 while (num_blocks
> 0) {
2787 array
= (struct snd_soc_tplg_vendor_array
*)
2788 (tplg_w
->priv
.data
+ off
);
2790 ret
= skl_tplg_get_desc_blocks(dev
, array
);
2797 array
= (struct snd_soc_tplg_vendor_array
*)
2798 (tplg_w
->priv
.data
+ off
);
2800 ret
= skl_tplg_get_desc_blocks(dev
, array
);
2807 array
= (struct snd_soc_tplg_vendor_array
*)
2808 (tplg_w
->priv
.data
+ off
);
2810 data
= (tplg_w
->priv
.data
+ off
);
2812 if (block_type
== SKL_TYPE_TUPLE
) {
2813 ret
= skl_tplg_get_tokens(dev
, data
,
2814 skl
, mconfig
, block_size
);
2821 if (mconfig
->formats_config
.caps_size
> 0)
2822 memcpy(mconfig
->formats_config
.caps
, data
,
2823 mconfig
->formats_config
.caps_size
);
2825 ret
= mconfig
->formats_config
.caps_size
;
2833 static void skl_clear_pin_config(struct snd_soc_component
*component
,
2834 struct snd_soc_dapm_widget
*w
)
2837 struct skl_module_cfg
*mconfig
;
2838 struct skl_pipe
*pipe
;
2840 if (!strncmp(w
->dapm
->component
->name
, component
->name
,
2841 strlen(component
->name
))) {
2843 pipe
= mconfig
->pipe
;
2844 for (i
= 0; i
< mconfig
->module
->max_input_pins
; i
++) {
2845 mconfig
->m_in_pin
[i
].in_use
= false;
2846 mconfig
->m_in_pin
[i
].pin_state
= SKL_PIN_UNBIND
;
2848 for (i
= 0; i
< mconfig
->module
->max_output_pins
; i
++) {
2849 mconfig
->m_out_pin
[i
].in_use
= false;
2850 mconfig
->m_out_pin
[i
].pin_state
= SKL_PIN_UNBIND
;
2852 pipe
->state
= SKL_PIPE_INVALID
;
2853 mconfig
->m_state
= SKL_MODULE_UNINIT
;
2857 void skl_cleanup_resources(struct skl_dev
*skl
)
2859 struct snd_soc_component
*soc_component
= skl
->component
;
2860 struct snd_soc_dapm_widget
*w
;
2861 struct snd_soc_card
*card
;
2863 if (soc_component
== NULL
)
2866 card
= soc_component
->card
;
2867 if (!card
|| !card
->instantiated
)
2870 list_for_each_entry(w
, &card
->widgets
, list
) {
2871 if (is_skl_dsp_widget_type(w
, skl
->dev
) && w
->priv
!= NULL
)
2872 skl_clear_pin_config(soc_component
, w
);
2875 skl_clear_module_cnt(skl
->dsp
);
2879 * Topology core widget load callback
2881 * This is used to save the private data for each widget which gives
2882 * information to the driver about module and pipeline parameters which DSP
2883 * FW expects like ids, resource values, formats etc
2885 static int skl_tplg_widget_load(struct snd_soc_component
*cmpnt
, int index
,
2886 struct snd_soc_dapm_widget
*w
,
2887 struct snd_soc_tplg_dapm_widget
*tplg_w
)
2890 struct hdac_bus
*bus
= snd_soc_component_get_drvdata(cmpnt
);
2891 struct skl_dev
*skl
= bus_to_skl(bus
);
2892 struct skl_module_cfg
*mconfig
;
2894 if (!tplg_w
->priv
.size
)
2897 mconfig
= devm_kzalloc(bus
->dev
, sizeof(*mconfig
), GFP_KERNEL
);
2902 if (skl
->nr_modules
== 0) {
2903 mconfig
->module
= devm_kzalloc(bus
->dev
,
2904 sizeof(*mconfig
->module
), GFP_KERNEL
);
2905 if (!mconfig
->module
)
2912 * module binary can be loaded later, so set it to query when
2913 * module is load for a use case
2915 mconfig
->id
.module_id
= -1;
2917 /* Parse private data for tuples */
2918 ret
= skl_tplg_get_pvt_data(tplg_w
, skl
, bus
->dev
, mconfig
);
2922 skl_debug_init_module(skl
->debugfs
, w
, mconfig
);
2925 if (tplg_w
->event_type
== 0) {
2926 dev_dbg(bus
->dev
, "ASoC: No event handler required\n");
2930 ret
= snd_soc_tplg_widget_bind_event(w
, skl_tplg_widget_ops
,
2931 ARRAY_SIZE(skl_tplg_widget_ops
),
2932 tplg_w
->event_type
);
2935 dev_err(bus
->dev
, "%s: No matching event handlers found for %d\n",
2936 __func__
, tplg_w
->event_type
);
2943 static int skl_init_algo_data(struct device
*dev
, struct soc_bytes_ext
*be
,
2944 struct snd_soc_tplg_bytes_control
*bc
)
2946 struct skl_algo_data
*ac
;
2947 struct skl_dfw_algo_data
*dfw_ac
=
2948 (struct skl_dfw_algo_data
*)bc
->priv
.data
;
2950 ac
= devm_kzalloc(dev
, sizeof(*ac
), GFP_KERNEL
);
2954 /* Fill private data */
2955 ac
->max
= dfw_ac
->max
;
2956 ac
->param_id
= dfw_ac
->param_id
;
2957 ac
->set_params
= dfw_ac
->set_params
;
2958 ac
->size
= dfw_ac
->max
;
2961 ac
->params
= devm_kzalloc(dev
, ac
->max
, GFP_KERNEL
);
2965 memcpy(ac
->params
, dfw_ac
->params
, ac
->max
);
2968 be
->dobj
.private = ac
;
2972 static int skl_init_enum_data(struct device
*dev
, struct soc_enum
*se
,
2973 struct snd_soc_tplg_enum_control
*ec
)
2978 if (ec
->priv
.size
) {
2979 data
= devm_kzalloc(dev
, sizeof(ec
->priv
.size
), GFP_KERNEL
);
2982 memcpy(data
, ec
->priv
.data
, ec
->priv
.size
);
2983 se
->dobj
.private = data
;
2990 static int skl_tplg_control_load(struct snd_soc_component
*cmpnt
,
2992 struct snd_kcontrol_new
*kctl
,
2993 struct snd_soc_tplg_ctl_hdr
*hdr
)
2995 struct soc_bytes_ext
*sb
;
2996 struct snd_soc_tplg_bytes_control
*tplg_bc
;
2997 struct snd_soc_tplg_enum_control
*tplg_ec
;
2998 struct hdac_bus
*bus
= snd_soc_component_get_drvdata(cmpnt
);
2999 struct soc_enum
*se
;
3001 switch (hdr
->ops
.info
) {
3002 case SND_SOC_TPLG_CTL_BYTES
:
3003 tplg_bc
= container_of(hdr
,
3004 struct snd_soc_tplg_bytes_control
, hdr
);
3005 if (kctl
->access
& SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK
) {
3006 sb
= (struct soc_bytes_ext
*)kctl
->private_value
;
3007 if (tplg_bc
->priv
.size
)
3008 return skl_init_algo_data(
3009 bus
->dev
, sb
, tplg_bc
);
3013 case SND_SOC_TPLG_CTL_ENUM
:
3014 tplg_ec
= container_of(hdr
,
3015 struct snd_soc_tplg_enum_control
, hdr
);
3016 if (kctl
->access
& SNDRV_CTL_ELEM_ACCESS_READWRITE
) {
3017 se
= (struct soc_enum
*)kctl
->private_value
;
3018 if (tplg_ec
->priv
.size
)
3019 return skl_init_enum_data(bus
->dev
, se
,
3025 dev_dbg(bus
->dev
, "Control load not supported %d:%d:%d\n",
3026 hdr
->ops
.get
, hdr
->ops
.put
, hdr
->ops
.info
);
3033 static int skl_tplg_fill_str_mfest_tkn(struct device
*dev
,
3034 struct snd_soc_tplg_vendor_string_elem
*str_elem
,
3035 struct skl_dev
*skl
)
3038 static int ref_count
;
3040 switch (str_elem
->token
) {
3041 case SKL_TKN_STR_LIB_NAME
:
3042 if (ref_count
> skl
->lib_count
- 1) {
3047 strncpy(skl
->lib_info
[ref_count
].name
,
3049 ARRAY_SIZE(skl
->lib_info
[ref_count
].name
));
3054 dev_err(dev
, "Not a string token %d\n", str_elem
->token
);
3062 static int skl_tplg_get_str_tkn(struct device
*dev
,
3063 struct snd_soc_tplg_vendor_array
*array
,
3064 struct skl_dev
*skl
)
3066 int tkn_count
= 0, ret
;
3067 struct snd_soc_tplg_vendor_string_elem
*str_elem
;
3069 str_elem
= (struct snd_soc_tplg_vendor_string_elem
*)array
->value
;
3070 while (tkn_count
< array
->num_elems
) {
3071 ret
= skl_tplg_fill_str_mfest_tkn(dev
, str_elem
, skl
);
3077 tkn_count
= tkn_count
+ ret
;
3083 static int skl_tplg_manifest_fill_fmt(struct device
*dev
,
3084 struct skl_module_iface
*fmt
,
3085 struct snd_soc_tplg_vendor_value_elem
*tkn_elem
,
3086 u32 dir
, int fmt_idx
)
3088 struct skl_module_pin_fmt
*dst_fmt
;
3089 struct skl_module_fmt
*mod_fmt
;
3097 dst_fmt
= &fmt
->inputs
[fmt_idx
];
3101 dst_fmt
= &fmt
->outputs
[fmt_idx
];
3105 dev_err(dev
, "Invalid direction: %d\n", dir
);
3109 mod_fmt
= &dst_fmt
->fmt
;
3111 switch (tkn_elem
->token
) {
3112 case SKL_TKN_MM_U32_INTF_PIN_ID
:
3113 dst_fmt
->id
= tkn_elem
->value
;
3117 ret
= skl_tplg_fill_fmt(dev
, mod_fmt
, tkn_elem
->token
,
3127 static int skl_tplg_fill_mod_info(struct device
*dev
,
3128 struct snd_soc_tplg_vendor_value_elem
*tkn_elem
,
3129 struct skl_module
*mod
)
3135 switch (tkn_elem
->token
) {
3136 case SKL_TKN_U8_IN_PIN_TYPE
:
3137 mod
->input_pin_type
= tkn_elem
->value
;
3140 case SKL_TKN_U8_OUT_PIN_TYPE
:
3141 mod
->output_pin_type
= tkn_elem
->value
;
3144 case SKL_TKN_U8_IN_QUEUE_COUNT
:
3145 mod
->max_input_pins
= tkn_elem
->value
;
3148 case SKL_TKN_U8_OUT_QUEUE_COUNT
:
3149 mod
->max_output_pins
= tkn_elem
->value
;
3152 case SKL_TKN_MM_U8_NUM_RES
:
3153 mod
->nr_resources
= tkn_elem
->value
;
3156 case SKL_TKN_MM_U8_NUM_INTF
:
3157 mod
->nr_interfaces
= tkn_elem
->value
;
3161 dev_err(dev
, "Invalid mod info token %d", tkn_elem
->token
);
3169 static int skl_tplg_get_int_tkn(struct device
*dev
,
3170 struct snd_soc_tplg_vendor_value_elem
*tkn_elem
,
3171 struct skl_dev
*skl
)
3173 int tkn_count
= 0, ret
;
3174 static int mod_idx
, res_val_idx
, intf_val_idx
, dir
, pin_idx
;
3175 struct skl_module_res
*res
= NULL
;
3176 struct skl_module_iface
*fmt
= NULL
;
3177 struct skl_module
*mod
= NULL
;
3178 static struct skl_astate_param
*astate_table
;
3179 static int astate_cfg_idx
, count
;
3184 mod
= skl
->modules
[mod_idx
];
3185 res
= &mod
->resources
[res_val_idx
];
3186 fmt
= &mod
->formats
[intf_val_idx
];
3189 switch (tkn_elem
->token
) {
3190 case SKL_TKN_U32_LIB_COUNT
:
3191 skl
->lib_count
= tkn_elem
->value
;
3194 case SKL_TKN_U8_NUM_MOD
:
3195 skl
->nr_modules
= tkn_elem
->value
;
3196 skl
->modules
= devm_kcalloc(dev
, skl
->nr_modules
,
3197 sizeof(*skl
->modules
), GFP_KERNEL
);
3201 for (i
= 0; i
< skl
->nr_modules
; i
++) {
3202 skl
->modules
[i
] = devm_kzalloc(dev
,
3203 sizeof(struct skl_module
), GFP_KERNEL
);
3204 if (!skl
->modules
[i
])
3209 case SKL_TKN_MM_U8_MOD_IDX
:
3210 mod_idx
= tkn_elem
->value
;
3213 case SKL_TKN_U32_ASTATE_COUNT
:
3214 if (astate_table
!= NULL
) {
3215 dev_err(dev
, "More than one entry for A-State count");
3219 if (tkn_elem
->value
> SKL_MAX_ASTATE_CFG
) {
3220 dev_err(dev
, "Invalid A-State count %d\n",
3225 size
= struct_size(skl
->cfg
.astate_cfg
, astate_table
,
3227 skl
->cfg
.astate_cfg
= devm_kzalloc(dev
, size
, GFP_KERNEL
);
3228 if (!skl
->cfg
.astate_cfg
)
3231 astate_table
= skl
->cfg
.astate_cfg
->astate_table
;
3232 count
= skl
->cfg
.astate_cfg
->count
= tkn_elem
->value
;
3235 case SKL_TKN_U32_ASTATE_IDX
:
3236 if (tkn_elem
->value
>= count
) {
3237 dev_err(dev
, "Invalid A-State index %d\n",
3242 astate_cfg_idx
= tkn_elem
->value
;
3245 case SKL_TKN_U32_ASTATE_KCPS
:
3246 astate_table
[astate_cfg_idx
].kcps
= tkn_elem
->value
;
3249 case SKL_TKN_U32_ASTATE_CLK_SRC
:
3250 astate_table
[astate_cfg_idx
].clk_src
= tkn_elem
->value
;
3253 case SKL_TKN_U8_IN_PIN_TYPE
:
3254 case SKL_TKN_U8_OUT_PIN_TYPE
:
3255 case SKL_TKN_U8_IN_QUEUE_COUNT
:
3256 case SKL_TKN_U8_OUT_QUEUE_COUNT
:
3257 case SKL_TKN_MM_U8_NUM_RES
:
3258 case SKL_TKN_MM_U8_NUM_INTF
:
3259 ret
= skl_tplg_fill_mod_info(dev
, tkn_elem
, mod
);
3264 case SKL_TKN_U32_DIR_PIN_COUNT
:
3265 dir
= tkn_elem
->value
& SKL_IN_DIR_BIT_MASK
;
3266 pin_idx
= (tkn_elem
->value
& SKL_PIN_COUNT_MASK
) >> 4;
3269 case SKL_TKN_MM_U32_RES_ID
:
3273 res
->id
= tkn_elem
->value
;
3274 res_val_idx
= tkn_elem
->value
;
3277 case SKL_TKN_MM_U32_FMT_ID
:
3281 fmt
->fmt_idx
= tkn_elem
->value
;
3282 intf_val_idx
= tkn_elem
->value
;
3285 case SKL_TKN_MM_U32_CPS
:
3286 case SKL_TKN_MM_U32_DMA_SIZE
:
3287 case SKL_TKN_MM_U32_CPC
:
3288 case SKL_TKN_U32_MEM_PAGES
:
3289 case SKL_TKN_U32_OBS
:
3290 case SKL_TKN_U32_IBS
:
3291 case SKL_TKN_MM_U32_RES_PIN_ID
:
3292 case SKL_TKN_MM_U32_PIN_BUF
:
3293 ret
= skl_tplg_fill_res_tkn(dev
, tkn_elem
, res
, pin_idx
, dir
);
3299 case SKL_TKN_MM_U32_NUM_IN_FMT
:
3303 res
->nr_input_pins
= tkn_elem
->value
;
3306 case SKL_TKN_MM_U32_NUM_OUT_FMT
:
3310 res
->nr_output_pins
= tkn_elem
->value
;
3313 case SKL_TKN_U32_FMT_CH
:
3314 case SKL_TKN_U32_FMT_FREQ
:
3315 case SKL_TKN_U32_FMT_BIT_DEPTH
:
3316 case SKL_TKN_U32_FMT_SAMPLE_SIZE
:
3317 case SKL_TKN_U32_FMT_CH_CONFIG
:
3318 case SKL_TKN_U32_FMT_INTERLEAVE
:
3319 case SKL_TKN_U32_FMT_SAMPLE_TYPE
:
3320 case SKL_TKN_U32_FMT_CH_MAP
:
3321 case SKL_TKN_MM_U32_INTF_PIN_ID
:
3322 ret
= skl_tplg_manifest_fill_fmt(dev
, fmt
, tkn_elem
,
3329 dev_err(dev
, "Not a manifest token %d\n", tkn_elem
->token
);
3338 * Fill the manifest structure by parsing the tokens based on the
3341 static int skl_tplg_get_manifest_tkn(struct device
*dev
,
3342 char *pvt_data
, struct skl_dev
*skl
,
3345 int tkn_count
= 0, ret
;
3346 int off
= 0, tuple_size
= 0;
3348 struct snd_soc_tplg_vendor_array
*array
;
3349 struct snd_soc_tplg_vendor_value_elem
*tkn_elem
;
3351 if (block_size
<= 0)
3354 while (tuple_size
< block_size
) {
3355 array
= (struct snd_soc_tplg_vendor_array
*)(pvt_data
+ off
);
3357 switch (array
->type
) {
3358 case SND_SOC_TPLG_TUPLE_TYPE_STRING
:
3359 ret
= skl_tplg_get_str_tkn(dev
, array
, skl
);
3365 tuple_size
+= tkn_count
*
3366 sizeof(struct snd_soc_tplg_vendor_string_elem
);
3369 case SND_SOC_TPLG_TUPLE_TYPE_UUID
:
3370 if (array
->uuid
->token
!= SKL_TKN_UUID
) {
3371 dev_err(dev
, "Not an UUID token: %d\n",
3372 array
->uuid
->token
);
3375 if (uuid_index
>= skl
->nr_modules
) {
3376 dev_err(dev
, "Too many UUID tokens\n");
3379 guid_copy(&skl
->modules
[uuid_index
++]->uuid
,
3380 (guid_t
*)&array
->uuid
->uuid
);
3382 tuple_size
+= sizeof(*array
->uuid
);
3386 tkn_elem
= array
->value
;
3391 while (tkn_count
<= array
->num_elems
- 1) {
3392 ret
= skl_tplg_get_int_tkn(dev
,
3397 tkn_count
= tkn_count
+ ret
;
3400 tuple_size
+= (tkn_count
* sizeof(*tkn_elem
));
3408 * Parse manifest private data for tokens. The private data block is
3409 * preceded by descriptors for type and size of data block.
3411 static int skl_tplg_get_manifest_data(struct snd_soc_tplg_manifest
*manifest
,
3412 struct device
*dev
, struct skl_dev
*skl
)
3414 struct snd_soc_tplg_vendor_array
*array
;
3415 int num_blocks
, block_size
= 0, block_type
, off
= 0;
3419 /* Read the NUM_DATA_BLOCKS descriptor */
3420 array
= (struct snd_soc_tplg_vendor_array
*)manifest
->priv
.data
;
3421 ret
= skl_tplg_get_desc_blocks(dev
, array
);
3427 /* Read the BLOCK_TYPE and BLOCK_SIZE descriptor */
3428 while (num_blocks
> 0) {
3429 array
= (struct snd_soc_tplg_vendor_array
*)
3430 (manifest
->priv
.data
+ off
);
3431 ret
= skl_tplg_get_desc_blocks(dev
, array
);
3438 array
= (struct snd_soc_tplg_vendor_array
*)
3439 (manifest
->priv
.data
+ off
);
3441 ret
= skl_tplg_get_desc_blocks(dev
, array
);
3448 array
= (struct snd_soc_tplg_vendor_array
*)
3449 (manifest
->priv
.data
+ off
);
3451 data
= (manifest
->priv
.data
+ off
);
3453 if (block_type
== SKL_TYPE_TUPLE
) {
3454 ret
= skl_tplg_get_manifest_tkn(dev
, data
, skl
,
3470 static int skl_manifest_load(struct snd_soc_component
*cmpnt
, int index
,
3471 struct snd_soc_tplg_manifest
*manifest
)
3473 struct hdac_bus
*bus
= snd_soc_component_get_drvdata(cmpnt
);
3474 struct skl_dev
*skl
= bus_to_skl(bus
);
3476 /* proceed only if we have private data defined */
3477 if (manifest
->priv
.size
== 0)
3480 skl_tplg_get_manifest_data(manifest
, bus
->dev
, skl
);
3482 if (skl
->lib_count
> SKL_MAX_LIB
) {
3483 dev_err(bus
->dev
, "Exceeding max Library count. Got:%d\n",
3491 static struct snd_soc_tplg_ops skl_tplg_ops
= {
3492 .widget_load
= skl_tplg_widget_load
,
3493 .control_load
= skl_tplg_control_load
,
3494 .bytes_ext_ops
= skl_tlv_ops
,
3495 .bytes_ext_ops_count
= ARRAY_SIZE(skl_tlv_ops
),
3496 .io_ops
= skl_tplg_kcontrol_ops
,
3497 .io_ops_count
= ARRAY_SIZE(skl_tplg_kcontrol_ops
),
3498 .manifest
= skl_manifest_load
,
3499 .dai_load
= skl_dai_load
,
3503 * A pipe can have multiple modules, each of them will be a DAPM widget as
3504 * well. While managing a pipeline we need to get the list of all the
3505 * widgets in a pipelines, so this helper - skl_tplg_create_pipe_widget_list()
3506 * helps to get the SKL type widgets in that pipeline
3508 static int skl_tplg_create_pipe_widget_list(struct snd_soc_component
*component
)
3510 struct snd_soc_dapm_widget
*w
;
3511 struct skl_module_cfg
*mcfg
= NULL
;
3512 struct skl_pipe_module
*p_module
= NULL
;
3513 struct skl_pipe
*pipe
;
3515 list_for_each_entry(w
, &component
->card
->widgets
, list
) {
3516 if (is_skl_dsp_widget_type(w
, component
->dev
) && w
->priv
) {
3520 p_module
= devm_kzalloc(component
->dev
,
3521 sizeof(*p_module
), GFP_KERNEL
);
3526 list_add_tail(&p_module
->node
, &pipe
->w_list
);
3533 static void skl_tplg_set_pipe_type(struct skl_dev
*skl
, struct skl_pipe
*pipe
)
3535 struct skl_pipe_module
*w_module
;
3536 struct snd_soc_dapm_widget
*w
;
3537 struct skl_module_cfg
*mconfig
;
3538 bool host_found
= false, link_found
= false;
3540 list_for_each_entry(w_module
, &pipe
->w_list
, node
) {
3544 if (mconfig
->dev_type
== SKL_DEVICE_HDAHOST
)
3546 else if (mconfig
->dev_type
!= SKL_DEVICE_NONE
)
3550 if (host_found
&& link_found
)
3551 pipe
->passthru
= true;
3553 pipe
->passthru
= false;
3557 * SKL topology init routine
3559 int skl_tplg_init(struct snd_soc_component
*component
, struct hdac_bus
*bus
)
3562 const struct firmware
*fw
;
3563 struct skl_dev
*skl
= bus_to_skl(bus
);
3564 struct skl_pipeline
*ppl
;
3566 ret
= request_firmware(&fw
, skl
->tplg_name
, bus
->dev
);
3568 dev_info(bus
->dev
, "tplg fw %s load failed with %d, falling back to dfw_sst.bin",
3569 skl
->tplg_name
, ret
);
3570 ret
= request_firmware(&fw
, "dfw_sst.bin", bus
->dev
);
3572 dev_err(bus
->dev
, "Fallback tplg fw %s load failed with %d\n",
3573 "dfw_sst.bin", ret
);
3579 * The complete tplg for SKL is loaded as index 0, we don't use
3582 ret
= snd_soc_tplg_component_load(component
, &skl_tplg_ops
, fw
, 0);
3584 dev_err(bus
->dev
, "tplg component load failed%d\n", ret
);
3588 ret
= skl_tplg_create_pipe_widget_list(component
);
3590 dev_err(bus
->dev
, "tplg create pipe widget list failed%d\n",
3595 list_for_each_entry(ppl
, &skl
->ppl_list
, node
)
3596 skl_tplg_set_pipe_type(skl
, ppl
->pipe
);
3599 release_firmware(fw
);
3603 void skl_tplg_exit(struct snd_soc_component
*component
, struct hdac_bus
*bus
)
3605 struct skl_dev
*skl
= bus_to_skl(bus
);
3606 struct skl_pipeline
*ppl
, *tmp
;
3608 if (!list_empty(&skl
->ppl_list
))
3609 list_for_each_entry_safe(ppl
, tmp
, &skl
->ppl_list
, node
)
3610 list_del(&ppl
->node
);
3612 /* clean up topology */
3613 snd_soc_tplg_component_remove(component
, SND_SOC_TPLG_INDEX_ALL
);