Skip to content

Commit 82d9d54

Browse files
perexgtiwai
authored andcommitted
ALSA: hda: add Intel DSP configuration / probe code
For distributions, we need one place where we can decide which driver will be activated for the auto-configation of the Intel's HDA hardware with DSP. Actually, we cover three drivers: * Legacy HDA * Intel SST * Intel Sound Open Firmware (SOF) All those drivers registers similar PCI IDs, so the first driver probed from the PCI stack can win. But... it is not guaranteed that the correct driver wins. This commit changes Intel's NHLT ACPI module to a common DSP probe module for the Intel's hardware. All above sound drivers calls this code. The user can force another behaviour using the module parameter 'dsp_driver' located in the 'snd-intel-dspcfg' module. This change allows to add specific dmi checks for the specific systems. The examples are taken from the pull request: thesofproject/linux#927 Tested on Lenovo Carbon X1 7th gen. Signed-off-by: Jaroslav Kysela <[email protected]> Tested-by: Pierre-Louis Bossart <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 46b4bff commit 82d9d54

File tree

11 files changed

+322
-68
lines changed

11 files changed

+322
-68
lines changed

include/sound/intel-dsp-config.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* intel-dsp-config.h - Intel DSP config
4+
*
5+
* Copyright (c) 2019 Jaroslav Kysela <[email protected]>
6+
*/
7+
8+
#ifndef __INTEL_DSP_CONFIG_H__
9+
#define __INTEL_DSP_CONFIG_H__
10+
11+
struct pci_dev;
12+
13+
enum {
14+
SND_INTEL_DSP_DRIVER_ANY = 0,
15+
SND_INTEL_DSP_DRIVER_LEGACY,
16+
SND_INTEL_DSP_DRIVER_SST,
17+
SND_INTEL_DSP_DRIVER_SOF,
18+
SND_INTEL_DSP_DRIVER_LAST = SND_INTEL_DSP_DRIVER_SOF
19+
};
20+
21+
#if IS_ENABLED(CONFIG_SND_INTEL_DSP_CONFIG)
22+
23+
int snd_intel_dsp_driver_probe(struct pci_dev *pci);
24+
25+
#else
26+
27+
static inline int snd_intel_dsp_driver_probe(struct pci_dev *pci)
28+
{
29+
return SND_INTEL_DSP_DRIVER_ANY;
30+
}
31+
32+
#endif
33+
34+
#endif

sound/hda/Kconfig

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ config SND_HDA_PREALLOC_SIZE
3434
via a proc file (/proc/asound/card*/pcm*/sub*/prealloc), too.
3535

3636
config SND_INTEL_NHLT
37-
tristate
37+
bool
3838
# this config should be selected only for Intel ACPI platforms.
39-
# A fallback is provided so that the code compiles in all cases.
39+
# A fallback is provided so that the code compiles in all cases.
40+
41+
config SND_INTEL_DSP_CONFIG
42+
tristate
43+
select SND_INTEL_NHLT if ACPI
44+
# this config should be selected only for Intel DSP platforms.
45+
# A fallback is provided so that the code compiles in all cases.

sound/hda/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ obj-$(CONFIG_SND_HDA_CORE) += snd-hda-core.o
1414
#extended hda
1515
obj-$(CONFIG_SND_HDA_EXT_CORE) += ext/
1616

17-
snd-intel-nhlt-objs := intel-nhlt.o
18-
obj-$(CONFIG_SND_INTEL_NHLT) += snd-intel-nhlt.o
17+
snd-intel-dspcfg-objs := intel-dsp-config.o
18+
snd-intel-dspcfg-$(CONFIG_SND_INTEL_NHLT) += intel-nhlt.o
19+
obj-$(CONFIG_SND_INTEL_DSP_CONFIG) += snd-intel-dspcfg.o

