mvebu: refresh 3.18 patches
[15.05/openwrt.git] / target / linux / mvebu / patches-3.18 / 019-mtd-nand-pxa3xx-Fix-PIO-FIFO-draining.patch
1 From 11aa9df4de06cc257327d783c5cb615989e87286 Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime.ripard@free-electrons.com>
3 Date: Fri, 23 Jan 2015 15:18:27 +0100
4 Subject: [PATCH v2 1/2] mtd: nand: pxa3xx: Fix PIO FIFO draining
5
6 The NDDB register holds the data that are needed by the read and write
7 commands.
8
9 However, during a read PIO access, the datasheet specifies that after each 32
10 bits read in that register, when BCH is enabled, we have to make sure that the
11 RDDREQ bit is set in the NDSR register.
12
13 This fixes an issue that was seen on the Armada 385, and presumably other mvebu
14 SoCs, when a read on a newly erased page would end up in the driver reporting a
15 timeout from the NAND.
16
17 Cc: <stable@vger.kernel.org> # v3.14
18 Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
19 ---
20  drivers/mtd/nand/pxa3xx_nand.c | 45 ++++++++++++++++++++++++++++++++++++------
21  1 file changed, 39 insertions(+), 6 deletions(-)
22
23 --- a/drivers/mtd/nand/pxa3xx_nand.c
24 +++ b/drivers/mtd/nand/pxa3xx_nand.c
25 @@ -23,6 +23,7 @@
26  #include <linux/mtd/partitions.h>
27  #include <linux/io.h>
28  #include <linux/irq.h>
29 +#include <linux/jiffies.h>
30  #include <linux/slab.h>
31  #include <linux/of.h>
32  #include <linux/of_device.h>
33 @@ -480,6 +481,38 @@ static void disable_int(struct pxa3xx_na
34         nand_writel(info, NDCR, ndcr | int_mask);
35  }
36  
37 +static void drain_fifo(struct pxa3xx_nand_info *info, void *data, int len)
38 +{
39 +       u32 *dst = (u32 *)data;
40 +
41 +       if (info->ecc_bch) {
42 +               while (len--) {
43 +                       u32 timeout;
44 +
45 +                       *dst++ = nand_readl(info, NDDB);
46 +
47 +                       /*
48 +                        * According to the datasheet, when reading
49 +                        * from NDDB with BCH enabled, after each 32
50 +                        * bits reads, we have to make sure that the
51 +                        * NDSR.RDDREQ bit is set
52 +                        */
53 +                       timeout = jiffies + msecs_to_jiffies(5);
54 +                       while (!(nand_readl(info, NDSR) & NDSR_RDDREQ)) {
55 +                               if (!time_before(jiffies, timeout)) {
56 +                                       dev_err(&info->pdev->dev,
57 +                                               "Timeout on RDDREQ while draining the FIFO\n");
58 +                                       return;
59 +                               }
60 +
61 +                               cpu_relax();
62 +                       }
63 +               }
64 +       } else {
65 +               __raw_readsl(info->mmio_base + NDDB, data, len);
66 +       }
67 +}
68 +
69  static void handle_data_pio(struct pxa3xx_nand_info *info)
70  {
71         unsigned int do_bytes = min(info->data_size, info->chunk_size);
72 @@ -496,14 +529,14 @@ static void handle_data_pio(struct pxa3x
73                                       DIV_ROUND_UP(info->oob_size, 4));
74                 break;
75         case STATE_PIO_READING:
76 -               __raw_readsl(info->mmio_base + NDDB,
77 -                            info->data_buff + info->data_buff_pos,
78 -                            DIV_ROUND_UP(do_bytes, 4));
79 +               drain_fifo(info,
80 +                          info->data_buff + info->data_buff_pos,
81 +                          DIV_ROUND_UP(do_bytes, 4));
82  
83                 if (info->oob_size > 0)
84 -                       __raw_readsl(info->mmio_base + NDDB,
85 -                                    info->oob_buff + info->oob_buff_pos,
86 -                                    DIV_ROUND_UP(info->oob_size, 4));
87 +                       drain_fifo(info,
88 +                                  info->oob_buff + info->oob_buff_pos,
89 +                                  DIV_ROUND_UP(info->oob_size, 4));
90                 break;
91         default:
92                 dev_err(&info->pdev->dev, "%s: invalid state %d\n", __func__,