From patchwork Tue Aug 3 12:54:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 490943 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:396:0:0:0:0 with SMTP id y22csp621779jap; Tue, 3 Aug 2021 05:54:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxasod6vdPeTFawzgy8pYD4n+8SHyNa/J70tDiyN973ncj6qKsNHX47xzcemz5+tdWOADdN X-Received: by 2002:aa7:c597:: with SMTP id g23mr25131395edq.340.1627995287195; Tue, 03 Aug 2021 05:54:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627995287; cv=none; d=google.com; s=arc-20160816; b=kNhTBRARqlQhKAE9Z5dafQ6ou/hLaaZCwWMWuP2sWLyMkLcr7375H4AYjx5Mn4AHWI USba5T653sO3zLMM5ToAVCsC8EhfPOTQBsGKrNUsnrU0zAHMCsHDxLWIxMGkCBfra23x 03OwIilbYg7F1YxnRNherfTexgup6gv+mNMH/zDWu4CyiNpUBumbR9n5sRNrrsNuDK+k uMMdeENzqa7NEaHcznqrdCM/LBp1/01lbAZ9MZYXWaJpFCUcpnShZ7D/Wpy7nfLIUvs5 Y9XYr1HJreYRgJ6SCrxWBqzvajY03Z2Qrg7XDbK3x1xGP2ca+/lY1pxOPOP7W7jsjJCZ vj5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0RCHKhb5XKSwg5gp8+2VEg2OAC9jcZJFGIHFD29kOtw=; b=x0kCV7jfRSQLHIH1Zk2mZuQHEg6Lffrsknw2dcllmmlQPxCBVr4ZSGv7o357M+5QtI TEopKrpiwZhObYFGmlvjiRzRV9b930sRMVPkmnaXEMSc8K4CurnMfZM3rAepBu0R5/if 6KOCkkFAUTi/87XxjW/4Tn/cVSzWASq9jTrTX7RjDa+9enhS8WhwAi9h1rtBQEm5b1yJ /KEwJaeS9Z9hYwtn6bbJtdjeN19W6IgR8MKDuq8YynQn0SGth9S+CgiKrzawrppITg69 CgK+PeserFFygWXuLPILCxC3zOyXdu7wq2lHWYoviQ7gql2V7EijGlunVeg5g6EvCO6O dRjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cE1C7WjV; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h14si13392628edq.2.2021.08.03.05.54.47; Tue, 03 Aug 2021 05:54:47 -0700 (PDT) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cE1C7WjV; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236028AbhHCMy5 (ORCPT + 7 others); Tue, 3 Aug 2021 08:54:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236065AbhHCMy4 (ORCPT ); Tue, 3 Aug 2021 08:54:56 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D28B0C061757 for ; Tue, 3 Aug 2021 05:54:44 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id m12so20421384wru.12 for ; Tue, 03 Aug 2021 05:54:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0RCHKhb5XKSwg5gp8+2VEg2OAC9jcZJFGIHFD29kOtw=; b=cE1C7WjVqLXWrSc8dTQ+n35ossfhgbDQj9T2kgKqpucS5pmKZHDqX5azkXfle5yyEH /HchvDWyY1lYF+IHDyO3Raz0+ffNqOEOfxtLx/FV7NdImEez84gaUcxNL3Sg+Wrzw5n1 vv8KnZntZLx3dNzifKRQ/j7iXEt7f5ko88XReGl1ndh2mvzTkLGgkAQ7Zdb0dy8JMD8G 1jqki2oaak5oR7uiOLvvOoUYFlOIchPonAGvSbBHjQyPsEog/DoL7wpjQtXALqCDP57C Ai57UYYuQorlgxXpu7vgFmdsFx4sjoBCnh2oF/X/8MP9dWVzSIcq7a/0br7dZFTy/jBI HtIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0RCHKhb5XKSwg5gp8+2VEg2OAC9jcZJFGIHFD29kOtw=; b=JmhvgGsuD2i8p0EiqLH1xzZgiT1lURdxothH3TJ05GTTwmVf56jC1F1v/Zhqkl+7bR mFUdID9lqUuM1jPTuRdfgy/KYMxWpFoYgnWPtL2riHm2UYPnemJsQ4PeOasbDF76UXRL U0gJopOAQ+gSmcfPx4CnXXiEQPqvCHhLHn74vNrI5NZ+BMiPOnhnZPSN/bL3smdNQVDs 5eV6ZciOW583JdD3lDWk/OQQdY00V6QPmNP/V9yZ41nS6/k8TH6sxQWnEPc+0DaekTol 7f33bKuLKHI74yL+WYSI0n5mZnTKMnAY+Yu+FuMxmSt7o8e2wOSi41wI3qW181H4C2Gk 348g== X-Gm-Message-State: AOAM531+W3YRA4jDymIDovh1L2dFr6Nc1JK6lqhwm0p3oZlPNJWLvvts A3vk42kgk5bdRUYlICCtE+AwLQ== X-Received: by 2002:a5d:6a89:: with SMTP id s9mr23305467wru.309.1627995283428; Tue, 03 Aug 2021 05:54:43 -0700 (PDT) Received: from srini-hackbox.lan (cpc86377-aztw32-2-0-cust226.18-1.cable.virginm.net. [92.233.226.227]) by smtp.gmail.com with ESMTPSA id h14sm14695574wrp.55.2021.08.03.05.54.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 05:54:43 -0700 (PDT) From: Srinivas Kandagatla To: bjorn.andersson@linaro.org, broonie@kernel.org, robh@kernel.org Cc: plai@codeaurora.org, tiwai@suse.de, devicetree@vger.kernel.org, perex@perex.cz, alsa-devel@alsa-project.org, lgirdwood@gmail.com, bgoswami@codeaurora.org, Srinivas Kandagatla Subject: [PATCH v3 18/20] ASoC: qdsp6: audioreach: add bedai support Date: Tue, 3 Aug 2021 13:54:09 +0100 Message-Id: <20210803125411.28066-19-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210803125411.28066-1-srinivas.kandagatla@linaro.org> References: <20210803125411.28066-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Signed-off-by: Srinivas Kandagatla --- sound/soc/qcom/Kconfig | 4 + sound/soc/qcom/qdsp6/Makefile | 2 + sound/soc/qcom/qdsp6/q6apm-bedai.c | 266 +++++++++++++++++++++++++++++ 3 files changed, 272 insertions(+) create mode 100644 sound/soc/qcom/qdsp6/q6apm-bedai.c -- 2.21.0 diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig index 4f0fbf2032cc..a2540a28b482 100644 --- a/sound/soc/qcom/Kconfig +++ b/sound/soc/qcom/Kconfig @@ -106,11 +106,15 @@ config SND_SOC_QDSP6 config SND_SOC_QDSP6_APM_DAI tristate +config SND_SOC_QDSP6_APM_BEDAI + tristate + config SND_SOC_QDSP6_AUDIOREACH tristate "SoC ALSA audio drives for Qualcomm QDSP AUDIOREACH Framework" depends on QCOM_GPR select SND_SOC_TOPOLOGY select SND_SOC_QDSP6_APM_DAI + select SND_SOC_QDSP6_APM_BEDAI help To add support for Qualcomm QDSP6 AudioReach Audio Framework. This will enable sound soc platform specific audio drivers. diff --git a/sound/soc/qcom/qdsp6/Makefile b/sound/soc/qcom/qdsp6/Makefile index 3e93911d04fa..d62f85b3f18a 100644 --- a/sound/soc/qcom/qdsp6/Makefile +++ b/sound/soc/qcom/qdsp6/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only snd-ar-objs := audioreach.o q6apm.o topology.o snd-apm-dai-objs := q6apm-dai.o +snd-apm-bedai-objs := q6dsp-audio-ports.o q6apm-bedai.o snd-afe-dai-objs += q6dsp-audio-ports.o q6afe-dai.o snd-afe-clks-objs := q6dsp-audio-clocks.o q6afe-clocks.o @@ -17,3 +18,4 @@ obj-$(CONFIG_SND_SOC_QDSP6_ASM_DAI) += q6asm-dai.o obj-$(CONFIG_SND_SOC_QDSP6_AUDIOREACH) += snd-ar.o obj-$(CONFIG_SND_SOC_QDSP6_APM_DAI) += snd-apm-dai.o +obj-$(CONFIG_SND_SOC_QDSP6_APM_BEDAI) += snd-apm-bedai.o diff --git a/sound/soc/qcom/qdsp6/q6apm-bedai.c b/sound/soc/qcom/qdsp6/q6apm-bedai.c new file mode 100644 index 000000000000..ac72c0eb73db --- /dev/null +++ b/sound/soc/qcom/qdsp6/q6apm-bedai.c @@ -0,0 +1,266 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2021, Linaro Limited + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "q6dsp-audio-ports.h" +#include "audioreach.h" +#include "q6apm.h" + +#define AUDIOREACH_BE_PCM_BASE 16 + +struct q6apm_bedai_data { + struct q6apm_graph *graph[APM_PORT_MAX]; + bool is_port_started[APM_PORT_MAX]; + struct audioreach_module_config module_config[APM_PORT_MAX]; +}; + +static int q6dma_set_channel_map(struct snd_soc_dai *dai, + unsigned int tx_num, unsigned int *tx_ch_mask, + unsigned int rx_num, unsigned int *rx_ch_mask) +{ + + struct q6apm_bedai_data *dai_data = dev_get_drvdata(dai->dev); + struct audioreach_module_config *cfg = &dai_data->module_config[dai->id]; + int ch_mask; + int rc = 0; + + switch (dai->id) { + case WSA_CODEC_DMA_TX_0: + case WSA_CODEC_DMA_TX_1: + case WSA_CODEC_DMA_TX_2: + case VA_CODEC_DMA_TX_0: + case VA_CODEC_DMA_TX_1: + case VA_CODEC_DMA_TX_2: + case TX_CODEC_DMA_TX_0: + case TX_CODEC_DMA_TX_1: + case TX_CODEC_DMA_TX_2: + case TX_CODEC_DMA_TX_3: + case TX_CODEC_DMA_TX_4: + case TX_CODEC_DMA_TX_5: + if (!tx_ch_mask) { + dev_err(dai->dev, "tx slot not found\n"); + return -EINVAL; + } + + if (tx_num > PCM_MAX_NUM_CHANNEL) { + dev_err(dai->dev, "invalid tx num %d\n", + tx_num); + return -EINVAL; + } + ch_mask = *tx_ch_mask; + + break; + case WSA_CODEC_DMA_RX_0: + case WSA_CODEC_DMA_RX_1: + case RX_CODEC_DMA_RX_0: + case RX_CODEC_DMA_RX_1: + case RX_CODEC_DMA_RX_2: + case RX_CODEC_DMA_RX_3: + case RX_CODEC_DMA_RX_4: + case RX_CODEC_DMA_RX_5: + case RX_CODEC_DMA_RX_6: + case RX_CODEC_DMA_RX_7: + /* rx */ + if (!rx_ch_mask) { + dev_err(dai->dev, "rx slot not found\n"); + return -EINVAL; + } + if (rx_num > APM_PORT_MAX_AUDIO_CHAN_CNT) { + dev_err(dai->dev, "invalid rx num %d\n", + rx_num); + return -EINVAL; + } + ch_mask = *rx_ch_mask; + + break; + default: + dev_err(dai->dev, "%s: invalid dai id 0x%x\n", + __func__, dai->id); + return -EINVAL; + } + + cfg->active_channels_mask = ch_mask; + + return rc; +} + +static int q6dma_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params, + struct snd_soc_dai *dai) +{ + struct q6apm_bedai_data *dai_data = dev_get_drvdata(dai->dev); + struct audioreach_module_config *cfg = &dai_data->module_config[dai->id]; + + cfg->bit_width = params_width(params); + cfg->sample_rate = params_rate(params); + cfg->num_channels = params_channels(params); + + return 0; +} + +static void q6apm_bedai_shutdown(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct q6apm_bedai_data *dai_data = dev_get_drvdata(dai->dev); + int rc; + + if (!dai_data->is_port_started[dai->id]) + return; + rc = q6apm_graph_stop(dai_data->graph[dai->id]); + if (rc < 0) + dev_err(dai->dev, "fail to close APM port (%d)\n", rc); + + q6apm_graph_close(dai_data->graph[dai->id]); + dai_data->is_port_started[dai->id] = false; + +} + +static int q6apm_bedai_prepare(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct q6apm_bedai_data *dai_data = dev_get_drvdata(dai->dev); + struct audioreach_module_config *cfg = &dai_data->module_config[dai->id]; + int graph_id = dai->id; + int rc; + struct q6apm_graph *graph; + + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { + graph = q6apm_graph_open(dai->dev, NULL, dai->dev, graph_id); + if (IS_ERR(graph)) { + dev_err(dai->dev, "Failed to open graph (%d)\n", + graph_id); + rc = PTR_ERR(graph); + return rc; + } + dai_data->graph[graph_id] = graph; + } + + cfg->direction = substream->stream; + rc = q6apm_graph_media_format_pcm(dai_data->graph[dai->id], cfg); + + if (rc) { + dev_err(dai->dev, "Failed to set media format %d\n", rc); + return rc; + } + + rc = q6apm_graph_prepare(dai_data->graph[dai->id]); + if (rc) { + dev_err(dai->dev, "Failed to prepare Graph %d\n", rc); + return rc; + } + + rc = q6apm_graph_start(dai_data->graph[dai->id]); + if (rc < 0) { + dev_err(dai->dev, "fail to start APM port %x\n", dai->id); + return rc; + } + dai_data->is_port_started[dai->id] = true; + + return 0; +} + +static int q6apm_bedai_startup(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct q6apm_bedai_data *dai_data = dev_get_drvdata(dai->dev); + int graph_id = dai->id; + struct q6apm_graph *graph; + + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { + graph = q6apm_graph_open(dai->dev, NULL, dai->dev, graph_id); + if (IS_ERR(graph)) { + dev_err(dai->dev, "Failed to open graph (%d)\n", + graph_id); + return PTR_ERR(graph); + } + dai_data->graph[graph_id] = graph; + } + + return 0; +} + +static int q6i2s_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) +{ + struct q6apm_bedai_data *dai_data = dev_get_drvdata(dai->dev); + struct audioreach_module_config *cfg = &dai_data->module_config[dai->id]; + + cfg->fmt = fmt; + + return 0; +} + +static const struct snd_soc_dai_ops q6dma_ops = { + .prepare = q6apm_bedai_prepare, + .startup = q6apm_bedai_startup, + .shutdown = q6apm_bedai_shutdown, + .set_channel_map = q6dma_set_channel_map, + .hw_params = q6dma_hw_params, +}; + +static const struct snd_soc_dai_ops q6i2s_ops = { + .prepare = q6apm_bedai_prepare, + .startup = q6apm_bedai_startup, + .shutdown = q6apm_bedai_shutdown, + .set_channel_map = q6dma_set_channel_map, + .hw_params = q6dma_hw_params, + .set_fmt = q6i2s_set_fmt, +}; + +static const struct snd_soc_component_driver q6apm_bedai_component = { + .name = "q6apm-be-dai-component", + .of_xlate_dai_name = q6dsp_audio_ports_of_xlate_dai_name, + .be_pcm_base = AUDIOREACH_BE_PCM_BASE, + .use_dai_pcm_id = true, +}; + +static int q6apm_bedai_dev_probe(struct platform_device *pdev) +{ + struct q6dsp_audio_port_dai_driver_config cfg; + struct snd_soc_dai_driver *dais; + struct q6apm_bedai_data *dai_data; + struct device *dev = &pdev->dev; + int num_dais; + + + dai_data = devm_kzalloc(dev, sizeof(*dai_data), GFP_KERNEL); + if (!dai_data) + return -ENOMEM; + + dev_set_drvdata(dev, dai_data); + + memset(&cfg, 0, sizeof(cfg)); + cfg.q6i2s_ops = &q6i2s_ops; + cfg.q6dma_ops = &q6dma_ops; + dais = q6dsp_audio_ports_set_config(dev, &cfg, &num_dais); + + return devm_snd_soc_register_component(dev, &q6apm_bedai_component, + dais, num_dais); +} + +#ifdef CONFIG_OF +static const struct of_device_id q6apm_bedai_device_id[] = { + { .compatible = "qcom,q6apm-bedais" }, + {}, +}; +MODULE_DEVICE_TABLE(of, q6apm_bedai_device_id); +#endif + +static struct platform_driver q6apm_bedai_platform_driver = { + .driver = { + .name = "q6apm-bedai", + .of_match_table = of_match_ptr(q6apm_bedai_device_id), + }, + .probe = q6apm_bedai_dev_probe, +}; +module_platform_driver(q6apm_bedai_platform_driver); + +MODULE_DESCRIPTION("AUDIOREACH Audio BackEnd dai driver"); +MODULE_LICENSE("GPL");