1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
3 // This file is provided under a dual BSD/GPLv2 license. When using or
4 // redistributing this file, you may do so under either license.
6 // Copyright(c) 2022 Intel Corporation. All rights reserved.
9 #include <linux/bitfield.h>
10 #include <uapi/sound/sof/tokens.h>
11 #include <sound/pcm_params.h>
12 #include <sound/sof/ext_manifest4.h>
13 #include <sound/intel-nhlt.h>
15 #include "sof-audio.h"
16 #include "ipc4-priv.h"
17 #include "ipc4-topology.h"
21 * The ignore_cpc flag can be used to ignore the CPC value for all modules by
23 * The CPC is sent to the firmware along with the SOF_IPC4_MOD_INIT_INSTANCE
24 * message and it is used for clock scaling.
25 * 0 as CPC value will instruct the firmware to use maximum frequency, thus
26 * deactivating the clock scaling.
28 static bool ignore_cpc;
29 module_param_named(ipc4_ignore_cpc, ignore_cpc, bool, 0444);
30 MODULE_PARM_DESC(ipc4_ignore_cpc,
31 "Ignore CPC values. This option will disable clock scaling in firmware.");
33 #define SOF_IPC4_GAIN_PARAM_ID 0
34 #define SOF_IPC4_TPLG_ABI_SIZE 6
35 #define SOF_IPC4_CHAIN_DMA_BUF_SIZE_MS 2
37 static DEFINE_IDA(alh_group_ida);
38 static DEFINE_IDA(pipeline_ida);
40 static const struct sof_topology_token ipc4_sched_tokens[] = {
41 {SOF_TKN_SCHED_LP_MODE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
42 offsetof(struct sof_ipc4_pipeline, lp_mode)},
43 {SOF_TKN_SCHED_USE_CHAIN_DMA, SND_SOC_TPLG_TUPLE_TYPE_BOOL, get_token_u16,
44 offsetof(struct sof_ipc4_pipeline, use_chain_dma)},
45 {SOF_TKN_SCHED_CORE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
46 offsetof(struct sof_ipc4_pipeline, core_id)},
47 {SOF_TKN_SCHED_PRIORITY, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
48 offsetof(struct sof_ipc4_pipeline, priority)},
51 static const struct sof_topology_token pipeline_tokens[] = {
52 {SOF_TKN_SCHED_DYNAMIC_PIPELINE, SND_SOC_TPLG_TUPLE_TYPE_BOOL, get_token_u16,
53 offsetof(struct snd_sof_widget, dynamic_pipeline_widget)},
56 static const struct sof_topology_token ipc4_comp_tokens[] = {
57 {SOF_TKN_COMP_IS_PAGES, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
58 offsetof(struct sof_ipc4_base_module_cfg, is_pages)},
61 static const struct sof_topology_token ipc4_in_audio_format_tokens[] = {
62 {SOF_TKN_CAVS_AUDIO_FORMAT_IN_RATE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
63 offsetof(struct sof_ipc4_pin_format, audio_fmt.sampling_frequency)},
64 {SOF_TKN_CAVS_AUDIO_FORMAT_IN_BIT_DEPTH, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
65 offsetof(struct sof_ipc4_pin_format, audio_fmt.bit_depth)},
66 {SOF_TKN_CAVS_AUDIO_FORMAT_IN_CH_MAP, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
67 offsetof(struct sof_ipc4_pin_format, audio_fmt.ch_map)},
68 {SOF_TKN_CAVS_AUDIO_FORMAT_IN_CH_CFG, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
69 offsetof(struct sof_ipc4_pin_format, audio_fmt.ch_cfg)},
70 {SOF_TKN_CAVS_AUDIO_FORMAT_IN_INTERLEAVING_STYLE, SND_SOC_TPLG_TUPLE_TYPE_WORD,
71 get_token_u32, offsetof(struct sof_ipc4_pin_format,
72 audio_fmt.interleaving_style)},
73 {SOF_TKN_CAVS_AUDIO_FORMAT_IN_FMT_CFG, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
74 offsetof(struct sof_ipc4_pin_format, audio_fmt.fmt_cfg)},
75 {SOF_TKN_CAVS_AUDIO_FORMAT_INPUT_PIN_INDEX, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
76 offsetof(struct sof_ipc4_pin_format, pin_index)},
77 {SOF_TKN_CAVS_AUDIO_FORMAT_IBS, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
78 offsetof(struct sof_ipc4_pin_format, buffer_size)},
81 static const struct sof_topology_token ipc4_out_audio_format_tokens[] = {
82 {SOF_TKN_CAVS_AUDIO_FORMAT_OUT_RATE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
83 offsetof(struct sof_ipc4_pin_format, audio_fmt.sampling_frequency)},
84 {SOF_TKN_CAVS_AUDIO_FORMAT_OUT_BIT_DEPTH, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
85 offsetof(struct sof_ipc4_pin_format, audio_fmt.bit_depth)},
86 {SOF_TKN_CAVS_AUDIO_FORMAT_OUT_CH_MAP, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
87 offsetof(struct sof_ipc4_pin_format, audio_fmt.ch_map)},
88 {SOF_TKN_CAVS_AUDIO_FORMAT_OUT_CH_CFG, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
89 offsetof(struct sof_ipc4_pin_format, audio_fmt.ch_cfg)},
90 {SOF_TKN_CAVS_AUDIO_FORMAT_OUT_INTERLEAVING_STYLE, SND_SOC_TPLG_TUPLE_TYPE_WORD,
91 get_token_u32, offsetof(struct sof_ipc4_pin_format,
92 audio_fmt.interleaving_style)},
93 {SOF_TKN_CAVS_AUDIO_FORMAT_OUT_FMT_CFG, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
94 offsetof(struct sof_ipc4_pin_format, audio_fmt.fmt_cfg)},
95 {SOF_TKN_CAVS_AUDIO_FORMAT_OUTPUT_PIN_INDEX, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
96 offsetof(struct sof_ipc4_pin_format, pin_index)},
97 {SOF_TKN_CAVS_AUDIO_FORMAT_OBS, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
98 offsetof(struct sof_ipc4_pin_format, buffer_size)},
101 static const struct sof_topology_token ipc4_copier_deep_buffer_tokens[] = {
102 {SOF_TKN_INTEL_COPIER_DEEP_BUFFER_DMA_MS, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32, 0},
105 static const struct sof_topology_token ipc4_copier_tokens[] = {
106 {SOF_TKN_INTEL_COPIER_NODE_TYPE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32, 0},
109 static const struct sof_topology_token ipc4_audio_fmt_num_tokens[] = {
110 {SOF_TKN_COMP_NUM_INPUT_AUDIO_FORMATS, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
111 offsetof(struct sof_ipc4_available_audio_format, num_input_formats)},
112 {SOF_TKN_COMP_NUM_OUTPUT_AUDIO_FORMATS, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
113 offsetof(struct sof_ipc4_available_audio_format, num_output_formats)},
116 static const struct sof_topology_token dai_tokens[] = {
117 {SOF_TKN_DAI_TYPE, SND_SOC_TPLG_TUPLE_TYPE_STRING, get_token_dai_type,
118 offsetof(struct sof_ipc4_copier, dai_type)},
119 {SOF_TKN_DAI_INDEX, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
120 offsetof(struct sof_ipc4_copier, dai_index)},
123 /* Component extended tokens */
124 static const struct sof_topology_token comp_ext_tokens[] = {
125 {SOF_TKN_COMP_UUID, SND_SOC_TPLG_TUPLE_TYPE_UUID, get_token_uuid,
126 offsetof(struct snd_sof_widget, uuid)},
127 {SOF_TKN_COMP_CORE_ID, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
128 offsetof(struct snd_sof_widget, core)},
131 static const struct sof_topology_token gain_tokens[] = {
132 {SOF_TKN_GAIN_RAMP_TYPE, SND_SOC_TPLG_TUPLE_TYPE_WORD,
133 get_token_u32, offsetof(struct sof_ipc4_gain_params, curve_type)},
134 {SOF_TKN_GAIN_RAMP_DURATION,
135 SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
136 offsetof(struct sof_ipc4_gain_params, curve_duration_l)},
137 {SOF_TKN_GAIN_VAL, SND_SOC_TPLG_TUPLE_TYPE_WORD,
138 get_token_u32, offsetof(struct sof_ipc4_gain_params, init_val)},
142 static const struct sof_topology_token src_tokens[] = {
143 {SOF_TKN_SRC_RATE_OUT, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
144 offsetof(struct sof_ipc4_src_data, sink_rate)},
147 static const struct sof_token_info ipc4_token_list[SOF_TOKEN_COUNT] = {
148 [SOF_DAI_TOKENS] = {"DAI tokens", dai_tokens, ARRAY_SIZE(dai_tokens)},
149 [SOF_PIPELINE_TOKENS] = {"Pipeline tokens", pipeline_tokens, ARRAY_SIZE(pipeline_tokens)},
150 [SOF_SCHED_TOKENS] = {"Scheduler tokens", ipc4_sched_tokens,
151 ARRAY_SIZE(ipc4_sched_tokens)},
152 [SOF_COMP_EXT_TOKENS] = {"Comp extended tokens", comp_ext_tokens,
153 ARRAY_SIZE(comp_ext_tokens)},
154 [SOF_COMP_TOKENS] = {"IPC4 Component tokens",
155 ipc4_comp_tokens, ARRAY_SIZE(ipc4_comp_tokens)},
156 [SOF_IN_AUDIO_FORMAT_TOKENS] = {"IPC4 Input Audio format tokens",
157 ipc4_in_audio_format_tokens, ARRAY_SIZE(ipc4_in_audio_format_tokens)},
158 [SOF_OUT_AUDIO_FORMAT_TOKENS] = {"IPC4 Output Audio format tokens",
159 ipc4_out_audio_format_tokens, ARRAY_SIZE(ipc4_out_audio_format_tokens)},
160 [SOF_COPIER_DEEP_BUFFER_TOKENS] = {"IPC4 Copier deep buffer tokens",
161 ipc4_copier_deep_buffer_tokens, ARRAY_SIZE(ipc4_copier_deep_buffer_tokens)},
162 [SOF_COPIER_TOKENS] = {"IPC4 Copier tokens", ipc4_copier_tokens,
163 ARRAY_SIZE(ipc4_copier_tokens)},
164 [SOF_AUDIO_FMT_NUM_TOKENS] = {"IPC4 Audio format number tokens",
165 ipc4_audio_fmt_num_tokens, ARRAY_SIZE(ipc4_audio_fmt_num_tokens)},
166 [SOF_GAIN_TOKENS] = {"Gain tokens", gain_tokens, ARRAY_SIZE(gain_tokens)},
167 [SOF_SRC_TOKENS] = {"SRC tokens", src_tokens, ARRAY_SIZE(src_tokens)},
170 struct snd_sof_widget *sof_ipc4_find_swidget_by_ids(struct snd_sof_dev *sdev,
171 u32 module_id, int instance_id)
173 struct snd_sof_widget *swidget;
175 list_for_each_entry(swidget, &sdev->widget_list, list) {
176 struct sof_ipc4_fw_module *fw_module = swidget->module_info;
178 /* Only active module instances have valid instance_id */
179 if (!swidget->use_count)
182 if (fw_module && fw_module->man4_module_entry.id == module_id &&
183 swidget->instance_id == instance_id)
190 static void sof_ipc4_dbg_audio_format(struct device *dev, struct sof_ipc4_pin_format *pin_fmt,
195 for (i = 0; i < num_formats; i++) {
196 struct sof_ipc4_audio_format *fmt = &pin_fmt[i].audio_fmt;
198 "Pin index #%d: %uHz, %ubit (ch_map %#x ch_cfg %u interleaving_style %u fmt_cfg %#x) buffer size %d\n",
199 pin_fmt[i].pin_index, fmt->sampling_frequency, fmt->bit_depth, fmt->ch_map,
200 fmt->ch_cfg, fmt->interleaving_style, fmt->fmt_cfg,
201 pin_fmt[i].buffer_size);
205 static const struct sof_ipc4_audio_format *
206 sof_ipc4_get_input_pin_audio_fmt(struct snd_sof_widget *swidget, int pin_index)
208 struct sof_ipc4_base_module_cfg_ext *base_cfg_ext;
209 struct sof_ipc4_process *process;
212 if (swidget->id != snd_soc_dapm_effect) {
213 struct sof_ipc4_base_module_cfg *base = swidget->private;
215 /* For non-process modules, base module config format is used for all input pins */
216 return &base->audio_fmt;
219 process = swidget->private;
220 base_cfg_ext = process->base_config_ext;
223 * If there are multiple input formats available for a pin, the first available format
226 for (i = 0; i < base_cfg_ext->num_input_pin_fmts; i++) {
227 struct sof_ipc4_pin_format *pin_format = &base_cfg_ext->pin_formats[i];
229 if (pin_format->pin_index == pin_index)
230 return &pin_format->audio_fmt;
237 * sof_ipc4_get_audio_fmt - get available audio formats from swidget->tuples
238 * @scomp: pointer to pointer to SOC component
239 * @swidget: pointer to struct snd_sof_widget containing tuples
240 * @available_fmt: pointer to struct sof_ipc4_available_audio_format being filling in
241 * @module_base_cfg: Pointer to the base_config in the module init IPC payload
243 * Return: 0 if successful
245 static int sof_ipc4_get_audio_fmt(struct snd_soc_component *scomp,
246 struct snd_sof_widget *swidget,
247 struct sof_ipc4_available_audio_format *available_fmt,
248 struct sof_ipc4_base_module_cfg *module_base_cfg)
250 struct sof_ipc4_pin_format *in_format = NULL;
251 struct sof_ipc4_pin_format *out_format;
254 ret = sof_update_ipc_object(scomp, available_fmt,
255 SOF_AUDIO_FMT_NUM_TOKENS, swidget->tuples,
256 swidget->num_tuples, sizeof(*available_fmt), 1);
258 dev_err(scomp->dev, "Failed to parse audio format token count\n");
262 if (!available_fmt->num_input_formats && !available_fmt->num_output_formats) {
263 dev_err(scomp->dev, "No input/output pin formats set in topology\n");
268 "Number of input audio formats: %d. Number of output audio formats: %d\n",
269 available_fmt->num_input_formats, available_fmt->num_output_formats);
271 /* set is_pages in the module's base_config */
272 ret = sof_update_ipc_object(scomp, module_base_cfg, SOF_COMP_TOKENS, swidget->tuples,
273 swidget->num_tuples, sizeof(*module_base_cfg), 1);
275 dev_err(scomp->dev, "parse comp tokens for %s failed, error: %d\n",
276 swidget->widget->name, ret);
280 dev_dbg(scomp->dev, "widget %s: is_pages: %d\n", swidget->widget->name,
281 module_base_cfg->is_pages);
283 if (available_fmt->num_input_formats) {
284 in_format = kcalloc(available_fmt->num_input_formats,
285 sizeof(*in_format), GFP_KERNEL);
288 available_fmt->input_pin_fmts = in_format;
290 ret = sof_update_ipc_object(scomp, in_format,
291 SOF_IN_AUDIO_FORMAT_TOKENS, swidget->tuples,
292 swidget->num_tuples, sizeof(*in_format),
293 available_fmt->num_input_formats);
295 dev_err(scomp->dev, "parse input audio fmt tokens failed %d\n", ret);
299 dev_dbg(scomp->dev, "Input audio formats for %s\n", swidget->widget->name);
300 sof_ipc4_dbg_audio_format(scomp->dev, in_format,
301 available_fmt->num_input_formats);
304 if (available_fmt->num_output_formats) {
305 out_format = kcalloc(available_fmt->num_output_formats, sizeof(*out_format),
312 ret = sof_update_ipc_object(scomp, out_format,
313 SOF_OUT_AUDIO_FORMAT_TOKENS, swidget->tuples,
314 swidget->num_tuples, sizeof(*out_format),
315 available_fmt->num_output_formats);
317 dev_err(scomp->dev, "parse output audio fmt tokens failed\n");
321 available_fmt->output_pin_fmts = out_format;
322 dev_dbg(scomp->dev, "Output audio formats for %s\n", swidget->widget->name);
323 sof_ipc4_dbg_audio_format(scomp->dev, out_format,
324 available_fmt->num_output_formats);
333 available_fmt->input_pin_fmts = NULL;
337 /* release the memory allocated in sof_ipc4_get_audio_fmt */
338 static void sof_ipc4_free_audio_fmt(struct sof_ipc4_available_audio_format *available_fmt)
341 kfree(available_fmt->output_pin_fmts);
342 available_fmt->output_pin_fmts = NULL;
343 kfree(available_fmt->input_pin_fmts);
344 available_fmt->input_pin_fmts = NULL;
347 static void sof_ipc4_widget_free_comp_pipeline(struct snd_sof_widget *swidget)
349 kfree(swidget->private);
352 static int sof_ipc4_widget_set_module_info(struct snd_sof_widget *swidget)
354 struct snd_soc_component *scomp = swidget->scomp;
355 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
357 swidget->module_info = sof_ipc4_find_module_by_uuid(sdev, &swidget->uuid);
359 if (swidget->module_info)
362 dev_err(sdev->dev, "failed to find module info for widget %s with UUID %pUL\n",
363 swidget->widget->name, &swidget->uuid);
367 static int sof_ipc4_widget_setup_msg(struct snd_sof_widget *swidget, struct sof_ipc4_msg *msg)
369 struct sof_ipc4_fw_module *fw_module;
373 ret = sof_ipc4_widget_set_module_info(swidget);
377 fw_module = swidget->module_info;
379 msg->primary = fw_module->man4_module_entry.id;
380 msg->primary |= SOF_IPC4_MSG_TYPE_SET(SOF_IPC4_MOD_INIT_INSTANCE);
381 msg->primary |= SOF_IPC4_MSG_DIR(SOF_IPC4_MSG_REQUEST);
382 msg->primary |= SOF_IPC4_MSG_TARGET(SOF_IPC4_MODULE_MSG);
384 msg->extension = SOF_IPC4_MOD_EXT_CORE_ID(swidget->core);
386 type = (fw_module->man4_module_entry.type & SOF_IPC4_MODULE_DP) ? 1 : 0;
387 msg->extension |= SOF_IPC4_MOD_EXT_DOMAIN(type);
392 static void sof_ipc4_widget_update_kcontrol_module_id(struct snd_sof_widget *swidget)
394 struct snd_soc_component *scomp = swidget->scomp;
395 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
396 struct sof_ipc4_fw_module *fw_module = swidget->module_info;
397 struct snd_sof_control *scontrol;
399 /* update module ID for all kcontrols for this widget */
400 list_for_each_entry(scontrol, &sdev->kcontrol_list, list) {
401 if (scontrol->comp_id == swidget->comp_id) {
402 struct sof_ipc4_control_data *cdata = scontrol->ipc_control_data;
403 struct sof_ipc4_msg *msg = &cdata->msg;
405 msg->primary |= fw_module->man4_module_entry.id;
410 static int sof_ipc4_widget_setup_pcm(struct snd_sof_widget *swidget)
412 struct sof_ipc4_available_audio_format *available_fmt;
413 struct snd_soc_component *scomp = swidget->scomp;
414 struct sof_ipc4_copier *ipc4_copier;
415 struct snd_sof_pcm *spcm;
419 ipc4_copier = kzalloc(sizeof(*ipc4_copier), GFP_KERNEL);
423 swidget->private = ipc4_copier;
424 available_fmt = &ipc4_copier->available_fmt;
426 dev_dbg(scomp->dev, "Updating IPC structure for %s\n", swidget->widget->name);
428 ret = sof_ipc4_get_audio_fmt(scomp, swidget, available_fmt,
429 &ipc4_copier->data.base_config);
434 * This callback is used by host copier and module-to-module copier,
435 * and only host copier needs to set gtw_cfg.
437 if (!WIDGET_IS_AIF(swidget->id))
440 ret = sof_update_ipc_object(scomp, &node_type,
441 SOF_COPIER_TOKENS, swidget->tuples,
442 swidget->num_tuples, sizeof(node_type), 1);
445 dev_err(scomp->dev, "parse host copier node type token failed %d\n",
447 goto free_available_fmt;
449 dev_dbg(scomp->dev, "host copier '%s' node_type %u\n", swidget->widget->name, node_type);
451 spcm = snd_sof_find_spcm_comp(scomp, swidget->comp_id, &dir);
455 if (dir == SNDRV_PCM_STREAM_PLAYBACK) {
456 struct snd_sof_pcm_stream *sps = &spcm->stream[dir];
458 sof_update_ipc_object(scomp, &sps->dsp_max_burst_size_in_ms,
459 SOF_COPIER_DEEP_BUFFER_TOKENS,
461 swidget->num_tuples, sizeof(u32), 1);
462 /* Set default DMA buffer size if it is not specified in topology */
463 if (!sps->dsp_max_burst_size_in_ms)
464 sps->dsp_max_burst_size_in_ms = SOF_IPC4_MIN_DMA_BUFFER_SIZE;
466 /* Capture data is copied from DSP to host in 1ms bursts */
467 spcm->stream[dir].dsp_max_burst_size_in_ms = 1;
471 ipc4_copier->gtw_attr = kzalloc(sizeof(*ipc4_copier->gtw_attr), GFP_KERNEL);
472 if (!ipc4_copier->gtw_attr) {
474 goto free_available_fmt;
477 ipc4_copier->copier_config = (uint32_t *)ipc4_copier->gtw_attr;
478 ipc4_copier->data.gtw_cfg.config_length =
479 sizeof(struct sof_ipc4_gtw_attributes) >> 2;
481 switch (swidget->id) {
482 case snd_soc_dapm_aif_in:
483 case snd_soc_dapm_aif_out:
484 ipc4_copier->data.gtw_cfg.node_id = SOF_IPC4_NODE_TYPE(node_type);
486 case snd_soc_dapm_buffer:
487 ipc4_copier->data.gtw_cfg.node_id = SOF_IPC4_INVALID_NODE_ID;
488 ipc4_copier->ipc_config_size = 0;
491 dev_err(scomp->dev, "invalid widget type %d\n", swidget->id);
496 /* set up module info and message header */
497 ret = sof_ipc4_widget_setup_msg(swidget, &ipc4_copier->msg);
504 kfree(ipc4_copier->gtw_attr);
506 sof_ipc4_free_audio_fmt(available_fmt);
509 swidget->private = NULL;
513 static void sof_ipc4_widget_free_comp_pcm(struct snd_sof_widget *swidget)
515 struct sof_ipc4_copier *ipc4_copier = swidget->private;
516 struct sof_ipc4_available_audio_format *available_fmt;
521 available_fmt = &ipc4_copier->available_fmt;
522 kfree(available_fmt->output_pin_fmts);
523 kfree(ipc4_copier->gtw_attr);
525 swidget->private = NULL;
528 static int sof_ipc4_widget_setup_comp_dai(struct snd_sof_widget *swidget)
530 struct sof_ipc4_available_audio_format *available_fmt;
531 struct snd_soc_component *scomp = swidget->scomp;
532 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
533 struct snd_sof_dai *dai = swidget->private;
534 struct sof_ipc4_copier *ipc4_copier;
535 struct snd_sof_widget *pipe_widget;
536 struct sof_ipc4_pipeline *pipeline;
540 ipc4_copier = kzalloc(sizeof(*ipc4_copier), GFP_KERNEL);
544 available_fmt = &ipc4_copier->available_fmt;
546 dev_dbg(scomp->dev, "Updating IPC structure for %s\n", swidget->widget->name);
548 ret = sof_ipc4_get_audio_fmt(scomp, swidget, available_fmt,
549 &ipc4_copier->data.base_config);
553 ret = sof_update_ipc_object(scomp, &node_type,
554 SOF_COPIER_TOKENS, swidget->tuples,
555 swidget->num_tuples, sizeof(node_type), 1);
557 dev_err(scomp->dev, "parse dai node type failed %d\n", ret);
558 goto free_available_fmt;
561 ret = sof_update_ipc_object(scomp, ipc4_copier,
562 SOF_DAI_TOKENS, swidget->tuples,
563 swidget->num_tuples, sizeof(u32), 1);
565 dev_err(scomp->dev, "parse dai copier node token failed %d\n", ret);
566 goto free_available_fmt;
569 dev_dbg(scomp->dev, "dai %s node_type %u dai_type %u dai_index %d\n", swidget->widget->name,
570 node_type, ipc4_copier->dai_type, ipc4_copier->dai_index);
572 dai->type = ipc4_copier->dai_type;
573 ipc4_copier->data.gtw_cfg.node_id = SOF_IPC4_NODE_TYPE(node_type);
575 pipe_widget = swidget->spipe->pipe_widget;
576 pipeline = pipe_widget->private;
578 if (pipeline->use_chain_dma &&
579 !snd_sof_is_chain_dma_supported(sdev, ipc4_copier->dai_type)) {
580 dev_err(scomp->dev, "Bad DAI type '%d', Chain DMA is not supported\n",
581 ipc4_copier->dai_type);
583 goto free_available_fmt;
586 switch (ipc4_copier->dai_type) {
587 case SOF_DAI_INTEL_ALH:
589 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
590 struct sof_ipc4_alh_configuration_blob *blob;
591 struct snd_soc_dapm_path *p;
592 struct snd_sof_widget *w;
595 snd_soc_dapm_widget_for_each_source_path(swidget->widget, p)
598 if (swidget->id == snd_soc_dapm_dai_in && src_num == 0) {
600 * The blob will not be used if the ALH copier is playback direction
601 * and doesn't connect to any source.
602 * It is fine to call kfree(ipc4_copier->copier_config) since
603 * ipc4_copier->copier_config is null.
609 blob = kzalloc(sizeof(*blob), GFP_KERNEL);
612 goto free_available_fmt;
615 list_for_each_entry(w, &sdev->widget_list, list) {
616 if (w->widget->sname &&
617 strcmp(w->widget->sname, swidget->widget->sname))
620 blob->alh_cfg.device_count++;
623 ipc4_copier->copier_config = (uint32_t *)blob;
624 /* set data.gtw_cfg.config_length based on device_count */
625 ipc4_copier->data.gtw_cfg.config_length = (sizeof(blob->gw_attr) +
626 sizeof(blob->alh_cfg.device_count) +
627 sizeof(*blob->alh_cfg.mapping) *
628 blob->alh_cfg.device_count) >> 2;
631 case SOF_DAI_INTEL_SSP:
632 /* set SSP DAI index as the node_id */
633 ipc4_copier->data.gtw_cfg.node_id |=
634 SOF_IPC4_NODE_INDEX_INTEL_SSP(ipc4_copier->dai_index);
636 case SOF_DAI_INTEL_DMIC:
637 /* set DMIC DAI index as the node_id */
638 ipc4_copier->data.gtw_cfg.node_id |=
639 SOF_IPC4_NODE_INDEX_INTEL_DMIC(ipc4_copier->dai_index);
642 ipc4_copier->gtw_attr = kzalloc(sizeof(*ipc4_copier->gtw_attr), GFP_KERNEL);
643 if (!ipc4_copier->gtw_attr) {
645 goto free_available_fmt;
648 ipc4_copier->copier_config = (uint32_t *)ipc4_copier->gtw_attr;
649 ipc4_copier->data.gtw_cfg.config_length =
650 sizeof(struct sof_ipc4_gtw_attributes) >> 2;
655 dai->private = ipc4_copier;
657 /* set up module info and message header */
658 ret = sof_ipc4_widget_setup_msg(swidget, &ipc4_copier->msg);
660 goto free_copier_config;
665 kfree(ipc4_copier->copier_config);
667 sof_ipc4_free_audio_fmt(available_fmt);
675 static void sof_ipc4_widget_free_comp_dai(struct snd_sof_widget *swidget)
677 struct sof_ipc4_available_audio_format *available_fmt;
678 struct snd_sof_dai *dai = swidget->private;
679 struct sof_ipc4_copier *ipc4_copier;
686 swidget->private = NULL;
690 ipc4_copier = dai->private;
691 available_fmt = &ipc4_copier->available_fmt;
693 kfree(available_fmt->output_pin_fmts);
694 if (ipc4_copier->dai_type != SOF_DAI_INTEL_SSP &&
695 ipc4_copier->dai_type != SOF_DAI_INTEL_DMIC)
696 kfree(ipc4_copier->copier_config);
699 swidget->private = NULL;
702 static int sof_ipc4_widget_setup_comp_pipeline(struct snd_sof_widget *swidget)
704 struct snd_soc_component *scomp = swidget->scomp;
705 struct sof_ipc4_pipeline *pipeline;
706 struct snd_sof_pipeline *spipe = swidget->spipe;
709 pipeline = kzalloc(sizeof(*pipeline), GFP_KERNEL);
713 ret = sof_update_ipc_object(scomp, pipeline, SOF_SCHED_TOKENS, swidget->tuples,
714 swidget->num_tuples, sizeof(*pipeline), 1);
716 dev_err(scomp->dev, "parsing scheduler tokens failed\n");
720 swidget->core = pipeline->core_id;
721 spipe->core_mask |= BIT(pipeline->core_id);
723 if (pipeline->use_chain_dma) {
724 dev_dbg(scomp->dev, "Set up chain DMA for %s\n", swidget->widget->name);
725 swidget->private = pipeline;
729 /* parse one set of pipeline tokens */
730 ret = sof_update_ipc_object(scomp, swidget, SOF_PIPELINE_TOKENS, swidget->tuples,
731 swidget->num_tuples, sizeof(*swidget), 1);
733 dev_err(scomp->dev, "parsing pipeline tokens failed\n");
737 dev_dbg(scomp->dev, "pipeline '%s': id %d, pri %d, core_id %u, lp mode %d\n",
738 swidget->widget->name, swidget->pipeline_id,
739 pipeline->priority, pipeline->core_id, pipeline->lp_mode);
741 swidget->private = pipeline;
743 pipeline->msg.primary = SOF_IPC4_GLB_PIPE_PRIORITY(pipeline->priority);
744 pipeline->msg.primary |= SOF_IPC4_MSG_TYPE_SET(SOF_IPC4_GLB_CREATE_PIPELINE);
745 pipeline->msg.primary |= SOF_IPC4_MSG_DIR(SOF_IPC4_MSG_REQUEST);
746 pipeline->msg.primary |= SOF_IPC4_MSG_TARGET(SOF_IPC4_FW_GEN_MSG);
748 pipeline->msg.extension = pipeline->lp_mode;
749 pipeline->msg.extension |= SOF_IPC4_GLB_PIPE_EXT_CORE_ID(pipeline->core_id);
750 pipeline->state = SOF_IPC4_PIPE_UNINITIALIZED;
758 static int sof_ipc4_widget_setup_comp_pga(struct snd_sof_widget *swidget)
760 struct snd_soc_component *scomp = swidget->scomp;
761 struct sof_ipc4_gain *gain;
764 gain = kzalloc(sizeof(*gain), GFP_KERNEL);
768 swidget->private = gain;
770 gain->data.params.channels = SOF_IPC4_GAIN_ALL_CHANNELS_MASK;
771 gain->data.params.init_val = SOF_IPC4_VOL_ZERO_DB;
773 ret = sof_ipc4_get_audio_fmt(scomp, swidget, &gain->available_fmt, &gain->data.base_config);
777 ret = sof_update_ipc_object(scomp, &gain->data.params, SOF_GAIN_TOKENS,
778 swidget->tuples, swidget->num_tuples, sizeof(gain->data), 1);
780 dev_err(scomp->dev, "Parsing gain tokens failed\n");
785 "pga widget %s: ramp type: %d, ramp duration %d, initial gain value: %#x\n",
786 swidget->widget->name, gain->data.params.curve_type,
787 gain->data.params.curve_duration_l, gain->data.params.init_val);
789 ret = sof_ipc4_widget_setup_msg(swidget, &gain->msg);
793 sof_ipc4_widget_update_kcontrol_module_id(swidget);
797 sof_ipc4_free_audio_fmt(&gain->available_fmt);
799 swidget->private = NULL;
803 static void sof_ipc4_widget_free_comp_pga(struct snd_sof_widget *swidget)
805 struct sof_ipc4_gain *gain = swidget->private;
810 sof_ipc4_free_audio_fmt(&gain->available_fmt);
811 kfree(swidget->private);
812 swidget->private = NULL;
815 static int sof_ipc4_widget_setup_comp_mixer(struct snd_sof_widget *swidget)
817 struct snd_soc_component *scomp = swidget->scomp;
818 struct sof_ipc4_mixer *mixer;
821 dev_dbg(scomp->dev, "Updating IPC structure for %s\n", swidget->widget->name);
823 mixer = kzalloc(sizeof(*mixer), GFP_KERNEL);
827 swidget->private = mixer;
829 ret = sof_ipc4_get_audio_fmt(scomp, swidget, &mixer->available_fmt,
830 &mixer->base_config);
834 ret = sof_ipc4_widget_setup_msg(swidget, &mixer->msg);
840 sof_ipc4_free_audio_fmt(&mixer->available_fmt);
842 swidget->private = NULL;
846 static int sof_ipc4_widget_setup_comp_src(struct snd_sof_widget *swidget)
848 struct snd_soc_component *scomp = swidget->scomp;
849 struct snd_sof_pipeline *spipe = swidget->spipe;
850 struct sof_ipc4_src *src;
853 dev_dbg(scomp->dev, "Updating IPC structure for %s\n", swidget->widget->name);
855 src = kzalloc(sizeof(*src), GFP_KERNEL);
859 swidget->private = src;
861 ret = sof_ipc4_get_audio_fmt(scomp, swidget, &src->available_fmt,
862 &src->data.base_config);
866 ret = sof_update_ipc_object(scomp, &src->data, SOF_SRC_TOKENS, swidget->tuples,
867 swidget->num_tuples, sizeof(*src), 1);
869 dev_err(scomp->dev, "Parsing SRC tokens failed\n");
873 spipe->core_mask |= BIT(swidget->core);
875 dev_dbg(scomp->dev, "SRC sink rate %d\n", src->data.sink_rate);
877 ret = sof_ipc4_widget_setup_msg(swidget, &src->msg);
883 sof_ipc4_free_audio_fmt(&src->available_fmt);
885 swidget->private = NULL;
889 static void sof_ipc4_widget_free_comp_src(struct snd_sof_widget *swidget)
891 struct sof_ipc4_src *src = swidget->private;
896 sof_ipc4_free_audio_fmt(&src->available_fmt);
897 kfree(swidget->private);
898 swidget->private = NULL;
901 static void sof_ipc4_widget_free_comp_mixer(struct snd_sof_widget *swidget)
903 struct sof_ipc4_mixer *mixer = swidget->private;
908 sof_ipc4_free_audio_fmt(&mixer->available_fmt);
909 kfree(swidget->private);
910 swidget->private = NULL;
914 * Add the process modules support. The process modules are defined as snd_soc_dapm_effect modules.
916 static int sof_ipc4_widget_setup_comp_process(struct snd_sof_widget *swidget)
918 struct snd_soc_component *scomp = swidget->scomp;
919 struct sof_ipc4_fw_module *fw_module;
920 struct snd_sof_pipeline *spipe = swidget->spipe;
921 struct sof_ipc4_process *process;
925 process = kzalloc(sizeof(*process), GFP_KERNEL);
929 swidget->private = process;
931 ret = sof_ipc4_get_audio_fmt(scomp, swidget, &process->available_fmt,
932 &process->base_config);
936 ret = sof_ipc4_widget_setup_msg(swidget, &process->msg);
940 /* parse process init module payload config type from module info */
941 fw_module = swidget->module_info;
942 process->init_config = FIELD_GET(SOF_IPC4_MODULE_INIT_CONFIG_MASK,
943 fw_module->man4_module_entry.type);
945 process->ipc_config_size = sizeof(struct sof_ipc4_base_module_cfg);
947 /* allocate memory for base config extension if needed */
948 if (process->init_config == SOF_IPC4_MODULE_INIT_CONFIG_TYPE_BASE_CFG_WITH_EXT) {
949 struct sof_ipc4_base_module_cfg_ext *base_cfg_ext;
950 u32 ext_size = struct_size(base_cfg_ext, pin_formats,
951 size_add(swidget->num_input_pins,
952 swidget->num_output_pins));
954 base_cfg_ext = kzalloc(ext_size, GFP_KERNEL);
957 goto free_available_fmt;
960 base_cfg_ext->num_input_pin_fmts = swidget->num_input_pins;
961 base_cfg_ext->num_output_pin_fmts = swidget->num_output_pins;
962 process->base_config_ext = base_cfg_ext;
963 process->base_config_ext_size = ext_size;
964 process->ipc_config_size += ext_size;
967 cfg = kzalloc(process->ipc_config_size, GFP_KERNEL);
970 goto free_base_cfg_ext;
973 process->ipc_config_data = cfg;
975 sof_ipc4_widget_update_kcontrol_module_id(swidget);
977 /* set pipeline core mask to keep track of the core the module is scheduled to run on */
978 spipe->core_mask |= BIT(swidget->core);
982 kfree(process->base_config_ext);
983 process->base_config_ext = NULL;
985 sof_ipc4_free_audio_fmt(&process->available_fmt);
988 swidget->private = NULL;
992 static void sof_ipc4_widget_free_comp_process(struct snd_sof_widget *swidget)
994 struct sof_ipc4_process *process = swidget->private;
999 kfree(process->ipc_config_data);
1000 kfree(process->base_config_ext);
1001 sof_ipc4_free_audio_fmt(&process->available_fmt);
1002 kfree(swidget->private);
1003 swidget->private = NULL;
1007 sof_ipc4_update_resource_usage(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget,
1008 struct sof_ipc4_base_module_cfg *base_config)
1010 struct sof_ipc4_fw_module *fw_module = swidget->module_info;
1011 struct snd_sof_widget *pipe_widget;
1012 struct sof_ipc4_pipeline *pipeline;
1013 int task_mem, queue_mem;
1014 int ibs, bss, total;
1016 ibs = base_config->ibs;
1017 bss = base_config->is_pages;
1019 task_mem = SOF_IPC4_PIPELINE_OBJECT_SIZE;
1020 task_mem += SOF_IPC4_MODULE_INSTANCE_LIST_ITEM_SIZE + bss;
1022 if (fw_module->man4_module_entry.type & SOF_IPC4_MODULE_LL) {
1023 task_mem += SOF_IPC4_FW_ROUNDUP(SOF_IPC4_LL_TASK_OBJECT_SIZE);
1024 task_mem += SOF_IPC4_FW_MAX_QUEUE_COUNT * SOF_IPC4_MODULE_INSTANCE_LIST_ITEM_SIZE;
1025 task_mem += SOF_IPC4_LL_TASK_LIST_ITEM_SIZE;
1027 task_mem += SOF_IPC4_FW_ROUNDUP(SOF_IPC4_DP_TASK_OBJECT_SIZE);
1028 task_mem += SOF_IPC4_DP_TASK_LIST_SIZE;
1031 ibs = SOF_IPC4_FW_ROUNDUP(ibs);
1032 queue_mem = SOF_IPC4_FW_MAX_QUEUE_COUNT * (SOF_IPC4_DATA_QUEUE_OBJECT_SIZE + ibs);
1034 total = SOF_IPC4_FW_PAGE(task_mem + queue_mem);
1036 pipe_widget = swidget->spipe->pipe_widget;
1037 pipeline = pipe_widget->private;
1038 pipeline->mem_usage += total;
1040 /* Update base_config->cpc from the module manifest */
1041 sof_ipc4_update_cpc_from_manifest(sdev, fw_module, base_config);
1044 dev_dbg(sdev->dev, "%s: ibs / obs: %u / %u, forcing cpc to 0 from %u\n",
1045 swidget->widget->name, base_config->ibs, base_config->obs,
1047 base_config->cpc = 0;
1049 dev_dbg(sdev->dev, "%s: ibs / obs / cpc: %u / %u / %u\n",
1050 swidget->widget->name, base_config->ibs, base_config->obs,
1055 static int sof_ipc4_widget_assign_instance_id(struct snd_sof_dev *sdev,
1056 struct snd_sof_widget *swidget)
1058 struct sof_ipc4_fw_module *fw_module = swidget->module_info;
1059 int max_instances = fw_module->man4_module_entry.instance_max_count;
1061 swidget->instance_id = ida_alloc_max(&fw_module->m_ida, max_instances, GFP_KERNEL);
1062 if (swidget->instance_id < 0) {
1063 dev_err(sdev->dev, "failed to assign instance id for widget %s",
1064 swidget->widget->name);
1065 return swidget->instance_id;
1071 /* update hw_params based on the audio stream format */
1072 static int sof_ipc4_update_hw_params(struct snd_sof_dev *sdev, struct snd_pcm_hw_params *params,
1073 struct sof_ipc4_audio_format *fmt)
1075 snd_pcm_format_t snd_fmt;
1076 struct snd_interval *i;
1078 int valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(fmt->fmt_cfg);
1079 unsigned int channels, rate;
1081 switch (valid_bits) {
1083 snd_fmt = SNDRV_PCM_FORMAT_S16_LE;
1086 snd_fmt = SNDRV_PCM_FORMAT_S24_LE;
1089 snd_fmt = SNDRV_PCM_FORMAT_S32_LE;
1092 dev_err(sdev->dev, "invalid PCM valid_bits %d\n", valid_bits);
1096 m = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
1098 snd_mask_set_format(m, snd_fmt);
1100 rate = fmt->sampling_frequency;
1101 i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
1105 channels = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(fmt->fmt_cfg);
1106 i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
1113 static bool sof_ipc4_is_single_format(struct snd_sof_dev *sdev,
1114 struct sof_ipc4_pin_format *pin_fmts, u32 pin_fmts_size)
1116 struct sof_ipc4_audio_format *fmt;
1117 u32 rate, channels, valid_bits;
1120 fmt = &pin_fmts[0].audio_fmt;
1121 rate = fmt->sampling_frequency;
1122 channels = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(fmt->fmt_cfg);
1123 valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(fmt->fmt_cfg);
1125 /* check if all output formats in topology are the same */
1126 for (i = 1; i < pin_fmts_size; i++) {
1127 u32 _rate, _channels, _valid_bits;
1129 fmt = &pin_fmts[i].audio_fmt;
1130 _rate = fmt->sampling_frequency;
1131 _channels = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(fmt->fmt_cfg);
1132 _valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(fmt->fmt_cfg);
1134 if (_rate != rate || _channels != channels || _valid_bits != valid_bits)
1141 static int sof_ipc4_init_output_audio_fmt(struct snd_sof_dev *sdev,
1142 struct sof_ipc4_base_module_cfg *base_config,
1143 struct sof_ipc4_available_audio_format *available_fmt,
1144 u32 out_ref_rate, u32 out_ref_channels,
1145 u32 out_ref_valid_bits)
1147 struct sof_ipc4_audio_format *out_fmt;
1151 if (!available_fmt->num_output_formats)
1154 single_format = sof_ipc4_is_single_format(sdev, available_fmt->output_pin_fmts,
1155 available_fmt->num_output_formats);
1157 /* pick the first format if there's only one available or if all formats are the same */
1158 if (single_format) {
1159 base_config->obs = available_fmt->output_pin_fmts[0].buffer_size;
1164 * if there are multiple output formats, then choose the output format that matches
1165 * the reference params
1167 for (i = 0; i < available_fmt->num_output_formats; i++) {
1168 u32 _out_rate, _out_channels, _out_valid_bits;
1170 out_fmt = &available_fmt->output_pin_fmts[i].audio_fmt;
1171 _out_rate = out_fmt->sampling_frequency;
1172 _out_channels = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(out_fmt->fmt_cfg);
1173 _out_valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(out_fmt->fmt_cfg);
1175 if (_out_rate == out_ref_rate && _out_channels == out_ref_channels &&
1176 _out_valid_bits == out_ref_valid_bits) {
1177 base_config->obs = available_fmt->output_pin_fmts[i].buffer_size;
1185 static int sof_ipc4_get_valid_bits(struct snd_sof_dev *sdev, struct snd_pcm_hw_params *params)
1187 switch (params_format(params)) {
1188 case SNDRV_PCM_FORMAT_S16_LE:
1190 case SNDRV_PCM_FORMAT_S24_LE:
1192 case SNDRV_PCM_FORMAT_S32_LE:
1195 dev_err(sdev->dev, "invalid pcm frame format %d\n", params_format(params));
1200 static int sof_ipc4_init_input_audio_fmt(struct snd_sof_dev *sdev,
1201 struct snd_sof_widget *swidget,
1202 struct sof_ipc4_base_module_cfg *base_config,
1203 struct snd_pcm_hw_params *params,
1204 struct sof_ipc4_available_audio_format *available_fmt)
1206 struct sof_ipc4_pin_format *pin_fmts = available_fmt->input_pin_fmts;
1207 u32 pin_fmts_size = available_fmt->num_input_formats;
1212 int sample_valid_bits;
1215 if (!available_fmt->num_input_formats) {
1216 dev_err(sdev->dev, "no input formats for %s\n", swidget->widget->name);
1220 single_format = sof_ipc4_is_single_format(sdev, available_fmt->input_pin_fmts,
1221 available_fmt->num_input_formats);
1225 sample_valid_bits = sof_ipc4_get_valid_bits(sdev, params);
1226 if (sample_valid_bits < 0)
1227 return sample_valid_bits;
1230 * Search supported input audio formats with pin index 0 to match rate, channels and
1231 * sample_valid_bits from reference params
1233 for (i = 0; i < pin_fmts_size; i++) {
1234 struct sof_ipc4_audio_format *fmt = &pin_fmts[i].audio_fmt;
1236 if (pin_fmts[i].pin_index)
1239 rate = fmt->sampling_frequency;
1240 channels = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(fmt->fmt_cfg);
1241 valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(fmt->fmt_cfg);
1242 if (params_rate(params) == rate && params_channels(params) == channels &&
1243 sample_valid_bits == valid_bits) {
1244 dev_dbg(sdev->dev, "matched audio format index for %uHz, %ubit, %u channels: %d\n",
1245 rate, valid_bits, channels, i);
1250 if (i == pin_fmts_size) {
1251 dev_err(sdev->dev, "%s: Unsupported audio format: %uHz, %ubit, %u channels\n",
1252 __func__, params_rate(params), sample_valid_bits, params_channels(params));
1257 /* copy input format */
1258 if (available_fmt->num_input_formats && i < available_fmt->num_input_formats) {
1259 memcpy(&base_config->audio_fmt, &available_fmt->input_pin_fmts[i].audio_fmt,
1260 sizeof(struct sof_ipc4_audio_format));
1262 /* set base_cfg ibs/obs */
1263 base_config->ibs = available_fmt->input_pin_fmts[i].buffer_size;
1265 dev_dbg(sdev->dev, "Init input audio formats for %s\n", swidget->widget->name);
1266 sof_ipc4_dbg_audio_format(sdev->dev, &available_fmt->input_pin_fmts[i], 1);
1272 static void sof_ipc4_unprepare_copier_module(struct snd_sof_widget *swidget)
1274 struct sof_ipc4_copier *ipc4_copier = NULL;
1275 struct snd_sof_widget *pipe_widget;
1276 struct sof_ipc4_pipeline *pipeline;
1278 /* reset pipeline memory usage */
1279 pipe_widget = swidget->spipe->pipe_widget;
1280 pipeline = pipe_widget->private;
1281 pipeline->mem_usage = 0;
1283 if (WIDGET_IS_AIF(swidget->id) || swidget->id == snd_soc_dapm_buffer) {
1284 if (pipeline->use_chain_dma) {
1285 pipeline->msg.primary = 0;
1286 pipeline->msg.extension = 0;
1288 ipc4_copier = swidget->private;
1289 } else if (WIDGET_IS_DAI(swidget->id)) {
1290 struct snd_sof_dai *dai = swidget->private;
1292 ipc4_copier = dai->private;
1294 if (pipeline->use_chain_dma) {
1295 pipeline->msg.primary = 0;
1296 pipeline->msg.extension = 0;
1299 if (ipc4_copier->dai_type == SOF_DAI_INTEL_ALH) {
1300 struct sof_ipc4_copier_data *copier_data = &ipc4_copier->data;
1301 struct sof_ipc4_alh_configuration_blob *blob;
1302 unsigned int group_id;
1304 blob = (struct sof_ipc4_alh_configuration_blob *)ipc4_copier->copier_config;
1305 if (blob->alh_cfg.device_count > 1) {
1306 group_id = SOF_IPC4_NODE_INDEX(ipc4_copier->data.gtw_cfg.node_id) -
1308 ida_free(&alh_group_ida, group_id);
1311 /* clear the node ID */
1312 copier_data->gtw_cfg.node_id &= ~SOF_IPC4_NODE_INDEX_MASK;
1317 kfree(ipc4_copier->ipc_config_data);
1318 ipc4_copier->ipc_config_data = NULL;
1319 ipc4_copier->ipc_config_size = 0;
1323 #if IS_ENABLED(CONFIG_ACPI) && IS_ENABLED(CONFIG_SND_INTEL_NHLT)
1324 static int snd_sof_get_hw_config_params(struct snd_sof_dev *sdev, struct snd_sof_dai *dai,
1325 int *sample_rate, int *channel_count, int *bit_depth)
1327 struct snd_soc_tplg_hw_config *hw_config;
1328 struct snd_sof_dai_link *slink;
1329 bool dai_link_found = false;
1330 bool hw_cfg_found = false;
1333 /* get current hw_config from link */
1334 list_for_each_entry(slink, &sdev->dai_link_list, list) {
1335 if (!strcmp(slink->link->name, dai->name)) {
1336 dai_link_found = true;
1341 if (!dai_link_found) {
1342 dev_err(sdev->dev, "%s: no DAI link found for DAI %s\n", __func__, dai->name);
1346 for (i = 0; i < slink->num_hw_configs; i++) {
1347 hw_config = &slink->hw_configs[i];
1348 if (dai->current_config == le32_to_cpu(hw_config->id)) {
1349 hw_cfg_found = true;
1354 if (!hw_cfg_found) {
1355 dev_err(sdev->dev, "%s: no matching hw_config found for DAI %s\n", __func__,
1360 *bit_depth = le32_to_cpu(hw_config->tdm_slot_width);
1361 *channel_count = le32_to_cpu(hw_config->tdm_slots);
1362 *sample_rate = le32_to_cpu(hw_config->fsync_rate);
1364 dev_dbg(sdev->dev, "sample rate: %d sample width: %d channels: %d\n",
1365 *sample_rate, *bit_depth, *channel_count);
1370 static int snd_sof_get_nhlt_endpoint_data(struct snd_sof_dev *sdev, struct snd_sof_dai *dai,
1371 struct snd_pcm_hw_params *params, u32 dai_index,
1372 u32 linktype, u8 dir, u32 **dst, u32 *len)
1374 struct sof_ipc4_fw_data *ipc4_data = sdev->private;
1375 struct nhlt_specific_cfg *cfg;
1376 int sample_rate, channel_count;
1381 /* convert to NHLT type */
1383 case SOF_DAI_INTEL_DMIC:
1384 nhlt_type = NHLT_LINK_DMIC;
1385 bit_depth = params_width(params);
1386 channel_count = params_channels(params);
1387 sample_rate = params_rate(params);
1389 case SOF_DAI_INTEL_SSP:
1390 nhlt_type = NHLT_LINK_SSP;
1391 ret = snd_sof_get_hw_config_params(sdev, dai, &sample_rate, &channel_count,
1397 * We need to know the type of the external device attached to a SSP
1398 * port to retrieve the blob from NHLT. However, device type is not
1399 * specified in topology.
1400 * Query the type for the port and then pass that information back
1401 * to the blob lookup function.
1403 dev_type = intel_nhlt_ssp_device_type(sdev->dev, ipc4_data->nhlt,
1412 dev_dbg(sdev->dev, "dai index %d nhlt type %d direction %d dev type %d\n",
1413 dai_index, nhlt_type, dir, dev_type);
1415 /* find NHLT blob with matching params */
1416 cfg = intel_nhlt_get_endpoint_blob(sdev->dev, ipc4_data->nhlt, dai_index, nhlt_type,
1417 bit_depth, bit_depth, channel_count, sample_rate,
1422 "no matching blob for sample rate: %d sample width: %d channels: %d\n",
1423 sample_rate, bit_depth, channel_count);
1427 /* config length should be in dwords */
1428 *len = cfg->size >> 2;
1429 *dst = (u32 *)cfg->caps;
1434 static int snd_sof_get_nhlt_endpoint_data(struct snd_sof_dev *sdev, struct snd_sof_dai *dai,
1435 struct snd_pcm_hw_params *params, u32 dai_index,
1436 u32 linktype, u8 dir, u32 **dst, u32 *len)
1442 bool sof_ipc4_copier_is_single_format(struct snd_sof_dev *sdev,
1443 struct sof_ipc4_pin_format *pin_fmts,
1446 struct sof_ipc4_audio_format *fmt;
1450 fmt = &pin_fmts[0].audio_fmt;
1451 valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(fmt->fmt_cfg);
1453 /* check if all formats in topology are the same */
1454 for (i = 1; i < pin_fmts_size; i++) {
1457 fmt = &pin_fmts[i].audio_fmt;
1458 _valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(fmt->fmt_cfg);
1460 if (_valid_bits != valid_bits)
1468 sof_ipc4_prepare_copier_module(struct snd_sof_widget *swidget,
1469 struct snd_pcm_hw_params *fe_params,
1470 struct snd_sof_platform_stream_params *platform_params,
1471 struct snd_pcm_hw_params *pipeline_params, int dir)
1473 struct sof_ipc4_available_audio_format *available_fmt;
1474 struct snd_soc_component *scomp = swidget->scomp;
1475 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
1476 struct sof_ipc4_copier_data *copier_data;
1477 struct snd_pcm_hw_params *ref_params;
1478 struct sof_ipc4_copier *ipc4_copier;
1479 struct snd_sof_dai *dai;
1480 u32 gtw_cfg_config_length;
1481 u32 dma_config_tlv_size = 0;
1482 void **ipc_config_data;
1483 int *ipc_config_size;
1485 int ipc_size, ret, out_ref_valid_bits;
1486 u32 out_ref_rate, out_ref_channels;
1487 u32 deep_buffer_dma_ms = 0;
1488 int output_fmt_index;
1489 bool single_output_format;
1491 dev_dbg(sdev->dev, "copier %s, type %d", swidget->widget->name, swidget->id);
1493 switch (swidget->id) {
1494 case snd_soc_dapm_aif_in:
1495 case snd_soc_dapm_aif_out:
1497 struct sof_ipc4_gtw_attributes *gtw_attr;
1498 struct snd_sof_widget *pipe_widget;
1499 struct sof_ipc4_pipeline *pipeline;
1501 /* parse the deep buffer dma size */
1502 ret = sof_update_ipc_object(scomp, &deep_buffer_dma_ms,
1503 SOF_COPIER_DEEP_BUFFER_TOKENS, swidget->tuples,
1504 swidget->num_tuples, sizeof(u32), 1);
1506 dev_err(scomp->dev, "Failed to parse deep buffer dma size for %s\n",
1507 swidget->widget->name);
1511 ipc4_copier = (struct sof_ipc4_copier *)swidget->private;
1512 gtw_attr = ipc4_copier->gtw_attr;
1513 copier_data = &ipc4_copier->data;
1514 available_fmt = &ipc4_copier->available_fmt;
1516 pipe_widget = swidget->spipe->pipe_widget;
1517 pipeline = pipe_widget->private;
1519 if (pipeline->use_chain_dma) {
1523 host_dma_id = platform_params->stream_tag - 1;
1524 pipeline->msg.primary |= SOF_IPC4_GLB_CHAIN_DMA_HOST_ID(host_dma_id);
1526 /* Set SCS bit for S16_LE format only */
1527 if (params_format(fe_params) == SNDRV_PCM_FORMAT_S16_LE)
1528 pipeline->msg.primary |= SOF_IPC4_GLB_CHAIN_DMA_SCS_MASK;
1531 * Despite its name the bitfield 'fifo_size' is used to define DMA buffer
1532 * size. The expression calculates 2ms buffer size.
1534 fifo_size = DIV_ROUND_UP((SOF_IPC4_CHAIN_DMA_BUF_SIZE_MS *
1535 params_rate(fe_params) *
1536 params_channels(fe_params) *
1537 params_physical_width(fe_params)), 8000);
1538 pipeline->msg.extension |= SOF_IPC4_GLB_EXT_CHAIN_DMA_FIFO_SIZE(fifo_size);
1541 * Chain DMA does not support stream timestamping, set node_id to invalid
1542 * to skip the code in sof_ipc4_get_stream_start_offset().
1544 copier_data->gtw_cfg.node_id = SOF_IPC4_INVALID_NODE_ID;
1550 * Use the input_pin_fmts to match pcm params for playback and the output_pin_fmts
1553 if (dir == SNDRV_PCM_STREAM_PLAYBACK)
1554 ref_params = fe_params;
1556 ref_params = pipeline_params;
1558 copier_data->gtw_cfg.node_id &= ~SOF_IPC4_NODE_INDEX_MASK;
1559 copier_data->gtw_cfg.node_id |=
1560 SOF_IPC4_NODE_INDEX(platform_params->stream_tag - 1);
1562 /* set gateway attributes */
1563 gtw_attr->lp_buffer_alloc = pipeline->lp_mode;
1566 case snd_soc_dapm_dai_in:
1567 case snd_soc_dapm_dai_out:
1569 struct snd_sof_widget *pipe_widget = swidget->spipe->pipe_widget;
1570 struct sof_ipc4_pipeline *pipeline = pipe_widget->private;
1572 if (pipeline->use_chain_dma)
1575 dai = swidget->private;
1577 ipc4_copier = (struct sof_ipc4_copier *)dai->private;
1578 copier_data = &ipc4_copier->data;
1579 available_fmt = &ipc4_copier->available_fmt;
1582 * When there is format conversion within a pipeline, the number of supported
1583 * output formats is typically limited to just 1 for the DAI copiers. But when there
1584 * is no format conversion, the DAI copiers input format must match that of the
1585 * FE hw_params for capture and the pipeline params for playback.
1587 if (dir == SNDRV_PCM_STREAM_PLAYBACK)
1588 ref_params = pipeline_params;
1590 ref_params = fe_params;
1592 ret = snd_sof_get_nhlt_endpoint_data(sdev, dai, fe_params, ipc4_copier->dai_index,
1593 ipc4_copier->dai_type, dir,
1594 &ipc4_copier->copier_config,
1595 &copier_data->gtw_cfg.config_length);
1601 case snd_soc_dapm_buffer:
1603 ipc4_copier = (struct sof_ipc4_copier *)swidget->private;
1604 copier_data = &ipc4_copier->data;
1605 available_fmt = &ipc4_copier->available_fmt;
1606 ref_params = pipeline_params;
1611 dev_err(sdev->dev, "unsupported type %d for copier %s",
1612 swidget->id, swidget->widget->name);
1616 /* set input and output audio formats */
1617 ret = sof_ipc4_init_input_audio_fmt(sdev, swidget, &copier_data->base_config, ref_params,
1622 /* set the reference params for output format selection */
1623 single_output_format = sof_ipc4_copier_is_single_format(sdev,
1624 available_fmt->output_pin_fmts,
1625 available_fmt->num_output_formats);
1626 switch (swidget->id) {
1627 case snd_soc_dapm_aif_in:
1628 case snd_soc_dapm_dai_out:
1629 case snd_soc_dapm_buffer:
1631 struct sof_ipc4_audio_format *in_fmt;
1633 in_fmt = &available_fmt->input_pin_fmts[ret].audio_fmt;
1634 out_ref_rate = in_fmt->sampling_frequency;
1635 out_ref_channels = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(in_fmt->fmt_cfg);
1637 if (!single_output_format)
1638 out_ref_valid_bits =
1639 SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(in_fmt->fmt_cfg);
1642 case snd_soc_dapm_aif_out:
1643 case snd_soc_dapm_dai_in:
1644 out_ref_rate = params_rate(fe_params);
1645 out_ref_channels = params_channels(fe_params);
1646 if (!single_output_format) {
1647 out_ref_valid_bits = sof_ipc4_get_valid_bits(sdev, fe_params);
1648 if (out_ref_valid_bits < 0)
1649 return out_ref_valid_bits;
1654 * Unsupported type should be caught by the former switch default
1655 * case, this should never happen in reality.
1661 * if the output format is the same across all available output formats, choose
1662 * that as the reference.
1664 if (single_output_format) {
1665 struct sof_ipc4_audio_format *out_fmt;
1667 out_fmt = &available_fmt->output_pin_fmts[0].audio_fmt;
1668 out_ref_valid_bits =
1669 SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(out_fmt->fmt_cfg);
1672 dev_dbg(sdev->dev, "copier %s: reference output rate %d, channels %d valid_bits %d\n",
1673 swidget->widget->name, out_ref_rate, out_ref_channels, out_ref_valid_bits);
1675 output_fmt_index = sof_ipc4_init_output_audio_fmt(sdev, &copier_data->base_config,
1676 available_fmt, out_ref_rate,
1677 out_ref_channels, out_ref_valid_bits);
1678 if (output_fmt_index < 0) {
1679 dev_err(sdev->dev, "Failed to initialize output format for %s",
1680 swidget->widget->name);
1681 return output_fmt_index;
1685 * Set the output format. Current topology defines pin 0 input and output formats in pairs.
1686 * This assumes that the pin 0 formats are defined before all other pins.
1687 * So pick the output audio format with the same index as the chosen
1688 * input format. This logic will need to be updated when the format definitions
1689 * in topology change.
1691 memcpy(&copier_data->out_format,
1692 &available_fmt->output_pin_fmts[output_fmt_index].audio_fmt,
1693 sizeof(struct sof_ipc4_audio_format));
1694 dev_dbg(sdev->dev, "Output audio format for %s\n", swidget->widget->name);
1695 sof_ipc4_dbg_audio_format(sdev->dev, &available_fmt->output_pin_fmts[output_fmt_index], 1);
1697 switch (swidget->id) {
1698 case snd_soc_dapm_dai_in:
1699 case snd_soc_dapm_dai_out:
1702 * Only SOF_DAI_INTEL_ALH needs copier_data to set blob.
1703 * That's why only ALH dai's blob is set after sof_ipc4_init_input_audio_fmt
1705 if (ipc4_copier->dai_type == SOF_DAI_INTEL_ALH) {
1706 struct sof_ipc4_alh_configuration_blob *blob;
1707 struct sof_ipc4_copier_data *alh_data;
1708 struct sof_ipc4_copier *alh_copier;
1709 struct snd_sof_widget *w;
1717 blob = (struct sof_ipc4_alh_configuration_blob *)ipc4_copier->copier_config;
1719 blob->gw_attr.lp_buffer_alloc = 0;
1721 /* Get channel_mask from ch_map */
1722 ch_map = copier_data->base_config.audio_fmt.ch_map;
1723 for (i = 0; ch_map; i++) {
1724 if ((ch_map & 0xf) != 0xf) {
1731 step = ch_count / blob->alh_cfg.device_count;
1732 mask = GENMASK(step - 1, 0);
1734 * Set each gtw_cfg.node_id to blob->alh_cfg.mapping[]
1735 * for all widgets with the same stream name
1738 list_for_each_entry(w, &sdev->widget_list, list) {
1739 if (w->widget->sname &&
1740 strcmp(w->widget->sname, swidget->widget->sname))
1744 alh_copier = (struct sof_ipc4_copier *)dai->private;
1745 alh_data = &alh_copier->data;
1746 blob->alh_cfg.mapping[i].device = alh_data->gtw_cfg.node_id;
1748 * Set the same channel mask for playback as the audio data is
1749 * duplicated for all speakers. For capture, split the channels
1750 * among the aggregated DAIs. For example, with 4 channels on 2
1751 * aggregated DAIs, the channel_mask should be 0x3 and 0xc for the
1753 * The channel masks used depend on the cpu_dais used in the
1754 * dailink at the machine driver level, which actually comes from
1755 * the tables in soc_acpi files depending on the _ADR and devID
1756 * registers for each codec.
1758 if (w->id == snd_soc_dapm_dai_in)
1759 blob->alh_cfg.mapping[i].channel_mask = ch_mask;
1761 blob->alh_cfg.mapping[i].channel_mask = mask << (step * i);
1765 if (blob->alh_cfg.device_count > 1) {
1768 group_id = ida_alloc_max(&alh_group_ida, ALH_MULTI_GTW_COUNT - 1,
1774 /* add multi-gateway base */
1775 group_id += ALH_MULTI_GTW_BASE;
1776 copier_data->gtw_cfg.node_id &= ~SOF_IPC4_NODE_INDEX_MASK;
1777 copier_data->gtw_cfg.node_id |= SOF_IPC4_NODE_INDEX(group_id);
1783 /* modify the input params for the next widget */
1784 ret = sof_ipc4_update_hw_params(sdev, pipeline_params, &copier_data->out_format);
1789 * Set the gateway dma_buffer_size to 2ms buffer size to meet the FW expectation. In the
1790 * deep buffer case, set the dma_buffer_size depending on the deep_buffer_dma_ms set
1793 switch (swidget->id) {
1794 case snd_soc_dapm_dai_in:
1795 copier_data->gtw_cfg.dma_buffer_size =
1796 SOF_IPC4_MIN_DMA_BUFFER_SIZE * copier_data->base_config.ibs;
1798 case snd_soc_dapm_aif_in:
1799 copier_data->gtw_cfg.dma_buffer_size =
1800 max((u32)SOF_IPC4_MIN_DMA_BUFFER_SIZE, deep_buffer_dma_ms) *
1801 copier_data->base_config.ibs;
1802 dev_dbg(sdev->dev, "copier %s, dma buffer%s: %u ms (%u bytes)",
1803 swidget->widget->name,
1804 deep_buffer_dma_ms ? " (using Deep Buffer)" : "",
1805 max((u32)SOF_IPC4_MIN_DMA_BUFFER_SIZE, deep_buffer_dma_ms),
1806 copier_data->gtw_cfg.dma_buffer_size);
1808 case snd_soc_dapm_dai_out:
1809 case snd_soc_dapm_aif_out:
1810 copier_data->gtw_cfg.dma_buffer_size =
1811 SOF_IPC4_MIN_DMA_BUFFER_SIZE * copier_data->base_config.obs;
1817 data = &ipc4_copier->copier_config;
1818 ipc_config_size = &ipc4_copier->ipc_config_size;
1819 ipc_config_data = &ipc4_copier->ipc_config_data;
1821 /* config_length is DWORD based */
1822 gtw_cfg_config_length = copier_data->gtw_cfg.config_length * 4;
1823 ipc_size = sizeof(*copier_data) + gtw_cfg_config_length;
1825 if (ipc4_copier->dma_config_tlv.type == SOF_IPC4_GTW_DMA_CONFIG_ID &&
1826 ipc4_copier->dma_config_tlv.length) {
1827 dma_config_tlv_size = sizeof(ipc4_copier->dma_config_tlv) +
1828 ipc4_copier->dma_config_tlv.dma_config.dma_priv_config_size;
1830 /* paranoia check on TLV size/length */
1831 if (dma_config_tlv_size != ipc4_copier->dma_config_tlv.length +
1832 sizeof(uint32_t) * 2) {
1833 dev_err(sdev->dev, "Invalid configuration, TLV size %d length %d\n",
1834 dma_config_tlv_size, ipc4_copier->dma_config_tlv.length);
1838 ipc_size += dma_config_tlv_size;
1840 /* we also need to increase the size at the gtw level */
1841 copier_data->gtw_cfg.config_length += dma_config_tlv_size / 4;
1844 dev_dbg(sdev->dev, "copier %s, IPC size is %d", swidget->widget->name, ipc_size);
1846 *ipc_config_data = kzalloc(ipc_size, GFP_KERNEL);
1847 if (!*ipc_config_data)
1850 *ipc_config_size = ipc_size;
1852 /* update pipeline memory usage */
1853 sof_ipc4_update_resource_usage(sdev, swidget, &copier_data->base_config);
1856 memcpy(*ipc_config_data, (void *)copier_data, sizeof(*copier_data));
1857 if (gtw_cfg_config_length)
1858 memcpy(*ipc_config_data + sizeof(*copier_data),
1859 *data, gtw_cfg_config_length);
1861 /* add DMA Config TLV, if configured */
1862 if (dma_config_tlv_size)
1863 memcpy(*ipc_config_data + sizeof(*copier_data) +
1864 gtw_cfg_config_length,
1865 &ipc4_copier->dma_config_tlv, dma_config_tlv_size);
1868 * Restore gateway config length now that IPC payload is prepared. This avoids
1869 * counting the DMA CONFIG TLV multiple times
1871 copier_data->gtw_cfg.config_length = gtw_cfg_config_length / 4;
1876 static int sof_ipc4_prepare_gain_module(struct snd_sof_widget *swidget,
1877 struct snd_pcm_hw_params *fe_params,
1878 struct snd_sof_platform_stream_params *platform_params,
1879 struct snd_pcm_hw_params *pipeline_params, int dir)
1881 struct snd_soc_component *scomp = swidget->scomp;
1882 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
1883 struct sof_ipc4_gain *gain = swidget->private;
1884 struct sof_ipc4_available_audio_format *available_fmt = &gain->available_fmt;
1885 struct sof_ipc4_audio_format *in_fmt;
1886 u32 out_ref_rate, out_ref_channels, out_ref_valid_bits;
1889 ret = sof_ipc4_init_input_audio_fmt(sdev, swidget, &gain->data.base_config,
1890 pipeline_params, available_fmt);
1894 in_fmt = &available_fmt->input_pin_fmts[ret].audio_fmt;
1895 out_ref_rate = in_fmt->sampling_frequency;
1896 out_ref_channels = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(in_fmt->fmt_cfg);
1897 out_ref_valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(in_fmt->fmt_cfg);
1899 ret = sof_ipc4_init_output_audio_fmt(sdev, &gain->data.base_config, available_fmt,
1900 out_ref_rate, out_ref_channels, out_ref_valid_bits);
1902 dev_err(sdev->dev, "Failed to initialize output format for %s",
1903 swidget->widget->name);
1907 /* update pipeline memory usage */
1908 sof_ipc4_update_resource_usage(sdev, swidget, &gain->data.base_config);
1913 static int sof_ipc4_prepare_mixer_module(struct snd_sof_widget *swidget,
1914 struct snd_pcm_hw_params *fe_params,
1915 struct snd_sof_platform_stream_params *platform_params,
1916 struct snd_pcm_hw_params *pipeline_params, int dir)
1918 struct snd_soc_component *scomp = swidget->scomp;
1919 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
1920 struct sof_ipc4_mixer *mixer = swidget->private;
1921 struct sof_ipc4_available_audio_format *available_fmt = &mixer->available_fmt;
1922 struct sof_ipc4_audio_format *in_fmt;
1923 u32 out_ref_rate, out_ref_channels, out_ref_valid_bits;
1926 ret = sof_ipc4_init_input_audio_fmt(sdev, swidget, &mixer->base_config,
1927 pipeline_params, available_fmt);
1931 in_fmt = &available_fmt->input_pin_fmts[ret].audio_fmt;
1932 out_ref_rate = in_fmt->sampling_frequency;
1933 out_ref_channels = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(in_fmt->fmt_cfg);
1934 out_ref_valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(in_fmt->fmt_cfg);
1936 ret = sof_ipc4_init_output_audio_fmt(sdev, &mixer->base_config, available_fmt,
1937 out_ref_rate, out_ref_channels, out_ref_valid_bits);
1939 dev_err(sdev->dev, "Failed to initialize output format for %s",
1940 swidget->widget->name);
1944 /* update pipeline memory usage */
1945 sof_ipc4_update_resource_usage(sdev, swidget, &mixer->base_config);
1950 static int sof_ipc4_prepare_src_module(struct snd_sof_widget *swidget,
1951 struct snd_pcm_hw_params *fe_params,
1952 struct snd_sof_platform_stream_params *platform_params,
1953 struct snd_pcm_hw_params *pipeline_params, int dir)
1955 struct snd_soc_component *scomp = swidget->scomp;
1956 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
1957 struct sof_ipc4_src *src = swidget->private;
1958 struct sof_ipc4_available_audio_format *available_fmt = &src->available_fmt;
1959 struct sof_ipc4_audio_format *out_audio_fmt;
1960 struct sof_ipc4_audio_format *in_audio_fmt;
1961 u32 out_ref_rate, out_ref_channels, out_ref_valid_bits;
1962 int output_format_index, input_format_index;
1964 input_format_index = sof_ipc4_init_input_audio_fmt(sdev, swidget, &src->data.base_config,
1965 pipeline_params, available_fmt);
1966 if (input_format_index < 0)
1967 return input_format_index;
1970 * For playback, the SRC sink rate will be configured based on the requested output
1971 * format, which is restricted to only deal with DAI's with a single format for now.
1973 if (dir == SNDRV_PCM_STREAM_PLAYBACK && available_fmt->num_output_formats > 1) {
1974 dev_err(sdev->dev, "Invalid number of output formats: %d for SRC %s\n",
1975 available_fmt->num_output_formats, swidget->widget->name);
1980 * SRC does not perform format conversion, so the output channels and valid bit depth must
1981 * be the same as that of the input.
1983 in_audio_fmt = &available_fmt->input_pin_fmts[input_format_index].audio_fmt;
1984 out_ref_channels = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(in_audio_fmt->fmt_cfg);
1985 out_ref_valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(in_audio_fmt->fmt_cfg);
1988 * For capture, the SRC module should convert the rate to match the rate requested by the
1989 * PCM hw_params. Set the reference params based on the fe_params unconditionally as it
1990 * will be ignored for playback anyway.
1992 out_ref_rate = params_rate(fe_params);
1994 output_format_index = sof_ipc4_init_output_audio_fmt(sdev, &src->data.base_config,
1995 available_fmt, out_ref_rate,
1996 out_ref_channels, out_ref_valid_bits);
1997 if (output_format_index < 0) {
1998 dev_err(sdev->dev, "Failed to initialize output format for %s",
1999 swidget->widget->name);
2000 return output_format_index;
2003 /* update pipeline memory usage */
2004 sof_ipc4_update_resource_usage(sdev, swidget, &src->data.base_config);
2006 out_audio_fmt = &available_fmt->output_pin_fmts[output_format_index].audio_fmt;
2007 src->data.sink_rate = out_audio_fmt->sampling_frequency;
2009 /* update pipeline_params for sink widgets */
2010 return sof_ipc4_update_hw_params(sdev, pipeline_params, out_audio_fmt);
2014 sof_ipc4_process_set_pin_formats(struct snd_sof_widget *swidget, int pin_type)
2016 struct sof_ipc4_process *process = swidget->private;
2017 struct sof_ipc4_base_module_cfg_ext *base_cfg_ext = process->base_config_ext;
2018 struct sof_ipc4_available_audio_format *available_fmt = &process->available_fmt;
2019 struct sof_ipc4_pin_format *pin_format, *format_list_to_search;
2020 struct snd_soc_component *scomp = swidget->scomp;
2021 int num_pins, format_list_count;
2022 int pin_format_offset = 0;
2025 /* set number of pins, offset of pin format and format list to search based on pin type */
2026 if (pin_type == SOF_PIN_TYPE_INPUT) {
2027 num_pins = swidget->num_input_pins;
2028 format_list_to_search = available_fmt->input_pin_fmts;
2029 format_list_count = available_fmt->num_input_formats;
2031 num_pins = swidget->num_output_pins;
2032 pin_format_offset = swidget->num_input_pins;
2033 format_list_to_search = available_fmt->output_pin_fmts;
2034 format_list_count = available_fmt->num_output_formats;
2037 for (i = pin_format_offset; i < num_pins + pin_format_offset; i++) {
2038 pin_format = &base_cfg_ext->pin_formats[i];
2040 /* Pin 0 audio formats are derived from the base config input/output format */
2041 if (i == pin_format_offset) {
2042 if (pin_type == SOF_PIN_TYPE_INPUT) {
2043 pin_format->buffer_size = process->base_config.ibs;
2044 pin_format->audio_fmt = process->base_config.audio_fmt;
2046 pin_format->buffer_size = process->base_config.obs;
2047 pin_format->audio_fmt = process->output_format;
2053 * For all other pins, find the pin formats from those set in topology. If there
2054 * is more than one format specified for a pin, this will pick the first available
2057 for (j = 0; j < format_list_count; j++) {
2058 struct sof_ipc4_pin_format *pin_format_item = &format_list_to_search[j];
2060 if (pin_format_item->pin_index == i - pin_format_offset) {
2061 *pin_format = *pin_format_item;
2066 if (j == format_list_count) {
2067 dev_err(scomp->dev, "%s pin %d format not found for %s\n",
2068 (pin_type == SOF_PIN_TYPE_INPUT) ? "input" : "output",
2069 i - pin_format_offset, swidget->widget->name);
2077 static int sof_ipc4_process_add_base_cfg_extn(struct snd_sof_widget *swidget)
2081 /* copy input and output pin formats */
2082 for (i = 0; i <= SOF_PIN_TYPE_OUTPUT; i++) {
2083 ret = sof_ipc4_process_set_pin_formats(swidget, i);
2091 static int sof_ipc4_prepare_process_module(struct snd_sof_widget *swidget,
2092 struct snd_pcm_hw_params *fe_params,
2093 struct snd_sof_platform_stream_params *platform_params,
2094 struct snd_pcm_hw_params *pipeline_params, int dir)
2096 struct snd_soc_component *scomp = swidget->scomp;
2097 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
2098 struct sof_ipc4_process *process = swidget->private;
2099 struct sof_ipc4_available_audio_format *available_fmt = &process->available_fmt;
2100 struct sof_ipc4_audio_format *in_fmt;
2101 u32 out_ref_rate, out_ref_channels, out_ref_valid_bits;
2102 void *cfg = process->ipc_config_data;
2103 int output_fmt_index;
2106 ret = sof_ipc4_init_input_audio_fmt(sdev, swidget, &process->base_config,
2107 pipeline_params, available_fmt);
2111 in_fmt = &available_fmt->input_pin_fmts[ret].audio_fmt;
2112 out_ref_rate = in_fmt->sampling_frequency;
2113 out_ref_channels = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(in_fmt->fmt_cfg);
2114 out_ref_valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(in_fmt->fmt_cfg);
2116 output_fmt_index = sof_ipc4_init_output_audio_fmt(sdev, &process->base_config,
2117 available_fmt, out_ref_rate,
2118 out_ref_channels, out_ref_valid_bits);
2119 if (output_fmt_index < 0 && available_fmt->num_output_formats) {
2120 dev_err(sdev->dev, "Failed to initialize output format for %s",
2121 swidget->widget->name);
2122 return output_fmt_index;
2125 /* copy Pin 0 output format */
2126 if (available_fmt->num_output_formats &&
2127 output_fmt_index < available_fmt->num_output_formats &&
2128 !available_fmt->output_pin_fmts[output_fmt_index].pin_index) {
2129 memcpy(&process->output_format,
2130 &available_fmt->output_pin_fmts[output_fmt_index].audio_fmt,
2131 sizeof(struct sof_ipc4_audio_format));
2133 /* modify the pipeline params with the pin 0 output format */
2134 ret = sof_ipc4_update_hw_params(sdev, pipeline_params, &process->output_format);
2139 /* update pipeline memory usage */
2140 sof_ipc4_update_resource_usage(sdev, swidget, &process->base_config);
2142 /* ipc_config_data is composed of the base_config followed by an optional extension */
2143 memcpy(cfg, &process->base_config, sizeof(struct sof_ipc4_base_module_cfg));
2144 cfg += sizeof(struct sof_ipc4_base_module_cfg);
2146 if (process->init_config == SOF_IPC4_MODULE_INIT_CONFIG_TYPE_BASE_CFG_WITH_EXT) {
2147 struct sof_ipc4_base_module_cfg_ext *base_cfg_ext = process->base_config_ext;
2149 ret = sof_ipc4_process_add_base_cfg_extn(swidget);
2153 memcpy(cfg, base_cfg_ext, process->base_config_ext_size);
2159 static int sof_ipc4_control_load_volume(struct snd_sof_dev *sdev, struct snd_sof_control *scontrol)
2161 struct sof_ipc4_control_data *control_data;
2162 struct sof_ipc4_msg *msg;
2165 scontrol->size = struct_size(control_data, chanv, scontrol->num_channels);
2167 /* scontrol->ipc_control_data will be freed in sof_control_unload */
2168 scontrol->ipc_control_data = kzalloc(scontrol->size, GFP_KERNEL);
2169 if (!scontrol->ipc_control_data)
2172 control_data = scontrol->ipc_control_data;
2173 control_data->index = scontrol->index;
2175 msg = &control_data->msg;
2176 msg->primary = SOF_IPC4_MSG_TYPE_SET(SOF_IPC4_MOD_LARGE_CONFIG_SET);
2177 msg->primary |= SOF_IPC4_MSG_DIR(SOF_IPC4_MSG_REQUEST);
2178 msg->primary |= SOF_IPC4_MSG_TARGET(SOF_IPC4_MODULE_MSG);
2180 /* volume controls with range 0-1 (off/on) are switch controls */
2181 if (scontrol->max == 1)
2182 msg->extension = SOF_IPC4_MOD_EXT_MSG_PARAM_ID(SOF_IPC4_SWITCH_CONTROL_PARAM_ID);
2184 msg->extension = SOF_IPC4_MOD_EXT_MSG_PARAM_ID(SOF_IPC4_GAIN_PARAM_ID);
2186 for (i = 0; i < scontrol->num_channels; i++) {
2187 control_data->chanv[i].channel = i;
2189 * Default, initial values:
2190 * - 0dB for volume controls
2191 * - off (0) for switch controls - value already zero after
2194 if (scontrol->max > 1)
2195 control_data->chanv[i].value = SOF_IPC4_VOL_ZERO_DB;
2201 static int sof_ipc4_control_load_enum(struct snd_sof_dev *sdev, struct snd_sof_control *scontrol)
2203 struct sof_ipc4_control_data *control_data;
2204 struct sof_ipc4_msg *msg;
2207 scontrol->size = struct_size(control_data, chanv, scontrol->num_channels);
2209 /* scontrol->ipc_control_data will be freed in sof_control_unload */
2210 scontrol->ipc_control_data = kzalloc(scontrol->size, GFP_KERNEL);
2211 if (!scontrol->ipc_control_data)
2214 control_data = scontrol->ipc_control_data;
2215 control_data->index = scontrol->index;
2217 msg = &control_data->msg;
2218 msg->primary = SOF_IPC4_MSG_TYPE_SET(SOF_IPC4_MOD_LARGE_CONFIG_SET);
2219 msg->primary |= SOF_IPC4_MSG_DIR(SOF_IPC4_MSG_REQUEST);
2220 msg->primary |= SOF_IPC4_MSG_TARGET(SOF_IPC4_MODULE_MSG);
2222 msg->extension = SOF_IPC4_MOD_EXT_MSG_PARAM_ID(SOF_IPC4_ENUM_CONTROL_PARAM_ID);
2224 /* Default, initial value for enums: first enum entry is selected (0) */
2225 for (i = 0; i < scontrol->num_channels; i++)
2226 control_data->chanv[i].channel = i;
2231 static int sof_ipc4_control_load_bytes(struct snd_sof_dev *sdev, struct snd_sof_control *scontrol)
2233 struct sof_ipc4_control_data *control_data;
2234 struct sof_ipc4_msg *msg;
2237 if (scontrol->max_size < (sizeof(*control_data) + sizeof(struct sof_abi_hdr))) {
2238 dev_err(sdev->dev, "insufficient size for a bytes control %s: %zu.\n",
2239 scontrol->name, scontrol->max_size);
2243 if (scontrol->priv_size > scontrol->max_size - sizeof(*control_data)) {
2244 dev_err(sdev->dev, "scontrol %s bytes data size %zu exceeds max %zu.\n",
2245 scontrol->name, scontrol->priv_size,
2246 scontrol->max_size - sizeof(*control_data));
2250 scontrol->size = sizeof(struct sof_ipc4_control_data) + scontrol->priv_size;
2252 scontrol->ipc_control_data = kzalloc(scontrol->max_size, GFP_KERNEL);
2253 if (!scontrol->ipc_control_data)
2256 control_data = scontrol->ipc_control_data;
2257 control_data->index = scontrol->index;
2258 if (scontrol->priv_size > 0) {
2259 memcpy(control_data->data, scontrol->priv, scontrol->priv_size);
2260 kfree(scontrol->priv);
2261 scontrol->priv = NULL;
2263 if (control_data->data->magic != SOF_IPC4_ABI_MAGIC) {
2264 dev_err(sdev->dev, "Wrong ABI magic (%#x) for control: %s\n",
2265 control_data->data->magic, scontrol->name);
2270 /* TODO: check the ABI version */
2272 if (control_data->data->size + sizeof(struct sof_abi_hdr) !=
2273 scontrol->priv_size) {
2274 dev_err(sdev->dev, "Control %s conflict in bytes %zu vs. priv size %zu.\n",
2276 control_data->data->size + sizeof(struct sof_abi_hdr),
2277 scontrol->priv_size);
2283 msg = &control_data->msg;
2284 msg->primary = SOF_IPC4_MSG_TYPE_SET(SOF_IPC4_MOD_LARGE_CONFIG_SET);
2285 msg->primary |= SOF_IPC4_MSG_DIR(SOF_IPC4_MSG_REQUEST);
2286 msg->primary |= SOF_IPC4_MSG_TARGET(SOF_IPC4_MODULE_MSG);
2291 kfree(scontrol->ipc_control_data);
2292 scontrol->ipc_control_data = NULL;
2296 static int sof_ipc4_control_setup(struct snd_sof_dev *sdev, struct snd_sof_control *scontrol)
2298 switch (scontrol->info_type) {
2299 case SND_SOC_TPLG_CTL_VOLSW:
2300 case SND_SOC_TPLG_CTL_VOLSW_SX:
2301 case SND_SOC_TPLG_CTL_VOLSW_XR_SX:
2302 return sof_ipc4_control_load_volume(sdev, scontrol);
2303 case SND_SOC_TPLG_CTL_BYTES:
2304 return sof_ipc4_control_load_bytes(sdev, scontrol);
2305 case SND_SOC_TPLG_CTL_ENUM:
2306 case SND_SOC_TPLG_CTL_ENUM_VALUE:
2307 return sof_ipc4_control_load_enum(sdev, scontrol);
2315 static int sof_ipc4_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
2317 struct snd_sof_widget *pipe_widget = swidget->spipe->pipe_widget;
2318 struct sof_ipc4_fw_data *ipc4_data = sdev->private;
2319 struct sof_ipc4_pipeline *pipeline;
2320 struct sof_ipc4_msg *msg;
2321 void *ipc_data = NULL;
2325 switch (swidget->id) {
2326 case snd_soc_dapm_scheduler:
2327 pipeline = swidget->private;
2329 if (pipeline->use_chain_dma) {
2330 dev_warn(sdev->dev, "use_chain_dma set for scheduler %s",
2331 swidget->widget->name);
2335 dev_dbg(sdev->dev, "pipeline: %d memory pages: %d\n", swidget->pipeline_id,
2336 pipeline->mem_usage);
2338 msg = &pipeline->msg;
2339 msg->primary |= pipeline->mem_usage;
2341 swidget->instance_id = ida_alloc_max(&pipeline_ida, ipc4_data->max_num_pipelines,
2343 if (swidget->instance_id < 0) {
2344 dev_err(sdev->dev, "failed to assign pipeline id for %s: %d\n",
2345 swidget->widget->name, swidget->instance_id);
2346 return swidget->instance_id;
2348 msg->primary &= ~SOF_IPC4_GLB_PIPE_INSTANCE_MASK;
2349 msg->primary |= SOF_IPC4_GLB_PIPE_INSTANCE_ID(swidget->instance_id);
2351 case snd_soc_dapm_aif_in:
2352 case snd_soc_dapm_aif_out:
2353 case snd_soc_dapm_buffer:
2355 struct sof_ipc4_copier *ipc4_copier = swidget->private;
2357 pipeline = pipe_widget->private;
2358 if (pipeline->use_chain_dma)
2361 ipc_size = ipc4_copier->ipc_config_size;
2362 ipc_data = ipc4_copier->ipc_config_data;
2364 msg = &ipc4_copier->msg;
2367 case snd_soc_dapm_dai_in:
2368 case snd_soc_dapm_dai_out:
2370 struct snd_sof_dai *dai = swidget->private;
2371 struct sof_ipc4_copier *ipc4_copier = dai->private;
2373 pipeline = pipe_widget->private;
2374 if (pipeline->use_chain_dma)
2377 ipc_size = ipc4_copier->ipc_config_size;
2378 ipc_data = ipc4_copier->ipc_config_data;
2380 msg = &ipc4_copier->msg;
2383 case snd_soc_dapm_pga:
2385 struct sof_ipc4_gain *gain = swidget->private;
2387 ipc_size = sizeof(gain->data);
2388 ipc_data = &gain->data;
2393 case snd_soc_dapm_mixer:
2395 struct sof_ipc4_mixer *mixer = swidget->private;
2397 ipc_size = sizeof(mixer->base_config);
2398 ipc_data = &mixer->base_config;
2403 case snd_soc_dapm_src:
2405 struct sof_ipc4_src *src = swidget->private;
2407 ipc_size = sizeof(src->data);
2408 ipc_data = &src->data;
2413 case snd_soc_dapm_effect:
2415 struct sof_ipc4_process *process = swidget->private;
2417 if (!process->ipc_config_size) {
2418 dev_err(sdev->dev, "module %s has no config data!\n",
2419 swidget->widget->name);
2423 ipc_size = process->ipc_config_size;
2424 ipc_data = process->ipc_config_data;
2426 msg = &process->msg;
2430 dev_err(sdev->dev, "widget type %d not supported", swidget->id);
2434 if (swidget->id != snd_soc_dapm_scheduler) {
2435 int module_id = msg->primary & SOF_IPC4_MOD_ID_MASK;
2437 ret = sof_ipc4_widget_assign_instance_id(sdev, swidget);
2439 dev_err(sdev->dev, "failed to assign instance id for %s\n",
2440 swidget->widget->name);
2444 msg->primary &= ~SOF_IPC4_MOD_INSTANCE_MASK;
2445 msg->primary |= SOF_IPC4_MOD_INSTANCE(swidget->instance_id);
2447 msg->extension &= ~SOF_IPC4_MOD_EXT_PARAM_SIZE_MASK;
2448 msg->extension |= ipc_size >> 2;
2450 msg->extension &= ~SOF_IPC4_MOD_EXT_PPL_ID_MASK;
2451 msg->extension |= SOF_IPC4_MOD_EXT_PPL_ID(pipe_widget->instance_id);
2453 dev_dbg(sdev->dev, "Create widget %s (pipe %d) - ID %d, instance %d, core %d\n",
2454 swidget->widget->name, swidget->pipeline_id, module_id,
2455 swidget->instance_id, swidget->core);
2457 dev_dbg(sdev->dev, "Create pipeline %s (pipe %d) - instance %d, core %d\n",
2458 swidget->widget->name, swidget->pipeline_id,
2459 swidget->instance_id, swidget->core);
2462 msg->data_size = ipc_size;
2463 msg->data_ptr = ipc_data;
2465 ret = sof_ipc_tx_message_no_reply(sdev->ipc, msg, ipc_size);
2467 dev_err(sdev->dev, "failed to create module %s\n", swidget->widget->name);
2469 if (swidget->id != snd_soc_dapm_scheduler) {
2470 struct sof_ipc4_fw_module *fw_module = swidget->module_info;
2472 ida_free(&fw_module->m_ida, swidget->instance_id);
2474 ida_free(&pipeline_ida, swidget->instance_id);
2481 static int sof_ipc4_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
2483 struct sof_ipc4_fw_module *fw_module = swidget->module_info;
2484 struct sof_ipc4_fw_data *ipc4_data = sdev->private;
2487 mutex_lock(&ipc4_data->pipeline_state_mutex);
2489 /* freeing a pipeline frees all the widgets associated with it */
2490 if (swidget->id == snd_soc_dapm_scheduler) {
2491 struct sof_ipc4_pipeline *pipeline = swidget->private;
2492 struct sof_ipc4_msg msg = {{ 0 }};
2495 if (pipeline->use_chain_dma) {
2496 dev_warn(sdev->dev, "use_chain_dma set for scheduler %s",
2497 swidget->widget->name);
2498 mutex_unlock(&ipc4_data->pipeline_state_mutex);
2502 header = SOF_IPC4_GLB_PIPE_INSTANCE_ID(swidget->instance_id);
2503 header |= SOF_IPC4_MSG_TYPE_SET(SOF_IPC4_GLB_DELETE_PIPELINE);
2504 header |= SOF_IPC4_MSG_DIR(SOF_IPC4_MSG_REQUEST);
2505 header |= SOF_IPC4_MSG_TARGET(SOF_IPC4_FW_GEN_MSG);
2507 msg.primary = header;
2509 ret = sof_ipc_tx_message_no_reply(sdev->ipc, &msg, 0);
2511 dev_err(sdev->dev, "failed to free pipeline widget %s\n",
2512 swidget->widget->name);
2514 pipeline->mem_usage = 0;
2515 pipeline->state = SOF_IPC4_PIPE_UNINITIALIZED;
2516 ida_free(&pipeline_ida, swidget->instance_id);
2517 swidget->instance_id = -EINVAL;
2519 struct snd_sof_widget *pipe_widget = swidget->spipe->pipe_widget;
2520 struct sof_ipc4_pipeline *pipeline = pipe_widget->private;
2522 if (!pipeline->use_chain_dma)
2523 ida_free(&fw_module->m_ida, swidget->instance_id);
2526 mutex_unlock(&ipc4_data->pipeline_state_mutex);
2531 static int sof_ipc4_get_queue_id(struct snd_sof_widget *src_widget,
2532 struct snd_sof_widget *sink_widget, bool pin_type)
2534 struct snd_sof_widget *current_swidget;
2535 struct snd_soc_component *scomp;
2536 struct ida *queue_ida;
2537 const char *buddy_name;
2542 if (pin_type == SOF_PIN_TYPE_OUTPUT) {
2543 current_swidget = src_widget;
2544 pin_binding = src_widget->output_pin_binding;
2545 queue_ida = &src_widget->output_queue_ida;
2546 num_pins = src_widget->num_output_pins;
2547 buddy_name = sink_widget->widget->name;
2549 current_swidget = sink_widget;
2550 pin_binding = sink_widget->input_pin_binding;
2551 queue_ida = &sink_widget->input_queue_ida;
2552 num_pins = sink_widget->num_input_pins;
2553 buddy_name = src_widget->widget->name;
2556 scomp = current_swidget->scomp;
2559 dev_err(scomp->dev, "invalid %s num_pins: %d for queue allocation for %s\n",
2560 (pin_type == SOF_PIN_TYPE_OUTPUT ? "output" : "input"),
2561 num_pins, current_swidget->widget->name);
2565 /* If there is only one input/output pin, queue id must be 0 */
2569 /* Allocate queue ID from pin binding array if it is defined in topology. */
2571 for (i = 0; i < num_pins; i++) {
2572 if (!strcmp(pin_binding[i], buddy_name))
2576 * Fail if no queue ID found from pin binding array, so that we don't
2577 * mixed use pin binding array and ida for queue ID allocation.
2579 dev_err(scomp->dev, "no %s queue id found from pin binding array for %s\n",
2580 (pin_type == SOF_PIN_TYPE_OUTPUT ? "output" : "input"),
2581 current_swidget->widget->name);
2585 /* If no pin binding array specified in topology, use ida to allocate one */
2586 return ida_alloc_max(queue_ida, num_pins, GFP_KERNEL);
2589 static void sof_ipc4_put_queue_id(struct snd_sof_widget *swidget, int queue_id,
2592 struct ida *queue_ida;
2596 if (pin_type == SOF_PIN_TYPE_OUTPUT) {
2597 pin_binding = swidget->output_pin_binding;
2598 queue_ida = &swidget->output_queue_ida;
2599 num_pins = swidget->num_output_pins;
2601 pin_binding = swidget->input_pin_binding;
2602 queue_ida = &swidget->input_queue_ida;
2603 num_pins = swidget->num_input_pins;
2606 /* Nothing to free if queue ID is not allocated with ida. */
2607 if (num_pins == 1 || pin_binding)
2610 ida_free(queue_ida, queue_id);
2613 static int sof_ipc4_set_copier_sink_format(struct snd_sof_dev *sdev,
2614 struct snd_sof_widget *src_widget,
2615 struct snd_sof_widget *sink_widget,
2618 struct sof_ipc4_copier_config_set_sink_format format;
2619 const struct sof_ipc_ops *iops = sdev->ipc->ops;
2620 struct sof_ipc4_base_module_cfg *src_config;
2621 const struct sof_ipc4_audio_format *pin_fmt;
2622 struct sof_ipc4_fw_module *fw_module;
2623 struct sof_ipc4_msg msg = {{ 0 }};
2625 dev_dbg(sdev->dev, "%s set copier sink %d format\n",
2626 src_widget->widget->name, sink_id);
2628 if (WIDGET_IS_DAI(src_widget->id)) {
2629 struct snd_sof_dai *dai = src_widget->private;
2631 src_config = dai->private;
2633 src_config = src_widget->private;
2636 fw_module = src_widget->module_info;
2638 format.sink_id = sink_id;
2639 memcpy(&format.source_fmt, &src_config->audio_fmt, sizeof(format.source_fmt));
2641 pin_fmt = sof_ipc4_get_input_pin_audio_fmt(sink_widget, sink_id);
2643 dev_err(sdev->dev, "Unable to get pin %d format for %s",
2644 sink_id, sink_widget->widget->name);
2648 memcpy(&format.sink_fmt, pin_fmt, sizeof(format.sink_fmt));
2650 msg.data_size = sizeof(format);
2651 msg.data_ptr = &format;
2653 msg.primary = fw_module->man4_module_entry.id;
2654 msg.primary |= SOF_IPC4_MOD_INSTANCE(src_widget->instance_id);
2655 msg.primary |= SOF_IPC4_MSG_DIR(SOF_IPC4_MSG_REQUEST);
2656 msg.primary |= SOF_IPC4_MSG_TARGET(SOF_IPC4_MODULE_MSG);
2659 SOF_IPC4_MOD_EXT_MSG_PARAM_ID(SOF_IPC4_COPIER_MODULE_CFG_PARAM_SET_SINK_FORMAT);
2661 return iops->set_get_data(sdev, &msg, msg.data_size, true);
2664 static int sof_ipc4_route_setup(struct snd_sof_dev *sdev, struct snd_sof_route *sroute)
2666 struct snd_sof_widget *src_widget = sroute->src_widget;
2667 struct snd_sof_widget *sink_widget = sroute->sink_widget;
2668 struct snd_sof_widget *src_pipe_widget = src_widget->spipe->pipe_widget;
2669 struct snd_sof_widget *sink_pipe_widget = sink_widget->spipe->pipe_widget;
2670 struct sof_ipc4_fw_module *src_fw_module = src_widget->module_info;
2671 struct sof_ipc4_fw_module *sink_fw_module = sink_widget->module_info;
2672 struct sof_ipc4_pipeline *src_pipeline = src_pipe_widget->private;
2673 struct sof_ipc4_pipeline *sink_pipeline = sink_pipe_widget->private;
2674 struct sof_ipc4_msg msg = {{ 0 }};
2675 u32 header, extension;
2678 /* no route set up if chain DMA is used */
2679 if (src_pipeline->use_chain_dma || sink_pipeline->use_chain_dma) {
2680 if (!src_pipeline->use_chain_dma || !sink_pipeline->use_chain_dma) {
2682 "use_chain_dma must be set for both src %s and sink %s pipelines\n",
2683 src_widget->widget->name, sink_widget->widget->name);
2689 if (!src_fw_module || !sink_fw_module) {
2691 "cannot bind %s -> %s, no firmware module for: %s%s\n",
2692 src_widget->widget->name, sink_widget->widget->name,
2693 src_fw_module ? "" : " source",
2694 sink_fw_module ? "" : " sink");
2699 sroute->src_queue_id = sof_ipc4_get_queue_id(src_widget, sink_widget,
2700 SOF_PIN_TYPE_OUTPUT);
2701 if (sroute->src_queue_id < 0) {
2702 dev_err(sdev->dev, "failed to get queue ID for source widget: %s\n",
2703 src_widget->widget->name);
2704 return sroute->src_queue_id;
2707 sroute->dst_queue_id = sof_ipc4_get_queue_id(src_widget, sink_widget,
2708 SOF_PIN_TYPE_INPUT);
2709 if (sroute->dst_queue_id < 0) {
2710 dev_err(sdev->dev, "failed to get queue ID for sink widget: %s\n",
2711 sink_widget->widget->name);
2712 sof_ipc4_put_queue_id(src_widget, sroute->src_queue_id,
2713 SOF_PIN_TYPE_OUTPUT);
2714 return sroute->dst_queue_id;
2717 /* Pin 0 format is already set during copier module init */
2718 if (sroute->src_queue_id > 0 && WIDGET_IS_COPIER(src_widget->id)) {
2719 ret = sof_ipc4_set_copier_sink_format(sdev, src_widget, sink_widget,
2720 sroute->src_queue_id);
2722 dev_err(sdev->dev, "failed to set sink format for %s source queue ID %d\n",
2723 src_widget->widget->name, sroute->src_queue_id);
2728 dev_dbg(sdev->dev, "bind %s:%d -> %s:%d\n",
2729 src_widget->widget->name, sroute->src_queue_id,
2730 sink_widget->widget->name, sroute->dst_queue_id);
2732 header = src_fw_module->man4_module_entry.id;
2733 header |= SOF_IPC4_MOD_INSTANCE(src_widget->instance_id);
2734 header |= SOF_IPC4_MSG_TYPE_SET(SOF_IPC4_MOD_BIND);
2735 header |= SOF_IPC4_MSG_DIR(SOF_IPC4_MSG_REQUEST);
2736 header |= SOF_IPC4_MSG_TARGET(SOF_IPC4_MODULE_MSG);
2738 extension = sink_fw_module->man4_module_entry.id;
2739 extension |= SOF_IPC4_MOD_EXT_DST_MOD_INSTANCE(sink_widget->instance_id);
2740 extension |= SOF_IPC4_MOD_EXT_DST_MOD_QUEUE_ID(sroute->dst_queue_id);
2741 extension |= SOF_IPC4_MOD_EXT_SRC_MOD_QUEUE_ID(sroute->src_queue_id);
2743 msg.primary = header;
2744 msg.extension = extension;
2746 ret = sof_ipc_tx_message_no_reply(sdev->ipc, &msg, 0);
2748 dev_err(sdev->dev, "failed to bind modules %s:%d -> %s:%d\n",
2749 src_widget->widget->name, sroute->src_queue_id,
2750 sink_widget->widget->name, sroute->dst_queue_id);
2757 sof_ipc4_put_queue_id(src_widget, sroute->src_queue_id, SOF_PIN_TYPE_OUTPUT);
2758 sof_ipc4_put_queue_id(sink_widget, sroute->dst_queue_id, SOF_PIN_TYPE_INPUT);
2762 static int sof_ipc4_route_free(struct snd_sof_dev *sdev, struct snd_sof_route *sroute)
2764 struct snd_sof_widget *src_widget = sroute->src_widget;
2765 struct snd_sof_widget *sink_widget = sroute->sink_widget;
2766 struct sof_ipc4_fw_module *src_fw_module = src_widget->module_info;
2767 struct sof_ipc4_fw_module *sink_fw_module = sink_widget->module_info;
2768 struct sof_ipc4_msg msg = {{ 0 }};
2769 struct snd_sof_widget *src_pipe_widget = src_widget->spipe->pipe_widget;
2770 struct snd_sof_widget *sink_pipe_widget = sink_widget->spipe->pipe_widget;
2771 struct sof_ipc4_pipeline *src_pipeline = src_pipe_widget->private;
2772 struct sof_ipc4_pipeline *sink_pipeline = sink_pipe_widget->private;
2773 u32 header, extension;
2776 /* no route is set up if chain DMA is used */
2777 if (src_pipeline->use_chain_dma || sink_pipeline->use_chain_dma)
2780 dev_dbg(sdev->dev, "unbind modules %s:%d -> %s:%d\n",
2781 src_widget->widget->name, sroute->src_queue_id,
2782 sink_widget->widget->name, sroute->dst_queue_id);
2785 * routes belonging to the same pipeline will be disconnected by the FW when the pipeline
2786 * is freed. So avoid sending this IPC which will be ignored by the FW anyway.
2788 if (src_widget->spipe->pipe_widget == sink_widget->spipe->pipe_widget)
2791 header = src_fw_module->man4_module_entry.id;
2792 header |= SOF_IPC4_MOD_INSTANCE(src_widget->instance_id);
2793 header |= SOF_IPC4_MSG_TYPE_SET(SOF_IPC4_MOD_UNBIND);
2794 header |= SOF_IPC4_MSG_DIR(SOF_IPC4_MSG_REQUEST);
2795 header |= SOF_IPC4_MSG_TARGET(SOF_IPC4_MODULE_MSG);
2797 extension = sink_fw_module->man4_module_entry.id;
2798 extension |= SOF_IPC4_MOD_EXT_DST_MOD_INSTANCE(sink_widget->instance_id);
2799 extension |= SOF_IPC4_MOD_EXT_DST_MOD_QUEUE_ID(sroute->dst_queue_id);
2800 extension |= SOF_IPC4_MOD_EXT_SRC_MOD_QUEUE_ID(sroute->src_queue_id);
2802 msg.primary = header;
2803 msg.extension = extension;
2805 ret = sof_ipc_tx_message_no_reply(sdev->ipc, &msg, 0);
2807 dev_err(sdev->dev, "failed to unbind modules %s:%d -> %s:%d\n",
2808 src_widget->widget->name, sroute->src_queue_id,
2809 sink_widget->widget->name, sroute->dst_queue_id);
2811 sof_ipc4_put_queue_id(sink_widget, sroute->dst_queue_id, SOF_PIN_TYPE_INPUT);
2812 sof_ipc4_put_queue_id(src_widget, sroute->src_queue_id, SOF_PIN_TYPE_OUTPUT);
2817 static int sof_ipc4_dai_config(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget,
2818 unsigned int flags, struct snd_sof_dai_config_data *data)
2820 struct snd_sof_widget *pipe_widget = swidget->spipe->pipe_widget;
2821 struct sof_ipc4_pipeline *pipeline = pipe_widget->private;
2822 struct snd_sof_dai *dai = swidget->private;
2823 struct sof_ipc4_gtw_attributes *gtw_attr;
2824 struct sof_ipc4_copier_data *copier_data;
2825 struct sof_ipc4_copier *ipc4_copier;
2827 if (!dai || !dai->private) {
2828 dev_err(sdev->dev, "Invalid DAI or DAI private data for %s\n",
2829 swidget->widget->name);
2833 ipc4_copier = (struct sof_ipc4_copier *)dai->private;
2834 copier_data = &ipc4_copier->data;
2839 if (pipeline->use_chain_dma) {
2840 pipeline->msg.primary &= ~SOF_IPC4_GLB_CHAIN_DMA_LINK_ID_MASK;
2841 pipeline->msg.primary |= SOF_IPC4_GLB_CHAIN_DMA_LINK_ID(data->dai_data);
2845 switch (ipc4_copier->dai_type) {
2846 case SOF_DAI_INTEL_HDA:
2847 gtw_attr = ipc4_copier->gtw_attr;
2848 gtw_attr->lp_buffer_alloc = pipeline->lp_mode;
2850 case SOF_DAI_INTEL_ALH:
2852 * Do not clear the node ID when this op is invoked with
2853 * SOF_DAI_CONFIG_FLAGS_HW_FREE. It is needed to free the group_ida during
2856 if (flags & SOF_DAI_CONFIG_FLAGS_HW_PARAMS) {
2857 copier_data->gtw_cfg.node_id &= ~SOF_IPC4_NODE_INDEX_MASK;
2858 copier_data->gtw_cfg.node_id |= SOF_IPC4_NODE_INDEX(data->dai_data);
2861 case SOF_DAI_INTEL_DMIC:
2862 case SOF_DAI_INTEL_SSP:
2863 /* nothing to do for SSP/DMIC */
2866 dev_err(sdev->dev, "%s: unsupported dai type %d\n", __func__,
2867 ipc4_copier->dai_type);
2874 static int sof_ipc4_parse_manifest(struct snd_soc_component *scomp, int index,
2875 struct snd_soc_tplg_manifest *man)
2877 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
2878 struct sof_ipc4_fw_data *ipc4_data = sdev->private;
2879 struct sof_manifest_tlv *manifest_tlv;
2880 struct sof_manifest *manifest;
2881 u32 size = le32_to_cpu(man->priv.size);
2882 u8 *man_ptr = man->priv.data;
2886 if (!size || size < SOF_IPC4_TPLG_ABI_SIZE) {
2887 dev_err(scomp->dev, "%s: Invalid topology ABI size: %u\n",
2892 manifest = (struct sof_manifest *)man_ptr;
2894 dev_info(scomp->dev,
2895 "Topology: ABI %d:%d:%d Kernel ABI %u:%u:%u\n",
2896 le16_to_cpu(manifest->abi_major), le16_to_cpu(manifest->abi_minor),
2897 le16_to_cpu(manifest->abi_patch),
2898 SOF_ABI_MAJOR, SOF_ABI_MINOR, SOF_ABI_PATCH);
2900 /* TODO: Add ABI compatibility check */
2902 /* no more data after the ABI version */
2903 if (size <= SOF_IPC4_TPLG_ABI_SIZE)
2906 manifest_tlv = manifest->items;
2907 len_check = sizeof(struct sof_manifest);
2908 for (i = 0; i < le16_to_cpu(manifest->count); i++) {
2909 len_check += sizeof(struct sof_manifest_tlv) + le32_to_cpu(manifest_tlv->size);
2910 if (len_check > size)
2913 switch (le32_to_cpu(manifest_tlv->type)) {
2914 case SOF_MANIFEST_DATA_TYPE_NHLT:
2915 /* no NHLT in BIOS, so use the one from topology manifest */
2916 if (ipc4_data->nhlt)
2918 ipc4_data->nhlt = devm_kmemdup(sdev->dev, manifest_tlv->data,
2919 le32_to_cpu(manifest_tlv->size), GFP_KERNEL);
2920 if (!ipc4_data->nhlt)
2924 dev_warn(scomp->dev, "Skipping unknown manifest data type %d\n",
2925 manifest_tlv->type);
2928 man_ptr += sizeof(struct sof_manifest_tlv) + le32_to_cpu(manifest_tlv->size);
2929 manifest_tlv = (struct sof_manifest_tlv *)man_ptr;
2935 static int sof_ipc4_dai_get_clk(struct snd_sof_dev *sdev, struct snd_sof_dai *dai, int clk_type)
2937 struct sof_ipc4_copier *ipc4_copier = dai->private;
2938 struct snd_soc_tplg_hw_config *hw_config;
2939 struct snd_sof_dai_link *slink;
2940 bool dai_link_found = false;
2941 bool hw_cfg_found = false;
2947 list_for_each_entry(slink, &sdev->dai_link_list, list) {
2948 if (!strcmp(slink->link->name, dai->name)) {
2949 dai_link_found = true;
2954 if (!dai_link_found) {
2955 dev_err(sdev->dev, "no DAI link found for DAI %s\n", dai->name);
2959 for (i = 0; i < slink->num_hw_configs; i++) {
2960 hw_config = &slink->hw_configs[i];
2961 if (dai->current_config == le32_to_cpu(hw_config->id)) {
2962 hw_cfg_found = true;
2967 if (!hw_cfg_found) {
2968 dev_err(sdev->dev, "no matching hw_config found for DAI %s\n", dai->name);
2972 switch (ipc4_copier->dai_type) {
2973 case SOF_DAI_INTEL_SSP:
2975 case SOF_DAI_CLK_INTEL_SSP_MCLK:
2976 return le32_to_cpu(hw_config->mclk_rate);
2977 case SOF_DAI_CLK_INTEL_SSP_BCLK:
2978 return le32_to_cpu(hw_config->bclk_rate);
2980 dev_err(sdev->dev, "Invalid clk type for SSP %d\n", clk_type);
2985 dev_err(sdev->dev, "DAI type %d not supported yet!\n", ipc4_copier->dai_type);
2992 static int sof_ipc4_tear_down_all_pipelines(struct snd_sof_dev *sdev, bool verify)
2994 struct snd_sof_pcm *spcm;
2998 * This function is called during system suspend, we need to make sure
2999 * that all streams have been freed up.
3000 * Freeing might have been skipped when xrun happened just at the start
3001 * of the suspend and it sent a SNDRV_PCM_TRIGGER_STOP to the active
3002 * stream. This will call sof_pcm_stream_free() with
3003 * free_widget_list = false which will leave the kernel and firmware out
3004 * of sync during suspend/resume.
3006 * This will also make sure that paused streams handled correctly.
3008 list_for_each_entry(spcm, &sdev->pcm_list, list) {
3009 for_each_pcm_streams(dir) {
3010 struct snd_pcm_substream *substream = spcm->stream[dir].substream;
3012 if (!substream || !substream->runtime || spcm->stream[dir].suspend_ignored)
3015 if (spcm->stream[dir].list) {
3016 ret = sof_pcm_stream_free(sdev, substream, spcm, dir, true);
3025 static int sof_ipc4_link_setup(struct snd_sof_dev *sdev, struct snd_soc_dai_link *link)
3031 * set default trigger order for all links. Exceptions to
3032 * the rule will be handled in sof_pcm_dai_link_fixup()
3033 * For playback, the sequence is the following: start BE,
3034 * start FE, stop FE, stop BE; for Capture the sequence is
3035 * inverted start FE, start BE, stop BE, stop FE
3037 link->trigger[SNDRV_PCM_STREAM_PLAYBACK] = SND_SOC_DPCM_TRIGGER_POST;
3038 link->trigger[SNDRV_PCM_STREAM_CAPTURE] = SND_SOC_DPCM_TRIGGER_PRE;
3043 static enum sof_tokens common_copier_token_list[] = {
3045 SOF_AUDIO_FMT_NUM_TOKENS,
3046 SOF_IN_AUDIO_FORMAT_TOKENS,
3047 SOF_OUT_AUDIO_FORMAT_TOKENS,
3048 SOF_COPIER_DEEP_BUFFER_TOKENS,
3050 SOF_COMP_EXT_TOKENS,
3053 static enum sof_tokens pipeline_token_list[] = {
3055 SOF_PIPELINE_TOKENS,
3058 static enum sof_tokens dai_token_list[] = {
3060 SOF_AUDIO_FMT_NUM_TOKENS,
3061 SOF_IN_AUDIO_FORMAT_TOKENS,
3062 SOF_OUT_AUDIO_FORMAT_TOKENS,
3065 SOF_COMP_EXT_TOKENS,
3068 static enum sof_tokens pga_token_list[] = {
3071 SOF_AUDIO_FMT_NUM_TOKENS,
3072 SOF_IN_AUDIO_FORMAT_TOKENS,
3073 SOF_OUT_AUDIO_FORMAT_TOKENS,
3074 SOF_COMP_EXT_TOKENS,
3077 static enum sof_tokens mixer_token_list[] = {
3079 SOF_AUDIO_FMT_NUM_TOKENS,
3080 SOF_IN_AUDIO_FORMAT_TOKENS,
3081 SOF_OUT_AUDIO_FORMAT_TOKENS,
3082 SOF_COMP_EXT_TOKENS,
3085 static enum sof_tokens src_token_list[] = {
3088 SOF_AUDIO_FMT_NUM_TOKENS,
3089 SOF_IN_AUDIO_FORMAT_TOKENS,
3090 SOF_OUT_AUDIO_FORMAT_TOKENS,
3091 SOF_COMP_EXT_TOKENS,
3094 static enum sof_tokens process_token_list[] = {
3096 SOF_AUDIO_FMT_NUM_TOKENS,
3097 SOF_IN_AUDIO_FORMAT_TOKENS,
3098 SOF_OUT_AUDIO_FORMAT_TOKENS,
3099 SOF_COMP_EXT_TOKENS,
3102 static const struct sof_ipc_tplg_widget_ops tplg_ipc4_widget_ops[SND_SOC_DAPM_TYPE_COUNT] = {
3103 [snd_soc_dapm_aif_in] = {sof_ipc4_widget_setup_pcm, sof_ipc4_widget_free_comp_pcm,
3104 common_copier_token_list, ARRAY_SIZE(common_copier_token_list),
3105 NULL, sof_ipc4_prepare_copier_module,
3106 sof_ipc4_unprepare_copier_module},
3107 [snd_soc_dapm_aif_out] = {sof_ipc4_widget_setup_pcm, sof_ipc4_widget_free_comp_pcm,
3108 common_copier_token_list, ARRAY_SIZE(common_copier_token_list),
3109 NULL, sof_ipc4_prepare_copier_module,
3110 sof_ipc4_unprepare_copier_module},
3111 [snd_soc_dapm_dai_in] = {sof_ipc4_widget_setup_comp_dai, sof_ipc4_widget_free_comp_dai,
3112 dai_token_list, ARRAY_SIZE(dai_token_list), NULL,
3113 sof_ipc4_prepare_copier_module,
3114 sof_ipc4_unprepare_copier_module},
3115 [snd_soc_dapm_dai_out] = {sof_ipc4_widget_setup_comp_dai, sof_ipc4_widget_free_comp_dai,
3116 dai_token_list, ARRAY_SIZE(dai_token_list), NULL,
3117 sof_ipc4_prepare_copier_module,
3118 sof_ipc4_unprepare_copier_module},
3119 [snd_soc_dapm_buffer] = {sof_ipc4_widget_setup_pcm, sof_ipc4_widget_free_comp_pcm,
3120 common_copier_token_list, ARRAY_SIZE(common_copier_token_list),
3121 NULL, sof_ipc4_prepare_copier_module,
3122 sof_ipc4_unprepare_copier_module},
3123 [snd_soc_dapm_scheduler] = {sof_ipc4_widget_setup_comp_pipeline,
3124 sof_ipc4_widget_free_comp_pipeline,
3125 pipeline_token_list, ARRAY_SIZE(pipeline_token_list), NULL,
3127 [snd_soc_dapm_pga] = {sof_ipc4_widget_setup_comp_pga, sof_ipc4_widget_free_comp_pga,
3128 pga_token_list, ARRAY_SIZE(pga_token_list), NULL,
3129 sof_ipc4_prepare_gain_module,
3131 [snd_soc_dapm_mixer] = {sof_ipc4_widget_setup_comp_mixer, sof_ipc4_widget_free_comp_mixer,
3132 mixer_token_list, ARRAY_SIZE(mixer_token_list),
3133 NULL, sof_ipc4_prepare_mixer_module,
3135 [snd_soc_dapm_src] = {sof_ipc4_widget_setup_comp_src, sof_ipc4_widget_free_comp_src,
3136 src_token_list, ARRAY_SIZE(src_token_list),
3137 NULL, sof_ipc4_prepare_src_module,
3139 [snd_soc_dapm_effect] = {sof_ipc4_widget_setup_comp_process,
3140 sof_ipc4_widget_free_comp_process,
3141 process_token_list, ARRAY_SIZE(process_token_list),
3142 NULL, sof_ipc4_prepare_process_module,
3146 const struct sof_ipc_tplg_ops ipc4_tplg_ops = {
3147 .widget = tplg_ipc4_widget_ops,
3148 .token_list = ipc4_token_list,
3149 .control_setup = sof_ipc4_control_setup,
3150 .control = &tplg_ipc4_control_ops,
3151 .widget_setup = sof_ipc4_widget_setup,
3152 .widget_free = sof_ipc4_widget_free,
3153 .route_setup = sof_ipc4_route_setup,
3154 .route_free = sof_ipc4_route_free,
3155 .dai_config = sof_ipc4_dai_config,
3156 .parse_manifest = sof_ipc4_parse_manifest,
3157 .dai_get_clk = sof_ipc4_dai_get_clk,
3158 .tear_down_all_pipelines = sof_ipc4_tear_down_all_pipelines,
3159 .link_setup = sof_ipc4_link_setup,