ASoC: SOF: Add i.MX8QM device descriptor
[linux-2.6-microblaze.git] / sound / soc / sof / sof-of-dev.c
1 // SPDX-License-Identifier: (GPL-2.0 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/pm_runtime.h>
11 #include <sound/sof.h>
12
13 #include "ops.h"
14
15 extern struct snd_sof_dsp_ops sof_imx8_ops;
16 extern struct snd_sof_dsp_ops sof_imx8x_ops;
17
18 /* platform specific devices */
19 #if IS_ENABLED(CONFIG_SND_SOC_SOF_IMX8)
20 static struct sof_dev_desc sof_of_imx8qxp_desc = {
21         .default_fw_path = "imx/sof",
22         .default_tplg_path = "imx/sof-tplg",
23         .default_fw_filename = "sof-imx8x.ri",
24         .nocodec_tplg_filename = "sof-imx8-nocodec.tplg",
25         .ops = &sof_imx8x_ops,
26 };
27
28 static struct sof_dev_desc sof_of_imx8qm_desc = {
29         .default_fw_path = "imx/sof",
30         .default_tplg_path = "imx/sof-tplg",
31         .default_fw_filename = "sof-imx8.ri",
32         .nocodec_tplg_filename = "sof-imx8-nocodec.tplg",
33         .ops = &sof_imx8_ops,
34 };
35 #endif
36
37 static const struct dev_pm_ops sof_of_pm = {
38         SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume)
39         SET_RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume,
40                            NULL)
41 };
42
43 static void sof_of_probe_complete(struct device *dev)
44 {
45         /* allow runtime_pm */
46         pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS);
47         pm_runtime_use_autosuspend(dev);
48         pm_runtime_enable(dev);
49 }
50
51 static int sof_of_probe(struct platform_device *pdev)
52 {
53         struct device *dev = &pdev->dev;
54         const struct sof_dev_desc *desc;
55         struct snd_sof_pdata *sof_pdata;
56         const struct snd_sof_dsp_ops *ops;
57         int ret;
58
59         dev_info(&pdev->dev, "DT DSP detected");
60
61         sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL);
62         if (!sof_pdata)
63                 return -ENOMEM;
64
65         desc = device_get_match_data(dev);
66         if (!desc)
67                 return -ENODEV;
68
69         /* get ops for platform */
70         ops = desc->ops;
71         if (!ops) {
72                 dev_err(dev, "error: no matching DT descriptor ops\n");
73                 return -ENODEV;
74         }
75
76         sof_pdata->desc = desc;
77         sof_pdata->dev = &pdev->dev;
78         sof_pdata->fw_filename = desc->default_fw_filename;
79
80         /* TODO: read alternate fw and tplg filenames from DT */
81         sof_pdata->fw_filename_prefix = sof_pdata->desc->default_fw_path;
82         sof_pdata->tplg_filename_prefix = sof_pdata->desc->default_tplg_path;
83
84 #if IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)
85         /* set callback to enable runtime_pm */
86         sof_pdata->sof_probe_complete = sof_of_probe_complete;
87 #endif
88          /* call sof helper for DSP hardware probe */
89         ret = snd_sof_device_probe(dev, sof_pdata);
90         if (ret) {
91                 dev_err(dev, "error: failed to probe DSP hardware\n");
92                 return ret;
93         }
94
95 #if !IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)
96         sof_of_probe_complete(dev);
97 #endif
98
99         return ret;
100 }
101
102 static int sof_of_remove(struct platform_device *pdev)
103 {
104         pm_runtime_disable(&pdev->dev);
105
106         /* call sof helper for DSP hardware remove */
107         snd_sof_device_remove(&pdev->dev);
108
109         return 0;
110 }
111
112 static const struct of_device_id sof_of_ids[] = {
113 #if IS_ENABLED(CONFIG_SND_SOC_SOF_IMX8)
114         { .compatible = "fsl,imx8qxp-dsp", .data = &sof_of_imx8qxp_desc},
115         { .compatible = "fsl,imx8qm-dsp", .data = &sof_of_imx8qm_desc},
116 #endif
117         { }
118 };
119 MODULE_DEVICE_TABLE(of, sof_of_ids);
120
121 /* DT driver definition */
122 static struct platform_driver snd_sof_of_driver = {
123         .probe = sof_of_probe,
124         .remove = sof_of_remove,
125         .driver = {
126                 .name = "sof-audio-of",
127                 .pm = &sof_of_pm,
128                 .of_match_table = sof_of_ids,
129         },
130 };
131 module_platform_driver(snd_sof_of_driver);
132
133 MODULE_LICENSE("Dual BSD/GPL");