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: Liam Girdwood <liam.r.girdwood@linux.intel.com> 9 // Ranjani Sridharan <ranjani.sridharan@linux.intel.com> 10 // Rander Wang <rander.wang@intel.com> 11 // Keyon Jie <yang.jie@linux.intel.com> 12 // 13 14 /* 15 * Hardware interface for generic Intel audio DSP HDA IP 16 */ 17 18 #include <sound/hdaudio_ext.h> 19 #include <sound/hda_register.h> 20 21 #include <linux/acpi.h> 22 #include <linux/module.h> 23 #include <linux/soundwire/sdw.h> 24 #include <linux/soundwire/sdw_intel.h> 25 #include <sound/intel-dsp-config.h> 26 #include <sound/intel-nhlt.h> 27 #include <sound/sof.h> 28 #include <sound/sof/xtensa.h> 29 #include "../sof-audio.h" 30 #include "../sof-pci-dev.h" 31 #include "../ops.h" 32 #include "hda.h" 33 34 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) 35 #include <sound/soc-acpi-intel-match.h> 36 #endif 37 38 /* platform specific devices */ 39 #include "shim.h" 40 41 #define EXCEPT_MAX_HDR_SIZE 0x400 42 #define HDA_EXT_ROM_STATUS_SIZE 8 43 44 int hda_ctrl_dai_widget_setup(struct snd_soc_dapm_widget *w) 45 { 46 struct snd_sof_widget *swidget = w->dobj.private; 47 struct snd_soc_component *component = swidget->scomp; 48 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component); 49 struct sof_ipc_dai_config *config; 50 struct snd_sof_dai *sof_dai; 51 struct sof_ipc_reply reply; 52 int ret; 53 54 sof_dai = swidget->private; 55 56 if (!sof_dai || !sof_dai->dai_config) { 57 dev_err(sdev->dev, "No config for DAI %s\n", w->name); 58 return -EINVAL; 59 } 60 61 config = &sof_dai->dai_config[sof_dai->current_config]; 62 63 /* 64 * For static pipelines, the DAI widget would already be set up and calling 65 * sof_widget_setup() simply returns without doing anything. 66 * For dynamic pipelines, the DAI widget will be set up now. 67 */ 68 ret = sof_widget_setup(sdev, swidget); 69 if (ret < 0) { 70 dev_err(sdev->dev, "error: failed setting up DAI widget %s\n", w->name); 71 return ret; 72 } 73 74 /* set HW_PARAMS flag */ 75 config->flags = FIELD_PREP(SOF_DAI_CONFIG_FLAGS_MASK, SOF_DAI_CONFIG_FLAGS_HW_PARAMS); 76 77 /* send DAI_CONFIG IPC */ 78 ret = sof_ipc_tx_message(sdev->ipc, config->hdr.cmd, config, config->hdr.size, 79 &reply, sizeof(reply)); 80 if (ret < 0) { 81 dev_err(sdev->dev, "error: failed setting DAI config for %s\n", w->name); 82 return ret; 83 } 84 85 sof_dai->configured = true; 86 87 return 0; 88 } 89 90 int hda_ctrl_dai_widget_free(struct snd_soc_dapm_widget *w) 91 { 92 struct snd_sof_widget *swidget = w->dobj.private; 93 struct snd_soc_component *component = swidget->scomp; 94 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component); 95 struct sof_ipc_dai_config *config; 96 struct snd_sof_dai *sof_dai; 97 struct sof_ipc_reply reply; 98 int ret; 99 100 sof_dai = swidget->private; 101 102 if (!sof_dai || !sof_dai->dai_config) { 103 dev_err(sdev->dev, "error: No config to free DAI %s\n", w->name); 104 return -EINVAL; 105 } 106 107 /* nothing to do if hw_free() is called without restarting the stream after resume. */ 108 if (!sof_dai->configured) 109 return 0; 110 111 config = &sof_dai->dai_config[sof_dai->current_config]; 112 113 /* set HW_FREE flag */ 114 config->flags = FIELD_PREP(SOF_DAI_CONFIG_FLAGS_MASK, SOF_DAI_CONFIG_FLAGS_HW_FREE); 115 116 ret = sof_ipc_tx_message(sdev->ipc, config->hdr.cmd, config, config->hdr.size, 117 &reply, sizeof(reply)); 118 if (ret < 0) 119 dev_err(sdev->dev, "error: failed resetting DAI config for %s\n", w->name); 120 121 /* 122 * Reset the configured_flag and free the widget even if the IPC fails to keep 123 * the widget use_count balanced 124 */ 125 sof_dai->configured = false; 126 127 return sof_widget_free(sdev, swidget); 128 } 129 130 static const struct sof_intel_dsp_desc 131 *get_chip_info(struct snd_sof_pdata *pdata) 132 { 133 const struct sof_dev_desc *desc = pdata->desc; 134 const struct sof_intel_dsp_desc *chip_info; 135 136 chip_info = desc->chip_info; 137 138 return chip_info; 139 } 140 141 #if IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE) 142 143 /* 144 * The default for SoundWire clock stop quirks is to power gate the IP 145 * and do a Bus Reset, this will need to be modified when the DSP 146 * needs to remain in D0i3 so that the Master does not lose context 147 * and enumeration is not required on clock restart 148 */ 149 static int sdw_clock_stop_quirks = SDW_INTEL_CLK_STOP_BUS_RESET; 150 module_param(sdw_clock_stop_quirks, int, 0444); 151 MODULE_PARM_DESC(sdw_clock_stop_quirks, "SOF SoundWire clock stop quirks"); 152 153 static int sdw_dai_config_ipc(struct snd_sof_dev *sdev, 154 struct snd_soc_dapm_widget *w, 155 int link_id, int alh_stream_id, int dai_id, bool setup) 156 { 157 struct snd_sof_widget *swidget = w->dobj.private; 158 struct sof_ipc_dai_config *config; 159 struct snd_sof_dai *sof_dai; 160 161 if (!swidget) { 162 dev_err(sdev->dev, "error: No private data for widget %s\n", w->name); 163 return -EINVAL; 164 } 165 166 sof_dai = swidget->private; 167 168 if (!sof_dai || !sof_dai->dai_config) { 169 dev_err(sdev->dev, "error: No config for DAI %s\n", w->name); 170 return -EINVAL; 171 } 172 173 config = &sof_dai->dai_config[sof_dai->current_config]; 174 175 /* update config with link and stream ID */ 176 config->dai_index = (link_id << 8) | dai_id; 177 config->alh.stream_id = alh_stream_id; 178 179 if (setup) 180 return hda_ctrl_dai_widget_setup(w); 181 182 return hda_ctrl_dai_widget_free(w); 183 } 184 185 static int sdw_params_stream(struct device *dev, 186 struct sdw_intel_stream_params_data *params_data) 187 { 188 struct snd_pcm_substream *substream = params_data->substream; 189 struct snd_sof_dev *sdev = dev_get_drvdata(dev); 190 struct snd_soc_dai *d = params_data->dai; 191 struct snd_soc_dapm_widget *w; 192 193 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 194 w = d->playback_widget; 195 else 196 w = d->capture_widget; 197 198 return sdw_dai_config_ipc(sdev, w, params_data->link_id, params_data->alh_stream_id, 199 d->id, true); 200 } 201 202 static int sdw_free_stream(struct device *dev, 203 struct sdw_intel_stream_free_data *free_data) 204 { 205 struct snd_pcm_substream *substream = free_data->substream; 206 struct snd_sof_dev *sdev = dev_get_drvdata(dev); 207 struct snd_soc_dai *d = free_data->dai; 208 struct snd_soc_dapm_widget *w; 209 210 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 211 w = d->playback_widget; 212 else 213 w = d->capture_widget; 214 215 /* send invalid stream_id */ 216 return sdw_dai_config_ipc(sdev, w, free_data->link_id, 0xFFFF, d->id, false); 217 } 218 219 static const struct sdw_intel_ops sdw_callback = { 220 .params_stream = sdw_params_stream, 221 .free_stream = sdw_free_stream, 222 }; 223 224 void hda_sdw_int_enable(struct snd_sof_dev *sdev, bool enable) 225 { 226 sdw_intel_enable_irq(sdev->bar[HDA_DSP_BAR], enable); 227 } 228 229 static int hda_sdw_acpi_scan(struct snd_sof_dev *sdev) 230 { 231 struct sof_intel_hda_dev *hdev; 232 acpi_handle handle; 233 int ret; 234 235 handle = ACPI_HANDLE(sdev->dev); 236 237 /* save ACPI info for the probe step */ 238 hdev = sdev->pdata->hw_pdata; 239 240 ret = sdw_intel_acpi_scan(handle, &hdev->info); 241 if (ret < 0) 242 return -EINVAL; 243 244 return 0; 245 } 246 247 static int hda_sdw_probe(struct snd_sof_dev *sdev) 248 { 249 struct sof_intel_hda_dev *hdev; 250 struct sdw_intel_res res; 251 void *sdw; 252 253 hdev = sdev->pdata->hw_pdata; 254 255 memset(&res, 0, sizeof(res)); 256 257 res.mmio_base = sdev->bar[HDA_DSP_BAR]; 258 res.shim_base = hdev->desc->sdw_shim_base; 259 res.alh_base = hdev->desc->sdw_alh_base; 260 res.irq = sdev->ipc_irq; 261 res.handle = hdev->info.handle; 262 res.parent = sdev->dev; 263 res.ops = &sdw_callback; 264 res.dev = sdev->dev; 265 res.clock_stop_quirks = sdw_clock_stop_quirks; 266 267 /* 268 * ops and arg fields are not populated for now, 269 * they will be needed when the DAI callbacks are 270 * provided 271 */ 272 273 /* we could filter links here if needed, e.g for quirks */ 274 res.count = hdev->info.count; 275 res.link_mask = hdev->info.link_mask; 276 277 sdw = sdw_intel_probe(&res); 278 if (!sdw) { 279 dev_err(sdev->dev, "error: SoundWire probe failed\n"); 280 return -EINVAL; 281 } 282 283 /* save context */ 284 hdev->sdw = sdw; 285 286 return 0; 287 } 288 289 int hda_sdw_startup(struct snd_sof_dev *sdev) 290 { 291 struct sof_intel_hda_dev *hdev; 292 struct snd_sof_pdata *pdata = sdev->pdata; 293 294 hdev = sdev->pdata->hw_pdata; 295 296 if (!hdev->sdw) 297 return 0; 298 299 if (pdata->machine && !pdata->machine->mach_params.link_mask) 300 return 0; 301 302 return sdw_intel_startup(hdev->sdw); 303 } 304 305 static int hda_sdw_exit(struct snd_sof_dev *sdev) 306 { 307 struct sof_intel_hda_dev *hdev; 308 309 hdev = sdev->pdata->hw_pdata; 310 311 hda_sdw_int_enable(sdev, false); 312 313 if (hdev->sdw) 314 sdw_intel_exit(hdev->sdw); 315 hdev->sdw = NULL; 316 317 return 0; 318 } 319 320 bool hda_common_check_sdw_irq(struct snd_sof_dev *sdev) 321 { 322 struct sof_intel_hda_dev *hdev; 323 bool ret = false; 324 u32 irq_status; 325 326 hdev = sdev->pdata->hw_pdata; 327 328 if (!hdev->sdw) 329 return ret; 330 331 /* store status */ 332 irq_status = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_ADSPIS2); 333 334 /* invalid message ? */ 335 if (irq_status == 0xffffffff) 336 goto out; 337 338 /* SDW message ? */ 339 if (irq_status & HDA_DSP_REG_ADSPIS2_SNDW) 340 ret = true; 341 342 out: 343 return ret; 344 } 345 346 static bool hda_dsp_check_sdw_irq(struct snd_sof_dev *sdev) 347 { 348 const struct sof_intel_dsp_desc *chip; 349 350 chip = get_chip_info(sdev->pdata); 351 if (chip && chip->check_sdw_irq) 352 return chip->check_sdw_irq(sdev); 353 354 return false; 355 } 356 357 static irqreturn_t hda_dsp_sdw_thread(int irq, void *context) 358 { 359 return sdw_intel_thread(irq, context); 360 } 361 362 static bool hda_sdw_check_wakeen_irq(struct snd_sof_dev *sdev) 363 { 364 struct sof_intel_hda_dev *hdev; 365 366 hdev = sdev->pdata->hw_pdata; 367 if (hdev->sdw && 368 snd_sof_dsp_read(sdev, HDA_DSP_BAR, 369 hdev->desc->sdw_shim_base + SDW_SHIM_WAKESTS)) 370 return true; 371 372 return false; 373 } 374 375 void hda_sdw_process_wakeen(struct snd_sof_dev *sdev) 376 { 377 struct sof_intel_hda_dev *hdev; 378 379 hdev = sdev->pdata->hw_pdata; 380 if (!hdev->sdw) 381 return; 382 383 sdw_intel_process_wakeen_event(hdev->sdw); 384 } 385 386 #else /* IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE) */ 387 static inline int hda_sdw_acpi_scan(struct snd_sof_dev *sdev) 388 { 389 return 0; 390 } 391 392 static inline int hda_sdw_probe(struct snd_sof_dev *sdev) 393 { 394 return 0; 395 } 396 397 static inline int hda_sdw_exit(struct snd_sof_dev *sdev) 398 { 399 return 0; 400 } 401 402 static inline bool hda_dsp_check_sdw_irq(struct snd_sof_dev *sdev) 403 { 404 return false; 405 } 406 407 static inline irqreturn_t hda_dsp_sdw_thread(int irq, void *context) 408 { 409 return IRQ_HANDLED; 410 } 411 412 static inline bool hda_sdw_check_wakeen_irq(struct snd_sof_dev *sdev) 413 { 414 return false; 415 } 416 417 #endif /* IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE) */ 418 419 /* 420 * Debug 421 */ 422 423 struct hda_dsp_msg_code { 424 u32 code; 425 const char *msg; 426 }; 427 428 #if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG) 429 static bool hda_use_msi = true; 430 module_param_named(use_msi, hda_use_msi, bool, 0444); 431 MODULE_PARM_DESC(use_msi, "SOF HDA use PCI MSI mode"); 432 #else 433 #define hda_use_msi (1) 434 #endif 435 436 static char *hda_model; 437 module_param(hda_model, charp, 0444); 438 MODULE_PARM_DESC(hda_model, "Use the given HDA board model."); 439 440 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) || IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE) 441 static int hda_dmic_num = -1; 442 module_param_named(dmic_num, hda_dmic_num, int, 0444); 443 MODULE_PARM_DESC(dmic_num, "SOF HDA DMIC number"); 444 #endif 445 446 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) 447 static bool hda_codec_use_common_hdmi = IS_ENABLED(CONFIG_SND_HDA_CODEC_HDMI); 448 module_param_named(use_common_hdmi, hda_codec_use_common_hdmi, bool, 0444); 449 MODULE_PARM_DESC(use_common_hdmi, "SOF HDA use common HDMI codec driver"); 450 #endif 451 452 static const struct hda_dsp_msg_code hda_dsp_rom_msg[] = { 453 {HDA_DSP_ROM_FW_MANIFEST_LOADED, "status: manifest loaded"}, 454 {HDA_DSP_ROM_FW_FW_LOADED, "status: fw loaded"}, 455 {HDA_DSP_ROM_FW_ENTERED, "status: fw entered"}, 456 {HDA_DSP_ROM_CSE_ERROR, "error: cse error"}, 457 {HDA_DSP_ROM_CSE_WRONG_RESPONSE, "error: cse wrong response"}, 458 {HDA_DSP_ROM_IMR_TO_SMALL, "error: IMR too small"}, 459 {HDA_DSP_ROM_BASE_FW_NOT_FOUND, "error: base fw not found"}, 460 {HDA_DSP_ROM_CSE_VALIDATION_FAILED, "error: signature verification failed"}, 461 {HDA_DSP_ROM_IPC_FATAL_ERROR, "error: ipc fatal error"}, 462 {HDA_DSP_ROM_L2_CACHE_ERROR, "error: L2 cache error"}, 463 {HDA_DSP_ROM_LOAD_OFFSET_TO_SMALL, "error: load offset too small"}, 464 {HDA_DSP_ROM_API_PTR_INVALID, "error: API ptr invalid"}, 465 {HDA_DSP_ROM_BASEFW_INCOMPAT, "error: base fw incompatible"}, 466 {HDA_DSP_ROM_UNHANDLED_INTERRUPT, "error: unhandled interrupt"}, 467 {HDA_DSP_ROM_MEMORY_HOLE_ECC, "error: ECC memory hole"}, 468 {HDA_DSP_ROM_KERNEL_EXCEPTION, "error: kernel exception"}, 469 {HDA_DSP_ROM_USER_EXCEPTION, "error: user exception"}, 470 {HDA_DSP_ROM_UNEXPECTED_RESET, "error: unexpected reset"}, 471 {HDA_DSP_ROM_NULL_FW_ENTRY, "error: null FW entry point"}, 472 }; 473 474 static void hda_dsp_get_status(struct snd_sof_dev *sdev) 475 { 476 u32 status; 477 int i; 478 479 status = snd_sof_dsp_read(sdev, HDA_DSP_BAR, 480 HDA_DSP_SRAM_REG_ROM_STATUS); 481 482 for (i = 0; i < ARRAY_SIZE(hda_dsp_rom_msg); i++) { 483 if (status == hda_dsp_rom_msg[i].code) { 484 dev_err(sdev->dev, "%s - code %8.8x\n", 485 hda_dsp_rom_msg[i].msg, status); 486 return; 487 } 488 } 489 490 /* not for us, must be generic sof message */ 491 dev_dbg(sdev->dev, "unknown ROM status value %8.8x\n", status); 492 } 493 494 static void hda_dsp_get_registers(struct snd_sof_dev *sdev, 495 struct sof_ipc_dsp_oops_xtensa *xoops, 496 struct sof_ipc_panic_info *panic_info, 497 u32 *stack, size_t stack_words) 498 { 499 u32 offset = sdev->dsp_oops_offset; 500 501 /* first read registers */ 502 sof_mailbox_read(sdev, offset, xoops, sizeof(*xoops)); 503 504 /* note: variable AR register array is not read */ 505 506 /* then get panic info */ 507 if (xoops->arch_hdr.totalsize > EXCEPT_MAX_HDR_SIZE) { 508 dev_err(sdev->dev, "invalid header size 0x%x. FW oops is bogus\n", 509 xoops->arch_hdr.totalsize); 510 return; 511 } 512 offset += xoops->arch_hdr.totalsize; 513 sof_block_read(sdev, sdev->mmio_bar, offset, 514 panic_info, sizeof(*panic_info)); 515 516 /* then get the stack */ 517 offset += sizeof(*panic_info); 518 sof_block_read(sdev, sdev->mmio_bar, offset, stack, 519 stack_words * sizeof(u32)); 520 } 521 522 /* dump the first 8 dwords representing the extended ROM status */ 523 static void hda_dsp_dump_ext_rom_status(struct snd_sof_dev *sdev, u32 flags) 524 { 525 char msg[128]; 526 int len = 0; 527 u32 value; 528 int i; 529 530 for (i = 0; i < HDA_EXT_ROM_STATUS_SIZE; i++) { 531 value = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_SRAM_REG_ROM_STATUS + i * 0x4); 532 len += snprintf(msg + len, sizeof(msg) - len, " 0x%x", value); 533 } 534 535 dev_err(sdev->dev, "extended rom status: %s", msg); 536 537 } 538 539 void hda_dsp_dump(struct snd_sof_dev *sdev, u32 flags) 540 { 541 struct sof_ipc_dsp_oops_xtensa xoops; 542 struct sof_ipc_panic_info panic_info; 543 u32 stack[HDA_DSP_STACK_DUMP_SIZE]; 544 545 /* print ROM/FW status */ 546 hda_dsp_get_status(sdev); 547 548 if (flags & SOF_DBG_DUMP_REGS) { 549 u32 status = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_SRAM_REG_FW_STATUS); 550 u32 panic = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_SRAM_REG_FW_TRACEP); 551 552 hda_dsp_get_registers(sdev, &xoops, &panic_info, stack, 553 HDA_DSP_STACK_DUMP_SIZE); 554 snd_sof_get_status(sdev, status, panic, &xoops, &panic_info, 555 stack, HDA_DSP_STACK_DUMP_SIZE); 556 } else { 557 hda_dsp_dump_ext_rom_status(sdev, flags); 558 } 559 } 560 561 void hda_ipc_irq_dump(struct snd_sof_dev *sdev) 562 { 563 struct hdac_bus *bus = sof_to_bus(sdev); 564 u32 adspis; 565 u32 intsts; 566 u32 intctl; 567 u32 ppsts; 568 u8 rirbsts; 569 570 /* read key IRQ stats and config registers */ 571 adspis = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_ADSPIS); 572 intsts = snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTSTS); 573 intctl = snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTCTL); 574 ppsts = snd_sof_dsp_read(sdev, HDA_DSP_PP_BAR, SOF_HDA_REG_PP_PPSTS); 575 rirbsts = snd_hdac_chip_readb(bus, RIRBSTS); 576 577 dev_err(sdev->dev, "hda irq intsts 0x%8.8x intlctl 0x%8.8x rirb %2.2x\n", 578 intsts, intctl, rirbsts); 579 dev_err(sdev->dev, "dsp irq ppsts 0x%8.8x adspis 0x%8.8x\n", ppsts, adspis); 580 } 581 582 void hda_ipc_dump(struct snd_sof_dev *sdev) 583 { 584 u32 hipcie; 585 u32 hipct; 586 u32 hipcctl; 587 588 hda_ipc_irq_dump(sdev); 589 590 /* read IPC status */ 591 hipcie = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCIE); 592 hipct = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCT); 593 hipcctl = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCCTL); 594 595 /* dump the IPC regs */ 596 /* TODO: parse the raw msg */ 597 dev_err(sdev->dev, "host status 0x%8.8x dsp status 0x%8.8x mask 0x%8.8x\n", 598 hipcie, hipct, hipcctl); 599 } 600 601 static int hda_init(struct snd_sof_dev *sdev) 602 { 603 struct hda_bus *hbus; 604 struct hdac_bus *bus; 605 struct pci_dev *pci = to_pci_dev(sdev->dev); 606 int ret; 607 608 hbus = sof_to_hbus(sdev); 609 bus = sof_to_bus(sdev); 610 611 /* HDA bus init */ 612 sof_hda_bus_init(bus, &pci->dev); 613 614 bus->use_posbuf = 1; 615 bus->bdl_pos_adj = 0; 616 bus->sync_write = 1; 617 618 mutex_init(&hbus->prepare_mutex); 619 hbus->pci = pci; 620 hbus->mixer_assigned = -1; 621 hbus->modelname = hda_model; 622 623 /* initialise hdac bus */ 624 bus->addr = pci_resource_start(pci, 0); 625 bus->remap_addr = pci_ioremap_bar(pci, 0); 626 if (!bus->remap_addr) { 627 dev_err(bus->dev, "error: ioremap error\n"); 628 return -ENXIO; 629 } 630 631 /* HDA base */ 632 sdev->bar[HDA_DSP_HDA_BAR] = bus->remap_addr; 633 634 /* init i915 and HDMI codecs */ 635 ret = hda_codec_i915_init(sdev); 636 if (ret < 0) 637 dev_warn(sdev->dev, "init of i915 and HDMI codec failed\n"); 638 639 /* get controller capabilities */ 640 ret = hda_dsp_ctrl_get_caps(sdev); 641 if (ret < 0) 642 dev_err(sdev->dev, "error: get caps error\n"); 643 644 return ret; 645 } 646 647 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) || IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE) 648 649 static int check_nhlt_dmic(struct snd_sof_dev *sdev) 650 { 651 struct nhlt_acpi_table *nhlt; 652 int dmic_num; 653 654 nhlt = intel_nhlt_init(sdev->dev); 655 if (nhlt) { 656 dmic_num = intel_nhlt_get_dmic_geo(sdev->dev, nhlt); 657 intel_nhlt_free(nhlt); 658 if (dmic_num >= 1 && dmic_num <= 4) 659 return dmic_num; 660 } 661 662 return 0; 663 } 664 665 static const char *fixup_tplg_name(struct snd_sof_dev *sdev, 666 const char *sof_tplg_filename, 667 const char *idisp_str, 668 const char *dmic_str) 669 { 670 const char *tplg_filename = NULL; 671 char *filename, *tmp; 672 const char *split_ext; 673 674 filename = kstrdup(sof_tplg_filename, GFP_KERNEL); 675 if (!filename) 676 return NULL; 677 678 /* this assumes a .tplg extension */ 679 tmp = filename; 680 split_ext = strsep(&tmp, "."); 681 if (split_ext) 682 tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL, 683 "%s%s%s.tplg", 684 split_ext, idisp_str, dmic_str); 685 kfree(filename); 686 687 return tplg_filename; 688 } 689 690 static int dmic_topology_fixup(struct snd_sof_dev *sdev, 691 const char **tplg_filename, 692 const char *idisp_str, 693 int *dmic_found) 694 { 695 const char *default_tplg_filename = *tplg_filename; 696 const char *fixed_tplg_filename; 697 const char *dmic_str; 698 int dmic_num; 699 700 /* first check NHLT for DMICs */ 701 dmic_num = check_nhlt_dmic(sdev); 702 703 /* allow for module parameter override */ 704 if (hda_dmic_num != -1) { 705 dev_dbg(sdev->dev, 706 "overriding DMICs detected in NHLT tables %d by kernel param %d\n", 707 dmic_num, hda_dmic_num); 708 dmic_num = hda_dmic_num; 709 } 710 711 switch (dmic_num) { 712 case 1: 713 dmic_str = "-1ch"; 714 break; 715 case 2: 716 dmic_str = "-2ch"; 717 break; 718 case 3: 719 dmic_str = "-3ch"; 720 break; 721 case 4: 722 dmic_str = "-4ch"; 723 break; 724 default: 725 dmic_num = 0; 726 dmic_str = ""; 727 break; 728 } 729 730 fixed_tplg_filename = fixup_tplg_name(sdev, default_tplg_filename, 731 idisp_str, dmic_str); 732 if (!fixed_tplg_filename) 733 return -ENOMEM; 734 735 dev_info(sdev->dev, "DMICs detected in NHLT tables: %d\n", dmic_num); 736 *dmic_found = dmic_num; 737 *tplg_filename = fixed_tplg_filename; 738 739 return 0; 740 } 741 #endif 742 743 static int hda_init_caps(struct snd_sof_dev *sdev) 744 { 745 struct hdac_bus *bus = sof_to_bus(sdev); 746 struct snd_sof_pdata *pdata = sdev->pdata; 747 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) 748 struct hdac_ext_link *hlink; 749 #endif 750 struct sof_intel_hda_dev *hdev = pdata->hw_pdata; 751 u32 link_mask; 752 int ret = 0; 753 754 /* check if dsp is there */ 755 if (bus->ppcap) 756 dev_dbg(sdev->dev, "PP capability, will probe DSP later.\n"); 757 758 /* Init HDA controller after i915 init */ 759 ret = hda_dsp_ctrl_init_chip(sdev, true); 760 if (ret < 0) { 761 dev_err(bus->dev, "error: init chip failed with ret: %d\n", 762 ret); 763 return ret; 764 } 765 766 /* scan SoundWire capabilities exposed by DSDT */ 767 ret = hda_sdw_acpi_scan(sdev); 768 if (ret < 0) { 769 dev_dbg(sdev->dev, "skipping SoundWire, not detected with ACPI scan\n"); 770 goto skip_soundwire; 771 } 772 773 link_mask = hdev->info.link_mask; 774 if (!link_mask) { 775 dev_dbg(sdev->dev, "skipping SoundWire, no links enabled\n"); 776 goto skip_soundwire; 777 } 778 779 /* 780 * probe/allocate SoundWire resources. 781 * The hardware configuration takes place in hda_sdw_startup 782 * after power rails are enabled. 783 * It's entirely possible to have a mix of I2S/DMIC/SoundWire 784 * devices, so we allocate the resources in all cases. 785 */ 786 ret = hda_sdw_probe(sdev); 787 if (ret < 0) { 788 dev_err(sdev->dev, "error: SoundWire probe error\n"); 789 return ret; 790 } 791 792 skip_soundwire: 793 794 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) 795 if (bus->mlcap) 796 snd_hdac_ext_bus_get_ml_capabilities(bus); 797 798 /* create codec instances */ 799 hda_codec_probe_bus(sdev, hda_codec_use_common_hdmi); 800 801 if (!HDA_IDISP_CODEC(bus->codec_mask)) 802 hda_codec_i915_display_power(sdev, false); 803 804 /* 805 * we are done probing so decrement link counts 806 */ 807 list_for_each_entry(hlink, &bus->hlink_list, list) 808 snd_hdac_ext_bus_link_put(bus, hlink); 809 #endif 810 return 0; 811 } 812 813 static void hda_check_for_state_change(struct snd_sof_dev *sdev) 814 { 815 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) 816 struct hdac_bus *bus = sof_to_bus(sdev); 817 unsigned int codec_mask; 818 819 codec_mask = snd_hdac_chip_readw(bus, STATESTS); 820 if (codec_mask) { 821 hda_codec_jack_check(sdev); 822 snd_hdac_chip_writew(bus, STATESTS, codec_mask); 823 } 824 #endif 825 } 826 827 static irqreturn_t hda_dsp_interrupt_handler(int irq, void *context) 828 { 829 struct snd_sof_dev *sdev = context; 830 831 /* 832 * Get global interrupt status. It includes all hardware interrupt 833 * sources in the Intel HD Audio controller. 834 */ 835 if (snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTSTS) & 836 SOF_HDA_INTSTS_GIS) { 837 838 /* disable GIE interrupt */ 839 snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR, 840 SOF_HDA_INTCTL, 841 SOF_HDA_INT_GLOBAL_EN, 842 0); 843 844 return IRQ_WAKE_THREAD; 845 } 846 847 return IRQ_NONE; 848 } 849 850 static irqreturn_t hda_dsp_interrupt_thread(int irq, void *context) 851 { 852 struct snd_sof_dev *sdev = context; 853 struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata; 854 855 /* deal with streams and controller first */ 856 if (hda_dsp_check_stream_irq(sdev)) 857 hda_dsp_stream_threaded_handler(irq, sdev); 858 859 if (hda_dsp_check_ipc_irq(sdev)) 860 sof_ops(sdev)->irq_thread(irq, sdev); 861 862 if (hda_dsp_check_sdw_irq(sdev)) 863 hda_dsp_sdw_thread(irq, hdev->sdw); 864 865 if (hda_sdw_check_wakeen_irq(sdev)) 866 hda_sdw_process_wakeen(sdev); 867 868 hda_check_for_state_change(sdev); 869 870 /* enable GIE interrupt */ 871 snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR, 872 SOF_HDA_INTCTL, 873 SOF_HDA_INT_GLOBAL_EN, 874 SOF_HDA_INT_GLOBAL_EN); 875 876 return IRQ_HANDLED; 877 } 878 879 int hda_dsp_probe(struct snd_sof_dev *sdev) 880 { 881 struct pci_dev *pci = to_pci_dev(sdev->dev); 882 struct sof_intel_hda_dev *hdev; 883 struct hdac_bus *bus; 884 const struct sof_intel_dsp_desc *chip; 885 int ret = 0; 886 887 /* 888 * detect DSP by checking class/subclass/prog-id information 889 * class=04 subclass 03 prog-if 00: no DSP, legacy driver is required 890 * class=04 subclass 01 prog-if 00: DSP is present 891 * (and may be required e.g. for DMIC or SSP support) 892 * class=04 subclass 03 prog-if 80: either of DSP or legacy mode works 893 */ 894 if (pci->class == 0x040300) { 895 dev_err(sdev->dev, "error: the DSP is not enabled on this platform, aborting probe\n"); 896 return -ENODEV; 897 } else if (pci->class != 0x040100 && pci->class != 0x040380) { 898 dev_err(sdev->dev, "error: unknown PCI class/subclass/prog-if 0x%06x found, aborting probe\n", pci->class); 899 return -ENODEV; 900 } 901 dev_info(sdev->dev, "DSP detected with PCI class/subclass/prog-if 0x%06x\n", pci->class); 902 903 chip = get_chip_info(sdev->pdata); 904 if (!chip) { 905 dev_err(sdev->dev, "error: no such device supported, chip id:%x\n", 906 pci->device); 907 ret = -EIO; 908 goto err; 909 } 910 911 hdev = devm_kzalloc(sdev->dev, sizeof(*hdev), GFP_KERNEL); 912 if (!hdev) 913 return -ENOMEM; 914 sdev->pdata->hw_pdata = hdev; 915 hdev->desc = chip; 916 917 hdev->dmic_dev = platform_device_register_data(sdev->dev, "dmic-codec", 918 PLATFORM_DEVID_NONE, 919 NULL, 0); 920 if (IS_ERR(hdev->dmic_dev)) { 921 dev_err(sdev->dev, "error: failed to create DMIC device\n"); 922 return PTR_ERR(hdev->dmic_dev); 923 } 924 925 /* 926 * use position update IPC if either it is forced 927 * or we don't have other choice 928 */ 929 #if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_FORCE_IPC_POSITION) 930 hdev->no_ipc_position = 0; 931 #else 932 hdev->no_ipc_position = sof_ops(sdev)->pcm_pointer ? 1 : 0; 933 #endif 934 935 /* set up HDA base */ 936 bus = sof_to_bus(sdev); 937 ret = hda_init(sdev); 938 if (ret < 0) 939 goto hdac_bus_unmap; 940 941 /* DSP base */ 942 sdev->bar[HDA_DSP_BAR] = pci_ioremap_bar(pci, HDA_DSP_BAR); 943 if (!sdev->bar[HDA_DSP_BAR]) { 944 dev_err(sdev->dev, "error: ioremap error\n"); 945 ret = -ENXIO; 946 goto hdac_bus_unmap; 947 } 948 949 sdev->mmio_bar = HDA_DSP_BAR; 950 sdev->mailbox_bar = HDA_DSP_BAR; 951 952 /* allow 64bit DMA address if supported by H/W */ 953 if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(64))) { 954 dev_dbg(sdev->dev, "DMA mask is 32 bit\n"); 955 dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(32)); 956 } 957 958 /* init streams */ 959 ret = hda_dsp_stream_init(sdev); 960 if (ret < 0) { 961 dev_err(sdev->dev, "error: failed to init streams\n"); 962 /* 963 * not all errors are due to memory issues, but trying 964 * to free everything does not harm 965 */ 966 goto free_streams; 967 } 968 969 /* 970 * register our IRQ 971 * let's try to enable msi firstly 972 * if it fails, use legacy interrupt mode 973 * TODO: support msi multiple vectors 974 */ 975 if (hda_use_msi && pci_alloc_irq_vectors(pci, 1, 1, PCI_IRQ_MSI) > 0) { 976 dev_info(sdev->dev, "use msi interrupt mode\n"); 977 sdev->ipc_irq = pci_irq_vector(pci, 0); 978 /* initialised to "false" by kzalloc() */ 979 sdev->msi_enabled = true; 980 } 981 982 if (!sdev->msi_enabled) { 983 dev_info(sdev->dev, "use legacy interrupt mode\n"); 984 /* 985 * in IO-APIC mode, hda->irq and ipc_irq are using the same 986 * irq number of pci->irq 987 */ 988 sdev->ipc_irq = pci->irq; 989 } 990 991 dev_dbg(sdev->dev, "using IPC IRQ %d\n", sdev->ipc_irq); 992 ret = request_threaded_irq(sdev->ipc_irq, hda_dsp_interrupt_handler, 993 hda_dsp_interrupt_thread, 994 IRQF_SHARED, "AudioDSP", sdev); 995 if (ret < 0) { 996 dev_err(sdev->dev, "error: failed to register IPC IRQ %d\n", 997 sdev->ipc_irq); 998 goto free_irq_vector; 999 } 1000 1001 pci_set_master(pci); 1002 synchronize_irq(pci->irq); 1003 1004 /* 1005 * clear TCSEL to clear playback on some HD Audio 1006 * codecs. PCI TCSEL is defined in the Intel manuals. 1007 */ 1008 snd_sof_pci_update_bits(sdev, PCI_TCSEL, 0x07, 0); 1009 1010 /* init HDA capabilities */ 1011 ret = hda_init_caps(sdev); 1012 if (ret < 0) 1013 goto free_ipc_irq; 1014 1015 /* enable ppcap interrupt */ 1016 hda_dsp_ctrl_ppcap_enable(sdev, true); 1017 hda_dsp_ctrl_ppcap_int_enable(sdev, true); 1018 1019 /* set default mailbox offset for FW ready message */ 1020 sdev->dsp_box.offset = HDA_DSP_MBOX_UPLINK_OFFSET; 1021 1022 INIT_DELAYED_WORK(&hdev->d0i3_work, hda_dsp_d0i3_work); 1023 1024 return 0; 1025 1026 free_ipc_irq: 1027 free_irq(sdev->ipc_irq, sdev); 1028 free_irq_vector: 1029 if (sdev->msi_enabled) 1030 pci_free_irq_vectors(pci); 1031 free_streams: 1032 hda_dsp_stream_free(sdev); 1033 /* dsp_unmap: not currently used */ 1034 iounmap(sdev->bar[HDA_DSP_BAR]); 1035 hdac_bus_unmap: 1036 platform_device_unregister(hdev->dmic_dev); 1037 iounmap(bus->remap_addr); 1038 hda_codec_i915_exit(sdev); 1039 err: 1040 return ret; 1041 } 1042 1043 int hda_dsp_remove(struct snd_sof_dev *sdev) 1044 { 1045 struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata; 1046 struct hdac_bus *bus = sof_to_bus(sdev); 1047 struct pci_dev *pci = to_pci_dev(sdev->dev); 1048 const struct sof_intel_dsp_desc *chip = hda->desc; 1049 1050 /* cancel any attempt for DSP D0I3 */ 1051 cancel_delayed_work_sync(&hda->d0i3_work); 1052 1053 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) 1054 /* codec removal, invoke bus_device_remove */ 1055 snd_hdac_ext_bus_device_remove(bus); 1056 #endif 1057 1058 hda_sdw_exit(sdev); 1059 1060 if (!IS_ERR_OR_NULL(hda->dmic_dev)) 1061 platform_device_unregister(hda->dmic_dev); 1062 1063 /* disable DSP IRQ */ 1064 snd_sof_dsp_update_bits(sdev, HDA_DSP_PP_BAR, SOF_HDA_REG_PP_PPCTL, 1065 SOF_HDA_PPCTL_PIE, 0); 1066 1067 /* disable CIE and GIE interrupts */ 1068 snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTCTL, 1069 SOF_HDA_INT_CTRL_EN | SOF_HDA_INT_GLOBAL_EN, 0); 1070 1071 /* disable cores */ 1072 if (chip) 1073 snd_sof_dsp_core_power_down(sdev, chip->host_managed_cores_mask); 1074 1075 /* disable DSP */ 1076 snd_sof_dsp_update_bits(sdev, HDA_DSP_PP_BAR, SOF_HDA_REG_PP_PPCTL, 1077 SOF_HDA_PPCTL_GPROCEN, 0); 1078 1079 free_irq(sdev->ipc_irq, sdev); 1080 if (sdev->msi_enabled) 1081 pci_free_irq_vectors(pci); 1082 1083 hda_dsp_stream_free(sdev); 1084 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) 1085 snd_hdac_link_free_all(bus); 1086 #endif 1087 1088 iounmap(sdev->bar[HDA_DSP_BAR]); 1089 iounmap(bus->remap_addr); 1090 1091 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) 1092 snd_hdac_ext_bus_exit(bus); 1093 #endif 1094 hda_codec_i915_exit(sdev); 1095 1096 return 0; 1097 } 1098 1099 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) 1100 static int hda_generic_machine_select(struct snd_sof_dev *sdev) 1101 { 1102 struct hdac_bus *bus = sof_to_bus(sdev); 1103 struct snd_soc_acpi_mach_params *mach_params; 1104 struct snd_soc_acpi_mach *hda_mach; 1105 struct snd_sof_pdata *pdata = sdev->pdata; 1106 const char *tplg_filename; 1107 const char *idisp_str; 1108 int dmic_num = 0; 1109 int codec_num = 0; 1110 int ret; 1111 int i; 1112 1113 /* codec detection */ 1114 if (!bus->codec_mask) { 1115 dev_info(bus->dev, "no hda codecs found!\n"); 1116 } else { 1117 dev_info(bus->dev, "hda codecs found, mask %lx\n", 1118 bus->codec_mask); 1119 1120 for (i = 0; i < HDA_MAX_CODECS; i++) { 1121 if (bus->codec_mask & (1 << i)) 1122 codec_num++; 1123 } 1124 1125 /* 1126 * If no machine driver is found, then: 1127 * 1128 * generic hda machine driver can handle: 1129 * - one HDMI codec, and/or 1130 * - one external HDAudio codec 1131 */ 1132 if (!pdata->machine && codec_num <= 2) { 1133 hda_mach = snd_soc_acpi_intel_hda_machines; 1134 1135 dev_info(bus->dev, "using HDA machine driver %s now\n", 1136 hda_mach->drv_name); 1137 1138 if (codec_num == 1 && HDA_IDISP_CODEC(bus->codec_mask)) 1139 idisp_str = "-idisp"; 1140 else 1141 idisp_str = ""; 1142 1143 /* topology: use the info from hda_machines */ 1144 tplg_filename = hda_mach->sof_tplg_filename; 1145 ret = dmic_topology_fixup(sdev, &tplg_filename, idisp_str, &dmic_num); 1146 if (ret < 0) 1147 return ret; 1148 1149 hda_mach->mach_params.dmic_num = dmic_num; 1150 pdata->machine = hda_mach; 1151 pdata->tplg_filename = tplg_filename; 1152 1153 if (codec_num == 2) { 1154 /* 1155 * Prevent SoundWire links from starting when an external 1156 * HDaudio codec is used 1157 */ 1158 hda_mach->mach_params.link_mask = 0; 1159 } 1160 } 1161 } 1162 1163 /* used by hda machine driver to create dai links */ 1164 if (pdata->machine) { 1165 mach_params = (struct snd_soc_acpi_mach_params *) 1166 &pdata->machine->mach_params; 1167 mach_params->codec_mask = bus->codec_mask; 1168 mach_params->common_hdmi_codec_drv = hda_codec_use_common_hdmi; 1169 } 1170 1171 return 0; 1172 } 1173 #else 1174 static int hda_generic_machine_select(struct snd_sof_dev *sdev) 1175 { 1176 return 0; 1177 } 1178 #endif 1179 1180 #if IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE) 1181 /* Check if all Slaves defined on the link can be found */ 1182 static bool link_slaves_found(struct snd_sof_dev *sdev, 1183 const struct snd_soc_acpi_link_adr *link, 1184 struct sdw_intel_ctx *sdw) 1185 { 1186 struct hdac_bus *bus = sof_to_bus(sdev); 1187 struct sdw_intel_slave_id *ids = sdw->ids; 1188 int num_slaves = sdw->num_slaves; 1189 unsigned int part_id, link_id, unique_id, mfg_id; 1190 int i, j, k; 1191 1192 for (i = 0; i < link->num_adr; i++) { 1193 u64 adr = link->adr_d[i].adr; 1194 int reported_part_count = 0; 1195 1196 mfg_id = SDW_MFG_ID(adr); 1197 part_id = SDW_PART_ID(adr); 1198 link_id = SDW_DISCO_LINK_ID(adr); 1199 1200 for (j = 0; j < num_slaves; j++) { 1201 /* find out how many identical parts were reported on that link */ 1202 if (ids[j].link_id == link_id && 1203 ids[j].id.part_id == part_id && 1204 ids[j].id.mfg_id == mfg_id) 1205 reported_part_count++; 1206 } 1207 1208 for (j = 0; j < num_slaves; j++) { 1209 int expected_part_count = 0; 1210 1211 if (ids[j].link_id != link_id || 1212 ids[j].id.part_id != part_id || 1213 ids[j].id.mfg_id != mfg_id) 1214 continue; 1215 1216 /* find out how many identical parts are expected */ 1217 for (k = 0; k < link->num_adr; k++) { 1218 u64 adr2 = link->adr_d[k].adr; 1219 unsigned int part_id2, link_id2, mfg_id2; 1220 1221 mfg_id2 = SDW_MFG_ID(adr2); 1222 part_id2 = SDW_PART_ID(adr2); 1223 link_id2 = SDW_DISCO_LINK_ID(adr2); 1224 1225 if (link_id2 == link_id && 1226 part_id2 == part_id && 1227 mfg_id2 == mfg_id) 1228 expected_part_count++; 1229 } 1230 1231 if (reported_part_count == expected_part_count) { 1232 /* 1233 * we have to check unique id 1234 * if there is more than one 1235 * Slave on the link 1236 */ 1237 unique_id = SDW_UNIQUE_ID(adr); 1238 if (reported_part_count == 1 || 1239 ids[j].id.unique_id == unique_id) { 1240 dev_dbg(bus->dev, "found %x at link %d\n", 1241 part_id, link_id); 1242 break; 1243 } 1244 } else { 1245 dev_dbg(bus->dev, "part %x reported %d expected %d on link %d, skipping\n", 1246 part_id, reported_part_count, expected_part_count, link_id); 1247 } 1248 } 1249 if (j == num_slaves) { 1250 dev_dbg(bus->dev, 1251 "Slave %x not found\n", 1252 part_id); 1253 return false; 1254 } 1255 } 1256 return true; 1257 } 1258 1259 static int hda_sdw_machine_select(struct snd_sof_dev *sdev) 1260 { 1261 struct snd_sof_pdata *pdata = sdev->pdata; 1262 const struct snd_soc_acpi_link_adr *link; 1263 struct snd_soc_acpi_mach *mach; 1264 struct sof_intel_hda_dev *hdev; 1265 u32 link_mask; 1266 int i; 1267 1268 hdev = pdata->hw_pdata; 1269 link_mask = hdev->info.link_mask; 1270 1271 /* 1272 * Select SoundWire machine driver if needed using the 1273 * alternate tables. This case deals with SoundWire-only 1274 * machines, for mixed cases with I2C/I2S the detection relies 1275 * on the HID list. 1276 */ 1277 if (link_mask && !pdata->machine) { 1278 for (mach = pdata->desc->alt_machines; 1279 mach && mach->link_mask; mach++) { 1280 /* 1281 * On some platforms such as Up Extreme all links 1282 * are enabled but only one link can be used by 1283 * external codec. Instead of exact match of two masks, 1284 * first check whether link_mask of mach is subset of 1285 * link_mask supported by hw and then go on searching 1286 * link_adr 1287 */ 1288 if (~link_mask & mach->link_mask) 1289 continue; 1290 1291 /* No need to match adr if there is no links defined */ 1292 if (!mach->links) 1293 break; 1294 1295 link = mach->links; 1296 for (i = 0; i < hdev->info.count && link->num_adr; 1297 i++, link++) { 1298 /* 1299 * Try next machine if any expected Slaves 1300 * are not found on this link. 1301 */ 1302 if (!link_slaves_found(sdev, link, hdev->sdw)) 1303 break; 1304 } 1305 /* Found if all Slaves are checked */ 1306 if (i == hdev->info.count || !link->num_adr) 1307 break; 1308 } 1309 if (mach && mach->link_mask) { 1310 int dmic_num = 0; 1311 1312 pdata->machine = mach; 1313 mach->mach_params.links = mach->links; 1314 mach->mach_params.link_mask = mach->link_mask; 1315 mach->mach_params.platform = dev_name(sdev->dev); 1316 if (mach->sof_fw_filename) 1317 pdata->fw_filename = mach->sof_fw_filename; 1318 else 1319 pdata->fw_filename = pdata->desc->default_fw_filename; 1320 pdata->tplg_filename = mach->sof_tplg_filename; 1321 1322 /* 1323 * DMICs use up to 4 pins and are typically pin-muxed with SoundWire 1324 * link 2 and 3, thus we only try to enable dmics if all conditions 1325 * are true: 1326 * a) link 2 and 3 are not used by SoundWire 1327 * b) the NHLT table reports the presence of microphones 1328 */ 1329 if (!(mach->link_mask & GENMASK(3, 2))) { 1330 const char *tplg_filename = mach->sof_tplg_filename; 1331 int ret; 1332 1333 ret = dmic_topology_fixup(sdev, &tplg_filename, "", &dmic_num); 1334 1335 if (ret < 0) 1336 return ret; 1337 1338 pdata->tplg_filename = tplg_filename; 1339 } 1340 mach->mach_params.dmic_num = dmic_num; 1341 1342 dev_dbg(sdev->dev, 1343 "SoundWire machine driver %s topology %s\n", 1344 mach->drv_name, 1345 pdata->tplg_filename); 1346 } else { 1347 dev_info(sdev->dev, 1348 "No SoundWire machine driver found\n"); 1349 } 1350 } 1351 1352 return 0; 1353 } 1354 #else 1355 static int hda_sdw_machine_select(struct snd_sof_dev *sdev) 1356 { 1357 return 0; 1358 } 1359 #endif 1360 1361 void hda_set_mach_params(const struct snd_soc_acpi_mach *mach, 1362 struct snd_sof_dev *sdev) 1363 { 1364 struct snd_sof_pdata *pdata = sdev->pdata; 1365 const struct sof_dev_desc *desc = pdata->desc; 1366 struct snd_soc_acpi_mach_params *mach_params; 1367 1368 mach_params = (struct snd_soc_acpi_mach_params *)&mach->mach_params; 1369 mach_params->platform = dev_name(sdev->dev); 1370 mach_params->num_dai_drivers = desc->ops->num_drv; 1371 mach_params->dai_drivers = desc->ops->drv; 1372 } 1373 1374 void hda_machine_select(struct snd_sof_dev *sdev) 1375 { 1376 struct snd_sof_pdata *sof_pdata = sdev->pdata; 1377 const struct sof_dev_desc *desc = sof_pdata->desc; 1378 struct snd_soc_acpi_mach *mach; 1379 1380 mach = snd_soc_acpi_find_machine(desc->machines); 1381 if (mach) { 1382 /* 1383 * If tplg file name is overridden, use it instead of 1384 * the one set in mach table 1385 */ 1386 if (!sof_pdata->tplg_filename) 1387 sof_pdata->tplg_filename = mach->sof_tplg_filename; 1388 1389 sof_pdata->machine = mach; 1390 1391 if (mach->link_mask) { 1392 mach->mach_params.links = mach->links; 1393 mach->mach_params.link_mask = mach->link_mask; 1394 } 1395 } 1396 1397 /* 1398 * If I2S fails, try SoundWire 1399 */ 1400 hda_sdw_machine_select(sdev); 1401 1402 /* 1403 * Choose HDA generic machine driver if mach is NULL. 1404 * Otherwise, set certain mach params. 1405 */ 1406 hda_generic_machine_select(sdev); 1407 1408 if (!sof_pdata->machine) 1409 dev_warn(sdev->dev, "warning: No matching ASoC machine driver found\n"); 1410 } 1411 1412 int hda_pci_intel_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) 1413 { 1414 int ret; 1415 1416 ret = snd_intel_dsp_driver_probe(pci); 1417 if (ret != SND_INTEL_DSP_DRIVER_ANY && ret != SND_INTEL_DSP_DRIVER_SOF) { 1418 dev_dbg(&pci->dev, "SOF PCI driver not selected, aborting probe\n"); 1419 return -ENODEV; 1420 } 1421 1422 return sof_pci_probe(pci, pci_id); 1423 } 1424 EXPORT_SYMBOL_NS(hda_pci_intel_probe, SND_SOC_SOF_INTEL_HDA_COMMON); 1425 1426 MODULE_LICENSE("Dual BSD/GPL"); 1427 MODULE_IMPORT_NS(SND_SOC_SOF_PCI_DEV); 1428 MODULE_IMPORT_NS(SND_SOC_SOF_HDA_AUDIO_CODEC); 1429 MODULE_IMPORT_NS(SND_SOC_SOF_HDA_AUDIO_CODEC_I915); 1430 MODULE_IMPORT_NS(SND_SOC_SOF_XTENSA); 1431 MODULE_IMPORT_NS(SND_INTEL_SOUNDWIRE_ACPI); 1432 MODULE_IMPORT_NS(SOUNDWIRE_INTEL_INIT); 1433