Pierre-Louis Bossart | e149ca2 | 2020-05-01 09:58:50 -0500 | [diff] [blame] | 1 | // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) |
Daniel Baluta | b9132b8 | 2019-08-21 11:47:29 -0500 | [diff] [blame] | 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/pm_runtime.h> |
| 11 | #include <sound/sof.h> |
| 12 | |
| 13 | #include "ops.h" |
| 14 | |
| 15 | extern struct snd_sof_dsp_ops sof_imx8_ops; |
Paul Olaru | f831ebf | 2020-02-10 11:58:16 +0200 | [diff] [blame] | 16 | extern struct snd_sof_dsp_ops sof_imx8x_ops; |
Daniel Baluta | 58825cc | 2020-04-09 10:18:31 +0300 | [diff] [blame] | 17 | extern struct snd_sof_dsp_ops sof_imx8m_ops; |
Daniel Baluta | b9132b8 | 2019-08-21 11:47:29 -0500 | [diff] [blame] | 18 | |
| 19 | /* platform specific devices */ |
| 20 | #if IS_ENABLED(CONFIG_SND_SOC_SOF_IMX8) |
| 21 | static struct sof_dev_desc sof_of_imx8qxp_desc = { |
| 22 | .default_fw_path = "imx/sof", |
| 23 | .default_tplg_path = "imx/sof-tplg", |
Paul Olaru | 9da9ace | 2020-02-10 11:58:14 +0200 | [diff] [blame] | 24 | .default_fw_filename = "sof-imx8x.ri", |
Daniel Baluta | b9132b8 | 2019-08-21 11:47:29 -0500 | [diff] [blame] | 25 | .nocodec_tplg_filename = "sof-imx8-nocodec.tplg", |
Paul Olaru | 9da9ace | 2020-02-10 11:58:14 +0200 | [diff] [blame] | 26 | .ops = &sof_imx8x_ops, |
Daniel Baluta | b9132b8 | 2019-08-21 11:47:29 -0500 | [diff] [blame] | 27 | }; |
Paul Olaru | f831ebf | 2020-02-10 11:58:16 +0200 | [diff] [blame] | 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 | }; |
Daniel Baluta | b9132b8 | 2019-08-21 11:47:29 -0500 | [diff] [blame] | 36 | #endif |
| 37 | |
Daniel Baluta | 58825cc | 2020-04-09 10:18:31 +0300 | [diff] [blame] | 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 | |
Daniel Baluta | b9132b8 | 2019-08-21 11:47:29 -0500 | [diff] [blame] | 48 | static const struct dev_pm_ops sof_of_pm = { |
Daniel Baluta | dd75980 | 2020-09-24 18:15:18 +0300 | [diff] [blame] | 49 | .prepare = snd_sof_prepare, |
| 50 | .complete = snd_sof_complete, |
Daniel Baluta | b9132b8 | 2019-08-21 11:47:29 -0500 | [diff] [blame] | 51 | SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume) |
| 52 | SET_RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume, |
| 53 | NULL) |
| 54 | }; |
| 55 | |
| 56 | static void sof_of_probe_complete(struct device *dev) |
| 57 | { |
| 58 | /* allow runtime_pm */ |
| 59 | pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS); |
| 60 | pm_runtime_use_autosuspend(dev); |
Daniel Baluta | 4fefc39 | 2020-09-24 18:15:17 +0300 | [diff] [blame] | 61 | pm_runtime_set_active(dev); |
Daniel Baluta | b9132b8 | 2019-08-21 11:47:29 -0500 | [diff] [blame] | 62 | pm_runtime_enable(dev); |
Daniel Baluta | 4fefc39 | 2020-09-24 18:15:17 +0300 | [diff] [blame] | 63 | |
| 64 | pm_runtime_mark_last_busy(dev); |
| 65 | pm_runtime_put_autosuspend(dev); |
Daniel Baluta | b9132b8 | 2019-08-21 11:47:29 -0500 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | static int sof_of_probe(struct platform_device *pdev) |
| 69 | { |
| 70 | struct device *dev = &pdev->dev; |
| 71 | const struct sof_dev_desc *desc; |
Daniel Baluta | b9132b8 | 2019-08-21 11:47:29 -0500 | [diff] [blame] | 72 | struct snd_sof_pdata *sof_pdata; |
Daniel Baluta | b9132b8 | 2019-08-21 11:47:29 -0500 | [diff] [blame] | 73 | |
| 74 | dev_info(&pdev->dev, "DT DSP detected"); |
| 75 | |
| 76 | sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL); |
| 77 | if (!sof_pdata) |
| 78 | return -ENOMEM; |
| 79 | |
| 80 | desc = device_get_match_data(dev); |
| 81 | if (!desc) |
| 82 | return -ENODEV; |
| 83 | |
Peter Ujfalusi | fd979ec | 2021-05-21 12:27:58 +0300 | [diff] [blame] | 84 | if (!desc->ops) { |
Daniel Baluta | b9132b8 | 2019-08-21 11:47:29 -0500 | [diff] [blame] | 85 | dev_err(dev, "error: no matching DT descriptor ops\n"); |
| 86 | return -ENODEV; |
| 87 | } |
| 88 | |
Daniel Baluta | b9132b8 | 2019-08-21 11:47:29 -0500 | [diff] [blame] | 89 | sof_pdata->desc = desc; |
| 90 | sof_pdata->dev = &pdev->dev; |
Daniel Baluta | 285880a2 | 2019-12-04 15:15:53 -0600 | [diff] [blame] | 91 | sof_pdata->fw_filename = desc->default_fw_filename; |
Daniel Baluta | b9132b8 | 2019-08-21 11:47:29 -0500 | [diff] [blame] | 92 | |
| 93 | /* TODO: read alternate fw and tplg filenames from DT */ |
| 94 | sof_pdata->fw_filename_prefix = sof_pdata->desc->default_fw_path; |
| 95 | sof_pdata->tplg_filename_prefix = sof_pdata->desc->default_tplg_path; |
| 96 | |
Peter Ujfalusi | 4d1284c | 2021-04-09 15:09:59 -0700 | [diff] [blame] | 97 | /* set callback to be called on successful device probe to enable runtime_pm */ |
Daniel Baluta | b9132b8 | 2019-08-21 11:47:29 -0500 | [diff] [blame] | 98 | sof_pdata->sof_probe_complete = sof_of_probe_complete; |
Daniel Baluta | b9132b8 | 2019-08-21 11:47:29 -0500 | [diff] [blame] | 99 | |
Peter Ujfalusi | 4d1284c | 2021-04-09 15:09:59 -0700 | [diff] [blame] | 100 | /* call sof helper for DSP hardware probe */ |
| 101 | return snd_sof_device_probe(dev, sof_pdata); |
Daniel Baluta | b9132b8 | 2019-08-21 11:47:29 -0500 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | static int sof_of_remove(struct platform_device *pdev) |
| 105 | { |
| 106 | pm_runtime_disable(&pdev->dev); |
| 107 | |
| 108 | /* call sof helper for DSP hardware remove */ |
| 109 | snd_sof_device_remove(&pdev->dev); |
| 110 | |
| 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | static const struct of_device_id sof_of_ids[] = { |
| 115 | #if IS_ENABLED(CONFIG_SND_SOC_SOF_IMX8) |
| 116 | { .compatible = "fsl,imx8qxp-dsp", .data = &sof_of_imx8qxp_desc}, |
Paul Olaru | f831ebf | 2020-02-10 11:58:16 +0200 | [diff] [blame] | 117 | { .compatible = "fsl,imx8qm-dsp", .data = &sof_of_imx8qm_desc}, |
Daniel Baluta | b9132b8 | 2019-08-21 11:47:29 -0500 | [diff] [blame] | 118 | #endif |
Daniel Baluta | 58825cc | 2020-04-09 10:18:31 +0300 | [diff] [blame] | 119 | #if IS_ENABLED(CONFIG_SND_SOC_SOF_IMX8M) |
| 120 | { .compatible = "fsl,imx8mp-dsp", .data = &sof_of_imx8mp_desc}, |
| 121 | #endif |
Daniel Baluta | b9132b8 | 2019-08-21 11:47:29 -0500 | [diff] [blame] | 122 | { } |
| 123 | }; |
| 124 | MODULE_DEVICE_TABLE(of, sof_of_ids); |
| 125 | |
| 126 | /* DT driver definition */ |
| 127 | static struct platform_driver snd_sof_of_driver = { |
| 128 | .probe = sof_of_probe, |
| 129 | .remove = sof_of_remove, |
| 130 | .driver = { |
| 131 | .name = "sof-audio-of", |
| 132 | .pm = &sof_of_pm, |
| 133 | .of_match_table = sof_of_ids, |
| 134 | }, |
| 135 | }; |
| 136 | module_platform_driver(snd_sof_of_driver); |
| 137 | |
| 138 | MODULE_LICENSE("Dual BSD/GPL"); |