Lines Matching +full:max +full:- +full:burst +full:- +full:len
1 // SPDX-License-Identifier: GPL-2.0-only
11 #include <linux/dma-mapping.h>
22 #include <linux/dma/pxa-dma.h>
25 #include "virt-dma.h"
36 #define PXA_DCSR_NODESC BIT(30) /* No-Descriptor Fetch (read / write) */
38 #define PXA_DCSR_REQPEND BIT(8) /* Request Pending (read-only) */
39 #define PXA_DCSR_STOPSTATE BIT(3) /* Stop State (read-only) */
64 #define PXA_DCMD_ENDIAN BIT(18) /* Device Endian-ness. */
65 #define PXA_DCMD_BURST8 (1 << 16) /* 8 byte burst */
66 #define PXA_DCMD_BURST16 (2 << 16) /* 16 byte burst */
67 #define PXA_DCMD_BURST32 (3 << 16) /* 32 byte burst */
71 #define PXA_DCMD_LENGTH 0x01fff /* length mask (max = 8K - 1) */
74 #define PDMA_MAX_DESC_BYTES (PXA_DCMD_LENGTH & ~((1 << PDMA_ALIGNMENT) - 1))
86 size_t len; /* Number of bytes xfered */ member
115 /* protected by vc->lock */
146 readl_relaxed((phy)->base + _reg((phy)->idx))
150 _v = readl_relaxed((phy)->base + _reg((phy)->idx)); \
151 dev_vdbg(&phy->vchan->vc.chan.dev->device, \
158 writel((val), (phy)->base + _reg((phy)->idx)); \
159 dev_vdbg(&phy->vchan->vc.chan.dev->device, \
165 writel_relaxed((val), (phy)->base + _reg((phy)->idx)); \
166 dev_vdbg(&phy->vchan->vc.chan.dev->device, \
190 struct pxad_phy *phy = s->private; in requester_chan_show()
194 seq_printf(s, "DMA channel %d requester :\n", phy->idx); in requester_chan_show()
196 drcmr = readl_relaxed(phy->base + pxad_drcmr(i)); in requester_chan_show()
197 if ((drcmr & DRCMR_CHLNUM) == phy->idx) in requester_chan_show()
206 int burst = (dcmd >> 16) & 0x3; in dbg_burst_from_dcmd() local
208 return burst ? 4 << burst : 0; in dbg_burst_from_dcmd()
221 struct pxad_phy *phy = s->private; in descriptors_show()
222 int i, max_show = 20, burst, width; in descriptors_show() local
229 seq_printf(s, "DMA channel %d descriptors :\n", phy->idx); in descriptors_show()
233 dcmd = desc->dcmd; in descriptors_show()
234 burst = dbg_burst_from_dcmd(dcmd); in descriptors_show()
239 seq_printf(s, "\tDDADR = %08x\n", desc->ddadr); in descriptors_show()
240 seq_printf(s, "\tDSADR = %08x\n", desc->dsadr); in descriptors_show()
241 seq_printf(s, "\tDTADR = %08x\n", desc->dtadr); in descriptors_show()
242 seq_printf(s, "\tDCMD = %08x (%s%s%s%s%s%s%sburst=%d width=%d len=%d)\n", in descriptors_show()
247 PXA_DCMD_STR(ENDIAN), burst, width, in descriptors_show()
249 phys_desc = desc->ddadr; in descriptors_show()
252 seq_printf(s, "[%03d] Desc at %08lx ... max display reached\n", in descriptors_show()
264 struct pxad_phy *phy = s->private; in chan_state_show()
266 int burst, width; in chan_state_show() local
273 burst = dbg_burst_from_dcmd(dcmd); in chan_state_show()
276 seq_printf(s, "DMA channel %d\n", phy->idx); in chan_state_show()
278 str_prio[(phy->idx & 0xf) / 4]); in chan_state_show()
280 _phy_readl_relaxed(phy, DALGN) & BIT(phy->idx) ? in chan_state_show()
292 seq_printf(s, "\tDCMD = %08x (%s%s%s%s%s%s%sburst=%d width=%d len=%d)\n", in chan_state_show()
297 PXA_DCMD_STR(ENDIAN), burst, width, dcmd & PXA_DCMD_LENGTH); in chan_state_show()
307 struct pxad_device *pdev = s->private; in state_show()
311 seq_printf(s, "\tChannel number: %d\n", pdev->nr_chans); in state_show()
330 dt = (void *)&pdev->phys[ch]; in pxad_dbg_alloc_chan()
344 pdev->dbgfs_chan = in pxad_init_debugfs()
345 kmalloc_array(pdev->nr_chans, sizeof(struct dentry *), in pxad_init_debugfs()
347 if (!pdev->dbgfs_chan) in pxad_init_debugfs()
350 pdev->dbgfs_root = debugfs_create_dir(dev_name(pdev->slave.dev), NULL); in pxad_init_debugfs()
352 debugfs_create_file("state", 0400, pdev->dbgfs_root, pdev, &state_fops); in pxad_init_debugfs()
354 chandir = debugfs_create_dir("channels", pdev->dbgfs_root); in pxad_init_debugfs()
356 for (i = 0; i < pdev->nr_chans; i++) in pxad_init_debugfs()
357 pdev->dbgfs_chan[i] = pxad_dbg_alloc_chan(pdev, i, chandir); in pxad_init_debugfs()
362 debugfs_remove_recursive(pdev->dbgfs_root); in pxad_cleanup_debugfs()
372 struct pxad_device *pdev = to_pxad_dev(pchan->vc.chan.device); in lookup_phy()
378 * ch 0 - 3, 16 - 19 <--> (0) in lookup_phy()
379 * ch 4 - 7, 20 - 23 <--> (1) in lookup_phy()
380 * ch 8 - 11, 24 - 27 <--> (2) in lookup_phy()
381 * ch 12 - 15, 28 - 31 <--> (3) in lookup_phy()
384 spin_lock_irqsave(&pdev->phy_lock, flags); in lookup_phy()
385 for (prio = pchan->prio; prio >= PXAD_PRIO_HIGHEST; prio--) { in lookup_phy()
386 for (i = 0; i < pdev->nr_chans; i++) { in lookup_phy()
389 phy = &pdev->phys[i]; in lookup_phy()
390 if (!phy->vchan) { in lookup_phy()
391 phy->vchan = pchan; in lookup_phy()
399 spin_unlock_irqrestore(&pdev->phy_lock, flags); in lookup_phy()
400 dev_dbg(&pchan->vc.chan.dev->device, in lookup_phy()
402 found ? found->idx : -1); in lookup_phy()
409 struct pxad_device *pdev = to_pxad_dev(chan->vc.chan.device); in pxad_free_phy()
413 dev_dbg(&chan->vc.chan.dev->device, in pxad_free_phy()
415 if (!chan->phy) in pxad_free_phy()
419 if (chan->drcmr <= pdev->nr_requestors) { in pxad_free_phy()
420 reg = pxad_drcmr(chan->drcmr); in pxad_free_phy()
421 writel_relaxed(0, chan->phy->base + reg); in pxad_free_phy()
424 spin_lock_irqsave(&pdev->phy_lock, flags); in pxad_free_phy()
425 chan->phy->vchan = NULL; in pxad_free_phy()
426 chan->phy = NULL; in pxad_free_phy()
427 spin_unlock_irqrestore(&pdev->phy_lock, flags); in pxad_free_phy()
433 struct pxad_phy *phy = chan->phy; in is_chan_running()
445 BUG_ON(!chan->phy); in is_running_chan_misaligned()
446 dalgn = phy_readl_relaxed(chan->phy, DALGN); in is_running_chan_misaligned()
447 return dalgn & (BIT(chan->phy->idx)); in is_running_chan_misaligned()
455 if (!phy->vchan) in phy_enable()
458 dev_dbg(&phy->vchan->vc.chan.dev->device, in phy_enable()
460 phy, phy->idx, misaligned); in phy_enable()
462 pdev = to_pxad_dev(phy->vchan->vc.chan.device); in phy_enable()
463 if (phy->vchan->drcmr <= pdev->nr_requestors) { in phy_enable()
464 reg = pxad_drcmr(phy->vchan->drcmr); in phy_enable()
465 writel_relaxed(DRCMR_MAPVLD | phy->idx, phy->base + reg); in phy_enable()
470 dalgn |= BIT(phy->idx); in phy_enable()
472 dalgn &= ~BIT(phy->idx); in phy_enable()
487 dev_dbg(&phy->vchan->vc.chan.dev->device, in phy_disable()
488 "%s(): phy=%p(%d)\n", __func__, phy, phy->idx); in phy_disable()
495 dev_dbg(&chan->vc.chan.dev->device, in pxad_launch_chan()
497 if (!chan->phy) { in pxad_launch_chan()
498 chan->phy = lookup_phy(chan); in pxad_launch_chan()
499 if (!chan->phy) { in pxad_launch_chan()
500 dev_dbg(&chan->vc.chan.dev->device, in pxad_launch_chan()
505 chan->bus_error = 0; in pxad_launch_chan()
511 phy_writel(chan->phy, desc->first, DDADR); in pxad_launch_chan()
512 phy_enable(chan->phy, chan->misaligned); in pxad_launch_chan()
513 wake_up(&chan->wq_state); in pxad_launch_chan()
520 sw_desc->hw_desc[sw_desc->nb_desc - 1]; in set_updater_desc()
521 dma_addr_t dma = sw_desc->hw_desc[sw_desc->nb_desc - 2]->ddadr; in set_updater_desc()
523 updater->ddadr = DDADR_STOP; in set_updater_desc()
524 updater->dsadr = dma; in set_updater_desc()
525 updater->dtadr = dma + 8; in set_updater_desc()
526 updater->dcmd = PXA_DCMD_WIDTH4 | PXA_DCMD_BURST32 | in set_updater_desc()
529 updater->dcmd |= PXA_DCMD_ENDIRQEN; in set_updater_desc()
530 if (sw_desc->cyclic) in set_updater_desc()
531 sw_desc->hw_desc[sw_desc->nb_desc - 2]->ddadr = sw_desc->first; in set_updater_desc()
538 sw_desc->hw_desc[sw_desc->nb_desc - 1]; in is_desc_completed()
540 return updater->dtadr != (updater->dsadr + 8); in is_desc_completed()
550 dma_to_chain = desc2->first; in pxad_desc_chain()
551 desc1->hw_desc[desc1->nb_desc - 1]->ddadr = dma_to_chain; in pxad_desc_chain()
558 struct pxad_chan *chan = to_pxad_chan(&vc->chan); in pxad_try_hotchain()
568 BUG_ON(list_empty(&vc->desc_issued)); in pxad_try_hotchain()
571 to_pxad_sw_desc(vd)->misaligned) in pxad_try_hotchain()
574 vd_last_issued = list_entry(vc->desc_issued.prev, in pxad_try_hotchain()
587 u32 dint = readl(phy->base + DINT); in clear_chan_irq()
589 if (!(dint & BIT(phy->idx))) in clear_chan_irq()
595 if ((dcsr & PXA_DCSR_BUSERR) && (phy->vchan)) in clear_chan_irq()
596 dev_warn(&phy->vchan->vc.chan.dev->device, in clear_chan_irq()
598 __func__, &phy->vchan); in clear_chan_irq()
606 struct pxad_chan *chan = phy->vchan; in pxad_chan_handler()
618 spin_lock(&chan->vc.lock); in pxad_chan_handler()
619 list_for_each_entry_safe(vd, tmp, &chan->vc.desc_issued, node) { in pxad_chan_handler()
621 dev_dbg(&chan->vc.chan.dev->device, in pxad_chan_handler()
623 __func__, vd, vd->tx.cookie, vd_completed, in pxad_chan_handler()
625 last_started = vd->tx.cookie; in pxad_chan_handler()
626 if (to_pxad_sw_desc(vd)->cyclic) { in pxad_chan_handler()
631 list_del(&vd->node); in pxad_chan_handler()
639 chan->bus_error = last_started; in pxad_chan_handler()
643 if (!chan->bus_error && dcsr & PXA_DCSR_STOPSTATE) { in pxad_chan_handler()
644 dev_dbg(&chan->vc.chan.dev->device, in pxad_chan_handler()
647 list_empty(&chan->vc.desc_submitted), in pxad_chan_handler()
648 list_empty(&chan->vc.desc_issued)); in pxad_chan_handler()
651 if (list_empty(&chan->vc.desc_issued)) { in pxad_chan_handler()
652 chan->misaligned = in pxad_chan_handler()
653 !list_empty(&chan->vc.desc_submitted); in pxad_chan_handler()
655 vd = list_first_entry(&chan->vc.desc_issued, in pxad_chan_handler()
660 spin_unlock(&chan->vc.lock); in pxad_chan_handler()
661 wake_up(&chan->wq_state); in pxad_chan_handler()
670 u32 dint = readl(pdev->base + DINT); in pxad_int_handler()
675 dint &= (dint - 1); in pxad_int_handler()
676 phy = &pdev->phys[i]; in pxad_int_handler()
687 struct pxad_device *pdev = to_pxad_dev(chan->vc.chan.device); in pxad_alloc_chan_resources()
689 if (chan->desc_pool) in pxad_alloc_chan_resources()
692 chan->desc_pool = dma_pool_create(dma_chan_name(dchan), in pxad_alloc_chan_resources()
693 pdev->slave.dev, in pxad_alloc_chan_resources()
697 if (!chan->desc_pool) { in pxad_alloc_chan_resources()
698 dev_err(&chan->vc.chan.dev->device, in pxad_alloc_chan_resources()
701 return -ENOMEM; in pxad_alloc_chan_resources()
711 vchan_free_chan_resources(&chan->vc); in pxad_free_chan_resources()
712 dma_pool_destroy(chan->desc_pool); in pxad_free_chan_resources()
713 chan->desc_pool = NULL; in pxad_free_chan_resources()
715 chan->drcmr = U32_MAX; in pxad_free_chan_resources()
716 chan->prio = PXAD_PRIO_LOWEST; in pxad_free_chan_resources()
725 for (i = sw_desc->nb_desc - 1; i >= 0; i--) { in pxad_free_desc()
727 dma = sw_desc->hw_desc[i - 1]->ddadr; in pxad_free_desc()
729 dma = sw_desc->first; in pxad_free_desc()
730 dma_pool_free(sw_desc->desc_pool, in pxad_free_desc()
731 sw_desc->hw_desc[i], dma); in pxad_free_desc()
733 sw_desc->nb_desc = 0; in pxad_free_desc()
748 sw_desc->desc_pool = chan->desc_pool; in pxad_alloc_desc()
751 sw_desc->hw_desc[i] = dma_pool_alloc(sw_desc->desc_pool, in pxad_alloc_desc()
753 if (!sw_desc->hw_desc[i]) { in pxad_alloc_desc()
754 dev_err(&chan->vc.chan.dev->device, in pxad_alloc_desc()
756 __func__, i, sw_desc->desc_pool); in pxad_alloc_desc()
761 sw_desc->first = dma; in pxad_alloc_desc()
763 sw_desc->hw_desc[i - 1]->ddadr = dma; in pxad_alloc_desc()
764 sw_desc->nb_desc++; in pxad_alloc_desc()
769 pxad_free_desc(&sw_desc->vd); in pxad_alloc_desc()
775 struct virt_dma_chan *vc = to_virt_chan(tx->chan); in pxad_tx_submit()
776 struct pxad_chan *chan = to_pxad_chan(&vc->chan); in pxad_tx_submit()
782 set_updater_desc(to_pxad_sw_desc(vd), tx->flags); in pxad_tx_submit()
784 spin_lock_irqsave(&vc->lock, flags); in pxad_tx_submit()
787 if (list_empty(&vc->desc_submitted) && pxad_try_hotchain(vc, vd)) { in pxad_tx_submit()
788 list_move_tail(&vd->node, &vc->desc_issued); in pxad_tx_submit()
789 dev_dbg(&chan->vc.chan.dev->device, in pxad_tx_submit()
798 if (!list_empty(&vc->desc_submitted)) { in pxad_tx_submit()
799 vd_chained = list_entry(vc->desc_submitted.prev, in pxad_tx_submit()
807 if (chan->misaligned || !to_pxad_sw_desc(vd)->misaligned) in pxad_tx_submit()
812 dev_dbg(&chan->vc.chan.dev->device, in pxad_tx_submit()
815 list_move_tail(&vd->node, &vc->desc_submitted); in pxad_tx_submit()
816 chan->misaligned |= to_pxad_sw_desc(vd)->misaligned; in pxad_tx_submit()
819 spin_unlock_irqrestore(&vc->lock, flags); in pxad_tx_submit()
829 spin_lock_irqsave(&chan->vc.lock, flags); in pxad_issue_pending()
830 if (list_empty(&chan->vc.desc_submitted)) in pxad_issue_pending()
833 vd_first = list_first_entry(&chan->vc.desc_submitted, in pxad_issue_pending()
835 dev_dbg(&chan->vc.chan.dev->device, in pxad_issue_pending()
836 "%s(): txd %p[%x]", __func__, vd_first, vd_first->tx.cookie); in pxad_issue_pending()
838 vchan_issue_pending(&chan->vc); in pxad_issue_pending()
839 if (!pxad_try_hotchain(&chan->vc, vd_first)) in pxad_issue_pending()
842 spin_unlock_irqrestore(&chan->vc.lock, flags); in pxad_issue_pending()
852 INIT_LIST_HEAD(&vd->node); in pxad_tx_prep()
854 tx->tx_submit = pxad_tx_submit; in pxad_tx_prep()
855 dev_dbg(&chan->vc.chan.dev->device, in pxad_tx_prep()
857 vc, vd, vd->tx.cookie, in pxad_tx_prep()
869 struct pxad_device *pdev = to_pxad_dev(chan->vc.chan.device); in pxad_get_config()
873 maxburst = chan->cfg.src_maxburst; in pxad_get_config()
874 width = chan->cfg.src_addr_width; in pxad_get_config()
875 dev_addr = chan->cfg.src_addr; in pxad_get_config()
878 if (chan->drcmr <= pdev->nr_requestors) in pxad_get_config()
882 maxburst = chan->cfg.dst_maxburst; in pxad_get_config()
883 width = chan->cfg.dst_addr_width; in pxad_get_config()
884 dev_addr = chan->cfg.dst_addr; in pxad_get_config()
887 if (chan->drcmr <= pdev->nr_requestors) in pxad_get_config()
894 dev_dbg(&chan->vc.chan.dev->device, in pxad_get_config()
916 size_t len, unsigned long flags) in pxad_prep_memcpy() argument
925 if (!dchan || !len) in pxad_prep_memcpy()
928 dev_dbg(&chan->vc.chan.dev->device, in pxad_prep_memcpy()
929 "%s(): dma_dst=0x%lx dma_src=0x%lx len=%zu flags=%lx\n", in pxad_prep_memcpy()
931 len, flags); in pxad_prep_memcpy()
934 nb_desc = DIV_ROUND_UP(len, PDMA_MAX_DESC_BYTES); in pxad_prep_memcpy()
938 sw_desc->len = len; in pxad_prep_memcpy()
942 sw_desc->misaligned = true; in pxad_prep_memcpy()
946 hw_desc = sw_desc->hw_desc[i++]; in pxad_prep_memcpy()
947 copy = min_t(size_t, len, PDMA_MAX_DESC_BYTES); in pxad_prep_memcpy()
948 hw_desc->dcmd = dcmd | (PXA_DCMD_LENGTH & copy); in pxad_prep_memcpy()
949 hw_desc->dsadr = dma_src; in pxad_prep_memcpy()
950 hw_desc->dtadr = dma_dst; in pxad_prep_memcpy()
951 len -= copy; in pxad_prep_memcpy()
954 } while (len); in pxad_prep_memcpy()
957 return pxad_tx_prep(&chan->vc, &sw_desc->vd, flags); in pxad_prep_memcpy()
967 size_t len, avail; in pxad_prep_slave_sg() local
977 dev_dbg(&chan->vc.chan.dev->device, in pxad_prep_slave_sg()
989 sw_desc->len += avail; in pxad_prep_slave_sg()
992 len = min_t(size_t, avail, PDMA_MAX_DESC_BYTES); in pxad_prep_slave_sg()
994 sw_desc->misaligned = true; in pxad_prep_slave_sg()
996 sw_desc->hw_desc[j]->dcmd = in pxad_prep_slave_sg()
997 dcmd | (PXA_DCMD_LENGTH & len); in pxad_prep_slave_sg()
998 sw_desc->hw_desc[j]->dsadr = dsadr ? dsadr : dma; in pxad_prep_slave_sg()
999 sw_desc->hw_desc[j++]->dtadr = dtadr ? dtadr : dma; in pxad_prep_slave_sg()
1001 dma += len; in pxad_prep_slave_sg()
1002 avail -= len; in pxad_prep_slave_sg()
1007 return pxad_tx_prep(&chan->vc, &sw_desc->vd, flags); in pxad_prep_slave_sg()
1012 dma_addr_t buf_addr, size_t len, size_t period_len, in pxad_prep_dma_cyclic() argument
1022 if (!dchan || !len || !period_len) in pxad_prep_dma_cyclic()
1025 dev_err(&chan->vc.chan.dev->device, in pxad_prep_dma_cyclic()
1030 if (len % period_len != 0 || period_len > PDMA_MAX_DESC_BYTES || in pxad_prep_dma_cyclic()
1036 dev_dbg(&chan->vc.chan.dev->device, in pxad_prep_dma_cyclic()
1037 "%s(): buf_addr=0x%lx len=%zu period=%zu dir=%d flags=%lx\n", in pxad_prep_dma_cyclic()
1038 __func__, (unsigned long)buf_addr, len, period_len, dir, flags); in pxad_prep_dma_cyclic()
1041 nb_desc *= DIV_ROUND_UP(len, period_len); in pxad_prep_dma_cyclic()
1045 sw_desc->cyclic = true; in pxad_prep_dma_cyclic()
1046 sw_desc->len = len; in pxad_prep_dma_cyclic()
1048 phw_desc = sw_desc->hw_desc; in pxad_prep_dma_cyclic()
1051 phw_desc[0]->dsadr = dsadr ? dsadr : dma; in pxad_prep_dma_cyclic()
1052 phw_desc[0]->dtadr = dtadr ? dtadr : dma; in pxad_prep_dma_cyclic()
1053 phw_desc[0]->dcmd = dcmd; in pxad_prep_dma_cyclic()
1056 len -= period_len; in pxad_prep_dma_cyclic()
1057 } while (len); in pxad_prep_dma_cyclic()
1060 return pxad_tx_prep(&chan->vc, &sw_desc->vd, flags); in pxad_prep_dma_cyclic()
1069 return -EINVAL; in pxad_config()
1071 chan->cfg = *cfg; in pxad_config()
1078 struct pxad_device *pdev = to_pxad_dev(chan->vc.chan.device); in pxad_terminate_all()
1084 dev_dbg(&chan->vc.chan.dev->device, in pxad_terminate_all()
1085 "%s(): vchan %p: terminate all\n", __func__, &chan->vc); in pxad_terminate_all()
1087 spin_lock_irqsave(&chan->vc.lock, flags); in pxad_terminate_all()
1088 vchan_get_all_descriptors(&chan->vc, &head); in pxad_terminate_all()
1091 dev_dbg(&chan->vc.chan.dev->device, in pxad_terminate_all()
1093 vd, vd->tx.cookie, is_desc_completed(vd)); in pxad_terminate_all()
1096 phy = chan->phy; in pxad_terminate_all()
1098 phy_disable(chan->phy); in pxad_terminate_all()
1100 chan->phy = NULL; in pxad_terminate_all()
1101 spin_lock(&pdev->phy_lock); in pxad_terminate_all()
1102 phy->vchan = NULL; in pxad_terminate_all()
1103 spin_unlock(&pdev->phy_lock); in pxad_terminate_all()
1105 spin_unlock_irqrestore(&chan->vc.lock, flags); in pxad_terminate_all()
1106 vchan_dma_desc_free_list(&chan->vc, &head); in pxad_terminate_all()
1117 u32 curr, start, len, end, residue = 0; in pxad_residue() local
1126 if (!chan->phy) in pxad_residue()
1129 spin_lock_irqsave(&chan->vc.lock, flags); in pxad_residue()
1131 vd = vchan_find_desc(&chan->vc, cookie); in pxad_residue()
1136 if (sw_desc->hw_desc[0]->dcmd & PXA_DCMD_INCSRCADDR) in pxad_residue()
1137 curr = phy_readl_relaxed(chan->phy, DSADR); in pxad_residue()
1139 curr = phy_readl_relaxed(chan->phy, DTADR); in pxad_residue()
1151 for (i = 0; i < sw_desc->nb_desc - 1; i++) { in pxad_residue()
1152 hw_desc = sw_desc->hw_desc[i]; in pxad_residue()
1153 if (sw_desc->hw_desc[0]->dcmd & PXA_DCMD_INCSRCADDR) in pxad_residue()
1154 start = hw_desc->dsadr; in pxad_residue()
1156 start = hw_desc->dtadr; in pxad_residue()
1157 len = hw_desc->dcmd & PXA_DCMD_LENGTH; in pxad_residue()
1158 end = start + len; in pxad_residue()
1170 residue += len; in pxad_residue()
1172 residue += end - curr; in pxad_residue()
1177 residue = sw_desc->len; in pxad_residue()
1180 spin_unlock_irqrestore(&chan->vc.lock, flags); in pxad_residue()
1181 dev_dbg(&chan->vc.chan.dev->device, in pxad_residue()
1194 if (cookie == chan->bus_error) in pxad_tx_status()
1208 wait_event(chan->wq_state, !is_chan_running(chan)); in pxad_synchronize()
1209 vchan_synchronize(&chan->vc); in pxad_synchronize()
1216 list_for_each_entry_safe(c, cn, &dmadev->channels, in pxad_free_channels()
1218 list_del(&c->vc.chan.device_node); in pxad_free_channels()
1219 tasklet_kill(&c->vc.task); in pxad_free_channels()
1228 pxad_free_channels(&pdev->slave); in pxad_remove()
1243 pdev->phys = devm_kcalloc(&op->dev, nb_phy_chans, in pxad_init_phys()
1244 sizeof(pdev->phys[0]), GFP_KERNEL); in pxad_init_phys()
1245 if (!pdev->phys) in pxad_init_phys()
1246 return -ENOMEM; in pxad_init_phys()
1253 phy = &pdev->phys[i]; in pxad_init_phys()
1254 phy->base = pdev->base; in pxad_init_phys()
1255 phy->idx = i; in pxad_init_phys()
1258 ret = devm_request_irq(&op->dev, irq, in pxad_init_phys()
1260 IRQF_SHARED, "pxa-dma", phy); in pxad_init_phys()
1262 ret = devm_request_irq(&op->dev, irq0, in pxad_init_phys()
1264 IRQF_SHARED, "pxa-dma", pdev); in pxad_init_phys()
1266 dev_err(pdev->slave.dev, in pxad_init_phys()
1277 { .compatible = "marvell,pdma-1.0", },
1285 struct pxad_device *d = ofdma->of_dma_data; in pxad_dma_xlate()
1288 chan = dma_get_any_slave_channel(&d->slave); in pxad_dma_xlate()
1292 to_pxad_chan(chan)->drcmr = dma_spec->args[0]; in pxad_dma_xlate()
1293 to_pxad_chan(chan)->prio = dma_spec->args[1]; in pxad_dma_xlate()
1307 pdev->nr_chans = nr_phy_chans; in pxad_init_dmadev()
1308 pdev->nr_requestors = nr_requestors; in pxad_init_dmadev()
1309 INIT_LIST_HEAD(&pdev->slave.channels); in pxad_init_dmadev()
1310 pdev->slave.device_alloc_chan_resources = pxad_alloc_chan_resources; in pxad_init_dmadev()
1311 pdev->slave.device_free_chan_resources = pxad_free_chan_resources; in pxad_init_dmadev()
1312 pdev->slave.device_tx_status = pxad_tx_status; in pxad_init_dmadev()
1313 pdev->slave.device_issue_pending = pxad_issue_pending; in pxad_init_dmadev()
1314 pdev->slave.device_config = pxad_config; in pxad_init_dmadev()
1315 pdev->slave.device_synchronize = pxad_synchronize; in pxad_init_dmadev()
1316 pdev->slave.device_terminate_all = pxad_terminate_all; in pxad_init_dmadev()
1318 if (op->dev.coherent_dma_mask) in pxad_init_dmadev()
1319 dma_set_mask(&op->dev, op->dev.coherent_dma_mask); in pxad_init_dmadev()
1321 dma_set_mask(&op->dev, DMA_BIT_MASK(32)); in pxad_init_dmadev()
1328 c = devm_kzalloc(&op->dev, sizeof(*c), GFP_KERNEL); in pxad_init_dmadev()
1330 return -ENOMEM; in pxad_init_dmadev()
1332 c->drcmr = U32_MAX; in pxad_init_dmadev()
1333 c->prio = PXAD_PRIO_LOWEST; in pxad_init_dmadev()
1334 c->vc.desc_free = pxad_free_desc; in pxad_init_dmadev()
1335 vchan_init(&c->vc, &pdev->slave); in pxad_init_dmadev()
1336 init_waitqueue_head(&c->wq_state); in pxad_init_dmadev()
1339 return dmaenginem_async_device_register(&pdev->slave); in pxad_init_dmadev()
1347 struct mmp_dma_platdata *pdata = dev_get_platdata(&op->dev); in pxad_probe()
1353 pdev = devm_kzalloc(&op->dev, sizeof(*pdev), GFP_KERNEL); in pxad_probe()
1355 return -ENOMEM; in pxad_probe()
1357 spin_lock_init(&pdev->phy_lock); in pxad_probe()
1359 pdev->base = devm_platform_ioremap_resource(op, 0); in pxad_probe()
1360 if (IS_ERR(pdev->base)) in pxad_probe()
1361 return PTR_ERR(pdev->base); in pxad_probe()
1363 of_id = of_match_device(pxad_dt_ids, &op->dev); in pxad_probe()
1365 /* Parse new and deprecated dma-channels properties */ in pxad_probe()
1366 if (of_property_read_u32(op->dev.of_node, "dma-channels", in pxad_probe()
1368 of_property_read_u32(op->dev.of_node, "#dma-channels", in pxad_probe()
1370 /* Parse new and deprecated dma-requests properties */ in pxad_probe()
1371 ret = of_property_read_u32(op->dev.of_node, "dma-requests", in pxad_probe()
1374 ret = of_property_read_u32(op->dev.of_node, "#dma-requests", in pxad_probe()
1377 dev_warn(pdev->slave.dev, in pxad_probe()
1378 "#dma-requests set to default 32 as missing in OF: %d", in pxad_probe()
1382 } else if (pdata && pdata->dma_channels) { in pxad_probe()
1383 dma_channels = pdata->dma_channels; in pxad_probe()
1384 nb_requestors = pdata->nb_requestors; in pxad_probe()
1385 slave_map = pdata->slave_map; in pxad_probe()
1386 slave_map_cnt = pdata->slave_map_cnt; in pxad_probe()
1391 dma_cap_set(DMA_SLAVE, pdev->slave.cap_mask); in pxad_probe()
1392 dma_cap_set(DMA_MEMCPY, pdev->slave.cap_mask); in pxad_probe()
1393 dma_cap_set(DMA_CYCLIC, pdev->slave.cap_mask); in pxad_probe()
1394 dma_cap_set(DMA_PRIVATE, pdev->slave.cap_mask); in pxad_probe()
1395 pdev->slave.device_prep_dma_memcpy = pxad_prep_memcpy; in pxad_probe()
1396 pdev->slave.device_prep_slave_sg = pxad_prep_slave_sg; in pxad_probe()
1397 pdev->slave.device_prep_dma_cyclic = pxad_prep_dma_cyclic; in pxad_probe()
1398 pdev->slave.filter.map = slave_map; in pxad_probe()
1399 pdev->slave.filter.mapcnt = slave_map_cnt; in pxad_probe()
1400 pdev->slave.filter.fn = pxad_filter_fn; in pxad_probe()
1402 pdev->slave.copy_align = PDMA_ALIGNMENT; in pxad_probe()
1403 pdev->slave.src_addr_widths = widths; in pxad_probe()
1404 pdev->slave.dst_addr_widths = widths; in pxad_probe()
1405 pdev->slave.directions = BIT(DMA_MEM_TO_DEV) | BIT(DMA_DEV_TO_MEM); in pxad_probe()
1406 pdev->slave.residue_granularity = DMA_RESIDUE_GRANULARITY_DESCRIPTOR; in pxad_probe()
1407 pdev->slave.descriptor_reuse = true; in pxad_probe()
1409 pdev->slave.dev = &op->dev; in pxad_probe()
1412 dev_err(pdev->slave.dev, "unable to register\n"); in pxad_probe()
1416 if (op->dev.of_node) { in pxad_probe()
1417 /* Device-tree DMA controller registration */ in pxad_probe()
1418 ret = of_dma_controller_register(op->dev.of_node, in pxad_probe()
1421 dev_err(pdev->slave.dev, in pxad_probe()
1429 dev_info(pdev->slave.dev, "initialized %d channels on %d requestors\n", in pxad_probe()
1435 { "pxa-dma", },
1441 .name = "pxa-dma",
1454 if (chan->device->dev->driver != &pxad_driver.driver) in pxad_filter_fn()
1457 c->drcmr = p->drcmr; in pxad_filter_fn()
1458 c->prio = p->prio; in pxad_filter_fn()