2 * linux/sound/arm/devdma.c
4 * Copyright (C) 2003-2004 Russell King, All rights reserved.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * ARM DMA shim for ALSA.
12 #include <linux/device.h>
13 #include <linux/dma-mapping.h>
15 #include <sound/driver.h>
16 #include <sound/core.h>
17 #include <sound/pcm.h>
21 void devdma_hw_free(struct device
*dev
, snd_pcm_substream_t
*substream
)
23 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
24 struct snd_dma_buffer
*buf
= runtime
->dma_buffer_p
;
26 if (runtime
->dma_area
== NULL
)
29 if (buf
!= &substream
->dma_buffer
) {
30 dma_free_coherent(buf
->dev
.dev
, buf
->bytes
, buf
->area
, buf
->addr
);
31 kfree(runtime
->dma_buffer_p
);
34 snd_pcm_set_runtime_buffer(substream
, NULL
);
37 int devdma_hw_alloc(struct device
*dev
, snd_pcm_substream_t
*substream
, size_t size
)
39 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
40 struct snd_dma_buffer
*buf
= runtime
->dma_buffer_p
;
44 if (buf
->bytes
>= size
)
46 devdma_hw_free(dev
, substream
);
49 if (substream
->dma_buffer
.area
!= NULL
&& substream
->dma_buffer
.bytes
>= size
) {
50 buf
= &substream
->dma_buffer
;
52 buf
= kmalloc(sizeof(struct snd_dma_buffer
), GFP_KERNEL
);
56 buf
->dev
.type
= SNDRV_DMA_TYPE_DEV
;
58 buf
->area
= dma_alloc_coherent(dev
, size
, &buf
->addr
, GFP_KERNEL
);
60 buf
->private_data
= NULL
;
65 snd_pcm_set_runtime_buffer(substream
, buf
);
68 runtime
->dma_bytes
= size
;
77 int devdma_mmap(struct device
*dev
, snd_pcm_substream_t
*substream
, struct vm_area_struct
*vma
)
79 snd_pcm_runtime_t
*runtime
= substream
->runtime
;
80 return dma_mmap_coherent(dev
, vma
, runtime
->dma_area
, runtime
->dma_addr
, runtime
->dma_bytes
);