13 #include <linux/module.h>
16 #include <linux/slab.h>
18 #include <linux/kernel.h>
26 #include <mach/sram.h>
31 static void print_buf_info(
int slot,
char *
name)
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);
43 static void print_buf_info(
int slot,
char *name)
48 #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)
79 .buffer_bytes_max = 128 * 1024,
80 .period_bytes_min = 32,
81 .period_bytes_max = 8 * 1024,
102 .buffer_bytes_max = 128 * 1024,
103 .period_bytes_min = 32,
104 .period_bytes_max = 8 * 1024,
183 unsigned int dma_offset;
186 unsigned short src_bidx, dst_bidx;
187 unsigned short src_cidx, dst_cidx;
191 unsigned int fifo_level;
193 period_size = snd_pcm_lib_period_bytes(substream);
195 dma_pos = runtime->
dma_addr + dma_offset;
196 fifo_level = prtd->
params->fifo_level;
198 pr_debug(
"davinci_pcm: audio_set_dma_params_play channel = %d "
199 "dma_ptr = %x period_size=%x\n", prtd->
asp_link[0], dma_pos,
202 data_type = prtd->
params->data_type;
209 dst = prtd->
params->dma_addr;
212 src_cidx = data_type * fifo_level;
215 src = prtd->
params->dma_addr;
220 dst_cidx = data_type * fifo_level;
223 acnt = prtd->
params->acnt;
239 static void davinci_pcm_dma_irq(
unsigned link,
u16 ch_status,
void *
data)
244 print_buf_info(prtd->
ram_channel,
"i ram_channel");
245 pr_debug(
"davinci_pcm: link=%d, status=0x%x\n", link, ch_status);
250 if (snd_pcm_running(substream)) {
251 spin_lock(&prtd->
lock);
254 davinci_pcm_enqueue_dma(substream);
256 davinci_pcm_period_elapsed(substream);
257 spin_unlock(&prtd->
lock);
268 void *iram_virt =
NULL;
277 iram_dma = kzalloc(
sizeof(*iram_dma),
GFP_KERNEL);
280 iram_dma->
area = iram_virt;
281 iram_dma->
addr = iram_phys;
299 unsigned short ram_src_cidx, ram_dst_cidx;
305 unsigned int data_type =
params->data_type;
306 unsigned int acnt =
params->acnt;
308 unsigned int ping_size = snd_pcm_lib_period_bytes(substream) >> 1;
309 unsigned int fifo_level = prtd->
params->fifo_level;
311 if ((data_type == 0) || (data_type > 4)) {
317 ram_src_cidx = ping_size;
318 ram_dst_cidx = -ping_size;
322 data_type * fifo_level);
324 data_type * fifo_level);
329 ram_src_cidx = -ping_size;
330 ram_dst_cidx = ping_size;
334 data_type * fifo_level);
336 data_type * fifo_level);
348 count = ping_size / (data_type * fifo_level);
350 count, fifo_level,
ABSYNC);
352 count, fifo_level,
ABSYNC);
366 prtd->
ram_params.a_b_cnt = (1 << 16) | (ping_size << 1);
368 prtd->
ram_params.src_dst_bidx = (ping_size << 1);
370 prtd->
ram_params.src_dst_cidx = (ping_size << 1);
375 p_ram.src += (ping_size << 1);
411 davinci_pcm_dma_irq, substream,
412 prtd->
params->ram_chan_q);
441 asp_src_ping = iram_dma->
addr;
445 asp_dst_ping = iram_dma->
addr;
475 pr_debug(
"%s: audio dma channels/slots in use for ram:%u %u %u,"
476 "for asp:%u %u %u\n", __func__,
506 davinci_pcm_dma_irq, substream,
507 prtd->
params->asp_chan_q);
519 if (request_ping_pong(substream, prtd, iram_dma) == 0)
522 "not using sram\n", __func__);
552 spin_lock(&prtd->
lock);
577 spin_unlock(&prtd->
lock);
586 davinci_pcm_period_reset(substream);
588 int ret = ping_pong_dma_setup(substream);
596 print_buf_info(prtd->
ram_link,
"ram_link");
597 print_buf_info(prtd->
ram_link2,
"ram_link2");
599 print_buf_info(prtd->
asp_link[0],
"asp_link[0]");
600 print_buf_info(prtd->
asp_link[1],
"asp_link[1]");
614 davinci_pcm_period_elapsed(substream);
615 davinci_pcm_period_elapsed(substream);
619 davinci_pcm_enqueue_dma(substream);
620 davinci_pcm_period_elapsed(substream);
625 davinci_pcm_enqueue_dma(substream);
626 davinci_pcm_period_elapsed(substream);
638 unsigned int period_size = snd_pcm_lib_period_bytes(substream);
647 spin_lock(&prtd->
lock);
648 asp_count = prtd->
period - 2;
649 spin_unlock(&prtd->
lock);
653 asp_count *= period_size;
655 offset = bytes_to_frames(runtime, asp_count);
672 pa = snd_soc_dai_get_dma_data(rtd->
cpu_dai, substream);
675 params = &pa[substream->
stream];
678 &pcm_hardware_playback : &pcm_hardware_capture;
679 allocate_sram(substream, params->
sram_size, ppcm);
701 ret = davinci_pcm_dma_request(substream);
761 return dma_mmap_writecombine(substream->
pcm->card->dev, vma,
768 .open = davinci_pcm_open,
769 .close = davinci_pcm_close,
771 .hw_params = davinci_pcm_hw_params,
772 .hw_free = davinci_pcm_hw_free,
773 .prepare = davinci_pcm_prepare,
774 .trigger = davinci_pcm_trigger,
775 .pointer = davinci_pcm_pointer,
776 .mmap = davinci_pcm_mmap,
779 static int davinci_pcm_preallocate_dma_buffer(
struct snd_pcm *pcm,
int stream,
791 pr_debug(
"davinci_pcm: preallocate_dma_buffer: area=%p, addr=%p, "
792 "size=%d\n", (
void *) buf->
area, (
void *) buf->
addr, size);
801 static void davinci_pcm_free(
struct snd_pcm *pcm)
807 for (stream = 0; stream < 2; stream++) {
809 substream = pcm->
streams[stream].substream;
836 if (!card->
dev->dma_mask)
837 card->
dev->dma_mask = &davinci_pcm_dmamask;
838 if (!card->
dev->coherent_dma_mask)
842 ret = davinci_pcm_preallocate_dma_buffer(pcm,
850 ret = davinci_pcm_preallocate_dma_buffer(pcm,
861 .ops = &davinci_pcm_ops,
862 .pcm_new = davinci_pcm_new,
863 .pcm_free = davinci_pcm_free,