1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
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.
6 // Copyright(c) 2018 Intel Corporation. All rights reserved.
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>
15 * Hardware interface for generic Intel audio DSP HDA IP
18 #include <sound/hdaudio_ext.h>
19 #include <sound/hda_register.h>
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"
34 #define CREATE_TRACE_POINTS
35 #include <trace/events/sof_intel.h>
37 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
38 #include <sound/soc-acpi-intel-match.h>
41 /* platform specific devices */
44 #define EXCEPT_MAX_HDR_SIZE 0x400
45 #define HDA_EXT_ROM_STATUS_SIZE 8
47 int hda_ctrl_dai_widget_setup(struct snd_soc_dapm_widget *w, unsigned int quirk_flags,
48 struct snd_sof_dai_config_data *data)
50 struct snd_sof_widget *swidget = w->dobj.private;
51 struct snd_soc_component *component = swidget->scomp;
52 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
53 const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
54 struct snd_sof_dai *sof_dai = swidget->private;
58 dev_err(sdev->dev, "%s: No DAI for DAI widget %s\n", __func__, w->name);
62 if (tplg_ops->dai_config) {
65 /* set HW_PARAMS flag along with quirks */
66 flags = SOF_DAI_CONFIG_FLAGS_HW_PARAMS |
67 quirk_flags << SOF_DAI_CONFIG_FLAGS_QUIRK_SHIFT;
69 ret = tplg_ops->dai_config(sdev, swidget, flags, data);
71 dev_err(sdev->dev, "%s: DAI config failed for widget %s\n", __func__,
80 int hda_ctrl_dai_widget_free(struct snd_soc_dapm_widget *w, unsigned int quirk_flags,
81 struct snd_sof_dai_config_data *data)
83 struct snd_sof_widget *swidget = w->dobj.private;
84 struct snd_soc_component *component = swidget->scomp;
85 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
86 const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
87 struct snd_sof_dai *sof_dai = swidget->private;
90 dev_err(sdev->dev, "%s: No DAI for BE DAI widget %s\n", __func__, w->name);
94 if (tplg_ops->dai_config) {
98 /* set HW_FREE flag along with any quirks */
99 flags = SOF_DAI_CONFIG_FLAGS_HW_FREE |
100 quirk_flags << SOF_DAI_CONFIG_FLAGS_QUIRK_SHIFT;
102 ret = tplg_ops->dai_config(sdev, swidget, flags, data);
104 dev_err(sdev->dev, "%s: DAI config failed for widget '%s'\n", __func__,
111 #if IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE)
114 * The default for SoundWire clock stop quirks is to power gate the IP
115 * and do a Bus Reset, this will need to be modified when the DSP
116 * needs to remain in D0i3 so that the Master does not lose context
117 * and enumeration is not required on clock restart
119 static int sdw_clock_stop_quirks = SDW_INTEL_CLK_STOP_BUS_RESET;
120 module_param(sdw_clock_stop_quirks, int, 0444);
121 MODULE_PARM_DESC(sdw_clock_stop_quirks, "SOF SoundWire clock stop quirks");
123 static int sdw_params_stream(struct device *dev,
124 struct sdw_intel_stream_params_data *params_data)
126 struct snd_soc_dai *d = params_data->dai;
127 struct snd_sof_dai_config_data data;
128 struct snd_soc_dapm_widget *w;
130 w = snd_soc_dai_get_widget(d, params_data->stream);
131 data.dai_index = (params_data->link_id << 8) | d->id;
132 data.dai_data = params_data->alh_stream_id;
134 return hda_ctrl_dai_widget_setup(w, SOF_DAI_CONFIG_FLAGS_NONE, &data);
137 static int sdw_free_stream(struct device *dev,
138 struct sdw_intel_stream_free_data *free_data)
140 struct snd_soc_dai *d = free_data->dai;
141 struct snd_sof_dai_config_data data;
142 struct snd_soc_dapm_widget *w;
144 w = snd_soc_dai_get_widget(d, free_data->stream);
145 data.dai_index = (free_data->link_id << 8) | d->id;
147 /* send invalid stream_id */
148 data.dai_data = 0xFFFF;
150 return hda_ctrl_dai_widget_free(w, SOF_DAI_CONFIG_FLAGS_NONE, &data);
153 struct sdw_intel_ops sdw_callback = {
154 .params_stream = sdw_params_stream,
155 .free_stream = sdw_free_stream,
158 void hda_common_enable_sdw_irq(struct snd_sof_dev *sdev, bool enable)
160 struct sof_intel_hda_dev *hdev;
162 hdev = sdev->pdata->hw_pdata;
167 snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, HDA_DSP_REG_ADSPIC2,
168 HDA_DSP_REG_ADSPIC2_SNDW,
169 enable ? HDA_DSP_REG_ADSPIC2_SNDW : 0);
172 void hda_sdw_int_enable(struct snd_sof_dev *sdev, bool enable)
174 const struct sof_intel_dsp_desc *chip;
176 chip = get_chip_info(sdev->pdata);
177 if (chip && chip->enable_sdw_irq)
178 chip->enable_sdw_irq(sdev, enable);
181 static int hda_sdw_acpi_scan(struct snd_sof_dev *sdev)
183 struct sof_intel_hda_dev *hdev;
187 handle = ACPI_HANDLE(sdev->dev);
189 /* save ACPI info for the probe step */
190 hdev = sdev->pdata->hw_pdata;
192 ret = sdw_intel_acpi_scan(handle, &hdev->info);
199 static int hda_sdw_probe(struct snd_sof_dev *sdev)
201 struct sof_intel_hda_dev *hdev;
202 struct sdw_intel_res res;
205 hdev = sdev->pdata->hw_pdata;
207 memset(&res, 0, sizeof(res));
209 res.hw_ops = &sdw_intel_cnl_hw_ops;
210 res.mmio_base = sdev->bar[HDA_DSP_BAR];
211 res.shim_base = hdev->desc->sdw_shim_base;
212 res.alh_base = hdev->desc->sdw_alh_base;
213 res.irq = sdev->ipc_irq;
214 res.handle = hdev->info.handle;
215 res.parent = sdev->dev;
216 res.ops = &sdw_callback;
218 res.clock_stop_quirks = sdw_clock_stop_quirks;
221 * ops and arg fields are not populated for now,
222 * they will be needed when the DAI callbacks are
226 /* we could filter links here if needed, e.g for quirks */
227 res.count = hdev->info.count;
228 res.link_mask = hdev->info.link_mask;
230 sdw = sdw_intel_probe(&res);
232 dev_err(sdev->dev, "error: SoundWire probe failed\n");
242 int hda_sdw_check_lcount_common(struct snd_sof_dev *sdev)
244 struct sof_intel_hda_dev *hdev;
245 struct sdw_intel_ctx *ctx;
248 hdev = sdev->pdata->hw_pdata;
251 caps = snd_sof_dsp_read(sdev, HDA_DSP_BAR, ctx->shim_base + SDW_SHIM_LCAP);
252 caps &= SDW_SHIM_LCAP_LCOUNT_MASK;
254 /* Check HW supported vs property value */
255 if (caps < ctx->count) {
257 "BIOS master count %d is larger than hardware capabilities %d\n",
265 static int hda_sdw_check_lcount(struct snd_sof_dev *sdev)
267 const struct sof_intel_dsp_desc *chip;
269 chip = get_chip_info(sdev->pdata);
270 if (chip && chip->read_sdw_lcount)
271 return chip->read_sdw_lcount(sdev);
276 int hda_sdw_startup(struct snd_sof_dev *sdev)
278 struct sof_intel_hda_dev *hdev;
279 struct snd_sof_pdata *pdata = sdev->pdata;
282 hdev = sdev->pdata->hw_pdata;
287 if (pdata->machine && !pdata->machine->mach_params.link_mask)
290 ret = hda_sdw_check_lcount(sdev);
294 return sdw_intel_startup(hdev->sdw);
297 static int hda_sdw_exit(struct snd_sof_dev *sdev)
299 struct sof_intel_hda_dev *hdev;
301 hdev = sdev->pdata->hw_pdata;
303 hda_sdw_int_enable(sdev, false);
306 sdw_intel_exit(hdev->sdw);
312 bool hda_common_check_sdw_irq(struct snd_sof_dev *sdev)
314 struct sof_intel_hda_dev *hdev;
318 hdev = sdev->pdata->hw_pdata;
324 irq_status = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_ADSPIS2);
326 /* invalid message ? */
327 if (irq_status == 0xffffffff)
331 if (irq_status & HDA_DSP_REG_ADSPIS2_SNDW)
338 static bool hda_dsp_check_sdw_irq(struct snd_sof_dev *sdev)
340 const struct sof_intel_dsp_desc *chip;
342 chip = get_chip_info(sdev->pdata);
343 if (chip && chip->check_sdw_irq)
344 return chip->check_sdw_irq(sdev);
349 static irqreturn_t hda_dsp_sdw_thread(int irq, void *context)
351 return sdw_intel_thread(irq, context);
354 static bool hda_sdw_check_wakeen_irq(struct snd_sof_dev *sdev)
356 struct sof_intel_hda_dev *hdev;
358 hdev = sdev->pdata->hw_pdata;
360 snd_sof_dsp_read(sdev, HDA_DSP_BAR,
361 hdev->desc->sdw_shim_base + SDW_SHIM_WAKESTS))
367 void hda_sdw_process_wakeen(struct snd_sof_dev *sdev)
369 struct sof_intel_hda_dev *hdev;
371 hdev = sdev->pdata->hw_pdata;
375 sdw_intel_process_wakeen_event(hdev->sdw);
378 #else /* IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE) */
379 static inline int hda_sdw_acpi_scan(struct snd_sof_dev *sdev)
384 static inline int hda_sdw_probe(struct snd_sof_dev *sdev)
389 static inline int hda_sdw_exit(struct snd_sof_dev *sdev)
394 static inline bool hda_dsp_check_sdw_irq(struct snd_sof_dev *sdev)
399 static inline irqreturn_t hda_dsp_sdw_thread(int irq, void *context)
404 static inline bool hda_sdw_check_wakeen_irq(struct snd_sof_dev *sdev)
409 #endif /* IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE) */
415 struct hda_dsp_msg_code {
420 #if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG)
421 static bool hda_use_msi = true;
422 module_param_named(use_msi, hda_use_msi, bool, 0444);
423 MODULE_PARM_DESC(use_msi, "SOF HDA use PCI MSI mode");
425 #define hda_use_msi (1)
428 int sof_hda_position_quirk = SOF_HDA_POSITION_QUIRK_USE_DPIB_REGISTERS;
429 module_param_named(position_quirk, sof_hda_position_quirk, int, 0444);
430 MODULE_PARM_DESC(position_quirk, "SOF HDaudio position quirk");
432 static char *hda_model;
433 module_param(hda_model, charp, 0444);
434 MODULE_PARM_DESC(hda_model, "Use the given HDA board model.");
436 static int dmic_num_override = -1;
437 module_param_named(dmic_num, dmic_num_override, int, 0444);
438 MODULE_PARM_DESC(dmic_num, "SOF HDA DMIC number");
440 static int mclk_id_override = -1;
441 module_param_named(mclk_id, mclk_id_override, int, 0444);
442 MODULE_PARM_DESC(mclk_id, "SOF SSP mclk_id");
444 static const struct hda_dsp_msg_code hda_dsp_rom_fw_error_texts[] = {
445 {HDA_DSP_ROM_CSE_ERROR, "error: cse error"},
446 {HDA_DSP_ROM_CSE_WRONG_RESPONSE, "error: cse wrong response"},
447 {HDA_DSP_ROM_IMR_TO_SMALL, "error: IMR too small"},
448 {HDA_DSP_ROM_BASE_FW_NOT_FOUND, "error: base fw not found"},
449 {HDA_DSP_ROM_CSE_VALIDATION_FAILED, "error: signature verification failed"},
450 {HDA_DSP_ROM_IPC_FATAL_ERROR, "error: ipc fatal error"},
451 {HDA_DSP_ROM_L2_CACHE_ERROR, "error: L2 cache error"},
452 {HDA_DSP_ROM_LOAD_OFFSET_TO_SMALL, "error: load offset too small"},
453 {HDA_DSP_ROM_API_PTR_INVALID, "error: API ptr invalid"},
454 {HDA_DSP_ROM_BASEFW_INCOMPAT, "error: base fw incompatible"},
455 {HDA_DSP_ROM_UNHANDLED_INTERRUPT, "error: unhandled interrupt"},
456 {HDA_DSP_ROM_MEMORY_HOLE_ECC, "error: ECC memory hole"},
457 {HDA_DSP_ROM_KERNEL_EXCEPTION, "error: kernel exception"},
458 {HDA_DSP_ROM_USER_EXCEPTION, "error: user exception"},
459 {HDA_DSP_ROM_UNEXPECTED_RESET, "error: unexpected reset"},
460 {HDA_DSP_ROM_NULL_FW_ENTRY, "error: null FW entry point"},
463 #define FSR_ROM_STATE_ENTRY(state) {FSR_STATE_ROM_##state, #state}
464 static const struct hda_dsp_msg_code fsr_rom_state_names[] = {
465 FSR_ROM_STATE_ENTRY(INIT),
466 FSR_ROM_STATE_ENTRY(INIT_DONE),
467 FSR_ROM_STATE_ENTRY(CSE_MANIFEST_LOADED),
468 FSR_ROM_STATE_ENTRY(FW_MANIFEST_LOADED),
469 FSR_ROM_STATE_ENTRY(FW_FW_LOADED),
470 FSR_ROM_STATE_ENTRY(FW_ENTERED),
471 FSR_ROM_STATE_ENTRY(VERIFY_FEATURE_MASK),
472 FSR_ROM_STATE_ENTRY(GET_LOAD_OFFSET),
473 FSR_ROM_STATE_ENTRY(FETCH_ROM_EXT),
474 FSR_ROM_STATE_ENTRY(FETCH_ROM_EXT_DONE),
476 FSR_ROM_STATE_ENTRY(CSE_IMR_REQUEST),
477 FSR_ROM_STATE_ENTRY(CSE_IMR_GRANTED),
478 FSR_ROM_STATE_ENTRY(CSE_VALIDATE_IMAGE_REQUEST),
479 FSR_ROM_STATE_ENTRY(CSE_IMAGE_VALIDATED),
480 FSR_ROM_STATE_ENTRY(CSE_IPC_IFACE_INIT),
481 FSR_ROM_STATE_ENTRY(CSE_IPC_RESET_PHASE_1),
482 FSR_ROM_STATE_ENTRY(CSE_IPC_OPERATIONAL_ENTRY),
483 FSR_ROM_STATE_ENTRY(CSE_IPC_OPERATIONAL),
484 FSR_ROM_STATE_ENTRY(CSE_IPC_DOWN),
487 #define FSR_BRINGUP_STATE_ENTRY(state) {FSR_STATE_BRINGUP_##state, #state}
488 static const struct hda_dsp_msg_code fsr_bringup_state_names[] = {
489 FSR_BRINGUP_STATE_ENTRY(INIT),
490 FSR_BRINGUP_STATE_ENTRY(INIT_DONE),
491 FSR_BRINGUP_STATE_ENTRY(HPSRAM_LOAD),
492 FSR_BRINGUP_STATE_ENTRY(UNPACK_START),
493 FSR_BRINGUP_STATE_ENTRY(IMR_RESTORE),
494 FSR_BRINGUP_STATE_ENTRY(FW_ENTERED),
497 #define FSR_WAIT_STATE_ENTRY(state) {FSR_WAIT_FOR_##state, #state}
498 static const struct hda_dsp_msg_code fsr_wait_state_names[] = {
499 FSR_WAIT_STATE_ENTRY(IPC_BUSY),
500 FSR_WAIT_STATE_ENTRY(IPC_DONE),
501 FSR_WAIT_STATE_ENTRY(CACHE_INVALIDATION),
502 FSR_WAIT_STATE_ENTRY(LP_SRAM_OFF),
503 FSR_WAIT_STATE_ENTRY(DMA_BUFFER_FULL),
504 FSR_WAIT_STATE_ENTRY(CSE_CSR),
507 #define FSR_MODULE_NAME_ENTRY(mod) [FSR_MOD_##mod] = #mod
508 static const char * const fsr_module_names[] = {
509 FSR_MODULE_NAME_ENTRY(ROM),
510 FSR_MODULE_NAME_ENTRY(ROM_BYP),
511 FSR_MODULE_NAME_ENTRY(BASE_FW),
512 FSR_MODULE_NAME_ENTRY(LP_BOOT),
513 FSR_MODULE_NAME_ENTRY(BRNGUP),
514 FSR_MODULE_NAME_ENTRY(ROM_EXT),
518 hda_dsp_get_state_text(u32 code, const struct hda_dsp_msg_code *msg_code,
523 for (i = 0; i < array_size; i++) {
524 if (code == msg_code[i].code)
525 return msg_code[i].text;
531 static void hda_dsp_get_state(struct snd_sof_dev *sdev, const char *level)
533 const struct sof_intel_dsp_desc *chip = get_chip_info(sdev->pdata);
534 const char *state_text, *error_text, *module_text;
535 u32 fsr, state, wait_state, module, error_code;
537 fsr = snd_sof_dsp_read(sdev, HDA_DSP_BAR, chip->rom_status_reg);
538 state = FSR_TO_STATE_CODE(fsr);
539 wait_state = FSR_TO_WAIT_STATE_CODE(fsr);
540 module = FSR_TO_MODULE_CODE(fsr);
542 if (module > FSR_MOD_ROM_EXT)
543 module_text = "unknown";
545 module_text = fsr_module_names[module];
547 if (module == FSR_MOD_BRNGUP)
548 state_text = hda_dsp_get_state_text(state, fsr_bringup_state_names,
549 ARRAY_SIZE(fsr_bringup_state_names));
551 state_text = hda_dsp_get_state_text(state, fsr_rom_state_names,
552 ARRAY_SIZE(fsr_rom_state_names));
554 /* not for us, must be generic sof message */
556 dev_printk(level, sdev->dev, "%#010x: unknown ROM status value\n", fsr);
561 const char *wait_state_text;
563 wait_state_text = hda_dsp_get_state_text(wait_state, fsr_wait_state_names,
564 ARRAY_SIZE(fsr_wait_state_names));
565 if (!wait_state_text)
566 wait_state_text = "unknown";
568 dev_printk(level, sdev->dev,
569 "%#010x: module: %s, state: %s, waiting for: %s, %s\n",
570 fsr, module_text, state_text, wait_state_text,
571 fsr & FSR_HALTED ? "not running" : "running");
573 dev_printk(level, sdev->dev, "%#010x: module: %s, state: %s, %s\n",
574 fsr, module_text, state_text,
575 fsr & FSR_HALTED ? "not running" : "running");
578 error_code = snd_sof_dsp_read(sdev, HDA_DSP_BAR, chip->rom_status_reg + 4);
582 error_text = hda_dsp_get_state_text(error_code, hda_dsp_rom_fw_error_texts,
583 ARRAY_SIZE(hda_dsp_rom_fw_error_texts));
585 error_text = "unknown";
587 if (state == FSR_STATE_FW_ENTERED)
588 dev_printk(level, sdev->dev, "status code: %#x (%s)\n", error_code,
591 dev_printk(level, sdev->dev, "error code: %#x (%s)\n", error_code,
595 static void hda_dsp_get_registers(struct snd_sof_dev *sdev,
596 struct sof_ipc_dsp_oops_xtensa *xoops,
597 struct sof_ipc_panic_info *panic_info,
598 u32 *stack, size_t stack_words)
600 u32 offset = sdev->dsp_oops_offset;
602 /* first read registers */
603 sof_mailbox_read(sdev, offset, xoops, sizeof(*xoops));
605 /* note: variable AR register array is not read */
607 /* then get panic info */
608 if (xoops->arch_hdr.totalsize > EXCEPT_MAX_HDR_SIZE) {
609 dev_err(sdev->dev, "invalid header size 0x%x. FW oops is bogus\n",
610 xoops->arch_hdr.totalsize);
613 offset += xoops->arch_hdr.totalsize;
614 sof_block_read(sdev, sdev->mmio_bar, offset,
615 panic_info, sizeof(*panic_info));
617 /* then get the stack */
618 offset += sizeof(*panic_info);
619 sof_block_read(sdev, sdev->mmio_bar, offset, stack,
620 stack_words * sizeof(u32));
623 /* dump the first 8 dwords representing the extended ROM status */
624 static void hda_dsp_dump_ext_rom_status(struct snd_sof_dev *sdev, const char *level,
627 const struct sof_intel_dsp_desc *chip;
633 chip = get_chip_info(sdev->pdata);
634 for (i = 0; i < HDA_EXT_ROM_STATUS_SIZE; i++) {
635 value = snd_sof_dsp_read(sdev, HDA_DSP_BAR, chip->rom_status_reg + i * 0x4);
636 len += scnprintf(msg + len, sizeof(msg) - len, " 0x%x", value);
639 dev_printk(level, sdev->dev, "extended rom status: %s", msg);
643 void hda_dsp_dump(struct snd_sof_dev *sdev, u32 flags)
645 char *level = (flags & SOF_DBG_DUMP_OPTIONAL) ? KERN_DEBUG : KERN_ERR;
646 struct sof_ipc_dsp_oops_xtensa xoops;
647 struct sof_ipc_panic_info panic_info;
648 u32 stack[HDA_DSP_STACK_DUMP_SIZE];
650 /* print ROM/FW status */
651 hda_dsp_get_state(sdev, level);
653 /* The firmware register dump only available with IPC3 */
654 if (flags & SOF_DBG_DUMP_REGS && sdev->pdata->ipc_type == SOF_IPC) {
655 u32 status = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_SRAM_REG_FW_STATUS);
656 u32 panic = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_SRAM_REG_FW_TRACEP);
658 hda_dsp_get_registers(sdev, &xoops, &panic_info, stack,
659 HDA_DSP_STACK_DUMP_SIZE);
660 sof_print_oops_and_stack(sdev, level, status, panic, &xoops,
661 &panic_info, stack, HDA_DSP_STACK_DUMP_SIZE);
663 hda_dsp_dump_ext_rom_status(sdev, level, flags);
667 static bool hda_check_ipc_irq(struct snd_sof_dev *sdev)
669 const struct sof_intel_dsp_desc *chip;
671 chip = get_chip_info(sdev->pdata);
672 if (chip && chip->check_ipc_irq)
673 return chip->check_ipc_irq(sdev);
678 void hda_ipc_irq_dump(struct snd_sof_dev *sdev)
686 /* read key IRQ stats and config registers */
687 adspis = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_ADSPIS);
688 intsts = snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTSTS);
689 intctl = snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTCTL);
690 ppsts = snd_sof_dsp_read(sdev, HDA_DSP_PP_BAR, SOF_HDA_REG_PP_PPSTS);
691 rirbsts = snd_sof_dsp_read8(sdev, HDA_DSP_HDA_BAR, AZX_REG_RIRBSTS);
693 dev_err(sdev->dev, "hda irq intsts 0x%8.8x intlctl 0x%8.8x rirb %2.2x\n",
694 intsts, intctl, rirbsts);
695 dev_err(sdev->dev, "dsp irq ppsts 0x%8.8x adspis 0x%8.8x\n", ppsts, adspis);
698 void hda_ipc_dump(struct snd_sof_dev *sdev)
704 hda_ipc_irq_dump(sdev);
706 /* read IPC status */
707 hipcie = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCIE);
708 hipct = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCT);
709 hipcctl = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCCTL);
711 /* dump the IPC regs */
712 /* TODO: parse the raw msg */
713 dev_err(sdev->dev, "host status 0x%8.8x dsp status 0x%8.8x mask 0x%8.8x\n",
714 hipcie, hipct, hipcctl);
717 void hda_ipc4_dump(struct snd_sof_dev *sdev)
719 u32 hipci, hipcie, hipct, hipcte, hipcctl;
721 hda_ipc_irq_dump(sdev);
723 hipci = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCI);
724 hipcie = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCIE);
725 hipct = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCT);
726 hipcte = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCTE);
727 hipcctl = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCCTL);
729 /* dump the IPC regs */
730 /* TODO: parse the raw msg */
731 dev_err(sdev->dev, "Host IPC initiator: %#x|%#x, target: %#x|%#x, ctl: %#x\n",
732 hipci, hipcie, hipct, hipcte, hipcctl);
735 bool hda_ipc4_tx_is_busy(struct snd_sof_dev *sdev)
737 struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
738 const struct sof_intel_dsp_desc *chip = hda->desc;
741 val = snd_sof_dsp_read(sdev, HDA_DSP_BAR, chip->ipc_req);
743 return !!(val & chip->ipc_req_mask);
746 static int hda_init(struct snd_sof_dev *sdev)
748 struct hda_bus *hbus;
749 struct hdac_bus *bus;
750 struct pci_dev *pci = to_pci_dev(sdev->dev);
753 hbus = sof_to_hbus(sdev);
754 bus = sof_to_bus(sdev);
757 sof_hda_bus_init(sdev, &pci->dev);
759 if (sof_hda_position_quirk == SOF_HDA_POSITION_QUIRK_USE_DPIB_REGISTERS)
763 bus->bdl_pos_adj = 0;
766 mutex_init(&hbus->prepare_mutex);
768 hbus->mixer_assigned = -1;
769 hbus->modelname = hda_model;
771 /* initialise hdac bus */
772 bus->addr = pci_resource_start(pci, 0);
773 bus->remap_addr = pci_ioremap_bar(pci, 0);
774 if (!bus->remap_addr) {
775 dev_err(bus->dev, "error: ioremap error\n");
780 sdev->bar[HDA_DSP_HDA_BAR] = bus->remap_addr;
782 /* init i915 and HDMI codecs */
783 ret = hda_codec_i915_init(sdev);
785 dev_warn(sdev->dev, "init of i915 and HDMI codec failed\n");
787 /* get controller capabilities */
788 ret = hda_dsp_ctrl_get_caps(sdev);
790 dev_err(sdev->dev, "error: get caps error\n");
795 static int check_dmic_num(struct snd_sof_dev *sdev)
797 struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata;
798 struct nhlt_acpi_table *nhlt;
803 dmic_num = intel_nhlt_get_dmic_geo(sdev->dev, nhlt);
805 /* allow for module parameter override */
806 if (dmic_num_override != -1) {
808 "overriding DMICs detected in NHLT tables %d by kernel param %d\n",
809 dmic_num, dmic_num_override);
810 dmic_num = dmic_num_override;
813 if (dmic_num < 0 || dmic_num > 4) {
814 dev_dbg(sdev->dev, "invalid dmic_number %d\n", dmic_num);
821 static int check_nhlt_ssp_mask(struct snd_sof_dev *sdev)
823 struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata;
824 struct nhlt_acpi_table *nhlt;
831 if (intel_nhlt_has_endpoint_type(nhlt, NHLT_LINK_SSP)) {
832 ssp_mask = intel_nhlt_ssp_endpoint_mask(nhlt, NHLT_DEVICE_I2S);
834 dev_info(sdev->dev, "NHLT_DEVICE_I2S detected, ssp_mask %#x\n", ssp_mask);
840 static int check_nhlt_ssp_mclk_mask(struct snd_sof_dev *sdev, int ssp_num)
842 struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata;
843 struct nhlt_acpi_table *nhlt;
849 return intel_nhlt_ssp_mclk_mask(nhlt, ssp_num);
852 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC) || IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE)
854 static const char *fixup_tplg_name(struct snd_sof_dev *sdev,
855 const char *sof_tplg_filename,
856 const char *idisp_str,
857 const char *dmic_str)
859 const char *tplg_filename = NULL;
860 char *filename, *tmp;
861 const char *split_ext;
863 filename = kstrdup(sof_tplg_filename, GFP_KERNEL);
867 /* this assumes a .tplg extension */
869 split_ext = strsep(&tmp, ".");
871 tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL,
873 split_ext, idisp_str, dmic_str);
876 return tplg_filename;
879 static int dmic_detect_topology_fixup(struct snd_sof_dev *sdev,
880 const char **tplg_filename,
881 const char *idisp_str,
885 const char *dmic_str;
888 /* first check for DMICs (using NHLT or module parameter) */
889 dmic_num = check_dmic_num(sdev);
911 const char *default_tplg_filename = *tplg_filename;
912 const char *fixed_tplg_filename;
914 fixed_tplg_filename = fixup_tplg_name(sdev, default_tplg_filename,
915 idisp_str, dmic_str);
916 if (!fixed_tplg_filename)
918 *tplg_filename = fixed_tplg_filename;
921 dev_info(sdev->dev, "DMICs detected in NHLT tables: %d\n", dmic_num);
922 *dmic_found = dmic_num;
928 static int hda_init_caps(struct snd_sof_dev *sdev)
930 struct hdac_bus *bus = sof_to_bus(sdev);
931 struct snd_sof_pdata *pdata = sdev->pdata;
932 struct sof_intel_hda_dev *hdev = pdata->hw_pdata;
936 /* check if dsp is there */
938 dev_dbg(sdev->dev, "PP capability, will probe DSP later.\n");
940 /* Init HDA controller after i915 init */
941 ret = hda_dsp_ctrl_init_chip(sdev);
943 dev_err(bus->dev, "error: init chip failed with ret: %d\n",
948 hda_bus_ml_get_capabilities(bus);
950 /* scan SoundWire capabilities exposed by DSDT */
951 ret = hda_sdw_acpi_scan(sdev);
953 dev_dbg(sdev->dev, "skipping SoundWire, not detected with ACPI scan\n");
957 link_mask = hdev->info.link_mask;
959 dev_dbg(sdev->dev, "skipping SoundWire, no links enabled\n");
964 * probe/allocate SoundWire resources.
965 * The hardware configuration takes place in hda_sdw_startup
966 * after power rails are enabled.
967 * It's entirely possible to have a mix of I2S/DMIC/SoundWire
968 * devices, so we allocate the resources in all cases.
970 ret = hda_sdw_probe(sdev);
972 dev_err(sdev->dev, "error: SoundWire probe error\n");
978 /* create codec instances */
979 hda_codec_probe_bus(sdev);
981 if (!HDA_IDISP_CODEC(bus->codec_mask))
982 hda_codec_i915_display_power(sdev, false);
984 hda_bus_ml_put_all(bus);
989 static irqreturn_t hda_dsp_interrupt_handler(int irq, void *context)
991 struct snd_sof_dev *sdev = context;
994 * Get global interrupt status. It includes all hardware interrupt
995 * sources in the Intel HD Audio controller.
997 if (snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTSTS) &
998 SOF_HDA_INTSTS_GIS) {
1000 /* disable GIE interrupt */
1001 snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR,
1003 SOF_HDA_INT_GLOBAL_EN,
1006 return IRQ_WAKE_THREAD;
1012 static irqreturn_t hda_dsp_interrupt_thread(int irq, void *context)
1014 struct snd_sof_dev *sdev = context;
1015 struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata;
1017 /* deal with streams and controller first */
1018 if (hda_dsp_check_stream_irq(sdev)) {
1019 trace_sof_intel_hda_irq(sdev, "stream");
1020 hda_dsp_stream_threaded_handler(irq, sdev);
1023 if (hda_check_ipc_irq(sdev)) {
1024 trace_sof_intel_hda_irq(sdev, "ipc");
1025 sof_ops(sdev)->irq_thread(irq, sdev);
1028 if (hda_dsp_check_sdw_irq(sdev)) {
1029 trace_sof_intel_hda_irq(sdev, "sdw");
1030 hda_dsp_sdw_thread(irq, hdev->sdw);
1033 if (hda_sdw_check_wakeen_irq(sdev)) {
1034 trace_sof_intel_hda_irq(sdev, "wakeen");
1035 hda_sdw_process_wakeen(sdev);
1038 hda_codec_check_for_state_change(sdev);
1040 /* enable GIE interrupt */
1041 snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR,
1043 SOF_HDA_INT_GLOBAL_EN,
1044 SOF_HDA_INT_GLOBAL_EN);
1049 int hda_dsp_probe(struct snd_sof_dev *sdev)
1051 struct pci_dev *pci = to_pci_dev(sdev->dev);
1052 struct sof_intel_hda_dev *hdev;
1053 struct hdac_bus *bus;
1054 const struct sof_intel_dsp_desc *chip;
1058 * detect DSP by checking class/subclass/prog-id information
1059 * class=04 subclass 03 prog-if 00: no DSP, legacy driver is required
1060 * class=04 subclass 01 prog-if 00: DSP is present
1061 * (and may be required e.g. for DMIC or SSP support)
1062 * class=04 subclass 03 prog-if 80: either of DSP or legacy mode works
1064 if (pci->class == 0x040300) {
1065 dev_err(sdev->dev, "error: the DSP is not enabled on this platform, aborting probe\n");
1067 } else if (pci->class != 0x040100 && pci->class != 0x040380) {
1068 dev_err(sdev->dev, "error: unknown PCI class/subclass/prog-if 0x%06x found, aborting probe\n", pci->class);
1071 dev_info(sdev->dev, "DSP detected with PCI class/subclass/prog-if 0x%06x\n", pci->class);
1073 chip = get_chip_info(sdev->pdata);
1075 dev_err(sdev->dev, "error: no such device supported, chip id:%x\n",
1081 sdev->num_cores = chip->cores_num;
1083 hdev = devm_kzalloc(sdev->dev, sizeof(*hdev), GFP_KERNEL);
1086 sdev->pdata->hw_pdata = hdev;
1089 hdev->dmic_dev = platform_device_register_data(sdev->dev, "dmic-codec",
1090 PLATFORM_DEVID_NONE,
1092 if (IS_ERR(hdev->dmic_dev)) {
1093 dev_err(sdev->dev, "error: failed to create DMIC device\n");
1094 return PTR_ERR(hdev->dmic_dev);
1098 * use position update IPC if either it is forced
1099 * or we don't have other choice
1101 #if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_FORCE_IPC_POSITION)
1102 hdev->no_ipc_position = 0;
1104 hdev->no_ipc_position = sof_ops(sdev)->pcm_pointer ? 1 : 0;
1107 /* set up HDA base */
1108 bus = sof_to_bus(sdev);
1109 ret = hda_init(sdev);
1111 goto hdac_bus_unmap;
1114 sdev->bar[HDA_DSP_BAR] = pci_ioremap_bar(pci, HDA_DSP_BAR);
1115 if (!sdev->bar[HDA_DSP_BAR]) {
1116 dev_err(sdev->dev, "error: ioremap error\n");
1118 goto hdac_bus_unmap;
1121 sdev->mmio_bar = HDA_DSP_BAR;
1122 sdev->mailbox_bar = HDA_DSP_BAR;
1124 /* allow 64bit DMA address if supported by H/W */
1125 if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(64))) {
1126 dev_dbg(sdev->dev, "DMA mask is 32 bit\n");
1127 dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(32));
1129 dma_set_max_seg_size(&pci->dev, UINT_MAX);
1132 ret = hda_dsp_stream_init(sdev);
1134 dev_err(sdev->dev, "error: failed to init streams\n");
1136 * not all errors are due to memory issues, but trying
1137 * to free everything does not harm
1144 * let's try to enable msi firstly
1145 * if it fails, use legacy interrupt mode
1146 * TODO: support msi multiple vectors
1148 if (hda_use_msi && pci_alloc_irq_vectors(pci, 1, 1, PCI_IRQ_MSI) > 0) {
1149 dev_info(sdev->dev, "use msi interrupt mode\n");
1150 sdev->ipc_irq = pci_irq_vector(pci, 0);
1151 /* initialised to "false" by kzalloc() */
1152 sdev->msi_enabled = true;
1155 if (!sdev->msi_enabled) {
1156 dev_info(sdev->dev, "use legacy interrupt mode\n");
1158 * in IO-APIC mode, hda->irq and ipc_irq are using the same
1159 * irq number of pci->irq
1161 sdev->ipc_irq = pci->irq;
1164 dev_dbg(sdev->dev, "using IPC IRQ %d\n", sdev->ipc_irq);
1165 ret = request_threaded_irq(sdev->ipc_irq, hda_dsp_interrupt_handler,
1166 hda_dsp_interrupt_thread,
1167 IRQF_SHARED, "AudioDSP", sdev);
1169 dev_err(sdev->dev, "error: failed to register IPC IRQ %d\n",
1171 goto free_irq_vector;
1174 pci_set_master(pci);
1175 synchronize_irq(pci->irq);
1178 * clear TCSEL to clear playback on some HD Audio
1179 * codecs. PCI TCSEL is defined in the Intel manuals.
1181 snd_sof_pci_update_bits(sdev, PCI_TCSEL, 0x07, 0);
1183 /* init HDA capabilities */
1184 ret = hda_init_caps(sdev);
1188 /* enable ppcap interrupt */
1189 hda_dsp_ctrl_ppcap_enable(sdev, true);
1190 hda_dsp_ctrl_ppcap_int_enable(sdev, true);
1192 /* set default mailbox offset for FW ready message */
1193 sdev->dsp_box.offset = HDA_DSP_MBOX_UPLINK_OFFSET;
1195 INIT_DELAYED_WORK(&hdev->d0i3_work, hda_dsp_d0i3_work);
1197 init_waitqueue_head(&hdev->waitq);
1199 hdev->nhlt = intel_nhlt_init(sdev->dev);
1204 free_irq(sdev->ipc_irq, sdev);
1206 if (sdev->msi_enabled)
1207 pci_free_irq_vectors(pci);
1209 hda_dsp_stream_free(sdev);
1210 /* dsp_unmap: not currently used */
1211 iounmap(sdev->bar[HDA_DSP_BAR]);
1213 platform_device_unregister(hdev->dmic_dev);
1214 iounmap(bus->remap_addr);
1215 hda_codec_i915_exit(sdev);
1220 int hda_dsp_remove(struct snd_sof_dev *sdev)
1222 struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
1223 const struct sof_intel_dsp_desc *chip = hda->desc;
1224 struct hdac_bus *bus = sof_to_bus(sdev);
1225 struct pci_dev *pci = to_pci_dev(sdev->dev);
1226 struct nhlt_acpi_table *nhlt = hda->nhlt;
1229 intel_nhlt_free(nhlt);
1231 /* cancel any attempt for DSP D0I3 */
1232 cancel_delayed_work_sync(&hda->d0i3_work);
1234 hda_codec_device_remove(sdev);
1238 if (!IS_ERR_OR_NULL(hda->dmic_dev))
1239 platform_device_unregister(hda->dmic_dev);
1241 /* disable DSP IRQ */
1242 snd_sof_dsp_update_bits(sdev, HDA_DSP_PP_BAR, SOF_HDA_REG_PP_PPCTL,
1243 SOF_HDA_PPCTL_PIE, 0);
1245 /* disable CIE and GIE interrupts */
1246 snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTCTL,
1247 SOF_HDA_INT_CTRL_EN | SOF_HDA_INT_GLOBAL_EN, 0);
1249 /* no need to check for error as the DSP will be disabled anyway */
1250 if (chip && chip->power_down_dsp)
1251 chip->power_down_dsp(sdev);
1254 snd_sof_dsp_update_bits(sdev, HDA_DSP_PP_BAR, SOF_HDA_REG_PP_PPCTL,
1255 SOF_HDA_PPCTL_GPROCEN, 0);
1257 free_irq(sdev->ipc_irq, sdev);
1258 if (sdev->msi_enabled)
1259 pci_free_irq_vectors(pci);
1261 hda_dsp_stream_free(sdev);
1263 hda_bus_ml_free(sof_to_bus(sdev));
1265 iounmap(sdev->bar[HDA_DSP_BAR]);
1266 iounmap(bus->remap_addr);
1268 sof_hda_bus_exit(sdev);
1270 hda_codec_i915_exit(sdev);
1275 int hda_power_down_dsp(struct snd_sof_dev *sdev)
1277 struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
1278 const struct sof_intel_dsp_desc *chip = hda->desc;
1280 return hda_dsp_core_reset_power_down(sdev, chip->host_managed_cores_mask);
1283 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC)
1284 static void hda_generic_machine_select(struct snd_sof_dev *sdev,
1285 struct snd_soc_acpi_mach **mach)
1287 struct hdac_bus *bus = sof_to_bus(sdev);
1288 struct snd_soc_acpi_mach_params *mach_params;
1289 struct snd_soc_acpi_mach *hda_mach;
1290 struct snd_sof_pdata *pdata = sdev->pdata;
1291 const char *tplg_filename;
1292 const char *idisp_str;
1298 /* codec detection */
1299 if (!bus->codec_mask) {
1300 dev_info(bus->dev, "no hda codecs found!\n");
1302 dev_info(bus->dev, "hda codecs found, mask %lx\n",
1305 for (i = 0; i < HDA_MAX_CODECS; i++) {
1306 if (bus->codec_mask & (1 << i))
1311 * If no machine driver is found, then:
1313 * generic hda machine driver can handle:
1314 * - one HDMI codec, and/or
1315 * - one external HDAudio codec
1317 if (!*mach && codec_num <= 2) {
1320 hda_mach = snd_soc_acpi_intel_hda_machines;
1322 dev_info(bus->dev, "using HDA machine driver %s now\n",
1323 hda_mach->drv_name);
1325 if (codec_num == 1 && HDA_IDISP_CODEC(bus->codec_mask))
1326 idisp_str = "-idisp";
1330 /* topology: use the info from hda_machines */
1331 if (pdata->tplg_filename) {
1333 tplg_filename = pdata->tplg_filename;
1336 tplg_filename = hda_mach->sof_tplg_filename;
1338 ret = dmic_detect_topology_fixup(sdev, &tplg_filename, idisp_str, &dmic_num,
1343 hda_mach->mach_params.dmic_num = dmic_num;
1344 pdata->tplg_filename = tplg_filename;
1346 if (codec_num == 2) {
1348 * Prevent SoundWire links from starting when an external
1349 * HDaudio codec is used
1351 hda_mach->mach_params.link_mask = 0;
1358 /* used by hda machine driver to create dai links */
1360 mach_params = &(*mach)->mach_params;
1361 mach_params->codec_mask = bus->codec_mask;
1362 mach_params->common_hdmi_codec_drv = true;
1366 static void hda_generic_machine_select(struct snd_sof_dev *sdev,
1367 struct snd_soc_acpi_mach **mach)
1372 #if IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE)
1374 #define SDW_CODEC_ADR_MASK(_adr) ((_adr) & (SDW_DISCO_LINK_ID_MASK | SDW_VERSION_MASK | \
1375 SDW_MFG_ID_MASK | SDW_PART_ID_MASK))
1377 /* Check if all Slaves defined on the link can be found */
1378 static bool link_slaves_found(struct snd_sof_dev *sdev,
1379 const struct snd_soc_acpi_link_adr *link,
1380 struct sdw_intel_ctx *sdw)
1382 struct hdac_bus *bus = sof_to_bus(sdev);
1383 struct sdw_intel_slave_id *ids = sdw->ids;
1384 int num_slaves = sdw->num_slaves;
1385 unsigned int part_id, link_id, unique_id, mfg_id, version;
1388 for (i = 0; i < link->num_adr; i++) {
1389 u64 adr = link->adr_d[i].adr;
1390 int reported_part_count = 0;
1392 mfg_id = SDW_MFG_ID(adr);
1393 part_id = SDW_PART_ID(adr);
1394 link_id = SDW_DISCO_LINK_ID(adr);
1395 version = SDW_VERSION(adr);
1397 for (j = 0; j < num_slaves; j++) {
1398 /* find out how many identical parts were reported on that link */
1399 if (ids[j].link_id == link_id &&
1400 ids[j].id.part_id == part_id &&
1401 ids[j].id.mfg_id == mfg_id &&
1402 ids[j].id.sdw_version == version)
1403 reported_part_count++;
1406 for (j = 0; j < num_slaves; j++) {
1407 int expected_part_count = 0;
1409 if (ids[j].link_id != link_id ||
1410 ids[j].id.part_id != part_id ||
1411 ids[j].id.mfg_id != mfg_id ||
1412 ids[j].id.sdw_version != version)
1415 /* find out how many identical parts are expected */
1416 for (k = 0; k < link->num_adr; k++) {
1417 u64 adr2 = link->adr_d[k].adr;
1419 if (SDW_CODEC_ADR_MASK(adr2) == SDW_CODEC_ADR_MASK(adr))
1420 expected_part_count++;
1423 if (reported_part_count == expected_part_count) {
1425 * we have to check unique id
1426 * if there is more than one
1429 unique_id = SDW_UNIQUE_ID(adr);
1430 if (reported_part_count == 1 ||
1431 ids[j].id.unique_id == unique_id) {
1432 dev_dbg(bus->dev, "found %x at link %d\n",
1437 dev_dbg(bus->dev, "part %x reported %d expected %d on link %d, skipping\n",
1438 part_id, reported_part_count, expected_part_count, link_id);
1441 if (j == num_slaves) {
1443 "Slave %x not found\n",
1451 static struct snd_soc_acpi_mach *hda_sdw_machine_select(struct snd_sof_dev *sdev)
1453 struct snd_sof_pdata *pdata = sdev->pdata;
1454 const struct snd_soc_acpi_link_adr *link;
1455 struct snd_soc_acpi_mach *mach;
1456 struct sof_intel_hda_dev *hdev;
1460 hdev = pdata->hw_pdata;
1461 link_mask = hdev->info.link_mask;
1464 * Select SoundWire machine driver if needed using the
1465 * alternate tables. This case deals with SoundWire-only
1466 * machines, for mixed cases with I2C/I2S the detection relies
1470 for (mach = pdata->desc->alt_machines;
1471 mach && mach->link_mask; mach++) {
1473 * On some platforms such as Up Extreme all links
1474 * are enabled but only one link can be used by
1475 * external codec. Instead of exact match of two masks,
1476 * first check whether link_mask of mach is subset of
1477 * link_mask supported by hw and then go on searching
1480 if (~link_mask & mach->link_mask)
1483 /* No need to match adr if there is no links defined */
1488 for (i = 0; i < hdev->info.count && link->num_adr;
1491 * Try next machine if any expected Slaves
1492 * are not found on this link.
1494 if (!link_slaves_found(sdev, link, hdev->sdw))
1497 /* Found if all Slaves are checked */
1498 if (i == hdev->info.count || !link->num_adr)
1501 if (mach && mach->link_mask) {
1504 const char *tplg_filename;
1506 mach->mach_params.links = mach->links;
1507 mach->mach_params.link_mask = mach->link_mask;
1508 mach->mach_params.platform = dev_name(sdev->dev);
1510 if (pdata->tplg_filename) {
1514 tplg_filename = mach->sof_tplg_filename;
1518 * DMICs use up to 4 pins and are typically pin-muxed with SoundWire
1519 * link 2 and 3, or link 1 and 2, thus we only try to enable dmics
1520 * if all conditions are true:
1521 * a) 2 or fewer links are used by SoundWire
1522 * b) the NHLT table reports the presence of microphones
1524 if (hweight_long(mach->link_mask) <= 2) {
1527 ret = dmic_detect_topology_fixup(sdev, &tplg_filename, "",
1528 &dmic_num, tplg_fixup);
1533 pdata->tplg_filename = tplg_filename;
1534 mach->mach_params.dmic_num = dmic_num;
1537 "SoundWire machine driver %s topology %s\n",
1539 pdata->tplg_filename);
1544 dev_info(sdev->dev, "No SoundWire machine driver found\n");
1550 static struct snd_soc_acpi_mach *hda_sdw_machine_select(struct snd_sof_dev *sdev)
1556 void hda_set_mach_params(struct snd_soc_acpi_mach *mach,
1557 struct snd_sof_dev *sdev)
1559 struct snd_sof_pdata *pdata = sdev->pdata;
1560 const struct sof_dev_desc *desc = pdata->desc;
1561 struct snd_soc_acpi_mach_params *mach_params;
1563 mach_params = &mach->mach_params;
1564 mach_params->platform = dev_name(sdev->dev);
1565 mach_params->num_dai_drivers = desc->ops->num_drv;
1566 mach_params->dai_drivers = desc->ops->drv;
1569 struct snd_soc_acpi_mach *hda_machine_select(struct snd_sof_dev *sdev)
1571 struct snd_sof_pdata *sof_pdata = sdev->pdata;
1572 const struct sof_dev_desc *desc = sof_pdata->desc;
1573 struct snd_soc_acpi_mach *mach;
1574 const char *tplg_filename;
1576 mach = snd_soc_acpi_find_machine(desc->machines);
1578 bool add_extension = false;
1579 bool tplg_fixup = false;
1582 * If tplg file name is overridden, use it instead of
1583 * the one set in mach table
1585 if (!sof_pdata->tplg_filename) {
1586 sof_pdata->tplg_filename = mach->sof_tplg_filename;
1590 /* report to machine driver if any DMICs are found */
1591 mach->mach_params.dmic_num = check_dmic_num(sdev);
1594 mach->tplg_quirk_mask & SND_SOC_ACPI_TPLG_INTEL_DMIC_NUMBER &&
1595 mach->mach_params.dmic_num) {
1596 tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL,
1598 sof_pdata->tplg_filename,
1600 mach->mach_params.dmic_num,
1605 sof_pdata->tplg_filename = tplg_filename;
1606 add_extension = true;
1609 if (mach->link_mask) {
1610 mach->mach_params.links = mach->links;
1611 mach->mach_params.link_mask = mach->link_mask;
1614 /* report SSP link mask to machine driver */
1615 mach->mach_params.i2s_link_mask = check_nhlt_ssp_mask(sdev);
1618 mach->tplg_quirk_mask & SND_SOC_ACPI_TPLG_INTEL_SSP_NUMBER &&
1619 mach->mach_params.i2s_link_mask) {
1620 const struct sof_intel_dsp_desc *chip = get_chip_info(sdev->pdata);
1624 if (hweight_long(mach->mach_params.i2s_link_mask) > 1 &&
1625 !(mach->tplg_quirk_mask & SND_SOC_ACPI_TPLG_INTEL_SSP_MSB))
1626 dev_warn(sdev->dev, "More than one SSP exposed by NHLT, choosing MSB\n");
1628 /* fls returns 1-based results, SSPs indices are 0-based */
1629 ssp_num = fls(mach->mach_params.i2s_link_mask) - 1;
1631 if (ssp_num >= chip->ssp_count) {
1632 dev_err(sdev->dev, "Invalid SSP %d, max on this platform is %d\n",
1633 ssp_num, chip->ssp_count);
1637 tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL,
1639 sof_pdata->tplg_filename,
1645 sof_pdata->tplg_filename = tplg_filename;
1646 add_extension = true;
1648 mclk_mask = check_nhlt_ssp_mclk_mask(sdev, ssp_num);
1650 if (mclk_mask < 0) {
1651 dev_err(sdev->dev, "Invalid MCLK configuration\n");
1655 dev_dbg(sdev->dev, "MCLK mask %#x found in NHLT\n", mclk_mask);
1658 dev_info(sdev->dev, "Overriding topology with MCLK mask %#x from NHLT\n", mclk_mask);
1659 sdev->mclk_id_override = true;
1660 sdev->mclk_id_quirk = (mclk_mask & BIT(0)) ? 0 : 1;
1664 if (tplg_fixup && add_extension) {
1665 tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL,
1667 sof_pdata->tplg_filename,
1672 sof_pdata->tplg_filename = tplg_filename;
1675 /* check if mclk_id should be modified from topology defaults */
1676 if (mclk_id_override >= 0) {
1677 dev_info(sdev->dev, "Overriding topology with MCLK %d from kernel_parameter\n", mclk_id_override);
1678 sdev->mclk_id_override = true;
1679 sdev->mclk_id_quirk = mclk_id_override;
1684 * If I2S fails, try SoundWire
1687 mach = hda_sdw_machine_select(sdev);
1690 * Choose HDA generic machine driver if mach is NULL.
1691 * Otherwise, set certain mach params.
1693 hda_generic_machine_select(sdev, &mach);
1695 dev_warn(sdev->dev, "warning: No matching ASoC machine driver found\n");
1700 int hda_pci_intel_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
1704 ret = snd_intel_dsp_driver_probe(pci);
1705 if (ret != SND_INTEL_DSP_DRIVER_ANY && ret != SND_INTEL_DSP_DRIVER_SOF) {
1706 dev_dbg(&pci->dev, "SOF PCI driver not selected, aborting probe\n");
1710 return sof_pci_probe(pci, pci_id);
1712 EXPORT_SYMBOL_NS(hda_pci_intel_probe, SND_SOC_SOF_INTEL_HDA_COMMON);
1714 int hda_register_clients(struct snd_sof_dev *sdev)
1716 return hda_probes_register(sdev);
1719 void hda_unregister_clients(struct snd_sof_dev *sdev)
1721 hda_probes_unregister(sdev);
1724 MODULE_LICENSE("Dual BSD/GPL");
1725 MODULE_IMPORT_NS(SND_SOC_SOF_PCI_DEV);
1726 MODULE_IMPORT_NS(SND_SOC_SOF_HDA_AUDIO_CODEC);
1727 MODULE_IMPORT_NS(SND_SOC_SOF_HDA_AUDIO_CODEC_I915);
1728 MODULE_IMPORT_NS(SND_SOC_SOF_XTENSA);
1729 MODULE_IMPORT_NS(SND_INTEL_SOUNDWIRE_ACPI);
1730 MODULE_IMPORT_NS(SOUNDWIRE_INTEL_INIT);
1731 MODULE_IMPORT_NS(SOUNDWIRE_INTEL);