1 // SPDX-License-Identifier: (GPL-2.0-only OR B !! 1 // SPDX-License-Identifier: (GPL-2.0 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> << 11 #include <linux/pm_runtime.h> 10 #include <linux/pm_runtime.h> 12 #include <sound/sof.h> 11 #include <sound/sof.h> 13 12 14 #include "sof-of-dev.h" << 15 #include "ops.h" 13 #include "ops.h" 16 14 17 static char *fw_path; !! 15 extern struct snd_sof_dsp_ops sof_imx8_ops; 18 module_param(fw_path, charp, 0444); !! 16 extern struct snd_sof_dsp_ops sof_imx8x_ops; 19 MODULE_PARM_DESC(fw_path, "alternate path for !! 17 20 !! 18 /* platform specific devices */ 21 static char *tplg_path; !! 19 #if IS_ENABLED(CONFIG_SND_SOC_SOF_IMX8) 22 module_param(tplg_path, charp, 0444); !! 20 static struct sof_dev_desc sof_of_imx8qxp_desc = { 23 MODULE_PARM_DESC(tplg_path, "alternate path fo !! 21 .default_fw_path = "imx/sof", 24 !! 22 .default_tplg_path = "imx/sof-tplg", 25 const struct dev_pm_ops sof_of_pm = { !! 23 .default_fw_filename = "sof-imx8x.ri", 26 .prepare = snd_sof_prepare, !! 24 .nocodec_tplg_filename = "sof-imx8-nocodec.tplg", 27 .complete = snd_sof_complete, !! 25 .ops = &sof_imx8x_ops, >> 26 }; >> 27 >> 28 static struct sof_dev_desc sof_of_imx8qm_desc = { >> 29 .default_fw_path = "imx/sof", >> 30 .default_tplg_path = "imx/sof-tplg", >> 31 .default_fw_filename = "sof-imx8.ri", >> 32 .nocodec_tplg_filename = "sof-imx8-nocodec.tplg", >> 33 .ops = &sof_imx8_ops, >> 34 }; >> 35 #endif >> 36 >> 37 static const struct dev_pm_ops sof_of_pm = { 28 SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspen 38 SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume) 29 SET_RUNTIME_PM_OPS(snd_sof_runtime_sus 39 SET_RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume, 30 NULL) 40 NULL) 31 }; 41 }; 32 EXPORT_SYMBOL(sof_of_pm); << 33 42 34 static void sof_of_probe_complete(struct devic 43 static void sof_of_probe_complete(struct device *dev) 35 { 44 { 36 /* allow runtime_pm */ 45 /* allow runtime_pm */ 37 pm_runtime_set_autosuspend_delay(dev, 46 pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS); 38 pm_runtime_use_autosuspend(dev); 47 pm_runtime_use_autosuspend(dev); 39 pm_runtime_mark_last_busy(dev); << 40 pm_runtime_set_active(dev); << 41 pm_runtime_enable(dev); 48 pm_runtime_enable(dev); 42 } 49 } 43 50 44 int sof_of_probe(struct platform_device *pdev) !! 51 static int sof_of_probe(struct platform_device *pdev) 45 { 52 { 46 struct device *dev = &pdev->dev; 53 struct device *dev = &pdev->dev; 47 const struct sof_dev_desc *desc; 54 const struct sof_dev_desc *desc; 48 struct snd_sof_pdata *sof_pdata; 55 struct snd_sof_pdata *sof_pdata; >> 56 const struct snd_sof_dsp_ops *ops; >> 57 int ret; 49 58 50 dev_info(&pdev->dev, "DT DSP detected" 59 dev_info(&pdev->dev, "DT DSP detected"); 51 60 52 sof_pdata = devm_kzalloc(dev, sizeof(* 61 sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL); 53 if (!sof_pdata) 62 if (!sof_pdata) 54 return -ENOMEM; 63 return -ENOMEM; 55 64 56 desc = device_get_match_data(dev); 65 desc = device_get_match_data(dev); 57 if (!desc) 66 if (!desc) 58 return -ENODEV; 67 return -ENODEV; 59 68 60 if (!desc->ops) { !! 69 /* get ops for platform */ >> 70 ops = desc->ops; >> 71 if (!ops) { 61 dev_err(dev, "error: no matchi 72 dev_err(dev, "error: no matching DT descriptor ops\n"); 62 return -ENODEV; 73 return -ENODEV; 63 } 74 } 64 75 65 sof_pdata->desc = desc; 76 sof_pdata->desc = desc; 66 sof_pdata->dev = &pdev->dev; 77 sof_pdata->dev = &pdev->dev; >> 78 sof_pdata->fw_filename = desc->default_fw_filename; 67 79 68 sof_pdata->ipc_file_profile_base.ipc_t !! 80 /* TODO: read alternate fw and tplg filenames from DT */ 69 sof_pdata->ipc_file_profile_base.fw_pa !! 81 sof_pdata->fw_filename_prefix = sof_pdata->desc->default_fw_path; 70 sof_pdata->ipc_file_profile_base.tplg_ !! 82 sof_pdata->tplg_filename_prefix = sof_pdata->desc->default_tplg_path; 71 83 72 /* set callback to be called on succes !! 84 #if IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE) >> 85 /* set callback to enable runtime_pm */ 73 sof_pdata->sof_probe_complete = sof_of 86 sof_pdata->sof_probe_complete = sof_of_probe_complete; >> 87 #endif >> 88 /* call sof helper for DSP hardware probe */ >> 89 ret = snd_sof_device_probe(dev, sof_pdata); >> 90 if (ret) { >> 91 dev_err(dev, "error: failed to probe DSP hardware\n"); >> 92 return ret; >> 93 } >> 94 >> 95 #if !IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE) >> 96 sof_of_probe_complete(dev); >> 97 #endif 74 98 75 /* call sof helper for DSP hardware pr !! 99 return ret; 76 return snd_sof_device_probe(dev, sof_p << 77 } 100 } 78 EXPORT_SYMBOL(sof_of_probe); << 79 101 80 void sof_of_remove(struct platform_device *pde !! 102 static int sof_of_remove(struct platform_device *pdev) 81 { 103 { 82 pm_runtime_disable(&pdev->dev); 104 pm_runtime_disable(&pdev->dev); 83 105 84 /* call sof helper for DSP hardware re 106 /* call sof helper for DSP hardware remove */ 85 snd_sof_device_remove(&pdev->dev); 107 snd_sof_device_remove(&pdev->dev); 86 } << 87 EXPORT_SYMBOL(sof_of_remove); << 88 108 89 void sof_of_shutdown(struct platform_device *p !! 109 return 0; 90 { << 91 snd_sof_device_shutdown(&pdev->dev); << 92 } 110 } 93 EXPORT_SYMBOL(sof_of_shutdown); !! 111 >> 112 static const struct of_device_id sof_of_ids[] = { >> 113 #if IS_ENABLED(CONFIG_SND_SOC_SOF_IMX8) >> 114 { .compatible = "fsl,imx8qxp-dsp", .data = &sof_of_imx8qxp_desc}, >> 115 { .compatible = "fsl,imx8qm-dsp", .data = &sof_of_imx8qm_desc}, >> 116 #endif >> 117 { } >> 118 }; >> 119 MODULE_DEVICE_TABLE(of, sof_of_ids); >> 120 >> 121 /* DT driver definition */ >> 122 static struct platform_driver snd_sof_of_driver = { >> 123 .probe = sof_of_probe, >> 124 .remove = sof_of_remove, >> 125 .driver = { >> 126 .name = "sof-audio-of", >> 127 .pm = &sof_of_pm, >> 128 .of_match_table = sof_of_ids, >> 129 }, >> 130 }; >> 131 module_platform_driver(snd_sof_of_driver); 94 132 95 MODULE_LICENSE("Dual BSD/GPL"); 133 MODULE_LICENSE("Dual BSD/GPL"); 96 MODULE_DESCRIPTION("SOF support for OF/DT plat << 97 134
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.