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_obj(*pipeline); 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_obj(*buffer); 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 = kzalloc_objs(*wdata, widget->num_kcontrols); 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_obj(*private); 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_comp; 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_comp; 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 ret = -EINVAL; 1607 goto free_comp; 1608 } 1609 comp_dai->dai_index -= INTEL_ALH_DAI_INDEX_BASE; 1610 } 1611 1612 dev_dbg(scomp->dev, "dai %s: type %d index %d\n", 1613 swidget->widget->name, comp_dai->type, comp_dai->dai_index); 1614 sof_dbg_comp_config(scomp, &comp_dai->config); 1615 1616 /* now update DAI config */ 1617 list_for_each_entry(slink, &sdev->dai_link_list, list) { 1618 struct sof_ipc_dai_config common_config; 1619 int i; 1620 1621 if (strcmp(slink->link->name, dai->name)) 1622 continue; 1623 1624 /* Reserve memory for all hw configs, eventually freed by widget */ 1625 config = kzalloc_objs(*config, slink->num_hw_configs, 1626 GFP_KERNEL); 1627 if (!config) { 1628 ret = -ENOMEM; 1629 goto free_comp; 1630 } 1631 1632 /* parse one set of DAI link tokens */ 1633 ret = sof_update_ipc_object(scomp, &common_config, SOF_DAI_LINK_TOKENS, 1634 slink->tuples, slink->num_tuples, 1635 sizeof(common_config), 1); 1636 if (ret < 0) 1637 goto free_config; 1638 1639 for (i = 0; i < slink->num_hw_configs; i++) { 1640 config[i].hdr.cmd = SOF_IPC_GLB_DAI_MSG | SOF_IPC_DAI_CONFIG; 1641 config[i].format = le32_to_cpu(slink->hw_configs[i].fmt); 1642 config[i].type = common_config.type; 1643 config[i].dai_index = comp_dai->dai_index; 1644 } 1645 1646 switch (common_config.type) { 1647 case SOF_DAI_INTEL_SSP: 1648 ret = sof_link_ssp_load(scomp, slink, config, dai); 1649 break; 1650 case SOF_DAI_INTEL_DMIC: 1651 ret = sof_link_dmic_load(scomp, slink, config, dai); 1652 break; 1653 case SOF_DAI_INTEL_HDA: 1654 ret = sof_link_hda_load(scomp, slink, config, dai); 1655 break; 1656 case SOF_DAI_INTEL_ALH: 1657 ret = sof_link_alh_load(scomp, slink, config, dai); 1658 break; 1659 case SOF_DAI_IMX_SAI: 1660 ret = sof_link_sai_load(scomp, slink, config, dai); 1661 break; 1662 case SOF_DAI_IMX_ESAI: 1663 ret = sof_link_esai_load(scomp, slink, config, dai); 1664 break; 1665 case SOF_DAI_IMX_MICFIL: 1666 ret = sof_link_micfil_load(scomp, slink, config, dai); 1667 break; 1668 case SOF_DAI_AMD_BT: 1669 ret = sof_link_acp_bt_load(scomp, slink, config, dai); 1670 break; 1671 case SOF_DAI_AMD_SP: 1672 case SOF_DAI_AMD_SP_VIRTUAL: 1673 ret = sof_link_acp_sp_load(scomp, slink, config, dai); 1674 break; 1675 case SOF_DAI_AMD_HS: 1676 case SOF_DAI_AMD_HS_VIRTUAL: 1677 ret = sof_link_acp_hs_load(scomp, slink, config, dai); 1678 break; 1679 case SOF_DAI_AMD_DMIC: 1680 ret = sof_link_acp_dmic_load(scomp, slink, config, dai); 1681 break; 1682 case SOF_DAI_MEDIATEK_AFE: 1683 ret = sof_link_afe_load(scomp, slink, config, dai); 1684 break; 1685 case SOF_DAI_AMD_SDW: 1686 ret = sof_link_acp_sdw_load(scomp, slink, config, dai); 1687 break; 1688 default: 1689 break; 1690 } 1691 if (ret < 0) { 1692 dev_err(scomp->dev, "failed to load config for dai %s\n", dai->name); 1693 goto free_config; 1694 } 1695 1696 kfree(config); 1697 } 1698 1699 return 0; 1700 free_config: 1701 kfree(config); 1702 free_comp: 1703 kfree(comp_dai); 1704 free: 1705 kfree(private); 1706 dai->private = NULL; 1707 return ret; 1708 } 1709 1710 static void sof_ipc3_widget_free_comp_dai(struct snd_sof_widget *swidget) 1711 { 1712 switch (swidget->id) { 1713 case snd_soc_dapm_dai_in: 1714 case snd_soc_dapm_dai_out: 1715 { 1716 struct snd_sof_dai *dai = swidget->private; 1717 struct sof_dai_private_data *dai_data; 1718 1719 if (!dai) 1720 return; 1721 1722 dai_data = dai->private; 1723 if (dai_data) { 1724 kfree(dai_data->comp_dai); 1725 kfree(dai_data->dai_config); 1726 kfree(dai_data); 1727 } 1728 kfree(dai); 1729 break; 1730 } 1731 default: 1732 break; 1733 } 1734 } 1735 1736 static int sof_ipc3_route_setup(struct snd_sof_dev *sdev, struct snd_sof_route *sroute) 1737 { 1738 struct sof_ipc_pipe_comp_connect connect; 1739 int ret; 1740 1741 connect.hdr.size = sizeof(connect); 1742 connect.hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_COMP_CONNECT; 1743 connect.source_id = sroute->src_widget->comp_id; 1744 connect.sink_id = sroute->sink_widget->comp_id; 1745 1746 dev_dbg(sdev->dev, "setting up route %s -> %s\n", 1747 sroute->src_widget->widget->name, 1748 sroute->sink_widget->widget->name); 1749 1750 /* send ipc */ 1751 ret = sof_ipc_tx_message_no_reply(sdev->ipc, &connect, sizeof(connect)); 1752 if (ret < 0) 1753 dev_err(sdev->dev, "%s: route %s -> %s failed\n", __func__, 1754 sroute->src_widget->widget->name, sroute->sink_widget->widget->name); 1755 1756 return ret; 1757 } 1758 1759 static int sof_ipc3_control_load_bytes(struct snd_sof_dev *sdev, struct snd_sof_control *scontrol) 1760 { 1761 struct sof_ipc_ctrl_data *cdata; 1762 size_t priv_size_check; 1763 int ret; 1764 1765 if (scontrol->max_size < (sizeof(*cdata) + sizeof(struct sof_abi_hdr))) { 1766 dev_err(sdev->dev, "%s: insufficient size for a bytes control: %zu.\n", 1767 __func__, scontrol->max_size); 1768 return -EINVAL; 1769 } 1770 1771 if (scontrol->priv_size > scontrol->max_size - sizeof(*cdata)) { 1772 dev_err(sdev->dev, 1773 "%s: bytes data size %zu exceeds max %zu.\n", __func__, 1774 scontrol->priv_size, scontrol->max_size - sizeof(*cdata)); 1775 return -EINVAL; 1776 } 1777 1778 scontrol->ipc_control_data = kzalloc(scontrol->max_size, GFP_KERNEL); 1779 if (!scontrol->ipc_control_data) 1780 return -ENOMEM; 1781 1782 scontrol->size = sizeof(struct sof_ipc_ctrl_data) + scontrol->priv_size; 1783 1784 cdata = scontrol->ipc_control_data; 1785 cdata->cmd = SOF_CTRL_CMD_BINARY; 1786 cdata->index = scontrol->index; 1787 1788 if (scontrol->priv_size > 0) { 1789 memcpy(cdata->data, scontrol->priv, scontrol->priv_size); 1790 kfree(scontrol->priv); 1791 scontrol->priv = NULL; 1792 1793 if (cdata->data->magic != SOF_ABI_MAGIC) { 1794 dev_err(sdev->dev, "Wrong ABI magic 0x%08x.\n", cdata->data->magic); 1795 ret = -EINVAL; 1796 goto err; 1797 } 1798 1799 if (SOF_ABI_VERSION_INCOMPATIBLE(SOF_ABI_VERSION, cdata->data->abi)) { 1800 dev_err(sdev->dev, "Incompatible ABI version 0x%08x.\n", 1801 cdata->data->abi); 1802 ret = -EINVAL; 1803 goto err; 1804 } 1805 1806 priv_size_check = cdata->data->size + sizeof(struct sof_abi_hdr); 1807 if (priv_size_check != scontrol->priv_size) { 1808 dev_err(sdev->dev, "Conflict in bytes (%zu) vs. priv size (%zu).\n", 1809 priv_size_check, scontrol->priv_size); 1810 ret = -EINVAL; 1811 goto err; 1812 } 1813 } 1814 1815 return 0; 1816 err: 1817 kfree(scontrol->ipc_control_data); 1818 scontrol->ipc_control_data = NULL; 1819 return ret; 1820 } 1821 1822 static int sof_ipc3_control_load_volume(struct snd_sof_dev *sdev, struct snd_sof_control *scontrol) 1823 { 1824 struct sof_ipc_ctrl_data *cdata; 1825 int i; 1826 1827 /* init the volume get/put data */ 1828 scontrol->size = struct_size(cdata, chanv, scontrol->num_channels); 1829 1830 scontrol->ipc_control_data = kzalloc(scontrol->size, GFP_KERNEL); 1831 if (!scontrol->ipc_control_data) 1832 return -ENOMEM; 1833 1834 cdata = scontrol->ipc_control_data; 1835 cdata->index = scontrol->index; 1836 1837 /* set cmd for mixer control */ 1838 if (scontrol->max == 1) { 1839 cdata->cmd = SOF_CTRL_CMD_SWITCH; 1840 return 0; 1841 } 1842 1843 cdata->cmd = SOF_CTRL_CMD_VOLUME; 1844 1845 /* set default volume values to 0dB in control */ 1846 for (i = 0; i < scontrol->num_channels; i++) { 1847 cdata->chanv[i].channel = i; 1848 cdata->chanv[i].value = VOL_ZERO_DB; 1849 } 1850 1851 return 0; 1852 } 1853 1854 static int sof_ipc3_control_load_enum(struct snd_sof_dev *sdev, struct snd_sof_control *scontrol) 1855 { 1856 struct sof_ipc_ctrl_data *cdata; 1857 1858 /* init the enum get/put data */ 1859 scontrol->size = struct_size(cdata, chanv, scontrol->num_channels); 1860 1861 scontrol->ipc_control_data = kzalloc(scontrol->size, GFP_KERNEL); 1862 if (!scontrol->ipc_control_data) 1863 return -ENOMEM; 1864 1865 cdata = scontrol->ipc_control_data; 1866 cdata->index = scontrol->index; 1867 cdata->cmd = SOF_CTRL_CMD_ENUM; 1868 1869 return 0; 1870 } 1871 1872 static int sof_ipc3_control_setup(struct snd_sof_dev *sdev, struct snd_sof_control *scontrol) 1873 { 1874 switch (scontrol->info_type) { 1875 case SND_SOC_TPLG_CTL_VOLSW: 1876 case SND_SOC_TPLG_CTL_VOLSW_SX: 1877 case SND_SOC_TPLG_CTL_VOLSW_XR_SX: 1878 return sof_ipc3_control_load_volume(sdev, scontrol); 1879 case SND_SOC_TPLG_CTL_BYTES: 1880 return sof_ipc3_control_load_bytes(sdev, scontrol); 1881 case SND_SOC_TPLG_CTL_ENUM: 1882 case SND_SOC_TPLG_CTL_ENUM_VALUE: 1883 return sof_ipc3_control_load_enum(sdev, scontrol); 1884 default: 1885 break; 1886 } 1887 1888 return 0; 1889 } 1890 1891 static int sof_ipc3_control_free(struct snd_sof_dev *sdev, struct snd_sof_control *scontrol) 1892 { 1893 struct sof_ipc_free fcomp; 1894 1895 fcomp.hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_COMP_FREE; 1896 fcomp.hdr.size = sizeof(fcomp); 1897 fcomp.id = scontrol->comp_id; 1898 1899 /* send IPC to the DSP */ 1900 return sof_ipc_tx_message_no_reply(sdev->ipc, &fcomp, sizeof(fcomp)); 1901 } 1902 1903 /* send pcm params ipc */ 1904 static int sof_ipc3_keyword_detect_pcm_params(struct snd_sof_widget *swidget, int dir) 1905 { 1906 struct snd_soc_component *scomp = swidget->scomp; 1907 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp); 1908 struct snd_pcm_hw_params *params; 1909 struct sof_ipc_pcm_params pcm; 1910 struct snd_sof_pcm *spcm; 1911 int ret; 1912 1913 /* get runtime PCM params using widget's stream name */ 1914 spcm = snd_sof_find_spcm_name(scomp, swidget->widget->sname); 1915 if (!spcm) { 1916 dev_err(scomp->dev, "Cannot find PCM for %s\n", swidget->widget->name); 1917 return -EINVAL; 1918 } 1919 1920 params = &spcm->params[dir]; 1921 1922 /* set IPC PCM params */ 1923 memset(&pcm, 0, sizeof(pcm)); 1924 pcm.hdr.size = sizeof(pcm); 1925 pcm.hdr.cmd = SOF_IPC_GLB_STREAM_MSG | SOF_IPC_STREAM_PCM_PARAMS; 1926 pcm.comp_id = swidget->comp_id; 1927 pcm.params.hdr.size = sizeof(pcm.params); 1928 pcm.params.direction = dir; 1929 pcm.params.sample_valid_bytes = params_width(params) >> 3; 1930 pcm.params.buffer_fmt = SOF_IPC_BUFFER_INTERLEAVED; 1931 pcm.params.rate = params_rate(params); 1932 pcm.params.channels = params_channels(params); 1933 pcm.params.host_period_bytes = params_period_bytes(params); 1934 1935 /* set format */ 1936 switch (params_format(params)) { 1937 case SNDRV_PCM_FORMAT_S16: 1938 pcm.params.frame_fmt = SOF_IPC_FRAME_S16_LE; 1939 break; 1940 case SNDRV_PCM_FORMAT_S24: 1941 pcm.params.frame_fmt = SOF_IPC_FRAME_S24_4LE; 1942 break; 1943 case SNDRV_PCM_FORMAT_S32: 1944 pcm.params.frame_fmt = SOF_IPC_FRAME_S32_LE; 1945 break; 1946 default: 1947 return -EINVAL; 1948 } 1949 1950 /* send IPC to the DSP */ 1951 ret = sof_ipc_tx_message_no_reply(sdev->ipc, &pcm, sizeof(pcm)); 1952 if (ret < 0) 1953 dev_err(scomp->dev, "%s: PCM params failed for %s\n", __func__, 1954 swidget->widget->name); 1955 1956 return ret; 1957 } 1958 1959 /* send stream trigger ipc */ 1960 static int sof_ipc3_keyword_detect_trigger(struct snd_sof_widget *swidget, int cmd) 1961 { 1962 struct snd_soc_component *scomp = swidget->scomp; 1963 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp); 1964 struct sof_ipc_stream stream; 1965 int ret; 1966 1967 /* set IPC stream params */ 1968 stream.hdr.size = sizeof(stream); 1969 stream.hdr.cmd = SOF_IPC_GLB_STREAM_MSG | cmd; 1970 stream.comp_id = swidget->comp_id; 1971 1972 /* send IPC to the DSP */ 1973 ret = sof_ipc_tx_message_no_reply(sdev->ipc, &stream, sizeof(stream)); 1974 if (ret < 0) 1975 dev_err(scomp->dev, "%s: Failed to trigger %s\n", __func__, swidget->widget->name); 1976 1977 return ret; 1978 } 1979 1980 static int sof_ipc3_keyword_dapm_event(struct snd_soc_dapm_widget *w, 1981 struct snd_kcontrol *k, int event) 1982 { 1983 struct snd_sof_widget *swidget = w->dobj.private; 1984 struct snd_soc_component *scomp; 1985 int stream = SNDRV_PCM_STREAM_CAPTURE; 1986 struct snd_sof_pcm *spcm; 1987 int ret = 0; 1988 1989 if (!swidget) 1990 return 0; 1991 1992 scomp = swidget->scomp; 1993 1994 dev_dbg(scomp->dev, "received event %d for widget %s\n", 1995 event, w->name); 1996 1997 /* get runtime PCM params using widget's stream name */ 1998 spcm = snd_sof_find_spcm_name(scomp, swidget->widget->sname); 1999 if (!spcm) { 2000 dev_err(scomp->dev, "%s: Cannot find PCM for %s\n", __func__, 2001 swidget->widget->name); 2002 return -EINVAL; 2003 } 2004 2005 /* process events */ 2006 switch (event) { 2007 case SND_SOC_DAPM_PRE_PMU: 2008 if (spcm->stream[stream].suspend_ignored) { 2009 dev_dbg(scomp->dev, "PRE_PMU event ignored, KWD pipeline is already RUNNING\n"); 2010 return 0; 2011 } 2012 2013 /* set pcm params */ 2014 ret = sof_ipc3_keyword_detect_pcm_params(swidget, stream); 2015 if (ret < 0) { 2016 dev_err(scomp->dev, "%s: Failed to set pcm params for widget %s\n", 2017 __func__, swidget->widget->name); 2018 break; 2019 } 2020 2021 /* start trigger */ 2022 ret = sof_ipc3_keyword_detect_trigger(swidget, SOF_IPC_STREAM_TRIG_START); 2023 if (ret < 0) 2024 dev_err(scomp->dev, "%s: Failed to trigger widget %s\n", __func__, 2025 swidget->widget->name); 2026 break; 2027 case SND_SOC_DAPM_POST_PMD: 2028 if (spcm->stream[stream].suspend_ignored) { 2029 dev_dbg(scomp->dev, 2030 "POST_PMD event ignored, KWD pipeline will remain RUNNING\n"); 2031 return 0; 2032 } 2033 2034 /* stop trigger */ 2035 ret = sof_ipc3_keyword_detect_trigger(swidget, SOF_IPC_STREAM_TRIG_STOP); 2036 if (ret < 0) 2037 dev_err(scomp->dev, "%s: Failed to trigger widget %s\n", __func__, 2038 swidget->widget->name); 2039 2040 /* pcm free */ 2041 ret = sof_ipc3_keyword_detect_trigger(swidget, SOF_IPC_STREAM_PCM_FREE); 2042 if (ret < 0) 2043 dev_err(scomp->dev, "%s: Failed to free PCM for widget %s\n", __func__, 2044 swidget->widget->name); 2045 break; 2046 default: 2047 break; 2048 } 2049 2050 return ret; 2051 } 2052 2053 /* event handlers for keyword detect component */ 2054 static const struct snd_soc_tplg_widget_events sof_kwd_events[] = { 2055 {SOF_KEYWORD_DETECT_DAPM_EVENT, sof_ipc3_keyword_dapm_event}, 2056 }; 2057 2058 static int sof_ipc3_widget_bind_event(struct snd_soc_component *scomp, 2059 struct snd_sof_widget *swidget, u16 event_type) 2060 { 2061 struct sof_ipc_comp *ipc_comp; 2062 2063 /* validate widget event type */ 2064 switch (event_type) { 2065 case SOF_KEYWORD_DETECT_DAPM_EVENT: 2066 /* only KEYWORD_DETECT comps should handle this */ 2067 if (swidget->id != snd_soc_dapm_effect) 2068 break; 2069 2070 ipc_comp = swidget->private; 2071 if (ipc_comp && ipc_comp->type != SOF_COMP_KEYWORD_DETECT) 2072 break; 2073 2074 /* bind event to keyword detect comp */ 2075 return snd_soc_tplg_widget_bind_event(swidget->widget, sof_kwd_events, 2076 ARRAY_SIZE(sof_kwd_events), event_type); 2077 default: 2078 break; 2079 } 2080 2081 dev_err(scomp->dev, "Invalid event type %d for widget %s\n", event_type, 2082 swidget->widget->name); 2083 2084 return -EINVAL; 2085 } 2086 2087 static int sof_ipc3_complete_pipeline(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget) 2088 { 2089 struct sof_ipc_pipe_ready ready; 2090 int ret; 2091 2092 dev_dbg(sdev->dev, "tplg: complete pipeline %s id %d\n", 2093 swidget->widget->name, swidget->comp_id); 2094 2095 memset(&ready, 0, sizeof(ready)); 2096 ready.hdr.size = sizeof(ready); 2097 ready.hdr.cmd = SOF_IPC_GLB_TPLG_MSG | SOF_IPC_TPLG_PIPE_COMPLETE; 2098 ready.comp_id = swidget->comp_id; 2099 2100 ret = sof_ipc_tx_message_no_reply(sdev->ipc, &ready, sizeof(ready)); 2101 if (ret < 0) 2102 return ret; 2103 2104 return 1; 2105 } 2106 2107 static int sof_ipc3_widget_free(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget) 2108 { 2109 struct sof_ipc_free ipc_free = { 2110 .hdr = { 2111 .size = sizeof(ipc_free), 2112 .cmd = SOF_IPC_GLB_TPLG_MSG, 2113 }, 2114 .id = swidget->comp_id, 2115 }; 2116 int ret; 2117 2118 if (!swidget->private) 2119 return 0; 2120 2121 switch (swidget->id) { 2122 case snd_soc_dapm_scheduler: 2123 { 2124 ipc_free.hdr.cmd |= SOF_IPC_TPLG_PIPE_FREE; 2125 break; 2126 } 2127 case snd_soc_dapm_buffer: 2128 ipc_free.hdr.cmd |= SOF_IPC_TPLG_BUFFER_FREE; 2129 break; 2130 default: 2131 ipc_free.hdr.cmd |= SOF_IPC_TPLG_COMP_FREE; 2132 break; 2133 } 2134 2135 ret = sof_ipc_tx_message_no_reply(sdev->ipc, &ipc_free, sizeof(ipc_free)); 2136 if (ret < 0) 2137 dev_err(sdev->dev, "failed to free widget %s\n", swidget->widget->name); 2138 2139 return ret; 2140 } 2141 2142 static int sof_ipc3_dai_config(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget, 2143 unsigned int flags, struct snd_sof_dai_config_data *data) 2144 { 2145 struct sof_ipc_fw_version *v = &sdev->fw_ready.version; 2146 struct snd_sof_dai *dai = swidget->private; 2147 struct sof_dai_private_data *private; 2148 struct sof_ipc_dai_config *config; 2149 int ret = 0; 2150 2151 if (!dai || !dai->private) { 2152 dev_err(sdev->dev, "No private data for DAI %s\n", swidget->widget->name); 2153 return -EINVAL; 2154 } 2155 2156 private = dai->private; 2157 if (!private->dai_config) { 2158 dev_err(sdev->dev, "No config for DAI %s\n", dai->name); 2159 return -EINVAL; 2160 } 2161 2162 config = &private->dai_config[dai->current_config]; 2163 if (!config) { 2164 dev_err(sdev->dev, "Invalid current config for DAI %s\n", dai->name); 2165 return -EINVAL; 2166 } 2167 2168 switch (config->type) { 2169 case SOF_DAI_INTEL_SSP: 2170 /* 2171 * DAI_CONFIG IPC during hw_params/hw_free for SSP DAI's is not supported in older 2172 * firmware 2173 */ 2174 if (v->abi_version < SOF_ABI_VER(3, 18, 0) && 2175 ((flags & SOF_DAI_CONFIG_FLAGS_HW_PARAMS) || 2176 (flags & SOF_DAI_CONFIG_FLAGS_HW_FREE))) 2177 return 0; 2178 break; 2179 case SOF_DAI_INTEL_HDA: 2180 if (data) 2181 config->hda.link_dma_ch = data->dai_data; 2182 break; 2183 case SOF_DAI_INTEL_ALH: 2184 if (data) { 2185 /* save the dai_index during hw_params and reuse it for hw_free */ 2186 if (flags & SOF_DAI_CONFIG_FLAGS_HW_PARAMS) { 2187 /* Subtract the base to match the FW dai index. */ 2188 if (data->dai_index < INTEL_ALH_DAI_INDEX_BASE) { 2189 dev_err(sdev->dev, 2190 "Invalid ALH dai index %d, only Pin numbers >= %d can be used\n", 2191 config->dai_index, INTEL_ALH_DAI_INDEX_BASE); 2192 return -EINVAL; 2193 } 2194 config->dai_index = data->dai_index - INTEL_ALH_DAI_INDEX_BASE; 2195 } 2196 config->alh.stream_id = data->dai_data; 2197 } 2198 break; 2199 default: 2200 break; 2201 } 2202 2203 /* 2204 * The dai_config op is invoked several times and the flags argument varies as below: 2205 * BE DAI hw_params: When the op is invoked during the BE DAI hw_params, flags contains 2206 * SOF_DAI_CONFIG_FLAGS_HW_PARAMS along with quirks 2207 * FE DAI hw_params: When invoked during FE DAI hw_params after the DAI widget has 2208 * just been set up in the DSP, flags is set to SOF_DAI_CONFIG_FLAGS_HW_PARAMS with no 2209 * quirks 2210 * BE DAI trigger: When invoked during the BE DAI trigger, flags is set to 2211 * SOF_DAI_CONFIG_FLAGS_PAUSE and contains no quirks 2212 * BE DAI hw_free: When invoked during the BE DAI hw_free, flags is set to 2213 * SOF_DAI_CONFIG_FLAGS_HW_FREE and contains no quirks 2214 * FE DAI hw_free: When invoked during the FE DAI hw_free, flags is set to 2215 * SOF_DAI_CONFIG_FLAGS_HW_FREE and contains no quirks 2216 * 2217 * The DAI_CONFIG IPC is sent to the DSP, only after the widget is set up during the FE 2218 * DAI hw_params. But since the BE DAI hw_params precedes the FE DAI hw_params, the quirks 2219 * need to be preserved when assigning the flags before sending the IPC. 2220 * For the case of PAUSE/HW_FREE, since there are no quirks, flags can be used as is. 2221 */ 2222 2223 if (flags & SOF_DAI_CONFIG_FLAGS_HW_PARAMS) { 2224 /* Clear stale command */ 2225 config->flags &= ~SOF_DAI_CONFIG_FLAGS_CMD_MASK; 2226 config->flags |= flags; 2227 } else { 2228 config->flags = flags; 2229 } 2230 2231 /* only send the IPC if the widget is set up in the DSP */ 2232 if (swidget->use_count > 0) { 2233 ret = sof_ipc_tx_message_no_reply(sdev->ipc, config, config->hdr.size); 2234 if (ret < 0) 2235 dev_err(sdev->dev, "Failed to set dai config for %s\n", dai->name); 2236 2237 /* clear the flags once the IPC has been sent even if it fails */ 2238 config->flags = SOF_DAI_CONFIG_FLAGS_NONE; 2239 } 2240 2241 return ret; 2242 } 2243 2244 static int sof_ipc3_widget_setup(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget) 2245 { 2246 int ret; 2247 2248 if (!swidget->private) 2249 return 0; 2250 2251 switch (swidget->id) { 2252 case snd_soc_dapm_dai_in: 2253 case snd_soc_dapm_dai_out: 2254 { 2255 struct snd_sof_dai *dai = swidget->private; 2256 struct sof_dai_private_data *dai_data = dai->private; 2257 struct sof_ipc_comp *comp = &dai_data->comp_dai->comp; 2258 2259 ret = sof_ipc_tx_message_no_reply(sdev->ipc, dai_data->comp_dai, comp->hdr.size); 2260 break; 2261 } 2262 case snd_soc_dapm_scheduler: 2263 { 2264 struct sof_ipc_pipe_new *pipeline; 2265 2266 pipeline = swidget->private; 2267 ret = sof_ipc_tx_message_no_reply(sdev->ipc, pipeline, sizeof(*pipeline)); 2268 break; 2269 } 2270 default: 2271 { 2272 struct sof_ipc_cmd_hdr *hdr; 2273 2274 hdr = swidget->private; 2275 ret = sof_ipc_tx_message_no_reply(sdev->ipc, swidget->private, hdr->size); 2276 break; 2277 } 2278 } 2279 if (ret < 0) 2280 dev_err(sdev->dev, "Failed to setup widget %s\n", swidget->widget->name); 2281 2282 return ret; 2283 } 2284 2285 static int sof_ipc3_set_up_all_pipelines(struct snd_sof_dev *sdev, bool verify) 2286 { 2287 struct sof_ipc_fw_version *v = &sdev->fw_ready.version; 2288 struct snd_sof_widget *swidget; 2289 struct snd_sof_route *sroute; 2290 int ret; 2291 2292 /* restore pipeline components */ 2293 list_for_each_entry(swidget, &sdev->widget_list, list) { 2294 /* only set up the widgets belonging to static pipelines */ 2295 if (!verify && swidget->dynamic_pipeline_widget) 2296 continue; 2297 2298 /* 2299 * For older firmware, skip scheduler widgets in this loop, 2300 * sof_widget_setup() will be called in the 'complete pipeline' loop 2301 */ 2302 if (v->abi_version < SOF_ABI_VER(3, 19, 0) && 2303 swidget->id == snd_soc_dapm_scheduler) 2304 continue; 2305 2306 /* update DAI config. The IPC will be sent in sof_widget_setup() */ 2307 if (WIDGET_IS_DAI(swidget->id)) { 2308 struct snd_sof_dai *dai = swidget->private; 2309 struct sof_dai_private_data *private; 2310 struct sof_ipc_dai_config *config; 2311 2312 if (!dai || !dai->private) 2313 continue; 2314 private = dai->private; 2315 if (!private->dai_config) 2316 continue; 2317 2318 config = private->dai_config; 2319 /* 2320 * The link DMA channel would be invalidated for running 2321 * streams but not for streams that were in the PAUSED 2322 * state during suspend. So invalidate it here before setting 2323 * the dai config in the DSP. 2324 */ 2325 if (config->type == SOF_DAI_INTEL_HDA) 2326 config->hda.link_dma_ch = DMA_CHAN_INVALID; 2327 } 2328 2329 ret = sof_widget_setup(sdev, swidget); 2330 if (ret < 0) 2331 return ret; 2332 } 2333 2334 /* restore pipeline connections */ 2335 list_for_each_entry(sroute, &sdev->route_list, list) { 2336 /* only set up routes belonging to static pipelines */ 2337 if (!verify && (sroute->src_widget->dynamic_pipeline_widget || 2338 sroute->sink_widget->dynamic_pipeline_widget)) 2339 continue; 2340 2341 /* 2342 * For virtual routes, both sink and source are not buffer. IPC3 only supports 2343 * connections between a buffer and a component. Ignore the rest. 2344 */ 2345 if (sroute->src_widget->id != snd_soc_dapm_buffer && 2346 sroute->sink_widget->id != snd_soc_dapm_buffer) 2347 continue; 2348 2349 ret = sof_route_setup(sdev, sroute->src_widget->widget, 2350 sroute->sink_widget->widget); 2351 if (ret < 0) { 2352 dev_err(sdev->dev, "%s: route set up failed\n", __func__); 2353 return ret; 2354 } 2355 } 2356 2357 /* complete pipeline */ 2358 list_for_each_entry(swidget, &sdev->widget_list, list) { 2359 switch (swidget->id) { 2360 case snd_soc_dapm_scheduler: 2361 /* only complete static pipelines */ 2362 if (!verify && swidget->dynamic_pipeline_widget) 2363 continue; 2364 2365 if (v->abi_version < SOF_ABI_VER(3, 19, 0)) { 2366 ret = sof_widget_setup(sdev, swidget); 2367 if (ret < 0) 2368 return ret; 2369 } 2370 2371 swidget->spipe->complete = sof_ipc3_complete_pipeline(sdev, swidget); 2372 if (swidget->spipe->complete < 0) 2373 return swidget->spipe->complete; 2374 break; 2375 default: 2376 break; 2377 } 2378 } 2379 2380 return 0; 2381 } 2382 2383 /* 2384 * Free the PCM, its associated widgets and set the prepared flag to false for all PCMs that 2385 * did not get suspended(ex: paused streams) so the widgets can be set up again during resume. 2386 */ 2387 static int sof_tear_down_left_over_pipelines(struct snd_sof_dev *sdev) 2388 { 2389 struct snd_sof_widget *swidget; 2390 int ret; 2391 2392 /* 2393 * free all PCMs and their associated DAPM widgets if their connected DAPM widget 2394 * list is not NULL. This should only be true for paused streams at this point. 2395 * This is equivalent to the handling of FE DAI suspend trigger for running streams. 2396 */ 2397 ret = sof_pcm_free_all_streams(sdev); 2398 if (ret) 2399 return ret; 2400 2401 /* 2402 * free any left over DAI widgets. This is equivalent to the handling of suspend trigger 2403 * for the BE DAI for running streams. 2404 */ 2405 list_for_each_entry(swidget, &sdev->widget_list, list) 2406 if (WIDGET_IS_DAI(swidget->id) && swidget->use_count == 1) { 2407 ret = sof_widget_free(sdev, swidget); 2408 if (ret < 0) 2409 return ret; 2410 } 2411 2412 return 0; 2413 } 2414 2415 static int sof_ipc3_free_widgets_in_list(struct snd_sof_dev *sdev, bool include_scheduler, 2416 bool *dyn_widgets, bool verify) 2417 { 2418 struct sof_ipc_fw_version *v = &sdev->fw_ready.version; 2419 struct snd_sof_widget *swidget; 2420 int ret; 2421 2422 list_for_each_entry(swidget, &sdev->widget_list, list) { 2423 if (swidget->dynamic_pipeline_widget) { 2424 *dyn_widgets = true; 2425 continue; 2426 } 2427 2428 /* Do not free widgets for static pipelines with FW older than SOF2.2 */ 2429 if (!verify && !swidget->dynamic_pipeline_widget && 2430 SOF_FW_VER(v->major, v->minor, v->micro) < SOF_FW_VER(2, 2, 0)) { 2431 scoped_guard(mutex, &swidget->setup_mutex) 2432 swidget->use_count = 0; 2433 2434 if (swidget->spipe) 2435 swidget->spipe->complete = 0; 2436 continue; 2437 } 2438 2439 if (include_scheduler && swidget->id != snd_soc_dapm_scheduler) 2440 continue; 2441 2442 if (!include_scheduler && swidget->id == snd_soc_dapm_scheduler) 2443 continue; 2444 2445 ret = sof_widget_free(sdev, swidget); 2446 if (ret < 0) 2447 return ret; 2448 } 2449 2450 return 0; 2451 } 2452 2453 /* 2454 * For older firmware, this function doesn't free widgets for static pipelines during suspend. 2455 * It only resets use_count for all widgets. 2456 */ 2457 static int sof_ipc3_tear_down_all_pipelines(struct snd_sof_dev *sdev, bool verify) 2458 { 2459 struct sof_ipc_fw_version *v = &sdev->fw_ready.version; 2460 struct snd_sof_widget *swidget; 2461 struct snd_sof_route *sroute; 2462 bool dyn_widgets = false; 2463 int ret; 2464 2465 /* 2466 * This function is called during suspend and for one-time topology verification during 2467 * first boot. In both cases, there is no need to protect swidget->use_count and 2468 * sroute->setup because during suspend all running streams are suspended and during 2469 * topology loading the sound card unavailable to open PCMs. Do not free the scheduler 2470 * widgets yet so that the secondary cores do not get powered down before all the widgets 2471 * associated with the scheduler are freed. 2472 */ 2473 ret = sof_ipc3_free_widgets_in_list(sdev, false, &dyn_widgets, verify); 2474 if (ret < 0) 2475 return ret; 2476 2477 /* 2478 * Tear down all pipelines associated with PCMs that did not get suspended 2479 * and unset the prepare flag so that they can be set up again during resume. 2480 * Skip this step for older firmware unless topology has any 2481 * dynamic pipeline (in which case the step is mandatory). 2482 */ 2483 if (!verify && (dyn_widgets || SOF_FW_VER(v->major, v->minor, v->micro) >= 2484 SOF_FW_VER(2, 2, 0))) { 2485 ret = sof_tear_down_left_over_pipelines(sdev); 2486 if (ret < 0) { 2487 dev_err(sdev->dev, "failed to tear down paused pipelines\n"); 2488 return ret; 2489 } 2490 } 2491 2492 /* free all the scheduler widgets now. This will also power down the secondary cores */ 2493 ret = sof_ipc3_free_widgets_in_list(sdev, true, &dyn_widgets, verify); 2494 if (ret < 0) 2495 return ret; 2496 2497 list_for_each_entry(sroute, &sdev->route_list, list) 2498 sroute->setup = false; 2499 2500 /* 2501 * before suspending, make sure the refcounts are all zeroed out. There's no way 2502 * to recover at this point but this will help root cause bad sequences leading to 2503 * more issues on resume 2504 */ 2505 list_for_each_entry(swidget, &sdev->widget_list, list) { 2506 if (swidget->use_count != 0) { 2507 dev_err(sdev->dev, "%s: widget %s is still in use: count %d\n", 2508 __func__, swidget->widget->name, swidget->use_count); 2509 } 2510 } 2511 2512 return 0; 2513 } 2514 2515 static int sof_ipc3_dai_get_param(struct snd_sof_dev *sdev, struct snd_sof_dai *dai, int param_type) 2516 { 2517 struct sof_dai_private_data *private = dai->private; 2518 2519 if (!private || !private->dai_config) 2520 return 0; 2521 2522 switch (private->dai_config->type) { 2523 case SOF_DAI_INTEL_SSP: 2524 switch (param_type) { 2525 case SOF_DAI_PARAM_INTEL_SSP_MCLK: 2526 return private->dai_config->ssp.mclk_rate; 2527 case SOF_DAI_PARAM_INTEL_SSP_BCLK: 2528 return private->dai_config->ssp.bclk_rate; 2529 case SOF_DAI_PARAM_INTEL_SSP_TDM_SLOTS: 2530 return private->dai_config->ssp.tdm_slots; 2531 default: 2532 dev_err(sdev->dev, "invalid SSP param %d\n", param_type); 2533 break; 2534 } 2535 break; 2536 default: 2537 /* not yet implemented for platforms other than the above */ 2538 dev_err(sdev->dev, "DAI type %d not supported yet!\n", private->dai_config->type); 2539 break; 2540 } 2541 2542 return -EINVAL; 2543 } 2544 2545 static int sof_ipc3_parse_manifest(struct snd_soc_component *scomp, int index, 2546 struct snd_soc_tplg_manifest *man) 2547 { 2548 u32 size = le32_to_cpu(man->priv.size); 2549 u32 abi_version; 2550 2551 /* backward compatible with tplg without ABI info */ 2552 if (!size) { 2553 dev_dbg(scomp->dev, "No topology ABI info\n"); 2554 return 0; 2555 } 2556 2557 if (size != SOF_IPC3_TPLG_ABI_SIZE) { 2558 dev_err(scomp->dev, "%s: Invalid topology ABI size: %u\n", 2559 __func__, size); 2560 return -EINVAL; 2561 } 2562 2563 dev_info(scomp->dev, 2564 "Topology: ABI %d:%d:%d Kernel ABI %d:%d:%d\n", 2565 man->priv.data[0], man->priv.data[1], man->priv.data[2], 2566 SOF_ABI_MAJOR, SOF_ABI_MINOR, SOF_ABI_PATCH); 2567 2568 abi_version = SOF_ABI_VER(man->priv.data[0], man->priv.data[1], man->priv.data[2]); 2569 2570 if (SOF_ABI_VERSION_INCOMPATIBLE(SOF_ABI_VERSION, abi_version)) { 2571 dev_err(scomp->dev, "%s: Incompatible topology ABI version\n", __func__); 2572 return -EINVAL; 2573 } 2574 2575 if (IS_ENABLED(CONFIG_SND_SOC_SOF_STRICT_ABI_CHECKS) && 2576 SOF_ABI_VERSION_MINOR(abi_version) > SOF_ABI_MINOR) { 2577 dev_err(scomp->dev, "%s: Topology ABI is more recent than kernel\n", __func__); 2578 return -EINVAL; 2579 } 2580 2581 return 0; 2582 } 2583 2584 static int sof_ipc3_link_setup(struct snd_sof_dev *sdev, struct snd_soc_dai_link *link) 2585 { 2586 if (link->no_pcm) 2587 return 0; 2588 2589 /* 2590 * set default trigger order for all links. Exceptions to 2591 * the rule will be handled in sof_pcm_dai_link_fixup() 2592 * For playback, the sequence is the following: start FE, 2593 * start BE, stop BE, stop FE; for Capture the sequence is 2594 * inverted start BE, start FE, stop FE, stop BE 2595 */ 2596 link->trigger[SNDRV_PCM_STREAM_PLAYBACK] = SND_SOC_DPCM_TRIGGER_PRE; 2597 link->trigger[SNDRV_PCM_STREAM_CAPTURE] = SND_SOC_DPCM_TRIGGER_POST; 2598 2599 return 0; 2600 } 2601 2602 /* token list for each topology object */ 2603 static enum sof_tokens host_token_list[] = { 2604 SOF_CORE_TOKENS, 2605 SOF_COMP_EXT_TOKENS, 2606 SOF_PCM_TOKENS, 2607 SOF_COMP_TOKENS, 2608 }; 2609 2610 static enum sof_tokens comp_generic_token_list[] = { 2611 SOF_CORE_TOKENS, 2612 SOF_COMP_EXT_TOKENS, 2613 SOF_COMP_TOKENS, 2614 }; 2615 2616 static enum sof_tokens buffer_token_list[] = { 2617 SOF_BUFFER_TOKENS, 2618 }; 2619 2620 static enum sof_tokens pipeline_token_list[] = { 2621 SOF_CORE_TOKENS, 2622 SOF_COMP_EXT_TOKENS, 2623 SOF_PIPELINE_TOKENS, 2624 SOF_SCHED_TOKENS, 2625 }; 2626 2627 static enum sof_tokens asrc_token_list[] = { 2628 SOF_CORE_TOKENS, 2629 SOF_COMP_EXT_TOKENS, 2630 SOF_ASRC_TOKENS, 2631 SOF_COMP_TOKENS, 2632 }; 2633 2634 static enum sof_tokens src_token_list[] = { 2635 SOF_CORE_TOKENS, 2636 SOF_COMP_EXT_TOKENS, 2637 SOF_SRC_TOKENS, 2638 SOF_COMP_TOKENS 2639 }; 2640 2641 static enum sof_tokens pga_token_list[] = { 2642 SOF_CORE_TOKENS, 2643 SOF_COMP_EXT_TOKENS, 2644 SOF_VOLUME_TOKENS, 2645 SOF_COMP_TOKENS, 2646 }; 2647 2648 static enum sof_tokens dai_token_list[] = { 2649 SOF_CORE_TOKENS, 2650 SOF_COMP_EXT_TOKENS, 2651 SOF_DAI_TOKENS, 2652 SOF_COMP_TOKENS, 2653 }; 2654 2655 static enum sof_tokens process_token_list[] = { 2656 SOF_CORE_TOKENS, 2657 SOF_COMP_EXT_TOKENS, 2658 SOF_PROCESS_TOKENS, 2659 SOF_COMP_TOKENS, 2660 }; 2661 2662 static const struct sof_ipc_tplg_widget_ops tplg_ipc3_widget_ops[SND_SOC_DAPM_TYPE_COUNT] = { 2663 [snd_soc_dapm_aif_in] = {sof_ipc3_widget_setup_comp_host, sof_ipc3_widget_free_comp, 2664 host_token_list, ARRAY_SIZE(host_token_list), NULL}, 2665 [snd_soc_dapm_aif_out] = {sof_ipc3_widget_setup_comp_host, sof_ipc3_widget_free_comp, 2666 host_token_list, ARRAY_SIZE(host_token_list), NULL}, 2667 2668 [snd_soc_dapm_dai_in] = {sof_ipc3_widget_setup_comp_dai, sof_ipc3_widget_free_comp_dai, 2669 dai_token_list, ARRAY_SIZE(dai_token_list), NULL}, 2670 [snd_soc_dapm_dai_out] = {sof_ipc3_widget_setup_comp_dai, sof_ipc3_widget_free_comp_dai, 2671 dai_token_list, ARRAY_SIZE(dai_token_list), NULL}, 2672 [snd_soc_dapm_buffer] = {sof_ipc3_widget_setup_comp_buffer, sof_ipc3_widget_free_comp, 2673 buffer_token_list, ARRAY_SIZE(buffer_token_list), NULL}, 2674 [snd_soc_dapm_mixer] = {sof_ipc3_widget_setup_comp_mixer, sof_ipc3_widget_free_comp, 2675 comp_generic_token_list, ARRAY_SIZE(comp_generic_token_list), 2676 NULL}, 2677 [snd_soc_dapm_src] = {sof_ipc3_widget_setup_comp_src, sof_ipc3_widget_free_comp, 2678 src_token_list, ARRAY_SIZE(src_token_list), NULL}, 2679 [snd_soc_dapm_asrc] = {sof_ipc3_widget_setup_comp_asrc, sof_ipc3_widget_free_comp, 2680 asrc_token_list, ARRAY_SIZE(asrc_token_list), NULL}, 2681 [snd_soc_dapm_siggen] = {sof_ipc3_widget_setup_comp_tone, sof_ipc3_widget_free_comp, 2682 comp_generic_token_list, ARRAY_SIZE(comp_generic_token_list), 2683 NULL}, 2684 [snd_soc_dapm_scheduler] = {sof_ipc3_widget_setup_comp_pipeline, sof_ipc3_widget_free_comp, 2685 pipeline_token_list, ARRAY_SIZE(pipeline_token_list), NULL}, 2686 [snd_soc_dapm_pga] = {sof_ipc3_widget_setup_comp_pga, sof_ipc3_widget_free_comp, 2687 pga_token_list, ARRAY_SIZE(pga_token_list), NULL}, 2688 [snd_soc_dapm_mux] = {sof_ipc3_widget_setup_comp_mux, sof_ipc3_widget_free_comp, 2689 comp_generic_token_list, ARRAY_SIZE(comp_generic_token_list), NULL}, 2690 [snd_soc_dapm_demux] = {sof_ipc3_widget_setup_comp_mux, sof_ipc3_widget_free_comp, 2691 comp_generic_token_list, ARRAY_SIZE(comp_generic_token_list), 2692 NULL}, 2693 [snd_soc_dapm_effect] = {sof_widget_update_ipc_comp_process, sof_ipc3_widget_free_comp, 2694 process_token_list, ARRAY_SIZE(process_token_list), 2695 sof_ipc3_widget_bind_event}, 2696 }; 2697 2698 const struct sof_ipc_tplg_ops ipc3_tplg_ops = { 2699 .widget = tplg_ipc3_widget_ops, 2700 .control = &tplg_ipc3_control_ops, 2701 .route_setup = sof_ipc3_route_setup, 2702 .control_setup = sof_ipc3_control_setup, 2703 .control_free = sof_ipc3_control_free, 2704 .pipeline_complete = sof_ipc3_complete_pipeline, 2705 .token_list = ipc3_token_list, 2706 .widget_free = sof_ipc3_widget_free, 2707 .widget_setup = sof_ipc3_widget_setup, 2708 .dai_config = sof_ipc3_dai_config, 2709 .dai_get_param = sof_ipc3_dai_get_param, 2710 .set_up_all_pipelines = sof_ipc3_set_up_all_pipelines, 2711 .tear_down_all_pipelines = sof_ipc3_tear_down_all_pipelines, 2712 .parse_manifest = sof_ipc3_parse_manifest, 2713 .link_setup = sof_ipc3_link_setup, 2714 }; 2715