Linux Media Controller development
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab@redhat.com>
To: unlisted-recipients:; (no To-header on input)@bombadil.infradead.org
Cc: Linux Media Mailing List <linux-media@vger.kernel.org>
Subject: [PATCH 3/6] tm6000-alsa: rework audio buffer allocation/deallocation
Date: Fri, 4 Jun 2010 21:21:07 -0300	[thread overview]
Message-ID: <20100604212107.3b9e8a1b@pedra> (raw)
In-Reply-To: <cover.1275696910.git.mchehab@redhat.com>

Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>

diff --git a/drivers/staging/tm6000/tm6000-alsa.c b/drivers/staging/tm6000/tm6000-alsa.c
index 8520434..ca9aec5 100644
--- a/drivers/staging/tm6000/tm6000-alsa.c
+++ b/drivers/staging/tm6000/tm6000-alsa.c
@@ -15,6 +15,7 @@
 #include <linux/device.h>
 #include <linux/interrupt.h>
 #include <linux/usb.h>
+#include <linux/vmalloc.h>
 
 #include <asm/delay.h>
 #include <sound/core.h>
@@ -105,19 +106,39 @@ static int _tm6000_stop_audio_dma(struct snd_tm6000_card *chip)
 	return 0;
 }
 
-static int dsp_buffer_free(struct snd_tm6000_card *chip)
+static void dsp_buffer_free(struct snd_pcm_substream *substream)
 {
-	BUG_ON(!chip->bufsize);
+	struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream);
 
 	dprintk(2, "Freeing buffer\n");
 
-	/* FIXME: Frees buffer */
+	vfree(substream->runtime->dma_area);
+	substream->runtime->dma_area = NULL;
+	substream->runtime->dma_bytes = 0;
+}
+
+static int dsp_buffer_alloc(struct snd_pcm_substream *substream, int size)
+{
+	struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream);
+
+	dprintk(2, "Allocating buffer\n");
 
-	chip->bufsize = 0;
+	if (substream->runtime->dma_area) {
+		if (substream->runtime->dma_bytes > size)
+			return 0;
+		dsp_buffer_free(substream);
+	}
 
-       return 0;
+	substream->runtime->dma_area = vmalloc(size);
+	if (!substream->runtime->dma_area)
+		return -ENOMEM;
+
+	substream->runtime->dma_bytes = size;
+
+	return 0;
 }
 
+
 /****************************************************************************
 				ALSA PCM Interface
  ****************************************************************************/
@@ -184,23 +205,13 @@ static int snd_tm6000_close(struct snd_pcm_substream *substream)
 static int snd_tm6000_hw_params(struct snd_pcm_substream *substream,
 			      struct snd_pcm_hw_params *hw_params)
 {
-	struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream);
+	int size, rc;
 
-	if (substream->runtime->dma_area) {
-		dsp_buffer_free(chip);
-		substream->runtime->dma_area = NULL;
-	}
-
-	chip->period_size = params_period_bytes(hw_params);
-	chip->num_periods = params_periods(hw_params);
-	chip->bufsize = chip->period_size * params_periods(hw_params);
-
-	BUG_ON(!chip->bufsize);
-
-	dprintk(1, "Setting buffer\n");
-
-	/* FIXME: Allocate buffer for audio */
+	size = params_period_bytes(hw_params) * params_periods(hw_params);
 
+	rc = dsp_buffer_alloc(substream, size);
+	if (rc < 0)
+		return rc;
 
 	return 0;
 }
@@ -210,13 +221,7 @@ static int snd_tm6000_hw_params(struct snd_pcm_substream *substream,
  */
 static int snd_tm6000_hw_free(struct snd_pcm_substream *substream)
 {
-
-	struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream);
-
-	if (substream->runtime->dma_area) {
-		dsp_buffer_free(chip);
-		substream->runtime->dma_area = NULL;
-	}
+	dsp_buffer_free(substream);
 
 	return 0;
 }
diff --git a/drivers/staging/tm6000/tm6000.h b/drivers/staging/tm6000/tm6000.h
index 18d1e51..a1d96d6 100644
--- a/drivers/staging/tm6000/tm6000.h
+++ b/drivers/staging/tm6000/tm6000.h
@@ -136,11 +136,7 @@ struct snd_tm6000_card {
 	struct snd_card			*card;
 	spinlock_t			reg_lock;
 	atomic_t			count;
-	unsigned int			period_size;
-	unsigned int			num_periods;
 	struct tm6000_core		*core;
-	struct tm6000_buffer		*buf;
-	int				bufsize;
 	struct snd_pcm_substream	*substream;
 };
 
-- 
1.7.1



  parent reply	other threads:[~2010-06-05  0:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1275696910.git.mchehab@redhat.com>
2010-06-05  0:21 ` [PATCH 6/6] tm6000: avoid unknown symbol tm6000_debug Mauro Carvalho Chehab
2010-06-05  0:21 ` [PATCH 5/6] tm6000: Add a callback code for buffer fill Mauro Carvalho Chehab
2010-06-05  0:21 ` [PATCH 4/6] tm6000: Use an emum for extension type Mauro Carvalho Chehab
2010-06-05  0:21 ` Mauro Carvalho Chehab [this message]
2010-06-05  0:21 ` [PATCH 1/6] tm6000: Fix compilation breakages Mauro Carvalho Chehab
2010-06-05  0:21 ` [PATCH 2/6] tm6000: Avoid OOPS when loading tm6000-alsa module Mauro Carvalho Chehab

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=20100604212107.3b9e8a1b@pedra \
    --to=mchehab@redhat.com \
    --cc=linux-media@vger.kernel.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