1 // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
5 // Author: Daniel Baluta <daniel.baluta@nxp.com>
8 #include <linux/firmware.h>
9 #include <linux/module.h>
10 #include <linux/pm_runtime.h>
11 #include <sound/sof.h>
15 extern struct snd_sof_dsp_ops sof_imx8_ops;
17 /* platform specific devices */
18 #if IS_ENABLED(CONFIG_SND_SOC_SOF_IMX8)
19 static struct sof_dev_desc sof_of_imx8qxp_desc = {
20 .default_fw_path = "imx/sof",
21 .default_tplg_path = "imx/sof-tplg",
22 .default_fw_filename = "sof-imx8.ri",
23 .nocodec_fw_filename = "sof-imx8.ri",
24 .nocodec_tplg_filename = "sof-imx8-nocodec.tplg",
29 static const struct dev_pm_ops sof_of_pm = {
30 SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume)
31 SET_RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume,
35 static void sof_of_probe_complete(struct device *dev)
37 /* allow runtime_pm */
38 pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS);
39 pm_runtime_use_autosuspend(dev);
40 pm_runtime_enable(dev);
43 static int sof_of_probe(struct platform_device *pdev)
45 struct device *dev = &pdev->dev;
46 const struct sof_dev_desc *desc;
47 struct snd_sof_pdata *sof_pdata;
48 const struct snd_sof_dsp_ops *ops;
51 dev_info(&pdev->dev, "DT DSP detected");
53 sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL);
57 desc = device_get_match_data(dev);
61 /* get ops for platform */
64 dev_err(dev, "error: no matching DT descriptor ops\n");
68 sof_pdata->desc = desc;
69 sof_pdata->dev = &pdev->dev;
70 sof_pdata->fw_filename = desc->default_fw_filename;
72 /* TODO: read alternate fw and tplg filenames from DT */
73 sof_pdata->fw_filename_prefix = sof_pdata->desc->default_fw_path;
74 sof_pdata->tplg_filename_prefix = sof_pdata->desc->default_tplg_path;
76 #if IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)
77 /* set callback to enable runtime_pm */
78 sof_pdata->sof_probe_complete = sof_of_probe_complete;
80 /* call sof helper for DSP hardware probe */
81 ret = snd_sof_device_probe(dev, sof_pdata);
83 dev_err(dev, "error: failed to probe DSP hardware\n");
87 #if !IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)
88 sof_of_probe_complete(dev);
94 static int sof_of_remove(struct platform_device *pdev)
96 pm_runtime_disable(&pdev->dev);
98 /* call sof helper for DSP hardware remove */
99 snd_sof_device_remove(&pdev->dev);
104 static const struct of_device_id sof_of_ids[] = {
105 #if IS_ENABLED(CONFIG_SND_SOC_SOF_IMX8)
106 { .compatible = "fsl,imx8qxp-dsp", .data = &sof_of_imx8qxp_desc},
110 MODULE_DEVICE_TABLE(of, sof_of_ids);
112 /* DT driver definition */
113 static struct platform_driver snd_sof_of_driver = {
114 .probe = sof_of_probe,
115 .remove = sof_of_remove,
117 .name = "sof-audio-of",
119 .of_match_table = sof_of_ids,
122 module_platform_driver(snd_sof_of_driver);
124 MODULE_LICENSE("Dual BSD/GPL");