linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ASoC: mediatek: Increase periods_min in capture
@ 2015-09-14  6:51 Koro Chen
  2015-09-23 10:03 ` Koro Chen
  0 siblings, 1 reply; 7+ messages in thread
From: Koro Chen @ 2015-09-14  6:51 UTC (permalink / raw)
  To: linux-arm-kernel

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

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH] ASoC: mediatek: Increase periods_min in capture
  2015-09-14  6:51 [PATCH] ASoC: mediatek: Increase periods_min in capture Koro Chen
@ 2015-09-23 10:03 ` Koro Chen
  2015-09-23 16:12   ` Mark Brown
  0 siblings, 1 reply; 7+ messages in thread
From: Koro Chen @ 2015-09-23 10:03 UTC (permalink / raw)
  To: linux-arm-kernel

Any suggestion for this patch?

On Mon, 2015-09-14 at 14:51 +0800, Koro Chen wrote:
> 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)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] ASoC: mediatek: Increase periods_min in capture
  2015-09-23 10:03 ` Koro Chen
@ 2015-09-23 16:12   ` Mark Brown
  2015-09-24  1:39     ` Koro Chen
  0 siblings, 1 reply; 7+ messages in thread
From: Mark Brown @ 2015-09-23 16:12 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Sep 23, 2015 at 06:03:19PM +0800, Koro Chen wrote:
> Any suggestion for this patch?
> 
> On Mon, 2015-09-14 at 14:51 +0800, Koro Chen wrote:
> > 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?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150923/0a40a3cf/attachment.sig>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] ASoC: mediatek: Increase periods_min in capture
  2015-09-23 16:12   ` Mark Brown
@ 2015-09-24  1:39     ` Koro Chen
  2015-09-24 17:11       ` Mark Brown
  0 siblings, 1 reply; 7+ messages in thread
From: Koro Chen @ 2015-09-24  1:39 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, 2015-09-23 at 09:12 -0700, Mark Brown wrote:
> On Wed, Sep 23, 2015 at 06:03:19PM +0800, Koro Chen wrote:
> > Any suggestion for this patch?
> > 
> > On Mon, 2015-09-14 at 14:51 +0800, Koro Chen wrote:
> > > 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?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] ASoC: mediatek: Increase periods_min in capture
  2015-09-24  1:39     ` Koro Chen
@ 2015-09-24 17:11       ` Mark Brown
  2015-09-24 17:31         ` Sascha Hauer
  0 siblings, 1 reply; 7+ messages in thread
From: Mark Brown @ 2015-09-24 17:11 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Sep 24, 2015 at 09:39:49AM +0800, Koro Chen wrote:

> 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?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150924/deb3df55/attachment-0001.sig>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] ASoC: mediatek: Increase periods_min in capture
  2015-09-24 17:11       ` Mark Brown
@ 2015-09-24 17:31         ` Sascha Hauer
  2015-09-24 18:43           ` Mark Brown
  0 siblings, 1 reply; 7+ messages in thread
From: Sascha Hauer @ 2015-09-24 17:31 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Sep 24, 2015 at 10:11:53AM -0700, Mark Brown wrote:
> On Thu, Sep 24, 2015 at 09:39:49AM +0800, Koro Chen wrote:
> 
> > 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


-- 
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 |

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] ASoC: mediatek: Increase periods_min in capture
  2015-09-24 17:31         ` Sascha Hauer
@ 2015-09-24 18:43           ` Mark Brown
  0 siblings, 0 replies; 7+ messages in thread
From: Mark Brown @ 2015-09-24 18:43 UTC (permalink / raw)
  To: linux-arm-kernel

On Thu, Sep 24, 2015 at 07:31:42PM +0200, Sascha Hauer wrote:
> On Thu, Sep 24, 2015 at 10:11:53AM -0700, Mark Brown wrote:

> > 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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150924/886f097c/attachment.sig>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-09-24 18:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-14  6:51 [PATCH] ASoC: mediatek: Increase periods_min in capture Koro Chen
2015-09-23 10:03 ` 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

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).