2 * skl.c - Implementation of ASoC Intel SKL HD Audio driver
4 * Copyright (C) 2014-2015 Intel Corp
7 * Derived mostly from Intel HDA driver with following copyrights:
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/soc-acpi-intel-match.h>
33 #include <sound/hda_register.h>
34 #include <sound/hdaudio.h>
35 #include <sound/hda_i915.h>
36 #include <sound/hda_codec.h>
38 #include "skl-sst-dsp.h"
39 #include "skl-sst-ipc.h"
40 #include "../../../soc/codecs/hdac_hda.h"
43 * initialize the PCI registers
45 static void skl_update_pci_byte(struct pci_dev *pci, unsigned int reg,
46 unsigned char mask, unsigned char val)
50 pci_read_config_byte(pci, reg, &data);
53 pci_write_config_byte(pci, reg, data);
56 static void skl_init_pci(struct skl *skl)
58 struct hdac_bus *bus = skl_to_bus(skl);
61 * Clear bits 0-2 of PCI register TCSEL (at offset 0x44)
62 * TCSEL == Traffic Class Select Register, which sets PCI express QOS
63 * Ensuring these bits are 0 clears playback static on some HD Audio
65 * The PCI register TCSEL is defined in the Intel manuals.
67 dev_dbg(bus->dev, "Clearing TCSEL\n");
68 skl_update_pci_byte(skl->pci, AZX_PCIREG_TCSEL, 0x07, 0);
71 static void update_pci_dword(struct pci_dev *pci,
72 unsigned int reg, u32 mask, u32 val)
76 pci_read_config_dword(pci, reg, &data);
79 pci_write_config_dword(pci, reg, data);
83 * skl_enable_miscbdcge - enable/dsiable CGCTL.MISCBDCGE bits
85 * @dev: device pointer
86 * @enable: enable/disable flag
88 static void skl_enable_miscbdcge(struct device *dev, bool enable)
90 struct pci_dev *pci = to_pci_dev(dev);
93 val = enable ? AZX_CGCTL_MISCBDCGE_MASK : 0;
95 update_pci_dword(pci, AZX_PCIREG_CGCTL, AZX_CGCTL_MISCBDCGE_MASK, val);
99 * skl_clock_power_gating: Enable/Disable clock and power gating
101 * @dev: Device pointer
102 * @enable: Enable/Disable flag
104 static void skl_clock_power_gating(struct device *dev, bool enable)
106 struct pci_dev *pci = to_pci_dev(dev);
107 struct hdac_bus *bus = pci_get_drvdata(pci);
110 /* Update PDCGE bit of CGCTL register */
111 val = enable ? AZX_CGCTL_ADSPDCGE : 0;
112 update_pci_dword(pci, AZX_PCIREG_CGCTL, AZX_CGCTL_ADSPDCGE, val);
114 /* Update L1SEN bit of EM2 register */
115 val = enable ? AZX_REG_VS_EM2_L1SEN : 0;
116 snd_hdac_chip_updatel(bus, VS_EM2, AZX_REG_VS_EM2_L1SEN, val);
118 /* Update ADSPPGD bit of PGCTL register */
119 val = enable ? 0 : AZX_PGCTL_ADSPPGD;
120 update_pci_dword(pci, AZX_PCIREG_PGCTL, AZX_PGCTL_ADSPPGD, val);
124 * While performing reset, controller may not come back properly causing
125 * issues, so recommendation is to set CGCTL.MISCBDCGE to 0 then do reset
126 * (init chip) and then again set CGCTL.MISCBDCGE to 1
128 static int skl_init_chip(struct hdac_bus *bus, bool full_reset)
130 struct hdac_ext_link *hlink;
133 skl_enable_miscbdcge(bus->dev, false);
134 ret = snd_hdac_bus_init_chip(bus, full_reset);
136 /* Reset stream-to-link mapping */
137 list_for_each_entry(hlink, &bus->hlink_list, list)
138 bus->io_ops->reg_writel(0, hlink->ml_addr + AZX_REG_ML_LOSIDV);
140 skl_enable_miscbdcge(bus->dev, true);
145 void skl_update_d0i3c(struct device *dev, bool enable)
147 struct pci_dev *pci = to_pci_dev(dev);
148 struct hdac_bus *bus = pci_get_drvdata(pci);
152 reg = snd_hdac_chip_readb(bus, VS_D0I3C);
153 /* Do not write to D0I3C until command in progress bit is cleared */
154 while ((reg & AZX_REG_VS_D0I3C_CIP) && --timeout) {
156 reg = snd_hdac_chip_readb(bus, VS_D0I3C);
159 /* Highly unlikely. But if it happens, flag error explicitly */
161 dev_err(bus->dev, "Before D0I3C update: D0I3C CIP timeout\n");
166 reg = reg | AZX_REG_VS_D0I3C_I3;
168 reg = reg & (~AZX_REG_VS_D0I3C_I3);
170 snd_hdac_chip_writeb(bus, VS_D0I3C, reg);
173 /* Wait for cmd in progress to be cleared before exiting the function */
174 reg = snd_hdac_chip_readb(bus, VS_D0I3C);
175 while ((reg & AZX_REG_VS_D0I3C_CIP) && --timeout) {
177 reg = snd_hdac_chip_readb(bus, VS_D0I3C);
180 /* Highly unlikely. But if it happens, flag error explicitly */
182 dev_err(bus->dev, "After D0I3C update: D0I3C CIP timeout\n");
186 dev_dbg(bus->dev, "D0I3C register = 0x%x\n",
187 snd_hdac_chip_readb(bus, VS_D0I3C));
190 /* called from IRQ */
191 static void skl_stream_update(struct hdac_bus *bus, struct hdac_stream *hstr)
193 snd_pcm_period_elapsed(hstr->substream);
196 static irqreturn_t skl_interrupt(int irq, void *dev_id)
198 struct hdac_bus *bus = dev_id;
201 if (!pm_runtime_active(bus->dev))
204 spin_lock(&bus->reg_lock);
206 status = snd_hdac_chip_readl(bus, INTSTS);
207 if (status == 0 || status == 0xffffffff) {
208 spin_unlock(&bus->reg_lock);
213 status = snd_hdac_chip_readb(bus, RIRBSTS);
214 if (status & RIRB_INT_MASK) {
215 if (status & RIRB_INT_RESPONSE)
216 snd_hdac_bus_update_rirb(bus);
217 snd_hdac_chip_writeb(bus, RIRBSTS, RIRB_INT_MASK);
220 spin_unlock(&bus->reg_lock);
222 return snd_hdac_chip_readl(bus, INTSTS) ? IRQ_WAKE_THREAD : IRQ_HANDLED;
225 static irqreturn_t skl_threaded_handler(int irq, void *dev_id)
227 struct hdac_bus *bus = dev_id;
230 status = snd_hdac_chip_readl(bus, INTSTS);
232 snd_hdac_bus_handle_stream_irq(bus, status, skl_stream_update);
237 static int skl_acquire_irq(struct hdac_bus *bus, int do_disconnect)
239 struct skl *skl = bus_to_skl(bus);
242 ret = request_threaded_irq(skl->pci->irq, skl_interrupt,
243 skl_threaded_handler,
245 KBUILD_MODNAME, bus);
248 "unable to grab IRQ %d, disabling device\n",
253 bus->irq = skl->pci->irq;
254 pci_intx(skl->pci, 1);
259 static int skl_suspend_late(struct device *dev)
261 struct pci_dev *pci = to_pci_dev(dev);
262 struct hdac_bus *bus = pci_get_drvdata(pci);
263 struct skl *skl = bus_to_skl(bus);
265 return skl_suspend_late_dsp(skl);
269 static int _skl_suspend(struct hdac_bus *bus)
271 struct skl *skl = bus_to_skl(bus);
272 struct pci_dev *pci = to_pci_dev(bus->dev);
275 snd_hdac_ext_bus_link_power_down_all(bus);
277 ret = skl_suspend_dsp(skl);
281 snd_hdac_bus_stop_chip(bus);
282 update_pci_dword(pci, AZX_PCIREG_PGCTL,
283 AZX_PGCTL_LSRMD_MASK, AZX_PGCTL_LSRMD_MASK);
284 skl_enable_miscbdcge(bus->dev, false);
285 snd_hdac_bus_enter_link_reset(bus);
286 skl_enable_miscbdcge(bus->dev, true);
287 skl_cleanup_resources(skl);
292 static int _skl_resume(struct hdac_bus *bus)
294 struct skl *skl = bus_to_skl(bus);
297 skl_init_chip(bus, true);
299 return skl_resume_dsp(skl);
303 #ifdef CONFIG_PM_SLEEP
307 static int skl_suspend(struct device *dev)
309 struct pci_dev *pci = to_pci_dev(dev);
310 struct hdac_bus *bus = pci_get_drvdata(pci);
311 struct skl *skl = bus_to_skl(bus);
315 * Do not suspend if streams which are marked ignore suspend are
316 * running, we need to save the state for these and continue
318 if (skl->supend_active) {
319 /* turn off the links and stop the CORB/RIRB DMA if it is On */
320 snd_hdac_ext_bus_link_power_down_all(bus);
322 if (bus->cmd_dma_state)
323 snd_hdac_bus_stop_cmd_io(bus);
325 enable_irq_wake(bus->irq);
328 ret = _skl_suspend(bus);
331 skl->skl_sst->fw_loaded = false;
334 if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI)) {
335 ret = snd_hdac_display_power(bus, false);
338 "Cannot turn OFF display power on i915\n");
344 static int skl_resume(struct device *dev)
346 struct pci_dev *pci = to_pci_dev(dev);
347 struct hdac_bus *bus = pci_get_drvdata(pci);
348 struct skl *skl = bus_to_skl(bus);
349 struct hdac_ext_link *hlink = NULL;
352 /* Turned OFF in HDMI codec driver after codec reconfiguration */
353 if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI)) {
354 ret = snd_hdac_display_power(bus, true);
357 "Cannot turn on display power on i915\n");
363 * resume only when we are not in suspend active, otherwise need to
366 if (skl->supend_active) {
367 pci_restore_state(pci);
368 snd_hdac_ext_bus_link_power_up_all(bus);
369 disable_irq_wake(bus->irq);
371 * turn On the links which are On before active suspend
372 * and start the CORB/RIRB DMA if On before
375 list_for_each_entry(hlink, &bus->hlink_list, list) {
376 if (hlink->ref_count)
377 snd_hdac_ext_bus_link_power_up(hlink);
381 if (bus->cmd_dma_state)
382 snd_hdac_bus_init_cmd_io(bus);
384 ret = _skl_resume(bus);
386 /* turn off the links which are off before suspend */
387 list_for_each_entry(hlink, &bus->hlink_list, list) {
388 if (!hlink->ref_count)
389 snd_hdac_ext_bus_link_power_down(hlink);
392 if (!bus->cmd_dma_state)
393 snd_hdac_bus_stop_cmd_io(bus);
398 #endif /* CONFIG_PM_SLEEP */
401 static int skl_runtime_suspend(struct device *dev)
403 struct pci_dev *pci = to_pci_dev(dev);
404 struct hdac_bus *bus = pci_get_drvdata(pci);
406 dev_dbg(bus->dev, "in %s\n", __func__);
408 return _skl_suspend(bus);
411 static int skl_runtime_resume(struct device *dev)
413 struct pci_dev *pci = to_pci_dev(dev);
414 struct hdac_bus *bus = pci_get_drvdata(pci);
416 dev_dbg(bus->dev, "in %s\n", __func__);
418 return _skl_resume(bus);
420 #endif /* CONFIG_PM */
422 static const struct dev_pm_ops skl_pm = {
423 SET_SYSTEM_SLEEP_PM_OPS(skl_suspend, skl_resume)
424 SET_RUNTIME_PM_OPS(skl_runtime_suspend, skl_runtime_resume, NULL)
425 .suspend_late = skl_suspend_late,
431 static int skl_free(struct hdac_bus *bus)
433 struct skl *skl = bus_to_skl(bus);
435 skl->init_done = 0; /* to be sure */
437 snd_hdac_ext_stop_streams(bus);
440 free_irq(bus->irq, (void *)bus);
441 snd_hdac_bus_free_stream_pages(bus);
442 snd_hdac_stream_free_all(bus);
443 snd_hdac_link_free_all(bus);
446 iounmap(bus->remap_addr);
448 pci_release_regions(skl->pci);
449 pci_disable_device(skl->pci);
451 snd_hdac_ext_bus_exit(bus);
453 cancel_work_sync(&skl->probe_work);
454 if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI))
455 snd_hdac_i915_exit(bus);
461 * For each ssp there are 3 clocks (mclk/sclk/sclkfs).
462 * e.g. for ssp0, clocks will be named as
463 * "ssp0_mclk", "ssp0_sclk", "ssp0_sclkfs"
464 * So for skl+, there are 6 ssps, so 18 clocks will be created.
466 static struct skl_ssp_clk skl_ssp_clks[] = {
467 {.name = "ssp0_mclk"}, {.name = "ssp1_mclk"}, {.name = "ssp2_mclk"},
468 {.name = "ssp3_mclk"}, {.name = "ssp4_mclk"}, {.name = "ssp5_mclk"},
469 {.name = "ssp0_sclk"}, {.name = "ssp1_sclk"}, {.name = "ssp2_sclk"},
470 {.name = "ssp3_sclk"}, {.name = "ssp4_sclk"}, {.name = "ssp5_sclk"},
471 {.name = "ssp0_sclkfs"}, {.name = "ssp1_sclkfs"},
472 {.name = "ssp2_sclkfs"},
473 {.name = "ssp3_sclkfs"}, {.name = "ssp4_sclkfs"},
474 {.name = "ssp5_sclkfs"},
477 static struct snd_soc_acpi_mach *skl_find_hda_machine(struct skl *skl,
478 struct snd_soc_acpi_mach *machines)
480 struct hdac_bus *bus = skl_to_bus(skl);
481 struct snd_soc_acpi_mach *mach;
483 /* check if we have any codecs detected on bus */
484 if (bus->codec_mask == 0)
487 /* point to common table */
488 mach = snd_soc_acpi_intel_hda_machines;
490 /* all entries in the machine table use the same firmware */
491 mach->fw_filename = machines->fw_filename;
496 static int skl_find_machine(struct skl *skl, void *driver_data)
498 struct hdac_bus *bus = skl_to_bus(skl);
499 struct snd_soc_acpi_mach *mach = driver_data;
500 struct skl_machine_pdata *pdata;
502 mach = snd_soc_acpi_find_machine(mach);
504 dev_dbg(bus->dev, "No matching I2S machine driver found\n");
505 mach = skl_find_hda_machine(skl, driver_data);
507 dev_err(bus->dev, "No matching machine driver found\n");
513 skl->fw_name = mach->fw_filename;
517 skl->use_tplg_pcm = pdata->use_tplg_pcm;
518 pdata->dmic_num = skl_get_dmic_geo(skl);
524 static int skl_machine_device_register(struct skl *skl)
526 struct snd_soc_acpi_mach *mach = skl->mach;
527 struct hdac_bus *bus = skl_to_bus(skl);
528 struct skl_machine_pdata *pdata;
529 struct platform_device *pdev;
532 pdev = platform_device_alloc(mach->drv_name, -1);
534 dev_err(bus->dev, "platform device alloc failed\n");
538 ret = platform_device_add(pdev);
540 dev_err(bus->dev, "failed to add machine device\n");
541 platform_device_put(pdev);
546 pdata = (struct skl_machine_pdata *)mach->pdata;
547 pdata->platform = dev_name(bus->dev);
548 pdata->codec_mask = bus->codec_mask;
549 dev_set_drvdata(&pdev->dev, mach->pdata);
557 static void skl_machine_device_unregister(struct skl *skl)
560 platform_device_unregister(skl->i2s_dev);
563 static int skl_dmic_device_register(struct skl *skl)
565 struct hdac_bus *bus = skl_to_bus(skl);
566 struct platform_device *pdev;
569 /* SKL has one dmic port, so allocate dmic device for this */
570 pdev = platform_device_alloc("dmic-codec", -1);
572 dev_err(bus->dev, "failed to allocate dmic device\n");
576 ret = platform_device_add(pdev);
578 dev_err(bus->dev, "failed to add dmic device: %d\n", ret);
579 platform_device_put(pdev);
582 skl->dmic_dev = pdev;
587 static void skl_dmic_device_unregister(struct skl *skl)
590 platform_device_unregister(skl->dmic_dev);
593 static struct skl_clk_parent_src skl_clk_src[] = {
594 { .clk_id = SKL_XTAL, .name = "xtal" },
595 { .clk_id = SKL_CARDINAL, .name = "cardinal", .rate = 24576000 },
596 { .clk_id = SKL_PLL, .name = "pll", .rate = 96000000 },
599 struct skl_clk_parent_src *skl_get_parent_clk(u8 clk_id)
603 for (i = 0; i < ARRAY_SIZE(skl_clk_src); i++) {
604 if (skl_clk_src[i].clk_id == clk_id)
605 return &skl_clk_src[i];
611 static void init_skl_xtal_rate(int pci_id)
616 skl_clk_src[0].rate = 24000000;
620 skl_clk_src[0].rate = 19200000;
625 static int skl_clock_device_register(struct skl *skl)
627 struct platform_device_info pdevinfo = {NULL};
628 struct skl_clk_pdata *clk_pdata;
630 clk_pdata = devm_kzalloc(&skl->pci->dev, sizeof(*clk_pdata),
635 init_skl_xtal_rate(skl->pci->device);
637 clk_pdata->parent_clks = skl_clk_src;
638 clk_pdata->ssp_clks = skl_ssp_clks;
639 clk_pdata->num_clks = ARRAY_SIZE(skl_ssp_clks);
641 /* Query NHLT to fill the rates and parent */
642 skl_get_clks(skl, clk_pdata->ssp_clks);
643 clk_pdata->pvt_data = skl;
645 /* Register Platform device */
646 pdevinfo.parent = &skl->pci->dev;
648 pdevinfo.name = "skl-ssp-clk";
649 pdevinfo.data = clk_pdata;
650 pdevinfo.size_data = sizeof(*clk_pdata);
651 skl->clk_dev = platform_device_register_full(&pdevinfo);
652 return PTR_ERR_OR_ZERO(skl->clk_dev);
655 static void skl_clock_device_unregister(struct skl *skl)
658 platform_device_unregister(skl->clk_dev);
661 #define IDISP_INTEL_VENDOR_ID 0x80860000
664 * load the legacy codec driver
666 static void load_codec_module(struct hda_codec *codec)
669 char modalias[MODULE_NAME_LEN];
670 const char *mod = NULL;
672 snd_hdac_codec_modalias(&codec->core, modalias, sizeof(modalias));
674 dev_dbg(&codec->core.dev, "loading %s codec module\n", mod);
680 * Probe the given codec address
682 static int probe_codec(struct hdac_bus *bus, int addr)
684 unsigned int cmd = (addr << 28) | (AC_NODE_ROOT << 20) |
685 (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID;
686 unsigned int res = -1;
687 struct skl *skl = bus_to_skl(bus);
688 struct hdac_hda_priv *hda_codec;
689 struct hdac_device *hdev;
692 mutex_lock(&bus->cmd_mutex);
693 snd_hdac_bus_send_cmd(bus, cmd);
694 snd_hdac_bus_get_response(bus, addr, &res);
695 mutex_unlock(&bus->cmd_mutex);
698 dev_dbg(bus->dev, "codec #%d probed OK: %x\n", addr, res);
700 hda_codec = devm_kzalloc(&skl->pci->dev, sizeof(*hda_codec),
705 hda_codec->codec.bus = skl_to_hbus(skl);
706 hdev = &hda_codec->codec.core;
708 err = snd_hdac_ext_bus_device_init(bus, addr, hdev);
712 /* use legacy bus only for HDA codecs, idisp uses ext bus */
713 if ((res & 0xFFFF0000) != IDISP_INTEL_VENDOR_ID) {
714 hdev->type = HDA_DEV_LEGACY;
715 load_codec_module(&hda_codec->codec);
720 /* Codec initialization */
721 static void skl_codec_create(struct hdac_bus *bus)
725 max_slots = HDA_MAX_CODECS;
727 /* First try to probe all given codec slots */
728 for (c = 0; c < max_slots; c++) {
729 if ((bus->codec_mask & (1 << c))) {
730 if (probe_codec(bus, c) < 0) {
732 * Some BIOSen give you wrong codec addresses
736 "Codec #%d probe error; disabling it...\n", c);
737 bus->codec_mask &= ~(1 << c);
739 * More badly, accessing to a non-existing
740 * codec often screws up the controller bus,
741 * and disturbs the further communications.
742 * Thus if an error occurs during probing,
743 * better to reset the controller bus to get
744 * back to the sanity state.
746 snd_hdac_bus_stop_chip(bus);
747 skl_init_chip(bus, true);
753 static const struct hdac_bus_ops bus_core_ops = {
754 .command = snd_hdac_bus_send_cmd,
755 .get_response = snd_hdac_bus_get_response,
758 static int skl_i915_init(struct hdac_bus *bus)
763 * The HDMI codec is in GPU so we need to ensure that it is powered
764 * up and ready for probe
766 err = snd_hdac_i915_init(bus);
770 err = snd_hdac_display_power(bus, true);
772 dev_err(bus->dev, "Cannot turn on display power on i915\n");
777 static void skl_probe_work(struct work_struct *work)
779 struct skl *skl = container_of(work, struct skl, probe_work);
780 struct hdac_bus *bus = skl_to_bus(skl);
781 struct hdac_ext_link *hlink = NULL;
784 if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI)) {
785 err = skl_i915_init(bus);
790 err = skl_init_chip(bus, true);
792 dev_err(bus->dev, "Init chip failed with err: %d\n", err);
796 /* codec detection */
797 if (!bus->codec_mask)
798 dev_info(bus->dev, "no hda codecs found!\n");
800 /* create codec instances */
801 skl_codec_create(bus);
803 /* register platform dai and controls */
804 err = skl_platform_register(bus->dev);
806 dev_err(bus->dev, "platform register failed: %d\n", err);
811 err = skl_machine_device_register(skl);
813 dev_err(bus->dev, "machine register failed: %d\n", err);
818 if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI)) {
819 err = snd_hdac_display_power(bus, false);
821 dev_err(bus->dev, "Cannot turn off display power on i915\n");
822 skl_machine_device_unregister(skl);
828 * we are done probing so decrement link counts
830 list_for_each_entry(hlink, &bus->hlink_list, list)
831 snd_hdac_ext_bus_link_put(bus, hlink);
834 pm_runtime_put_noidle(bus->dev);
835 pm_runtime_allow(bus->dev);
841 if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI))
842 err = snd_hdac_display_power(bus, false);
848 static int skl_create(struct pci_dev *pci,
849 const struct hdac_io_ops *io_ops,
852 struct hdac_ext_bus_ops *ext_ops = NULL;
854 struct hdac_bus *bus;
855 struct hda_bus *hbus;
860 err = pci_enable_device(pci);
864 skl = devm_kzalloc(&pci->dev, sizeof(*skl), GFP_KERNEL);
866 pci_disable_device(pci);
870 hbus = skl_to_hbus(skl);
871 bus = skl_to_bus(skl);
873 #if IS_ENABLED(CONFIG_SND_SOC_HDAC_HDA)
874 ext_ops = snd_soc_hdac_hda_get_ops();
876 snd_hdac_ext_bus_init(bus, &pci->dev, &bus_core_ops, io_ops, ext_ops);
879 INIT_WORK(&skl->probe_work, skl_probe_work);
880 bus->bdl_pos_adj = 0;
882 mutex_init(&hbus->prepare_mutex);
884 hbus->mixer_assigned = -1;
885 hbus->modelname = "sklbus";
892 static int skl_first_init(struct hdac_bus *bus)
894 struct skl *skl = bus_to_skl(bus);
895 struct pci_dev *pci = skl->pci;
898 int cp_streams, pb_streams, start_idx;
900 err = pci_request_regions(pci, "Skylake HD audio");
904 bus->addr = pci_resource_start(pci, 0);
905 bus->remap_addr = pci_ioremap_bar(pci, 0);
906 if (bus->remap_addr == NULL) {
907 dev_err(bus->dev, "ioremap error\n");
911 snd_hdac_bus_reset_link(bus, true);
913 snd_hdac_bus_parse_capabilities(bus);
915 if (skl_acquire_irq(bus, 0) < 0)
919 synchronize_irq(bus->irq);
921 gcap = snd_hdac_chip_readw(bus, GCAP);
922 dev_dbg(bus->dev, "chipset global capabilities = 0x%x\n", gcap);
924 /* allow 64bit DMA address if supported by H/W */
925 if (!dma_set_mask(bus->dev, DMA_BIT_MASK(64))) {
926 dma_set_coherent_mask(bus->dev, DMA_BIT_MASK(64));
928 dma_set_mask(bus->dev, DMA_BIT_MASK(32));
929 dma_set_coherent_mask(bus->dev, DMA_BIT_MASK(32));
932 /* read number of streams from GCAP register */
933 cp_streams = (gcap >> 8) & 0x0f;
934 pb_streams = (gcap >> 12) & 0x0f;
936 if (!pb_streams && !cp_streams)
939 bus->num_streams = cp_streams + pb_streams;
941 /* initialize streams */
942 snd_hdac_ext_stream_init_all
943 (bus, 0, cp_streams, SNDRV_PCM_STREAM_CAPTURE);
944 start_idx = cp_streams;
945 snd_hdac_ext_stream_init_all
946 (bus, start_idx, pb_streams, SNDRV_PCM_STREAM_PLAYBACK);
948 err = snd_hdac_bus_alloc_stream_pages(bus);
952 /* initialize chip */
955 return skl_init_chip(bus, true);
958 static int skl_probe(struct pci_dev *pci,
959 const struct pci_device_id *pci_id)
962 struct hdac_bus *bus = NULL;
965 /* we use ext core ops, so provide NULL for ops here */
966 err = skl_create(pci, NULL, &skl);
970 bus = skl_to_bus(skl);
972 err = skl_first_init(bus);
976 skl->pci_id = pci->device;
978 device_disable_async_suspend(bus->dev);
980 skl->nhlt = skl_nhlt_init(bus->dev);
982 if (skl->nhlt == NULL) {
987 err = skl_nhlt_create_sysfs(skl);
991 skl_nhlt_update_topology_bin(skl);
993 pci_set_drvdata(skl->pci, bus);
995 /* check if dsp is there */
997 /* create device for dsp clk */
998 err = skl_clock_device_register(skl);
1002 err = skl_find_machine(skl, (void *)pci_id->driver_data);
1006 err = skl_init_dsp(skl);
1008 dev_dbg(bus->dev, "error failed to register dsp\n");
1011 skl->skl_sst->enable_miscbdcge = skl_enable_miscbdcge;
1012 skl->skl_sst->clock_power_gating = skl_clock_power_gating;
1015 snd_hdac_ext_bus_get_ml_capabilities(bus);
1017 snd_hdac_bus_stop_chip(bus);
1019 /* create device for soc dmic */
1020 err = skl_dmic_device_register(skl);
1024 schedule_work(&skl->probe_work);
1031 skl_clock_device_unregister(skl);
1033 skl_nhlt_free(skl->nhlt);
1040 static void skl_shutdown(struct pci_dev *pci)
1042 struct hdac_bus *bus = pci_get_drvdata(pci);
1043 struct hdac_stream *s;
1044 struct hdac_ext_stream *stream;
1050 skl = bus_to_skl(bus);
1052 if (!skl->init_done)
1055 snd_hdac_ext_stop_streams(bus);
1056 list_for_each_entry(s, &bus->stream_list, list) {
1057 stream = stream_to_hdac_ext_stream(s);
1058 snd_hdac_ext_stream_decouple(bus, stream, false);
1061 snd_hdac_bus_stop_chip(bus);
1064 static void skl_remove(struct pci_dev *pci)
1066 struct hdac_bus *bus = pci_get_drvdata(pci);
1067 struct skl *skl = bus_to_skl(bus);
1069 release_firmware(skl->tplg);
1071 pm_runtime_get_noresume(&pci->dev);
1073 /* codec removal, invoke bus_device_remove */
1074 snd_hdac_ext_bus_device_remove(bus);
1076 skl->debugfs = NULL;
1077 skl_platform_unregister(&pci->dev);
1079 skl_machine_device_unregister(skl);
1080 skl_dmic_device_unregister(skl);
1081 skl_clock_device_unregister(skl);
1082 skl_nhlt_remove_sysfs(skl);
1083 skl_nhlt_free(skl->nhlt);
1085 dev_set_drvdata(&pci->dev, NULL);
1089 static const struct pci_device_id skl_ids[] = {
1090 /* Sunrise Point-LP */
1091 { PCI_DEVICE(0x8086, 0x9d70),
1092 .driver_data = (unsigned long)&snd_soc_acpi_intel_skl_machines},
1094 { PCI_DEVICE(0x8086, 0x5a98),
1095 .driver_data = (unsigned long)&snd_soc_acpi_intel_bxt_machines},
1097 { PCI_DEVICE(0x8086, 0x9D71),
1098 .driver_data = (unsigned long)&snd_soc_acpi_intel_kbl_machines},
1100 { PCI_DEVICE(0x8086, 0x3198),
1101 .driver_data = (unsigned long)&snd_soc_acpi_intel_glk_machines},
1103 { PCI_DEVICE(0x8086, 0x9dc8),
1104 .driver_data = (unsigned long)&snd_soc_acpi_intel_cnl_machines},
1107 MODULE_DEVICE_TABLE(pci, skl_ids);
1109 /* pci_driver definition */
1110 static struct pci_driver skl_driver = {
1111 .name = KBUILD_MODNAME,
1112 .id_table = skl_ids,
1114 .remove = skl_remove,
1115 .shutdown = skl_shutdown,
1120 module_pci_driver(skl_driver);
1122 MODULE_LICENSE("GPL v2");
1123 MODULE_DESCRIPTION("Intel Skylake ASoC HDA driver");