xref: /openbmc/linux/sound/soc/sof/intel/hda.c (revision b5f184fbdb03b4fcc1141de34dd5ec964ca5d99e)
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-nhlt.h>
26 #include <sound/sof.h>
27 #include <sound/sof/xtensa.h>
28 #include "../sof-audio.h"
29 #include "../ops.h"
30 #include "hda.h"
31 
32 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
33 #include <sound/soc-acpi-intel-match.h>
34 #endif
35 
36 /* platform specific devices */
37 #include "shim.h"
38 
39 #define EXCEPT_MAX_HDR_SIZE	0x400
40 #define HDA_EXT_ROM_STATUS_SIZE 8
41 
42 #if IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE)
43 
44 /*
45  * The default for SoundWire clock stop quirks is to power gate the IP
46  * and do a Bus Reset, this will need to be modified when the DSP
47  * needs to remain in D0i3 so that the Master does not lose context
48  * and enumeration is not required on clock restart
49  */
50 static int sdw_clock_stop_quirks = SDW_INTEL_CLK_STOP_BUS_RESET;
51 module_param(sdw_clock_stop_quirks, int, 0444);
52 MODULE_PARM_DESC(sdw_clock_stop_quirks, "SOF SoundWire clock stop quirks");
53 
54 static int sdw_params_stream(struct device *dev,
55 			     struct sdw_intel_stream_params_data *params_data)
56 {
57 	struct snd_sof_dev *sdev = dev_get_drvdata(dev);
58 	struct snd_soc_dai *d = params_data->dai;
59 	struct sof_ipc_dai_config config;
60 	struct sof_ipc_reply reply;
61 	int link_id = params_data->link_id;
62 	int alh_stream_id = params_data->alh_stream_id;
63 	int ret;
64 	u32 size = sizeof(config);
65 
66 	memset(&config, 0, size);
67 	config.hdr.size = size;
68 	config.hdr.cmd = SOF_IPC_GLB_DAI_MSG | SOF_IPC_DAI_CONFIG;
69 	config.type = SOF_DAI_INTEL_ALH;
70 	config.dai_index = (link_id << 8) | (d->id);
71 	config.alh.stream_id = alh_stream_id;
72 
73 	/* send message to DSP */
74 	ret = sof_ipc_tx_message(sdev->ipc,
75 				 config.hdr.cmd, &config, size, &reply,
76 				 sizeof(reply));
77 	if (ret < 0) {
78 		dev_err(sdev->dev,
79 			"error: failed to set DAI hw_params for link %d dai->id %d ALH %d\n",
80 			link_id, d->id, alh_stream_id);
81 	}
82 
83 	return ret;
84 }
85 
86 static int sdw_free_stream(struct device *dev,
87 			   struct sdw_intel_stream_free_data *free_data)
88 {
89 	struct snd_sof_dev *sdev = dev_get_drvdata(dev);
90 	struct snd_soc_dai *d = free_data->dai;
91 	struct sof_ipc_dai_config config;
92 	struct sof_ipc_reply reply;
93 	int link_id = free_data->link_id;
94 	int ret;
95 	u32 size = sizeof(config);
96 
97 	memset(&config, 0, size);
98 	config.hdr.size = size;
99 	config.hdr.cmd = SOF_IPC_GLB_DAI_MSG | SOF_IPC_DAI_CONFIG;
100 	config.type = SOF_DAI_INTEL_ALH;
101 	config.dai_index = (link_id << 8) | d->id;
102 	config.alh.stream_id = 0xFFFF; /* invalid value on purpose */
103 
104 	/* send message to DSP */
105 	ret = sof_ipc_tx_message(sdev->ipc,
106 				 config.hdr.cmd, &config, size, &reply,
107 				 sizeof(reply));
108 	if (ret < 0) {
109 		dev_err(sdev->dev,
110 			"error: failed to free stream for link %d dai->id %d\n",
111 			link_id, d->id);
112 	}
113 
114 	return ret;
115 }
116 
117 static const struct sdw_intel_ops sdw_callback = {
118 	.params_stream = sdw_params_stream,
119 	.free_stream = sdw_free_stream,
120 };
121 
122 void hda_sdw_int_enable(struct snd_sof_dev *sdev, bool enable)
123 {
124 	sdw_intel_enable_irq(sdev->bar[HDA_DSP_BAR], enable);
125 }
126 
127 static int hda_sdw_acpi_scan(struct snd_sof_dev *sdev)
128 {
129 	struct sof_intel_hda_dev *hdev;
130 	acpi_handle handle;
131 	int ret;
132 
133 	handle = ACPI_HANDLE(sdev->dev);
134 
135 	/* save ACPI info for the probe step */
136 	hdev = sdev->pdata->hw_pdata;
137 
138 	ret = sdw_intel_acpi_scan(handle, &hdev->info);
139 	if (ret < 0)
140 		return -EINVAL;
141 
142 	return 0;
143 }
144 
145 static int hda_sdw_probe(struct snd_sof_dev *sdev)
146 {
147 	struct sof_intel_hda_dev *hdev;
148 	struct sdw_intel_res res;
149 	void *sdw;
150 
151 	hdev = sdev->pdata->hw_pdata;
152 
153 	memset(&res, 0, sizeof(res));
154 
155 	res.mmio_base = sdev->bar[HDA_DSP_BAR];
156 	res.irq = sdev->ipc_irq;
157 	res.handle = hdev->info.handle;
158 	res.parent = sdev->dev;
159 	res.ops = &sdw_callback;
160 	res.dev = sdev->dev;
161 	res.clock_stop_quirks = sdw_clock_stop_quirks;
162 
163 	/*
164 	 * ops and arg fields are not populated for now,
165 	 * they will be needed when the DAI callbacks are
166 	 * provided
167 	 */
168 
169 	/* we could filter links here if needed, e.g for quirks */
170 	res.count = hdev->info.count;
171 	res.link_mask = hdev->info.link_mask;
172 
173 	sdw = sdw_intel_probe(&res);
174 	if (!sdw) {
175 		dev_err(sdev->dev, "error: SoundWire probe failed\n");
176 		return -EINVAL;
177 	}
178 
179 	/* save context */
180 	hdev->sdw = sdw;
181 
182 	return 0;
183 }
184 
185 int hda_sdw_startup(struct snd_sof_dev *sdev)
186 {
187 	struct sof_intel_hda_dev *hdev;
188 
189 	hdev = sdev->pdata->hw_pdata;
190 
191 	if (!hdev->sdw)
192 		return 0;
193 
194 	return sdw_intel_startup(hdev->sdw);
195 }
196 
197 static int hda_sdw_exit(struct snd_sof_dev *sdev)
198 {
199 	struct sof_intel_hda_dev *hdev;
200 
201 	hdev = sdev->pdata->hw_pdata;
202 
203 	hda_sdw_int_enable(sdev, false);
204 
205 	if (hdev->sdw)
206 		sdw_intel_exit(hdev->sdw);
207 	hdev->sdw = NULL;
208 
209 	return 0;
210 }
211 
212 static bool hda_dsp_check_sdw_irq(struct snd_sof_dev *sdev)
213 {
214 	struct sof_intel_hda_dev *hdev;
215 	bool ret = false;
216 	u32 irq_status;
217 
218 	hdev = sdev->pdata->hw_pdata;
219 
220 	if (!hdev->sdw)
221 		return ret;
222 
223 	/* store status */
224 	irq_status = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_ADSPIS2);
225 
226 	/* invalid message ? */
227 	if (irq_status == 0xffffffff)
228 		goto out;
229 
230 	/* SDW message ? */
231 	if (irq_status & HDA_DSP_REG_ADSPIS2_SNDW)
232 		ret = true;
233 
234 out:
235 	return ret;
236 }
237 
238 static irqreturn_t hda_dsp_sdw_thread(int irq, void *context)
239 {
240 	return sdw_intel_thread(irq, context);
241 }
242 
243 static bool hda_sdw_check_wakeen_irq(struct snd_sof_dev *sdev)
244 {
245 	struct sof_intel_hda_dev *hdev;
246 
247 	hdev = sdev->pdata->hw_pdata;
248 	if (hdev->sdw &&
249 	    snd_sof_dsp_read(sdev, HDA_DSP_BAR,
250 			     HDA_DSP_REG_SNDW_WAKE_STS))
251 		return true;
252 
253 	return false;
254 }
255 
256 void hda_sdw_process_wakeen(struct snd_sof_dev *sdev)
257 {
258 	struct sof_intel_hda_dev *hdev;
259 
260 	hdev = sdev->pdata->hw_pdata;
261 	if (!hdev->sdw)
262 		return;
263 
264 	sdw_intel_process_wakeen_event(hdev->sdw);
265 }
266 
267 #endif
268 
269 /*
270  * Debug
271  */
272 
273 struct hda_dsp_msg_code {
274 	u32 code;
275 	const char *msg;
276 };
277 
278 static bool hda_use_msi = IS_ENABLED(CONFIG_PCI);
279 #if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG)
280 module_param_named(use_msi, hda_use_msi, bool, 0444);
281 MODULE_PARM_DESC(use_msi, "SOF HDA use PCI MSI mode");
282 #endif
283 
284 static char *hda_model;
285 module_param(hda_model, charp, 0444);
286 MODULE_PARM_DESC(hda_model, "Use the given HDA board model.");
287 
288 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) || IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE)
289 static int hda_dmic_num = -1;
290 module_param_named(dmic_num, hda_dmic_num, int, 0444);
291 MODULE_PARM_DESC(dmic_num, "SOF HDA DMIC number");
292 #endif
293 
294 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
295 static bool hda_codec_use_common_hdmi = IS_ENABLED(CONFIG_SND_HDA_CODEC_HDMI);
296 module_param_named(use_common_hdmi, hda_codec_use_common_hdmi, bool, 0444);
297 MODULE_PARM_DESC(use_common_hdmi, "SOF HDA use common HDMI codec driver");
298 #endif
299 
300 static const struct hda_dsp_msg_code hda_dsp_rom_msg[] = {
301 	{HDA_DSP_ROM_FW_MANIFEST_LOADED, "status: manifest loaded"},
302 	{HDA_DSP_ROM_FW_FW_LOADED, "status: fw loaded"},
303 	{HDA_DSP_ROM_FW_ENTERED, "status: fw entered"},
304 	{HDA_DSP_ROM_CSE_ERROR, "error: cse error"},
305 	{HDA_DSP_ROM_CSE_WRONG_RESPONSE, "error: cse wrong response"},
306 	{HDA_DSP_ROM_IMR_TO_SMALL, "error: IMR too small"},
307 	{HDA_DSP_ROM_BASE_FW_NOT_FOUND, "error: base fw not found"},
308 	{HDA_DSP_ROM_CSE_VALIDATION_FAILED, "error: signature verification failed"},
309 	{HDA_DSP_ROM_IPC_FATAL_ERROR, "error: ipc fatal error"},
310 	{HDA_DSP_ROM_L2_CACHE_ERROR, "error: L2 cache error"},
311 	{HDA_DSP_ROM_LOAD_OFFSET_TO_SMALL, "error: load offset too small"},
312 	{HDA_DSP_ROM_API_PTR_INVALID, "error: API ptr invalid"},
313 	{HDA_DSP_ROM_BASEFW_INCOMPAT, "error: base fw incompatible"},
314 	{HDA_DSP_ROM_UNHANDLED_INTERRUPT, "error: unhandled interrupt"},
315 	{HDA_DSP_ROM_MEMORY_HOLE_ECC, "error: ECC memory hole"},
316 	{HDA_DSP_ROM_KERNEL_EXCEPTION, "error: kernel exception"},
317 	{HDA_DSP_ROM_USER_EXCEPTION, "error: user exception"},
318 	{HDA_DSP_ROM_UNEXPECTED_RESET, "error: unexpected reset"},
319 	{HDA_DSP_ROM_NULL_FW_ENTRY,	"error: null FW entry point"},
320 };
321 
322 static void hda_dsp_get_status(struct snd_sof_dev *sdev)
323 {
324 	u32 status;
325 	int i;
326 
327 	status = snd_sof_dsp_read(sdev, HDA_DSP_BAR,
328 				  HDA_DSP_SRAM_REG_ROM_STATUS);
329 
330 	for (i = 0; i < ARRAY_SIZE(hda_dsp_rom_msg); i++) {
331 		if (status == hda_dsp_rom_msg[i].code) {
332 			dev_err(sdev->dev, "%s - code %8.8x\n",
333 				hda_dsp_rom_msg[i].msg, status);
334 			return;
335 		}
336 	}
337 
338 	/* not for us, must be generic sof message */
339 	dev_dbg(sdev->dev, "unknown ROM status value %8.8x\n", status);
340 }
341 
342 static void hda_dsp_get_registers(struct snd_sof_dev *sdev,
343 				  struct sof_ipc_dsp_oops_xtensa *xoops,
344 				  struct sof_ipc_panic_info *panic_info,
345 				  u32 *stack, size_t stack_words)
346 {
347 	u32 offset = sdev->dsp_oops_offset;
348 
349 	/* first read registers */
350 	sof_mailbox_read(sdev, offset, xoops, sizeof(*xoops));
351 
352 	/* note: variable AR register array is not read */
353 
354 	/* then get panic info */
355 	if (xoops->arch_hdr.totalsize > EXCEPT_MAX_HDR_SIZE) {
356 		dev_err(sdev->dev, "invalid header size 0x%x. FW oops is bogus\n",
357 			xoops->arch_hdr.totalsize);
358 		return;
359 	}
360 	offset += xoops->arch_hdr.totalsize;
361 	sof_block_read(sdev, sdev->mmio_bar, offset,
362 		       panic_info, sizeof(*panic_info));
363 
364 	/* then get the stack */
365 	offset += sizeof(*panic_info);
366 	sof_block_read(sdev, sdev->mmio_bar, offset, stack,
367 		       stack_words * sizeof(u32));
368 }
369 
370 /* dump the first 8 dwords representing the extended ROM status */
371 static void hda_dsp_dump_ext_rom_status(struct snd_sof_dev *sdev, u32 flags)
372 {
373 	char msg[128];
374 	int len = 0;
375 	u32 value;
376 	int i;
377 
378 	for (i = 0; i < HDA_EXT_ROM_STATUS_SIZE; i++) {
379 		value = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_SRAM_REG_ROM_STATUS + i * 0x4);
380 		len += snprintf(msg + len, sizeof(msg) - len, " 0x%x", value);
381 	}
382 
383 	sof_dev_dbg_or_err(sdev->dev, flags & SOF_DBG_DUMP_FORCE_ERR_LEVEL,
384 			   "extended rom status: %s", msg);
385 
386 }
387 
388 void hda_dsp_dump(struct snd_sof_dev *sdev, u32 flags)
389 {
390 	struct sof_ipc_dsp_oops_xtensa xoops;
391 	struct sof_ipc_panic_info panic_info;
392 	u32 stack[HDA_DSP_STACK_DUMP_SIZE];
393 	u32 status, panic;
394 
395 	/* try APL specific status message types first */
396 	hda_dsp_get_status(sdev);
397 
398 	/* now try generic SOF status messages */
399 	status = snd_sof_dsp_read(sdev, HDA_DSP_BAR,
400 				  HDA_DSP_SRAM_REG_FW_STATUS);
401 	panic = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_SRAM_REG_FW_TRACEP);
402 
403 	if (sdev->fw_state == SOF_FW_BOOT_COMPLETE) {
404 		hda_dsp_get_registers(sdev, &xoops, &panic_info, stack,
405 				      HDA_DSP_STACK_DUMP_SIZE);
406 		snd_sof_get_status(sdev, status, panic, &xoops, &panic_info,
407 				   stack, HDA_DSP_STACK_DUMP_SIZE);
408 	} else {
409 		sof_dev_dbg_or_err(sdev->dev, flags & SOF_DBG_DUMP_FORCE_ERR_LEVEL,
410 				   "status = 0x%8.8x panic = 0x%8.8x\n",
411 				   status, panic);
412 
413 		hda_dsp_dump_ext_rom_status(sdev, flags);
414 		hda_dsp_get_status(sdev);
415 	}
416 }
417 
418 void hda_ipc_irq_dump(struct snd_sof_dev *sdev)
419 {
420 	struct hdac_bus *bus = sof_to_bus(sdev);
421 	u32 adspis;
422 	u32 intsts;
423 	u32 intctl;
424 	u32 ppsts;
425 	u8 rirbsts;
426 
427 	/* read key IRQ stats and config registers */
428 	adspis = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_ADSPIS);
429 	intsts = snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTSTS);
430 	intctl = snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTCTL);
431 	ppsts = snd_sof_dsp_read(sdev, HDA_DSP_PP_BAR, SOF_HDA_REG_PP_PPSTS);
432 	rirbsts = snd_hdac_chip_readb(bus, RIRBSTS);
433 
434 	dev_err(sdev->dev,
435 		"error: hda irq intsts 0x%8.8x intlctl 0x%8.8x rirb %2.2x\n",
436 		intsts, intctl, rirbsts);
437 	dev_err(sdev->dev,
438 		"error: dsp irq ppsts 0x%8.8x adspis 0x%8.8x\n",
439 		ppsts, adspis);
440 }
441 
442 void hda_ipc_dump(struct snd_sof_dev *sdev)
443 {
444 	u32 hipcie;
445 	u32 hipct;
446 	u32 hipcctl;
447 
448 	hda_ipc_irq_dump(sdev);
449 
450 	/* read IPC status */
451 	hipcie = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCIE);
452 	hipct = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCT);
453 	hipcctl = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCCTL);
454 
455 	/* dump the IPC regs */
456 	/* TODO: parse the raw msg */
457 	dev_err(sdev->dev,
458 		"error: host status 0x%8.8x dsp status 0x%8.8x mask 0x%8.8x\n",
459 		hipcie, hipct, hipcctl);
460 }
461 
462 static int hda_init(struct snd_sof_dev *sdev)
463 {
464 	struct hda_bus *hbus;
465 	struct hdac_bus *bus;
466 	struct pci_dev *pci = to_pci_dev(sdev->dev);
467 	int ret;
468 
469 	hbus = sof_to_hbus(sdev);
470 	bus = sof_to_bus(sdev);
471 
472 	/* HDA bus init */
473 	sof_hda_bus_init(bus, &pci->dev);
474 
475 	bus->use_posbuf = 1;
476 	bus->bdl_pos_adj = 0;
477 	bus->sync_write = 1;
478 
479 	mutex_init(&hbus->prepare_mutex);
480 	hbus->pci = pci;
481 	hbus->mixer_assigned = -1;
482 	hbus->modelname = hda_model;
483 
484 	/* initialise hdac bus */
485 	bus->addr = pci_resource_start(pci, 0);
486 #if IS_ENABLED(CONFIG_PCI)
487 	bus->remap_addr = pci_ioremap_bar(pci, 0);
488 #endif
489 	if (!bus->remap_addr) {
490 		dev_err(bus->dev, "error: ioremap error\n");
491 		return -ENXIO;
492 	}
493 
494 	/* HDA base */
495 	sdev->bar[HDA_DSP_HDA_BAR] = bus->remap_addr;
496 
497 	/* init i915 and HDMI codecs */
498 	ret = hda_codec_i915_init(sdev);
499 	if (ret < 0)
500 		dev_warn(sdev->dev, "init of i915 and HDMI codec failed\n");
501 
502 	/* get controller capabilities */
503 	ret = hda_dsp_ctrl_get_caps(sdev);
504 	if (ret < 0)
505 		dev_err(sdev->dev, "error: get caps error\n");
506 
507 	return ret;
508 }
509 
510 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) || IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE)
511 
512 static int check_nhlt_dmic(struct snd_sof_dev *sdev)
513 {
514 	struct nhlt_acpi_table *nhlt;
515 	int dmic_num;
516 
517 	nhlt = intel_nhlt_init(sdev->dev);
518 	if (nhlt) {
519 		dmic_num = intel_nhlt_get_dmic_geo(sdev->dev, nhlt);
520 		intel_nhlt_free(nhlt);
521 		if (dmic_num >= 1 && dmic_num <= 4)
522 			return dmic_num;
523 	}
524 
525 	return 0;
526 }
527 
528 static const char *fixup_tplg_name(struct snd_sof_dev *sdev,
529 				   const char *sof_tplg_filename,
530 				   const char *idisp_str,
531 				   const char *dmic_str)
532 {
533 	const char *tplg_filename = NULL;
534 	char *filename, *tmp;
535 	const char *split_ext;
536 
537 	filename = kstrdup(sof_tplg_filename, GFP_KERNEL);
538 	if (!filename)
539 		return NULL;
540 
541 	/* this assumes a .tplg extension */
542 	tmp = filename;
543 	split_ext = strsep(&tmp, ".");
544 	if (split_ext)
545 		tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL,
546 					       "%s%s%s.tplg",
547 					       split_ext, idisp_str, dmic_str);
548 	kfree(filename);
549 
550 	return tplg_filename;
551 }
552 
553 static int dmic_topology_fixup(struct snd_sof_dev *sdev,
554 			       const char **tplg_filename,
555 			       const char *idisp_str,
556 			       int *dmic_found)
557 {
558 	const char *default_tplg_filename = *tplg_filename;
559 	const char *fixed_tplg_filename;
560 	const char *dmic_str;
561 	int dmic_num;
562 
563 	/* first check NHLT for DMICs */
564 	dmic_num = check_nhlt_dmic(sdev);
565 
566 	/* allow for module parameter override */
567 	if (hda_dmic_num != -1) {
568 		dev_dbg(sdev->dev,
569 			"overriding DMICs detected in NHLT tables %d by kernel param %d\n",
570 			dmic_num, hda_dmic_num);
571 		dmic_num = hda_dmic_num;
572 	}
573 
574 	switch (dmic_num) {
575 	case 1:
576 		dmic_str = "-1ch";
577 		break;
578 	case 2:
579 		dmic_str = "-2ch";
580 		break;
581 	case 3:
582 		dmic_str = "-3ch";
583 		break;
584 	case 4:
585 		dmic_str = "-4ch";
586 		break;
587 	default:
588 		dmic_num = 0;
589 		dmic_str = "";
590 		break;
591 	}
592 
593 	fixed_tplg_filename = fixup_tplg_name(sdev, default_tplg_filename,
594 					      idisp_str, dmic_str);
595 	if (!fixed_tplg_filename)
596 		return -ENOMEM;
597 
598 	dev_info(sdev->dev, "DMICs detected in NHLT tables: %d\n", dmic_num);
599 	*dmic_found = dmic_num;
600 	*tplg_filename = fixed_tplg_filename;
601 
602 	return 0;
603 }
604 #endif
605 
606 static int hda_init_caps(struct snd_sof_dev *sdev)
607 {
608 	struct hdac_bus *bus = sof_to_bus(sdev);
609 	struct snd_sof_pdata *pdata = sdev->pdata;
610 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
611 	struct hdac_ext_link *hlink;
612 #endif
613 	struct sof_intel_hda_dev *hdev = pdata->hw_pdata;
614 	u32 link_mask;
615 	int ret = 0;
616 
617 	device_disable_async_suspend(bus->dev);
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 	iounmap(bus->remap_addr);
899 	hda_codec_i915_exit(sdev);
900 err:
901 	return ret;
902 }
903 
904 int hda_dsp_remove(struct snd_sof_dev *sdev)
905 {
906 	struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
907 	struct hdac_bus *bus = sof_to_bus(sdev);
908 	struct pci_dev *pci = to_pci_dev(sdev->dev);
909 	const struct sof_intel_dsp_desc *chip = hda->desc;
910 
911 	/* cancel any attempt for DSP D0I3 */
912 	cancel_delayed_work_sync(&hda->d0i3_work);
913 
914 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
915 	/* codec removal, invoke bus_device_remove */
916 	snd_hdac_ext_bus_device_remove(bus);
917 #endif
918 
919 	hda_sdw_exit(sdev);
920 
921 	if (!IS_ERR_OR_NULL(hda->dmic_dev))
922 		platform_device_unregister(hda->dmic_dev);
923 
924 	/* disable DSP IRQ */
925 	snd_sof_dsp_update_bits(sdev, HDA_DSP_PP_BAR, SOF_HDA_REG_PP_PPCTL,
926 				SOF_HDA_PPCTL_PIE, 0);
927 
928 	/* disable CIE and GIE interrupts */
929 	snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTCTL,
930 				SOF_HDA_INT_CTRL_EN | SOF_HDA_INT_GLOBAL_EN, 0);
931 
932 	/* disable cores */
933 	if (chip)
934 		snd_sof_dsp_core_power_down(sdev, chip->host_managed_cores_mask);
935 
936 	/* disable DSP */
937 	snd_sof_dsp_update_bits(sdev, HDA_DSP_PP_BAR, SOF_HDA_REG_PP_PPCTL,
938 				SOF_HDA_PPCTL_GPROCEN, 0);
939 
940 	free_irq(sdev->ipc_irq, sdev);
941 	if (sdev->msi_enabled)
942 		pci_free_irq_vectors(pci);
943 
944 	hda_dsp_stream_free(sdev);
945 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
946 	snd_hdac_link_free_all(bus);
947 #endif
948 
949 	iounmap(sdev->bar[HDA_DSP_BAR]);
950 	iounmap(bus->remap_addr);
951 
952 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
953 	snd_hdac_ext_bus_exit(bus);
954 #endif
955 	hda_codec_i915_exit(sdev);
956 
957 	return 0;
958 }
959 
960 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
961 static int hda_generic_machine_select(struct snd_sof_dev *sdev)
962 {
963 	struct hdac_bus *bus = sof_to_bus(sdev);
964 	struct snd_soc_acpi_mach_params *mach_params;
965 	struct snd_soc_acpi_mach *hda_mach;
966 	struct snd_sof_pdata *pdata = sdev->pdata;
967 	const char *tplg_filename;
968 	const char *idisp_str;
969 	int dmic_num = 0;
970 	int codec_num = 0;
971 	int ret;
972 	int i;
973 
974 	/* codec detection */
975 	if (!bus->codec_mask) {
976 		dev_info(bus->dev, "no hda codecs found!\n");
977 	} else {
978 		dev_info(bus->dev, "hda codecs found, mask %lx\n",
979 			 bus->codec_mask);
980 
981 		for (i = 0; i < HDA_MAX_CODECS; i++) {
982 			if (bus->codec_mask & (1 << i))
983 				codec_num++;
984 		}
985 
986 		/*
987 		 * If no machine driver is found, then:
988 		 *
989 		 * generic hda machine driver can handle:
990 		 *  - one HDMI codec, and/or
991 		 *  - one external HDAudio codec
992 		 */
993 		if (!pdata->machine && codec_num <= 2) {
994 			hda_mach = snd_soc_acpi_intel_hda_machines;
995 
996 			dev_info(bus->dev, "using HDA machine driver %s now\n",
997 				 hda_mach->drv_name);
998 
999 			if (codec_num == 1 && HDA_IDISP_CODEC(bus->codec_mask))
1000 				idisp_str = "-idisp";
1001 			else
1002 				idisp_str = "";
1003 
1004 			/* topology: use the info from hda_machines */
1005 			tplg_filename = hda_mach->sof_tplg_filename;
1006 			ret = dmic_topology_fixup(sdev, &tplg_filename, idisp_str, &dmic_num);
1007 			if (ret < 0)
1008 				return ret;
1009 
1010 			hda_mach->mach_params.dmic_num = dmic_num;
1011 			pdata->machine = hda_mach;
1012 			pdata->tplg_filename = tplg_filename;
1013 		}
1014 	}
1015 
1016 	/* used by hda machine driver to create dai links */
1017 	if (pdata->machine) {
1018 		mach_params = (struct snd_soc_acpi_mach_params *)
1019 			&pdata->machine->mach_params;
1020 		mach_params->codec_mask = bus->codec_mask;
1021 		mach_params->common_hdmi_codec_drv = hda_codec_use_common_hdmi;
1022 	}
1023 
1024 	return 0;
1025 }
1026 #else
1027 static int hda_generic_machine_select(struct snd_sof_dev *sdev)
1028 {
1029 	return 0;
1030 }
1031 #endif
1032 
1033 #if IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE)
1034 /* Check if all Slaves defined on the link can be found */
1035 static bool link_slaves_found(struct snd_sof_dev *sdev,
1036 			      const struct snd_soc_acpi_link_adr *link,
1037 			      struct sdw_intel_ctx *sdw)
1038 {
1039 	struct hdac_bus *bus = sof_to_bus(sdev);
1040 	struct sdw_intel_slave_id *ids = sdw->ids;
1041 	int num_slaves = sdw->num_slaves;
1042 	unsigned int part_id, link_id, unique_id, mfg_id;
1043 	int i, j, k;
1044 
1045 	for (i = 0; i < link->num_adr; i++) {
1046 		u64 adr = link->adr_d[i].adr;
1047 		int reported_part_count = 0;
1048 
1049 		mfg_id = SDW_MFG_ID(adr);
1050 		part_id = SDW_PART_ID(adr);
1051 		link_id = SDW_DISCO_LINK_ID(adr);
1052 
1053 		for (j = 0; j < num_slaves; j++) {
1054 			/* find out how many identical parts were reported on that link */
1055 			if (ids[j].link_id == link_id &&
1056 			    ids[j].id.part_id == part_id &&
1057 			    ids[j].id.mfg_id == mfg_id)
1058 				reported_part_count++;
1059 		}
1060 
1061 		for (j = 0; j < num_slaves; j++) {
1062 			int expected_part_count = 0;
1063 
1064 			if (ids[j].link_id != link_id ||
1065 			    ids[j].id.part_id != part_id ||
1066 			    ids[j].id.mfg_id != mfg_id)
1067 				continue;
1068 
1069 			/* find out how many identical parts are expected */
1070 			for (k = 0; k < link->num_adr; k++) {
1071 				u64 adr2 = link->adr_d[i].adr;
1072 				unsigned int part_id2, link_id2, mfg_id2;
1073 
1074 				mfg_id2 = SDW_MFG_ID(adr2);
1075 				part_id2 = SDW_PART_ID(adr2);
1076 				link_id2 = SDW_DISCO_LINK_ID(adr2);
1077 
1078 				if (link_id2 == link_id &&
1079 				    part_id2 == part_id &&
1080 				    mfg_id2 == mfg_id)
1081 					expected_part_count++;
1082 			}
1083 
1084 			if (reported_part_count == expected_part_count) {
1085 				/*
1086 				 * we have to check unique id
1087 				 * if there is more than one
1088 				 * Slave on the link
1089 				 */
1090 				unique_id = SDW_UNIQUE_ID(adr);
1091 				if (reported_part_count == 1 ||
1092 				    ids[j].id.unique_id == unique_id) {
1093 					dev_dbg(bus->dev, "found %x at link %d\n",
1094 						part_id, link_id);
1095 					break;
1096 				}
1097 			} else {
1098 				dev_dbg(bus->dev, "part %x reported %d expected %d on link %d, skipping\n",
1099 					part_id, reported_part_count, expected_part_count, link_id);
1100 			}
1101 		}
1102 		if (j == num_slaves) {
1103 			dev_dbg(bus->dev,
1104 				"Slave %x not found\n",
1105 				part_id);
1106 			return false;
1107 		}
1108 	}
1109 	return true;
1110 }
1111 
1112 static int hda_sdw_machine_select(struct snd_sof_dev *sdev)
1113 {
1114 	struct snd_sof_pdata *pdata = sdev->pdata;
1115 	const struct snd_soc_acpi_link_adr *link;
1116 	struct snd_soc_acpi_mach *mach;
1117 	struct sof_intel_hda_dev *hdev;
1118 	u32 link_mask;
1119 	int i;
1120 
1121 	hdev = pdata->hw_pdata;
1122 	link_mask = hdev->info.link_mask;
1123 
1124 	/*
1125 	 * Select SoundWire machine driver if needed using the
1126 	 * alternate tables. This case deals with SoundWire-only
1127 	 * machines, for mixed cases with I2C/I2S the detection relies
1128 	 * on the HID list.
1129 	 */
1130 	if (link_mask && !pdata->machine) {
1131 		for (mach = pdata->desc->alt_machines;
1132 		     mach && mach->link_mask; mach++) {
1133 			/*
1134 			 * On some platforms such as Up Extreme all links
1135 			 * are enabled but only one link can be used by
1136 			 * external codec. Instead of exact match of two masks,
1137 			 * first check whether link_mask of mach is subset of
1138 			 * link_mask supported by hw and then go on searching
1139 			 * link_adr
1140 			 */
1141 			if (~link_mask & mach->link_mask)
1142 				continue;
1143 
1144 			/* No need to match adr if there is no links defined */
1145 			if (!mach->links)
1146 				break;
1147 
1148 			link = mach->links;
1149 			for (i = 0; i < hdev->info.count && link->num_adr;
1150 			     i++, link++) {
1151 				/*
1152 				 * Try next machine if any expected Slaves
1153 				 * are not found on this link.
1154 				 */
1155 				if (!link_slaves_found(sdev, link, hdev->sdw))
1156 					break;
1157 			}
1158 			/* Found if all Slaves are checked */
1159 			if (i == hdev->info.count || !link->num_adr)
1160 				break;
1161 		}
1162 		if (mach && mach->link_mask) {
1163 			int dmic_num = 0;
1164 
1165 			pdata->machine = mach;
1166 			mach->mach_params.links = mach->links;
1167 			mach->mach_params.link_mask = mach->link_mask;
1168 			mach->mach_params.platform = dev_name(sdev->dev);
1169 			if (mach->sof_fw_filename)
1170 				pdata->fw_filename = mach->sof_fw_filename;
1171 			else
1172 				pdata->fw_filename = pdata->desc->default_fw_filename;
1173 			pdata->tplg_filename = mach->sof_tplg_filename;
1174 
1175 			/*
1176 			 * DMICs use up to 4 pins and are typically pin-muxed with SoundWire
1177 			 * link 2 and 3, thus we only try to enable dmics if all conditions
1178 			 * are true:
1179 			 * a) link 2 and 3 are not used by SoundWire
1180 			 * b) the NHLT table reports the presence of microphones
1181 			 */
1182 			if (!(mach->link_mask & GENMASK(3, 2))) {
1183 				const char *tplg_filename = mach->sof_tplg_filename;
1184 				int ret;
1185 
1186 				ret = dmic_topology_fixup(sdev, &tplg_filename, "", &dmic_num);
1187 
1188 				if (ret < 0)
1189 					return ret;
1190 
1191 				pdata->tplg_filename = tplg_filename;
1192 			}
1193 			mach->mach_params.dmic_num = dmic_num;
1194 
1195 			dev_dbg(sdev->dev,
1196 				"SoundWire machine driver %s topology %s\n",
1197 				mach->drv_name,
1198 				pdata->tplg_filename);
1199 		} else {
1200 			dev_info(sdev->dev,
1201 				 "No SoundWire machine driver found\n");
1202 		}
1203 	}
1204 
1205 	return 0;
1206 }
1207 #else
1208 static int hda_sdw_machine_select(struct snd_sof_dev *sdev)
1209 {
1210 	return 0;
1211 }
1212 #endif
1213 
1214 void hda_set_mach_params(const struct snd_soc_acpi_mach *mach,
1215 			 struct device *dev)
1216 {
1217 	struct snd_soc_acpi_mach_params *mach_params;
1218 
1219 	mach_params = (struct snd_soc_acpi_mach_params *)&mach->mach_params;
1220 	mach_params->platform = dev_name(dev);
1221 }
1222 
1223 void hda_machine_select(struct snd_sof_dev *sdev)
1224 {
1225 	struct snd_sof_pdata *sof_pdata = sdev->pdata;
1226 	const struct sof_dev_desc *desc = sof_pdata->desc;
1227 	struct snd_soc_acpi_mach *mach;
1228 
1229 	mach = snd_soc_acpi_find_machine(desc->machines);
1230 	if (mach) {
1231 		/*
1232 		 * If tplg file name is overridden, use it instead of
1233 		 * the one set in mach table
1234 		 */
1235 		if (!sof_pdata->tplg_filename)
1236 			sof_pdata->tplg_filename = mach->sof_tplg_filename;
1237 
1238 		sof_pdata->machine = mach;
1239 
1240 		if (mach->link_mask) {
1241 			mach->mach_params.links = mach->links;
1242 			mach->mach_params.link_mask = mach->link_mask;
1243 		}
1244 	}
1245 
1246 	/*
1247 	 * If I2S fails, try SoundWire
1248 	 */
1249 	hda_sdw_machine_select(sdev);
1250 
1251 	/*
1252 	 * Choose HDA generic machine driver if mach is NULL.
1253 	 * Otherwise, set certain mach params.
1254 	 */
1255 	hda_generic_machine_select(sdev);
1256 
1257 	if (!sof_pdata->machine)
1258 		dev_warn(sdev->dev, "warning: No matching ASoC machine driver found\n");
1259 }
1260 
1261 MODULE_LICENSE("Dual BSD/GPL");
1262 MODULE_IMPORT_NS(SND_SOC_SOF_HDA_AUDIO_CODEC);
1263 MODULE_IMPORT_NS(SND_SOC_SOF_HDA_AUDIO_CODEC_I915);
1264 MODULE_IMPORT_NS(SND_SOC_SOF_XTENSA);
1265 MODULE_IMPORT_NS(SOUNDWIRE_INTEL_INIT);
1266