Skip to contentSkip to conversation

mtd: nand: fsmc: Add BCH4 SW ECC support for SPEAr600

PATCH New Stefan Roese 3 participants 9 messages Sep 2, 2015 – Sep 12, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/4 mtd: nand: fsmc: Add BCH4 SW ECC support for SPEAr600

This patch adds support for 4-bit ECC BCH4 for the SPEAr600 SoC. This can be used by boards equipped with a NAND chip that requires 4-bit ECC strength. The SPEAr600 HW ECC only supports 1-bit ECC strength.

To enable SW BCH4, you need to specify this in your config header:

And use the command "nandecc bch4" to select this ECC scheme upon runtime.

Tested on SPEAr600 x600 board.

Cc Scott Wood <[email protected]>
Cc Viresh Kumar <[email protected]>
---
 drivers/mtd/nand/fsmc_nand.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
drivers/mtd/nand/fsmc_nand.c +40 -0
index 567eff0..19f5526 100644
@@ -13,6 +13,7 @@
 #include <asm/io.h>
 #include <linux/bitops.h>
 #include <linux/err.h>
+#include <linux/mtd/nand_bch.h>
 #include <linux/mtd/nand_ecc.h>
 #include <linux/mtd/fsmc_nand.h>
 #include <asm/arch/hardware.h>
@@ -390,6 +391,45 @@ static int fsmc_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
 	return 0;
 }
 
+#ifndef CONFIG_SPL_BUILD
+/*
+ * fsmc_nand_switch_ecc - switch the ECC operation between different engines
+ *
+ * @eccstrength		- the number of bits that could be corrected
+ *			  (1 - HW, 4 - SW BCH4)
+ */
+int __maybe_unused fsmc_nand_switch_ecc(uint32_t eccstrength)
+{
+	struct nand_chip *nand;
+	struct mtd_info *mtd;
+	int err = 0;
+
+	mtd = &nand_info[nand_curr_device];
+	nand = mtd->priv;
+
+	/* Setup the ecc configurations again */
+	if (eccstrength == 1) {
+		nand->ecc.mode = NAND_ECC_HW;
+		nand->ecc.bytes = 3;
+		nand->ecc.strength = 1;
+		nand->ecc.layout = &fsmc_ecc1_layout;
+		nand->ecc.correct = nand_correct_data;
+	} else {
+		nand->ecc.mode = NAND_ECC_SOFT_BCH;
+		nand->ecc.calculate = nand_bch_calculate_ecc;
+		nand->ecc.correct = nand_bch_correct_data;
+		nand->ecc.bytes = 7;
+		nand->ecc.strength = 4;
+		nand->ecc.layout = NULL;
+	}
+
+	/* Update NAND handling after ECC mode switch */
+	err = nand_scan_tail(mtd);
+
+	return err;
+}
+#endif /* CONFIG_SPL_BUILD */
+
 int fsmc_nand_init(struct nand_chip *nand)
 {
 	static int chip_nr;
Signature · 1 line
2.5.1
#1 lore raw

PATCH 2/4 arm: spear: Add command to switch between 1-bit HW ECC and SW BCH4

This patch adds the "nandecc" command to switch between the SPEAr600 internal 1-bit HW ECC and the 4-bit SW BCH4 ECC. This can be needed to support NAND chips with a stronger ECC than 1-bit, as on the x600. And to dynamically switch between both ECC schemes for backwards compatibility.

---
 arch/arm/cpu/arm926ejs/spear/cpu.c         | 34 ++++++++++++++++++++++++++++++
 arch/arm/include/asm/arch-spear/spr_misc.h |  1 +
 2 files changed, 35 insertions(+)
arch/arm/cpu/arm926ejs/spear/cpu.c +34 -0
index e39cdba..be0d14f 100644
@@ -83,3 +83,37 @@ int print_cpuinfo(void)
 	return 0;
 }
 #endif
