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")
252 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
258 .codec_hid = "ESSX8336",
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"),
281 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
287 .codec_hid = "ESSX8336",
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 .codec_hid = "ESSX8336",
322 #if IS_ENABLED(CONFIG_SND_SOC_SOF_TIGERLAKE)
326 .dmi_table = (const struct dmi_system_id []) {
328 .ident = "Google Chromebooks",
330 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
337 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
341 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
347 .codec_hid = "ESSX8336",
352 #if IS_ENABLED(CONFIG_SND_SOC_SOF_ELKHARTLAKE)
354 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC,
358 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC,
364 #if IS_ENABLED(CONFIG_SND_SOC_SOF_ALDERLAKE)
366 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
370 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
374 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
378 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
382 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
389 static const struct config_entry *snd_intel_dsp_find_config
390 (struct pci_dev *pci, const struct config_entry *table, u32 len)
394 device = pci->device;
395 for (; len > 0; len--, table++) {
396 if (table->device != device)
398 if (table->dmi_table && !dmi_check_system(table->dmi_table))
400 if (table->codec_hid[0] && !acpi_dev_present(table->codec_hid, NULL, -1))
407 static int snd_intel_dsp_check_dmic(struct pci_dev *pci)
409 struct nhlt_acpi_table *nhlt;
412 nhlt = intel_nhlt_init(&pci->dev);
414 if (intel_nhlt_has_endpoint_type(nhlt, NHLT_LINK_DMIC))
416 intel_nhlt_free(nhlt);
421 #if IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE)
422 static int snd_intel_dsp_check_soundwire(struct pci_dev *pci)
424 struct sdw_intel_acpi_info info;
428 handle = ACPI_HANDLE(&pci->dev);
430 ret = sdw_intel_acpi_scan(handle, &info);
434 return info.link_mask;
437 static int snd_intel_dsp_check_soundwire(struct pci_dev *pci)
443 int snd_intel_dsp_driver_probe(struct pci_dev *pci)
445 const struct config_entry *cfg;
447 /* Intel vendor only */
448 if (pci->vendor != 0x8086)
449 return SND_INTEL_DSP_DRIVER_ANY;
452 * Legacy devices don't have a PCI-based DSP and use HDaudio
453 * for HDMI/DP support, ignore kernel parameter
455 switch (pci->device) {
456 case 0x160c: /* Broadwell */
457 case 0x0a0c: /* Haswell */
460 case 0x0f04: /* Baytrail */
461 case 0x2284: /* Braswell */
462 return SND_INTEL_DSP_DRIVER_ANY;
465 if (dsp_driver > 0 && dsp_driver <= SND_INTEL_DSP_DRIVER_LAST)
469 * detect DSP by checking class/subclass/prog-id information
470 * class=04 subclass 03 prog-if 00: no DSP, use legacy driver
471 * class=04 subclass 01 prog-if 00: DSP is present
472 * (and may be required e.g. for DMIC or SSP support)
473 * class=04 subclass 03 prog-if 80: use DSP or legacy mode
475 if (pci->class == 0x040300)
476 return SND_INTEL_DSP_DRIVER_LEGACY;
477 if (pci->class != 0x040100 && pci->class != 0x040380) {
478 dev_err(&pci->dev, "Unknown PCI class/subclass/prog-if information (0x%06x) found, selecting HDAudio legacy driver\n", pci->class);
479 return SND_INTEL_DSP_DRIVER_LEGACY;
482 dev_info(&pci->dev, "DSP detected with PCI class/subclass/prog-if info 0x%06x\n", pci->class);
484 /* find the configuration for the specific device */
485 cfg = snd_intel_dsp_find_config(pci, config_table, ARRAY_SIZE(config_table));
487 return SND_INTEL_DSP_DRIVER_ANY;
489 if (cfg->flags & FLAG_SOF) {
490 if (cfg->flags & FLAG_SOF_ONLY_IF_SOUNDWIRE &&
491 snd_intel_dsp_check_soundwire(pci) > 0) {
492 dev_info(&pci->dev, "SoundWire enabled on CannonLake+ platform, using SOF driver\n");
493 return SND_INTEL_DSP_DRIVER_SOF;
495 if (cfg->flags & FLAG_SOF_ONLY_IF_DMIC &&
496 snd_intel_dsp_check_dmic(pci)) {
497 dev_info(&pci->dev, "Digital mics found on Skylake+ platform, using SOF driver\n");
498 return SND_INTEL_DSP_DRIVER_SOF;
500 if (!(cfg->flags & FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE))
501 return SND_INTEL_DSP_DRIVER_SOF;
505 if (cfg->flags & FLAG_SST) {
506 if (cfg->flags & FLAG_SST_ONLY_IF_DMIC) {
507 if (snd_intel_dsp_check_dmic(pci)) {
508 dev_info(&pci->dev, "Digital mics found on Skylake+ platform, using SST driver\n");
509 return SND_INTEL_DSP_DRIVER_SST;
512 return SND_INTEL_DSP_DRIVER_SST;
516 return SND_INTEL_DSP_DRIVER_LEGACY;
518 EXPORT_SYMBOL_GPL(snd_intel_dsp_driver_probe);
520 /* Should we default to SOF or SST for BYT/CHT ? */
521 #if IS_ENABLED(CONFIG_SND_INTEL_BYT_PREFER_SOF) || \
522 !IS_ENABLED(CONFIG_SND_SST_ATOM_HIFI2_PLATFORM_ACPI)
523 #define FLAG_SST_OR_SOF_BYT FLAG_SOF
525 #define FLAG_SST_OR_SOF_BYT FLAG_SST
529 * configuration table
530 * - the order of similar ACPI ID entries is important!
531 * - the first successful match will win
533 static const struct config_entry acpi_config_table[] = {
534 #if IS_ENABLED(CONFIG_SND_SST_ATOM_HIFI2_PLATFORM_ACPI) || \
535 IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
538 .flags = FLAG_SST_OR_SOF_BYT,
539 .acpi_hid = "80860F28",
543 .flags = FLAG_SST_OR_SOF_BYT,
544 .acpi_hid = "808622A8",
548 #if IS_ENABLED(CONFIG_SND_SOC_INTEL_CATPT)
551 .acpi_hid = "INT3438"
554 #if IS_ENABLED(CONFIG_SND_SOC_SOF_BROADWELL)
557 .acpi_hid = "INT3438"
560 /* Haswell - not supported by SOF but added for consistency */
561 #if IS_ENABLED(CONFIG_SND_SOC_INTEL_CATPT)
564 .acpi_hid = "INT33C8"
569 static const struct config_entry *snd_intel_acpi_dsp_find_config(const u8 acpi_hid[ACPI_ID_LEN],
570 const struct config_entry *table,
573 for (; len > 0; len--, table++) {
574 if (memcmp(table->acpi_hid, acpi_hid, ACPI_ID_LEN))
576 if (table->dmi_table && !dmi_check_system(table->dmi_table))
583 int snd_intel_acpi_dsp_driver_probe(struct device *dev, const u8 acpi_hid[ACPI_ID_LEN])
585 const struct config_entry *cfg;
587 if (dsp_driver > SND_INTEL_DSP_DRIVER_LEGACY && dsp_driver <= SND_INTEL_DSP_DRIVER_LAST)
590 if (dsp_driver == SND_INTEL_DSP_DRIVER_LEGACY) {
591 dev_warn(dev, "dsp_driver parameter %d not supported, using automatic detection\n",
592 SND_INTEL_DSP_DRIVER_LEGACY);
595 /* find the configuration for the specific device */
596 cfg = snd_intel_acpi_dsp_find_config(acpi_hid, acpi_config_table,
597 ARRAY_SIZE(acpi_config_table));
599 return SND_INTEL_DSP_DRIVER_ANY;
601 if (cfg->flags & FLAG_SST)
602 return SND_INTEL_DSP_DRIVER_SST;
604 if (cfg->flags & FLAG_SOF)
605 return SND_INTEL_DSP_DRIVER_SOF;
607 return SND_INTEL_DSP_DRIVER_SST;
609 EXPORT_SYMBOL_GPL(snd_intel_acpi_dsp_driver_probe);
611 MODULE_LICENSE("GPL v2");
612 MODULE_DESCRIPTION("Intel DSP config driver");
613 MODULE_IMPORT_NS(SND_INTEL_SOUNDWIRE_ACPI);