Lines Matching +full:dma +full:- +full:channel +full:- +full:mask
1 // SPDX-License-Identifier: GPL-2.0
3 * Core driver for the Synopsys DesignWare DMA Controller
5 * Copyright (C) 2007-2008 Atmel Corporation
6 * Copyright (C) 2010-2011 ST Microelectronics
13 #include <linux/dma-mapping.h>
28 * This supports the Synopsys "DesignWare AHB Central DMA Controller",
34 /* The set of bus widths supported by the DMA controller */
41 /*----------------------------------------------------------------------*/
45 return &chan->dev->device; in chan2dev()
50 return to_dw_desc(dwc->active_list.next); in dwc_first_active()
56 struct dw_dma_chan *dwc = to_dw_dma_chan(tx->chan); in dwc_tx_submit()
60 spin_lock_irqsave(&dwc->lock, flags); in dwc_tx_submit()
66 * for DMA. But this is hard to do in a race-free manner. in dwc_tx_submit()
69 list_add_tail(&desc->desc_node, &dwc->queue); in dwc_tx_submit()
70 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_tx_submit()
71 dev_vdbg(chan2dev(tx->chan), "%s: queued %u\n", in dwc_tx_submit()
72 __func__, desc->txd.cookie); in dwc_tx_submit()
79 struct dw_dma *dw = to_dw_dma(dwc->chan.device); in dwc_desc_get()
83 desc = dma_pool_zalloc(dw->desc_pool, GFP_ATOMIC, &phys); in dwc_desc_get()
87 dwc->descs_allocated++; in dwc_desc_get()
88 INIT_LIST_HEAD(&desc->tx_list); in dwc_desc_get()
89 dma_async_tx_descriptor_init(&desc->txd, &dwc->chan); in dwc_desc_get()
90 desc->txd.tx_submit = dwc_tx_submit; in dwc_desc_get()
91 desc->txd.flags = DMA_CTRL_ACK; in dwc_desc_get()
92 desc->txd.phys = phys; in dwc_desc_get()
98 struct dw_dma *dw = to_dw_dma(dwc->chan.device); in dwc_desc_put()
104 list_for_each_entry_safe(child, _next, &desc->tx_list, desc_node) { in dwc_desc_put()
105 list_del(&child->desc_node); in dwc_desc_put()
106 dma_pool_free(dw->desc_pool, child, child->txd.phys); in dwc_desc_put()
107 dwc->descs_allocated--; in dwc_desc_put()
110 dma_pool_free(dw->desc_pool, desc, desc->txd.phys); in dwc_desc_put()
111 dwc->descs_allocated--; in dwc_desc_put()
116 struct dw_dma *dw = to_dw_dma(dwc->chan.device); in dwc_initialize()
118 dw->initialize_chan(dwc); in dwc_initialize()
121 channel_set_bit(dw, MASK.XFER, dwc->mask); in dwc_initialize()
122 channel_set_bit(dw, MASK.ERROR, dwc->mask); in dwc_initialize()
125 /*----------------------------------------------------------------------*/
129 dev_err(chan2dev(&dwc->chan), in dwc_dump_chan_regs()
140 channel_clear_bit(dw, CH_EN, dwc->mask); in dwc_chan_disable()
141 while (dma_readl(dw, CH_EN) & dwc->mask) in dwc_chan_disable()
145 /*----------------------------------------------------------------------*/
151 struct dw_dma *dw = to_dw_dma(dwc->chan.device); in dwc_do_single_block()
164 channel_set_bit(dw, CH_EN, dwc->mask); in dwc_do_single_block()
167 dwc->tx_node_active = dwc->tx_node_active->next; in dwc_do_single_block()
170 /* Called with dwc->lock held and bh disabled */
173 struct dw_dma *dw = to_dw_dma(dwc->chan.device); in dwc_dostart()
174 u8 lms = DWC_LLP_LMS(dwc->dws.m_master); in dwc_dostart()
177 /* ASSERT: channel is idle */ in dwc_dostart()
178 if (dma_readl(dw, CH_EN) & dwc->mask) { in dwc_dostart()
179 dev_err(chan2dev(&dwc->chan), in dwc_dostart()
180 "%s: BUG: Attempted to start non-idle channel\n", in dwc_dostart()
188 if (dwc->nollp) { in dwc_dostart()
190 &dwc->flags); in dwc_dostart()
192 dev_err(chan2dev(&dwc->chan), in dwc_dostart()
199 first->residue = first->total_len; in dwc_dostart()
200 dwc->tx_node_active = &first->tx_list; in dwc_dostart()
210 channel_writel(dwc, LLP, first->txd.phys | lms); in dwc_dostart()
213 channel_set_bit(dw, CH_EN, dwc->mask); in dwc_dostart()
220 if (list_empty(&dwc->queue)) in dwc_dostart_first_queued()
223 list_move(dwc->queue.next, &dwc->active_list); in dwc_dostart_first_queued()
225 dev_vdbg(chan2dev(&dwc->chan), "%s: started %u\n", __func__, desc->txd.cookie); in dwc_dostart_first_queued()
229 /*----------------------------------------------------------------------*/
235 struct dma_async_tx_descriptor *txd = &desc->txd; in dwc_descriptor_complete()
240 dev_vdbg(chan2dev(&dwc->chan), "descriptor %u complete\n", txd->cookie); in dwc_descriptor_complete()
242 spin_lock_irqsave(&dwc->lock, flags); in dwc_descriptor_complete()
250 list_for_each_entry(child, &desc->tx_list, desc_node) in dwc_descriptor_complete()
251 async_tx_ack(&child->txd); in dwc_descriptor_complete()
252 async_tx_ack(&desc->txd); in dwc_descriptor_complete()
254 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_descriptor_complete()
265 spin_lock_irqsave(&dwc->lock, flags); in dwc_complete_all()
266 if (dma_readl(dw, CH_EN) & dwc->mask) { in dwc_complete_all()
267 dev_err(chan2dev(&dwc->chan), in dwc_complete_all()
268 "BUG: XFER bit set, but channel not idle!\n"); in dwc_complete_all()
270 /* Try to continue after resetting the channel... */ in dwc_complete_all()
278 list_splice_init(&dwc->active_list, &list); in dwc_complete_all()
281 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_complete_all()
290 struct dw_dma *dw = to_dw_dma(dwc->chan.device); in dwc_get_sent()
294 return dw->block2bytes(dwc, ctlhi, ctllo >> 4 & 7); in dwc_get_sent()
305 spin_lock_irqsave(&dwc->lock, flags); in dwc_scan_descriptors()
309 if (status_xfer & dwc->mask) { in dwc_scan_descriptors()
311 dma_writel(dw, CLEAR.XFER, dwc->mask); in dwc_scan_descriptors()
313 if (test_bit(DW_DMA_IS_SOFT_LLP, &dwc->flags)) { in dwc_scan_descriptors()
314 struct list_head *head, *active = dwc->tx_node_active; in dwc_scan_descriptors()
322 head = &desc->tx_list; in dwc_scan_descriptors()
325 if (active == head->next) in dwc_scan_descriptors()
326 desc->residue -= desc->len; in dwc_scan_descriptors()
328 desc->residue -= to_dw_desc(active->prev)->len; in dwc_scan_descriptors()
335 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_scan_descriptors()
340 clear_bit(DW_DMA_IS_SOFT_LLP, &dwc->flags); in dwc_scan_descriptors()
343 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_scan_descriptors()
349 if (list_empty(&dwc->active_list)) { in dwc_scan_descriptors()
350 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_scan_descriptors()
354 if (test_bit(DW_DMA_IS_SOFT_LLP, &dwc->flags)) { in dwc_scan_descriptors()
355 dev_vdbg(chan2dev(&dwc->chan), "%s: soft LLP mode\n", __func__); in dwc_scan_descriptors()
356 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_scan_descriptors()
360 dev_vdbg(chan2dev(&dwc->chan), "%s: llp=%pad\n", __func__, &llp); in dwc_scan_descriptors()
362 list_for_each_entry_safe(desc, _desc, &dwc->active_list, desc_node) { in dwc_scan_descriptors()
364 desc->residue = desc->total_len; in dwc_scan_descriptors()
367 if (desc->txd.phys == DWC_LLP_LOC(llp)) { in dwc_scan_descriptors()
368 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_scan_descriptors()
375 desc->residue -= dwc_get_sent(dwc); in dwc_scan_descriptors()
376 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_scan_descriptors()
380 desc->residue -= desc->len; in dwc_scan_descriptors()
381 list_for_each_entry(child, &desc->tx_list, desc_node) { in dwc_scan_descriptors()
384 desc->residue -= dwc_get_sent(dwc); in dwc_scan_descriptors()
385 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_scan_descriptors()
388 desc->residue -= child->len; in dwc_scan_descriptors()
395 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_scan_descriptors()
397 spin_lock_irqsave(&dwc->lock, flags); in dwc_scan_descriptors()
400 dev_err(chan2dev(&dwc->chan), in dwc_scan_descriptors()
401 "BUG: All descriptors done, but channel not idle!\n"); in dwc_scan_descriptors()
403 /* Try to continue after resetting the channel... */ in dwc_scan_descriptors()
407 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_scan_descriptors()
412 dev_crit(chan2dev(&dwc->chan), " desc: s0x%x d0x%x l0x%x c0x%x:%x\n", in dwc_dump_lli()
428 spin_lock_irqsave(&dwc->lock, flags); in dwc_handle_error()
436 list_del_init(&bad_desc->desc_node); in dwc_handle_error()
437 list_move(dwc->queue.next, dwc->active_list.prev); in dwc_handle_error()
440 dma_writel(dw, CLEAR.ERROR, dwc->mask); in dwc_handle_error()
441 if (!list_empty(&dwc->active_list)) in dwc_handle_error()
451 dev_WARN(chan2dev(&dwc->chan), "Bad descriptor submitted for DMA!\n" in dwc_handle_error()
452 " cookie: %d\n", bad_desc->txd.cookie); in dwc_handle_error()
454 list_for_each_entry(child, &bad_desc->tx_list, desc_node) in dwc_handle_error()
457 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_handle_error()
474 dev_vdbg(dw->dma.dev, "%s: status_err=%x\n", __func__, status_err); in dw_dma_tasklet()
476 for (i = 0; i < dw->dma.chancnt; i++) { in dw_dma_tasklet()
477 dwc = &dw->chan[i]; in dw_dma_tasklet()
478 if (test_bit(DW_DMA_IS_CYCLIC, &dwc->flags)) in dw_dma_tasklet()
479 dev_vdbg(dw->dma.dev, "Cyclic xfer is not implemented\n"); in dw_dma_tasklet()
486 /* Re-enable interrupts */ in dw_dma_tasklet()
487 channel_set_bit(dw, MASK.XFER, dw->all_chan_mask); in dw_dma_tasklet()
488 channel_set_bit(dw, MASK.ERROR, dw->all_chan_mask); in dw_dma_tasklet()
497 if (!dw->in_use) in dw_dma_interrupt()
501 dev_vdbg(dw->dma.dev, "%s: status=0x%x\n", __func__, status); in dw_dma_interrupt()
511 channel_clear_bit(dw, MASK.XFER, dw->all_chan_mask); in dw_dma_interrupt()
512 channel_clear_bit(dw, MASK.BLOCK, dw->all_chan_mask); in dw_dma_interrupt()
513 channel_clear_bit(dw, MASK.ERROR, dw->all_chan_mask); in dw_dma_interrupt()
517 dev_err(dw->dma.dev, in dw_dma_interrupt()
522 channel_clear_bit(dw, MASK.XFER, (1 << 8) - 1); in dw_dma_interrupt()
523 channel_clear_bit(dw, MASK.BLOCK, (1 << 8) - 1); in dw_dma_interrupt()
524 channel_clear_bit(dw, MASK.SRC_TRAN, (1 << 8) - 1); in dw_dma_interrupt()
525 channel_clear_bit(dw, MASK.DST_TRAN, (1 << 8) - 1); in dw_dma_interrupt()
526 channel_clear_bit(dw, MASK.ERROR, (1 << 8) - 1); in dw_dma_interrupt()
529 tasklet_schedule(&dw->tasklet); in dw_dma_interrupt()
534 /*----------------------------------------------------------------------*/
541 struct dw_dma *dw = to_dw_dma(chan->device); in dwc_prep_dma_memcpy()
547 u8 m_master = dwc->dws.m_master; in dwc_prep_dma_memcpy()
550 unsigned int data_width = dw->pdata->data_width[m_master]; in dwc_prep_dma_memcpy()
563 dwc->direction = DMA_MEM_TO_MEM; in dwc_prep_dma_memcpy()
567 ctllo = dw->prepare_ctllo(dwc) in dwc_prep_dma_memcpy()
580 ctlhi = dw->bytes2block(dwc, len - offset, src_width, &xfer_count); in dwc_prep_dma_memcpy()
586 desc->len = xfer_count; in dwc_prep_dma_memcpy()
591 lli_write(prev, llp, desc->txd.phys | lms); in dwc_prep_dma_memcpy()
592 list_add_tail(&desc->desc_node, &first->tx_list); in dwc_prep_dma_memcpy()
601 prev->lli.llp = 0; in dwc_prep_dma_memcpy()
603 first->txd.flags = flags; in dwc_prep_dma_memcpy()
604 first->total_len = len; in dwc_prep_dma_memcpy()
606 return &first->txd; in dwc_prep_dma_memcpy()
619 struct dw_dma *dw = to_dw_dma(chan->device); in dwc_prep_slave_sg()
620 struct dma_slave_config *sconfig = &dwc->dma_sconfig; in dwc_prep_slave_sg()
624 u8 m_master = dwc->dws.m_master; in dwc_prep_slave_sg()
629 unsigned int data_width = dw->pdata->data_width[m_master]; in dwc_prep_slave_sg()
639 dwc->direction = direction; in dwc_prep_slave_sg()
645 reg_width = __ffs(sconfig->dst_addr_width); in dwc_prep_slave_sg()
646 reg = sconfig->dst_addr; in dwc_prep_slave_sg()
647 ctllo = dw->prepare_ctllo(dwc) in dwc_prep_slave_sg()
652 ctllo |= sconfig->device_fc ? DWC_CTLL_FC(DW_DMA_FC_P_M2P) : in dwc_prep_slave_sg()
670 ctlhi = dw->bytes2block(dwc, len, mem_width, &dlen); in dwc_prep_slave_sg()
676 desc->len = dlen; in dwc_prep_slave_sg()
681 lli_write(prev, llp, desc->txd.phys | lms); in dwc_prep_slave_sg()
682 list_add_tail(&desc->desc_node, &first->tx_list); in dwc_prep_slave_sg()
687 len -= dlen; in dwc_prep_slave_sg()
695 reg_width = __ffs(sconfig->src_addr_width); in dwc_prep_slave_sg()
696 reg = sconfig->src_addr; in dwc_prep_slave_sg()
697 ctllo = dw->prepare_ctllo(dwc) in dwc_prep_slave_sg()
702 ctllo |= sconfig->device_fc ? DWC_CTLL_FC(DW_DMA_FC_P_P2M) : in dwc_prep_slave_sg()
718 ctlhi = dw->bytes2block(dwc, len, reg_width, &dlen); in dwc_prep_slave_sg()
725 desc->len = dlen; in dwc_prep_slave_sg()
730 lli_write(prev, llp, desc->txd.phys | lms); in dwc_prep_slave_sg()
731 list_add_tail(&desc->desc_node, &first->tx_list); in dwc_prep_slave_sg()
736 len -= dlen; in dwc_prep_slave_sg()
751 prev->lli.llp = 0; in dwc_prep_slave_sg()
753 first->total_len = total_len; in dwc_prep_slave_sg()
755 return &first->txd; in dwc_prep_slave_sg()
769 if (dws->dma_dev != chan->device->dev) in dw_dma_filter()
772 /* permit channels in accordance with the channels mask */ in dw_dma_filter()
773 if (dws->channels && !(dws->channels & dwc->mask)) in dw_dma_filter()
777 memcpy(&dwc->dws, dws, sizeof(struct dw_dma_slave)); in dw_dma_filter()
786 struct dw_dma *dw = to_dw_dma(chan->device); in dwc_config()
788 memcpy(&dwc->dma_sconfig, sconfig, sizeof(*sconfig)); in dwc_config()
790 dwc->dma_sconfig.src_maxburst = in dwc_config()
791 clamp(dwc->dma_sconfig.src_maxburst, 0U, dwc->max_burst); in dwc_config()
792 dwc->dma_sconfig.dst_maxburst = in dwc_config()
793 clamp(dwc->dma_sconfig.dst_maxburst, 0U, dwc->max_burst); in dwc_config()
795 dw->encode_maxburst(dwc, &dwc->dma_sconfig.src_maxburst); in dwc_config()
796 dw->encode_maxburst(dwc, &dwc->dma_sconfig.dst_maxburst); in dwc_config()
803 struct dw_dma *dw = to_dw_dma(dwc->chan.device); in dwc_chan_pause()
806 dw->suspend_chan(dwc, drain); in dwc_chan_pause()
808 while (!(channel_readl(dwc, CFG_LO) & DWC_CFGL_FIFO_EMPTY) && count--) in dwc_chan_pause()
811 set_bit(DW_DMA_IS_PAUSED, &dwc->flags); in dwc_chan_pause()
819 spin_lock_irqsave(&dwc->lock, flags); in dwc_pause()
821 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_pause()
828 struct dw_dma *dw = to_dw_dma(dwc->chan.device); in dwc_chan_resume()
830 dw->resume_chan(dwc, drain); in dwc_chan_resume()
832 clear_bit(DW_DMA_IS_PAUSED, &dwc->flags); in dwc_chan_resume()
840 spin_lock_irqsave(&dwc->lock, flags); in dwc_resume()
842 if (test_bit(DW_DMA_IS_PAUSED, &dwc->flags)) in dwc_resume()
845 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_resume()
853 struct dw_dma *dw = to_dw_dma(chan->device); in dwc_terminate_all()
858 spin_lock_irqsave(&dwc->lock, flags); in dwc_terminate_all()
860 clear_bit(DW_DMA_IS_SOFT_LLP, &dwc->flags); in dwc_terminate_all()
869 list_splice_init(&dwc->queue, &list); in dwc_terminate_all()
870 list_splice_init(&dwc->active_list, &list); in dwc_terminate_all()
872 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_terminate_all()
885 list_for_each_entry(desc, &dwc->active_list, desc_node) in dwc_find_desc()
886 if (desc->txd.cookie == c) in dwc_find_desc()
899 spin_lock_irqsave(&dwc->lock, flags); in dwc_get_residue_and_status()
904 residue = desc->residue; in dwc_get_residue_and_status()
905 if (test_bit(DW_DMA_IS_SOFT_LLP, &dwc->flags) && residue) in dwc_get_residue_and_status()
906 residue -= dwc_get_sent(dwc); in dwc_get_residue_and_status()
907 if (test_bit(DW_DMA_IS_PAUSED, &dwc->flags)) in dwc_get_residue_and_status()
910 residue = desc->total_len; in dwc_get_residue_and_status()
916 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_get_residue_and_status()
932 dwc_scan_descriptors(to_dw_dma(chan->device), dwc); in dwc_tx_status()
947 spin_lock_irqsave(&dwc->lock, flags); in dwc_issue_pending()
948 if (list_empty(&dwc->active_list)) in dwc_issue_pending()
950 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_issue_pending()
953 /*----------------------------------------------------------------------*/
959 channel_clear_bit(dw, MASK.XFER, dw->all_chan_mask); in do_dw_dma_off()
960 channel_clear_bit(dw, MASK.BLOCK, dw->all_chan_mask); in do_dw_dma_off()
961 channel_clear_bit(dw, MASK.SRC_TRAN, dw->all_chan_mask); in do_dw_dma_off()
962 channel_clear_bit(dw, MASK.DST_TRAN, dw->all_chan_mask); in do_dw_dma_off()
963 channel_clear_bit(dw, MASK.ERROR, dw->all_chan_mask); in do_dw_dma_off()
977 struct dw_dma *dw = to_dw_dma(chan->device); in dwc_alloc_chan_resources()
981 /* ASSERT: channel is idle */ in dwc_alloc_chan_resources()
982 if (dma_readl(dw, CH_EN) & dwc->mask) { in dwc_alloc_chan_resources()
983 dev_dbg(chan2dev(chan), "DMA channel not idle?\n"); in dwc_alloc_chan_resources()
984 return -EIO; in dwc_alloc_chan_resources()
991 * need to initialize here, like "scatter-gather" (which in dwc_alloc_chan_resources()
996 * We need controller-specific data to set up slave transfers. in dwc_alloc_chan_resources()
998 if (chan->private && !dw_dma_filter(chan, chan->private)) { in dwc_alloc_chan_resources()
999 dev_warn(chan2dev(chan), "Wrong controller-specific data\n"); in dwc_alloc_chan_resources()
1000 return -EINVAL; in dwc_alloc_chan_resources()
1004 if (!dw->in_use) in dwc_alloc_chan_resources()
1006 dw->in_use |= dwc->mask; in dwc_alloc_chan_resources()
1014 struct dw_dma *dw = to_dw_dma(chan->device); in dwc_free_chan_resources()
1018 dwc->descs_allocated); in dwc_free_chan_resources()
1020 /* ASSERT: channel is idle */ in dwc_free_chan_resources()
1021 BUG_ON(!list_empty(&dwc->active_list)); in dwc_free_chan_resources()
1022 BUG_ON(!list_empty(&dwc->queue)); in dwc_free_chan_resources()
1023 BUG_ON(dma_readl(to_dw_dma(chan->device), CH_EN) & dwc->mask); in dwc_free_chan_resources()
1025 spin_lock_irqsave(&dwc->lock, flags); in dwc_free_chan_resources()
1027 /* Clear custom channel configuration */ in dwc_free_chan_resources()
1028 memset(&dwc->dws, 0, sizeof(struct dw_dma_slave)); in dwc_free_chan_resources()
1031 channel_clear_bit(dw, MASK.XFER, dwc->mask); in dwc_free_chan_resources()
1032 channel_clear_bit(dw, MASK.BLOCK, dwc->mask); in dwc_free_chan_resources()
1033 channel_clear_bit(dw, MASK.ERROR, dwc->mask); in dwc_free_chan_resources()
1035 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_free_chan_resources()
1038 dw->in_use &= ~dwc->mask; in dwc_free_chan_resources()
1039 if (!dw->in_use) in dwc_free_chan_resources()
1049 caps->max_burst = dwc->max_burst; in dwc_caps()
1053 * accelerated multi-block transfers supported, aka LLPs in DW DMAC in dwc_caps()
1056 * single DMA transaction, otherwise it's just one SG entry. in dwc_caps()
1058 if (dwc->nollp) in dwc_caps()
1059 caps->max_sg_burst = 1; in dwc_caps()
1061 caps->max_sg_burst = 0; in dwc_caps()
1066 struct dw_dma *dw = chip->dw; in do_dma_probe()
1073 dw->pdata = devm_kzalloc(chip->dev, sizeof(*dw->pdata), GFP_KERNEL); in do_dma_probe()
1074 if (!dw->pdata) in do_dma_probe()
1075 return -ENOMEM; in do_dma_probe()
1077 dw->regs = chip->regs; in do_dma_probe()
1079 pm_runtime_get_sync(chip->dev); in do_dma_probe()
1081 if (!chip->pdata) { in do_dma_probe()
1083 dev_dbg(chip->dev, "DW_PARAMS: 0x%08x\n", dw_params); in do_dma_probe()
1087 err = -EINVAL; in do_dma_probe()
1092 pdata = dw->pdata; in do_dma_probe()
1095 pdata->nr_channels = (dw_params >> DW_PARAMS_NR_CHAN & 7) + 1; in do_dma_probe()
1096 pdata->nr_masters = (dw_params >> DW_PARAMS_NR_MASTER & 3) + 1; in do_dma_probe()
1097 for (i = 0; i < pdata->nr_masters; i++) { in do_dma_probe()
1098 pdata->data_width[i] = in do_dma_probe()
1101 pdata->block_size = dma_readl(dw, MAX_BLK_SIZE); in do_dma_probe()
1104 pdata->chan_allocation_order = CHAN_ALLOCATION_ASCENDING; in do_dma_probe()
1105 pdata->chan_priority = CHAN_PRIORITY_ASCENDING; in do_dma_probe()
1106 } else if (chip->pdata->nr_channels > DW_DMA_MAX_NR_CHANNELS) { in do_dma_probe()
1107 err = -EINVAL; in do_dma_probe()
1110 memcpy(dw->pdata, chip->pdata, sizeof(*dw->pdata)); in do_dma_probe()
1113 pdata = dw->pdata; in do_dma_probe()
1116 dw->chan = devm_kcalloc(chip->dev, pdata->nr_channels, sizeof(*dw->chan), in do_dma_probe()
1118 if (!dw->chan) { in do_dma_probe()
1119 err = -ENOMEM; in do_dma_probe()
1123 /* Calculate all channel mask before DMA setup */ in do_dma_probe()
1124 dw->all_chan_mask = (1 << pdata->nr_channels) - 1; in do_dma_probe()
1126 /* Force dma off, just in case */ in do_dma_probe()
1127 dw->disable(dw); in do_dma_probe()
1129 /* Device and instance ID for IRQ and DMA pool */ in do_dma_probe()
1130 dw->set_device_name(dw, chip->id); in do_dma_probe()
1133 dw->desc_pool = dmam_pool_create(dw->name, chip->dev, in do_dma_probe()
1135 if (!dw->desc_pool) { in do_dma_probe()
1136 dev_err(chip->dev, "No memory for descriptors dma pool\n"); in do_dma_probe()
1137 err = -ENOMEM; in do_dma_probe()
1141 tasklet_setup(&dw->tasklet, dw_dma_tasklet); in do_dma_probe()
1143 err = request_irq(chip->irq, dw_dma_interrupt, IRQF_SHARED, in do_dma_probe()
1144 dw->name, dw); in do_dma_probe()
1148 INIT_LIST_HEAD(&dw->dma.channels); in do_dma_probe()
1149 for (i = 0; i < pdata->nr_channels; i++) { in do_dma_probe()
1150 struct dw_dma_chan *dwc = &dw->chan[i]; in do_dma_probe()
1152 dwc->chan.device = &dw->dma; in do_dma_probe()
1153 dma_cookie_init(&dwc->chan); in do_dma_probe()
1154 if (pdata->chan_allocation_order == CHAN_ALLOCATION_ASCENDING) in do_dma_probe()
1155 list_add_tail(&dwc->chan.device_node, in do_dma_probe()
1156 &dw->dma.channels); in do_dma_probe()
1158 list_add(&dwc->chan.device_node, &dw->dma.channels); in do_dma_probe()
1161 if (pdata->chan_priority == CHAN_PRIORITY_ASCENDING) in do_dma_probe()
1162 dwc->priority = pdata->nr_channels - i - 1; in do_dma_probe()
1164 dwc->priority = i; in do_dma_probe()
1166 dwc->ch_regs = &__dw_regs(dw)->CHAN[i]; in do_dma_probe()
1167 spin_lock_init(&dwc->lock); in do_dma_probe()
1168 dwc->mask = 1 << i; in do_dma_probe()
1170 INIT_LIST_HEAD(&dwc->active_list); in do_dma_probe()
1171 INIT_LIST_HEAD(&dwc->queue); in do_dma_probe()
1173 channel_clear_bit(dw, CH_EN, dwc->mask); in do_dma_probe()
1175 dwc->direction = DMA_TRANS_NONE; in do_dma_probe()
1179 unsigned int r = DW_DMA_MAX_NR_CHANNELS - i - 1; in do_dma_probe()
1180 void __iomem *addr = &__dw_regs(dw)->DWC_PARAMS[r]; in do_dma_probe()
1183 dev_dbg(chip->dev, "DWC_PARAMS[%d]: 0x%08x\n", i, in do_dma_probe()
1187 * Decode maximum block size for given channel. The in do_dma_probe()
1191 dwc->block_size = in do_dma_probe()
1192 (4 << ((pdata->block_size >> 4 * i) & 0xf)) - 1; in do_dma_probe()
1195 * According to the DW DMA databook the true scatter- in do_dma_probe()
1196 * gether LLPs aren't available if either multi-block in do_dma_probe()
1198 * LLP register is hard-coded to zeros in do_dma_probe()
1201 dwc->nollp = in do_dma_probe()
1204 dwc->max_burst = in do_dma_probe()
1207 dwc->block_size = pdata->block_size; in do_dma_probe()
1208 dwc->nollp = !pdata->multi_block[i]; in do_dma_probe()
1209 dwc->max_burst = pdata->max_burst[i] ?: DW_DMA_MAX_BURST; in do_dma_probe()
1214 dma_writel(dw, CLEAR.XFER, dw->all_chan_mask); in do_dma_probe()
1215 dma_writel(dw, CLEAR.BLOCK, dw->all_chan_mask); in do_dma_probe()
1216 dma_writel(dw, CLEAR.SRC_TRAN, dw->all_chan_mask); in do_dma_probe()
1217 dma_writel(dw, CLEAR.DST_TRAN, dw->all_chan_mask); in do_dma_probe()
1218 dma_writel(dw, CLEAR.ERROR, dw->all_chan_mask); in do_dma_probe()
1221 dma_cap_set(DMA_SLAVE, dw->dma.cap_mask); in do_dma_probe()
1222 dma_cap_set(DMA_PRIVATE, dw->dma.cap_mask); in do_dma_probe()
1223 dma_cap_set(DMA_MEMCPY, dw->dma.cap_mask); in do_dma_probe()
1225 dw->dma.dev = chip->dev; in do_dma_probe()
1226 dw->dma.device_alloc_chan_resources = dwc_alloc_chan_resources; in do_dma_probe()
1227 dw->dma.device_free_chan_resources = dwc_free_chan_resources; in do_dma_probe()
1229 dw->dma.device_prep_dma_memcpy = dwc_prep_dma_memcpy; in do_dma_probe()
1230 dw->dma.device_prep_slave_sg = dwc_prep_slave_sg; in do_dma_probe()
1232 dw->dma.device_caps = dwc_caps; in do_dma_probe()
1233 dw->dma.device_config = dwc_config; in do_dma_probe()
1234 dw->dma.device_pause = dwc_pause; in do_dma_probe()
1235 dw->dma.device_resume = dwc_resume; in do_dma_probe()
1236 dw->dma.device_terminate_all = dwc_terminate_all; in do_dma_probe()
1238 dw->dma.device_tx_status = dwc_tx_status; in do_dma_probe()
1239 dw->dma.device_issue_pending = dwc_issue_pending; in do_dma_probe()
1241 /* DMA capabilities */ in do_dma_probe()
1242 dw->dma.min_burst = DW_DMA_MIN_BURST; in do_dma_probe()
1243 dw->dma.max_burst = DW_DMA_MAX_BURST; in do_dma_probe()
1244 dw->dma.src_addr_widths = DW_DMA_BUSWIDTHS; in do_dma_probe()
1245 dw->dma.dst_addr_widths = DW_DMA_BUSWIDTHS; in do_dma_probe()
1246 dw->dma.directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV) | in do_dma_probe()
1248 dw->dma.residue_granularity = DMA_RESIDUE_GRANULARITY_BURST; in do_dma_probe()
1253 * size as the block size found for the very first channel. in do_dma_probe()
1255 dma_set_max_seg_size(dw->dma.dev, dw->chan[0].block_size); in do_dma_probe()
1257 err = dma_async_device_register(&dw->dma); in do_dma_probe()
1261 dev_info(chip->dev, "DesignWare DMA Controller, %d channels\n", in do_dma_probe()
1262 pdata->nr_channels); in do_dma_probe()
1264 pm_runtime_put_sync_suspend(chip->dev); in do_dma_probe()
1269 free_irq(chip->irq, dw); in do_dma_probe()
1271 pm_runtime_put_sync_suspend(chip->dev); in do_dma_probe()
1277 struct dw_dma *dw = chip->dw; in do_dma_remove()
1280 pm_runtime_get_sync(chip->dev); in do_dma_remove()
1283 dma_async_device_unregister(&dw->dma); in do_dma_remove()
1285 free_irq(chip->irq, dw); in do_dma_remove()
1286 tasklet_kill(&dw->tasklet); in do_dma_remove()
1288 list_for_each_entry_safe(dwc, _dwc, &dw->dma.channels, in do_dma_remove()
1290 list_del(&dwc->chan.device_node); in do_dma_remove()
1291 channel_clear_bit(dw, CH_EN, dwc->mask); in do_dma_remove()
1294 pm_runtime_put_sync_suspend(chip->dev); in do_dma_remove()
1300 struct dw_dma *dw = chip->dw; in do_dw_dma_disable()
1302 dw->disable(dw); in do_dw_dma_disable()
1309 struct dw_dma *dw = chip->dw; in do_dw_dma_enable()
1311 dw->enable(dw); in do_dw_dma_enable()
1317 MODULE_DESCRIPTION("Synopsys DesignWare DMA Controller core driver");