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