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