aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/blackfin
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2013-05-28 13:22:13 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2013-05-30 07:33:40 -0400
commita3935a29f68c261d31b41c896f95c9333b615abf (patch)
treebcaf387162fc6dc13c3df6fe81d61b60ec7f5511 /sound/soc/blackfin
parent569ef65a973e19ec3327c8efbcf26bfc844af7e3 (diff)
ASoC: blackfin: bf5xx-i2s-pcm: Use snd_pcm_lib_preallocate_pages_for_all()
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@metafoo.de> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/blackfin')
-rw-r--r--sound/soc/blackfin/bf5xx-i2s-pcm.c63
1 files changed, 3 insertions, 60 deletions
diff --git a/sound/soc/blackfin/bf5xx-i2s-pcm.c b/sound/soc/blackfin/bf5xx-i2s-pcm.c
index 107c1c9b1cb6..9931a18c962e 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 = {
209 .mmap = bf5xx_pcm_mmap, 209 .mmap = bf5xx_pcm_mmap,
210}; 210};
211 211
212static int bf5xx_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream)
213{
214 struct snd_pcm_substream *substream = pcm->streams[stream].substream;
215 struct snd_dma_buffer *buf = &substream->dma_buffer;
216 size_t size = bf5xx_pcm_hardware.buffer_bytes_max;
217
218 buf->dev.type = SNDRV_DMA_TYPE_DEV;
219 buf->dev.dev = pcm->card->dev;
220 buf->private_data = NULL;
221 buf->area = dma_alloc_coherent(pcm->card->dev, size,
222 &buf->addr, GFP_KERNEL);
223 if (!buf->area) {
224 pr_err("Failed to allocate dma memory - Please increase uncached DMA memory region\n");
225 return -ENOMEM;
226 }
227 buf->bytes = size;
228
229 pr_debug("%s, area:%p, size:0x%08lx\n", __func__,
230 buf->area, buf->bytes);
231
232 return 0;
233}
234
235static void bf5xx_pcm_free_dma_buffers(struct snd_pcm *pcm)
236{
237 struct snd_pcm_substream *substream;
238 struct snd_dma_buffer *buf;
239 int stream;
240
241 for (stream = 0; stream < 2; stream++) {
242 substream = pcm->streams[stream].substream;
243 if (!substream)
244 continue;
245
246 buf = &substream->dma_buffer;
247 if (!buf->area)
248 continue;
249 dma_free_coherent(NULL, buf->bytes, buf->area, 0);
250 buf->area = NULL;
251 }
252}
253
254static u64 bf5xx_pcm_dmamask = DMA_BIT_MASK(32); 212static u64 bf5xx_pcm_dmamask = DMA_BIT_MASK(32);
255 213
256static int bf5xx_pcm_i2s_new(struct snd_soc_pcm_runtime *rtd) 214static int bf5xx_pcm_i2s_new(struct snd_soc_pcm_runtime *rtd)
257{ 215{
258 struct snd_card *card = rtd->card->snd_card; 216 struct snd_card *card = rtd->card->snd_card;
259 struct snd_pcm *pcm = rtd->pcm; 217 size_t size = bf5xx_pcm_hardware.buffer_bytes_max;
260 int ret = 0;
261 218
262 pr_debug("%s enter\n", __func__); 219 pr_debug("%s enter\n", __func__);
263 if (!card->dev->dma_mask) 220 if (!card->dev->dma_mask)
@@ -265,27 +222,13 @@ static int bf5xx_pcm_i2s_new(struct snd_soc_pcm_runtime *rtd)
265 if (!card->dev->coherent_dma_mask) 222 if (!card->dev->coherent_dma_mask)
266 card->dev->coherent_dma_mask = DMA_BIT_MASK(32); 223 card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
267 224
268 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) { 225 return snd_pcm_lib_preallocate_pages_for_all(rtd->pcm,
269 ret = bf5xx_pcm_preallocate_dma_buffer(pcm, 226 SNDRV_DMA_TYPE_DEV, card->dev, size, size);
270 SNDRV_PCM_STREAM_PLAYBACK);
271 if (ret)
272 goto out;
273 }
274
275 if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
276 ret = bf5xx_pcm_preallocate_dma_buffer(pcm,
277 SNDRV_PCM_STREAM_CAPTURE);
278 if (ret)
279 goto out;
280 }
281 out:
282 return ret;
283} 227}
284 228
285static struct snd_soc_platform_driver bf5xx_i2s_soc_platform = { 229static struct snd_soc_platform_driver bf5xx_i2s_soc_platform = {
286 .ops = &bf5xx_pcm_i2s_ops, 230 .ops = &bf5xx_pcm_i2s_ops,
287 .pcm_new = bf5xx_pcm_i2s_new, 231 .pcm_new = bf5xx_pcm_i2s_new,
288 .pcm_free = bf5xx_pcm_free_dma_buffers,
289}; 232};
290 233
291static int bfin_i2s_soc_platform_probe(struct platform_device *pdev) 234static int bfin_i2s_soc_platform_probe(struct platform_device *pdev)