blob: dd38f5feb7c03e8c7ead8543ed868c6da0b6ae72 [file] [log] [blame]
Jeeja KPd8c2dab2015-07-09 15:20:09 +05301/*
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>
Vinod Kould8018362016-01-05 17:16:04 +053028#include <linux/firmware.h>
Jeeja KPd8c2dab2015-07-09 15:20:09 +053029#include <sound/pcm.h>
Vinod Koulcc18c5f2015-11-05 21:34:13 +053030#include "../common/sst-acpi.h"
Jeeja KPd8c2dab2015-07-09 15:20:09 +053031#include "skl.h"
Jayachandran B0c8ba9d2015-12-18 15:12:03 +053032#include "skl-sst-dsp.h"
33#include "skl-sst-ipc.h"
Jeeja KPd8c2dab2015-07-09 15:20:09 +053034
35/*
36 * initialize the PCI registers
37 */
38static void skl_update_pci_byte(struct pci_dev *pci, unsigned int reg,
39 unsigned char mask, unsigned char val)
40{
41 unsigned char data;
42
43 pci_read_config_byte(pci, reg, &data);
44 data &= ~mask;
45 data |= (val & mask);
46 pci_write_config_byte(pci, reg, data);
47}
48
49static void skl_init_pci(struct skl *skl)
50{
51 struct hdac_ext_bus *ebus = &skl->ebus;
52
53 /*
54 * Clear bits 0-2 of PCI register TCSEL (at offset 0x44)
55 * TCSEL == Traffic Class Select Register, which sets PCI express QOS
56 * Ensuring these bits are 0 clears playback static on some HD Audio
57 * codecs.
58 * The PCI register TCSEL is defined in the Intel manuals.
59 */
60 dev_dbg(ebus_to_hbus(ebus)->dev, "Clearing TCSEL\n");
61 skl_update_pci_byte(skl->pci, AZX_PCIREG_TCSEL, 0x07, 0);
62}
63
Jayachandran B0c8ba9d2015-12-18 15:12:03 +053064static void update_pci_dword(struct pci_dev *pci,
65 unsigned int reg, u32 mask, u32 val)
66{
67 u32 data = 0;
68
69 pci_read_config_dword(pci, reg, &data);
70 data &= ~mask;
71 data |= (val & mask);
72 pci_write_config_dword(pci, reg, data);
73}
74
75/*
76 * skl_enable_miscbdcge - enable/dsiable CGCTL.MISCBDCGE bits
77 *
78 * @dev: device pointer
79 * @enable: enable/disable flag
80 */
81static void skl_enable_miscbdcge(struct device *dev, bool enable)
82{
83 struct pci_dev *pci = to_pci_dev(dev);
84 u32 val;
85
86 val = enable ? AZX_CGCTL_MISCBDCGE_MASK : 0;
87
88 update_pci_dword(pci, AZX_PCIREG_CGCTL, AZX_CGCTL_MISCBDCGE_MASK, val);
89}
90
91/*
92 * While performing reset, controller may not come back properly causing
93 * issues, so recommendation is to set CGCTL.MISCBDCGE to 0 then do reset
94 * (init chip) and then again set CGCTL.MISCBDCGE to 1
95 */
96static int skl_init_chip(struct hdac_bus *bus, bool full_reset)
97{
98 int ret;
99
100 skl_enable_miscbdcge(bus->dev, false);
101 ret = snd_hdac_bus_init_chip(bus, full_reset);
102 skl_enable_miscbdcge(bus->dev, true);
103
104 return ret;
105}
106
Jeeja KPd8c2dab2015-07-09 15:20:09 +0530107/* called from IRQ */
108static void skl_stream_update(struct hdac_bus *bus, struct hdac_stream *hstr)
109{
110 snd_pcm_period_elapsed(hstr->substream);
111}
112
113static irqreturn_t skl_interrupt(int irq, void *dev_id)
114{
115 struct hdac_ext_bus *ebus = dev_id;
116 struct hdac_bus *bus = ebus_to_hbus(ebus);
117 u32 status;
118
119 if (!pm_runtime_active(bus->dev))
120 return IRQ_NONE;
121
122 spin_lock(&bus->reg_lock);
123
124 status = snd_hdac_chip_readl(bus, INTSTS);
125 if (status == 0 || status == 0xffffffff) {
126 spin_unlock(&bus->reg_lock);
127 return IRQ_NONE;
128 }
129
130 /* clear rirb int */
131 status = snd_hdac_chip_readb(bus, RIRBSTS);
132 if (status & RIRB_INT_MASK) {
133 if (status & RIRB_INT_RESPONSE)
134 snd_hdac_bus_update_rirb(bus);
135 snd_hdac_chip_writeb(bus, RIRBSTS, RIRB_INT_MASK);
136 }
137
138 spin_unlock(&bus->reg_lock);
139
140 return snd_hdac_chip_readl(bus, INTSTS) ? IRQ_WAKE_THREAD : IRQ_HANDLED;
141}
142
143static irqreturn_t skl_threaded_handler(int irq, void *dev_id)
144{
145 struct hdac_ext_bus *ebus = dev_id;
146 struct hdac_bus *bus = ebus_to_hbus(ebus);
147 u32 status;
148
149 status = snd_hdac_chip_readl(bus, INTSTS);
150
151 snd_hdac_bus_handle_stream_irq(bus, status, skl_stream_update);
152
153 return IRQ_HANDLED;
154}
155
156static int skl_acquire_irq(struct hdac_ext_bus *ebus, int do_disconnect)
157{
158 struct skl *skl = ebus_to_skl(ebus);
159 struct hdac_bus *bus = ebus_to_hbus(ebus);
160 int ret;
161
162 ret = request_threaded_irq(skl->pci->irq, skl_interrupt,
163 skl_threaded_handler,
164 IRQF_SHARED,
165 KBUILD_MODNAME, ebus);
166 if (ret) {
167 dev_err(bus->dev,
168 "unable to grab IRQ %d, disabling device\n",
169 skl->pci->irq);
170 return ret;
171 }
172
173 bus->irq = skl->pci->irq;
174 pci_intx(skl->pci, 1);
175
176 return 0;
177}
178
Jeeja KPd8c2dab2015-07-09 15:20:09 +0530179#ifdef CONFIG_PM
Jeeja KP61722f42015-10-27 09:23:00 +0900180static int _skl_suspend(struct hdac_ext_bus *ebus)
Jeeja KPd8c2dab2015-07-09 15:20:09 +0530181{
Jeeja KP2a29b202015-10-07 11:31:58 +0100182 struct skl *skl = ebus_to_skl(ebus);
Jeeja KP61722f42015-10-27 09:23:00 +0900183 struct hdac_bus *bus = ebus_to_hbus(ebus);
Jeeja KP2a29b202015-10-07 11:31:58 +0100184 int ret;
Jeeja KPd8c2dab2015-07-09 15:20:09 +0530185
Jeeja KP01bb84b2015-10-09 09:01:51 +0100186 snd_hdac_ext_bus_link_power_down_all(ebus);
187
Jeeja KP2a29b202015-10-07 11:31:58 +0100188 ret = skl_suspend_dsp(skl);
189 if (ret < 0)
190 return ret;
Jeeja KPd8c2dab2015-07-09 15:20:09 +0530191
192 snd_hdac_bus_stop_chip(bus);
Jayachandran B0c8ba9d2015-12-18 15:12:03 +0530193 skl_enable_miscbdcge(bus->dev, false);
Jeeja KPd8c2dab2015-07-09 15:20:09 +0530194 snd_hdac_bus_enter_link_reset(bus);
Jayachandran B0c8ba9d2015-12-18 15:12:03 +0530195 skl_enable_miscbdcge(bus->dev, true);
Jeeja KPd8c2dab2015-07-09 15:20:09 +0530196
197 return 0;
198}
199
Jeeja KP61722f42015-10-27 09:23:00 +0900200static int _skl_resume(struct hdac_ext_bus *ebus)
201{
202 struct skl *skl = ebus_to_skl(ebus);
203 struct hdac_bus *bus = ebus_to_hbus(ebus);
204
205 skl_init_pci(skl);
Jayachandran B0c8ba9d2015-12-18 15:12:03 +0530206 skl_init_chip(bus, true);
Jeeja KP61722f42015-10-27 09:23:00 +0900207
208 return skl_resume_dsp(skl);
209}
210#endif
211
212#ifdef CONFIG_PM_SLEEP
213/*
214 * power management
215 */
216static int skl_suspend(struct device *dev)
217{
218 struct pci_dev *pci = to_pci_dev(dev);
219 struct hdac_ext_bus *ebus = pci_get_drvdata(pci);
Jeeja KP4557c302015-12-03 23:30:00 +0530220 struct skl *skl = ebus_to_skl(ebus);
Jeeja KP61722f42015-10-27 09:23:00 +0900221
Jeeja KP4557c302015-12-03 23:30:00 +0530222 /*
223 * Do not suspend if streams which are marked ignore suspend are
224 * running, we need to save the state for these and continue
225 */
226 if (skl->supend_active) {
227 pci_save_state(pci);
228 pci_disable_device(pci);
229 return 0;
230 } else {
231 return _skl_suspend(ebus);
232 }
Jeeja KP61722f42015-10-27 09:23:00 +0900233}
234
235static int skl_resume(struct device *dev)
236{
237 struct pci_dev *pci = to_pci_dev(dev);
238 struct hdac_ext_bus *ebus = pci_get_drvdata(pci);
Jeeja KP4557c302015-12-03 23:30:00 +0530239 struct skl *skl = ebus_to_skl(ebus);
240 int ret;
Jeeja KP61722f42015-10-27 09:23:00 +0900241
Jeeja KP4557c302015-12-03 23:30:00 +0530242 /*
243 * resume only when we are not in suspend active, otherwise need to
244 * restore the device
245 */
246 if (skl->supend_active) {
247 pci_restore_state(pci);
248 ret = pci_enable_device(pci);
249 } else {
250 ret = _skl_resume(ebus);
251 }
252
253 return ret;
Jeeja KP61722f42015-10-27 09:23:00 +0900254}
255#endif /* CONFIG_PM_SLEEP */
256
257#ifdef CONFIG_PM
258static int skl_runtime_suspend(struct device *dev)
259{
260 struct pci_dev *pci = to_pci_dev(dev);
261 struct hdac_ext_bus *ebus = pci_get_drvdata(pci);
262 struct hdac_bus *bus = ebus_to_hbus(ebus);
263
264 dev_dbg(bus->dev, "in %s\n", __func__);
265
Jeeja KP61722f42015-10-27 09:23:00 +0900266 return _skl_suspend(ebus);
267}
268
Jeeja KPd8c2dab2015-07-09 15:20:09 +0530269static int skl_runtime_resume(struct device *dev)
270{
271 struct pci_dev *pci = to_pci_dev(dev);
272 struct hdac_ext_bus *ebus = pci_get_drvdata(pci);
273 struct hdac_bus *bus = ebus_to_hbus(ebus);
Jeeja KPd8c2dab2015-07-09 15:20:09 +0530274
275 dev_dbg(bus->dev, "in %s\n", __func__);
276
Jeeja KP61722f42015-10-27 09:23:00 +0900277 return _skl_resume(ebus);
Jeeja KPd8c2dab2015-07-09 15:20:09 +0530278}
279#endif /* CONFIG_PM */
280
281static const struct dev_pm_ops skl_pm = {
282 SET_SYSTEM_SLEEP_PM_OPS(skl_suspend, skl_resume)
283 SET_RUNTIME_PM_OPS(skl_runtime_suspend, skl_runtime_resume, NULL)
284};
285
286/*
287 * destructor
288 */
289static int skl_free(struct hdac_ext_bus *ebus)
290{
291 struct skl *skl = ebus_to_skl(ebus);
292 struct hdac_bus *bus = ebus_to_hbus(ebus);
293
294 skl->init_failed = 1; /* to be sure */
295
296 snd_hdac_ext_stop_streams(ebus);
297
298 if (bus->irq >= 0)
299 free_irq(bus->irq, (void *)bus);
300 if (bus->remap_addr)
301 iounmap(bus->remap_addr);
302
303 snd_hdac_bus_free_stream_pages(bus);
304 snd_hdac_stream_free_all(ebus);
305 snd_hdac_link_free_all(ebus);
306 pci_release_regions(skl->pci);
307 pci_disable_device(skl->pci);
308
309 snd_hdac_ext_bus_exit(ebus);
310
311 return 0;
312}
313
Vinod Koulcc18c5f2015-11-05 21:34:13 +0530314static int skl_machine_device_register(struct skl *skl, void *driver_data)
315{
316 struct hdac_bus *bus = ebus_to_hbus(&skl->ebus);
317 struct platform_device *pdev;
318 struct sst_acpi_mach *mach = driver_data;
319 int ret;
320
321 mach = sst_acpi_find_machine(mach);
322 if (mach == NULL) {
323 dev_err(bus->dev, "No matching machine driver found\n");
324 return -ENODEV;
325 }
Vinod Koulaecf6fd2015-11-05 21:34:15 +0530326 skl->fw_name = mach->fw_filename;
Vinod Koulcc18c5f2015-11-05 21:34:13 +0530327
328 pdev = platform_device_alloc(mach->drv_name, -1);
329 if (pdev == NULL) {
330 dev_err(bus->dev, "platform device alloc failed\n");
331 return -EIO;
332 }
333
334 ret = platform_device_add(pdev);
335 if (ret) {
336 dev_err(bus->dev, "failed to add machine device\n");
337 platform_device_put(pdev);
338 return -EIO;
339 }
340 skl->i2s_dev = pdev;
341
342 return 0;
343}
344
345static void skl_machine_device_unregister(struct skl *skl)
346{
347 if (skl->i2s_dev)
348 platform_device_unregister(skl->i2s_dev);
349}
350
Jeeja KPd8c2dab2015-07-09 15:20:09 +0530351static int skl_dmic_device_register(struct skl *skl)
352{
353 struct hdac_bus *bus = ebus_to_hbus(&skl->ebus);
354 struct platform_device *pdev;
355 int ret;
356
357 /* SKL has one dmic port, so allocate dmic device for this */
358 pdev = platform_device_alloc("dmic-codec", -1);
359 if (!pdev) {
360 dev_err(bus->dev, "failed to allocate dmic device\n");
361 return -ENOMEM;
362 }
363
364 ret = platform_device_add(pdev);
365 if (ret) {
366 dev_err(bus->dev, "failed to add dmic device: %d\n", ret);
367 platform_device_put(pdev);
368 return ret;
369 }
370 skl->dmic_dev = pdev;
371
372 return 0;
373}
374
375static void skl_dmic_device_unregister(struct skl *skl)
376{
377 if (skl->dmic_dev)
378 platform_device_unregister(skl->dmic_dev);
379}
380
381/*
382 * Probe the given codec address
383 */
384static int probe_codec(struct hdac_ext_bus *ebus, int addr)
385{
386 struct hdac_bus *bus = ebus_to_hbus(ebus);
387 unsigned int cmd = (addr << 28) | (AC_NODE_ROOT << 20) |
388 (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID;
389 unsigned int res;
390
391 mutex_lock(&bus->cmd_mutex);
392 snd_hdac_bus_send_cmd(bus, cmd);
393 snd_hdac_bus_get_response(bus, addr, &res);
394 mutex_unlock(&bus->cmd_mutex);
395 if (res == -1)
396 return -EIO;
397 dev_dbg(bus->dev, "codec #%d probed OK\n", addr);
398
399 return snd_hdac_ext_bus_device_init(ebus, addr);
400}
401
402/* Codec initialization */
403static int skl_codec_create(struct hdac_ext_bus *ebus)
404{
405 struct hdac_bus *bus = ebus_to_hbus(ebus);
406 int c, max_slots;
407
408 max_slots = HDA_MAX_CODECS;
409
410 /* First try to probe all given codec slots */
411 for (c = 0; c < max_slots; c++) {
412 if ((bus->codec_mask & (1 << c))) {
413 if (probe_codec(ebus, c) < 0) {
414 /*
415 * Some BIOSen give you wrong codec addresses
416 * that don't exist
417 */
418 dev_warn(bus->dev,
419 "Codec #%d probe error; disabling it...\n", c);
420 bus->codec_mask &= ~(1 << c);
421 /*
422 * More badly, accessing to a non-existing
423 * codec often screws up the controller bus,
424 * and disturbs the further communications.
425 * Thus if an error occurs during probing,
426 * better to reset the controller bus to get
427 * back to the sanity state.
428 */
429 snd_hdac_bus_stop_chip(bus);
Jayachandran B0c8ba9d2015-12-18 15:12:03 +0530430 skl_init_chip(bus, true);
Jeeja KPd8c2dab2015-07-09 15:20:09 +0530431 }
432 }
433 }
434
435 return 0;
436}
437
438static const struct hdac_bus_ops bus_core_ops = {
439 .command = snd_hdac_bus_send_cmd,
440 .get_response = snd_hdac_bus_get_response,
441};
442
443/*
444 * constructor
445 */
446static int skl_create(struct pci_dev *pci,
447 const struct hdac_io_ops *io_ops,
448 struct skl **rskl)
449{
450 struct skl *skl;
451 struct hdac_ext_bus *ebus;
452
453 int err;
454
455 *rskl = NULL;
456
457 err = pci_enable_device(pci);
458 if (err < 0)
459 return err;
460
461 skl = devm_kzalloc(&pci->dev, sizeof(*skl), GFP_KERNEL);
462 if (!skl) {
463 pci_disable_device(pci);
464 return -ENOMEM;
465 }
466 ebus = &skl->ebus;
467 snd_hdac_ext_bus_init(ebus, &pci->dev, &bus_core_ops, io_ops);
468 ebus->bus.use_posbuf = 1;
469 skl->pci = pci;
470
471 ebus->bus.bdl_pos_adj = 0;
472
473 *rskl = skl;
474
475 return 0;
476}
477
478static int skl_first_init(struct hdac_ext_bus *ebus)
479{
480 struct skl *skl = ebus_to_skl(ebus);
481 struct hdac_bus *bus = ebus_to_hbus(ebus);
482 struct pci_dev *pci = skl->pci;
483 int err;
484 unsigned short gcap;
485 int cp_streams, pb_streams, start_idx;
486
487 err = pci_request_regions(pci, "Skylake HD audio");
488 if (err < 0)
489 return err;
490
491 bus->addr = pci_resource_start(pci, 0);
492 bus->remap_addr = pci_ioremap_bar(pci, 0);
493 if (bus->remap_addr == NULL) {
494 dev_err(bus->dev, "ioremap error\n");
495 return -ENXIO;
496 }
497
Jeeja KP05057002015-07-09 15:20:11 +0530498 snd_hdac_ext_bus_parse_capabilities(ebus);
499
Jeeja KPd8c2dab2015-07-09 15:20:09 +0530500 if (skl_acquire_irq(ebus, 0) < 0)
501 return -EBUSY;
502
503 pci_set_master(pci);
504 synchronize_irq(bus->irq);
505
506 gcap = snd_hdac_chip_readw(bus, GCAP);
507 dev_dbg(bus->dev, "chipset global capabilities = 0x%x\n", gcap);
508
509 /* allow 64bit DMA address if supported by H/W */
510 if (!dma_set_mask(bus->dev, DMA_BIT_MASK(64))) {
511 dma_set_coherent_mask(bus->dev, DMA_BIT_MASK(64));
512 } else {
513 dma_set_mask(bus->dev, DMA_BIT_MASK(32));
514 dma_set_coherent_mask(bus->dev, DMA_BIT_MASK(32));
515 }
516
517 /* read number of streams from GCAP register */
518 cp_streams = (gcap >> 8) & 0x0f;
519 pb_streams = (gcap >> 12) & 0x0f;
520
521 if (!pb_streams && !cp_streams)
522 return -EIO;
523
524 ebus->num_streams = cp_streams + pb_streams;
525
526 /* initialize streams */
527 snd_hdac_ext_stream_init_all
528 (ebus, 0, cp_streams, SNDRV_PCM_STREAM_CAPTURE);
529 start_idx = cp_streams;
530 snd_hdac_ext_stream_init_all
531 (ebus, start_idx, pb_streams, SNDRV_PCM_STREAM_PLAYBACK);
532
533 err = snd_hdac_bus_alloc_stream_pages(bus);
534 if (err < 0)
535 return err;
536
537 /* initialize chip */
538 skl_init_pci(skl);
539
Jayachandran B0c8ba9d2015-12-18 15:12:03 +0530540 skl_init_chip(bus, true);
Jeeja KPd8c2dab2015-07-09 15:20:09 +0530541
542 /* codec detection */
543 if (!bus->codec_mask) {
Jeeja KP029890c2015-10-27 09:22:47 +0900544 dev_info(bus->dev, "no hda codecs found!\n");
Jeeja KPd8c2dab2015-07-09 15:20:09 +0530545 }
546
547 return 0;
548}
549
550static int skl_probe(struct pci_dev *pci,
551 const struct pci_device_id *pci_id)
552{
553 struct skl *skl;
554 struct hdac_ext_bus *ebus = NULL;
555 struct hdac_bus *bus = NULL;
556 int err;
557
558 /* we use ext core ops, so provide NULL for ops here */
559 err = skl_create(pci, NULL, &skl);
560 if (err < 0)
561 return err;
562
563 ebus = &skl->ebus;
564 bus = ebus_to_hbus(ebus);
565
566 err = skl_first_init(ebus);
567 if (err < 0)
568 goto out_free;
569
Jeeja KP87b2bdf2015-10-07 11:31:59 +0100570 skl->nhlt = skl_nhlt_init(bus->dev);
571
572 if (skl->nhlt == NULL)
573 goto out_free;
574
Jeeja KPd8c2dab2015-07-09 15:20:09 +0530575 pci_set_drvdata(skl->pci, ebus);
576
Jeeja KP05057002015-07-09 15:20:11 +0530577 /* check if dsp is there */
578 if (ebus->ppcap) {
Vinod Koulcc18c5f2015-11-05 21:34:13 +0530579 err = skl_machine_device_register(skl,
580 (void *)pci_id->driver_data);
581 if (err < 0)
582 goto out_free;
583
Jeeja KP2a29b202015-10-07 11:31:58 +0100584 err = skl_init_dsp(skl);
585 if (err < 0) {
586 dev_dbg(bus->dev, "error failed to register dsp\n");
Vinod Koulcc18c5f2015-11-05 21:34:13 +0530587 goto out_mach_free;
Jeeja KP2a29b202015-10-07 11:31:58 +0100588 }
Jayachandran B0c8ba9d2015-12-18 15:12:03 +0530589 skl->skl_sst->enable_miscbdcge = skl_enable_miscbdcge;
590
Jeeja KP05057002015-07-09 15:20:11 +0530591 }
Jeeja KP05057002015-07-09 15:20:11 +0530592 if (ebus->mlcap)
593 snd_hdac_ext_bus_get_ml_capabilities(ebus);
594
Jeeja KPd8c2dab2015-07-09 15:20:09 +0530595 /* create device for soc dmic */
596 err = skl_dmic_device_register(skl);
597 if (err < 0)
Jeeja KP2a29b202015-10-07 11:31:58 +0100598 goto out_dsp_free;
Jeeja KPd8c2dab2015-07-09 15:20:09 +0530599
600 /* register platform dai and controls */
601 err = skl_platform_register(bus->dev);
602 if (err < 0)
603 goto out_dmic_free;
604
605 /* create codec instances */
606 err = skl_codec_create(ebus);
607 if (err < 0)
608 goto out_unregister;
609
610 /*configure PM */
611 pm_runtime_set_autosuspend_delay(bus->dev, SKL_SUSPEND_DELAY);
612 pm_runtime_use_autosuspend(bus->dev);
613 pm_runtime_put_noidle(bus->dev);
614 pm_runtime_allow(bus->dev);
615
616 return 0;
617
618out_unregister:
619 skl_platform_unregister(bus->dev);
620out_dmic_free:
621 skl_dmic_device_unregister(skl);
Jeeja KP2a29b202015-10-07 11:31:58 +0100622out_dsp_free:
623 skl_free_dsp(skl);
Vinod Koulcc18c5f2015-11-05 21:34:13 +0530624out_mach_free:
625 skl_machine_device_unregister(skl);
Jeeja KPd8c2dab2015-07-09 15:20:09 +0530626out_free:
627 skl->init_failed = 1;
628 skl_free(ebus);
629
630 return err;
631}
632
633static void skl_remove(struct pci_dev *pci)
634{
635 struct hdac_ext_bus *ebus = pci_get_drvdata(pci);
636 struct skl *skl = ebus_to_skl(ebus);
637
Vinod Kould8018362016-01-05 17:16:04 +0530638 if (skl->tplg)
639 release_firmware(skl->tplg);
640
Jeeja KPd8c2dab2015-07-09 15:20:09 +0530641 if (pci_dev_run_wake(pci))
642 pm_runtime_get_noresume(&pci->dev);
643 pci_dev_put(pci);
644 skl_platform_unregister(&pci->dev);
Jeeja KP2a29b202015-10-07 11:31:58 +0100645 skl_free_dsp(skl);
Vinod Koulcc18c5f2015-11-05 21:34:13 +0530646 skl_machine_device_unregister(skl);
Jeeja KPd8c2dab2015-07-09 15:20:09 +0530647 skl_dmic_device_unregister(skl);
648 skl_free(ebus);
649 dev_set_drvdata(&pci->dev, NULL);
650}
651
Vinod Koulcc18c5f2015-11-05 21:34:13 +0530652static struct sst_acpi_mach sst_skl_devdata[] = {
653 { "INT343A", "skl_alc286s_i2s", "intel/dsp_fw_release.bin", NULL, NULL, NULL },
Fang, Yang A02cc2352015-11-05 22:53:08 +0530654 { "INT343B", "skl_nau88l25_ssm4567_i2s", "intel/dsp_fw_release.bin",
655 NULL, NULL, NULL },
Rohit Ainapure69b7f9c2015-12-11 11:29:07 -0800656 { "MX98357A", "skl_nau88l25_max98357a_i2s", "intel/dsp_fw_release.bin",
657 NULL, NULL, NULL },
Vinod Koulcc18c5f2015-11-05 21:34:13 +0530658 {}
659};
660
Jeeja KPd8c2dab2015-07-09 15:20:09 +0530661/* PCI IDs */
662static const struct pci_device_id skl_ids[] = {
663 /* Sunrise Point-LP */
Vinod Koulcc18c5f2015-11-05 21:34:13 +0530664 { PCI_DEVICE(0x8086, 0x9d70),
665 .driver_data = (unsigned long)&sst_skl_devdata},
Jeeja KPd8c2dab2015-07-09 15:20:09 +0530666 { 0, }
667};
668MODULE_DEVICE_TABLE(pci, skl_ids);
669
670/* pci_driver definition */
671static struct pci_driver skl_driver = {
672 .name = KBUILD_MODNAME,
673 .id_table = skl_ids,
674 .probe = skl_probe,
675 .remove = skl_remove,
676 .driver = {
677 .pm = &skl_pm,
678 },
679};
680module_pci_driver(skl_driver);
681
682MODULE_LICENSE("GPL v2");
683MODULE_DESCRIPTION("Intel Skylake ASoC HDA driver");