Skip to content

Commit b9132b8

Browse files
dbalutabroonie
authored andcommitted
ASoC: SOF: Add OF DSP device support
Add support for device tree based SOF DSP devices. Signed-off-by: Daniel Baluta <[email protected]> Signed-off-by: Pierre-Louis Bossart <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 7db2f2d commit b9132b8

File tree

3 files changed

+156
-0
lines changed

3 files changed

+156
-0
lines changed

sound/soc/sof/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ config SND_SOC_SOF_ACPI
3636
Say Y if you need this option
3737
If unsure select "N".
3838

39+
config SND_SOC_SOF_OF
40+
tristate "SOF OF enumeration support"
41+
depends on OF || COMPILE_TEST
42+
select SND_SOC_SOF
43+
select SND_SOC_SOF_OPTIONS
44+
help
45+
This adds support for Device Tree enumeration. This option is
46+
required to enable i.MX8 devices.
47+
Say Y if you need this option. If unsure select "N".
48+
3949
config SND_SOC_SOF_OPTIONS
4050
tristate
4151
help

sound/soc/sof/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ snd-sof-objs := core.o ops.o loader.o ipc.o pcm.o pm.o debug.o topology.o\
55

66
snd-sof-pci-objs := sof-pci-dev.o
77
snd-sof-acpi-objs := sof-acpi-dev.o
8+
snd-sof-of-objs := sof-of-dev.o
9+
810
snd-sof-nocodec-objs := nocodec.o
911

1012
obj-$(CONFIG_SND_SOC_SOF) += snd-sof.o
1113
obj-$(CONFIG_SND_SOC_SOF_NOCODEC) += snd-sof-nocodec.o
1214

1315

1416
obj-$(CONFIG_SND_SOC_SOF_ACPI) += snd-sof-acpi.o
17+
obj-$(CONFIG_SND_SOC_SOF_OF) += snd-sof-of.o
1518
obj-$(CONFIG_SND_SOC_SOF_PCI) += snd-sof-pci.o
1619

1720
obj-$(CONFIG_SND_SOC_SOF_INTEL_TOPLEVEL) += intel/

sound/soc/sof/sof-of-dev.c

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
// SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
2+
//
3+
// Copyright 2019 NXP
4+
//
5+
// Author: Daniel Baluta <[email protected]>
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+
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+
.nocodec_fw_filename = "sof-imx8.ri",
23+
.nocodec_tplg_filename = "sof-imx8-nocodec.tplg",
24+
.ops = &sof_imx8_ops,
25+
};
26+
#endif
27+
28+
static const struct dev_pm_ops sof_of_pm = {
29+
SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume)
30+
SET_RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume,
31+
NULL)
32+
};
33+
34+
static void sof_of_probe_complete(struct device *dev)
35+
{
36+
/* allow runtime_pm */
37+
pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS);
38+
pm_runtime_use_autosuspend(dev);
39+
pm_runtime_enable(dev);
40+
}
41+
42+
static int sof_of_probe(struct platform_device *pdev)
43+
{
44+
struct device *dev = &pdev->dev;
45+
const struct sof_dev_desc *desc;
46+
/*TODO: create a generic snd_soc_xxx_mach */
47+
struct snd_soc_acpi_mach *mach;
48+
struct snd_sof_pdata *sof_pdata;
49+
const struct snd_sof_dsp_ops *ops;
50+
int ret;
51+
52+
dev_info(&pdev->dev, "DT DSP detected");
53+
54+
sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL);
55+
if (!sof_pdata)
56+
return -ENOMEM;
57+
58+
desc = device_get_match_data(dev);
59+
if (!desc)
60+
return -ENODEV;
61+
62+
/* get ops for platform */
63+
ops = desc->ops;
64+
if (!ops) {
65+
dev_err(dev, "error: no matching DT descriptor ops\n");
66+
return -ENODEV;
67+
}
68+
69+
#if IS_ENABLED(CONFIG_SND_SOC_SOF_FORCE_NOCODEC_MODE)
70+
/* force nocodec mode */
71+
dev_warn(dev, "Force to use nocodec mode\n");
72+
mach = devm_kzalloc(dev, sizeof(*mach), GFP_KERNEL);
73+
if (!mach)
74+
return -ENOMEM;
75+
ret = sof_nocodec_setup(dev, sof_pdata, mach, desc, ops);
76+
if (ret < 0)
77+
return ret;
78+
#else
79+
/* TODO: implement case where we actually have a codec */
80+
return -ENODEV;
81+
#endif
82+
83+
if (mach)
84+
mach->mach_params.platform = dev_name(dev);
85+
86+
sof_pdata->machine = mach;
87+
sof_pdata->desc = desc;
88+
sof_pdata->dev = &pdev->dev;
89+
sof_pdata->platform = dev_name(dev);
90+
91+
/* TODO: read alternate fw and tplg filenames from DT */
92+
sof_pdata->fw_filename_prefix = sof_pdata->desc->default_fw_path;
93+
sof_pdata->tplg_filename_prefix = sof_pdata->desc->default_tplg_path;
94+
95+
#if IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)
96+
/* set callback to enable runtime_pm */
97+
sof_pdata->sof_probe_complete = sof_of_probe_complete;
98+
#endif
99+
/* call sof helper for DSP hardware probe */
100+
ret = snd_sof_device_probe(dev, sof_pdata);
101+
if (ret) {
102+
dev_err(dev, "error: failed to probe DSP hardware\n");
103+
return ret;
104+
}
105+
106+
#if !IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)
107+
sof_of_probe_complete(dev);
108+
#endif
109+
110+
return ret;
111+
}
112+
113+
static int sof_of_remove(struct platform_device *pdev)
114+
{
115+
pm_runtime_disable(&pdev->dev);
116+
117+
/* call sof helper for DSP hardware remove */
118+
snd_sof_device_remove(&pdev->dev);
119+
120+
return 0;
121+
}
122+
123+
static const struct of_device_id sof_of_ids[] = {
124+
#if IS_ENABLED(CONFIG_SND_SOC_SOF_IMX8)
125+
{ .compatible = "fsl,imx8qxp-dsp", .data = &sof_of_imx8qxp_desc},
126+
#endif
127+
{ }
128+
};
129+
MODULE_DEVICE_TABLE(of, sof_of_ids);
130+
131+
/* DT driver definition */
132+
static struct platform_driver snd_sof_of_driver = {
133+
.probe = sof_of_probe,
134+
.remove = sof_of_remove,
135+
.driver = {
136+
.name = "sof-audio-of",
137+
.pm = &sof_of_pm,
138+
.of_match_table = sof_of_ids,
139+
},
140+
};
141+
module_platform_driver(snd_sof_of_driver);
142+
143+
MODULE_LICENSE("Dual BSD/GPL");

0 commit comments

Comments
 (0)