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
,
381 static const struct config_entry
*snd_intel_dsp_find_config
382 (struct pci_dev
*pci
, const struct config_entry
*table
, u32 len
)
386 device
= pci
->device
;
387 for (; len
> 0; len
--, table
++) {
388 if (table
->device
!= device
)
390 if (table
->dmi_table
&& !dmi_check_system(table
->dmi_table
))
392 if (table
->codec_hid
[0] && !acpi_dev_present(table
->codec_hid
, NULL
, -1))
399 static int snd_intel_dsp_check_dmic(struct pci_dev
*pci
)
401 struct nhlt_acpi_table
*nhlt
;
404 nhlt
= intel_nhlt_init(&pci
->dev
);
406 if (intel_nhlt_get_dmic_geo(&pci
->dev
, nhlt
))
408 intel_nhlt_free(nhlt
);
413 #if IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE)
414 static int snd_intel_dsp_check_soundwire(struct pci_dev
*pci
)
416 struct sdw_intel_acpi_info info
;
420 handle
= ACPI_HANDLE(&pci
->dev
);
422 ret
= sdw_intel_acpi_scan(handle
, &info
);
426 return info
.link_mask
;
429 static int snd_intel_dsp_check_soundwire(struct pci_dev
*pci
)
435 int snd_intel_dsp_driver_probe(struct pci_dev
*pci
)
437 const struct config_entry
*cfg
;
439 /* Intel vendor only */
440 if (pci
->vendor
!= 0x8086)
441 return SND_INTEL_DSP_DRIVER_ANY
;
444 * Legacy devices don't have a PCI-based DSP and use HDaudio
445 * for HDMI/DP support, ignore kernel parameter
447 switch (pci
->device
) {
448 case 0x160c: /* Broadwell */
449 case 0x0a0c: /* Haswell */
452 case 0x0f04: /* Baytrail */
453 case 0x2284: /* Braswell */
454 return SND_INTEL_DSP_DRIVER_ANY
;
457 if (dsp_driver
> 0 && dsp_driver
<= SND_INTEL_DSP_DRIVER_LAST
)
461 * detect DSP by checking class/subclass/prog-id information
462 * class=04 subclass 03 prog-if 00: no DSP, use legacy driver
463 * class=04 subclass 01 prog-if 00: DSP is present
464 * (and may be required e.g. for DMIC or SSP support)
465 * class=04 subclass 03 prog-if 80: use DSP or legacy mode
467 if (pci
->class == 0x040300)
468 return SND_INTEL_DSP_DRIVER_LEGACY
;
469 if (pci
->class != 0x040100 && pci
->class != 0x040380) {
470 dev_err(&pci
->dev
, "Unknown PCI class/subclass/prog-if information (0x%06x) found, selecting HDAudio legacy driver\n", pci
->class);
471 return SND_INTEL_DSP_DRIVER_LEGACY
;
474 dev_info(&pci
->dev
, "DSP detected with PCI class/subclass/prog-if info 0x%06x\n", pci
->class);
476 /* find the configuration for the specific device */
477 cfg
= snd_intel_dsp_find_config(pci
, config_table
, ARRAY_SIZE(config_table
));
479 return SND_INTEL_DSP_DRIVER_ANY
;
481 if (cfg
->flags
& FLAG_SOF
) {
482 if (cfg
->flags
& FLAG_SOF_ONLY_IF_SOUNDWIRE
&&
483 snd_intel_dsp_check_soundwire(pci
) > 0) {
484 dev_info(&pci
->dev
, "SoundWire enabled on CannonLake+ platform, using SOF driver\n");
485 return SND_INTEL_DSP_DRIVER_SOF
;
487 if (cfg
->flags
& FLAG_SOF_ONLY_IF_DMIC
&&
488 snd_intel_dsp_check_dmic(pci
)) {
489 dev_info(&pci
->dev
, "Digital mics found on Skylake+ platform, using SOF driver\n");
490 return SND_INTEL_DSP_DRIVER_SOF
;
492 if (!(cfg
->flags
& FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE
))
493 return SND_INTEL_DSP_DRIVER_SOF
;
497 if (cfg
->flags
& FLAG_SST
) {
498 if (cfg
->flags
& FLAG_SST_ONLY_IF_DMIC
) {
499 if (snd_intel_dsp_check_dmic(pci
)) {
500 dev_info(&pci
->dev
, "Digital mics found on Skylake+ platform, using SST driver\n");
501 return SND_INTEL_DSP_DRIVER_SST
;
504 return SND_INTEL_DSP_DRIVER_SST
;
508 return SND_INTEL_DSP_DRIVER_LEGACY
;
510 EXPORT_SYMBOL_GPL(snd_intel_dsp_driver_probe
);
512 /* Should we default to SOF or SST for BYT/CHT ? */
513 #if IS_ENABLED(CONFIG_SND_INTEL_BYT_PREFER_SOF) || \
514 !IS_ENABLED(CONFIG_SND_SST_ATOM_HIFI2_PLATFORM_ACPI)
515 #define FLAG_SST_OR_SOF_BYT FLAG_SOF
517 #define FLAG_SST_OR_SOF_BYT FLAG_SST
521 * configuration table
522 * - the order of similar ACPI ID entries is important!
523 * - the first successful match will win
525 static const struct config_entry acpi_config_table
[] = {
526 #if IS_ENABLED(CONFIG_SND_SST_ATOM_HIFI2_PLATFORM_ACPI) || \
527 IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
530 .flags
= FLAG_SST_OR_SOF_BYT
,
531 .acpi_hid
= "80860F28",
535 .flags
= FLAG_SST_OR_SOF_BYT
,
536 .acpi_hid
= "808622A8",
540 #if IS_ENABLED(CONFIG_SND_SOC_INTEL_CATPT)
543 .acpi_hid
= "INT3438"
546 #if IS_ENABLED(CONFIG_SND_SOC_SOF_BROADWELL)
549 .acpi_hid
= "INT3438"
552 /* Haswell - not supported by SOF but added for consistency */
553 #if IS_ENABLED(CONFIG_SND_SOC_INTEL_CATPT)
556 .acpi_hid
= "INT33C8"
561 static const struct config_entry
*snd_intel_acpi_dsp_find_config(const u8 acpi_hid
[ACPI_ID_LEN
],
562 const struct config_entry
*table
,
565 for (; len
> 0; len
--, table
++) {
566 if (memcmp(table
->acpi_hid
, acpi_hid
, ACPI_ID_LEN
))
568 if (table
->dmi_table
&& !dmi_check_system(table
->dmi_table
))
575 int snd_intel_acpi_dsp_driver_probe(struct device
*dev
, const u8 acpi_hid
[ACPI_ID_LEN
])
577 const struct config_entry
*cfg
;
579 if (dsp_driver
> SND_INTEL_DSP_DRIVER_LEGACY
&& dsp_driver
<= SND_INTEL_DSP_DRIVER_LAST
)
582 if (dsp_driver
== SND_INTEL_DSP_DRIVER_LEGACY
) {
583 dev_warn(dev
, "dsp_driver parameter %d not supported, using automatic detection\n",
584 SND_INTEL_DSP_DRIVER_LEGACY
);
587 /* find the configuration for the specific device */
588 cfg
= snd_intel_acpi_dsp_find_config(acpi_hid
, acpi_config_table
,
589 ARRAY_SIZE(acpi_config_table
));
591 return SND_INTEL_DSP_DRIVER_ANY
;
593 if (cfg
->flags
& FLAG_SST
)
594 return SND_INTEL_DSP_DRIVER_SST
;
596 if (cfg
->flags
& FLAG_SOF
)
597 return SND_INTEL_DSP_DRIVER_SOF
;
599 return SND_INTEL_DSP_DRIVER_SST
;
601 EXPORT_SYMBOL_GPL(snd_intel_acpi_dsp_driver_probe
);
603 MODULE_LICENSE("GPL v2");
604 MODULE_DESCRIPTION("Intel DSP config driver");
605 MODULE_IMPORT_NS(SND_INTEL_SOUNDWIRE_ACPI
);