
From: WingMan Kwok w-kwok2@ti.com
This patch adds opportunity to change ecclayout of current nand device during runtime. So we can change the current nand device ecclayout using the "nand ecclayout set" command before writing the data to nand flash.
Signed-off-by: Hao Zhang hzhang@ti.com Signed-off-by: WingMan Kwok w-kwok2@ti.com Signed-off-by: Ivan Khoronzhuk ivan.khoronzhuk@ti.com --- drivers/mtd/nand/davinci_nand.c | 101 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+)
diff --git a/drivers/mtd/nand/davinci_nand.c b/drivers/mtd/nand/davinci_nand.c index 75b03a7..b33de0d 100644 --- a/drivers/mtd/nand/davinci_nand.c +++ b/drivers/mtd/nand/davinci_nand.c @@ -306,6 +306,103 @@ static struct nand_ecclayout nand_davinci_4bit_layout_oobfirst = { #endif };
+#if defined(CONFIG_CMD_NAND_ECCLAYOUT) +#if defined(CONFIG_SYS_NAND_PAGE_2K) +static struct nand_ecclayout nand_keystone_rbl_4bit_layout_oobfirst = { + .eccbytes = 40, + .eccpos = { + 6, 7, + 8, 9, 10, 11, 12, 13, 14, 15, + 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, + 38, 39, + 40, 41, 42, 43, 44, 45, 46, 47, + 54, 55, + 56, 57, 58, 59, 60, 61, 62, 63, + }, + .oobfree = { + {.offset = 2, .length = 4, }, + {.offset = 16, .length = 6, }, + {.offset = 32, .length = 6, }, + {.offset = 48, .length = 6, }, + }, +}; +#elif defined(CONFIG_SYS_NAND_PAGE_4K) +static struct nand_ecclayout nand_keystone_rbl_4bit_layout_oobfirst = { + .eccbytes = 80, + .eccpos = { + 6, 7, + 8, 9, 10, 11, 12, 13, 14, 15, + 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, + 38, 39, + 40, 41, 42, 43, 44, 45, 46, 47, + 54, 55, + 56, 57, 58, 59, 60, 61, 62, 63, + 70, 71, + 72, 73, 74, 75, 76, 77, 78, 79, + 86, 87, + 88, 89, 90, 91, 92, 93, 94, 95, + 102, 103, + 104, 105, 106, 107, 108, 109, 110, 111, + 118, 119, + 120, 121, 122, 123, 124, 125, 126, 127, + }, + .oobfree = { + {.offset = 2, .length = 4, }, + {.offset = 16, .length = 6, }, + {.offset = 32, .length = 6, }, + {.offset = 48, .length = 6, }, + {.offset = 64, .length = 6, }, + {.offset = 80, .length = 6, }, + {.offset = 96, .length = 6, }, + {.offset = 112, .length = 6, }, + }, +}; +#endif + +#define NAND_ECCLAYOUT_NUM 2 + +struct nand_ecclayout *davinci_nand_ecclayouts[NAND_ECCLAYOUT_NUM] = { + &nand_davinci_4bit_layout_oobfirst, + &nand_keystone_rbl_4bit_layout_oobfirst, +}; + +int board_nand_ecclayout_get_idx(struct nand_chip *nand, + struct nand_ecclayout *p) +{ + int i; + + if (!p) + return -1; + + for (i = 0; i < NAND_ECCLAYOUT_NUM; i++) + if (davinci_nand_ecclayouts[i] == p) + return i; + + return -1; +} + +struct nand_ecclayout *board_nand_ecclayout_get_layout(struct nand_chip *nand, + int idx) +{ + if ((idx >= 0) && (idx < NAND_ECCLAYOUT_NUM)) + return davinci_nand_ecclayouts[idx]; + else + return NULL; +} + +int board_nand_ecclayout_set(struct nand_chip *nand, int idx) +{ + if (idx < 0 || idx >= NAND_ECCLAYOUT_NUM) + return -1; + + nand->ecc.layout = davinci_nand_ecclayouts[idx]; + + return 0; +} +#endif + static void nand_davinci_4bit_enable_hwecc(struct mtd_info *mtd, int mode) { u32 val; @@ -631,7 +728,11 @@ void davinci_nand_init(struct nand_chip *nand) nand->ecc.calculate = nand_davinci_4bit_calculate_ecc; nand->ecc.correct = nand_davinci_4bit_correct_data; nand->ecc.hwctl = nand_davinci_4bit_enable_hwecc; +#ifndef CONFIG_CMD_NAND_ECCLAYOUT nand->ecc.layout = &nand_davinci_4bit_layout_oobfirst; +#else + nand->ecc.layout = &nand_keystone_rbl_4bit_layout_oobfirst; +#endif #endif /* Set address of hardware control function */ nand->cmd_ctrl = nand_davinci_hwcontrol;