1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) 2 // 3 // Copyright 2019 NXP 4 // 5 // Author: Daniel Baluta <daniel.baluta@nxp.com> 6 // 7 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> 13 14 #include "sof-of-dev.h" 15 #include "ops.h" 16 17 static char *fw_path; 18 module_param(fw_path, charp, 0444); 19 MODULE_PARM_DESC(fw_path, "deprecated - moved to snd-sof module."); 20 21 static char *fw_filename; 22 module_param(fw_filename, charp, 0444); 23 MODULE_PARM_DESC(fw_filename, "deprecated - moved to snd-sof module."); 24 25 static char *tplg_path; 26 module_param(tplg_path, charp, 0444); 27 MODULE_PARM_DESC(tplg_path, "deprecated - moved to snd-sof module."); 28 29 static char *tplg_filename; 30 module_param(tplg_filename, charp, 0444); 31 MODULE_PARM_DESC(tplg_filename, "deprecated - moved to snd-sof module."); 32 33 const struct dev_pm_ops sof_of_pm = { 34 .prepare = snd_sof_prepare, 35 .complete = snd_sof_complete, 36 SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume) 37 SET_RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume, 38 NULL) 39 }; 40 EXPORT_SYMBOL(sof_of_pm); 41 42 static void sof_of_probe_complete(struct device *dev) 43 { 44 /* allow runtime_pm */ 45 pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS); 46 pm_runtime_use_autosuspend(dev); 47 pm_runtime_mark_last_busy(dev); 48 pm_runtime_set_active(dev); 49 pm_runtime_enable(dev); 50 } 51 52 int sof_of_probe(struct platform_device *pdev) 53 { 54 struct device *dev = &pdev->dev; 55 const struct sof_dev_desc *desc; 56 struct snd_sof_pdata *sof_pdata; 57 58 dev_info(&pdev->dev, "DT DSP detected"); 59 60 sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL); 61 if (!sof_pdata) 62 return -ENOMEM; 63 64 desc = device_get_match_data(dev); 65 if (!desc) 66 return -ENODEV; 67 68 if (!desc->ops) { 69 dev_err(dev, "error: no matching DT descriptor ops\n"); 70 return -ENODEV; 71 } 72 73 sof_pdata->desc = desc; 74 sof_pdata->dev = &pdev->dev; 75 76 sof_pdata->ipc_file_profile_base.ipc_type = desc->ipc_default; 77 sof_pdata->ipc_file_profile_base.fw_path = fw_path; 78 sof_pdata->ipc_file_profile_base.tplg_path = tplg_path; 79 sof_pdata->ipc_file_profile_base.fw_name = fw_filename; 80 sof_pdata->ipc_file_profile_base.tplg_name = tplg_filename; 81 82 /* set callback to be called on successful device probe to enable runtime_pm */ 83 sof_pdata->sof_probe_complete = sof_of_probe_complete; 84 85 /* call sof helper for DSP hardware probe */ 86 return snd_sof_device_probe(dev, sof_pdata); 87 } 88 EXPORT_SYMBOL(sof_of_probe); 89 90 void sof_of_remove(struct platform_device *pdev) 91 { 92 pm_runtime_disable(&pdev->dev); 93 94 /* call sof helper for DSP hardware remove */ 95 snd_sof_device_remove(&pdev->dev); 96 } 97 EXPORT_SYMBOL(sof_of_remove); 98 99 void sof_of_shutdown(struct platform_device *pdev) 100 { 101 snd_sof_device_shutdown(&pdev->dev); 102 } 103 EXPORT_SYMBOL(sof_of_shutdown); 104 105 MODULE_LICENSE("Dual BSD/GPL"); 106 MODULE_DESCRIPTION("SOF support for OF/DT platforms"); 107