Lines Matching +full:config +full:- +full:cond
1 // SPDX-License-Identifier: GPL-2.0-or-later
19 #include <linux/dma-mapping.h>
46 CCTRL6, /* Cacheable write-through, allocate on writes only */
47 CCTRL7, /* Cacheable write-back, allocate on writes only */
245 * at 1byte/burst for P<->M and M<->M respectively.
247 * should be enough for P<->M and M<->M respectively.
382 /* Index of the last submitted request or -1 if the DMA is stopped */
423 /* DMA-Engine Channel */
449 /* For D-to-M and M-to-D channels */
453 /* DMA-mapped view of the FIFO; may differ if an IOMMU is present */
466 /* DMA-Engine Device */
514 .quirk = "arm,pl330-broken-no-flushp",
518 .quirk = "arm,pl330-periph-burst",
561 return thrd->req[0].desc != NULL && thrd->req[1].desc != NULL; in _queue_full()
566 return thrd->dmac->manager == thrd; in is_manager()
569 /* If manager of the thread is in Non-Secure mode */
572 return (thrd->dmac->pcfg.mode & DMAC_MODE_NS) ? true : false; in _manager_ns()
608 static inline u32 _emit_LD(unsigned dry_run, u8 buf[], enum pl330_cond cond) in _emit_LD() argument
615 if (cond == SINGLE) in _emit_LD()
617 else if (cond == BURST) in _emit_LD()
621 cond == SINGLE ? 'S' : (cond == BURST ? 'B' : 'A')); in _emit_LD()
627 enum pl330_cond cond, u8 peri) in _emit_LDP() argument
634 if (cond == BURST) in _emit_LDP()
642 cond == SINGLE ? 'S' : 'B', peri >> 3); in _emit_LDP()
658 cnt--; /* DMAC increments by 1 internally */ in _emit_LP()
667 enum pl330_cond cond; member
676 enum pl330_cond cond = arg->cond; in _emit_LPEND() local
677 bool forever = arg->forever; in _emit_LPEND()
678 unsigned loop = arg->loop; in _emit_LPEND()
679 u8 bjump = arg->bjump; in _emit_LPEND()
692 if (cond == SINGLE) in _emit_LPEND()
694 else if (cond == BURST) in _emit_LPEND()
701 cond == SINGLE ? 'S' : (cond == BURST ? 'B' : 'A'), in _emit_LPEND()
765 static inline u32 _emit_ST(unsigned dry_run, u8 buf[], enum pl330_cond cond) in _emit_ST() argument
772 if (cond == SINGLE) in _emit_ST()
774 else if (cond == BURST) in _emit_ST()
778 cond == SINGLE ? 'S' : (cond == BURST ? 'B' : 'A')); in _emit_ST()
784 enum pl330_cond cond, u8 peri) in _emit_STP() argument
791 if (cond == BURST) in _emit_STP()
799 cond == SINGLE ? 'S' : 'B', peri >> 3); in _emit_STP()
805 enum pl330_cond cond, u8 peri) in _emit_WFP() argument
812 if (cond == SINGLE) in _emit_WFP()
814 else if (cond == BURST) in _emit_WFP()
824 cond == SINGLE ? 'S' : (cond == BURST ? 'B' : 'P'), peri >> 3); in _emit_WFP()
850 u8 chan = arg->chan; in _emit_GO()
851 u32 addr = arg->addr; in _emit_GO()
852 unsigned ns = arg->ns; in _emit_GO()
870 /* Returns Time-Out */
873 void __iomem *regs = thrd->dmac->base; in _until_dmac_idle()
882 } while (--loops); in _until_dmac_idle()
893 void __iomem *regs = thrd->dmac->base; in _execute_DBGINSN()
896 /* If timed out due to halted state-machine */ in _execute_DBGINSN()
898 dev_err(thrd->dmac->ddma.dev, "DMAC halted!\n"); in _execute_DBGINSN()
905 val |= (thrd->id << 8); /* Channel Number */ in _execute_DBGINSN()
918 void __iomem *regs = thrd->dmac->base; in _state()
924 val = readl(regs + CS(thrd->id)) & 0xf; in _state()
976 void __iomem *regs = thrd->dmac->base; in _stop()
994 if (inten & (1 << thrd->ev)) in _stop()
995 writel(1 << thrd->ev, regs + INTCLR); in _stop()
997 writel(inten & ~(1 << thrd->ev), regs + INTEN); in _stop()
1003 void __iomem *regs = thrd->dmac->base; in _trigger()
1015 idx = 1 - thrd->lstenq; in _trigger()
1016 if (thrd->req[idx].desc != NULL) { in _trigger()
1017 req = &thrd->req[idx]; in _trigger()
1019 idx = thrd->lstenq; in _trigger()
1020 if (thrd->req[idx].desc != NULL) in _trigger()
1021 req = &thrd->req[idx]; in _trigger()
1031 if (idx == thrd->req_running) in _trigger()
1034 desc = req->desc; in _trigger()
1036 ns = desc->rqcfg.nonsecure ? 1 : 0; in _trigger()
1038 /* See 'Abort Sources' point-4 at Page 2-25 */ in _trigger()
1040 dev_info(thrd->dmac->ddma.dev, "%s:%d Recipe for ABORT!\n", in _trigger()
1043 go.chan = thrd->id; in _trigger()
1044 go.addr = req->mc_bus; in _trigger()
1049 writel(readl(regs + INTEN) | (1 << thrd->ev), regs + INTEN); in _trigger()
1054 thrd->req_running = idx; in _trigger()
1056 if (desc->rqtype == DMA_MEM_TO_DEV || desc->rqtype == DMA_DEV_TO_MEM) in _trigger()
1102 struct pl330_config *pcfg = pxs->desc->rqcfg.pcfg; in _ldst_memtomem()
1104 /* check lock-up free version */ in _ldst_memtomem()
1105 if (get_revision(pcfg->periph_id) >= PERIPH_REV_R1P0) { in _ldst_memtomem()
1106 while (cyc--) { in _ldst_memtomem()
1111 while (cyc--) { in _ldst_memtomem()
1123 enum pl330_cond cond, enum dma_transfer_direction direction, in _emit_load() argument
1131 off += _emit_LD(dry_run, &buf[off], cond); in _emit_load()
1135 if (cond == ALWAYS) { in _emit_load()
1141 off += _emit_LDP(dry_run, &buf[off], cond, in _emit_load()
1156 enum pl330_cond cond, enum dma_transfer_direction direction, in _emit_store() argument
1164 off += _emit_ST(dry_run, &buf[off], cond); in _emit_store()
1168 if (cond == ALWAYS) { in _emit_store()
1174 off += _emit_STP(dry_run, &buf[off], cond, in _emit_store()
1191 enum pl330_cond cond) in _ldst_peripheral() argument
1199 if (!(pl330->quirks & PL330_QUIRK_BROKEN_NO_FLUSHP)) in _ldst_peripheral()
1200 off += _emit_FLUSHP(dry_run, &buf[off], pxs->desc->peri); in _ldst_peripheral()
1201 while (cyc--) { in _ldst_peripheral()
1202 off += _emit_WFP(dry_run, &buf[off], cond, pxs->desc->peri); in _ldst_peripheral()
1203 off += _emit_load(dry_run, &buf[off], cond, pxs->desc->rqtype, in _ldst_peripheral()
1204 pxs->desc->peri); in _ldst_peripheral()
1205 off += _emit_store(dry_run, &buf[off], cond, pxs->desc->rqtype, in _ldst_peripheral()
1206 pxs->desc->peri); in _ldst_peripheral()
1216 enum pl330_cond cond = BRST_LEN(pxs->ccr) > 1 ? BURST : SINGLE; in _bursts() local
1218 if (pl330->quirks & PL330_QUIRK_PERIPH_BURST) in _bursts()
1219 cond = BURST; in _bursts()
1221 switch (pxs->desc->rqtype) { in _bursts()
1225 cond); in _bursts()
1244 * for mem-to-mem, mem-to-dev or dev-to-mem.
1256 * dregs_len = (total bytes - BURST_TO_BYTE(bursts, ccr)) / in _dregs()
1262 dregs_ccr = pxs->ccr; in _dregs()
1265 dregs_ccr |= (((transfer_length - 1) & 0xf) << in _dregs()
1267 dregs_ccr |= (((transfer_length - 1) & 0xf) << in _dregs()
1270 switch (pxs->desc->rqtype) { in _dregs()
1321 lpend.cond = ALWAYS; in _loop()
1335 * which is 8-bits and hence 255 in _loop()
1337 cycmax = (255 - (szlp + szlpend)) / szbrst; in _loop()
1353 lpend.cond = ALWAYS; in _loop()
1356 lpend.bjump = off - ljmp1; in _loop()
1360 lpend.cond = ALWAYS; in _loop()
1363 lpend.bjump = off - ljmp0; in _loop()
1378 struct pl330_xfer *x = &pxs->desc->px; in _setup_loops()
1379 u32 ccr = pxs->ccr; in _setup_loops()
1380 unsigned long c, bursts = BYTE_TO_BURST(x->bytes, ccr); in _setup_loops()
1381 int num_dregs = (x->bytes - BURST_TO_BYTE(bursts, ccr)) / in _setup_loops()
1388 bursts -= c; in _setup_loops()
1399 struct pl330_xfer *x = &pxs->desc->px; in _setup_xfer()
1402 /* DMAMOV SAR, x->src_addr */ in _setup_xfer()
1403 off += _emit_MOV(dry_run, &buf[off], SAR, x->src_addr); in _setup_xfer()
1404 /* DMAMOV DAR, x->dst_addr */ in _setup_xfer()
1405 off += _emit_MOV(dry_run, &buf[off], DAR, x->dst_addr); in _setup_xfer()
1421 struct _pl330_req *req = &thrd->req[index]; in _setup_req()
1422 u8 *buf = req->mc_cpu; in _setup_req()
1425 PL330_DBGMC_START(req->mc_bus); in _setup_req()
1428 off += _emit_MOV(dry_run, &buf[off], CCR, pxs->ccr); in _setup_req()
1433 off += _emit_SEV(dry_run, &buf[off], thrd->ev); in _setup_req()
1444 if (rqc->src_inc) in _prepare_ccr()
1447 if (rqc->dst_inc) in _prepare_ccr()
1451 if (rqc->privileged) in _prepare_ccr()
1453 if (rqc->nonsecure) in _prepare_ccr()
1455 if (rqc->insnaccess) in _prepare_ccr()
1458 ccr |= (((rqc->brst_len - 1) & 0xf) << CC_SRCBRSTLEN_SHFT); in _prepare_ccr()
1459 ccr |= (((rqc->brst_len - 1) & 0xf) << CC_DSTBRSTLEN_SHFT); in _prepare_ccr()
1461 ccr |= (rqc->brst_size << CC_SRCBRSTSIZE_SHFT); in _prepare_ccr()
1462 ccr |= (rqc->brst_size << CC_DSTBRSTSIZE_SHFT); in _prepare_ccr()
1464 ccr |= (rqc->scctl << CC_SRCCCTRL_SHFT); in _prepare_ccr()
1465 ccr |= (rqc->dcctl << CC_DSTCCTRL_SHFT); in _prepare_ccr()
1467 ccr |= (rqc->swap << CC_SWAP_SHFT); in _prepare_ccr()
1480 struct pl330_dmac *pl330 = thrd->dmac; in pl330_submit_req()
1487 switch (desc->rqtype) { in pl330_submit_req()
1498 return -ENOTSUPP; in pl330_submit_req()
1501 if (pl330->state == DYING in pl330_submit_req()
1502 || pl330->dmac_tbd.reset_chan & (1 << thrd->id)) { in pl330_submit_req()
1503 dev_info(thrd->dmac->ddma.dev, "%s:%d\n", in pl330_submit_req()
1505 return -EAGAIN; in pl330_submit_req()
1508 /* If request for non-existing peripheral */ in pl330_submit_req()
1509 if (desc->rqtype != DMA_MEM_TO_MEM && in pl330_submit_req()
1510 desc->peri >= pl330->pcfg.num_peri) { in pl330_submit_req()
1511 dev_info(thrd->dmac->ddma.dev, in pl330_submit_req()
1513 __func__, __LINE__, desc->peri); in pl330_submit_req()
1514 return -EINVAL; in pl330_submit_req()
1517 spin_lock_irqsave(&pl330->lock, flags); in pl330_submit_req()
1520 ret = -EAGAIN; in pl330_submit_req()
1526 desc->rqcfg.nonsecure = 0; in pl330_submit_req()
1528 desc->rqcfg.nonsecure = 1; in pl330_submit_req()
1530 ccr = _prepare_ccr(&desc->rqcfg); in pl330_submit_req()
1532 idx = thrd->req[0].desc == NULL ? 0 : 1; in pl330_submit_req()
1540 if (ret > pl330->mcbufsz / 2) { in pl330_submit_req()
1541 dev_info(pl330->ddma.dev, "%s:%d Try increasing mcbufsz (%i/%i)\n", in pl330_submit_req()
1542 __func__, __LINE__, ret, pl330->mcbufsz / 2); in pl330_submit_req()
1543 ret = -ENOMEM; in pl330_submit_req()
1548 thrd->lstenq = idx; in pl330_submit_req()
1549 thrd->req[idx].desc = desc; in pl330_submit_req()
1555 spin_unlock_irqrestore(&pl330->lock, flags); in pl330_submit_req()
1568 pch = desc->pchan; in dma_pl330_rqcb()
1574 spin_lock_irqsave(&pch->lock, flags); in dma_pl330_rqcb()
1576 desc->status = DONE; in dma_pl330_rqcb()
1578 spin_unlock_irqrestore(&pch->lock, flags); in dma_pl330_rqcb()
1580 tasklet_schedule(&pch->task); in dma_pl330_rqcb()
1589 spin_lock_irqsave(&pl330->lock, flags); in pl330_dotask()
1592 if (pl330->dmac_tbd.reset_dmac) { in pl330_dotask()
1593 pl330->state = DYING; in pl330_dotask()
1595 pl330->dmac_tbd.reset_mngr = true; in pl330_dotask()
1597 pl330->dmac_tbd.reset_dmac = false; in pl330_dotask()
1600 if (pl330->dmac_tbd.reset_mngr) { in pl330_dotask()
1601 _stop(pl330->manager); in pl330_dotask()
1603 pl330->dmac_tbd.reset_chan = (1 << pl330->pcfg.num_chan) - 1; in pl330_dotask()
1605 pl330->dmac_tbd.reset_mngr = false; in pl330_dotask()
1608 for (i = 0; i < pl330->pcfg.num_chan; i++) { in pl330_dotask()
1610 if (pl330->dmac_tbd.reset_chan & (1 << i)) { in pl330_dotask()
1611 struct pl330_thread *thrd = &pl330->channels[i]; in pl330_dotask()
1612 void __iomem *regs = pl330->base; in pl330_dotask()
1617 if (readl(regs + FSC) & (1 << thrd->id)) in pl330_dotask()
1622 spin_unlock_irqrestore(&pl330->lock, flags); in pl330_dotask()
1623 dma_pl330_rqcb(thrd->req[1 - thrd->lstenq].desc, err); in pl330_dotask()
1624 dma_pl330_rqcb(thrd->req[thrd->lstenq].desc, err); in pl330_dotask()
1625 spin_lock_irqsave(&pl330->lock, flags); in pl330_dotask()
1627 thrd->req[0].desc = NULL; in pl330_dotask()
1628 thrd->req[1].desc = NULL; in pl330_dotask()
1629 thrd->req_running = -1; in pl330_dotask()
1632 pl330->dmac_tbd.reset_chan &= ~(1 << i); in pl330_dotask()
1636 spin_unlock_irqrestore(&pl330->lock, flags); in pl330_dotask()
1650 regs = pl330->base; in pl330_update()
1652 spin_lock_irqsave(&pl330->lock, flags); in pl330_update()
1656 pl330->dmac_tbd.reset_mngr = true; in pl330_update()
1658 pl330->dmac_tbd.reset_mngr = false; in pl330_update()
1660 val = readl(regs + FSC) & ((1 << pl330->pcfg.num_chan) - 1); in pl330_update()
1661 pl330->dmac_tbd.reset_chan |= val; in pl330_update()
1664 while (i < pl330->pcfg.num_chan) { in pl330_update()
1666 dev_info(pl330->ddma.dev, in pl330_update()
1667 "Reset Channel-%d\t CS-%x FTC-%x\n", in pl330_update()
1670 _stop(&pl330->channels[i]); in pl330_update()
1678 if (pl330->pcfg.num_events < 32 in pl330_update()
1679 && val & ~((1 << pl330->pcfg.num_events) - 1)) { in pl330_update()
1680 pl330->dmac_tbd.reset_dmac = true; in pl330_update()
1681 dev_err(pl330->ddma.dev, "%s:%d Unexpected!\n", __func__, in pl330_update()
1687 for (ev = 0; ev < pl330->pcfg.num_events; ev++) { in pl330_update()
1699 id = pl330->events[ev]; in pl330_update()
1701 thrd = &pl330->channels[id]; in pl330_update()
1703 active = thrd->req_running; in pl330_update()
1704 if (active == -1) /* Aborted */ in pl330_update()
1708 descdone = thrd->req[active].desc; in pl330_update()
1709 thrd->req[active].desc = NULL; in pl330_update()
1711 thrd->req_running = -1; in pl330_update()
1717 list_add_tail(&descdone->rqd, &pl330->req_done); in pl330_update()
1722 while (!list_empty(&pl330->req_done)) { in pl330_update()
1723 descdone = list_first_entry(&pl330->req_done, in pl330_update()
1725 list_del(&descdone->rqd); in pl330_update()
1726 spin_unlock_irqrestore(&pl330->lock, flags); in pl330_update()
1728 spin_lock_irqsave(&pl330->lock, flags); in pl330_update()
1732 spin_unlock_irqrestore(&pl330->lock, flags); in pl330_update()
1734 if (pl330->dmac_tbd.reset_dmac in pl330_update()
1735 || pl330->dmac_tbd.reset_mngr in pl330_update()
1736 || pl330->dmac_tbd.reset_chan) { in pl330_update()
1738 tasklet_schedule(&pl330->tasks); in pl330_update()
1747 struct pl330_dmac *pl330 = thrd->dmac; in _alloc_event()
1750 for (ev = 0; ev < pl330->pcfg.num_events; ev++) in _alloc_event()
1751 if (pl330->events[ev] == -1) { in _alloc_event()
1752 pl330->events[ev] = thrd->id; in _alloc_event()
1756 return -1; in _alloc_event()
1761 return pl330->pcfg.irq_ns & (1 << i); in _chan_ns()
1772 if (pl330->state == DYING) in pl330_request_channel()
1775 chans = pl330->pcfg.num_chan; in pl330_request_channel()
1778 thrd = &pl330->channels[i]; in pl330_request_channel()
1779 if ((thrd->free) && (!_manager_ns(thrd) || in pl330_request_channel()
1781 thrd->ev = _alloc_event(thrd); in pl330_request_channel()
1782 if (thrd->ev >= 0) { in pl330_request_channel()
1783 thrd->free = false; in pl330_request_channel()
1784 thrd->lstenq = 1; in pl330_request_channel()
1785 thrd->req[0].desc = NULL; in pl330_request_channel()
1786 thrd->req[1].desc = NULL; in pl330_request_channel()
1787 thrd->req_running = -1; in pl330_request_channel()
1800 struct pl330_dmac *pl330 = thrd->dmac; in _free_event()
1803 if (ev >= 0 && ev < pl330->pcfg.num_events in _free_event()
1804 && pl330->events[ev] == thrd->id) in _free_event()
1805 pl330->events[ev] = -1; in _free_event()
1810 if (!thrd || thrd->free) in pl330_release_channel()
1815 dma_pl330_rqcb(thrd->req[1 - thrd->lstenq].desc, PL330_ERR_ABORT); in pl330_release_channel()
1816 dma_pl330_rqcb(thrd->req[thrd->lstenq].desc, PL330_ERR_ABORT); in pl330_release_channel()
1818 _free_event(thrd, thrd->ev); in pl330_release_channel()
1819 thrd->free = true; in pl330_release_channel()
1827 void __iomem *regs = pl330->base; in read_dmac_config()
1832 pl330->pcfg.data_bus_width = 8 * (1 << val); in read_dmac_config()
1836 pl330->pcfg.data_buf_dep = val + 1; in read_dmac_config()
1841 pl330->pcfg.num_chan = val; in read_dmac_config()
1847 pl330->pcfg.num_peri = val; in read_dmac_config()
1848 pl330->pcfg.peri_ns = readl(regs + CR4); in read_dmac_config()
1850 pl330->pcfg.num_peri = 0; in read_dmac_config()
1855 pl330->pcfg.mode |= DMAC_MODE_NS; in read_dmac_config()
1857 pl330->pcfg.mode &= ~DMAC_MODE_NS; in read_dmac_config()
1862 pl330->pcfg.num_events = val; in read_dmac_config()
1864 pl330->pcfg.irq_ns = readl(regs + CR3); in read_dmac_config()
1869 struct pl330_dmac *pl330 = thrd->dmac; in _reset_thread()
1871 thrd->req[0].mc_cpu = pl330->mcode_cpu in _reset_thread()
1872 + (thrd->id * pl330->mcbufsz); in _reset_thread()
1873 thrd->req[0].mc_bus = pl330->mcode_bus in _reset_thread()
1874 + (thrd->id * pl330->mcbufsz); in _reset_thread()
1875 thrd->req[0].desc = NULL; in _reset_thread()
1877 thrd->req[1].mc_cpu = thrd->req[0].mc_cpu in _reset_thread()
1878 + pl330->mcbufsz / 2; in _reset_thread()
1879 thrd->req[1].mc_bus = thrd->req[0].mc_bus in _reset_thread()
1880 + pl330->mcbufsz / 2; in _reset_thread()
1881 thrd->req[1].desc = NULL; in _reset_thread()
1883 thrd->req_running = -1; in _reset_thread()
1888 int chans = pl330->pcfg.num_chan; in dmac_alloc_threads()
1893 pl330->channels = kcalloc(1 + chans, sizeof(*thrd), in dmac_alloc_threads()
1895 if (!pl330->channels) in dmac_alloc_threads()
1896 return -ENOMEM; in dmac_alloc_threads()
1900 thrd = &pl330->channels[i]; in dmac_alloc_threads()
1901 thrd->id = i; in dmac_alloc_threads()
1902 thrd->dmac = pl330; in dmac_alloc_threads()
1904 thrd->free = true; in dmac_alloc_threads()
1908 thrd = &pl330->channels[chans]; in dmac_alloc_threads()
1909 thrd->id = chans; in dmac_alloc_threads()
1910 thrd->dmac = pl330; in dmac_alloc_threads()
1911 thrd->free = false; in dmac_alloc_threads()
1912 pl330->manager = thrd; in dmac_alloc_threads()
1919 int chans = pl330->pcfg.num_chan; in dmac_alloc_resources()
1926 pl330->mcode_cpu = dma_alloc_attrs(pl330->ddma.dev, in dmac_alloc_resources()
1927 chans * pl330->mcbufsz, in dmac_alloc_resources()
1928 &pl330->mcode_bus, GFP_KERNEL, in dmac_alloc_resources()
1930 if (!pl330->mcode_cpu) { in dmac_alloc_resources()
1931 dev_err(pl330->ddma.dev, "%s:%d Can't allocate memory!\n", in dmac_alloc_resources()
1933 return -ENOMEM; in dmac_alloc_resources()
1938 dev_err(pl330->ddma.dev, "%s:%d Can't to create channels for DMAC!\n", in dmac_alloc_resources()
1940 dma_free_attrs(pl330->ddma.dev, in dmac_alloc_resources()
1941 chans * pl330->mcbufsz, in dmac_alloc_resources()
1942 pl330->mcode_cpu, pl330->mcode_bus, in dmac_alloc_resources()
1955 if ((pl330->pcfg.periph_id & 0xfffff) != PERIPH_ID_VAL) { in pl330_add()
1956 dev_err(pl330->ddma.dev, "PERIPH_ID 0x%x !\n", in pl330_add()
1957 pl330->pcfg.periph_id); in pl330_add()
1958 return -EINVAL; in pl330_add()
1964 if (pl330->pcfg.num_events == 0) { in pl330_add()
1965 dev_err(pl330->ddma.dev, "%s:%d Can't work without events!\n", in pl330_add()
1967 return -EINVAL; in pl330_add()
1970 spin_lock_init(&pl330->lock); in pl330_add()
1972 INIT_LIST_HEAD(&pl330->req_done); in pl330_add()
1975 if (!pl330->mcbufsz) in pl330_add()
1976 pl330->mcbufsz = MCODE_BUFF_PER_REQ * 2; in pl330_add()
1979 for (i = 0; i < pl330->pcfg.num_events; i++) in pl330_add()
1980 pl330->events[i] = -1; in pl330_add()
1985 dev_err(pl330->ddma.dev, "Unable to create channels for DMAC\n"); in pl330_add()
1989 tasklet_setup(&pl330->tasks, pl330_dotask); in pl330_add()
1991 pl330->state = INIT; in pl330_add()
2002 for (i = 0; i < pl330->pcfg.num_chan; i++) { in dmac_free_threads()
2003 thrd = &pl330->channels[i]; in dmac_free_threads()
2008 kfree(pl330->channels); in dmac_free_threads()
2015 pl330->state = UNINIT; in pl330_del()
2017 tasklet_kill(&pl330->tasks); in pl330_del()
2022 dma_free_attrs(pl330->ddma.dev, in pl330_del()
2023 pl330->pcfg.num_chan * pl330->mcbufsz, pl330->mcode_cpu, in pl330_del()
2024 pl330->mcode_bus, DMA_ATTR_PRIVILEGED); in pl330_del()
2050 list_for_each_entry(desc, &pch->work_list, node) { in fill_queue()
2053 if (desc->status == BUSY || desc->status == PAUSED) in fill_queue()
2056 ret = pl330_submit_req(pch->thread, desc); in fill_queue()
2058 desc->status = BUSY; in fill_queue()
2059 } else if (ret == -EAGAIN) { in fill_queue()
2064 desc->status = DONE; in fill_queue()
2065 dev_err(pch->dmac->ddma.dev, "%s:%d Bad Desc(%d)\n", in fill_queue()
2066 __func__, __LINE__, desc->txd.cookie); in fill_queue()
2067 tasklet_schedule(&pch->task); in fill_queue()
2079 spin_lock_irqsave(&pch->lock, flags); in pl330_tasklet()
2082 list_for_each_entry_safe(desc, _dt, &pch->work_list, node) in pl330_tasklet()
2083 if (desc->status == DONE) { in pl330_tasklet()
2084 if (!pch->cyclic) in pl330_tasklet()
2085 dma_cookie_complete(&desc->txd); in pl330_tasklet()
2086 list_move_tail(&desc->node, &pch->completed_list); in pl330_tasklet()
2092 if (list_empty(&pch->work_list)) { in pl330_tasklet()
2093 spin_lock(&pch->thread->dmac->lock); in pl330_tasklet()
2094 _stop(pch->thread); in pl330_tasklet()
2095 spin_unlock(&pch->thread->dmac->lock); in pl330_tasklet()
2097 pch->active = false; in pl330_tasklet()
2100 spin_lock(&pch->thread->dmac->lock); in pl330_tasklet()
2101 pl330_start_thread(pch->thread); in pl330_tasklet()
2102 spin_unlock(&pch->thread->dmac->lock); in pl330_tasklet()
2105 while (!list_empty(&pch->completed_list)) { in pl330_tasklet()
2108 desc = list_first_entry(&pch->completed_list, in pl330_tasklet()
2111 dmaengine_desc_get_callback(&desc->txd, &cb); in pl330_tasklet()
2113 if (pch->cyclic) { in pl330_tasklet()
2114 desc->status = PREP; in pl330_tasklet()
2115 list_move_tail(&desc->node, &pch->work_list); in pl330_tasklet()
2117 pch->active = true; in pl330_tasklet()
2118 spin_lock(&pch->thread->dmac->lock); in pl330_tasklet()
2119 pl330_start_thread(pch->thread); in pl330_tasklet()
2120 spin_unlock(&pch->thread->dmac->lock); in pl330_tasklet()
2124 desc->status = FREE; in pl330_tasklet()
2125 list_move_tail(&desc->node, &pch->dmac->desc_pool); in pl330_tasklet()
2128 dma_descriptor_unmap(&desc->txd); in pl330_tasklet()
2131 spin_unlock_irqrestore(&pch->lock, flags); in pl330_tasklet()
2133 spin_lock_irqsave(&pch->lock, flags); in pl330_tasklet()
2136 spin_unlock_irqrestore(&pch->lock, flags); in pl330_tasklet()
2140 pm_runtime_mark_last_busy(pch->dmac->ddma.dev); in pl330_tasklet()
2141 pm_runtime_put_autosuspend(pch->dmac->ddma.dev); in pl330_tasklet()
2148 int count = dma_spec->args_count; in of_dma_pl330_xlate()
2149 struct pl330_dmac *pl330 = ofdma->of_dma_data; in of_dma_pl330_xlate()
2158 chan_id = dma_spec->args[0]; in of_dma_pl330_xlate()
2159 if (chan_id >= pl330->num_peripherals) in of_dma_pl330_xlate()
2162 return dma_get_slave_channel(&pl330->peripherals[chan_id].chan); in of_dma_pl330_xlate()
2168 struct pl330_dmac *pl330 = pch->dmac; in pl330_alloc_chan_resources()
2171 spin_lock_irqsave(&pl330->lock, flags); in pl330_alloc_chan_resources()
2174 pch->cyclic = false; in pl330_alloc_chan_resources()
2176 pch->thread = pl330_request_channel(pl330); in pl330_alloc_chan_resources()
2177 if (!pch->thread) { in pl330_alloc_chan_resources()
2178 spin_unlock_irqrestore(&pl330->lock, flags); in pl330_alloc_chan_resources()
2179 return -ENOMEM; in pl330_alloc_chan_resources()
2182 tasklet_setup(&pch->task, pl330_tasklet); in pl330_alloc_chan_resources()
2184 spin_unlock_irqrestore(&pl330->lock, flags); in pl330_alloc_chan_resources()
2190 * We need the data direction between the DMAC (the dma-mapping "device") and
2210 if (pch->dir != DMA_NONE) in pl330_unprep_slave_fifo()
2211 dma_unmap_resource(pch->chan.device->dev, pch->fifo_dma, in pl330_unprep_slave_fifo()
2212 1 << pch->burst_sz, pch->dir, 0); in pl330_unprep_slave_fifo()
2213 pch->dir = DMA_NONE; in pl330_unprep_slave_fifo()
2220 struct device *dev = pch->chan.device->dev; in pl330_prep_slave_fifo()
2223 /* Already mapped for this config? */ in pl330_prep_slave_fifo()
2224 if (pch->dir == dma_dir) in pl330_prep_slave_fifo()
2228 pch->fifo_dma = dma_map_resource(dev, pch->fifo_addr, in pl330_prep_slave_fifo()
2229 1 << pch->burst_sz, dma_dir, 0); in pl330_prep_slave_fifo()
2230 if (dma_mapping_error(dev, pch->fifo_dma)) in pl330_prep_slave_fifo()
2233 pch->dir = dma_dir; in pl330_prep_slave_fifo()
2255 if (slave_config->dst_addr) in pl330_config_write()
2256 pch->fifo_addr = slave_config->dst_addr; in pl330_config_write()
2257 if (slave_config->dst_addr_width) in pl330_config_write()
2258 pch->burst_sz = __ffs(slave_config->dst_addr_width); in pl330_config_write()
2259 pch->burst_len = fixup_burst_len(slave_config->dst_maxburst, in pl330_config_write()
2260 pch->dmac->quirks); in pl330_config_write()
2262 if (slave_config->src_addr) in pl330_config_write()
2263 pch->fifo_addr = slave_config->src_addr; in pl330_config_write()
2264 if (slave_config->src_addr_width) in pl330_config_write()
2265 pch->burst_sz = __ffs(slave_config->src_addr_width); in pl330_config_write()
2266 pch->burst_len = fixup_burst_len(slave_config->src_maxburst, in pl330_config_write()
2267 pch->dmac->quirks); in pl330_config_write()
2278 memcpy(&pch->slave_config, slave_config, sizeof(*slave_config)); in pl330_config()
2288 struct pl330_dmac *pl330 = pch->dmac; in pl330_terminate_all()
2291 pm_runtime_get_sync(pl330->ddma.dev); in pl330_terminate_all()
2292 spin_lock_irqsave(&pch->lock, flags); in pl330_terminate_all()
2294 spin_lock(&pl330->lock); in pl330_terminate_all()
2295 _stop(pch->thread); in pl330_terminate_all()
2296 pch->thread->req[0].desc = NULL; in pl330_terminate_all()
2297 pch->thread->req[1].desc = NULL; in pl330_terminate_all()
2298 pch->thread->req_running = -1; in pl330_terminate_all()
2299 spin_unlock(&pl330->lock); in pl330_terminate_all()
2301 power_down = pch->active; in pl330_terminate_all()
2302 pch->active = false; in pl330_terminate_all()
2305 list_for_each_entry(desc, &pch->submitted_list, node) { in pl330_terminate_all()
2306 desc->status = FREE; in pl330_terminate_all()
2307 dma_cookie_complete(&desc->txd); in pl330_terminate_all()
2310 list_for_each_entry(desc, &pch->work_list , node) { in pl330_terminate_all()
2311 desc->status = FREE; in pl330_terminate_all()
2312 dma_cookie_complete(&desc->txd); in pl330_terminate_all()
2315 list_splice_tail_init(&pch->submitted_list, &pl330->desc_pool); in pl330_terminate_all()
2316 list_splice_tail_init(&pch->work_list, &pl330->desc_pool); in pl330_terminate_all()
2317 list_splice_tail_init(&pch->completed_list, &pl330->desc_pool); in pl330_terminate_all()
2318 spin_unlock_irqrestore(&pch->lock, flags); in pl330_terminate_all()
2319 pm_runtime_mark_last_busy(pl330->ddma.dev); in pl330_terminate_all()
2321 pm_runtime_put_autosuspend(pl330->ddma.dev); in pl330_terminate_all()
2322 pm_runtime_put_autosuspend(pl330->ddma.dev); in pl330_terminate_all()
2337 struct pl330_dmac *pl330 = pch->dmac; in pl330_pause()
2341 pm_runtime_get_sync(pl330->ddma.dev); in pl330_pause()
2342 spin_lock_irqsave(&pch->lock, flags); in pl330_pause()
2344 spin_lock(&pl330->lock); in pl330_pause()
2345 _stop(pch->thread); in pl330_pause()
2346 spin_unlock(&pl330->lock); in pl330_pause()
2348 list_for_each_entry(desc, &pch->work_list, node) { in pl330_pause()
2349 if (desc->status == BUSY) in pl330_pause()
2350 desc->status = PAUSED; in pl330_pause()
2352 spin_unlock_irqrestore(&pch->lock, flags); in pl330_pause()
2353 pm_runtime_mark_last_busy(pl330->ddma.dev); in pl330_pause()
2354 pm_runtime_put_autosuspend(pl330->ddma.dev); in pl330_pause()
2362 struct pl330_dmac *pl330 = pch->dmac; in pl330_free_chan_resources()
2365 tasklet_kill(&pch->task); in pl330_free_chan_resources()
2367 pm_runtime_get_sync(pch->dmac->ddma.dev); in pl330_free_chan_resources()
2368 spin_lock_irqsave(&pl330->lock, flags); in pl330_free_chan_resources()
2370 pl330_release_channel(pch->thread); in pl330_free_chan_resources()
2371 pch->thread = NULL; in pl330_free_chan_resources()
2373 if (pch->cyclic) in pl330_free_chan_resources()
2374 list_splice_tail_init(&pch->work_list, &pch->dmac->desc_pool); in pl330_free_chan_resources()
2376 spin_unlock_irqrestore(&pl330->lock, flags); in pl330_free_chan_resources()
2377 pm_runtime_mark_last_busy(pch->dmac->ddma.dev); in pl330_free_chan_resources()
2378 pm_runtime_put_autosuspend(pch->dmac->ddma.dev); in pl330_free_chan_resources()
2385 struct pl330_thread *thrd = pch->thread; in pl330_get_current_xferred_count()
2386 struct pl330_dmac *pl330 = pch->dmac; in pl330_get_current_xferred_count()
2387 void __iomem *regs = thrd->dmac->base; in pl330_get_current_xferred_count()
2390 pm_runtime_get_sync(pl330->ddma.dev); in pl330_get_current_xferred_count()
2392 if (desc->rqcfg.src_inc) { in pl330_get_current_xferred_count()
2393 val = readl(regs + SA(thrd->id)); in pl330_get_current_xferred_count()
2394 addr = desc->px.src_addr; in pl330_get_current_xferred_count()
2396 val = readl(regs + DA(thrd->id)); in pl330_get_current_xferred_count()
2397 addr = desc->px.dst_addr; in pl330_get_current_xferred_count()
2399 pm_runtime_mark_last_busy(pch->dmac->ddma.dev); in pl330_get_current_xferred_count()
2400 pm_runtime_put_autosuspend(pl330->ddma.dev); in pl330_get_current_xferred_count()
2406 return val - addr; in pl330_get_current_xferred_count()
2427 spin_lock_irqsave(&pch->lock, flags); in pl330_tx_status()
2428 spin_lock(&pch->thread->dmac->lock); in pl330_tx_status()
2430 if (pch->thread->req_running != -1) in pl330_tx_status()
2431 running = pch->thread->req[pch->thread->req_running].desc; in pl330_tx_status()
2433 last_enq = pch->thread->req[pch->thread->lstenq].desc; in pl330_tx_status()
2436 list_for_each_entry(desc, &pch->work_list, node) { in pl330_tx_status()
2437 if (desc->status == DONE) in pl330_tx_status()
2438 transferred = desc->bytes_requested; in pl330_tx_status()
2442 else if (desc->status == BUSY || desc->status == PAUSED) in pl330_tx_status()
2450 transferred = desc->bytes_requested; in pl330_tx_status()
2453 residual += desc->bytes_requested - transferred; in pl330_tx_status()
2454 if (desc->txd.cookie == cookie) { in pl330_tx_status()
2455 switch (desc->status) { in pl330_tx_status()
2471 if (desc->last) in pl330_tx_status()
2474 spin_unlock(&pch->thread->dmac->lock); in pl330_tx_status()
2475 spin_unlock_irqrestore(&pch->lock, flags); in pl330_tx_status()
2488 spin_lock_irqsave(&pch->lock, flags); in pl330_issue_pending()
2489 if (list_empty(&pch->work_list)) { in pl330_issue_pending()
2495 WARN_ON(list_empty(&pch->submitted_list)); in pl330_issue_pending()
2496 pch->active = true; in pl330_issue_pending()
2497 pm_runtime_get_sync(pch->dmac->ddma.dev); in pl330_issue_pending()
2499 list_splice_tail_init(&pch->submitted_list, &pch->work_list); in pl330_issue_pending()
2500 spin_unlock_irqrestore(&pch->lock, flags); in pl330_issue_pending()
2502 pl330_tasklet(&pch->task); in pl330_issue_pending()
2513 struct dma_pl330_chan *pch = to_pchan(tx->chan); in pl330_tx_submit()
2517 spin_lock_irqsave(&pch->lock, flags); in pl330_tx_submit()
2520 while (!list_empty(&last->node)) { in pl330_tx_submit()
2521 desc = list_entry(last->node.next, struct dma_pl330_desc, node); in pl330_tx_submit()
2522 if (pch->cyclic) { in pl330_tx_submit()
2523 desc->txd.callback = last->txd.callback; in pl330_tx_submit()
2524 desc->txd.callback_param = last->txd.callback_param; in pl330_tx_submit()
2526 desc->last = false; in pl330_tx_submit()
2528 dma_cookie_assign(&desc->txd); in pl330_tx_submit()
2530 list_move_tail(&desc->node, &pch->submitted_list); in pl330_tx_submit()
2533 last->last = true; in pl330_tx_submit()
2534 cookie = dma_cookie_assign(&last->txd); in pl330_tx_submit()
2535 list_add_tail(&last->node, &pch->submitted_list); in pl330_tx_submit()
2536 spin_unlock_irqrestore(&pch->lock, flags); in pl330_tx_submit()
2543 desc->rqcfg.swap = SWAP_NO; in _init_desc()
2544 desc->rqcfg.scctl = CCTRL0; in _init_desc()
2545 desc->rqcfg.dcctl = CCTRL0; in _init_desc()
2546 desc->txd.tx_submit = pl330_tx_submit; in _init_desc()
2548 INIT_LIST_HEAD(&desc->node); in _init_desc()
2584 desc = list_entry(pool->next, in pluck_desc()
2587 list_del_init(&desc->node); in pluck_desc()
2589 desc->status = PREP; in pluck_desc()
2590 desc->txd.callback = NULL; in pluck_desc()
2600 struct pl330_dmac *pl330 = pch->dmac; in pl330_get_desc()
2601 u8 *peri_id = pch->chan.private; in pl330_get_desc()
2605 desc = pluck_desc(&pl330->desc_pool, &pl330->pool_lock); in pl330_get_desc()
2620 desc->pchan = pch; in pl330_get_desc()
2621 desc->txd.cookie = 0; in pl330_get_desc()
2622 async_tx_ack(&desc->txd); in pl330_get_desc()
2624 desc->peri = peri_id ? pch->chan.chan_id : 0; in pl330_get_desc()
2625 desc->rqcfg.pcfg = &pch->dmac->pcfg; in pl330_get_desc()
2627 dma_async_tx_descriptor_init(&desc->txd, &pch->chan); in pl330_get_desc()
2635 px->bytes = len; in fill_px()
2636 px->dst_addr = dst; in fill_px()
2637 px->src_addr = src; in fill_px()
2647 dev_err(pch->dmac->ddma.dev, "%s:%d Unable to fetch desc\n", in __pl330_prep_dma_memcpy()
2656 * going to be word-unaligned and more than 200MB, in __pl330_prep_dma_memcpy()
2662 fill_px(&desc->px, dst, src, len); in __pl330_prep_dma_memcpy()
2670 struct dma_pl330_chan *pch = desc->pchan; in get_burst_len()
2671 struct pl330_dmac *pl330 = pch->dmac; in get_burst_len()
2674 burst_len = pl330->pcfg.data_bus_width / 8; in get_burst_len()
2675 burst_len *= pl330->pcfg.data_buf_dep / pl330->pcfg.num_chan; in get_burst_len()
2676 burst_len >>= desc->rqcfg.brst_size; in get_burst_len()
2692 struct pl330_dmac *pl330 = pch->dmac; in pl330_prep_dma_cyclic()
2701 dev_err(pch->dmac->ddma.dev, "%s:%d Invalid dma direction\n", in pl330_prep_dma_cyclic()
2706 pl330_config_write(chan, &pch->slave_config, direction); in pl330_prep_dma_cyclic()
2716 dev_err(pch->dmac->ddma.dev, "%s:%d Unable to fetch desc\n", in pl330_prep_dma_cyclic()
2722 spin_lock_irqsave(&pl330->pool_lock, iflags); in pl330_prep_dma_cyclic()
2724 while (!list_empty(&first->node)) { in pl330_prep_dma_cyclic()
2725 desc = list_entry(first->node.next, in pl330_prep_dma_cyclic()
2727 list_move_tail(&desc->node, &pl330->desc_pool); in pl330_prep_dma_cyclic()
2730 list_move_tail(&first->node, &pl330->desc_pool); in pl330_prep_dma_cyclic()
2732 spin_unlock_irqrestore(&pl330->pool_lock, iflags); in pl330_prep_dma_cyclic()
2739 desc->rqcfg.src_inc = 1; in pl330_prep_dma_cyclic()
2740 desc->rqcfg.dst_inc = 0; in pl330_prep_dma_cyclic()
2742 dst = pch->fifo_dma; in pl330_prep_dma_cyclic()
2745 desc->rqcfg.src_inc = 0; in pl330_prep_dma_cyclic()
2746 desc->rqcfg.dst_inc = 1; in pl330_prep_dma_cyclic()
2747 src = pch->fifo_dma; in pl330_prep_dma_cyclic()
2754 desc->rqtype = direction; in pl330_prep_dma_cyclic()
2755 desc->rqcfg.brst_size = pch->burst_sz; in pl330_prep_dma_cyclic()
2756 desc->rqcfg.brst_len = pch->burst_len; in pl330_prep_dma_cyclic()
2757 desc->bytes_requested = period_len; in pl330_prep_dma_cyclic()
2758 fill_px(&desc->px, dst, src, period_len); in pl330_prep_dma_cyclic()
2763 list_add_tail(&desc->node, &first->node); in pl330_prep_dma_cyclic()
2771 pch->cyclic = true; in pl330_prep_dma_cyclic()
2773 return &desc->txd; in pl330_prep_dma_cyclic()
2788 pl330 = pch->dmac; in pl330_prep_dma_memcpy()
2794 desc->rqcfg.src_inc = 1; in pl330_prep_dma_memcpy()
2795 desc->rqcfg.dst_inc = 1; in pl330_prep_dma_memcpy()
2796 desc->rqtype = DMA_MEM_TO_MEM; in pl330_prep_dma_memcpy()
2799 burst = pl330->pcfg.data_bus_width / 8; in pl330_prep_dma_memcpy()
2806 while ((src | dst | len) & (burst - 1)) in pl330_prep_dma_memcpy()
2809 desc->rqcfg.brst_size = 0; in pl330_prep_dma_memcpy()
2810 while (burst != (1 << desc->rqcfg.brst_size)) in pl330_prep_dma_memcpy()
2811 desc->rqcfg.brst_size++; in pl330_prep_dma_memcpy()
2813 desc->rqcfg.brst_len = get_burst_len(desc, len); in pl330_prep_dma_memcpy()
2818 if (burst * 8 < pl330->pcfg.data_bus_width) in pl330_prep_dma_memcpy()
2819 desc->rqcfg.brst_len = 1; in pl330_prep_dma_memcpy()
2821 desc->bytes_requested = len; in pl330_prep_dma_memcpy()
2823 return &desc->txd; in pl330_prep_dma_memcpy()
2835 spin_lock_irqsave(&pl330->pool_lock, flags); in __pl330_giveback_desc()
2837 while (!list_empty(&first->node)) { in __pl330_giveback_desc()
2838 desc = list_entry(first->node.next, in __pl330_giveback_desc()
2840 list_move_tail(&desc->node, &pl330->desc_pool); in __pl330_giveback_desc()
2843 list_move_tail(&first->node, &pl330->desc_pool); in __pl330_giveback_desc()
2845 spin_unlock_irqrestore(&pl330->pool_lock, flags); in __pl330_giveback_desc()
2861 pl330_config_write(chan, &pch->slave_config, direction); in pl330_prep_slave_sg()
2872 struct pl330_dmac *pl330 = pch->dmac; in pl330_prep_slave_sg()
2874 dev_err(pch->dmac->ddma.dev, in pl330_prep_slave_sg()
2885 list_add_tail(&desc->node, &first->node); in pl330_prep_slave_sg()
2888 desc->rqcfg.src_inc = 1; in pl330_prep_slave_sg()
2889 desc->rqcfg.dst_inc = 0; in pl330_prep_slave_sg()
2890 fill_px(&desc->px, pch->fifo_dma, sg_dma_address(sg), in pl330_prep_slave_sg()
2893 desc->rqcfg.src_inc = 0; in pl330_prep_slave_sg()
2894 desc->rqcfg.dst_inc = 1; in pl330_prep_slave_sg()
2895 fill_px(&desc->px, sg_dma_address(sg), pch->fifo_dma, in pl330_prep_slave_sg()
2899 desc->rqcfg.brst_size = pch->burst_sz; in pl330_prep_slave_sg()
2900 desc->rqcfg.brst_len = pch->burst_len; in pl330_prep_slave_sg()
2901 desc->rqtype = direction; in pl330_prep_slave_sg()
2902 desc->bytes_requested = sg_dma_len(sg); in pl330_prep_slave_sg()
2906 return &desc->txd; in pl330_prep_slave_sg()
2927 struct pl330_dmac *pl330 = s->private; in pl330_debugfs_show()
2930 chans = pl330->pcfg.num_chan; in pl330_debugfs_show()
2931 pchs = pl330->num_peripherals; in pl330_debugfs_show()
2935 seq_puts(s, "--------\t-----\n"); in pl330_debugfs_show()
2937 struct pl330_thread *thrd = &pl330->channels[ch]; in pl330_debugfs_show()
2938 int found = -1; in pl330_debugfs_show()
2941 struct dma_pl330_chan *pch = &pl330->peripherals[pr]; in pl330_debugfs_show()
2943 if (!pch->thread || thrd->id != pch->thread->id) in pl330_debugfs_show()
2949 seq_printf(s, "%d\t\t", thrd->id); in pl330_debugfs_show()
2950 if (found == -1) in pl330_debugfs_show()
2951 seq_puts(s, "--\n"); in pl330_debugfs_show()
2963 debugfs_create_file(dev_name(pl330->ddma.dev), in init_pl330_debugfs()
2984 clk_unprepare(pcdev->pclk); in pl330_suspend()
2994 ret = clk_prepare(pcdev->pclk); in pl330_resume()
3017 struct device_node *np = adev->dev.of_node; in pl330_probe()
3019 ret = dma_set_mask_and_coherent(&adev->dev, DMA_BIT_MASK(32)); in pl330_probe()
3024 pl330 = devm_kzalloc(&adev->dev, sizeof(*pl330), GFP_KERNEL); in pl330_probe()
3026 return -ENOMEM; in pl330_probe()
3028 pd = &pl330->ddma; in pl330_probe()
3029 pd->dev = &adev->dev; in pl330_probe()
3031 pl330->mcbufsz = 0; in pl330_probe()
3036 pl330->quirks |= of_quirks[i].id; in pl330_probe()
3038 res = &adev->res; in pl330_probe()
3039 pl330->base = devm_ioremap_resource(&adev->dev, res); in pl330_probe()
3040 if (IS_ERR(pl330->base)) in pl330_probe()
3041 return PTR_ERR(pl330->base); in pl330_probe()
3045 pl330->rstc = devm_reset_control_get_optional(&adev->dev, "dma"); in pl330_probe()
3046 if (IS_ERR(pl330->rstc)) { in pl330_probe()
3047 return dev_err_probe(&adev->dev, PTR_ERR(pl330->rstc), "Failed to get reset!\n"); in pl330_probe()
3049 ret = reset_control_deassert(pl330->rstc); in pl330_probe()
3051 dev_err(&adev->dev, "Couldn't deassert the device from reset!\n"); in pl330_probe()
3056 pl330->rstc_ocp = devm_reset_control_get_optional(&adev->dev, "dma-ocp"); in pl330_probe()
3057 if (IS_ERR(pl330->rstc_ocp)) { in pl330_probe()
3058 return dev_err_probe(&adev->dev, PTR_ERR(pl330->rstc_ocp), in pl330_probe()
3061 ret = reset_control_deassert(pl330->rstc_ocp); in pl330_probe()
3063 dev_err(&adev->dev, "Couldn't deassert the device from OCP reset!\n"); in pl330_probe()
3069 irq = adev->irq[i]; in pl330_probe()
3071 ret = devm_request_irq(&adev->dev, irq, in pl330_probe()
3073 dev_name(&adev->dev), pl330); in pl330_probe()
3081 pcfg = &pl330->pcfg; in pl330_probe()
3083 pcfg->periph_id = adev->periphid; in pl330_probe()
3088 INIT_LIST_HEAD(&pl330->desc_pool); in pl330_probe()
3089 spin_lock_init(&pl330->pool_lock); in pl330_probe()
3092 if (!add_desc(&pl330->desc_pool, &pl330->pool_lock, in pl330_probe()
3094 dev_warn(&adev->dev, "unable to allocate desc\n"); in pl330_probe()
3096 INIT_LIST_HEAD(&pd->channels); in pl330_probe()
3099 num_chan = max_t(int, pcfg->num_peri, pcfg->num_chan); in pl330_probe()
3101 pl330->num_peripherals = num_chan; in pl330_probe()
3103 pl330->peripherals = kcalloc(num_chan, sizeof(*pch), GFP_KERNEL); in pl330_probe()
3104 if (!pl330->peripherals) { in pl330_probe()
3105 ret = -ENOMEM; in pl330_probe()
3110 pch = &pl330->peripherals[i]; in pl330_probe()
3112 pch->chan.private = adev->dev.of_node; in pl330_probe()
3113 INIT_LIST_HEAD(&pch->submitted_list); in pl330_probe()
3114 INIT_LIST_HEAD(&pch->work_list); in pl330_probe()
3115 INIT_LIST_HEAD(&pch->completed_list); in pl330_probe()
3116 spin_lock_init(&pch->lock); in pl330_probe()
3117 pch->thread = NULL; in pl330_probe()
3118 pch->chan.device = pd; in pl330_probe()
3119 pch->dmac = pl330; in pl330_probe()
3120 pch->dir = DMA_NONE; in pl330_probe()
3123 list_add_tail(&pch->chan.device_node, &pd->channels); in pl330_probe()
3126 dma_cap_set(DMA_MEMCPY, pd->cap_mask); in pl330_probe()
3127 if (pcfg->num_peri) { in pl330_probe()
3128 dma_cap_set(DMA_SLAVE, pd->cap_mask); in pl330_probe()
3129 dma_cap_set(DMA_CYCLIC, pd->cap_mask); in pl330_probe()
3130 dma_cap_set(DMA_PRIVATE, pd->cap_mask); in pl330_probe()
3133 pd->device_alloc_chan_resources = pl330_alloc_chan_resources; in pl330_probe()
3134 pd->device_free_chan_resources = pl330_free_chan_resources; in pl330_probe()
3135 pd->device_prep_dma_memcpy = pl330_prep_dma_memcpy; in pl330_probe()
3136 pd->device_prep_dma_cyclic = pl330_prep_dma_cyclic; in pl330_probe()
3137 pd->device_tx_status = pl330_tx_status; in pl330_probe()
3138 pd->device_prep_slave_sg = pl330_prep_slave_sg; in pl330_probe()
3139 pd->device_config = pl330_config; in pl330_probe()
3140 pd->device_pause = pl330_pause; in pl330_probe()
3141 pd->device_terminate_all = pl330_terminate_all; in pl330_probe()
3142 pd->device_issue_pending = pl330_issue_pending; in pl330_probe()
3143 pd->src_addr_widths = PL330_DMA_BUSWIDTHS; in pl330_probe()
3144 pd->dst_addr_widths = PL330_DMA_BUSWIDTHS; in pl330_probe()
3145 pd->directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV); in pl330_probe()
3146 pd->residue_granularity = DMA_RESIDUE_GRANULARITY_BURST; in pl330_probe()
3147 pd->max_burst = PL330_MAX_BURST; in pl330_probe()
3151 dev_err(&adev->dev, "unable to register DMAC\n"); in pl330_probe()
3155 if (adev->dev.of_node) { in pl330_probe()
3156 ret = of_dma_controller_register(adev->dev.of_node, in pl330_probe()
3159 dev_err(&adev->dev, in pl330_probe()
3168 ret = dma_set_max_seg_size(&adev->dev, 1900800); in pl330_probe()
3170 dev_err(&adev->dev, "unable to set the seg size\n"); in pl330_probe()
3174 dev_info(&adev->dev, in pl330_probe()
3175 "Loaded driver for PL330 DMAC-%x\n", adev->periphid); in pl330_probe()
3176 dev_info(&adev->dev, in pl330_probe()
3177 "\tDBUFF-%ux%ubytes Num_Chans-%u Num_Peri-%u Num_Events-%u\n", in pl330_probe()
3178 pcfg->data_buf_dep, pcfg->data_bus_width / 8, pcfg->num_chan, in pl330_probe()
3179 pcfg->num_peri, pcfg->num_events); in pl330_probe()
3181 pm_runtime_irq_safe(&adev->dev); in pl330_probe()
3182 pm_runtime_use_autosuspend(&adev->dev); in pl330_probe()
3183 pm_runtime_set_autosuspend_delay(&adev->dev, PL330_AUTOSUSPEND_DELAY); in pl330_probe()
3184 pm_runtime_mark_last_busy(&adev->dev); in pl330_probe()
3185 pm_runtime_put_autosuspend(&adev->dev); in pl330_probe()
3190 list_for_each_entry_safe(pch, _p, &pl330->ddma.channels, in pl330_probe()
3194 list_del(&pch->chan.device_node); in pl330_probe()
3197 if (pch->thread) { in pl330_probe()
3198 pl330_terminate_all(&pch->chan); in pl330_probe()
3199 pl330_free_chan_resources(&pch->chan); in pl330_probe()
3205 if (pl330->rstc_ocp) in pl330_probe()
3206 reset_control_assert(pl330->rstc_ocp); in pl330_probe()
3208 if (pl330->rstc) in pl330_probe()
3209 reset_control_assert(pl330->rstc); in pl330_probe()
3219 pm_runtime_get_noresume(pl330->ddma.dev); in pl330_remove()
3221 if (adev->dev.of_node) in pl330_remove()
3222 of_dma_controller_free(adev->dev.of_node); in pl330_remove()
3225 irq = adev->irq[i]; in pl330_remove()
3227 devm_free_irq(&adev->dev, irq, pl330); in pl330_remove()
3230 dma_async_device_unregister(&pl330->ddma); in pl330_remove()
3233 list_for_each_entry_safe(pch, _p, &pl330->ddma.channels, in pl330_remove()
3237 list_del(&pch->chan.device_node); in pl330_remove()
3240 if (pch->thread) { in pl330_remove()
3241 pl330_terminate_all(&pch->chan); in pl330_remove()
3242 pl330_free_chan_resources(&pch->chan); in pl330_remove()
3248 if (pl330->rstc_ocp) in pl330_remove()
3249 reset_control_assert(pl330->rstc_ocp); in pl330_remove()
3251 if (pl330->rstc) in pl330_remove()
3252 reset_control_assert(pl330->rstc); in pl330_remove()
3268 .name = "dma-pl330",