1 // SPDX-License-Identifier: (GPL-2.0-only 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/dmi.h>
13 #include <linux/module.h>
14 #include <linux/pci.h>
15 #include <linux/platform_data/x86/soc.h>
16 #include <linux/pm_runtime.h>
17 #include <sound/intel-dsp-config.h>
18 #include <sound/soc-acpi.h>
19 #include <sound/soc-acpi-intel-match.h>
20 #include <sound/sof.h>
23 /* platform specific devices */
24 #include "intel/shim.h"
25 #include "intel/hda.h"
28 module_param(fw_path, charp, 0444);
29 MODULE_PARM_DESC(fw_path, "alternate path for SOF firmware.");
31 static char *tplg_path;
32 module_param(tplg_path, charp, 0444);
33 MODULE_PARM_DESC(tplg_path, "alternate path for SOF topology.");
35 static char *tplg_filename;
36 module_param(tplg_filename, charp, 0444);
37 MODULE_PARM_DESC(tplg_filename, "alternate filename for SOF topology.");
39 static int sof_pci_debug;
40 module_param_named(sof_pci_debug, sof_pci_debug, int, 0444);
41 MODULE_PARM_DESC(sof_pci_debug, "SOF PCI debug options (0x0 all off)");
43 static const char *sof_dmi_override_tplg_name;
44 static bool sof_dmi_use_community_key;
46 #define SOF_PCI_DISABLE_PM_RUNTIME BIT(0)
48 static int sof_tplg_cb(const struct dmi_system_id *id)
50 sof_dmi_override_tplg_name = id->driver_data;
54 static const struct dmi_system_id sof_tplg_table[] = {
56 .callback = sof_tplg_cb,
58 DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Volteer"),
59 DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98373_ALC5682I_I2S_UP4"),
61 .driver_data = "sof-tgl-rt5682-ssp0-max98373-ssp2.tplg",
66 /* all Up boards use the community key */
67 static int up_use_community_key(const struct dmi_system_id *id)
69 sof_dmi_use_community_key = true;
74 * For ApolloLake Chromebooks we want to force the use of the Intel production key.
75 * All newer platforms use the community key
77 static int chromebook_use_community_key(const struct dmi_system_id *id)
79 if (!soc_intel_is_apl())
80 sof_dmi_use_community_key = true;
84 static const struct dmi_system_id community_key_platforms[] = {
87 .callback = up_use_community_key,
89 DMI_MATCH(DMI_SYS_VENDOR, "AAEON"),
93 .ident = "Google Chromebooks",
94 .callback = chromebook_use_community_key,
96 DMI_MATCH(DMI_PRODUCT_FAMILY, "Google"),
100 .ident = "Google firmware",
101 .callback = chromebook_use_community_key,
103 DMI_MATCH(DMI_BIOS_VERSION, "Google"),
109 #if IS_ENABLED(CONFIG_SND_SOC_SOF_APOLLOLAKE)
110 static const struct sof_dev_desc bxt_desc = {
111 .machines = snd_soc_acpi_intel_bxt_machines,
112 .use_acpi_target_states = true,
113 .resindex_lpe_base = 0,
114 .resindex_pcicfg_base = -1,
115 .resindex_imr_base = -1,
116 .irqindex_host_ipc = -1,
117 .resindex_dma_base = -1,
118 .chip_info = &apl_chip_info,
119 .default_fw_path = "intel/sof",
120 .default_tplg_path = "intel/sof-tplg",
121 .default_fw_filename = "sof-apl.ri",
122 .nocodec_tplg_filename = "sof-apl-nocodec.tplg",
127 #if IS_ENABLED(CONFIG_SND_SOC_SOF_GEMINILAKE)
128 static const struct sof_dev_desc glk_desc = {
129 .machines = snd_soc_acpi_intel_glk_machines,
130 .use_acpi_target_states = true,
131 .resindex_lpe_base = 0,
132 .resindex_pcicfg_base = -1,
133 .resindex_imr_base = -1,
134 .irqindex_host_ipc = -1,
135 .resindex_dma_base = -1,
136 .chip_info = &apl_chip_info,
137 .default_fw_path = "intel/sof",
138 .default_tplg_path = "intel/sof-tplg",
139 .default_fw_filename = "sof-glk.ri",
140 .nocodec_tplg_filename = "sof-glk-nocodec.tplg",
145 #if IS_ENABLED(CONFIG_SND_SOC_SOF_MERRIFIELD)
146 static struct snd_soc_acpi_mach sof_tng_machines[] = {
149 .drv_name = "edison",
150 .sof_fw_filename = "sof-byt.ri",
151 .sof_tplg_filename = "sof-byt.tplg",
156 static const struct sof_dev_desc tng_desc = {
157 .machines = sof_tng_machines,
158 .resindex_lpe_base = 3, /* IRAM, but subtract IRAM offset */
159 .resindex_pcicfg_base = -1,
160 .resindex_imr_base = 0,
161 .irqindex_host_ipc = -1,
162 .resindex_dma_base = -1,
163 .chip_info = &tng_chip_info,
164 .default_fw_path = "intel/sof",
165 .default_tplg_path = "intel/sof-tplg",
166 .default_fw_filename = "sof-byt.ri",
167 .nocodec_tplg_filename = "sof-byt.tplg",
172 #if IS_ENABLED(CONFIG_SND_SOC_SOF_CANNONLAKE)
173 static const struct sof_dev_desc cnl_desc = {
174 .machines = snd_soc_acpi_intel_cnl_machines,
175 .alt_machines = snd_soc_acpi_intel_cnl_sdw_machines,
176 .use_acpi_target_states = true,
177 .resindex_lpe_base = 0,
178 .resindex_pcicfg_base = -1,
179 .resindex_imr_base = -1,
180 .irqindex_host_ipc = -1,
181 .resindex_dma_base = -1,
182 .chip_info = &cnl_chip_info,
183 .default_fw_path = "intel/sof",
184 .default_tplg_path = "intel/sof-tplg",
185 .default_fw_filename = "sof-cnl.ri",
186 .nocodec_tplg_filename = "sof-cnl-nocodec.tplg",
191 #if IS_ENABLED(CONFIG_SND_SOC_SOF_COFFEELAKE)
192 static const struct sof_dev_desc cfl_desc = {
193 .machines = snd_soc_acpi_intel_cfl_machines,
194 .alt_machines = snd_soc_acpi_intel_cfl_sdw_machines,
195 .use_acpi_target_states = true,
196 .resindex_lpe_base = 0,
197 .resindex_pcicfg_base = -1,
198 .resindex_imr_base = -1,
199 .irqindex_host_ipc = -1,
200 .resindex_dma_base = -1,
201 .chip_info = &cnl_chip_info,
202 .default_fw_path = "intel/sof",
203 .default_tplg_path = "intel/sof-tplg",
204 .default_fw_filename = "sof-cfl.ri",
205 .nocodec_tplg_filename = "sof-cnl-nocodec.tplg",
210 #if IS_ENABLED(CONFIG_SND_SOC_SOF_COMETLAKE)
211 static const struct sof_dev_desc cml_desc = {
212 .machines = snd_soc_acpi_intel_cml_machines,
213 .alt_machines = snd_soc_acpi_intel_cml_sdw_machines,
214 .use_acpi_target_states = true,
215 .resindex_lpe_base = 0,
216 .resindex_pcicfg_base = -1,
217 .resindex_imr_base = -1,
218 .irqindex_host_ipc = -1,
219 .resindex_dma_base = -1,
220 .chip_info = &cnl_chip_info,
221 .default_fw_path = "intel/sof",
222 .default_tplg_path = "intel/sof-tplg",
223 .default_fw_filename = "sof-cml.ri",
224 .nocodec_tplg_filename = "sof-cnl-nocodec.tplg",
229 #if IS_ENABLED(CONFIG_SND_SOC_SOF_ICELAKE)
230 static const struct sof_dev_desc icl_desc = {
231 .machines = snd_soc_acpi_intel_icl_machines,
232 .alt_machines = snd_soc_acpi_intel_icl_sdw_machines,
233 .use_acpi_target_states = true,
234 .resindex_lpe_base = 0,
235 .resindex_pcicfg_base = -1,
236 .resindex_imr_base = -1,
237 .irqindex_host_ipc = -1,
238 .resindex_dma_base = -1,
239 .chip_info = &icl_chip_info,
240 .default_fw_path = "intel/sof",
241 .default_tplg_path = "intel/sof-tplg",
242 .default_fw_filename = "sof-icl.ri",
243 .nocodec_tplg_filename = "sof-icl-nocodec.tplg",
248 #if IS_ENABLED(CONFIG_SND_SOC_SOF_TIGERLAKE)
249 static const struct sof_dev_desc tgl_desc = {
250 .machines = snd_soc_acpi_intel_tgl_machines,
251 .alt_machines = snd_soc_acpi_intel_tgl_sdw_machines,
252 .use_acpi_target_states = true,
253 .resindex_lpe_base = 0,
254 .resindex_pcicfg_base = -1,
255 .resindex_imr_base = -1,
256 .irqindex_host_ipc = -1,
257 .resindex_dma_base = -1,
258 .chip_info = &tgl_chip_info,
259 .default_fw_path = "intel/sof",
260 .default_tplg_path = "intel/sof-tplg",
261 .default_fw_filename = "sof-tgl.ri",
262 .nocodec_tplg_filename = "sof-tgl-nocodec.tplg",
266 static const struct sof_dev_desc tglh_desc = {
267 .machines = snd_soc_acpi_intel_tgl_machines,
268 .alt_machines = snd_soc_acpi_intel_tgl_sdw_machines,
269 .resindex_lpe_base = 0,
270 .resindex_pcicfg_base = -1,
271 .resindex_imr_base = -1,
272 .irqindex_host_ipc = -1,
273 .resindex_dma_base = -1,
274 .chip_info = &tglh_chip_info,
275 .default_fw_path = "intel/sof",
276 .default_tplg_path = "intel/sof-tplg",
277 .default_fw_filename = "sof-tgl-h.ri",
278 .nocodec_tplg_filename = "sof-tgl-nocodec.tplg",
283 #if IS_ENABLED(CONFIG_SND_SOC_SOF_ELKHARTLAKE)
284 static const struct sof_dev_desc ehl_desc = {
285 .machines = snd_soc_acpi_intel_ehl_machines,
286 .use_acpi_target_states = true,
287 .resindex_lpe_base = 0,
288 .resindex_pcicfg_base = -1,
289 .resindex_imr_base = -1,
290 .irqindex_host_ipc = -1,
291 .resindex_dma_base = -1,
292 .chip_info = &ehl_chip_info,
293 .default_fw_path = "intel/sof",
294 .default_tplg_path = "intel/sof-tplg",
295 .default_fw_filename = "sof-ehl.ri",
296 .nocodec_tplg_filename = "sof-ehl-nocodec.tplg",
301 #if IS_ENABLED(CONFIG_SND_SOC_SOF_JASPERLAKE)
302 static const struct sof_dev_desc jsl_desc = {
303 .machines = snd_soc_acpi_intel_jsl_machines,
304 .use_acpi_target_states = true,
305 .resindex_lpe_base = 0,
306 .resindex_pcicfg_base = -1,
307 .resindex_imr_base = -1,
308 .irqindex_host_ipc = -1,
309 .resindex_dma_base = -1,
310 .chip_info = &jsl_chip_info,
311 .default_fw_path = "intel/sof",
312 .default_tplg_path = "intel/sof-tplg",
313 .default_fw_filename = "sof-jsl.ri",
314 .nocodec_tplg_filename = "sof-jsl-nocodec.tplg",
319 static const struct dev_pm_ops sof_pci_pm = {
320 .prepare = snd_sof_prepare,
321 .complete = snd_sof_complete,
322 SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume)
323 SET_RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume,
324 snd_sof_runtime_idle)
327 static void sof_pci_probe_complete(struct device *dev)
329 dev_dbg(dev, "Completing SOF PCI probe");
331 if (sof_pci_debug & SOF_PCI_DISABLE_PM_RUNTIME)
334 /* allow runtime_pm */
335 pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS);
336 pm_runtime_use_autosuspend(dev);
339 * runtime pm for pci device is "forbidden" by default.
340 * so call pm_runtime_allow() to enable it.
342 pm_runtime_allow(dev);
344 /* mark last_busy for pm_runtime to make sure not suspend immediately */
345 pm_runtime_mark_last_busy(dev);
347 /* follow recommendation in pci-driver.c to decrement usage counter */
348 pm_runtime_put_noidle(dev);
351 static int sof_pci_probe(struct pci_dev *pci,
352 const struct pci_device_id *pci_id)
354 struct device *dev = &pci->dev;
355 const struct sof_dev_desc *desc =
356 (const struct sof_dev_desc *)pci_id->driver_data;
357 struct snd_sof_pdata *sof_pdata;
358 const struct snd_sof_dsp_ops *ops;
361 ret = snd_intel_dsp_driver_probe(pci);
362 if (ret != SND_INTEL_DSP_DRIVER_ANY && ret != SND_INTEL_DSP_DRIVER_SOF) {
363 dev_dbg(&pci->dev, "SOF PCI driver not selected, aborting probe\n");
366 dev_dbg(&pci->dev, "PCI DSP detected");
368 /* get ops for platform */
371 dev_err(dev, "error: no matching PCI descriptor ops\n");
375 sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL);
379 ret = pcim_enable_device(pci);
383 ret = pci_request_regions(pci, "Audio DSP");
387 sof_pdata->name = pci_name(pci);
388 sof_pdata->desc = (struct sof_dev_desc *)pci_id->driver_data;
389 sof_pdata->dev = dev;
390 sof_pdata->fw_filename = desc->default_fw_filename;
393 * for platforms using the SOF community key, change the
394 * default path automatically to pick the right files from the
395 * linux-firmware tree. This can be overridden with the
396 * fw_path kernel parameter, e.g. for developers.
399 /* alternate fw and tplg filenames ? */
401 sof_pdata->fw_filename_prefix = fw_path;
404 "Module parameter used, changed fw path to %s\n",
405 sof_pdata->fw_filename_prefix);
407 } else if (dmi_check_system(community_key_platforms) && sof_dmi_use_community_key) {
408 sof_pdata->fw_filename_prefix =
409 devm_kasprintf(dev, GFP_KERNEL, "%s/%s",
410 sof_pdata->desc->default_fw_path,
414 "Platform uses community key, changed fw path to %s\n",
415 sof_pdata->fw_filename_prefix);
417 sof_pdata->fw_filename_prefix =
418 sof_pdata->desc->default_fw_path;
422 sof_pdata->tplg_filename_prefix = tplg_path;
424 sof_pdata->tplg_filename_prefix =
425 sof_pdata->desc->default_tplg_path;
428 * the topology filename will be provided in the machine descriptor, unless
429 * it is overridden by a module parameter or DMI quirk.
432 sof_pdata->tplg_filename = tplg_filename;
434 dev_dbg(dev, "Module parameter used, changed tplg filename to %s\n",
435 sof_pdata->tplg_filename);
437 dmi_check_system(sof_tplg_table);
438 if (sof_dmi_override_tplg_name)
439 sof_pdata->tplg_filename = sof_dmi_override_tplg_name;
442 #if IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)
443 /* set callback to enable runtime_pm */
444 sof_pdata->sof_probe_complete = sof_pci_probe_complete;
446 /* call sof helper for DSP hardware probe */
447 ret = snd_sof_device_probe(dev, sof_pdata);
449 dev_err(dev, "error: failed to probe DSP hardware!\n");
450 goto release_regions;
453 #if !IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)
454 sof_pci_probe_complete(dev);
460 pci_release_regions(pci);
465 static void sof_pci_remove(struct pci_dev *pci)
467 /* call sof helper for DSP hardware remove */
468 snd_sof_device_remove(&pci->dev);
470 /* follow recommendation in pci-driver.c to increment usage counter */
471 if (!(sof_pci_debug & SOF_PCI_DISABLE_PM_RUNTIME))
472 pm_runtime_get_noresume(&pci->dev);
474 /* release pci regions and disable device */
475 pci_release_regions(pci);
479 static const struct pci_device_id sof_pci_ids[] = {
480 #if IS_ENABLED(CONFIG_SND_SOC_SOF_MERRIFIELD)
481 { PCI_DEVICE(0x8086, 0x119a),
482 .driver_data = (unsigned long)&tng_desc},
484 #if IS_ENABLED(CONFIG_SND_SOC_SOF_APOLLOLAKE)
485 /* BXT-P & Apollolake */
486 { PCI_DEVICE(0x8086, 0x5a98),
487 .driver_data = (unsigned long)&bxt_desc},
488 { PCI_DEVICE(0x8086, 0x1a98),
489 .driver_data = (unsigned long)&bxt_desc},
491 #if IS_ENABLED(CONFIG_SND_SOC_SOF_GEMINILAKE)
492 { PCI_DEVICE(0x8086, 0x3198),
493 .driver_data = (unsigned long)&glk_desc},
495 #if IS_ENABLED(CONFIG_SND_SOC_SOF_CANNONLAKE)
496 { PCI_DEVICE(0x8086, 0x9dc8),
497 .driver_data = (unsigned long)&cnl_desc},
499 #if IS_ENABLED(CONFIG_SND_SOC_SOF_COFFEELAKE)
500 { PCI_DEVICE(0x8086, 0xa348),
501 .driver_data = (unsigned long)&cfl_desc},
503 #if IS_ENABLED(CONFIG_SND_SOC_SOF_ICELAKE)
504 { PCI_DEVICE(0x8086, 0x34C8), /* ICL-LP */
505 .driver_data = (unsigned long)&icl_desc},
506 { PCI_DEVICE(0x8086, 0x3dc8), /* ICL-H */
507 .driver_data = (unsigned long)&icl_desc},
510 #if IS_ENABLED(CONFIG_SND_SOC_SOF_JASPERLAKE)
511 { PCI_DEVICE(0x8086, 0x38c8),
512 .driver_data = (unsigned long)&jsl_desc},
513 { PCI_DEVICE(0x8086, 0x4dc8),
514 .driver_data = (unsigned long)&jsl_desc},
516 #if IS_ENABLED(CONFIG_SND_SOC_SOF_COMETLAKE)
517 { PCI_DEVICE(0x8086, 0x02c8), /* CML-LP */
518 .driver_data = (unsigned long)&cml_desc},
519 { PCI_DEVICE(0x8086, 0x06c8), /* CML-H */
520 .driver_data = (unsigned long)&cml_desc},
521 { PCI_DEVICE(0x8086, 0xa3f0), /* CML-S */
522 .driver_data = (unsigned long)&cml_desc},
524 #if IS_ENABLED(CONFIG_SND_SOC_SOF_TIGERLAKE)
525 { PCI_DEVICE(0x8086, 0xa0c8), /* TGL-LP */
526 .driver_data = (unsigned long)&tgl_desc},
527 { PCI_DEVICE(0x8086, 0x43c8), /* TGL-H */
528 .driver_data = (unsigned long)&tglh_desc},
531 #if IS_ENABLED(CONFIG_SND_SOC_SOF_ELKHARTLAKE)
532 { PCI_DEVICE(0x8086, 0x4b55),
533 .driver_data = (unsigned long)&ehl_desc},
534 { PCI_DEVICE(0x8086, 0x4b58),
535 .driver_data = (unsigned long)&ehl_desc},
539 MODULE_DEVICE_TABLE(pci, sof_pci_ids);
541 /* pci_driver definition */
542 static struct pci_driver snd_sof_pci_driver = {
543 .name = "sof-audio-pci",
544 .id_table = sof_pci_ids,
545 .probe = sof_pci_probe,
546 .remove = sof_pci_remove,
551 module_pci_driver(snd_sof_pci_driver);
553 MODULE_LICENSE("Dual BSD/GPL");
554 MODULE_IMPORT_NS(SND_SOC_SOF_MERRIFIELD);
555 MODULE_IMPORT_NS(SND_SOC_SOF_INTEL_HDA_COMMON);