2 * OMAP DMAengine support
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 #include <linux/delay.h>
9 #include <linux/dmaengine.h>
10 #include <linux/dma-mapping.h>
11 #include <linux/err.h>
12 #include <linux/init.h>
13 #include <linux/interrupt.h>
14 #include <linux/list.h>
15 #include <linux/module.h>
16 #include <linux/omap-dma.h>
17 #include <linux/platform_device.h>
18 #include <linux/slab.h>
19 #include <linux/spinlock.h>
20 #include <linux/of_dma.h>
21 #include <linux/of_device.h>
26 struct dma_device ddev;
28 struct tasklet_struct task;
29 struct list_head pending;
30 struct omap_system_dma_plat_info *plat;
34 struct virt_dma_chan vc;
35 struct list_head node;
36 struct omap_system_dma_plat_info *plat;
38 struct dma_slave_config cfg;
44 struct omap_desc *desc;
50 uint32_t en; /* number of elements (24-bit) */
51 uint32_t fn; /* number of frames (16-bit) */
55 struct virt_dma_desc vd;
56 enum dma_transfer_direction dir;
59 int16_t fi; /* for OMAP_DMA_SYNC_PACKET */
60 uint8_t es; /* OMAP_DMA_DATA_TYPE_xxx */
61 uint32_t ccr; /* CCR value */
62 uint16_t cicr; /* CICR value */
63 uint32_t csdp; /* CSDP value */
69 static const unsigned es_bytes[] = {
70 [OMAP_DMA_DATA_TYPE_S8] = 1,
71 [OMAP_DMA_DATA_TYPE_S16] = 2,
72 [OMAP_DMA_DATA_TYPE_S32] = 4,
75 static struct of_dma_filter_info omap_dma_info = {
76 .filter_fn = omap_dma_filter_fn,
79 static inline struct omap_dmadev *to_omap_dma_dev(struct dma_device *d)
81 return container_of(d, struct omap_dmadev, ddev);
84 static inline struct omap_chan *to_omap_dma_chan(struct dma_chan *c)
86 return container_of(c, struct omap_chan, vc.chan);
89 static inline struct omap_desc *to_omap_dma_desc(struct dma_async_tx_descriptor *t)
91 return container_of(t, struct omap_desc, vd.tx);
94 static void omap_dma_desc_free(struct virt_dma_desc *vd)
96 kfree(container_of(vd, struct omap_desc, vd));
99 static void omap_dma_start(struct omap_chan *c, struct omap_desc *d)
101 struct omap_dmadev *od = to_omap_dma_dev(c->vc.chan.device);
104 if (__dma_omap15xx(od->plat->dma_attr))
105 c->plat->dma_write(0, CPC, c->dma_ch);
107 c->plat->dma_write(0, CDAC, c->dma_ch);
109 if (!__dma_omap15xx(od->plat->dma_attr) && c->cyclic) {
110 val = c->plat->dma_read(CLNK_CTRL, c->dma_ch);
115 val |= c->dma_ch | 1 << 15;
117 c->plat->dma_write(val, CLNK_CTRL, c->dma_ch);
118 } else if (od->plat->errata & DMA_ERRATA_PARALLEL_CHANNELS)
119 c->plat->dma_write(c->dma_ch, CLNK_CTRL, c->dma_ch);
123 c->plat->dma_read(CSR, c->dma_ch);
125 c->plat->dma_write(~0, CSR, c->dma_ch);
127 /* Enable interrupts */
128 c->plat->dma_write(d->cicr, CICR, c->dma_ch);
130 val = c->plat->dma_read(CCR, c->dma_ch);
131 if (od->plat->errata & DMA_ERRATA_IFRAME_BUFFERING)
132 val |= OMAP_DMA_CCR_BUFFERING_DISABLE;
133 val |= OMAP_DMA_CCR_EN;
135 c->plat->dma_write(val, CCR, c->dma_ch);
138 static void omap_dma_stop(struct omap_chan *c)
140 struct omap_dmadev *od = to_omap_dma_dev(c->vc.chan.device);
144 c->plat->dma_write(0, CICR, c->dma_ch);
148 c->plat->dma_read(CSR, c->dma_ch);
150 c->plat->dma_write(~0, CSR, c->dma_ch);
152 val = c->plat->dma_read(CCR, c->dma_ch);
153 if (od->plat->errata & DMA_ERRATA_i541 &&
154 val & OMAP_DMA_CCR_SEL_SRC_DST_SYNC) {
158 sysconfig = c->plat->dma_read(OCP_SYSCONFIG, c->dma_ch);
159 val = sysconfig & ~DMA_SYSCONFIG_MIDLEMODE_MASK;
160 val |= DMA_SYSCONFIG_MIDLEMODE(DMA_IDLEMODE_NO_IDLE);
161 c->plat->dma_write(val, OCP_SYSCONFIG, c->dma_ch);
163 val = c->plat->dma_read(CCR, c->dma_ch);
164 val &= ~OMAP_DMA_CCR_EN;
165 c->plat->dma_write(val, CCR, c->dma_ch);
167 /* Wait for sDMA FIFO to drain */
169 val = c->plat->dma_read(CCR, c->dma_ch);
170 if (!(val & (OMAP_DMA_CCR_RD_ACTIVE | OMAP_DMA_CCR_WR_ACTIVE)))
179 if (val & (OMAP_DMA_CCR_RD_ACTIVE | OMAP_DMA_CCR_WR_ACTIVE))
180 dev_err(c->vc.chan.device->dev,
181 "DMA drain did not complete on lch %d\n",
184 c->plat->dma_write(sysconfig, OCP_SYSCONFIG, c->dma_ch);
186 val &= ~OMAP_DMA_CCR_EN;
187 c->plat->dma_write(val, CCR, c->dma_ch);
192 if (!__dma_omap15xx(od->plat->dma_attr) && c->cyclic) {
193 val = c->plat->dma_read(CLNK_CTRL, c->dma_ch);
196 val |= 1 << 14; /* set the STOP_LNK bit */
198 val &= ~(1 << 15); /* Clear the ENABLE_LNK bit */
200 c->plat->dma_write(val, CLNK_CTRL, c->dma_ch);
204 static void omap_dma_start_sg(struct omap_chan *c, struct omap_desc *d,
207 struct omap_sg *sg = d->sg + idx;
209 if (d->dir == DMA_DEV_TO_MEM) {
210 c->plat->dma_write(sg->addr, CDSA, c->dma_ch);
211 c->plat->dma_write(0, CDEI, c->dma_ch);
212 c->plat->dma_write(0, CDFI, c->dma_ch);
214 c->plat->dma_write(sg->addr, CSSA, c->dma_ch);
215 c->plat->dma_write(0, CSEI, c->dma_ch);
216 c->plat->dma_write(0, CSFI, c->dma_ch);
219 c->plat->dma_write(sg->en, CEN, c->dma_ch);
220 c->plat->dma_write(sg->fn, CFN, c->dma_ch);
222 omap_dma_start(c, d);
225 static void omap_dma_start_desc(struct omap_chan *c)
227 struct virt_dma_desc *vd = vchan_next_desc(&c->vc);
237 c->desc = d = to_omap_dma_desc(&vd->tx);
240 c->plat->dma_write(d->ccr, CCR, c->dma_ch);
242 c->plat->dma_write(d->ccr >> 16, CCR2, c->dma_ch);
244 if (d->dir == DMA_DEV_TO_MEM) {
245 c->plat->dma_write(d->dev_addr, CSSA, c->dma_ch);
246 c->plat->dma_write(0, CSEI, c->dma_ch);
247 c->plat->dma_write(d->fi, CSFI, c->dma_ch);
249 c->plat->dma_write(d->dev_addr, CDSA, c->dma_ch);
250 c->plat->dma_write(0, CDEI, c->dma_ch);
251 c->plat->dma_write(d->fi, CDFI, c->dma_ch);
254 c->plat->dma_write(d->csdp, CSDP, c->dma_ch);
256 omap_dma_start_sg(c, d, 0);
259 static void omap_dma_callback(int ch, u16 status, void *data)
261 struct omap_chan *c = data;
265 spin_lock_irqsave(&c->vc.lock, flags);
269 if (++c->sgidx < d->sglen) {
270 omap_dma_start_sg(c, d, c->sgidx);
272 omap_dma_start_desc(c);
273 vchan_cookie_complete(&d->vd);
276 vchan_cyclic_callback(&d->vd);
279 spin_unlock_irqrestore(&c->vc.lock, flags);
283 * This callback schedules all pending channels. We could be more
284 * clever here by postponing allocation of the real DMA channels to
285 * this point, and freeing them when our virtual channel becomes idle.
287 * We would then need to deal with 'all channels in-use'
289 static void omap_dma_sched(unsigned long data)
291 struct omap_dmadev *d = (struct omap_dmadev *)data;
294 spin_lock_irq(&d->lock);
295 list_splice_tail_init(&d->pending, &head);
296 spin_unlock_irq(&d->lock);
298 while (!list_empty(&head)) {
299 struct omap_chan *c = list_first_entry(&head,
300 struct omap_chan, node);
302 spin_lock_irq(&c->vc.lock);
303 list_del_init(&c->node);
304 omap_dma_start_desc(c);
305 spin_unlock_irq(&c->vc.lock);
309 static int omap_dma_alloc_chan_resources(struct dma_chan *chan)
311 struct omap_chan *c = to_omap_dma_chan(chan);
313 dev_dbg(c->vc.chan.device->dev, "allocating channel for %u\n", c->dma_sig);
315 return omap_request_dma(c->dma_sig, "DMA engine",
316 omap_dma_callback, c, &c->dma_ch);
319 static void omap_dma_free_chan_resources(struct dma_chan *chan)
321 struct omap_chan *c = to_omap_dma_chan(chan);
323 vchan_free_chan_resources(&c->vc);
324 omap_free_dma(c->dma_ch);
326 dev_dbg(c->vc.chan.device->dev, "freeing channel for %u\n", c->dma_sig);
329 static size_t omap_dma_sg_size(struct omap_sg *sg)
331 return sg->en * sg->fn;
334 static size_t omap_dma_desc_size(struct omap_desc *d)
339 for (size = i = 0; i < d->sglen; i++)
340 size += omap_dma_sg_size(&d->sg[i]);
342 return size * es_bytes[d->es];
345 static size_t omap_dma_desc_size_pos(struct omap_desc *d, dma_addr_t addr)
348 size_t size, es_size = es_bytes[d->es];
350 for (size = i = 0; i < d->sglen; i++) {
351 size_t this_size = omap_dma_sg_size(&d->sg[i]) * es_size;
355 else if (addr >= d->sg[i].addr &&
356 addr < d->sg[i].addr + this_size)
357 size += d->sg[i].addr + this_size - addr;
362 static dma_addr_t omap_dma_get_src_pos(struct omap_chan *c)
364 struct omap_dmadev *od = to_omap_dma_dev(c->vc.chan.device);
367 if (__dma_omap15xx(od->plat->dma_attr))
368 addr = c->plat->dma_read(CPC, c->dma_ch);
370 addr = c->plat->dma_read(CSAC, c->dma_ch);
372 if (od->plat->errata & DMA_ERRATA_3_3 && addr == 0)
373 addr = c->plat->dma_read(CSAC, c->dma_ch);
375 if (!__dma_omap15xx(od->plat->dma_attr)) {
377 * CDAC == 0 indicates that the DMA transfer on the channel has
378 * not been started (no data has been transferred so far).
379 * Return the programmed source start address in this case.
381 if (c->plat->dma_read(CDAC, c->dma_ch))
382 addr = c->plat->dma_read(CSAC, c->dma_ch);
384 addr = c->plat->dma_read(CSSA, c->dma_ch);
388 addr |= c->plat->dma_read(CSSA, c->dma_ch) & 0xffff0000;
393 static dma_addr_t omap_dma_get_dst_pos(struct omap_chan *c)
395 struct omap_dmadev *od = to_omap_dma_dev(c->vc.chan.device);
398 if (__dma_omap15xx(od->plat->dma_attr))
399 addr = c->plat->dma_read(CPC, c->dma_ch);
401 addr = c->plat->dma_read(CDAC, c->dma_ch);
404 * omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
405 * read before the DMA controller finished disabling the channel.
407 if (!__dma_omap15xx(od->plat->dma_attr) && addr == 0) {
408 addr = c->plat->dma_read(CDAC, c->dma_ch);
410 * CDAC == 0 indicates that the DMA transfer on the channel has
411 * not been started (no data has been transferred so far).
412 * Return the programmed destination start address in this case.
415 addr = c->plat->dma_read(CDSA, c->dma_ch);
419 addr |= c->plat->dma_read(CDSA, c->dma_ch) & 0xffff0000;
424 static enum dma_status omap_dma_tx_status(struct dma_chan *chan,
425 dma_cookie_t cookie, struct dma_tx_state *txstate)
427 struct omap_chan *c = to_omap_dma_chan(chan);
428 struct virt_dma_desc *vd;
432 ret = dma_cookie_status(chan, cookie, txstate);
433 if (ret == DMA_COMPLETE || !txstate)
436 spin_lock_irqsave(&c->vc.lock, flags);
437 vd = vchan_find_desc(&c->vc, cookie);
439 txstate->residue = omap_dma_desc_size(to_omap_dma_desc(&vd->tx));
440 } else if (c->desc && c->desc->vd.tx.cookie == cookie) {
441 struct omap_desc *d = c->desc;
444 if (d->dir == DMA_MEM_TO_DEV)
445 pos = omap_dma_get_src_pos(c);
446 else if (d->dir == DMA_DEV_TO_MEM)
447 pos = omap_dma_get_dst_pos(c);
451 txstate->residue = omap_dma_desc_size_pos(d, pos);
453 txstate->residue = 0;
455 spin_unlock_irqrestore(&c->vc.lock, flags);
460 static void omap_dma_issue_pending(struct dma_chan *chan)
462 struct omap_chan *c = to_omap_dma_chan(chan);
465 spin_lock_irqsave(&c->vc.lock, flags);
466 if (vchan_issue_pending(&c->vc) && !c->desc) {
468 * c->cyclic is used only by audio and in this case the DMA need
469 * to be started without delay.
472 struct omap_dmadev *d = to_omap_dma_dev(chan->device);
474 if (list_empty(&c->node))
475 list_add_tail(&c->node, &d->pending);
476 spin_unlock(&d->lock);
477 tasklet_schedule(&d->task);
479 omap_dma_start_desc(c);
482 spin_unlock_irqrestore(&c->vc.lock, flags);
485 static struct dma_async_tx_descriptor *omap_dma_prep_slave_sg(
486 struct dma_chan *chan, struct scatterlist *sgl, unsigned sglen,
487 enum dma_transfer_direction dir, unsigned long tx_flags, void *context)
489 struct omap_chan *c = to_omap_dma_chan(chan);
490 enum dma_slave_buswidth dev_width;
491 struct scatterlist *sgent;
494 unsigned i, j = 0, es, en, frame_bytes;
497 if (dir == DMA_DEV_TO_MEM) {
498 dev_addr = c->cfg.src_addr;
499 dev_width = c->cfg.src_addr_width;
500 burst = c->cfg.src_maxburst;
501 } else if (dir == DMA_MEM_TO_DEV) {
502 dev_addr = c->cfg.dst_addr;
503 dev_width = c->cfg.dst_addr_width;
504 burst = c->cfg.dst_maxburst;
506 dev_err(chan->device->dev, "%s: bad direction?\n", __func__);
510 /* Bus width translates to the element size (ES) */
512 case DMA_SLAVE_BUSWIDTH_1_BYTE:
513 es = OMAP_DMA_DATA_TYPE_S8;
515 case DMA_SLAVE_BUSWIDTH_2_BYTES:
516 es = OMAP_DMA_DATA_TYPE_S16;
518 case DMA_SLAVE_BUSWIDTH_4_BYTES:
519 es = OMAP_DMA_DATA_TYPE_S32;
521 default: /* not reached */
525 /* Now allocate and setup the descriptor. */
526 d = kzalloc(sizeof(*d) + sglen * sizeof(d->sg[0]), GFP_ATOMIC);
531 d->dev_addr = dev_addr;
535 if (dir == DMA_DEV_TO_MEM)
536 d->ccr |= OMAP_DMA_AMODE_POST_INC << 14 |
537 OMAP_DMA_AMODE_CONSTANT << 12;
539 d->ccr |= OMAP_DMA_AMODE_CONSTANT << 14 |
540 OMAP_DMA_AMODE_POST_INC << 12;
542 d->cicr = OMAP_DMA_DROP_IRQ | OMAP_DMA_BLOCK_IRQ;
546 d->ccr |= 1 << 5; /* frame sync */
547 if (__dma_omap16xx(od->plat->dma_attr)) {
548 d->ccr |= 1 << 10; /* disable 3.0/3.1 compatibility mode */
549 /* Duplicate what plat-omap/dma.c does */
550 d->ccr |= c->dma_ch + 1;
552 d->ccr |= c->dma_sig & 0x1f;
555 d->cicr |= OMAP1_DMA_TOUT_IRQ;
557 if (dir == DMA_DEV_TO_MEM)
558 d->csdp |= OMAP_DMA_PORT_EMIFF << 9 |
559 OMAP_DMA_PORT_TIPB << 2;
561 d->csdp |= OMAP_DMA_PORT_TIPB << 9 |
562 OMAP_DMA_PORT_EMIFF << 2;
564 d->ccr |= (c->dma_sig & ~0x1f) << 14;
565 d->ccr |= c->dma_sig & 0x1f;
566 d->ccr |= 1 << 5; /* frame sync */
568 if (dir == DMA_DEV_TO_MEM)
569 d->ccr |= 1 << 24; /* source synch */
571 d->cicr |= OMAP2_DMA_MISALIGNED_ERR_IRQ | OMAP2_DMA_TRANS_ERR_IRQ;
575 * Build our scatterlist entries: each contains the address,
576 * the number of elements (EN) in each frame, and the number of
577 * frames (FN). Number of bytes for this entry = ES * EN * FN.
579 * Burst size translates to number of elements with frame sync.
580 * Note: DMA engine defines burst to be the number of dev-width
584 frame_bytes = es_bytes[es] * en;
585 for_each_sg(sgl, sgent, sglen, i) {
586 d->sg[j].addr = sg_dma_address(sgent);
588 d->sg[j].fn = sg_dma_len(sgent) / frame_bytes;
594 return vchan_tx_prep(&c->vc, &d->vd, tx_flags);
597 static struct dma_async_tx_descriptor *omap_dma_prep_dma_cyclic(
598 struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
599 size_t period_len, enum dma_transfer_direction dir, unsigned long flags,
602 struct omap_dmadev *od = to_omap_dma_dev(chan->device);
603 struct omap_chan *c = to_omap_dma_chan(chan);
604 enum dma_slave_buswidth dev_width;
610 if (dir == DMA_DEV_TO_MEM) {
611 dev_addr = c->cfg.src_addr;
612 dev_width = c->cfg.src_addr_width;
613 burst = c->cfg.src_maxburst;
614 } else if (dir == DMA_MEM_TO_DEV) {
615 dev_addr = c->cfg.dst_addr;
616 dev_width = c->cfg.dst_addr_width;
617 burst = c->cfg.dst_maxburst;
619 dev_err(chan->device->dev, "%s: bad direction?\n", __func__);
623 /* Bus width translates to the element size (ES) */
625 case DMA_SLAVE_BUSWIDTH_1_BYTE:
626 es = OMAP_DMA_DATA_TYPE_S8;
628 case DMA_SLAVE_BUSWIDTH_2_BYTES:
629 es = OMAP_DMA_DATA_TYPE_S16;
631 case DMA_SLAVE_BUSWIDTH_4_BYTES:
632 es = OMAP_DMA_DATA_TYPE_S32;
634 default: /* not reached */
638 /* Now allocate and setup the descriptor. */
639 d = kzalloc(sizeof(*d) + sizeof(d->sg[0]), GFP_ATOMIC);
644 d->dev_addr = dev_addr;
647 d->sg[0].addr = buf_addr;
648 d->sg[0].en = period_len / es_bytes[es];
649 d->sg[0].fn = buf_len / period_len;
653 if (__dma_omap15xx(od->plat->dma_attr))
655 if (dir == DMA_DEV_TO_MEM)
656 d->ccr |= OMAP_DMA_AMODE_POST_INC << 14 |
657 OMAP_DMA_AMODE_CONSTANT << 12;
659 d->ccr |= OMAP_DMA_AMODE_CONSTANT << 14 |
660 OMAP_DMA_AMODE_POST_INC << 12;
662 d->cicr = OMAP_DMA_DROP_IRQ;
663 if (flags & DMA_PREP_INTERRUPT)
664 d->cicr |= OMAP_DMA_FRAME_IRQ;
669 if (__dma_omap16xx(od->plat->dma_attr)) {
670 d->ccr |= 1 << 10; /* disable 3.0/3.1 compatibility mode */
671 /* Duplicate what plat-omap/dma.c does */
672 d->ccr |= c->dma_ch + 1;
674 d->ccr |= c->dma_sig & 0x1f;
677 d->cicr |= OMAP1_DMA_TOUT_IRQ;
679 if (dir == DMA_DEV_TO_MEM)
680 d->csdp |= OMAP_DMA_PORT_EMIFF << 9 |
681 OMAP_DMA_PORT_MPUI << 2;
683 d->csdp |= OMAP_DMA_PORT_MPUI << 9 |
684 OMAP_DMA_PORT_EMIFF << 2;
686 d->ccr |= (c->dma_sig & ~0x1f) << 14;
687 d->ccr |= c->dma_sig & 0x1f;
690 d->ccr |= 1 << 18 | 1 << 5; /* packet */
692 if (dir == DMA_DEV_TO_MEM)
693 d->ccr |= 1 << 24; /* source synch */
695 d->cicr |= OMAP2_DMA_MISALIGNED_ERR_IRQ | OMAP2_DMA_TRANS_ERR_IRQ;
697 /* src and dst burst mode 16 */
698 d->csdp |= 3 << 14 | 3 << 7;
703 return vchan_tx_prep(&c->vc, &d->vd, flags);
706 static int omap_dma_slave_config(struct omap_chan *c, struct dma_slave_config *cfg)
708 if (cfg->src_addr_width == DMA_SLAVE_BUSWIDTH_8_BYTES ||
709 cfg->dst_addr_width == DMA_SLAVE_BUSWIDTH_8_BYTES)
712 memcpy(&c->cfg, cfg, sizeof(c->cfg));
717 static int omap_dma_terminate_all(struct omap_chan *c)
719 struct omap_dmadev *d = to_omap_dma_dev(c->vc.chan.device);
723 spin_lock_irqsave(&c->vc.lock, flags);
725 /* Prevent this channel being scheduled */
727 list_del_init(&c->node);
728 spin_unlock(&d->lock);
731 * Stop DMA activity: we assume the callback will not be called
732 * after omap_dma_stop() returns (even if it does, it will see
733 * c->desc is NULL and exit.)
737 /* Avoid stopping the dma twice */
747 vchan_get_all_descriptors(&c->vc, &head);
748 spin_unlock_irqrestore(&c->vc.lock, flags);
749 vchan_dma_desc_free_list(&c->vc, &head);
754 static int omap_dma_pause(struct omap_chan *c)
756 /* Pause/Resume only allowed with cyclic mode */
768 static int omap_dma_resume(struct omap_chan *c)
770 /* Pause/Resume only allowed with cyclic mode */
775 omap_dma_start(c, c->desc);
782 static int omap_dma_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
785 struct omap_chan *c = to_omap_dma_chan(chan);
789 case DMA_SLAVE_CONFIG:
790 ret = omap_dma_slave_config(c, (struct dma_slave_config *)arg);
793 case DMA_TERMINATE_ALL:
794 ret = omap_dma_terminate_all(c);
798 ret = omap_dma_pause(c);
802 ret = omap_dma_resume(c);
813 static int omap_dma_chan_init(struct omap_dmadev *od, int dma_sig)
817 c = kzalloc(sizeof(*c), GFP_KERNEL);
822 c->dma_sig = dma_sig;
823 c->vc.desc_free = omap_dma_desc_free;
824 vchan_init(&c->vc, &od->ddev);
825 INIT_LIST_HEAD(&c->node);
832 static void omap_dma_free(struct omap_dmadev *od)
834 tasklet_kill(&od->task);
835 while (!list_empty(&od->ddev.channels)) {
836 struct omap_chan *c = list_first_entry(&od->ddev.channels,
837 struct omap_chan, vc.chan.device_node);
839 list_del(&c->vc.chan.device_node);
840 tasklet_kill(&c->vc.task);
845 static int omap_dma_probe(struct platform_device *pdev)
847 struct omap_dmadev *od;
850 od = devm_kzalloc(&pdev->dev, sizeof(*od), GFP_KERNEL);
854 od->plat = omap_get_plat_info();
856 return -EPROBE_DEFER;
858 dma_cap_set(DMA_SLAVE, od->ddev.cap_mask);
859 dma_cap_set(DMA_CYCLIC, od->ddev.cap_mask);
860 od->ddev.device_alloc_chan_resources = omap_dma_alloc_chan_resources;
861 od->ddev.device_free_chan_resources = omap_dma_free_chan_resources;
862 od->ddev.device_tx_status = omap_dma_tx_status;
863 od->ddev.device_issue_pending = omap_dma_issue_pending;
864 od->ddev.device_prep_slave_sg = omap_dma_prep_slave_sg;
865 od->ddev.device_prep_dma_cyclic = omap_dma_prep_dma_cyclic;
866 od->ddev.device_control = omap_dma_control;
867 od->ddev.dev = &pdev->dev;
868 INIT_LIST_HEAD(&od->ddev.channels);
869 INIT_LIST_HEAD(&od->pending);
870 spin_lock_init(&od->lock);
872 tasklet_init(&od->task, omap_dma_sched, (unsigned long)od);
874 for (i = 0; i < 127; i++) {
875 rc = omap_dma_chan_init(od, i);
882 rc = dma_async_device_register(&od->ddev);
884 pr_warn("OMAP-DMA: failed to register slave DMA engine device: %d\n",
890 platform_set_drvdata(pdev, od);
892 if (pdev->dev.of_node) {
893 omap_dma_info.dma_cap = od->ddev.cap_mask;
895 /* Device-tree DMA controller registration */
896 rc = of_dma_controller_register(pdev->dev.of_node,
897 of_dma_simple_xlate, &omap_dma_info);
899 pr_warn("OMAP-DMA: failed to register DMA controller\n");
900 dma_async_device_unregister(&od->ddev);
905 dev_info(&pdev->dev, "OMAP DMA engine driver\n");
910 static int omap_dma_remove(struct platform_device *pdev)
912 struct omap_dmadev *od = platform_get_drvdata(pdev);
914 if (pdev->dev.of_node)
915 of_dma_controller_free(pdev->dev.of_node);
917 dma_async_device_unregister(&od->ddev);
923 static const struct of_device_id omap_dma_match[] = {
924 { .compatible = "ti,omap2420-sdma", },
925 { .compatible = "ti,omap2430-sdma", },
926 { .compatible = "ti,omap3430-sdma", },
927 { .compatible = "ti,omap3630-sdma", },
928 { .compatible = "ti,omap4430-sdma", },
931 MODULE_DEVICE_TABLE(of, omap_dma_match);
933 static struct platform_driver omap_dma_driver = {
934 .probe = omap_dma_probe,
935 .remove = omap_dma_remove,
937 .name = "omap-dma-engine",
938 .owner = THIS_MODULE,
939 .of_match_table = of_match_ptr(omap_dma_match),
943 bool omap_dma_filter_fn(struct dma_chan *chan, void *param)
945 if (chan->device->dev->driver == &omap_dma_driver.driver) {
946 struct omap_chan *c = to_omap_dma_chan(chan);
947 unsigned req = *(unsigned *)param;
949 return req == c->dma_sig;
953 EXPORT_SYMBOL_GPL(omap_dma_filter_fn);
955 static int omap_dma_init(void)
957 return platform_driver_register(&omap_dma_driver);
959 subsys_initcall(omap_dma_init);
961 static void __exit omap_dma_exit(void)
963 platform_driver_unregister(&omap_dma_driver);
965 module_exit(omap_dma_exit);
967 MODULE_AUTHOR("Russell King");
968 MODULE_LICENSE("GPL");