xref: /linux/sound/soc/sof/sof-acpi-dev.c (revision 36ec807b627b4c0a0a382f0ae48eac7187d14b2b)
1e149ca29SPierre-Louis Bossart // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2cd679898SLiam Girdwood //
3cd679898SLiam Girdwood // This file is provided under a dual BSD/GPLv2 license.  When using or
4cd679898SLiam Girdwood // redistributing this file, you may do so under either license.
5cd679898SLiam Girdwood //
6293ad281SPierre-Louis Bossart // Copyright(c) 2018 Intel Corporation
7cd679898SLiam Girdwood //
8cd679898SLiam Girdwood // Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
9cd679898SLiam Girdwood //
10cd679898SLiam Girdwood 
11cd679898SLiam Girdwood #include <linux/acpi.h>
12cd679898SLiam Girdwood #include <linux/firmware.h>
13cd679898SLiam Girdwood #include <linux/module.h>
14cd679898SLiam Girdwood #include <linux/pm_runtime.h>
15cd679898SLiam Girdwood #include <sound/soc-acpi.h>
16cd679898SLiam Girdwood #include <sound/soc-acpi-intel-match.h>
17cd679898SLiam Girdwood #include <sound/sof.h>
18536cfd2fSPierre-Louis Bossart #include "../intel/common/soc-intel-quirks.h"
19cd679898SLiam Girdwood #include "ops.h"
208a49cd11SArnd Bergmann #include "sof-acpi-dev.h"
21cd679898SLiam Girdwood 
22cd679898SLiam Girdwood /* platform specific devices */
23cd679898SLiam Girdwood #include "intel/shim.h"
24cd679898SLiam Girdwood 
25cd679898SLiam Girdwood static char *fw_path;
26cd679898SLiam Girdwood module_param(fw_path, charp, 0444);
27cd679898SLiam Girdwood MODULE_PARM_DESC(fw_path, "alternate path for SOF firmware.");
28cd679898SLiam Girdwood 
29cd679898SLiam Girdwood static char *tplg_path;
30cd679898SLiam Girdwood module_param(tplg_path, charp, 0444);
31cd679898SLiam Girdwood MODULE_PARM_DESC(tplg_path, "alternate path for SOF topology.");
32cd679898SLiam Girdwood 
3370b0c75aSPierre-Louis Bossart static int sof_acpi_debug;
3470b0c75aSPierre-Louis Bossart module_param_named(sof_acpi_debug, sof_acpi_debug, int, 0444);
3570b0c75aSPierre-Louis Bossart MODULE_PARM_DESC(sof_acpi_debug, "SOF ACPI debug options (0x0 all off)");
3670b0c75aSPierre-Louis Bossart 
3770b0c75aSPierre-Louis Bossart #define SOF_ACPI_DISABLE_PM_RUNTIME BIT(0)
3870b0c75aSPierre-Louis Bossart 
398a49cd11SArnd Bergmann const struct dev_pm_ops sof_acpi_pm = {
40cd679898SLiam Girdwood 	SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume)
41cd679898SLiam Girdwood 	SET_RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume,
4262fde977SKai Vehmanen 			   snd_sof_runtime_idle)
43cd679898SLiam Girdwood };
448a49cd11SArnd Bergmann EXPORT_SYMBOL_NS(sof_acpi_pm, SND_SOC_SOF_ACPI_DEV);
45cd679898SLiam Girdwood 
46cd679898SLiam Girdwood static void sof_acpi_probe_complete(struct device *dev)
47cd679898SLiam Girdwood {
4871d551f5SPierre-Louis Bossart 	dev_dbg(dev, "Completing SOF ACPI probe");
4971d551f5SPierre-Louis Bossart 
5070b0c75aSPierre-Louis Bossart 	if (sof_acpi_debug & SOF_ACPI_DISABLE_PM_RUNTIME)
5170b0c75aSPierre-Louis Bossart 		return;
5270b0c75aSPierre-Louis Bossart 
53cd679898SLiam Girdwood 	/* allow runtime_pm */
54cd679898SLiam Girdwood 	pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS);
55cd679898SLiam Girdwood 	pm_runtime_use_autosuspend(dev);
56cd679898SLiam Girdwood 	pm_runtime_enable(dev);
57cd679898SLiam Girdwood }
58cd679898SLiam Girdwood 
598a49cd11SArnd Bergmann int sof_acpi_probe(struct platform_device *pdev, const struct sof_dev_desc *desc)
60cd679898SLiam Girdwood {
61cd679898SLiam Girdwood 	struct device *dev = &pdev->dev;
62cd679898SLiam Girdwood 	struct snd_sof_pdata *sof_pdata;
63cd679898SLiam Girdwood 
64f7313f9fSPierre-Louis Bossart 	dev_dbg(dev, "ACPI DSP detected");
65cd679898SLiam Girdwood 
66cd679898SLiam Girdwood 	sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL);
67cd679898SLiam Girdwood 	if (!sof_pdata)
68cd679898SLiam Girdwood 		return -ENOMEM;
69cd679898SLiam Girdwood 
70fd979ec1SPeter Ujfalusi 	if (!desc->ops) {
71cd679898SLiam Girdwood 		dev_err(dev, "error: no matching ACPI descriptor ops\n");
72cd679898SLiam Girdwood 		return -ENODEV;
73cd679898SLiam Girdwood 	}
74cd679898SLiam Girdwood 
75cd679898SLiam Girdwood 	sof_pdata->desc = desc;
76cd679898SLiam Girdwood 	sof_pdata->dev = &pdev->dev;
77cd679898SLiam Girdwood 
78a07625dcSPeter Ujfalusi 	sof_pdata->ipc_file_profile_base.ipc_type = desc->ipc_default;
79a07625dcSPeter Ujfalusi 	sof_pdata->ipc_file_profile_base.fw_path = fw_path;
80a07625dcSPeter Ujfalusi 	sof_pdata->ipc_file_profile_base.tplg_path = tplg_path;
81a07625dcSPeter Ujfalusi 
824d1284cdSPeter Ujfalusi 	/* set callback to be called on successful device probe to enable runtime_pm */
83cd679898SLiam Girdwood 	sof_pdata->sof_probe_complete = sof_acpi_probe_complete;
844d1284cdSPeter Ujfalusi 
85cd679898SLiam Girdwood 	/* call sof helper for DSP hardware probe */
864d1284cdSPeter Ujfalusi 	return snd_sof_device_probe(dev, sof_pdata);
87cd679898SLiam Girdwood }
888a49cd11SArnd Bergmann EXPORT_SYMBOL_NS(sof_acpi_probe, SND_SOC_SOF_ACPI_DEV);
89cd679898SLiam Girdwood 
9052fee5c9SUwe Kleine-König void sof_acpi_remove(struct platform_device *pdev)
91cd679898SLiam Girdwood {
928a49cd11SArnd Bergmann 	struct device *dev = &pdev->dev;
938a49cd11SArnd Bergmann 
9470b0c75aSPierre-Louis Bossart 	if (!(sof_acpi_debug & SOF_ACPI_DISABLE_PM_RUNTIME))
958a49cd11SArnd Bergmann 		pm_runtime_disable(dev);
96cd679898SLiam Girdwood 
97cd679898SLiam Girdwood 	/* call sof helper for DSP hardware remove */
988a49cd11SArnd Bergmann 	snd_sof_device_remove(dev);
99cd679898SLiam Girdwood }
1008a49cd11SArnd Bergmann EXPORT_SYMBOL_NS(sof_acpi_remove, SND_SOC_SOF_ACPI_DEV);
101cd679898SLiam Girdwood 
102cd679898SLiam Girdwood MODULE_LICENSE("Dual BSD/GPL");
103*3ff78451SPierre-Louis Bossart MODULE_DESCRIPTION("SOF support for ACPI platforms");
104