Patchwork [U-Boot,U-boot,v3,1/3] mtd: nand: davinci: allow to change ecclayout by ecclayout command

login
register
mail settings
Submitter Khoronzhuk, Ivan
Date June 24, 2014, 1:49 p.m.
Message ID <1403617746-25024-2-git-send-email-ivan.khoronzhuk@ti.com>
Download mbox | patch
Permalink /patch/363464/
State Superseded
Delegated to: Tom Rini
Headers show

Comments

Khoronzhuk, Ivan - June 24, 2014, 1:49 p.m.
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>
---
 arch/arm/include/asm/ti-common/davinci_nand.h |  4 ++
 drivers/mtd/nand/davinci_nand.c               | 94 +++++++++++++++++++++++++++
 2 files changed, 98 insertions(+)
Tom Rini - Aug. 25, 2014, 7:14 p.m.
On Tue, Jun 24, 2014 at 04:49:04PM +0300, Khoronzhuk, Ivan wrote:

> 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>

Applied to u-boot-ti/master, thanks!
Khoronzhuk, Ivan - Aug. 25, 2014, 9:21 p.m.
On 08/25/2014 10:14 PM, Tom Rini wrote:
> On Tue, Jun 24, 2014 at 04:49:04PM +0300, Khoronzhuk, Ivan wrote:
>
>> 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>
> Applied to u-boot-ti/master, thanks!
>

Sorry Tom, but the subj patch as
entire "[U-boot] [Patch v3 0/3] keystone: nand: add additional nand 
ecclayout" series
was completely replaced by "[U-boot] [Patch 0/3] Add support for NAND 
U-boot image upgrade" series
(http://lists.denx.de/pipermail/u-boot/2014-July/182956.html)
which has been applied already.

Hence, this patch as all patches from this series would be better to 
remove...

Once again sorry. I should specify here about this.

Patch

diff --git a/arch/arm/include/asm/ti-common/davinci_nand.h b/arch/arm/include/asm/ti-common/davinci_nand.h
index 11407be..bb3ed94 100644
--- a/arch/arm/include/asm/ti-common/davinci_nand.h
+++ b/arch/arm/include/asm/ti-common/davinci_nand.h
@@ -93,6 +93,10 @@  struct davinci_emif_regs {
 #define DAVINCI_ABCR_ASIZE_16BIT			1
 #define DAVINCI_ABCR_ASIZE_8BIT				0
 
+/* Layouts */
+#define NAND_DAVINCI_4BIT_LAYOUT			0
+#define NAND_KEYSTONE_RBL_4BIT_LAYOUT			1
+
 void davinci_nand_init(struct nand_chip *nand);
 
 #endif
diff --git a/drivers/mtd/nand/davinci_nand.c b/drivers/mtd/nand/davinci_nand.c
index 5d42509..7a84047 100644
--- a/drivers/mtd/nand/davinci_nand.c
+++ b/drivers/mtd/nand/davinci_nand.c
@@ -305,6 +305,100 @@  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
+
+struct nand_ecclayout *davinci_nand_ecclayouts[] = {
+	&nand_davinci_4bit_layout_oobfirst,
+	&nand_keystone_rbl_4bit_layout_oobfirst,
+};
+
+int board_nand_get_ecclayout_idx(struct nand_chip *nand,
+				 struct nand_ecclayout *layout)
+{
+	int i;
+
+	if (!layout)
+		return -1;
+
+	for (i = 0; i < ARRAY_SIZE(davinci_nand_ecclayouts); i++)
+		if (davinci_nand_ecclayouts[i] == layout)
+			return i;
+
+	return -1;
+}
+
+struct nand_ecclayout *board_nand_get_ecclayout(int idx)
+{
+	if ((idx >= 0) && (idx < ARRAY_SIZE(davinci_nand_ecclayouts)))
+		return davinci_nand_ecclayouts[idx];
+	else
+		return NULL;
+}
+
+int board_nand_set_ecclayout(struct mtd_info *mtd, int idx)
+{
+	int i;
+	struct nand_ecclayout *layout;
+	struct nand_chip *nand = mtd->priv;
+
+	if (idx < 0 || idx >= ARRAY_SIZE(davinci_nand_ecclayouts))
+		return -1;
+
+	layout = davinci_nand_ecclayouts[idx];
+
+	layout->oobavail = 0;
+	for (i = 0; layout->oobfree[i].length &&
+	     i < ARRAY_SIZE(layout->oobfree); i++)
+		layout->oobavail += layout->oobfree[i].length;
+
+	mtd->oobavail = layout->oobavail;
+	nand->ecc.layout = layout;
+
+	return 0;
+}
+#endif /* CONFIG_CMD_NAND_ECCLAYOUT */
+
 static void nand_davinci_4bit_enable_hwecc(struct mtd_info *mtd, int mode)
 {
 	u32 val;