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) 2018 Intel Corporation 7 // 8 // Authors: Keyon Jie <yang.jie@linux.intel.com> 9 // 10 11 #include <sound/pcm_params.h> 12 #include <sound/hdaudio_ext.h> 13 #include <sound/hda-mlink.h> 14 #include <sound/hda_register.h> 15 #include <sound/intel-nhlt.h> 16 #include <sound/sof/ipc4/header.h> 17 #include <uapi/sound/sof/header.h> 18 #include "../ipc4-priv.h" 19 #include "../ipc4-topology.h" 20 #include "../sof-priv.h" 21 #include "../sof-audio.h" 22 #include "hda.h" 23 24 /* 25 * The default method is to fetch NHLT from BIOS. With this parameter set 26 * it is possible to override that with NHLT in the SOF topology manifest. 27 */ 28 static bool hda_use_tplg_nhlt; 29 module_param_named(sof_use_tplg_nhlt, hda_use_tplg_nhlt, bool, 0444); 30 MODULE_PARM_DESC(sof_use_tplg_nhlt, "SOF topology nhlt override"); 31 32 int hda_dai_config(struct snd_soc_dapm_widget *w, unsigned int flags, 33 struct snd_sof_dai_config_data *data) 34 { 35 struct snd_sof_widget *swidget = w->dobj.private; 36 const struct sof_ipc_tplg_ops *tplg_ops; 37 struct snd_sof_dev *sdev; 38 int ret; 39 40 if (!swidget) 41 return 0; 42 43 sdev = widget_to_sdev(w); 44 tplg_ops = sof_ipc_get_ops(sdev, tplg); 45 46 if (tplg_ops && tplg_ops->dai_config) { 47 ret = tplg_ops->dai_config(sdev, swidget, flags, data); 48 if (ret < 0) { 49 dev_err(sdev->dev, "DAI config with flags %x failed for widget %s\n", 50 flags, w->name); 51 return ret; 52 } 53 } 54 55 return 0; 56 } 57 EXPORT_SYMBOL_NS(hda_dai_config, SND_SOC_SOF_INTEL_HDA_COMMON); 58 59 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_LINK) 60 61 static struct snd_sof_dev *dai_to_sdev(struct snd_pcm_substream *substream, 62 struct snd_soc_dai *cpu_dai) 63 { 64 struct snd_soc_dapm_widget *w = snd_soc_dai_get_widget(cpu_dai, substream->stream); 65 66 return widget_to_sdev(w); 67 } 68 69 static const struct hda_dai_widget_dma_ops * 70 hda_dai_get_ops(struct snd_pcm_substream *substream, struct snd_soc_dai *cpu_dai) 71 { 72 struct snd_soc_dapm_widget *w = snd_soc_dai_get_widget(cpu_dai, substream->stream); 73 struct snd_sof_widget *swidget = w->dobj.private; 74 struct snd_sof_dev *sdev; 75 struct snd_sof_dai *sdai; 76 77 sdev = widget_to_sdev(w); 78 79 if (!swidget) { 80 dev_err(sdev->dev, "%s: swidget is NULL\n", __func__); 81 return NULL; 82 } 83 84 if (sdev->dspless_mode_selected) 85 return hda_select_dai_widget_ops(sdev, swidget); 86 87 sdai = swidget->private; 88 89 /* select and set the DAI widget ops if not set already */ 90 if (!sdai->platform_private) { 91 const struct hda_dai_widget_dma_ops *ops = 92 hda_select_dai_widget_ops(sdev, swidget); 93 if (!ops) 94 return NULL; 95 96 /* check if mandatory ops are set */ 97 if (!ops || !ops->get_hext_stream) 98 return NULL; 99 100 sdai->platform_private = ops; 101 } 102 103 return sdai->platform_private; 104 } 105 106 int hda_link_dma_cleanup(struct snd_pcm_substream *substream, struct hdac_ext_stream *hext_stream, 107 struct snd_soc_dai *cpu_dai) 108 { 109 const struct hda_dai_widget_dma_ops *ops = hda_dai_get_ops(substream, cpu_dai); 110 struct sof_intel_hda_stream *hda_stream; 111 struct hdac_ext_link *hlink; 112 struct snd_sof_dev *sdev; 113 int stream_tag; 114 115 if (!ops) { 116 dev_err(cpu_dai->dev, "DAI widget ops not set\n"); 117 return -EINVAL; 118 } 119 120 sdev = dai_to_sdev(substream, cpu_dai); 121 122 hlink = ops->get_hlink(sdev, substream); 123 if (!hlink) 124 return -EINVAL; 125 126 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 127 stream_tag = hdac_stream(hext_stream)->stream_tag; 128 snd_hdac_ext_bus_link_clear_stream_id(hlink, stream_tag); 129 } 130 131 if (ops->release_hext_stream) 132 ops->release_hext_stream(sdev, cpu_dai, substream); 133 134 hext_stream->link_prepared = 0; 135 136 /* free the host DMA channel reserved by hostless streams */ 137 hda_stream = hstream_to_sof_hda_stream(hext_stream); 138 hda_stream->host_reserved = 0; 139 140 return 0; 141 } 142 143 static int hda_link_dma_hw_params(struct snd_pcm_substream *substream, 144 struct snd_pcm_hw_params *params, struct snd_soc_dai *cpu_dai) 145 { 146 const struct hda_dai_widget_dma_ops *ops = hda_dai_get_ops(substream, cpu_dai); 147 struct hdac_ext_stream *hext_stream; 148 struct hdac_stream *hstream; 149 struct hdac_ext_link *hlink; 150 struct snd_sof_dev *sdev; 151 int stream_tag; 152 153 if (!ops) { 154 dev_err(cpu_dai->dev, "DAI widget ops not set\n"); 155 return -EINVAL; 156 } 157 158 sdev = dai_to_sdev(substream, cpu_dai); 159 160 hlink = ops->get_hlink(sdev, substream); 161 if (!hlink) 162 return -EINVAL; 163 164 hext_stream = ops->get_hext_stream(sdev, cpu_dai, substream); 165 166 if (!hext_stream) { 167 if (ops->assign_hext_stream) 168 hext_stream = ops->assign_hext_stream(sdev, cpu_dai, substream); 169 } 170 171 if (!hext_stream) 172 return -EBUSY; 173 174 hstream = &hext_stream->hstream; 175 stream_tag = hstream->stream_tag; 176 177 if (hext_stream->hstream.direction == SNDRV_PCM_STREAM_PLAYBACK) 178 snd_hdac_ext_bus_link_set_stream_id(hlink, stream_tag); 179 180 /* set the hdac_stream in the codec dai */ 181 if (ops->codec_dai_set_stream) 182 ops->codec_dai_set_stream(sdev, substream, hstream); 183 184 if (ops->reset_hext_stream) 185 ops->reset_hext_stream(sdev, hext_stream); 186 187 if (ops->calc_stream_format && ops->setup_hext_stream) { 188 unsigned int format_val = ops->calc_stream_format(sdev, substream, params); 189 190 ops->setup_hext_stream(sdev, hext_stream, format_val); 191 } 192 193 hext_stream->link_prepared = 1; 194 195 return 0; 196 } 197 198 static int __maybe_unused hda_dai_hw_free(struct snd_pcm_substream *substream, 199 struct snd_soc_dai *cpu_dai) 200 { 201 const struct hda_dai_widget_dma_ops *ops = hda_dai_get_ops(substream, cpu_dai); 202 struct hdac_ext_stream *hext_stream; 203 struct snd_sof_dev *sdev = dai_to_sdev(substream, cpu_dai); 204 205 if (!ops) { 206 dev_err(cpu_dai->dev, "DAI widget ops not set\n"); 207 return -EINVAL; 208 } 209 210 hext_stream = ops->get_hext_stream(sdev, cpu_dai, substream); 211 if (!hext_stream) 212 return 0; 213 214 return hda_link_dma_cleanup(substream, hext_stream, cpu_dai); 215 } 216 217 static int __maybe_unused hda_dai_hw_params_data(struct snd_pcm_substream *substream, 218 struct snd_pcm_hw_params *params, 219 struct snd_soc_dai *dai, 220 struct snd_sof_dai_config_data *data, 221 unsigned int flags) 222 { 223 struct snd_soc_dapm_widget *w = snd_soc_dai_get_widget(dai, substream->stream); 224 const struct hda_dai_widget_dma_ops *ops = hda_dai_get_ops(substream, dai); 225 struct hdac_ext_stream *hext_stream; 226 struct snd_sof_dev *sdev = widget_to_sdev(w); 227 int ret; 228 229 if (!ops) { 230 dev_err(sdev->dev, "DAI widget ops not set\n"); 231 return -EINVAL; 232 } 233 234 hext_stream = ops->get_hext_stream(sdev, dai, substream); 235 if (hext_stream && hext_stream->link_prepared) 236 return 0; 237 238 ret = hda_link_dma_hw_params(substream, params, dai); 239 if (ret < 0) 240 return ret; 241 242 hext_stream = ops->get_hext_stream(sdev, dai, substream); 243 244 flags |= SOF_DAI_CONFIG_FLAGS_2_STEP_STOP << SOF_DAI_CONFIG_FLAGS_QUIRK_SHIFT; 245 data->dai_data = hdac_stream(hext_stream)->stream_tag - 1; 246 247 return hda_dai_config(w, flags, data); 248 } 249 250 static int __maybe_unused hda_dai_hw_params(struct snd_pcm_substream *substream, 251 struct snd_pcm_hw_params *params, 252 struct snd_soc_dai *dai) 253 { 254 struct snd_sof_dai_config_data data = { 0 }; 255 unsigned int flags = SOF_DAI_CONFIG_FLAGS_HW_PARAMS; 256 257 return hda_dai_hw_params_data(substream, params, dai, &data, flags); 258 } 259 260 /* 261 * In contrast to IPC3, the dai trigger in IPC4 mixes pipeline state changes 262 * (over IPC channel) and DMA state change (direct host register changes). 263 */ 264 static int __maybe_unused hda_dai_trigger(struct snd_pcm_substream *substream, int cmd, 265 struct snd_soc_dai *dai) 266 { 267 const struct hda_dai_widget_dma_ops *ops = hda_dai_get_ops(substream, dai); 268 struct hdac_ext_stream *hext_stream; 269 struct snd_sof_dev *sdev; 270 int ret; 271 272 if (!ops) { 273 dev_err(dai->dev, "DAI widget ops not set\n"); 274 return -EINVAL; 275 } 276 277 dev_dbg(dai->dev, "cmd=%d dai %s direction %d\n", cmd, 278 dai->name, substream->stream); 279 280 sdev = dai_to_sdev(substream, dai); 281 282 hext_stream = ops->get_hext_stream(sdev, dai, substream); 283 if (!hext_stream) 284 return -EINVAL; 285 286 if (ops->pre_trigger) { 287 ret = ops->pre_trigger(sdev, dai, substream, cmd); 288 if (ret < 0) 289 return ret; 290 } 291 292 if (ops->trigger) { 293 ret = ops->trigger(sdev, dai, substream, cmd); 294 if (ret < 0) 295 return ret; 296 } 297 298 if (ops->post_trigger) { 299 ret = ops->post_trigger(sdev, dai, substream, cmd); 300 if (ret < 0) 301 return ret; 302 } 303 304 switch (cmd) { 305 case SNDRV_PCM_TRIGGER_SUSPEND: 306 ret = hda_link_dma_cleanup(substream, hext_stream, dai); 307 if (ret < 0) { 308 dev_err(sdev->dev, "%s: failed to clean up link DMA\n", __func__); 309 return ret; 310 } 311 break; 312 default: 313 break; 314 } 315 316 return 0; 317 } 318 319 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC) 320 321 static int hda_dai_prepare(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) 322 { 323 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 324 int stream = substream->stream; 325 326 return hda_dai_hw_params(substream, &rtd->dpcm[stream].hw_params, dai); 327 } 328 329 static const struct snd_soc_dai_ops hda_dai_ops = { 330 .hw_params = hda_dai_hw_params, 331 .hw_free = hda_dai_hw_free, 332 .trigger = hda_dai_trigger, 333 .prepare = hda_dai_prepare, 334 }; 335 336 #endif 337 338 static struct sof_ipc4_copier *widget_to_copier(struct snd_soc_dapm_widget *w) 339 { 340 struct snd_sof_widget *swidget = w->dobj.private; 341 struct snd_sof_dai *sdai = swidget->private; 342 struct sof_ipc4_copier *ipc4_copier = (struct sof_ipc4_copier *)sdai->private; 343 344 return ipc4_copier; 345 } 346 347 static int non_hda_dai_hw_params_data(struct snd_pcm_substream *substream, 348 struct snd_pcm_hw_params *params, 349 struct snd_soc_dai *cpu_dai, 350 struct snd_sof_dai_config_data *data, 351 unsigned int flags) 352 { 353 struct snd_soc_dapm_widget *w = snd_soc_dai_get_widget(cpu_dai, substream->stream); 354 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 355 struct sof_ipc4_dma_config_tlv *dma_config_tlv; 356 const struct hda_dai_widget_dma_ops *ops; 357 struct sof_ipc4_dma_config *dma_config; 358 struct sof_ipc4_copier *ipc4_copier; 359 struct hdac_ext_stream *hext_stream; 360 struct hdac_stream *hstream; 361 struct snd_sof_dev *sdev; 362 struct snd_soc_dai *dai; 363 int cpu_dai_id; 364 int stream_id; 365 int ret; 366 367 ops = hda_dai_get_ops(substream, cpu_dai); 368 if (!ops) { 369 dev_err(cpu_dai->dev, "DAI widget ops not set\n"); 370 return -EINVAL; 371 } 372 373 /* use HDaudio stream handling */ 374 ret = hda_dai_hw_params_data(substream, params, cpu_dai, data, flags); 375 if (ret < 0) { 376 dev_err(cpu_dai->dev, "%s: hda_dai_hw_params_data failed: %d\n", __func__, ret); 377 return ret; 378 } 379 380 sdev = widget_to_sdev(w); 381 if (sdev->dspless_mode_selected) 382 goto skip_tlv; 383 384 /* get stream_id */ 385 hext_stream = ops->get_hext_stream(sdev, cpu_dai, substream); 386 387 if (!hext_stream) { 388 dev_err(cpu_dai->dev, "%s: no hext_stream found\n", __func__); 389 return -ENODEV; 390 } 391 392 hstream = &hext_stream->hstream; 393 stream_id = hstream->stream_tag; 394 395 if (!stream_id) { 396 dev_err(cpu_dai->dev, "%s: no stream_id allocated\n", __func__); 397 return -ENODEV; 398 } 399 400 /* configure TLV */ 401 ipc4_copier = widget_to_copier(w); 402 403 for_each_rtd_cpu_dais(rtd, cpu_dai_id, dai) { 404 if (dai == cpu_dai) 405 break; 406 } 407 408 dma_config_tlv = &ipc4_copier->dma_config_tlv[cpu_dai_id]; 409 dma_config_tlv->type = SOF_IPC4_GTW_DMA_CONFIG_ID; 410 /* dma_config_priv_size is zero */ 411 dma_config_tlv->length = sizeof(dma_config_tlv->dma_config); 412 413 dma_config = &dma_config_tlv->dma_config; 414 415 dma_config->dma_method = SOF_IPC4_DMA_METHOD_HDA; 416 dma_config->pre_allocated_by_host = 1; 417 dma_config->dma_channel_id = stream_id - 1; 418 dma_config->stream_id = stream_id; 419 /* 420 * Currently we use a DMA for each device in ALH blob. The device will 421 * be copied in sof_ipc4_prepare_copier_module. 422 */ 423 dma_config->dma_stream_channel_map.device_count = 1; 424 dma_config->dma_priv_config_size = 0; 425 426 skip_tlv: 427 return 0; 428 } 429 430 static int non_hda_dai_hw_params(struct snd_pcm_substream *substream, 431 struct snd_pcm_hw_params *params, 432 struct snd_soc_dai *cpu_dai) 433 { 434 struct snd_sof_dai_config_data data = { 0 }; 435 unsigned int flags = SOF_DAI_CONFIG_FLAGS_HW_PARAMS; 436 437 return non_hda_dai_hw_params_data(substream, params, cpu_dai, &data, flags); 438 } 439 440 static int non_hda_dai_prepare(struct snd_pcm_substream *substream, 441 struct snd_soc_dai *cpu_dai) 442 { 443 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 444 int stream = substream->stream; 445 446 return non_hda_dai_hw_params(substream, &rtd->dpcm[stream].hw_params, cpu_dai); 447 } 448 449 static const struct snd_soc_dai_ops ssp_dai_ops = { 450 .hw_params = non_hda_dai_hw_params, 451 .hw_free = hda_dai_hw_free, 452 .trigger = hda_dai_trigger, 453 .prepare = non_hda_dai_prepare, 454 }; 455 456 static const struct snd_soc_dai_ops dmic_dai_ops = { 457 .hw_params = non_hda_dai_hw_params, 458 .hw_free = hda_dai_hw_free, 459 .trigger = hda_dai_trigger, 460 .prepare = non_hda_dai_prepare, 461 }; 462 463 int sdw_hda_dai_hw_params(struct snd_pcm_substream *substream, 464 struct snd_pcm_hw_params *params, 465 struct snd_soc_dai *cpu_dai, 466 int link_id, 467 int intel_alh_id) 468 { 469 struct snd_soc_dapm_widget *w = snd_soc_dai_get_widget(cpu_dai, substream->stream); 470 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); 471 struct sof_ipc4_dma_config_tlv *dma_config_tlv; 472 struct snd_sof_dai_config_data data = { 0 }; 473 unsigned int flags = SOF_DAI_CONFIG_FLAGS_HW_PARAMS; 474 const struct hda_dai_widget_dma_ops *ops; 475 struct sof_ipc4_dma_config *dma_config; 476 struct sof_ipc4_copier *ipc4_copier; 477 struct hdac_ext_stream *hext_stream; 478 struct snd_soc_dai *dai; 479 struct snd_sof_dev *sdev; 480 bool cpu_dai_found = false; 481 int cpu_dai_id; 482 int ch_mask; 483 int ret; 484 int i; 485 486 data.dai_index = (link_id << 8) | cpu_dai->id; 487 data.dai_node_id = intel_alh_id; 488 ret = non_hda_dai_hw_params_data(substream, params, cpu_dai, &data, flags); 489 if (ret < 0) { 490 dev_err(cpu_dai->dev, "%s: non_hda_dai_hw_params failed %d\n", __func__, ret); 491 return ret; 492 } 493 494 ops = hda_dai_get_ops(substream, cpu_dai); 495 sdev = widget_to_sdev(w); 496 hext_stream = ops->get_hext_stream(sdev, cpu_dai, substream); 497 498 if (!hext_stream) 499 return -ENODEV; 500 501 /* 502 * in the case of SoundWire we need to program the PCMSyCM registers. In case 503 * of aggregated devices, we need to define the channel mask for each sublink 504 * by reconstructing the split done in soc-pcm.c 505 */ 506 for_each_rtd_cpu_dais(rtd, cpu_dai_id, dai) { 507 if (dai == cpu_dai) { 508 cpu_dai_found = true; 509 break; 510 } 511 } 512 513 if (!cpu_dai_found) 514 return -ENODEV; 515 516 ch_mask = GENMASK(params_channels(params) - 1, 0); 517 518 ret = hdac_bus_eml_sdw_map_stream_ch(sof_to_bus(sdev), link_id, cpu_dai->id, 519 ch_mask, 520 hdac_stream(hext_stream)->stream_tag, 521 substream->stream); 522 if (ret < 0) { 523 dev_err(cpu_dai->dev, "%s: hdac_bus_eml_sdw_map_stream_ch failed %d\n", 524 __func__, ret); 525 return ret; 526 } 527 528 ipc4_copier = widget_to_copier(w); 529 dma_config_tlv = &ipc4_copier->dma_config_tlv[cpu_dai_id]; 530 dma_config = &dma_config_tlv->dma_config; 531 dma_config->dma_stream_channel_map.mapping[0].device = data.dai_index; 532 dma_config->dma_stream_channel_map.mapping[0].channel_mask = ch_mask; 533 534 /* 535 * copy the dma_config_tlv to all ipc4_copier in the same link. Because only one copier 536 * will be handled in sof_ipc4_prepare_copier_module. 537 */ 538 for_each_rtd_cpu_dais(rtd, i, dai) { 539 w = snd_soc_dai_get_widget(dai, substream->stream); 540 ipc4_copier = widget_to_copier(w); 541 memcpy(&ipc4_copier->dma_config_tlv[cpu_dai_id], dma_config_tlv, 542 sizeof(*dma_config_tlv)); 543 } 544 return 0; 545 } 546 EXPORT_SYMBOL_NS(sdw_hda_dai_hw_params, SND_SOC_SOF_INTEL_HDA_COMMON); 547 548 int sdw_hda_dai_hw_free(struct snd_pcm_substream *substream, 549 struct snd_soc_dai *cpu_dai, 550 int link_id) 551 { 552 struct snd_soc_dapm_widget *w = snd_soc_dai_get_widget(cpu_dai, substream->stream); 553 struct snd_sof_dev *sdev; 554 int ret; 555 556 ret = hda_dai_hw_free(substream, cpu_dai); 557 if (ret < 0) { 558 dev_err(cpu_dai->dev, "%s: non_hda_dai_hw_free failed %d\n", __func__, ret); 559 return ret; 560 } 561 562 sdev = widget_to_sdev(w); 563 564 /* in the case of SoundWire we need to reset the PCMSyCM registers */ 565 ret = hdac_bus_eml_sdw_map_stream_ch(sof_to_bus(sdev), link_id, cpu_dai->id, 566 0, 0, substream->stream); 567 if (ret < 0) { 568 dev_err(cpu_dai->dev, "%s: hdac_bus_eml_sdw_map_stream_ch failed %d\n", 569 __func__, ret); 570 return ret; 571 } 572 573 return 0; 574 } 575 EXPORT_SYMBOL_NS(sdw_hda_dai_hw_free, SND_SOC_SOF_INTEL_HDA_COMMON); 576 577 int sdw_hda_dai_trigger(struct snd_pcm_substream *substream, int cmd, 578 struct snd_soc_dai *cpu_dai) 579 { 580 return hda_dai_trigger(substream, cmd, cpu_dai); 581 } 582 EXPORT_SYMBOL_NS(sdw_hda_dai_trigger, SND_SOC_SOF_INTEL_HDA_COMMON); 583 584 static int hda_dai_suspend(struct hdac_bus *bus) 585 { 586 struct snd_soc_pcm_runtime *rtd; 587 struct hdac_ext_stream *hext_stream; 588 struct hdac_stream *s; 589 int ret; 590 591 /* set internal flag for BE */ 592 list_for_each_entry(s, &bus->stream_list, list) { 593 594 hext_stream = stream_to_hdac_ext_stream(s); 595 596 /* 597 * clear stream. This should already be taken care for running 598 * streams when the SUSPEND trigger is called. But paused 599 * streams do not get suspended, so this needs to be done 600 * explicitly during suspend. 601 */ 602 if (hext_stream->link_substream) { 603 const struct hda_dai_widget_dma_ops *ops; 604 struct snd_sof_widget *swidget; 605 struct snd_soc_dapm_widget *w; 606 struct snd_soc_dai *cpu_dai; 607 struct snd_sof_dev *sdev; 608 struct snd_sof_dai *sdai; 609 610 rtd = snd_soc_substream_to_rtd(hext_stream->link_substream); 611 cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); 612 w = snd_soc_dai_get_widget(cpu_dai, hdac_stream(hext_stream)->direction); 613 swidget = w->dobj.private; 614 sdev = widget_to_sdev(w); 615 sdai = swidget->private; 616 ops = sdai->platform_private; 617 618 ret = hda_link_dma_cleanup(hext_stream->link_substream, 619 hext_stream, 620 cpu_dai); 621 if (ret < 0) 622 return ret; 623 624 /* for consistency with TRIGGER_SUSPEND */ 625 if (ops->post_trigger) { 626 ret = ops->post_trigger(sdev, cpu_dai, 627 hext_stream->link_substream, 628 SNDRV_PCM_TRIGGER_SUSPEND); 629 if (ret < 0) 630 return ret; 631 } 632 } 633 } 634 635 return 0; 636 } 637 638 static void ssp_set_dai_drv_ops(struct snd_sof_dev *sdev, struct snd_sof_dsp_ops *ops) 639 { 640 const struct sof_intel_dsp_desc *chip; 641 int i; 642 643 chip = get_chip_info(sdev->pdata); 644 645 if (chip->hw_ip_version >= SOF_INTEL_ACE_2_0) { 646 for (i = 0; i < ops->num_drv; i++) { 647 if (strstr(ops->drv[i].name, "SSP")) 648 ops->drv[i].ops = &ssp_dai_ops; 649 } 650 } 651 } 652 653 static void dmic_set_dai_drv_ops(struct snd_sof_dev *sdev, struct snd_sof_dsp_ops *ops) 654 { 655 const struct sof_intel_dsp_desc *chip; 656 int i; 657 658 chip = get_chip_info(sdev->pdata); 659 660 if (chip->hw_ip_version >= SOF_INTEL_ACE_2_0) { 661 for (i = 0; i < ops->num_drv; i++) { 662 if (strstr(ops->drv[i].name, "DMIC")) 663 ops->drv[i].ops = &dmic_dai_ops; 664 } 665 } 666 } 667 668 #else 669 670 static inline void ssp_set_dai_drv_ops(struct snd_sof_dev *sdev, struct snd_sof_dsp_ops *ops) {} 671 static inline void dmic_set_dai_drv_ops(struct snd_sof_dev *sdev, struct snd_sof_dsp_ops *ops) {} 672 673 #endif /* CONFIG_SND_SOC_SOF_HDA_LINK */ 674 675 void hda_set_dai_drv_ops(struct snd_sof_dev *sdev, struct snd_sof_dsp_ops *ops) 676 { 677 int i; 678 679 for (i = 0; i < ops->num_drv; i++) { 680 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC) 681 if (strstr(ops->drv[i].name, "iDisp") || 682 strstr(ops->drv[i].name, "Analog") || 683 strstr(ops->drv[i].name, "Digital")) 684 ops->drv[i].ops = &hda_dai_ops; 685 #endif 686 } 687 688 ssp_set_dai_drv_ops(sdev, ops); 689 dmic_set_dai_drv_ops(sdev, ops); 690 691 if (sdev->pdata->ipc_type == SOF_IPC_TYPE_4 && !hda_use_tplg_nhlt) { 692 struct sof_ipc4_fw_data *ipc4_data = sdev->private; 693 694 ipc4_data->nhlt = intel_nhlt_init(sdev->dev); 695 } 696 } 697 EXPORT_SYMBOL_NS(hda_set_dai_drv_ops, SND_SOC_SOF_INTEL_HDA_COMMON); 698 699 void hda_ops_free(struct snd_sof_dev *sdev) 700 { 701 if (sdev->pdata->ipc_type == SOF_IPC_TYPE_4) { 702 struct sof_ipc4_fw_data *ipc4_data = sdev->private; 703 704 if (!hda_use_tplg_nhlt) 705 intel_nhlt_free(ipc4_data->nhlt); 706 707 kfree(sdev->private); 708 sdev->private = NULL; 709 } 710 } 711 EXPORT_SYMBOL_NS(hda_ops_free, SND_SOC_SOF_INTEL_HDA_COMMON); 712 713 /* 714 * common dai driver for skl+ platforms. 715 * some products who use this DAI array only physically have a subset of 716 * the DAIs, but no harm is done here by adding the whole set. 717 */ 718 struct snd_soc_dai_driver skl_dai[] = { 719 { 720 .name = "SSP0 Pin", 721 .playback = { 722 .channels_min = 1, 723 .channels_max = 8, 724 }, 725 .capture = { 726 .channels_min = 1, 727 .channels_max = 8, 728 }, 729 }, 730 { 731 .name = "SSP1 Pin", 732 .playback = { 733 .channels_min = 1, 734 .channels_max = 8, 735 }, 736 .capture = { 737 .channels_min = 1, 738 .channels_max = 8, 739 }, 740 }, 741 { 742 .name = "SSP2 Pin", 743 .playback = { 744 .channels_min = 1, 745 .channels_max = 8, 746 }, 747 .capture = { 748 .channels_min = 1, 749 .channels_max = 8, 750 }, 751 }, 752 { 753 .name = "SSP3 Pin", 754 .playback = { 755 .channels_min = 1, 756 .channels_max = 8, 757 }, 758 .capture = { 759 .channels_min = 1, 760 .channels_max = 8, 761 }, 762 }, 763 { 764 .name = "SSP4 Pin", 765 .playback = { 766 .channels_min = 1, 767 .channels_max = 8, 768 }, 769 .capture = { 770 .channels_min = 1, 771 .channels_max = 8, 772 }, 773 }, 774 { 775 .name = "SSP5 Pin", 776 .playback = { 777 .channels_min = 1, 778 .channels_max = 8, 779 }, 780 .capture = { 781 .channels_min = 1, 782 .channels_max = 8, 783 }, 784 }, 785 { 786 .name = "DMIC01 Pin", 787 .capture = { 788 .channels_min = 1, 789 .channels_max = 4, 790 }, 791 }, 792 { 793 .name = "DMIC16k Pin", 794 .capture = { 795 .channels_min = 1, 796 .channels_max = 4, 797 }, 798 }, 799 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC) 800 { 801 .name = "iDisp1 Pin", 802 .playback = { 803 .channels_min = 1, 804 .channels_max = 8, 805 }, 806 }, 807 { 808 .name = "iDisp2 Pin", 809 .playback = { 810 .channels_min = 1, 811 .channels_max = 8, 812 }, 813 }, 814 { 815 .name = "iDisp3 Pin", 816 .playback = { 817 .channels_min = 1, 818 .channels_max = 8, 819 }, 820 }, 821 { 822 .name = "iDisp4 Pin", 823 .playback = { 824 .channels_min = 1, 825 .channels_max = 8, 826 }, 827 }, 828 { 829 .name = "Analog CPU DAI", 830 .playback = { 831 .channels_min = 1, 832 .channels_max = 16, 833 }, 834 .capture = { 835 .channels_min = 1, 836 .channels_max = 16, 837 }, 838 }, 839 { 840 .name = "Digital CPU DAI", 841 .playback = { 842 .channels_min = 1, 843 .channels_max = 16, 844 }, 845 .capture = { 846 .channels_min = 1, 847 .channels_max = 16, 848 }, 849 }, 850 { 851 .name = "Alt Analog CPU DAI", 852 .playback = { 853 .channels_min = 1, 854 .channels_max = 16, 855 }, 856 .capture = { 857 .channels_min = 1, 858 .channels_max = 16, 859 }, 860 }, 861 #endif 862 }; 863 EXPORT_SYMBOL_NS(skl_dai, SND_SOC_SOF_INTEL_HDA_COMMON); 864 865 int hda_dsp_dais_suspend(struct snd_sof_dev *sdev) 866 { 867 /* 868 * In the corner case where a SUSPEND happens during a PAUSE, the ALSA core 869 * does not throw the TRIGGER_SUSPEND. This leaves the DAIs in an unbalanced state. 870 * Since the component suspend is called last, we can trap this corner case 871 * and force the DAIs to release their resources. 872 */ 873 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_LINK) 874 int ret; 875 876 ret = hda_dai_suspend(sof_to_bus(sdev)); 877 if (ret < 0) 878 return ret; 879 #endif 880 881 return 0; 882 } 883