xref: /openbmc/linux/sound/soc/sof/intel/hda.c (revision 28dce2c4)
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 	/* check if dsp is there */
620 	if (bus->ppcap)
621 		dev_dbg(sdev->dev, "PP capability, will probe DSP later.\n");
622 
623 	/* Init HDA controller after i915 init */
624 	ret = hda_dsp_ctrl_init_chip(sdev, true);
625 	if (ret < 0) {
626 		dev_err(bus->dev, "error: init chip failed with ret: %d\n",
627 			ret);
628 		return ret;
629 	}
630 
631 	/* scan SoundWire capabilities exposed by DSDT */
632 	ret = hda_sdw_acpi_scan(sdev);
633 	if (ret < 0) {
634 		dev_dbg(sdev->dev, "skipping SoundWire, not detected with ACPI scan\n");
635 		goto skip_soundwire;
636 	}
637 
638 	link_mask = hdev->info.link_mask;
639 	if (!link_mask) {
640 		dev_dbg(sdev->dev, "skipping SoundWire, no links enabled\n");
641 		goto skip_soundwire;
642 	}
643 
644 	/*
645 	 * probe/allocate SoundWire resources.
646 	 * The hardware configuration takes place in hda_sdw_startup
647 	 * after power rails are enabled.
648 	 * It's entirely possible to have a mix of I2S/DMIC/SoundWire
649 	 * devices, so we allocate the resources in all cases.
650 	 */
651 	ret = hda_sdw_probe(sdev);
652 	if (ret < 0) {
653 		dev_err(sdev->dev, "error: SoundWire probe error\n");
654 		return ret;
655 	}
656 
657 skip_soundwire:
658 
659 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
660 	if (bus->mlcap)
661 		snd_hdac_ext_bus_get_ml_capabilities(bus);
662 
663 	/* create codec instances */
664 	hda_codec_probe_bus(sdev, hda_codec_use_common_hdmi);
665 
666 	if (!HDA_IDISP_CODEC(bus->codec_mask))
667 		hda_codec_i915_display_power(sdev, false);
668 
669 	/*
670 	 * we are done probing so decrement link counts
671 	 */
672 	list_for_each_entry(hlink, &bus->hlink_list, list)
673 		snd_hdac_ext_bus_link_put(bus, hlink);
674 #endif
675 	return 0;
676 }
677 
678 static const struct sof_intel_dsp_desc
679 	*get_chip_info(struct snd_sof_pdata *pdata)
680 {
681 	const struct sof_dev_desc *desc = pdata->desc;
682 	const struct sof_intel_dsp_desc *chip_info;
683 
684 	chip_info = desc->chip_info;
685 
686 	return chip_info;
687 }
688 
689 static irqreturn_t hda_dsp_interrupt_handler(int irq, void *context)
690 {
691 	struct snd_sof_dev *sdev = context;
692 
693 	/*
694 	 * Get global interrupt status. It includes all hardware interrupt
695 	 * sources in the Intel HD Audio controller.
696 	 */
697 	if (snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTSTS) &
698 	    SOF_HDA_INTSTS_GIS) {
699 
700 		/* disable GIE interrupt */
701 		snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR,
702 					SOF_HDA_INTCTL,
703 					SOF_HDA_INT_GLOBAL_EN,
704 					0);
705 
706 		return IRQ_WAKE_THREAD;
707 	}
708 
709 	return IRQ_NONE;
710 }
711 
712 static irqreturn_t hda_dsp_interrupt_thread(int irq, void *context)
713 {
714 	struct snd_sof_dev *sdev = context;
715 	struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata;
716 
717 	/* deal with streams and controller first */
718 	if (hda_dsp_check_stream_irq(sdev))
719 		hda_dsp_stream_threaded_handler(irq, sdev);
720 
721 	if (hda_dsp_check_ipc_irq(sdev))
722 		sof_ops(sdev)->irq_thread(irq, sdev);
723 
724 	if (hda_dsp_check_sdw_irq(sdev))
725 		hda_dsp_sdw_thread(irq, hdev->sdw);
726 
727 	if (hda_sdw_check_wakeen_irq(sdev))
728 		hda_sdw_process_wakeen(sdev);
729 
730 	/* enable GIE interrupt */
731 	snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR,
732 				SOF_HDA_INTCTL,
733 				SOF_HDA_INT_GLOBAL_EN,
734 				SOF_HDA_INT_GLOBAL_EN);
735 
736 	return IRQ_HANDLED;
737 }
738 
739 int hda_dsp_probe(struct snd_sof_dev *sdev)
740 {
741 	struct pci_dev *pci = to_pci_dev(sdev->dev);
742 	struct sof_intel_hda_dev *hdev;
743 	struct hdac_bus *bus;
744 	const struct sof_intel_dsp_desc *chip;
745 	int ret = 0;
746 
747 	/*
748 	 * detect DSP by checking class/subclass/prog-id information
749 	 * class=04 subclass 03 prog-if 00: no DSP, legacy driver is required
750 	 * class=04 subclass 01 prog-if 00: DSP is present
751 	 *   (and may be required e.g. for DMIC or SSP support)
752 	 * class=04 subclass 03 prog-if 80: either of DSP or legacy mode works
753 	 */
754 	if (pci->class == 0x040300) {
755 		dev_err(sdev->dev, "error: the DSP is not enabled on this platform, aborting probe\n");
756 		return -ENODEV;
757 	} else if (pci->class != 0x040100 && pci->class != 0x040380) {
758 		dev_err(sdev->dev, "error: unknown PCI class/subclass/prog-if 0x%06x found, aborting probe\n", pci->class);
759 		return -ENODEV;
760 	}
761 	dev_info(sdev->dev, "DSP detected with PCI class/subclass/prog-if 0x%06x\n", pci->class);
762 
763 	chip = get_chip_info(sdev->pdata);
764 	if (!chip) {
765 		dev_err(sdev->dev, "error: no such device supported, chip id:%x\n",
766 			pci->device);
767 		ret = -EIO;
768 		goto err;
769 	}
770 
771 	hdev = devm_kzalloc(sdev->dev, sizeof(*hdev), GFP_KERNEL);
772 	if (!hdev)
773 		return -ENOMEM;
774 	sdev->pdata->hw_pdata = hdev;
775 	hdev->desc = chip;
776 
777 	hdev->dmic_dev = platform_device_register_data(sdev->dev, "dmic-codec",
778 						       PLATFORM_DEVID_NONE,
779 						       NULL, 0);
780 	if (IS_ERR(hdev->dmic_dev)) {
781 		dev_err(sdev->dev, "error: failed to create DMIC device\n");
782 		return PTR_ERR(hdev->dmic_dev);
783 	}
784 
785 	/*
786 	 * use position update IPC if either it is forced
787 	 * or we don't have other choice
788 	 */
789 #if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_FORCE_IPC_POSITION)
790 	hdev->no_ipc_position = 0;
791 #else
792 	hdev->no_ipc_position = sof_ops(sdev)->pcm_pointer ? 1 : 0;
793 #endif
794 
795 	/* set up HDA base */
796 	bus = sof_to_bus(sdev);
797 	ret = hda_init(sdev);
798 	if (ret < 0)
799 		goto hdac_bus_unmap;
800 
801 	/* DSP base */
802 #if IS_ENABLED(CONFIG_PCI)
803 	sdev->bar[HDA_DSP_BAR] = pci_ioremap_bar(pci, HDA_DSP_BAR);
804 #endif
805 	if (!sdev->bar[HDA_DSP_BAR]) {
806 		dev_err(sdev->dev, "error: ioremap error\n");
807 		ret = -ENXIO;
808 		goto hdac_bus_unmap;
809 	}
810 
811 	sdev->mmio_bar = HDA_DSP_BAR;
812 	sdev->mailbox_bar = HDA_DSP_BAR;
813 
814 	/* allow 64bit DMA address if supported by H/W */
815 	if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(64))) {
816 		dev_dbg(sdev->dev, "DMA mask is 32 bit\n");
817 		dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(32));
818 	}
819 
820 	/* init streams */
821 	ret = hda_dsp_stream_init(sdev);
822 	if (ret < 0) {
823 		dev_err(sdev->dev, "error: failed to init streams\n");
824 		/*
825 		 * not all errors are due to memory issues, but trying
826 		 * to free everything does not harm
827 		 */
828 		goto free_streams;
829 	}
830 
831 	/*
832 	 * register our IRQ
833 	 * let's try to enable msi firstly
834 	 * if it fails, use legacy interrupt mode
835 	 * TODO: support msi multiple vectors
836 	 */
837 	if (hda_use_msi && pci_alloc_irq_vectors(pci, 1, 1, PCI_IRQ_MSI) > 0) {
838 		dev_info(sdev->dev, "use msi interrupt mode\n");
839 		sdev->ipc_irq = pci_irq_vector(pci, 0);
840 		/* initialised to "false" by kzalloc() */
841 		sdev->msi_enabled = true;
842 	}
843 
844 	if (!sdev->msi_enabled) {
845 		dev_info(sdev->dev, "use legacy interrupt mode\n");
846 		/*
847 		 * in IO-APIC mode, hda->irq and ipc_irq are using the same
848 		 * irq number of pci->irq
849 		 */
850 		sdev->ipc_irq = pci->irq;
851 	}
852 
853 	dev_dbg(sdev->dev, "using IPC IRQ %d\n", sdev->ipc_irq);
854 	ret = request_threaded_irq(sdev->ipc_irq, hda_dsp_interrupt_handler,
855 				   hda_dsp_interrupt_thread,
856 				   IRQF_SHARED, "AudioDSP", sdev);
857 	if (ret < 0) {
858 		dev_err(sdev->dev, "error: failed to register IPC IRQ %d\n",
859 			sdev->ipc_irq);
860 		goto free_irq_vector;
861 	}
862 
863 	pci_set_master(pci);
864 	synchronize_irq(pci->irq);
865 
866 	/*
867 	 * clear TCSEL to clear playback on some HD Audio
868 	 * codecs. PCI TCSEL is defined in the Intel manuals.
869 	 */
870 	snd_sof_pci_update_bits(sdev, PCI_TCSEL, 0x07, 0);
871 
872 	/* init HDA capabilities */
873 	ret = hda_init_caps(sdev);
874 	if (ret < 0)
875 		goto free_ipc_irq;
876 
877 	/* enable ppcap interrupt */
878 	hda_dsp_ctrl_ppcap_enable(sdev, true);
879 	hda_dsp_ctrl_ppcap_int_enable(sdev, true);
880 
881 	/* set default mailbox offset for FW ready message */
882 	sdev->dsp_box.offset = HDA_DSP_MBOX_UPLINK_OFFSET;
883 
884 	INIT_DELAYED_WORK(&hdev->d0i3_work, hda_dsp_d0i3_work);
885 
886 	return 0;
887 
888 free_ipc_irq:
889 	free_irq(sdev->ipc_irq, sdev);
890 free_irq_vector:
891 	if (sdev->msi_enabled)
892 		pci_free_irq_vectors(pci);
893 free_streams:
894 	hda_dsp_stream_free(sdev);
895 /* dsp_unmap: not currently used */
896 	iounmap(sdev->bar[HDA_DSP_BAR]);
897 hdac_bus_unmap:
898 	platform_device_unregister(hdev->dmic_dev);
899 	iounmap(bus->remap_addr);
900 	hda_codec_i915_exit(sdev);
901 err:
902 	return ret;
903 }
904 
905 int hda_dsp_remove(struct snd_sof_dev *sdev)
906 {
907 	struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
908 	struct hdac_bus *bus = sof_to_bus(sdev);
909 	struct pci_dev *pci = to_pci_dev(sdev->dev);
910 	const struct sof_intel_dsp_desc *chip = hda->desc;
911 
912 	/* cancel any attempt for DSP D0I3 */
913 	cancel_delayed_work_sync(&hda->d0i3_work);
914 
915 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
916 	/* codec removal, invoke bus_device_remove */
917 	snd_hdac_ext_bus_device_remove(bus);
918 #endif
919 
920 	hda_sdw_exit(sdev);
921 
922 	if (!IS_ERR_OR_NULL(hda->dmic_dev))
923 		platform_device_unregister(hda->dmic_dev);
924 
925 	/* disable DSP IRQ */
926 	snd_sof_dsp_update_bits(sdev, HDA_DSP_PP_BAR, SOF_HDA_REG_PP_PPCTL,
927 				SOF_HDA_PPCTL_PIE, 0);
928 
929 	/* disable CIE and GIE interrupts */
930 	snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTCTL,
931 				SOF_HDA_INT_CTRL_EN | SOF_HDA_INT_GLOBAL_EN, 0);
932 
933 	/* disable cores */
934 	if (chip)
935 		snd_sof_dsp_core_power_down(sdev, chip->host_managed_cores_mask);
936 
937 	/* disable DSP */
938 	snd_sof_dsp_update_bits(sdev, HDA_DSP_PP_BAR, SOF_HDA_REG_PP_PPCTL,
939 				SOF_HDA_PPCTL_GPROCEN, 0);
940 
941 	free_irq(sdev->ipc_irq, sdev);
942 	if (sdev->msi_enabled)
943 		pci_free_irq_vectors(pci);
944 
945 	hda_dsp_stream_free(sdev);
946 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
947 	snd_hdac_link_free_all(bus);
948 #endif
949 
950 	iounmap(sdev->bar[HDA_DSP_BAR]);
951 	iounmap(bus->remap_addr);
952 
953 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
954 	snd_hdac_ext_bus_exit(bus);
955 #endif
956 	hda_codec_i915_exit(sdev);
957 
958 	return 0;
959 }
960 
961 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
962 static int hda_generic_machine_select(struct snd_sof_dev *sdev)
963 {
964 	struct hdac_bus *bus = sof_to_bus(sdev);
965 	struct snd_soc_acpi_mach_params *mach_params;
966 	struct snd_soc_acpi_mach *hda_mach;
967 	struct snd_sof_pdata *pdata = sdev->pdata;
968 	const char *tplg_filename;
969 	const char *idisp_str;
970 	int dmic_num = 0;
971 	int codec_num = 0;
972 	int ret;
973 	int i;
974 
975 	/* codec detection */
976 	if (!bus->codec_mask) {
977 		dev_info(bus->dev, "no hda codecs found!\n");
978 	} else {
979 		dev_info(bus->dev, "hda codecs found, mask %lx\n",
980 			 bus->codec_mask);
981 
982 		for (i = 0; i < HDA_MAX_CODECS; i++) {
983 			if (bus->codec_mask & (1 << i))
984 				codec_num++;
985 		}
986 
987 		/*
988 		 * If no machine driver is found, then:
989 		 *
990 		 * generic hda machine driver can handle:
991 		 *  - one HDMI codec, and/or
992 		 *  - one external HDAudio codec
993 		 */
994 		if (!pdata->machine && codec_num <= 2) {
995 			hda_mach = snd_soc_acpi_intel_hda_machines;
996 
997 			dev_info(bus->dev, "using HDA machine driver %s now\n",
998 				 hda_mach->drv_name);
999 
1000 			if (codec_num == 1 && HDA_IDISP_CODEC(bus->codec_mask))
1001 				idisp_str = "-idisp";
1002 			else
1003 				idisp_str = "";
1004 
1005 			/* topology: use the info from hda_machines */
1006 			tplg_filename = hda_mach->sof_tplg_filename;
1007 			ret = dmic_topology_fixup(sdev, &tplg_filename, idisp_str, &dmic_num);
1008 			if (ret < 0)
1009 				return ret;
1010 
1011 			hda_mach->mach_params.dmic_num = dmic_num;
1012 			pdata->machine = hda_mach;
1013 			pdata->tplg_filename = tplg_filename;
1014 		}
1015 	}
1016 
1017 	/* used by hda machine driver to create dai links */
1018 	if (pdata->machine) {
1019 		mach_params = (struct snd_soc_acpi_mach_params *)
1020 			&pdata->machine->mach_params;
1021 		mach_params->codec_mask = bus->codec_mask;
1022 		mach_params->common_hdmi_codec_drv = hda_codec_use_common_hdmi;
1023 	}
1024 
1025 	return 0;
1026 }
1027 #else
1028 static int hda_generic_machine_select(struct snd_sof_dev *sdev)
1029 {
1030 	return 0;
1031 }
1032 #endif
1033 
1034 #if IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE)
1035 /* Check if all Slaves defined on the link can be found */
1036 static bool link_slaves_found(struct snd_sof_dev *sdev,
1037 			      const struct snd_soc_acpi_link_adr *link,
1038 			      struct sdw_intel_ctx *sdw)
1039 {
1040 	struct hdac_bus *bus = sof_to_bus(sdev);
1041 	struct sdw_intel_slave_id *ids = sdw->ids;
1042 	int num_slaves = sdw->num_slaves;
1043 	unsigned int part_id, link_id, unique_id, mfg_id;
1044 	int i, j, k;
1045 
1046 	for (i = 0; i < link->num_adr; i++) {
1047 		u64 adr = link->adr_d[i].adr;
1048 		int reported_part_count = 0;
1049 
1050 		mfg_id = SDW_MFG_ID(adr);
1051 		part_id = SDW_PART_ID(adr);
1052 		link_id = SDW_DISCO_LINK_ID(adr);
1053 
1054 		for (j = 0; j < num_slaves; j++) {
1055 			/* find out how many identical parts were reported on that link */
1056 			if (ids[j].link_id == link_id &&
1057 			    ids[j].id.part_id == part_id &&
1058 			    ids[j].id.mfg_id == mfg_id)
1059 				reported_part_count++;
1060 		}
1061 
1062 		for (j = 0; j < num_slaves; j++) {
1063 			int expected_part_count = 0;
1064 
1065 			if (ids[j].link_id != link_id ||
1066 			    ids[j].id.part_id != part_id ||
1067 			    ids[j].id.mfg_id != mfg_id)
1068 				continue;
1069 
1070 			/* find out how many identical parts are expected */
1071 			for (k = 0; k < link->num_adr; k++) {
1072 				u64 adr2 = link->adr_d[i].adr;
1073 				unsigned int part_id2, link_id2, mfg_id2;
1074 
1075 				mfg_id2 = SDW_MFG_ID(adr2);
1076 				part_id2 = SDW_PART_ID(adr2);
1077 				link_id2 = SDW_DISCO_LINK_ID(adr2);
1078 
1079 				if (link_id2 == link_id &&
1080 				    part_id2 == part_id &&
1081 				    mfg_id2 == mfg_id)
1082 					expected_part_count++;
1083 			}
1084 
1085 			if (reported_part_count == expected_part_count) {
1086 				/*
1087 				 * we have to check unique id
1088 				 * if there is more than one
1089 				 * Slave on the link
1090 				 */
1091 				unique_id = SDW_UNIQUE_ID(adr);
1092 				if (reported_part_count == 1 ||
1093 				    ids[j].id.unique_id == unique_id) {
1094 					dev_dbg(bus->dev, "found %x at link %d\n",
1095 						part_id, link_id);
1096 					break;
1097 				}
1098 			} else {
1099 				dev_dbg(bus->dev, "part %x reported %d expected %d on link %d, skipping\n",
1100 					part_id, reported_part_count, expected_part_count, link_id);
1101 			}
1102 		}
1103 		if (j == num_slaves) {
1104 			dev_dbg(bus->dev,
1105 				"Slave %x not found\n",
1106 				part_id);
1107 			return false;
1108 		}
1109 	}
1110 	return true;
1111 }
1112 
1113 static int hda_sdw_machine_select(struct snd_sof_dev *sdev)
1114 {
1115 	struct snd_sof_pdata *pdata = sdev->pdata;
1116 	const struct snd_soc_acpi_link_adr *link;
1117 	struct snd_soc_acpi_mach *mach;
1118 	struct sof_intel_hda_dev *hdev;
1119 	u32 link_mask;
1120 	int i;
1121 
1122 	hdev = pdata->hw_pdata;
1123 	link_mask = hdev->info.link_mask;
1124 
1125 	/*
1126 	 * Select SoundWire machine driver if needed using the
1127 	 * alternate tables. This case deals with SoundWire-only
1128 	 * machines, for mixed cases with I2C/I2S the detection relies
1129 	 * on the HID list.
1130 	 */
1131 	if (link_mask && !pdata->machine) {
1132 		for (mach = pdata->desc->alt_machines;
1133 		     mach && mach->link_mask; mach++) {
1134 			/*
1135 			 * On some platforms such as Up Extreme all links
1136 			 * are enabled but only one link can be used by
1137 			 * external codec. Instead of exact match of two masks,
1138 			 * first check whether link_mask of mach is subset of
1139 			 * link_mask supported by hw and then go on searching
1140 			 * link_adr
1141 			 */
1142 			if (~link_mask & mach->link_mask)
1143 				continue;
1144 
1145 			/* No need to match adr if there is no links defined */
1146 			if (!mach->links)
1147 				break;
1148 
1149 			link = mach->links;
1150 			for (i = 0; i < hdev->info.count && link->num_adr;
1151 			     i++, link++) {
1152 				/*
1153 				 * Try next machine if any expected Slaves
1154 				 * are not found on this link.
1155 				 */
1156 				if (!link_slaves_found(sdev, link, hdev->sdw))
1157 					break;
1158 			}
1159 			/* Found if all Slaves are checked */
1160 			if (i == hdev->info.count || !link->num_adr)
1161 				break;
1162 		}
1163 		if (mach && mach->link_mask) {
1164 			int dmic_num = 0;
1165 
1166 			pdata->machine = mach;
1167 			mach->mach_params.links = mach->links;
1168 			mach->mach_params.link_mask = mach->link_mask;
1169 			mach->mach_params.platform = dev_name(sdev->dev);
1170 			if (mach->sof_fw_filename)
1171 				pdata->fw_filename = mach->sof_fw_filename;
1172 			else
1173 				pdata->fw_filename = pdata->desc->default_fw_filename;
1174 			pdata->tplg_filename = mach->sof_tplg_filename;
1175 
1176 			/*
1177 			 * DMICs use up to 4 pins and are typically pin-muxed with SoundWire
1178 			 * link 2 and 3, thus we only try to enable dmics if all conditions
1179 			 * are true:
1180 			 * a) link 2 and 3 are not used by SoundWire
1181 			 * b) the NHLT table reports the presence of microphones
1182 			 */
1183 			if (!(mach->link_mask & GENMASK(3, 2))) {
1184 				const char *tplg_filename = mach->sof_tplg_filename;
1185 				int ret;
1186 
1187 				ret = dmic_topology_fixup(sdev, &tplg_filename, "", &dmic_num);
1188 
1189 				if (ret < 0)
1190 					return ret;
1191 
1192 				pdata->tplg_filename = tplg_filename;
1193 			}
1194 			mach->mach_params.dmic_num = dmic_num;
1195 
1196 			dev_dbg(sdev->dev,
1197 				"SoundWire machine driver %s topology %s\n",
1198 				mach->drv_name,
1199 				pdata->tplg_filename);
1200 		} else {
1201 			dev_info(sdev->dev,
1202 				 "No SoundWire machine driver found\n");
1203 		}
1204 	}
1205 
1206 	return 0;
1207 }
1208 #else
1209 static int hda_sdw_machine_select(struct snd_sof_dev *sdev)
1210 {
1211 	return 0;
1212 }
1213 #endif
1214 
1215 void hda_set_mach_params(const struct snd_soc_acpi_mach *mach,
1216 			 struct snd_sof_dev *sdev)
1217 {
1218 	struct snd_sof_pdata *pdata = sdev->pdata;
1219 	const struct sof_dev_desc *desc = pdata->desc;
1220 	struct snd_soc_acpi_mach_params *mach_params;
1221 
1222 	mach_params = (struct snd_soc_acpi_mach_params *)&mach->mach_params;
1223 	mach_params->platform = dev_name(sdev->dev);
1224 	mach_params->num_dai_drivers = desc->ops->num_drv;
1225 	mach_params->dai_drivers = desc->ops->drv;
1226 }
1227 
1228 void hda_machine_select(struct snd_sof_dev *sdev)
1229 {
1230 	struct snd_sof_pdata *sof_pdata = sdev->pdata;
1231 	const struct sof_dev_desc *desc = sof_pdata->desc;
1232 	struct snd_soc_acpi_mach *mach;
1233 
1234 	mach = snd_soc_acpi_find_machine(desc->machines);
1235 	if (mach) {
1236 		/*
1237 		 * If tplg file name is overridden, use it instead of
1238 		 * the one set in mach table
1239 		 */
1240 		if (!sof_pdata->tplg_filename)
1241 			sof_pdata->tplg_filename = mach->sof_tplg_filename;
1242 
1243 		sof_pdata->machine = mach;
1244 
1245 		if (mach->link_mask) {
1246 			mach->mach_params.links = mach->links;
1247 			mach->mach_params.link_mask = mach->link_mask;
1248 		}
1249 	}
1250 
1251 	/*
1252 	 * If I2S fails, try SoundWire
1253 	 */
1254 	hda_sdw_machine_select(sdev);
1255 
1256 	/*
1257 	 * Choose HDA generic machine driver if mach is NULL.
1258 	 * Otherwise, set certain mach params.
1259 	 */
1260 	hda_generic_machine_select(sdev);
1261 
1262 	if (!sof_pdata->machine)
1263 		dev_warn(sdev->dev, "warning: No matching ASoC machine driver found\n");
1264 }
1265 
1266 int hda_pci_intel_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
1267 {
1268 	int ret;
1269 
1270 	ret = snd_intel_dsp_driver_probe(pci);
1271 	if (ret != SND_INTEL_DSP_DRIVER_ANY && ret != SND_INTEL_DSP_DRIVER_SOF) {
1272 		dev_dbg(&pci->dev, "SOF PCI driver not selected, aborting probe\n");
1273 		return -ENODEV;
1274 	}
1275 
1276 	return sof_pci_probe(pci, pci_id);
1277 }
1278 EXPORT_SYMBOL_NS(hda_pci_intel_probe, SND_SOC_SOF_INTEL_HDA_COMMON);
1279 
1280 MODULE_LICENSE("Dual BSD/GPL");
1281 MODULE_IMPORT_NS(SND_SOC_SOF_PCI_DEV);
1282 MODULE_IMPORT_NS(SND_SOC_SOF_HDA_AUDIO_CODEC);
1283 MODULE_IMPORT_NS(SND_SOC_SOF_HDA_AUDIO_CODEC_I915);
1284 MODULE_IMPORT_NS(SND_SOC_SOF_XTENSA);
1285 MODULE_IMPORT_NS(SND_INTEL_SOUNDWIRE_ACPI);
1286 MODULE_IMPORT_NS(SOUNDWIRE_INTEL_INIT);
1287