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 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
35 #include <sound/soc-acpi-intel-match.h>
38 /* platform specific devices */
41 #define EXCEPT_MAX_HDR_SIZE 0x400
42 #define HDA_EXT_ROM_STATUS_SIZE 8
44 int hda_ctrl_dai_widget_setup(struct snd_soc_dapm_widget *w, unsigned int quirk_flags,
45 struct snd_sof_dai_config_data *data)
47 struct snd_sof_widget *swidget = w->dobj.private;
48 struct snd_soc_component *component = swidget->scomp;
49 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
50 const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
51 struct snd_sof_dai *sof_dai = swidget->private;
55 dev_err(sdev->dev, "%s: No DAI for DAI widget %s\n", __func__, w->name);
59 if (tplg_ops->dai_config) {
62 /* set HW_PARAMS flag along with quirks */
63 flags = SOF_DAI_CONFIG_FLAGS_HW_PARAMS |
64 quirk_flags << SOF_DAI_CONFIG_FLAGS_QUIRK_SHIFT;
66 ret = tplg_ops->dai_config(sdev, swidget, flags, data);
68 dev_err(sdev->dev, "%s: DAI config failed for widget %s\n", __func__,
77 int hda_ctrl_dai_widget_free(struct snd_soc_dapm_widget *w, unsigned int quirk_flags,
78 struct snd_sof_dai_config_data *data)
80 struct snd_sof_widget *swidget = w->dobj.private;
81 struct snd_soc_component *component = swidget->scomp;
82 struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(component);
83 const struct sof_ipc_tplg_ops *tplg_ops = sdev->ipc->ops->tplg;
84 struct snd_sof_dai *sof_dai = swidget->private;
87 dev_err(sdev->dev, "%s: No DAI for BE DAI widget %s\n", __func__, w->name);
91 if (tplg_ops->dai_config) {
95 /* set HW_FREE flag along with any quirks */
96 flags = SOF_DAI_CONFIG_FLAGS_HW_FREE |
97 quirk_flags << SOF_DAI_CONFIG_FLAGS_QUIRK_SHIFT;
99 ret = tplg_ops->dai_config(sdev, swidget, flags, data);
101 dev_err(sdev->dev, "%s: DAI config failed for widget '%s'\n", __func__,
108 #if IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE)
111 * The default for SoundWire clock stop quirks is to power gate the IP
112 * and do a Bus Reset, this will need to be modified when the DSP
113 * needs to remain in D0i3 so that the Master does not lose context
114 * and enumeration is not required on clock restart
116 static int sdw_clock_stop_quirks = SDW_INTEL_CLK_STOP_BUS_RESET;
117 module_param(sdw_clock_stop_quirks, int, 0444);
118 MODULE_PARM_DESC(sdw_clock_stop_quirks, "SOF SoundWire clock stop quirks");
120 static int sdw_params_stream(struct device *dev,
121 struct sdw_intel_stream_params_data *params_data)
123 struct snd_soc_dai *d = params_data->dai;
124 struct snd_sof_dai_config_data data;
125 struct snd_soc_dapm_widget *w;
127 w = snd_soc_dai_get_widget(d, params_data->stream);
128 data.dai_index = (params_data->link_id << 8) | d->id;
129 data.dai_data = params_data->alh_stream_id;
131 return hda_ctrl_dai_widget_setup(w, SOF_DAI_CONFIG_FLAGS_NONE, &data);
134 static int sdw_free_stream(struct device *dev,
135 struct sdw_intel_stream_free_data *free_data)
137 struct snd_soc_dai *d = free_data->dai;
138 struct snd_sof_dai_config_data data;
139 struct snd_soc_dapm_widget *w;
141 w = snd_soc_dai_get_widget(d, free_data->stream);
142 data.dai_index = (free_data->link_id << 8) | d->id;
144 /* send invalid stream_id */
145 data.dai_data = 0xFFFF;
147 return hda_ctrl_dai_widget_free(w, SOF_DAI_CONFIG_FLAGS_NONE, &data);
150 struct sdw_intel_ops sdw_callback = {
151 .params_stream = sdw_params_stream,
152 .free_stream = sdw_free_stream,
155 void hda_sdw_int_enable(struct snd_sof_dev *sdev, bool enable)
157 sdw_intel_enable_irq(sdev->bar[HDA_DSP_BAR], enable);
160 static int hda_sdw_acpi_scan(struct snd_sof_dev *sdev)
162 struct sof_intel_hda_dev *hdev;
166 handle = ACPI_HANDLE(sdev->dev);
168 /* save ACPI info for the probe step */
169 hdev = sdev->pdata->hw_pdata;
171 ret = sdw_intel_acpi_scan(handle, &hdev->info);
178 static int hda_sdw_probe(struct snd_sof_dev *sdev)
180 struct sof_intel_hda_dev *hdev;
181 struct sdw_intel_res res;
184 hdev = sdev->pdata->hw_pdata;
186 memset(&res, 0, sizeof(res));
188 res.mmio_base = sdev->bar[HDA_DSP_BAR];
189 res.shim_base = hdev->desc->sdw_shim_base;
190 res.alh_base = hdev->desc->sdw_alh_base;
191 res.irq = sdev->ipc_irq;
192 res.handle = hdev->info.handle;
193 res.parent = sdev->dev;
194 res.ops = &sdw_callback;
196 res.clock_stop_quirks = sdw_clock_stop_quirks;
199 * ops and arg fields are not populated for now,
200 * they will be needed when the DAI callbacks are
204 /* we could filter links here if needed, e.g for quirks */
205 res.count = hdev->info.count;
206 res.link_mask = hdev->info.link_mask;
208 sdw = sdw_intel_probe(&res);
210 dev_err(sdev->dev, "error: SoundWire probe failed\n");
220 int hda_sdw_startup(struct snd_sof_dev *sdev)
222 struct sof_intel_hda_dev *hdev;
223 struct snd_sof_pdata *pdata = sdev->pdata;
225 hdev = sdev->pdata->hw_pdata;
230 if (pdata->machine && !pdata->machine->mach_params.link_mask)
233 return sdw_intel_startup(hdev->sdw);
236 static int hda_sdw_exit(struct snd_sof_dev *sdev)
238 struct sof_intel_hda_dev *hdev;
240 hdev = sdev->pdata->hw_pdata;
242 hda_sdw_int_enable(sdev, false);
245 sdw_intel_exit(hdev->sdw);
251 bool hda_common_check_sdw_irq(struct snd_sof_dev *sdev)
253 struct sof_intel_hda_dev *hdev;
257 hdev = sdev->pdata->hw_pdata;
263 irq_status = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_ADSPIS2);
265 /* invalid message ? */
266 if (irq_status == 0xffffffff)
270 if (irq_status & HDA_DSP_REG_ADSPIS2_SNDW)
277 static bool hda_dsp_check_sdw_irq(struct snd_sof_dev *sdev)
279 const struct sof_intel_dsp_desc *chip;
281 chip = get_chip_info(sdev->pdata);
282 if (chip && chip->check_sdw_irq)
283 return chip->check_sdw_irq(sdev);
288 static irqreturn_t hda_dsp_sdw_thread(int irq, void *context)
290 return sdw_intel_thread(irq, context);
293 static bool hda_sdw_check_wakeen_irq(struct snd_sof_dev *sdev)
295 struct sof_intel_hda_dev *hdev;
297 hdev = sdev->pdata->hw_pdata;
299 snd_sof_dsp_read(sdev, HDA_DSP_BAR,
300 hdev->desc->sdw_shim_base + SDW_SHIM_WAKESTS))
306 void hda_sdw_process_wakeen(struct snd_sof_dev *sdev)
308 struct sof_intel_hda_dev *hdev;
310 hdev = sdev->pdata->hw_pdata;
314 sdw_intel_process_wakeen_event(hdev->sdw);
317 #else /* IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE) */
318 static inline int hda_sdw_acpi_scan(struct snd_sof_dev *sdev)
323 static inline int hda_sdw_probe(struct snd_sof_dev *sdev)
328 static inline int hda_sdw_exit(struct snd_sof_dev *sdev)
333 static inline bool hda_dsp_check_sdw_irq(struct snd_sof_dev *sdev)
338 static inline irqreturn_t hda_dsp_sdw_thread(int irq, void *context)
343 static inline bool hda_sdw_check_wakeen_irq(struct snd_sof_dev *sdev)
348 #endif /* IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE) */
354 struct hda_dsp_msg_code {
359 #if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG)
360 static bool hda_use_msi = true;
361 module_param_named(use_msi, hda_use_msi, bool, 0444);
362 MODULE_PARM_DESC(use_msi, "SOF HDA use PCI MSI mode");
364 #define hda_use_msi (1)
367 int sof_hda_position_quirk = SOF_HDA_POSITION_QUIRK_USE_DPIB_REGISTERS;
368 module_param_named(position_quirk, sof_hda_position_quirk, int, 0444);
369 MODULE_PARM_DESC(position_quirk, "SOF HDaudio position quirk");
371 static char *hda_model;
372 module_param(hda_model, charp, 0444);
373 MODULE_PARM_DESC(hda_model, "Use the given HDA board model.");
375 static int dmic_num_override = -1;
376 module_param_named(dmic_num, dmic_num_override, int, 0444);
377 MODULE_PARM_DESC(dmic_num, "SOF HDA DMIC number");
379 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
380 static bool hda_codec_use_common_hdmi = IS_ENABLED(CONFIG_SND_HDA_CODEC_HDMI);
381 module_param_named(use_common_hdmi, hda_codec_use_common_hdmi, bool, 0444);
382 MODULE_PARM_DESC(use_common_hdmi, "SOF HDA use common HDMI codec driver");
385 static const struct hda_dsp_msg_code hda_dsp_rom_fw_error_texts[] = {
386 {HDA_DSP_ROM_CSE_ERROR, "error: cse error"},
387 {HDA_DSP_ROM_CSE_WRONG_RESPONSE, "error: cse wrong response"},
388 {HDA_DSP_ROM_IMR_TO_SMALL, "error: IMR too small"},
389 {HDA_DSP_ROM_BASE_FW_NOT_FOUND, "error: base fw not found"},
390 {HDA_DSP_ROM_CSE_VALIDATION_FAILED, "error: signature verification failed"},
391 {HDA_DSP_ROM_IPC_FATAL_ERROR, "error: ipc fatal error"},
392 {HDA_DSP_ROM_L2_CACHE_ERROR, "error: L2 cache error"},
393 {HDA_DSP_ROM_LOAD_OFFSET_TO_SMALL, "error: load offset too small"},
394 {HDA_DSP_ROM_API_PTR_INVALID, "error: API ptr invalid"},
395 {HDA_DSP_ROM_BASEFW_INCOMPAT, "error: base fw incompatible"},
396 {HDA_DSP_ROM_UNHANDLED_INTERRUPT, "error: unhandled interrupt"},
397 {HDA_DSP_ROM_MEMORY_HOLE_ECC, "error: ECC memory hole"},
398 {HDA_DSP_ROM_KERNEL_EXCEPTION, "error: kernel exception"},
399 {HDA_DSP_ROM_USER_EXCEPTION, "error: user exception"},
400 {HDA_DSP_ROM_UNEXPECTED_RESET, "error: unexpected reset"},
401 {HDA_DSP_ROM_NULL_FW_ENTRY, "error: null FW entry point"},
404 #define FSR_ROM_STATE_ENTRY(state) {FSR_STATE_ROM_##state, #state}
405 static const struct hda_dsp_msg_code fsr_rom_state_names[] = {
406 FSR_ROM_STATE_ENTRY(INIT),
407 FSR_ROM_STATE_ENTRY(INIT_DONE),
408 FSR_ROM_STATE_ENTRY(CSE_MANIFEST_LOADED),
409 FSR_ROM_STATE_ENTRY(FW_MANIFEST_LOADED),
410 FSR_ROM_STATE_ENTRY(FW_FW_LOADED),
411 FSR_ROM_STATE_ENTRY(FW_ENTERED),
412 FSR_ROM_STATE_ENTRY(VERIFY_FEATURE_MASK),
413 FSR_ROM_STATE_ENTRY(GET_LOAD_OFFSET),
414 FSR_ROM_STATE_ENTRY(FETCH_ROM_EXT),
415 FSR_ROM_STATE_ENTRY(FETCH_ROM_EXT_DONE),
417 FSR_ROM_STATE_ENTRY(CSE_IMR_REQUEST),
418 FSR_ROM_STATE_ENTRY(CSE_IMR_GRANTED),
419 FSR_ROM_STATE_ENTRY(CSE_VALIDATE_IMAGE_REQUEST),
420 FSR_ROM_STATE_ENTRY(CSE_IMAGE_VALIDATED),
421 FSR_ROM_STATE_ENTRY(CSE_IPC_IFACE_INIT),
422 FSR_ROM_STATE_ENTRY(CSE_IPC_RESET_PHASE_1),
423 FSR_ROM_STATE_ENTRY(CSE_IPC_OPERATIONAL_ENTRY),
424 FSR_ROM_STATE_ENTRY(CSE_IPC_OPERATIONAL),
425 FSR_ROM_STATE_ENTRY(CSE_IPC_DOWN),
428 #define FSR_BRINGUP_STATE_ENTRY(state) {FSR_STATE_BRINGUP_##state, #state}
429 static const struct hda_dsp_msg_code fsr_bringup_state_names[] = {
430 FSR_BRINGUP_STATE_ENTRY(INIT),
431 FSR_BRINGUP_STATE_ENTRY(INIT_DONE),
432 FSR_BRINGUP_STATE_ENTRY(HPSRAM_LOAD),
433 FSR_BRINGUP_STATE_ENTRY(UNPACK_START),
434 FSR_BRINGUP_STATE_ENTRY(IMR_RESTORE),
435 FSR_BRINGUP_STATE_ENTRY(FW_ENTERED),
438 #define FSR_WAIT_STATE_ENTRY(state) {FSR_WAIT_FOR_##state, #state}
439 static const struct hda_dsp_msg_code fsr_wait_state_names[] = {
440 FSR_WAIT_STATE_ENTRY(IPC_BUSY),
441 FSR_WAIT_STATE_ENTRY(IPC_DONE),
442 FSR_WAIT_STATE_ENTRY(CACHE_INVALIDATION),
443 FSR_WAIT_STATE_ENTRY(LP_SRAM_OFF),
444 FSR_WAIT_STATE_ENTRY(DMA_BUFFER_FULL),
445 FSR_WAIT_STATE_ENTRY(CSE_CSR),
448 #define FSR_MODULE_NAME_ENTRY(mod) [FSR_MOD_##mod] = #mod
449 static const char * const fsr_module_names[] = {
450 FSR_MODULE_NAME_ENTRY(ROM),
451 FSR_MODULE_NAME_ENTRY(ROM_BYP),
452 FSR_MODULE_NAME_ENTRY(BASE_FW),
453 FSR_MODULE_NAME_ENTRY(LP_BOOT),
454 FSR_MODULE_NAME_ENTRY(BRNGUP),
455 FSR_MODULE_NAME_ENTRY(ROM_EXT),
459 hda_dsp_get_state_text(u32 code, const struct hda_dsp_msg_code *msg_code,
464 for (i = 0; i < array_size; i++) {
465 if (code == msg_code[i].code)
466 return msg_code[i].text;
472 static void hda_dsp_get_state(struct snd_sof_dev *sdev, const char *level)
474 const struct sof_intel_dsp_desc *chip = get_chip_info(sdev->pdata);
475 const char *state_text, *error_text, *module_text;
476 u32 fsr, state, wait_state, module, error_code;
478 fsr = snd_sof_dsp_read(sdev, HDA_DSP_BAR, chip->rom_status_reg);
479 state = FSR_TO_STATE_CODE(fsr);
480 wait_state = FSR_TO_WAIT_STATE_CODE(fsr);
481 module = FSR_TO_MODULE_CODE(fsr);
483 if (module > FSR_MOD_ROM_EXT)
484 module_text = "unknown";
486 module_text = fsr_module_names[module];
488 if (module == FSR_MOD_BRNGUP)
489 state_text = hda_dsp_get_state_text(state, fsr_bringup_state_names,
490 ARRAY_SIZE(fsr_bringup_state_names));
492 state_text = hda_dsp_get_state_text(state, fsr_rom_state_names,
493 ARRAY_SIZE(fsr_rom_state_names));
495 /* not for us, must be generic sof message */
497 dev_printk(level, sdev->dev, "%#010x: unknown ROM status value\n", fsr);
502 const char *wait_state_text;
504 wait_state_text = hda_dsp_get_state_text(wait_state, fsr_wait_state_names,
505 ARRAY_SIZE(fsr_wait_state_names));
506 if (!wait_state_text)
507 wait_state_text = "unknown";
509 dev_printk(level, sdev->dev,
510 "%#010x: module: %s, state: %s, waiting for: %s, %s\n",
511 fsr, module_text, state_text, wait_state_text,
512 fsr & FSR_HALTED ? "not running" : "running");
514 dev_printk(level, sdev->dev, "%#010x: module: %s, state: %s, %s\n",
515 fsr, module_text, state_text,
516 fsr & FSR_HALTED ? "not running" : "running");
519 error_code = snd_sof_dsp_read(sdev, HDA_DSP_BAR, chip->rom_status_reg + 4);
523 error_text = hda_dsp_get_state_text(error_code, hda_dsp_rom_fw_error_texts,
524 ARRAY_SIZE(hda_dsp_rom_fw_error_texts));
526 error_text = "unknown";
528 if (state == FSR_STATE_FW_ENTERED)
529 dev_printk(level, sdev->dev, "status code: %#x (%s)\n", error_code,
532 dev_printk(level, sdev->dev, "error code: %#x (%s)\n", error_code,
536 static void hda_dsp_get_registers(struct snd_sof_dev *sdev,
537 struct sof_ipc_dsp_oops_xtensa *xoops,
538 struct sof_ipc_panic_info *panic_info,
539 u32 *stack, size_t stack_words)
541 u32 offset = sdev->dsp_oops_offset;
543 /* first read registers */
544 sof_mailbox_read(sdev, offset, xoops, sizeof(*xoops));
546 /* note: variable AR register array is not read */
548 /* then get panic info */
549 if (xoops->arch_hdr.totalsize > EXCEPT_MAX_HDR_SIZE) {
550 dev_err(sdev->dev, "invalid header size 0x%x. FW oops is bogus\n",
551 xoops->arch_hdr.totalsize);
554 offset += xoops->arch_hdr.totalsize;
555 sof_block_read(sdev, sdev->mmio_bar, offset,
556 panic_info, sizeof(*panic_info));
558 /* then get the stack */
559 offset += sizeof(*panic_info);
560 sof_block_read(sdev, sdev->mmio_bar, offset, stack,
561 stack_words * sizeof(u32));
564 /* dump the first 8 dwords representing the extended ROM status */
565 static void hda_dsp_dump_ext_rom_status(struct snd_sof_dev *sdev, const char *level,
568 const struct sof_intel_dsp_desc *chip;
574 chip = get_chip_info(sdev->pdata);
575 for (i = 0; i < HDA_EXT_ROM_STATUS_SIZE; i++) {
576 value = snd_sof_dsp_read(sdev, HDA_DSP_BAR, chip->rom_status_reg + i * 0x4);
577 len += snprintf(msg + len, sizeof(msg) - len, " 0x%x", value);
580 dev_printk(level, sdev->dev, "extended rom status: %s", msg);
584 void hda_dsp_dump(struct snd_sof_dev *sdev, u32 flags)
586 char *level = (flags & SOF_DBG_DUMP_OPTIONAL) ? KERN_DEBUG : KERN_ERR;
587 struct sof_ipc_dsp_oops_xtensa xoops;
588 struct sof_ipc_panic_info panic_info;
589 u32 stack[HDA_DSP_STACK_DUMP_SIZE];
591 /* print ROM/FW status */
592 hda_dsp_get_state(sdev, level);
594 if (flags & SOF_DBG_DUMP_REGS) {
595 u32 status = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_SRAM_REG_FW_STATUS);
596 u32 panic = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_SRAM_REG_FW_TRACEP);
598 hda_dsp_get_registers(sdev, &xoops, &panic_info, stack,
599 HDA_DSP_STACK_DUMP_SIZE);
600 sof_print_oops_and_stack(sdev, level, status, panic, &xoops,
601 &panic_info, stack, HDA_DSP_STACK_DUMP_SIZE);
603 hda_dsp_dump_ext_rom_status(sdev, level, flags);
607 static bool hda_check_ipc_irq(struct snd_sof_dev *sdev)
609 const struct sof_intel_dsp_desc *chip;
611 chip = get_chip_info(sdev->pdata);
612 if (chip && chip->check_ipc_irq)
613 return chip->check_ipc_irq(sdev);
618 void hda_ipc_irq_dump(struct snd_sof_dev *sdev)
620 struct hdac_bus *bus = sof_to_bus(sdev);
627 /* read key IRQ stats and config registers */
628 adspis = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_ADSPIS);
629 intsts = snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTSTS);
630 intctl = snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTCTL);
631 ppsts = snd_sof_dsp_read(sdev, HDA_DSP_PP_BAR, SOF_HDA_REG_PP_PPSTS);
632 rirbsts = snd_hdac_chip_readb(bus, RIRBSTS);
634 dev_err(sdev->dev, "hda irq intsts 0x%8.8x intlctl 0x%8.8x rirb %2.2x\n",
635 intsts, intctl, rirbsts);
636 dev_err(sdev->dev, "dsp irq ppsts 0x%8.8x adspis 0x%8.8x\n", ppsts, adspis);
639 void hda_ipc_dump(struct snd_sof_dev *sdev)
645 hda_ipc_irq_dump(sdev);
647 /* read IPC status */
648 hipcie = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCIE);
649 hipct = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCT);
650 hipcctl = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCCTL);
652 /* dump the IPC regs */
653 /* TODO: parse the raw msg */
654 dev_err(sdev->dev, "host status 0x%8.8x dsp status 0x%8.8x mask 0x%8.8x\n",
655 hipcie, hipct, hipcctl);
658 static int hda_init(struct snd_sof_dev *sdev)
660 struct hda_bus *hbus;
661 struct hdac_bus *bus;
662 struct pci_dev *pci = to_pci_dev(sdev->dev);
665 hbus = sof_to_hbus(sdev);
666 bus = sof_to_bus(sdev);
669 sof_hda_bus_init(bus, &pci->dev);
671 if (sof_hda_position_quirk == SOF_HDA_POSITION_QUIRK_USE_DPIB_REGISTERS)
675 bus->bdl_pos_adj = 0;
678 mutex_init(&hbus->prepare_mutex);
680 hbus->mixer_assigned = -1;
681 hbus->modelname = hda_model;
683 /* initialise hdac bus */
684 bus->addr = pci_resource_start(pci, 0);
685 bus->remap_addr = pci_ioremap_bar(pci, 0);
686 if (!bus->remap_addr) {
687 dev_err(bus->dev, "error: ioremap error\n");
692 sdev->bar[HDA_DSP_HDA_BAR] = bus->remap_addr;
694 /* init i915 and HDMI codecs */
695 ret = hda_codec_i915_init(sdev);
697 dev_warn(sdev->dev, "init of i915 and HDMI codec failed\n");
699 /* get controller capabilities */
700 ret = hda_dsp_ctrl_get_caps(sdev);
702 dev_err(sdev->dev, "error: get caps error\n");
707 static int check_dmic_num(struct snd_sof_dev *sdev)
709 struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata;
710 struct nhlt_acpi_table *nhlt;
715 dmic_num = intel_nhlt_get_dmic_geo(sdev->dev, nhlt);
717 /* allow for module parameter override */
718 if (dmic_num_override != -1) {
720 "overriding DMICs detected in NHLT tables %d by kernel param %d\n",
721 dmic_num, dmic_num_override);
722 dmic_num = dmic_num_override;
725 if (dmic_num < 0 || dmic_num > 4) {
726 dev_dbg(sdev->dev, "invalid dmic_number %d\n", dmic_num);
733 static int check_nhlt_ssp_mask(struct snd_sof_dev *sdev)
735 struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata;
736 struct nhlt_acpi_table *nhlt;
743 if (intel_nhlt_has_endpoint_type(nhlt, NHLT_LINK_SSP)) {
744 ssp_mask = intel_nhlt_ssp_endpoint_mask(nhlt, NHLT_DEVICE_I2S);
746 dev_info(sdev->dev, "NHLT_DEVICE_I2S detected, ssp_mask %#x\n", ssp_mask);
752 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) || IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE)
754 static const char *fixup_tplg_name(struct snd_sof_dev *sdev,
755 const char *sof_tplg_filename,
756 const char *idisp_str,
757 const char *dmic_str)
759 const char *tplg_filename = NULL;
760 char *filename, *tmp;
761 const char *split_ext;
763 filename = kstrdup(sof_tplg_filename, GFP_KERNEL);
767 /* this assumes a .tplg extension */
769 split_ext = strsep(&tmp, ".");
771 tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL,
773 split_ext, idisp_str, dmic_str);
776 return tplg_filename;
779 static int dmic_detect_topology_fixup(struct snd_sof_dev *sdev,
780 const char **tplg_filename,
781 const char *idisp_str,
785 const char *dmic_str;
788 /* first check for DMICs (using NHLT or module parameter) */
789 dmic_num = check_dmic_num(sdev);
811 const char *default_tplg_filename = *tplg_filename;
812 const char *fixed_tplg_filename;
814 fixed_tplg_filename = fixup_tplg_name(sdev, default_tplg_filename,
815 idisp_str, dmic_str);
816 if (!fixed_tplg_filename)
818 *tplg_filename = fixed_tplg_filename;
821 dev_info(sdev->dev, "DMICs detected in NHLT tables: %d\n", dmic_num);
822 *dmic_found = dmic_num;
828 static int hda_init_caps(struct snd_sof_dev *sdev)
830 struct hdac_bus *bus = sof_to_bus(sdev);
831 struct snd_sof_pdata *pdata = sdev->pdata;
832 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
833 struct hdac_ext_link *hlink;
835 struct sof_intel_hda_dev *hdev = pdata->hw_pdata;
839 /* check if dsp is there */
841 dev_dbg(sdev->dev, "PP capability, will probe DSP later.\n");
843 /* Init HDA controller after i915 init */
844 ret = hda_dsp_ctrl_init_chip(sdev, true);
846 dev_err(bus->dev, "error: init chip failed with ret: %d\n",
851 /* scan SoundWire capabilities exposed by DSDT */
852 ret = hda_sdw_acpi_scan(sdev);
854 dev_dbg(sdev->dev, "skipping SoundWire, not detected with ACPI scan\n");
858 link_mask = hdev->info.link_mask;
860 dev_dbg(sdev->dev, "skipping SoundWire, no links enabled\n");
865 * probe/allocate SoundWire resources.
866 * The hardware configuration takes place in hda_sdw_startup
867 * after power rails are enabled.
868 * It's entirely possible to have a mix of I2S/DMIC/SoundWire
869 * devices, so we allocate the resources in all cases.
871 ret = hda_sdw_probe(sdev);
873 dev_err(sdev->dev, "error: SoundWire probe error\n");
879 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
881 snd_hdac_ext_bus_get_ml_capabilities(bus);
883 /* create codec instances */
884 hda_codec_probe_bus(sdev, hda_codec_use_common_hdmi);
886 if (!HDA_IDISP_CODEC(bus->codec_mask))
887 hda_codec_i915_display_power(sdev, false);
890 * we are done probing so decrement link counts
892 list_for_each_entry(hlink, &bus->hlink_list, list)
893 snd_hdac_ext_bus_link_put(bus, hlink);
898 static void hda_check_for_state_change(struct snd_sof_dev *sdev)
900 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
901 struct hdac_bus *bus = sof_to_bus(sdev);
902 unsigned int codec_mask;
904 codec_mask = snd_hdac_chip_readw(bus, STATESTS);
906 hda_codec_jack_check(sdev);
907 snd_hdac_chip_writew(bus, STATESTS, codec_mask);
912 static irqreturn_t hda_dsp_interrupt_handler(int irq, void *context)
914 struct snd_sof_dev *sdev = context;
917 * Get global interrupt status. It includes all hardware interrupt
918 * sources in the Intel HD Audio controller.
920 if (snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTSTS) &
921 SOF_HDA_INTSTS_GIS) {
923 /* disable GIE interrupt */
924 snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR,
926 SOF_HDA_INT_GLOBAL_EN,
929 return IRQ_WAKE_THREAD;
935 static irqreturn_t hda_dsp_interrupt_thread(int irq, void *context)
937 struct snd_sof_dev *sdev = context;
938 struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata;
940 /* deal with streams and controller first */
941 if (hda_dsp_check_stream_irq(sdev))
942 hda_dsp_stream_threaded_handler(irq, sdev);
944 if (hda_check_ipc_irq(sdev))
945 sof_ops(sdev)->irq_thread(irq, sdev);
947 if (hda_dsp_check_sdw_irq(sdev))
948 hda_dsp_sdw_thread(irq, hdev->sdw);
950 if (hda_sdw_check_wakeen_irq(sdev))
951 hda_sdw_process_wakeen(sdev);
953 hda_check_for_state_change(sdev);
955 /* enable GIE interrupt */
956 snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR,
958 SOF_HDA_INT_GLOBAL_EN,
959 SOF_HDA_INT_GLOBAL_EN);
964 int hda_dsp_probe(struct snd_sof_dev *sdev)
966 struct pci_dev *pci = to_pci_dev(sdev->dev);
967 struct sof_intel_hda_dev *hdev;
968 struct hdac_bus *bus;
969 const struct sof_intel_dsp_desc *chip;
973 * detect DSP by checking class/subclass/prog-id information
974 * class=04 subclass 03 prog-if 00: no DSP, legacy driver is required
975 * class=04 subclass 01 prog-if 00: DSP is present
976 * (and may be required e.g. for DMIC or SSP support)
977 * class=04 subclass 03 prog-if 80: either of DSP or legacy mode works
979 if (pci->class == 0x040300) {
980 dev_err(sdev->dev, "error: the DSP is not enabled on this platform, aborting probe\n");
982 } else if (pci->class != 0x040100 && pci->class != 0x040380) {
983 dev_err(sdev->dev, "error: unknown PCI class/subclass/prog-if 0x%06x found, aborting probe\n", pci->class);
986 dev_info(sdev->dev, "DSP detected with PCI class/subclass/prog-if 0x%06x\n", pci->class);
988 chip = get_chip_info(sdev->pdata);
990 dev_err(sdev->dev, "error: no such device supported, chip id:%x\n",
996 sdev->num_cores = chip->cores_num;
998 hdev = devm_kzalloc(sdev->dev, sizeof(*hdev), GFP_KERNEL);
1001 sdev->pdata->hw_pdata = hdev;
1004 hdev->dmic_dev = platform_device_register_data(sdev->dev, "dmic-codec",
1005 PLATFORM_DEVID_NONE,
1007 if (IS_ERR(hdev->dmic_dev)) {
1008 dev_err(sdev->dev, "error: failed to create DMIC device\n");
1009 return PTR_ERR(hdev->dmic_dev);
1013 * use position update IPC if either it is forced
1014 * or we don't have other choice
1016 #if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_FORCE_IPC_POSITION)
1017 hdev->no_ipc_position = 0;
1019 hdev->no_ipc_position = sof_ops(sdev)->pcm_pointer ? 1 : 0;
1022 /* set up HDA base */
1023 bus = sof_to_bus(sdev);
1024 ret = hda_init(sdev);
1026 goto hdac_bus_unmap;
1029 sdev->bar[HDA_DSP_BAR] = pci_ioremap_bar(pci, HDA_DSP_BAR);
1030 if (!sdev->bar[HDA_DSP_BAR]) {
1031 dev_err(sdev->dev, "error: ioremap error\n");
1033 goto hdac_bus_unmap;
1036 sdev->mmio_bar = HDA_DSP_BAR;
1037 sdev->mailbox_bar = HDA_DSP_BAR;
1039 /* allow 64bit DMA address if supported by H/W */
1040 if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(64))) {
1041 dev_dbg(sdev->dev, "DMA mask is 32 bit\n");
1042 dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(32));
1044 dma_set_max_seg_size(&pci->dev, UINT_MAX);
1047 ret = hda_dsp_stream_init(sdev);
1049 dev_err(sdev->dev, "error: failed to init streams\n");
1051 * not all errors are due to memory issues, but trying
1052 * to free everything does not harm
1059 * let's try to enable msi firstly
1060 * if it fails, use legacy interrupt mode
1061 * TODO: support msi multiple vectors
1063 if (hda_use_msi && pci_alloc_irq_vectors(pci, 1, 1, PCI_IRQ_MSI) > 0) {
1064 dev_info(sdev->dev, "use msi interrupt mode\n");
1065 sdev->ipc_irq = pci_irq_vector(pci, 0);
1066 /* initialised to "false" by kzalloc() */
1067 sdev->msi_enabled = true;
1070 if (!sdev->msi_enabled) {
1071 dev_info(sdev->dev, "use legacy interrupt mode\n");
1073 * in IO-APIC mode, hda->irq and ipc_irq are using the same
1074 * irq number of pci->irq
1076 sdev->ipc_irq = pci->irq;
1079 dev_dbg(sdev->dev, "using IPC IRQ %d\n", sdev->ipc_irq);
1080 ret = request_threaded_irq(sdev->ipc_irq, hda_dsp_interrupt_handler,
1081 hda_dsp_interrupt_thread,
1082 IRQF_SHARED, "AudioDSP", sdev);
1084 dev_err(sdev->dev, "error: failed to register IPC IRQ %d\n",
1086 goto free_irq_vector;
1089 pci_set_master(pci);
1090 synchronize_irq(pci->irq);
1093 * clear TCSEL to clear playback on some HD Audio
1094 * codecs. PCI TCSEL is defined in the Intel manuals.
1096 snd_sof_pci_update_bits(sdev, PCI_TCSEL, 0x07, 0);
1098 /* init HDA capabilities */
1099 ret = hda_init_caps(sdev);
1103 /* enable ppcap interrupt */
1104 hda_dsp_ctrl_ppcap_enable(sdev, true);
1105 hda_dsp_ctrl_ppcap_int_enable(sdev, true);
1107 /* set default mailbox offset for FW ready message */
1108 sdev->dsp_box.offset = HDA_DSP_MBOX_UPLINK_OFFSET;
1110 INIT_DELAYED_WORK(&hdev->d0i3_work, hda_dsp_d0i3_work);
1112 hdev->nhlt = intel_nhlt_init(sdev->dev);
1117 free_irq(sdev->ipc_irq, sdev);
1119 if (sdev->msi_enabled)
1120 pci_free_irq_vectors(pci);
1122 hda_dsp_stream_free(sdev);
1123 /* dsp_unmap: not currently used */
1124 iounmap(sdev->bar[HDA_DSP_BAR]);
1126 platform_device_unregister(hdev->dmic_dev);
1127 iounmap(bus->remap_addr);
1128 hda_codec_i915_exit(sdev);
1133 int hda_dsp_remove(struct snd_sof_dev *sdev)
1135 struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
1136 const struct sof_intel_dsp_desc *chip = hda->desc;
1137 struct hdac_bus *bus = sof_to_bus(sdev);
1138 struct pci_dev *pci = to_pci_dev(sdev->dev);
1139 struct nhlt_acpi_table *nhlt = hda->nhlt;
1142 intel_nhlt_free(nhlt);
1144 /* cancel any attempt for DSP D0I3 */
1145 cancel_delayed_work_sync(&hda->d0i3_work);
1147 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
1148 /* codec removal, invoke bus_device_remove */
1149 snd_hdac_ext_bus_device_remove(bus);
1154 if (!IS_ERR_OR_NULL(hda->dmic_dev))
1155 platform_device_unregister(hda->dmic_dev);
1157 /* disable DSP IRQ */
1158 snd_sof_dsp_update_bits(sdev, HDA_DSP_PP_BAR, SOF_HDA_REG_PP_PPCTL,
1159 SOF_HDA_PPCTL_PIE, 0);
1161 /* disable CIE and GIE interrupts */
1162 snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTCTL,
1163 SOF_HDA_INT_CTRL_EN | SOF_HDA_INT_GLOBAL_EN, 0);
1167 hda_dsp_core_reset_power_down(sdev, chip->host_managed_cores_mask);
1170 snd_sof_dsp_update_bits(sdev, HDA_DSP_PP_BAR, SOF_HDA_REG_PP_PPCTL,
1171 SOF_HDA_PPCTL_GPROCEN, 0);
1173 free_irq(sdev->ipc_irq, sdev);
1174 if (sdev->msi_enabled)
1175 pci_free_irq_vectors(pci);
1177 hda_dsp_stream_free(sdev);
1178 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
1179 snd_hdac_link_free_all(bus);
1182 iounmap(sdev->bar[HDA_DSP_BAR]);
1183 iounmap(bus->remap_addr);
1185 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
1186 snd_hdac_ext_bus_exit(bus);
1188 hda_codec_i915_exit(sdev);
1193 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
1194 static void hda_generic_machine_select(struct snd_sof_dev *sdev,
1195 struct snd_soc_acpi_mach **mach)
1197 struct hdac_bus *bus = sof_to_bus(sdev);
1198 struct snd_soc_acpi_mach_params *mach_params;
1199 struct snd_soc_acpi_mach *hda_mach;
1200 struct snd_sof_pdata *pdata = sdev->pdata;
1201 const char *tplg_filename;
1202 const char *idisp_str;
1208 /* codec detection */
1209 if (!bus->codec_mask) {
1210 dev_info(bus->dev, "no hda codecs found!\n");
1212 dev_info(bus->dev, "hda codecs found, mask %lx\n",
1215 for (i = 0; i < HDA_MAX_CODECS; i++) {
1216 if (bus->codec_mask & (1 << i))
1221 * If no machine driver is found, then:
1223 * generic hda machine driver can handle:
1224 * - one HDMI codec, and/or
1225 * - one external HDAudio codec
1227 if (!*mach && codec_num <= 2) {
1230 hda_mach = snd_soc_acpi_intel_hda_machines;
1232 dev_info(bus->dev, "using HDA machine driver %s now\n",
1233 hda_mach->drv_name);
1235 if (codec_num == 1 && HDA_IDISP_CODEC(bus->codec_mask))
1236 idisp_str = "-idisp";
1240 /* topology: use the info from hda_machines */
1241 if (pdata->tplg_filename) {
1243 tplg_filename = pdata->tplg_filename;
1246 tplg_filename = hda_mach->sof_tplg_filename;
1248 ret = dmic_detect_topology_fixup(sdev, &tplg_filename, idisp_str, &dmic_num,
1253 hda_mach->mach_params.dmic_num = dmic_num;
1254 pdata->tplg_filename = tplg_filename;
1256 if (codec_num == 2) {
1258 * Prevent SoundWire links from starting when an external
1259 * HDaudio codec is used
1261 hda_mach->mach_params.link_mask = 0;
1268 /* used by hda machine driver to create dai links */
1270 mach_params = &(*mach)->mach_params;
1271 mach_params->codec_mask = bus->codec_mask;
1272 mach_params->common_hdmi_codec_drv = hda_codec_use_common_hdmi;
1276 static void hda_generic_machine_select(struct snd_sof_dev *sdev,
1277 struct snd_soc_acpi_mach **mach)
1282 #if IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE)
1284 #define SDW_CODEC_ADR_MASK(_adr) ((_adr) & (SDW_DISCO_LINK_ID_MASK | SDW_VERSION_MASK | \
1285 SDW_MFG_ID_MASK | SDW_PART_ID_MASK))
1287 /* Check if all Slaves defined on the link can be found */
1288 static bool link_slaves_found(struct snd_sof_dev *sdev,
1289 const struct snd_soc_acpi_link_adr *link,
1290 struct sdw_intel_ctx *sdw)
1292 struct hdac_bus *bus = sof_to_bus(sdev);
1293 struct sdw_intel_slave_id *ids = sdw->ids;
1294 int num_slaves = sdw->num_slaves;
1295 unsigned int part_id, link_id, unique_id, mfg_id, version;
1298 for (i = 0; i < link->num_adr; i++) {
1299 u64 adr = link->adr_d[i].adr;
1300 int reported_part_count = 0;
1302 mfg_id = SDW_MFG_ID(adr);
1303 part_id = SDW_PART_ID(adr);
1304 link_id = SDW_DISCO_LINK_ID(adr);
1305 version = SDW_VERSION(adr);
1307 for (j = 0; j < num_slaves; j++) {
1308 /* find out how many identical parts were reported on that link */
1309 if (ids[j].link_id == link_id &&
1310 ids[j].id.part_id == part_id &&
1311 ids[j].id.mfg_id == mfg_id &&
1312 ids[j].id.sdw_version == version)
1313 reported_part_count++;
1316 for (j = 0; j < num_slaves; j++) {
1317 int expected_part_count = 0;
1319 if (ids[j].link_id != link_id ||
1320 ids[j].id.part_id != part_id ||
1321 ids[j].id.mfg_id != mfg_id ||
1322 ids[j].id.sdw_version != version)
1325 /* find out how many identical parts are expected */
1326 for (k = 0; k < link->num_adr; k++) {
1327 u64 adr2 = link->adr_d[k].adr;
1329 if (SDW_CODEC_ADR_MASK(adr2) == SDW_CODEC_ADR_MASK(adr))
1330 expected_part_count++;
1333 if (reported_part_count == expected_part_count) {
1335 * we have to check unique id
1336 * if there is more than one
1339 unique_id = SDW_UNIQUE_ID(adr);
1340 if (reported_part_count == 1 ||
1341 ids[j].id.unique_id == unique_id) {
1342 dev_dbg(bus->dev, "found %x at link %d\n",
1347 dev_dbg(bus->dev, "part %x reported %d expected %d on link %d, skipping\n",
1348 part_id, reported_part_count, expected_part_count, link_id);
1351 if (j == num_slaves) {
1353 "Slave %x not found\n",
1361 static struct snd_soc_acpi_mach *hda_sdw_machine_select(struct snd_sof_dev *sdev)
1363 struct snd_sof_pdata *pdata = sdev->pdata;
1364 const struct snd_soc_acpi_link_adr *link;
1365 struct snd_soc_acpi_mach *mach;
1366 struct sof_intel_hda_dev *hdev;
1370 hdev = pdata->hw_pdata;
1371 link_mask = hdev->info.link_mask;
1374 * Select SoundWire machine driver if needed using the
1375 * alternate tables. This case deals with SoundWire-only
1376 * machines, for mixed cases with I2C/I2S the detection relies
1380 for (mach = pdata->desc->alt_machines;
1381 mach && mach->link_mask; mach++) {
1383 * On some platforms such as Up Extreme all links
1384 * are enabled but only one link can be used by
1385 * external codec. Instead of exact match of two masks,
1386 * first check whether link_mask of mach is subset of
1387 * link_mask supported by hw and then go on searching
1390 if (~link_mask & mach->link_mask)
1393 /* No need to match adr if there is no links defined */
1398 for (i = 0; i < hdev->info.count && link->num_adr;
1401 * Try next machine if any expected Slaves
1402 * are not found on this link.
1404 if (!link_slaves_found(sdev, link, hdev->sdw))
1407 /* Found if all Slaves are checked */
1408 if (i == hdev->info.count || !link->num_adr)
1411 if (mach && mach->link_mask) {
1414 const char *tplg_filename;
1416 mach->mach_params.links = mach->links;
1417 mach->mach_params.link_mask = mach->link_mask;
1418 mach->mach_params.platform = dev_name(sdev->dev);
1420 if (pdata->tplg_filename) {
1424 tplg_filename = mach->sof_tplg_filename;
1428 * DMICs use up to 4 pins and are typically pin-muxed with SoundWire
1429 * link 2 and 3, or link 1 and 2, thus we only try to enable dmics
1430 * if all conditions are true:
1431 * a) 2 or fewer links are used by SoundWire
1432 * b) the NHLT table reports the presence of microphones
1434 if (hweight_long(mach->link_mask) <= 2) {
1437 ret = dmic_detect_topology_fixup(sdev, &tplg_filename, "",
1438 &dmic_num, tplg_fixup);
1443 pdata->tplg_filename = tplg_filename;
1444 mach->mach_params.dmic_num = dmic_num;
1447 "SoundWire machine driver %s topology %s\n",
1449 pdata->tplg_filename);
1454 dev_info(sdev->dev, "No SoundWire machine driver found\n");
1460 static struct snd_soc_acpi_mach *hda_sdw_machine_select(struct snd_sof_dev *sdev)
1466 void hda_set_mach_params(struct snd_soc_acpi_mach *mach,
1467 struct snd_sof_dev *sdev)
1469 struct snd_sof_pdata *pdata = sdev->pdata;
1470 const struct sof_dev_desc *desc = pdata->desc;
1471 struct snd_soc_acpi_mach_params *mach_params;
1473 mach_params = &mach->mach_params;
1474 mach_params->platform = dev_name(sdev->dev);
1475 mach_params->num_dai_drivers = desc->ops->num_drv;
1476 mach_params->dai_drivers = desc->ops->drv;
1479 struct snd_soc_acpi_mach *hda_machine_select(struct snd_sof_dev *sdev)
1481 struct snd_sof_pdata *sof_pdata = sdev->pdata;
1482 const struct sof_dev_desc *desc = sof_pdata->desc;
1483 struct snd_soc_acpi_mach *mach;
1484 const char *tplg_filename;
1486 mach = snd_soc_acpi_find_machine(desc->machines);
1488 bool add_extension = false;
1489 bool tplg_fixup = false;
1492 * If tplg file name is overridden, use it instead of
1493 * the one set in mach table
1495 if (!sof_pdata->tplg_filename) {
1496 sof_pdata->tplg_filename = mach->sof_tplg_filename;
1500 /* report to machine driver if any DMICs are found */
1501 mach->mach_params.dmic_num = check_dmic_num(sdev);
1504 mach->tplg_quirk_mask & SND_SOC_ACPI_TPLG_INTEL_DMIC_NUMBER &&
1505 mach->mach_params.dmic_num) {
1506 tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL,
1508 sof_pdata->tplg_filename,
1510 mach->mach_params.dmic_num,
1515 sof_pdata->tplg_filename = tplg_filename;
1516 add_extension = true;
1519 if (mach->link_mask) {
1520 mach->mach_params.links = mach->links;
1521 mach->mach_params.link_mask = mach->link_mask;
1524 /* report SSP link mask to machine driver */
1525 mach->mach_params.i2s_link_mask = check_nhlt_ssp_mask(sdev);
1528 mach->tplg_quirk_mask & SND_SOC_ACPI_TPLG_INTEL_SSP_NUMBER &&
1529 mach->mach_params.i2s_link_mask) {
1530 const struct sof_intel_dsp_desc *chip = get_chip_info(sdev->pdata);
1533 if (hweight_long(mach->mach_params.i2s_link_mask) > 1 &&
1534 !(mach->tplg_quirk_mask & SND_SOC_ACPI_TPLG_INTEL_SSP_MSB))
1535 dev_warn(sdev->dev, "More than one SSP exposed by NHLT, choosing MSB\n");
1537 /* fls returns 1-based results, SSPs indices are 0-based */
1538 ssp_num = fls(mach->mach_params.i2s_link_mask) - 1;
1540 if (ssp_num >= chip->ssp_count) {
1541 dev_err(sdev->dev, "Invalid SSP %d, max on this platform is %d\n",
1542 ssp_num, chip->ssp_count);
1546 tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL,
1548 sof_pdata->tplg_filename,
1554 sof_pdata->tplg_filename = tplg_filename;
1555 add_extension = true;
1558 if (tplg_fixup && add_extension) {
1559 tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL,
1561 sof_pdata->tplg_filename,
1566 sof_pdata->tplg_filename = tplg_filename;
1571 * If I2S fails, try SoundWire
1574 mach = hda_sdw_machine_select(sdev);
1577 * Choose HDA generic machine driver if mach is NULL.
1578 * Otherwise, set certain mach params.
1580 hda_generic_machine_select(sdev, &mach);
1582 dev_warn(sdev->dev, "warning: No matching ASoC machine driver found\n");
1587 int hda_pci_intel_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
1591 ret = snd_intel_dsp_driver_probe(pci);
1592 if (ret != SND_INTEL_DSP_DRIVER_ANY && ret != SND_INTEL_DSP_DRIVER_SOF) {
1593 dev_dbg(&pci->dev, "SOF PCI driver not selected, aborting probe\n");
1597 return sof_pci_probe(pci, pci_id);
1599 EXPORT_SYMBOL_NS(hda_pci_intel_probe, SND_SOC_SOF_INTEL_HDA_COMMON);
1601 int hda_register_clients(struct snd_sof_dev *sdev)
1603 return hda_probes_register(sdev);
1606 void hda_unregister_clients(struct snd_sof_dev *sdev)
1608 hda_probes_unregister(sdev);
1611 MODULE_LICENSE("Dual BSD/GPL");
1612 MODULE_IMPORT_NS(SND_SOC_SOF_PCI_DEV);
1613 MODULE_IMPORT_NS(SND_SOC_SOF_HDA_AUDIO_CODEC);
1614 MODULE_IMPORT_NS(SND_SOC_SOF_HDA_AUDIO_CODEC_I915);
1615 MODULE_IMPORT_NS(SND_SOC_SOF_XTENSA);
1616 MODULE_IMPORT_NS(SND_INTEL_SOUNDWIRE_ACPI);
1617 MODULE_IMPORT_NS(SOUNDWIRE_INTEL_INIT);