Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp183381pxb; Thu, 17 Feb 2022 01:28:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJwx4BjfASuluwZP/B/GSwTi6C98w0GwFjGPDixMfRsY52fuHZKqGDye3Mufpn8pclfzmXLu X-Received: by 2002:a17:907:2087:b0:6cf:e170:171 with SMTP id pv7-20020a170907208700b006cfe1700171mr1664896ejb.163.1645090093460; Thu, 17 Feb 2022 01:28:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645090093; cv=none; d=google.com; s=arc-20160816; b=dKOg1t3IC2yh5qucwO0mmlNhJC0b2WA+j9pkh+Zu/KT1WeePGPYnBUrKdzvdCRSHE4 OjQu9vRYw+OvhIRTU7pocKoliCO08F7Lk8oPotGcQ86bVxTYNPnmiCYm7Y2M1gx57tfu vGDV4pybMF2d6eF6MoGYklxpTPFybvswsU26tmhDiowpBgdhqVXK627V+nTvvg39AMZ9 ZMc3m5/wAlj8Iyllxlh5VKfik3p6V9L5pbEMEFBr3OlvPyYvJxOox/XJQv2DJf+0b//U 0n1erS35uNZmO4lhAGmwpjWSBOtr4KRQNvej9SMTvlxUvUcccicyj+JgIxUrr/9cZpNW NRMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=CGoveBkiGtagOkLFxTBBjwIUEuvWkhHcr6NS8Gpw0kg=; b=RRrLOHSQ6mzhopS1OuOJPMa5/iwUZIRSs0U4Gme7brpYmuTljgUEyHVh3vROrQDgq9 a42t9OGAyRDy0P5Jri/LoNmoT85/pP/HkmRnCALNy1rMCg5sF+mYcExe9Ti7Hy8qyMXW rJu79WW1918a5CajVt62e4VDTkXA1n7C1KgO35fzBAPNFwY6WMGC4IcIHGL9clVAUaym QoBo6UmmoBzG+m1dT0okkt6IXOkJRoRnJmZsdV4oLApnYf1ucy8WkG5in2BMY+o15Oh1 cNjLT7I+/2DAPOtKKda9NueIfrUidqvX68G0tnH5U2AJzJpPm2S0gmv+qfchXyA2BfKH 8Piw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b="yOYxEmL/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qk12si1423991ejc.261.2022.02.17.01.27.48; Thu, 17 Feb 2022 01:28:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b="yOYxEmL/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234997AbiBQGJZ (ORCPT + 99 others); Thu, 17 Feb 2022 01:09:25 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:50904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235003AbiBQGJX (ORCPT ); Thu, 17 Feb 2022 01:09:23 -0500 Received: from alexa-out-sd-02.qualcomm.com (alexa-out-sd-02.qualcomm.com [199.106.114.39]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1CA129ADF2; Wed, 16 Feb 2022 22:09:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1645078146; x=1676614146; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=CGoveBkiGtagOkLFxTBBjwIUEuvWkhHcr6NS8Gpw0kg=; b=yOYxEmL/eNT7RbjLHEgVlQqpEnaU70d41HdehPh/0XwqujLGIaNRq7Tj WMNVix7DKgxbzev1iouaAmoq5Hgr4pyz3BD8198wb3G9QfHPhDHGy2Lps MIwazIDaNZghTAWswDC1bpBJ8kCa63QzwrFJL+se5+Twihgc7IRzrMyTp 8=; Received: from unknown (HELO ironmsg01-sd.qualcomm.com) ([10.53.140.141]) by alexa-out-sd-02.qualcomm.com with ESMTP; 16 Feb 2022 22:09:06 -0800 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg01-sd.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Feb 2022 22:09:05 -0800 Received: from nalasex01b.na.qualcomm.com (10.47.209.197) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.15; Wed, 16 Feb 2022 22:09:03 -0800 Received: from hu-srivasam-hyd.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.922.19; Wed, 16 Feb 2022 22:08:57 -0800 From: Srinivasa Rao Mandadapu To: , , , , , , , , , , , , , , , , CC: Srinivasa Rao Mandadapu , "Venkata Prasad Potturu" Subject: [PATCH v14 04/10] ASoC: qcom: Add helper function to get dma control and lpaif handle Date: Thu, 17 Feb 2022 11:37:40 +0530 Message-ID: <1645078066-9365-5-git-send-email-quic_srivasam@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1645078066-9365-1-git-send-email-quic_srivasam@quicinc.com> References: <1645078066-9365-1-git-send-email-quic_srivasam@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support function to get dma control and lpaif handle to avoid repeated code in platform driver Signed-off-by: Srinivasa Rao Mandadapu Co-developed-by: Venkata Prasad Potturu Signed-off-by: Venkata Prasad Potturu Reviewed-by: Srinivas Kandagatla --- sound/soc/qcom/lpass-platform.c | 110 +++++++++++++++++++++++----------------- 1 file changed, 63 insertions(+), 47 deletions(-) diff --git a/sound/soc/qcom/lpass-platform.c b/sound/soc/qcom/lpass-platform.c index a44162c..74ddc3f 100644 --- a/sound/soc/qcom/lpass-platform.c +++ b/sound/soc/qcom/lpass-platform.c @@ -177,6 +177,46 @@ static int lpass_platform_pcmops_close(struct snd_soc_component *component, return 0; } +static void __lpass_get_lpaif_handle(const struct snd_pcm_substream *substream, + struct snd_soc_component *component, + struct lpaif_dmactl **dmactl, int *id, struct regmap **map) +{ + struct snd_soc_pcm_runtime *soc_runtime = asoc_substream_to_rtd(substream); + struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(soc_runtime, 0); + struct lpass_data *drvdata = snd_soc_component_get_drvdata(component); + struct snd_pcm_runtime *rt = substream->runtime; + struct lpass_pcm_data *pcm_data = rt->private_data; + struct lpass_variant *v = drvdata->variant; + unsigned int dai_id = cpu_dai->driver->id; + struct lpaif_dmactl *l_dmactl = NULL; + struct regmap *l_map = NULL; + int l_id = 0; + + switch (dai_id) { + case MI2S_PRIMARY ... MI2S_QUINARY: + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { + l_id = pcm_data->dma_ch; + l_dmactl = drvdata->rd_dmactl; + } else { + l_dmactl = drvdata->wr_dmactl; + l_id = pcm_data->dma_ch - v->wrdma_channel_start; + } + l_map = drvdata->lpaif_map; + break; + case LPASS_DP_RX: + l_id = pcm_data->dma_ch; + l_dmactl = drvdata->hdmi_rd_dmactl; + l_map = drvdata->hdmiif_map; + break; + } + if (dmactl) + *dmactl = l_dmactl; + if (id) + *id = l_id; + if (map) + *map = l_map; +} + static int lpass_platform_pcmops_hw_params(struct snd_soc_component *component, struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) @@ -191,21 +231,15 @@ static int lpass_platform_pcmops_hw_params(struct snd_soc_component *component, unsigned int channels = params_channels(params); unsigned int regval; struct lpaif_dmactl *dmactl; - int id, dir = substream->stream; + int id; int bitwidth; int ret, dma_port = pcm_data->i2s_port + v->dmactl_audif_start; unsigned int dai_id = cpu_dai->driver->id; - if (dir == SNDRV_PCM_STREAM_PLAYBACK) { - id = pcm_data->dma_ch; - if (dai_id == LPASS_DP_RX) - dmactl = drvdata->hdmi_rd_dmactl; - else - dmactl = drvdata->rd_dmactl; - - } else { - dmactl = drvdata->wr_dmactl; - id = pcm_data->dma_ch - v->wrdma_channel_start; + __lpass_get_lpaif_handle(substream, component, &dmactl, &id, NULL); + if (!dmactl) { + dev_err(soc_runtime->dev, "%s: failed to get dmactl handle\n", __func__); + return -EINVAL; } bitwidth = snd_pcm_format_width(format); @@ -350,10 +384,11 @@ static int lpass_platform_pcmops_hw_free(struct snd_soc_component *component, struct regmap *map; unsigned int dai_id = cpu_dai->driver->id; - if (dai_id == LPASS_DP_RX) - map = drvdata->hdmiif_map; - else - map = drvdata->lpaif_map; + __lpass_get_lpaif_handle(substream, component, NULL, NULL, &map); + if (!map) { + dev_err(soc_runtime->dev, "%s: failed to get dmactl handle\n", __func__); + return -EINVAL; + } reg = LPAIF_DMACTL_REG(v, pcm_data->dma_ch, substream->stream, dai_id); ret = regmap_write(map, reg, 0); @@ -379,22 +414,12 @@ static int lpass_platform_pcmops_prepare(struct snd_soc_component *component, int ret, id, ch, dir = substream->stream; unsigned int dai_id = cpu_dai->driver->id; - ch = pcm_data->dma_ch; - if (dir == SNDRV_PCM_STREAM_PLAYBACK) { - if (dai_id == LPASS_DP_RX) { - dmactl = drvdata->hdmi_rd_dmactl; - map = drvdata->hdmiif_map; - } else { - dmactl = drvdata->rd_dmactl; - map = drvdata->lpaif_map; - } - id = pcm_data->dma_ch; - } else { - dmactl = drvdata->wr_dmactl; - id = pcm_data->dma_ch - v->wrdma_channel_start; - map = drvdata->lpaif_map; + __lpass_get_lpaif_handle(substream, component, &dmactl, &id, &map); + if (!dmactl) { + dev_err(soc_runtime->dev, "%s: failed to get dmactl handle\n", __func__); + return -EINVAL; } ret = regmap_write(map, LPAIF_DMABASE_REG(v, ch, dir, dai_id), @@ -444,25 +469,15 @@ static int lpass_platform_pcmops_trigger(struct snd_soc_component *component, struct lpaif_dmactl *dmactl; struct regmap *map; int ret, ch, id; - int dir = substream->stream; unsigned int reg_irqclr = 0, val_irqclr = 0; unsigned int reg_irqen = 0, val_irqen = 0, val_mask = 0; unsigned int dai_id = cpu_dai->driver->id; ch = pcm_data->dma_ch; - if (dir == SNDRV_PCM_STREAM_PLAYBACK) { - id = pcm_data->dma_ch; - if (dai_id == LPASS_DP_RX) { - dmactl = drvdata->hdmi_rd_dmactl; - map = drvdata->hdmiif_map; - } else { - dmactl = drvdata->rd_dmactl; - map = drvdata->lpaif_map; - } - } else { - dmactl = drvdata->wr_dmactl; - id = pcm_data->dma_ch - v->wrdma_channel_start; - map = drvdata->lpaif_map; + __lpass_get_lpaif_handle(substream, component, &dmactl, &id, &map); + if (!dmactl) { + dev_err(soc_runtime->dev, "%s: failed to get dmactl handle\n", __func__); + return -EINVAL; } switch (cmd) { @@ -597,10 +612,11 @@ static snd_pcm_uframes_t lpass_platform_pcmops_pointer( struct regmap *map; unsigned int dai_id = cpu_dai->driver->id; - if (dai_id == LPASS_DP_RX) - map = drvdata->hdmiif_map; - else - map = drvdata->lpaif_map; + __lpass_get_lpaif_handle(substream, component, NULL, NULL, &map); + if (!map) { + dev_err(soc_runtime->dev, "%s: failed to get dmactl handle\n", __func__); + return -EINVAL; + } ch = pcm_data->dma_ch; -- 2.7.4