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