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>
18 #include "../intel/common/soc-intel-quirks.h"
21 /* platform specific devices */
22 #include "intel/shim.h"
25 module_param(fw_path
, charp
, 0444);
26 MODULE_PARM_DESC(fw_path
, "alternate path for SOF firmware.");
28 static char *tplg_path
;
29 module_param(tplg_path
, charp
, 0444);
30 MODULE_PARM_DESC(tplg_path
, "alternate path for SOF topology.");
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)");
36 #define SOF_ACPI_DISABLE_PM_RUNTIME BIT(0)
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",
52 .arch_ops
= &sof_xtensa_arch_ops
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",
70 .arch_ops
= &sof_xtensa_arch_ops
74 #if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
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",
90 .arch_ops
= &sof_xtensa_arch_ops
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",
106 .arch_ops
= &sof_xtensa_arch_ops
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",
122 .arch_ops
= &sof_xtensa_arch_ops
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
)
133 static void sof_acpi_probe_complete(struct device
*dev
)
135 if (sof_acpi_debug
& SOF_ACPI_DISABLE_PM_RUNTIME
)
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
);
144 static int sof_acpi_probe(struct platform_device
*pdev
)
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
;
152 dev_dbg(&pdev
->dev
, "ACPI DSP detected");
154 sof_pdata
= devm_kzalloc(dev
, sizeof(*sof_pdata
), GFP_KERNEL
);
158 desc
= device_get_match_data(dev
);
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
;
167 /* get ops for platform */
170 dev_err(dev
, "error: no matching ACPI descriptor ops\n");
174 sof_pdata
->desc
= desc
;
175 sof_pdata
->dev
= &pdev
->dev
;
176 sof_pdata
->fw_filename
= desc
->default_fw_filename
;
178 /* alternate fw and tplg filenames ? */
180 sof_pdata
->fw_filename_prefix
= fw_path
;
182 sof_pdata
->fw_filename_prefix
=
183 sof_pdata
->desc
->default_fw_path
;
186 sof_pdata
->tplg_filename_prefix
= tplg_path
;
188 sof_pdata
->tplg_filename_prefix
=
189 sof_pdata
->desc
->default_tplg_path
;
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
;
195 /* call sof helper for DSP hardware probe */
196 ret
= snd_sof_device_probe(dev
, sof_pdata
);
198 dev_err(dev
, "error: failed to probe DSP hardware!\n");
202 #if !IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)
203 sof_acpi_probe_complete(dev
);
209 static int sof_acpi_remove(struct platform_device
*pdev
)
211 if (!(sof_acpi_debug
& SOF_ACPI_DISABLE_PM_RUNTIME
))
212 pm_runtime_disable(&pdev
->dev
);
214 /* call sof helper for DSP hardware remove */
215 snd_sof_device_remove(&pdev
->dev
);
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
},
224 #if IS_ENABLED(CONFIG_SND_SOC_SOF_BROADWELL)
225 { "INT3438", (unsigned long)&sof_acpi_broadwell_desc
},
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
},
233 MODULE_DEVICE_TABLE(acpi
, sof_acpi_match
);
235 /* acpi_driver definition */
236 static struct platform_driver snd_sof_acpi_driver
= {
237 .probe
= sof_acpi_probe
,
238 .remove
= sof_acpi_remove
,
240 .name
= "sof-audio-acpi",
242 .acpi_match_table
= ACPI_PTR(sof_acpi_match
),
245 module_platform_driver(snd_sof_acpi_driver
);
247 MODULE_LICENSE("Dual BSD/GPL");