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