Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
0002 //
0003 // Copyright 2019 NXP
0004 //
0005 // Author: Daniel Baluta <daniel.baluta@nxp.com>
0006 //
0007 
0008 #include <linux/firmware.h>
0009 #include <linux/module.h>
0010 #include <linux/moduleparam.h>
0011 #include <linux/pm_runtime.h>
0012 #include <sound/sof.h>
0013 
0014 #include "sof-of-dev.h"
0015 #include "ops.h"
0016 
0017 static char *fw_path;
0018 module_param(fw_path, charp, 0444);
0019 MODULE_PARM_DESC(fw_path, "alternate path for SOF firmware.");
0020 
0021 static char *tplg_path;
0022 module_param(tplg_path, charp, 0444);
0023 MODULE_PARM_DESC(tplg_path, "alternate path for SOF topology.");
0024 
0025 const struct dev_pm_ops sof_of_pm = {
0026     .prepare = snd_sof_prepare,
0027     .complete = snd_sof_complete,
0028     SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume)
0029     SET_RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume,
0030                NULL)
0031 };
0032 EXPORT_SYMBOL(sof_of_pm);
0033 
0034 static void sof_of_probe_complete(struct device *dev)
0035 {
0036     /* allow runtime_pm */
0037     pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS);
0038     pm_runtime_use_autosuspend(dev);
0039     pm_runtime_mark_last_busy(dev);
0040     pm_runtime_set_active(dev);
0041     pm_runtime_enable(dev);
0042 }
0043 
0044 int sof_of_probe(struct platform_device *pdev)
0045 {
0046     struct device *dev = &pdev->dev;
0047     const struct sof_dev_desc *desc;
0048     struct snd_sof_pdata *sof_pdata;
0049 
0050     dev_info(&pdev->dev, "DT DSP detected");
0051 
0052     sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL);
0053     if (!sof_pdata)
0054         return -ENOMEM;
0055 
0056     desc = device_get_match_data(dev);
0057     if (!desc)
0058         return -ENODEV;
0059 
0060     if (!desc->ops) {
0061         dev_err(dev, "error: no matching DT descriptor ops\n");
0062         return -ENODEV;
0063     }
0064 
0065     sof_pdata->desc = desc;
0066     sof_pdata->dev = &pdev->dev;
0067     sof_pdata->fw_filename = desc->default_fw_filename[SOF_IPC];
0068 
0069     if (fw_path)
0070         sof_pdata->fw_filename_prefix = fw_path;
0071     else
0072         sof_pdata->fw_filename_prefix = sof_pdata->desc->default_fw_path[SOF_IPC];
0073 
0074     if (tplg_path)
0075         sof_pdata->tplg_filename_prefix = tplg_path;
0076     else
0077         sof_pdata->tplg_filename_prefix = sof_pdata->desc->default_tplg_path[SOF_IPC];
0078 
0079     /* set callback to be called on successful device probe to enable runtime_pm */
0080     sof_pdata->sof_probe_complete = sof_of_probe_complete;
0081 
0082     /* call sof helper for DSP hardware probe */
0083     return snd_sof_device_probe(dev, sof_pdata);
0084 }
0085 EXPORT_SYMBOL(sof_of_probe);
0086 
0087 int sof_of_remove(struct platform_device *pdev)
0088 {
0089     pm_runtime_disable(&pdev->dev);
0090 
0091     /* call sof helper for DSP hardware remove */
0092     snd_sof_device_remove(&pdev->dev);
0093 
0094     return 0;
0095 }
0096 EXPORT_SYMBOL(sof_of_remove);
0097 
0098 void sof_of_shutdown(struct platform_device *pdev)
0099 {
0100     snd_sof_device_shutdown(&pdev->dev);
0101 }
0102 EXPORT_SYMBOL(sof_of_shutdown);
0103 
0104 MODULE_LICENSE("Dual BSD/GPL");