^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) // Copyright 2019 NXP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) // Author: Daniel Baluta <daniel.baluta@nxp.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/firmware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/pm_runtime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <sound/sof.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "ops.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) extern struct snd_sof_dsp_ops sof_imx8_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) extern struct snd_sof_dsp_ops sof_imx8x_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) extern struct snd_sof_dsp_ops sof_imx8m_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) /* platform specific devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #if IS_ENABLED(CONFIG_SND_SOC_SOF_IMX8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) static struct sof_dev_desc sof_of_imx8qxp_desc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) .default_fw_path = "imx/sof",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) .default_tplg_path = "imx/sof-tplg",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) .default_fw_filename = "sof-imx8x.ri",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) .nocodec_tplg_filename = "sof-imx8-nocodec.tplg",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) .ops = &sof_imx8x_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static struct sof_dev_desc sof_of_imx8qm_desc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) .default_fw_path = "imx/sof",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) .default_tplg_path = "imx/sof-tplg",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) .default_fw_filename = "sof-imx8.ri",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) .nocodec_tplg_filename = "sof-imx8-nocodec.tplg",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) .ops = &sof_imx8_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #if IS_ENABLED(CONFIG_SND_SOC_SOF_IMX8M)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static struct sof_dev_desc sof_of_imx8mp_desc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) .default_fw_path = "imx/sof",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) .default_tplg_path = "imx/sof-tplg",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) .default_fw_filename = "sof-imx8m.ri",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) .nocodec_tplg_filename = "sof-imx8-nocodec.tplg",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) .ops = &sof_imx8m_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static const struct dev_pm_ops sof_of_pm = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) .prepare = snd_sof_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) .complete = snd_sof_complete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) SET_RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static void sof_of_probe_complete(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) /* allow runtime_pm */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) pm_runtime_use_autosuspend(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) pm_runtime_set_active(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) pm_runtime_enable(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) pm_runtime_mark_last_busy(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) pm_runtime_put_autosuspend(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) static int sof_of_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) const struct sof_dev_desc *desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct snd_sof_pdata *sof_pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) const struct snd_sof_dsp_ops *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) dev_info(&pdev->dev, "DT DSP detected");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) if (!sof_pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) desc = device_get_match_data(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) if (!desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) /* get ops for platform */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) ops = desc->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) if (!ops) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) dev_err(dev, "error: no matching DT descriptor ops\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) sof_pdata->desc = desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) sof_pdata->dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) sof_pdata->fw_filename = desc->default_fw_filename;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) /* TODO: read alternate fw and tplg filenames from DT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) sof_pdata->fw_filename_prefix = sof_pdata->desc->default_fw_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) sof_pdata->tplg_filename_prefix = sof_pdata->desc->default_tplg_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #if IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) /* set callback to enable runtime_pm */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) sof_pdata->sof_probe_complete = sof_of_probe_complete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /* call sof helper for DSP hardware probe */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) ret = snd_sof_device_probe(dev, sof_pdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) dev_err(dev, "error: failed to probe DSP hardware\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) #if !IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) sof_of_probe_complete(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static int sof_of_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) pm_runtime_disable(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /* call sof helper for DSP hardware remove */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) snd_sof_device_remove(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static const struct of_device_id sof_of_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) #if IS_ENABLED(CONFIG_SND_SOC_SOF_IMX8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) { .compatible = "fsl,imx8qxp-dsp", .data = &sof_of_imx8qxp_desc},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) { .compatible = "fsl,imx8qm-dsp", .data = &sof_of_imx8qm_desc},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) #if IS_ENABLED(CONFIG_SND_SOC_SOF_IMX8M)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) { .compatible = "fsl,imx8mp-dsp", .data = &sof_of_imx8mp_desc},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) MODULE_DEVICE_TABLE(of, sof_of_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) /* DT driver definition */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static struct platform_driver snd_sof_of_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) .probe = sof_of_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) .remove = sof_of_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) .name = "sof-audio-of",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) .pm = &sof_of_pm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) .of_match_table = sof_of_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) module_platform_driver(snd_sof_of_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) MODULE_LICENSE("Dual BSD/GPL");