• Home
  • Raw
  • Download

Lines Matching refs:dwc

51 static struct dw_desc *dwc_first_active(struct dw_dma_chan *dwc)  in dwc_first_active()  argument
53 return to_dw_desc(dwc->active_list.next); in dwc_first_active()
59 struct dw_dma_chan *dwc = to_dw_dma_chan(tx->chan); in dwc_tx_submit() local
63 spin_lock_irqsave(&dwc->lock, flags); in dwc_tx_submit()
72 list_add_tail(&desc->desc_node, &dwc->queue); in dwc_tx_submit()
73 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_tx_submit()
80 static struct dw_desc *dwc_desc_get(struct dw_dma_chan *dwc) in dwc_desc_get() argument
82 struct dw_dma *dw = to_dw_dma(dwc->chan.device); in dwc_desc_get()
90 dwc->descs_allocated++; in dwc_desc_get()
92 dma_async_tx_descriptor_init(&desc->txd, &dwc->chan); in dwc_desc_get()
99 static void dwc_desc_put(struct dw_dma_chan *dwc, struct dw_desc *desc) in dwc_desc_put() argument
101 struct dw_dma *dw = to_dw_dma(dwc->chan.device); in dwc_desc_put()
110 dwc->descs_allocated--; in dwc_desc_put()
114 dwc->descs_allocated--; in dwc_desc_put()
117 static void dwc_initialize(struct dw_dma_chan *dwc) in dwc_initialize() argument
119 struct dw_dma *dw = to_dw_dma(dwc->chan.device); in dwc_initialize()
121 if (test_bit(DW_DMA_IS_INITIALIZED, &dwc->flags)) in dwc_initialize()
124 dw->initialize_chan(dwc); in dwc_initialize()
127 channel_set_bit(dw, MASK.XFER, dwc->mask); in dwc_initialize()
128 channel_set_bit(dw, MASK.ERROR, dwc->mask); in dwc_initialize()
130 set_bit(DW_DMA_IS_INITIALIZED, &dwc->flags); in dwc_initialize()
135 static inline void dwc_dump_chan_regs(struct dw_dma_chan *dwc) in dwc_dump_chan_regs() argument
137 dev_err(chan2dev(&dwc->chan), in dwc_dump_chan_regs()
139 channel_readl(dwc, SAR), in dwc_dump_chan_regs()
140 channel_readl(dwc, DAR), in dwc_dump_chan_regs()
141 channel_readl(dwc, LLP), in dwc_dump_chan_regs()
142 channel_readl(dwc, CTL_HI), in dwc_dump_chan_regs()
143 channel_readl(dwc, CTL_LO)); in dwc_dump_chan_regs()
146 static inline void dwc_chan_disable(struct dw_dma *dw, struct dw_dma_chan *dwc) in dwc_chan_disable() argument
148 channel_clear_bit(dw, CH_EN, dwc->mask); in dwc_chan_disable()
149 while (dma_readl(dw, CH_EN) & dwc->mask) in dwc_chan_disable()
156 static inline void dwc_do_single_block(struct dw_dma_chan *dwc, in dwc_do_single_block() argument
159 struct dw_dma *dw = to_dw_dma(dwc->chan.device); in dwc_do_single_block()
168 channel_writel(dwc, SAR, lli_read(desc, sar)); in dwc_do_single_block()
169 channel_writel(dwc, DAR, lli_read(desc, dar)); in dwc_do_single_block()
170 channel_writel(dwc, CTL_LO, ctllo); in dwc_do_single_block()
171 channel_writel(dwc, CTL_HI, lli_read(desc, ctlhi)); in dwc_do_single_block()
172 channel_set_bit(dw, CH_EN, dwc->mask); in dwc_do_single_block()
175 dwc->tx_node_active = dwc->tx_node_active->next; in dwc_do_single_block()
179 static void dwc_dostart(struct dw_dma_chan *dwc, struct dw_desc *first) in dwc_dostart() argument
181 struct dw_dma *dw = to_dw_dma(dwc->chan.device); in dwc_dostart()
182 u8 lms = DWC_LLP_LMS(dwc->dws.m_master); in dwc_dostart()
186 if (dma_readl(dw, CH_EN) & dwc->mask) { in dwc_dostart()
187 dev_err(chan2dev(&dwc->chan), in dwc_dostart()
190 dwc_dump_chan_regs(dwc); in dwc_dostart()
196 if (dwc->nollp) { in dwc_dostart()
198 &dwc->flags); in dwc_dostart()
200 dev_err(chan2dev(&dwc->chan), in dwc_dostart()
205 dwc_initialize(dwc); in dwc_dostart()
208 dwc->tx_node_active = &first->tx_list; in dwc_dostart()
211 dwc_do_single_block(dwc, first); in dwc_dostart()
216 dwc_initialize(dwc); in dwc_dostart()
218 channel_writel(dwc, LLP, first->txd.phys | lms); in dwc_dostart()
219 channel_writel(dwc, CTL_LO, DWC_CTLL_LLP_D_EN | DWC_CTLL_LLP_S_EN); in dwc_dostart()
220 channel_writel(dwc, CTL_HI, 0); in dwc_dostart()
221 channel_set_bit(dw, CH_EN, dwc->mask); in dwc_dostart()
224 static void dwc_dostart_first_queued(struct dw_dma_chan *dwc) in dwc_dostart_first_queued() argument
228 if (list_empty(&dwc->queue)) in dwc_dostart_first_queued()
231 list_move(dwc->queue.next, &dwc->active_list); in dwc_dostart_first_queued()
232 desc = dwc_first_active(dwc); in dwc_dostart_first_queued()
233 dev_vdbg(chan2dev(&dwc->chan), "%s: started %u\n", __func__, desc->txd.cookie); in dwc_dostart_first_queued()
234 dwc_dostart(dwc, desc); in dwc_dostart_first_queued()
240 dwc_descriptor_complete(struct dw_dma_chan *dwc, struct dw_desc *desc, in dwc_descriptor_complete() argument
248 dev_vdbg(chan2dev(&dwc->chan), "descriptor %u complete\n", txd->cookie); in dwc_descriptor_complete()
250 spin_lock_irqsave(&dwc->lock, flags); in dwc_descriptor_complete()
261 dwc_desc_put(dwc, desc); in dwc_descriptor_complete()
262 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_descriptor_complete()
267 static void dwc_complete_all(struct dw_dma *dw, struct dw_dma_chan *dwc) in dwc_complete_all() argument
273 spin_lock_irqsave(&dwc->lock, flags); in dwc_complete_all()
274 if (dma_readl(dw, CH_EN) & dwc->mask) { in dwc_complete_all()
275 dev_err(chan2dev(&dwc->chan), in dwc_complete_all()
279 dwc_chan_disable(dw, dwc); in dwc_complete_all()
286 list_splice_init(&dwc->active_list, &list); in dwc_complete_all()
287 dwc_dostart_first_queued(dwc); in dwc_complete_all()
289 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_complete_all()
292 dwc_descriptor_complete(dwc, desc, true); in dwc_complete_all()
296 static inline u32 dwc_get_sent(struct dw_dma_chan *dwc) in dwc_get_sent() argument
298 struct dw_dma *dw = to_dw_dma(dwc->chan.device); in dwc_get_sent()
299 u32 ctlhi = channel_readl(dwc, CTL_HI); in dwc_get_sent()
300 u32 ctllo = channel_readl(dwc, CTL_LO); in dwc_get_sent()
302 return dw->block2bytes(dwc, ctlhi, ctllo >> 4 & 7); in dwc_get_sent()
305 static void dwc_scan_descriptors(struct dw_dma *dw, struct dw_dma_chan *dwc) in dwc_scan_descriptors() argument
313 spin_lock_irqsave(&dwc->lock, flags); in dwc_scan_descriptors()
314 llp = channel_readl(dwc, LLP); in dwc_scan_descriptors()
317 if (status_xfer & dwc->mask) { in dwc_scan_descriptors()
319 dma_writel(dw, CLEAR.XFER, dwc->mask); in dwc_scan_descriptors()
321 if (test_bit(DW_DMA_IS_SOFT_LLP, &dwc->flags)) { in dwc_scan_descriptors()
322 struct list_head *head, *active = dwc->tx_node_active; in dwc_scan_descriptors()
328 desc = dwc_first_active(dwc); in dwc_scan_descriptors()
341 dwc_do_single_block(dwc, child); in dwc_scan_descriptors()
343 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_scan_descriptors()
348 clear_bit(DW_DMA_IS_SOFT_LLP, &dwc->flags); in dwc_scan_descriptors()
351 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_scan_descriptors()
353 dwc_complete_all(dw, dwc); in dwc_scan_descriptors()
357 if (list_empty(&dwc->active_list)) { in dwc_scan_descriptors()
358 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_scan_descriptors()
362 if (test_bit(DW_DMA_IS_SOFT_LLP, &dwc->flags)) { in dwc_scan_descriptors()
363 dev_vdbg(chan2dev(&dwc->chan), "%s: soft LLP mode\n", __func__); in dwc_scan_descriptors()
364 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_scan_descriptors()
368 dev_vdbg(chan2dev(&dwc->chan), "%s: llp=%pad\n", __func__, &llp); in dwc_scan_descriptors()
370 list_for_each_entry_safe(desc, _desc, &dwc->active_list, desc_node) { in dwc_scan_descriptors()
376 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_scan_descriptors()
383 desc->residue -= dwc_get_sent(dwc); in dwc_scan_descriptors()
384 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_scan_descriptors()
392 desc->residue -= dwc_get_sent(dwc); in dwc_scan_descriptors()
393 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_scan_descriptors()
403 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_scan_descriptors()
404 dwc_descriptor_complete(dwc, desc, true); in dwc_scan_descriptors()
405 spin_lock_irqsave(&dwc->lock, flags); in dwc_scan_descriptors()
408 dev_err(chan2dev(&dwc->chan), in dwc_scan_descriptors()
412 dwc_chan_disable(dw, dwc); in dwc_scan_descriptors()
414 dwc_dostart_first_queued(dwc); in dwc_scan_descriptors()
415 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_scan_descriptors()
418 static inline void dwc_dump_lli(struct dw_dma_chan *dwc, struct dw_desc *desc) in dwc_dump_lli() argument
420 dev_crit(chan2dev(&dwc->chan), " desc: s0x%x d0x%x l0x%x c0x%x:%x\n", in dwc_dump_lli()
428 static void dwc_handle_error(struct dw_dma *dw, struct dw_dma_chan *dwc) in dwc_handle_error() argument
434 dwc_scan_descriptors(dw, dwc); in dwc_handle_error()
436 spin_lock_irqsave(&dwc->lock, flags); in dwc_handle_error()
443 bad_desc = dwc_first_active(dwc); in dwc_handle_error()
445 list_move(dwc->queue.next, dwc->active_list.prev); in dwc_handle_error()
448 dma_writel(dw, CLEAR.ERROR, dwc->mask); in dwc_handle_error()
449 if (!list_empty(&dwc->active_list)) in dwc_handle_error()
450 dwc_dostart(dwc, dwc_first_active(dwc)); in dwc_handle_error()
459 dev_WARN(chan2dev(&dwc->chan), "Bad descriptor submitted for DMA!\n" in dwc_handle_error()
461 dwc_dump_lli(dwc, bad_desc); in dwc_handle_error()
463 dwc_dump_lli(dwc, child); in dwc_handle_error()
465 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_handle_error()
468 dwc_descriptor_complete(dwc, bad_desc, true); in dwc_handle_error()
474 struct dw_dma_chan *dwc; in dw_dma_tasklet() local
485 dwc = &dw->chan[i]; in dw_dma_tasklet()
486 if (test_bit(DW_DMA_IS_CYCLIC, &dwc->flags)) in dw_dma_tasklet()
489 dwc_handle_error(dw, dwc); in dw_dma_tasklet()
491 dwc_scan_descriptors(dw, dwc); in dw_dma_tasklet()
548 struct dw_dma_chan *dwc = to_dw_dma_chan(chan); in dwc_prep_dma_memcpy() local
555 u8 m_master = dwc->dws.m_master; in dwc_prep_dma_memcpy()
571 dwc->direction = DMA_MEM_TO_MEM; in dwc_prep_dma_memcpy()
575 ctllo = dw->prepare_ctllo(dwc) in dwc_prep_dma_memcpy()
584 desc = dwc_desc_get(dwc); in dwc_prep_dma_memcpy()
588 ctlhi = dw->bytes2block(dwc, len - offset, src_width, &xfer_count); in dwc_prep_dma_memcpy()
617 dwc_desc_put(dwc, first); in dwc_prep_dma_memcpy()
626 struct dw_dma_chan *dwc = to_dw_dma_chan(chan); in dwc_prep_slave_sg() local
628 struct dma_slave_config *sconfig = &dwc->dma_sconfig; in dwc_prep_slave_sg()
632 u8 m_master = dwc->dws.m_master; in dwc_prep_slave_sg()
647 dwc->direction = direction; in dwc_prep_slave_sg()
655 ctllo = dw->prepare_ctllo(dwc) in dwc_prep_slave_sg()
674 desc = dwc_desc_get(dwc); in dwc_prep_slave_sg()
678 ctlhi = dw->bytes2block(dwc, len, mem_width, &dlen); in dwc_prep_slave_sg()
705 ctllo = dw->prepare_ctllo(dwc) in dwc_prep_slave_sg()
722 desc = dwc_desc_get(dwc); in dwc_prep_slave_sg()
726 ctlhi = dw->bytes2block(dwc, len, reg_width, &dlen); in dwc_prep_slave_sg()
768 dwc_desc_put(dwc, first); in dwc_prep_slave_sg()
774 struct dw_dma_chan *dwc = to_dw_dma_chan(chan); in dw_dma_filter() local
781 memcpy(&dwc->dws, dws, sizeof(struct dw_dma_slave)); in dw_dma_filter()
789 struct dw_dma_chan *dwc = to_dw_dma_chan(chan); in dwc_config() local
792 memcpy(&dwc->dma_sconfig, sconfig, sizeof(*sconfig)); in dwc_config()
794 dw->encode_maxburst(dwc, &dwc->dma_sconfig.src_maxburst); in dwc_config()
795 dw->encode_maxburst(dwc, &dwc->dma_sconfig.dst_maxburst); in dwc_config()
800 static void dwc_chan_pause(struct dw_dma_chan *dwc, bool drain) in dwc_chan_pause() argument
802 struct dw_dma *dw = to_dw_dma(dwc->chan.device); in dwc_chan_pause()
805 dw->suspend_chan(dwc, drain); in dwc_chan_pause()
807 while (!(channel_readl(dwc, CFG_LO) & DWC_CFGL_FIFO_EMPTY) && count--) in dwc_chan_pause()
810 set_bit(DW_DMA_IS_PAUSED, &dwc->flags); in dwc_chan_pause()
815 struct dw_dma_chan *dwc = to_dw_dma_chan(chan); in dwc_pause() local
818 spin_lock_irqsave(&dwc->lock, flags); in dwc_pause()
819 dwc_chan_pause(dwc, false); in dwc_pause()
820 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_pause()
825 static inline void dwc_chan_resume(struct dw_dma_chan *dwc, bool drain) in dwc_chan_resume() argument
827 struct dw_dma *dw = to_dw_dma(dwc->chan.device); in dwc_chan_resume()
829 dw->resume_chan(dwc, drain); in dwc_chan_resume()
831 clear_bit(DW_DMA_IS_PAUSED, &dwc->flags); in dwc_chan_resume()
836 struct dw_dma_chan *dwc = to_dw_dma_chan(chan); in dwc_resume() local
839 spin_lock_irqsave(&dwc->lock, flags); in dwc_resume()
841 if (test_bit(DW_DMA_IS_PAUSED, &dwc->flags)) in dwc_resume()
842 dwc_chan_resume(dwc, false); in dwc_resume()
844 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_resume()
851 struct dw_dma_chan *dwc = to_dw_dma_chan(chan); in dwc_terminate_all() local
857 spin_lock_irqsave(&dwc->lock, flags); in dwc_terminate_all()
859 clear_bit(DW_DMA_IS_SOFT_LLP, &dwc->flags); in dwc_terminate_all()
861 dwc_chan_pause(dwc, true); in dwc_terminate_all()
863 dwc_chan_disable(dw, dwc); in dwc_terminate_all()
865 dwc_chan_resume(dwc, true); in dwc_terminate_all()
868 list_splice_init(&dwc->queue, &list); in dwc_terminate_all()
869 list_splice_init(&dwc->active_list, &list); in dwc_terminate_all()
871 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_terminate_all()
875 dwc_descriptor_complete(dwc, desc, false); in dwc_terminate_all()
880 static struct dw_desc *dwc_find_desc(struct dw_dma_chan *dwc, dma_cookie_t c) in dwc_find_desc() argument
884 list_for_each_entry(desc, &dwc->active_list, desc_node) in dwc_find_desc()
891 static u32 dwc_get_residue(struct dw_dma_chan *dwc, dma_cookie_t cookie) in dwc_get_residue() argument
897 spin_lock_irqsave(&dwc->lock, flags); in dwc_get_residue()
899 desc = dwc_find_desc(dwc, cookie); in dwc_get_residue()
901 if (desc == dwc_first_active(dwc)) { in dwc_get_residue()
903 if (test_bit(DW_DMA_IS_SOFT_LLP, &dwc->flags) && residue) in dwc_get_residue()
904 residue -= dwc_get_sent(dwc); in dwc_get_residue()
912 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_get_residue()
921 struct dw_dma_chan *dwc = to_dw_dma_chan(chan); in dwc_tx_status() local
928 dwc_scan_descriptors(to_dw_dma(chan->device), dwc); in dwc_tx_status()
934 dma_set_residue(txstate, dwc_get_residue(dwc, cookie)); in dwc_tx_status()
936 if (test_bit(DW_DMA_IS_PAUSED, &dwc->flags) && ret == DMA_IN_PROGRESS) in dwc_tx_status()
944 struct dw_dma_chan *dwc = to_dw_dma_chan(chan); in dwc_issue_pending() local
947 spin_lock_irqsave(&dwc->lock, flags); in dwc_issue_pending()
948 if (list_empty(&dwc->active_list)) in dwc_issue_pending()
949 dwc_dostart_first_queued(dwc); in dwc_issue_pending()
950 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_issue_pending()
981 struct dw_dma_chan *dwc = to_dw_dma_chan(chan); in dwc_alloc_chan_resources() local
987 if (dma_readl(dw, CH_EN) & dwc->mask) { in dwc_alloc_chan_resources()
1011 dw->in_use |= dwc->mask; in dwc_alloc_chan_resources()
1018 struct dw_dma_chan *dwc = to_dw_dma_chan(chan); in dwc_free_chan_resources() local
1023 dwc->descs_allocated); in dwc_free_chan_resources()
1026 BUG_ON(!list_empty(&dwc->active_list)); in dwc_free_chan_resources()
1027 BUG_ON(!list_empty(&dwc->queue)); in dwc_free_chan_resources()
1028 BUG_ON(dma_readl(to_dw_dma(chan->device), CH_EN) & dwc->mask); in dwc_free_chan_resources()
1030 spin_lock_irqsave(&dwc->lock, flags); in dwc_free_chan_resources()
1033 memset(&dwc->dws, 0, sizeof(struct dw_dma_slave)); in dwc_free_chan_resources()
1035 clear_bit(DW_DMA_IS_INITIALIZED, &dwc->flags); in dwc_free_chan_resources()
1038 channel_clear_bit(dw, MASK.XFER, dwc->mask); in dwc_free_chan_resources()
1039 channel_clear_bit(dw, MASK.BLOCK, dwc->mask); in dwc_free_chan_resources()
1040 channel_clear_bit(dw, MASK.ERROR, dwc->mask); in dwc_free_chan_resources()
1042 spin_unlock_irqrestore(&dwc->lock, flags); in dwc_free_chan_resources()
1045 dw->in_use &= ~dwc->mask; in dwc_free_chan_resources()
1138 struct dw_dma_chan *dwc = &dw->chan[i]; in do_dma_probe() local
1140 dwc->chan.device = &dw->dma; in do_dma_probe()
1141 dma_cookie_init(&dwc->chan); in do_dma_probe()
1143 list_add_tail(&dwc->chan.device_node, in do_dma_probe()
1146 list_add(&dwc->chan.device_node, &dw->dma.channels); in do_dma_probe()
1150 dwc->priority = pdata->nr_channels - i - 1; in do_dma_probe()
1152 dwc->priority = i; in do_dma_probe()
1154 dwc->ch_regs = &__dw_regs(dw)->CHAN[i]; in do_dma_probe()
1155 spin_lock_init(&dwc->lock); in do_dma_probe()
1156 dwc->mask = 1 << i; in do_dma_probe()
1158 INIT_LIST_HEAD(&dwc->active_list); in do_dma_probe()
1159 INIT_LIST_HEAD(&dwc->queue); in do_dma_probe()
1161 channel_clear_bit(dw, CH_EN, dwc->mask); in do_dma_probe()
1163 dwc->direction = DMA_TRANS_NONE; in do_dma_probe()
1179 dwc->block_size = in do_dma_probe()
1181 dwc->nollp = in do_dma_probe()
1184 dwc->block_size = pdata->block_size; in do_dma_probe()
1185 dwc->nollp = !pdata->multi_block[i]; in do_dma_probe()
1244 struct dw_dma_chan *dwc, *_dwc; in do_dma_remove() local
1254 list_for_each_entry_safe(dwc, _dwc, &dw->dma.channels, in do_dma_remove()
1256 list_del(&dwc->chan.device_node); in do_dma_remove()
1257 channel_clear_bit(dw, CH_EN, dwc->mask); in do_dma_remove()