Merge branch 'asoc-5.2' into asoc-5.3
[linux-2.6-microblaze.git] / sound / soc / sof / intel / hda.c
1 // SPDX-License-Identifier: (GPL-2.0 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 <linux/module.h>
19 #include <sound/hdaudio_ext.h>
20 #include <sound/sof.h>
21 #include <sound/sof/xtensa.h>
22 #include "../ops.h"
23 #include "hda.h"
24 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC)
25 #include "../../codecs/hdac_hda.h"
26 #endif
27
28 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
29 #include <sound/soc-acpi-intel-match.h>
30 #endif
31
32 /* platform specific devices */
33 #include "shim.h"
34
35 /*
36  * Debug
37  */
38
39 struct hda_dsp_msg_code {
40         u32 code;
41         const char *msg;
42 };
43
44 static const struct hda_dsp_msg_code hda_dsp_rom_msg[] = {
45         {HDA_DSP_ROM_FW_MANIFEST_LOADED, "status: manifest loaded"},
46         {HDA_DSP_ROM_FW_FW_LOADED, "status: fw loaded"},
47         {HDA_DSP_ROM_FW_ENTERED, "status: fw entered"},
48         {HDA_DSP_ROM_CSE_ERROR, "error: cse error"},
49         {HDA_DSP_ROM_CSE_WRONG_RESPONSE, "error: cse wrong response"},
50         {HDA_DSP_ROM_IMR_TO_SMALL, "error: IMR too small"},
51         {HDA_DSP_ROM_BASE_FW_NOT_FOUND, "error: base fw not found"},
52         {HDA_DSP_ROM_CSE_VALIDATION_FAILED, "error: signature verification failed"},
53         {HDA_DSP_ROM_IPC_FATAL_ERROR, "error: ipc fatal error"},
54         {HDA_DSP_ROM_L2_CACHE_ERROR, "error: L2 cache error"},
55         {HDA_DSP_ROM_LOAD_OFFSET_TO_SMALL, "error: load offset too small"},
56         {HDA_DSP_ROM_API_PTR_INVALID, "error: API ptr invalid"},
57         {HDA_DSP_ROM_BASEFW_INCOMPAT, "error: base fw incompatible"},
58         {HDA_DSP_ROM_UNHANDLED_INTERRUPT, "error: unhandled interrupt"},
59         {HDA_DSP_ROM_MEMORY_HOLE_ECC, "error: ECC memory hole"},
60         {HDA_DSP_ROM_KERNEL_EXCEPTION, "error: kernel exception"},
61         {HDA_DSP_ROM_USER_EXCEPTION, "error: user exception"},
62         {HDA_DSP_ROM_UNEXPECTED_RESET, "error: unexpected reset"},
63         {HDA_DSP_ROM_NULL_FW_ENTRY,     "error: null FW entry point"},
64 };
65
66 static void hda_dsp_get_status_skl(struct snd_sof_dev *sdev)
67 {
68         u32 status;
69         int i;
70
71         status = snd_sof_dsp_read(sdev, HDA_DSP_BAR,
72                                   HDA_ADSP_FW_STATUS_SKL);
73
74         for (i = 0; i < ARRAY_SIZE(hda_dsp_rom_msg); i++) {
75                 if (status == hda_dsp_rom_msg[i].code) {
76                         dev_err(sdev->dev, "%s - code %8.8x\n",
77                                 hda_dsp_rom_msg[i].msg, status);
78                         return;
79                 }
80         }
81
82         /* not for us, must be generic sof message */
83         dev_dbg(sdev->dev, "unknown ROM status value %8.8x\n", status);
84 }
85
86 static void hda_dsp_get_status(struct snd_sof_dev *sdev)
87 {
88         u32 status;
89         int i;
90
91         status = snd_sof_dsp_read(sdev, HDA_DSP_BAR,
92                                   HDA_DSP_SRAM_REG_ROM_STATUS);
93
94         for (i = 0; i < ARRAY_SIZE(hda_dsp_rom_msg); i++) {
95                 if (status == hda_dsp_rom_msg[i].code) {
96                         dev_err(sdev->dev, "%s - code %8.8x\n",
97                                 hda_dsp_rom_msg[i].msg, status);
98                         return;
99                 }
100         }
101
102         /* not for us, must be generic sof message */
103         dev_dbg(sdev->dev, "unknown ROM status value %8.8x\n", status);
104 }
105
106 static void hda_dsp_get_registers(struct snd_sof_dev *sdev,
107                                   struct sof_ipc_dsp_oops_xtensa *xoops,
108                                   struct sof_ipc_panic_info *panic_info,
109                                   u32 *stack, size_t stack_words)
110 {
111         /* first read registers */
112         sof_block_read(sdev, sdev->mmio_bar, sdev->dsp_oops_offset, xoops,
113                        sizeof(*xoops));
114
115         /* then get panic info */
116         sof_block_read(sdev, sdev->mmio_bar, sdev->dsp_oops_offset +
117                        sizeof(*xoops), panic_info, sizeof(*panic_info));
118
119         /* then get the stack */
120         sof_block_read(sdev, sdev->mmio_bar, sdev->dsp_oops_offset +
121                        sizeof(*xoops) + sizeof(*panic_info), stack,
122                        stack_words * sizeof(u32));
123 }
124
125 void hda_dsp_dump_skl(struct snd_sof_dev *sdev, u32 flags)
126 {
127         struct sof_ipc_dsp_oops_xtensa xoops;
128         struct sof_ipc_panic_info panic_info;
129         u32 stack[HDA_DSP_STACK_DUMP_SIZE];
130         u32 status, panic;
131
132         /* try APL specific status message types first */
133         hda_dsp_get_status_skl(sdev);
134
135         /* now try generic SOF status messages */
136         status = snd_sof_dsp_read(sdev, HDA_DSP_BAR,
137                                   HDA_ADSP_ERROR_CODE_SKL);
138
139         /*TODO: Check: there is no define in spec, but it is used in the code*/
140         panic = snd_sof_dsp_read(sdev, HDA_DSP_BAR,
141                                  HDA_ADSP_ERROR_CODE_SKL + 0x4);
142
143         if (sdev->boot_complete) {
144                 hda_dsp_get_registers(sdev, &xoops, &panic_info, stack,
145                                       HDA_DSP_STACK_DUMP_SIZE);
146                 snd_sof_get_status(sdev, status, panic, &xoops, &panic_info,
147                                    stack, HDA_DSP_STACK_DUMP_SIZE);
148         } else {
149                 dev_err(sdev->dev, "error: status = 0x%8.8x panic = 0x%8.8x\n",
150                         status, panic);
151                 hda_dsp_get_status_skl(sdev);
152         }
153 }
154
155 void hda_dsp_dump(struct snd_sof_dev *sdev, u32 flags)
156 {
157         struct sof_ipc_dsp_oops_xtensa xoops;
158         struct sof_ipc_panic_info panic_info;
159         u32 stack[HDA_DSP_STACK_DUMP_SIZE];
160         u32 status, panic;
161
162         /* try APL specific status message types first */
163         hda_dsp_get_status(sdev);
164
165         /* now try generic SOF status messages */
166         status = snd_sof_dsp_read(sdev, HDA_DSP_BAR,
167                                   HDA_DSP_SRAM_REG_FW_STATUS);
168         panic = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_SRAM_REG_FW_TRACEP);
169
170         if (sdev->boot_complete) {
171                 hda_dsp_get_registers(sdev, &xoops, &panic_info, stack,
172                                       HDA_DSP_STACK_DUMP_SIZE);
173                 snd_sof_get_status(sdev, status, panic, &xoops, &panic_info,
174                                    stack, HDA_DSP_STACK_DUMP_SIZE);
175         } else {
176                 dev_err(sdev->dev, "error: status = 0x%8.8x panic = 0x%8.8x\n",
177                         status, panic);
178                 hda_dsp_get_status(sdev);
179         }
180 }
181
182 void hda_ipc_dump(struct snd_sof_dev *sdev)
183 {
184         u32 hipcie;
185         u32 hipct;
186         u32 hipcctl;
187
188         /* read IPC status */
189         hipcie = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCIE);
190         hipct = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCT);
191         hipcctl = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCCTL);
192
193         /* dump the IPC regs */
194         /* TODO: parse the raw msg */
195         dev_err(sdev->dev,
196                 "error: host status 0x%8.8x dsp status 0x%8.8x mask 0x%8.8x\n",
197                 hipcie, hipct, hipcctl);
198 }
199
200 static int hda_init(struct snd_sof_dev *sdev)
201 {
202         struct hda_bus *hbus;
203         struct hdac_bus *bus;
204         struct hdac_ext_bus_ops *ext_ops = NULL;
205         struct pci_dev *pci = to_pci_dev(sdev->dev);
206         int ret;
207
208         hbus = sof_to_hbus(sdev);
209         bus = sof_to_bus(sdev);
210
211         /* HDA bus init */
212 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC)
213         ext_ops = snd_soc_hdac_hda_get_ops();
214 #endif
215         sof_hda_bus_init(bus, &pci->dev, ext_ops);
216         bus->use_posbuf = 1;
217         bus->bdl_pos_adj = 0;
218
219         mutex_init(&hbus->prepare_mutex);
220         hbus->pci = pci;
221         hbus->mixer_assigned = -1;
222         hbus->modelname = "sofbus";
223
224         /* initialise hdac bus */
225         bus->addr = pci_resource_start(pci, 0);
226         bus->remap_addr = pci_ioremap_bar(pci, 0);
227         if (!bus->remap_addr) {
228                 dev_err(bus->dev, "error: ioremap error\n");
229                 return -ENXIO;
230         }
231
232         /* HDA base */
233         sdev->bar[HDA_DSP_HDA_BAR] = bus->remap_addr;
234
235         /* get controller capabilities */
236         ret = hda_dsp_ctrl_get_caps(sdev);
237         if (ret < 0)
238                 dev_err(sdev->dev, "error: get caps error\n");
239
240         return ret;
241 }
242
243 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
244
245 static const char *fixup_tplg_name(struct snd_sof_dev *sdev,
246                                    const char *sof_tplg_filename)
247 {
248         const char *tplg_filename = NULL;
249         char *filename;
250         char *split_ext;
251
252         filename = devm_kstrdup(sdev->dev, sof_tplg_filename, GFP_KERNEL);
253         if (!filename)
254                 return NULL;
255
256         /* this assumes a .tplg extension */
257         split_ext = strsep(&filename, ".");
258         if (split_ext) {
259                 tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL,
260                                                "%s-idisp.tplg", split_ext);
261                 if (!tplg_filename)
262                         return NULL;
263         }
264         return tplg_filename;
265 }
266
267 #endif
268
269 static int hda_init_caps(struct snd_sof_dev *sdev)
270 {
271         struct hdac_bus *bus = sof_to_bus(sdev);
272 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
273         struct hdac_ext_link *hlink;
274         struct snd_soc_acpi_mach_params *mach_params;
275         struct snd_soc_acpi_mach *hda_mach;
276         struct snd_sof_pdata *pdata = sdev->pdata;
277         struct snd_soc_acpi_mach *mach;
278         const char *tplg_filename;
279         int codec_num = 0;
280         int i;
281 #endif
282         int ret = 0;
283
284         device_disable_async_suspend(bus->dev);
285
286         /* check if dsp is there */
287         if (bus->ppcap)
288                 dev_dbg(sdev->dev, "PP capability, will probe DSP later.\n");
289
290         ret = hda_dsp_ctrl_init_chip(sdev, true);
291         if (ret < 0) {
292                 dev_err(bus->dev, "error: init chip failed with ret: %d\n",
293                         ret);
294                 return ret;
295         }
296
297 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
298         if (bus->mlcap)
299                 snd_hdac_ext_bus_get_ml_capabilities(bus);
300
301         /* init i915 and HDMI codecs */
302         ret = hda_codec_i915_init(sdev);
303         if (ret < 0) {
304                 dev_err(sdev->dev, "error: no HDMI audio devices found\n");
305                 return ret;
306         }
307
308         /* codec detection */
309         if (!bus->codec_mask) {
310                 dev_info(bus->dev, "no hda codecs found!\n");
311         } else {
312                 dev_info(bus->dev, "hda codecs found, mask %lx\n",
313                          bus->codec_mask);
314
315                 for (i = 0; i < HDA_MAX_CODECS; i++) {
316                         if (bus->codec_mask & (1 << i))
317                                 codec_num++;
318                 }
319
320                 /*
321                  * If no machine driver is found, then:
322                  *
323                  * hda machine driver is used if :
324                  * 1. there is one HDMI codec and one external HDAudio codec
325                  * 2. only HDMI codec
326                  */
327                 if (!pdata->machine && codec_num <= 2 &&
328                     HDA_IDISP_CODEC(bus->codec_mask)) {
329                         hda_mach = snd_soc_acpi_intel_hda_machines;
330                         pdata->machine = hda_mach;
331
332                         /* topology: use the info from hda_machines */
333                         pdata->tplg_filename =
334                                 hda_mach->sof_tplg_filename;
335
336                         /* firmware: pick the first in machine list */
337                         mach = pdata->desc->machines;
338                         pdata->fw_filename = mach->sof_fw_filename;
339
340                         dev_info(bus->dev, "using HDA machine driver %s now\n",
341                                  hda_mach->drv_name);
342
343                         /* fixup topology file for HDMI only platforms */
344                         if (codec_num == 1) {
345                                 /* use local variable for readability */
346                                 tplg_filename = pdata->tplg_filename;
347                                 tplg_filename = fixup_tplg_name(sdev, tplg_filename);
348                                 if (!tplg_filename) {
349                                         hda_codec_i915_exit(sdev);
350                                         return ret;
351                                 }
352                                 pdata->tplg_filename = tplg_filename;
353                         }
354                 }
355         }
356
357         /* used by hda machine driver to create dai links */
358         if (pdata->machine) {
359                 mach_params = (struct snd_soc_acpi_mach_params *)
360                         &pdata->machine->mach_params;
361                 mach_params->codec_mask = bus->codec_mask;
362                 mach_params->platform = dev_name(sdev->dev);
363         }
364
365         /* create codec instances */
366         hda_codec_probe_bus(sdev);
367
368         hda_codec_i915_put(sdev);
369
370         /*
371          * we are done probing so decrement link counts
372          */
373         list_for_each_entry(hlink, &bus->hlink_list, list)
374                 snd_hdac_ext_bus_link_put(bus, hlink);
375 #endif
376         return 0;
377 }
378
379 static const struct sof_intel_dsp_desc
380         *get_chip_info(struct snd_sof_pdata *pdata)
381 {
382         const struct sof_dev_desc *desc = pdata->desc;
383         const struct sof_intel_dsp_desc *chip_info;
384
385         chip_info = desc->chip_info;
386
387         return chip_info;
388 }
389
390 int hda_dsp_probe(struct snd_sof_dev *sdev)
391 {
392         struct pci_dev *pci = to_pci_dev(sdev->dev);
393         struct sof_intel_hda_dev *hdev;
394         struct hdac_bus *bus;
395         const struct sof_intel_dsp_desc *chip;
396         int ret = 0;
397
398         /*
399          * detect DSP by checking class/subclass/prog-id information
400          * class=04 subclass 03 prog-if 00: no DSP, legacy driver is required
401          * class=04 subclass 01 prog-if 00: DSP is present
402          *   (and may be required e.g. for DMIC or SSP support)
403          * class=04 subclass 03 prog-if 80: either of DSP or legacy mode works
404          */
405         if (pci->class == 0x040300) {
406                 dev_err(sdev->dev, "error: the DSP is not enabled on this platform, aborting probe\n");
407                 return -ENODEV;
408         } else if (pci->class != 0x040100 && pci->class != 0x040380) {
409                 dev_err(sdev->dev, "error: unknown PCI class/subclass/prog-if 0x%06x found, aborting probe\n", pci->class);
410                 return -ENODEV;
411         }
412         dev_info(sdev->dev, "DSP detected with PCI class/subclass/prog-if 0x%06x\n", pci->class);
413
414         chip = get_chip_info(sdev->pdata);
415         if (!chip) {
416                 dev_err(sdev->dev, "error: no such device supported, chip id:%x\n",
417                         pci->device);
418                 ret = -EIO;
419                 goto err;
420         }
421
422         hdev = devm_kzalloc(sdev->dev, sizeof(*hdev), GFP_KERNEL);
423         if (!hdev)
424                 return -ENOMEM;
425         sdev->pdata->hw_pdata = hdev;
426         hdev->desc = chip;
427
428         hdev->dmic_dev = platform_device_register_data(sdev->dev, "dmic-codec",
429                                                        PLATFORM_DEVID_NONE,
430                                                        NULL, 0);
431         if (IS_ERR(hdev->dmic_dev)) {
432                 dev_err(sdev->dev, "error: failed to create DMIC device\n");
433                 return PTR_ERR(hdev->dmic_dev);
434         }
435
436         /*
437          * use position update IPC if either it is forced
438          * or we don't have other choice
439          */
440 #if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_FORCE_IPC_POSITION)
441         hdev->no_ipc_position = 0;
442 #else
443         hdev->no_ipc_position = sof_ops(sdev)->pcm_pointer ? 1 : 0;
444 #endif
445
446         /* set up HDA base */
447         bus = sof_to_bus(sdev);
448         ret = hda_init(sdev);
449         if (ret < 0)
450                 goto hdac_bus_unmap;
451
452         /* DSP base */
453         sdev->bar[HDA_DSP_BAR] = pci_ioremap_bar(pci, HDA_DSP_BAR);
454         if (!sdev->bar[HDA_DSP_BAR]) {
455                 dev_err(sdev->dev, "error: ioremap error\n");
456                 ret = -ENXIO;
457                 goto hdac_bus_unmap;
458         }
459
460         sdev->mmio_bar = HDA_DSP_BAR;
461         sdev->mailbox_bar = HDA_DSP_BAR;
462
463         /* allow 64bit DMA address if supported by H/W */
464         if (!dma_set_mask(&pci->dev, DMA_BIT_MASK(64))) {
465                 dev_dbg(sdev->dev, "DMA mask is 64 bit\n");
466                 dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(64));
467         } else {
468                 dev_dbg(sdev->dev, "DMA mask is 32 bit\n");
469                 dma_set_mask(&pci->dev, DMA_BIT_MASK(32));
470                 dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(32));
471         }
472
473         /* init streams */
474         ret = hda_dsp_stream_init(sdev);
475         if (ret < 0) {
476                 dev_err(sdev->dev, "error: failed to init streams\n");
477                 /*
478                  * not all errors are due to memory issues, but trying
479                  * to free everything does not harm
480                  */
481                 goto free_streams;
482         }
483
484         /*
485          * register our IRQ
486          * let's try to enable msi firstly
487          * if it fails, use legacy interrupt mode
488          * TODO: support interrupt mode selection with kernel parameter
489          *       support msi multiple vectors
490          */
491 #if IS_ENABLED(CONFIG_PCI)
492         ret = pci_alloc_irq_vectors(pci, 1, 1, PCI_IRQ_MSI);
493 #endif
494         if (ret < 0) {
495                 dev_info(sdev->dev, "use legacy interrupt mode\n");
496                 /*
497                  * in IO-APIC mode, hda->irq and ipc_irq are using the same
498                  * irq number of pci->irq
499                  */
500                 hdev->irq = pci->irq;
501                 sdev->ipc_irq = pci->irq;
502                 sdev->msi_enabled = 0;
503         } else {
504                 dev_info(sdev->dev, "use msi interrupt mode\n");
505 #if IS_ENABLED(CONFIG_PCI)
506                 hdev->irq = pci_irq_vector(pci, 0);
507 #endif
508                 /* ipc irq number is the same of hda irq */
509                 sdev->ipc_irq = hdev->irq;
510                 sdev->msi_enabled = 1;
511         }
512
513         dev_dbg(sdev->dev, "using HDA IRQ %d\n", hdev->irq);
514         ret = request_threaded_irq(hdev->irq, hda_dsp_stream_interrupt,
515                                    hda_dsp_stream_threaded_handler,
516                                    IRQF_SHARED, "AudioHDA", bus);
517         if (ret < 0) {
518                 dev_err(sdev->dev, "error: failed to register HDA IRQ %d\n",
519                         hdev->irq);
520                 goto free_irq_vector;
521         }
522
523         dev_dbg(sdev->dev, "using IPC IRQ %d\n", sdev->ipc_irq);
524         ret = request_threaded_irq(sdev->ipc_irq, hda_dsp_ipc_irq_handler,
525                                    sof_ops(sdev)->irq_thread, IRQF_SHARED,
526                                    "AudioDSP", sdev);
527         if (ret < 0) {
528                 dev_err(sdev->dev, "error: failed to register IPC IRQ %d\n",
529                         sdev->ipc_irq);
530                 goto free_hda_irq;
531         }
532
533         pci_set_master(pci);
534         synchronize_irq(pci->irq);
535
536         /*
537          * clear TCSEL to clear playback on some HD Audio
538          * codecs. PCI TCSEL is defined in the Intel manuals.
539          */
540         snd_sof_pci_update_bits(sdev, PCI_TCSEL, 0x07, 0);
541
542         /* init HDA capabilities */
543         ret = hda_init_caps(sdev);
544         if (ret < 0)
545                 goto free_ipc_irq;
546
547         /* enable DSP features */
548         snd_sof_dsp_update_bits(sdev, HDA_DSP_PP_BAR, SOF_HDA_REG_PP_PPCTL,
549                                 SOF_HDA_PPCTL_GPROCEN, SOF_HDA_PPCTL_GPROCEN);
550
551         /* enable DSP IRQ */
552         snd_sof_dsp_update_bits(sdev, HDA_DSP_PP_BAR, SOF_HDA_REG_PP_PPCTL,
553                                 SOF_HDA_PPCTL_PIE, SOF_HDA_PPCTL_PIE);
554
555         /* initialize waitq for code loading */
556         init_waitqueue_head(&sdev->waitq);
557
558         /* set default mailbox offset for FW ready message */
559         sdev->dsp_box.offset = HDA_DSP_MBOX_UPLINK_OFFSET;
560
561         return 0;
562
563 free_ipc_irq:
564         free_irq(sdev->ipc_irq, sdev);
565 free_hda_irq:
566         free_irq(hdev->irq, bus);
567 free_irq_vector:
568 #if IS_ENABLED(CONFIG_PCI)
569         if (sdev->msi_enabled)
570                 pci_free_irq_vectors(pci);
571 #endif
572 free_streams:
573         hda_dsp_stream_free(sdev);
574 /* dsp_unmap: not currently used */
575         iounmap(sdev->bar[HDA_DSP_BAR]);
576 hdac_bus_unmap:
577         iounmap(bus->remap_addr);
578 err:
579         return ret;
580 }
581
582 int hda_dsp_remove(struct snd_sof_dev *sdev)
583 {
584         struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
585         struct hdac_bus *bus = sof_to_bus(sdev);
586         const struct sof_intel_dsp_desc *chip = hda->desc;
587
588 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
589         /* codec removal, invoke bus_device_remove */
590         snd_hdac_ext_bus_device_remove(bus);
591 #endif
592
593         if (!IS_ERR_OR_NULL(hda->dmic_dev))
594                 platform_device_unregister(hda->dmic_dev);
595
596         /* disable DSP IRQ */
597         snd_sof_dsp_update_bits(sdev, HDA_DSP_PP_BAR, SOF_HDA_REG_PP_PPCTL,
598                                 SOF_HDA_PPCTL_PIE, 0);
599
600         /* disable CIE and GIE interrupts */
601         snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTCTL,
602                                 SOF_HDA_INT_CTRL_EN | SOF_HDA_INT_GLOBAL_EN, 0);
603
604         /* disable cores */
605         if (chip)
606                 hda_dsp_core_reset_power_down(sdev, chip->cores_mask);
607
608         /* disable DSP */
609         snd_sof_dsp_update_bits(sdev, HDA_DSP_PP_BAR, SOF_HDA_REG_PP_PPCTL,
610                                 SOF_HDA_PPCTL_GPROCEN, 0);
611
612         free_irq(sdev->ipc_irq, sdev);
613         free_irq(hda->irq, bus);
614 #if IS_ENABLED(CONFIG_PCI)
615         if (sdev->msi_enabled) {
616                 struct pci_dev *pci = to_pci_dev(sdev->dev);
617                 pci_free_irq_vectors(pci);
618         }
619 #endif
620
621         hda_dsp_stream_free(sdev);
622 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
623         snd_hdac_link_free_all(bus);
624 #endif
625
626         iounmap(sdev->bar[HDA_DSP_BAR]);
627         iounmap(bus->remap_addr);
628
629 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
630         snd_hdac_ext_bus_exit(bus);
631 #endif
632         hda_codec_i915_exit(sdev);
633
634         return 0;
635 }
636
637 MODULE_LICENSE("Dual BSD/GPL");