summaryrefslogtreecommitdiff
path: root/sound/soc/fsl/imx-xcvr.c
diff options
context:
space:
mode:
authorViorel Suman <viorel.suman@nxp.com>2020-02-13 11:58:56 +0200
committerViorel Suman <viorel.suman@nxp.com>2020-02-20 12:58:12 +0200
commitbf133eb85426e72e3e4342c0c0a76383bd940d97 (patch)
treea4da48fcc2b22b5bb926a9e48093e5d9472baeca /sound/soc/fsl/imx-xcvr.c
parentc7aa3b9266707af7ef4b01406d487bec5648ab7e (diff)
MLK-23313-4: ASoC: fsl: Add Audio XCVR machine driver
This patch implements Audio XCVR machine driver for NXP iMX8 SOCs. Signed-off-by: Viorel Suman <viorel.suman@nxp.com> Reviewed-by: Shengjiu Wang <shengjiu.wang@nxp.com>
Diffstat (limited to 'sound/soc/fsl/imx-xcvr.c')
-rw-r--r--sound/soc/fsl/imx-xcvr.c101
1 files changed, 101 insertions, 0 deletions
diff --git a/sound/soc/fsl/imx-xcvr.c b/sound/soc/fsl/imx-xcvr.c
new file mode 100644
index 000000000000..d7731bcadd85
--- /dev/null
+++ b/sound/soc/fsl/imx-xcvr.c
@@ -0,0 +1,101 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright 2019 NXP
+
+#include <linux/module.h>
+#include <linux/of_platform.h>
+#include <sound/soc.h>
+#include "fsl_xcvr.h"
+
+struct imx_xcvr_data {
+ struct snd_soc_dai_link dai;
+ struct snd_soc_card card;
+};
+
+static int imx_xcvr_audio_probe(struct platform_device *pdev)
+{
+ struct device_node *xcvr_np, *np = pdev->dev.of_node;
+ struct snd_soc_dai_link_component *dlc;
+ struct snd_soc_dai *cpu_dai, *codec_dai;
+ struct imx_xcvr_data *data;
+ int ret = 0;
+
+ xcvr_np = of_parse_phandle(np, "cpu-dai", 0);
+ if (!xcvr_np) {
+ dev_err(&pdev->dev, "failed to find cpu-dai\n");
+ ret = -EINVAL;
+ goto end;
+ }
+
+ data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
+ if (!data) {
+ ret = -ENOMEM;
+ goto end;
+ }
+
+ dlc = devm_kzalloc(&pdev->dev, 3 * sizeof(*dlc), GFP_KERNEL);
+ if (!dlc) {
+ ret = -ENOMEM;
+ goto end;
+ }
+
+ data->dai.cpus = &dlc[0];
+ data->dai.num_cpus = 1;
+ data->dai.platforms = &dlc[1];
+ data->dai.num_platforms = 1;
+ data->dai.codecs = &dlc[2];
+ data->dai.num_codecs = 1;
+
+ data->dai.name = "XCVR PCM";
+ data->dai.stream_name = "XCVR PCM";
+ data->dai.codecs->dai_name = "snd-soc-dummy-dai";
+ data->dai.codecs->name = "snd-soc-dummy";
+ data->dai.cpus->of_node = xcvr_np;
+ data->dai.platforms->of_node = xcvr_np;
+
+ data->card.dev = &pdev->dev;
+ data->card.dai_link = &data->dai;
+ data->card.num_links = 1;
+ data->card.owner = THIS_MODULE;
+
+ cpu_dai = snd_soc_find_dai(data->dai.cpus);
+ codec_dai = snd_soc_find_dai(data->dai.codecs);
+ if (cpu_dai && codec_dai) {
+ codec_dai->driver->playback = cpu_dai->driver->playback;
+ codec_dai->driver->capture = cpu_dai->driver->capture;
+ }
+
+ ret = snd_soc_of_parse_card_name(&data->card, "model");
+ if (ret)
+ goto end;
+
+ ret = devm_snd_soc_register_card(&pdev->dev, &data->card);
+ if (ret) {
+ dev_err(&pdev->dev, "snd_soc_register_card failed: %d\n", ret);
+ goto end;
+ }
+end:
+ of_node_put(xcvr_np);
+ return ret;
+}
+
+static const struct of_device_id imx_xcvr_dt_ids[] = {
+ { .compatible = "fsl,imx-audio-xcvr", },
+ { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, imx_xcvr_dt_ids);
+
+static struct platform_driver imx_xcvr_driver = {
+ .driver = {
+ .name = "imx-xcvr",
+ .pm = &snd_soc_pm_ops,
+ .of_match_table = imx_xcvr_dt_ids,
+ },
+ .probe = imx_xcvr_audio_probe,
+};
+
+module_platform_driver(imx_xcvr_driver);
+
+MODULE_AUTHOR("Viorel Suman <viorel.suman@nxp.com>");
+MODULE_DESCRIPTION("NXP Audio Transceiver (XCVR) machine driver");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:imx-xcvr");