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