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 const struct dmi_system_id *dmi_table;
37 * - the order of similar PCI ID entries is important!
38 * - the first successful match will win
40 static const struct config_entry config_table[] = {
42 #if IS_ENABLED(CONFIG_SND_SOC_SOF_MERRIFIELD)
49 #if IS_ENABLED(CONFIG_SND_SOC_SOF_APOLLOLAKE)
56 * Apollolake (Broxton-P)
57 * the legacy HDaudio driver is used except on Up Squared (SOF) and
60 #if IS_ENABLED(CONFIG_SND_SOC_SOF_APOLLOLAKE)
64 .dmi_table = (const struct dmi_system_id []) {
66 .ident = "Up Squared",
68 DMI_MATCH(DMI_SYS_VENDOR, "AAEON"),
69 DMI_MATCH(DMI_BOARD_NAME, "UP-APL01"),
76 #if IS_ENABLED(CONFIG_SND_SOC_INTEL_APL)
80 .dmi_table = (const struct dmi_system_id []) {
82 .ident = "Google Chromebooks",
84 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
92 * Skylake and Kabylake use legacy HDaudio driver except for Google
96 /* Sunrise Point-LP */
97 #if IS_ENABLED(CONFIG_SND_SOC_INTEL_SKL)
101 .dmi_table = (const struct dmi_system_id []) {
103 .ident = "Google Chromebooks",
105 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
112 .flags = FLAG_SST | FLAG_SST_ONLY_IF_DMIC,
117 #if IS_ENABLED(CONFIG_SND_SOC_INTEL_KBL)
121 .dmi_table = (const struct dmi_system_id []) {
123 .ident = "Google Chromebooks",
125 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
132 .flags = FLAG_SST | FLAG_SST_ONLY_IF_DMIC,
138 * Geminilake uses legacy HDaudio driver except for Google
142 #if IS_ENABLED(CONFIG_SND_SOC_SOF_GEMINILAKE)
146 .dmi_table = (const struct dmi_system_id []) {
148 .ident = "Google Chromebooks",
150 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
159 * CoffeeLake, CannonLake, CometLake, IceLake, TigerLake use legacy
160 * HDaudio driver except for Google Chromebooks and when DMICs are
161 * present. Two cases are required since Coreboot does not expose NHLT
164 * When the Chromebook quirk is not present, it's based on information
165 * that no such device exists. When the quirk is present, it could be
166 * either based on product information or a placeholder.
170 #if IS_ENABLED(CONFIG_SND_SOC_SOF_CANNONLAKE)
174 .dmi_table = (const struct dmi_system_id []) {
176 .ident = "Google Chromebooks",
178 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
185 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
191 #if IS_ENABLED(CONFIG_SND_SOC_SOF_COFFEELAKE)
195 .dmi_table = (const struct dmi_system_id []) {
197 .ident = "Google Chromebooks",
199 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
206 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
212 #if IS_ENABLED(CONFIG_SND_SOC_SOF_COMETLAKE_LP)
216 .dmi_table = (const struct dmi_system_id []) {
218 .ident = "Google Chromebooks",
220 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
225 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
226 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "09C6")
230 /* early version of SKU 09C6 */
232 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
233 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0983")
240 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
245 #if IS_ENABLED(CONFIG_SND_SOC_SOF_COMETLAKE_H)
249 .dmi_table = (const struct dmi_system_id []) {
252 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
253 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "098F"),
258 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"),
259 DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0990"),
266 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
272 #if IS_ENABLED(CONFIG_SND_SOC_SOF_ICELAKE)
276 .dmi_table = (const struct dmi_system_id []) {
278 .ident = "Google Chromebooks",
280 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
287 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
293 #if IS_ENABLED(CONFIG_SND_SOC_SOF_TIGERLAKE)
297 .dmi_table = (const struct dmi_system_id []) {
299 .ident = "Google Chromebooks",
301 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
308 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE,
314 #if IS_ENABLED(CONFIG_SND_SOC_SOF_ELKHARTLAKE)
316 .flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC,
323 static const struct config_entry *snd_intel_dsp_find_config
324 (struct pci_dev *pci, const struct config_entry *table, u32 len)
328 device = pci->device;
329 for (; len > 0; len--, table++) {
330 if (table->device != device)
332 if (table->dmi_table && !dmi_check_system(table->dmi_table))
339 static int snd_intel_dsp_check_dmic(struct pci_dev *pci)
341 struct nhlt_acpi_table *nhlt;
344 nhlt = intel_nhlt_init(&pci->dev);
346 if (intel_nhlt_get_dmic_geo(&pci->dev, nhlt))
348 intel_nhlt_free(nhlt);
353 #if IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE)
354 static int snd_intel_dsp_check_soundwire(struct pci_dev *pci)
356 struct sdw_intel_acpi_info info;
360 handle = ACPI_HANDLE(&pci->dev);
362 ret = sdw_intel_acpi_scan(handle, &info);
366 return info.link_mask;
369 static int snd_intel_dsp_check_soundwire(struct pci_dev *pci)
375 int snd_intel_dsp_driver_probe(struct pci_dev *pci)
377 const struct config_entry *cfg;
379 /* Intel vendor only */
380 if (pci->vendor != 0x8086)
381 return SND_INTEL_DSP_DRIVER_ANY;
383 if (dsp_driver > 0 && dsp_driver <= SND_INTEL_DSP_DRIVER_LAST)
387 * detect DSP by checking class/subclass/prog-id information
388 * class=04 subclass 03 prog-if 00: no DSP, use legacy driver
389 * class=04 subclass 01 prog-if 00: DSP is present
390 * (and may be required e.g. for DMIC or SSP support)
391 * class=04 subclass 03 prog-if 80: use DSP or legacy mode
393 if (pci->class == 0x040300)
394 return SND_INTEL_DSP_DRIVER_LEGACY;
395 if (pci->class != 0x040100 && pci->class != 0x040380) {
396 dev_err(&pci->dev, "Unknown PCI class/subclass/prog-if information (0x%06x) found, selecting HDA legacy driver\n", pci->class);
397 return SND_INTEL_DSP_DRIVER_LEGACY;
400 dev_info(&pci->dev, "DSP detected with PCI class/subclass/prog-if info 0x%06x\n", pci->class);
402 /* find the configuration for the specific device */
403 cfg = snd_intel_dsp_find_config(pci, config_table, ARRAY_SIZE(config_table));
405 return SND_INTEL_DSP_DRIVER_ANY;
407 if (cfg->flags & FLAG_SOF) {
408 if (cfg->flags & FLAG_SOF_ONLY_IF_SOUNDWIRE &&
409 snd_intel_dsp_check_soundwire(pci) > 0) {
410 dev_info(&pci->dev, "SoundWire enabled on CannonLake+ platform, using SOF driver\n");
411 return SND_INTEL_DSP_DRIVER_SOF;
413 if (cfg->flags & FLAG_SOF_ONLY_IF_DMIC &&
414 snd_intel_dsp_check_dmic(pci)) {
415 dev_info(&pci->dev, "Digital mics found on Skylake+ platform, using SOF driver\n");
416 return SND_INTEL_DSP_DRIVER_SOF;
418 if (!(cfg->flags & FLAG_SOF_ONLY_IF_DMIC_OR_SOUNDWIRE))
419 return SND_INTEL_DSP_DRIVER_SOF;
423 if (cfg->flags & FLAG_SST) {
424 if (cfg->flags & FLAG_SST_ONLY_IF_DMIC) {
425 if (snd_intel_dsp_check_dmic(pci)) {
426 dev_info(&pci->dev, "Digital mics found on Skylake+ platform, using SST driver\n");
427 return SND_INTEL_DSP_DRIVER_SST;
430 return SND_INTEL_DSP_DRIVER_SST;
434 return SND_INTEL_DSP_DRIVER_LEGACY;
436 EXPORT_SYMBOL_GPL(snd_intel_dsp_driver_probe);
438 MODULE_LICENSE("GPL v2");
439 MODULE_DESCRIPTION("Intel DSP config driver");
440 MODULE_IMPORT_NS(SOUNDWIRE_INTEL_INIT);