]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - sound/soc/intel/skylake/skl.c
ASoC: Intel: Skylake: Unmap the address last
[mirror_ubuntu-hirsute-kernel.git] / sound / soc / intel / skylake / skl.c
CommitLineData
d8c2dab8
JK
1/*
2 * skl.c - Implementation of ASoC Intel SKL HD Audio driver
3 *
4 * Copyright (C) 2014-2015 Intel Corp
5 * Author: Jeeja KP <jeeja.kp@intel.com>
6 *
7 * Derived mostly from Intel HDA driver with following copyrights:
8 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
9 * PeiSen Hou <pshou@realtek.com.tw>
10 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; version 2 of the License.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22 */
23
24#include <linux/module.h>
25#include <linux/pci.h>
26#include <linux/pm_runtime.h>
27#include <linux/platform_device.h>
d8018361 28#include <linux/firmware.h>
d8c2dab8 29#include <sound/pcm.h>
cc18c5fd 30#include "../common/sst-acpi.h"
6980c057
VK
31#include <sound/hda_register.h>
32#include <sound/hdaudio.h>
33#include <sound/hda_i915.h>
d8c2dab8 34#include "skl.h"
0c8ba9d2
J
35#include "skl-sst-dsp.h"
36#include "skl-sst-ipc.h"
d8c2dab8
JK
37
38/*
39 * initialize the PCI registers
40 */
41static void skl_update_pci_byte(struct pci_dev *pci, unsigned int reg,
42 unsigned char mask, unsigned char val)
43{
44 unsigned char data;
45
46 pci_read_config_byte(pci, reg, &data);
47 data &= ~mask;
48 data |= (val & mask);
49 pci_write_config_byte(pci, reg, data);
50}
51
52static void skl_init_pci(struct skl *skl)
53{
54 struct hdac_ext_bus *ebus = &skl->ebus;
55
56 /*
57 * Clear bits 0-2 of PCI register TCSEL (at offset 0x44)
58 * TCSEL == Traffic Class Select Register, which sets PCI express QOS
59 * Ensuring these bits are 0 clears playback static on some HD Audio
60 * codecs.
61 * The PCI register TCSEL is defined in the Intel manuals.
62 */
63 dev_dbg(ebus_to_hbus(ebus)->dev, "Clearing TCSEL\n");
64 skl_update_pci_byte(skl->pci, AZX_PCIREG_TCSEL, 0x07, 0);
65}
66
0c8ba9d2
J
67static void update_pci_dword(struct pci_dev *pci,
68 unsigned int reg, u32 mask, u32 val)
69{
70 u32 data = 0;
71
72 pci_read_config_dword(pci, reg, &data);
73 data &= ~mask;
74 data |= (val & mask);
75 pci_write_config_dword(pci, reg, data);
76}
77
78/*
79 * skl_enable_miscbdcge - enable/dsiable CGCTL.MISCBDCGE bits
80 *
81 * @dev: device pointer
82 * @enable: enable/disable flag
83 */
84static void skl_enable_miscbdcge(struct device *dev, bool enable)
85{
86 struct pci_dev *pci = to_pci_dev(dev);
87 u32 val;
88
89 val = enable ? AZX_CGCTL_MISCBDCGE_MASK : 0;
90
91 update_pci_dword(pci, AZX_PCIREG_CGCTL, AZX_CGCTL_MISCBDCGE_MASK, val);
92}
93
94/*
95 * While performing reset, controller may not come back properly causing
96 * issues, so recommendation is to set CGCTL.MISCBDCGE to 0 then do reset
97 * (init chip) and then again set CGCTL.MISCBDCGE to 1
98 */
99static int skl_init_chip(struct hdac_bus *bus, bool full_reset)
100{
101 int ret;
102
103 skl_enable_miscbdcge(bus->dev, false);
104 ret = snd_hdac_bus_init_chip(bus, full_reset);
105 skl_enable_miscbdcge(bus->dev, true);
106
107 return ret;
108}
109
d8c2dab8
JK
110/* called from IRQ */
111static void skl_stream_update(struct hdac_bus *bus, struct hdac_stream *hstr)
112{
113 snd_pcm_period_elapsed(hstr->substream);
114}
115
116static irqreturn_t skl_interrupt(int irq, void *dev_id)
117{
118 struct hdac_ext_bus *ebus = dev_id;
119 struct hdac_bus *bus = ebus_to_hbus(ebus);
120 u32 status;
121
122 if (!pm_runtime_active(bus->dev))
123 return IRQ_NONE;
124
125 spin_lock(&bus->reg_lock);
126
127 status = snd_hdac_chip_readl(bus, INTSTS);
128 if (status == 0 || status == 0xffffffff) {
129 spin_unlock(&bus->reg_lock);
130 return IRQ_NONE;
131 }
132
133 /* clear rirb int */
134 status = snd_hdac_chip_readb(bus, RIRBSTS);
135 if (status & RIRB_INT_MASK) {
136 if (status & RIRB_INT_RESPONSE)
137 snd_hdac_bus_update_rirb(bus);
138 snd_hdac_chip_writeb(bus, RIRBSTS, RIRB_INT_MASK);
139 }
140
141 spin_unlock(&bus->reg_lock);
142
143 return snd_hdac_chip_readl(bus, INTSTS) ? IRQ_WAKE_THREAD : IRQ_HANDLED;
144}
145
146static irqreturn_t skl_threaded_handler(int irq, void *dev_id)
147{
148 struct hdac_ext_bus *ebus = dev_id;
149 struct hdac_bus *bus = ebus_to_hbus(ebus);
150 u32 status;
151
152 status = snd_hdac_chip_readl(bus, INTSTS);
153
154 snd_hdac_bus_handle_stream_irq(bus, status, skl_stream_update);
155
156 return IRQ_HANDLED;
157}
158
159static int skl_acquire_irq(struct hdac_ext_bus *ebus, int do_disconnect)
160{
161 struct skl *skl = ebus_to_skl(ebus);
162 struct hdac_bus *bus = ebus_to_hbus(ebus);
163 int ret;
164
165 ret = request_threaded_irq(skl->pci->irq, skl_interrupt,
166 skl_threaded_handler,
167 IRQF_SHARED,
168 KBUILD_MODNAME, ebus);
169 if (ret) {
170 dev_err(bus->dev,
171 "unable to grab IRQ %d, disabling device\n",
172 skl->pci->irq);
173 return ret;
174 }
175
176 bus->irq = skl->pci->irq;
177 pci_intx(skl->pci, 1);
178
179 return 0;
180}
181
61722f44
JK
182#ifdef CONFIG_PM
183static int _skl_suspend(struct hdac_ext_bus *ebus)
184{
185 struct skl *skl = ebus_to_skl(ebus);
186 struct hdac_bus *bus = ebus_to_hbus(ebus);
187 int ret;
188
189 snd_hdac_ext_bus_link_power_down_all(ebus);
190
191 ret = skl_suspend_dsp(skl);
192 if (ret < 0)
193 return ret;
194
195 snd_hdac_bus_stop_chip(bus);
0c8ba9d2 196 skl_enable_miscbdcge(bus->dev, false);
61722f44 197 snd_hdac_bus_enter_link_reset(bus);
0c8ba9d2 198 skl_enable_miscbdcge(bus->dev, true);
61722f44
JK
199
200 return 0;
201}
202
203static int _skl_resume(struct hdac_ext_bus *ebus)
204{
205 struct skl *skl = ebus_to_skl(ebus);
206 struct hdac_bus *bus = ebus_to_hbus(ebus);
207
208 skl_init_pci(skl);
0c8ba9d2 209 skl_init_chip(bus, true);
61722f44
JK
210
211 return skl_resume_dsp(skl);
212}
213#endif
214
d8c2dab8
JK
215#ifdef CONFIG_PM_SLEEP
216/*
217 * power management
218 */
219static int skl_suspend(struct device *dev)
220{
221 struct pci_dev *pci = to_pci_dev(dev);
222 struct hdac_ext_bus *ebus = pci_get_drvdata(pci);
4557c305 223 struct skl *skl = ebus_to_skl(ebus);
1f4956fd 224 struct hdac_bus *bus = ebus_to_hbus(ebus);
d8c2dab8 225
4557c305
JK
226 /*
227 * Do not suspend if streams which are marked ignore suspend are
228 * running, we need to save the state for these and continue
229 */
230 if (skl->supend_active) {
c2e20cd8 231 snd_hdac_ext_bus_link_power_down_all(ebus);
1f4956fd 232 enable_irq_wake(bus->irq);
4557c305
JK
233 pci_save_state(pci);
234 pci_disable_device(pci);
235 return 0;
236 } else {
237 return _skl_suspend(ebus);
238 }
d8c2dab8
JK
239}
240
241static int skl_resume(struct device *dev)
242{
243 struct pci_dev *pci = to_pci_dev(dev);
244 struct hdac_ext_bus *ebus = pci_get_drvdata(pci);
4557c305 245 struct skl *skl = ebus_to_skl(ebus);
1f4956fd 246 struct hdac_bus *bus = ebus_to_hbus(ebus);
4557c305
JK
247 int ret;
248
6980c057
VK
249 /* Turned OFF in HDMI codec driver after codec reconfiguration */
250 if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI)) {
251 ret = snd_hdac_display_power(bus, true);
252 if (ret < 0) {
253 dev_err(bus->dev,
254 "Cannot turn on display power on i915\n");
255 return ret;
256 }
257 }
258
4557c305
JK
259 /*
260 * resume only when we are not in suspend active, otherwise need to
261 * restore the device
262 */
263 if (skl->supend_active) {
264 pci_restore_state(pci);
265 ret = pci_enable_device(pci);
c2e20cd8 266 snd_hdac_ext_bus_link_power_up_all(ebus);
1f4956fd 267 disable_irq_wake(bus->irq);
4557c305
JK
268 } else {
269 ret = _skl_resume(ebus);
270 }
d8c2dab8 271
4557c305 272 return ret;
d8c2dab8
JK
273}
274#endif /* CONFIG_PM_SLEEP */
275
276#ifdef CONFIG_PM
277static int skl_runtime_suspend(struct device *dev)
278{
279 struct pci_dev *pci = to_pci_dev(dev);
280 struct hdac_ext_bus *ebus = pci_get_drvdata(pci);
281 struct hdac_bus *bus = ebus_to_hbus(ebus);
282
283 dev_dbg(bus->dev, "in %s\n", __func__);
284
61722f44 285 return _skl_suspend(ebus);
d8c2dab8
JK
286}
287
288static int skl_runtime_resume(struct device *dev)
289{
290 struct pci_dev *pci = to_pci_dev(dev);
291 struct hdac_ext_bus *ebus = pci_get_drvdata(pci);
292 struct hdac_bus *bus = ebus_to_hbus(ebus);
d8c2dab8
JK
293
294 dev_dbg(bus->dev, "in %s\n", __func__);
295
61722f44 296 return _skl_resume(ebus);
d8c2dab8
JK
297}
298#endif /* CONFIG_PM */
299
300static const struct dev_pm_ops skl_pm = {
301 SET_SYSTEM_SLEEP_PM_OPS(skl_suspend, skl_resume)
302 SET_RUNTIME_PM_OPS(skl_runtime_suspend, skl_runtime_resume, NULL)
303};
304
305/*
306 * destructor
307 */
308static int skl_free(struct hdac_ext_bus *ebus)
309{
310 struct skl *skl = ebus_to_skl(ebus);
311 struct hdac_bus *bus = ebus_to_hbus(ebus);
312
313 skl->init_failed = 1; /* to be sure */
314
315 snd_hdac_ext_stop_streams(ebus);
316
317 if (bus->irq >= 0)
318 free_irq(bus->irq, (void *)bus);
d8c2dab8
JK
319 snd_hdac_bus_free_stream_pages(bus);
320 snd_hdac_stream_free_all(ebus);
321 snd_hdac_link_free_all(ebus);
077411e5
VK
322
323 if (bus->remap_addr)
324 iounmap(bus->remap_addr);
325
d8c2dab8
JK
326 pci_release_regions(skl->pci);
327 pci_disable_device(skl->pci);
328
329 snd_hdac_ext_bus_exit(ebus);
330
331 return 0;
332}
333
cc18c5fd
VK
334static int skl_machine_device_register(struct skl *skl, void *driver_data)
335{
336 struct hdac_bus *bus = ebus_to_hbus(&skl->ebus);
337 struct platform_device *pdev;
338 struct sst_acpi_mach *mach = driver_data;
339 int ret;
340
341 mach = sst_acpi_find_machine(mach);
342 if (mach == NULL) {
343 dev_err(bus->dev, "No matching machine driver found\n");
344 return -ENODEV;
345 }
aecf6fd8 346 skl->fw_name = mach->fw_filename;
cc18c5fd
VK
347
348 pdev = platform_device_alloc(mach->drv_name, -1);
349 if (pdev == NULL) {
350 dev_err(bus->dev, "platform device alloc failed\n");
351 return -EIO;
352 }
353
354 ret = platform_device_add(pdev);
355 if (ret) {
356 dev_err(bus->dev, "failed to add machine device\n");
357 platform_device_put(pdev);
358 return -EIO;
359 }
360 skl->i2s_dev = pdev;
361
362 return 0;
363}
364
365static void skl_machine_device_unregister(struct skl *skl)
366{
367 if (skl->i2s_dev)
368 platform_device_unregister(skl->i2s_dev);
369}
370
d8c2dab8
JK
371static int skl_dmic_device_register(struct skl *skl)
372{
373 struct hdac_bus *bus = ebus_to_hbus(&skl->ebus);
374 struct platform_device *pdev;
375 int ret;
376
377 /* SKL has one dmic port, so allocate dmic device for this */
378 pdev = platform_device_alloc("dmic-codec", -1);
379 if (!pdev) {
380 dev_err(bus->dev, "failed to allocate dmic device\n");
381 return -ENOMEM;
382 }
383
384 ret = platform_device_add(pdev);
385 if (ret) {
386 dev_err(bus->dev, "failed to add dmic device: %d\n", ret);
387 platform_device_put(pdev);
388 return ret;
389 }
390 skl->dmic_dev = pdev;
391
392 return 0;
393}
394
395static void skl_dmic_device_unregister(struct skl *skl)
396{
397 if (skl->dmic_dev)
398 platform_device_unregister(skl->dmic_dev);
399}
400
401/*
402 * Probe the given codec address
403 */
404static int probe_codec(struct hdac_ext_bus *ebus, int addr)
405{
406 struct hdac_bus *bus = ebus_to_hbus(ebus);
407 unsigned int cmd = (addr << 28) | (AC_NODE_ROOT << 20) |
408 (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID;
409 unsigned int res;
410
411 mutex_lock(&bus->cmd_mutex);
412 snd_hdac_bus_send_cmd(bus, cmd);
413 snd_hdac_bus_get_response(bus, addr, &res);
414 mutex_unlock(&bus->cmd_mutex);
415 if (res == -1)
416 return -EIO;
417 dev_dbg(bus->dev, "codec #%d probed OK\n", addr);
418
419 return snd_hdac_ext_bus_device_init(ebus, addr);
420}
421
422/* Codec initialization */
423static int skl_codec_create(struct hdac_ext_bus *ebus)
424{
425 struct hdac_bus *bus = ebus_to_hbus(ebus);
426 int c, max_slots;
427
428 max_slots = HDA_MAX_CODECS;
429
430 /* First try to probe all given codec slots */
431 for (c = 0; c < max_slots; c++) {
432 if ((bus->codec_mask & (1 << c))) {
433 if (probe_codec(ebus, c) < 0) {
434 /*
435 * Some BIOSen give you wrong codec addresses
436 * that don't exist
437 */
438 dev_warn(bus->dev,
439 "Codec #%d probe error; disabling it...\n", c);
440 bus->codec_mask &= ~(1 << c);
441 /*
442 * More badly, accessing to a non-existing
443 * codec often screws up the controller bus,
444 * and disturbs the further communications.
445 * Thus if an error occurs during probing,
446 * better to reset the controller bus to get
447 * back to the sanity state.
448 */
449 snd_hdac_bus_stop_chip(bus);
0c8ba9d2 450 skl_init_chip(bus, true);
d8c2dab8
JK
451 }
452 }
453 }
454
455 return 0;
456}
457
458static const struct hdac_bus_ops bus_core_ops = {
459 .command = snd_hdac_bus_send_cmd,
460 .get_response = snd_hdac_bus_get_response,
461};
462
463/*
464 * constructor
465 */
466static int skl_create(struct pci_dev *pci,
467 const struct hdac_io_ops *io_ops,
468 struct skl **rskl)
469{
470 struct skl *skl;
471 struct hdac_ext_bus *ebus;
472
473 int err;
474
475 *rskl = NULL;
476
477 err = pci_enable_device(pci);
478 if (err < 0)
479 return err;
480
481 skl = devm_kzalloc(&pci->dev, sizeof(*skl), GFP_KERNEL);
482 if (!skl) {
483 pci_disable_device(pci);
484 return -ENOMEM;
485 }
486 ebus = &skl->ebus;
487 snd_hdac_ext_bus_init(ebus, &pci->dev, &bus_core_ops, io_ops);
488 ebus->bus.use_posbuf = 1;
489 skl->pci = pci;
490
491 ebus->bus.bdl_pos_adj = 0;
492
493 *rskl = skl;
494
495 return 0;
496}
497
6980c057
VK
498static int skl_i915_init(struct hdac_bus *bus)
499{
500 int err;
501
502 /*
503 * The HDMI codec is in GPU so we need to ensure that it is powered
504 * up and ready for probe
505 */
506 err = snd_hdac_i915_init(bus);
507 if (err < 0)
508 return err;
509
510 err = snd_hdac_display_power(bus, true);
511 if (err < 0) {
512 dev_err(bus->dev, "Cannot turn on display power on i915\n");
513 return err;
514 }
515
516 return err;
517}
518
d8c2dab8
JK
519static int skl_first_init(struct hdac_ext_bus *ebus)
520{
521 struct skl *skl = ebus_to_skl(ebus);
522 struct hdac_bus *bus = ebus_to_hbus(ebus);
523 struct pci_dev *pci = skl->pci;
524 int err;
525 unsigned short gcap;
526 int cp_streams, pb_streams, start_idx;
527
528 err = pci_request_regions(pci, "Skylake HD audio");
529 if (err < 0)
530 return err;
531
532 bus->addr = pci_resource_start(pci, 0);
533 bus->remap_addr = pci_ioremap_bar(pci, 0);
534 if (bus->remap_addr == NULL) {
535 dev_err(bus->dev, "ioremap error\n");
536 return -ENXIO;
537 }
538
05057001
JK
539 snd_hdac_ext_bus_parse_capabilities(ebus);
540
d8c2dab8
JK
541 if (skl_acquire_irq(ebus, 0) < 0)
542 return -EBUSY;
543
544 pci_set_master(pci);
545 synchronize_irq(bus->irq);
546
547 gcap = snd_hdac_chip_readw(bus, GCAP);
548 dev_dbg(bus->dev, "chipset global capabilities = 0x%x\n", gcap);
549
550 /* allow 64bit DMA address if supported by H/W */
551 if (!dma_set_mask(bus->dev, DMA_BIT_MASK(64))) {
552 dma_set_coherent_mask(bus->dev, DMA_BIT_MASK(64));
553 } else {
554 dma_set_mask(bus->dev, DMA_BIT_MASK(32));
555 dma_set_coherent_mask(bus->dev, DMA_BIT_MASK(32));
556 }
557
558 /* read number of streams from GCAP register */
559 cp_streams = (gcap >> 8) & 0x0f;
560 pb_streams = (gcap >> 12) & 0x0f;
561
562 if (!pb_streams && !cp_streams)
563 return -EIO;
564
565 ebus->num_streams = cp_streams + pb_streams;
566
567 /* initialize streams */
568 snd_hdac_ext_stream_init_all
569 (ebus, 0, cp_streams, SNDRV_PCM_STREAM_CAPTURE);
570 start_idx = cp_streams;
571 snd_hdac_ext_stream_init_all
572 (ebus, start_idx, pb_streams, SNDRV_PCM_STREAM_PLAYBACK);
573
574 err = snd_hdac_bus_alloc_stream_pages(bus);
575 if (err < 0)
576 return err;
577
578 /* initialize chip */
579 skl_init_pci(skl);
580
6980c057
VK
581 if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI)) {
582 err = skl_i915_init(bus);
583 if (err < 0)
584 return err;
585 }
586
0c8ba9d2 587 skl_init_chip(bus, true);
d8c2dab8
JK
588
589 /* codec detection */
590 if (!bus->codec_mask) {
029890c6 591 dev_info(bus->dev, "no hda codecs found!\n");
d8c2dab8
JK
592 }
593
594 return 0;
595}
596
597static int skl_probe(struct pci_dev *pci,
598 const struct pci_device_id *pci_id)
599{
600 struct skl *skl;
601 struct hdac_ext_bus *ebus = NULL;
602 struct hdac_bus *bus = NULL;
603 int err;
604
605 /* we use ext core ops, so provide NULL for ops here */
606 err = skl_create(pci, NULL, &skl);
607 if (err < 0)
608 return err;
609
610 ebus = &skl->ebus;
611 bus = ebus_to_hbus(ebus);
612
613 err = skl_first_init(ebus);
614 if (err < 0)
615 goto out_free;
616
4b235c43
VK
617 skl->pci_id = pci->device;
618
87b2bdf0
JK
619 skl->nhlt = skl_nhlt_init(bus->dev);
620
621 if (skl->nhlt == NULL)
622 goto out_free;
623
4b235c43
VK
624 skl_nhlt_update_topology_bin(skl);
625
d8c2dab8
JK
626 pci_set_drvdata(skl->pci, ebus);
627
05057001
JK
628 /* check if dsp is there */
629 if (ebus->ppcap) {
cc18c5fd
VK
630 err = skl_machine_device_register(skl,
631 (void *)pci_id->driver_data);
632 if (err < 0)
633 goto out_free;
634
2a29b200
JK
635 err = skl_init_dsp(skl);
636 if (err < 0) {
637 dev_dbg(bus->dev, "error failed to register dsp\n");
cc18c5fd 638 goto out_mach_free;
2a29b200 639 }
0c8ba9d2
J
640 skl->skl_sst->enable_miscbdcge = skl_enable_miscbdcge;
641
05057001 642 }
05057001
JK
643 if (ebus->mlcap)
644 snd_hdac_ext_bus_get_ml_capabilities(ebus);
645
d8c2dab8
JK
646 /* create device for soc dmic */
647 err = skl_dmic_device_register(skl);
648 if (err < 0)
2a29b200 649 goto out_dsp_free;
d8c2dab8
JK
650
651 /* register platform dai and controls */
652 err = skl_platform_register(bus->dev);
653 if (err < 0)
654 goto out_dmic_free;
655
656 /* create codec instances */
657 err = skl_codec_create(ebus);
658 if (err < 0)
659 goto out_unregister;
660
6980c057
VK
661 if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI)) {
662 err = snd_hdac_display_power(bus, false);
663 if (err < 0) {
664 dev_err(bus->dev, "Cannot turn off display power on i915\n");
665 return err;
666 }
667 }
668
d8c2dab8 669 /*configure PM */
d8c2dab8
JK
670 pm_runtime_put_noidle(bus->dev);
671 pm_runtime_allow(bus->dev);
672
673 return 0;
674
675out_unregister:
676 skl_platform_unregister(bus->dev);
677out_dmic_free:
678 skl_dmic_device_unregister(skl);
2a29b200
JK
679out_dsp_free:
680 skl_free_dsp(skl);
cc18c5fd
VK
681out_mach_free:
682 skl_machine_device_unregister(skl);
d8c2dab8
JK
683out_free:
684 skl->init_failed = 1;
685 skl_free(ebus);
686
687 return err;
688}
689
c5a76a24
JK
690static void skl_shutdown(struct pci_dev *pci)
691{
692 struct hdac_ext_bus *ebus = pci_get_drvdata(pci);
693 struct hdac_bus *bus = ebus_to_hbus(ebus);
694 struct hdac_stream *s;
695 struct hdac_ext_stream *stream;
696 struct skl *skl;
697
698 if (ebus == NULL)
699 return;
700
701 skl = ebus_to_skl(ebus);
702
703 if (skl->init_failed)
704 return;
705
706 snd_hdac_ext_stop_streams(ebus);
707 list_for_each_entry(s, &bus->stream_list, list) {
708 stream = stream_to_hdac_ext_stream(s);
709 snd_hdac_ext_stream_decouple(ebus, stream, false);
710 }
711
712 snd_hdac_bus_stop_chip(bus);
713}
714
d8c2dab8
JK
715static void skl_remove(struct pci_dev *pci)
716{
717 struct hdac_ext_bus *ebus = pci_get_drvdata(pci);
718 struct skl *skl = ebus_to_skl(ebus);
719
d8018361
VK
720 if (skl->tplg)
721 release_firmware(skl->tplg);
722
6980c057
VK
723 if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI))
724 snd_hdac_i915_exit(&ebus->bus);
725
d8c2dab8
JK
726 if (pci_dev_run_wake(pci))
727 pm_runtime_get_noresume(&pci->dev);
728 pci_dev_put(pci);
7373f481
VK
729
730 /* codec removal, invoke bus_device_remove */
731 snd_hdac_ext_bus_device_remove(ebus);
732
d8c2dab8 733 skl_platform_unregister(&pci->dev);
2a29b200 734 skl_free_dsp(skl);
cc18c5fd 735 skl_machine_device_unregister(skl);
d8c2dab8
JK
736 skl_dmic_device_unregister(skl);
737 skl_free(ebus);
738 dev_set_drvdata(&pci->dev, NULL);
739}
740
cc18c5fd
VK
741static struct sst_acpi_mach sst_skl_devdata[] = {
742 { "INT343A", "skl_alc286s_i2s", "intel/dsp_fw_release.bin", NULL, NULL, NULL },
02cc2355
FY
743 { "INT343B", "skl_nau88l25_ssm4567_i2s", "intel/dsp_fw_release.bin",
744 NULL, NULL, NULL },
69b7f9c4
RA
745 { "MX98357A", "skl_nau88l25_max98357a_i2s", "intel/dsp_fw_release.bin",
746 NULL, NULL, NULL },
cc18c5fd
VK
747 {}
748};
749
b379b1fa
SV
750static struct sst_acpi_mach sst_bxtp_devdata[] = {
751 { "INT343A", "bxt_alc298s_i2s", "intel/dsp_fw_bxtn.bin", NULL, NULL, NULL },
752};
753
d8c2dab8
JK
754/* PCI IDs */
755static const struct pci_device_id skl_ids[] = {
756 /* Sunrise Point-LP */
cc18c5fd
VK
757 { PCI_DEVICE(0x8086, 0x9d70),
758 .driver_data = (unsigned long)&sst_skl_devdata},
b379b1fa
SV
759 /* BXT-P */
760 { PCI_DEVICE(0x8086, 0x5a98),
761 .driver_data = (unsigned long)&sst_bxtp_devdata},
d8c2dab8
JK
762 { 0, }
763};
764MODULE_DEVICE_TABLE(pci, skl_ids);
765
766/* pci_driver definition */
767static struct pci_driver skl_driver = {
768 .name = KBUILD_MODNAME,
769 .id_table = skl_ids,
770 .probe = skl_probe,
771 .remove = skl_remove,
c5a76a24 772 .shutdown = skl_shutdown,
d8c2dab8
JK
773 .driver = {
774 .pm = &skl_pm,
775 },
776};
777module_pci_driver(skl_driver);
778
779MODULE_LICENSE("GPL v2");
780MODULE_DESCRIPTION("Intel Skylake ASoC HDA driver");