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>
15 static int dsp_driver;
17 module_param(dsp_driver, int, 0444);
18 MODULE_PARM_DESC(dsp_driver, "Force the DSP driver for Intel DSP (0=auto, 1=legacy, 2=SST, 3=SOF)");
20 #define FLAG_SST BIT(0)
21 #define FLAG_SOF BIT(1)
22 #define FLAG_SST_ONLY_IF_DMIC BIT(15)
23 #define FLAG_SOF_ONLY_IF_DMIC BIT(16)
24 #define FLAG_SOF_ONLY_IF_SOUNDWIRE BIT(17)
26 #define FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE (FLAG_SOF_ONLY_IF_DMIC | \
27 FLAG_SOF_ONLY_IF_SOUNDWIRE)
32 u8 acpi_hid[ACPI_ID_LEN];
33 const struct dmi_system_id *dmi_table;
34 u8 codec_hid[ACPI_ID_LEN];
39 * - the order of similar PCI ID entries is important!
40 * - the first successful match will win
42 static const struct config_entry config_table[] = {
44 #if IS_ENABLED(CONFIG_SND_SOC_SOF_MERRIFIELD)
51 #if IS_ENABLED(CONFIG_SND_SOC_SOF_APOLLOLAKE)
58 * Apollolake (Broxton-P)
59 * the legacy HDAudio driver is used except on Up Squared (SOF) and
60 * Chromebooks (SST), as well as devices based on the ES8336 codec
62 #if IS_ENABLED(CONFIG_SND_SOC_SOF_APOLLOLAKE)
66 .dmi_table = (const struct dmi_system_id []) {
68 .ident = "Up Squared",
70 DMI_MATCH(DMI_SYS_VENDOR, "AAEON"),
71 DMI_MATCH(DMI_BOARD_NAME, "UP-APL01"),
80 .codec_hid = "ESSX8336",
83 #if IS_ENABLED(CONFIG_SND_SOC_INTEL_APL)
87 .dmi_table = (const struct dmi_system_id []) {
89 .ident = "Google Chromebooks",
91 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
99 * Skylake and Kabylake use legacy HDAudio driver except for Google
103 /* Sunrise Point-LP */
104 #if IS_ENABLED(CONFIG_SND_SOC_INTEL_SKL)
108 .dmi_table = (const struct dmi_system_id []) {
110 .ident = "Google Chromebooks",
112 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
119 .flags = FLAG_SST | FLAG_SST_ONLY_IF_DMIC,
124 #if IS_ENABLED(CONFIG_SND_SOC_INTEL_KBL)
128 .dmi_table = (const struct dmi_system_id []) {
130 .ident = "Google Chromebooks",
132 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
139 .flags = FLAG_SST | FLAG_SST_ONLY_IF_DMIC,
145 * Geminilake uses legacy HDAudio driver except for Google
146 * Chromebooks and devices based on the ES8336 codec
149 #if IS_ENABLED(CONFIG_SND_SOC_SOF_GEMINILAKE)
153 .dmi_table = (const struct dmi_system_id []) {
155 .ident = "Google Chromebooks",
157 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
166 .codec_hid = "ESSX8336",
171 * CoffeeLake, CannonLake, CometLake, IceLake, TigerLake use legacy
172 * HDAudio driver except for Google Chromebooks and when DMICs are
173 * present. Two cases are required since Coreboot does not expose NHLT
176 * When the Chromebook quirk is not present, it's based on information
177 * that no such device exists. When the quirk is present, it could be
178 * either based on product information or a placeholder.
182 #if IS_ENABLED(CONFIG_SND_SOC_SOF_CANNONLAKE)
186 .dmi_table = (const struct dmi_system_id []) {
188 .ident = "Google Chromebooks",
190 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
197 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
203 #if IS_ENABLED(CONFIG_SND_SOC_SOF_COFFEELAKE)
207 .dmi_table = (const struct dmi_system_id []) {
209 .ident = "Google Chromebooks",
211 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
218 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
223 #if IS_ENABLED(CONFIG_SND_SOC_SOF_COMETLAKE)
228 .dmi_table = (const struct dmi_system_id []) {
230 .ident = "Google Chromebooks",
232 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
237 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
238 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "09C6")
242 /* early version of SKU 09C6 */
244 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
245 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0983")
254 .codec_hid = "ESSX8336",
257 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
264 .dmi_table = (const struct dmi_system_id []) {
267 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
268 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "098F"),
273 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
274 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0990"),
283 .codec_hid = "ESSX8336",
286 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
292 #if IS_ENABLED(CONFIG_SND_SOC_SOF_ICELAKE)
296 .dmi_table = (const struct dmi_system_id []) {
298 .ident = "Google Chromebooks",
300 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
307 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
313 #if IS_ENABLED(CONFIG_SND_SOC_SOF_JASPERLAKE)
317 .dmi_table = (const struct dmi_system_id []) {
319 .ident = "Google Chromebooks",
321 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
330 .codec_hid = "ESSX8336",
333 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC,
339 #if IS_ENABLED(CONFIG_SND_SOC_SOF_TIGERLAKE)
343 .dmi_table = (const struct dmi_system_id []) {
345 .ident = "Google Chromebooks",
347 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
356 .codec_hid = "ESSX8336",
359 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
363 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
369 #if IS_ENABLED(CONFIG_SND_SOC_SOF_ELKHARTLAKE)
371 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC,
375 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC,
381 #if IS_ENABLED(CONFIG_SND_SOC_SOF_ALDERLAKE)
383 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
387 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
391 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
395 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
399 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
406 static const struct config_entry *snd_intel_dsp_find_config
407 (struct pci_dev *pci, const struct config_entry *table, u32 len)
411 device = pci->device;
412 for (; len > 0; len--, table++) {
413 if (table->device != device)
415 if (table->dmi_table && !dmi_check_system(table->dmi_table))
417 if (table->codec_hid[0] && !acpi_dev_present(table->codec_hid, NULL, -1))
424 static int snd_intel_dsp_check_dmic(struct pci_dev *pci)
426 struct nhlt_acpi_table *nhlt;
429 nhlt = intel_nhlt_init(&pci->dev);
431 if (intel_nhlt_has_endpoint_type(nhlt, NHLT_LINK_DMIC))
433 intel_nhlt_free(nhlt);
438 #if IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE)
439 static int snd_intel_dsp_check_soundwire(struct pci_dev *pci)
441 struct sdw_intel_acpi_info info;
445 handle = ACPI_HANDLE(&pci->dev);
447 ret = sdw_intel_acpi_scan(handle, &info);
451 return info.link_mask;
454 static int snd_intel_dsp_check_soundwire(struct pci_dev *pci)
460 int snd_intel_dsp_driver_probe(struct pci_dev *pci)
462 const struct config_entry *cfg;
464 /* Intel vendor only */
465 if (pci->vendor != 0x8086)
466 return SND_INTEL_DSP_DRIVER_ANY;
469 * Legacy devices don't have a PCI-based DSP and use HDaudio
470 * for HDMI/DP support, ignore kernel parameter
472 switch (pci->device) {
473 case 0x160c: /* Broadwell */
474 case 0x0a0c: /* Haswell */
477 case 0x0f04: /* Baytrail */
478 case 0x2284: /* Braswell */
479 return SND_INTEL_DSP_DRIVER_ANY;
482 if (dsp_driver > 0 && dsp_driver <= SND_INTEL_DSP_DRIVER_LAST)
486 * detect DSP by checking class/subclass/prog-id information
487 * class=04 subclass 03 prog-if 00: no DSP, use legacy driver
488 * class=04 subclass 01 prog-if 00: DSP is present
489 * (and may be required e.g. for DMIC or SSP support)
490 * class=04 subclass 03 prog-if 80: use DSP or legacy mode
492 if (pci->class == 0x040300)
493 return SND_INTEL_DSP_DRIVER_LEGACY;
494 if (pci->class != 0x040100 && pci->class != 0x040380) {
495 dev_err(&pci->dev, "Unknown PCI class/subclass/prog-if information (0x%06x) found, selecting HDAudio legacy driver\n", pci->class);
496 return SND_INTEL_DSP_DRIVER_LEGACY;
499 dev_info(&pci->dev, "DSP detected with PCI class/subclass/prog-if info 0x%06x\n", pci->class);
501 /* find the configuration for the specific device */
502 cfg = snd_intel_dsp_find_config(pci, config_table, ARRAY_SIZE(config_table));
504 return SND_INTEL_DSP_DRIVER_ANY;
506 if (cfg->flags & FLAG_SOF) {
507 if (cfg->flags & FLAG_SOF_ONLY_IF_SOUNDWIRE &&
508 snd_intel_dsp_check_soundwire(pci) > 0) {
509 dev_info(&pci->dev, "SoundWire enabled on CannonLake+ platform, using SOF driver\n");
510 return SND_INTEL_DSP_DRIVER_SOF;
512 if (cfg->flags & FLAG_SOF_ONLY_IF_DMIC &&
513 snd_intel_dsp_check_dmic(pci)) {
514 dev_info(&pci->dev, "Digital mics found on Skylake+ platform, using SOF driver\n");
515 return SND_INTEL_DSP_DRIVER_SOF;
517 if (!(cfg->flags & FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE))
518 return SND_INTEL_DSP_DRIVER_SOF;
522 if (cfg->flags & FLAG_SST) {
523 if (cfg->flags & FLAG_SST_ONLY_IF_DMIC) {
524 if (snd_intel_dsp_check_dmic(pci)) {
525 dev_info(&pci->dev, "Digital mics found on Skylake+ platform, using SST driver\n");
526 return SND_INTEL_DSP_DRIVER_SST;
529 return SND_INTEL_DSP_DRIVER_SST;
533 return SND_INTEL_DSP_DRIVER_LEGACY;
535 EXPORT_SYMBOL_GPL(snd_intel_dsp_driver_probe);
537 /* Should we default to SOF or SST for BYT/CHT ? */
538 #if IS_ENABLED(CONFIG_SND_INTEL_BYT_PREFER_SOF) || \
539 !IS_ENABLED(CONFIG_SND_SST_ATOM_HIFI2_PLATFORM_ACPI)
540 #define FLAG_SST_OR_SOF_BYT FLAG_SOF
542 #define FLAG_SST_OR_SOF_BYT FLAG_SST
546 * configuration table
547 * - the order of similar ACPI ID entries is important!
548 * - the first successful match will win
550 static const struct config_entry acpi_config_table[] = {
551 #if IS_ENABLED(CONFIG_SND_SST_ATOM_HIFI2_PLATFORM_ACPI) || \
552 IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
555 .flags = FLAG_SST_OR_SOF_BYT,
556 .acpi_hid = "80860F28",
560 .flags = FLAG_SST_OR_SOF_BYT,
561 .acpi_hid = "808622A8",
565 #if IS_ENABLED(CONFIG_SND_SOC_INTEL_CATPT)
568 .acpi_hid = "INT3438"
571 #if IS_ENABLED(CONFIG_SND_SOC_SOF_BROADWELL)
574 .acpi_hid = "INT3438"
577 /* Haswell - not supported by SOF but added for consistency */
578 #if IS_ENABLED(CONFIG_SND_SOC_INTEL_CATPT)
581 .acpi_hid = "INT33C8"
586 static const struct config_entry *snd_intel_acpi_dsp_find_config(const u8 acpi_hid[ACPI_ID_LEN],
587 const struct config_entry *table,
590 for (; len > 0; len--, table++) {
591 if (memcmp(table->acpi_hid, acpi_hid, ACPI_ID_LEN))
593 if (table->dmi_table && !dmi_check_system(table->dmi_table))
600 int snd_intel_acpi_dsp_driver_probe(struct device *dev, const u8 acpi_hid[ACPI_ID_LEN])
602 const struct config_entry *cfg;
604 if (dsp_driver > SND_INTEL_DSP_DRIVER_LEGACY && dsp_driver <= SND_INTEL_DSP_DRIVER_LAST)
607 if (dsp_driver == SND_INTEL_DSP_DRIVER_LEGACY) {
608 dev_warn(dev, "dsp_driver parameter %d not supported, using automatic detection\n",
609 SND_INTEL_DSP_DRIVER_LEGACY);
612 /* find the configuration for the specific device */
613 cfg = snd_intel_acpi_dsp_find_config(acpi_hid, acpi_config_table,
614 ARRAY_SIZE(acpi_config_table));
616 return SND_INTEL_DSP_DRIVER_ANY;
618 if (cfg->flags & FLAG_SST)
619 return SND_INTEL_DSP_DRIVER_SST;
621 if (cfg->flags & FLAG_SOF)
622 return SND_INTEL_DSP_DRIVER_SOF;
624 return SND_INTEL_DSP_DRIVER_SST;
626 EXPORT_SYMBOL_GPL(snd_intel_acpi_dsp_driver_probe);
628 MODULE_LICENSE("GPL v2");
629 MODULE_DESCRIPTION("Intel DSP config driver");
630 MODULE_IMPORT_NS(SND_INTEL_SOUNDWIRE_ACPI);