36 #include <linux/module.h>
41 #include <linux/slab.h>
45 #include <linux/random.h>
50 #define MPC_DMA_DESCRIPTORS 64
53 #define MPC_DMA_CHANNELS 64
54 #define MPC_DMA_TCD_OFFSET 0x1000
57 #define MPC_DMA_DMACR_EDCG (1 << 31)
58 #define MPC_DMA_DMACR_ERGA (1 << 3)
59 #define MPC_DMA_DMACR_ERCA (1 << 2)
62 #define MPC_DMA_DMAES_VLD (1 << 31)
63 #define MPC_DMA_DMAES_GPE (1 << 15)
64 #define MPC_DMA_DMAES_CPE (1 << 14)
65 #define MPC_DMA_DMAES_ERRCHN(err) \
67 #define MPC_DMA_DMAES_SAE (1 << 7)
68 #define MPC_DMA_DMAES_SOE (1 << 6)
69 #define MPC_DMA_DMAES_DAE (1 << 5)
70 #define MPC_DMA_DMAES_DOE (1 << 4)
71 #define MPC_DMA_DMAES_NCE (1 << 3)
72 #define MPC_DMA_DMAES_SGE (1 << 2)
73 #define MPC_DMA_DMAES_SBE (1 << 1)
74 #define MPC_DMA_DMAES_DBE (1 << 0)
76 #define MPC_DMA_DMAGPOR_SNOOP_ENABLE (1 << 6)
78 #define MPC_DMA_TSIZE_1 0x00
79 #define MPC_DMA_TSIZE_2 0x01
80 #define MPC_DMA_TSIZE_4 0x02
81 #define MPC_DMA_TSIZE_16 0x04
82 #define MPC_DMA_TSIZE_32 0x05
213 #define DRV_NAME "mpc512x_dma"
224 struct mpc_dma_chan *mchan = dma_chan_to_mpc_dma_chan(c);
238 struct mpc_dma *mdma = dma_chan_to_mpc_dma(&mchan->
chan);
259 mdesc->
tcd->start = 1;
264 prev->
tcd->int_maj = 1;
282 while ((ch = fls(status) - 1) >= 0) {
283 status &= ~(1 << ch);
286 spin_lock(&mchan->
lock);
298 if (!list_empty(&mchan->queued))
299 mpc_dma_execute(mchan);
301 spin_unlock(&mchan->lock);
319 if (mdma->
dma.chancnt > 32) {
320 mpc_dma_irq_process(mdma,
in_be32(&mdma->
regs->dmainth),
323 mpc_dma_irq_process(mdma,
in_be32(&mdma->
regs->dmaintl),
327 tasklet_schedule(&mdma->
tasklet);
333 static void mpc_dma_process_completed(
struct mpc_dma *mdma)
343 for (i = 0; i < mdma->
dma.chancnt; i++) {
350 spin_unlock_irqrestore(&mchan->
lock, flags);
352 if (list_empty(&
list))
362 last_cookie = desc->
cookie;
368 list_splice_tail_init(&
list, &mchan->
free);
369 mchan->
chan.completed_cookie = last_cookie;
370 spin_unlock_irqrestore(&mchan->
lock, flags);
375 static void mpc_dma_tasklet(
unsigned long data)
377 struct mpc_dma *mdma = (
void *)data;
389 "Hardware reported following error(s) on channel %u:\n",
393 dev_err(mdma->
dma.dev,
"- Group Priority Error\n");
395 dev_err(mdma->
dma.dev,
"- Channel Priority Error\n");
397 dev_err(mdma->
dma.dev,
"- Source Address Error\n");
400 " Configuration Error\n");
402 dev_err(mdma->
dma.dev,
"- Destination Address"
406 " Configuration Error\n");
409 " Configuration Error\n");
412 " Configuration Error\n");
414 dev_err(mdma->
dma.dev,
"- Source Bus Error\n");
416 dev_err(mdma->
dma.dev,
"- Destination Bus Error\n");
419 mpc_dma_process_completed(mdma);
438 if (list_empty(&mchan->
active))
439 mpc_dma_execute(mchan);
442 cookie = dma_cookie_assign(txd);
443 spin_unlock_irqrestore(&mchan->
lock, flags);
449 static int mpc_dma_alloc_chan_resources(
struct dma_chan *
chan)
451 struct mpc_dma *mdma = dma_chan_to_mpc_dma(chan);
452 struct mpc_dma_chan *mchan = dma_chan_to_mpc_dma_chan(chan);
454 struct mpc_dma_tcd *tcd;
471 dev_notice(mdma->
dma.dev,
"Memory allocation error. "
472 "Allocated only %u descriptors\n", i);
478 mdesc->
desc.tx_submit = mpc_dma_tx_submit;
480 mdesc->
tcd = &tcd[
i];
481 mdesc->
tcd_paddr = tcd_paddr + (i *
sizeof(
struct mpc_dma_tcd));
489 MPC_DMA_DESCRIPTORS *
sizeof(
struct mpc_dma_tcd),
497 list_splice_tail_init(&descs, &mchan->
free);
498 spin_unlock_irqrestore(&mchan->
lock, flags);
507 static void mpc_dma_free_chan_resources(
struct dma_chan *chan)
509 struct mpc_dma *mdma = dma_chan_to_mpc_dma(chan);
510 struct mpc_dma_chan *mchan = dma_chan_to_mpc_dma_chan(chan);
512 struct mpc_dma_tcd *tcd;
526 list_splice_tail_init(&mchan->
free, &descs);
530 spin_unlock_irqrestore(&mchan->
lock, flags);
534 MPC_DMA_DESCRIPTORS *
sizeof(
struct mpc_dma_tcd),
542 out_8(&mdma->
regs->dmaceei, chan->chan_id);
559 struct mpc_dma_chan *mchan = dma_chan_to_mpc_dma_chan(chan);
564 ret = dma_cookie_status(chan, cookie, txstate);
565 spin_unlock_irqrestore(&mchan->
lock, flags);
573 size_t len,
unsigned long flags)
575 struct mpc_dma *mdma = dma_chan_to_mpc_dma(chan);
576 struct mpc_dma_chan *mchan = dma_chan_to_mpc_dma_chan(chan);
578 struct mpc_dma_tcd *tcd;
579 unsigned long iflags;
583 if (!list_empty(&mchan->
free)) {
588 spin_unlock_irqrestore(&mchan->
lock, iflags);
592 mpc_dma_process_completed(mdma);
600 memset(tcd, 0,
sizeof(
struct mpc_dma_tcd));
639 spin_unlock_irqrestore(&mchan->
lock, iflags);
652 ulong regs_start, regs_size;
657 dev_err(dev,
"Memory exhausted!\n");
663 dev_err(dev,
"Error mapping IRQ!\n");
671 dev_err(dev,
"Error mapping IRQ!\n");
678 dev_err(dev,
"Error parsing memory region!\n");
682 regs_start =
res.start;
683 regs_size = resource_size(&
res);
686 dev_err(dev,
"Error requesting memory region!\n");
692 dev_err(dev,
"Error mapping memory region!\n");
696 mdma->
tcd = (
struct mpc_dma_tcd *)((
u8 *)(mdma->
regs)
699 retval = devm_request_irq(dev, mdma->
irq, &mpc_dma_irq, 0,
DRV_NAME,
702 dev_err(dev,
"Error requesting IRQ!\n");
707 retval = devm_request_irq(dev, mdma->
irq2, &mpc_dma_irq, 0,
710 dev_err(dev,
"Error requesting IRQ2!\n");
732 for (i = 0; i < dma->
chancnt; i++) {
736 dma_cookie_init(&mchan->
chan);
738 INIT_LIST_HEAD(&mchan->
free);
740 INIT_LIST_HEAD(&mchan->
queued);
741 INIT_LIST_HEAD(&mchan->
active);
815 { .compatible =
"fsl,mpc5121-dma", },
820 .probe = mpc_dma_probe,
825 .of_match_table = mpc_dma_match,