1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2019 Jaroslav Kysela <perex@perex.cz>
4 #include <linux/acpi.h>
5 #include <linux/bits.h>
7 #include <linux/module.h>
9 #include <linux/soundwire/sdw.h>
10 #include <linux/soundwire/sdw_intel.h>
11 #include <sound/core.h>
12 #include <sound/intel-dsp-config.h>
13 #include <sound/intel-nhlt.h>
14 #include <sound/soc-acpi.h>
16 static int dsp_driver;
18 module_param(dsp_driver, int, 0444);
19 MODULE_PARM_DESC(dsp_driver, "Force the DSP driver for Intel DSP (0=auto, 1=legacy, 2=SST, 3=SOF)");
21 #define FLAG_SST BIT(0)
22 #define FLAG_SOF BIT(1)
23 #define FLAG_SST_ONLY_IF_DMIC BIT(15)
24 #define FLAG_SOF_ONLY_IF_DMIC BIT(16)
25 #define FLAG_SOF_ONLY_IF_SOUNDWIRE BIT(17)
27 #define FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE (FLAG_SOF_ONLY_IF_DMIC | \
28 FLAG_SOF_ONLY_IF_SOUNDWIRE)
33 u8 acpi_hid[ACPI_ID_LEN];
34 const struct dmi_system_id *dmi_table;
35 const struct snd_soc_acpi_codecs *codec_hid;
38 static const struct snd_soc_acpi_codecs __maybe_unused essx_83x6 = {
40 .codecs = { "ESSX8316", "ESSX8326", "ESSX8336"},
45 * - the order of similar PCI ID entries is important!
46 * - the first successful match will win
48 static const struct config_entry config_table[] = {
50 #if IS_ENABLED(CONFIG_SND_SOC_SOF_MERRIFIELD)
57 #if IS_ENABLED(CONFIG_SND_SOC_SOF_APOLLOLAKE)
64 * Apollolake (Broxton-P)
65 * the legacy HDAudio driver is used except on Up Squared (SOF) and
66 * Chromebooks (SST), as well as devices based on the ES8336 codec
68 #if IS_ENABLED(CONFIG_SND_SOC_SOF_APOLLOLAKE)
72 .dmi_table = (const struct dmi_system_id []) {
74 .ident = "Up Squared",
76 DMI_MATCH(DMI_SYS_VENDOR, "AAEON"),
77 DMI_MATCH(DMI_BOARD_NAME, "UP-APL01"),
86 .codec_hid = &essx_83x6,
89 #if IS_ENABLED(CONFIG_SND_SOC_INTEL_APL)
93 .dmi_table = (const struct dmi_system_id []) {
95 .ident = "Google Chromebooks",
97 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
105 * Skylake and Kabylake use legacy HDAudio driver except for Google
109 /* Sunrise Point-LP */
110 #if IS_ENABLED(CONFIG_SND_SOC_INTEL_SKL)
114 .dmi_table = (const struct dmi_system_id []) {
116 .ident = "Google Chromebooks",
118 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
125 .flags = FLAG_SST | FLAG_SST_ONLY_IF_DMIC,
130 #if IS_ENABLED(CONFIG_SND_SOC_INTEL_KBL)
134 .dmi_table = (const struct dmi_system_id []) {
136 .ident = "Google Chromebooks",
138 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
145 .flags = FLAG_SST | FLAG_SST_ONLY_IF_DMIC,
151 * Geminilake uses legacy HDAudio driver except for Google
152 * Chromebooks and devices based on the ES8336 codec
155 #if IS_ENABLED(CONFIG_SND_SOC_SOF_GEMINILAKE)
159 .dmi_table = (const struct dmi_system_id []) {
161 .ident = "Google Chromebooks",
163 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
172 .codec_hid = &essx_83x6,
177 * CoffeeLake, CannonLake, CometLake, IceLake, TigerLake use legacy
178 * HDAudio driver except for Google Chromebooks and when DMICs are
179 * present. Two cases are required since Coreboot does not expose NHLT
182 * When the Chromebook quirk is not present, it's based on information
183 * that no such device exists. When the quirk is present, it could be
184 * either based on product information or a placeholder.
188 #if IS_ENABLED(CONFIG_SND_SOC_SOF_CANNONLAKE)
192 .dmi_table = (const struct dmi_system_id []) {
194 .ident = "Google Chromebooks",
196 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
202 DMI_MATCH(DMI_SYS_VENDOR, "AAEON"),
211 .codec_hid = &essx_83x6,
214 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
220 #if IS_ENABLED(CONFIG_SND_SOC_SOF_COFFEELAKE)
224 .dmi_table = (const struct dmi_system_id []) {
226 .ident = "Google Chromebooks",
228 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
235 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
240 #if IS_ENABLED(CONFIG_SND_SOC_SOF_COMETLAKE)
245 .dmi_table = (const struct dmi_system_id []) {
247 .ident = "Google Chromebooks",
249 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
254 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
255 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "09C6")
259 /* early version of SKU 09C6 */
261 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
262 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0983")
271 .codec_hid = &essx_83x6,
274 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
281 .dmi_table = (const struct dmi_system_id []) {
284 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
285 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "098F"),
290 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
291 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0990"),
300 .codec_hid = &essx_83x6,
303 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
309 #if IS_ENABLED(CONFIG_SND_SOC_SOF_ICELAKE)
313 .dmi_table = (const struct dmi_system_id []) {
315 .ident = "Google Chromebooks",
317 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
326 .codec_hid = &essx_83x6,
329 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
335 #if IS_ENABLED(CONFIG_SND_SOC_SOF_JASPERLAKE)
339 .dmi_table = (const struct dmi_system_id []) {
341 .ident = "Google Chromebooks",
343 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
352 .codec_hid = &essx_83x6,
355 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC,
361 #if IS_ENABLED(CONFIG_SND_SOC_SOF_TIGERLAKE)
365 .dmi_table = (const struct dmi_system_id []) {
367 .ident = "Google Chromebooks",
369 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
375 DMI_MATCH(DMI_SYS_VENDOR, "AAEON"),
384 .codec_hid = &essx_83x6,
387 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
391 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
397 #if IS_ENABLED(CONFIG_SND_SOC_SOF_ELKHARTLAKE)
399 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC,
403 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC,
409 #if IS_ENABLED(CONFIG_SND_SOC_SOF_ALDERLAKE)
412 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
417 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
424 .codec_hid = &essx_83x6,
427 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
431 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
438 .codec_hid = &essx_83x6,
441 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
446 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
451 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
456 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
460 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
465 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
470 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
477 static const struct config_entry *snd_intel_dsp_find_config
478 (struct pci_dev *pci, const struct config_entry *table, u32 len)
482 device = pci->device;
483 for (; len > 0; len--, table++) {
484 if (table->device != device)
486 if (table->dmi_table && !dmi_check_system(table->dmi_table))
488 if (table->codec_hid) {
491 for (i = 0; i < table->codec_hid->num_codecs; i++)
492 if (acpi_dev_present(table->codec_hid->codecs[i], NULL, -1))
494 if (i == table->codec_hid->num_codecs)
502 static int snd_intel_dsp_check_dmic(struct pci_dev *pci)
504 struct nhlt_acpi_table *nhlt;
507 nhlt = intel_nhlt_init(&pci->dev);
509 if (intel_nhlt_has_endpoint_type(nhlt, NHLT_LINK_DMIC))
511 intel_nhlt_free(nhlt);
516 #if IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE)
517 static int snd_intel_dsp_check_soundwire(struct pci_dev *pci)
519 struct sdw_intel_acpi_info info;
523 handle = ACPI_HANDLE(&pci->dev);
525 ret = sdw_intel_acpi_scan(handle, &info);
529 return info.link_mask;
532 static int snd_intel_dsp_check_soundwire(struct pci_dev *pci)
538 int snd_intel_dsp_driver_probe(struct pci_dev *pci)
540 const struct config_entry *cfg;
542 /* Intel vendor only */
543 if (pci->vendor != 0x8086)
544 return SND_INTEL_DSP_DRIVER_ANY;
547 * Legacy devices don't have a PCI-based DSP and use HDaudio
548 * for HDMI/DP support, ignore kernel parameter
550 switch (pci->device) {
551 case 0x160c: /* Broadwell */
552 case 0x0a0c: /* Haswell */
555 case 0x0f04: /* Baytrail */
556 case 0x2284: /* Braswell */
557 return SND_INTEL_DSP_DRIVER_ANY;
560 if (dsp_driver > 0 && dsp_driver <= SND_INTEL_DSP_DRIVER_LAST)
564 * detect DSP by checking class/subclass/prog-id information
565 * class=04 subclass 03 prog-if 00: no DSP, use legacy driver
566 * class=04 subclass 01 prog-if 00: DSP is present
567 * (and may be required e.g. for DMIC or SSP support)
568 * class=04 subclass 03 prog-if 80: use DSP or legacy mode
570 if (pci->class == 0x040300)
571 return SND_INTEL_DSP_DRIVER_LEGACY;
572 if (pci->class != 0x040100 && pci->class != 0x040380) {
573 dev_err(&pci->dev, "Unknown PCI class/subclass/prog-if information (0x%06x) found, selecting HDAudio legacy driver\n", pci->class);
574 return SND_INTEL_DSP_DRIVER_LEGACY;
577 dev_info(&pci->dev, "DSP detected with PCI class/subclass/prog-if info 0x%06x\n", pci->class);
579 /* find the configuration for the specific device */
580 cfg = snd_intel_dsp_find_config(pci, config_table, ARRAY_SIZE(config_table));
582 return SND_INTEL_DSP_DRIVER_ANY;
584 if (cfg->flags & FLAG_SOF) {
585 if (cfg->flags & FLAG_SOF_ONLY_IF_SOUNDWIRE &&
586 snd_intel_dsp_check_soundwire(pci) > 0) {
587 dev_info(&pci->dev, "SoundWire enabled on CannonLake+ platform, using SOF driver\n");
588 return SND_INTEL_DSP_DRIVER_SOF;
590 if (cfg->flags & FLAG_SOF_ONLY_IF_DMIC &&
591 snd_intel_dsp_check_dmic(pci)) {
592 dev_info(&pci->dev, "Digital mics found on Skylake+ platform, using SOF driver\n");
593 return SND_INTEL_DSP_DRIVER_SOF;
595 if (!(cfg->flags & FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE))
596 return SND_INTEL_DSP_DRIVER_SOF;
600 if (cfg->flags & FLAG_SST) {
601 if (cfg->flags & FLAG_SST_ONLY_IF_DMIC) {
602 if (snd_intel_dsp_check_dmic(pci)) {
603 dev_info(&pci->dev, "Digital mics found on Skylake+ platform, using SST driver\n");
604 return SND_INTEL_DSP_DRIVER_SST;
607 return SND_INTEL_DSP_DRIVER_SST;
611 return SND_INTEL_DSP_DRIVER_LEGACY;
613 EXPORT_SYMBOL_GPL(snd_intel_dsp_driver_probe);
615 /* Should we default to SOF or SST for BYT/CHT ? */
616 #if IS_ENABLED(CONFIG_SND_INTEL_BYT_PREFER_SOF) || \
617 !IS_ENABLED(CONFIG_SND_SST_ATOM_HIFI2_PLATFORM_ACPI)
618 #define FLAG_SST_OR_SOF_BYT FLAG_SOF
620 #define FLAG_SST_OR_SOF_BYT FLAG_SST
624 * configuration table
625 * - the order of similar ACPI ID entries is important!
626 * - the first successful match will win
628 static const struct config_entry acpi_config_table[] = {
629 #if IS_ENABLED(CONFIG_SND_SST_ATOM_HIFI2_PLATFORM_ACPI) || \
630 IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
633 .flags = FLAG_SST_OR_SOF_BYT,
634 .acpi_hid = "80860F28",
638 .flags = FLAG_SST_OR_SOF_BYT,
639 .acpi_hid = "808622A8",
643 #if IS_ENABLED(CONFIG_SND_SOC_INTEL_CATPT)
646 .acpi_hid = "INT3438"
649 #if IS_ENABLED(CONFIG_SND_SOC_SOF_BROADWELL)
652 .acpi_hid = "INT3438"
655 /* Haswell - not supported by SOF but added for consistency */
656 #if IS_ENABLED(CONFIG_SND_SOC_INTEL_CATPT)
659 .acpi_hid = "INT33C8"
664 static const struct config_entry *snd_intel_acpi_dsp_find_config(const u8 acpi_hid[ACPI_ID_LEN],
665 const struct config_entry *table,
668 for (; len > 0; len--, table++) {
669 if (memcmp(table->acpi_hid, acpi_hid, ACPI_ID_LEN))
671 if (table->dmi_table && !dmi_check_system(table->dmi_table))
678 int snd_intel_acpi_dsp_driver_probe(struct device *dev, const u8 acpi_hid[ACPI_ID_LEN])
680 const struct config_entry *cfg;
682 if (dsp_driver > SND_INTEL_DSP_DRIVER_LEGACY && dsp_driver <= SND_INTEL_DSP_DRIVER_LAST)
685 if (dsp_driver == SND_INTEL_DSP_DRIVER_LEGACY) {
686 dev_warn(dev, "dsp_driver parameter %d not supported, using automatic detection\n",
687 SND_INTEL_DSP_DRIVER_LEGACY);
690 /* find the configuration for the specific device */
691 cfg = snd_intel_acpi_dsp_find_config(acpi_hid, acpi_config_table,
692 ARRAY_SIZE(acpi_config_table));
694 return SND_INTEL_DSP_DRIVER_ANY;
696 if (cfg->flags & FLAG_SST)
697 return SND_INTEL_DSP_DRIVER_SST;
699 if (cfg->flags & FLAG_SOF)
700 return SND_INTEL_DSP_DRIVER_SOF;
702 return SND_INTEL_DSP_DRIVER_SST;
704 EXPORT_SYMBOL_GPL(snd_intel_acpi_dsp_driver_probe);
706 MODULE_LICENSE("GPL v2");
707 MODULE_DESCRIPTION("Intel DSP config driver");
708 MODULE_IMPORT_NS(SND_INTEL_SOUNDWIRE_ACPI);