Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp169546imd; Wed, 31 Oct 2018 16:43:19 -0700 (PDT) X-Google-Smtp-Source: AJdET5cxjrqcTxTMOmYTTopHfMD9q56aZCj7Xg/Klr+6MXNznmE+jPuDHWQJQsisPf56SsqXAc16 X-Received: by 2002:a17:902:2bc3:: with SMTP id l61-v6mr318259plb.5.1541029399532; Wed, 31 Oct 2018 16:43:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541029399; cv=none; d=google.com; s=arc-20160816; b=CgVdmX3KxHfCrBl6RGt0I4jS+v/UBgbjE6HdGpgSbaDWnCP9gpNN+em672jyRN9S22 RyoNXu5KELpIt75p79SeOaTAI4PhsOX+agH4Bblth8G6TxeWC+W3n8Zx0FI5rx4Hf9p/ pxVkxs/FfvBsMvfD8w7EnfNYnV5K7qaSJ3HOLwSXBqWCBk0R6JnwzyUozaHuELX3g/Zd xvnPHkoAWOMi9M6dLVCo66G2yo9xPHgVLpt8hNLWHm0kePArx7IK1LoYPbnV1s2bIcQR 3HI+vH4CMWusWPLrHxbVVAg0gObv7d/CndKn8LvRhftcAFGBkbhKJAinpxZxiU5yqoAa 2ujQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=VetiYbZhWgL/A4frkykazarhF8eeIWJVzkL5t3GanV4=; b=co02lZiDaYtQzOb3fDGi2v08TdYv5m1qCLR1g1ow5c1auLLPArXvZjL0fGTIe2aWj2 dagBN28ny3NY46mi70ED+u6DRoiHlRYvMnVnc37AFi/tDthnNfoPqacPSkQ0FlUr0+2R LwAO3K46WFDYkgxEUL9ilbp9YKJbcAyNLdI11vb6FF1XY3rb84dfDjLDv/0m46V2p/a8 ezT5CTEYrPgNo+1xc6E9qAXO+BWv4D6uEmXKswcCik62gZQZK56uvQuWqgc9zf5SfAWc XRB7soGn7tGVBSe2l4dUdN7lEj2OY/sCKBMCIxBN6nSBaeLnypui4J3/fVMar49gxlxN fItw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=huMKa5Da; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b13-v6si28717129pgj.154.2018.10.31.16.43.05; Wed, 31 Oct 2018 16:43:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=huMKa5Da; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729253AbeKAIHx (ORCPT + 99 others); Thu, 1 Nov 2018 04:07:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:56060 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729150AbeKAIHv (ORCPT ); Thu, 1 Nov 2018 04:07:51 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4290220847; Wed, 31 Oct 2018 23:07:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027260; bh=tcoRiYmjAZfeRl0GAiTVtRoXj59w79nkV7wvusDboCI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=huMKa5Da0rzk/j5vFAR8/7t5IepF94SQ6WBZxgyyHIKBKS57a8RwSNILZEqJKIPJz m0CKGRlKSijZ6RlyUm/c1JkrozrpcFtM23AIyFqNykN5tJl4LlVcyhpHO8zqS0RM3N Gs9h2kpJPZsMbSkYOhNyyt1faIhtOFSkwCu8vmgg= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Akshu Agrawal , Mark Brown , Sasha Levin Subject: [PATCH AUTOSEL 4.19 132/146] ASoC: AMD: Fix capture unstable in beginning for some runs Date: Wed, 31 Oct 2018 19:05:27 -0400 Message-Id: <20181031230541.28822-132-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031230541.28822-1-sashal@kernel.org> References: <20181031230541.28822-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Akshu Agrawal [ Upstream commit c50535ed6a10fcae1b64ae83c0f6b1eeb5535afc ] alsa_conformance_test -C hw:0,4 -p 1024 --debug would sometime show: TIME_DIFF(s) HW_LEVEL READ RATE 0.000095970 1024 1024 10670001.041992 0.042609555 1024 2048 24032.168372 0.021330364 1024 3072 48006.681930 0.021339559 1024 4096 47985.996337 The issue is that in dma pointer function we can have stale value of the register for current descriptor of channel. The register retains the number of the last descriptor that was transferred. Fix ensures that we report position, 0, till the one period worth of data is transferred. After one period of data, in handler of period completion interrupt we update the config and correct value of descriptor starts reflecting. Signed-off-by: Akshu Agrawal Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/amd/acp-pcm-dma.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/sound/soc/amd/acp-pcm-dma.c b/sound/soc/amd/acp-pcm-dma.c index 77b265bd0505..3135e9eafd18 100644 --- a/sound/soc/amd/acp-pcm-dma.c +++ b/sound/soc/amd/acp-pcm-dma.c @@ -1036,16 +1036,22 @@ static snd_pcm_uframes_t acp_dma_pointer(struct snd_pcm_substream *substream) if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { period_bytes = frames_to_bytes(runtime, runtime->period_size); - dscr = acp_reg_read(rtd->acp_mmio, rtd->dma_curr_dscr); - if (dscr == rtd->dma_dscr_idx_1) - pos = period_bytes; - else - pos = 0; bytescount = acp_get_byte_count(rtd); - if (bytescount > rtd->bytescount) + if (bytescount >= rtd->bytescount) bytescount -= rtd->bytescount; - delay = do_div(bytescount, period_bytes); - runtime->delay = bytes_to_frames(runtime, delay); + if (bytescount < period_bytes) { + pos = 0; + } else { + dscr = acp_reg_read(rtd->acp_mmio, rtd->dma_curr_dscr); + if (dscr == rtd->dma_dscr_idx_1) + pos = period_bytes; + else + pos = 0; + } + if (bytescount > 0) { + delay = do_div(bytescount, period_bytes); + runtime->delay = bytes_to_frames(runtime, delay); + } } else { buffersize = frames_to_bytes(runtime, runtime->buffer_size); bytescount = acp_get_byte_count(rtd); -- 2.17.1