forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-31 f70575805708cabdedea7498aaa3f710fde4d920
kernel/sound/soc/intel/skylake/skl.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * skl.c - Implementation of ASoC Intel SKL HD Audio driver
34 *
....@@ -8,15 +9,6 @@
89 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
910 * PeiSen Hou <pshou@realtek.com.tw>
1011 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
2012 *
2113 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2214 */
....@@ -33,9 +25,19 @@
3325 #include <sound/hda_register.h>
3426 #include <sound/hdaudio.h>
3527 #include <sound/hda_i915.h>
28
+#include <sound/hda_codec.h>
29
+#include <sound/intel-nhlt.h>
30
+#include <sound/intel-dsp-config.h>
3631 #include "skl.h"
3732 #include "skl-sst-dsp.h"
3833 #include "skl-sst-ipc.h"
34
+
35
+#if IS_ENABLED(CONFIG_SND_SOC_INTEL_SKYLAKE_HDAUDIO_CODEC)
36
+#include "../../../soc/codecs/hdac_hda.h"
37
+#endif
38
+static int skl_pci_binding;
39
+module_param_named(pci_binding, skl_pci_binding, int, 0444);
40
+MODULE_PARM_DESC(pci_binding, "PCI binding (0=auto, 1=only legacy, 2=only asoc");
3941
4042 /*
4143 * initialize the PCI registers
....@@ -51,7 +53,7 @@
5153 pci_write_config_byte(pci, reg, data);
5254 }
5355
54
-static void skl_init_pci(struct skl *skl)
56
+static void skl_init_pci(struct skl_dev *skl)
5557 {
5658 struct hdac_bus *bus = skl_to_bus(skl);
5759
....@@ -128,14 +130,16 @@
128130 struct hdac_ext_link *hlink;
129131 int ret;
130132
133
+ snd_hdac_set_codec_wakeup(bus, true);
131134 skl_enable_miscbdcge(bus->dev, false);
132135 ret = snd_hdac_bus_init_chip(bus, full_reset);
133136
134137 /* Reset stream-to-link mapping */
135138 list_for_each_entry(hlink, &bus->hlink_list, list)
136
- bus->io_ops->reg_writel(0, hlink->ml_addr + AZX_REG_ML_LOSIDV);
139
+ writel(0, hlink->ml_addr + AZX_REG_ML_LOSIDV);
137140
138141 skl_enable_miscbdcge(bus->dev, true);
142
+ snd_hdac_set_codec_wakeup(bus, false);
139143
140144 return ret;
141145 }
....@@ -183,6 +187,25 @@
183187
184188 dev_dbg(bus->dev, "D0I3C register = 0x%x\n",
185189 snd_hdac_chip_readb(bus, VS_D0I3C));
190
+}
191
+
192
+/**
193
+ * skl_dum_set - set DUM bit in EM2 register
194
+ * @bus: HD-audio core bus
195
+ *
196
+ * Addresses incorrect position reporting for capture streams.
197
+ * Used on device power up.
198
+ */
199
+static void skl_dum_set(struct hdac_bus *bus)
200
+{
201
+ /* For the DUM bit to be set, CRST needs to be out of reset state */
202
+ if (!(snd_hdac_chip_readb(bus, GCTL) & AZX_GCTL_RESET)) {
203
+ skl_enable_miscbdcge(bus->dev, false);
204
+ snd_hdac_bus_exit_link_reset(bus);
205
+ skl_enable_miscbdcge(bus->dev, true);
206
+ }
207
+
208
+ snd_hdac_chip_updatel(bus, VS_EM2, AZX_VS_EM2_DUM, AZX_VS_EM2_DUM);
186209 }
187210
188211 /* called from IRQ */
....@@ -234,7 +257,7 @@
234257
235258 static int skl_acquire_irq(struct hdac_bus *bus, int do_disconnect)
236259 {
237
- struct skl *skl = bus_to_skl(bus);
260
+ struct skl_dev *skl = bus_to_skl(bus);
238261 int ret;
239262
240263 ret = request_threaded_irq(skl->pci->irq, skl_interrupt,
....@@ -258,7 +281,7 @@
258281 {
259282 struct pci_dev *pci = to_pci_dev(dev);
260283 struct hdac_bus *bus = pci_get_drvdata(pci);
261
- struct skl *skl = bus_to_skl(bus);
284
+ struct skl_dev *skl = bus_to_skl(bus);
262285
263286 return skl_suspend_late_dsp(skl);
264287 }
....@@ -266,7 +289,7 @@
266289 #ifdef CONFIG_PM
267290 static int _skl_suspend(struct hdac_bus *bus)
268291 {
269
- struct skl *skl = bus_to_skl(bus);
292
+ struct skl_dev *skl = bus_to_skl(bus);
270293 struct pci_dev *pci = to_pci_dev(bus->dev);
271294 int ret;
272295
....@@ -289,9 +312,10 @@
289312
290313 static int _skl_resume(struct hdac_bus *bus)
291314 {
292
- struct skl *skl = bus_to_skl(bus);
315
+ struct skl_dev *skl = bus_to_skl(bus);
293316
294317 skl_init_pci(skl);
318
+ skl_dum_set(bus);
295319 skl_init_chip(bus, true);
296320
297321 return skl_resume_dsp(skl);
....@@ -306,8 +330,8 @@
306330 {
307331 struct pci_dev *pci = to_pci_dev(dev);
308332 struct hdac_bus *bus = pci_get_drvdata(pci);
309
- struct skl *skl = bus_to_skl(bus);
310
- int ret = 0;
333
+ struct skl_dev *skl = bus_to_skl(bus);
334
+ int ret;
311335
312336 /*
313337 * Do not suspend if streams which are marked ignore suspend are
....@@ -326,36 +350,19 @@
326350 ret = _skl_suspend(bus);
327351 if (ret < 0)
328352 return ret;
329
- skl->skl_sst->fw_loaded = false;
353
+ skl->fw_loaded = false;
330354 }
331355
332
- if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI)) {
333
- ret = snd_hdac_display_power(bus, false);
334
- if (ret < 0)
335
- dev_err(bus->dev,
336
- "Cannot turn OFF display power on i915\n");
337
- }
338
-
339
- return ret;
356
+ return 0;
340357 }
341358
342359 static int skl_resume(struct device *dev)
343360 {
344361 struct pci_dev *pci = to_pci_dev(dev);
345362 struct hdac_bus *bus = pci_get_drvdata(pci);
346
- struct skl *skl = bus_to_skl(bus);
347
- struct hdac_ext_link *hlink = NULL;
363
+ struct skl_dev *skl = bus_to_skl(bus);
364
+ struct hdac_ext_link *hlink;
348365 int ret;
349
-
350
- /* Turned OFF in HDMI codec driver after codec reconfiguration */
351
- if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI)) {
352
- ret = snd_hdac_display_power(bus, true);
353
- if (ret < 0) {
354
- dev_err(bus->dev,
355
- "Cannot turn on display power on i915\n");
356
- return ret;
357
- }
358
- }
359366
360367 /*
361368 * resume only when we are not in suspend active, otherwise need to
....@@ -428,11 +435,11 @@
428435 */
429436 static int skl_free(struct hdac_bus *bus)
430437 {
431
- struct skl *skl = bus_to_skl(bus);
438
+ struct skl_dev *skl = bus_to_skl(bus);
432439
433440 skl->init_done = 0; /* to be sure */
434441
435
- snd_hdac_ext_stop_streams(bus);
442
+ snd_hdac_stop_streams_and_chip(bus);
436443
437444 if (bus->irq >= 0)
438445 free_irq(bus->irq, (void *)bus);
....@@ -448,9 +455,10 @@
448455
449456 snd_hdac_ext_bus_exit(bus);
450457
451
- cancel_work_sync(&skl->probe_work);
452
- if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI))
458
+ if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI)) {
459
+ snd_hdac_display_power(bus, HDA_CODEC_IDX_CONTROLLER, false);
453460 snd_hdac_i915_exit(bus);
461
+ }
454462
455463 return 0;
456464 }
....@@ -472,16 +480,34 @@
472480 {.name = "ssp5_sclkfs"},
473481 };
474482
475
-static int skl_find_machine(struct skl *skl, void *driver_data)
483
+static struct snd_soc_acpi_mach *skl_find_hda_machine(struct skl_dev *skl,
484
+ struct snd_soc_acpi_mach *machines)
485
+{
486
+ struct snd_soc_acpi_mach *mach;
487
+
488
+ /* point to common table */
489
+ mach = snd_soc_acpi_intel_hda_machines;
490
+
491
+ /* all entries in the machine table use the same firmware */
492
+ mach->fw_filename = machines->fw_filename;
493
+
494
+ return mach;
495
+}
496
+
497
+static int skl_find_machine(struct skl_dev *skl, void *driver_data)
476498 {
477499 struct hdac_bus *bus = skl_to_bus(skl);
478500 struct snd_soc_acpi_mach *mach = driver_data;
479501 struct skl_machine_pdata *pdata;
480502
481503 mach = snd_soc_acpi_find_machine(mach);
482
- if (mach == NULL) {
483
- dev_err(bus->dev, "No matching machine driver found\n");
484
- return -ENODEV;
504
+ if (!mach) {
505
+ dev_dbg(bus->dev, "No matching I2S machine driver found\n");
506
+ mach = skl_find_hda_machine(skl, driver_data);
507
+ if (!mach) {
508
+ dev_err(bus->dev, "No matching machine driver found\n");
509
+ return -ENODEV;
510
+ }
485511 }
486512
487513 skl->mach = mach;
....@@ -490,16 +516,18 @@
490516
491517 if (pdata) {
492518 skl->use_tplg_pcm = pdata->use_tplg_pcm;
493
- pdata->dmic_num = skl_get_dmic_geo(skl);
519
+ mach->mach_params.dmic_num =
520
+ intel_nhlt_get_dmic_geo(&skl->pci->dev,
521
+ skl->nhlt);
494522 }
495523
496524 return 0;
497525 }
498526
499
-static int skl_machine_device_register(struct skl *skl)
527
+static int skl_machine_device_register(struct skl_dev *skl)
500528 {
501
- struct hdac_bus *bus = skl_to_bus(skl);
502529 struct snd_soc_acpi_mach *mach = skl->mach;
530
+ struct hdac_bus *bus = skl_to_bus(skl);
503531 struct platform_device *pdev;
504532 int ret;
505533
....@@ -509,6 +537,16 @@
509537 return -EIO;
510538 }
511539
540
+ mach->mach_params.platform = dev_name(bus->dev);
541
+ mach->mach_params.codec_mask = bus->codec_mask;
542
+
543
+ ret = platform_device_add_data(pdev, (const void *)mach, sizeof(*mach));
544
+ if (ret) {
545
+ dev_err(bus->dev, "failed to add machine device platform data\n");
546
+ platform_device_put(pdev);
547
+ return ret;
548
+ }
549
+
512550 ret = platform_device_add(pdev);
513551 if (ret) {
514552 dev_err(bus->dev, "failed to add machine device\n");
....@@ -516,21 +554,19 @@
516554 return -EIO;
517555 }
518556
519
- if (mach->pdata)
520
- dev_set_drvdata(&pdev->dev, mach->pdata);
521557
522558 skl->i2s_dev = pdev;
523559
524560 return 0;
525561 }
526562
527
-static void skl_machine_device_unregister(struct skl *skl)
563
+static void skl_machine_device_unregister(struct skl_dev *skl)
528564 {
529565 if (skl->i2s_dev)
530566 platform_device_unregister(skl->i2s_dev);
531567 }
532568
533
-static int skl_dmic_device_register(struct skl *skl)
569
+static int skl_dmic_device_register(struct skl_dev *skl)
534570 {
535571 struct hdac_bus *bus = skl_to_bus(skl);
536572 struct platform_device *pdev;
....@@ -554,7 +590,7 @@
554590 return 0;
555591 }
556592
557
-static void skl_dmic_device_unregister(struct skl *skl)
593
+static void skl_dmic_device_unregister(struct skl_dev *skl)
558594 {
559595 if (skl->dmic_dev)
560596 platform_device_unregister(skl->dmic_dev);
....@@ -592,10 +628,13 @@
592628 }
593629 }
594630
595
-static int skl_clock_device_register(struct skl *skl)
631
+static int skl_clock_device_register(struct skl_dev *skl)
596632 {
597633 struct platform_device_info pdevinfo = {NULL};
598634 struct skl_clk_pdata *clk_pdata;
635
+
636
+ if (!skl->nhlt)
637
+ return 0;
599638
600639 clk_pdata = devm_kzalloc(&skl->pci->dev, sizeof(*clk_pdata),
601640 GFP_KERNEL);
....@@ -622,11 +661,33 @@
622661 return PTR_ERR_OR_ZERO(skl->clk_dev);
623662 }
624663
625
-static void skl_clock_device_unregister(struct skl *skl)
664
+static void skl_clock_device_unregister(struct skl_dev *skl)
626665 {
627666 if (skl->clk_dev)
628667 platform_device_unregister(skl->clk_dev);
629668 }
669
+
670
+#if IS_ENABLED(CONFIG_SND_SOC_INTEL_SKYLAKE_HDAUDIO_CODEC)
671
+
672
+#define IDISP_INTEL_VENDOR_ID 0x80860000
673
+
674
+/*
675
+ * load the legacy codec driver
676
+ */
677
+static void load_codec_module(struct hda_codec *codec)
678
+{
679
+#ifdef MODULE
680
+ char modalias[MODULE_NAME_LEN];
681
+ const char *mod = NULL;
682
+
683
+ snd_hdac_codec_modalias(&codec->core, modalias, sizeof(modalias));
684
+ mod = modalias;
685
+ dev_dbg(&codec->core.dev, "loading %s codec module\n", mod);
686
+ request_module(mod);
687
+#endif
688
+}
689
+
690
+#endif /* CONFIG_SND_SOC_INTEL_SKYLAKE_HDAUDIO_CODEC */
630691
631692 /*
632693 * Probe the given codec address
....@@ -636,7 +697,11 @@
636697 unsigned int cmd = (addr << 28) | (AC_NODE_ROOT << 20) |
637698 (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID;
638699 unsigned int res = -1;
639
- struct skl *skl = bus_to_skl(bus);
700
+ struct skl_dev *skl = bus_to_skl(bus);
701
+#if IS_ENABLED(CONFIG_SND_SOC_INTEL_SKYLAKE_HDAUDIO_CODEC)
702
+ struct hdac_hda_priv *hda_codec;
703
+ int err;
704
+#endif
640705 struct hdac_device *hdev;
641706
642707 mutex_lock(&bus->cmd_mutex);
....@@ -645,13 +710,34 @@
645710 mutex_unlock(&bus->cmd_mutex);
646711 if (res == -1)
647712 return -EIO;
648
- dev_dbg(bus->dev, "codec #%d probed OK\n", addr);
713
+ dev_dbg(bus->dev, "codec #%d probed OK: %x\n", addr, res);
649714
715
+#if IS_ENABLED(CONFIG_SND_SOC_INTEL_SKYLAKE_HDAUDIO_CODEC)
716
+ hda_codec = devm_kzalloc(&skl->pci->dev, sizeof(*hda_codec),
717
+ GFP_KERNEL);
718
+ if (!hda_codec)
719
+ return -ENOMEM;
720
+
721
+ hda_codec->codec.bus = skl_to_hbus(skl);
722
+ hdev = &hda_codec->codec.core;
723
+
724
+ err = snd_hdac_ext_bus_device_init(bus, addr, hdev, HDA_DEV_ASOC);
725
+ if (err < 0)
726
+ return err;
727
+
728
+ /* use legacy bus only for HDA codecs, idisp uses ext bus */
729
+ if ((res & 0xFFFF0000) != IDISP_INTEL_VENDOR_ID) {
730
+ hdev->type = HDA_DEV_LEGACY;
731
+ load_codec_module(&hda_codec->codec);
732
+ }
733
+ return 0;
734
+#else
650735 hdev = devm_kzalloc(&skl->pci->dev, sizeof(*hdev), GFP_KERNEL);
651736 if (!hdev)
652737 return -ENOMEM;
653738
654
- return snd_hdac_ext_bus_device_init(bus, addr, hdev);
739
+ return snd_hdac_ext_bus_device_init(bus, addr, hdev, HDA_DEV_ASOC);
740
+#endif /* CONFIG_SND_SOC_INTEL_SKYLAKE_HDAUDIO_CODEC */
655741 }
656742
657743 /* Codec initialization */
....@@ -687,11 +773,6 @@
687773 }
688774 }
689775
690
-static const struct hdac_bus_ops bus_core_ops = {
691
- .command = snd_hdac_bus_send_cmd,
692
- .get_response = snd_hdac_bus_get_response,
693
-};
694
-
695776 static int skl_i915_init(struct hdac_bus *bus)
696777 {
697778 int err;
....@@ -704,18 +785,16 @@
704785 if (err < 0)
705786 return err;
706787
707
- err = snd_hdac_display_power(bus, true);
708
- if (err < 0)
709
- dev_err(bus->dev, "Cannot turn on display power on i915\n");
788
+ snd_hdac_display_power(bus, HDA_CODEC_IDX_CONTROLLER, true);
710789
711
- return err;
790
+ return 0;
712791 }
713792
714793 static void skl_probe_work(struct work_struct *work)
715794 {
716
- struct skl *skl = container_of(work, struct skl, probe_work);
795
+ struct skl_dev *skl = container_of(work, struct skl_dev, probe_work);
717796 struct hdac_bus *bus = skl_to_bus(skl);
718
- struct hdac_ext_link *hlink = NULL;
797
+ struct hdac_ext_link *hlink;
719798 int err;
720799
721800 if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI)) {
....@@ -723,6 +802,9 @@
723802 if (err < 0)
724803 return;
725804 }
805
+
806
+ skl_init_pci(skl);
807
+ skl_dum_set(bus);
726808
727809 err = skl_init_chip(bus, true);
728810 if (err < 0) {
....@@ -741,15 +823,13 @@
741823 err = skl_platform_register(bus->dev);
742824 if (err < 0) {
743825 dev_err(bus->dev, "platform register failed: %d\n", err);
744
- return;
826
+ goto out_err;
745827 }
746828
747
- if (bus->ppcap) {
748
- err = skl_machine_device_register(skl);
749
- if (err < 0) {
750
- dev_err(bus->dev, "machine register failed: %d\n", err);
751
- goto out_err;
752
- }
829
+ err = skl_machine_device_register(skl);
830
+ if (err < 0) {
831
+ dev_err(bus->dev, "machine register failed: %d\n", err);
832
+ goto out_err;
753833 }
754834
755835 /*
....@@ -758,14 +838,8 @@
758838 list_for_each_entry(hlink, &bus->hlink_list, list)
759839 snd_hdac_ext_bus_link_put(bus, hlink);
760840
761
- if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI)) {
762
- err = snd_hdac_display_power(bus, false);
763
- if (err < 0) {
764
- dev_err(bus->dev, "Cannot turn off display power on i915\n");
765
- skl_machine_device_unregister(skl);
766
- return;
767
- }
768
- }
841
+ if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI))
842
+ snd_hdac_display_power(bus, HDA_CODEC_IDX_CONTROLLER, false);
769843
770844 /* configure PM */
771845 pm_runtime_put_noidle(bus->dev);
....@@ -776,19 +850,19 @@
776850
777851 out_err:
778852 if (IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI))
779
- err = snd_hdac_display_power(bus, false);
853
+ snd_hdac_display_power(bus, HDA_CODEC_IDX_CONTROLLER, false);
780854 }
781855
782856 /*
783857 * constructor
784858 */
785859 static int skl_create(struct pci_dev *pci,
786
- const struct hdac_io_ops *io_ops,
787
- struct skl **rskl)
860
+ struct skl_dev **rskl)
788861 {
789
- struct skl *skl;
862
+ struct hdac_ext_bus_ops *ext_ops = NULL;
863
+ struct skl_dev *skl;
790864 struct hdac_bus *bus;
791
-
865
+ struct hda_bus *hbus;
792866 int err;
793867
794868 *rskl = NULL;
....@@ -803,12 +877,25 @@
803877 return -ENOMEM;
804878 }
805879
880
+ hbus = skl_to_hbus(skl);
806881 bus = skl_to_bus(skl);
807
- snd_hdac_ext_bus_init(bus, &pci->dev, &bus_core_ops, io_ops, NULL);
882
+
883
+ INIT_LIST_HEAD(&skl->ppl_list);
884
+ INIT_LIST_HEAD(&skl->bind_list);
885
+
886
+#if IS_ENABLED(CONFIG_SND_SOC_INTEL_SKYLAKE_HDAUDIO_CODEC)
887
+ ext_ops = snd_soc_hdac_hda_get_ops();
888
+#endif
889
+ snd_hdac_ext_bus_init(bus, &pci->dev, NULL, ext_ops);
808890 bus->use_posbuf = 1;
809891 skl->pci = pci;
810892 INIT_WORK(&skl->probe_work, skl_probe_work);
811893 bus->bdl_pos_adj = 0;
894
+
895
+ mutex_init(&hbus->prepare_mutex);
896
+ hbus->pci = pci;
897
+ hbus->mixer_assigned = -1;
898
+ hbus->modelname = "sklbus";
812899
813900 *rskl = skl;
814901
....@@ -817,7 +904,7 @@
817904
818905 static int skl_first_init(struct hdac_bus *bus)
819906 {
820
- struct skl *skl = bus_to_skl(bus);
907
+ struct skl_dev *skl = bus_to_skl(bus);
821908 struct pci_dev *pci = skl->pci;
822909 int err;
823910 unsigned short gcap;
....@@ -834,9 +921,13 @@
834921 return -ENXIO;
835922 }
836923
837
- snd_hdac_bus_reset_link(bus, true);
838
-
839924 snd_hdac_bus_parse_capabilities(bus);
925
+
926
+ /* check if PPCAP exists */
927
+ if (!bus->ppcap) {
928
+ dev_err(bus->dev, "bus ppcap not set, HDAudio or DSP not present?\n");
929
+ return -ENODEV;
930
+ }
840931
841932 if (skl_acquire_irq(bus, 0) < 0)
842933 return -EBUSY;
....@@ -847,6 +938,17 @@
847938 gcap = snd_hdac_chip_readw(bus, GCAP);
848939 dev_dbg(bus->dev, "chipset global capabilities = 0x%x\n", gcap);
849940
941
+ /* read number of streams from GCAP register */
942
+ cp_streams = (gcap >> 8) & 0x0f;
943
+ pb_streams = (gcap >> 12) & 0x0f;
944
+
945
+ if (!pb_streams && !cp_streams) {
946
+ dev_err(bus->dev, "no streams found in GCAP definitions?\n");
947
+ return -EIO;
948
+ }
949
+
950
+ bus->num_streams = cp_streams + pb_streams;
951
+
850952 /* allow 64bit DMA address if supported by H/W */
851953 if (!dma_set_mask(bus->dev, DMA_BIT_MASK(64))) {
852954 dma_set_coherent_mask(bus->dev, DMA_BIT_MASK(64));
....@@ -854,15 +956,6 @@
854956 dma_set_mask(bus->dev, DMA_BIT_MASK(32));
855957 dma_set_coherent_mask(bus->dev, DMA_BIT_MASK(32));
856958 }
857
-
858
- /* read number of streams from GCAP register */
859
- cp_streams = (gcap >> 8) & 0x0f;
860
- pb_streams = (gcap >> 12) & 0x0f;
861
-
862
- if (!pb_streams && !cp_streams)
863
- return -EIO;
864
-
865
- bus->num_streams = cp_streams + pb_streams;
866959
867960 /* initialize streams */
868961 snd_hdac_ext_stream_init_all
....@@ -875,77 +968,105 @@
875968 if (err < 0)
876969 return err;
877970
878
- /* initialize chip */
879
- skl_init_pci(skl);
880
-
881
- return skl_init_chip(bus, true);
971
+ return 0;
882972 }
883973
884974 static int skl_probe(struct pci_dev *pci,
885975 const struct pci_device_id *pci_id)
886976 {
887
- struct skl *skl;
977
+ struct skl_dev *skl;
888978 struct hdac_bus *bus = NULL;
889979 int err;
890980
981
+ switch (skl_pci_binding) {
982
+ case SND_SKL_PCI_BIND_AUTO:
983
+ err = snd_intel_dsp_driver_probe(pci);
984
+ if (err != SND_INTEL_DSP_DRIVER_ANY &&
985
+ err != SND_INTEL_DSP_DRIVER_SST)
986
+ return -ENODEV;
987
+ break;
988
+ case SND_SKL_PCI_BIND_LEGACY:
989
+ dev_info(&pci->dev, "Module parameter forced binding with HDAudio legacy, aborting probe\n");
990
+ return -ENODEV;
991
+ case SND_SKL_PCI_BIND_ASOC:
992
+ dev_info(&pci->dev, "Module parameter forced binding with SKL driver, bypassed detection logic\n");
993
+ break;
994
+ default:
995
+ dev_err(&pci->dev, "invalid value for skl_pci_binding module parameter, ignored\n");
996
+ break;
997
+ }
998
+
891999 /* we use ext core ops, so provide NULL for ops here */
892
- err = skl_create(pci, NULL, &skl);
1000
+ err = skl_create(pci, &skl);
8931001 if (err < 0)
8941002 return err;
8951003
8961004 bus = skl_to_bus(skl);
8971005
8981006 err = skl_first_init(bus);
899
- if (err < 0)
1007
+ if (err < 0) {
1008
+ dev_err(bus->dev, "skl_first_init failed with err: %d\n", err);
9001009 goto out_free;
1010
+ }
9011011
9021012 skl->pci_id = pci->device;
9031013
9041014 device_disable_async_suspend(bus->dev);
9051015
906
- skl->nhlt = skl_nhlt_init(bus->dev);
1016
+ skl->nhlt = intel_nhlt_init(bus->dev);
9071017
9081018 if (skl->nhlt == NULL) {
1019
+#if !IS_ENABLED(CONFIG_SND_SOC_INTEL_SKYLAKE_HDAUDIO_CODEC)
1020
+ dev_err(bus->dev, "no nhlt info found\n");
9091021 err = -ENODEV;
9101022 goto out_free;
1023
+#else
1024
+ dev_warn(bus->dev, "no nhlt info found, continuing to try to enable HDAudio codec\n");
1025
+#endif
1026
+ } else {
1027
+
1028
+ err = skl_nhlt_create_sysfs(skl);
1029
+ if (err < 0) {
1030
+ dev_err(bus->dev, "skl_nhlt_create_sysfs failed with err: %d\n", err);
1031
+ goto out_nhlt_free;
1032
+ }
1033
+
1034
+ skl_nhlt_update_topology_bin(skl);
1035
+
1036
+ /* create device for dsp clk */
1037
+ err = skl_clock_device_register(skl);
1038
+ if (err < 0) {
1039
+ dev_err(bus->dev, "skl_clock_device_register failed with err: %d\n", err);
1040
+ goto out_clk_free;
1041
+ }
9111042 }
912
-
913
- err = skl_nhlt_create_sysfs(skl);
914
- if (err < 0)
915
- goto out_nhlt_free;
916
-
917
- skl_nhlt_update_topology_bin(skl);
9181043
9191044 pci_set_drvdata(skl->pci, bus);
9201045
921
- /* check if dsp is there */
922
- if (bus->ppcap) {
923
- /* create device for dsp clk */
924
- err = skl_clock_device_register(skl);
925
- if (err < 0)
926
- goto out_clk_free;
9271046
928
- err = skl_find_machine(skl, (void *)pci_id->driver_data);
929
- if (err < 0)
930
- goto out_nhlt_free;
931
-
932
- err = skl_init_dsp(skl);
933
- if (err < 0) {
934
- dev_dbg(bus->dev, "error failed to register dsp\n");
935
- goto out_nhlt_free;
936
- }
937
- skl->skl_sst->enable_miscbdcge = skl_enable_miscbdcge;
938
- skl->skl_sst->clock_power_gating = skl_clock_power_gating;
1047
+ err = skl_find_machine(skl, (void *)pci_id->driver_data);
1048
+ if (err < 0) {
1049
+ dev_err(bus->dev, "skl_find_machine failed with err: %d\n", err);
1050
+ goto out_nhlt_free;
9391051 }
1052
+
1053
+ err = skl_init_dsp(skl);
1054
+ if (err < 0) {
1055
+ dev_dbg(bus->dev, "error failed to register dsp\n");
1056
+ goto out_nhlt_free;
1057
+ }
1058
+ skl->enable_miscbdcge = skl_enable_miscbdcge;
1059
+ skl->clock_power_gating = skl_clock_power_gating;
1060
+
9401061 if (bus->mlcap)
9411062 snd_hdac_ext_bus_get_ml_capabilities(bus);
9421063
943
- snd_hdac_bus_stop_chip(bus);
944
-
9451064 /* create device for soc dmic */
9461065 err = skl_dmic_device_register(skl);
947
- if (err < 0)
1066
+ if (err < 0) {
1067
+ dev_err(bus->dev, "skl_dmic_device_register failed with err: %d\n", err);
9481068 goto out_dsp_free;
1069
+ }
9491070
9501071 schedule_work(&skl->probe_work);
9511072
....@@ -956,7 +1077,8 @@
9561077 out_clk_free:
9571078 skl_clock_device_unregister(skl);
9581079 out_nhlt_free:
959
- skl_nhlt_free(skl->nhlt);
1080
+ if (skl->nhlt)
1081
+ intel_nhlt_free(skl->nhlt);
9601082 out_free:
9611083 skl_free(bus);
9621084
....@@ -968,7 +1090,7 @@
9681090 struct hdac_bus *bus = pci_get_drvdata(pci);
9691091 struct hdac_stream *s;
9701092 struct hdac_ext_stream *stream;
971
- struct skl *skl;
1093
+ struct skl_dev *skl;
9721094
9731095 if (!bus)
9741096 return;
....@@ -978,7 +1100,10 @@
9781100 if (!skl->init_done)
9791101 return;
9801102
981
- snd_hdac_ext_stop_streams(bus);
1103
+ snd_hdac_stop_streams(bus);
1104
+ snd_hdac_ext_bus_link_power_down_all(bus);
1105
+ skl_dsp_sleep(skl->dsp);
1106
+
9821107 list_for_each_entry(s, &bus->stream_list, list) {
9831108 stream = stream_to_hdac_ext_stream(s);
9841109 snd_hdac_ext_stream_decouple(bus, stream, false);
....@@ -990,44 +1115,69 @@
9901115 static void skl_remove(struct pci_dev *pci)
9911116 {
9921117 struct hdac_bus *bus = pci_get_drvdata(pci);
993
- struct skl *skl = bus_to_skl(bus);
1118
+ struct skl_dev *skl = bus_to_skl(bus);
9941119
995
- release_firmware(skl->tplg);
1120
+ cancel_work_sync(&skl->probe_work);
9961121
9971122 pm_runtime_get_noresume(&pci->dev);
9981123
9991124 /* codec removal, invoke bus_device_remove */
10001125 snd_hdac_ext_bus_device_remove(bus);
10011126
1002
- skl->debugfs = NULL;
10031127 skl_platform_unregister(&pci->dev);
10041128 skl_free_dsp(skl);
10051129 skl_machine_device_unregister(skl);
10061130 skl_dmic_device_unregister(skl);
10071131 skl_clock_device_unregister(skl);
10081132 skl_nhlt_remove_sysfs(skl);
1009
- skl_nhlt_free(skl->nhlt);
1133
+ if (skl->nhlt)
1134
+ intel_nhlt_free(skl->nhlt);
10101135 skl_free(bus);
10111136 dev_set_drvdata(&pci->dev, NULL);
10121137 }
10131138
10141139 /* PCI IDs */
10151140 static const struct pci_device_id skl_ids[] = {
1141
+#if IS_ENABLED(CONFIG_SND_SOC_INTEL_SKL)
10161142 /* Sunrise Point-LP */
10171143 { PCI_DEVICE(0x8086, 0x9d70),
10181144 .driver_data = (unsigned long)&snd_soc_acpi_intel_skl_machines},
1145
+#endif
1146
+#if IS_ENABLED(CONFIG_SND_SOC_INTEL_APL)
10191147 /* BXT-P */
10201148 { PCI_DEVICE(0x8086, 0x5a98),
10211149 .driver_data = (unsigned long)&snd_soc_acpi_intel_bxt_machines},
1150
+#endif
1151
+#if IS_ENABLED(CONFIG_SND_SOC_INTEL_KBL)
10221152 /* KBL */
10231153 { PCI_DEVICE(0x8086, 0x9D71),
10241154 .driver_data = (unsigned long)&snd_soc_acpi_intel_kbl_machines},
1155
+#endif
1156
+#if IS_ENABLED(CONFIG_SND_SOC_INTEL_GLK)
10251157 /* GLK */
10261158 { PCI_DEVICE(0x8086, 0x3198),
10271159 .driver_data = (unsigned long)&snd_soc_acpi_intel_glk_machines},
1160
+#endif
1161
+#if IS_ENABLED(CONFIG_SND_SOC_INTEL_CNL)
10281162 /* CNL */
10291163 { PCI_DEVICE(0x8086, 0x9dc8),
10301164 .driver_data = (unsigned long)&snd_soc_acpi_intel_cnl_machines},
1165
+#endif
1166
+#if IS_ENABLED(CONFIG_SND_SOC_INTEL_CFL)
1167
+ /* CFL */
1168
+ { PCI_DEVICE(0x8086, 0xa348),
1169
+ .driver_data = (unsigned long)&snd_soc_acpi_intel_cnl_machines},
1170
+#endif
1171
+#if IS_ENABLED(CONFIG_SND_SOC_INTEL_CML_LP)
1172
+ /* CML-LP */
1173
+ { PCI_DEVICE(0x8086, 0x02c8),
1174
+ .driver_data = (unsigned long)&snd_soc_acpi_intel_cnl_machines},
1175
+#endif
1176
+#if IS_ENABLED(CONFIG_SND_SOC_INTEL_CML_H)
1177
+ /* CML-H */
1178
+ { PCI_DEVICE(0x8086, 0x06c8),
1179
+ .driver_data = (unsigned long)&snd_soc_acpi_intel_cnl_machines},
1180
+#endif
10311181 { 0, }
10321182 };
10331183 MODULE_DEVICE_TABLE(pci, skl_ids);