0039962481f82430afd7697ca5c9338b9e24d17b
[librecmc/librecmc.git] / target / linux / ipq806x / patches-4.4 / 714-spi-qup-properly-detect-extra-interrupts.patch
1 From b69e5e855aaae2dd9f7fc6f4a40af8e6e0cf98ee Mon Sep 17 00:00:00 2001
2 From: Matthew McClintock <mmcclint@codeaurora.org>
3 Date: Thu, 10 Mar 2016 16:44:55 -0600
4 Subject: [PATCH] spi: qup: properly detect extra interrupts
5
6 It's possible for a SPI transaction to complete and get another
7 interrupt and have it processed on the same spi_transfer before the
8 transfer_one can set it to NULL.
9
10 This masks unexpected interrupts, so let's set the spi_transfer to
11 NULL in the interrupt once the transaction is done. So we can
12 properly detect these bad interrupts and print warning messages.
13
14 Change-Id: I0e70ed59fb50e5c48a72a38f74bd178b17c9f24d
15 Signed-off-by: Matthew McClintock <mmcclint@codeaurora.org>
16 ---
17  drivers/spi/spi-qup.c | 15 +++++++++------
18  1 file changed, 9 insertions(+), 6 deletions(-)
19
20 --- a/drivers/spi/spi-qup.c
21 +++ b/drivers/spi/spi-qup.c
22 @@ -509,6 +509,7 @@ static irqreturn_t spi_qup_qup_irq(int i
23         u32 opflags, qup_err, spi_err;
24         unsigned long flags;
25         int error = 0;
26 +       bool done = 0;
27  
28         spin_lock_irqsave(&controller->lock, flags);
29         xfer = controller->xfer;
30 @@ -567,16 +568,19 @@ static irqreturn_t spi_qup_qup_irq(int i
31                         spi_qup_write(controller, xfer);
32         }
33  
34 -       spin_lock_irqsave(&controller->lock, flags);
35 -       controller->error = error;
36 -       controller->xfer = xfer;
37 -       spin_unlock_irqrestore(&controller->lock, flags);
38 -
39         /* re-read opflags as flags may have changed due to actions above */
40         opflags = readl_relaxed(controller->base + QUP_OPERATIONAL);
41  
42         if ((controller->rx_bytes == xfer->len &&
43                 (opflags & QUP_OP_MAX_INPUT_DONE_FLAG)) ||  error)
44 +               done = true;
45 +
46 +       spin_lock_irqsave(&controller->lock, flags);
47 +       controller->error = error;
48 +       controller->xfer = done ? NULL : xfer;
49 +       spin_unlock_irqrestore(&controller->lock, flags);
50 +
51 +       if (done)
52                 complete(&controller->done);
53  
54         return IRQ_HANDLED;
55 @@ -769,7 +773,6 @@ static int spi_qup_transfer_one(struct s
56  exit:
57         spi_qup_set_state(controller, QUP_STATE_RESET);
58         spin_lock_irqsave(&controller->lock, flags);
59 -       controller->xfer = NULL;
60         if (!ret)
61                 ret = controller->error;
62         spin_unlock_irqrestore(&controller->lock, flags);