9 #include <linux/module.h>
14 #include <linux/slab.h>
23 #define SIRFSOC_DMA_DESCRIPTORS 16
24 #define SIRFSOC_DMA_CHANNELS 16
26 #define SIRFSOC_DMA_CH_ADDR 0x00
27 #define SIRFSOC_DMA_CH_XLEN 0x04
28 #define SIRFSOC_DMA_CH_YLEN 0x08
29 #define SIRFSOC_DMA_CH_CTRL 0x0C
31 #define SIRFSOC_DMA_WIDTH_0 0x100
32 #define SIRFSOC_DMA_CH_VALID 0x140
33 #define SIRFSOC_DMA_CH_INT 0x144
34 #define SIRFSOC_DMA_INT_EN 0x148
35 #define SIRFSOC_DMA_CH_LOOP_CTRL 0x150
37 #define SIRFSOC_DMA_MODE_CTRL_BIT 4
38 #define SIRFSOC_DMA_DIR_CTRL_BIT 5
41 #define SIRFSOC_DMA_WORD_LEN 4
81 #define DRV_NAME "sirfsoc_dma"
120 writel_relaxed(sdesc->
xlen, sdma->
base + cid * 0x10 +
122 writel_relaxed(sdesc->
ylen, sdma->
base + cid * 0x10 +
134 writel((1 << cid) | 1 << (cid + 16) |
151 while ((ch = fls(is) - 1) >= 0) {
156 spin_lock(&schan->
lock);
163 if (!list_empty(&schan->
queued))
164 sirfsoc_dma_execute(schan);
168 spin_unlock(&schan->
lock);
172 tasklet_schedule(&sdma->
tasklet);
178 static void sirfsoc_dma_process_completed(
struct sirfsoc_dma *sdma)
185 unsigned long happened_cyclic;
189 for (i = 0; i < sdma->
dma.chancnt; i++) {
196 spin_unlock_irqrestore(&schan->
lock, flags);
205 last_cookie = desc->
cookie;
211 list_splice_tail_init(&
list, &schan->
free);
212 schan->
chan.completed_cookie = last_cookie;
213 spin_unlock_irqrestore(&schan->
lock, flags);
219 if (!sdesc || (sdesc && !sdesc->
cyclic)) {
221 spin_unlock_irqrestore(&schan->
lock, flags);
227 spin_unlock_irqrestore(&schan->
lock, flags);
240 static void sirfsoc_dma_tasklet(
unsigned long data)
244 sirfsoc_dma_process_completed(sdma);
262 cookie = dma_cookie_assign(txd);
264 spin_unlock_irqrestore(&schan->
lock, flags);
280 spin_unlock_irqrestore(&schan->
lock, flags);
288 int cid = schan->
chan.chan_id;
296 & ~((1 << cid) | 1 << (cid + 16)),
300 list_splice_tail_init(&schan->
active, &schan->
free);
301 list_splice_tail_init(&schan->
queued, &schan->
free);
302 spin_unlock_irqrestore(&schan->
lock, flags);
315 return sirfsoc_dma_terminate_all(schan);
318 return sirfsoc_dma_slave_config(schan, config);
328 static int sirfsoc_dma_alloc_chan_resources(
struct dma_chan *chan)
330 struct sirfsoc_dma *sdma = dma_chan_to_sirfsoc_dma(chan);
341 dev_notice(sdma->
dma.dev,
"Memory allocation error. "
342 "Allocated only %u descriptors\n", i);
348 sdesc->
desc.tx_submit = sirfsoc_dma_tx_submit;
359 list_splice_tail_init(&descs, &schan->
free);
360 spin_unlock_irqrestore(&schan->
lock, flags);
366 static void sirfsoc_dma_free_chan_resources(
struct dma_chan *chan)
382 list_splice_tail_init(&schan->
free, &descs);
384 spin_unlock_irqrestore(&schan->
lock, flags);
399 if (list_empty(&schan->
active) && !list_empty(&schan->
queued))
400 sirfsoc_dma_execute(schan);
402 spin_unlock_irqrestore(&schan->
lock, flags);
415 ret = dma_cookie_status(chan, cookie, txstate);
416 spin_unlock_irqrestore(&schan->
lock, flags);
425 struct sirfsoc_dma *sdma = dma_chan_to_sirfsoc_dma(chan);
428 unsigned long iflags;
438 if (!list_empty(&schan->
free)) {
443 spin_unlock_irqrestore(&schan->
lock, iflags);
447 sirfsoc_dma_process_completed(sdma);
462 sdesc->
width = (xt->
sgl[0].size + xt->
sgl[0].icg) /
475 pr_err(
"sirfsoc DMA Invalid xfer\n");
479 spin_unlock_irqrestore(&schan->
lock, iflags);
483 spin_unlock_irqrestore(&schan->
lock, iflags);
491 size_t buf_len,
size_t period_len,
496 unsigned long iflags;
509 if (buf_len != 2 * period_len)
514 if (!list_empty(&schan->
free)) {
519 spin_unlock_irqrestore(&schan->
lock, iflags);
532 spin_unlock_irqrestore(&schan->
lock, iflags);
543 unsigned int ch_nr = (
unsigned int) chan_id;
561 ulong regs_start, regs_size;
567 dev_err(dev,
"Memory exhausted!\n");
571 if (of_property_read_u32(dn,
"cell-index", &
id)) {
572 dev_err(dev,
"Fail to get DMAC index\n");
578 dev_err(dev,
"Error mapping IRQ!\n");
584 dev_err(dev,
"Error parsing memory region!\n");
588 regs_start =
res.start;
589 regs_size = resource_size(&
res);
593 dev_err(dev,
"Error mapping memory region!\n");
600 dev_err(dev,
"Error requesting IRQ!\n");
623 for (i = 0; i < dma->
chancnt; i++) {
627 dma_cookie_init(&schan->
chan);
629 INIT_LIST_HEAD(&schan->
free);
631 INIT_LIST_HEAD(&schan->
queued);
632 INIT_LIST_HEAD(&schan->
active);
647 dev_info(dev,
"initialized SIRFSOC DMAC driver\n");
670 { .compatible =
"sirf,prima2-dmac", },
675 .probe = sirfsoc_dma_probe,
680 .of_match_table = sirfsoc_dma_match,