1 // SPDX-License-Identifier: (GPL-2.0-only OR B !! 1 // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) 2 // 2 // 3 // This file is provided under a dual BSD/GPLv 3 // This file is provided under a dual BSD/GPLv2 license. When using or 4 // redistributing this file, you may do so und 4 // redistributing this file, you may do so under either license. 5 // 5 // 6 // Copyright(c) 2018 Intel Corporation !! 6 // Copyright(c) 2018 Intel Corporation. All rights reserved. 7 // 7 // 8 // Author: Liam Girdwood <liam.r.girdwood@linu 8 // Author: Liam Girdwood <liam.r.girdwood@linux.intel.com> 9 // 9 // 10 10 11 #include <linux/acpi.h> 11 #include <linux/acpi.h> 12 #include <linux/firmware.h> 12 #include <linux/firmware.h> 13 #include <linux/module.h> 13 #include <linux/module.h> 14 #include <linux/pm_runtime.h> 14 #include <linux/pm_runtime.h> 15 #include <sound/soc-acpi.h> 15 #include <sound/soc-acpi.h> 16 #include <sound/soc-acpi-intel-match.h> 16 #include <sound/soc-acpi-intel-match.h> 17 #include <sound/sof.h> 17 #include <sound/sof.h> 18 #include "../intel/common/soc-intel-quirks.h" 18 #include "../intel/common/soc-intel-quirks.h" 19 #include "ops.h" 19 #include "ops.h" 20 #include "sof-acpi-dev.h" << 21 20 22 /* platform specific devices */ 21 /* platform specific devices */ 23 #include "intel/shim.h" 22 #include "intel/shim.h" 24 23 25 static char *fw_path; 24 static char *fw_path; 26 module_param(fw_path, charp, 0444); 25 module_param(fw_path, charp, 0444); 27 MODULE_PARM_DESC(fw_path, "alternate path for 26 MODULE_PARM_DESC(fw_path, "alternate path for SOF firmware."); 28 27 29 static char *tplg_path; 28 static char *tplg_path; 30 module_param(tplg_path, charp, 0444); 29 module_param(tplg_path, charp, 0444); 31 MODULE_PARM_DESC(tplg_path, "alternate path fo 30 MODULE_PARM_DESC(tplg_path, "alternate path for SOF topology."); 32 31 33 static int sof_acpi_debug; !! 32 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HASWELL) 34 module_param_named(sof_acpi_debug, sof_acpi_de !! 33 static const struct sof_dev_desc sof_acpi_haswell_desc = { 35 MODULE_PARM_DESC(sof_acpi_debug, "SOF ACPI deb !! 34 .machines = snd_soc_acpi_intel_haswell_machines, >> 35 .resindex_lpe_base = 0, >> 36 .resindex_pcicfg_base = 1, >> 37 .resindex_imr_base = -1, >> 38 .irqindex_host_ipc = 0, >> 39 .chip_info = &hsw_chip_info, >> 40 .default_fw_path = "intel/sof", >> 41 .default_tplg_path = "intel/sof-tplg", >> 42 .nocodec_fw_filename = "sof-hsw.ri", >> 43 .nocodec_tplg_filename = "sof-hsw-nocodec.tplg", >> 44 .ops = &sof_hsw_ops, >> 45 .arch_ops = &sof_xtensa_arch_ops >> 46 }; >> 47 #endif >> 48 >> 49 #if IS_ENABLED(CONFIG_SND_SOC_SOF_BROADWELL) >> 50 static const struct sof_dev_desc sof_acpi_broadwell_desc = { >> 51 .machines = snd_soc_acpi_intel_broadwell_machines, >> 52 .resindex_lpe_base = 0, >> 53 .resindex_pcicfg_base = 1, >> 54 .resindex_imr_base = -1, >> 55 .irqindex_host_ipc = 0, >> 56 .chip_info = &bdw_chip_info, >> 57 .default_fw_path = "intel/sof", >> 58 .default_tplg_path = "intel/sof-tplg", >> 59 .nocodec_fw_filename = "sof-bdw.ri", >> 60 .nocodec_tplg_filename = "sof-bdw-nocodec.tplg", >> 61 .ops = &sof_bdw_ops, >> 62 .arch_ops = &sof_xtensa_arch_ops >> 63 }; >> 64 #endif >> 65 >> 66 #if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL) 36 67 37 #define SOF_ACPI_DISABLE_PM_RUNTIME BIT(0) !! 68 /* BYTCR uses different IRQ index */ >> 69 static const struct sof_dev_desc sof_acpi_baytrailcr_desc = { >> 70 .machines = snd_soc_acpi_intel_baytrail_machines, >> 71 .resindex_lpe_base = 0, >> 72 .resindex_pcicfg_base = 1, >> 73 .resindex_imr_base = 2, >> 74 .irqindex_host_ipc = 0, >> 75 .chip_info = &byt_chip_info, >> 76 .default_fw_path = "intel/sof", >> 77 .default_tplg_path = "intel/sof-tplg", >> 78 .nocodec_fw_filename = "sof-byt.ri", >> 79 .nocodec_tplg_filename = "sof-byt-nocodec.tplg", >> 80 .ops = &sof_byt_ops, >> 81 .arch_ops = &sof_xtensa_arch_ops >> 82 }; >> 83 >> 84 static const struct sof_dev_desc sof_acpi_baytrail_desc = { >> 85 .machines = snd_soc_acpi_intel_baytrail_machines, >> 86 .resindex_lpe_base = 0, >> 87 .resindex_pcicfg_base = 1, >> 88 .resindex_imr_base = 2, >> 89 .irqindex_host_ipc = 5, >> 90 .chip_info = &byt_chip_info, >> 91 .default_fw_path = "intel/sof", >> 92 .default_tplg_path = "intel/sof-tplg", >> 93 .nocodec_fw_filename = "sof-byt.ri", >> 94 .nocodec_tplg_filename = "sof-byt-nocodec.tplg", >> 95 .ops = &sof_byt_ops, >> 96 .arch_ops = &sof_xtensa_arch_ops >> 97 }; 38 98 39 const struct dev_pm_ops sof_acpi_pm = { !! 99 static const struct sof_dev_desc sof_acpi_cherrytrail_desc = { >> 100 .machines = snd_soc_acpi_intel_cherrytrail_machines, >> 101 .resindex_lpe_base = 0, >> 102 .resindex_pcicfg_base = 1, >> 103 .resindex_imr_base = 2, >> 104 .irqindex_host_ipc = 5, >> 105 .chip_info = &cht_chip_info, >> 106 .default_fw_path = "intel/sof", >> 107 .default_tplg_path = "intel/sof-tplg", >> 108 .nocodec_fw_filename = "sof-cht.ri", >> 109 .nocodec_tplg_filename = "sof-cht-nocodec.tplg", >> 110 .ops = &sof_cht_ops, >> 111 .arch_ops = &sof_xtensa_arch_ops >> 112 }; >> 113 >> 114 #endif >> 115 >> 116 static const struct dev_pm_ops sof_acpi_pm = { 40 SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspen 117 SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume) 41 SET_RUNTIME_PM_OPS(snd_sof_runtime_sus 118 SET_RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume, 42 snd_sof_runtime_idl 119 snd_sof_runtime_idle) 43 }; 120 }; 44 EXPORT_SYMBOL_NS(sof_acpi_pm, SND_SOC_SOF_ACPI << 45 121 46 static void sof_acpi_probe_complete(struct dev 122 static void sof_acpi_probe_complete(struct device *dev) 47 { 123 { 48 dev_dbg(dev, "Completing SOF ACPI prob << 49 << 50 if (sof_acpi_debug & SOF_ACPI_DISABLE_ << 51 return; << 52 << 53 /* allow runtime_pm */ 124 /* allow runtime_pm */ 54 pm_runtime_set_autosuspend_delay(dev, 125 pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS); 55 pm_runtime_use_autosuspend(dev); 126 pm_runtime_use_autosuspend(dev); 56 pm_runtime_enable(dev); 127 pm_runtime_enable(dev); 57 } 128 } 58 129 59 int sof_acpi_probe(struct platform_device *pde !! 130 static int sof_acpi_probe(struct platform_device *pdev) 60 { 131 { 61 struct device *dev = &pdev->dev; 132 struct device *dev = &pdev->dev; >> 133 const struct sof_dev_desc *desc; >> 134 struct snd_soc_acpi_mach *mach; 62 struct snd_sof_pdata *sof_pdata; 135 struct snd_sof_pdata *sof_pdata; >> 136 const struct snd_sof_dsp_ops *ops; >> 137 int ret; 63 138 64 dev_dbg(dev, "ACPI DSP detected"); !! 139 dev_dbg(&pdev->dev, "ACPI DSP detected"); 65 140 66 sof_pdata = devm_kzalloc(dev, sizeof(* 141 sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL); 67 if (!sof_pdata) 142 if (!sof_pdata) 68 return -ENOMEM; 143 return -ENOMEM; 69 144 70 if (!desc->ops) { !! 145 desc = device_get_match_data(dev); >> 146 if (!desc) >> 147 return -ENODEV; >> 148 >> 149 #if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL) >> 150 if (desc == &sof_acpi_baytrail_desc && soc_intel_is_byt_cr(pdev)) >> 151 desc = &sof_acpi_baytrailcr_desc; >> 152 #endif >> 153 >> 154 /* get ops for platform */ >> 155 ops = desc->ops; >> 156 if (!ops) { 71 dev_err(dev, "error: no matchi 157 dev_err(dev, "error: no matching ACPI descriptor ops\n"); 72 return -ENODEV; 158 return -ENODEV; 73 } 159 } 74 160 >> 161 #if IS_ENABLED(CONFIG_SND_SOC_SOF_FORCE_NOCODEC_MODE) >> 162 /* force nocodec mode */ >> 163 dev_warn(dev, "Force to use nocodec mode\n"); >> 164 mach = devm_kzalloc(dev, sizeof(*mach), GFP_KERNEL); >> 165 if (!mach) >> 166 return -ENOMEM; >> 167 ret = sof_nocodec_setup(dev, sof_pdata, mach, desc, ops); >> 168 if (ret < 0) >> 169 return ret; >> 170 #else >> 171 /* find machine */ >> 172 mach = snd_soc_acpi_find_machine(desc->machines); >> 173 if (!mach) { >> 174 dev_warn(dev, "warning: No matching ASoC machine driver found\n"); >> 175 } else { >> 176 sof_pdata->fw_filename = mach->sof_fw_filename; >> 177 sof_pdata->tplg_filename = mach->sof_tplg_filename; >> 178 } >> 179 #endif >> 180 >> 181 if (mach) { >> 182 mach->mach_params.platform = dev_name(dev); >> 183 mach->mach_params.acpi_ipc_irq_index = desc->irqindex_host_ipc; >> 184 } >> 185 >> 186 sof_pdata->machine = mach; 75 sof_pdata->desc = desc; 187 sof_pdata->desc = desc; 76 sof_pdata->dev = &pdev->dev; 188 sof_pdata->dev = &pdev->dev; >> 189 sof_pdata->platform = dev_name(dev); 77 190 78 sof_pdata->ipc_file_profile_base.ipc_t !! 191 /* alternate fw and tplg filenames ? */ 79 sof_pdata->ipc_file_profile_base.fw_pa !! 192 if (fw_path) 80 sof_pdata->ipc_file_profile_base.tplg_ !! 193 sof_pdata->fw_filename_prefix = fw_path; >> 194 else >> 195 sof_pdata->fw_filename_prefix = >> 196 sof_pdata->desc->default_fw_path; >> 197 >> 198 if (tplg_path) >> 199 sof_pdata->tplg_filename_prefix = tplg_path; >> 200 else >> 201 sof_pdata->tplg_filename_prefix = >> 202 sof_pdata->desc->default_tplg_path; 81 203 82 /* set callback to be called on succes !! 204 #if IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE) >> 205 /* set callback to enable runtime_pm */ 83 sof_pdata->sof_probe_complete = sof_ac 206 sof_pdata->sof_probe_complete = sof_acpi_probe_complete; 84 !! 207 #endif 85 /* call sof helper for DSP hardware pr 208 /* call sof helper for DSP hardware probe */ 86 return snd_sof_device_probe(dev, sof_p !! 209 ret = snd_sof_device_probe(dev, sof_pdata); >> 210 if (ret) { >> 211 dev_err(dev, "error: failed to probe DSP hardware!\n"); >> 212 return ret; >> 213 } >> 214 >> 215 #if !IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE) >> 216 sof_acpi_probe_complete(dev); >> 217 #endif >> 218 >> 219 return ret; 87 } 220 } 88 EXPORT_SYMBOL_NS(sof_acpi_probe, SND_SOC_SOF_A << 89 221 90 void sof_acpi_remove(struct platform_device *p !! 222 static int sof_acpi_remove(struct platform_device *pdev) 91 { 223 { 92 struct device *dev = &pdev->dev; !! 224 pm_runtime_disable(&pdev->dev); 93 << 94 if (!(sof_acpi_debug & SOF_ACPI_DISABL << 95 pm_runtime_disable(dev); << 96 225 97 /* call sof helper for DSP hardware re 226 /* call sof helper for DSP hardware remove */ 98 snd_sof_device_remove(dev); !! 227 snd_sof_device_remove(&pdev->dev); >> 228 >> 229 return 0; 99 } 230 } 100 EXPORT_SYMBOL_NS(sof_acpi_remove, SND_SOC_SOF_ !! 231 >> 232 static const struct acpi_device_id sof_acpi_match[] = { >> 233 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HASWELL) >> 234 { "INT33C8", (unsigned long)&sof_acpi_haswell_desc }, >> 235 #endif >> 236 #if IS_ENABLED(CONFIG_SND_SOC_SOF_BROADWELL) >> 237 { "INT3438", (unsigned long)&sof_acpi_broadwell_desc }, >> 238 #endif >> 239 #if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL) >> 240 { "80860F28", (unsigned long)&sof_acpi_baytrail_desc }, >> 241 { "808622A8", (unsigned long)&sof_acpi_cherrytrail_desc }, >> 242 #endif >> 243 { } >> 244 }; >> 245 MODULE_DEVICE_TABLE(acpi, sof_acpi_match); >> 246 >> 247 /* acpi_driver definition */ >> 248 static struct platform_driver snd_sof_acpi_driver = { >> 249 .probe = sof_acpi_probe, >> 250 .remove = sof_acpi_remove, >> 251 .driver = { >> 252 .name = "sof-audio-acpi", >> 253 .pm = &sof_acpi_pm, >> 254 .acpi_match_table = ACPI_PTR(sof_acpi_match), >> 255 }, >> 256 }; >> 257 module_platform_driver(snd_sof_acpi_driver); 101 258 102 MODULE_LICENSE("Dual BSD/GPL"); 259 MODULE_LICENSE("Dual BSD/GPL"); 103 MODULE_DESCRIPTION("SOF support for ACPI platf << 104 260
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.