Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp254469pxb; Thu, 25 Feb 2021 01:22:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJzk2fAI6pBrwYWh/uU5ORAi8cJCyy3bnmjTm6Cd5YSnSWbewi8lHSX2HkwImx8FOqOLwXcn X-Received: by 2002:a17:906:c1ca:: with SMTP id bw10mr1780741ejb.510.1614244947032; Thu, 25 Feb 2021 01:22:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614244947; cv=none; d=google.com; s=arc-20160816; b=upPw1LKMBAlW28JP27faw0a8NeOICYk3CyPsN4270RTZdmUS+F8VqBVJ4hZfZjJ+sV pznyllBKJkuRoBe7zoURc8bPBkrwz0qQRxNt4cZ3MYzi+PmzeyhBlz3cS7M9L3Ijxmod P+qSOoDE5PtTCi5EhlhqS1SW1h8I52VFjSVVO9xtxGKUE6RmGa150AY4AyL89Y/EQ94e yQ8Qks9j3CFTYJG21uuKzyxj/jZoP36dZ+tpyjBXXb47Od9RhGeKN8Bk0aQZaRGUM/9U bxgdw0Ks7Ewd4v5IAopvmTyky/BJMUVTfNptFihu8vO9JsuCPEBnEa1ysX1fOvXZQBT7 tqmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :to:from; bh=uza+MUvXMX5kGptSCYxalFam0vmqVGI69Pk6xSsipBA=; b=tFNCYT4iGK4lGXZ8S2hqeW0DPKKrbgH4O3FEhyfS77lKq+/5sTvRpnxZceA7IPiJZb K8U47ItsHW9LrcHnqZrdAdJCyLKFrg1w3BCUbvOjrIu8Gmyb6Px8+TSX2XK37+MWhVAN 1ISnFzZ3rcJVX8xDB0gYHtOi7GGEX/1tFQT7QTzoq2s9lxK2wRXUzGOPs4HGa/t5ZY67 65rXu1H2yBpuctWe68MmvmqxsgLMvKRdiHMWDmnWG0BV5aa6REruK5h2e2+7+9RhsJav bAfv0H5GqgM6Kp5CYjW+WRQWauZnP0wNwGUiOE2uWnl/sZUkdiiiFM/RRx5FAvxCnfhG fpvA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u19si2860990edo.338.2021.02.25.01.22.03; Thu, 25 Feb 2021 01:22:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237003AbhBYDHN (ORCPT + 99 others); Wed, 24 Feb 2021 22:07:13 -0500 Received: from inva021.nxp.com ([92.121.34.21]:40600 "EHLO inva021.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236944AbhBYDGQ (ORCPT ); Wed, 24 Feb 2021 22:06:16 -0500 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 445C1200633; Thu, 25 Feb 2021 04:05:28 +0100 (CET) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 6BEF42006BD; Thu, 25 Feb 2021 04:05:21 +0100 (CET) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id ABF69402B7; Thu, 25 Feb 2021 04:05:13 +0100 (CET) From: Shengjiu Wang To: lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, timur@kernel.org, nicoleotsuka@gmail.com, Xiubo.Lee@gmail.com, festevam@gmail.com, linuxppc-dev@lists.ozlabs.org, robh+dt@kernel.org, devicetree@vger.kernel.org Subject: [PATCH v3 6/7] ASoC: imx-rpmsg: Add machine driver for audio base on rpmsg Date: Thu, 25 Feb 2021 10:52:42 +0800 Message-Id: <1614221563-26822-7-git-send-email-shengjiu.wang@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1614221563-26822-1-git-send-email-shengjiu.wang@nxp.com> References: <1614221563-26822-1-git-send-email-shengjiu.wang@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The platform device is not registered by device tree or cpu dai driver, it is registered by the rpmsg channel, So add a dedicated machine driver to handle this case. Signed-off-by: Shengjiu Wang --- sound/soc/fsl/Kconfig | 12 ++++ sound/soc/fsl/Makefile | 2 + sound/soc/fsl/imx-rpmsg.c | 148 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 162 insertions(+) create mode 100644 sound/soc/fsl/imx-rpmsg.c diff --git a/sound/soc/fsl/Kconfig b/sound/soc/fsl/Kconfig index 749c44fc0759..3557866d3fa2 100644 --- a/sound/soc/fsl/Kconfig +++ b/sound/soc/fsl/Kconfig @@ -334,6 +334,18 @@ config SND_SOC_IMX_HDMI Say Y if you want to add support for SoC audio on an i.MX board with IMX HDMI. +config SND_SOC_IMX_RPMSG + tristate "SoC Audio support for i.MX boards with rpmsg" + depends on RPMSG + select SND_SOC_IMX_PCM_RPMSG + select SND_SOC_IMX_AUDIO_RPMSG + select SND_SOC_FSL_RPMSG + help + SoC Audio support for i.MX boards with rpmsg. + There should be rpmsg devices defined in other core (M core) + Say Y if you want to add support for SoC audio on an i.MX board with + a rpmsg devices. + endif # SND_IMX_SOC endmenu diff --git a/sound/soc/fsl/Makefile b/sound/soc/fsl/Makefile index ce4f4324c3a2..f146ce464acd 100644 --- a/sound/soc/fsl/Makefile +++ b/sound/soc/fsl/Makefile @@ -70,6 +70,7 @@ snd-soc-imx-sgtl5000-objs := imx-sgtl5000.o snd-soc-imx-spdif-objs := imx-spdif.o snd-soc-imx-audmix-objs := imx-audmix.o snd-soc-imx-hdmi-objs := imx-hdmi.o +snd-soc-imx-rpmsg-objs := imx-rpmsg.o obj-$(CONFIG_SND_SOC_EUKREA_TLV320) += snd-soc-eukrea-tlv320.o obj-$(CONFIG_SND_SOC_IMX_ES8328) += snd-soc-imx-es8328.o @@ -77,3 +78,4 @@ obj-$(CONFIG_SND_SOC_IMX_SGTL5000) += snd-soc-imx-sgtl5000.o obj-$(CONFIG_SND_SOC_IMX_SPDIF) += snd-soc-imx-spdif.o obj-$(CONFIG_SND_SOC_IMX_AUDMIX) += snd-soc-imx-audmix.o obj-$(CONFIG_SND_SOC_IMX_HDMI) += snd-soc-imx-hdmi.o +obj-$(CONFIG_SND_SOC_IMX_RPMSG) += snd-soc-imx-rpmsg.o diff --git a/sound/soc/fsl/imx-rpmsg.c b/sound/soc/fsl/imx-rpmsg.c new file mode 100644 index 000000000000..a87dcbce4f36 --- /dev/null +++ b/sound/soc/fsl/imx-rpmsg.c @@ -0,0 +1,148 @@ +// SPDX-License-Identifier: GPL-2.0+ +// Copyright 2017-2020 NXP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "imx-pcm-rpmsg.h" + +struct imx_rpmsg { + struct snd_soc_dai_link dai; + struct snd_soc_card card; +}; + +static int imx_rpmsg_probe(struct platform_device *pdev) +{ + struct snd_soc_dai_link_component *dlc; + struct platform_device *cpu_pdev; + struct of_phandle_args args; + struct device_node *cpu_np; + struct imx_rpmsg *data; + int ret; + + dlc = devm_kzalloc(&pdev->dev, 3 * sizeof(*dlc), GFP_KERNEL); + if (!dlc) + return -ENOMEM; + + cpu_np = of_parse_phandle(pdev->dev.of_node, "audio-cpu", 0); + if (!cpu_np) { + dev_err(&pdev->dev, "cpu dai phandle missing or invalid\n"); + ret = -EINVAL; + goto fail; + } + + data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); + if (!data) { + ret = -ENOMEM; + goto fail; + } + + cpu_pdev = of_find_device_by_node(cpu_np); + if (!cpu_pdev) { + dev_err(&pdev->dev, "failed to find rpmsg platform device\n"); + ret = -EINVAL; + goto fail; + } + + ret = of_reserved_mem_device_init_by_idx(&pdev->dev, pdev->dev.of_node, 0); + if (ret) + dev_warn(&pdev->dev, "no reserved DMA memory\n"); + + 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 = "rpmsg hifi"; + data->dai.stream_name = "rpmsg hifi"; + data->dai.dai_fmt = SND_SOC_DAIFMT_I2S | + SND_SOC_DAIFMT_NB_NF | + SND_SOC_DAIFMT_CBS_CFS; + + /* Optional codec node */ + ret = of_parse_phandle_with_fixed_args(pdev->dev.of_node, + "audio-codec", 0, 0, &args); + if (ret) { + data->dai.codecs->dai_name = "snd-soc-dummy-dai"; + data->dai.codecs->name = "snd-soc-dummy"; + } else { + data->dai.codecs->of_node = args.np; + ret = snd_soc_get_dai_name(&args, &data->dai.codecs->dai_name); + if (ret) { + dev_err(&pdev->dev, "Unable to get codec_dai_name\n"); + goto fail; + } + } + + data->dai.cpus->dai_name = dev_name(&cpu_pdev->dev); + data->dai.platforms->name = IMX_PCM_DRV_NAME; + data->dai.playback_only = true; + data->dai.capture_only = true; + data->card.num_links = 1; + data->card.dai_link = &data->dai; + + if (of_property_read_bool(pdev->dev.of_node, "rpmsg-out")) + data->dai.capture_only = false; + + if (of_property_read_bool(pdev->dev.of_node, "rpmsg-in")) + data->dai.playback_only = false; + + if (data->dai.playback_only && data->dai.capture_only) { + dev_err(&pdev->dev, "no enabled rpmsg DAI link\n"); + ret = -EINVAL; + goto fail; + } + + data->card.dev = &pdev->dev; + data->card.owner = THIS_MODULE; + ret = snd_soc_of_parse_card_name(&data->card, "model"); + if (ret) + goto fail; + + platform_set_drvdata(pdev, &data->card); + snd_soc_card_set_drvdata(&data->card, data); + 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 fail; + } + +fail: + if (cpu_np) + of_node_put(cpu_np); + return ret; +} + +static const struct of_device_id imx_rpmsg_dt_ids[] = { + { .compatible = "fsl,imx-audio-rpmsg", }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, imx_rpmsg_dt_ids); + +static struct platform_driver imx_rpmsg_driver = { + .driver = { + .name = "imx-audio-rpmsg", + .owner = THIS_MODULE, + .pm = &snd_soc_pm_ops, + .of_match_table = imx_rpmsg_dt_ids, + }, + .probe = imx_rpmsg_probe, +}; +module_platform_driver(imx_rpmsg_driver); + +MODULE_DESCRIPTION("Freescale SoC Audio RPMSG Machine Driver"); +MODULE_AUTHOR("Shengjiu Wang "); +MODULE_ALIAS("platform:imx-rpmsg"); +MODULE_LICENSE("GPL v2"); -- 2.27.0