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 ret
= snd_intel_acpi_dsp_driver_probe(dev
, id
->id
);
135 if (ret
!= SND_INTEL_DSP_DRIVER_ANY
&& ret
!= SND_INTEL_DSP_DRIVER_SOF
) {
136 dev_dbg(dev
, "SOF ACPI driver not selected, aborting probe\n");
140 dev_dbg(dev
, "ACPI DSP detected");
142 sof_pdata
= devm_kzalloc(dev
, sizeof(*sof_pdata
), GFP_KERNEL
);
146 desc
= device_get_match_data(dev
);
150 #if IS_ENABLED(CONFIG_ACPI) && IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
151 if (desc
== &sof_acpi_baytrail_desc
&& soc_intel_is_byt_cr(pdev
))
152 desc
= &sof_acpi_baytrailcr_desc
;
155 /* get ops for platform */
158 dev_err(dev
, "error: no matching ACPI descriptor ops\n");
162 sof_pdata
->desc
= desc
;
163 sof_pdata
->dev
= &pdev
->dev
;
164 sof_pdata
->fw_filename
= desc
->default_fw_filename
;
166 /* alternate fw and tplg filenames ? */
168 sof_pdata
->fw_filename_prefix
= fw_path
;
170 sof_pdata
->fw_filename_prefix
=
171 sof_pdata
->desc
->default_fw_path
;
174 sof_pdata
->tplg_filename_prefix
= tplg_path
;
176 sof_pdata
->tplg_filename_prefix
=
177 sof_pdata
->desc
->default_tplg_path
;
179 #if IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)
180 /* set callback to enable runtime_pm */
181 sof_pdata
->sof_probe_complete
= sof_acpi_probe_complete
;
183 /* call sof helper for DSP hardware probe */
184 ret
= snd_sof_device_probe(dev
, sof_pdata
);
186 dev_err(dev
, "error: failed to probe DSP hardware!\n");
190 #if !IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)
191 sof_acpi_probe_complete(dev
);
197 static int sof_acpi_remove(struct platform_device
*pdev
)
199 if (!(sof_acpi_debug
& SOF_ACPI_DISABLE_PM_RUNTIME
))
200 pm_runtime_disable(&pdev
->dev
);
202 /* call sof helper for DSP hardware remove */
203 snd_sof_device_remove(&pdev
->dev
);
209 static const struct acpi_device_id sof_acpi_match
[] = {
210 #if IS_ENABLED(CONFIG_SND_SOC_SOF_BROADWELL)
211 { "INT3438", (unsigned long)&sof_acpi_broadwell_desc
},
213 #if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
214 { "80860F28", (unsigned long)&sof_acpi_baytrail_desc
},
215 { "808622A8", (unsigned long)&sof_acpi_cherrytrail_desc
},
219 MODULE_DEVICE_TABLE(acpi
, sof_acpi_match
);
222 /* acpi_driver definition */
223 static struct platform_driver snd_sof_acpi_driver
= {
224 .probe
= sof_acpi_probe
,
225 .remove
= sof_acpi_remove
,
227 .name
= "sof-audio-acpi",
229 .acpi_match_table
= ACPI_PTR(sof_acpi_match
),
232 module_platform_driver(snd_sof_acpi_driver
);
234 MODULE_LICENSE("Dual BSD/GPL");
235 MODULE_IMPORT_NS(SND_SOC_SOF_BAYTRAIL
);
236 MODULE_IMPORT_NS(SND_SOC_SOF_BROADWELL
);