From patchwork Fri Nov 3 20:35:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Deucher X-Patchwork-Id: 10041191 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2E140603D7 for ; Fri, 3 Nov 2017 20:44:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D65D29935 for ; Fri, 3 Nov 2017 20:44:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 120A629937; Fri, 3 Nov 2017 20:44:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=0.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM, RCVD_IN_SORBS_WEB,T_DKIM_INVALID autolearn=no version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4FB4229933 for ; Fri, 3 Nov 2017 20:44:18 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 9DCAE2675C4; Fri, 3 Nov 2017 21:36:01 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 5DABD2675BD; Fri, 3 Nov 2017 21:36:00 +0100 (CET) Received: from mail-io0-f196.google.com (mail-io0-f196.google.com [209.85.223.196]) by alsa0.perex.cz (Postfix) with ESMTP id 69D7E2675B4 for ; Fri, 3 Nov 2017 21:35:57 +0100 (CET) Received: by mail-io0-f196.google.com with SMTP id m16so8971113iod.1 for ; Fri, 03 Nov 2017 13:35:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CiPlu2F1clh2TdrMUkzQ29mvumug+V/v0MSo6P5uMHs=; b=tEUS+GsLfbuoWavR2yHwaJah1BPcAy94m2kPOOxRFMRqwO7G7itK+qLDNUeBhWDBsw CU2YAMteicirzMvYoh3kOapg9mcaqZvGWbaR2j6GuWBndVeRpcU1jo2a9pb49shuRzpF v/ekqQPQbmM6M9z5q21kdSpWufxV8FnaoQwg4uyUleEKugn1qBnWg5YN74FLGxuk/pgi Z6Y7OUWlo4T8ORY4r6lwMp1NJjqJqWLPmQ3lWTrJOKwkTsfPunC+jLl3Gtnqxbflp/Wu qxX5xQ2r7mxD04ZuGM2BbAKraBHlVPR3wnbmH+racQlRaAbj4uBu2pMAlmTDS8Fir3UV NEmA== 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; bh=CiPlu2F1clh2TdrMUkzQ29mvumug+V/v0MSo6P5uMHs=; b=iNCMfe4QhL7BtDwNvgV+rhEPmEGlQTeuBxBFVvGRoPMFVzqmgZ28DzK9xwKA9qyaNO JCuDcEiPBCp5tudNmQevXvJ/5TUVAQg+p2WLExE+cjnl4zs1/qcSDnpfbBrjVET3NZlv X5ZcwHY947/wvPSUXwwOwlzAGdPWnwddigHRnU7fAVZNSPyWDM4xPaCYvArRFiXEObwg b6affxTiie+TiNToAebY0tTn0jaXVC2gSgNlbkTOoPEvFTN9EjGSf8sqNBjNuk2IoeOV MuHGl2Ii61PUhls9YKb7wAtXkZAimZtxhpx1/BEkjr0JzVdq6VEiXa1EigRxZKK4+wUY I55Q== X-Gm-Message-State: AMCzsaWeInHOt4Tg9s10Lq00W7IP0wGhngwxza3XAojpclI/KltU09Lv kq5j4Rhy7g4p9vxisd5lqQo= X-Google-Smtp-Source: ABhQp+SbqvYQbVy7bE2JBwdhfRZZh5ZbK3AY0CrFOteKwWxMboOF95Gtr+bvpqfflxB3UsThT5JDdA== X-Received: by 10.107.83.12 with SMTP id h12mr10255535iob.13.1509741356378; Fri, 03 Nov 2017 13:35:56 -0700 (PDT) Received: from cm.amd.com ([165.204.55.251]) by smtp.gmail.com with ESMTPSA id y16sm1571946ita.11.2017.11.03.13.35.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Nov 2017 13:35:55 -0700 (PDT) From: Alex Deucher X-Google-Original-From: Alex Deucher To: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, airlied@gmail.com, alsa-devel@alsa-project.org, broonie@kernel.org, Vijendar.Mukunda@amd.com Date: Fri, 3 Nov 2017 16:35:43 -0400 Message-Id: <1509741345-1589-2-git-send-email-alexander.deucher@amd.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1509741345-1589-1-git-send-email-alexander.deucher@amd.com> References: <1509741345-1589-1-git-send-email-alexander.deucher@amd.com> Cc: tiwai@suse.de, Alex Deucher , lgirdwood@gmail.com, Akshu Agrawal Subject: [alsa-devel] [PATCH 1/3] ASoC: amd: Report accurate hw_ptr during dma X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From: Vijendar Mukunda Using hw register to read transmitted byte count and report accordingly the hw pointer. BUG=b:63121716 TEST= modprobe snd-soc-acp-pcm.ko modprobe snd-soc-acp-rt5645.ko aplay Signed-off-by: Vijendar Mukunda Signed-off-by: Akshu Agrawal Reviewed-on: https://chromium-review.googlesource.com/659699 Commit-Ready: Akshu Agrawal Tested-by: Akshu Agrawal Reviewed-by: Jason Clinton Reviewed-on: https://chromium-review.googlesource.com/676627 Signed-off-by: Alex Deucher --- sound/soc/amd/acp-pcm-dma.c | 71 ++++++++++++++++++++++++++++----------------- sound/soc/amd/acp.h | 10 +++++++ 2 files changed, 55 insertions(+), 26 deletions(-) diff --git a/sound/soc/amd/acp-pcm-dma.c b/sound/soc/amd/acp-pcm-dma.c index 73b58ee..e19f281 100644 --- a/sound/soc/amd/acp-pcm-dma.c +++ b/sound/soc/amd/acp-pcm-dma.c @@ -817,39 +817,48 @@ static int acp_dma_hw_free(struct snd_pcm_substream *substream) return snd_pcm_lib_free_pages(substream); } +static u64 acp_get_byte_count(void __iomem *acp_mmio, int stream) +{ + union acp_dma_count playback_dma_count; + union acp_dma_count capture_dma_count; + u64 bytescount = 0; + + if (stream == SNDRV_PCM_STREAM_PLAYBACK) { + playback_dma_count.bcount.high = acp_reg_read(acp_mmio, + mmACP_I2S_TRANSMIT_BYTE_CNT_HIGH); + playback_dma_count.bcount.low = acp_reg_read(acp_mmio, + mmACP_I2S_TRANSMIT_BYTE_CNT_LOW); + bytescount = playback_dma_count.bytescount; + } else { + capture_dma_count.bcount.high = acp_reg_read(acp_mmio, + mmACP_I2S_RECEIVED_BYTE_CNT_HIGH); + capture_dma_count.bcount.low = acp_reg_read(acp_mmio, + mmACP_I2S_RECEIVED_BYTE_CNT_LOW); + bytescount = capture_dma_count.bytescount; + } + return bytescount; +} + static snd_pcm_uframes_t acp_dma_pointer(struct snd_pcm_substream *substream) { - u16 dscr; - u32 mul, dma_config, period_bytes; + u32 buffersize; u32 pos = 0; + u64 bytescount = 0; struct snd_pcm_runtime *runtime = substream->runtime; struct audio_substream_data *rtd = runtime->private_data; - period_bytes = frames_to_bytes(runtime, runtime->period_size); - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { - dscr = acp_reg_read(rtd->acp_mmio, mmACP_DMA_CUR_DSCR_13); + buffersize = frames_to_bytes(runtime, runtime->buffer_size); + bytescount = acp_get_byte_count(rtd->acp_mmio, substream->stream); - if (dscr == PLAYBACK_START_DMA_DESCR_CH13) - mul = 0; - else - mul = 1; - pos = (mul * period_bytes); + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { + if (bytescount > rtd->renderbytescount) + bytescount = bytescount - rtd->renderbytescount; + pos = bytescount % buffersize; } else { - dma_config = acp_reg_read(rtd->acp_mmio, mmACP_DMA_CNTL_14); - if (dma_config != 0) { - dscr = acp_reg_read(rtd->acp_mmio, - mmACP_DMA_CUR_DSCR_14); - if (dscr == CAPTURE_START_DMA_DESCR_CH14) - mul = 1; - else - mul = 2; - pos = (mul * period_bytes); - } - - if (pos >= (2 * period_bytes)) - pos = 0; - + if (bytescount > rtd->capturebytescount) + bytescount = bytescount - rtd->capturebytescount; + pos = bytescount % buffersize; } return bytes_to_frames(runtime, pos); } @@ -904,6 +913,7 @@ static int acp_dma_trigger(struct snd_pcm_substream *substream, int cmd) { int ret; u32 loops = 1000; + u64 bytescount = 0; struct snd_pcm_runtime *runtime = substream->runtime; struct snd_soc_pcm_runtime *prtd = substream->private_data; @@ -915,7 +925,11 @@ static int acp_dma_trigger(struct snd_pcm_substream *substream, int cmd) case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: case SNDRV_PCM_TRIGGER_RESUME: + bytescount = acp_get_byte_count(rtd->acp_mmio, + substream->stream); if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { + if (rtd->renderbytescount == 0) + rtd->renderbytescount = bytescount; acp_dma_start(rtd->acp_mmio, SYSRAM_TO_ACP_CH_NUM, false); while (acp_reg_read(rtd->acp_mmio, mmACP_DMA_CH_STS) & @@ -932,6 +946,8 @@ static int acp_dma_trigger(struct snd_pcm_substream *substream, int cmd) ACP_TO_I2S_DMA_CH_NUM, true); } else { + if (rtd->capturebytescount == 0) + rtd->capturebytescount = bytescount; acp_dma_start(rtd->acp_mmio, I2S_TO_ACP_DMA_CH_NUM, true); } @@ -945,12 +961,15 @@ static int acp_dma_trigger(struct snd_pcm_substream *substream, int cmd) * channels will stopped automatically after its transfer * completes : SYSRAM_TO_ACP_CH_NUM / ACP_TO_SYSRAM_CH_NUM */ - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { ret = acp_dma_stop(rtd->acp_mmio, ACP_TO_I2S_DMA_CH_NUM); - else + rtd->renderbytescount = 0; + } else { ret = acp_dma_stop(rtd->acp_mmio, I2S_TO_ACP_DMA_CH_NUM); + rtd->capturebytescount = 0; + } break; default: ret = -EINVAL; diff --git a/sound/soc/amd/acp.h b/sound/soc/amd/acp.h index a330a99..de08ff0 100644 --- a/sound/soc/amd/acp.h +++ b/sound/soc/amd/acp.h @@ -83,6 +83,8 @@ struct audio_substream_data { u16 num_of_pages; u16 direction; uint64_t size; + u64 renderbytescount; + u64 capturebytescount; void __iomem *acp_mmio; }; @@ -93,6 +95,14 @@ struct audio_drv_data { u32 asic_type; }; +union acp_dma_count { + struct { + u32 low; + u32 high; + } bcount; + u64 bytescount; +}; + enum { ACP_TILE_P1 = 0, ACP_TILE_P2,