1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
5 // Author: Daniel Baluta <daniel.baluta@nxp.com>
8 #include <linux/firmware.h>
9 #include <linux/module.h>
10 #include <linux/moduleparam.h>
11 #include <linux/pm_runtime.h>
12 #include <sound/sof.h>
14 #include "sof-of-dev.h"
18 module_param(fw_path, charp, 0444);
19 MODULE_PARM_DESC(fw_path, "alternate path for SOF firmware.");
21 static char *tplg_path;
22 module_param(tplg_path, charp, 0444);
23 MODULE_PARM_DESC(tplg_path, "alternate path for SOF topology.");
25 const struct dev_pm_ops sof_of_pm = {
26 .prepare = snd_sof_prepare,
27 .complete = snd_sof_complete,
28 SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume)
29 SET_RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume,
32 EXPORT_SYMBOL(sof_of_pm);
34 static void sof_of_probe_complete(struct device *dev)
36 /* allow runtime_pm */
37 pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS);
38 pm_runtime_use_autosuspend(dev);
39 pm_runtime_mark_last_busy(dev);
40 pm_runtime_set_active(dev);
41 pm_runtime_enable(dev);
44 int sof_of_probe(struct platform_device *pdev)
46 struct device *dev = &pdev->dev;
47 const struct sof_dev_desc *desc;
48 struct snd_sof_pdata *sof_pdata;
50 dev_info(&pdev->dev, "DT DSP detected");
52 sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL);
56 desc = device_get_match_data(dev);
61 dev_err(dev, "error: no matching DT descriptor ops\n");
65 sof_pdata->desc = desc;
66 sof_pdata->dev = &pdev->dev;
67 sof_pdata->fw_filename = desc->default_fw_filename[SOF_IPC];
70 sof_pdata->fw_filename_prefix = fw_path;
72 sof_pdata->fw_filename_prefix = sof_pdata->desc->default_fw_path[SOF_IPC];
75 sof_pdata->tplg_filename_prefix = tplg_path;
77 sof_pdata->tplg_filename_prefix = sof_pdata->desc->default_tplg_path[SOF_IPC];
79 /* set callback to be called on successful device probe to enable runtime_pm */
80 sof_pdata->sof_probe_complete = sof_of_probe_complete;
82 /* call sof helper for DSP hardware probe */
83 return snd_sof_device_probe(dev, sof_pdata);
85 EXPORT_SYMBOL(sof_of_probe);
87 int sof_of_remove(struct platform_device *pdev)
89 pm_runtime_disable(&pdev->dev);
91 /* call sof helper for DSP hardware remove */
92 snd_sof_device_remove(&pdev->dev);
96 EXPORT_SYMBOL(sof_of_remove);
98 void sof_of_shutdown(struct platform_device *pdev)
100 snd_sof_device_shutdown(&pdev->dev);
102 EXPORT_SYMBOL(sof_of_shutdown);
104 MODULE_LICENSE("Dual BSD/GPL");