sound/hda/intel-dsp-config.c

Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
// Copyright (c) 2019 Jaroslav Kysela <[email protected]>
3+
4+
#include <linux/bits.h>
5+
#include <linux/dmi.h>
6+
#include <linux/module.h>
7+
#include <linux/pci.h>
8+
#include <sound/core.h>
9+
#include <sound/intel-dsp-config.h>
10+
#include <sound/intel-nhlt.h>
11+
12+
static int dsp_driver;
13+
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)");
16+
17+
#define FLAG_SST BIT(0)
18+
#define FLAG_SOF BIT(1)
19+
#define FLAG_SOF_ONLY_IF_DMIC BIT(16)
20+
21+
struct config_entry {
22+
u32 flags;
23+
u16 device;
24+
const struct dmi_system_id *dmi_table;
25+
};
26+
27+
/*
28+
* configuration table
29+
* - the order of similar PCI ID entries is important!
30+
* - the first successful match will win
31+
*/
32+
static const struct config_entry config_table[] = {
33+
/* Cometlake-LP */
34+
#if IS_ENABLED(CONFIG_SND_SOC_INTEL_CML_LP)
35+
{
36+
/* prefer SST */
37+
.flags = FLAG_SST,
38+
.device = 0x02c8,
39+
},
40+
#elif IS_ENABLED(CONFIG_SND_SOC_SOF_COMETLAKE_LP)
41+
{
42+
.flags = FLAG_SOF,
43+
.device = 0x02c8,
44+
},
45+
#endif
46+
/* Cometlake-H */
47+
#if IS_ENABLED(CONFIG_SND_SOC_INTEL_CML_H)
48+
{
49+
.flags = FLAG_SST,
50+
.device = 0x06c8,
51+
},
52+
#elif IS_ENABLED(CONFIG_SND_SOC_SOF_COMETLAKE_H)
53+
{
54+
.flags = FLAG_SOF,
55+
.device = 0x06c8,
56+
},
57+
#endif
58+
/* Merrifield */
59+
#if IS_ENABLED(CONFIG_SND_SOC_SOF_MERRIFIELD)
60+
{
61+
.flags = FLAG_SOF,
62+
.device = 0x119a,
63+
},
64+
#endif
65+
/* Broxton-T */
66+
#if IS_ENABLED(CONFIG_SND_SOC_SOF_APOLLOLAKE)
67+
{
68+
.flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC,
69+
.device = 0x1a98,
70+
},
71+
#endif
72+
/* Geminilake */
73+
#if IS_ENABLED(CONFIG_SND_SOC_SOF_GEMINILAKE)
74+
{
75+
.flags = FLAG_SOF,
76+
.device = 0x3198,
77+
.dmi_table = (const struct dmi_system_id []) {
78+
{
79+
.ident = "Google Chromebooks",
80+
.matches = {
81+
DMI_MATCH(DMI_SYS_VENDOR, "Google"),
82+
}
83+
},
84+
{}
85+
}
86+
},
87+
#endif
88+
#if IS_ENABLED(CONFIG_SND_SOC_INTEL_GLK)
89+
{
90+
.flags = FLAG_SST,
91+
.device = 0x3198,
92+
},
93+
#endif
94+
/* Icelake */
95+
#if IS_ENABLED(CONFIG_SND_SOC_SOF_ICELAKE)
96+
{
97+
.flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC,
98+
.device = 0x34c8,
99+
},
100+
#endif
101+
/* Elkhart Lake */
102+
#if IS_ENABLED(CONFIG_SND_SOC_SOF_ELKHARTLAKE)
103+
{
104+
.flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC,
105+
.device = 0x4b55,
106+
},
107+
#endif
108+
/* Appololake (Broxton-P) */
109+
#if IS_ENABLED(CONFIG_SND_SOC_SOF_APOLLOLAKE)
110+
{
111+
.flags = FLAG_SOF,
112+
.device = 0x5a98,
113+
.dmi_table = (const struct dmi_system_id []) {
114+
{
115+
.ident = "Up Squared",
116+
.matches = {
117+
DMI_MATCH(DMI_SYS_VENDOR, "AAEON"),
118+
DMI_MATCH(DMI_BOARD_NAME, "UP-APL01"),
119+
}
120+
},
121+
{}
122+
}
123+
},
124+
#endif
125+
#if IS_ENABLED(CONFIG_SND_SOC_INTEL_APL)
126+
{
127+
.flags = FLAG_SST,
128+
.device = 0x5a98,
129+
},
130+
#endif
131+
/* Cannonlake */
132+
#if IS_ENABLED(CONFIG_SND_SOC_SOF_CANNONLAKE)
133+
{
134+
.flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC,
135+
.device = 0x9dc8,
136+
},
137+
#endif
138+
/* Sunrise Point-LP */
139+
#if IS_ENABLED(CONFIG_SND_SOC_SOF_SKYLAKE)
140+
{
141+
.flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC,
142+
.device = 0x9d70,
143+
},
144+
#endif
145+
/* Kabylake-LP */
146+
#if IS_ENABLED(CONFIG_SND_SOC_SOF_KABYLAKE)
147+
{
148+
.flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC,
149+
.device = 0x9d71,
150+
},
151+
#endif
152+
/* Tigerlake */
153+
#if IS_ENABLED(CONFIG_SND_SOC_SOF_TIGERLAKE)
154+
{
155+
.flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC,
156+
.device = 0xa0c8,
157+
},
158+
#endif
159+
/* Coffelake */
160+
#if IS_ENABLED(CONFIG_SND_SOC_SOF_COFFEELAKE)
161+
{
162+
.flags = FLAG_SOF | FLAG_SOF_ONLY_IF_DMIC,
163+
.device = 0xa348,
164+
},
165+
#endif
166+
};
167+
168+
static const struct config_entry *snd_intel_dsp_find_config
169+
(struct pci_dev *pci, const struct config_entry *table, u32 len)
170+
{
171+
u16 device;
172+
173+
device = pci->device;
174+
for (; len > 0; len--, table++) {
175+
if (table->device != device)
176+
continue;
177+
if (table->dmi_table && !dmi_check_system(table->dmi_table))
178+
continue;
179+
return table;
180+
}
181+
return NULL;
182+
}
183+
184+
static int snd_intel_dsp_check_dmic(struct pci_dev *pci)
185+
{
186+
struct nhlt_acpi_table *nhlt;
187+
int ret = 0;
188+
189+
nhlt = intel_nhlt_init(&pci->dev);
190+
if (nhlt) {
191+
if (intel_nhlt_get_dmic_geo(&pci->dev, nhlt))
192+
ret = 1;
193+
intel_nhlt_free(nhlt);
194+
}
195+
return ret;
196+
}
197+
198+
int snd_intel_dsp_driver_probe(struct pci_dev *pci)
199+
{
200+
const struct config_entry *cfg;
201+
202+
if (dsp_driver > 0 && dsp_driver <= SND_INTEL_DSP_DRIVER_LAST)
203+
return dsp_driver;
204+
205+
/* Intel vendor only */
206+
if (snd_BUG_ON(pci->vendor != 0x8086))
207+
return SND_INTEL_DSP_DRIVER_ANY;
208+
209+
/*
210+
* detect DSP by checking class/subclass/prog-id information
211+
* class=04 subclass 03 prog-if 00: no DSP, use legacy driver
212+
* class=04 subclass 01 prog-if 00: DSP is present
213+
* (and may be required e.g. for DMIC or SSP support)
214+
* class=04 subclass 03 prog-if 80: use DSP or legacy mode
215+
*/
216+
if (pci->class == 0x040300)
217+
return SND_INTEL_DSP_DRIVER_LEGACY;
218+
if (pci->class != 0x040100 && pci->class != 0x040380) {
219+
dev_err(&pci->dev, "Unknown PCI class/subclass/prog-if information (0x%06x) found, selecting HDA legacy driver\n", pci->class);
220+
return SND_INTEL_DSP_DRIVER_LEGACY;
221+
}
222+
223+
dev_info(&pci->dev, "DSP detected with PCI class/subclass/prog-if info 0x%06x\n", pci->class);
224+
225+
/* find the configuration for the specific device */
226+
cfg = snd_intel_dsp_find_config(pci, config_table, ARRAY_SIZE(config_table));
227+
if (!cfg)
228+
return SND_INTEL_DSP_DRIVER_ANY;
229+
230+
if (cfg->flags & FLAG_SOF) {
231+
if (cfg->flags & FLAG_SOF_ONLY_IF_DMIC) {
232+
if (snd_intel_dsp_check_dmic(pci)) {
233+
dev_info(&pci->dev, "Digital mics found on Skylake+ platform, using SOF driver\n");
234+
return SND_INTEL_DSP_DRIVER_SOF;
235+
}
236+
} else {
237+
return SND_INTEL_DSP_DRIVER_SOF;
238+
}
239+
}
240+
241+
if (cfg->flags & FLAG_SST)
242+
return SND_INTEL_DSP_DRIVER_SST;
243+
244+
return SND_INTEL_DSP_DRIVER_LEGACY;
245+
}
246+
EXPORT_SYMBOL_GPL(snd_intel_dsp_driver_probe);
247+
248+
MODULE_LICENSE("GPL v2");
249+
MODULE_DESCRIPTION("Intel DSP config driver");

