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 "ops.h" 15 #include "imx/imx-ops.h" 16 #include "mediatek/mediatek-ops.h" 17 18 static char *fw_path; 19 module_param(fw_path, charp, 0444); 20 MODULE_PARM_DESC(fw_path, "alternate path for SOF firmware."); 21 22 static char *tplg_path; 23 module_param(tplg_path, charp, 0444); 24 MODULE_PARM_DESC(tplg_path, "alternate path for SOF topology."); 25 26 /* platform specific devices */ 27 #if IS_ENABLED(CONFIG_SND_SOC_SOF_IMX8) 28 static struct sof_dev_desc sof_of_imx8qxp_desc = { 29 .default_fw_path = "imx/sof", 30 .default_tplg_path = "imx/sof-tplg", 31 .default_fw_filename = "sof-imx8x.ri", 32 .nocodec_tplg_filename = "sof-imx8-nocodec.tplg", 33 .ops = &sof_imx8x_ops, 34 }; 35 36 static struct sof_dev_desc sof_of_imx8qm_desc = { 37 .default_fw_path = "imx/sof", 38 .default_tplg_path = "imx/sof-tplg", 39 .default_fw_filename = "sof-imx8.ri", 40 .nocodec_tplg_filename = "sof-imx8-nocodec.tplg", 41 .ops = &sof_imx8_ops, 42 }; 43 #endif 44 45 #if IS_ENABLED(CONFIG_SND_SOC_SOF_IMX8M) 46 static struct sof_dev_desc sof_of_imx8mp_desc = { 47 .default_fw_path = "imx/sof", 48 .default_tplg_path = "imx/sof-tplg", 49 .default_fw_filename = "sof-imx8m.ri", 50 .nocodec_tplg_filename = "sof-imx8-nocodec.tplg", 51 .ops = &sof_imx8m_ops, 52 }; 53 #endif 54 #if IS_ENABLED(CONFIG_SND_SOC_SOF_MT8195) 55 static const struct sof_dev_desc sof_of_mt8195_desc = { 56 .default_fw_path = "mediatek/sof", 57 .default_tplg_path = "mediatek/sof-tplg", 58 .default_fw_filename = "sof-mt8195.ri", 59 .nocodec_tplg_filename = "sof-mt8195-nocodec.tplg", 60 .ops = &sof_mt8195_ops, 61 }; 62 #endif 63 64 static const struct dev_pm_ops sof_of_pm = { 65 .prepare = snd_sof_prepare, 66 .complete = snd_sof_complete, 67 SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume) 68 SET_RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume, 69 NULL) 70 }; 71 72 static void sof_of_probe_complete(struct device *dev) 73 { 74 /* allow runtime_pm */ 75 pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS); 76 pm_runtime_use_autosuspend(dev); 77 pm_runtime_set_active(dev); 78 pm_runtime_enable(dev); 79 80 pm_runtime_mark_last_busy(dev); 81 pm_runtime_put_autosuspend(dev); 82 } 83 84 static int sof_of_probe(struct platform_device *pdev) 85 { 86 struct device *dev = &pdev->dev; 87 const struct sof_dev_desc *desc; 88 struct snd_sof_pdata *sof_pdata; 89 90 dev_info(&pdev->dev, "DT DSP detected"); 91 92 sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL); 93 if (!sof_pdata) 94 return -ENOMEM; 95 96 desc = device_get_match_data(dev); 97 if (!desc) 98 return -ENODEV; 99 100 if (!desc->ops) { 101 dev_err(dev, "error: no matching DT descriptor ops\n"); 102 return -ENODEV; 103 } 104 105 sof_pdata->desc = desc; 106 sof_pdata->dev = &pdev->dev; 107 sof_pdata->fw_filename = desc->default_fw_filename; 108 109 if (fw_path) 110 sof_pdata->fw_filename_prefix = fw_path; 111 else 112 sof_pdata->fw_filename_prefix = sof_pdata->desc->default_fw_path; 113 114 if (tplg_path) 115 sof_pdata->tplg_filename_prefix = tplg_path; 116 else 117 sof_pdata->tplg_filename_prefix = sof_pdata->desc->default_tplg_path; 118 119 /* set callback to be called on successful device probe to enable runtime_pm */ 120 sof_pdata->sof_probe_complete = sof_of_probe_complete; 121 122 /* call sof helper for DSP hardware probe */ 123 return snd_sof_device_probe(dev, sof_pdata); 124 } 125 126 static int sof_of_remove(struct platform_device *pdev) 127 { 128 pm_runtime_disable(&pdev->dev); 129 130 /* call sof helper for DSP hardware remove */ 131 snd_sof_device_remove(&pdev->dev); 132 133 return 0; 134 } 135 136 static const struct of_device_id sof_of_ids[] = { 137 #if IS_ENABLED(CONFIG_SND_SOC_SOF_IMX8) 138 { .compatible = "fsl,imx8qxp-dsp", .data = &sof_of_imx8qxp_desc}, 139 { .compatible = "fsl,imx8qm-dsp", .data = &sof_of_imx8qm_desc}, 140 #endif 141 #if IS_ENABLED(CONFIG_SND_SOC_SOF_IMX8M) 142 { .compatible = "fsl,imx8mp-dsp", .data = &sof_of_imx8mp_desc}, 143 #endif 144 #if IS_ENABLED(CONFIG_SND_SOC_SOF_MT8195) 145 { .compatible = "mediatek,mt8195-dsp", .data = &sof_of_mt8195_desc}, 146 #endif 147 { } 148 }; 149 MODULE_DEVICE_TABLE(of, sof_of_ids); 150 151 /* DT driver definition */ 152 static struct platform_driver snd_sof_of_driver = { 153 .probe = sof_of_probe, 154 .remove = sof_of_remove, 155 .driver = { 156 .name = "sof-audio-of", 157 .pm = &sof_of_pm, 158 .of_match_table = sof_of_ids, 159 }, 160 }; 161 module_platform_driver(snd_sof_of_driver); 162 163 MODULE_LICENSE("Dual BSD/GPL"); 164