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