sound/hda/intel-nhlt.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,3 @@ int intel_nhlt_get_dmic_geo(struct device *dev, struct nhlt_acpi_table *nhlt)
102102
return dmic_geo;
103103
}
104104
EXPORT_SYMBOL_GPL(intel_nhlt_get_dmic_geo);
105-
106-
MODULE_LICENSE("GPL v2");
107-
MODULE_DESCRIPTION("Intel NHLT driver");

sound/pci/hda/Kconfig

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ config SND_HDA_INTEL
1212
tristate "HD Audio PCI"
1313
depends on SND_PCI
1414
select SND_HDA
15-
select SND_INTEL_NHLT if ACPI
15+
select SND_INTEL_DSP_CONFIG
1616
help
1717
Say Y here to include support for Intel "High Definition
1818
Audio" (Azalia) and its compatible devices.
@@ -23,15 +23,6 @@ config SND_HDA_INTEL
2323
To compile this driver as a module, choose M here: the module
2424
will be called snd-hda-intel.
2525

26-
config SND_HDA_INTEL_DETECT_DMIC
27-
bool "DMIC detection and probe abort"
28-
depends on SND_HDA_INTEL
29-
help
30-
Say Y to detect digital microphones on SKL+ devices. DMICs
31-
cannot be handled by the HDaudio legacy driver and are
32-
currently only supported by the SOF driver.
33-
If unsure say N.
34-
3526
config SND_HDA_TEGRA
3627
tristate "NVIDIA Tegra HD Audio"
3728
depends on ARCH_TEGRA

0 commit comments

Comments
 (0)