>From 465846f6fd1ea39534f32b984d352b5bc6928889 Mon Sep 17 00:00:00 2001 From: Daniel Mack Date: Thu, 4 Oct 2012 11:12:28 +0200 Subject: [PATCH 2/2] ALSA: ASoC: McASP: use gen_pool from platform data This makes the gen_pool SRAM usage a runtime decision. Signed-off-by: Daniel Mack --- sound/soc/davinci/davinci-pcm.c | 59 +++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 17 deletions(-) diff --git a/sound/soc/davinci/davinci-pcm.c b/sound/soc/davinci/davinci-pcm.c index 7ac5a19..f47b8f3 100644 --- a/sound/soc/davinci/davinci-pcm.c +++ b/sound/soc/davinci/davinci-pcm.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -261,26 +262,27 @@ static void davinci_pcm_dma_irq(unsigned link, u16 ch_status, void *data) } } -#if defined(CONFIG_SND_DAVINCI_HAVE_SRAM) +#ifdef CONFIG_GENERIC_ALLOCATOR static int allocate_sram(struct snd_pcm_substream *substream, unsigned size, - struct snd_pcm_hardware *ppcm) + struct snd_pcm_hardware *ppcm, struct gen_pool *pool) { struct snd_dma_buffer *buf = &substream->dma_buffer; struct snd_dma_buffer *iram_dma = NULL; + unsigned long iram_virt = 0; dma_addr_t iram_phys = 0; - void *iram_virt = NULL; if (buf->private_data || !size) return 0; ppcm->period_bytes_max = size; - iram_virt = sram_alloc(size, &iram_phys); + iram_virt = gen_pool_alloc(pool, size); if (!iram_virt) goto exit1; + iram_phys = gen_pool_virt_to_phys(pool, iram_virt); iram_dma = kzalloc(sizeof(*iram_dma), GFP_KERNEL); if (!iram_dma) goto exit2; - iram_dma->area = iram_virt; + iram_dma->area = (void *) iram_virt; iram_dma->addr = iram_phys; memset(iram_dma->area, 0, size); iram_dma->bytes = size; @@ -288,12 +290,40 @@ static int allocate_sram(struct snd_pcm_substream *substream, unsigned size, return 0; exit2: if (iram_virt) - sram_free(iram_virt, size); + gen_pool_free(pool, iram_virt, size); exit1: return -ENOMEM; } + +static void free_sram(struct snd_pcm_substream *substream) +{ + struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct snd_dma_buffer *buf = &substream->dma_buffer; + struct snd_dma_buffer *iram_dma = buf->private_data; + struct davinci_pcm_dma_params *params, *pa; + + if (!buf || !rtd || !iram_dma) + return; + + pa = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream); + params = &pa[substream->stream]; + + gen_pool_free(params->sram_pool, (unsigned long) iram_dma->area, + iram_dma->bytes); +} +#else +static int allocate_sram(struct snd_pcm_substream *substream, unsigned size, + struct snd_pcm_hardware *ppcm, struct gen_pool *pool) +{ + return 0; +} + +static void free_sram(struct snd_pcm_substream *substream) +{ +} #endif + /* * Only used with ping/pong. * This is called after runtime->dma_addr, period_bytes and data_type are valid @@ -680,9 +710,11 @@ static int davinci_pcm_open(struct snd_pcm_substream *substream) ppcm = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ? &pcm_hardware_playback : &pcm_hardware_capture; -#if defined(CONFIG_SND_DAVINCI_HAVE_SRAM) - allocate_sram(substream, params->sram_size, ppcm); -#endif + + if (params->sram_pool) + allocate_sram(substream, params->sram_size, ppcm, + params->sram_pool); + snd_soc_set_runtime_hwparams(substream, ppcm); /* ensure that buffer size is a multiple of period size */ ret = snd_pcm_hw_constraint_integer(runtime, @@ -811,7 +843,6 @@ static void davinci_pcm_free(struct snd_pcm *pcm) int stream; for (stream = 0; stream < 2; stream++) { - struct snd_dma_buffer *iram_dma; substream = pcm->streams[stream].substream; if (!substream) continue; @@ -823,13 +854,7 @@ static void davinci_pcm_free(struct snd_pcm *pcm) dma_free_writecombine(pcm->card->dev, buf->bytes, buf->area, buf->addr); buf->area = NULL; -#if defined(CONFIG_SND_DAVINCI_HAVE_SRAM) - iram_dma = buf->private_data; - if (iram_dma) { - sram_free(iram_dma->area, iram_dma->bytes); - kfree(iram_dma); - } -#endif + free_sram(substream); } } -- 1.7.11.4