From patchwork Mon Aug 9 11:23:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 493859 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:396:0:0:0:0 with SMTP id y22csp2811603jap; Mon, 9 Aug 2021 04:25:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOeUWXi+3hQ8QcVzYp8rbYOQ3VggU/+lWRpNlkbLSk8qrTdatOyP56xM9jrnqXPDYzqyya X-Received: by 2002:a05:6e02:156b:: with SMTP id k11mr66203ilu.51.1628508300562; Mon, 09 Aug 2021 04:25:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628508300; cv=none; d=google.com; s=arc-20160816; b=TVbeyz/A+gqFCnBlnAtLgjCifJvvJ55hyegrXJ9mQ7lNBJHKuggt8X1m9B5ao7Jk6c 1d9Mcsv4xHdW/yB7vgzqDCQVyiJtyeN/JKoLQDEmG0sJKy8uQDNv4aBB4xpTX/uCfNY9 /z/RKpuMztfvvoAalA3B7zJ1tUzWja1V6K+32UcstfwsCC6OTTnK5TwUZ0krxS47/oug D87Vh99PpB3W2BDXOAXaAF5+WuAAw5hoxi/ghf7tPQgnxnLnLx2UfaZRstsZ9YRlKYJa FoWU474tOoecwd35x70aUIALt26TxH4NNN/C+a8sjUfxUtfmsITu5TXAEKYK9/0kq5ZV 3ilw== 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=Mj5WKVcVLXFEu37rHCiplZXnki8QDcauYvEePFOTcG8=; b=TSfTqDsIoW/yOgj26HNi0iJSWiSH5CEy2wz2r8AVY/l+pmDXo4PhAhbRcQD8kDC2jT 7guEyoFakpuar39g6CxmRnGfYObIBH2JEqbqFib+rnRUJhbuzN1JIeDjXdGBTthcc94A Wn1AxUWTtnihZHrJczNzAMmGtkUOALPLmyDzXZsHyuX74SAOW9E48TVv1VEGShLFww3c mROKrhYyM+wonvO2nSO4fOR4ZAq3hmY2j5z3iJGi7pxV3T706sHumfPdAqxjptjuD5Vh /jwYIF1y88i+5HOEjG8CO7ZtVs0IK68X81Wj9JCNvgqhGvMsKo4NoxYA8BinAN6ag2/l dx6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tmCHUP+X; 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 q9si16629084jap.5.2021.08.09.04.25.00; Mon, 09 Aug 2021 04:25:00 -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=tmCHUP+X; 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 S235117AbhHILZT (ORCPT + 7 others); Mon, 9 Aug 2021 07:25:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235156AbhHILZN (ORCPT ); Mon, 9 Aug 2021 07:25:13 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67A13C06179B for ; Mon, 9 Aug 2021 04:24:52 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id l11-20020a7bcf0b0000b0290253545c2997so11276363wmg.4 for ; Mon, 09 Aug 2021 04:24:52 -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=Mj5WKVcVLXFEu37rHCiplZXnki8QDcauYvEePFOTcG8=; b=tmCHUP+Xn4C31zeLrKTMMXeUhhcLWmo7N/yyFoz4ThrPXZvuCEF82UPZ1oHwLgx5lw X4fvreFYg16vvH3P8ncYUeT7Qb/C6dM+5Sa5ZyjUbe5W5TOuOb+DqplwUdKDsbjJCLUE e5D8uX2YRrFMWIFUobCUjEj69ER+yTAE4ghRqdgMlA9z+zP17zVVXAYmebnYOSg44FPG hckR44hBRIn2JvpCvGr4CGaZrp9ZNPzCJVQowZOFqqAXqK+Q1BYBCDkmdNyFRCsFd6DO 3NrYLuKkGfXtKTErZNofd6V0H/qBo+mbLsOPhMWLyfrLoiTOOjdggIiMLkaiJRA463zM tr3Q== 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=Mj5WKVcVLXFEu37rHCiplZXnki8QDcauYvEePFOTcG8=; b=NH6MEHzV5bD7ZTqhM/0D/kOmiONjLLwPJ9cWW2sRYar2VC1fzgVyb/SAX2qZvU8cwm IIDuAAFcckAZ8jbSllbavNVwqxXMS7HZ36AlAjZeJxyDRe5it+rkY/JXbI0ENs+mTqnn QTb/j15tlAQ0gQh78kw+qc3JJINQBc7JC+5peQ4n0gZmhXZQ01jRwtRpDKGS5V/NpYxb 06RpnpxgA3LSkVkJng916q7ADobvqLTx1ntDf4MpX1Rs3Q/Ir/N6aXfLwTRrV5NLDnMn ruAmv4apXECJa1gj1kUpXmLXx/YC6yT1kbEHQsdLfIDLQOMQQASZ2pY2SpFwF58ItiUE utbA== X-Gm-Message-State: AOAM5320GHKyvXjhluSyXYWfYfSjqNUZortCXHHtD4PW7zhTqgr5bynn nVB4lDO8VZNSFspMLiwQz1t3gQ== X-Received: by 2002:a05:600c:4a12:: with SMTP id c18mr33750101wmp.9.1628508290978; Mon, 09 Aug 2021 04:24:50 -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 b80sm7774900wmb.2.2021.08.09.04.24.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Aug 2021 04:24:50 -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 v4 18/20] ASoC: qdsp6: audioreach: add q6apm lpass dai support Date: Mon, 9 Aug 2021 12:23:37 +0100 Message-Id: <20210809112339.8368-19-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210809112339.8368-1-srinivas.kandagatla@linaro.org> References: <20210809112339.8368-1-srinivas.kandagatla@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Add support to Audio port dais on LPASS Audio IP using existing common q6dsp-lpass-ports. Signed-off-by: Srinivas Kandagatla --- sound/soc/qcom/Kconfig | 4 + sound/soc/qcom/qdsp6/Makefile | 1 + sound/soc/qcom/qdsp6/q6apm-lpass-dais.c | 266 ++++++++++++++++++++++++ 3 files changed, 271 insertions(+) create mode 100644 sound/soc/qcom/qdsp6/q6apm-lpass-dais.c -- 2.21.0 diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig index fb1921889dc4..51b5a173e8ed 100644 --- a/sound/soc/qcom/Kconfig +++ b/sound/soc/qcom/Kconfig @@ -88,8 +88,12 @@ config SND_SOC_QDSP6_APM_DAI select SND_SOC_COMPRESS tristate +config SND_SOC_QDSP6_APM_LPASS_DAI + tristate + config SND_SOC_QDSP6_APM select SND_SOC_QDSP6_APM_DAI + select SND_SOC_QDSP6_APM_LPASS_DAI tristate config SND_SOC_QDSP6 diff --git a/sound/soc/qcom/qdsp6/Makefile b/sound/soc/qcom/qdsp6/Makefile index a4ec7c4d0e48..bdcbfdfa9bd0 100644 --- a/sound/soc/qcom/qdsp6/Makefile +++ b/sound/soc/qcom/qdsp6/Makefile @@ -14,3 +14,4 @@ obj-$(CONFIG_SND_SOC_QDSP6_ASM_DAI) += q6asm-dai.o obj-$(CONFIG_SND_SOC_QDSP6_APM) += snd-q6apm.o obj-$(CONFIG_SND_SOC_QDSP6_APM_DAI) += q6apm-dai.o +obj-$(CONFIG_SND_SOC_QDSP6_APM_LPASS_DAI) += q6apm-lpass-dais.o diff --git a/sound/soc/qcom/qdsp6/q6apm-lpass-dais.c b/sound/soc/qcom/qdsp6/q6apm-lpass-dais.c new file mode 100644 index 000000000000..25f31d425746 --- /dev/null +++ b/sound/soc/qcom/qdsp6/q6apm-lpass-dais.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-lpass-ports.h" +#include "audioreach.h" +#include "q6apm.h" + +#define AUDIOREACH_BE_PCM_BASE 16 + +struct q6apm_lpass_dai_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_lpass_dai_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_lpass_dai_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_lpass_dai_shutdown(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct q6apm_lpass_dai_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_lpass_dai_prepare(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct q6apm_lpass_dai_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_lpass_dai_startup(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct q6apm_lpass_dai_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_lpass_dai_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_lpass_dai_prepare, + .startup = q6apm_lpass_dai_startup, + .shutdown = q6apm_lpass_dai_shutdown, + .set_channel_map = q6dma_set_channel_map, + .hw_params = q6dma_hw_params, +}; + +static const struct snd_soc_dai_ops q6i2s_ops = { + .prepare = q6apm_lpass_dai_prepare, + .startup = q6apm_lpass_dai_startup, + .shutdown = q6apm_lpass_dai_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_lpass_dai_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_lpass_dai_dev_probe(struct platform_device *pdev) +{ + struct q6dsp_audio_port_dai_driver_config cfg; + struct snd_soc_dai_driver *dais; + struct q6apm_lpass_dai_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_lpass_dai_component, + dais, num_dais); +} + +#ifdef CONFIG_OF +static const struct of_device_id q6apm_lpass_dai_device_id[] = { + { .compatible = "qcom,q6apm-lpass-dais" }, + {}, +}; +MODULE_DEVICE_TABLE(of, q6apm_lpass_dai_device_id); +#endif + +static struct platform_driver q6apm_lpass_dai_platform_driver = { + .driver = { + .name = "q6apm-lpass-dais", + .of_match_table = of_match_ptr(q6apm_lpass_dai_device_id), + }, + .probe = q6apm_lpass_dai_dev_probe, +}; +module_platform_driver(q6apm_lpass_dai_platform_driver); + +MODULE_DESCRIPTION("AUDIOREACH APM LPASS dai driver"); +MODULE_LICENSE("GPL");