brcm2708: update linux 4.4 patches to latest version
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-4.4 / 0408-dmaengine-bcm2835-Fix-polling-for-completion-of-DMA-.patch
1 From 467c8219ee56e75ab53f29b569f9fb5d033f57d4 Mon Sep 17 00:00:00 2001
2 From: Eric Anholt <eric@anholt.net>
3 Date: Fri, 3 Jun 2016 19:29:11 -0700
4 Subject: [PATCH 408/423] dmaengine: bcm2835: Fix polling for completion of DMA
5 with interrupts masked.
6
7 The tx_status hook is supposed to be safe to call from interrupt
8 context, but it wouldn't ever return completion for the last transfer,
9 meaning you couldn't poll for DMA completion with interrupts masked.
10
11 This fixes IRQ handling for bcm2835's DSI1, which requires using the
12 DMA engine to write its registers due to a bug in the AXI bridge.
13
14 Signed-off-by: Eric Anholt <eric@anholt.net>
15 ---
16 drivers/dma/bcm2835-dma.c | 24 +++++++++++++++++++-----
17 1 file changed, 19 insertions(+), 5 deletions(-)
18
19 --- a/drivers/dma/bcm2835-dma.c
20 +++ b/drivers/dma/bcm2835-dma.c
21 @@ -588,16 +588,16 @@ static enum dma_status bcm2835_dma_tx_st
22 struct virt_dma_desc *vd;
23 enum dma_status ret;
24 unsigned long flags;
25 + u32 residue;
26
27 ret = dma_cookie_status(chan, cookie, txstate);
28 - if (ret == DMA_COMPLETE || !txstate)
29 + if (ret == DMA_COMPLETE)
30 return ret;
31
32 spin_lock_irqsave(&c->vc.lock, flags);
33 vd = vchan_find_desc(&c->vc, cookie);
34 if (vd) {
35 - txstate->residue =
36 - bcm2835_dma_desc_size(to_bcm2835_dma_desc(&vd->tx));
37 + residue = bcm2835_dma_desc_size(to_bcm2835_dma_desc(&vd->tx));
38 } else if (c->desc && c->desc->vd.tx.cookie == cookie) {
39 struct bcm2835_desc *d = c->desc;
40 dma_addr_t pos;
41 @@ -609,11 +609,25 @@ static enum dma_status bcm2835_dma_tx_st
42 else
43 pos = 0;
44
45 - txstate->residue = bcm2835_dma_desc_size_pos(d, pos);
46 + residue = bcm2835_dma_desc_size_pos(d, pos);
47 +
48 + /*
49 + * If our non-cyclic transfer is done, then report
50 + * complete and trigger the next tx now. This lets
51 + * the dmaengine API be used synchronously from an IRQ
52 + * handler.
53 + */
54 + if (!d->cyclic && residue == 0) {
55 + vchan_cookie_complete(&c->desc->vd);
56 + bcm2835_dma_start_desc(c);
57 + ret = dma_cookie_status(chan, cookie, txstate);
58 + }
59 } else {
60 - txstate->residue = 0;
61 + residue = 0;
62 }
63
64 + dma_set_residue(txstate, residue);
65 +
66 spin_unlock_irqrestore(&c->vc.lock, flags);
67
68 return ret;