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.
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/soc-acpi.h>
18 #include <sound/soc-acpi-intel-match.h>
19 #include <sound/sof.h>
21 #include "sof-pci-dev.h"
24 module_param(fw_path, charp, 0444);
25 MODULE_PARM_DESC(fw_path, "alternate path for SOF firmware.");
27 static char *fw_filename;
28 module_param(fw_filename, charp, 0444);
29 MODULE_PARM_DESC(fw_filename, "alternate filename for SOF firmware.");
31 static char *lib_path;
32 module_param(lib_path, charp, 0444);
33 MODULE_PARM_DESC(lib_path, "alternate path for SOF firmware libraries.");
35 static char *tplg_path;
36 module_param(tplg_path, charp, 0444);
37 MODULE_PARM_DESC(tplg_path, "alternate path for SOF topology.");
39 static char *tplg_filename;
40 module_param(tplg_filename, charp, 0444);
41 MODULE_PARM_DESC(tplg_filename, "alternate filename for SOF topology.");
43 static int sof_pci_debug;
44 module_param_named(sof_pci_debug, sof_pci_debug, int, 0444);
45 MODULE_PARM_DESC(sof_pci_debug, "SOF PCI debug options (0x0 all off)");
47 static int sof_pci_ipc_type = -1;
48 module_param_named(ipc_type, sof_pci_ipc_type, int, 0444);
49 MODULE_PARM_DESC(ipc_type, "SOF IPC type (0): SOF, (1) Intel CAVS");
51 static const char *sof_dmi_override_tplg_name;
52 static bool sof_dmi_use_community_key;
54 #define SOF_PCI_DISABLE_PM_RUNTIME BIT(0)
56 static int sof_tplg_cb(const struct dmi_system_id *id)
58 sof_dmi_override_tplg_name = id->driver_data;
62 static const struct dmi_system_id sof_tplg_table[] = {
64 .callback = sof_tplg_cb,
66 DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Volteer"),
67 DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98373_ALC5682I_I2S_UP4"),
69 .driver_data = "sof-tgl-rt5682-ssp0-max98373-ssp2.tplg",
72 .callback = sof_tplg_cb,
74 DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
75 DMI_MATCH(DMI_PRODUCT_NAME, "Alder Lake Client Platform"),
76 DMI_MATCH(DMI_OEM_STRING, "AUDIO-ADL_MAX98373_ALC5682I_I2S"),
78 .driver_data = "sof-adl-rt5682-ssp0-max98373-ssp2.tplg",
81 .callback = sof_tplg_cb,
83 DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Brya"),
84 DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98390_ALC5682I_I2S"),
86 .driver_data = "sof-adl-max98390-ssp2-rt5682-ssp0.tplg",
89 .callback = sof_tplg_cb,
91 DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Brya"),
92 DMI_MATCH(DMI_OEM_STRING, "AUDIO_AMP-MAX98360_ALC5682VS_I2S_2WAY"),
94 .driver_data = "sof-adl-max98360a-rt5682-2way.tplg",
97 .callback = sof_tplg_cb,
99 DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Brya"),
100 DMI_MATCH(DMI_OEM_STRING, "AUDIO-AUDIO_MAX98357_ALC5682I_I2S_2WAY"),
102 .driver_data = "sof-adl-max98357a-rt5682-2way.tplg",
105 .callback = sof_tplg_cb,
107 DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Brya"),
108 DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98360_ALC5682I_I2S_AMP_SSP2"),
110 .driver_data = "sof-adl-max98357a-rt5682.tplg",
115 /* all Up boards use the community key */
116 static int up_use_community_key(const struct dmi_system_id *id)
118 sof_dmi_use_community_key = true;
123 * For ApolloLake Chromebooks we want to force the use of the Intel production key.
124 * All newer platforms use the community key
126 static int chromebook_use_community_key(const struct dmi_system_id *id)
128 if (!soc_intel_is_apl())
129 sof_dmi_use_community_key = true;
133 static const struct dmi_system_id community_key_platforms[] = {
135 .ident = "Up boards",
136 .callback = up_use_community_key,
138 DMI_MATCH(DMI_SYS_VENDOR, "AAEON"),
142 .ident = "Google Chromebooks",
143 .callback = chromebook_use_community_key,
145 DMI_MATCH(DMI_PRODUCT_FAMILY, "Google"),
151 const struct dev_pm_ops sof_pci_pm = {
152 .prepare = snd_sof_prepare,
153 .complete = snd_sof_complete,
154 SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume)
155 SET_RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume,
156 snd_sof_runtime_idle)
158 EXPORT_SYMBOL_NS(sof_pci_pm, SND_SOC_SOF_PCI_DEV);
160 static void sof_pci_probe_complete(struct device *dev)
162 dev_dbg(dev, "Completing SOF PCI probe");
164 if (sof_pci_debug & SOF_PCI_DISABLE_PM_RUNTIME)
167 /* allow runtime_pm */
168 pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS);
169 pm_runtime_use_autosuspend(dev);
172 * runtime pm for pci device is "forbidden" by default.
173 * so call pm_runtime_allow() to enable it.
175 pm_runtime_allow(dev);
177 /* mark last_busy for pm_runtime to make sure not suspend immediately */
178 pm_runtime_mark_last_busy(dev);
180 /* follow recommendation in pci-driver.c to decrement usage counter */
181 pm_runtime_put_noidle(dev);
184 int sof_pci_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
186 struct device *dev = &pci->dev;
187 const struct sof_dev_desc *desc =
188 (const struct sof_dev_desc *)pci_id->driver_data;
189 struct snd_sof_pdata *sof_pdata;
192 dev_dbg(&pci->dev, "PCI DSP detected");
195 dev_err(dev, "error: no matching PCI descriptor\n");
200 dev_err(dev, "error: no matching PCI descriptor ops\n");
204 sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL);
208 ret = pcim_enable_device(pci);
212 ret = pci_request_regions(pci, "Audio DSP");
216 sof_pdata->name = pci_name(pci);
217 sof_pdata->desc = desc;
218 sof_pdata->dev = dev;
220 sof_pdata->ipc_type = desc->ipc_default;
222 if (sof_pci_ipc_type < 0) {
223 sof_pdata->ipc_type = desc->ipc_default;
225 dev_info(dev, "overriding default IPC %d to requested %d\n",
226 desc->ipc_default, sof_pci_ipc_type);
227 if (sof_pci_ipc_type >= SOF_IPC_TYPE_COUNT) {
228 dev_err(dev, "invalid request value %d\n", sof_pci_ipc_type);
232 if (!(BIT(sof_pci_ipc_type) & desc->ipc_supported_mask)) {
233 dev_err(dev, "invalid request value %d, supported mask is %#x\n",
234 sof_pci_ipc_type, desc->ipc_supported_mask);
238 sof_pdata->ipc_type = sof_pci_ipc_type;
242 sof_pdata->fw_filename = fw_filename;
244 dev_dbg(dev, "Module parameter used, changed fw filename to %s\n",
245 sof_pdata->fw_filename);
247 sof_pdata->fw_filename = desc->default_fw_filename[sof_pdata->ipc_type];
251 * for platforms using the SOF community key, change the
252 * default path automatically to pick the right files from the
253 * linux-firmware tree. This can be overridden with the
254 * fw_path kernel parameter, e.g. for developers.
257 /* alternate fw and tplg filenames ? */
259 sof_pdata->fw_filename_prefix = fw_path;
262 "Module parameter used, changed fw path to %s\n",
263 sof_pdata->fw_filename_prefix);
265 } else if (dmi_check_system(community_key_platforms) && sof_dmi_use_community_key) {
266 sof_pdata->fw_filename_prefix =
267 devm_kasprintf(dev, GFP_KERNEL, "%s/%s",
268 sof_pdata->desc->default_fw_path[sof_pdata->ipc_type],
272 "Platform uses community key, changed fw path to %s\n",
273 sof_pdata->fw_filename_prefix);
275 sof_pdata->fw_filename_prefix =
276 sof_pdata->desc->default_fw_path[sof_pdata->ipc_type];
280 sof_pdata->fw_lib_prefix = lib_path;
282 dev_dbg(dev, "Module parameter used, changed fw_lib path to %s\n",
283 sof_pdata->fw_lib_prefix);
285 } else if (sof_pdata->desc->default_lib_path[sof_pdata->ipc_type]) {
286 if (dmi_check_system(community_key_platforms) && sof_dmi_use_community_key) {
287 sof_pdata->fw_lib_prefix =
288 devm_kasprintf(dev, GFP_KERNEL, "%s/%s",
289 sof_pdata->desc->default_lib_path[sof_pdata->ipc_type],
293 "Platform uses community key, changed fw_lib path to %s\n",
294 sof_pdata->fw_lib_prefix);
296 sof_pdata->fw_lib_prefix =
297 sof_pdata->desc->default_lib_path[sof_pdata->ipc_type];
302 sof_pdata->tplg_filename_prefix = tplg_path;
304 sof_pdata->tplg_filename_prefix =
305 sof_pdata->desc->default_tplg_path[sof_pdata->ipc_type];
308 * the topology filename will be provided in the machine descriptor, unless
309 * it is overridden by a module parameter or DMI quirk.
312 sof_pdata->tplg_filename = tplg_filename;
314 dev_dbg(dev, "Module parameter used, changed tplg filename to %s\n",
315 sof_pdata->tplg_filename);
317 dmi_check_system(sof_tplg_table);
318 if (sof_dmi_override_tplg_name)
319 sof_pdata->tplg_filename = sof_dmi_override_tplg_name;
322 /* set callback to be called on successful device probe to enable runtime_pm */
323 sof_pdata->sof_probe_complete = sof_pci_probe_complete;
325 /* call sof helper for DSP hardware probe */
326 ret = snd_sof_device_probe(dev, sof_pdata);
330 pci_release_regions(pci);
334 EXPORT_SYMBOL_NS(sof_pci_probe, SND_SOC_SOF_PCI_DEV);
336 void sof_pci_remove(struct pci_dev *pci)
338 /* call sof helper for DSP hardware remove */
339 snd_sof_device_remove(&pci->dev);
341 /* follow recommendation in pci-driver.c to increment usage counter */
342 if (snd_sof_device_probe_completed(&pci->dev) &&
343 !(sof_pci_debug & SOF_PCI_DISABLE_PM_RUNTIME))
344 pm_runtime_get_noresume(&pci->dev);
346 /* release pci regions and disable device */
347 pci_release_regions(pci);
349 EXPORT_SYMBOL_NS(sof_pci_remove, SND_SOC_SOF_PCI_DEV);
351 void sof_pci_shutdown(struct pci_dev *pci)
353 snd_sof_device_shutdown(&pci->dev);
355 EXPORT_SYMBOL_NS(sof_pci_shutdown, SND_SOC_SOF_PCI_DEV);
357 MODULE_LICENSE("Dual BSD/GPL");