1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) 2 // 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. 5 // 6 // Copyright(c) 2018 Intel Corporation. All rights reserved. 7 // 8 // Author: Liam Girdwood <liam.r.girdwood@linux.intel.com> 9 // 10 11 #include <linux/acpi.h> 12 #include <linux/firmware.h> 13 #include <linux/module.h> 14 #include <linux/pm_runtime.h> 15 #include <sound/soc-acpi.h> 16 #include <sound/soc-acpi-intel-match.h> 17 #include <sound/sof.h> 18 #include "../intel/common/soc-intel-quirks.h" 19 #include "ops.h" 20 #include "sof-acpi-dev.h" 21 22 /* platform specific devices */ 23 #include "intel/shim.h" 24 25 static char *fw_path; 26 module_param(fw_path, charp, 0444); 27 MODULE_PARM_DESC(fw_path, "alternate path for SOF firmware."); 28 29 static char *tplg_path; 30 module_param(tplg_path, charp, 0444); 31 MODULE_PARM_DESC(tplg_path, "alternate path for SOF topology."); 32 33 static int sof_acpi_debug; 34 module_param_named(sof_acpi_debug, sof_acpi_debug, int, 0444); 35 MODULE_PARM_DESC(sof_acpi_debug, "SOF ACPI debug options (0x0 all off)"); 36 37 #define SOF_ACPI_DISABLE_PM_RUNTIME BIT(0) 38 39 const struct dev_pm_ops sof_acpi_pm = { 40 SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume) 41 SET_RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume, 42 snd_sof_runtime_idle) 43 }; 44 EXPORT_SYMBOL_NS(sof_acpi_pm, SND_SOC_SOF_ACPI_DEV); 45 46 static void sof_acpi_probe_complete(struct device *dev) 47 { 48 dev_dbg(dev, "Completing SOF ACPI probe"); 49 50 if (sof_acpi_debug & SOF_ACPI_DISABLE_PM_RUNTIME) 51 return; 52 53 /* allow runtime_pm */ 54 pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS); 55 pm_runtime_use_autosuspend(dev); 56 pm_runtime_enable(dev); 57 } 58 59 int sof_acpi_probe(struct platform_device *pdev, const struct sof_dev_desc *desc) 60 { 61 struct device *dev = &pdev->dev; 62 struct snd_sof_pdata *sof_pdata; 63 const struct snd_sof_dsp_ops *ops; 64 int ret; 65 66 dev_dbg(dev, "ACPI DSP detected"); 67 68 sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL); 69 if (!sof_pdata) 70 return -ENOMEM; 71 72 /* get ops for platform */ 73 ops = desc->ops; 74 if (!ops) { 75 dev_err(dev, "error: no matching ACPI descriptor ops\n"); 76 return -ENODEV; 77 } 78 79 sof_pdata->desc = desc; 80 sof_pdata->dev = &pdev->dev; 81 sof_pdata->fw_filename = desc->default_fw_filename; 82 83 /* alternate fw and tplg filenames ? */ 84 if (fw_path) 85 sof_pdata->fw_filename_prefix = fw_path; 86 else 87 sof_pdata->fw_filename_prefix = 88 sof_pdata->desc->default_fw_path; 89 90 if (tplg_path) 91 sof_pdata->tplg_filename_prefix = tplg_path; 92 else 93 sof_pdata->tplg_filename_prefix = 94 sof_pdata->desc->default_tplg_path; 95 96 #if IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE) 97 /* set callback to enable runtime_pm */ 98 sof_pdata->sof_probe_complete = sof_acpi_probe_complete; 99 #endif 100 /* call sof helper for DSP hardware probe */ 101 ret = snd_sof_device_probe(dev, sof_pdata); 102 if (ret) { 103 dev_err(dev, "error: failed to probe DSP hardware!\n"); 104 return ret; 105 } 106 107 #if !IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE) 108 sof_acpi_probe_complete(dev); 109 #endif 110 111 return ret; 112 } 113 EXPORT_SYMBOL_NS(sof_acpi_probe, SND_SOC_SOF_ACPI_DEV); 114 115 int sof_acpi_remove(struct platform_device *pdev) 116 { 117 struct device *dev = &pdev->dev; 118 119 if (!(sof_acpi_debug & SOF_ACPI_DISABLE_PM_RUNTIME)) 120 pm_runtime_disable(dev); 121 122 /* call sof helper for DSP hardware remove */ 123 snd_sof_device_remove(dev); 124 125 return 0; 126 } 127 EXPORT_SYMBOL_NS(sof_acpi_remove, SND_SOC_SOF_ACPI_DEV); 128 129 MODULE_LICENSE("Dual BSD/GPL"); 130