blob: a78b76ef37b2cd94971b4dd76ba14401be013861 [file] [log] [blame]
Olivier Deprez157378f2022-04-04 15:47:50 +02001// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
David Brazdil0f672f62019-12-10 10:32:29 +00002//
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 <liam.r.girdwood@linux.intel.com>
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
24static char *fw_path;
25module_param(fw_path, charp, 0444);
26MODULE_PARM_DESC(fw_path, "alternate path for SOF firmware.");
27
28static char *tplg_path;
29module_param(tplg_path, charp, 0444);
30MODULE_PARM_DESC(tplg_path, "alternate path for SOF topology.");
31
Olivier Deprez157378f2022-04-04 15:47:50 +020032static int sof_acpi_debug;
33module_param_named(sof_acpi_debug, sof_acpi_debug, int, 0444);
34MODULE_PARM_DESC(sof_acpi_debug, "SOF ACPI debug options (0x0 all off)");
David Brazdil0f672f62019-12-10 10:32:29 +000035
Olivier Deprez157378f2022-04-04 15:47:50 +020036#define SOF_ACPI_DISABLE_PM_RUNTIME BIT(0)
37
38#if IS_ENABLED(CONFIG_ACPI) && IS_ENABLED(CONFIG_SND_SOC_SOF_BROADWELL)
David Brazdil0f672f62019-12-10 10:32:29 +000039static const struct sof_dev_desc sof_acpi_broadwell_desc = {
40 .machines = snd_soc_acpi_intel_broadwell_machines,
41 .resindex_lpe_base = 0,
42 .resindex_pcicfg_base = 1,
43 .resindex_imr_base = -1,
44 .irqindex_host_ipc = 0,
45 .chip_info = &bdw_chip_info,
46 .default_fw_path = "intel/sof",
47 .default_tplg_path = "intel/sof-tplg",
Olivier Deprez157378f2022-04-04 15:47:50 +020048 .default_fw_filename = "sof-bdw.ri",
David Brazdil0f672f62019-12-10 10:32:29 +000049 .nocodec_tplg_filename = "sof-bdw-nocodec.tplg",
50 .ops = &sof_bdw_ops,
David Brazdil0f672f62019-12-10 10:32:29 +000051};
52#endif
53
Olivier Deprez157378f2022-04-04 15:47:50 +020054#if IS_ENABLED(CONFIG_ACPI) && IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
David Brazdil0f672f62019-12-10 10:32:29 +000055
56/* BYTCR uses different IRQ index */
57static const struct sof_dev_desc sof_acpi_baytrailcr_desc = {
58 .machines = snd_soc_acpi_intel_baytrail_machines,
59 .resindex_lpe_base = 0,
60 .resindex_pcicfg_base = 1,
61 .resindex_imr_base = 2,
62 .irqindex_host_ipc = 0,
63 .chip_info = &byt_chip_info,
64 .default_fw_path = "intel/sof",
65 .default_tplg_path = "intel/sof-tplg",
Olivier Deprez157378f2022-04-04 15:47:50 +020066 .default_fw_filename = "sof-byt.ri",
David Brazdil0f672f62019-12-10 10:32:29 +000067 .nocodec_tplg_filename = "sof-byt-nocodec.tplg",
68 .ops = &sof_byt_ops,
David Brazdil0f672f62019-12-10 10:32:29 +000069};
70
71static const struct sof_dev_desc sof_acpi_baytrail_desc = {
72 .machines = snd_soc_acpi_intel_baytrail_machines,
73 .resindex_lpe_base = 0,
74 .resindex_pcicfg_base = 1,
75 .resindex_imr_base = 2,
76 .irqindex_host_ipc = 5,
77 .chip_info = &byt_chip_info,
78 .default_fw_path = "intel/sof",
79 .default_tplg_path = "intel/sof-tplg",
Olivier Deprez157378f2022-04-04 15:47:50 +020080 .default_fw_filename = "sof-byt.ri",
David Brazdil0f672f62019-12-10 10:32:29 +000081 .nocodec_tplg_filename = "sof-byt-nocodec.tplg",
82 .ops = &sof_byt_ops,
David Brazdil0f672f62019-12-10 10:32:29 +000083};
84
85static const struct sof_dev_desc sof_acpi_cherrytrail_desc = {
86 .machines = snd_soc_acpi_intel_cherrytrail_machines,
87 .resindex_lpe_base = 0,
88 .resindex_pcicfg_base = 1,
89 .resindex_imr_base = 2,
90 .irqindex_host_ipc = 5,
91 .chip_info = &cht_chip_info,
92 .default_fw_path = "intel/sof",
93 .default_tplg_path = "intel/sof-tplg",
Olivier Deprez157378f2022-04-04 15:47:50 +020094 .default_fw_filename = "sof-cht.ri",
David Brazdil0f672f62019-12-10 10:32:29 +000095 .nocodec_tplg_filename = "sof-cht-nocodec.tplg",
96 .ops = &sof_cht_ops,
David Brazdil0f672f62019-12-10 10:32:29 +000097};
98
99#endif
100
101static const struct dev_pm_ops sof_acpi_pm = {
102 SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume)
103 SET_RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume,
104 snd_sof_runtime_idle)
105};
106
107static void sof_acpi_probe_complete(struct device *dev)
108{
Olivier Deprez157378f2022-04-04 15:47:50 +0200109 dev_dbg(dev, "Completing SOF ACPI probe");
110
111 if (sof_acpi_debug & SOF_ACPI_DISABLE_PM_RUNTIME)
112 return;
113
David Brazdil0f672f62019-12-10 10:32:29 +0000114 /* allow runtime_pm */
115 pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS);
116 pm_runtime_use_autosuspend(dev);
117 pm_runtime_enable(dev);
118}
119
120static int sof_acpi_probe(struct platform_device *pdev)
121{
122 struct device *dev = &pdev->dev;
123 const struct sof_dev_desc *desc;
David Brazdil0f672f62019-12-10 10:32:29 +0000124 struct snd_sof_pdata *sof_pdata;
125 const struct snd_sof_dsp_ops *ops;
126 int ret;
127
128 dev_dbg(&pdev->dev, "ACPI DSP detected");
129
130 sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL);
131 if (!sof_pdata)
132 return -ENOMEM;
133
134 desc = device_get_match_data(dev);
135 if (!desc)
136 return -ENODEV;
137
Olivier Deprez157378f2022-04-04 15:47:50 +0200138#if IS_ENABLED(CONFIG_ACPI) && IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
David Brazdil0f672f62019-12-10 10:32:29 +0000139 if (desc == &sof_acpi_baytrail_desc && soc_intel_is_byt_cr(pdev))
140 desc = &sof_acpi_baytrailcr_desc;
141#endif
142
143 /* get ops for platform */
144 ops = desc->ops;
145 if (!ops) {
146 dev_err(dev, "error: no matching ACPI descriptor ops\n");
147 return -ENODEV;
148 }
149
David Brazdil0f672f62019-12-10 10:32:29 +0000150 sof_pdata->desc = desc;
151 sof_pdata->dev = &pdev->dev;
Olivier Deprez157378f2022-04-04 15:47:50 +0200152 sof_pdata->fw_filename = desc->default_fw_filename;
David Brazdil0f672f62019-12-10 10:32:29 +0000153
154 /* alternate fw and tplg filenames ? */
155 if (fw_path)
156 sof_pdata->fw_filename_prefix = fw_path;
157 else
158 sof_pdata->fw_filename_prefix =
159 sof_pdata->desc->default_fw_path;
160
161 if (tplg_path)
162 sof_pdata->tplg_filename_prefix = tplg_path;
163 else
164 sof_pdata->tplg_filename_prefix =
165 sof_pdata->desc->default_tplg_path;
166
167#if IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)
168 /* set callback to enable runtime_pm */
169 sof_pdata->sof_probe_complete = sof_acpi_probe_complete;
170#endif
171 /* call sof helper for DSP hardware probe */
172 ret = snd_sof_device_probe(dev, sof_pdata);
173 if (ret) {
174 dev_err(dev, "error: failed to probe DSP hardware!\n");
175 return ret;
176 }
177
178#if !IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)
179 sof_acpi_probe_complete(dev);
180#endif
181
182 return ret;
183}
184
185static int sof_acpi_remove(struct platform_device *pdev)
186{
Olivier Deprez157378f2022-04-04 15:47:50 +0200187 if (!(sof_acpi_debug & SOF_ACPI_DISABLE_PM_RUNTIME))
188 pm_runtime_disable(&pdev->dev);
David Brazdil0f672f62019-12-10 10:32:29 +0000189
190 /* call sof helper for DSP hardware remove */
191 snd_sof_device_remove(&pdev->dev);
192
193 return 0;
194}
195
Olivier Deprez157378f2022-04-04 15:47:50 +0200196#ifdef CONFIG_ACPI
David Brazdil0f672f62019-12-10 10:32:29 +0000197static const struct acpi_device_id sof_acpi_match[] = {
David Brazdil0f672f62019-12-10 10:32:29 +0000198#if IS_ENABLED(CONFIG_SND_SOC_SOF_BROADWELL)
199 { "INT3438", (unsigned long)&sof_acpi_broadwell_desc },
200#endif
201#if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
202 { "80860F28", (unsigned long)&sof_acpi_baytrail_desc },
203 { "808622A8", (unsigned long)&sof_acpi_cherrytrail_desc },
204#endif
205 { }
206};
207MODULE_DEVICE_TABLE(acpi, sof_acpi_match);
Olivier Deprez157378f2022-04-04 15:47:50 +0200208#endif
David Brazdil0f672f62019-12-10 10:32:29 +0000209
210/* acpi_driver definition */
211static struct platform_driver snd_sof_acpi_driver = {
212 .probe = sof_acpi_probe,
213 .remove = sof_acpi_remove,
214 .driver = {
215 .name = "sof-audio-acpi",
216 .pm = &sof_acpi_pm,
217 .acpi_match_table = ACPI_PTR(sof_acpi_match),
218 },
219};
220module_platform_driver(snd_sof_acpi_driver);
221
222MODULE_LICENSE("Dual BSD/GPL");
Olivier Deprez157378f2022-04-04 15:47:50 +0200223MODULE_IMPORT_NS(SND_SOC_SOF_BAYTRAIL);
224MODULE_IMPORT_NS(SND_SOC_SOF_BROADWELL);