1 // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
3 // This file is provided under a dual BSD/GPLv2 license. When using or
4 // redistributing this file, you may do so under either license.
6 // Copyright(c) 2018 Intel Corporation. All rights reserved.
8 // Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
11 #include <linux/firmware.h>
12 #include <linux/module.h>
13 #include <linux/pci.h>
14 #include <linux/pm_runtime.h>
15 #include <sound/intel-dsp-config.h>
16 #include <sound/soc-acpi.h>
17 #include <sound/soc-acpi-intel-match.h>
18 #include <sound/sof.h>
21 /* platform specific devices */
22 #include "intel/shim.h"
23 #include "intel/hda.h"
26 module_param(fw_path, charp, 0444);
27 MODULE_PARM_DESC(fw_path, "alternate path for SOF firmware.");
29 static char *tplg_path;
30 module_param(tplg_path, charp, 0444);
31 MODULE_PARM_DESC(tplg_path, "alternate path for SOF topology.");
33 static int sof_pci_debug;
34 module_param_named(sof_pci_debug, sof_pci_debug, int, 0444);
35 MODULE_PARM_DESC(sof_pci_debug, "SOF PCI debug options (0x0 all off)");
37 #define SOF_PCI_DISABLE_PM_RUNTIME BIT(0)
39 #if IS_ENABLED(CONFIG_SND_SOC_SOF_APOLLOLAKE)
40 static const struct sof_dev_desc bxt_desc = {
41 .machines = snd_soc_acpi_intel_bxt_machines,
42 .resindex_lpe_base = 0,
43 .resindex_pcicfg_base = -1,
44 .resindex_imr_base = -1,
45 .irqindex_host_ipc = -1,
46 .resindex_dma_base = -1,
47 .chip_info = &apl_chip_info,
48 .default_fw_path = "intel/sof",
49 .default_tplg_path = "intel/sof-tplg",
50 .default_fw_filename = "sof-apl.ri",
51 .nocodec_fw_filename = "sof-apl.ri",
52 .nocodec_tplg_filename = "sof-apl-nocodec.tplg",
54 .arch_ops = &sof_xtensa_arch_ops
58 #if IS_ENABLED(CONFIG_SND_SOC_SOF_GEMINILAKE)
59 static const struct sof_dev_desc glk_desc = {
60 .machines = snd_soc_acpi_intel_glk_machines,
61 .resindex_lpe_base = 0,
62 .resindex_pcicfg_base = -1,
63 .resindex_imr_base = -1,
64 .irqindex_host_ipc = -1,
65 .resindex_dma_base = -1,
66 .chip_info = &apl_chip_info,
67 .default_fw_path = "intel/sof",
68 .default_tplg_path = "intel/sof-tplg",
69 .default_fw_filename = "sof-glk.ri",
70 .nocodec_fw_filename = "sof-glk.ri",
71 .nocodec_tplg_filename = "sof-glk-nocodec.tplg",
73 .arch_ops = &sof_xtensa_arch_ops
77 #if IS_ENABLED(CONFIG_SND_SOC_SOF_MERRIFIELD)
78 static struct snd_soc_acpi_mach sof_tng_machines[] = {
82 .sof_fw_filename = "sof-byt.ri",
83 .sof_tplg_filename = "sof-byt.tplg",
88 static const struct sof_dev_desc tng_desc = {
89 .machines = sof_tng_machines,
90 .resindex_lpe_base = 3, /* IRAM, but subtract IRAM offset */
91 .resindex_pcicfg_base = -1,
92 .resindex_imr_base = 0,
93 .irqindex_host_ipc = -1,
94 .resindex_dma_base = -1,
95 .chip_info = &tng_chip_info,
96 .default_fw_path = "intel/sof",
97 .default_tplg_path = "intel/sof-tplg",
98 .default_fw_filename = "sof-byt.ri",
99 .nocodec_fw_filename = "sof-byt.ri",
100 .nocodec_tplg_filename = "sof-byt.tplg",
102 .arch_ops = &sof_xtensa_arch_ops
106 #if IS_ENABLED(CONFIG_SND_SOC_SOF_CANNONLAKE)
107 static const struct sof_dev_desc cnl_desc = {
108 .machines = snd_soc_acpi_intel_cnl_machines,
109 .resindex_lpe_base = 0,
110 .resindex_pcicfg_base = -1,
111 .resindex_imr_base = -1,
112 .irqindex_host_ipc = -1,
113 .resindex_dma_base = -1,
114 .chip_info = &cnl_chip_info,
115 .default_fw_path = "intel/sof",
116 .default_tplg_path = "intel/sof-tplg",
117 .default_fw_filename = "sof-cnl.ri",
118 .nocodec_fw_filename = "sof-cnl.ri",
119 .nocodec_tplg_filename = "sof-cnl-nocodec.tplg",
121 .arch_ops = &sof_xtensa_arch_ops
125 #if IS_ENABLED(CONFIG_SND_SOC_SOF_COFFEELAKE)
126 static const struct sof_dev_desc cfl_desc = {
127 .machines = snd_soc_acpi_intel_cfl_machines,
128 .resindex_lpe_base = 0,
129 .resindex_pcicfg_base = -1,
130 .resindex_imr_base = -1,
131 .irqindex_host_ipc = -1,
132 .resindex_dma_base = -1,
133 .chip_info = &cnl_chip_info,
134 .default_fw_path = "intel/sof",
135 .default_tplg_path = "intel/sof-tplg",
136 .default_fw_filename = "sof-cfl.ri",
137 .nocodec_fw_filename = "sof-cfl.ri",
138 .nocodec_tplg_filename = "sof-cnl-nocodec.tplg",
140 .arch_ops = &sof_xtensa_arch_ops
144 #if IS_ENABLED(CONFIG_SND_SOC_SOF_COMETLAKE_LP) || \
145 IS_ENABLED(CONFIG_SND_SOC_SOF_COMETLAKE_H)
147 static const struct sof_dev_desc cml_desc = {
148 .machines = snd_soc_acpi_intel_cml_machines,
149 .resindex_lpe_base = 0,
150 .resindex_pcicfg_base = -1,
151 .resindex_imr_base = -1,
152 .irqindex_host_ipc = -1,
153 .resindex_dma_base = -1,
154 .chip_info = &cnl_chip_info,
155 .default_fw_path = "intel/sof",
156 .default_tplg_path = "intel/sof-tplg",
157 .default_fw_filename = "sof-cml.ri",
158 .nocodec_fw_filename = "sof-cml.ri",
159 .nocodec_tplg_filename = "sof-cnl-nocodec.tplg",
161 .arch_ops = &sof_xtensa_arch_ops
165 #if IS_ENABLED(CONFIG_SND_SOC_SOF_ICELAKE)
166 static const struct sof_dev_desc icl_desc = {
167 .machines = snd_soc_acpi_intel_icl_machines,
168 .resindex_lpe_base = 0,
169 .resindex_pcicfg_base = -1,
170 .resindex_imr_base = -1,
171 .irqindex_host_ipc = -1,
172 .resindex_dma_base = -1,
173 .chip_info = &icl_chip_info,
174 .default_fw_path = "intel/sof",
175 .default_tplg_path = "intel/sof-tplg",
176 .default_fw_filename = "sof-icl.ri",
177 .nocodec_fw_filename = "sof-icl.ri",
178 .nocodec_tplg_filename = "sof-icl-nocodec.tplg",
180 .arch_ops = &sof_xtensa_arch_ops
184 #if IS_ENABLED(CONFIG_SND_SOC_SOF_TIGERLAKE)
185 static const struct sof_dev_desc tgl_desc = {
186 .machines = snd_soc_acpi_intel_tgl_machines,
187 .resindex_lpe_base = 0,
188 .resindex_pcicfg_base = -1,
189 .resindex_imr_base = -1,
190 .irqindex_host_ipc = -1,
191 .resindex_dma_base = -1,
192 .chip_info = &tgl_chip_info,
193 .default_fw_path = "intel/sof",
194 .default_tplg_path = "intel/sof-tplg",
195 .default_fw_filename = "sof-tgl.ri",
196 .nocodec_fw_filename = "sof-tgl.ri",
197 .nocodec_tplg_filename = "sof-tgl-nocodec.tplg",
199 .arch_ops = &sof_xtensa_arch_ops
203 #if IS_ENABLED(CONFIG_SND_SOC_SOF_ELKHARTLAKE)
204 static const struct sof_dev_desc ehl_desc = {
205 .machines = snd_soc_acpi_intel_ehl_machines,
206 .resindex_lpe_base = 0,
207 .resindex_pcicfg_base = -1,
208 .resindex_imr_base = -1,
209 .irqindex_host_ipc = -1,
210 .resindex_dma_base = -1,
211 .chip_info = &ehl_chip_info,
212 .default_fw_path = "intel/sof",
213 .default_tplg_path = "intel/sof-tplg",
214 .default_fw_filename = "sof-ehl.ri",
215 .nocodec_fw_filename = "sof-ehl.ri",
216 .nocodec_tplg_filename = "sof-ehl-nocodec.tplg",
218 .arch_ops = &sof_xtensa_arch_ops
222 #if IS_ENABLED(CONFIG_SND_SOC_SOF_JASPERLAKE)
223 static const struct sof_dev_desc jsl_desc = {
224 .machines = snd_soc_acpi_intel_jsl_machines,
225 .resindex_lpe_base = 0,
226 .resindex_pcicfg_base = -1,
227 .resindex_imr_base = -1,
228 .irqindex_host_ipc = -1,
229 .resindex_dma_base = -1,
230 .chip_info = &jsl_chip_info,
231 .default_fw_path = "intel/sof",
232 .default_tplg_path = "intel/sof-tplg",
233 .nocodec_fw_filename = "sof-jsl.ri",
234 .nocodec_tplg_filename = "sof-jsl-nocodec.tplg",
236 .arch_ops = &sof_xtensa_arch_ops
240 static const struct dev_pm_ops sof_pci_pm = {
241 .prepare = snd_sof_prepare,
242 .complete = snd_sof_complete,
243 SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume)
244 SET_RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume,
245 snd_sof_runtime_idle)
248 static void sof_pci_probe_complete(struct device *dev)
250 dev_dbg(dev, "Completing SOF PCI probe");
252 if (sof_pci_debug & SOF_PCI_DISABLE_PM_RUNTIME)
255 /* allow runtime_pm */
256 pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS);
257 pm_runtime_use_autosuspend(dev);
260 * runtime pm for pci device is "forbidden" by default.
261 * so call pm_runtime_allow() to enable it.
263 pm_runtime_allow(dev);
265 /* mark last_busy for pm_runtime to make sure not suspend immediately */
266 pm_runtime_mark_last_busy(dev);
268 /* follow recommendation in pci-driver.c to decrement usage counter */
269 pm_runtime_put_noidle(dev);
272 static int sof_pci_probe(struct pci_dev *pci,
273 const struct pci_device_id *pci_id)
275 struct device *dev = &pci->dev;
276 const struct sof_dev_desc *desc =
277 (const struct sof_dev_desc *)pci_id->driver_data;
278 struct snd_sof_pdata *sof_pdata;
279 const struct snd_sof_dsp_ops *ops;
282 ret = snd_intel_dsp_driver_probe(pci);
283 if (ret != SND_INTEL_DSP_DRIVER_ANY &&
284 ret != SND_INTEL_DSP_DRIVER_SOF)
287 dev_dbg(&pci->dev, "PCI DSP detected");
289 /* get ops for platform */
292 dev_err(dev, "error: no matching PCI descriptor ops\n");
296 sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL);
300 ret = pcim_enable_device(pci);
304 ret = pci_request_regions(pci, "Audio DSP");
308 sof_pdata->name = pci_name(pci);
309 sof_pdata->desc = (struct sof_dev_desc *)pci_id->driver_data;
310 sof_pdata->dev = dev;
311 sof_pdata->fw_filename = desc->default_fw_filename;
313 /* alternate fw and tplg filenames ? */
315 sof_pdata->fw_filename_prefix = fw_path;
317 sof_pdata->fw_filename_prefix =
318 sof_pdata->desc->default_fw_path;
321 sof_pdata->tplg_filename_prefix = tplg_path;
323 sof_pdata->tplg_filename_prefix =
324 sof_pdata->desc->default_tplg_path;
326 #if IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)
327 /* set callback to enable runtime_pm */
328 sof_pdata->sof_probe_complete = sof_pci_probe_complete;
330 /* call sof helper for DSP hardware probe */
331 ret = snd_sof_device_probe(dev, sof_pdata);
333 dev_err(dev, "error: failed to probe DSP hardware!\n");
334 goto release_regions;
337 #if !IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)
338 sof_pci_probe_complete(dev);
344 pci_release_regions(pci);
349 static void sof_pci_remove(struct pci_dev *pci)
351 /* call sof helper for DSP hardware remove */
352 snd_sof_device_remove(&pci->dev);
354 /* follow recommendation in pci-driver.c to increment usage counter */
355 if (!(sof_pci_debug & SOF_PCI_DISABLE_PM_RUNTIME))
356 pm_runtime_get_noresume(&pci->dev);
358 /* release pci regions and disable device */
359 pci_release_regions(pci);
363 static const struct pci_device_id sof_pci_ids[] = {
364 #if IS_ENABLED(CONFIG_SND_SOC_SOF_MERRIFIELD)
365 { PCI_DEVICE(0x8086, 0x119a),
366 .driver_data = (unsigned long)&tng_desc},
368 #if IS_ENABLED(CONFIG_SND_SOC_SOF_APOLLOLAKE)
369 /* BXT-P & Apollolake */
370 { PCI_DEVICE(0x8086, 0x5a98),
371 .driver_data = (unsigned long)&bxt_desc},
372 { PCI_DEVICE(0x8086, 0x1a98),
373 .driver_data = (unsigned long)&bxt_desc},
375 #if IS_ENABLED(CONFIG_SND_SOC_SOF_GEMINILAKE)
376 { PCI_DEVICE(0x8086, 0x3198),
377 .driver_data = (unsigned long)&glk_desc},
379 #if IS_ENABLED(CONFIG_SND_SOC_SOF_CANNONLAKE)
380 { PCI_DEVICE(0x8086, 0x9dc8),
381 .driver_data = (unsigned long)&cnl_desc},
383 #if IS_ENABLED(CONFIG_SND_SOC_SOF_COFFEELAKE)
384 { PCI_DEVICE(0x8086, 0xa348),
385 .driver_data = (unsigned long)&cfl_desc},
387 #if IS_ENABLED(CONFIG_SND_SOC_SOF_ICELAKE)
388 { PCI_DEVICE(0x8086, 0x34C8),
389 .driver_data = (unsigned long)&icl_desc},
391 #if IS_ENABLED(CONFIG_SND_SOC_SOF_JASPERLAKE)
392 { PCI_DEVICE(0x8086, 0x38c8),
393 .driver_data = (unsigned long)&jsl_desc},
395 #if IS_ENABLED(CONFIG_SND_SOC_SOF_COMETLAKE_LP)
396 { PCI_DEVICE(0x8086, 0x02c8),
397 .driver_data = (unsigned long)&cml_desc},
399 #if IS_ENABLED(CONFIG_SND_SOC_SOF_COMETLAKE_H)
400 { PCI_DEVICE(0x8086, 0x06c8),
401 .driver_data = (unsigned long)&cml_desc},
403 #if IS_ENABLED(CONFIG_SND_SOC_SOF_TIGERLAKE)
404 { PCI_DEVICE(0x8086, 0xa0c8),
405 .driver_data = (unsigned long)&tgl_desc},
407 #if IS_ENABLED(CONFIG_SND_SOC_SOF_ELKHARTLAKE)
408 { PCI_DEVICE(0x8086, 0x4b55),
409 .driver_data = (unsigned long)&ehl_desc},
413 MODULE_DEVICE_TABLE(pci, sof_pci_ids);
415 /* pci_driver definition */
416 static struct pci_driver snd_sof_pci_driver = {
417 .name = "sof-audio-pci",
418 .id_table = sof_pci_ids,
419 .probe = sof_pci_probe,
420 .remove = sof_pci_remove,
425 module_pci_driver(snd_sof_pci_driver);
427 MODULE_LICENSE("Dual BSD/GPL");