Skip to contentSkip to conversation

ASoC: mediatek: Increase periods_min in capture

PATCH In review Koro Chen 3 participants 7 messages Sep 14, 2015 – Sep 24, 2015

Subsystems (3)
lore
Share & tools
lore

Koro Chen

author
#0 lore raw

PATCH 1/1 ASoC: mediatek: Increase periods_min in capture

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.

---
 sound/soc/mediatek/mtk-afe-pcm.c |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)
sound/soc/mediatek/mtk-afe-pcm.c +17 -0
index d190fe0..f5baf3c 100644
@@ -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)
Signature · 1 line
1.7.9.5
author
#1 lore raw

Any suggestion for this patch?

Quoted 45 lines · Koro Chen

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.

---
 sound/soc/mediatek/mtk-afe-pcm.c |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)
sound/soc/mediatek/mtk-afe-pcm.c +17 -0
index d190fe0..f5baf3c 100644
@@ -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)
maintainer
#2 lore raw
Quoted 6 lines · Koro Chen

Any suggestion for this patch?

Quoted 3 lines · Koro Chen

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:

Please don't top post or send content free pings. I'm not entirely sure what you're asking for here - the patch has been applied, what further suggestions were you looking for?

_______________________________________________
Linux-mediatek mailing list [email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek

author
#3 lore raw
Quoted 11 lines · Mark Brown
Quoted 6 lines · Koro Chen

Any suggestion for this patch?

Quoted 3 lines · Koro Chen

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:

Please don't top post or send content free pings. I'm not entirely sure what you're asking for here - the patch has been applied, what further suggestions were you looking for?

I am sorry about the top posting ping... will never do this again. OK thank you, now I see the patch is already in the tree, but I am sure I didn't get the mail titled "Applied xxx to the asoc tree", so I didn't know the patch status. Maybe something was wrong with the mail system?

maintainer
#4 lore raw
Quoted 3 lines · Koro Chen

OK thank you, now I see the patch is already in the tree, but I am sure I didn't get the mail titled "Applied xxx to the asoc tree", so I didn't know the patch status. Maybe something was wrong with the mail system?

Possibly your mail system flagged it as spam?

#5 lore raw
Quoted 7 lines · Mark Brown
Quoted 3 lines · Koro Chen

OK thank you, now I see the patch is already in the tree, but I am sure I didn't get the mail titled "Applied xxx to the asoc tree", so I didn't know the patch status. Maybe something was wrong with the mail system?

Possibly your mail system flagged it as spam?

I didn't receive it either and it doesn't seem to be in the archives.

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
maintainer
#6 lore raw
Quoted 5 lines · Sascha Hauer
Quoted 1 line · Mark Brown

Possibly your mail system flagged it as spam?

I didn't receive it either and it doesn't seem to be in the archives.

Initially they weren't CCed to the list.