[alsa-devel] [PATCH] ASoC: MPC5200: Support for buffer wrap around

John Bonesio bones at secretlab.ca
Wed Jul 29 17:38:55 CEST 2009

Here's another appl_ptr related patch to the alsa soc mpc5200 ac97 driver. This 
time the patch is to fix a problem with not correctly handling appl_ptr
wrapping back around to the beginning of the buffer.

I haven't yet seen a symptom related to this. This came up when I was chatting
with Jon Smirl about another bug I was examining. Right now there is another
problem that is preventing me from playing really long audio streams. 

Let me know if this is the wrong approach.

- John

The code in psc_dma_bcom_enqueue_tx() didn't account for the fact that
s->runtime->control->appl_ptr can wrap around to the beginning of the
buffer. This change fixes this problem.

Signed-off-by: John Bonesio <bones at secretlab.ca>

 sound/soc/fsl/mpc5200_dma.c |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/sound/soc/fsl/mpc5200_dma.c b/sound/soc/fsl/mpc5200_dma.c
index cfe0ea4..2551c58 100644
--- a/sound/soc/fsl/mpc5200_dma.c
+++ b/sound/soc/fsl/mpc5200_dma.c
@@ -70,6 +70,23 @@ static void psc_dma_bcom_enqueue_next_buffer(struct psc_dma_stream *s)
 static void psc_dma_bcom_enqueue_tx(struct psc_dma_stream *s)
+	if (s->appl_ptr > s->runtime->control->appl_ptr) {
+		/*
+		 * In this case s->runtime->control->appl_ptr has wrapped around.
+		 * Play the data to the end of the boundary, then wrap our own
+		 * appl_ptr back around.
+		 */
+		while (s->appl_ptr < s->runtime->boundary) {
+			if (bcom_queue_full(s->bcom_task))
+				return;
+			s->appl_ptr += s->period_size;
+			psc_dma_bcom_enqueue_next_buffer(s);
+		}
+		s->appl_ptr -= s->runtime->boundary;
+	}
 	while (s->appl_ptr < s->runtime->control->appl_ptr) {
 		if (bcom_queue_full(s->bcom_task))

More information about the Alsa-devel mailing list