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