+
+#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_NAND_ECC_BCH)
+static int do_switch_ecc(cmd_tbl_t *cmdtp, int flag, int argc,
+			 char *const argv[])
+{
+	if (argc != 2)
+		goto usage;
+
+	if (strncmp(argv[1], "hw", 2) == 0) {
+		/* 1-bit HW ECC */
+		printf("Switching to 1-bit HW ECC\n");
+		fsmc_nand_switch_ecc(1);
+	} else if (strncmp(argv[1], "bch4", 2) == 0) {
+		/* 4-bit SW ECC BCH4 */
+		printf("Switching to 4-bit SW ECC (BCH4)\n");
+		fsmc_nand_switch_ecc(4);
+	} else {
+		goto usage;
+	}
+
+	return 0;
+
+usage:
+	printf("Usage: nandecc %s\n", cmdtp->usage);
+	return 1;
+}
+
+U_BOOT_CMD(
+	nandecc, 2, 0,	do_switch_ecc,
+	"switch NAND ECC calculation algorithm",
+	"hw|bch4 - Switch between NAND hardware 1-bit HW and"
+	" 4-bit SW BCH\n"
+);
+#endif
arch/arm/include/asm/arch-spear/spr_misc.h +1 -0
index b55026e..6f2e19e 100644
@@ -253,5 +253,6 @@ struct misc_regs {
 #define SOC_SPEAR320		203
 
 extern int get_socrev(void);
+int fsmc_nand_switch_ecc(uint32_t eccstrength);
 
 #endif
Signature · 1 line
2.5.1
#2 lore raw

PATCH 2/4 arm: spear: Add command to switch between 1-bit HW ECC and SW BCH4

Quoted 11 lines · Stefan Roese

This patch adds the "nandecc" command to switch between the SPEAr600 internal 1-bit HW ECC and the 4-bit SW BCH4 ECC. This can be needed to support NAND chips with a stronger ECC than 1-bit, as on the x600. And to dynamically switch between both ECC schemes for backwards compatibility.

---
 arch/arm/cpu/arm926ejs/spear/cpu.c         | 34 ++++++++++++++++++++++++++++++
 arch/arm/include/asm/arch-spear/spr_misc.h |  1 +
 2 files changed, 35 insertions(+)

For [2-4]/4:

Signature · 1 line
viresh
#3 lore raw

PATCH 2/4 arm: spear: Add command to switch between 1-bit HW ECC and SW BCH4

In reply to Stefan Roese
Quoted 8 lines · Stefan Roese

This patch adds the "nandecc" command to switch between the SPEAr600 internal 1-bit HW ECC and the 4-bit SW BCH4 ECC. This can be needed to support NAND chips with a stronger ECC than 1-bit, as on the x600. And to dynamically switch between both ECC schemes for backwards compatibility.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150912/c994b4b7/attachment.sig>
#4 lore raw

PATCH 3/4 arm: spear: Add BCH4 SW support to SPEAr600 x600 board

In reply to Stefan Roese

This board is equipped with a Micron NAND chip (MT29F1G08ABADAH4) that needs 4-bit ECC. But the SPEAr600 only supports 1-bit HW ECC internally. This patch enables the SW 4-bit BCH support for this board.

---
 include/configs/x600.h | 2 ++
 1 file changed, 2 insertions(+)
include/configs/x600.h +2 -0
index 6a57388..f672485 100644
@@ -67,6 +67,8 @@
 #define CONFIG_MTD_ECC_SOFT
 #define CONFIG_SYS_FSMC_NAND_8BIT
 #define CONFIG_SYS_NAND_ONFI_DETECTION
+#define CONFIG_NAND_ECC_BCH
+#define CONFIG_BCH
 
 /* UBI/UBI config options */
 #define CONFIG_MTD_DEVICE
Signature · 1 line
2.5.1
#5 lore raw

PATCH 3/4 arm: spear: Add BCH4 SW support to SPEAr600 x600 board

Quoted 6 lines · Stefan Roese

This board is equipped with a Micron NAND chip (MT29F1G08ABADAH4) that needs 4-bit ECC. But the SPEAr600 only supports 1-bit HW ECC internally. This patch enables the SW 4-bit BCH support for this board.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150912/c9b8f7e4/attachment.sig>
#6 lore raw

PATCH 4/4 arm: spear: Enable THUMB mode on x600 board

In reply to Stefan Roese

To reduce the size of the U-Boot image on the x600 board, lets enable the THUMB mode. This reduces the overall size to less than 0x6000 bytes. Fitting it again in the onboard NOR flash.

---
 include/configs/x600.h | 1 +
 1 file changed, 1 insertion(+)
include/configs/x600.h +1 -0
index f672485..73ba67c 100644
@@ -17,6 +17,7 @@
 #define CONFIG_SPEAR600				/* SPEAr600 SoC */
 #define CONFIG_X600				/* on X600 board */
 #define CONFIG_SYS_GENERIC_BOARD
+#define CONFIG_SYS_THUMB_BUILD
 
 #include <asm/arch/hardware.h>
 
Signature · 1 line
2.5.1
#7 lore raw

PATCH 4/4 arm: spear: Enable THUMB mode on x600 board

Quoted 6 lines · Stefan Roese

To reduce the size of the U-Boot image on the x600 board, lets enable the THUMB mode. This reduces the overall size to less than 0x6000 bytes. Fitting it again in the onboard NOR flash.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150912/b250a4a6/attachment.sig>
#8 lore raw

PATCH 1/4 mtd: nand: fsmc: Add BCH4 SW ECC support for SPEAr600

In reply to Stefan Roese
Quoted 35 lines · Stefan Roese

This patch adds support for 4-bit ECC BCH4 for the SPEAr600 SoC. This can be used by boards equipped with a NAND chip that requires 4-bit ECC strength. The SPEAr600 HW ECC only supports 1-bit ECC strength.

To enable SW BCH4, you need to specify this in your config header:

And use the command "nandecc bch4" to select this ECC scheme upon runtime.

Tested on SPEAr600 x600 board.

Cc Scott Wood <[email protected]>
Cc Viresh Kumar <[email protected]>
---
 drivers/mtd/nand/fsmc_nand.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
drivers/mtd/nand/fsmc_nand.c +3 -0
index 567eff0..19f5526 100644
@@ -13,6 +13,7 @@
 #include <asm/io.h>
 #include <linux/bitops.h>
 #include <linux/err.h>
+#include <linux/mtd/nand_bch.h>
 #include <linux/mtd/nand_ecc.h>
 #include <linux/mtd/fsmc_nand.h>
 #include <asm/arch/hardware.h>
@@ -390,6 +391,45 @@ static int fsmc_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
 	return 0;
 }
 
