apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 1 | /* |
| 2 | * kirkwood-dma.c |
| 3 | * |
| 4 | * (c) 2010 Arnaud Patard <apatard@mandriva.com> |
Arnaud Patard (Rtp) | 6973789 | 2010-09-09 14:10:33 +0200 | [diff] [blame] | 5 | * (c) 2010 Arnaud Patard <arnaud.patard@rtp-net.org> |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2 of the License, or (at your |
| 10 | * option) any later version. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/device.h> |
| 16 | #include <linux/io.h> |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/interrupt.h> |
| 19 | #include <linux/dma-mapping.h> |
| 20 | #include <linux/mbus.h> |
| 21 | #include <sound/soc.h> |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 22 | #include "kirkwood.h" |
| 23 | |
| 24 | #define KIRKWOOD_RATES \ |
Russell King | 0aa5e47 | 2012-11-20 12:20:14 +0000 | [diff] [blame] | 25 | (SNDRV_PCM_RATE_8000_192000 | \ |
| 26 | SNDRV_PCM_RATE_CONTINUOUS | \ |
| 27 | SNDRV_PCM_RATE_KNOT) |
| 28 | |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 29 | #define KIRKWOOD_FORMATS \ |
| 30 | (SNDRV_PCM_FMTBIT_S16_LE | \ |
| 31 | SNDRV_PCM_FMTBIT_S24_LE | \ |
Russell King | b51600c | 2013-08-31 13:43:36 +0100 | [diff] [blame] | 32 | SNDRV_PCM_FMTBIT_S32_LE) |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 33 | |
Russell King | a7d0942 | 2013-08-04 20:22:03 +0100 | [diff] [blame] | 34 | static struct kirkwood_dma_data *kirkwood_priv(struct snd_pcm_substream *subs) |
| 35 | { |
| 36 | struct snd_soc_pcm_runtime *soc_runtime = subs->private_data; |
| 37 | return snd_soc_dai_get_drvdata(soc_runtime->cpu_dai); |
| 38 | } |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 39 | |
| 40 | static struct snd_pcm_hardware kirkwood_dma_snd_hw = { |
| 41 | .info = (SNDRV_PCM_INFO_INTERLEAVED | |
| 42 | SNDRV_PCM_INFO_MMAP | |
| 43 | SNDRV_PCM_INFO_MMAP_VALID | |
| 44 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 45 | SNDRV_PCM_INFO_PAUSE), |
| 46 | .formats = KIRKWOOD_FORMATS, |
| 47 | .rates = KIRKWOOD_RATES, |
Russell King | 0aa5e47 | 2012-11-20 12:20:14 +0000 | [diff] [blame] | 48 | .rate_min = 8000, |
| 49 | .rate_max = 384000, |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 50 | .channels_min = 1, |
Russell King | 1703470 | 2012-11-20 12:20:55 +0000 | [diff] [blame] | 51 | .channels_max = 8, |
Russell King | e4065f3 | 2013-08-04 20:28:04 +0100 | [diff] [blame] | 52 | .buffer_bytes_max = KIRKWOOD_SND_MAX_BUFFER_BYTES, |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 53 | .period_bytes_min = KIRKWOOD_SND_MIN_PERIOD_BYTES, |
| 54 | .period_bytes_max = KIRKWOOD_SND_MAX_PERIOD_BYTES, |
| 55 | .periods_min = KIRKWOOD_SND_MIN_PERIODS, |
| 56 | .periods_max = KIRKWOOD_SND_MAX_PERIODS, |
| 57 | .fifo_size = 0, |
| 58 | }; |
| 59 | |
Joachim Eastwood | 350e16d | 2012-01-01 02:43:03 +0100 | [diff] [blame] | 60 | static u64 kirkwood_dma_dmamask = DMA_BIT_MASK(32); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 61 | |
| 62 | static irqreturn_t kirkwood_dma_irq(int irq, void *dev_id) |
| 63 | { |
Russell King | a7d0942 | 2013-08-04 20:22:03 +0100 | [diff] [blame] | 64 | struct kirkwood_dma_data *priv = dev_id; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 65 | unsigned long mask, status, cause; |
| 66 | |
| 67 | mask = readl(priv->io + KIRKWOOD_INT_MASK); |
| 68 | status = readl(priv->io + KIRKWOOD_INT_CAUSE) & mask; |
| 69 | |
| 70 | cause = readl(priv->io + KIRKWOOD_ERR_CAUSE); |
| 71 | if (unlikely(cause)) { |
| 72 | printk(KERN_WARNING "%s: got err interrupt 0x%lx\n", |
| 73 | __func__, cause); |
| 74 | writel(cause, priv->io + KIRKWOOD_ERR_CAUSE); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /* we've enabled only bytes interrupts ... */ |
| 78 | if (status & ~(KIRKWOOD_INT_CAUSE_PLAY_BYTES | \ |
| 79 | KIRKWOOD_INT_CAUSE_REC_BYTES)) { |
| 80 | printk(KERN_WARNING "%s: unexpected interrupt %lx\n", |
| 81 | __func__, status); |
| 82 | return IRQ_NONE; |
| 83 | } |
| 84 | |
| 85 | /* ack int */ |
| 86 | writel(status, priv->io + KIRKWOOD_INT_CAUSE); |
| 87 | |
| 88 | if (status & KIRKWOOD_INT_CAUSE_PLAY_BYTES) |
Russell King | a7d0942 | 2013-08-04 20:22:03 +0100 | [diff] [blame] | 89 | snd_pcm_period_elapsed(priv->substream_play); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 90 | |
| 91 | if (status & KIRKWOOD_INT_CAUSE_REC_BYTES) |
Russell King | a7d0942 | 2013-08-04 20:22:03 +0100 | [diff] [blame] | 92 | snd_pcm_period_elapsed(priv->substream_rec); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 93 | |
| 94 | return IRQ_HANDLED; |
| 95 | } |
| 96 | |
Andrew Lunn | 63a9332 | 2011-12-07 21:48:07 +0100 | [diff] [blame] | 97 | static void |
| 98 | kirkwood_dma_conf_mbus_windows(void __iomem *base, int win, |
| 99 | unsigned long dma, |
| 100 | const struct mbus_dram_target_info *dram) |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 101 | { |
| 102 | int i; |
| 103 | |
| 104 | /* First disable and clear windows */ |
| 105 | writel(0, base + KIRKWOOD_AUDIO_WIN_CTRL_REG(win)); |
| 106 | writel(0, base + KIRKWOOD_AUDIO_WIN_BASE_REG(win)); |
| 107 | |
| 108 | /* try to find matching cs for current dma address */ |
| 109 | for (i = 0; i < dram->num_cs; i++) { |
Andrew Lunn | 63a9332 | 2011-12-07 21:48:07 +0100 | [diff] [blame] | 110 | const struct mbus_dram_window *cs = dram->cs + i; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 111 | if ((cs->base & 0xffff0000) < (dma & 0xffff0000)) { |
| 112 | writel(cs->base & 0xffff0000, |
| 113 | base + KIRKWOOD_AUDIO_WIN_BASE_REG(win)); |
| 114 | writel(((cs->size - 1) & 0xffff0000) | |
| 115 | (cs->mbus_attr << 8) | |
| 116 | (dram->mbus_dram_target_id << 4) | 1, |
| 117 | base + KIRKWOOD_AUDIO_WIN_CTRL_REG(win)); |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | static int kirkwood_dma_open(struct snd_pcm_substream *substream) |
| 123 | { |
| 124 | int err; |
| 125 | struct snd_pcm_runtime *runtime = substream->runtime; |
Russell King | a7d0942 | 2013-08-04 20:22:03 +0100 | [diff] [blame] | 126 | struct kirkwood_dma_data *priv = kirkwood_priv(substream); |
Andrew Lunn | 63a9332 | 2011-12-07 21:48:07 +0100 | [diff] [blame] | 127 | const struct mbus_dram_target_info *dram; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 128 | unsigned long addr; |
| 129 | |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 130 | snd_soc_set_runtime_hwparams(substream, &kirkwood_dma_snd_hw); |
| 131 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 132 | /* Ensure that all constraints linked to dma burst are fulfilled */ |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 133 | err = snd_pcm_hw_constraint_minmax(runtime, |
| 134 | SNDRV_PCM_HW_PARAM_BUFFER_BYTES, |
| 135 | priv->burst * 2, |
| 136 | KIRKWOOD_AUDIO_BUF_MAX-1); |
| 137 | if (err < 0) |
| 138 | return err; |
| 139 | |
| 140 | err = snd_pcm_hw_constraint_step(runtime, 0, |
| 141 | SNDRV_PCM_HW_PARAM_BUFFER_BYTES, |
| 142 | priv->burst); |
| 143 | if (err < 0) |
| 144 | return err; |
| 145 | |
| 146 | err = snd_pcm_hw_constraint_step(substream->runtime, 0, |
| 147 | SNDRV_PCM_HW_PARAM_PERIOD_BYTES, |
| 148 | priv->burst); |
| 149 | if (err < 0) |
| 150 | return err; |
| 151 | |
Russell King | a7d0942 | 2013-08-04 20:22:03 +0100 | [diff] [blame] | 152 | if (!priv->substream_play && !priv->substream_rec) { |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 153 | err = request_irq(priv->irq, kirkwood_dma_irq, IRQF_SHARED, |
Russell King | a7d0942 | 2013-08-04 20:22:03 +0100 | [diff] [blame] | 154 | "kirkwood-i2s", priv); |
| 155 | if (err) |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 156 | return -EBUSY; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 157 | |
| 158 | /* |
| 159 | * Enable Error interrupts. We're only ack'ing them but |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 160 | * it's useful for diagnostics |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 161 | */ |
Vladimir Murzin | e2c9917 | 2013-09-29 16:00:13 +0200 | [diff] [blame] | 162 | writel((unsigned int)-1, priv->io + KIRKWOOD_ERR_MASK); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 163 | } |
| 164 | |
Andrew Lunn | 63a9332 | 2011-12-07 21:48:07 +0100 | [diff] [blame] | 165 | dram = mv_mbus_dram_info(); |
Russell King | ae6a5d3 | 2012-11-20 12:17:51 +0000 | [diff] [blame] | 166 | addr = substream->dma_buffer.addr; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 167 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
Russell King | a7d0942 | 2013-08-04 20:22:03 +0100 | [diff] [blame] | 168 | priv->substream_play = substream; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 169 | kirkwood_dma_conf_mbus_windows(priv->io, |
Andrew Lunn | 63a9332 | 2011-12-07 21:48:07 +0100 | [diff] [blame] | 170 | KIRKWOOD_PLAYBACK_WIN, addr, dram); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 171 | } else { |
Russell King | a7d0942 | 2013-08-04 20:22:03 +0100 | [diff] [blame] | 172 | priv->substream_rec = substream; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 173 | kirkwood_dma_conf_mbus_windows(priv->io, |
Andrew Lunn | 63a9332 | 2011-12-07 21:48:07 +0100 | [diff] [blame] | 174 | KIRKWOOD_RECORD_WIN, addr, dram); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | static int kirkwood_dma_close(struct snd_pcm_substream *substream) |
| 181 | { |
Russell King | a7d0942 | 2013-08-04 20:22:03 +0100 | [diff] [blame] | 182 | struct kirkwood_dma_data *priv = kirkwood_priv(substream); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 183 | |
Russell King | a7d0942 | 2013-08-04 20:22:03 +0100 | [diff] [blame] | 184 | if (!priv) |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 185 | return 0; |
| 186 | |
| 187 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
Russell King | a7d0942 | 2013-08-04 20:22:03 +0100 | [diff] [blame] | 188 | priv->substream_play = NULL; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 189 | else |
Russell King | a7d0942 | 2013-08-04 20:22:03 +0100 | [diff] [blame] | 190 | priv->substream_rec = NULL; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 191 | |
Russell King | a7d0942 | 2013-08-04 20:22:03 +0100 | [diff] [blame] | 192 | if (!priv->substream_play && !priv->substream_rec) { |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 193 | writel(0, priv->io + KIRKWOOD_ERR_MASK); |
Russell King | a7d0942 | 2013-08-04 20:22:03 +0100 | [diff] [blame] | 194 | free_irq(priv->irq, priv); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | return 0; |
| 198 | } |
| 199 | |
| 200 | static int kirkwood_dma_hw_params(struct snd_pcm_substream *substream, |
| 201 | struct snd_pcm_hw_params *params) |
| 202 | { |
| 203 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 204 | |
| 205 | snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer); |
| 206 | runtime->dma_bytes = params_buffer_bytes(params); |
| 207 | |
| 208 | return 0; |
| 209 | } |
| 210 | |
| 211 | static int kirkwood_dma_hw_free(struct snd_pcm_substream *substream) |
| 212 | { |
| 213 | snd_pcm_set_runtime_buffer(substream, NULL); |
| 214 | return 0; |
| 215 | } |
| 216 | |
| 217 | static int kirkwood_dma_prepare(struct snd_pcm_substream *substream) |
| 218 | { |
| 219 | struct snd_pcm_runtime *runtime = substream->runtime; |
Russell King | a7d0942 | 2013-08-04 20:22:03 +0100 | [diff] [blame] | 220 | struct kirkwood_dma_data *priv = kirkwood_priv(substream); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 221 | unsigned long size, count; |
| 222 | |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 223 | /* compute buffer size in term of "words" as requested in specs */ |
| 224 | size = frames_to_bytes(runtime, runtime->buffer_size); |
| 225 | size = (size>>2)-1; |
| 226 | count = snd_pcm_lib_period_bytes(substream); |
| 227 | |
| 228 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 229 | writel(count, priv->io + KIRKWOOD_PLAY_BYTE_INT_COUNT); |
| 230 | writel(runtime->dma_addr, priv->io + KIRKWOOD_PLAY_BUF_ADDR); |
| 231 | writel(size, priv->io + KIRKWOOD_PLAY_BUF_SIZE); |
| 232 | } else { |
| 233 | writel(count, priv->io + KIRKWOOD_REC_BYTE_INT_COUNT); |
| 234 | writel(runtime->dma_addr, priv->io + KIRKWOOD_REC_BUF_ADDR); |
| 235 | writel(size, priv->io + KIRKWOOD_REC_BUF_SIZE); |
| 236 | } |
| 237 | |
| 238 | |
| 239 | return 0; |
| 240 | } |
| 241 | |
| 242 | static snd_pcm_uframes_t kirkwood_dma_pointer(struct snd_pcm_substream |
| 243 | *substream) |
| 244 | { |
Russell King | a7d0942 | 2013-08-04 20:22:03 +0100 | [diff] [blame] | 245 | struct kirkwood_dma_data *priv = kirkwood_priv(substream); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 246 | snd_pcm_uframes_t count; |
| 247 | |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 248 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 249 | count = bytes_to_frames(substream->runtime, |
| 250 | readl(priv->io + KIRKWOOD_PLAY_BYTE_COUNT)); |
| 251 | else |
| 252 | count = bytes_to_frames(substream->runtime, |
| 253 | readl(priv->io + KIRKWOOD_REC_BYTE_COUNT)); |
| 254 | |
| 255 | return count; |
| 256 | } |
| 257 | |
Lars-Peter Clausen | 5d0c8a5 | 2013-05-14 22:19:48 +0200 | [diff] [blame] | 258 | static struct snd_pcm_ops kirkwood_dma_ops = { |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 259 | .open = kirkwood_dma_open, |
| 260 | .close = kirkwood_dma_close, |
| 261 | .ioctl = snd_pcm_lib_ioctl, |
| 262 | .hw_params = kirkwood_dma_hw_params, |
| 263 | .hw_free = kirkwood_dma_hw_free, |
| 264 | .prepare = kirkwood_dma_prepare, |
| 265 | .pointer = kirkwood_dma_pointer, |
| 266 | }; |
| 267 | |
| 268 | static int kirkwood_dma_preallocate_dma_buffer(struct snd_pcm *pcm, |
| 269 | int stream) |
| 270 | { |
| 271 | struct snd_pcm_substream *substream = pcm->streams[stream].substream; |
| 272 | struct snd_dma_buffer *buf = &substream->dma_buffer; |
| 273 | size_t size = kirkwood_dma_snd_hw.buffer_bytes_max; |
| 274 | |
| 275 | buf->dev.type = SNDRV_DMA_TYPE_DEV; |
| 276 | buf->dev.dev = pcm->card->dev; |
| 277 | buf->area = dma_alloc_coherent(pcm->card->dev, size, |
| 278 | &buf->addr, GFP_KERNEL); |
| 279 | if (!buf->area) |
| 280 | return -ENOMEM; |
| 281 | buf->bytes = size; |
| 282 | buf->private_data = NULL; |
| 283 | |
| 284 | return 0; |
| 285 | } |
| 286 | |
Liam Girdwood | 552d1ef | 2011-06-07 16:08:33 +0100 | [diff] [blame] | 287 | static int kirkwood_dma_new(struct snd_soc_pcm_runtime *rtd) |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 288 | { |
Liam Girdwood | 552d1ef | 2011-06-07 16:08:33 +0100 | [diff] [blame] | 289 | struct snd_card *card = rtd->card->snd_card; |
Liam Girdwood | 552d1ef | 2011-06-07 16:08:33 +0100 | [diff] [blame] | 290 | struct snd_pcm *pcm = rtd->pcm; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 291 | int ret; |
| 292 | |
| 293 | if (!card->dev->dma_mask) |
| 294 | card->dev->dma_mask = &kirkwood_dma_dmamask; |
| 295 | if (!card->dev->coherent_dma_mask) |
Joachim Eastwood | 350e16d | 2012-01-01 02:43:03 +0100 | [diff] [blame] | 296 | card->dev->coherent_dma_mask = DMA_BIT_MASK(32); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 297 | |
Joachim Eastwood | 25e9e75 | 2012-01-01 01:58:44 +0100 | [diff] [blame] | 298 | if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) { |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 299 | ret = kirkwood_dma_preallocate_dma_buffer(pcm, |
| 300 | SNDRV_PCM_STREAM_PLAYBACK); |
| 301 | if (ret) |
| 302 | return ret; |
| 303 | } |
| 304 | |
Joachim Eastwood | 25e9e75 | 2012-01-01 01:58:44 +0100 | [diff] [blame] | 305 | if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) { |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 306 | ret = kirkwood_dma_preallocate_dma_buffer(pcm, |
| 307 | SNDRV_PCM_STREAM_CAPTURE); |
| 308 | if (ret) |
| 309 | return ret; |
| 310 | } |
| 311 | |
| 312 | return 0; |
| 313 | } |
| 314 | |
| 315 | static void kirkwood_dma_free_dma_buffers(struct snd_pcm *pcm) |
| 316 | { |
| 317 | struct snd_pcm_substream *substream; |
| 318 | struct snd_dma_buffer *buf; |
| 319 | int stream; |
| 320 | |
| 321 | for (stream = 0; stream < 2; stream++) { |
| 322 | substream = pcm->streams[stream].substream; |
| 323 | if (!substream) |
| 324 | continue; |
| 325 | buf = &substream->dma_buffer; |
| 326 | if (!buf->area) |
| 327 | continue; |
| 328 | |
| 329 | dma_free_coherent(pcm->card->dev, buf->bytes, |
| 330 | buf->area, buf->addr); |
| 331 | buf->area = NULL; |
| 332 | } |
| 333 | } |
| 334 | |
Russell King | 64ddf1f | 2013-08-04 20:27:03 +0100 | [diff] [blame] | 335 | struct snd_soc_platform_driver kirkwood_soc_platform = { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 336 | .ops = &kirkwood_dma_ops, |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 337 | .pcm_new = kirkwood_dma_new, |
| 338 | .pcm_free = kirkwood_dma_free_dma_buffers, |
| 339 | }; |