1 // SPDX-License-Identifier: (GPL-2.0 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/soc-acpi.h>
16 #include <sound/soc-acpi-intel-match.h>
17 #include <sound/sof.h>
19 #include <asm/iosf_mbi.h>
24 /* platform specific devices */
25 #include "intel/shim.h"
28 module_param(fw_path, charp, 0444);
29 MODULE_PARM_DESC(fw_path, "alternate path for SOF firmware.");
31 static char *tplg_path;
32 module_param(tplg_path, charp, 0444);
33 MODULE_PARM_DESC(tplg_path, "alternate path for SOF topology.");
35 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HASWELL)
36 static const struct sof_dev_desc sof_acpi_haswell_desc = {
37 .machines = snd_soc_acpi_intel_haswell_machines,
38 .resindex_lpe_base = 0,
39 .resindex_pcicfg_base = 1,
40 .resindex_imr_base = -1,
41 .irqindex_host_ipc = 0,
42 .chip_info = &hsw_chip_info,
43 .default_fw_path = "intel/sof",
44 .default_tplg_path = "intel/sof-tplg",
45 .nocodec_fw_filename = "sof-hsw.ri",
46 .nocodec_tplg_filename = "sof-hsw-nocodec.tplg",
48 .arch_ops = &sof_xtensa_arch_ops
52 #if IS_ENABLED(CONFIG_SND_SOC_SOF_BROADWELL)
53 static const struct sof_dev_desc sof_acpi_broadwell_desc = {
54 .machines = snd_soc_acpi_intel_broadwell_machines,
55 .resindex_lpe_base = 0,
56 .resindex_pcicfg_base = 1,
57 .resindex_imr_base = -1,
58 .irqindex_host_ipc = 0,
59 .chip_info = &bdw_chip_info,
60 .default_fw_path = "intel/sof",
61 .default_tplg_path = "intel/sof-tplg",
62 .nocodec_fw_filename = "sof-bdw.ri",
63 .nocodec_tplg_filename = "sof-bdw-nocodec.tplg",
65 .arch_ops = &sof_xtensa_arch_ops
69 #if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
71 /* BYTCR uses different IRQ index */
72 static const struct sof_dev_desc sof_acpi_baytrailcr_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 = 0,
78 .chip_info = &byt_chip_info,
79 .default_fw_path = "intel/sof",
80 .default_tplg_path = "intel/sof-tplg",
81 .nocodec_fw_filename = "sof-byt.ri",
82 .nocodec_tplg_filename = "sof-byt-nocodec.tplg",
84 .arch_ops = &sof_xtensa_arch_ops
87 static const struct sof_dev_desc sof_acpi_baytrail_desc = {
88 .machines = snd_soc_acpi_intel_baytrail_machines,
89 .resindex_lpe_base = 0,
90 .resindex_pcicfg_base = 1,
91 .resindex_imr_base = 2,
92 .irqindex_host_ipc = 5,
93 .chip_info = &byt_chip_info,
94 .default_fw_path = "intel/sof",
95 .default_tplg_path = "intel/sof-tplg",
96 .nocodec_fw_filename = "sof-byt.ri",
97 .nocodec_tplg_filename = "sof-byt-nocodec.tplg",
99 .arch_ops = &sof_xtensa_arch_ops
102 #ifdef CONFIG_X86 /* TODO: move this to common helper */
104 static bool is_byt_cr(struct platform_device *pdev)
106 struct device *dev = &pdev->dev;
109 if (iosf_mbi_available()) {
111 status = iosf_mbi_read(BT_MBI_UNIT_PMC, /* 0x04 PUNIT */
112 MBI_REG_READ, /* 0x10 */
113 0x006, /* BIOS_CONFIG */
117 dev_err(dev, "could not read PUNIT BIOS_CONFIG\n");
119 /* bits 26:27 mirror PMIC options */
120 bios_status = (bios_status >> 26) & 3;
122 if (bios_status == 1 || bios_status == 3) {
123 dev_info(dev, "Detected Baytrail-CR platform\n");
127 dev_info(dev, "BYT-CR not detected\n");
130 dev_info(dev, "IOSF_MBI not available, no BYT-CR detection\n");
133 if (platform_get_resource(pdev, IORESOURCE_IRQ, 5) == NULL) {
135 * Some devices detected as BYT-T have only a single IRQ listed,
136 * causing platform_get_irq with index 5 to return -ENXIO.
137 * The correct IRQ in this case is at index 0, as on BYT-CR.
139 dev_info(dev, "Falling back to Baytrail-CR platform\n");
146 static int is_byt_cr(struct platform_device *pdev)
152 static const struct sof_dev_desc sof_acpi_cherrytrail_desc = {
153 .machines = snd_soc_acpi_intel_cherrytrail_machines,
154 .resindex_lpe_base = 0,
155 .resindex_pcicfg_base = 1,
156 .resindex_imr_base = 2,
157 .irqindex_host_ipc = 5,
158 .chip_info = &cht_chip_info,
159 .default_fw_path = "intel/sof",
160 .default_tplg_path = "intel/sof-tplg",
161 .nocodec_fw_filename = "sof-cht.ri",
162 .nocodec_tplg_filename = "sof-cht-nocodec.tplg",
164 .arch_ops = &sof_xtensa_arch_ops
169 static const struct dev_pm_ops sof_acpi_pm = {
170 SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume)
171 SET_RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume,
175 static void sof_acpi_probe_complete(struct device *dev)
177 /* allow runtime_pm */
178 pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS);
179 pm_runtime_use_autosuspend(dev);
180 pm_runtime_enable(dev);
183 static int sof_acpi_probe(struct platform_device *pdev)
185 struct device *dev = &pdev->dev;
186 const struct sof_dev_desc *desc;
187 struct snd_soc_acpi_mach *mach;
188 struct snd_sof_pdata *sof_pdata;
189 const struct snd_sof_dsp_ops *ops;
192 dev_dbg(&pdev->dev, "ACPI DSP detected");
194 sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL);
198 desc = device_get_match_data(dev);
202 #if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
203 if (desc == &sof_acpi_baytrail_desc && is_byt_cr(pdev))
204 desc = &sof_acpi_baytrailcr_desc;
207 /* get ops for platform */
210 dev_err(dev, "error: no matching ACPI descriptor ops\n");
214 #if IS_ENABLED(CONFIG_SND_SOC_SOF_FORCE_NOCODEC_MODE)
215 /* force nocodec mode */
216 dev_warn(dev, "Force to use nocodec mode\n");
217 mach = devm_kzalloc(dev, sizeof(*mach), GFP_KERNEL);
220 ret = sof_nocodec_setup(dev, sof_pdata, mach, desc, ops);
225 mach = snd_soc_acpi_find_machine(desc->machines);
227 dev_warn(dev, "warning: No matching ASoC machine driver found\n");
229 sof_pdata->fw_filename = mach->sof_fw_filename;
230 sof_pdata->tplg_filename = mach->sof_tplg_filename;
235 mach->mach_params.platform = dev_name(dev);
236 mach->mach_params.acpi_ipc_irq_index = desc->irqindex_host_ipc;
239 sof_pdata->machine = mach;
240 sof_pdata->desc = desc;
241 sof_pdata->dev = &pdev->dev;
242 sof_pdata->platform = dev_name(dev);
244 /* alternate fw and tplg filenames ? */
246 sof_pdata->fw_filename_prefix = fw_path;
248 sof_pdata->fw_filename_prefix =
249 sof_pdata->desc->default_fw_path;
252 sof_pdata->tplg_filename_prefix = tplg_path;
254 sof_pdata->tplg_filename_prefix =
255 sof_pdata->desc->default_tplg_path;
257 #if IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)
258 /* set callback to enable runtime_pm */
259 sof_pdata->sof_probe_complete = sof_acpi_probe_complete;
261 /* call sof helper for DSP hardware probe */
262 ret = snd_sof_device_probe(dev, sof_pdata);
264 dev_err(dev, "error: failed to probe DSP hardware!\n");
268 #if !IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)
269 sof_acpi_probe_complete(dev);
275 static int sof_acpi_remove(struct platform_device *pdev)
277 pm_runtime_disable(&pdev->dev);
279 /* call sof helper for DSP hardware remove */
280 snd_sof_device_remove(&pdev->dev);
285 static const struct acpi_device_id sof_acpi_match[] = {
286 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HASWELL)
287 { "INT33C8", (unsigned long)&sof_acpi_haswell_desc },
289 #if IS_ENABLED(CONFIG_SND_SOC_SOF_BROADWELL)
290 { "INT3438", (unsigned long)&sof_acpi_broadwell_desc },
292 #if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
293 { "80860F28", (unsigned long)&sof_acpi_baytrail_desc },
294 { "808622A8", (unsigned long)&sof_acpi_cherrytrail_desc },
298 MODULE_DEVICE_TABLE(acpi, sof_acpi_match);
300 /* acpi_driver definition */
301 static struct platform_driver snd_sof_acpi_driver = {
302 .probe = sof_acpi_probe,
303 .remove = sof_acpi_remove,
305 .name = "sof-audio-acpi",
307 .acpi_match_table = ACPI_PTR(sof_acpi_match),
310 module_platform_driver(snd_sof_acpi_driver);
312 MODULE_LICENSE("Dual BSD/GPL");