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"),
205 .codec_hid = &essx_83x6,
208 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
214 #if IS_ENABLED(CONFIG_SND_SOC_SOF_COFFEELAKE)
218 .dmi_table = (const struct dmi_system_id []) {
220 .ident = "Google Chromebooks",
222 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
229 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
234 #if IS_ENABLED(CONFIG_SND_SOC_SOF_COMETLAKE)
239 .dmi_table = (const struct dmi_system_id []) {
241 .ident = "Google Chromebooks",
243 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
248 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
249 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "09C6")
253 /* early version of SKU 09C6 */
255 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
256 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0983")
265 .codec_hid = &essx_83x6,
268 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
275 .dmi_table = (const struct dmi_system_id []) {
278 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
279 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "098F"),
284 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
285 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0990"),
294 .codec_hid = &essx_83x6,
297 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
303 #if IS_ENABLED(CONFIG_SND_SOC_SOF_ICELAKE)
307 .dmi_table = (const struct dmi_system_id []) {
309 .ident = "Google Chromebooks",
311 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
318 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
324 #if IS_ENABLED(CONFIG_SND_SOC_SOF_JASPERLAKE)
328 .dmi_table = (const struct dmi_system_id []) {
330 .ident = "Google Chromebooks",
332 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
341 .codec_hid = &essx_83x6,
344 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC,
350 #if IS_ENABLED(CONFIG_SND_SOC_SOF_TIGERLAKE)
354 .dmi_table = (const struct dmi_system_id []) {
356 .ident = "Google Chromebooks",
358 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
367 .codec_hid = &essx_83x6,
370 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
374 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
380 #if IS_ENABLED(CONFIG_SND_SOC_SOF_ELKHARTLAKE)
382 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC,
386 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC,
392 #if IS_ENABLED(CONFIG_SND_SOC_SOF_ALDERLAKE)
394 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
398 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
402 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
406 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
410 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
417 static const struct config_entry *snd_intel_dsp_find_config
418 (struct pci_dev *pci, const struct config_entry *table, u32 len)
422 device = pci->device;
423 for (; len > 0; len--, table++) {
424 if (table->device != device)
426 if (table->dmi_table && !dmi_check_system(table->dmi_table))
428 if (table->codec_hid) {
431 for (i = 0; i < table->codec_hid->num_codecs; i++)
432 if (acpi_dev_present(table->codec_hid->codecs[i], NULL, -1))
434 if (i == table->codec_hid->num_codecs)
442 static int snd_intel_dsp_check_dmic(struct pci_dev *pci)
444 struct nhlt_acpi_table *nhlt;
447 nhlt = intel_nhlt_init(&pci->dev);
449 if (intel_nhlt_has_endpoint_type(nhlt, NHLT_LINK_DMIC))
451 intel_nhlt_free(nhlt);
456 #if IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE)
457 static int snd_intel_dsp_check_soundwire(struct pci_dev *pci)
459 struct sdw_intel_acpi_info info;
463 handle = ACPI_HANDLE(&pci->dev);
465 ret = sdw_intel_acpi_scan(handle, &info);
469 return info.link_mask;
472 static int snd_intel_dsp_check_soundwire(struct pci_dev *pci)
478 int snd_intel_dsp_driver_probe(struct pci_dev *pci)
480 const struct config_entry *cfg;
482 /* Intel vendor only */
483 if (pci->vendor != 0x8086)
484 return SND_INTEL_DSP_DRIVER_ANY;
487 * Legacy devices don't have a PCI-based DSP and use HDaudio
488 * for HDMI/DP support, ignore kernel parameter
490 switch (pci->device) {
491 case 0x160c: /* Broadwell */
492 case 0x0a0c: /* Haswell */
495 case 0x0f04: /* Baytrail */
496 case 0x2284: /* Braswell */
497 return SND_INTEL_DSP_DRIVER_ANY;
500 if (dsp_driver > 0 && dsp_driver <= SND_INTEL_DSP_DRIVER_LAST)
504 * detect DSP by checking class/subclass/prog-id information
505 * class=04 subclass 03 prog-if 00: no DSP, use legacy driver
506 * class=04 subclass 01 prog-if 00: DSP is present
507 * (and may be required e.g. for DMIC or SSP support)
508 * class=04 subclass 03 prog-if 80: use DSP or legacy mode
510 if (pci->class == 0x040300)
511 return SND_INTEL_DSP_DRIVER_LEGACY;
512 if (pci->class != 0x040100 && pci->class != 0x040380) {
513 dev_err(&pci->dev, "Unknown PCI class/subclass/prog-if information (0x%06x) found, selecting HDAudio legacy driver\n", pci->class);
514 return SND_INTEL_DSP_DRIVER_LEGACY;
517 dev_info(&pci->dev, "DSP detected with PCI class/subclass/prog-if info 0x%06x\n", pci->class);
519 /* find the configuration for the specific device */
520 cfg = snd_intel_dsp_find_config(pci, config_table, ARRAY_SIZE(config_table));
522 return SND_INTEL_DSP_DRIVER_ANY;
524 if (cfg->flags & FLAG_SOF) {
525 if (cfg->flags & FLAG_SOF_ONLY_IF_SOUNDWIRE &&
526 snd_intel_dsp_check_soundwire(pci) > 0) {
527 dev_info(&pci->dev, "SoundWire enabled on CannonLake+ platform, using SOF driver\n");
528 return SND_INTEL_DSP_DRIVER_SOF;
530 if (cfg->flags & FLAG_SOF_ONLY_IF_DMIC &&
531 snd_intel_dsp_check_dmic(pci)) {
532 dev_info(&pci->dev, "Digital mics found on Skylake+ platform, using SOF driver\n");
533 return SND_INTEL_DSP_DRIVER_SOF;
535 if (!(cfg->flags & FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE))
536 return SND_INTEL_DSP_DRIVER_SOF;
540 if (cfg->flags & FLAG_SST) {
541 if (cfg->flags & FLAG_SST_ONLY_IF_DMIC) {
542 if (snd_intel_dsp_check_dmic(pci)) {
543 dev_info(&pci->dev, "Digital mics found on Skylake+ platform, using SST driver\n");
544 return SND_INTEL_DSP_DRIVER_SST;
547 return SND_INTEL_DSP_DRIVER_SST;
551 return SND_INTEL_DSP_DRIVER_LEGACY;
553 EXPORT_SYMBOL_GPL(snd_intel_dsp_driver_probe);
555 /* Should we default to SOF or SST for BYT/CHT ? */
556 #if IS_ENABLED(CONFIG_SND_INTEL_BYT_PREFER_SOF) || \
557 !IS_ENABLED(CONFIG_SND_SST_ATOM_HIFI2_PLATFORM_ACPI)
558 #define FLAG_SST_OR_SOF_BYT FLAG_SOF
560 #define FLAG_SST_OR_SOF_BYT FLAG_SST
564 * configuration table
565 * - the order of similar ACPI ID entries is important!
566 * - the first successful match will win
568 static const struct config_entry acpi_config_table[] = {
569 #if IS_ENABLED(CONFIG_SND_SST_ATOM_HIFI2_PLATFORM_ACPI) || \
570 IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
573 .flags = FLAG_SST_OR_SOF_BYT,
574 .acpi_hid = "80860F28",
578 .flags = FLAG_SST_OR_SOF_BYT,
579 .acpi_hid = "808622A8",
583 #if IS_ENABLED(CONFIG_SND_SOC_INTEL_CATPT)
586 .acpi_hid = "INT3438"
589 #if IS_ENABLED(CONFIG_SND_SOC_SOF_BROADWELL)
592 .acpi_hid = "INT3438"
595 /* Haswell - not supported by SOF but added for consistency */
596 #if IS_ENABLED(CONFIG_SND_SOC_INTEL_CATPT)
599 .acpi_hid = "INT33C8"
604 static const struct config_entry *snd_intel_acpi_dsp_find_config(const u8 acpi_hid[ACPI_ID_LEN],
605 const struct config_entry *table,
608 for (; len > 0; len--, table++) {
609 if (memcmp(table->acpi_hid, acpi_hid, ACPI_ID_LEN))
611 if (table->dmi_table && !dmi_check_system(table->dmi_table))
618 int snd_intel_acpi_dsp_driver_probe(struct device *dev, const u8 acpi_hid[ACPI_ID_LEN])
620 const struct config_entry *cfg;
622 if (dsp_driver > SND_INTEL_DSP_DRIVER_LEGACY && dsp_driver <= SND_INTEL_DSP_DRIVER_LAST)
625 if (dsp_driver == SND_INTEL_DSP_DRIVER_LEGACY) {
626 dev_warn(dev, "dsp_driver parameter %d not supported, using automatic detection\n",
627 SND_INTEL_DSP_DRIVER_LEGACY);
630 /* find the configuration for the specific device */
631 cfg = snd_intel_acpi_dsp_find_config(acpi_hid, acpi_config_table,
632 ARRAY_SIZE(acpi_config_table));
634 return SND_INTEL_DSP_DRIVER_ANY;
636 if (cfg->flags & FLAG_SST)
637 return SND_INTEL_DSP_DRIVER_SST;
639 if (cfg->flags & FLAG_SOF)
640 return SND_INTEL_DSP_DRIVER_SOF;
642 return SND_INTEL_DSP_DRIVER_SST;
644 EXPORT_SYMBOL_GPL(snd_intel_acpi_dsp_driver_probe);
646 MODULE_LICENSE("GPL v2");
647 MODULE_DESCRIPTION("Intel DSP config driver");
648 MODULE_IMPORT_NS(SND_INTEL_SOUNDWIRE_ACPI);