Merge tag 'block-5.11-2020-12-23' of git://git.kernel.dk/linux-block
[linux-2.6-microblaze.git] / sound / soc / sof / sof-acpi-dev.c
1 // SPDX-License-Identifier: (GPL-2.0-only 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 <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/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"
20 #include "ops.h"
21
22 /* platform specific devices */
23 #include "intel/shim.h"
24
25 static char *fw_path;
26 module_param(fw_path, charp, 0444);
27 MODULE_PARM_DESC(fw_path, "alternate path for SOF firmware.");
28
29 static char *tplg_path;
30 module_param(tplg_path, charp, 0444);
31 MODULE_PARM_DESC(tplg_path, "alternate path for SOF topology.");
32
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)");
36
37 #define SOF_ACPI_DISABLE_PM_RUNTIME BIT(0)
38
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",
51         .ops = &sof_bdw_ops,
52 };
53 #endif
54
55 #if IS_ENABLED(CONFIG_ACPI) && IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
56
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",
69         .ops = &sof_byt_ops,
70 };
71
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",
83         .ops = &sof_byt_ops,
84 };
85
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",
97         .ops = &sof_cht_ops,
98 };
99
100 #endif
101
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)
106 };
107
108 static void sof_acpi_probe_complete(struct device *dev)
109 {
110         dev_dbg(dev, "Completing SOF ACPI probe");
111
112         if (sof_acpi_debug & SOF_ACPI_DISABLE_PM_RUNTIME)
113                 return;
114
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);
119 }
120
121 static int sof_acpi_probe(struct platform_device *pdev)
122 {
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;
128         int ret;
129
130         id = acpi_match_device(dev->driver->acpi_match_table, dev);
131         if (!id)
132                 return -ENODEV;
133
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");
137                 return -ENODEV;
138         }
139
140         dev_dbg(dev, "ACPI DSP detected");
141
142         sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL);
143         if (!sof_pdata)
144                 return -ENOMEM;
145
146         desc = device_get_match_data(dev);
147         if (!desc)
148                 return -ENODEV;
149
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;
153 #endif
154
155         /* get ops for platform */
156         ops = desc->ops;
157         if (!ops) {
158                 dev_err(dev, "error: no matching ACPI descriptor ops\n");
159                 return -ENODEV;
160         }
161
162         sof_pdata->desc = desc;
163         sof_pdata->dev = &pdev->dev;
164         sof_pdata->fw_filename = desc->default_fw_filename;
165
166         /* alternate fw and tplg filenames ? */
167         if (fw_path)
168                 sof_pdata->fw_filename_prefix = fw_path;
169         else
170                 sof_pdata->fw_filename_prefix =
171                         sof_pdata->desc->default_fw_path;
172
173         if (tplg_path)
174                 sof_pdata->tplg_filename_prefix = tplg_path;
175         else
176                 sof_pdata->tplg_filename_prefix =
177                         sof_pdata->desc->default_tplg_path;
178
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;
182 #endif
183         /* call sof helper for DSP hardware probe */
184         ret = snd_sof_device_probe(dev, sof_pdata);
185         if (ret) {
186                 dev_err(dev, "error: failed to probe DSP hardware!\n");
187                 return ret;
188         }
189
190 #if !IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)
191         sof_acpi_probe_complete(dev);
192 #endif
193
194         return ret;
195 }
196
197 static int sof_acpi_remove(struct platform_device *pdev)
198 {
199         if (!(sof_acpi_debug & SOF_ACPI_DISABLE_PM_RUNTIME))
200                 pm_runtime_disable(&pdev->dev);
201
202         /* call sof helper for DSP hardware remove */
203         snd_sof_device_remove(&pdev->dev);
204
205         return 0;
206 }
207
208 #ifdef CONFIG_ACPI
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 },
212 #endif
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 },
216 #endif
217         { }
218 };
219 MODULE_DEVICE_TABLE(acpi, sof_acpi_match);
220 #endif
221
222 /* acpi_driver definition */
223 static struct platform_driver snd_sof_acpi_driver = {
224         .probe = sof_acpi_probe,
225         .remove = sof_acpi_remove,
226         .driver = {
227                 .name = "sof-audio-acpi",
228                 .pm = &sof_acpi_pm,
229                 .acpi_match_table = ACPI_PTR(sof_acpi_match),
230         },
231 };
232 module_platform_driver(snd_sof_acpi_driver);
233
234 MODULE_LICENSE("Dual BSD/GPL");
235 MODULE_IMPORT_NS(SND_SOC_SOF_BAYTRAIL);
236 MODULE_IMPORT_NS(SND_SOC_SOF_BROADWELL);