mvebu: Enable the A385 AP on 3.19
[openwrt/svn-archive/archive.git] / target / linux / mvebu / patches-3.19 / 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 diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
24 index 96b0b1d27df1..e6918befb951 100644
25 --- a/drivers/mtd/nand/pxa3xx_nand.c
26 +++ b/drivers/mtd/nand/pxa3xx_nand.c
27 @@ -23,6 +23,7 @@
28 #include <linux/mtd/partitions.h>
29 #include <linux/io.h>
30 #include <linux/irq.h>
31 +#include <linux/jiffies.h>
32 #include <linux/slab.h>
33 #include <linux/of.h>
34 #include <linux/of_device.h>
35 @@ -480,6 +481,38 @@ static void disable_int(struct pxa3xx_nand_info *info, uint32_t int_mask)
36 nand_writel(info, NDCR, ndcr | int_mask);
37 }
38
39 +static void drain_fifo(struct pxa3xx_nand_info *info, void *data, int len)
40 +{
41 + u32 *dst = (u32 *)data;
42 +
43 + if (info->ecc_bch) {
44 + while (len--) {
45 + u32 timeout;
46 +
47 + *dst++ = nand_readl(info, NDDB);
48 +
49 + /*
50 + * According to the datasheet, when reading
51 + * from NDDB with BCH enabled, after each 32
52 + * bits reads, we have to make sure that the
53 + * NDSR.RDDREQ bit is set
54 + */
55 + timeout = jiffies + msecs_to_jiffies(5);
56 + while (!(nand_readl(info, NDSR) & NDSR_RDDREQ)) {
57 + if (!time_before(jiffies, timeout)) {
58 + dev_err(&info->pdev->dev,
59 + "Timeout on RDDREQ while draining the FIFO\n");
60 + return;
61 + }
62 +
63 + cpu_relax();
64 + }
65 + }
66 + } else {
67 + __raw_readsl(info->mmio_base + NDDB, data, len);
68 + }
69 +}
70 +
71 static void handle_data_pio(struct pxa3xx_nand_info *info)
72 {
73 unsigned int do_bytes = min(info->data_size, info->chunk_size);
74 @@ -496,14 +529,14 @@ static void handle_data_pio(struct pxa3xx_nand_info *info)
75 DIV_ROUND_UP(info->oob_size, 4));
76 break;
77 case STATE_PIO_READING:
78 - __raw_readsl(info->mmio_base + NDDB,
79 - info->data_buff + info->data_buff_pos,
80 - DIV_ROUND_UP(do_bytes, 4));
81 + drain_fifo(info,
82 + info->data_buff + info->data_buff_pos,
83 + DIV_ROUND_UP(do_bytes, 4));
84
85 if (info->oob_size > 0)
86 - __raw_readsl(info->mmio_base + NDDB,
87 - info->oob_buff + info->oob_buff_pos,
88 - DIV_ROUND_UP(info->oob_size, 4));
89 + drain_fifo(info,
90 + info->oob_buff + info->oob_buff_pos,
91 + DIV_ROUND_UP(info->oob_size, 4));
92 break;
93 default:
94 dev_err(&info->pdev->dev, "%s: invalid state %d\n", __func__,
95 --
96 2.2.2
97