1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2019 Jaroslav Kysela <perex@perex.cz>
4 #include <linux/bits.h>
6 #include <linux/module.h>
8 #include <sound/core.h>
9 #include <sound/intel-dsp-config.h>
10 #include <sound/intel-nhlt.h>
12 static int dsp_driver
;
14 module_param(dsp_driver
, int, 0444);
15 MODULE_PARM_DESC(dsp_driver
, "Force the DSP driver for Intel DSP (0=auto, 1=legacy, 2=SST, 3=SOF)");
17 #define FLAG_SST BIT(0)
18 #define FLAG_SOF BIT(1)
19 #define FLAG_SOF_ONLY_IF_DMIC BIT(16)
24 const struct dmi_system_id
*dmi_table
;
29 * - the order of similar PCI ID entries is important!
30 * - the first successful match will win
32 static const struct config_entry config_table
[] = {
34 #if IS_ENABLED(CONFIG_SND_SOC_SOF_MERRIFIELD)
41 #if IS_ENABLED(CONFIG_SND_SOC_SOF_APOLLOLAKE)
48 * Apollolake (Broxton-P)
49 * the legacy HDaudio driver is used except on Up Squared (SOF) and
52 #if IS_ENABLED(CONFIG_SND_SOC_SOF_APOLLOLAKE)
56 .dmi_table
= (const struct dmi_system_id
[]) {
58 .ident
= "Up Squared",
60 DMI_MATCH(DMI_SYS_VENDOR
, "AAEON"),
61 DMI_MATCH(DMI_BOARD_NAME
, "UP-APL01"),
68 #if IS_ENABLED(CONFIG_SND_SOC_INTEL_APL)
72 .dmi_table
= (const struct dmi_system_id
[]) {
74 .ident
= "Google Chromebooks",
76 DMI_MATCH(DMI_SYS_VENDOR
, "Google"),
84 * Skylake and Kabylake use legacy HDaudio driver except for Google
88 /* Sunrise Point-LP */
89 #if IS_ENABLED(CONFIG_SND_SOC_INTEL_SKL)
93 .dmi_table
= (const struct dmi_system_id
[]) {
95 .ident
= "Google Chromebooks",
97 DMI_MATCH(DMI_SYS_VENDOR
, "Google"),
105 #if IS_ENABLED(CONFIG_SND_SOC_INTEL_KBL)
109 .dmi_table
= (const struct dmi_system_id
[]) {
111 .ident
= "Google Chromebooks",
113 DMI_MATCH(DMI_SYS_VENDOR
, "Google"),
122 * Geminilake uses legacy HDaudio driver except for Google
126 #if IS_ENABLED(CONFIG_SND_SOC_SOF_GEMINILAKE)
130 .dmi_table
= (const struct dmi_system_id
[]) {
132 .ident
= "Google Chromebooks",
134 DMI_MATCH(DMI_SYS_VENDOR
, "Google"),
143 * CoffeeLake, CannonLake, CometLake, IceLake, TigerLake use legacy
144 * HDaudio driver except for Google Chromebooks and when DMICs are
145 * present. Two cases are required since Coreboot does not expose NHLT
148 * When the Chromebook quirk is not present, it's based on information
149 * that no such device exists. When the quirk is present, it could be
150 * either based on product information or a placeholder.
154 #if IS_ENABLED(CONFIG_SND_SOC_SOF_CANNONLAKE)
158 .dmi_table
= (const struct dmi_system_id
[]) {
160 .ident
= "Google Chromebooks",
162 DMI_MATCH(DMI_SYS_VENDOR
, "Google"),
169 .flags
= FLAG_SOF
| FLAG_SOF_ONLY_IF_DMIC
,
175 #if IS_ENABLED(CONFIG_SND_SOC_SOF_COFFEELAKE)
179 .dmi_table
= (const struct dmi_system_id
[]) {
181 .ident
= "Google Chromebooks",
183 DMI_MATCH(DMI_SYS_VENDOR
, "Google"),
190 .flags
= FLAG_SOF
| FLAG_SOF_ONLY_IF_DMIC
,
196 #if IS_ENABLED(CONFIG_SND_SOC_SOF_COMETLAKE_LP)
200 .dmi_table
= (const struct dmi_system_id
[]) {
202 .ident
= "Google Chromebooks",
204 DMI_MATCH(DMI_SYS_VENDOR
, "Google"),
211 .flags
= FLAG_SOF
| FLAG_SOF_ONLY_IF_DMIC
,
216 #if IS_ENABLED(CONFIG_SND_SOC_SOF_COMETLAKE_H)
218 .flags
= FLAG_SOF
| FLAG_SOF_ONLY_IF_DMIC
,
224 #if IS_ENABLED(CONFIG_SND_SOC_SOF_ICELAKE)
228 .dmi_table
= (const struct dmi_system_id
[]) {
230 .ident
= "Google Chromebooks",
232 DMI_MATCH(DMI_SYS_VENDOR
, "Google"),
239 .flags
= FLAG_SOF
| FLAG_SOF_ONLY_IF_DMIC
,
245 #if IS_ENABLED(CONFIG_SND_SOC_SOF_TIGERLAKE)
249 .dmi_table
= (const struct dmi_system_id
[]) {
251 .ident
= "Google Chromebooks",
253 DMI_MATCH(DMI_SYS_VENDOR
, "Google"),
261 .flags
= FLAG_SOF
| FLAG_SOF_ONLY_IF_DMIC
,
267 #if IS_ENABLED(CONFIG_SND_SOC_SOF_ELKHARTLAKE)
269 .flags
= FLAG_SOF
| FLAG_SOF_ONLY_IF_DMIC
,
276 static const struct config_entry
*snd_intel_dsp_find_config
277 (struct pci_dev
*pci
, const struct config_entry
*table
, u32 len
)
281 device
= pci
->device
;
282 for (; len
> 0; len
--, table
++) {
283 if (table
->device
!= device
)
285 if (table
->dmi_table
&& !dmi_check_system(table
->dmi_table
))
292 static int snd_intel_dsp_check_dmic(struct pci_dev
*pci
)
294 struct nhlt_acpi_table
*nhlt
;
297 nhlt
= intel_nhlt_init(&pci
->dev
);
299 if (intel_nhlt_get_dmic_geo(&pci
->dev
, nhlt
))
301 intel_nhlt_free(nhlt
);
306 int snd_intel_dsp_driver_probe(struct pci_dev
*pci
)
308 const struct config_entry
*cfg
;
310 /* Intel vendor only */
311 if (pci
->vendor
!= 0x8086)
312 return SND_INTEL_DSP_DRIVER_ANY
;
314 if (dsp_driver
> 0 && dsp_driver
<= SND_INTEL_DSP_DRIVER_LAST
)
318 * detect DSP by checking class/subclass/prog-id information
319 * class=04 subclass 03 prog-if 00: no DSP, use legacy driver
320 * class=04 subclass 01 prog-if 00: DSP is present
321 * (and may be required e.g. for DMIC or SSP support)
322 * class=04 subclass 03 prog-if 80: use DSP or legacy mode
324 if (pci
->class == 0x040300)
325 return SND_INTEL_DSP_DRIVER_LEGACY
;
326 if (pci
->class != 0x040100 && pci
->class != 0x040380) {
327 dev_err(&pci
->dev
, "Unknown PCI class/subclass/prog-if information (0x%06x) found, selecting HDA legacy driver\n", pci
->class);
328 return SND_INTEL_DSP_DRIVER_LEGACY
;
331 dev_info(&pci
->dev
, "DSP detected with PCI class/subclass/prog-if info 0x%06x\n", pci
->class);
333 /* find the configuration for the specific device */
334 cfg
= snd_intel_dsp_find_config(pci
, config_table
, ARRAY_SIZE(config_table
));
336 return SND_INTEL_DSP_DRIVER_ANY
;
338 if (cfg
->flags
& FLAG_SOF
) {
339 if (cfg
->flags
& FLAG_SOF_ONLY_IF_DMIC
) {
340 if (snd_intel_dsp_check_dmic(pci
)) {
341 dev_info(&pci
->dev
, "Digital mics found on Skylake+ platform, using SOF driver\n");
342 return SND_INTEL_DSP_DRIVER_SOF
;
345 return SND_INTEL_DSP_DRIVER_SOF
;
349 if (cfg
->flags
& FLAG_SST
)
350 return SND_INTEL_DSP_DRIVER_SST
;
352 return SND_INTEL_DSP_DRIVER_LEGACY
;
354 EXPORT_SYMBOL_GPL(snd_intel_dsp_driver_probe
);
356 MODULE_LICENSE("GPL v2");
357 MODULE_DESCRIPTION("Intel DSP config driver");