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/acpi.h>
12 #include <linux/firmware.h>
13 #include <linux/module.h>
14 #include <linux/pm_runtime.h>
15 #include <sound/intel-dsp-config.h>
16 #include <sound/soc-acpi.h>
17 #include <sound/soc-acpi-intel-match.h>
18 #include <sound/sof.h>
19 #include "../intel/common/soc-intel-quirks.h"
22 /* platform specific devices */
23 #include "intel/shim.h"
26 module_param(fw_path, charp, 0444);
27 MODULE_PARM_DESC(fw_path, "alternate path for SOF firmware.");
29 static char *tplg_path;
30 module_param(tplg_path, charp, 0444);
31 MODULE_PARM_DESC(tplg_path, "alternate path for SOF topology.");
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)");
37 #define SOF_ACPI_DISABLE_PM_RUNTIME BIT(0)
39 #if IS_ENABLED(CONFIG_ACPI) && IS_ENABLED(CONFIG_SND_SOC_SOF_BROADWELL)
40 static const struct sof_dev_desc sof_acpi_broadwell_desc = {
41 .machines = snd_soc_acpi_intel_broadwell_machines,
42 .resindex_lpe_base = 0,
43 .resindex_pcicfg_base = 1,
44 .resindex_imr_base = -1,
45 .irqindex_host_ipc = 0,
46 .chip_info = &bdw_chip_info,
47 .default_fw_path = "intel/sof",
48 .default_tplg_path = "intel/sof-tplg",
49 .default_fw_filename = "sof-bdw.ri",
50 .nocodec_tplg_filename = "sof-bdw-nocodec.tplg",
55 #if IS_ENABLED(CONFIG_ACPI) && IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
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",
72 static const struct sof_dev_desc sof_acpi_baytrail_desc = {
73 .machines = snd_soc_acpi_intel_baytrail_machines,
74 .resindex_lpe_base = 0,
75 .resindex_pcicfg_base = 1,
76 .resindex_imr_base = 2,
77 .irqindex_host_ipc = 5,
78 .chip_info = &byt_chip_info,
79 .default_fw_path = "intel/sof",
80 .default_tplg_path = "intel/sof-tplg",
81 .default_fw_filename = "sof-byt.ri",
82 .nocodec_tplg_filename = "sof-byt-nocodec.tplg",
86 static const struct sof_dev_desc sof_acpi_cherrytrail_desc = {
87 .machines = snd_soc_acpi_intel_cherrytrail_machines,
88 .resindex_lpe_base = 0,
89 .resindex_pcicfg_base = 1,
90 .resindex_imr_base = 2,
91 .irqindex_host_ipc = 5,
92 .chip_info = &cht_chip_info,
93 .default_fw_path = "intel/sof",
94 .default_tplg_path = "intel/sof-tplg",
95 .default_fw_filename = "sof-cht.ri",
96 .nocodec_tplg_filename = "sof-cht-nocodec.tplg",
102 static const struct dev_pm_ops sof_acpi_pm = {
103 SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume)
104 SET_RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume,
105 snd_sof_runtime_idle)
108 static void sof_acpi_probe_complete(struct device *dev)
110 dev_dbg(dev, "Completing SOF ACPI probe");
112 if (sof_acpi_debug & SOF_ACPI_DISABLE_PM_RUNTIME)
115 /* allow runtime_pm */
116 pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS);
117 pm_runtime_use_autosuspend(dev);
118 pm_runtime_enable(dev);
121 static int sof_acpi_probe(struct platform_device *pdev)
123 struct device *dev = &pdev->dev;
124 const struct acpi_device_id *id;
125 const struct sof_dev_desc *desc;
126 struct snd_sof_pdata *sof_pdata;
127 const struct snd_sof_dsp_ops *ops;
130 id = acpi_match_device(dev->driver->acpi_match_table, dev);
134 if (IS_REACHABLE(CONFIG_SND_INTEL_DSP_CONFIG)) {
135 ret = snd_intel_acpi_dsp_driver_probe(dev, id->id);
136 if (ret != SND_INTEL_DSP_DRIVER_ANY && ret != SND_INTEL_DSP_DRIVER_SOF) {
137 dev_dbg(dev, "SOF ACPI driver not selected, aborting probe\n");
141 dev_dbg(dev, "ACPI DSP detected");
143 sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL);
147 desc = device_get_match_data(dev);
151 #if IS_ENABLED(CONFIG_ACPI) && IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
152 if (desc == &sof_acpi_baytrail_desc && soc_intel_is_byt_cr(pdev))
153 desc = &sof_acpi_baytrailcr_desc;
156 /* get ops for platform */
159 dev_err(dev, "error: no matching ACPI descriptor ops\n");
163 sof_pdata->desc = desc;
164 sof_pdata->dev = &pdev->dev;
165 sof_pdata->fw_filename = desc->default_fw_filename;
167 /* alternate fw and tplg filenames ? */
169 sof_pdata->fw_filename_prefix = fw_path;
171 sof_pdata->fw_filename_prefix =
172 sof_pdata->desc->default_fw_path;
175 sof_pdata->tplg_filename_prefix = tplg_path;
177 sof_pdata->tplg_filename_prefix =
178 sof_pdata->desc->default_tplg_path;
180 #if IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)
181 /* set callback to enable runtime_pm */
182 sof_pdata->sof_probe_complete = sof_acpi_probe_complete;
184 /* call sof helper for DSP hardware probe */
185 ret = snd_sof_device_probe(dev, sof_pdata);
187 dev_err(dev, "error: failed to probe DSP hardware!\n");
191 #if !IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)
192 sof_acpi_probe_complete(dev);
198 static int sof_acpi_remove(struct platform_device *pdev)
200 if (!(sof_acpi_debug & SOF_ACPI_DISABLE_PM_RUNTIME))
201 pm_runtime_disable(&pdev->dev);
203 /* call sof helper for DSP hardware remove */
204 snd_sof_device_remove(&pdev->dev);
210 static const struct acpi_device_id sof_acpi_match[] = {
211 #if IS_ENABLED(CONFIG_SND_SOC_SOF_BROADWELL)
212 { "INT3438", (unsigned long)&sof_acpi_broadwell_desc },
214 #if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
215 { "80860F28", (unsigned long)&sof_acpi_baytrail_desc },
216 { "808622A8", (unsigned long)&sof_acpi_cherrytrail_desc },
220 MODULE_DEVICE_TABLE(acpi, sof_acpi_match);
223 /* acpi_driver definition */
224 static struct platform_driver snd_sof_acpi_driver = {
225 .probe = sof_acpi_probe,
226 .remove = sof_acpi_remove,
228 .name = "sof-audio-acpi",
230 .acpi_match_table = ACPI_PTR(sof_acpi_match),
233 module_platform_driver(snd_sof_acpi_driver);
235 MODULE_LICENSE("Dual BSD/GPL");
236 MODULE_IMPORT_NS(SND_SOC_SOF_BAYTRAIL);
237 MODULE_IMPORT_NS(SND_SOC_SOF_BROADWELL);