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/pm_runtime.h>
16 #include <sound/soc-acpi.h>
17 #include <sound/soc-acpi-intel-match.h>
18 #include <sound/sof.h>
20 #include "sof-pci-dev.h"
23 module_param(fw_path, charp, 0444);
24 MODULE_PARM_DESC(fw_path, "alternate path for SOF firmware.");
26 static char *tplg_path;
27 module_param(tplg_path, charp, 0444);
28 MODULE_PARM_DESC(tplg_path, "alternate path for SOF topology.");
30 static int sof_pci_debug;
31 module_param_named(sof_pci_debug, sof_pci_debug, int, 0444);
32 MODULE_PARM_DESC(sof_pci_debug, "SOF PCI debug options (0x0 all off)");
34 static const char *sof_override_tplg_name;
36 #define SOF_PCI_DISABLE_PM_RUNTIME BIT(0)
38 static int sof_tplg_cb(const struct dmi_system_id *id)
40 sof_override_tplg_name = id->driver_data;
44 static const struct dmi_system_id sof_tplg_table[] = {
46 .callback = sof_tplg_cb,
48 DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Volteer"),
49 DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98373_ALC5682I_I2S_UP4"),
51 .driver_data = "sof-tgl-rt5682-ssp0-max98373-ssp2.tplg",
56 static const struct dmi_system_id community_key_platforms[] = {
58 .ident = "Up Squared",
60 DMI_MATCH(DMI_SYS_VENDOR, "AAEON"),
61 DMI_MATCH(DMI_BOARD_NAME, "UP-APL01"),
65 .ident = "Up Extreme",
67 DMI_MATCH(DMI_SYS_VENDOR, "AAEON"),
68 DMI_MATCH(DMI_BOARD_NAME, "UP-WHL01"),
72 .ident = "Google Chromebooks",
74 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
80 const struct dev_pm_ops sof_pci_pm = {
81 .prepare = snd_sof_prepare,
82 .complete = snd_sof_complete,
83 SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume)
84 SET_RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume,
87 EXPORT_SYMBOL_NS(sof_pci_pm, SND_SOC_SOF_PCI_DEV);
89 static void sof_pci_probe_complete(struct device *dev)
91 dev_dbg(dev, "Completing SOF PCI probe");
93 if (sof_pci_debug & SOF_PCI_DISABLE_PM_RUNTIME)
96 /* allow runtime_pm */
97 pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS);
98 pm_runtime_use_autosuspend(dev);
101 * runtime pm for pci device is "forbidden" by default.
102 * so call pm_runtime_allow() to enable it.
104 pm_runtime_allow(dev);
106 /* mark last_busy for pm_runtime to make sure not suspend immediately */
107 pm_runtime_mark_last_busy(dev);
109 /* follow recommendation in pci-driver.c to decrement usage counter */
110 pm_runtime_put_noidle(dev);
113 int sof_pci_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
115 struct device *dev = &pci->dev;
116 const struct sof_dev_desc *desc =
117 (const struct sof_dev_desc *)pci_id->driver_data;
118 struct snd_sof_pdata *sof_pdata;
119 const struct snd_sof_dsp_ops *ops;
122 dev_dbg(&pci->dev, "PCI DSP detected");
124 /* get ops for platform */
127 dev_err(dev, "error: no matching PCI descriptor ops\n");
131 sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL);
135 ret = pcim_enable_device(pci);
139 ret = pci_request_regions(pci, "Audio DSP");
143 sof_pdata->name = pci_name(pci);
144 sof_pdata->desc = (struct sof_dev_desc *)pci_id->driver_data;
145 sof_pdata->dev = dev;
146 sof_pdata->fw_filename = desc->default_fw_filename;
149 * for platforms using the SOF community key, change the
150 * default path automatically to pick the right files from the
151 * linux-firmware tree. This can be overridden with the
152 * fw_path kernel parameter, e.g. for developers.
155 /* alternate fw and tplg filenames ? */
157 sof_pdata->fw_filename_prefix = fw_path;
160 "Module parameter used, changed fw path to %s\n",
161 sof_pdata->fw_filename_prefix);
163 } else if (dmi_check_system(community_key_platforms)) {
164 sof_pdata->fw_filename_prefix =
165 devm_kasprintf(dev, GFP_KERNEL, "%s/%s",
166 sof_pdata->desc->default_fw_path,
170 "Platform uses community key, changed fw path to %s\n",
171 sof_pdata->fw_filename_prefix);
173 sof_pdata->fw_filename_prefix =
174 sof_pdata->desc->default_fw_path;
178 sof_pdata->tplg_filename_prefix = tplg_path;
180 sof_pdata->tplg_filename_prefix =
181 sof_pdata->desc->default_tplg_path;
183 dmi_check_system(sof_tplg_table);
184 if (sof_override_tplg_name)
185 sof_pdata->tplg_filename = sof_override_tplg_name;
187 #if IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)
188 /* set callback to enable runtime_pm */
189 sof_pdata->sof_probe_complete = sof_pci_probe_complete;
191 /* call sof helper for DSP hardware probe */
192 ret = snd_sof_device_probe(dev, sof_pdata);
194 dev_err(dev, "error: failed to probe DSP hardware!\n");
195 goto release_regions;
198 #if !IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)
199 sof_pci_probe_complete(dev);
205 pci_release_regions(pci);
209 EXPORT_SYMBOL_NS(sof_pci_probe, SND_SOC_SOF_PCI_DEV);
211 void sof_pci_remove(struct pci_dev *pci)
213 /* call sof helper for DSP hardware remove */
214 snd_sof_device_remove(&pci->dev);
216 /* follow recommendation in pci-driver.c to increment usage counter */
217 if (snd_sof_device_probe_completed(&pci->dev) &&
218 !(sof_pci_debug & SOF_PCI_DISABLE_PM_RUNTIME))
219 pm_runtime_get_noresume(&pci->dev);
221 /* release pci regions and disable device */
222 pci_release_regions(pci);
224 EXPORT_SYMBOL_NS(sof_pci_remove, SND_SOC_SOF_PCI_DEV);
226 void sof_pci_shutdown(struct pci_dev *pci)
228 snd_sof_device_shutdown(&pci->dev);
230 EXPORT_SYMBOL_NS(sof_pci_shutdown, SND_SOC_SOF_PCI_DEV);
232 MODULE_LICENSE("Dual BSD/GPL");