From bf133eb85426e72e3e4342c0c0a76383bd940d97 Mon Sep 17 00:00:00 2001 From: Viorel Suman Date: Thu, 13 Feb 2020 11:58:56 +0200 Subject: 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 Reviewed-by: Shengjiu Wang --- sound/soc/fsl/imx-xcvr.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 sound/soc/fsl/imx-xcvr.c (limited to 'sound/soc/fsl/imx-xcvr.c') 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 +#include +#include +#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 "); +MODULE_DESCRIPTION("NXP Audio Transceiver (XCVR) machine driver"); +MODULE_LICENSE("GPL v2"); +MODULE_ALIAS("platform:imx-xcvr"); -- cgit v1.2.3