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/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 *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 int sof_pci_ipc_type = -1;
44 module_param_named(ipc_type, sof_pci_ipc_type, int, 0444);
45 MODULE_PARM_DESC(ipc_type, "SOF IPC type (0): SOF, (1) Intel CAVS");
47 static const char *sof_dmi_override_tplg_name;
48 static bool sof_dmi_use_community_key;
50 #define SOF_PCI_DISABLE_PM_RUNTIME BIT(0)
52 static int sof_tplg_cb(const struct dmi_system_id *id)
54 sof_dmi_override_tplg_name = id->driver_data;
58 static const struct dmi_system_id sof_tplg_table[] = {
60 .callback = sof_tplg_cb,
62 DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Volteer"),
63 DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98373_ALC5682I_I2S_UP4"),
65 .driver_data = "sof-tgl-rt5682-ssp0-max98373-ssp2.tplg",
68 .callback = sof_tplg_cb,
70 DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
71 DMI_MATCH(DMI_PRODUCT_NAME, "Alder Lake Client Platform"),
72 DMI_MATCH(DMI_OEM_STRING, "AUDIO-ADL_MAX98373_ALC5682I_I2S"),
74 .driver_data = "sof-adl-rt5682-ssp0-max98373-ssp2.tplg",
77 .callback = sof_tplg_cb,
79 DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Brya"),
80 DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98390_ALC5682I_I2S"),
82 .driver_data = "sof-adl-max98390-ssp2-rt5682-ssp0.tplg",
85 .callback = sof_tplg_cb,
87 DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Brya"),
88 DMI_MATCH(DMI_OEM_STRING, "AUDIO_AMP-MAX98360_ALC5682VS_I2S_2WAY"),
90 .driver_data = "sof-adl-max98360a-rt5682-2way.tplg",
93 .callback = sof_tplg_cb,
95 DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Brya"),
96 DMI_MATCH(DMI_OEM_STRING, "AUDIO-AUDIO_MAX98357_ALC5682I_I2S_2WAY"),
98 .driver_data = "sof-adl-max98357a-rt5682-2way.tplg",
101 .callback = sof_tplg_cb,
103 DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Brya"),
104 DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98360_ALC5682I_I2S_AMP_SSP2"),
106 .driver_data = "sof-adl-max98357a-rt5682.tplg",
111 /* all Up boards use the community key */
112 static int up_use_community_key(const struct dmi_system_id *id)
114 sof_dmi_use_community_key = true;
119 * For ApolloLake Chromebooks we want to force the use of the Intel production key.
120 * All newer platforms use the community key
122 static int chromebook_use_community_key(const struct dmi_system_id *id)
124 if (!soc_intel_is_apl())
125 sof_dmi_use_community_key = true;
129 static const struct dmi_system_id community_key_platforms[] = {
131 .ident = "Up boards",
132 .callback = up_use_community_key,
134 DMI_MATCH(DMI_SYS_VENDOR, "AAEON"),
138 .ident = "Google Chromebooks",
139 .callback = chromebook_use_community_key,
141 DMI_MATCH(DMI_PRODUCT_FAMILY, "Google"),
145 .ident = "Google firmware",
146 .callback = chromebook_use_community_key,
148 DMI_MATCH(DMI_BIOS_VERSION, "Google"),
154 const struct dev_pm_ops sof_pci_pm = {
155 .prepare = snd_sof_prepare,
156 .complete = snd_sof_complete,
157 SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume)
158 SET_RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume,
159 snd_sof_runtime_idle)
161 EXPORT_SYMBOL_NS(sof_pci_pm, SND_SOC_SOF_PCI_DEV);
163 static void sof_pci_probe_complete(struct device *dev)
165 dev_dbg(dev, "Completing SOF PCI probe");
167 if (sof_pci_debug & SOF_PCI_DISABLE_PM_RUNTIME)
170 /* allow runtime_pm */
171 pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS);
172 pm_runtime_use_autosuspend(dev);
175 * runtime pm for pci device is "forbidden" by default.
176 * so call pm_runtime_allow() to enable it.
178 pm_runtime_allow(dev);
180 /* mark last_busy for pm_runtime to make sure not suspend immediately */
181 pm_runtime_mark_last_busy(dev);
183 /* follow recommendation in pci-driver.c to decrement usage counter */
184 pm_runtime_put_noidle(dev);
187 int sof_pci_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
189 struct device *dev = &pci->dev;
190 const struct sof_dev_desc *desc =
191 (const struct sof_dev_desc *)pci_id->driver_data;
192 struct snd_sof_pdata *sof_pdata;
195 dev_dbg(&pci->dev, "PCI DSP detected");
198 dev_err(dev, "error: no matching PCI descriptor\n");
203 dev_err(dev, "error: no matching PCI descriptor ops\n");
207 sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL);
211 ret = pcim_enable_device(pci);
215 ret = pci_request_regions(pci, "Audio DSP");
219 sof_pdata->name = pci_name(pci);
221 /* PCI defines a vendor ID of 0xFFFF as invalid. */
222 if (pci->subsystem_vendor != 0xFFFF) {
223 sof_pdata->subsystem_vendor = pci->subsystem_vendor;
224 sof_pdata->subsystem_device = pci->subsystem_device;
225 sof_pdata->subsystem_id_set = true;
228 sof_pdata->desc = desc;
229 sof_pdata->dev = dev;
231 sof_pdata->ipc_type = desc->ipc_default;
233 if (sof_pci_ipc_type < 0) {
234 sof_pdata->ipc_type = desc->ipc_default;
236 dev_info(dev, "overriding default IPC %d to requested %d\n",
237 desc->ipc_default, sof_pci_ipc_type);
238 if (sof_pci_ipc_type >= SOF_IPC_TYPE_COUNT) {
239 dev_err(dev, "invalid request value %d\n", sof_pci_ipc_type);
243 if (!(BIT(sof_pci_ipc_type) & desc->ipc_supported_mask)) {
244 dev_err(dev, "invalid request value %d, supported mask is %#x\n",
245 sof_pci_ipc_type, desc->ipc_supported_mask);
249 sof_pdata->ipc_type = sof_pci_ipc_type;
253 sof_pdata->fw_filename = fw_filename;
255 dev_dbg(dev, "Module parameter used, changed fw filename to %s\n",
256 sof_pdata->fw_filename);
258 sof_pdata->fw_filename = desc->default_fw_filename[sof_pdata->ipc_type];
262 * for platforms using the SOF community key, change the
263 * default path automatically to pick the right files from the
264 * linux-firmware tree. This can be overridden with the
265 * fw_path kernel parameter, e.g. for developers.
268 /* alternate fw and tplg filenames ? */
270 sof_pdata->fw_filename_prefix = fw_path;
273 "Module parameter used, changed fw path to %s\n",
274 sof_pdata->fw_filename_prefix);
276 } else if (dmi_check_system(community_key_platforms) && sof_dmi_use_community_key) {
277 sof_pdata->fw_filename_prefix =
278 devm_kasprintf(dev, GFP_KERNEL, "%s/%s",
279 sof_pdata->desc->default_fw_path[sof_pdata->ipc_type],
283 "Platform uses community key, changed fw path to %s\n",
284 sof_pdata->fw_filename_prefix);
286 sof_pdata->fw_filename_prefix =
287 sof_pdata->desc->default_fw_path[sof_pdata->ipc_type];
291 sof_pdata->tplg_filename_prefix = tplg_path;
293 sof_pdata->tplg_filename_prefix =
294 sof_pdata->desc->default_tplg_path[sof_pdata->ipc_type];
297 * the topology filename will be provided in the machine descriptor, unless
298 * it is overridden by a module parameter or DMI quirk.
301 sof_pdata->tplg_filename = tplg_filename;
303 dev_dbg(dev, "Module parameter used, changed tplg filename to %s\n",
304 sof_pdata->tplg_filename);
306 dmi_check_system(sof_tplg_table);
307 if (sof_dmi_override_tplg_name)
308 sof_pdata->tplg_filename = sof_dmi_override_tplg_name;
311 /* set callback to be called on successful device probe to enable runtime_pm */
312 sof_pdata->sof_probe_complete = sof_pci_probe_complete;
314 /* call sof helper for DSP hardware probe */
315 ret = snd_sof_device_probe(dev, sof_pdata);
319 pci_release_regions(pci);
323 EXPORT_SYMBOL_NS(sof_pci_probe, SND_SOC_SOF_PCI_DEV);
325 void sof_pci_remove(struct pci_dev *pci)
327 /* call sof helper for DSP hardware remove */
328 snd_sof_device_remove(&pci->dev);
330 /* follow recommendation in pci-driver.c to increment usage counter */
331 if (snd_sof_device_probe_completed(&pci->dev) &&
332 !(sof_pci_debug & SOF_PCI_DISABLE_PM_RUNTIME))
333 pm_runtime_get_noresume(&pci->dev);
335 /* release pci regions and disable device */
336 pci_release_regions(pci);
338 EXPORT_SYMBOL_NS(sof_pci_remove, SND_SOC_SOF_PCI_DEV);
340 void sof_pci_shutdown(struct pci_dev *pci)
342 snd_sof_device_shutdown(&pci->dev);
344 EXPORT_SYMBOL_NS(sof_pci_shutdown, SND_SOC_SOF_PCI_DEV);
346 MODULE_LICENSE("Dual BSD/GPL");