All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lars-Peter Clausen <lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
To: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Liam Girdwood <lgirdwood-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Scott Jiang
	<scott.jiang.linux-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Steven Miao <realmz6-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: uclinux-dist-devel-ZG0+EudsQA8dtHy/vicBwGD2FQJk+8+b@public.gmane.org,
	alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw@public.gmane.org
Subject: [PATCH 05/10] ASoC: blackfin: bf5xx-i2s-pcm: Use snd_pcm_lib_preallocate_pages_for_all()
Date: Tue, 28 May 2013 19:22:13 +0200	[thread overview]
Message-ID: <1369761738-29503-5-git-send-email-lars@metafoo.de> (raw)
In-Reply-To: <1369761738-29503-1-git-send-email-lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>

Use snd_pcm_lib_preallocate_pages_for_all() for pre-allocating the DMA buffers
instead of re-implementing the same functionality.  Note that there is no need
to call snd_pcm_lib_free_pages_for_all() since the ALSA core takes care of this
for us.

Signed-off-by: Lars-Peter Clausen <lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
---
 sound/soc/blackfin/bf5xx-i2s-pcm.c | 63 ++------------------------------------
 1 file changed, 3 insertions(+), 60 deletions(-)

diff --git a/sound/soc/blackfin/bf5xx-i2s-pcm.c b/sound/soc/blackfin/bf5xx-i2s-pcm.c
index 107c1c9..9931a18 100644
--- a/sound/soc/blackfin/bf5xx-i2s-pcm.c
+++ b/sound/soc/blackfin/bf5xx-i2s-pcm.c
@@ -209,55 +209,12 @@ static struct snd_pcm_ops bf5xx_pcm_i2s_ops = {
 	.mmap		= bf5xx_pcm_mmap,
 };
 
-static int bf5xx_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream)
-{
-	struct snd_pcm_substream *substream = pcm->streams[stream].substream;
-	struct snd_dma_buffer *buf = &substream->dma_buffer;
-	size_t size = bf5xx_pcm_hardware.buffer_bytes_max;
-
-	buf->dev.type = SNDRV_DMA_TYPE_DEV;
-	buf->dev.dev = pcm->card->dev;
-	buf->private_data = NULL;
-	buf->area = dma_alloc_coherent(pcm->card->dev, size,
-			&buf->addr, GFP_KERNEL);
-	if (!buf->area) {
-		pr_err("Failed to allocate dma memory - Please increase uncached DMA memory region\n");
-		return -ENOMEM;
-	}
-	buf->bytes = size;
-
-	pr_debug("%s, area:%p, size:0x%08lx\n", __func__,
-		buf->area, buf->bytes);
-
-	return 0;
-}
-
-static void bf5xx_pcm_free_dma_buffers(struct snd_pcm *pcm)
-{
-	struct snd_pcm_substream *substream;
-	struct snd_dma_buffer *buf;
-	int stream;
-
-	for (stream = 0; stream < 2; stream++) {
-		substream = pcm->streams[stream].substream;
-		if (!substream)
-			continue;
-
-		buf = &substream->dma_buffer;
-		if (!buf->area)
-			continue;
-		dma_free_coherent(NULL, buf->bytes, buf->area, 0);
-		buf->area = NULL;
-	}
-}
-
 static u64 bf5xx_pcm_dmamask = DMA_BIT_MASK(32);
 
 static int bf5xx_pcm_i2s_new(struct snd_soc_pcm_runtime *rtd)
 {
 	struct snd_card *card = rtd->card->snd_card;
-	struct snd_pcm *pcm = rtd->pcm;
-	int ret = 0;
+	size_t size = bf5xx_pcm_hardware.buffer_bytes_max;
 
 	pr_debug("%s enter\n", __func__);
 	if (!card->dev->dma_mask)
@@ -265,27 +222,13 @@ static int bf5xx_pcm_i2s_new(struct snd_soc_pcm_runtime *rtd)
 	if (!card->dev->coherent_dma_mask)
 		card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
 
-	if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
-		ret = bf5xx_pcm_preallocate_dma_buffer(pcm,
-			SNDRV_PCM_STREAM_PLAYBACK);
-		if (ret)
-			goto out;
-	}
-
-	if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
-		ret = bf5xx_pcm_preallocate_dma_buffer(pcm,
-			SNDRV_PCM_STREAM_CAPTURE);
-		if (ret)
-			goto out;
-	}
- out:
-	return ret;
+	return snd_pcm_lib_preallocate_pages_for_all(rtd->pcm,
+				SNDRV_DMA_TYPE_DEV, card->dev, size, size);
 }
 
 static struct snd_soc_platform_driver bf5xx_i2s_soc_platform = {
 	.ops		= &bf5xx_pcm_i2s_ops,
 	.pcm_new	= bf5xx_pcm_i2s_new,
-	.pcm_free	= bf5xx_pcm_free_dma_buffers,
 };
 
 static int bfin_i2s_soc_platform_probe(struct platform_device *pdev)
-- 
1.8.0

  parent reply	other threads:[~2013-05-28 17:22 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-28 17:22 [PATCH 01/10] ASoC: blackfin: Remove unused bf5xx-{i2s, tdm, ac97}-pcm.h Lars-Peter Clausen
     [not found] ` <1369761738-29503-1-git-send-email-lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2013-05-28 17:22   ` [PATCH 02/10] ASoC: blackfin: bf5xx-i2s: Use dev_{err, dbg} instead of pr_{error, debug} Lars-Peter Clausen
2013-05-28 17:22   ` [PATCH 03/10] ASoC: blackfin: bf5xx-sport: Allow setting rx and tx mask independently Lars-Peter Clausen
2013-05-28 17:22   ` [PATCH 04/10] ASoC: blackfin: bf5xx-i2s: Allocate buffer only as large as requested Lars-Peter Clausen
2013-05-28 17:22   ` Lars-Peter Clausen [this message]
2013-05-28 17:22   ` [PATCH 06/10] ASoC: blackfin: bf5xx-i2s: Add support for TDM mode Lars-Peter Clausen
2013-05-28 17:22   ` [PATCH 07/10] ASoC: blackfin: Switch bf5xx-ad193x from bf5xx-tdm to bf5xx-i2s Lars-Peter Clausen
2013-05-28 17:22   ` [PATCH 08/10] ASoC: blackfin: Switch bf5xx-ad1836 " Lars-Peter Clausen
2013-05-28 17:22   ` [PATCH 09/10] ASoC: blackfin: Remove bf5xx-tdm driver Lars-Peter Clausen
2013-05-28 17:22   ` [PATCH 10/10] blackfin: Remove references to the bf5x_tdm driver Lars-Peter Clausen
2013-05-29 19:27 ` [PATCH 01/10] ASoC: blackfin: Remove unused bf5xx-{i2s, tdm, ac97}-pcm.h Mark Brown
2013-05-30  7:47   ` Lars-Peter Clausen
2013-05-30 10:47     ` Mark Brown
2013-05-30 11:06       ` Lars-Peter Clausen
2013-05-30 11:34         ` 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=1369761738-29503-5-git-send-email-lars@metafoo.de \
    --to=lars-qo5elluwu/uelga04laivw@public.gmane.org \
    --cc=alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw@public.gmane.org \
    --cc=broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=lgirdwood-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=realmz6-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=scott.jiang.linux-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=uclinux-dist-devel-ZG0+EudsQA8dtHy/vicBwGD2FQJk+8+b@public.gmane.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.