xref: /linux/sound/soc/sof/ipc3-topology.c (revision d9265a36f4be6f322814e0eb255e4e29b39dd5cc)
1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2 //
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.
5 //
6 // Copyright(c) 2021 Intel Corporation
7 //
8 //
9 
10 #include <uapi/sound/sof/tokens.h>
11 #include <sound/pcm_params.h>
12 #include "sof-priv.h"
13 #include "sof-audio.h"
14 #include "ipc3-priv.h"
15 #include "ops.h"
16 
17 /* Full volume for default values */
18 #define VOL_ZERO_DB	BIT(VOLUME_FWL)
19 
20 /* size of tplg ABI in bytes */
21 #define SOF_IPC3_TPLG_ABI_SIZE 3
22 
23 /* Base of SOF_DAI_INTEL_ALH, this should be aligned with SOC_SDW_INTEL_BIDIR_PDI_BASE */
24 #define INTEL_ALH_DAI_INDEX_BASE 2
25 
26 struct sof_widget_data {
27 	int ctrl_type;
28 	int ipc_cmd;
29 	void *pdata;
30 	size_t pdata_size;
31 	struct snd_sof_control *control;
32 };
33 
34 struct sof_process_types {
35 	const char *name;
36 	enum sof_ipc_process_type type;
37 	enum sof_comp_type comp_type;
38 };
39 
40 static const struct sof_process_types sof_process[] = {
41 	{"EQFIR", SOF_PROCESS_EQFIR, SOF_COMP_EQ_FIR},
42 	{"EQIIR", SOF_PROCESS_EQIIR, SOF_COMP_EQ_IIR},
43 	{"KEYWORD_DETECT", SOF_PROCESS_KEYWORD_DETECT, SOF_COMP_KEYWORD_DETECT},
44 	{"KPB", SOF_PROCESS_KPB, SOF_COMP_KPB},
45 	{"CHAN_SELECTOR", SOF_PROCESS_CHAN_SELECTOR, SOF_COMP_SELECTOR},
46 	{"MUX", SOF_PROCESS_MUX, SOF_COMP_MUX},
47 	{"DEMUX", SOF_PROCESS_DEMUX, SOF_COMP_DEMUX},
48 	{"DCBLOCK", SOF_PROCESS_DCBLOCK, SOF_COMP_DCBLOCK},
49 	{"SMART_AMP", SOF_PROCESS_SMART_AMP, SOF_COMP_SMART_AMP},
50 };
51 
52 static enum sof_ipc_process_type find_process(const char *name)
53 {
54 	int i;
55 
56 	for (i = 0; i < ARRAY_SIZE(sof_process); i++) {
57 		if (strcmp(name, sof_process[i].name) == 0)
58 			return sof_process[i].type;
59 	}
60 
61 	return SOF_PROCESS_NONE;
62 }
63 
64 static int get_token_process_type(void *elem, void *object, u32 offset)
65 {
66 	u32 *val = (u32 *)((u8 *)object + offset);
67 
68 	*val = find_process((const char *)elem);
69 	return 0;
70 }
71 
72 /* Buffers */
73 static const struct sof_topology_token buffer_tokens[] = {
74 	{SOF_TKN_BUF_SIZE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
75 		offsetof(struct sof_ipc_buffer, size)},
76 	{SOF_TKN_BUF_CAPS, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
77 		offsetof(struct sof_ipc_buffer, caps)},
78 	{SOF_TKN_BUF_FLAGS, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
79 		offsetof(struct sof_ipc_buffer, flags)},
80 };
81 
82 /* DAI */
83 static const struct sof_topology_token dai_tokens[] = {
84 	{SOF_TKN_DAI_TYPE, SND_SOC_TPLG_TUPLE_TYPE_STRING, get_token_dai_type,
85 		offsetof(struct sof_ipc_comp_dai, type)},
86 	{SOF_TKN_DAI_INDEX, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
87 		offsetof(struct sof_ipc_comp_dai, dai_index)},
88 	{SOF_TKN_DAI_DIRECTION, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
89 		offsetof(struct sof_ipc_comp_dai, direction)},
90 };
91 
92 /* BE DAI link */
93 static const struct sof_topology_token dai_link_tokens[] = {
94 	{SOF_TKN_DAI_TYPE, SND_SOC_TPLG_TUPLE_TYPE_STRING, get_token_dai_type,
95 		offsetof(struct sof_ipc_dai_config, type)},
96 	{SOF_TKN_DAI_INDEX, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
97 		offsetof(struct sof_ipc_dai_config, dai_index)},
98 };
99 
100 /* scheduling */
101 static const struct sof_topology_token sched_tokens[] = {
102 	{SOF_TKN_SCHED_PERIOD, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
103 		offsetof(struct sof_ipc_pipe_new, period)},
104 	{SOF_TKN_SCHED_PRIORITY, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
105 		offsetof(struct sof_ipc_pipe_new, priority)},
106 	{SOF_TKN_SCHED_MIPS, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
107 		offsetof(struct sof_ipc_pipe_new, period_mips)},
108 	{SOF_TKN_SCHED_CORE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
109 		offsetof(struct sof_ipc_pipe_new, core)},
110 	{SOF_TKN_SCHED_FRAMES, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
111 		offsetof(struct sof_ipc_pipe_new, frames_per_sched)},
112 	{SOF_TKN_SCHED_TIME_DOMAIN, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
113 		offsetof(struct sof_ipc_pipe_new, time_domain)},
114 };
115 
116 static const struct sof_topology_token pipeline_tokens[] = {
117 	{SOF_TKN_SCHED_DYNAMIC_PIPELINE, SND_SOC_TPLG_TUPLE_TYPE_BOOL, get_token_u16,
118 		offsetof(struct snd_sof_widget, dynamic_pipeline_widget)},
119 
120 };
121 
122 /* volume */
123 static const struct sof_topology_token volume_tokens[] = {
124 	{SOF_TKN_VOLUME_RAMP_STEP_TYPE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
125 		offsetof(struct sof_ipc_comp_volume, ramp)},
126 	{SOF_TKN_VOLUME_RAMP_STEP_MS, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
127 		offsetof(struct sof_ipc_comp_volume, initial_ramp)},
128 };
129 
130 /* SRC */
131 static const struct sof_topology_token src_tokens[] = {
132 	{SOF_TKN_SRC_RATE_IN, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
133 		offsetof(struct sof_ipc_comp_src, source_rate)},
134 	{SOF_TKN_SRC_RATE_OUT, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
135 		offsetof(struct sof_ipc_comp_src, sink_rate)},
136 };
137 
138 /* ASRC */
139 static const struct sof_topology_token asrc_tokens[] = {
140 	{SOF_TKN_ASRC_RATE_IN, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
141 		offsetof(struct sof_ipc_comp_asrc, source_rate)},
142 	{SOF_TKN_ASRC_RATE_OUT, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
143 		offsetof(struct sof_ipc_comp_asrc, sink_rate)},
144 	{SOF_TKN_ASRC_ASYNCHRONOUS_MODE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
145 		offsetof(struct sof_ipc_comp_asrc, asynchronous_mode)},
146 	{SOF_TKN_ASRC_OPERATION_MODE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
147 		offsetof(struct sof_ipc_comp_asrc, operation_mode)},
148 };
149 
150 /* EFFECT */
151 static const struct sof_topology_token process_tokens[] = {
152 	{SOF_TKN_PROCESS_TYPE, SND_SOC_TPLG_TUPLE_TYPE_STRING, get_token_process_type,
153 		offsetof(struct sof_ipc_comp_process, type)},
154 };
155 
156 /* PCM */
157 static const struct sof_topology_token pcm_tokens[] = {
158 	{SOF_TKN_PCM_DMAC_CONFIG, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
159 		offsetof(struct sof_ipc_comp_host, dmac_config)},
160 };
161 
162 /* Generic components */
163 static const struct sof_topology_token comp_tokens[] = {
164 	{SOF_TKN_COMP_PERIOD_SINK_COUNT, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
165 		offsetof(struct sof_ipc_comp_config, periods_sink)},
166 	{SOF_TKN_COMP_PERIOD_SOURCE_COUNT, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
167 		offsetof(struct sof_ipc_comp_config, periods_source)},
168 	{SOF_TKN_COMP_FORMAT,
169 		SND_SOC_TPLG_TUPLE_TYPE_STRING, get_token_comp_format,
170 		offsetof(struct sof_ipc_comp_config, frame_fmt)},
171 };
172 
173 /* SSP */
174 static const struct sof_topology_token ssp_tokens[] = {
175 	{SOF_TKN_INTEL_SSP_CLKS_CONTROL, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
176 		offsetof(struct sof_ipc_dai_ssp_params, clks_control)},
177 	{SOF_TKN_INTEL_SSP_MCLK_ID, SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
178 		offsetof(struct sof_ipc_dai_ssp_params, mclk_id)},
179 	{SOF_TKN_INTEL_SSP_SAMPLE_BITS, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
180 		offsetof(struct sof_ipc_dai_ssp_params, sample_valid_bits)},
181 	{SOF_TKN_INTEL_SSP_FRAME_PULSE_WIDTH, SND_SOC_TPLG_TUPLE_TYPE_SHORT,	get_token_u16,
182 		offsetof(struct sof_ipc_dai_ssp_params, frame_pulse_width)},
183 	{SOF_TKN_INTEL_SSP_QUIRKS, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
184 		offsetof(struct sof_ipc_dai_ssp_params, quirks)},
185 	{SOF_TKN_INTEL_SSP_TDM_PADDING_PER_SLOT, SND_SOC_TPLG_TUPLE_TYPE_BOOL, get_token_u16,
186 		offsetof(struct sof_ipc_dai_ssp_params, tdm_per_slot_padding_flag)},
187 	{SOF_TKN_INTEL_SSP_BCLK_DELAY, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
188 		offsetof(struct sof_ipc_dai_ssp_params, bclk_delay)},
189 };
190 
191 /* ALH */
192 static const struct sof_topology_token alh_tokens[] = {
193 	{SOF_TKN_INTEL_ALH_RATE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
194 		offsetof(struct sof_ipc_dai_alh_params, rate)},
195 	{SOF_TKN_INTEL_ALH_CH,	SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
196 		offsetof(struct sof_ipc_dai_alh_params, channels)},
197 };
198 
199 /* DMIC */
200 static const struct sof_topology_token dmic_tokens[] = {
201 	{SOF_TKN_INTEL_DMIC_DRIVER_VERSION, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
202 		offsetof(struct sof_ipc_dai_dmic_params, driver_ipc_version)},
203 	{SOF_TKN_INTEL_DMIC_CLK_MIN, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
204 		offsetof(struct sof_ipc_dai_dmic_params, pdmclk_min)},
205 	{SOF_TKN_INTEL_DMIC_CLK_MAX, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
206 		offsetof(struct sof_ipc_dai_dmic_params, pdmclk_max)},
207 	{SOF_TKN_INTEL_DMIC_SAMPLE_RATE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
208 		offsetof(struct sof_ipc_dai_dmic_params, fifo_fs)},
209 	{SOF_TKN_INTEL_DMIC_DUTY_MIN, SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
210 		offsetof(struct sof_ipc_dai_dmic_params, duty_min)},
211 	{SOF_TKN_INTEL_DMIC_DUTY_MAX, SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
212 		offsetof(struct sof_ipc_dai_dmic_params, duty_max)},
213 	{SOF_TKN_INTEL_DMIC_NUM_PDM_ACTIVE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
214 		offsetof(struct sof_ipc_dai_dmic_params, num_pdm_active)},
215 	{SOF_TKN_INTEL_DMIC_FIFO_WORD_LENGTH, SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
216 		offsetof(struct sof_ipc_dai_dmic_params, fifo_bits)},
217 	{SOF_TKN_INTEL_DMIC_UNMUTE_RAMP_TIME_MS, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
218 		offsetof(struct sof_ipc_dai_dmic_params, unmute_ramp_time)},
219 };
220 
221 /* ESAI */
222 static const struct sof_topology_token esai_tokens[] = {
223 	{SOF_TKN_IMX_ESAI_MCLK_ID, SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
224 		offsetof(struct sof_ipc_dai_esai_params, mclk_id)},
225 };
226 
227 /* SAI */
228 static const struct sof_topology_token sai_tokens[] = {
229 	{SOF_TKN_IMX_SAI_MCLK_ID, SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
230 		offsetof(struct sof_ipc_dai_sai_params, mclk_id)},
231 };
232 
233 /*
234  * DMIC PDM Tokens
235  * SOF_TKN_INTEL_DMIC_PDM_CTRL_ID should be the first token
236  * as it increments the index while parsing the array of pdm tokens
237  * and determines the correct offset
238  */
239 static const struct sof_topology_token dmic_pdm_tokens[] = {
240 	{SOF_TKN_INTEL_DMIC_PDM_CTRL_ID, SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
241 		offsetof(struct sof_ipc_dai_dmic_pdm_ctrl, id)},
242 	{SOF_TKN_INTEL_DMIC_PDM_MIC_A_Enable, SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
243 		offsetof(struct sof_ipc_dai_dmic_pdm_ctrl, enable_mic_a)},
244 	{SOF_TKN_INTEL_DMIC_PDM_MIC_B_Enable, SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
245 		offsetof(struct sof_ipc_dai_dmic_pdm_ctrl, enable_mic_b)},
246 	{SOF_TKN_INTEL_DMIC_PDM_POLARITY_A, SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
247 		offsetof(struct sof_ipc_dai_dmic_pdm_ctrl, polarity_mic_a)},
248 	{SOF_TKN_INTEL_DMIC_PDM_POLARITY_B, SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
249 		offsetof(struct sof_ipc_dai_dmic_pdm_ctrl, polarity_mic_b)},
250 	{SOF_TKN_INTEL_DMIC_PDM_CLK_EDGE, SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
251 		offsetof(struct sof_ipc_dai_dmic_pdm_ctrl, clk_edge)},
252 	{SOF_TKN_INTEL_DMIC_PDM_SKEW, SND_SOC_TPLG_TUPLE_TYPE_SHORT, get_token_u16,
253 		offsetof(struct sof_ipc_dai_dmic_pdm_ctrl, skew)},
254 };
255 
256 /* HDA */
257 static const struct sof_topology_token hda_tokens[] = {
258 	{SOF_TKN_INTEL_HDA_RATE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
259 		offsetof(struct sof_ipc_dai_hda_params, rate)},
260 	{SOF_TKN_INTEL_HDA_CH, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
261 		offsetof(struct sof_ipc_dai_hda_params, channels)},
262 };
263 
264 /* AFE */
265 static const struct sof_topology_token afe_tokens[] = {
266 	{SOF_TKN_MEDIATEK_AFE_RATE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
267 		offsetof(struct sof_ipc_dai_mtk_afe_params, rate)},
268 	{SOF_TKN_MEDIATEK_AFE_CH, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
269 		offsetof(struct sof_ipc_dai_mtk_afe_params, channels)},
270 	{SOF_TKN_MEDIATEK_AFE_FORMAT, SND_SOC_TPLG_TUPLE_TYPE_STRING, get_token_comp_format,
271 		offsetof(struct sof_ipc_dai_mtk_afe_params, format)},
272 };
273 
274 /* ACPDMIC */
275 static const struct sof_topology_token acpdmic_tokens[] = {
276 	{SOF_TKN_AMD_ACPDMIC_RATE,
277 		SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
278 		offsetof(struct sof_ipc_dai_acpdmic_params, pdm_rate)},
279 	{SOF_TKN_AMD_ACPDMIC_CH,
280 		SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
281 		offsetof(struct sof_ipc_dai_acpdmic_params, pdm_ch)},
282 };
283 
284 /* ACPI2S */
285 static const struct sof_topology_token acpi2s_tokens[] = {
286 	{SOF_TKN_AMD_ACPI2S_RATE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
287 		offsetof(struct sof_ipc_dai_acp_params, fsync_rate)},
288 	{SOF_TKN_AMD_ACPI2S_CH, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
289 		offsetof(struct sof_ipc_dai_acp_params, tdm_slots)},
290 	{SOF_TKN_AMD_ACPI2S_TDM_MODE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
291 		offsetof(struct sof_ipc_dai_acp_params, tdm_mode)},
292 };
293 
294 /* MICFIL PDM */
295 static const struct sof_topology_token micfil_pdm_tokens[] = {
296 	{SOF_TKN_IMX_MICFIL_RATE,
297 		SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
298 		offsetof(struct sof_ipc_dai_micfil_params, pdm_rate)},
299 	{SOF_TKN_IMX_MICFIL_CH,
300 		SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
301 		offsetof(struct sof_ipc_dai_micfil_params, pdm_ch)},
302 };
303 
304 /* ACP_SDW */
305 static const struct sof_topology_token acp_sdw_tokens[] = {
306 	{SOF_TKN_AMD_ACP_SDW_RATE, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
307 		offsetof(struct sof_ipc_dai_acp_sdw_params, rate)},
308 	{SOF_TKN_AMD_ACP_SDW_CH, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
309 		offsetof(struct sof_ipc_dai_acp_sdw_params, channels)},
310 };
311 
312 /* Core tokens */
313 static const struct sof_topology_token core_tokens[] = {
314 	{SOF_TKN_COMP_CORE_ID, SND_SOC_TPLG_TUPLE_TYPE_WORD, get_token_u32,
315 		offsetof(struct sof_ipc_comp, core)},
316 };
317 
318 /* Component extended tokens */
319 static const struct sof_topology_token comp_ext_tokens[] = {
320 	{SOF_TKN_COMP_UUID, SND_SOC_TPLG_TUPLE_TYPE_UUID, get_token_uuid,
321 		offsetof(struct snd_sof_widget, uuid)},
322 };
323 
324 static const struct sof_token_info ipc3_token_list[SOF_TOKEN_COUNT] = {
325 	[SOF_PCM_TOKENS] = {"PCM tokens", pcm_tokens, ARRAY_SIZE(pcm_tokens)},
326 	[SOF_PIPELINE_TOKENS] = {"Pipeline tokens", pipeline_tokens, ARRAY_SIZE(pipeline_tokens)},
327 	[SOF_SCHED_TOKENS] = {"Scheduler tokens", sched_tokens, ARRAY_SIZE(sched_tokens)},
328 	[SOF_COMP_TOKENS] = {"Comp tokens", comp_tokens, ARRAY_SIZE(comp_tokens)},
329 	[SOF_CORE_TOKENS] = {"Core tokens", core_tokens, ARRAY_SIZE(core_tokens)},
330 	[SOF_COMP_EXT_TOKENS] = {"AFE tokens", comp_ext_tokens, ARRAY_SIZE(comp_ext_tokens)},
331 	[SOF_BUFFER_TOKENS] = {"Buffer tokens", buffer_tokens, ARRAY_SIZE(buffer_tokens)},
332 	[SOF_VOLUME_TOKENS] = {"Volume tokens", volume_tokens, ARRAY_SIZE(volume_tokens)},
333 	[SOF_SRC_TOKENS] = {"SRC tokens", src_tokens, ARRAY_SIZE(src_tokens)},
334 	[SOF_ASRC_TOKENS] = {"ASRC tokens", asrc_tokens, ARRAY_SIZE(asrc_tokens)},
335 	[SOF_PROCESS_TOKENS] = {"Process tokens", process_tokens, ARRAY_SIZE(process_tokens)},
336 	[SOF_DAI_TOKENS] = {"DAI tokens", dai_tokens, ARRAY_SIZE(dai_tokens)},
337 	[SOF_DAI_LINK_TOKENS] = {"DAI link tokens", dai_link_tokens, ARRAY_SIZE(dai_link_tokens)},
338 	[SOF_HDA_TOKENS] = {"HDA tokens", hda_tokens, ARRAY_SIZE(hda_tokens)},
339 	[SOF_SSP_TOKENS] = {"SSP tokens", ssp_tokens, ARRAY_SIZE(ssp_tokens)},
340 	[SOF_ALH_TOKENS] = {"ALH tokens", alh_tokens, ARRAY_SIZE(alh_tokens)},
341 	[SOF_DMIC_TOKENS] = {"DMIC tokens", dmic_tokens, ARRAY_SIZE(dmic_tokens)},
342 	[SOF_DMIC_PDM_TOKENS] = {"DMIC PDM tokens", dmic_pdm_tokens, ARRAY_SIZE(dmic_pdm_tokens)},
343 	[SOF_ESAI_TOKENS] = {"ESAI tokens", esai_tokens, ARRAY_SIZE(esai_tokens)},
344 	[SOF_SAI_TOKENS] = {"SAI tokens", sai_tokens, ARRAY_SIZE(sai_tokens)},
345 	[SOF_AFE_TOKENS] = {"AFE tokens", afe_tokens, ARRAY_SIZE(afe_tokens)},
346 	[SOF_ACPDMIC_TOKENS] = {"ACPDMIC tokens", acpdmic_tokens, ARRAY_SIZE(acpdmic_tokens)},
347 	[SOF_ACPI2S_TOKENS]   = {"ACPI2S tokens", acpi2s_tokens, ARRAY_SIZE(acpi2s_tokens)},
348 	[SOF_MICFIL_TOKENS] = {"MICFIL PDM tokens",
349 		micfil_pdm_tokens, ARRAY_SIZE(micfil_pdm_tokens)},
350 	[SOF_ACP_SDW_TOKENS]   = {"ACP_SDW tokens", acp_sdw_tokens, ARRAY_SIZE(acp_sdw_tokens)},
351 };
352 
353 /**
354  * sof_comp_alloc - allocate and initialize buffer for a new component
355  * @swidget: pointer to struct snd_sof_widget containing extended data
356  * @ipc_size: IPC payload size that will be updated depending on valid
357  *  extended data.
358  * @index: ID of the pipeline the component belongs to
359  *
360  * Return: The pointer to the new allocated component, NULL if failed.
361  */
362 static void *sof_comp_alloc(struct snd_sof_widget *swidget, size_t *ipc_size,
363 			    int index)
364 {
365 	struct sof_ipc_comp *comp;
366 	size_t total_size = *ipc_size;
367 	size_t ext_size = sizeof(swidget->uuid);
368 
369 	/* only non-zero UUID is valid */
370 	if (!guid_is_null(&swidget->uuid))
371 		total_size += ext_size;
372 
373 	comp = kzalloc(total_size, GFP_KERNEL);
374 	if (!comp)
375 		return NULL;
376 
377 	/* configure comp new IPC message */
378 	comp->hdr.size = total_size;
379 	comp->hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_COMP_NEW;
380 	comp->id = swidget->comp_id;
381 	comp->pipeline_id = index;
382 	comp->core = swidget->core;
383 
384 	/* handle the extended data if needed */
385 	if (total_size > *ipc_size) {
386 		/* append extended data to the end of the component */
387 		memcpy((u8 *)comp + *ipc_size, &swidget->uuid, ext_size);
388 		comp->ext_data_length = ext_size;
389 	}
390 
391 	/* update ipc_size and return */
392 	*ipc_size = total_size;
393 	return comp;
394 }
395 
396 static void sof_dbg_comp_config(struct snd_soc_component *scomp, struct sof_ipc_comp_config *config)
397 {
398 	dev_dbg(scomp->dev, " config: periods snk %d src %d fmt %d\n",
399 		config->periods_sink, config->periods_source,
400 		config->frame_fmt);
401 }
402 
403 static int sof_ipc3_widget_setup_comp_host(struct snd_sof_widget *swidget)
404 {
405 	struct snd_soc_component *scomp = swidget->scomp;
406 	struct sof_ipc_comp_host *host;
407 	size_t ipc_size = sizeof(*host);
408 	int ret;
409 
410 	host = sof_comp_alloc(swidget, &ipc_size, swidget->pipeline_id);
411 	if (!host)
412 		return -ENOMEM;
413 	swidget->private = host;
414 
415 	/* configure host comp IPC message */
416 	host->comp.type = SOF_COMP_HOST;
417 	host->config.hdr.size = sizeof(host->config);
418 
419 	if (swidget->id == snd_soc_dapm_aif_out)
420 		host->direction = SOF_IPC_STREAM_CAPTURE;
421 	else
422 		host->direction = SOF_IPC_STREAM_PLAYBACK;
423 
424 	/* parse one set of pcm_tokens */
425 	ret = sof_update_ipc_object(scomp, host, SOF_PCM_TOKENS, swidget->tuples,
426 				    swidget->num_tuples, sizeof(*host), 1);
427 	if (ret < 0)
428 		goto err;
429 
430 	/* parse one set of comp_tokens */
431 	ret = sof_update_ipc_object(scomp, &host->config, SOF_COMP_TOKENS, swidget->tuples,
432 				    swidget->num_tuples, sizeof(host->config), 1);
433 	if (ret < 0)
434 		goto err;
435 
436 	dev_dbg(scomp->dev, "loaded host %s\n", swidget->widget->name);
437 	sof_dbg_comp_config(scomp, &host->config);
438 
439 	return 0;
440 err:
441 	kfree(swidget->private);
442 	swidget->private = NULL;
443 
444 	return ret;
445 }
446 
447 static void sof_ipc3_widget_free_comp(struct snd_sof_widget *swidget)
448 {
449 	kfree(swidget->private);
450 }
451 
452 static int sof_ipc3_widget_setup_comp_tone(struct snd_sof_widget *swidget)
453 {
454 	struct snd_soc_component *scomp = swidget->scomp;
455 	struct sof_ipc_comp_tone *tone;
456 	size_t ipc_size = sizeof(*tone);
457 	int ret;
458 
459 	tone = sof_comp_alloc(swidget, &ipc_size, swidget->pipeline_id);
460 	if (!tone)
461 		return -ENOMEM;
462 
463 	swidget->private = tone;
464 
465 	/* configure siggen IPC message */
466 	tone->comp.type = SOF_COMP_TONE;
467 	tone->config.hdr.size = sizeof(tone->config);
468 
469 	/* parse one set of comp tokens */
470 	ret = sof_update_ipc_object(scomp, &tone->config, SOF_COMP_TOKENS, swidget->tuples,
471 				    swidget->num_tuples, sizeof(tone->config), 1);
472 	if (ret < 0) {
473 		kfree(swidget->private);
474 		swidget->private = NULL;
475 		return ret;
476 	}
477 
478 	dev_dbg(scomp->dev, "tone %s: frequency %d amplitude %d\n",
479 		swidget->widget->name, tone->frequency, tone->amplitude);
480 	sof_dbg_comp_config(scomp, &tone->config);
481 
482 	return 0;
483 }
484 
485 static int sof_ipc3_widget_setup_comp_mixer(struct snd_sof_widget *swidget)
486 {
487 	struct snd_soc_component *scomp = swidget->scomp;
488 	struct sof_ipc_comp_mixer *mixer;
489 	size_t ipc_size = sizeof(*mixer);
490 	int ret;
491 
492 	mixer = sof_comp_alloc(swidget, &ipc_size, swidget->pipeline_id);
493 	if (!mixer)
494 		return -ENOMEM;
495 
496 	swidget->private = mixer;
497 
498 	/* configure mixer IPC message */
499 	mixer->comp.type = SOF_COMP_MIXER;
500 	mixer->config.hdr.size = sizeof(mixer->config);
501 
502 	/* parse one set of comp tokens */
503 	ret = sof_update_ipc_object(scomp, &mixer->config, SOF_COMP_TOKENS,
504 				    swidget->tuples, swidget->num_tuples,
505 				    sizeof(mixer->config), 1);
506 	if (ret < 0) {
507 		kfree(swidget->private);
508 		swidget->private = NULL;
509 
510 		return ret;
511 	}
512 
513 	dev_dbg(scomp->dev, "loaded mixer %s\n", swidget->widget->name);
514 	sof_dbg_comp_config(scomp, &mixer->config);
515 
516 	return 0;
517 }
518 
519 static int sof_ipc3_widget_setup_comp_pipeline(struct snd_sof_widget *swidget)
520 {
521 	struct snd_soc_component *scomp = swidget->scomp;
522 	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
523 	struct snd_sof_pipeline *spipe = swidget->spipe;
524 	struct sof_ipc_pipe_new *pipeline;
525 	struct snd_sof_widget *comp_swidget;
526 	int ret;
527 
528 	pipeline = kzalloc_obj(*pipeline);
529 	if (!pipeline)
530 		return -ENOMEM;
531 
532 	/* configure pipeline IPC message */
533 	pipeline->hdr.size = sizeof(*pipeline);
534 	pipeline->hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_PIPE_NEW;
535 	pipeline->pipeline_id = swidget->pipeline_id;
536 	pipeline->comp_id = swidget->comp_id;
537 
538 	swidget->private = pipeline;
539 
540 	/* component at start of pipeline is our stream id */
541 	comp_swidget = snd_sof_find_swidget(scomp, swidget->widget->sname);
542 	if (!comp_swidget) {
543 		dev_err(scomp->dev, "scheduler %s refers to non existent widget %s\n",
544 			swidget->widget->name, swidget->widget->sname);
545 		ret = -EINVAL;
546 		goto err;
547 	}
548 
549 	pipeline->sched_id = comp_swidget->comp_id;
550 
551 	/* parse one set of scheduler tokens */
552 	ret = sof_update_ipc_object(scomp, pipeline, SOF_SCHED_TOKENS, swidget->tuples,
553 				    swidget->num_tuples, sizeof(*pipeline), 1);
554 	if (ret < 0)
555 		goto err;
556 
557 	/* parse one set of pipeline tokens */
558 	ret = sof_update_ipc_object(scomp, swidget, SOF_PIPELINE_TOKENS, swidget->tuples,
559 				    swidget->num_tuples, sizeof(*swidget), 1);
560 	if (ret < 0)
561 		goto err;
562 
563 	if (sof_debug_check_flag(SOF_DBG_DISABLE_MULTICORE)) {
564 		pipeline->core = SOF_DSP_PRIMARY_CORE;
565 	} else if (pipeline->core > sdev->num_cores - 1) {
566 		dev_info(scomp->dev,
567 			 "out of range core id for %s, moving it %d -> %d\n",
568 			 swidget->widget->name, pipeline->core,
569 			 SOF_DSP_PRIMARY_CORE);
570 		pipeline->core = SOF_DSP_PRIMARY_CORE;
571 	}
572 
573 	if (sof_debug_check_flag(SOF_DBG_DYNAMIC_PIPELINES_OVERRIDE))
574 		swidget->dynamic_pipeline_widget =
575 			sof_debug_check_flag(SOF_DBG_DYNAMIC_PIPELINES_ENABLE);
576 
577 	dev_dbg(scomp->dev, "pipeline %s: period %d pri %d mips %d core %d frames %d dynamic %d\n",
578 		swidget->widget->name, pipeline->period, pipeline->priority,
579 		pipeline->period_mips, pipeline->core, pipeline->frames_per_sched,
580 		swidget->dynamic_pipeline_widget);
581 
582 	swidget->core = pipeline->core;
583 	spipe->core_mask |= BIT(pipeline->core);
584 
585 	return 0;
586 
587 err:
588 	kfree(swidget->private);
589 	swidget->private = NULL;
590 
591 	return ret;
592 }
593 
594 static int sof_ipc3_widget_setup_comp_buffer(struct snd_sof_widget *swidget)
595 {
596 	struct snd_soc_component *scomp = swidget->scomp;
597 	struct sof_ipc_buffer *buffer;
598 	int ret;
599 
600 	buffer = kzalloc_obj(*buffer);
601 	if (!buffer)
602 		return -ENOMEM;
603 
604 	swidget->private = buffer;
605 
606 	/* configure dai IPC message */
607 	buffer->comp.hdr.size = sizeof(*buffer);
608 	buffer->comp.hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_BUFFER_NEW;
609 	buffer->comp.id = swidget->comp_id;
610 	buffer->comp.type = SOF_COMP_BUFFER;
611 	buffer->comp.pipeline_id = swidget->pipeline_id;
612 	buffer->comp.core = swidget->core;
613 
614 	/* parse one set of buffer tokens */
615 	ret = sof_update_ipc_object(scomp, buffer, SOF_BUFFER_TOKENS, swidget->tuples,
616 				    swidget->num_tuples, sizeof(*buffer), 1);
617 	if (ret < 0) {
618 		kfree(swidget->private);
619 		swidget->private = NULL;
620 		return ret;
621 	}
622 
623 	dev_dbg(scomp->dev, "buffer %s: size %d caps 0x%x\n",
624 		swidget->widget->name, buffer->size, buffer->caps);
625 
626 	return 0;
627 }
628 
629 static int sof_ipc3_widget_setup_comp_src(struct snd_sof_widget *swidget)
630 {
631 	struct snd_soc_component *scomp = swidget->scomp;
632 	struct sof_ipc_comp_src *src;
633 	size_t ipc_size = sizeof(*src);
634 	int ret;
635 
636 	src = sof_comp_alloc(swidget, &ipc_size, swidget->pipeline_id);
637 	if (!src)
638 		return -ENOMEM;
639 
640 	swidget->private = src;
641 
642 	/* configure src IPC message */
643 	src->comp.type = SOF_COMP_SRC;
644 	src->config.hdr.size = sizeof(src->config);
645 
646 	/* parse one set of src tokens */
647 	ret = sof_update_ipc_object(scomp, src, SOF_SRC_TOKENS, swidget->tuples,
648 				    swidget->num_tuples, sizeof(*src), 1);
649 	if (ret < 0)
650 		goto err;
651 
652 	/* parse one set of comp tokens */
653 	ret = sof_update_ipc_object(scomp, &src->config, SOF_COMP_TOKENS,
654 				    swidget->tuples, swidget->num_tuples, sizeof(src->config), 1);
655 	if (ret < 0)
656 		goto err;
657 
658 	dev_dbg(scomp->dev, "src %s: source rate %d sink rate %d\n",
659 		swidget->widget->name, src->source_rate, src->sink_rate);
660 	sof_dbg_comp_config(scomp, &src->config);
661 
662 	return 0;
663 err:
664 	kfree(swidget->private);
665 	swidget->private = NULL;
666 
667 	return ret;
668 }
669 
670 static int sof_ipc3_widget_setup_comp_asrc(struct snd_sof_widget *swidget)
671 {
672 	struct snd_soc_component *scomp = swidget->scomp;
673 	struct sof_ipc_comp_asrc *asrc;
674 	size_t ipc_size = sizeof(*asrc);
675 	int ret;
676 
677 	asrc = sof_comp_alloc(swidget, &ipc_size, swidget->pipeline_id);
678 	if (!asrc)
679 		return -ENOMEM;
680 
681 	swidget->private = asrc;
682 
683 	/* configure ASRC IPC message */
684 	asrc->comp.type = SOF_COMP_ASRC;
685 	asrc->config.hdr.size = sizeof(asrc->config);
686 
687 	/* parse one set of asrc tokens */
688 	ret = sof_update_ipc_object(scomp, asrc, SOF_ASRC_TOKENS, swidget->tuples,
689 				    swidget->num_tuples, sizeof(*asrc), 1);
690 	if (ret < 0)
691 		goto err;
692 
693 	/* parse one set of comp tokens */
694 	ret = sof_update_ipc_object(scomp, &asrc->config, SOF_COMP_TOKENS,
695 				    swidget->tuples, swidget->num_tuples, sizeof(asrc->config), 1);
696 	if (ret < 0)
697 		goto err;
698 
699 	dev_dbg(scomp->dev, "asrc %s: source rate %d sink rate %d asynch %d operation %d\n",
700 		swidget->widget->name, asrc->source_rate, asrc->sink_rate,
701 		asrc->asynchronous_mode, asrc->operation_mode);
702 
703 	sof_dbg_comp_config(scomp, &asrc->config);
704 
705 	return 0;
706 err:
707 	kfree(swidget->private);
708 	swidget->private = NULL;
709 
710 	return ret;
711 }
712 
713 /*
714  * Mux topology
715  */
716 static int sof_ipc3_widget_setup_comp_mux(struct snd_sof_widget *swidget)
717 {
718 	struct snd_soc_component *scomp = swidget->scomp;
719 	struct sof_ipc_comp_mux *mux;
720 	size_t ipc_size = sizeof(*mux);
721 	int ret;
722 
723 	mux = sof_comp_alloc(swidget, &ipc_size, swidget->pipeline_id);
724 	if (!mux)
725 		return -ENOMEM;
726 
727 	swidget->private = mux;
728 
729 	/* configure mux IPC message */
730 	mux->comp.type = SOF_COMP_MUX;
731 	mux->config.hdr.size = sizeof(mux->config);
732 
733 	/* parse one set of comp tokens */
734 	ret = sof_update_ipc_object(scomp, &mux->config, SOF_COMP_TOKENS,
735 				    swidget->tuples, swidget->num_tuples, sizeof(mux->config), 1);
736 	if (ret < 0) {
737 		kfree(swidget->private);
738 		swidget->private = NULL;
739 		return ret;
740 	}
741 
742 	dev_dbg(scomp->dev, "loaded mux %s\n", swidget->widget->name);
743 	sof_dbg_comp_config(scomp, &mux->config);
744 
745 	return 0;
746 }
747 
748 /*
749  * PGA Topology
750  */
751 
752 static int sof_ipc3_widget_setup_comp_pga(struct snd_sof_widget *swidget)
753 {
754 	struct snd_soc_component *scomp = swidget->scomp;
755 	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
756 	struct sof_ipc_comp_volume *volume;
757 	struct snd_sof_control *scontrol;
758 	size_t ipc_size = sizeof(*volume);
759 	int min_step, max_step;
760 	int ret;
761 
762 	volume = sof_comp_alloc(swidget, &ipc_size, swidget->pipeline_id);
763 	if (!volume)
764 		return -ENOMEM;
765 
766 	swidget->private = volume;
767 
768 	/* configure volume IPC message */
769 	volume->comp.type = SOF_COMP_VOLUME;
770 	volume->config.hdr.size = sizeof(volume->config);
771 
772 	/* parse one set of volume tokens */
773 	ret = sof_update_ipc_object(scomp, volume, SOF_VOLUME_TOKENS, swidget->tuples,
774 				    swidget->num_tuples, sizeof(*volume), 1);
775 	if (ret < 0)
776 		goto err;
777 
778 	/* parse one set of comp tokens */
779 	ret = sof_update_ipc_object(scomp, &volume->config, SOF_COMP_TOKENS,
780 				    swidget->tuples, swidget->num_tuples,
781 				    sizeof(volume->config), 1);
782 	if (ret < 0)
783 		goto err;
784 
785 	dev_dbg(scomp->dev, "loaded PGA %s\n", swidget->widget->name);
786 	sof_dbg_comp_config(scomp, &volume->config);
787 
788 	list_for_each_entry(scontrol, &sdev->kcontrol_list, list) {
789 		if (scontrol->comp_id == swidget->comp_id &&
790 		    scontrol->volume_table) {
791 			min_step = scontrol->min_volume_step;
792 			max_step = scontrol->max_volume_step;
793 			volume->min_value = scontrol->volume_table[min_step];
794 			volume->max_value = scontrol->volume_table[max_step];
795 			volume->channels = scontrol->num_channels;
796 			break;
797 		}
798 	}
799 
800 	return 0;
801 err:
802 	kfree(swidget->private);
803 	swidget->private = NULL;
804 
805 	return ret;
806 }
807 
808 static int sof_get_control_data(struct snd_soc_component *scomp,
809 				struct snd_soc_dapm_widget *widget,
810 				struct sof_widget_data *wdata, size_t *size)
811 {
812 	const struct snd_kcontrol_new *kc;
813 	struct sof_ipc_ctrl_data *cdata;
814 	struct soc_mixer_control *sm;
815 	struct soc_bytes_ext *sbe;
816 	struct soc_enum *se;
817 	int i;
818 
819 	*size = 0;
820 
821 	for (i = 0; i < widget->num_kcontrols; i++) {
822 		kc = &widget->kcontrol_news[i];
823 
824 		switch (widget->dobj.widget.kcontrol_type[i]) {
825 		case SND_SOC_TPLG_TYPE_MIXER:
826 			sm = (struct soc_mixer_control *)kc->private_value;
827 			wdata[i].control = sm->dobj.private;
828 			break;
829 		case SND_SOC_TPLG_TYPE_BYTES:
830 			sbe = (struct soc_bytes_ext *)kc->private_value;
831 			wdata[i].control = sbe->dobj.private;
832 			break;
833 		case SND_SOC_TPLG_TYPE_ENUM:
834 			se = (struct soc_enum *)kc->private_value;
835 			wdata[i].control = se->dobj.private;
836 			break;
837 		default:
838 			dev_err(scomp->dev, "Unknown kcontrol type %u in widget %s\n",
839 				widget->dobj.widget.kcontrol_type[i], widget->name);
840 			return -EINVAL;
841 		}
842 
843 		if (!wdata[i].control) {
844 			dev_err(scomp->dev, "No scontrol for widget %s\n", widget->name);
845 			return -EINVAL;
846 		}
847 
848 		cdata = wdata[i].control->ipc_control_data;
849 
850 		if (widget->dobj.widget.kcontrol_type[i] == SND_SOC_TPLG_TYPE_BYTES) {
851 			/* make sure data is valid - data can be updated at runtime */
852 			if (cdata->data->magic != SOF_ABI_MAGIC)
853 				return -EINVAL;
854 
855 			wdata[i].pdata = cdata->data->data;
856 			wdata[i].pdata_size = cdata->data->size;
857 		} else {
858 			/* points to the control data union */
859 			wdata[i].pdata = cdata->chanv;
860 			/*
861 			 * wdata[i].control->size is calculated with struct_size
862 			 * and includes the size of struct sof_ipc_ctrl_data
863 			 */
864 			wdata[i].pdata_size = wdata[i].control->size -
865 					      sizeof(struct sof_ipc_ctrl_data);
866 		}
867 
868 		*size += wdata[i].pdata_size;
869 
870 		/* get data type */
871 		switch (cdata->cmd) {
872 		case SOF_CTRL_CMD_VOLUME:
873 		case SOF_CTRL_CMD_ENUM:
874 		case SOF_CTRL_CMD_SWITCH:
875 			wdata[i].ipc_cmd = SOF_IPC_COMP_SET_VALUE;
876 			wdata[i].ctrl_type = SOF_CTRL_TYPE_VALUE_CHAN_SET;
877 			break;
878 		case SOF_CTRL_CMD_BINARY:
879 			wdata[i].ipc_cmd = SOF_IPC_COMP_SET_DATA;
880 			wdata[i].ctrl_type = SOF_CTRL_TYPE_DATA_SET;
881 			break;
882 		default:
883 			break;
884 		}
885 	}
886 
887 	return 0;
888 }
889 
890 static int sof_process_load(struct snd_soc_component *scomp,
891 			    struct snd_sof_widget *swidget, int type)
892 {
893 	struct snd_soc_dapm_widget *widget = swidget->widget;
894 	struct sof_ipc_comp_process *process;
895 	struct sof_widget_data *wdata = NULL;
896 	size_t ipc_data_size = 0;
897 	size_t ipc_size;
898 	int offset = 0;
899 	int ret;
900 	int i;
901 
902 	/* allocate struct for widget control data sizes and types */
903 	if (widget->num_kcontrols) {
904 		wdata = kzalloc_objs(*wdata, widget->num_kcontrols);
905 		if (!wdata)
906 			return -ENOMEM;
907 
908 		/* get possible component controls and get size of all pdata */
909 		ret = sof_get_control_data(scomp, widget, wdata, &ipc_data_size);
910 		if (ret < 0)
911 			goto out;
912 	}
913 
914 	ipc_size = sizeof(struct sof_ipc_comp_process) + ipc_data_size;
915 
916 	/* we are exceeding max ipc size, config needs to be sent separately */
917 	if (ipc_size > SOF_IPC_MSG_MAX_SIZE) {
918 		ipc_size -= ipc_data_size;
919 		ipc_data_size = 0;
920 	}
921 
922 	process = sof_comp_alloc(swidget, &ipc_size, swidget->pipeline_id);
923 	if (!process) {
924 		ret = -ENOMEM;
925 		goto out;
926 	}
927 
928 	swidget->private = process;
929 
930 	/* configure iir IPC message */
931 	process->comp.type = type;
932 	process->config.hdr.size = sizeof(process->config);
933 
934 	/* parse one set of comp tokens */
935 	ret = sof_update_ipc_object(scomp, &process->config, SOF_COMP_TOKENS,
936 				    swidget->tuples, swidget->num_tuples,
937 				    sizeof(process->config), 1);
938 	if (ret < 0)
939 		goto err;
940 
941 	dev_dbg(scomp->dev, "loaded process %s\n", swidget->widget->name);
942 	sof_dbg_comp_config(scomp, &process->config);
943 
944 	/*
945 	 * found private data in control, so copy it.
946 	 * get possible component controls - get size of all pdata,
947 	 * then memcpy with headers
948 	 */
949 	if (ipc_data_size) {
950 		for (i = 0; i < widget->num_kcontrols; i++) {
951 			if (!wdata[i].pdata_size)
952 				continue;
953 
954 			memcpy(&process->data[offset], wdata[i].pdata,
955 			       wdata[i].pdata_size);
956 			offset += wdata[i].pdata_size;
957 		}
958 	}
959 
960 	process->size = ipc_data_size;
961 
962 	kfree(wdata);
963 
964 	return 0;
965 err:
966 	kfree(swidget->private);
967 	swidget->private = NULL;
968 out:
969 	kfree(wdata);
970 	return ret;
971 }
972 
973 static enum sof_comp_type find_process_comp_type(enum sof_ipc_process_type type)
974 {
975 	int i;
976 
977 	for (i = 0; i < ARRAY_SIZE(sof_process); i++) {
978 		if (sof_process[i].type == type)
979 			return sof_process[i].comp_type;
980 	}
981 
982 	return SOF_COMP_NONE;
983 }
984 
985 /*
986  * Processing Component Topology - can be "effect", "codec", or general
987  * "processing".
988  */
989 
990 static int sof_widget_update_ipc_comp_process(struct snd_sof_widget *swidget)
991 {
992 	struct snd_soc_component *scomp = swidget->scomp;
993 	struct sof_ipc_comp_process config;
994 	int ret;
995 
996 	memset(&config, 0, sizeof(config));
997 	config.comp.core = swidget->core;
998 
999 	/* parse one set of process tokens */
1000 	ret = sof_update_ipc_object(scomp, &config, SOF_PROCESS_TOKENS, swidget->tuples,
1001 				    swidget->num_tuples, sizeof(config), 1);
1002 	if (ret < 0)
1003 		return ret;
1004 
1005 	/* now load process specific data and send IPC */
1006 	return sof_process_load(scomp, swidget, find_process_comp_type(config.type));
1007 }
1008 
1009 static int sof_link_hda_load(struct snd_soc_component *scomp, struct snd_sof_dai_link *slink,
1010 			     struct sof_ipc_dai_config *config, struct snd_sof_dai *dai)
1011 {
1012 	struct sof_dai_private_data *private = dai->private;
1013 	u32 size = sizeof(*config);
1014 	int ret;
1015 
1016 	/* init IPC */
1017 	memset(&config->hda, 0, sizeof(config->hda));
1018 	config->hdr.size = size;
1019 
1020 	/* parse one set of HDA tokens */
1021 	ret = sof_update_ipc_object(scomp, &config->hda, SOF_HDA_TOKENS, slink->tuples,
1022 				    slink->num_tuples, size, 1);
1023 	if (ret < 0)
1024 		return ret;
1025 
1026 	dev_dbg(scomp->dev, "HDA config rate %d channels %d\n",
1027 		config->hda.rate, config->hda.channels);
1028 
1029 	config->hda.link_dma_ch = DMA_CHAN_INVALID;
1030 
1031 	dai->number_configs = 1;
1032 	dai->current_config = 0;
1033 	private->dai_config = kmemdup(config, size, GFP_KERNEL);
1034 	if (!private->dai_config)
1035 		return -ENOMEM;
1036 
1037 	return 0;
1038 }
1039 
1040 static void sof_dai_set_format(struct snd_soc_tplg_hw_config *hw_config,
1041 			       struct sof_ipc_dai_config *config)
1042 {
1043 	/* clock directions wrt codec */
1044 	config->format &= ~SOF_DAI_FMT_CLOCK_PROVIDER_MASK;
1045 	if (hw_config->bclk_provider == SND_SOC_TPLG_BCLK_CP) {
1046 		/* codec is bclk provider */
1047 		if (hw_config->fsync_provider == SND_SOC_TPLG_FSYNC_CP)
1048 			config->format |= SOF_DAI_FMT_CBP_CFP;
1049 		else
1050 			config->format |= SOF_DAI_FMT_CBP_CFC;
1051 	} else {
1052 		/* codec is bclk consumer */
1053 		if (hw_config->fsync_provider == SND_SOC_TPLG_FSYNC_CP)
1054 			config->format |= SOF_DAI_FMT_CBC_CFP;
1055 		else
1056 			config->format |= SOF_DAI_FMT_CBC_CFC;
1057 	}
1058 
1059 	/* inverted clocks ? */
1060 	config->format &= ~SOF_DAI_FMT_INV_MASK;
1061 	if (hw_config->invert_bclk) {
1062 		if (hw_config->invert_fsync)
1063 			config->format |= SOF_DAI_FMT_IB_IF;
1064 		else
1065 			config->format |= SOF_DAI_FMT_IB_NF;
1066 	} else {
1067 		if (hw_config->invert_fsync)
1068 			config->format |= SOF_DAI_FMT_NB_IF;
1069 		else
1070 			config->format |= SOF_DAI_FMT_NB_NF;
1071 	}
1072 }
1073 
1074 static int sof_link_sai_load(struct snd_soc_component *scomp, struct snd_sof_dai_link *slink,
1075 			     struct sof_ipc_dai_config *config, struct snd_sof_dai *dai)
1076 {
1077 	struct snd_soc_tplg_hw_config *hw_config = slink->hw_configs;
1078 	struct sof_dai_private_data *private = dai->private;
1079 	u32 size = sizeof(*config);
1080 	int ret;
1081 
1082 	/* handle master/slave and inverted clocks */
1083 	sof_dai_set_format(hw_config, config);
1084 
1085 	/* init IPC */
1086 	memset(&config->sai, 0, sizeof(config->sai));
1087 	config->hdr.size = size;
1088 
1089 	/* parse one set of SAI tokens */
1090 	ret = sof_update_ipc_object(scomp, &config->sai, SOF_SAI_TOKENS, slink->tuples,
1091 				    slink->num_tuples, size, 1);
1092 	if (ret < 0)
1093 		return ret;
1094 
1095 	config->sai.mclk_rate = le32_to_cpu(hw_config->mclk_rate);
1096 	config->sai.bclk_rate = le32_to_cpu(hw_config->bclk_rate);
1097 	config->sai.fsync_rate = le32_to_cpu(hw_config->fsync_rate);
1098 	config->sai.mclk_direction = hw_config->mclk_direction;
1099 
1100 	config->sai.tdm_slots = le32_to_cpu(hw_config->tdm_slots);
1101 	config->sai.tdm_slot_width = le32_to_cpu(hw_config->tdm_slot_width);
1102 	config->sai.rx_slots = le32_to_cpu(hw_config->rx_slots);
1103 	config->sai.tx_slots = le32_to_cpu(hw_config->tx_slots);
1104 
1105 	dev_info(scomp->dev,
1106 		 "tplg: config SAI%d fmt 0x%x mclk %d width %d slots %d mclk id %d\n",
1107 		config->dai_index, config->format,
1108 		config->sai.mclk_rate, config->sai.tdm_slot_width,
1109 		config->sai.tdm_slots, config->sai.mclk_id);
1110 
1111 	if (config->sai.tdm_slots < 1 || config->sai.tdm_slots > 8) {
1112 		dev_err(scomp->dev, "Invalid channel count for SAI%d\n", config->dai_index);
1113 		return -EINVAL;
1114 	}
1115 
1116 	dai->number_configs = 1;
1117 	dai->current_config = 0;
1118 	private->dai_config = kmemdup(config, size, GFP_KERNEL);
1119 	if (!private->dai_config)
1120 		return -ENOMEM;
1121 
1122 	return 0;
1123 }
1124 
1125 static int sof_link_esai_load(struct snd_soc_component *scomp, struct snd_sof_dai_link *slink,
1126 			      struct sof_ipc_dai_config *config, struct snd_sof_dai *dai)
1127 {
1128 	struct snd_soc_tplg_hw_config *hw_config = slink->hw_configs;
1129 	struct sof_dai_private_data *private = dai->private;
1130 	u32 size = sizeof(*config);
1131 	int ret;
1132 
1133 	/* handle master/slave and inverted clocks */
1134 	sof_dai_set_format(hw_config, config);
1135 
1136 	/* init IPC */
1137 	memset(&config->esai, 0, sizeof(config->esai));
1138 	config->hdr.size = size;
1139 
1140 	/* parse one set of ESAI tokens */
1141 	ret = sof_update_ipc_object(scomp, &config->esai, SOF_ESAI_TOKENS, slink->tuples,
1142 				    slink->num_tuples, size, 1);
1143 	if (ret < 0)
1144 		return ret;
1145 
1146 	config->esai.mclk_rate = le32_to_cpu(hw_config->mclk_rate);
1147 	config->esai.bclk_rate = le32_to_cpu(hw_config->bclk_rate);
1148 	config->esai.fsync_rate = le32_to_cpu(hw_config->fsync_rate);
1149 	config->esai.mclk_direction = hw_config->mclk_direction;
1150 	config->esai.tdm_slots = le32_to_cpu(hw_config->tdm_slots);
1151 	config->esai.tdm_slot_width = le32_to_cpu(hw_config->tdm_slot_width);
1152 	config->esai.rx_slots = le32_to_cpu(hw_config->rx_slots);
1153 	config->esai.tx_slots = le32_to_cpu(hw_config->tx_slots);
1154 
1155 	dev_info(scomp->dev,
1156 		 "tplg: config ESAI%d fmt 0x%x mclk %d width %d slots %d mclk id %d\n",
1157 		config->dai_index, config->format,
1158 		config->esai.mclk_rate, config->esai.tdm_slot_width,
1159 		config->esai.tdm_slots, config->esai.mclk_id);
1160 
1161 	if (config->esai.tdm_slots < 1 || config->esai.tdm_slots > 8) {
1162 		dev_err(scomp->dev, "Invalid channel count for ESAI%d\n", config->dai_index);
1163 		return -EINVAL;
1164 	}
1165 
1166 	dai->number_configs = 1;
1167 	dai->current_config = 0;
1168 	private->dai_config = kmemdup(config, size, GFP_KERNEL);
1169 	if (!private->dai_config)
1170 		return -ENOMEM;
1171 
1172 	return 0;
1173 }
1174 
1175 static int sof_link_micfil_load(struct snd_soc_component *scomp, struct snd_sof_dai_link *slink,
1176 				struct sof_ipc_dai_config *config, struct snd_sof_dai *dai)
1177 {
1178 	struct snd_soc_tplg_hw_config *hw_config = slink->hw_configs;
1179 	struct sof_dai_private_data *private = dai->private;
1180 	u32 size = sizeof(*config);
1181 	int ret;
1182 
1183        /* handle master/slave and inverted clocks */
1184 	sof_dai_set_format(hw_config, config);
1185 
1186 	config->hdr.size = size;
1187 
1188 	/* parse the required set of MICFIL PDM tokens based on num_hw_cfgs */
1189 	ret = sof_update_ipc_object(scomp, &config->micfil, SOF_MICFIL_TOKENS, slink->tuples,
1190 				    slink->num_tuples, size, slink->num_hw_configs);
1191 	if (ret < 0)
1192 		return ret;
1193 
1194 	dev_info(scomp->dev, "MICFIL PDM config dai_index %d channel %d rate %d\n",
1195 		 config->dai_index, config->micfil.pdm_ch, config->micfil.pdm_rate);
1196 
1197 	dai->number_configs = 1;
1198 	dai->current_config = 0;
1199 	private->dai_config = kmemdup(config, size, GFP_KERNEL);
1200 	if (!private->dai_config)
1201 		return -ENOMEM;
1202 
1203 	return 0;
1204 }
1205 
1206 static int sof_link_acp_dmic_load(struct snd_soc_component *scomp, struct snd_sof_dai_link *slink,
1207 				  struct sof_ipc_dai_config *config, struct snd_sof_dai *dai)
1208 {
1209 	struct snd_soc_tplg_hw_config *hw_config = slink->hw_configs;
1210 	struct sof_dai_private_data *private = dai->private;
1211 	u32 size = sizeof(*config);
1212 	int ret;
1213 
1214        /* handle master/slave and inverted clocks */
1215 	sof_dai_set_format(hw_config, config);
1216 
1217 	config->hdr.size = size;
1218 
1219 	/* parse the required set of ACPDMIC tokens based on num_hw_cfgs */
1220 	ret = sof_update_ipc_object(scomp, &config->acpdmic, SOF_ACPDMIC_TOKENS, slink->tuples,
1221 				    slink->num_tuples, size, slink->num_hw_configs);
1222 	if (ret < 0)
1223 		return ret;
1224 
1225 	dev_info(scomp->dev, "ACP_DMIC config ACP%d channel %d rate %d\n",
1226 		 config->dai_index, config->acpdmic.pdm_ch,
1227 		 config->acpdmic.pdm_rate);
1228 
1229 	dai->number_configs = 1;
1230 	dai->current_config = 0;
1231 	private->dai_config = kmemdup(config, size, GFP_KERNEL);
1232 	if (!private->dai_config)
1233 		return -ENOMEM;
1234 
1235 	return 0;
1236 }
1237 
1238 static int sof_link_acp_bt_load(struct snd_soc_component *scomp, struct snd_sof_dai_link *slink,
1239 				struct sof_ipc_dai_config *config, struct snd_sof_dai *dai)
1240 {
1241 	struct snd_soc_tplg_hw_config *hw_config = slink->hw_configs;
1242 	struct sof_dai_private_data *private = dai->private;
1243 	u32 size = sizeof(*config);
1244 	int ret;
1245 
1246 	/* handle master/slave and inverted clocks */
1247 	sof_dai_set_format(hw_config, config);
1248 
1249 	/* init IPC */
1250 	memset(&config->acpbt, 0, sizeof(config->acpbt));
1251 	config->hdr.size = size;
1252 
1253 	ret = sof_update_ipc_object(scomp, &config->acpbt, SOF_ACPI2S_TOKENS, slink->tuples,
1254 				    slink->num_tuples, size, slink->num_hw_configs);
1255 	if (ret < 0)
1256 		return ret;
1257 
1258 	dev_info(scomp->dev, "ACP_BT config ACP%d channel %d rate %d tdm_mode %d\n",
1259 		 config->dai_index, config->acpbt.tdm_slots,
1260 		 config->acpbt.fsync_rate, config->acpbt.tdm_mode);
1261 
1262 	dai->number_configs = 1;
1263 	dai->current_config = 0;
1264 	private->dai_config = kmemdup(config, size, GFP_KERNEL);
1265 	if (!private->dai_config)
1266 		return -ENOMEM;
1267 
1268 	return 0;
1269 }
1270 
1271 static int sof_link_acp_sp_load(struct snd_soc_component *scomp, struct snd_sof_dai_link *slink,
1272 				struct sof_ipc_dai_config *config, struct snd_sof_dai *dai)
1273 {
1274 	struct snd_soc_tplg_hw_config *hw_config = slink->hw_configs;
1275 	struct sof_dai_private_data *private = dai->private;
1276 	u32 size = sizeof(*config);
1277 	int ret;
1278 
1279 	/* handle master/slave and inverted clocks */
1280 	sof_dai_set_format(hw_config, config);
1281 
1282 	/* init IPC */
1283 	memset(&config->acpsp, 0, sizeof(config->acpsp));
1284 	config->hdr.size = size;
1285 
1286 	ret = sof_update_ipc_object(scomp, &config->acpsp, SOF_ACPI2S_TOKENS, slink->tuples,
1287 				    slink->num_tuples, size, slink->num_hw_configs);
1288 	if (ret < 0)
1289 		return ret;
1290 
1291 
1292 	dev_info(scomp->dev, "ACP_SP config ACP%d channel %d rate %d tdm_mode %d\n",
1293 		 config->dai_index, config->acpsp.tdm_slots,
1294 		 config->acpsp.fsync_rate, config->acpsp.tdm_mode);
1295 
1296 	dai->number_configs = 1;
1297 	dai->current_config = 0;
1298 	private->dai_config = kmemdup(config, size, GFP_KERNEL);
1299 	if (!private->dai_config)
1300 		return -ENOMEM;
1301 
1302 	return 0;
1303 }
1304 
1305 static int sof_link_acp_hs_load(struct snd_soc_component *scomp, struct snd_sof_dai_link *slink,
1306 				struct sof_ipc_dai_config *config, struct snd_sof_dai *dai)
1307 {
1308 	struct snd_soc_tplg_hw_config *hw_config = slink->hw_configs;
1309 	struct sof_dai_private_data *private = dai->private;
1310 	u32 size = sizeof(*config);
1311 	int ret;
1312 
1313 	/* Configures the DAI hardware format and inverted clocks */
1314 	sof_dai_set_format(hw_config, config);
1315 
1316 	/* init IPC */
1317 	memset(&config->acphs, 0, sizeof(config->acphs));
1318 	config->hdr.size = size;
1319 
1320 	ret = sof_update_ipc_object(scomp, &config->acphs, SOF_ACPI2S_TOKENS, slink->tuples,
1321 				    slink->num_tuples, size, slink->num_hw_configs);
1322 	if (ret < 0)
1323 		return ret;
1324 
1325 	dev_info(scomp->dev, "ACP_HS config ACP%d channel %d rate %d tdm_mode %d\n",
1326 		 config->dai_index, config->acphs.tdm_slots,
1327 		 config->acphs.fsync_rate, config->acphs.tdm_mode);
1328 
1329 	dai->number_configs = 1;
1330 	dai->current_config = 0;
1331 	private->dai_config = kmemdup(config, size, GFP_KERNEL);
1332 	if (!private->dai_config)
1333 		return -ENOMEM;
1334 
1335 	return 0;
1336 }
1337 
1338 static int sof_link_acp_sdw_load(struct snd_soc_component *scomp, struct snd_sof_dai_link *slink,
1339 				 struct sof_ipc_dai_config *config, struct snd_sof_dai *dai)
1340 {
1341 	struct sof_dai_private_data *private = dai->private;
1342 	u32 size = sizeof(*config);
1343 	int ret;
1344 
1345 	/* parse the required set of ACP_SDW tokens based on num_hw_cfgs */
1346 	ret = sof_update_ipc_object(scomp, &config->acp_sdw, SOF_ACP_SDW_TOKENS, slink->tuples,
1347 				    slink->num_tuples, size, slink->num_hw_configs);
1348 	if (ret < 0)
1349 		return ret;
1350 
1351 	/* init IPC */
1352 	config->hdr.size = size;
1353 	dev_dbg(scomp->dev, "ACP SDW config rate %d channels %d\n",
1354 		config->acp_sdw.rate, config->acp_sdw.channels);
1355 
1356 	/* set config for all DAI's with name matching the link name */
1357 	dai->number_configs = 1;
1358 	dai->current_config = 0;
1359 	private->dai_config = kmemdup(config, size, GFP_KERNEL);
1360 	if (!private->dai_config)
1361 		return -ENOMEM;
1362 
1363 	return 0;
1364 }
1365 
1366 static int sof_link_afe_load(struct snd_soc_component *scomp, struct snd_sof_dai_link *slink,
1367 			     struct sof_ipc_dai_config *config, struct snd_sof_dai *dai)
1368 {
1369 	struct sof_dai_private_data *private = dai->private;
1370 	u32 size = sizeof(*config);
1371 	int ret;
1372 
1373 	config->hdr.size = size;
1374 
1375 	/* parse the required set of AFE tokens based on num_hw_cfgs */
1376 	ret = sof_update_ipc_object(scomp, &config->afe, SOF_AFE_TOKENS, slink->tuples,
1377 				    slink->num_tuples, size, slink->num_hw_configs);
1378 	if (ret < 0)
1379 		return ret;
1380 
1381 	dev_dbg(scomp->dev, "AFE config rate %d channels %d format:%d\n",
1382 		config->afe.rate, config->afe.channels, config->afe.format);
1383 
1384 	config->afe.stream_id = DMA_CHAN_INVALID;
1385 
1386 	dai->number_configs = 1;
1387 	dai->current_config = 0;
1388 	private->dai_config = kmemdup(config, size, GFP_KERNEL);
1389 	if (!private->dai_config)
1390 		return -ENOMEM;
1391 
1392 	return 0;
1393 }
1394 
1395 static int sof_link_ssp_load(struct snd_soc_component *scomp, struct snd_sof_dai_link *slink,
1396 			     struct sof_ipc_dai_config *config, struct snd_sof_dai *dai)
1397 {
1398 	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
1399 	struct snd_soc_tplg_hw_config *hw_config = slink->hw_configs;
1400 	struct sof_dai_private_data *private = dai->private;
1401 	u32 size = sizeof(*config);
1402 	int current_config = 0;
1403 	int i, ret;
1404 
1405 	/*
1406 	 * Parse common data, we should have 1 common data per hw_config.
1407 	 */
1408 	ret = sof_update_ipc_object(scomp, &config->ssp, SOF_SSP_TOKENS, slink->tuples,
1409 				    slink->num_tuples, size, slink->num_hw_configs);
1410 	if (ret < 0)
1411 		return ret;
1412 
1413 	/* process all possible hw configs */
1414 	for (i = 0; i < slink->num_hw_configs; i++) {
1415 		if (le32_to_cpu(hw_config[i].id) == slink->default_hw_cfg_id)
1416 			current_config = i;
1417 
1418 		/* handle master/slave and inverted clocks */
1419 		sof_dai_set_format(&hw_config[i], &config[i]);
1420 
1421 		config[i].hdr.size = size;
1422 
1423 		if (sdev->mclk_id_override) {
1424 			dev_dbg(scomp->dev, "tplg: overriding topology mclk_id %d by quirk %d\n",
1425 				config[i].ssp.mclk_id, sdev->mclk_id_quirk);
1426 			config[i].ssp.mclk_id = sdev->mclk_id_quirk;
1427 		}
1428 
1429 		/* copy differentiating hw configs to ipc structs */
1430 		config[i].ssp.mclk_rate = le32_to_cpu(hw_config[i].mclk_rate);
1431 		config[i].ssp.bclk_rate = le32_to_cpu(hw_config[i].bclk_rate);
1432 		config[i].ssp.fsync_rate = le32_to_cpu(hw_config[i].fsync_rate);
1433 		config[i].ssp.tdm_slots = le32_to_cpu(hw_config[i].tdm_slots);
1434 		config[i].ssp.tdm_slot_width = le32_to_cpu(hw_config[i].tdm_slot_width);
1435 		config[i].ssp.mclk_direction = hw_config[i].mclk_direction;
1436 		config[i].ssp.rx_slots = le32_to_cpu(hw_config[i].rx_slots);
1437 		config[i].ssp.tx_slots = le32_to_cpu(hw_config[i].tx_slots);
1438 
1439 		dev_dbg(scomp->dev, "tplg: config SSP%d fmt %#x mclk %d bclk %d fclk %d width (%d)%d slots %d mclk id %d quirks %d clks_control %#x\n",
1440 			config[i].dai_index, config[i].format,
1441 			config[i].ssp.mclk_rate, config[i].ssp.bclk_rate,
1442 			config[i].ssp.fsync_rate, config[i].ssp.sample_valid_bits,
1443 			config[i].ssp.tdm_slot_width, config[i].ssp.tdm_slots,
1444 			config[i].ssp.mclk_id, config[i].ssp.quirks, config[i].ssp.clks_control);
1445 
1446 		/* validate SSP fsync rate and channel count */
1447 		if (config[i].ssp.fsync_rate < 8000 || config[i].ssp.fsync_rate > 192000) {
1448 			dev_err(scomp->dev, "Invalid fsync rate for SSP%d\n", config[i].dai_index);
1449 			return -EINVAL;
1450 		}
1451 
1452 		if (config[i].ssp.tdm_slots < 1 || config[i].ssp.tdm_slots > 8) {
1453 			dev_err(scomp->dev, "Invalid channel count for SSP%d\n",
1454 				config[i].dai_index);
1455 			return -EINVAL;
1456 		}
1457 	}
1458 
1459 	dai->number_configs = slink->num_hw_configs;
1460 	dai->current_config = current_config;
1461 	private->dai_config = kmemdup(config, size * slink->num_hw_configs, GFP_KERNEL);
1462 	if (!private->dai_config)
1463 		return -ENOMEM;
1464 
1465 	return 0;
1466 }
1467 
1468 static int sof_link_dmic_load(struct snd_soc_component *scomp, struct snd_sof_dai_link *slink,
1469 			      struct sof_ipc_dai_config *config, struct snd_sof_dai *dai)
1470 {
1471 	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
1472 	struct sof_dai_private_data *private = dai->private;
1473 	struct sof_ipc_fw_ready *ready = &sdev->fw_ready;
1474 	struct sof_ipc_fw_version *v = &ready->version;
1475 	size_t size = sizeof(*config);
1476 	int i, ret;
1477 
1478 	/* Ensure the entire DMIC config struct is zeros */
1479 	memset(&config->dmic, 0, sizeof(config->dmic));
1480 
1481 	/* parse the required set of DMIC tokens based on num_hw_cfgs */
1482 	ret = sof_update_ipc_object(scomp, &config->dmic, SOF_DMIC_TOKENS, slink->tuples,
1483 				    slink->num_tuples, size, slink->num_hw_configs);
1484 	if (ret < 0)
1485 		return ret;
1486 
1487 	/* parse the required set of DMIC PDM tokens based on number of active PDM's */
1488 	ret = sof_update_ipc_object(scomp, &config->dmic.pdm[0], SOF_DMIC_PDM_TOKENS,
1489 				    slink->tuples, slink->num_tuples,
1490 				    sizeof(struct sof_ipc_dai_dmic_pdm_ctrl),
1491 				    config->dmic.num_pdm_active);
1492 	if (ret < 0)
1493 		return ret;
1494 
1495 	/* set IPC header size */
1496 	config->hdr.size = size;
1497 
1498 	/* debug messages */
1499 	dev_dbg(scomp->dev, "tplg: config DMIC%d driver version %d\n",
1500 		config->dai_index, config->dmic.driver_ipc_version);
1501 	dev_dbg(scomp->dev, "pdmclk_min %d pdm_clkmax %d duty_min %d\n",
1502 		config->dmic.pdmclk_min, config->dmic.pdmclk_max,
1503 		config->dmic.duty_min);
1504 	dev_dbg(scomp->dev, "duty_max %d fifo_fs %d num_pdms active %d\n",
1505 		config->dmic.duty_max, config->dmic.fifo_fs,
1506 		config->dmic.num_pdm_active);
1507 	dev_dbg(scomp->dev, "fifo word length %d\n", config->dmic.fifo_bits);
1508 
1509 	for (i = 0; i < config->dmic.num_pdm_active; i++) {
1510 		dev_dbg(scomp->dev, "pdm %d mic a %d mic b %d\n",
1511 			config->dmic.pdm[i].id,
1512 			config->dmic.pdm[i].enable_mic_a,
1513 			config->dmic.pdm[i].enable_mic_b);
1514 		dev_dbg(scomp->dev, "pdm %d polarity a %d polarity b %d\n",
1515 			config->dmic.pdm[i].id,
1516 			config->dmic.pdm[i].polarity_mic_a,
1517 			config->dmic.pdm[i].polarity_mic_b);
1518 		dev_dbg(scomp->dev, "pdm %d clk_edge %d skew %d\n",
1519 			config->dmic.pdm[i].id,
1520 			config->dmic.pdm[i].clk_edge,
1521 			config->dmic.pdm[i].skew);
1522 	}
1523 
1524 	/*
1525 	 * this takes care of backwards compatible handling of fifo_bits_b.
1526 	 * It is deprecated since firmware ABI version 3.0.1.
1527 	 */
1528 	if (SOF_ABI_VER(v->major, v->minor, v->micro) < SOF_ABI_VER(3, 0, 1))
1529 		config->dmic.fifo_bits_b = config->dmic.fifo_bits;
1530 
1531 	dai->number_configs = 1;
1532 	dai->current_config = 0;
1533 	private->dai_config = kmemdup(config, size, GFP_KERNEL);
1534 	if (!private->dai_config)
1535 		return -ENOMEM;
1536 
1537 	return 0;
1538 }
1539 
1540 static int sof_link_alh_load(struct snd_soc_component *scomp, struct snd_sof_dai_link *slink,
1541 			     struct sof_ipc_dai_config *config, struct snd_sof_dai *dai)
1542 {
1543 	struct sof_dai_private_data *private = dai->private;
1544 	u32 size = sizeof(*config);
1545 	int ret;
1546 
1547 	/* parse the required set of ALH tokens based on num_hw_cfgs */
1548 	ret = sof_update_ipc_object(scomp, &config->alh, SOF_ALH_TOKENS, slink->tuples,
1549 				    slink->num_tuples, size, slink->num_hw_configs);
1550 	if (ret < 0)
1551 		return ret;
1552 
1553 	/* init IPC */
1554 	config->hdr.size = size;
1555 
1556 	/* set config for all DAI's with name matching the link name */
1557 	dai->number_configs = 1;
1558 	dai->current_config = 0;
1559 	private->dai_config = kmemdup(config, size, GFP_KERNEL);
1560 	if (!private->dai_config)
1561 		return -ENOMEM;
1562 
1563 	return 0;
1564 }
1565 
1566 static int sof_ipc3_widget_setup_comp_dai(struct snd_sof_widget *swidget)
1567 {
1568 	struct snd_soc_component *scomp = swidget->scomp;
1569 	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
1570 	struct snd_sof_dai *dai = swidget->private;
1571 	struct sof_dai_private_data *private;
1572 	struct sof_ipc_comp_dai *comp_dai;
1573 	size_t ipc_size = sizeof(*comp_dai);
1574 	struct sof_ipc_dai_config *config;
1575 	struct snd_sof_dai_link *slink;
1576 	int ret;
1577 
1578 	private = kzalloc_obj(*private);
1579 	if (!private)
1580 		return -ENOMEM;
1581 
1582 	dai->private = private;
1583 
1584 	private->comp_dai = sof_comp_alloc(swidget, &ipc_size, swidget->pipeline_id);
1585 	if (!private->comp_dai) {
1586 		ret = -ENOMEM;
1587 		goto free;
1588 	}
1589 
1590 	/* configure dai IPC message */
1591 	comp_dai = private->comp_dai;
1592 	comp_dai->comp.type = SOF_COMP_DAI;
1593 	comp_dai->config.hdr.size = sizeof(comp_dai->config);
1594 
1595 	/* parse one set of DAI tokens */
1596 	ret = sof_update_ipc_object(scomp, comp_dai, SOF_DAI_TOKENS, swidget->tuples,
1597 				    swidget->num_tuples, sizeof(*comp_dai), 1);
1598 	if (ret < 0)
1599 		goto free_comp;
1600 
1601 	/* update comp_tokens */
1602 	ret = sof_update_ipc_object(scomp, &comp_dai->config, SOF_COMP_TOKENS,
1603 				    swidget->tuples, swidget->num_tuples,
1604 				    sizeof(comp_dai->config), 1);
1605 	if (ret < 0)
1606 		goto free_comp;
1607 
1608 	/* Subtract the base to match the FW dai index. */
1609 	if (comp_dai->type == SOF_DAI_INTEL_ALH) {
1610 		if (comp_dai->dai_index < INTEL_ALH_DAI_INDEX_BASE) {
1611 			dev_err(sdev->dev,
1612 				"Invalid ALH dai index %d, only Pin numbers >= %d can be used\n",
1613 				comp_dai->dai_index, INTEL_ALH_DAI_INDEX_BASE);
1614 			ret = -EINVAL;
1615 			goto free_comp;
1616 		}
1617 		comp_dai->dai_index -= INTEL_ALH_DAI_INDEX_BASE;
1618 	}
1619 
1620 	dev_dbg(scomp->dev, "dai %s: type %d index %d\n",
1621 		swidget->widget->name, comp_dai->type, comp_dai->dai_index);
1622 	sof_dbg_comp_config(scomp, &comp_dai->config);
1623 
1624 	/* now update DAI config */
1625 	list_for_each_entry(slink, &sdev->dai_link_list, list) {
1626 		struct sof_ipc_dai_config common_config;
1627 		int i;
1628 
1629 		if (strcmp(slink->link->name, dai->name))
1630 			continue;
1631 
1632 		/* Reserve memory for all hw configs, eventually freed by widget */
1633 		config = kzalloc_objs(*config, slink->num_hw_configs);
1634 		if (!config) {
1635 			ret = -ENOMEM;
1636 			goto free_comp;
1637 		}
1638 
1639 		/* parse one set of DAI link tokens */
1640 		ret = sof_update_ipc_object(scomp, &common_config, SOF_DAI_LINK_TOKENS,
1641 					    slink->tuples, slink->num_tuples,
1642 					    sizeof(common_config), 1);
1643 		if (ret < 0)
1644 			goto free_config;
1645 
1646 		for (i = 0; i < slink->num_hw_configs; i++) {
1647 			config[i].hdr.cmd = SOF_IPC_GLB_DAI_MSG | SOF_IPC_DAI_CONFIG;
1648 			config[i].format = le32_to_cpu(slink->hw_configs[i].fmt);
1649 			config[i].type = common_config.type;
1650 			config[i].dai_index = comp_dai->dai_index;
1651 		}
1652 
1653 		switch (common_config.type) {
1654 		case SOF_DAI_INTEL_SSP:
1655 			ret = sof_link_ssp_load(scomp, slink, config, dai);
1656 			break;
1657 		case SOF_DAI_INTEL_DMIC:
1658 			ret = sof_link_dmic_load(scomp, slink, config, dai);
1659 			break;
1660 		case SOF_DAI_INTEL_HDA:
1661 			ret = sof_link_hda_load(scomp, slink, config, dai);
1662 			break;
1663 		case SOF_DAI_INTEL_ALH:
1664 			ret = sof_link_alh_load(scomp, slink, config, dai);
1665 			break;
1666 		case SOF_DAI_IMX_SAI:
1667 			ret = sof_link_sai_load(scomp, slink, config, dai);
1668 			break;
1669 		case SOF_DAI_IMX_ESAI:
1670 			ret = sof_link_esai_load(scomp, slink, config, dai);
1671 			break;
1672 		case SOF_DAI_IMX_MICFIL:
1673 			ret = sof_link_micfil_load(scomp, slink, config, dai);
1674 			break;
1675 		case SOF_DAI_AMD_BT:
1676 			ret = sof_link_acp_bt_load(scomp, slink, config, dai);
1677 			break;
1678 		case SOF_DAI_AMD_SP:
1679 		case SOF_DAI_AMD_SP_VIRTUAL:
1680 			ret = sof_link_acp_sp_load(scomp, slink, config, dai);
1681 			break;
1682 		case SOF_DAI_AMD_HS:
1683 		case SOF_DAI_AMD_HS_VIRTUAL:
1684 			ret = sof_link_acp_hs_load(scomp, slink, config, dai);
1685 			break;
1686 		case SOF_DAI_AMD_DMIC:
1687 			ret = sof_link_acp_dmic_load(scomp, slink, config, dai);
1688 			break;
1689 		case SOF_DAI_MEDIATEK_AFE:
1690 			ret = sof_link_afe_load(scomp, slink, config, dai);
1691 			break;
1692 		case SOF_DAI_AMD_SDW:
1693 			ret = sof_link_acp_sdw_load(scomp, slink, config, dai);
1694 			break;
1695 		default:
1696 			break;
1697 		}
1698 		if (ret < 0) {
1699 			dev_err(scomp->dev, "failed to load config for dai %s\n", dai->name);
1700 			goto free_config;
1701 		}
1702 
1703 		kfree(config);
1704 	}
1705 
1706 	return 0;
1707 free_config:
1708 	kfree(config);
1709 free_comp:
1710 	kfree(comp_dai);
1711 free:
1712 	kfree(private);
1713 	dai->private = NULL;
1714 	return ret;
1715 }
1716 
1717 static void sof_ipc3_widget_free_comp_dai(struct snd_sof_widget *swidget)
1718 {
1719 	switch (swidget->id) {
1720 	case snd_soc_dapm_dai_in:
1721 	case snd_soc_dapm_dai_out:
1722 	{
1723 		struct snd_sof_dai *dai = swidget->private;
1724 		struct sof_dai_private_data *dai_data;
1725 
1726 		if (!dai)
1727 			return;
1728 
1729 		dai_data = dai->private;
1730 		if (dai_data) {
1731 			kfree(dai_data->comp_dai);
1732 			kfree(dai_data->dai_config);
1733 			kfree(dai_data);
1734 		}
1735 		kfree(dai);
1736 		break;
1737 	}
1738 	default:
1739 		break;
1740 	}
1741 }
1742 
1743 static int sof_ipc3_route_setup(struct snd_sof_dev *sdev, struct snd_sof_route *sroute)
1744 {
1745 	struct sof_ipc_pipe_comp_connect connect;
1746 	int ret;
1747 
1748 	connect.hdr.size = sizeof(connect);
1749 	connect.hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_COMP_CONNECT;
1750 	connect.source_id = sroute->src_widget->comp_id;
1751 	connect.sink_id = sroute->sink_widget->comp_id;
1752 
1753 	dev_dbg(sdev->dev, "setting up route %s -> %s\n",
1754 		sroute->src_widget->widget->name,
1755 		sroute->sink_widget->widget->name);
1756 
1757 	/* send ipc */
1758 	ret = sof_ipc_tx_message_no_reply(sdev->ipc, &connect, sizeof(connect));
1759 	if (ret < 0)
1760 		dev_err(sdev->dev, "%s: route %s -> %s failed\n", __func__,
1761 			sroute->src_widget->widget->name, sroute->sink_widget->widget->name);
1762 
1763 	return ret;
1764 }
1765 
1766 static int sof_ipc3_control_load_bytes(struct snd_sof_dev *sdev, struct snd_sof_control *scontrol)
1767 {
1768 	struct sof_ipc_ctrl_data *cdata;
1769 	size_t priv_size_check;
1770 	int ret;
1771 
1772 	if (scontrol->max_size < (sizeof(*cdata) + sizeof(struct sof_abi_hdr))) {
1773 		dev_err(sdev->dev, "%s: insufficient size for a bytes control: %zu.\n",
1774 			__func__, scontrol->max_size);
1775 		return -EINVAL;
1776 	}
1777 
1778 	if (scontrol->priv_size > scontrol->max_size - sizeof(*cdata)) {
1779 		dev_err(sdev->dev,
1780 			"%s: bytes data size %zu exceeds max %zu.\n", __func__,
1781 			scontrol->priv_size, scontrol->max_size - sizeof(*cdata));
1782 		return -EINVAL;
1783 	}
1784 
1785 	scontrol->ipc_control_data = kzalloc(scontrol->max_size, GFP_KERNEL);
1786 	if (!scontrol->ipc_control_data)
1787 		return -ENOMEM;
1788 
1789 	scontrol->size = sizeof(struct sof_ipc_ctrl_data) + scontrol->priv_size;
1790 
1791 	cdata = scontrol->ipc_control_data;
1792 	cdata->cmd = SOF_CTRL_CMD_BINARY;
1793 	cdata->index = scontrol->index;
1794 
1795 	if (scontrol->priv_size > 0) {
1796 		memcpy(cdata->data, scontrol->priv, scontrol->priv_size);
1797 		kfree(scontrol->priv);
1798 		scontrol->priv = NULL;
1799 
1800 		if (cdata->data->magic != SOF_ABI_MAGIC) {
1801 			dev_err(sdev->dev, "Wrong ABI magic 0x%08x.\n", cdata->data->magic);
1802 			ret = -EINVAL;
1803 			goto err;
1804 		}
1805 
1806 		if (SOF_ABI_VERSION_INCOMPATIBLE(SOF_ABI_VERSION, cdata->data->abi)) {
1807 			dev_err(sdev->dev, "Incompatible ABI version 0x%08x.\n",
1808 				cdata->data->abi);
1809 			ret = -EINVAL;
1810 			goto err;
1811 		}
1812 
1813 		priv_size_check = cdata->data->size + sizeof(struct sof_abi_hdr);
1814 		if (priv_size_check != scontrol->priv_size) {
1815 			dev_err(sdev->dev, "Conflict in bytes (%zu) vs. priv size (%zu).\n",
1816 				priv_size_check, scontrol->priv_size);
1817 			ret = -EINVAL;
1818 			goto err;
1819 		}
1820 	}
1821 
1822 	return 0;
1823 err:
1824 	kfree(scontrol->ipc_control_data);
1825 	scontrol->ipc_control_data = NULL;
1826 	return ret;
1827 }
1828 
1829 static int sof_ipc3_control_load_volume(struct snd_sof_dev *sdev, struct snd_sof_control *scontrol)
1830 {
1831 	struct sof_ipc_ctrl_data *cdata;
1832 	int i;
1833 
1834 	/* init the volume get/put data */
1835 	scontrol->size = struct_size(cdata, chanv, scontrol->num_channels);
1836 
1837 	scontrol->ipc_control_data = kzalloc(scontrol->size, GFP_KERNEL);
1838 	if (!scontrol->ipc_control_data)
1839 		return -ENOMEM;
1840 
1841 	cdata = scontrol->ipc_control_data;
1842 	cdata->index = scontrol->index;
1843 
1844 	/* set cmd for mixer control */
1845 	if (scontrol->max == 1) {
1846 		cdata->cmd = SOF_CTRL_CMD_SWITCH;
1847 		return 0;
1848 	}
1849 
1850 	cdata->cmd = SOF_CTRL_CMD_VOLUME;
1851 
1852 	/* set default volume values to 0dB in control */
1853 	for (i = 0; i < scontrol->num_channels; i++) {
1854 		cdata->chanv[i].channel = i;
1855 		cdata->chanv[i].value = VOL_ZERO_DB;
1856 	}
1857 
1858 	return 0;
1859 }
1860 
1861 static int sof_ipc3_control_load_enum(struct snd_sof_dev *sdev, struct snd_sof_control *scontrol)
1862 {
1863 	struct sof_ipc_ctrl_data *cdata;
1864 
1865 	/* init the enum get/put data */
1866 	scontrol->size = struct_size(cdata, chanv, scontrol->num_channels);
1867 
1868 	scontrol->ipc_control_data = kzalloc(scontrol->size, GFP_KERNEL);
1869 	if (!scontrol->ipc_control_data)
1870 		return -ENOMEM;
1871 
1872 	cdata = scontrol->ipc_control_data;
1873 	cdata->index = scontrol->index;
1874 	cdata->cmd = SOF_CTRL_CMD_ENUM;
1875 
1876 	return 0;
1877 }
1878 
1879 static int sof_ipc3_control_setup(struct snd_sof_dev *sdev, struct snd_sof_control *scontrol)
1880 {
1881 	switch (scontrol->info_type) {
1882 	case SND_SOC_TPLG_CTL_VOLSW:
1883 	case SND_SOC_TPLG_CTL_VOLSW_SX:
1884 	case SND_SOC_TPLG_CTL_VOLSW_XR_SX:
1885 		return sof_ipc3_control_load_volume(sdev, scontrol);
1886 	case SND_SOC_TPLG_CTL_BYTES:
1887 		return sof_ipc3_control_load_bytes(sdev, scontrol);
1888 	case SND_SOC_TPLG_CTL_ENUM:
1889 	case SND_SOC_TPLG_CTL_ENUM_VALUE:
1890 		return sof_ipc3_control_load_enum(sdev, scontrol);
1891 	default:
1892 		break;
1893 	}
1894 
1895 	return 0;
1896 }
1897 
1898 static int sof_ipc3_control_free(struct snd_sof_dev *sdev, struct snd_sof_control *scontrol)
1899 {
1900 	struct sof_ipc_free fcomp;
1901 
1902 	fcomp.hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_COMP_FREE;
1903 	fcomp.hdr.size = sizeof(fcomp);
1904 	fcomp.id = scontrol->comp_id;
1905 
1906 	/* send IPC to the DSP */
1907 	return sof_ipc_tx_message_no_reply(sdev->ipc, &fcomp, sizeof(fcomp));
1908 }
1909 
1910 /* send pcm params ipc */
1911 static int sof_ipc3_keyword_detect_pcm_params(struct snd_sof_widget *swidget, int dir)
1912 {
1913 	struct snd_soc_component *scomp = swidget->scomp;
1914 	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
1915 	struct snd_pcm_hw_params *params;
1916 	struct sof_ipc_pcm_params pcm;
1917 	struct snd_sof_pcm *spcm;
1918 	int ret;
1919 
1920 	/* get runtime PCM params using widget's stream name */
1921 	spcm = snd_sof_find_spcm_name(scomp, swidget->widget->sname);
1922 	if (!spcm) {
1923 		dev_err(scomp->dev, "Cannot find PCM for %s\n", swidget->widget->name);
1924 		return -EINVAL;
1925 	}
1926 
1927 	params = &spcm->params[dir];
1928 
1929 	/* set IPC PCM params */
1930 	memset(&pcm, 0, sizeof(pcm));
1931 	pcm.hdr.size = sizeof(pcm);
1932 	pcm.hdr.cmd = SOF_IPC_GLB_STREAM_MSG | SOF_IPC_STREAM_PCM_PARAMS;
1933 	pcm.comp_id = swidget->comp_id;
1934 	pcm.params.hdr.size = sizeof(pcm.params);
1935 	pcm.params.direction = dir;
1936 	pcm.params.sample_valid_bytes = params_width(params) >> 3;
1937 	pcm.params.buffer_fmt = SOF_IPC_BUFFER_INTERLEAVED;
1938 	pcm.params.rate = params_rate(params);
1939 	pcm.params.channels = params_channels(params);
1940 	pcm.params.host_period_bytes = params_period_bytes(params);
1941 
1942 	/* set format */
1943 	switch (params_format(params)) {
1944 	case SNDRV_PCM_FORMAT_S16:
1945 		pcm.params.frame_fmt = SOF_IPC_FRAME_S16_LE;
1946 		break;
1947 	case SNDRV_PCM_FORMAT_S24:
1948 		pcm.params.frame_fmt = SOF_IPC_FRAME_S24_4LE;
1949 		break;
1950 	case SNDRV_PCM_FORMAT_S32:
1951 		pcm.params.frame_fmt = SOF_IPC_FRAME_S32_LE;
1952 		break;
1953 	default:
1954 		return -EINVAL;
1955 	}
1956 
1957 	/* send IPC to the DSP */
1958 	ret = sof_ipc_tx_message_no_reply(sdev->ipc, &pcm, sizeof(pcm));
1959 	if (ret < 0)
1960 		dev_err(scomp->dev, "%s: PCM params failed for %s\n", __func__,
1961 			swidget->widget->name);
1962 
1963 	return ret;
1964 }
1965 
1966  /* send stream trigger ipc */
1967 static int sof_ipc3_keyword_detect_trigger(struct snd_sof_widget *swidget, int cmd)
1968 {
1969 	struct snd_soc_component *scomp = swidget->scomp;
1970 	struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
1971 	struct sof_ipc_stream stream;
1972 	int ret;
1973 
1974 	/* set IPC stream params */
1975 	stream.hdr.size = sizeof(stream);
1976 	stream.hdr.cmd = SOF_IPC_GLB_STREAM_MSG | cmd;
1977 	stream.comp_id = swidget->comp_id;
1978 
1979 	/* send IPC to the DSP */
1980 	ret = sof_ipc_tx_message_no_reply(sdev->ipc, &stream, sizeof(stream));
1981 	if (ret < 0)
1982 		dev_err(scomp->dev, "%s: Failed to trigger %s\n", __func__, swidget->widget->name);
1983 
1984 	return ret;
1985 }
1986 
1987 static int sof_ipc3_keyword_dapm_event(struct snd_soc_dapm_widget *w,
1988 				       struct snd_kcontrol *k, int event)
1989 {
1990 	struct snd_sof_widget *swidget = w->dobj.private;
1991 	struct snd_soc_component *scomp;
1992 	int stream = SNDRV_PCM_STREAM_CAPTURE;
1993 	struct snd_sof_pcm *spcm;
1994 	int ret = 0;
1995 
1996 	if (!swidget)
1997 		return 0;
1998 
1999 	scomp = swidget->scomp;
2000 
2001 	dev_dbg(scomp->dev, "received event %d for widget %s\n",
2002 		event, w->name);
2003 
2004 	/* get runtime PCM params using widget's stream name */
2005 	spcm = snd_sof_find_spcm_name(scomp, swidget->widget->sname);
2006 	if (!spcm) {
2007 		dev_err(scomp->dev, "%s: Cannot find PCM for %s\n", __func__,
2008 			swidget->widget->name);
2009 		return -EINVAL;
2010 	}
2011 
2012 	/* process events */
2013 	switch (event) {
2014 	case SND_SOC_DAPM_PRE_PMU:
2015 		if (spcm->stream[stream].suspend_ignored) {
2016 			dev_dbg(scomp->dev, "PRE_PMU event ignored, KWD pipeline is already RUNNING\n");
2017 			return 0;
2018 		}
2019 
2020 		/* set pcm params */
2021 		ret = sof_ipc3_keyword_detect_pcm_params(swidget, stream);
2022 		if (ret < 0) {
2023 			dev_err(scomp->dev, "%s: Failed to set pcm params for widget %s\n",
2024 				__func__, swidget->widget->name);
2025 			break;
2026 		}
2027 
2028 		/* start trigger */
2029 		ret = sof_ipc3_keyword_detect_trigger(swidget, SOF_IPC_STREAM_TRIG_START);
2030 		if (ret < 0)
2031 			dev_err(scomp->dev, "%s: Failed to trigger widget %s\n", __func__,
2032 				swidget->widget->name);
2033 		break;
2034 	case SND_SOC_DAPM_POST_PMD:
2035 		if (spcm->stream[stream].suspend_ignored) {
2036 			dev_dbg(scomp->dev,
2037 				"POST_PMD event ignored, KWD pipeline will remain RUNNING\n");
2038 			return 0;
2039 		}
2040 
2041 		/* stop trigger */
2042 		ret = sof_ipc3_keyword_detect_trigger(swidget, SOF_IPC_STREAM_TRIG_STOP);
2043 		if (ret < 0)
2044 			dev_err(scomp->dev, "%s: Failed to trigger widget %s\n", __func__,
2045 				swidget->widget->name);
2046 
2047 		/* pcm free */
2048 		ret = sof_ipc3_keyword_detect_trigger(swidget, SOF_IPC_STREAM_PCM_FREE);
2049 		if (ret < 0)
2050 			dev_err(scomp->dev, "%s: Failed to free PCM for widget %s\n", __func__,
2051 				swidget->widget->name);
2052 		break;
2053 	default:
2054 		break;
2055 	}
2056 
2057 	return ret;
2058 }
2059 
2060 /* event handlers for keyword detect component */
2061 static const struct snd_soc_tplg_widget_events sof_kwd_events[] = {
2062 	{SOF_KEYWORD_DETECT_DAPM_EVENT, sof_ipc3_keyword_dapm_event},
2063 };
2064 
2065 static int sof_ipc3_widget_bind_event(struct snd_soc_component *scomp,
2066 				      struct snd_sof_widget *swidget, u16 event_type)
2067 {
2068 	struct sof_ipc_comp *ipc_comp;
2069 
2070 	/* validate widget event type */
2071 	switch (event_type) {
2072 	case SOF_KEYWORD_DETECT_DAPM_EVENT:
2073 		/* only KEYWORD_DETECT comps should handle this */
2074 		if (swidget->id != snd_soc_dapm_effect)
2075 			break;
2076 
2077 		ipc_comp = swidget->private;
2078 		if (ipc_comp && ipc_comp->type != SOF_COMP_KEYWORD_DETECT)
2079 			break;
2080 
2081 		/* bind event to keyword detect comp */
2082 		return snd_soc_tplg_widget_bind_event(swidget->widget, sof_kwd_events,
2083 						      ARRAY_SIZE(sof_kwd_events), event_type);
2084 	default:
2085 		break;
2086 	}
2087 
2088 	dev_err(scomp->dev, "Invalid event type %d for widget %s\n", event_type,
2089 		swidget->widget->name);
2090 
2091 	return -EINVAL;
2092 }
2093 
2094 static int sof_ipc3_complete_pipeline(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
2095 {
2096 	struct sof_ipc_pipe_ready ready;
2097 	int ret;
2098 
2099 	dev_dbg(sdev->dev, "tplg: complete pipeline %s id %d\n",
2100 		swidget->widget->name, swidget->comp_id);
2101 
2102 	memset(&ready, 0, sizeof(ready));
2103 	ready.hdr.size = sizeof(ready);
2104 	ready.hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_PIPE_COMPLETE;
2105 	ready.comp_id = swidget->comp_id;
2106 
2107 	ret = sof_ipc_tx_message_no_reply(sdev->ipc, &ready, sizeof(ready));
2108 	if (ret < 0)
2109 		return ret;
2110 
2111 	return 1;
2112 }
2113 
2114 static int sof_ipc3_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
2115 {
2116 	struct sof_ipc_free ipc_free = {
2117 		.hdr = {
2118 			.size = sizeof(ipc_free),
2119 			.cmd = SOF_IPC_GLB_TPLG_MSG,
2120 		},
2121 		.id = swidget->comp_id,
2122 	};
2123 	int ret;
2124 
2125 	if (!swidget->private)
2126 		return 0;
2127 
2128 	switch (swidget->id) {
2129 	case snd_soc_dapm_scheduler:
2130 	{
2131 		ipc_free.hdr.cmd |= SOF_IPC_TPLG_PIPE_FREE;
2132 		break;
2133 	}
2134 	case snd_soc_dapm_buffer:
2135 		ipc_free.hdr.cmd |= SOF_IPC_TPLG_BUFFER_FREE;
2136 		break;
2137 	default:
2138 		ipc_free.hdr.cmd |= SOF_IPC_TPLG_COMP_FREE;
2139 		break;
2140 	}
2141 
2142 	ret = sof_ipc_tx_message_no_reply(sdev->ipc, &ipc_free, sizeof(ipc_free));
2143 	if (ret < 0)
2144 		dev_err(sdev->dev, "failed to free widget %s\n", swidget->widget->name);
2145 
2146 	return ret;
2147 }
2148 
2149 static int sof_ipc3_dai_config(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget,
2150 			       unsigned int flags, struct snd_sof_dai_config_data *data)
2151 {
2152 	struct sof_ipc_fw_version *v = &sdev->fw_ready.version;
2153 	struct snd_sof_dai *dai = swidget->private;
2154 	struct sof_dai_private_data *private;
2155 	struct sof_ipc_dai_config *config;
2156 	int ret = 0;
2157 
2158 	if (!dai || !dai->private) {
2159 		dev_err(sdev->dev, "No private data for DAI %s\n", swidget->widget->name);
2160 		return -EINVAL;
2161 	}
2162 
2163 	private = dai->private;
2164 	if (!private->dai_config) {
2165 		dev_err(sdev->dev, "No config for DAI %s\n", dai->name);
2166 		return -EINVAL;
2167 	}
2168 
2169 	config = &private->dai_config[dai->current_config];
2170 	if (!config) {
2171 		dev_err(sdev->dev, "Invalid current config for DAI %s\n", dai->name);
2172 		return -EINVAL;
2173 	}
2174 
2175 	switch (config->type) {
2176 	case SOF_DAI_INTEL_SSP:
2177 		/*
2178 		 * DAI_CONFIG IPC during hw_params/hw_free for SSP DAI's is not supported in older
2179 		 * firmware
2180 		 */
2181 		if (v->abi_version < SOF_ABI_VER(3, 18, 0) &&
2182 		    ((flags & SOF_DAI_CONFIG_FLAGS_HW_PARAMS) ||
2183 		     (flags & SOF_DAI_CONFIG_FLAGS_HW_FREE)))
2184 			return 0;
2185 		break;
2186 	case SOF_DAI_INTEL_HDA:
2187 		if (data)
2188 			config->hda.link_dma_ch = data->dai_data;
2189 		break;
2190 	case SOF_DAI_INTEL_ALH:
2191 		if (data) {
2192 			/* save the dai_index during hw_params and reuse it for hw_free */
2193 			if (flags & SOF_DAI_CONFIG_FLAGS_HW_PARAMS) {
2194 				/* Subtract the base to match the FW dai index. */
2195 				if (data->dai_index < INTEL_ALH_DAI_INDEX_BASE) {
2196 					dev_err(sdev->dev,
2197 						"Invalid ALH dai index %d, only Pin numbers >= %d can be used\n",
2198 						config->dai_index, INTEL_ALH_DAI_INDEX_BASE);
2199 					return -EINVAL;
2200 				}
2201 				config->dai_index = data->dai_index - INTEL_ALH_DAI_INDEX_BASE;
2202 			}
2203 			config->alh.stream_id = data->dai_data;
2204 		}
2205 		break;
2206 	default:
2207 		break;
2208 	}
2209 
2210 	/*
2211 	 * The dai_config op is invoked several times and the flags argument varies as below:
2212 	 * BE DAI hw_params: When the op is invoked during the BE DAI hw_params, flags contains
2213 	 * SOF_DAI_CONFIG_FLAGS_HW_PARAMS along with quirks
2214 	 * FE DAI hw_params: When invoked during FE DAI hw_params after the DAI widget has
2215 	 * just been set up in the DSP, flags is set to SOF_DAI_CONFIG_FLAGS_HW_PARAMS with no
2216 	 * quirks
2217 	 * BE DAI trigger: When invoked during the BE DAI trigger, flags is set to
2218 	 * SOF_DAI_CONFIG_FLAGS_PAUSE and contains no quirks
2219 	 * BE DAI hw_free: When invoked during the BE DAI hw_free, flags is set to
2220 	 * SOF_DAI_CONFIG_FLAGS_HW_FREE and contains no quirks
2221 	 * FE DAI hw_free: When invoked during the FE DAI hw_free, flags is set to
2222 	 * SOF_DAI_CONFIG_FLAGS_HW_FREE and contains no quirks
2223 	 *
2224 	 * The DAI_CONFIG IPC is sent to the DSP, only after the widget is set up during the FE
2225 	 * DAI hw_params. But since the BE DAI hw_params precedes the FE DAI hw_params, the quirks
2226 	 * need to be preserved when assigning the flags before sending the IPC.
2227 	 * For the case of PAUSE/HW_FREE, since there are no quirks, flags can be used as is.
2228 	 */
2229 
2230 	if (flags & SOF_DAI_CONFIG_FLAGS_HW_PARAMS) {
2231 		/* Clear stale command */
2232 		config->flags &= ~SOF_DAI_CONFIG_FLAGS_CMD_MASK;
2233 		config->flags |= flags;
2234 	} else {
2235 		config->flags = flags;
2236 	}
2237 
2238 	/* only send the IPC if the widget is set up in the DSP */
2239 	if (swidget->use_count > 0) {
2240 		ret = sof_ipc_tx_message_no_reply(sdev->ipc, config, config->hdr.size);
2241 		if (ret < 0)
2242 			dev_err(sdev->dev, "Failed to set dai config for %s\n", dai->name);
2243 
2244 		/* clear the flags once the IPC has been sent even if it fails */
2245 		config->flags = SOF_DAI_CONFIG_FLAGS_NONE;
2246 	}
2247 
2248 	return ret;
2249 }
2250 
2251 static int sof_ipc3_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
2252 {
2253 	int ret;
2254 
2255 	if (!swidget->private)
2256 		return 0;
2257 
2258 	switch (swidget->id) {
2259 	case snd_soc_dapm_dai_in:
2260 	case snd_soc_dapm_dai_out:
2261 	{
2262 		struct snd_sof_dai *dai = swidget->private;
2263 		struct sof_dai_private_data *dai_data = dai->private;
2264 		struct sof_ipc_comp *comp = &dai_data->comp_dai->comp;
2265 
2266 		ret = sof_ipc_tx_message_no_reply(sdev->ipc, dai_data->comp_dai, comp->hdr.size);
2267 		break;
2268 	}
2269 	case snd_soc_dapm_scheduler:
2270 	{
2271 		struct sof_ipc_pipe_new *pipeline;
2272 
2273 		pipeline = swidget->private;
2274 		ret = sof_ipc_tx_message_no_reply(sdev->ipc, pipeline, sizeof(*pipeline));
2275 		break;
2276 	}
2277 	default:
2278 	{
2279 		struct sof_ipc_cmd_hdr *hdr;
2280 
2281 		hdr = swidget->private;
2282 		ret = sof_ipc_tx_message_no_reply(sdev->ipc, swidget->private, hdr->size);
2283 		break;
2284 	}
2285 	}
2286 	if (ret < 0)
2287 		dev_err(sdev->dev, "Failed to setup widget %s\n", swidget->widget->name);
2288 
2289 	return ret;
2290 }
2291 
2292 static int sof_ipc3_set_up_all_pipelines(struct snd_sof_dev *sdev, bool verify)
2293 {
2294 	struct sof_ipc_fw_version *v = &sdev->fw_ready.version;
2295 	struct snd_sof_widget *swidget;
2296 	struct snd_sof_route *sroute;
2297 	int ret;
2298 
2299 	/* restore pipeline components */
2300 	list_for_each_entry(swidget, &sdev->widget_list, list) {
2301 		/* only set up the widgets belonging to static pipelines */
2302 		if (!verify && swidget->dynamic_pipeline_widget)
2303 			continue;
2304 
2305 		/*
2306 		 * For older firmware, skip scheduler widgets in this loop,
2307 		 * sof_widget_setup() will be called in the 'complete pipeline' loop
2308 		 */
2309 		if (v->abi_version < SOF_ABI_VER(3, 19, 0) &&
2310 		    swidget->id == snd_soc_dapm_scheduler)
2311 			continue;
2312 
2313 		/* update DAI config. The IPC will be sent in sof_widget_setup() */
2314 		if (WIDGET_IS_DAI(swidget->id)) {
2315 			struct snd_sof_dai *dai = swidget->private;
2316 			struct sof_dai_private_data *private;
2317 			struct sof_ipc_dai_config *config;
2318 
2319 			if (!dai || !dai->private)
2320 				continue;
2321 			private = dai->private;
2322 			if (!private->dai_config)
2323 				continue;
2324 
2325 			config = private->dai_config;
2326 			/*
2327 			 * The link DMA channel would be invalidated for running
2328 			 * streams but not for streams that were in the PAUSED
2329 			 * state during suspend. So invalidate it here before setting
2330 			 * the dai config in the DSP.
2331 			 */
2332 			if (config->type == SOF_DAI_INTEL_HDA)
2333 				config->hda.link_dma_ch = DMA_CHAN_INVALID;
2334 		}
2335 
2336 		ret = sof_widget_setup(sdev, swidget);
2337 		if (ret < 0)
2338 			return ret;
2339 	}
2340 
2341 	/* restore pipeline connections */
2342 	list_for_each_entry(sroute, &sdev->route_list, list) {
2343 		/* only set up routes belonging to static pipelines */
2344 		if (!verify && (sroute->src_widget->dynamic_pipeline_widget ||
2345 				sroute->sink_widget->dynamic_pipeline_widget))
2346 			continue;
2347 
2348 		/*
2349 		 * For virtual routes, both sink and source are not buffer. IPC3 only supports
2350 		 * connections between a buffer and a component. Ignore the rest.
2351 		 */
2352 		if (sroute->src_widget->id != snd_soc_dapm_buffer &&
2353 		    sroute->sink_widget->id != snd_soc_dapm_buffer)
2354 			continue;
2355 
2356 		ret = sof_route_setup(sdev, sroute->src_widget->widget,
2357 				      sroute->sink_widget->widget);
2358 		if (ret < 0) {
2359 			dev_err(sdev->dev, "%s: route set up failed\n", __func__);
2360 			return ret;
2361 		}
2362 	}
2363 
2364 	/* complete pipeline */
2365 	list_for_each_entry(swidget, &sdev->widget_list, list) {
2366 		switch (swidget->id) {
2367 		case snd_soc_dapm_scheduler:
2368 			/* only complete static pipelines */
2369 			if (!verify && swidget->dynamic_pipeline_widget)
2370 				continue;
2371 
2372 			if (v->abi_version < SOF_ABI_VER(3, 19, 0)) {
2373 				ret = sof_widget_setup(sdev, swidget);
2374 				if (ret < 0)
2375 					return ret;
2376 			}
2377 
2378 			swidget->spipe->complete = sof_ipc3_complete_pipeline(sdev, swidget);
2379 			if (swidget->spipe->complete < 0)
2380 				return swidget->spipe->complete;
2381 			break;
2382 		default:
2383 			break;
2384 		}
2385 	}
2386 
2387 	return 0;
2388 }
2389 
2390 /*
2391  * Free the PCM, its associated widgets and set the prepared flag to false for all PCMs that
2392  * did not get suspended(ex: paused streams) so the widgets can be set up again during resume.
2393  */
2394 static int sof_tear_down_left_over_pipelines(struct snd_sof_dev *sdev)
2395 {
2396 	struct snd_sof_widget *swidget;
2397 	int ret;
2398 
2399 	/*
2400 	 * free all PCMs and their associated DAPM widgets if their connected DAPM widget
2401 	 * list is not NULL. This should only be true for paused streams at this point.
2402 	 * This is equivalent to the handling of FE DAI suspend trigger for running streams.
2403 	 */
2404 	ret = sof_pcm_free_all_streams(sdev);
2405 	if (ret)
2406 		return ret;
2407 
2408 	/*
2409 	 * free any left over DAI widgets. This is equivalent to the handling of suspend trigger
2410 	 * for the BE DAI for running streams.
2411 	 */
2412 	list_for_each_entry(swidget, &sdev->widget_list, list)
2413 		if (WIDGET_IS_DAI(swidget->id) && swidget->use_count == 1) {
2414 			ret = sof_widget_free(sdev, swidget);
2415 			if (ret < 0)
2416 				return ret;
2417 		}
2418 
2419 	return 0;
2420 }
2421 
2422 static int sof_ipc3_free_widgets_in_list(struct snd_sof_dev *sdev, bool include_scheduler,
2423 					 bool *dyn_widgets, bool verify)
2424 {
2425 	struct sof_ipc_fw_version *v = &sdev->fw_ready.version;
2426 	struct snd_sof_widget *swidget;
2427 	int ret;
2428 
2429 	list_for_each_entry(swidget, &sdev->widget_list, list) {
2430 		if (swidget->dynamic_pipeline_widget) {
2431 			*dyn_widgets = true;
2432 			continue;
2433 		}
2434 
2435 		/* Do not free widgets for static pipelines with FW older than SOF2.2 */
2436 		if (!verify && !swidget->dynamic_pipeline_widget &&
2437 		    SOF_FW_VER(v->major, v->minor, v->micro) < SOF_FW_VER(2, 2, 0)) {
2438 			scoped_guard(mutex, &swidget->setup_mutex)
2439 				swidget->use_count = 0;
2440 
2441 			if (swidget->spipe)
2442 				swidget->spipe->complete = 0;
2443 			continue;
2444 		}
2445 
2446 		if (include_scheduler && swidget->id != snd_soc_dapm_scheduler)
2447 			continue;
2448 
2449 		if (!include_scheduler && swidget->id == snd_soc_dapm_scheduler)
2450 			continue;
2451 
2452 		ret = sof_widget_free(sdev, swidget);
2453 		if (ret < 0)
2454 			return ret;
2455 	}
2456 
2457 	return 0;
2458 }
2459 
2460 /*
2461  * For older firmware, this function doesn't free widgets for static pipelines during suspend.
2462  * It only resets use_count for all widgets.
2463  */
2464 static int sof_ipc3_tear_down_all_pipelines(struct snd_sof_dev *sdev, bool verify)
2465 {
2466 	struct sof_ipc_fw_version *v = &sdev->fw_ready.version;
2467 	struct snd_sof_widget *swidget;
2468 	struct snd_sof_route *sroute;
2469 	bool dyn_widgets = false;
2470 	int ret;
2471 
2472 	/*
2473 	 * This function is called during suspend and for one-time topology verification during
2474 	 * first boot. In both cases, there is no need to protect swidget->use_count and
2475 	 * sroute->setup because during suspend all running streams are suspended and during
2476 	 * topology loading the sound card unavailable to open PCMs. Do not free the scheduler
2477 	 * widgets yet so that the secondary cores do not get powered down before all the widgets
2478 	 * associated with the scheduler are freed.
2479 	 */
2480 	ret = sof_ipc3_free_widgets_in_list(sdev, false, &dyn_widgets, verify);
2481 	if (ret < 0)
2482 		return ret;
2483 
2484 	/*
2485 	 * Tear down all pipelines associated with PCMs that did not get suspended
2486 	 * and unset the prepare flag so that they can be set up again during resume.
2487 	 * Skip this step for older firmware unless topology has any
2488 	 * dynamic pipeline (in which case the step is mandatory).
2489 	 */
2490 	if (!verify && (dyn_widgets || SOF_FW_VER(v->major, v->minor, v->micro) >=
2491 	    SOF_FW_VER(2, 2, 0))) {
2492 		ret = sof_tear_down_left_over_pipelines(sdev);
2493 		if (ret < 0) {
2494 			dev_err(sdev->dev, "failed to tear down paused pipelines\n");
2495 			return ret;
2496 		}
2497 	}
2498 
2499 	/* free all the scheduler widgets now. This will also power down the secondary cores */
2500 	ret = sof_ipc3_free_widgets_in_list(sdev, true, &dyn_widgets, verify);
2501 	if (ret < 0)
2502 		return ret;
2503 
2504 	list_for_each_entry(sroute, &sdev->route_list, list)
2505 		sroute->setup = false;
2506 
2507 	/*
2508 	 * before suspending, make sure the refcounts are all zeroed out. There's no way
2509 	 * to recover at this point but this will help root cause bad sequences leading to
2510 	 * more issues on resume
2511 	 */
2512 	list_for_each_entry(swidget, &sdev->widget_list, list) {
2513 		if (swidget->use_count != 0) {
2514 			dev_err(sdev->dev, "%s: widget %s is still in use: count %d\n",
2515 				__func__, swidget->widget->name, swidget->use_count);
2516 		}
2517 	}
2518 
2519 	return 0;
2520 }
2521 
2522 static int sof_ipc3_dai_get_param(struct snd_sof_dev *sdev, struct snd_sof_dai *dai, int param_type)
2523 {
2524 	struct sof_dai_private_data *private = dai->private;
2525 
2526 	if (!private || !private->dai_config)
2527 		return 0;
2528 
2529 	switch (private->dai_config->type) {
2530 	case SOF_DAI_INTEL_SSP:
2531 		switch (param_type) {
2532 		case SOF_DAI_PARAM_INTEL_SSP_MCLK:
2533 			return private->dai_config->ssp.mclk_rate;
2534 		case SOF_DAI_PARAM_INTEL_SSP_BCLK:
2535 			return private->dai_config->ssp.bclk_rate;
2536 		case SOF_DAI_PARAM_INTEL_SSP_TDM_SLOTS:
2537 			return private->dai_config->ssp.tdm_slots;
2538 		default:
2539 			dev_err(sdev->dev, "invalid SSP param %d\n", param_type);
2540 			break;
2541 		}
2542 		break;
2543 	default:
2544 		/* not yet implemented for platforms other than the above */
2545 		dev_err(sdev->dev, "DAI type %d not supported yet!\n", private->dai_config->type);
2546 		break;
2547 	}
2548 
2549 	return -EINVAL;
2550 }
2551 
2552 static int sof_ipc3_parse_manifest(struct snd_soc_component *scomp, int index,
2553 				   struct snd_soc_tplg_manifest *man)
2554 {
2555 	u32 size = le32_to_cpu(man->priv.size);
2556 	u32 abi_version;
2557 
2558 	/* backward compatible with tplg without ABI info */
2559 	if (!size) {
2560 		dev_dbg(scomp->dev, "No topology ABI info\n");
2561 		return 0;
2562 	}
2563 
2564 	if (size != SOF_IPC3_TPLG_ABI_SIZE) {
2565 		dev_err(scomp->dev, "%s: Invalid topology ABI size: %u\n",
2566 			__func__, size);
2567 		return -EINVAL;
2568 	}
2569 
2570 	dev_info(scomp->dev,
2571 		 "Topology: ABI %d:%d:%d Kernel ABI %d:%d:%d\n",
2572 		 man->priv.data[0], man->priv.data[1], man->priv.data[2],
2573 		 SOF_ABI_MAJOR, SOF_ABI_MINOR, SOF_ABI_PATCH);
2574 
2575 	abi_version = SOF_ABI_VER(man->priv.data[0], man->priv.data[1], man->priv.data[2]);
2576 
2577 	if (SOF_ABI_VERSION_INCOMPATIBLE(SOF_ABI_VERSION, abi_version)) {
2578 		dev_err(scomp->dev, "%s: Incompatible topology ABI version\n", __func__);
2579 		return -EINVAL;
2580 	}
2581 
2582 	if (IS_ENABLED(CONFIG_SND_SOC_SOF_STRICT_ABI_CHECKS) &&
2583 	    SOF_ABI_VERSION_MINOR(abi_version) > SOF_ABI_MINOR) {
2584 		dev_err(scomp->dev, "%s: Topology ABI is more recent than kernel\n", __func__);
2585 		return -EINVAL;
2586 	}
2587 
2588 	return 0;
2589 }
2590 
2591 static int sof_ipc3_link_setup(struct snd_sof_dev *sdev, struct snd_soc_dai_link *link)
2592 {
2593 	if (link->no_pcm)
2594 		return 0;
2595 
2596 	/*
2597 	 * set default trigger order for all links. Exceptions to
2598 	 * the rule will be handled in sof_pcm_dai_link_fixup()
2599 	 * For playback, the sequence is the following: start FE,
2600 	 * start BE, stop BE, stop FE; for Capture the sequence is
2601 	 * inverted start BE, start FE, stop FE, stop BE
2602 	 */
2603 	link->trigger[SNDRV_PCM_STREAM_PLAYBACK] = SND_SOC_DPCM_TRIGGER_PRE;
2604 	link->trigger[SNDRV_PCM_STREAM_CAPTURE] = SND_SOC_DPCM_TRIGGER_POST;
2605 
2606 	return 0;
2607 }
2608 
2609 /* token list for each topology object */
2610 static enum sof_tokens host_token_list[] = {
2611 	SOF_CORE_TOKENS,
2612 	SOF_COMP_EXT_TOKENS,
2613 	SOF_PCM_TOKENS,
2614 	SOF_COMP_TOKENS,
2615 };
2616 
2617 static enum sof_tokens comp_generic_token_list[] = {
2618 	SOF_CORE_TOKENS,
2619 	SOF_COMP_EXT_TOKENS,
2620 	SOF_COMP_TOKENS,
2621 };
2622 
2623 static enum sof_tokens buffer_token_list[] = {
2624 	SOF_BUFFER_TOKENS,
2625 };
2626 
2627 static enum sof_tokens pipeline_token_list[] = {
2628 	SOF_CORE_TOKENS,
2629 	SOF_COMP_EXT_TOKENS,
2630 	SOF_PIPELINE_TOKENS,
2631 	SOF_SCHED_TOKENS,
2632 };
2633 
2634 static enum sof_tokens asrc_token_list[] = {
2635 	SOF_CORE_TOKENS,
2636 	SOF_COMP_EXT_TOKENS,
2637 	SOF_ASRC_TOKENS,
2638 	SOF_COMP_TOKENS,
2639 };
2640 
2641 static enum sof_tokens src_token_list[] = {
2642 	SOF_CORE_TOKENS,
2643 	SOF_COMP_EXT_TOKENS,
2644 	SOF_SRC_TOKENS,
2645 	SOF_COMP_TOKENS
2646 };
2647 
2648 static enum sof_tokens pga_token_list[] = {
2649 	SOF_CORE_TOKENS,
2650 	SOF_COMP_EXT_TOKENS,
2651 	SOF_VOLUME_TOKENS,
2652 	SOF_COMP_TOKENS,
2653 };
2654 
2655 static enum sof_tokens dai_token_list[] = {
2656 	SOF_CORE_TOKENS,
2657 	SOF_COMP_EXT_TOKENS,
2658 	SOF_DAI_TOKENS,
2659 	SOF_COMP_TOKENS,
2660 };
2661 
2662 static enum sof_tokens process_token_list[] = {
2663 	SOF_CORE_TOKENS,
2664 	SOF_COMP_EXT_TOKENS,
2665 	SOF_PROCESS_TOKENS,
2666 	SOF_COMP_TOKENS,
2667 };
2668 
2669 static const struct sof_ipc_tplg_widget_ops tplg_ipc3_widget_ops[SND_SOC_DAPM_TYPE_COUNT] = {
2670 	[snd_soc_dapm_aif_in] =  {sof_ipc3_widget_setup_comp_host, sof_ipc3_widget_free_comp,
2671 				  host_token_list, ARRAY_SIZE(host_token_list), NULL},
2672 	[snd_soc_dapm_aif_out] = {sof_ipc3_widget_setup_comp_host, sof_ipc3_widget_free_comp,
2673 				  host_token_list, ARRAY_SIZE(host_token_list), NULL},
2674 
2675 	[snd_soc_dapm_dai_in] = {sof_ipc3_widget_setup_comp_dai, sof_ipc3_widget_free_comp_dai,
2676 				 dai_token_list, ARRAY_SIZE(dai_token_list), NULL},
2677 	[snd_soc_dapm_dai_out] = {sof_ipc3_widget_setup_comp_dai, sof_ipc3_widget_free_comp_dai,
2678 				  dai_token_list, ARRAY_SIZE(dai_token_list), NULL},
2679 	[snd_soc_dapm_buffer] = {sof_ipc3_widget_setup_comp_buffer, sof_ipc3_widget_free_comp,
2680 				 buffer_token_list, ARRAY_SIZE(buffer_token_list), NULL},
2681 	[snd_soc_dapm_mixer] = {sof_ipc3_widget_setup_comp_mixer, sof_ipc3_widget_free_comp,
2682 				comp_generic_token_list, ARRAY_SIZE(comp_generic_token_list),
2683 				NULL},
2684 	[snd_soc_dapm_src] = {sof_ipc3_widget_setup_comp_src, sof_ipc3_widget_free_comp,
2685 			      src_token_list, ARRAY_SIZE(src_token_list), NULL},
2686 	[snd_soc_dapm_asrc] = {sof_ipc3_widget_setup_comp_asrc, sof_ipc3_widget_free_comp,
2687 			       asrc_token_list, ARRAY_SIZE(asrc_token_list), NULL},
2688 	[snd_soc_dapm_siggen] = {sof_ipc3_widget_setup_comp_tone, sof_ipc3_widget_free_comp,
2689 				 comp_generic_token_list, ARRAY_SIZE(comp_generic_token_list),
2690 				 NULL},
2691 	[snd_soc_dapm_scheduler] = {sof_ipc3_widget_setup_comp_pipeline, sof_ipc3_widget_free_comp,
2692 				    pipeline_token_list, ARRAY_SIZE(pipeline_token_list), NULL},
2693 	[snd_soc_dapm_pga] = {sof_ipc3_widget_setup_comp_pga, sof_ipc3_widget_free_comp,
2694 			      pga_token_list, ARRAY_SIZE(pga_token_list), NULL},
2695 	[snd_soc_dapm_mux] = {sof_ipc3_widget_setup_comp_mux, sof_ipc3_widget_free_comp,
2696 			      comp_generic_token_list, ARRAY_SIZE(comp_generic_token_list), NULL},
2697 	[snd_soc_dapm_demux] = {sof_ipc3_widget_setup_comp_mux, sof_ipc3_widget_free_comp,
2698 				 comp_generic_token_list, ARRAY_SIZE(comp_generic_token_list),
2699 				 NULL},
2700 	[snd_soc_dapm_effect] = {sof_widget_update_ipc_comp_process, sof_ipc3_widget_free_comp,
2701 				 process_token_list, ARRAY_SIZE(process_token_list),
2702 				 sof_ipc3_widget_bind_event},
2703 };
2704 
2705 const struct sof_ipc_tplg_ops ipc3_tplg_ops = {
2706 	.widget = tplg_ipc3_widget_ops,
2707 	.control = &tplg_ipc3_control_ops,
2708 	.route_setup = sof_ipc3_route_setup,
2709 	.control_setup = sof_ipc3_control_setup,
2710 	.control_free = sof_ipc3_control_free,
2711 	.pipeline_complete = sof_ipc3_complete_pipeline,
2712 	.token_list = ipc3_token_list,
2713 	.widget_free = sof_ipc3_widget_free,
2714 	.widget_setup = sof_ipc3_widget_setup,
2715 	.dai_config = sof_ipc3_dai_config,
2716 	.dai_get_param = sof_ipc3_dai_get_param,
2717 	.set_up_all_pipelines = sof_ipc3_set_up_all_pipelines,
2718 	.tear_down_all_pipelines = sof_ipc3_tear_down_all_pipelines,
2719 	.parse_manifest = sof_ipc3_parse_manifest,
2720 	.link_setup = sof_ipc3_link_setup,
2721 };
2722