2 * skl.c - Implementation of ASoC Intel SKL HD Audio driver
4 * Copyright (C) 2014-2015 Intel Corp
5 * Author: Jeeja KP <jeeja.kp@intel.com>
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 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
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.
21 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24 #include <linux/module.h>
25 #include <linux/pci.h>
26 #include <linux/pm_runtime.h>
27 #include <linux/platform_device.h>
28 #include <linux/firmware.h>
29 #include <linux/delay.h>
30 #include <sound/pcm.h>
31 #include <sound/soc-acpi.h>
32 #include <sound/hda_register.h>
33 #include <sound/hdaudio.h>
34 #include <sound/hda_i915.h>
36 #include "skl-sst-dsp.h"
37 #include "skl-sst-ipc.h"
39 static struct skl_machine_pdata skl_dmic_data;
42 * initialize the PCI registers
44 static void skl_update_pci_byte(struct pci_dev *pci, unsigned int reg,
45 unsigned char mask, unsigned char val)
49 pci_read_config_byte(pci, reg, &data);
52 pci_write_config_byte(pci, reg, data);
55 static void skl_init_pci(struct skl *skl)
57 struct hdac_bus *bus = skl_to_bus(skl);
60 * Clear bits 0-2 of PCI register TCSEL (at offset 0x44)
61 * TCSEL == Traffic Class Select Register, which sets PCI express QOS
62 * Ensuring these bits are 0 clears playback static on some HD Audio
64 * The PCI register TCSEL is defined in the Intel manuals.
66 dev_dbg(bus->dev, "Clearing TCSEL\n");
67 skl_update_pci_byte(skl->pci, AZX_PCIREG_TCSEL, 0x07, 0);
70 static void update_pci_dword(struct pci_dev *pci,
71 unsigned int reg, u32 mask, u32 val)
75 pci_read_config_dword(pci, reg, &data);
78 pci_write_config_dword(pci, reg, data);
82 * skl_enable_miscbdcge - enable/dsiable CGCTL.MISCBDCGE bits
84 * @dev: device pointer
85 * @enable: enable/disable flag
87 static void skl_enable_miscbdcge(struct device *dev, bool enable)
89 struct pci_dev *pci = to_pci_dev(dev);
92 val = enable ? AZX_CGCTL_MISCBDCGE_MASK : 0;
94 update_pci_dword(pci, AZX_PCIREG_CGCTL, AZX_CGCTL_MISCBDCGE_MASK, val);
98 * skl_clock_power_gating: Enable/Disable clock and power gating
100 * @dev: Device pointer
101 * @enable: Enable/Disable flag
103 static void skl_clock_power_gating(struct device *dev, bool enable)
105 struct pci_dev *pci = to_pci_dev(dev);
106 struct hdac_bus *bus = pci_get_drvdata(pci);
109 /* Update PDCGE bit of CGCTL register */
110 val = enable ? AZX_CGCTL_ADSPDCGE : 0;
111 update_pci_dword(pci, AZX_PCIREG_CGCTL, AZX_CGCTL_ADSPDCGE, val);
113 /* Update L1SEN bit of EM2 register */
114 val = enable ? AZX_REG_VS_EM2_L1SEN : 0;
115 snd_hdac_chip_updatel(bus, VS_EM2, AZX_REG_VS_EM2_L1SEN, val);
117 /* Update ADSPPGD bit of PGCTL register */
118 val = enable ? 0 : AZX_PGCTL_ADSPPGD;
119 update_pci_dword(pci, AZX_PCIREG_PGCTL, AZX_PGCTL_ADSPPGD, val);
123 * While performing reset, controller may not come back properly causing
124 * issues, so recommendation is to set CGCTL.MISCBDCGE to 0 then do reset
125 * (init chip) and then again set CGCTL.MISCBDCGE to 1
127 static int skl_init_chip(struct hdac_bus *bus, bool full_reset)
129 struct hdac_ext_link *hlink;
132 skl_enable_miscbdcge(bus->dev, false);
133 ret = snd_hdac_bus_init_chip(bus, full_reset);
135 /* Reset stream-to-link mapping */
136 list_for_each_entry(hlink, &bus->hlink_list, list)
137 bus->io_ops->reg_writel(0, hlink->ml_addr + AZX_REG_ML_LOSIDV);
139 skl_enable_miscbdcge(bus->dev, true);
144 void skl_update_d0i3c(struct device *dev, bool enable)
146 struct pci_dev *pci = to_pci_dev(dev);
147 struct hdac_bus *bus = pci_get_drvdata(pci);
151 reg = snd_hdac_chip_readb(bus, VS_D0I3C);
152 /* Do not write to D0I3C until command in progress bit is cleared */
153 while ((reg & AZX_REG_VS_D0I3C_CIP) && --timeout) {
155 reg = snd_hdac_chip_readb(bus, VS_D0I3C);
158 /* Highly unlikely. But if it happens, flag error explicitly */
160 dev_err(bus->dev, "Before D0I3C update: D0I3C CIP timeout\n");
165 reg = reg | AZX_REG_VS_D0I3C_I3;
167 reg = reg & (~AZX_REG_VS_D0I3C_I3);
169 snd_hdac_chip_writeb(bus, VS_D0I3C, reg);
172 /* Wait for cmd in progress to be cleared before exiting the function */
173 reg = snd_hdac_chip_readb(bus, VS_D0I3C);
174 while ((reg & AZX_REG_VS_D0I3C_CIP) && --timeout) {
176 reg = snd_hdac_chip_readb(bus, VS_D0I3C);
179 /* Highly unlikely. But if it happens, flag error explicitly */
181 dev_err(bus->dev, "After D0I3C update: D0I3C CIP timeout\n");
185 dev_dbg(bus->dev, "D0I3C register = 0x%x\n",
186 snd_hdac_chip_readb(bus, VS_D0I3C));
189 /* called from IRQ */
190 static void skl_stream_update(struct hdac_bus *bus, struct hdac_stream *hstr)
192 snd_pcm_period_elapsed(hstr->substream);
195 static irqreturn_t skl_interrupt(int irq, void *dev_id)
197 struct hdac_bus *bus = dev_id;
200 if (!pm_runtime_active(bus->dev))
203 spin_lock(&bus->reg_lock);
205 status = snd_hdac_chip_readl(bus, INTSTS);
206 if (status == 0 || status == 0xffffffff) {
207 spin_unlock(&bus->reg_lock);
212 status = snd_hdac_chip_readb(bus, RIRBSTS);
213 if (status & RIRB_INT_MASK) {
214 if (status & RIRB_INT_RESPONSE)
215 snd_hdac_bus_update_rirb(bus);
216 snd_hdac_chip_writeb(bus, RIRBSTS, RIRB_INT_MASK);
219 spin_unlock(&bus->reg_lock);
221 return snd_hdac_chip_readl(bus, INTSTS) ? IRQ_WAKE_THREAD : IRQ_HANDLED;
224 static irqreturn_t skl_threaded_handler(int irq, void *dev_id)
226 struct hdac_bus *bus = dev_id;
229 status = snd_hdac_chip_readl(bus, INTSTS);
231 snd_hdac_bus_handle_stream_irq(bus, status, skl_stream_update);
236 static int skl_acquire_irq(struct hdac_bus *bus, int do_disconnect)
238 struct skl *skl = bus_to_skl(bus);
241 ret = request_threaded_irq(skl->pci->irq, skl_interrupt,
242 skl_threaded_handler,
244 KBUILD_MODNAME, bus);
247 "unable to grab IRQ %d, disabling device\n",
252 bus->irq = skl->pci->irq;
253 pci_intx(skl->pci, 1);
258 static int skl_suspend_late(struct device *dev)
260 struct pci_dev *pci = to_pci_dev(dev);
261 struct hdac_bus *bus = pci_get_drvdata(pci);
262 struct skl *skl = bus_to_skl(bus);
264 return skl_suspend_late_dsp(skl);
268 static int _skl_suspend(struct hdac_bus *bus)
270 struct skl *skl = bus_to_skl(bus);
271 struct pci_dev *pci = to_pci_dev(bus->dev);
274 snd_hdac_ext_bus_link_power_down_all(bus);
276 ret = skl_suspend_dsp(skl);
280 snd_hdac_bus_stop_chip(bus);
281 update_pci_dword(pci, AZX_PCIREG_PGCTL,
282 AZX_PGCTL_LSRMD_MASK, AZX_PGCTL_LSRMD_MASK);
283 skl_enable_miscbdcge(bus->dev, false);
284 snd_hdac_bus_enter_link_reset(bus);
285 skl_enable_miscbdcge(bus->dev, true);
286 skl_cleanup_resources(skl);
291 static int _skl_resume(struct hdac_bus *bus)
293 struct skl *skl = bus_to_skl(bus);
296 skl_init_chip(bus, true);
298 return skl_resume_dsp(skl);
302 #ifdef CONFIG_PM_SLEEP
306 static int skl_suspend(struct device *dev)
308 struct pci_dev *pci = to_pci_dev(dev);
309 struct hdac_bus *bus = pci_get_drvdata(pci);
310 struct skl *skl = bus_to_skl(bus);
314 * Do not suspend if streams which are marked ignore suspend are
315 * running, we need to save the state for these and continue
317 if (skl->supend_active) {
318 /* turn off the links and stop the CORB/RIRB DMA if it is On */
319 snd_hdac_ext_bus_link_power_down_all(bus);
321 if (bus->cmd_dma_state)
322 snd_hdac_bus_stop_cmd_io(bus);
324 enable_irq_wake(bus->irq);
327 ret = _skl_suspend(bus);
330 skl->skl_sst->fw_loaded = false;
333 if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI)) {
334 ret = snd_hdac_display_power(bus, false);
337 "Cannot turn OFF display power on i915\n");
343 static int skl_resume(struct device *dev)
345 struct pci_dev *pci = to_pci_dev(dev);
346 struct hdac_bus *bus = pci_get_drvdata(pci);
347 struct skl *skl = bus_to_skl(bus);
348 struct hdac_ext_link *hlink = NULL;
351 /* Turned OFF in HDMI codec driver after codec reconfiguration */
352 if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI)) {
353 ret = snd_hdac_display_power(bus, true);
356 "Cannot turn on display power on i915\n");
362 * resume only when we are not in suspend active, otherwise need to
365 if (skl->supend_active) {
366 pci_restore_state(pci);
367 snd_hdac_ext_bus_link_power_up_all(bus);
368 disable_irq_wake(bus->irq);
370 * turn On the links which are On before active suspend
371 * and start the CORB/RIRB DMA if On before
374 list_for_each_entry(hlink, &bus->hlink_list, list) {
375 if (hlink->ref_count)
376 snd_hdac_ext_bus_link_power_up(hlink);
380 if (bus->cmd_dma_state)
381 snd_hdac_bus_init_cmd_io(bus);
383 ret = _skl_resume(bus);
385 /* turn off the links which are off before suspend */
386 list_for_each_entry(hlink, &bus->hlink_list, list) {
387 if (!hlink->ref_count)
388 snd_hdac_ext_bus_link_power_down(hlink);
391 if (!bus->cmd_dma_state)
392 snd_hdac_bus_stop_cmd_io(bus);
397 #endif /* CONFIG_PM_SLEEP */
400 static int skl_runtime_suspend(struct device *dev)
402 struct pci_dev *pci = to_pci_dev(dev);
403 struct hdac_bus *bus = pci_get_drvdata(pci);
405 dev_dbg(bus->dev, "in %s\n", __func__);
407 return _skl_suspend(bus);
410 static int skl_runtime_resume(struct device *dev)
412 struct pci_dev *pci = to_pci_dev(dev);
413 struct hdac_bus *bus = pci_get_drvdata(pci);
415 dev_dbg(bus->dev, "in %s\n", __func__);
417 return _skl_resume(bus);
419 #endif /* CONFIG_PM */
421 static const struct dev_pm_ops skl_pm = {
422 SET_SYSTEM_SLEEP_PM_OPS(skl_suspend, skl_resume)
423 SET_RUNTIME_PM_OPS(skl_runtime_suspend, skl_runtime_resume, NULL)
424 .suspend_late = skl_suspend_late,
430 static int skl_free(struct hdac_bus *bus)
432 struct skl *skl = bus_to_skl(bus);
434 skl->init_done = 0; /* to be sure */
436 snd_hdac_ext_stop_streams(bus);
439 free_irq(bus->irq, (void *)bus);
440 snd_hdac_bus_free_stream_pages(bus);
441 snd_hdac_stream_free_all(bus);
442 snd_hdac_link_free_all(bus);
445 iounmap(bus->remap_addr);
447 pci_release_regions(skl->pci);
448 pci_disable_device(skl->pci);
450 snd_hdac_ext_bus_exit(bus);
452 cancel_work_sync(&skl->probe_work);
453 if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI))
454 snd_hdac_i915_exit(bus);
460 * For each ssp there are 3 clocks (mclk/sclk/sclkfs).
461 * e.g. for ssp0, clocks will be named as
462 * "ssp0_mclk", "ssp0_sclk", "ssp0_sclkfs"
463 * So for skl+, there are 6 ssps, so 18 clocks will be created.
465 static struct skl_ssp_clk skl_ssp_clks[] = {
466 {.name = "ssp0_mclk"}, {.name = "ssp1_mclk"}, {.name = "ssp2_mclk"},
467 {.name = "ssp3_mclk"}, {.name = "ssp4_mclk"}, {.name = "ssp5_mclk"},
468 {.name = "ssp0_sclk"}, {.name = "ssp1_sclk"}, {.name = "ssp2_sclk"},
469 {.name = "ssp3_sclk"}, {.name = "ssp4_sclk"}, {.name = "ssp5_sclk"},
470 {.name = "ssp0_sclkfs"}, {.name = "ssp1_sclkfs"},
471 {.name = "ssp2_sclkfs"},
472 {.name = "ssp3_sclkfs"}, {.name = "ssp4_sclkfs"},
473 {.name = "ssp5_sclkfs"},
476 static int skl_find_machine(struct skl *skl, void *driver_data)
478 struct hdac_bus *bus = skl_to_bus(skl);
479 struct snd_soc_acpi_mach *mach = driver_data;
480 struct skl_machine_pdata *pdata;
482 mach = snd_soc_acpi_find_machine(mach);
484 dev_err(bus->dev, "No matching machine driver found\n");
489 skl->fw_name = mach->fw_filename;
490 pdata = skl->mach->pdata;
493 skl->use_tplg_pcm = pdata->use_tplg_pcm;
498 static int skl_machine_device_register(struct skl *skl)
500 struct hdac_bus *bus = skl_to_bus(skl);
501 struct snd_soc_acpi_mach *mach = skl->mach;
502 struct platform_device *pdev;
505 pdev = platform_device_alloc(mach->drv_name, -1);
507 dev_err(bus->dev, "platform device alloc failed\n");
511 ret = platform_device_add(pdev);
513 dev_err(bus->dev, "failed to add machine device\n");
514 platform_device_put(pdev);
519 dev_set_drvdata(&pdev->dev, mach->pdata);
526 static void skl_machine_device_unregister(struct skl *skl)
529 platform_device_unregister(skl->i2s_dev);
532 static int skl_dmic_device_register(struct skl *skl)
534 struct hdac_bus *bus = skl_to_bus(skl);
535 struct platform_device *pdev;
538 /* SKL has one dmic port, so allocate dmic device for this */
539 pdev = platform_device_alloc("dmic-codec", -1);
541 dev_err(bus->dev, "failed to allocate dmic device\n");
545 ret = platform_device_add(pdev);
547 dev_err(bus->dev, "failed to add dmic device: %d\n", ret);
548 platform_device_put(pdev);
551 skl->dmic_dev = pdev;
556 static void skl_dmic_device_unregister(struct skl *skl)
559 platform_device_unregister(skl->dmic_dev);
562 static struct skl_clk_parent_src skl_clk_src[] = {
563 { .clk_id = SKL_XTAL, .name = "xtal" },
564 { .clk_id = SKL_CARDINAL, .name = "cardinal", .rate = 24576000 },
565 { .clk_id = SKL_PLL, .name = "pll", .rate = 96000000 },
568 struct skl_clk_parent_src *skl_get_parent_clk(u8 clk_id)
572 for (i = 0; i < ARRAY_SIZE(skl_clk_src); i++) {
573 if (skl_clk_src[i].clk_id == clk_id)
574 return &skl_clk_src[i];
580 static void init_skl_xtal_rate(int pci_id)
585 skl_clk_src[0].rate = 24000000;
589 skl_clk_src[0].rate = 19200000;
594 static int skl_clock_device_register(struct skl *skl)
596 struct platform_device_info pdevinfo = {NULL};
597 struct skl_clk_pdata *clk_pdata;
599 clk_pdata = devm_kzalloc(&skl->pci->dev, sizeof(*clk_pdata),
604 init_skl_xtal_rate(skl->pci->device);
606 clk_pdata->parent_clks = skl_clk_src;
607 clk_pdata->ssp_clks = skl_ssp_clks;
608 clk_pdata->num_clks = ARRAY_SIZE(skl_ssp_clks);
610 /* Query NHLT to fill the rates and parent */
611 skl_get_clks(skl, clk_pdata->ssp_clks);
612 clk_pdata->pvt_data = skl;
614 /* Register Platform device */
615 pdevinfo.parent = &skl->pci->dev;
617 pdevinfo.name = "skl-ssp-clk";
618 pdevinfo.data = clk_pdata;
619 pdevinfo.size_data = sizeof(*clk_pdata);
620 skl->clk_dev = platform_device_register_full(&pdevinfo);
621 return PTR_ERR_OR_ZERO(skl->clk_dev);
624 static void skl_clock_device_unregister(struct skl *skl)
627 platform_device_unregister(skl->clk_dev);
631 * Probe the given codec address
633 static int probe_codec(struct hdac_bus *bus, int addr)
635 unsigned int cmd = (addr << 28) | (AC_NODE_ROOT << 20) |
636 (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID;
637 unsigned int res = -1;
638 struct skl *skl = bus_to_skl(bus);
639 struct hdac_device *hdev;
641 mutex_lock(&bus->cmd_mutex);
642 snd_hdac_bus_send_cmd(bus, cmd);
643 snd_hdac_bus_get_response(bus, addr, &res);
644 mutex_unlock(&bus->cmd_mutex);
647 dev_dbg(bus->dev, "codec #%d probed OK\n", addr);
649 hdev = devm_kzalloc(&skl->pci->dev, sizeof(*hdev), GFP_KERNEL);
653 return snd_hdac_ext_bus_device_init(bus, addr, hdev);
656 /* Codec initialization */
657 static void skl_codec_create(struct hdac_bus *bus)
661 max_slots = HDA_MAX_CODECS;
663 /* First try to probe all given codec slots */
664 for (c = 0; c < max_slots; c++) {
665 if ((bus->codec_mask & (1 << c))) {
666 if (probe_codec(bus, c) < 0) {
668 * Some BIOSen give you wrong codec addresses
672 "Codec #%d probe error; disabling it...\n", c);
673 bus->codec_mask &= ~(1 << c);
675 * More badly, accessing to a non-existing
676 * codec often screws up the controller bus,
677 * and disturbs the further communications.
678 * Thus if an error occurs during probing,
679 * better to reset the controller bus to get
680 * back to the sanity state.
682 snd_hdac_bus_stop_chip(bus);
683 skl_init_chip(bus, true);
689 static const struct hdac_bus_ops bus_core_ops = {
690 .command = snd_hdac_bus_send_cmd,
691 .get_response = snd_hdac_bus_get_response,
694 static int skl_i915_init(struct hdac_bus *bus)
699 * The HDMI codec is in GPU so we need to ensure that it is powered
700 * up and ready for probe
702 err = snd_hdac_i915_init(bus);
706 err = snd_hdac_display_power(bus, true);
708 dev_err(bus->dev, "Cannot turn on display power on i915\n");
713 static void skl_probe_work(struct work_struct *work)
715 struct skl *skl = container_of(work, struct skl, probe_work);
716 struct hdac_bus *bus = skl_to_bus(skl);
717 struct hdac_ext_link *hlink = NULL;
720 if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI)) {
721 err = skl_i915_init(bus);
726 err = skl_init_chip(bus, true);
728 dev_err(bus->dev, "Init chip failed with err: %d\n", err);
732 /* codec detection */
733 if (!bus->codec_mask)
734 dev_info(bus->dev, "no hda codecs found!\n");
736 /* create codec instances */
737 skl_codec_create(bus);
739 /* register platform dai and controls */
740 err = skl_platform_register(bus->dev);
742 dev_err(bus->dev, "platform register failed: %d\n", err);
747 err = skl_machine_device_register(skl);
749 dev_err(bus->dev, "machine register failed: %d\n", err);
754 if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI)) {
755 err = snd_hdac_display_power(bus, false);
757 dev_err(bus->dev, "Cannot turn off display power on i915\n");
758 skl_machine_device_unregister(skl);
764 * we are done probing so decrement link counts
766 list_for_each_entry(hlink, &bus->hlink_list, list)
767 snd_hdac_ext_bus_link_put(bus, hlink);
770 pm_runtime_put_noidle(bus->dev);
771 pm_runtime_allow(bus->dev);
777 if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI))
778 err = snd_hdac_display_power(bus, false);
784 static int skl_create(struct pci_dev *pci,
785 const struct hdac_io_ops *io_ops,
789 struct hdac_bus *bus;
795 err = pci_enable_device(pci);
799 skl = devm_kzalloc(&pci->dev, sizeof(*skl), GFP_KERNEL);
801 pci_disable_device(pci);
805 bus = skl_to_bus(skl);
806 snd_hdac_ext_bus_init(bus, &pci->dev, &bus_core_ops, io_ops, NULL);
809 INIT_WORK(&skl->probe_work, skl_probe_work);
810 bus->bdl_pos_adj = 0;
817 static int skl_first_init(struct hdac_bus *bus)
819 struct skl *skl = bus_to_skl(bus);
820 struct pci_dev *pci = skl->pci;
823 int cp_streams, pb_streams, start_idx;
825 err = pci_request_regions(pci, "Skylake HD audio");
829 bus->addr = pci_resource_start(pci, 0);
830 bus->remap_addr = pci_ioremap_bar(pci, 0);
831 if (bus->remap_addr == NULL) {
832 dev_err(bus->dev, "ioremap error\n");
836 skl_init_chip(bus, true);
838 snd_hdac_bus_parse_capabilities(bus);
840 if (skl_acquire_irq(bus, 0) < 0)
844 synchronize_irq(bus->irq);
846 gcap = snd_hdac_chip_readw(bus, GCAP);
847 dev_dbg(bus->dev, "chipset global capabilities = 0x%x\n", gcap);
849 /* allow 64bit DMA address if supported by H/W */
850 if (!dma_set_mask(bus->dev, DMA_BIT_MASK(64))) {
851 dma_set_coherent_mask(bus->dev, DMA_BIT_MASK(64));
853 dma_set_mask(bus->dev, DMA_BIT_MASK(32));
854 dma_set_coherent_mask(bus->dev, DMA_BIT_MASK(32));
857 /* read number of streams from GCAP register */
858 cp_streams = (gcap >> 8) & 0x0f;
859 pb_streams = (gcap >> 12) & 0x0f;
861 if (!pb_streams && !cp_streams)
864 bus->num_streams = cp_streams + pb_streams;
866 /* initialize streams */
867 snd_hdac_ext_stream_init_all
868 (bus, 0, cp_streams, SNDRV_PCM_STREAM_CAPTURE);
869 start_idx = cp_streams;
870 snd_hdac_ext_stream_init_all
871 (bus, start_idx, pb_streams, SNDRV_PCM_STREAM_PLAYBACK);
873 err = snd_hdac_bus_alloc_stream_pages(bus);
877 /* initialize chip */
880 return skl_init_chip(bus, true);
883 static int skl_probe(struct pci_dev *pci,
884 const struct pci_device_id *pci_id)
887 struct hdac_bus *bus = NULL;
890 /* we use ext core ops, so provide NULL for ops here */
891 err = skl_create(pci, NULL, &skl);
895 bus = skl_to_bus(skl);
897 err = skl_first_init(bus);
901 skl->pci_id = pci->device;
903 device_disable_async_suspend(bus->dev);
905 skl->nhlt = skl_nhlt_init(bus->dev);
907 if (skl->nhlt == NULL) {
912 err = skl_nhlt_create_sysfs(skl);
916 skl_nhlt_update_topology_bin(skl);
918 pci_set_drvdata(skl->pci, bus);
920 skl_dmic_data.dmic_num = skl_get_dmic_geo(skl);
922 /* check if dsp is there */
924 /* create device for dsp clk */
925 err = skl_clock_device_register(skl);
929 err = skl_find_machine(skl, (void *)pci_id->driver_data);
933 err = skl_init_dsp(skl);
935 dev_dbg(bus->dev, "error failed to register dsp\n");
938 skl->skl_sst->enable_miscbdcge = skl_enable_miscbdcge;
939 skl->skl_sst->clock_power_gating = skl_clock_power_gating;
942 snd_hdac_ext_bus_get_ml_capabilities(bus);
944 snd_hdac_bus_stop_chip(bus);
946 /* create device for soc dmic */
947 err = skl_dmic_device_register(skl);
951 schedule_work(&skl->probe_work);
958 skl_clock_device_unregister(skl);
960 skl_nhlt_free(skl->nhlt);
967 static void skl_shutdown(struct pci_dev *pci)
969 struct hdac_bus *bus = pci_get_drvdata(pci);
970 struct hdac_stream *s;
971 struct hdac_ext_stream *stream;
977 skl = bus_to_skl(bus);
982 snd_hdac_ext_stop_streams(bus);
983 list_for_each_entry(s, &bus->stream_list, list) {
984 stream = stream_to_hdac_ext_stream(s);
985 snd_hdac_ext_stream_decouple(bus, stream, false);
988 snd_hdac_bus_stop_chip(bus);
991 static void skl_remove(struct pci_dev *pci)
993 struct hdac_bus *bus = pci_get_drvdata(pci);
994 struct skl *skl = bus_to_skl(bus);
996 release_firmware(skl->tplg);
998 pm_runtime_get_noresume(&pci->dev);
1000 /* codec removal, invoke bus_device_remove */
1001 snd_hdac_ext_bus_device_remove(bus);
1003 skl->debugfs = NULL;
1004 skl_platform_unregister(&pci->dev);
1006 skl_machine_device_unregister(skl);
1007 skl_dmic_device_unregister(skl);
1008 skl_clock_device_unregister(skl);
1009 skl_nhlt_remove_sysfs(skl);
1010 skl_nhlt_free(skl->nhlt);
1012 dev_set_drvdata(&pci->dev, NULL);
1015 static struct snd_soc_acpi_codecs skl_codecs = {
1017 .codecs = {"10508825"}
1020 static struct snd_soc_acpi_codecs kbl_codecs = {
1022 .codecs = {"10508825"}
1025 static struct snd_soc_acpi_codecs bxt_codecs = {
1027 .codecs = {"MX98357A"}
1030 static struct snd_soc_acpi_codecs kbl_poppy_codecs = {
1032 .codecs = {"10EC5663"}
1035 static struct snd_soc_acpi_codecs kbl_5663_5514_codecs = {
1037 .codecs = {"10EC5663", "10EC5514"}
1040 static struct snd_soc_acpi_codecs kbl_7219_98357_codecs = {
1042 .codecs = {"MX98357A"}
1045 static struct skl_machine_pdata cnl_pdata = {
1046 .use_tplg_pcm = true,
1049 static struct snd_soc_acpi_mach sst_skl_devdata[] = {
1052 .drv_name = "skl_alc286s_i2s",
1053 .fw_filename = "intel/dsp_fw_release.bin",
1057 .drv_name = "skl_n88l25_s4567",
1058 .fw_filename = "intel/dsp_fw_release.bin",
1059 .machine_quirk = snd_soc_acpi_codec_list,
1060 .quirk_data = &skl_codecs,
1061 .pdata = &skl_dmic_data
1065 .drv_name = "skl_n88l25_m98357a",
1066 .fw_filename = "intel/dsp_fw_release.bin",
1067 .machine_quirk = snd_soc_acpi_codec_list,
1068 .quirk_data = &skl_codecs,
1069 .pdata = &skl_dmic_data
1074 static struct snd_soc_acpi_mach sst_bxtp_devdata[] = {
1077 .drv_name = "bxt_alc298s_i2s",
1078 .fw_filename = "intel/dsp_fw_bxtn.bin",
1082 .drv_name = "bxt_da7219_max98357a_i2s",
1083 .fw_filename = "intel/dsp_fw_bxtn.bin",
1084 .machine_quirk = snd_soc_acpi_codec_list,
1085 .quirk_data = &bxt_codecs,
1090 static struct snd_soc_acpi_mach sst_kbl_devdata[] = {
1093 .drv_name = "kbl_alc286s_i2s",
1094 .fw_filename = "intel/dsp_fw_kbl.bin",
1098 .drv_name = "kbl_n88l25_s4567",
1099 .fw_filename = "intel/dsp_fw_kbl.bin",
1100 .machine_quirk = snd_soc_acpi_codec_list,
1101 .quirk_data = &kbl_codecs,
1102 .pdata = &skl_dmic_data
1106 .drv_name = "kbl_n88l25_m98357a",
1107 .fw_filename = "intel/dsp_fw_kbl.bin",
1108 .machine_quirk = snd_soc_acpi_codec_list,
1109 .quirk_data = &kbl_codecs,
1110 .pdata = &skl_dmic_data
1114 .drv_name = "kbl_r5514_5663_max",
1115 .fw_filename = "intel/dsp_fw_kbl.bin",
1116 .machine_quirk = snd_soc_acpi_codec_list,
1117 .quirk_data = &kbl_5663_5514_codecs,
1118 .pdata = &skl_dmic_data
1122 .drv_name = "kbl_rt5663_m98927",
1123 .fw_filename = "intel/dsp_fw_kbl.bin",
1124 .machine_quirk = snd_soc_acpi_codec_list,
1125 .quirk_data = &kbl_poppy_codecs,
1126 .pdata = &skl_dmic_data
1130 .drv_name = "kbl_rt5663",
1131 .fw_filename = "intel/dsp_fw_kbl.bin",
1135 .drv_name = "kbl_da7219_max98357a",
1136 .fw_filename = "intel/dsp_fw_kbl.bin",
1137 .machine_quirk = snd_soc_acpi_codec_list,
1138 .quirk_data = &kbl_7219_98357_codecs,
1139 .pdata = &skl_dmic_data
1145 static struct snd_soc_acpi_mach sst_glk_devdata[] = {
1148 .drv_name = "glk_alc298s_i2s",
1149 .fw_filename = "intel/dsp_fw_glk.bin",
1154 static const struct snd_soc_acpi_mach sst_cnl_devdata[] = {
1157 .drv_name = "cnl_rt274",
1158 .fw_filename = "intel/dsp_fw_cnl.bin",
1159 .pdata = &cnl_pdata,
1165 static const struct pci_device_id skl_ids[] = {
1166 /* Sunrise Point-LP */
1167 { PCI_DEVICE(0x8086, 0x9d70),
1168 .driver_data = (unsigned long)&sst_skl_devdata},
1170 { PCI_DEVICE(0x8086, 0x5a98),
1171 .driver_data = (unsigned long)&sst_bxtp_devdata},
1173 { PCI_DEVICE(0x8086, 0x9D71),
1174 .driver_data = (unsigned long)&sst_kbl_devdata},
1176 { PCI_DEVICE(0x8086, 0x3198),
1177 .driver_data = (unsigned long)&sst_glk_devdata},
1179 { PCI_DEVICE(0x8086, 0x9dc8),
1180 .driver_data = (unsigned long)&sst_cnl_devdata},
1183 MODULE_DEVICE_TABLE(pci, skl_ids);
1185 /* pci_driver definition */
1186 static struct pci_driver skl_driver = {
1187 .name = KBUILD_MODNAME,
1188 .id_table = skl_ids,
1190 .remove = skl_remove,
1191 .shutdown = skl_shutdown,
1196 module_pci_driver(skl_driver);
1198 MODULE_LICENSE("GPL v2");
1199 MODULE_DESCRIPTION("Intel Skylake ASoC HDA driver");