blob: 6ebbc888551869f2951ff404b02287dada3f4748 [file] [log] [blame]
Vladimir Barinov310355c2008-02-18 11:40:22 +01001/*
2 * ALSA PCM interface for the TI DAVINCI processor
3 *
Vladimir Barinovd6b52032008-09-29 23:14:11 +04004 * Author: Vladimir Barinov, <vbarinov@embeddedalley.com>
Vladimir Barinov310355c2008-02-18 11:40:22 +01005 * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com>
Troy Kisky1e224f32009-11-18 17:49:53 -07006 * added SRAM ping/pong (C) 2008 Troy Kisky <troy.kisky@boundarydevices.com>
Vladimir Barinov310355c2008-02-18 11:40:22 +01007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/platform_device.h>
16#include <linux/slab.h>
17#include <linux/dma-mapping.h>
Alexander Beregalov9cd28ab2008-12-13 16:25:27 +030018#include <linux/kernel.h>
Vladimir Barinov310355c2008-02-18 11:40:22 +010019
20#include <sound/core.h>
21#include <sound/pcm.h>
22#include <sound/pcm_params.h>
23#include <sound/soc.h>
24
25#include <asm/dma.h>
Troy Kisky1e224f32009-11-18 17:49:53 -070026#include <mach/sram.h>
Vladimir Barinov310355c2008-02-18 11:40:22 +010027
28#include "davinci-pcm.h"
29
Troy Kisky1e224f32009-11-18 17:49:53 -070030#ifdef DEBUG
31static void print_buf_info(int slot, char *name)
32{
33 struct edmacc_param p;
34 if (slot < 0)
35 return;
36 edma_read_slot(slot, &p);
37 printk(KERN_DEBUG "%s: 0x%x, opt=%x, src=%x, a_b_cnt=%x dst=%x\n",
38 name, slot, p.opt, p.src, p.a_b_cnt, p.dst);
39 printk(KERN_DEBUG " src_dst_bidx=%x link_bcntrld=%x src_dst_cidx=%x ccnt=%x\n",
40 p.src_dst_bidx, p.link_bcntrld, p.src_dst_cidx, p.ccnt);
41}
42#else
43static void print_buf_info(int slot, char *name)
44{
45}
46#endif
47
Ben Gardiner8e56d5b2011-05-24 14:50:16 -040048#define DAVINCI_PCM_FMTBITS (\
49 SNDRV_PCM_FMTBIT_S8 |\
50 SNDRV_PCM_FMTBIT_U8 |\
51 SNDRV_PCM_FMTBIT_S16_LE |\
52 SNDRV_PCM_FMTBIT_S16_BE |\
53 SNDRV_PCM_FMTBIT_U16_LE |\
54 SNDRV_PCM_FMTBIT_U16_BE |\
55 SNDRV_PCM_FMTBIT_S24_LE |\
56 SNDRV_PCM_FMTBIT_S24_BE |\
57 SNDRV_PCM_FMTBIT_U24_LE |\
58 SNDRV_PCM_FMTBIT_U24_BE |\
59 SNDRV_PCM_FMTBIT_S32_LE |\
60 SNDRV_PCM_FMTBIT_S32_BE |\
61 SNDRV_PCM_FMTBIT_U32_LE |\
62 SNDRV_PCM_FMTBIT_U32_BE)
63
Troy Kisky1e224f32009-11-18 17:49:53 -070064static struct snd_pcm_hardware pcm_hardware_playback = {
Vladimir Barinov310355c2008-02-18 11:40:22 +010065 .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
66 SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID |
Ben Gardiner52e2c5d2011-05-24 14:50:20 -040067 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME|
68 SNDRV_PCM_INFO_BATCH),
Ben Gardiner8e56d5b2011-05-24 14:50:16 -040069 .formats = DAVINCI_PCM_FMTBITS,
Daniel Mack393a53c2012-10-04 15:08:38 +020070 .rates = SNDRV_PCM_RATE_8000_192000 | SNDRV_PCM_RATE_KNOT,
Vladimir Barinov310355c2008-02-18 11:40:22 +010071 .rate_min = 8000,
Daniel Mack393a53c2012-10-04 15:08:38 +020072 .rate_max = 192000,
Vladimir Barinov310355c2008-02-18 11:40:22 +010073 .channels_min = 2,
Ben Gardineracb8e262011-05-24 14:50:17 -040074 .channels_max = 384,
Vladimir Barinov310355c2008-02-18 11:40:22 +010075 .buffer_bytes_max = 128 * 1024,
76 .period_bytes_min = 32,
77 .period_bytes_max = 8 * 1024,
78 .periods_min = 16,
79 .periods_max = 255,
80 .fifo_size = 0,
81};
82
Troy Kisky1e224f32009-11-18 17:49:53 -070083static struct snd_pcm_hardware pcm_hardware_capture = {
84 .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
85 SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID |
Ben Gardiner52e2c5d2011-05-24 14:50:20 -040086 SNDRV_PCM_INFO_PAUSE |
87 SNDRV_PCM_INFO_BATCH),
Ben Gardiner8e56d5b2011-05-24 14:50:16 -040088 .formats = DAVINCI_PCM_FMTBITS,
Daniel Mack393a53c2012-10-04 15:08:38 +020089 .rates = SNDRV_PCM_RATE_8000_192000 | SNDRV_PCM_RATE_KNOT,
Troy Kisky1e224f32009-11-18 17:49:53 -070090 .rate_min = 8000,
Daniel Mack393a53c2012-10-04 15:08:38 +020091 .rate_max = 192000,
Troy Kisky1e224f32009-11-18 17:49:53 -070092 .channels_min = 2,
Ben Gardineracb8e262011-05-24 14:50:17 -040093 .channels_max = 384,
Troy Kisky1e224f32009-11-18 17:49:53 -070094 .buffer_bytes_max = 128 * 1024,
95 .period_bytes_min = 32,
96 .period_bytes_max = 8 * 1024,
97 .periods_min = 16,
98 .periods_max = 255,
99 .fifo_size = 0,
100};
101
102/*
103 * How ping/pong works....
104 *
105 * Playback:
106 * ram_params - copys 2*ping_size from start of SDRAM to iram,
107 * links to ram_link2
108 * ram_link2 - copys rest of SDRAM to iram in ping_size units,
109 * links to ram_link
110 * ram_link - copys entire SDRAM to iram in ping_size uints,
111 * links to self
112 *
113 * asp_params - same as asp_link[0]
114 * asp_link[0] - copys from lower half of iram to asp port
115 * links to asp_link[1], triggers iram copy event on completion
116 * asp_link[1] - copys from upper half of iram to asp port
117 * links to asp_link[0], triggers iram copy event on completion
118 * triggers interrupt only needed to let upper SOC levels update position
119 * in stream on completion
120 *
121 * When playback is started:
122 * ram_params started
123 * asp_params started
124 *
125 * Capture:
126 * ram_params - same as ram_link,
127 * links to ram_link
128 * ram_link - same as playback
129 * links to self
130 *
131 * asp_params - same as playback
132 * asp_link[0] - same as playback
133 * asp_link[1] - same as playback
134 *
135 * When capture is started:
136 * asp_params started
137 */
Vladimir Barinov310355c2008-02-18 11:40:22 +0100138struct davinci_runtime_data {
139 spinlock_t lock;
140 int period; /* current DMA period */
Troy Kisky1587ea312009-11-18 17:49:52 -0700141 int asp_channel; /* Master DMA channel */
142 int asp_link[2]; /* asp parameter link channel, ping/pong */
Vladimir Barinov310355c2008-02-18 11:40:22 +0100143 struct davinci_pcm_dma_params *params; /* DMA params */
Troy Kisky1e224f32009-11-18 17:49:53 -0700144 int ram_channel;
145 int ram_link;
146 int ram_link2;
147 struct edmacc_param asp_params;
148 struct edmacc_param ram_params;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100149};
150
Ben Gardiner10ab3bf2011-05-24 14:50:19 -0400151static void davinci_pcm_period_elapsed(struct snd_pcm_substream *substream)
152{
153 struct davinci_runtime_data *prtd = substream->runtime->private_data;
154 struct snd_pcm_runtime *runtime = substream->runtime;
155
156 prtd->period++;
157 if (unlikely(prtd->period >= runtime->periods))
158 prtd->period = 0;
159}
160
161static void davinci_pcm_period_reset(struct snd_pcm_substream *substream)
162{
163 struct davinci_runtime_data *prtd = substream->runtime->private_data;
164
165 prtd->period = 0;
166}
Troy Kisky1e224f32009-11-18 17:49:53 -0700167/*
168 * Not used with ping/pong
169 */
Vladimir Barinov310355c2008-02-18 11:40:22 +0100170static void davinci_pcm_enqueue_dma(struct snd_pcm_substream *substream)
171{
172 struct davinci_runtime_data *prtd = substream->runtime->private_data;
173 struct snd_pcm_runtime *runtime = substream->runtime;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100174 unsigned int period_size;
175 unsigned int dma_offset;
176 dma_addr_t dma_pos;
177 dma_addr_t src, dst;
178 unsigned short src_bidx, dst_bidx;
Chaithrika U S4fa9c1a2009-09-30 17:32:27 -0400179 unsigned short src_cidx, dst_cidx;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100180 unsigned int data_type;
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400181 unsigned short acnt;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100182 unsigned int count;
Chaithrika U S4fa9c1a2009-09-30 17:32:27 -0400183 unsigned int fifo_level;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100184
185 period_size = snd_pcm_lib_period_bytes(substream);
186 dma_offset = prtd->period * period_size;
187 dma_pos = runtime->dma_addr + dma_offset;
Chaithrika U S4fa9c1a2009-09-30 17:32:27 -0400188 fifo_level = prtd->params->fifo_level;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100189
Alexander Beregalov9cd28ab2008-12-13 16:25:27 +0300190 pr_debug("davinci_pcm: audio_set_dma_params_play channel = %d "
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400191 "dma_ptr = %x period_size=%x\n", prtd->asp_link[0], dma_pos,
192 period_size);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100193
194 data_type = prtd->params->data_type;
195 count = period_size / data_type;
Chaithrika U S4fa9c1a2009-09-30 17:32:27 -0400196 if (fifo_level)
197 count /= fifo_level;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100198
199 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
200 src = dma_pos;
201 dst = prtd->params->dma_addr;
202 src_bidx = data_type;
203 dst_bidx = 0;
Chaithrika U S4fa9c1a2009-09-30 17:32:27 -0400204 src_cidx = data_type * fifo_level;
205 dst_cidx = 0;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100206 } else {
207 src = prtd->params->dma_addr;
208 dst = dma_pos;
209 src_bidx = 0;
210 dst_bidx = data_type;
Chaithrika U S4fa9c1a2009-09-30 17:32:27 -0400211 src_cidx = 0;
212 dst_cidx = data_type * fifo_level;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100213 }
214
Chaithrika U S6a99fb52009-08-11 16:58:52 -0400215 acnt = prtd->params->acnt;
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400216 edma_set_src(prtd->asp_link[0], src, INCR, W8BIT);
217 edma_set_dest(prtd->asp_link[0], dst, INCR, W8BIT);
Chaithrika U S4fa9c1a2009-09-30 17:32:27 -0400218
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400219 edma_set_src_index(prtd->asp_link[0], src_bidx, src_cidx);
220 edma_set_dest_index(prtd->asp_link[0], dst_bidx, dst_cidx);
Chaithrika U S4fa9c1a2009-09-30 17:32:27 -0400221
222 if (!fifo_level)
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400223 edma_set_transfer_params(prtd->asp_link[0], acnt, count, 1, 0,
224 ASYNC);
Chaithrika U S4fa9c1a2009-09-30 17:32:27 -0400225 else
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400226 edma_set_transfer_params(prtd->asp_link[0], acnt, fifo_level,
227 count, fifo_level,
228 ABSYNC);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100229}
230
Troy Kisky1587ea312009-11-18 17:49:52 -0700231static void davinci_pcm_dma_irq(unsigned link, u16 ch_status, void *data)
Vladimir Barinov310355c2008-02-18 11:40:22 +0100232{
233 struct snd_pcm_substream *substream = data;
234 struct davinci_runtime_data *prtd = substream->runtime->private_data;
235
Troy Kisky1e224f32009-11-18 17:49:53 -0700236 print_buf_info(prtd->ram_channel, "i ram_channel");
Troy Kisky1587ea312009-11-18 17:49:52 -0700237 pr_debug("davinci_pcm: link=%d, status=0x%x\n", link, ch_status);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100238
239 if (unlikely(ch_status != DMA_COMPLETE))
240 return;
241
242 if (snd_pcm_running(substream)) {
Ben Gardiner52e2c5d2011-05-24 14:50:20 -0400243 spin_lock(&prtd->lock);
Troy Kisky1e224f32009-11-18 17:49:53 -0700244 if (prtd->ram_channel < 0) {
245 /* No ping/pong must fix up link dma data*/
Troy Kisky1e224f32009-11-18 17:49:53 -0700246 davinci_pcm_enqueue_dma(substream);
Troy Kisky1e224f32009-11-18 17:49:53 -0700247 }
Ben Gardiner52e2c5d2011-05-24 14:50:20 -0400248 davinci_pcm_period_elapsed(substream);
249 spin_unlock(&prtd->lock);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100250 snd_pcm_period_elapsed(substream);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100251 }
252}
253
Troy Kisky1e224f32009-11-18 17:49:53 -0700254static int allocate_sram(struct snd_pcm_substream *substream, unsigned size,
255 struct snd_pcm_hardware *ppcm)
256{
257 struct snd_dma_buffer *buf = &substream->dma_buffer;
258 struct snd_dma_buffer *iram_dma = NULL;
259 dma_addr_t iram_phys = 0;
260 void *iram_virt = NULL;
261
262 if (buf->private_data || !size)
263 return 0;
264
265 ppcm->period_bytes_max = size;
266 iram_virt = sram_alloc(size, &iram_phys);
267 if (!iram_virt)
268 goto exit1;
269 iram_dma = kzalloc(sizeof(*iram_dma), GFP_KERNEL);
270 if (!iram_dma)
271 goto exit2;
272 iram_dma->area = iram_virt;
273 iram_dma->addr = iram_phys;
274 memset(iram_dma->area, 0, size);
275 iram_dma->bytes = size;
276 buf->private_data = iram_dma;
277 return 0;
278exit2:
279 if (iram_virt)
280 sram_free(iram_virt, size);
281exit1:
282 return -ENOMEM;
283}
284
285/*
286 * Only used with ping/pong.
287 * This is called after runtime->dma_addr, period_bytes and data_type are valid
288 */
289static int ping_pong_dma_setup(struct snd_pcm_substream *substream)
290{
291 unsigned short ram_src_cidx, ram_dst_cidx;
292 struct snd_pcm_runtime *runtime = substream->runtime;
293 struct davinci_runtime_data *prtd = runtime->private_data;
294 struct snd_dma_buffer *iram_dma =
295 (struct snd_dma_buffer *)substream->dma_buffer.private_data;
296 struct davinci_pcm_dma_params *params = prtd->params;
297 unsigned int data_type = params->data_type;
298 unsigned int acnt = params->acnt;
299 /* divide by 2 for ping/pong */
300 unsigned int ping_size = snd_pcm_lib_period_bytes(substream) >> 1;
Troy Kisky1e224f32009-11-18 17:49:53 -0700301 unsigned int fifo_level = prtd->params->fifo_level;
302 unsigned int count;
303 if ((data_type == 0) || (data_type > 4)) {
304 printk(KERN_ERR "%s: data_type=%i\n", __func__, data_type);
305 return -EINVAL;
306 }
307 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
308 dma_addr_t asp_src_pong = iram_dma->addr + ping_size;
309 ram_src_cidx = ping_size;
310 ram_dst_cidx = -ping_size;
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400311 edma_set_src(prtd->asp_link[1], asp_src_pong, INCR, W8BIT);
Troy Kisky1e224f32009-11-18 17:49:53 -0700312
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400313 edma_set_src_index(prtd->asp_link[0], data_type,
314 data_type * fifo_level);
315 edma_set_src_index(prtd->asp_link[1], data_type,
316 data_type * fifo_level);
Troy Kisky1e224f32009-11-18 17:49:53 -0700317
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400318 edma_set_src(prtd->ram_link, runtime->dma_addr, INCR, W32BIT);
Troy Kisky1e224f32009-11-18 17:49:53 -0700319 } else {
320 dma_addr_t asp_dst_pong = iram_dma->addr + ping_size;
321 ram_src_cidx = -ping_size;
322 ram_dst_cidx = ping_size;
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400323 edma_set_dest(prtd->asp_link[1], asp_dst_pong, INCR, W8BIT);
Troy Kisky1e224f32009-11-18 17:49:53 -0700324
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400325 edma_set_dest_index(prtd->asp_link[0], data_type,
326 data_type * fifo_level);
327 edma_set_dest_index(prtd->asp_link[1], data_type,
328 data_type * fifo_level);
Troy Kisky1e224f32009-11-18 17:49:53 -0700329
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400330 edma_set_dest(prtd->ram_link, runtime->dma_addr, INCR, W32BIT);
Troy Kisky1e224f32009-11-18 17:49:53 -0700331 }
332
333 if (!fifo_level) {
334 count = ping_size / data_type;
335 edma_set_transfer_params(prtd->asp_link[0], acnt, count,
336 1, 0, ASYNC);
337 edma_set_transfer_params(prtd->asp_link[1], acnt, count,
338 1, 0, ASYNC);
339 } else {
340 count = ping_size / (data_type * fifo_level);
341 edma_set_transfer_params(prtd->asp_link[0], acnt, fifo_level,
342 count, fifo_level, ABSYNC);
343 edma_set_transfer_params(prtd->asp_link[1], acnt, fifo_level,
344 count, fifo_level, ABSYNC);
345 }
346
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400347 edma_set_src_index(prtd->ram_link, ping_size, ram_src_cidx);
348 edma_set_dest_index(prtd->ram_link, ping_size, ram_dst_cidx);
349 edma_set_transfer_params(prtd->ram_link, ping_size, 2,
Troy Kisky1e224f32009-11-18 17:49:53 -0700350 runtime->periods, 2, ASYNC);
351
352 /* init master params */
353 edma_read_slot(prtd->asp_link[0], &prtd->asp_params);
354 edma_read_slot(prtd->ram_link, &prtd->ram_params);
355 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
356 struct edmacc_param p_ram;
357 /* Copy entire iram buffer before playback started */
358 prtd->ram_params.a_b_cnt = (1 << 16) | (ping_size << 1);
359 /* 0 dst_bidx */
360 prtd->ram_params.src_dst_bidx = (ping_size << 1);
361 /* 0 dst_cidx */
362 prtd->ram_params.src_dst_cidx = (ping_size << 1);
363 prtd->ram_params.ccnt = 1;
364
365 /* Skip 1st period */
366 edma_read_slot(prtd->ram_link, &p_ram);
367 p_ram.src += (ping_size << 1);
368 p_ram.ccnt -= 1;
369 edma_write_slot(prtd->ram_link2, &p_ram);
370 /*
371 * When 1st started, ram -> iram dma channel will fill the
372 * entire iram. Then, whenever a ping/pong asp buffer finishes,
373 * 1/2 iram will be filled.
374 */
375 prtd->ram_params.link_bcntrld =
376 EDMA_CHAN_SLOT(prtd->ram_link2) << 5;
377 }
378 return 0;
379}
380
381/* 1 asp tx or rx channel using 2 parameter channels
382 * 1 ram to/from iram channel using 1 parameter channel
383 *
384 * Playback
385 * ram copy channel kicks off first,
386 * 1st ram copy of entire iram buffer completion kicks off asp channel
387 * asp tcc always kicks off ram copy of 1/2 iram buffer
388 *
389 * Record
390 * asp channel starts, tcc kicks off ram copy
391 */
392static int request_ping_pong(struct snd_pcm_substream *substream,
393 struct davinci_runtime_data *prtd,
394 struct snd_dma_buffer *iram_dma)
395{
396 dma_addr_t asp_src_ping;
397 dma_addr_t asp_dst_ping;
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400398 int ret;
Troy Kisky1e224f32009-11-18 17:49:53 -0700399 struct davinci_pcm_dma_params *params = prtd->params;
400
401 /* Request ram master channel */
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400402 ret = prtd->ram_channel = edma_alloc_channel(EDMA_CHANNEL_ANY,
Troy Kisky1e224f32009-11-18 17:49:53 -0700403 davinci_pcm_dma_irq, substream,
Sekhar Nori48519f02010-07-19 12:31:16 +0530404 prtd->params->ram_chan_q);
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400405 if (ret < 0)
Troy Kisky1e224f32009-11-18 17:49:53 -0700406 goto exit1;
407
408 /* Request ram link channel */
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400409 ret = prtd->ram_link = edma_alloc_slot(
Troy Kisky1e224f32009-11-18 17:49:53 -0700410 EDMA_CTLR(prtd->ram_channel), EDMA_SLOT_ANY);
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400411 if (ret < 0)
Troy Kisky1e224f32009-11-18 17:49:53 -0700412 goto exit2;
413
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400414 ret = prtd->asp_link[1] = edma_alloc_slot(
Troy Kisky1e224f32009-11-18 17:49:53 -0700415 EDMA_CTLR(prtd->asp_channel), EDMA_SLOT_ANY);
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400416 if (ret < 0)
Troy Kisky1e224f32009-11-18 17:49:53 -0700417 goto exit3;
418
419 prtd->ram_link2 = -1;
420 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400421 ret = prtd->ram_link2 = edma_alloc_slot(
Troy Kisky1e224f32009-11-18 17:49:53 -0700422 EDMA_CTLR(prtd->ram_channel), EDMA_SLOT_ANY);
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400423 if (ret < 0)
Troy Kisky1e224f32009-11-18 17:49:53 -0700424 goto exit4;
425 }
426 /* circle ping-pong buffers */
427 edma_link(prtd->asp_link[0], prtd->asp_link[1]);
428 edma_link(prtd->asp_link[1], prtd->asp_link[0]);
429 /* circle ram buffers */
430 edma_link(prtd->ram_link, prtd->ram_link);
431
432 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
433 asp_src_ping = iram_dma->addr;
434 asp_dst_ping = params->dma_addr; /* fifo */
435 } else {
436 asp_src_ping = params->dma_addr; /* fifo */
437 asp_dst_ping = iram_dma->addr;
438 }
439 /* ping */
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400440 edma_set_src(prtd->asp_link[0], asp_src_ping, INCR, W16BIT);
441 edma_set_dest(prtd->asp_link[0], asp_dst_ping, INCR, W16BIT);
442 edma_set_src_index(prtd->asp_link[0], 0, 0);
443 edma_set_dest_index(prtd->asp_link[0], 0, 0);
Troy Kisky1e224f32009-11-18 17:49:53 -0700444
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400445 edma_read_slot(prtd->asp_link[0], &prtd->asp_params);
Troy Kisky1e224f32009-11-18 17:49:53 -0700446 prtd->asp_params.opt &= ~(TCCMODE | EDMA_TCC(0x3f) | TCINTEN);
Ben Gardinerfb1e97032011-05-24 14:50:15 -0400447 prtd->asp_params.opt |= TCCHEN |
448 EDMA_TCC(prtd->ram_channel & 0x3f);
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400449 edma_write_slot(prtd->asp_link[0], &prtd->asp_params);
Troy Kisky1e224f32009-11-18 17:49:53 -0700450
451 /* pong */
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400452 edma_set_src(prtd->asp_link[1], asp_src_ping, INCR, W16BIT);
453 edma_set_dest(prtd->asp_link[1], asp_dst_ping, INCR, W16BIT);
454 edma_set_src_index(prtd->asp_link[1], 0, 0);
455 edma_set_dest_index(prtd->asp_link[1], 0, 0);
Troy Kisky1e224f32009-11-18 17:49:53 -0700456
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400457 edma_read_slot(prtd->asp_link[1], &prtd->asp_params);
Troy Kisky1e224f32009-11-18 17:49:53 -0700458 prtd->asp_params.opt &= ~(TCCMODE | EDMA_TCC(0x3f));
459 /* interrupt after every pong completion */
460 prtd->asp_params.opt |= TCINTEN | TCCHEN |
Ben Gardinerfb1e97032011-05-24 14:50:15 -0400461 EDMA_TCC(prtd->ram_channel & 0x3f);
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400462 edma_write_slot(prtd->asp_link[1], &prtd->asp_params);
Troy Kisky1e224f32009-11-18 17:49:53 -0700463
464 /* ram */
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400465 edma_set_src(prtd->ram_link, iram_dma->addr, INCR, W32BIT);
466 edma_set_dest(prtd->ram_link, iram_dma->addr, INCR, W32BIT);
Troy Kisky1e224f32009-11-18 17:49:53 -0700467 pr_debug("%s: audio dma channels/slots in use for ram:%u %u %u,"
468 "for asp:%u %u %u\n", __func__,
469 prtd->ram_channel, prtd->ram_link, prtd->ram_link2,
470 prtd->asp_channel, prtd->asp_link[0],
471 prtd->asp_link[1]);
472 return 0;
473exit4:
474 edma_free_channel(prtd->asp_link[1]);
475 prtd->asp_link[1] = -1;
476exit3:
477 edma_free_channel(prtd->ram_link);
478 prtd->ram_link = -1;
479exit2:
480 edma_free_channel(prtd->ram_channel);
481 prtd->ram_channel = -1;
482exit1:
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400483 return ret;
Troy Kisky1e224f32009-11-18 17:49:53 -0700484}
485
Vladimir Barinov310355c2008-02-18 11:40:22 +0100486static int davinci_pcm_dma_request(struct snd_pcm_substream *substream)
487{
Troy Kisky1e224f32009-11-18 17:49:53 -0700488 struct snd_dma_buffer *iram_dma;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100489 struct davinci_runtime_data *prtd = substream->runtime->private_data;
Troy Kisky1e224f32009-11-18 17:49:53 -0700490 struct davinci_pcm_dma_params *params = prtd->params;
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400491 int ret;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100492
Troy Kisky1e224f32009-11-18 17:49:53 -0700493 if (!params)
494 return -ENODEV;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100495
Troy Kisky1e224f32009-11-18 17:49:53 -0700496 /* Request asp master DMA channel */
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400497 ret = prtd->asp_channel = edma_alloc_channel(params->channel,
Sekhar Nori48519f02010-07-19 12:31:16 +0530498 davinci_pcm_dma_irq, substream,
499 prtd->params->asp_chan_q);
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400500 if (ret < 0)
Troy Kisky1e224f32009-11-18 17:49:53 -0700501 goto exit1;
502
503 /* Request asp link channels */
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400504 ret = prtd->asp_link[0] = edma_alloc_slot(
Troy Kisky1e224f32009-11-18 17:49:53 -0700505 EDMA_CTLR(prtd->asp_channel), EDMA_SLOT_ANY);
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400506 if (ret < 0)
Troy Kisky1e224f32009-11-18 17:49:53 -0700507 goto exit2;
508
509 iram_dma = (struct snd_dma_buffer *)substream->dma_buffer.private_data;
510 if (iram_dma) {
511 if (request_ping_pong(substream, prtd, iram_dma) == 0)
512 return 0;
513 printk(KERN_WARNING "%s: dma channel allocation failed,"
514 "not using sram\n", __func__);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100515 }
516
David Brownell82075af2009-05-14 12:41:22 -0700517 /* Issue transfer completion IRQ when the channel completes a
518 * transfer, then always reload from the same slot (by a kind
519 * of loopback link). The completion IRQ handler will update
520 * the reload slot with a new buffer.
521 *
522 * REVISIT save p_ram here after setting up everything except
523 * the buffer and its length (ccnt) ... use it as a template
524 * so davinci_pcm_enqueue_dma() takes less time in IRQ.
525 */
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400526 edma_read_slot(prtd->asp_link[0], &prtd->asp_params);
Troy Kisky1e224f32009-11-18 17:49:53 -0700527 prtd->asp_params.opt |= TCINTEN |
528 EDMA_TCC(EDMA_CHAN_SLOT(prtd->asp_channel));
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400529 prtd->asp_params.link_bcntrld = EDMA_CHAN_SLOT(prtd->asp_link[0]) << 5;
530 edma_write_slot(prtd->asp_link[0], &prtd->asp_params);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100531 return 0;
Troy Kisky1e224f32009-11-18 17:49:53 -0700532exit2:
533 edma_free_channel(prtd->asp_channel);
534 prtd->asp_channel = -1;
535exit1:
Ben Gardinerbe4ff962011-09-09 17:06:05 -0400536 return ret;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100537}
538
539static int davinci_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
540{
541 struct davinci_runtime_data *prtd = substream->runtime->private_data;
542 int ret = 0;
543
544 spin_lock(&prtd->lock);
545
546 switch (cmd) {
547 case SNDRV_PCM_TRIGGER_START:
Ben Gardineref39eb62011-05-24 14:50:18 -0400548 edma_start(prtd->asp_channel);
549 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
550 prtd->ram_channel >= 0) {
551 /* copy 1st iram buffer */
552 edma_start(prtd->ram_channel);
553 }
554 break;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100555 case SNDRV_PCM_TRIGGER_RESUME:
556 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
Troy Kisky2b7b2502009-11-18 17:49:54 -0700557 edma_resume(prtd->asp_channel);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100558 break;
559 case SNDRV_PCM_TRIGGER_STOP:
560 case SNDRV_PCM_TRIGGER_SUSPEND:
561 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
Troy Kisky2b7b2502009-11-18 17:49:54 -0700562 edma_pause(prtd->asp_channel);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100563 break;
564 default:
565 ret = -EINVAL;
566 break;
567 }
568
569 spin_unlock(&prtd->lock);
570
571 return ret;
572}
573
574static int davinci_pcm_prepare(struct snd_pcm_substream *substream)
575{
576 struct davinci_runtime_data *prtd = substream->runtime->private_data;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100577
Ben Gardiner52e2c5d2011-05-24 14:50:20 -0400578 davinci_pcm_period_reset(substream);
Troy Kisky1e224f32009-11-18 17:49:53 -0700579 if (prtd->ram_channel >= 0) {
580 int ret = ping_pong_dma_setup(substream);
581 if (ret < 0)
582 return ret;
583
584 edma_write_slot(prtd->ram_channel, &prtd->ram_params);
585 edma_write_slot(prtd->asp_channel, &prtd->asp_params);
586
587 print_buf_info(prtd->ram_channel, "ram_channel");
588 print_buf_info(prtd->ram_link, "ram_link");
589 print_buf_info(prtd->ram_link2, "ram_link2");
590 print_buf_info(prtd->asp_channel, "asp_channel");
591 print_buf_info(prtd->asp_link[0], "asp_link[0]");
592 print_buf_info(prtd->asp_link[1], "asp_link[1]");
593
Ben Gardinerbb5b5fd2011-05-25 09:27:22 -0400594 /*
595 * There is a phase offset of 2 periods between the position
596 * used by dma setup and the position reported in the pointer
597 * function.
598 *
599 * The phase offset, when not using ping-pong buffers, is due to
600 * the two consecutive calls to davinci_pcm_enqueue_dma() below.
601 *
602 * Whereas here, with ping-pong buffers, the phase is due to
603 * there being an entire buffer transfer complete before the
604 * first dma completion event triggers davinci_pcm_dma_irq().
605 */
Ben Gardiner52e2c5d2011-05-24 14:50:20 -0400606 davinci_pcm_period_elapsed(substream);
607 davinci_pcm_period_elapsed(substream);
608
Troy Kisky1e224f32009-11-18 17:49:53 -0700609 return 0;
610 }
Vladimir Barinov310355c2008-02-18 11:40:22 +0100611 davinci_pcm_enqueue_dma(substream);
Ben Gardiner52e2c5d2011-05-24 14:50:20 -0400612 davinci_pcm_period_elapsed(substream);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100613
David Brownell82075af2009-05-14 12:41:22 -0700614 /* Copy self-linked parameter RAM entry into master channel */
Troy Kisky1e224f32009-11-18 17:49:53 -0700615 edma_read_slot(prtd->asp_link[0], &prtd->asp_params);
616 edma_write_slot(prtd->asp_channel, &prtd->asp_params);
Troy Kisky6e541472009-07-07 17:36:06 -0700617 davinci_pcm_enqueue_dma(substream);
Ben Gardiner52e2c5d2011-05-24 14:50:20 -0400618 davinci_pcm_period_elapsed(substream);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100619
620 return 0;
621}
622
623static snd_pcm_uframes_t
624davinci_pcm_pointer(struct snd_pcm_substream *substream)
625{
626 struct snd_pcm_runtime *runtime = substream->runtime;
627 struct davinci_runtime_data *prtd = runtime->private_data;
628 unsigned int offset;
Troy Kisky1587ea312009-11-18 17:49:52 -0700629 int asp_count;
Ben Gardiner52e2c5d2011-05-24 14:50:20 -0400630 unsigned int period_size = snd_pcm_lib_period_bytes(substream);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100631
Ben Gardinerbb5b5fd2011-05-25 09:27:22 -0400632 /*
633 * There is a phase offset of 2 periods between the position used by dma
634 * setup and the position reported in the pointer function. Either +2 in
635 * the dma setup or -2 here in the pointer function (with wrapping,
636 * both) accounts for this offset -- choose the latter since it makes
637 * the first-time setup clearer.
638 */
Vladimir Barinov310355c2008-02-18 11:40:22 +0100639 spin_lock(&prtd->lock);
Ben Gardiner52e2c5d2011-05-24 14:50:20 -0400640 asp_count = prtd->period - 2;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100641 spin_unlock(&prtd->lock);
642
Ben Gardiner52e2c5d2011-05-24 14:50:20 -0400643 if (asp_count < 0)
644 asp_count += runtime->periods;
645 asp_count *= period_size;
646
Troy Kisky1587ea312009-11-18 17:49:52 -0700647 offset = bytes_to_frames(runtime, asp_count);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100648 if (offset >= runtime->buffer_size)
649 offset = 0;
650
651 return offset;
652}
653
654static int davinci_pcm_open(struct snd_pcm_substream *substream)
655{
656 struct snd_pcm_runtime *runtime = substream->runtime;
657 struct davinci_runtime_data *prtd;
Troy Kisky1e224f32009-11-18 17:49:53 -0700658 struct snd_pcm_hardware *ppcm;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100659 int ret = 0;
Troy Kisky81ac55a2009-09-11 14:29:02 -0700660 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Daniel Mack5f712b22010-03-22 10:11:15 +0100661 struct davinci_pcm_dma_params *pa;
Troy Kisky57512c62009-11-16 16:52:31 -0700662 struct davinci_pcm_dma_params *params;
Daniel Mack5f712b22010-03-22 10:11:15 +0100663
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000664 pa = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
Troy Kisky57512c62009-11-16 16:52:31 -0700665 if (!pa)
Troy Kisky81ac55a2009-09-11 14:29:02 -0700666 return -ENODEV;
Troy Kisky57512c62009-11-16 16:52:31 -0700667 params = &pa[substream->stream];
Vladimir Barinov310355c2008-02-18 11:40:22 +0100668
Troy Kisky1e224f32009-11-18 17:49:53 -0700669 ppcm = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
670 &pcm_hardware_playback : &pcm_hardware_capture;
671 allocate_sram(substream, params->sram_size, ppcm);
672 snd_soc_set_runtime_hwparams(substream, ppcm);
Troy Kisky6a90d532009-08-06 16:55:32 -0700673 /* ensure that buffer size is a multiple of period size */
674 ret = snd_pcm_hw_constraint_integer(runtime,
675 SNDRV_PCM_HW_PARAM_PERIODS);
676 if (ret < 0)
677 return ret;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100678
679 prtd = kzalloc(sizeof(struct davinci_runtime_data), GFP_KERNEL);
680 if (prtd == NULL)
681 return -ENOMEM;
682
683 spin_lock_init(&prtd->lock);
Troy Kisky81ac55a2009-09-11 14:29:02 -0700684 prtd->params = params;
Troy Kisky1e224f32009-11-18 17:49:53 -0700685 prtd->asp_channel = -1;
686 prtd->asp_link[0] = prtd->asp_link[1] = -1;
687 prtd->ram_channel = -1;
688 prtd->ram_link = -1;
689 prtd->ram_link2 = -1;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100690
691 runtime->private_data = prtd;
692
693 ret = davinci_pcm_dma_request(substream);
694 if (ret) {
695 printk(KERN_ERR "davinci_pcm: Failed to get dma channels\n");
696 kfree(prtd);
697 }
698
699 return ret;
700}
701
702static int davinci_pcm_close(struct snd_pcm_substream *substream)
703{
704 struct snd_pcm_runtime *runtime = substream->runtime;
705 struct davinci_runtime_data *prtd = runtime->private_data;
706
Troy Kisky1e224f32009-11-18 17:49:53 -0700707 if (prtd->ram_channel >= 0)
708 edma_stop(prtd->ram_channel);
709 if (prtd->asp_channel >= 0)
710 edma_stop(prtd->asp_channel);
711 if (prtd->asp_link[0] >= 0)
712 edma_unlink(prtd->asp_link[0]);
713 if (prtd->asp_link[1] >= 0)
714 edma_unlink(prtd->asp_link[1]);
715 if (prtd->ram_link >= 0)
716 edma_unlink(prtd->ram_link);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100717
Troy Kisky1e224f32009-11-18 17:49:53 -0700718 if (prtd->asp_link[0] >= 0)
719 edma_free_slot(prtd->asp_link[0]);
720 if (prtd->asp_link[1] >= 0)
721 edma_free_slot(prtd->asp_link[1]);
722 if (prtd->asp_channel >= 0)
723 edma_free_channel(prtd->asp_channel);
724 if (prtd->ram_link >= 0)
725 edma_free_slot(prtd->ram_link);
726 if (prtd->ram_link2 >= 0)
727 edma_free_slot(prtd->ram_link2);
728 if (prtd->ram_channel >= 0)
729 edma_free_channel(prtd->ram_channel);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100730
731 kfree(prtd);
732
733 return 0;
734}
735
736static int davinci_pcm_hw_params(struct snd_pcm_substream *substream,
737 struct snd_pcm_hw_params *hw_params)
738{
739 return snd_pcm_lib_malloc_pages(substream,
740 params_buffer_bytes(hw_params));
741}
742
743static int davinci_pcm_hw_free(struct snd_pcm_substream *substream)
744{
745 return snd_pcm_lib_free_pages(substream);
746}
747
748static int davinci_pcm_mmap(struct snd_pcm_substream *substream,
749 struct vm_area_struct *vma)
750{
751 struct snd_pcm_runtime *runtime = substream->runtime;
752
753 return dma_mmap_writecombine(substream->pcm->card->dev, vma,
754 runtime->dma_area,
755 runtime->dma_addr,
756 runtime->dma_bytes);
757}
758
Mark Brownb2a19d02009-01-17 19:14:26 +0000759static struct snd_pcm_ops davinci_pcm_ops = {
Vladimir Barinov310355c2008-02-18 11:40:22 +0100760 .open = davinci_pcm_open,
761 .close = davinci_pcm_close,
762 .ioctl = snd_pcm_lib_ioctl,
763 .hw_params = davinci_pcm_hw_params,
764 .hw_free = davinci_pcm_hw_free,
765 .prepare = davinci_pcm_prepare,
766 .trigger = davinci_pcm_trigger,
767 .pointer = davinci_pcm_pointer,
768 .mmap = davinci_pcm_mmap,
769};
770
Troy Kisky1e224f32009-11-18 17:49:53 -0700771static int davinci_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream,
772 size_t size)
Vladimir Barinov310355c2008-02-18 11:40:22 +0100773{
774 struct snd_pcm_substream *substream = pcm->streams[stream].substream;
775 struct snd_dma_buffer *buf = &substream->dma_buffer;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100776
777 buf->dev.type = SNDRV_DMA_TYPE_DEV;
778 buf->dev.dev = pcm->card->dev;
779 buf->private_data = NULL;
780 buf->area = dma_alloc_writecombine(pcm->card->dev, size,
781 &buf->addr, GFP_KERNEL);
782
Alexander Beregalov9cd28ab2008-12-13 16:25:27 +0300783 pr_debug("davinci_pcm: preallocate_dma_buffer: area=%p, addr=%p, "
784 "size=%d\n", (void *) buf->area, (void *) buf->addr, size);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100785
786 if (!buf->area)
787 return -ENOMEM;
788
789 buf->bytes = size;
790 return 0;
791}
792
793static void davinci_pcm_free(struct snd_pcm *pcm)
794{
795 struct snd_pcm_substream *substream;
796 struct snd_dma_buffer *buf;
797 int stream;
798
799 for (stream = 0; stream < 2; stream++) {
Troy Kisky1e224f32009-11-18 17:49:53 -0700800 struct snd_dma_buffer *iram_dma;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100801 substream = pcm->streams[stream].substream;
802 if (!substream)
803 continue;
804
805 buf = &substream->dma_buffer;
806 if (!buf->area)
807 continue;
808
809 dma_free_writecombine(pcm->card->dev, buf->bytes,
810 buf->area, buf->addr);
811 buf->area = NULL;
Joe Perches4726a572010-07-12 13:50:27 -0700812 iram_dma = buf->private_data;
Troy Kisky1e224f32009-11-18 17:49:53 -0700813 if (iram_dma) {
814 sram_free(iram_dma->area, iram_dma->bytes);
815 kfree(iram_dma);
816 }
Vladimir Barinov310355c2008-02-18 11:40:22 +0100817 }
818}
819
Joachim Eastwood350e16d2012-01-01 02:43:03 +0100820static u64 davinci_pcm_dmamask = DMA_BIT_MASK(32);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100821
Liam Girdwood552d1ef2011-06-07 16:08:33 +0100822static int davinci_pcm_new(struct snd_soc_pcm_runtime *rtd)
Vladimir Barinov310355c2008-02-18 11:40:22 +0100823{
Liam Girdwood552d1ef2011-06-07 16:08:33 +0100824 struct snd_card *card = rtd->card->snd_card;
Liam Girdwood552d1ef2011-06-07 16:08:33 +0100825 struct snd_pcm *pcm = rtd->pcm;
Vladimir Barinov310355c2008-02-18 11:40:22 +0100826 int ret;
827
828 if (!card->dev->dma_mask)
829 card->dev->dma_mask = &davinci_pcm_dmamask;
830 if (!card->dev->coherent_dma_mask)
Joachim Eastwood350e16d2012-01-01 02:43:03 +0100831 card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100832
Joachim Eastwood25e9e752012-01-01 01:58:44 +0100833 if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
Vladimir Barinov310355c2008-02-18 11:40:22 +0100834 ret = davinci_pcm_preallocate_dma_buffer(pcm,
Troy Kisky1e224f32009-11-18 17:49:53 -0700835 SNDRV_PCM_STREAM_PLAYBACK,
836 pcm_hardware_playback.buffer_bytes_max);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100837 if (ret)
838 return ret;
839 }
840
Joachim Eastwood25e9e752012-01-01 01:58:44 +0100841 if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
Vladimir Barinov310355c2008-02-18 11:40:22 +0100842 ret = davinci_pcm_preallocate_dma_buffer(pcm,
Troy Kisky1e224f32009-11-18 17:49:53 -0700843 SNDRV_PCM_STREAM_CAPTURE,
844 pcm_hardware_capture.buffer_bytes_max);
Vladimir Barinov310355c2008-02-18 11:40:22 +0100845 if (ret)
846 return ret;
847 }
848
849 return 0;
850}
851
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000852static struct snd_soc_platform_driver davinci_soc_platform = {
853 .ops = &davinci_pcm_ops,
Vladimir Barinov310355c2008-02-18 11:40:22 +0100854 .pcm_new = davinci_pcm_new,
855 .pcm_free = davinci_pcm_free,
856};
Vladimir Barinov310355c2008-02-18 11:40:22 +0100857
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530858int davinci_soc_platform_register(struct device *dev)
Mark Brown958e7922008-12-03 19:58:17 +0000859{
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530860 return snd_soc_register_platform(dev, &davinci_soc_platform);
Mark Brown958e7922008-12-03 19:58:17 +0000861}
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530862EXPORT_SYMBOL_GPL(davinci_soc_platform_register);
Mark Brown958e7922008-12-03 19:58:17 +0000863
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530864void davinci_soc_platform_unregister(struct device *dev)
Mark Brown958e7922008-12-03 19:58:17 +0000865{
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530866 snd_soc_unregister_platform(dev);
Mark Brown958e7922008-12-03 19:58:17 +0000867}
Hebbar, Gururajaf08095a2012-08-27 18:56:39 +0530868EXPORT_SYMBOL_GPL(davinci_soc_platform_unregister);
Mark Brown958e7922008-12-03 19:58:17 +0000869
Vladimir Barinov310355c2008-02-18 11:40:22 +0100870MODULE_AUTHOR("Vladimir Barinov");
871MODULE_DESCRIPTION("TI DAVINCI PCM DMA module");
872MODULE_LICENSE("GPL");