Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
0002 //
0003 // This file is provided under a dual BSD/GPLv2 license.  When using or
0004 // redistributing this file, you may do so under either license.
0005 //
0006 // Copyright(c) 2018 Intel Corporation. All rights reserved.
0007 //
0008 // Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
0009 //
0010 
0011 #include <linux/acpi.h>
0012 #include <linux/firmware.h>
0013 #include <linux/module.h>
0014 #include <linux/pm_runtime.h>
0015 #include <sound/soc-acpi.h>
0016 #include <sound/soc-acpi-intel-match.h>
0017 #include <sound/sof.h>
0018 #include "../intel/common/soc-intel-quirks.h"
0019 #include "ops.h"
0020 #include "sof-acpi-dev.h"
0021 
0022 /* platform specific devices */
0023 #include "intel/shim.h"
0024 
0025 static char *fw_path;
0026 module_param(fw_path, charp, 0444);
0027 MODULE_PARM_DESC(fw_path, "alternate path for SOF firmware.");
0028 
0029 static char *tplg_path;
0030 module_param(tplg_path, charp, 0444);
0031 MODULE_PARM_DESC(tplg_path, "alternate path for SOF topology.");
0032 
0033 static int sof_acpi_debug;
0034 module_param_named(sof_acpi_debug, sof_acpi_debug, int, 0444);
0035 MODULE_PARM_DESC(sof_acpi_debug, "SOF ACPI debug options (0x0 all off)");
0036 
0037 #define SOF_ACPI_DISABLE_PM_RUNTIME BIT(0)
0038 
0039 const struct dev_pm_ops sof_acpi_pm = {
0040     SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume)
0041     SET_RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume,
0042                snd_sof_runtime_idle)
0043 };
0044 EXPORT_SYMBOL_NS(sof_acpi_pm, SND_SOC_SOF_ACPI_DEV);
0045 
0046 static void sof_acpi_probe_complete(struct device *dev)
0047 {
0048     dev_dbg(dev, "Completing SOF ACPI probe");
0049 
0050     if (sof_acpi_debug & SOF_ACPI_DISABLE_PM_RUNTIME)
0051         return;
0052 
0053     /* allow runtime_pm */
0054     pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS);
0055     pm_runtime_use_autosuspend(dev);
0056     pm_runtime_enable(dev);
0057 }
0058 
0059 int sof_acpi_probe(struct platform_device *pdev, const struct sof_dev_desc *desc)
0060 {
0061     struct device *dev = &pdev->dev;
0062     struct snd_sof_pdata *sof_pdata;
0063 
0064     dev_dbg(dev, "ACPI DSP detected");
0065 
0066     sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL);
0067     if (!sof_pdata)
0068         return -ENOMEM;
0069 
0070     if (!desc->ops) {
0071         dev_err(dev, "error: no matching ACPI descriptor ops\n");
0072         return -ENODEV;
0073     }
0074 
0075     sof_pdata->desc = desc;
0076     sof_pdata->dev = &pdev->dev;
0077     sof_pdata->fw_filename = desc->default_fw_filename[SOF_IPC];
0078 
0079     /* alternate fw and tplg filenames ? */
0080     if (fw_path)
0081         sof_pdata->fw_filename_prefix = fw_path;
0082     else
0083         sof_pdata->fw_filename_prefix =
0084             sof_pdata->desc->default_fw_path[SOF_IPC];
0085 
0086     if (tplg_path)
0087         sof_pdata->tplg_filename_prefix = tplg_path;
0088     else
0089         sof_pdata->tplg_filename_prefix =
0090             sof_pdata->desc->default_tplg_path[SOF_IPC];
0091 
0092     /* set callback to be called on successful device probe to enable runtime_pm */
0093     sof_pdata->sof_probe_complete = sof_acpi_probe_complete;
0094 
0095     /* call sof helper for DSP hardware probe */
0096     return snd_sof_device_probe(dev, sof_pdata);
0097 }
0098 EXPORT_SYMBOL_NS(sof_acpi_probe, SND_SOC_SOF_ACPI_DEV);
0099 
0100 int sof_acpi_remove(struct platform_device *pdev)
0101 {
0102     struct device *dev = &pdev->dev;
0103 
0104     if (!(sof_acpi_debug & SOF_ACPI_DISABLE_PM_RUNTIME))
0105         pm_runtime_disable(dev);
0106 
0107     /* call sof helper for DSP hardware remove */
0108     snd_sof_device_remove(dev);
0109 
0110     return 0;
0111 }
0112 EXPORT_SYMBOL_NS(sof_acpi_remove, SND_SOC_SOF_ACPI_DEV);
0113 
0114 MODULE_LICENSE("Dual BSD/GPL");