ipq: more v4.9 fixes
[openwrt/staging/blogic.git] / target / linux / ipq806x / patches-4.9 / 0047-mtd-nand-Create-a-BBT-flag-to-access-bad-block-marke.patch
1 From c7c6a0f50f9ac3620c611ce06ba1f9fafea0444e Mon Sep 17 00:00:00 2001
2 From: Archit Taneja <architt@codeaurora.org>
3 Date: Mon, 3 Aug 2015 10:38:14 +0530
4 Subject: [PATCH 47/69] mtd: nand: Create a BBT flag to access bad block
5 markers in raw mode
6
7 Some controllers can access the factory bad block marker from OOB only
8 when they read it in raw mode. When ECC is enabled, these controllers
9 discard reading/writing bad block markers, preventing access to them
10 altogether.
11
12 The bbt driver assumes MTD_OPS_PLACE_OOB when scanning for bad blocks.
13 This results in the nand driver's ecc->read_oob() op to be called, which
14 works with ECC enabled.
15
16 Create a new BBT option flag that tells nand_bbt to force the mode to
17 MTD_OPS_RAW. This would result in the correct op being called for the
18 underlying nand controller driver.
19
20 Reviewed-by: Andy Gross <agross@codeaurora.org>
21 Signed-off-by: Archit Taneja <architt@codeaurora.org>
22 ---
23 drivers/mtd/nand/nand_base.c | 6 +++++-
24 drivers/mtd/nand/nand_bbt.c | 6 +++++-
25 include/linux/mtd/bbm.h | 6 ++++++
26 3 files changed, 16 insertions(+), 2 deletions(-)
27
28 diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
29 index 3bde96a3f7bf..23d6f8de525a 100644
30 --- a/drivers/mtd/nand/nand_base.c
31 +++ b/drivers/mtd/nand/nand_base.c
32 @@ -414,7 +414,11 @@ static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)
33 } else {
34 ops.len = ops.ooblen = 1;
35 }
36 - ops.mode = MTD_OPS_PLACE_OOB;
37 +
38 + if (unlikely(chip->bbt_options & NAND_BBT_ACCESS_BBM_RAW))
39 + ops.mode = MTD_OPS_RAW;
40 + else
41 + ops.mode = MTD_OPS_PLACE_OOB;
42
43 /* Write to first/last page(s) if necessary */
44 if (chip->bbt_options & NAND_BBT_SCANLASTPAGE)
45 diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c
46 index 7695efea65f2..8f95b8222614 100644
47 --- a/drivers/mtd/nand/nand_bbt.c
48 +++ b/drivers/mtd/nand/nand_bbt.c
49 @@ -420,7 +420,11 @@ static int scan_block_fast(struct mtd_info *mtd, struct nand_bbt_descr *bd,
50 ops.oobbuf = buf;
51 ops.ooboffs = 0;
52 ops.datbuf = NULL;
53 - ops.mode = MTD_OPS_PLACE_OOB;
54 +
55 + if (unlikely(bd->options & NAND_BBT_ACCESS_BBM_RAW))
56 + ops.mode = MTD_OPS_RAW;
57 + else
58 + ops.mode = MTD_OPS_PLACE_OOB;
59
60 for (j = 0; j < numpages; j++) {
61 /*
62 diff --git a/include/linux/mtd/bbm.h b/include/linux/mtd/bbm.h
63 index 3bf8f954b642..7460b57c90f5 100644
64 --- a/include/linux/mtd/bbm.h
65 +++ b/include/linux/mtd/bbm.h
66 @@ -116,6 +116,12 @@ struct nand_bbt_descr {
67 #define NAND_BBT_NO_OOB_BBM 0x00080000
68
69 /*
70 + * Force MTD_OPS_RAW mode when trying to access bad block markes from OOB. To
71 + * be used by controllers which can access BBM only when ECC is disabled, i.e,
72 + * when in RAW access mode
73 + */
74 +#define NAND_BBT_ACCESS_BBM_RAW 0x00100000
75 +/*
76 * Flag set by nand_create_default_bbt_descr(), marking that the nand_bbt_descr
77 * was allocated dynamicaly and must be freed in nand_release(). Has no meaning
78 * in nand_chip.bbt_options.
79 --
80 2.11.0
81