1 // SPDX-License-Identifier: (GPL-2.0-only OR B 1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) 2 // 2 // 3 // Copyright 2019 NXP 3 // Copyright 2019 NXP 4 // 4 // 5 // Author: Daniel Baluta <daniel.baluta@nxp.co 5 // Author: Daniel Baluta <daniel.baluta@nxp.com> 6 // 6 // 7 7 8 #include <linux/firmware.h> 8 #include <linux/firmware.h> 9 #include <linux/module.h> 9 #include <linux/module.h> 10 #include <linux/moduleparam.h> 10 #include <linux/moduleparam.h> 11 #include <linux/pm_runtime.h> 11 #include <linux/pm_runtime.h> 12 #include <sound/sof.h> 12 #include <sound/sof.h> 13 13 14 #include "sof-of-dev.h" 14 #include "sof-of-dev.h" 15 #include "ops.h" 15 #include "ops.h" 16 16 17 static char *fw_path; 17 static char *fw_path; 18 module_param(fw_path, charp, 0444); 18 module_param(fw_path, charp, 0444); 19 MODULE_PARM_DESC(fw_path, "alternate path for 19 MODULE_PARM_DESC(fw_path, "alternate path for SOF firmware."); 20 20 21 static char *tplg_path; 21 static char *tplg_path; 22 module_param(tplg_path, charp, 0444); 22 module_param(tplg_path, charp, 0444); 23 MODULE_PARM_DESC(tplg_path, "alternate path fo 23 MODULE_PARM_DESC(tplg_path, "alternate path for SOF topology."); 24 24 25 const struct dev_pm_ops sof_of_pm = { 25 const struct dev_pm_ops sof_of_pm = { 26 .prepare = snd_sof_prepare, 26 .prepare = snd_sof_prepare, 27 .complete = snd_sof_complete, 27 .complete = snd_sof_complete, 28 SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspen 28 SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume) 29 SET_RUNTIME_PM_OPS(snd_sof_runtime_sus 29 SET_RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume, 30 NULL) 30 NULL) 31 }; 31 }; 32 EXPORT_SYMBOL(sof_of_pm); 32 EXPORT_SYMBOL(sof_of_pm); 33 33 34 static void sof_of_probe_complete(struct devic 34 static void sof_of_probe_complete(struct device *dev) 35 { 35 { 36 /* allow runtime_pm */ 36 /* allow runtime_pm */ 37 pm_runtime_set_autosuspend_delay(dev, 37 pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS); 38 pm_runtime_use_autosuspend(dev); 38 pm_runtime_use_autosuspend(dev); 39 pm_runtime_mark_last_busy(dev); 39 pm_runtime_mark_last_busy(dev); 40 pm_runtime_set_active(dev); 40 pm_runtime_set_active(dev); 41 pm_runtime_enable(dev); 41 pm_runtime_enable(dev); 42 } 42 } 43 43 44 int sof_of_probe(struct platform_device *pdev) 44 int sof_of_probe(struct platform_device *pdev) 45 { 45 { 46 struct device *dev = &pdev->dev; 46 struct device *dev = &pdev->dev; 47 const struct sof_dev_desc *desc; 47 const struct sof_dev_desc *desc; 48 struct snd_sof_pdata *sof_pdata; 48 struct snd_sof_pdata *sof_pdata; 49 49 50 dev_info(&pdev->dev, "DT DSP detected" 50 dev_info(&pdev->dev, "DT DSP detected"); 51 51 52 sof_pdata = devm_kzalloc(dev, sizeof(* 52 sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL); 53 if (!sof_pdata) 53 if (!sof_pdata) 54 return -ENOMEM; 54 return -ENOMEM; 55 55 56 desc = device_get_match_data(dev); 56 desc = device_get_match_data(dev); 57 if (!desc) 57 if (!desc) 58 return -ENODEV; 58 return -ENODEV; 59 59 60 if (!desc->ops) { 60 if (!desc->ops) { 61 dev_err(dev, "error: no matchi 61 dev_err(dev, "error: no matching DT descriptor ops\n"); 62 return -ENODEV; 62 return -ENODEV; 63 } 63 } 64 64 65 sof_pdata->desc = desc; 65 sof_pdata->desc = desc; 66 sof_pdata->dev = &pdev->dev; 66 sof_pdata->dev = &pdev->dev; >> 67 sof_pdata->fw_filename = desc->default_fw_filename[SOF_IPC]; 67 68 68 sof_pdata->ipc_file_profile_base.ipc_t !! 69 if (fw_path) 69 sof_pdata->ipc_file_profile_base.fw_pa !! 70 sof_pdata->fw_filename_prefix = fw_path; 70 sof_pdata->ipc_file_profile_base.tplg_ !! 71 else >> 72 sof_pdata->fw_filename_prefix = sof_pdata->desc->default_fw_path[SOF_IPC]; >> 73 >> 74 if (tplg_path) >> 75 sof_pdata->tplg_filename_prefix = tplg_path; >> 76 else >> 77 sof_pdata->tplg_filename_prefix = sof_pdata->desc->default_tplg_path[SOF_IPC]; 71 78 72 /* set callback to be called on succes 79 /* set callback to be called on successful device probe to enable runtime_pm */ 73 sof_pdata->sof_probe_complete = sof_of 80 sof_pdata->sof_probe_complete = sof_of_probe_complete; 74 81 75 /* call sof helper for DSP hardware pr 82 /* call sof helper for DSP hardware probe */ 76 return snd_sof_device_probe(dev, sof_p 83 return snd_sof_device_probe(dev, sof_pdata); 77 } 84 } 78 EXPORT_SYMBOL(sof_of_probe); 85 EXPORT_SYMBOL(sof_of_probe); 79 86 80 void sof_of_remove(struct platform_device *pde !! 87 int sof_of_remove(struct platform_device *pdev) 81 { 88 { 82 pm_runtime_disable(&pdev->dev); 89 pm_runtime_disable(&pdev->dev); 83 90 84 /* call sof helper for DSP hardware re 91 /* call sof helper for DSP hardware remove */ 85 snd_sof_device_remove(&pdev->dev); 92 snd_sof_device_remove(&pdev->dev); >> 93 >> 94 return 0; 86 } 95 } 87 EXPORT_SYMBOL(sof_of_remove); 96 EXPORT_SYMBOL(sof_of_remove); 88 97 89 void sof_of_shutdown(struct platform_device *p 98 void sof_of_shutdown(struct platform_device *pdev) 90 { 99 { 91 snd_sof_device_shutdown(&pdev->dev); 100 snd_sof_device_shutdown(&pdev->dev); 92 } 101 } 93 EXPORT_SYMBOL(sof_of_shutdown); 102 EXPORT_SYMBOL(sof_of_shutdown); 94 103 95 MODULE_LICENSE("Dual BSD/GPL"); 104 MODULE_LICENSE("Dual BSD/GPL"); 96 MODULE_DESCRIPTION("SOF support for OF/DT plat << 97 105
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.