+#ifndef CONFIG_SPL_BUILD
+/*

drivers/mtd/nand/fsmc_nand.c static int fsmc_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip, · line 405

Quoted 10 lines
drivers/mtd/nand/fsmc_nand.c +10 -0
+ * fsmc_nand_switch_ecc - switch the ECC operation between different engines
+ *
+ * @eccstrength		- the number of bits that could be corrected
+ *			  (1 - HW, 4 - SW BCH4)
+ */
+int __maybe_unused fsmc_nand_switch_ecc(uint32_t eccstrength)
+{
+	struct nand_chip *nand;
+	struct mtd_info *mtd;
+	int err = 0;

You don't have to initialize it.

Quoted 20 lines
drivers/mtd/nand/fsmc_nand.c +20 -0
+
+	mtd = &nand_info[nand_curr_device];
+	nand = mtd->priv;
+
+	/* Setup the ecc configurations again */
+	if (eccstrength == 1) {
+		nand->ecc.mode = NAND_ECC_HW;
+		nand->ecc.bytes = 3;
+		nand->ecc.strength = 1;
+		nand->ecc.layout = &fsmc_ecc1_layout;
+		nand->ecc.correct = nand_correct_data;
+	} else {
+		nand->ecc.mode = NAND_ECC_SOFT_BCH;
+		nand->ecc.calculate = nand_bch_calculate_ecc;
+		nand->ecc.correct = nand_bch_correct_data;
+		nand->ecc.bytes = 7;
+		nand->ecc.strength = 4;
+		nand->ecc.layout = NULL;
+	}
+

drivers/mtd/nand/fsmc_nand.c static int fsmc_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip, · line 435

Quoted 10 lines
drivers/mtd/nand/fsmc_nand.c +7 -0
+	/* Update NAND handling after ECC mode switch */
+	err = nand_scan_tail(mtd);
+
+	return err;
+}
+#endif /* CONFIG_SPL_BUILD */
+
 int fsmc_nand_init(struct nand_chip *nand)
 {
 	static int chip_nr;

Other than that:

Signature · 1 line
viresh