From: koro.chen@mediatek.com (Koro Chen)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] ASoC: mediatek: Increase periods_min in capture
Date: Mon, 14 Sep 2015 14:51:17 +0800 [thread overview]
Message-ID: <1442213477-63721-1-git-send-email-koro.chen@mediatek.com> (raw)
In capture, there is chance that hw_ptr reported at IRQ is
a little smaller than period_size due to internal AFE buffer.
In the case of ping-pong buffer:
|xxxxxxxxxxxxxxxxxxxxxxxxxxxx--|-----------------------------|
hw_ptr < period_size
This available buffer will not be read since its size is smaller than
avail_min (which is period_size by default), and read thread continues
to sleep. If the next hw_ptr is just a little larger than buffer_size,
overrun occurs. One more period can hold the possible unread buffer.
Signed-off-by: Koro Chen <koro.chen@mediatek.com>
---
sound/soc/mediatek/mtk-afe-pcm.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/sound/soc/mediatek/mtk-afe-pcm.c b/sound/soc/mediatek/mtk-afe-pcm.c
index d190fe0..f5baf3c 100644
--- a/sound/soc/mediatek/mtk-afe-pcm.c
+++ b/sound/soc/mediatek/mtk-afe-pcm.c
@@ -549,6 +549,23 @@ static int mtk_afe_dais_startup(struct snd_pcm_substream *substream,
memif->substream = substream;
snd_soc_set_runtime_hwparams(substream, &mtk_afe_hardware);
+
+ /*
+ * Capture cannot use ping-pong buffer since hw_ptr at IRQ may be
+ * smaller than period_size due to AFE's internal buffer.
+ * This easily leads to overrun when avail_min is period_size.
+ * One more period can hold the possible unread buffer.
+ */
+ if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
+ ret = snd_pcm_hw_constraint_minmax(runtime,
+ SNDRV_PCM_HW_PARAM_PERIODS,
+ 3,
+ mtk_afe_hardware.periods_max);
+ if (ret < 0) {
+ dev_err(afe->dev, "hw_constraint_minmax failed\n");
+ return ret;
+ }
+ }
ret = snd_pcm_hw_constraint_integer(runtime,
SNDRV_PCM_HW_PARAM_PERIODS);
if (ret < 0)
--
1.7.9.5
next reply other threads:[~2015-09-14 6:51 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-14 6:51 Koro Chen [this message]
2015-09-23 10:03 ` [PATCH] ASoC: mediatek: Increase periods_min in capture Koro Chen
2015-09-23 16:12 ` Mark Brown
2015-09-24 1:39 ` Koro Chen
2015-09-24 17:11 ` Mark Brown
2015-09-24 17:31 ` Sascha Hauer
2015-09-24 18:43 ` Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1442213477-63721-1-git-send-email-koro.chen@mediatek.com \
--to=koro.chen@mediatek.com \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).