1 // SPDX-License-Identifier: (GPL-2.0 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 <[email protected]> 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 21 /* platform specific devices */ 22 #include "intel/shim.h" 23 24 static char *fw_path; 25 module_param(fw_path, charp, 0444); 26 MODULE_PARM_DESC(fw_path, "alternate path for SOF firmware."); 27 28 static char *tplg_path; 29 module_param(tplg_path, charp, 0444); 30 MODULE_PARM_DESC(tplg_path, "alternate path for SOF topology."); 31 32 static int sof_acpi_debug; 33 module_param_named(sof_acpi_debug, sof_acpi_debug, int, 0444); 34 MODULE_PARM_DESC(sof_acpi_debug, "SOF ACPI debug options (0x0 all off)"); 35 36 #define SOF_ACPI_DISABLE_PM_RUNTIME BIT(0) 37 38 #if IS_ENABLED(CONFIG_SND_SOC_SOF_BROADWELL) 39 static const struct sof_dev_desc sof_acpi_broadwell_desc = { 40 .machines = snd_soc_acpi_intel_broadwell_machines, 41 .resindex_lpe_base = 0, 42 .resindex_pcicfg_base = 1, 43 .resindex_imr_base = -1, 44 .irqindex_host_ipc = 0, 45 .chip_info = &bdw_chip_info, 46 .default_fw_path = "intel/sof", 47 .default_tplg_path = "intel/sof-tplg", 48 .default_fw_filename = "sof-bdw.ri", 49 .nocodec_tplg_filename = "sof-bdw-nocodec.tplg", 50 .ops = &sof_bdw_ops, 51 .arch_ops = &sof_xtensa_arch_ops 52 }; 53 #endif 54 55 #if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL) 56 57 /* BYTCR uses different IRQ index */ 58 static const struct sof_dev_desc sof_acpi_baytrailcr_desc = { 59 .machines = snd_soc_acpi_intel_baytrail_machines, 60 .resindex_lpe_base = 0, 61 .resindex_pcicfg_base = 1, 62 .resindex_imr_base = 2, 63 .irqindex_host_ipc = 0, 64 .chip_info = &byt_chip_info, 65 .default_fw_path = "intel/sof", 66 .default_tplg_path = "intel/sof-tplg", 67 .default_fw_filename = "sof-byt.ri", 68 .nocodec_tplg_filename = "sof-byt-nocodec.tplg", 69 .ops = &sof_byt_ops, 70 .arch_ops = &sof_xtensa_arch_ops 71 }; 72 73 static const struct sof_dev_desc sof_acpi_baytrail_desc = { 74 .machines = snd_soc_acpi_intel_baytrail_machines, 75 .resindex_lpe_base = 0, 76 .resindex_pcicfg_base = 1, 77 .resindex_imr_base = 2, 78 .irqindex_host_ipc = 5, 79 .chip_info = &byt_chip_info, 80 .default_fw_path = "intel/sof", 81 .default_tplg_path = "intel/sof-tplg", 82 .default_fw_filename = "sof-byt.ri", 83 .nocodec_tplg_filename = "sof-byt-nocodec.tplg", 84 .ops = &sof_byt_ops, 85 .arch_ops = &sof_xtensa_arch_ops 86 }; 87 88 static const struct sof_dev_desc sof_acpi_cherrytrail_desc = { 89 .machines = snd_soc_acpi_intel_cherrytrail_machines, 90 .resindex_lpe_base = 0, 91 .resindex_pcicfg_base = 1, 92 .resindex_imr_base = 2, 93 .irqindex_host_ipc = 5, 94 .chip_info = &cht_chip_info, 95 .default_fw_path = "intel/sof", 96 .default_tplg_path = "intel/sof-tplg", 97 .default_fw_filename = "sof-cht.ri", 98 .nocodec_tplg_filename = "sof-cht-nocodec.tplg", 99 .ops = &sof_cht_ops, 100 .arch_ops = &sof_xtensa_arch_ops 101 }; 102 103 #endif 104 105 static const struct dev_pm_ops sof_acpi_pm = { 106 SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume) 107 SET_RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume, 108 snd_sof_runtime_idle) 109 }; 110 111 static void sof_acpi_probe_complete(struct device *dev) 112 { 113 if (sof_acpi_debug & SOF_ACPI_DISABLE_PM_RUNTIME) 114 return; 115 116 /* allow runtime_pm */ 117 pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS); 118 pm_runtime_use_autosuspend(dev); 119 pm_runtime_enable(dev); 120 } 121 122 static int sof_acpi_probe(struct platform_device *pdev) 123 { 124 struct device *dev = &pdev->dev; 125 const struct sof_dev_desc *desc; 126 struct snd_sof_pdata *sof_pdata; 127 const struct snd_sof_dsp_ops *ops; 128 int ret; 129 130 dev_dbg(&pdev->dev, "ACPI DSP detected"); 131 132 sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL); 133 if (!sof_pdata) 134 return -ENOMEM; 135 136 desc = device_get_match_data(dev); 137 if (!desc) 138 return -ENODEV; 139 140 #if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL) 141 if (desc == &sof_acpi_baytrail_desc && soc_intel_is_byt_cr(pdev)) 142 desc = &sof_acpi_baytrailcr_desc; 143 #endif 144 145 /* get ops for platform */ 146 ops = desc->ops; 147 if (!ops) { 148 dev_err(dev, "error: no matching ACPI descriptor ops\n"); 149 return -ENODEV; 150 } 151 152 sof_pdata->desc = desc; 153 sof_pdata->dev = &pdev->dev; 154 sof_pdata->fw_filename = desc->default_fw_filename; 155 156 /* alternate fw and tplg filenames ? */ 157 if (fw_path) 158 sof_pdata->fw_filename_prefix = fw_path; 159 else 160 sof_pdata->fw_filename_prefix = 161 sof_pdata->desc->default_fw_path; 162 163 if (tplg_path) 164 sof_pdata->tplg_filename_prefix = tplg_path; 165 else 166 sof_pdata->tplg_filename_prefix = 167 sof_pdata->desc->default_tplg_path; 168 169 #if IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE) 170 /* set callback to enable runtime_pm */ 171 sof_pdata->sof_probe_complete = sof_acpi_probe_complete; 172 #endif 173 /* call sof helper for DSP hardware probe */ 174 ret = snd_sof_device_probe(dev, sof_pdata); 175 if (ret) { 176 dev_err(dev, "error: failed to probe DSP hardware!\n"); 177 return ret; 178 } 179 180 #if !IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE) 181 sof_acpi_probe_complete(dev); 182 #endif 183 184 return ret; 185 } 186 187 static int sof_acpi_remove(struct platform_device *pdev) 188 { 189 if (!(sof_acpi_debug & SOF_ACPI_DISABLE_PM_RUNTIME)) 190 pm_runtime_disable(&pdev->dev); 191 192 /* call sof helper for DSP hardware remove */ 193 snd_sof_device_remove(&pdev->dev); 194 195 return 0; 196 } 197 198 static const struct acpi_device_id sof_acpi_match[] = { 199 #if IS_ENABLED(CONFIG_SND_SOC_SOF_BROADWELL) 200 { "INT3438", (unsigned long)&sof_acpi_broadwell_desc }, 201 #endif 202 #if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL) 203 { "80860F28", (unsigned long)&sof_acpi_baytrail_desc }, 204 { "808622A8", (unsigned long)&sof_acpi_cherrytrail_desc }, 205 #endif 206 { } 207 }; 208 MODULE_DEVICE_TABLE(acpi, sof_acpi_match); 209 210 /* acpi_driver definition */ 211 static struct platform_driver snd_sof_acpi_driver = { 212 .probe = sof_acpi_probe, 213 .remove = sof_acpi_remove, 214 .driver = { 215 .name = "sof-audio-acpi", 216 .pm = &sof_acpi_pm, 217 .acpi_match_table = ACPI_PTR(sof_acpi_match), 218 }, 219 }; 220 module_platform_driver(snd_sof_acpi_driver); 221 222 MODULE_LICENSE("Dual BSD/GPL"); 223 MODULE_IMPORT_NS(SND_SOC_SOF_BAYTRAIL); 224 MODULE_IMPORT_NS(SND_SOC_SOF_BROADWELL); 225