1*4882a593Smuzhiyun // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2*4882a593Smuzhiyun //
3*4882a593Smuzhiyun // This file is provided under a dual BSD/GPLv2 license. When using or
4*4882a593Smuzhiyun // redistributing this file, you may do so under either license.
5*4882a593Smuzhiyun //
6*4882a593Smuzhiyun // Copyright(c) 2018 Intel Corporation. All rights reserved.
7*4882a593Smuzhiyun //
8*4882a593Smuzhiyun // Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
9*4882a593Smuzhiyun //
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun #include <linux/firmware.h>
12*4882a593Smuzhiyun #include <linux/dmi.h>
13*4882a593Smuzhiyun #include <linux/module.h>
14*4882a593Smuzhiyun #include <linux/pci.h>
15*4882a593Smuzhiyun #include <linux/pm_runtime.h>
16*4882a593Smuzhiyun #include <sound/intel-dsp-config.h>
17*4882a593Smuzhiyun #include <sound/soc-acpi.h>
18*4882a593Smuzhiyun #include <sound/soc-acpi-intel-match.h>
19*4882a593Smuzhiyun #include <sound/sof.h>
20*4882a593Smuzhiyun #include "ops.h"
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun /* platform specific devices */
23*4882a593Smuzhiyun #include "intel/shim.h"
24*4882a593Smuzhiyun #include "intel/hda.h"
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun static char *fw_path;
27*4882a593Smuzhiyun module_param(fw_path, charp, 0444);
28*4882a593Smuzhiyun MODULE_PARM_DESC(fw_path, "alternate path for SOF firmware.");
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun static char *tplg_path;
31*4882a593Smuzhiyun module_param(tplg_path, charp, 0444);
32*4882a593Smuzhiyun MODULE_PARM_DESC(tplg_path, "alternate path for SOF topology.");
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun static int sof_pci_debug;
35*4882a593Smuzhiyun module_param_named(sof_pci_debug, sof_pci_debug, int, 0444);
36*4882a593Smuzhiyun MODULE_PARM_DESC(sof_pci_debug, "SOF PCI debug options (0x0 all off)");
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun static const char *sof_override_tplg_name;
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun #define SOF_PCI_DISABLE_PM_RUNTIME BIT(0)
41*4882a593Smuzhiyun
sof_tplg_cb(const struct dmi_system_id * id)42*4882a593Smuzhiyun static int sof_tplg_cb(const struct dmi_system_id *id)
43*4882a593Smuzhiyun {
44*4882a593Smuzhiyun sof_override_tplg_name = id->driver_data;
45*4882a593Smuzhiyun return 1;
46*4882a593Smuzhiyun }
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun static const struct dmi_system_id sof_tplg_table[] = {
49*4882a593Smuzhiyun {
50*4882a593Smuzhiyun .callback = sof_tplg_cb,
51*4882a593Smuzhiyun .matches = {
52*4882a593Smuzhiyun DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Volteer"),
53*4882a593Smuzhiyun DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98373_ALC5682I_I2S_UP4"),
54*4882a593Smuzhiyun },
55*4882a593Smuzhiyun .driver_data = "sof-tgl-rt5682-ssp0-max98373-ssp2.tplg",
56*4882a593Smuzhiyun },
57*4882a593Smuzhiyun {}
58*4882a593Smuzhiyun };
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun static const struct dmi_system_id community_key_platforms[] = {
61*4882a593Smuzhiyun {
62*4882a593Smuzhiyun .ident = "Up Squared",
63*4882a593Smuzhiyun .matches = {
64*4882a593Smuzhiyun DMI_MATCH(DMI_SYS_VENDOR, "AAEON"),
65*4882a593Smuzhiyun DMI_MATCH(DMI_BOARD_NAME, "UP-APL01"),
66*4882a593Smuzhiyun }
67*4882a593Smuzhiyun },
68*4882a593Smuzhiyun {
69*4882a593Smuzhiyun .ident = "Up Extreme",
70*4882a593Smuzhiyun .matches = {
71*4882a593Smuzhiyun DMI_MATCH(DMI_SYS_VENDOR, "AAEON"),
72*4882a593Smuzhiyun DMI_MATCH(DMI_BOARD_NAME, "UP-WHL01"),
73*4882a593Smuzhiyun }
74*4882a593Smuzhiyun },
75*4882a593Smuzhiyun {
76*4882a593Smuzhiyun .ident = "Google Chromebooks",
77*4882a593Smuzhiyun .matches = {
78*4882a593Smuzhiyun DMI_MATCH(DMI_PRODUCT_FAMILY, "Google"),
79*4882a593Smuzhiyun }
80*4882a593Smuzhiyun },
81*4882a593Smuzhiyun {},
82*4882a593Smuzhiyun };
83*4882a593Smuzhiyun
84*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_SND_SOC_SOF_APOLLOLAKE)
85*4882a593Smuzhiyun static const struct sof_dev_desc bxt_desc = {
86*4882a593Smuzhiyun .machines = snd_soc_acpi_intel_bxt_machines,
87*4882a593Smuzhiyun .use_acpi_target_states = true,
88*4882a593Smuzhiyun .resindex_lpe_base = 0,
89*4882a593Smuzhiyun .resindex_pcicfg_base = -1,
90*4882a593Smuzhiyun .resindex_imr_base = -1,
91*4882a593Smuzhiyun .irqindex_host_ipc = -1,
92*4882a593Smuzhiyun .resindex_dma_base = -1,
93*4882a593Smuzhiyun .chip_info = &apl_chip_info,
94*4882a593Smuzhiyun .default_fw_path = "intel/sof",
95*4882a593Smuzhiyun .default_tplg_path = "intel/sof-tplg",
96*4882a593Smuzhiyun .default_fw_filename = "sof-apl.ri",
97*4882a593Smuzhiyun .nocodec_tplg_filename = "sof-apl-nocodec.tplg",
98*4882a593Smuzhiyun .ops = &sof_apl_ops,
99*4882a593Smuzhiyun };
100*4882a593Smuzhiyun #endif
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_SND_SOC_SOF_GEMINILAKE)
103*4882a593Smuzhiyun static const struct sof_dev_desc glk_desc = {
104*4882a593Smuzhiyun .machines = snd_soc_acpi_intel_glk_machines,
105*4882a593Smuzhiyun .use_acpi_target_states = true,
106*4882a593Smuzhiyun .resindex_lpe_base = 0,
107*4882a593Smuzhiyun .resindex_pcicfg_base = -1,
108*4882a593Smuzhiyun .resindex_imr_base = -1,
109*4882a593Smuzhiyun .irqindex_host_ipc = -1,
110*4882a593Smuzhiyun .resindex_dma_base = -1,
111*4882a593Smuzhiyun .chip_info = &apl_chip_info,
112*4882a593Smuzhiyun .default_fw_path = "intel/sof",
113*4882a593Smuzhiyun .default_tplg_path = "intel/sof-tplg",
114*4882a593Smuzhiyun .default_fw_filename = "sof-glk.ri",
115*4882a593Smuzhiyun .nocodec_tplg_filename = "sof-glk-nocodec.tplg",
116*4882a593Smuzhiyun .ops = &sof_apl_ops,
117*4882a593Smuzhiyun };
118*4882a593Smuzhiyun #endif
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_SND_SOC_SOF_MERRIFIELD)
121*4882a593Smuzhiyun static struct snd_soc_acpi_mach sof_tng_machines[] = {
122*4882a593Smuzhiyun {
123*4882a593Smuzhiyun .id = "INT343A",
124*4882a593Smuzhiyun .drv_name = "edison",
125*4882a593Smuzhiyun .sof_fw_filename = "sof-byt.ri",
126*4882a593Smuzhiyun .sof_tplg_filename = "sof-byt.tplg",
127*4882a593Smuzhiyun },
128*4882a593Smuzhiyun {}
129*4882a593Smuzhiyun };
130*4882a593Smuzhiyun
131*4882a593Smuzhiyun static const struct sof_dev_desc tng_desc = {
132*4882a593Smuzhiyun .machines = sof_tng_machines,
133*4882a593Smuzhiyun .resindex_lpe_base = 3, /* IRAM, but subtract IRAM offset */
134*4882a593Smuzhiyun .resindex_pcicfg_base = -1,
135*4882a593Smuzhiyun .resindex_imr_base = 0,
136*4882a593Smuzhiyun .irqindex_host_ipc = -1,
137*4882a593Smuzhiyun .resindex_dma_base = -1,
138*4882a593Smuzhiyun .chip_info = &tng_chip_info,
139*4882a593Smuzhiyun .default_fw_path = "intel/sof",
140*4882a593Smuzhiyun .default_tplg_path = "intel/sof-tplg",
141*4882a593Smuzhiyun .default_fw_filename = "sof-byt.ri",
142*4882a593Smuzhiyun .nocodec_tplg_filename = "sof-byt.tplg",
143*4882a593Smuzhiyun .ops = &sof_tng_ops,
144*4882a593Smuzhiyun };
145*4882a593Smuzhiyun #endif
146*4882a593Smuzhiyun
147*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_SND_SOC_SOF_CANNONLAKE)
148*4882a593Smuzhiyun static const struct sof_dev_desc cnl_desc = {
149*4882a593Smuzhiyun .machines = snd_soc_acpi_intel_cnl_machines,
150*4882a593Smuzhiyun .alt_machines = snd_soc_acpi_intel_cnl_sdw_machines,
151*4882a593Smuzhiyun .use_acpi_target_states = true,
152*4882a593Smuzhiyun .resindex_lpe_base = 0,
153*4882a593Smuzhiyun .resindex_pcicfg_base = -1,
154*4882a593Smuzhiyun .resindex_imr_base = -1,
155*4882a593Smuzhiyun .irqindex_host_ipc = -1,
156*4882a593Smuzhiyun .resindex_dma_base = -1,
157*4882a593Smuzhiyun .chip_info = &cnl_chip_info,
158*4882a593Smuzhiyun .default_fw_path = "intel/sof",
159*4882a593Smuzhiyun .default_tplg_path = "intel/sof-tplg",
160*4882a593Smuzhiyun .default_fw_filename = "sof-cnl.ri",
161*4882a593Smuzhiyun .nocodec_tplg_filename = "sof-cnl-nocodec.tplg",
162*4882a593Smuzhiyun .ops = &sof_cnl_ops,
163*4882a593Smuzhiyun };
164*4882a593Smuzhiyun #endif
165*4882a593Smuzhiyun
166*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_SND_SOC_SOF_COFFEELAKE)
167*4882a593Smuzhiyun static const struct sof_dev_desc cfl_desc = {
168*4882a593Smuzhiyun .machines = snd_soc_acpi_intel_cfl_machines,
169*4882a593Smuzhiyun .alt_machines = snd_soc_acpi_intel_cfl_sdw_machines,
170*4882a593Smuzhiyun .use_acpi_target_states = true,
171*4882a593Smuzhiyun .resindex_lpe_base = 0,
172*4882a593Smuzhiyun .resindex_pcicfg_base = -1,
173*4882a593Smuzhiyun .resindex_imr_base = -1,
174*4882a593Smuzhiyun .irqindex_host_ipc = -1,
175*4882a593Smuzhiyun .resindex_dma_base = -1,
176*4882a593Smuzhiyun .chip_info = &cnl_chip_info,
177*4882a593Smuzhiyun .default_fw_path = "intel/sof",
178*4882a593Smuzhiyun .default_tplg_path = "intel/sof-tplg",
179*4882a593Smuzhiyun .default_fw_filename = "sof-cfl.ri",
180*4882a593Smuzhiyun .nocodec_tplg_filename = "sof-cnl-nocodec.tplg",
181*4882a593Smuzhiyun .ops = &sof_cnl_ops,
182*4882a593Smuzhiyun };
183*4882a593Smuzhiyun #endif
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_SND_SOC_SOF_COMETLAKE)
186*4882a593Smuzhiyun static const struct sof_dev_desc cml_desc = {
187*4882a593Smuzhiyun .machines = snd_soc_acpi_intel_cml_machines,
188*4882a593Smuzhiyun .alt_machines = snd_soc_acpi_intel_cml_sdw_machines,
189*4882a593Smuzhiyun .use_acpi_target_states = true,
190*4882a593Smuzhiyun .resindex_lpe_base = 0,
191*4882a593Smuzhiyun .resindex_pcicfg_base = -1,
192*4882a593Smuzhiyun .resindex_imr_base = -1,
193*4882a593Smuzhiyun .irqindex_host_ipc = -1,
194*4882a593Smuzhiyun .resindex_dma_base = -1,
195*4882a593Smuzhiyun .chip_info = &cnl_chip_info,
196*4882a593Smuzhiyun .default_fw_path = "intel/sof",
197*4882a593Smuzhiyun .default_tplg_path = "intel/sof-tplg",
198*4882a593Smuzhiyun .default_fw_filename = "sof-cml.ri",
199*4882a593Smuzhiyun .nocodec_tplg_filename = "sof-cnl-nocodec.tplg",
200*4882a593Smuzhiyun .ops = &sof_cnl_ops,
201*4882a593Smuzhiyun };
202*4882a593Smuzhiyun #endif
203*4882a593Smuzhiyun
204*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_SND_SOC_SOF_ICELAKE)
205*4882a593Smuzhiyun static const struct sof_dev_desc icl_desc = {
206*4882a593Smuzhiyun .machines = snd_soc_acpi_intel_icl_machines,
207*4882a593Smuzhiyun .alt_machines = snd_soc_acpi_intel_icl_sdw_machines,
208*4882a593Smuzhiyun .use_acpi_target_states = true,
209*4882a593Smuzhiyun .resindex_lpe_base = 0,
210*4882a593Smuzhiyun .resindex_pcicfg_base = -1,
211*4882a593Smuzhiyun .resindex_imr_base = -1,
212*4882a593Smuzhiyun .irqindex_host_ipc = -1,
213*4882a593Smuzhiyun .resindex_dma_base = -1,
214*4882a593Smuzhiyun .chip_info = &icl_chip_info,
215*4882a593Smuzhiyun .default_fw_path = "intel/sof",
216*4882a593Smuzhiyun .default_tplg_path = "intel/sof-tplg",
217*4882a593Smuzhiyun .default_fw_filename = "sof-icl.ri",
218*4882a593Smuzhiyun .nocodec_tplg_filename = "sof-icl-nocodec.tplg",
219*4882a593Smuzhiyun .ops = &sof_cnl_ops,
220*4882a593Smuzhiyun };
221*4882a593Smuzhiyun #endif
222*4882a593Smuzhiyun
223*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_SND_SOC_SOF_TIGERLAKE)
224*4882a593Smuzhiyun static const struct sof_dev_desc tgl_desc = {
225*4882a593Smuzhiyun .machines = snd_soc_acpi_intel_tgl_machines,
226*4882a593Smuzhiyun .alt_machines = snd_soc_acpi_intel_tgl_sdw_machines,
227*4882a593Smuzhiyun .use_acpi_target_states = true,
228*4882a593Smuzhiyun .resindex_lpe_base = 0,
229*4882a593Smuzhiyun .resindex_pcicfg_base = -1,
230*4882a593Smuzhiyun .resindex_imr_base = -1,
231*4882a593Smuzhiyun .irqindex_host_ipc = -1,
232*4882a593Smuzhiyun .resindex_dma_base = -1,
233*4882a593Smuzhiyun .chip_info = &tgl_chip_info,
234*4882a593Smuzhiyun .default_fw_path = "intel/sof",
235*4882a593Smuzhiyun .default_tplg_path = "intel/sof-tplg",
236*4882a593Smuzhiyun .default_fw_filename = "sof-tgl.ri",
237*4882a593Smuzhiyun .nocodec_tplg_filename = "sof-tgl-nocodec.tplg",
238*4882a593Smuzhiyun .ops = &sof_tgl_ops,
239*4882a593Smuzhiyun };
240*4882a593Smuzhiyun
241*4882a593Smuzhiyun static const struct sof_dev_desc tglh_desc = {
242*4882a593Smuzhiyun .machines = snd_soc_acpi_intel_tgl_machines,
243*4882a593Smuzhiyun .alt_machines = snd_soc_acpi_intel_tgl_sdw_machines,
244*4882a593Smuzhiyun .resindex_lpe_base = 0,
245*4882a593Smuzhiyun .resindex_pcicfg_base = -1,
246*4882a593Smuzhiyun .resindex_imr_base = -1,
247*4882a593Smuzhiyun .irqindex_host_ipc = -1,
248*4882a593Smuzhiyun .resindex_dma_base = -1,
249*4882a593Smuzhiyun .chip_info = &tglh_chip_info,
250*4882a593Smuzhiyun .default_fw_path = "intel/sof",
251*4882a593Smuzhiyun .default_tplg_path = "intel/sof-tplg",
252*4882a593Smuzhiyun .default_fw_filename = "sof-tgl-h.ri",
253*4882a593Smuzhiyun .nocodec_tplg_filename = "sof-tgl-nocodec.tplg",
254*4882a593Smuzhiyun .ops = &sof_tgl_ops,
255*4882a593Smuzhiyun };
256*4882a593Smuzhiyun #endif
257*4882a593Smuzhiyun
258*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_SND_SOC_SOF_ELKHARTLAKE)
259*4882a593Smuzhiyun static const struct sof_dev_desc ehl_desc = {
260*4882a593Smuzhiyun .machines = snd_soc_acpi_intel_ehl_machines,
261*4882a593Smuzhiyun .use_acpi_target_states = true,
262*4882a593Smuzhiyun .resindex_lpe_base = 0,
263*4882a593Smuzhiyun .resindex_pcicfg_base = -1,
264*4882a593Smuzhiyun .resindex_imr_base = -1,
265*4882a593Smuzhiyun .irqindex_host_ipc = -1,
266*4882a593Smuzhiyun .resindex_dma_base = -1,
267*4882a593Smuzhiyun .chip_info = &ehl_chip_info,
268*4882a593Smuzhiyun .default_fw_path = "intel/sof",
269*4882a593Smuzhiyun .default_tplg_path = "intel/sof-tplg",
270*4882a593Smuzhiyun .default_fw_filename = "sof-ehl.ri",
271*4882a593Smuzhiyun .nocodec_tplg_filename = "sof-ehl-nocodec.tplg",
272*4882a593Smuzhiyun .ops = &sof_cnl_ops,
273*4882a593Smuzhiyun };
274*4882a593Smuzhiyun #endif
275*4882a593Smuzhiyun
276*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_SND_SOC_SOF_JASPERLAKE)
277*4882a593Smuzhiyun static const struct sof_dev_desc jsl_desc = {
278*4882a593Smuzhiyun .machines = snd_soc_acpi_intel_jsl_machines,
279*4882a593Smuzhiyun .use_acpi_target_states = true,
280*4882a593Smuzhiyun .resindex_lpe_base = 0,
281*4882a593Smuzhiyun .resindex_pcicfg_base = -1,
282*4882a593Smuzhiyun .resindex_imr_base = -1,
283*4882a593Smuzhiyun .irqindex_host_ipc = -1,
284*4882a593Smuzhiyun .resindex_dma_base = -1,
285*4882a593Smuzhiyun .chip_info = &jsl_chip_info,
286*4882a593Smuzhiyun .default_fw_path = "intel/sof",
287*4882a593Smuzhiyun .default_tplg_path = "intel/sof-tplg",
288*4882a593Smuzhiyun .default_fw_filename = "sof-jsl.ri",
289*4882a593Smuzhiyun .nocodec_tplg_filename = "sof-jsl-nocodec.tplg",
290*4882a593Smuzhiyun .ops = &sof_cnl_ops,
291*4882a593Smuzhiyun };
292*4882a593Smuzhiyun #endif
293*4882a593Smuzhiyun
294*4882a593Smuzhiyun static const struct dev_pm_ops sof_pci_pm = {
295*4882a593Smuzhiyun .prepare = snd_sof_prepare,
296*4882a593Smuzhiyun .complete = snd_sof_complete,
297*4882a593Smuzhiyun SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume)
298*4882a593Smuzhiyun SET_RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume,
299*4882a593Smuzhiyun snd_sof_runtime_idle)
300*4882a593Smuzhiyun };
301*4882a593Smuzhiyun
sof_pci_probe_complete(struct device * dev)302*4882a593Smuzhiyun static void sof_pci_probe_complete(struct device *dev)
303*4882a593Smuzhiyun {
304*4882a593Smuzhiyun dev_dbg(dev, "Completing SOF PCI probe");
305*4882a593Smuzhiyun
306*4882a593Smuzhiyun if (sof_pci_debug & SOF_PCI_DISABLE_PM_RUNTIME)
307*4882a593Smuzhiyun return;
308*4882a593Smuzhiyun
309*4882a593Smuzhiyun /* allow runtime_pm */
310*4882a593Smuzhiyun pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS);
311*4882a593Smuzhiyun pm_runtime_use_autosuspend(dev);
312*4882a593Smuzhiyun
313*4882a593Smuzhiyun /*
314*4882a593Smuzhiyun * runtime pm for pci device is "forbidden" by default.
315*4882a593Smuzhiyun * so call pm_runtime_allow() to enable it.
316*4882a593Smuzhiyun */
317*4882a593Smuzhiyun pm_runtime_allow(dev);
318*4882a593Smuzhiyun
319*4882a593Smuzhiyun /* mark last_busy for pm_runtime to make sure not suspend immediately */
320*4882a593Smuzhiyun pm_runtime_mark_last_busy(dev);
321*4882a593Smuzhiyun
322*4882a593Smuzhiyun /* follow recommendation in pci-driver.c to decrement usage counter */
323*4882a593Smuzhiyun pm_runtime_put_noidle(dev);
324*4882a593Smuzhiyun }
325*4882a593Smuzhiyun
sof_pci_probe(struct pci_dev * pci,const struct pci_device_id * pci_id)326*4882a593Smuzhiyun static int sof_pci_probe(struct pci_dev *pci,
327*4882a593Smuzhiyun const struct pci_device_id *pci_id)
328*4882a593Smuzhiyun {
329*4882a593Smuzhiyun struct device *dev = &pci->dev;
330*4882a593Smuzhiyun const struct sof_dev_desc *desc =
331*4882a593Smuzhiyun (const struct sof_dev_desc *)pci_id->driver_data;
332*4882a593Smuzhiyun struct snd_sof_pdata *sof_pdata;
333*4882a593Smuzhiyun const struct snd_sof_dsp_ops *ops;
334*4882a593Smuzhiyun int ret;
335*4882a593Smuzhiyun
336*4882a593Smuzhiyun ret = snd_intel_dsp_driver_probe(pci);
337*4882a593Smuzhiyun if (ret != SND_INTEL_DSP_DRIVER_ANY && ret != SND_INTEL_DSP_DRIVER_SOF) {
338*4882a593Smuzhiyun dev_dbg(&pci->dev, "SOF PCI driver not selected, aborting probe\n");
339*4882a593Smuzhiyun return -ENODEV;
340*4882a593Smuzhiyun }
341*4882a593Smuzhiyun dev_dbg(&pci->dev, "PCI DSP detected");
342*4882a593Smuzhiyun
343*4882a593Smuzhiyun /* get ops for platform */
344*4882a593Smuzhiyun ops = desc->ops;
345*4882a593Smuzhiyun if (!ops) {
346*4882a593Smuzhiyun dev_err(dev, "error: no matching PCI descriptor ops\n");
347*4882a593Smuzhiyun return -ENODEV;
348*4882a593Smuzhiyun }
349*4882a593Smuzhiyun
350*4882a593Smuzhiyun sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL);
351*4882a593Smuzhiyun if (!sof_pdata)
352*4882a593Smuzhiyun return -ENOMEM;
353*4882a593Smuzhiyun
354*4882a593Smuzhiyun ret = pcim_enable_device(pci);
355*4882a593Smuzhiyun if (ret < 0)
356*4882a593Smuzhiyun return ret;
357*4882a593Smuzhiyun
358*4882a593Smuzhiyun ret = pci_request_regions(pci, "Audio DSP");
359*4882a593Smuzhiyun if (ret < 0)
360*4882a593Smuzhiyun return ret;
361*4882a593Smuzhiyun
362*4882a593Smuzhiyun sof_pdata->name = pci_name(pci);
363*4882a593Smuzhiyun sof_pdata->desc = (struct sof_dev_desc *)pci_id->driver_data;
364*4882a593Smuzhiyun sof_pdata->dev = dev;
365*4882a593Smuzhiyun sof_pdata->fw_filename = desc->default_fw_filename;
366*4882a593Smuzhiyun
367*4882a593Smuzhiyun /*
368*4882a593Smuzhiyun * for platforms using the SOF community key, change the
369*4882a593Smuzhiyun * default path automatically to pick the right files from the
370*4882a593Smuzhiyun * linux-firmware tree. This can be overridden with the
371*4882a593Smuzhiyun * fw_path kernel parameter, e.g. for developers.
372*4882a593Smuzhiyun */
373*4882a593Smuzhiyun
374*4882a593Smuzhiyun /* alternate fw and tplg filenames ? */
375*4882a593Smuzhiyun if (fw_path) {
376*4882a593Smuzhiyun sof_pdata->fw_filename_prefix = fw_path;
377*4882a593Smuzhiyun
378*4882a593Smuzhiyun dev_dbg(dev,
379*4882a593Smuzhiyun "Module parameter used, changed fw path to %s\n",
380*4882a593Smuzhiyun sof_pdata->fw_filename_prefix);
381*4882a593Smuzhiyun
382*4882a593Smuzhiyun } else if (dmi_check_system(community_key_platforms)) {
383*4882a593Smuzhiyun sof_pdata->fw_filename_prefix =
384*4882a593Smuzhiyun devm_kasprintf(dev, GFP_KERNEL, "%s/%s",
385*4882a593Smuzhiyun sof_pdata->desc->default_fw_path,
386*4882a593Smuzhiyun "community");
387*4882a593Smuzhiyun
388*4882a593Smuzhiyun dev_dbg(dev,
389*4882a593Smuzhiyun "Platform uses community key, changed fw path to %s\n",
390*4882a593Smuzhiyun sof_pdata->fw_filename_prefix);
391*4882a593Smuzhiyun } else {
392*4882a593Smuzhiyun sof_pdata->fw_filename_prefix =
393*4882a593Smuzhiyun sof_pdata->desc->default_fw_path;
394*4882a593Smuzhiyun }
395*4882a593Smuzhiyun
396*4882a593Smuzhiyun if (tplg_path)
397*4882a593Smuzhiyun sof_pdata->tplg_filename_prefix = tplg_path;
398*4882a593Smuzhiyun else
399*4882a593Smuzhiyun sof_pdata->tplg_filename_prefix =
400*4882a593Smuzhiyun sof_pdata->desc->default_tplg_path;
401*4882a593Smuzhiyun
402*4882a593Smuzhiyun dmi_check_system(sof_tplg_table);
403*4882a593Smuzhiyun if (sof_override_tplg_name)
404*4882a593Smuzhiyun sof_pdata->tplg_filename = sof_override_tplg_name;
405*4882a593Smuzhiyun
406*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)
407*4882a593Smuzhiyun /* set callback to enable runtime_pm */
408*4882a593Smuzhiyun sof_pdata->sof_probe_complete = sof_pci_probe_complete;
409*4882a593Smuzhiyun #endif
410*4882a593Smuzhiyun /* call sof helper for DSP hardware probe */
411*4882a593Smuzhiyun ret = snd_sof_device_probe(dev, sof_pdata);
412*4882a593Smuzhiyun if (ret) {
413*4882a593Smuzhiyun dev_err(dev, "error: failed to probe DSP hardware!\n");
414*4882a593Smuzhiyun goto release_regions;
415*4882a593Smuzhiyun }
416*4882a593Smuzhiyun
417*4882a593Smuzhiyun #if !IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)
418*4882a593Smuzhiyun sof_pci_probe_complete(dev);
419*4882a593Smuzhiyun #endif
420*4882a593Smuzhiyun
421*4882a593Smuzhiyun return ret;
422*4882a593Smuzhiyun
423*4882a593Smuzhiyun release_regions:
424*4882a593Smuzhiyun pci_release_regions(pci);
425*4882a593Smuzhiyun
426*4882a593Smuzhiyun return ret;
427*4882a593Smuzhiyun }
428*4882a593Smuzhiyun
sof_pci_remove(struct pci_dev * pci)429*4882a593Smuzhiyun static void sof_pci_remove(struct pci_dev *pci)
430*4882a593Smuzhiyun {
431*4882a593Smuzhiyun /* call sof helper for DSP hardware remove */
432*4882a593Smuzhiyun snd_sof_device_remove(&pci->dev);
433*4882a593Smuzhiyun
434*4882a593Smuzhiyun /* follow recommendation in pci-driver.c to increment usage counter */
435*4882a593Smuzhiyun if (!(sof_pci_debug & SOF_PCI_DISABLE_PM_RUNTIME))
436*4882a593Smuzhiyun pm_runtime_get_noresume(&pci->dev);
437*4882a593Smuzhiyun
438*4882a593Smuzhiyun /* release pci regions and disable device */
439*4882a593Smuzhiyun pci_release_regions(pci);
440*4882a593Smuzhiyun }
441*4882a593Smuzhiyun
442*4882a593Smuzhiyun /* PCI IDs */
443*4882a593Smuzhiyun static const struct pci_device_id sof_pci_ids[] = {
444*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_SND_SOC_SOF_MERRIFIELD)
445*4882a593Smuzhiyun { PCI_DEVICE(0x8086, 0x119a),
446*4882a593Smuzhiyun .driver_data = (unsigned long)&tng_desc},
447*4882a593Smuzhiyun #endif
448*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_SND_SOC_SOF_APOLLOLAKE)
449*4882a593Smuzhiyun /* BXT-P & Apollolake */
450*4882a593Smuzhiyun { PCI_DEVICE(0x8086, 0x5a98),
451*4882a593Smuzhiyun .driver_data = (unsigned long)&bxt_desc},
452*4882a593Smuzhiyun { PCI_DEVICE(0x8086, 0x1a98),
453*4882a593Smuzhiyun .driver_data = (unsigned long)&bxt_desc},
454*4882a593Smuzhiyun #endif
455*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_SND_SOC_SOF_GEMINILAKE)
456*4882a593Smuzhiyun { PCI_DEVICE(0x8086, 0x3198),
457*4882a593Smuzhiyun .driver_data = (unsigned long)&glk_desc},
458*4882a593Smuzhiyun #endif
459*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_SND_SOC_SOF_CANNONLAKE)
460*4882a593Smuzhiyun { PCI_DEVICE(0x8086, 0x9dc8),
461*4882a593Smuzhiyun .driver_data = (unsigned long)&cnl_desc},
462*4882a593Smuzhiyun #endif
463*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_SND_SOC_SOF_COFFEELAKE)
464*4882a593Smuzhiyun { PCI_DEVICE(0x8086, 0xa348),
465*4882a593Smuzhiyun .driver_data = (unsigned long)&cfl_desc},
466*4882a593Smuzhiyun #endif
467*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_SND_SOC_SOF_ICELAKE)
468*4882a593Smuzhiyun { PCI_DEVICE(0x8086, 0x34C8), /* ICL-LP */
469*4882a593Smuzhiyun .driver_data = (unsigned long)&icl_desc},
470*4882a593Smuzhiyun { PCI_DEVICE(0x8086, 0x3dc8), /* ICL-H */
471*4882a593Smuzhiyun .driver_data = (unsigned long)&icl_desc},
472*4882a593Smuzhiyun
473*4882a593Smuzhiyun #endif
474*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_SND_SOC_SOF_JASPERLAKE)
475*4882a593Smuzhiyun { PCI_DEVICE(0x8086, 0x38c8),
476*4882a593Smuzhiyun .driver_data = (unsigned long)&jsl_desc},
477*4882a593Smuzhiyun { PCI_DEVICE(0x8086, 0x4dc8),
478*4882a593Smuzhiyun .driver_data = (unsigned long)&jsl_desc},
479*4882a593Smuzhiyun #endif
480*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_SND_SOC_SOF_COMETLAKE)
481*4882a593Smuzhiyun { PCI_DEVICE(0x8086, 0x02c8), /* CML-LP */
482*4882a593Smuzhiyun .driver_data = (unsigned long)&cml_desc},
483*4882a593Smuzhiyun { PCI_DEVICE(0x8086, 0x06c8), /* CML-H */
484*4882a593Smuzhiyun .driver_data = (unsigned long)&cml_desc},
485*4882a593Smuzhiyun { PCI_DEVICE(0x8086, 0xa3f0), /* CML-S */
486*4882a593Smuzhiyun .driver_data = (unsigned long)&cml_desc},
487*4882a593Smuzhiyun #endif
488*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_SND_SOC_SOF_TIGERLAKE)
489*4882a593Smuzhiyun { PCI_DEVICE(0x8086, 0xa0c8), /* TGL-LP */
490*4882a593Smuzhiyun .driver_data = (unsigned long)&tgl_desc},
491*4882a593Smuzhiyun { PCI_DEVICE(0x8086, 0x43c8), /* TGL-H */
492*4882a593Smuzhiyun .driver_data = (unsigned long)&tglh_desc},
493*4882a593Smuzhiyun
494*4882a593Smuzhiyun #endif
495*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_SND_SOC_SOF_ELKHARTLAKE)
496*4882a593Smuzhiyun { PCI_DEVICE(0x8086, 0x4b55),
497*4882a593Smuzhiyun .driver_data = (unsigned long)&ehl_desc},
498*4882a593Smuzhiyun { PCI_DEVICE(0x8086, 0x4b58),
499*4882a593Smuzhiyun .driver_data = (unsigned long)&ehl_desc},
500*4882a593Smuzhiyun #endif
501*4882a593Smuzhiyun { 0, }
502*4882a593Smuzhiyun };
503*4882a593Smuzhiyun MODULE_DEVICE_TABLE(pci, sof_pci_ids);
504*4882a593Smuzhiyun
505*4882a593Smuzhiyun /* pci_driver definition */
506*4882a593Smuzhiyun static struct pci_driver snd_sof_pci_driver = {
507*4882a593Smuzhiyun .name = "sof-audio-pci",
508*4882a593Smuzhiyun .id_table = sof_pci_ids,
509*4882a593Smuzhiyun .probe = sof_pci_probe,
510*4882a593Smuzhiyun .remove = sof_pci_remove,
511*4882a593Smuzhiyun .driver = {
512*4882a593Smuzhiyun .pm = &sof_pci_pm,
513*4882a593Smuzhiyun },
514*4882a593Smuzhiyun };
515*4882a593Smuzhiyun module_pci_driver(snd_sof_pci_driver);
516*4882a593Smuzhiyun
517*4882a593Smuzhiyun MODULE_LICENSE("Dual BSD/GPL");
518*4882a593Smuzhiyun MODULE_IMPORT_NS(SND_SOC_SOF_MERRIFIELD);
519*4882a593Smuzhiyun MODULE_IMPORT_NS(SND_SOC_SOF_INTEL_HDA_COMMON);
520