0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <linux/firmware.h>
0012 #include <linux/dmi.h>
0013 #include <linux/module.h>
0014 #include <linux/pci.h>
0015 #include <linux/platform_data/x86/soc.h>
0016 #include <linux/pm_runtime.h>
0017 #include <sound/soc-acpi.h>
0018 #include <sound/soc-acpi-intel-match.h>
0019 #include <sound/sof.h>
0020 #include "ops.h"
0021 #include "sof-pci-dev.h"
0022
0023 static char *fw_path;
0024 module_param(fw_path, charp, 0444);
0025 MODULE_PARM_DESC(fw_path, "alternate path for SOF firmware.");
0026
0027 static char *fw_filename;
0028 module_param(fw_filename, charp, 0444);
0029 MODULE_PARM_DESC(fw_filename, "alternate filename for SOF firmware.");
0030
0031 static char *tplg_path;
0032 module_param(tplg_path, charp, 0444);
0033 MODULE_PARM_DESC(tplg_path, "alternate path for SOF topology.");
0034
0035 static char *tplg_filename;
0036 module_param(tplg_filename, charp, 0444);
0037 MODULE_PARM_DESC(tplg_filename, "alternate filename for SOF topology.");
0038
0039 static int sof_pci_debug;
0040 module_param_named(sof_pci_debug, sof_pci_debug, int, 0444);
0041 MODULE_PARM_DESC(sof_pci_debug, "SOF PCI debug options (0x0 all off)");
0042
0043 static int sof_pci_ipc_type = -1;
0044 module_param_named(ipc_type, sof_pci_ipc_type, int, 0444);
0045 MODULE_PARM_DESC(ipc_type, "SOF IPC type (0): SOF, (1) Intel CAVS");
0046
0047 static const char *sof_dmi_override_tplg_name;
0048 static bool sof_dmi_use_community_key;
0049
0050 #define SOF_PCI_DISABLE_PM_RUNTIME BIT(0)
0051
0052 static int sof_tplg_cb(const struct dmi_system_id *id)
0053 {
0054 sof_dmi_override_tplg_name = id->driver_data;
0055 return 1;
0056 }
0057
0058 static const struct dmi_system_id sof_tplg_table[] = {
0059 {
0060 .callback = sof_tplg_cb,
0061 .matches = {
0062 DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Volteer"),
0063 DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98373_ALC5682I_I2S_UP4"),
0064 },
0065 .driver_data = "sof-tgl-rt5682-ssp0-max98373-ssp2.tplg",
0066 },
0067 {
0068 .callback = sof_tplg_cb,
0069 .matches = {
0070 DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
0071 DMI_MATCH(DMI_PRODUCT_NAME, "Alder Lake Client Platform"),
0072 DMI_MATCH(DMI_OEM_STRING, "AUDIO-ADL_MAX98373_ALC5682I_I2S"),
0073 },
0074 .driver_data = "sof-adl-rt5682-ssp0-max98373-ssp2.tplg",
0075 },
0076 {
0077 .callback = sof_tplg_cb,
0078 .matches = {
0079 DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Brya"),
0080 DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98390_ALC5682I_I2S"),
0081 },
0082 .driver_data = "sof-adl-max98390-ssp2-rt5682-ssp0.tplg",
0083 },
0084 {
0085 .callback = sof_tplg_cb,
0086 .matches = {
0087 DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Brya"),
0088 DMI_MATCH(DMI_OEM_STRING, "AUDIO_AMP-MAX98360_ALC5682VS_I2S_2WAY"),
0089 },
0090 .driver_data = "sof-adl-max98360a-rt5682-2way.tplg",
0091 },
0092 {
0093 .callback = sof_tplg_cb,
0094 .matches = {
0095 DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Brya"),
0096 DMI_MATCH(DMI_OEM_STRING, "AUDIO-AUDIO_MAX98357_ALC5682I_I2S_2WAY"),
0097 },
0098 .driver_data = "sof-adl-max98357a-rt5682-2way.tplg",
0099 },
0100 {
0101 .callback = sof_tplg_cb,
0102 .matches = {
0103 DMI_MATCH(DMI_PRODUCT_FAMILY, "Google_Brya"),
0104 DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98360_ALC5682I_I2S_AMP_SSP2"),
0105 },
0106 .driver_data = "sof-adl-max98357a-rt5682.tplg",
0107 },
0108 {}
0109 };
0110
0111
0112 static int up_use_community_key(const struct dmi_system_id *id)
0113 {
0114 sof_dmi_use_community_key = true;
0115 return 1;
0116 }
0117
0118
0119
0120
0121
0122 static int chromebook_use_community_key(const struct dmi_system_id *id)
0123 {
0124 if (!soc_intel_is_apl())
0125 sof_dmi_use_community_key = true;
0126 return 1;
0127 }
0128
0129 static const struct dmi_system_id community_key_platforms[] = {
0130 {
0131 .ident = "Up boards",
0132 .callback = up_use_community_key,
0133 .matches = {
0134 DMI_MATCH(DMI_SYS_VENDOR, "AAEON"),
0135 }
0136 },
0137 {
0138 .ident = "Google Chromebooks",
0139 .callback = chromebook_use_community_key,
0140 .matches = {
0141 DMI_MATCH(DMI_SYS_VENDOR, "Google"),
0142 }
0143 },
0144 {},
0145 };
0146
0147 const struct dev_pm_ops sof_pci_pm = {
0148 .prepare = snd_sof_prepare,
0149 .complete = snd_sof_complete,
0150 SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume)
0151 SET_RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume,
0152 snd_sof_runtime_idle)
0153 };
0154 EXPORT_SYMBOL_NS(sof_pci_pm, SND_SOC_SOF_PCI_DEV);
0155
0156 static void sof_pci_probe_complete(struct device *dev)
0157 {
0158 dev_dbg(dev, "Completing SOF PCI probe");
0159
0160 if (sof_pci_debug & SOF_PCI_DISABLE_PM_RUNTIME)
0161 return;
0162
0163
0164 pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS);
0165 pm_runtime_use_autosuspend(dev);
0166
0167
0168
0169
0170
0171 pm_runtime_allow(dev);
0172
0173
0174 pm_runtime_mark_last_busy(dev);
0175
0176
0177 pm_runtime_put_noidle(dev);
0178 }
0179
0180 int sof_pci_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
0181 {
0182 struct device *dev = &pci->dev;
0183 const struct sof_dev_desc *desc =
0184 (const struct sof_dev_desc *)pci_id->driver_data;
0185 struct snd_sof_pdata *sof_pdata;
0186 int ret;
0187
0188 dev_dbg(&pci->dev, "PCI DSP detected");
0189
0190 if (!desc) {
0191 dev_err(dev, "error: no matching PCI descriptor\n");
0192 return -ENODEV;
0193 }
0194
0195 if (!desc->ops) {
0196 dev_err(dev, "error: no matching PCI descriptor ops\n");
0197 return -ENODEV;
0198 }
0199
0200 sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL);
0201 if (!sof_pdata)
0202 return -ENOMEM;
0203
0204 ret = pcim_enable_device(pci);
0205 if (ret < 0)
0206 return ret;
0207
0208 ret = pci_request_regions(pci, "Audio DSP");
0209 if (ret < 0)
0210 return ret;
0211
0212 sof_pdata->name = pci_name(pci);
0213 sof_pdata->desc = desc;
0214 sof_pdata->dev = dev;
0215
0216 sof_pdata->ipc_type = desc->ipc_default;
0217
0218 if (sof_pci_ipc_type < 0) {
0219 sof_pdata->ipc_type = desc->ipc_default;
0220 } else {
0221 dev_info(dev, "overriding default IPC %d to requested %d\n",
0222 desc->ipc_default, sof_pci_ipc_type);
0223 if (sof_pci_ipc_type >= SOF_IPC_TYPE_COUNT) {
0224 dev_err(dev, "invalid request value %d\n", sof_pci_ipc_type);
0225 ret = -EINVAL;
0226 goto out;
0227 }
0228 if (!(BIT(sof_pci_ipc_type) & desc->ipc_supported_mask)) {
0229 dev_err(dev, "invalid request value %d, supported mask is %#x\n",
0230 sof_pci_ipc_type, desc->ipc_supported_mask);
0231 ret = -EINVAL;
0232 goto out;
0233 }
0234 sof_pdata->ipc_type = sof_pci_ipc_type;
0235 }
0236
0237 if (fw_filename) {
0238 sof_pdata->fw_filename = fw_filename;
0239
0240 dev_dbg(dev, "Module parameter used, changed fw filename to %s\n",
0241 sof_pdata->fw_filename);
0242 } else {
0243 sof_pdata->fw_filename = desc->default_fw_filename[sof_pdata->ipc_type];
0244 }
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254 if (fw_path) {
0255 sof_pdata->fw_filename_prefix = fw_path;
0256
0257 dev_dbg(dev,
0258 "Module parameter used, changed fw path to %s\n",
0259 sof_pdata->fw_filename_prefix);
0260
0261 } else if (dmi_check_system(community_key_platforms) && sof_dmi_use_community_key) {
0262 sof_pdata->fw_filename_prefix =
0263 devm_kasprintf(dev, GFP_KERNEL, "%s/%s",
0264 sof_pdata->desc->default_fw_path[sof_pdata->ipc_type],
0265 "community");
0266
0267 dev_dbg(dev,
0268 "Platform uses community key, changed fw path to %s\n",
0269 sof_pdata->fw_filename_prefix);
0270 } else {
0271 sof_pdata->fw_filename_prefix =
0272 sof_pdata->desc->default_fw_path[sof_pdata->ipc_type];
0273 }
0274
0275 if (tplg_path)
0276 sof_pdata->tplg_filename_prefix = tplg_path;
0277 else
0278 sof_pdata->tplg_filename_prefix =
0279 sof_pdata->desc->default_tplg_path[sof_pdata->ipc_type];
0280
0281
0282
0283
0284
0285 if (tplg_filename) {
0286 sof_pdata->tplg_filename = tplg_filename;
0287
0288 dev_dbg(dev, "Module parameter used, changed tplg filename to %s\n",
0289 sof_pdata->tplg_filename);
0290 } else {
0291 dmi_check_system(sof_tplg_table);
0292 if (sof_dmi_override_tplg_name)
0293 sof_pdata->tplg_filename = sof_dmi_override_tplg_name;
0294 }
0295
0296
0297 sof_pdata->sof_probe_complete = sof_pci_probe_complete;
0298
0299
0300 ret = snd_sof_device_probe(dev, sof_pdata);
0301
0302 out:
0303 if (ret)
0304 pci_release_regions(pci);
0305
0306 return ret;
0307 }
0308 EXPORT_SYMBOL_NS(sof_pci_probe, SND_SOC_SOF_PCI_DEV);
0309
0310 void sof_pci_remove(struct pci_dev *pci)
0311 {
0312
0313 snd_sof_device_remove(&pci->dev);
0314
0315
0316 if (snd_sof_device_probe_completed(&pci->dev) &&
0317 !(sof_pci_debug & SOF_PCI_DISABLE_PM_RUNTIME))
0318 pm_runtime_get_noresume(&pci->dev);
0319
0320
0321 pci_release_regions(pci);
0322 }
0323 EXPORT_SYMBOL_NS(sof_pci_remove, SND_SOC_SOF_PCI_DEV);
0324
0325 void sof_pci_shutdown(struct pci_dev *pci)
0326 {
0327 snd_sof_device_shutdown(&pci->dev);
0328 }
0329 EXPORT_SYMBOL_NS(sof_pci_shutdown, SND_SOC_SOF_PCI_DEV);
0330
0331 MODULE_LICENSE("Dual BSD/GPL");