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