Skip to contentSkip to conversation

mtd: nand: omap: optimize and clean-up of OMAP NAND driver

PATCH Superseded Pekon Gupta 2 participants 8 messages Aug 6, 2013 – Aug 13, 2013 2 messages not in the archive

Subsystems (2)

v1 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

cover mtd: nand: omap: optimize and clean-up of OMAP NAND driver

This series of patch series does updates H/W based ECC scheme in omap_gpmc.c
- adds scalability for higher ECC schemes in future.
- removes CONFIG_AM335x and it makes it generic for all platforms.
- optimizes read_data paths

This series is tested for H/W BCH8_ECC scheme on
- AM335x_EVM
- And plan to test it on TI814x_EVM
But is not tested for HAM1 and S/W BCH8_ECC scheme.

Pekon Gupta (4):
[PATCH 1/4] mtd: nand: omap_gpmc: enable BCH ECC scheme using ELM for generic [PATCH 2/4] mtd: nand: omap: optimize chip->ecc.hwctl() for H/W ECC schemes [PATCH 3/4] mtd: nand: omap: optimize chip->ecc.calculate() for H/W ECC schemes [PATCH 4/4] mtd: nand: omap: optimized chip->ecc.correct() for H/W ECC schemes

 drivers/mtd/nand/omap_gpmc.c | 507 +++++++++++++++----------------------------
 include/configs/am335x_evm.h |   1 +
 include/configs/ti814x_evm.h |   2 +-
 include/configs/tricorder.h  |   2 +-
 4 files changed, 175 insertions(+), 337 deletions(-)
Signature · 1 line
1.8.1
#1 lore raw

PATCH 1/4 mtd: nand: omap: enable BCH ECC scheme using ELM for generic platform

BCH8_ECC scheme implemented in omap_gpmc.c driver has following two favours

+-----------------------------------+-----------------+-----------------+
|ECC Scheme                         | ECC Calculation | Error Detection |
+-----------------------------------+-----------------+-----------------+
|OMAP_ECC_BCH8_CODE_HW              |GPMC             |ELM H/W engine   |
|OMAP_ECC_BCH8_CODE_HW_DETECTION_SW |GPMC             |S/W BCH library  |
+-----------------------------------+-----------------+-----------------+

Current implementation enables of BCH8_CODE_HW only for AM33xx SoC family. (using CONFIG_AM33XX). However, other SoC families (like TI81xx) also have ELM hardware module, and can support ECC error detection using ELM.

This patch
- replaces CONFIG_AM33xx define with generic CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW so that all device families having required h/w capability can use ELM for error detection in ECC_BCHx schemes.

- replaces CONFIG_NAND_OMAP_BCH8 with CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW_DETECTION_SW and separates out code for above mentioned BCH8_ECC implementations so that driver can be build independently using anyone of them.

---
 drivers/mtd/nand/omap_gpmc.c | 117 +++++++++++++++++++++++--------------------
 include/configs/am335x_evm.h |   1 +
 include/configs/ti814x_evm.h |   2 +-
 include/configs/tricorder.h  |   2 +-
 4 files changed, 65 insertions(+), 57 deletions(-)
drivers/mtd/nand/omap_gpmc.c +62 -55
index ec1787f..c6c5cec 100644
@@ -12,11 +12,12 @@
 #include <asm/arch/cpu.h>
 #include <asm/omap_gpmc.h>
 #include <linux/mtd/nand_ecc.h>
-#include <linux/bch.h>
 #include <linux/compiler.h>
 #include <nand.h>
-#ifdef CONFIG_AM33XX
+#if defined(CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW)
 #include <asm/arch/elm.h>
+#elif defined(CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW_DETECTION_SW)
+#include <linux/bch.h>
 #endif
 
 static uint8_t cs;
@@ -274,7 +275,7 @@ static void omap_hwecc_init_bch(struct nand_chip *chip, int32_t mode)
 {
 	uint32_t val;
 	uint32_t dev_width = (chip->options & NAND_BUSWIDTH_16) >> 1;
-#ifdef CONFIG_AM33XX
+#if defined(CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW)
 	uint32_t unused_length = 0;
 #endif
 	uint32_t wr_mode = BCH_WRAPMODE_6;
@@ -283,7 +284,7 @@ static void omap_hwecc_init_bch(struct nand_chip *chip, int32_t mode)
 	/* Clear the ecc result registers, select ecc reg as 1 */
 	writel(ECCCLEAR | ECCRESULTREG1, &gpmc_cfg->ecc_control);
 
-#ifdef CONFIG_AM33XX
+#if defined(CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW)
 	wr_mode = BCH_WRAPMODE_1;
 
 	switch (bch->nibbles) {
@@ -375,10 +376,10 @@ static void __maybe_unused omap_ecc_disable(struct mtd_info *mtd)
 	writel((readl(&gpmc_cfg->ecc_config) & ~0x1), &gpmc_cfg->ecc_config);
 }
 
+#if defined(CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW)
 /*
  * BCH8 support (needs ELM and thus AM33xx-only)
  */
-#ifdef CONFIG_AM33XX
 /*
  * omap_read_bch8_result - Read BCH result for BCH8 level
  *
@@ -631,12 +632,12 @@ static int omap_read_page_bch(struct mtd_info *mtd, struct nand_chip *chip,
 	}
 	return 0;
 }
-#endif /* CONFIG_AM33XX */
+#endif /* CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW */
 
 /*
  * OMAP3 BCH8 support (with BCH library)
  */
-#ifdef CONFIG_NAND_OMAP_BCH8
+#ifdef CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW_DETECTION_SW
 /*
  *  omap_calculate_ecc_bch - Read BCH ECC result
  *
@@ -752,7 +753,7 @@ static void __maybe_unused omap_free_bch(struct mtd_info *mtd)
 		chip_priv->control = NULL;
 	}
 }
-#endif /* CONFIG_NAND_OMAP_BCH8 */
+#endif /* CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW_DETECTION_SW */
 
 #ifndef CONFIG_SPL_BUILD
 /*
@@ -803,25 +804,32 @@ void omap_nand_switch_ecc(uint32_t hardware, uint32_t eccstrength)
 			nand->ecc.calculate = omap_calculate_ecc;
 			omap_hwecc_init(nand);
 			printf("1-bit hamming HW ECC selected\n");
-		}
-#if defined(CONFIG_AM33XX) || defined(CONFIG_NAND_OMAP_BCH8)
-		else if (eccstrength == 8) {
-			nand->ecc.mode = NAND_ECC_HW;
-			nand->ecc.layout = &hw_bch8_nand_oob;
-			nand->ecc.size = 512;
-#ifdef CONFIG_AM33XX
-			nand->ecc.bytes = 14;
-			nand->ecc.read_page = omap_read_page_bch;
+		} else if (eccstrength == 8) {
+#if defined(CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW)
+			nand->ecc.mode		= NAND_ECC_HW;
+			nand->ecc.layout	= &hw_bch8_nand_oob;
+			nand->ecc.size		= 512;
+			nand->ecc.bytes		= 14;
+			nand->ecc.read_page	= omap_read_page_bch;
+			nand->ecc.hwctl		= omap_enable_ecc_bch;
+			nand->ecc.correct	= omap_correct_data_bch;
+			nand->ecc.calculate	= omap_calculate_ecc_bch;
+			omap_hwecc_init_bch(nand, NAND_ECC_READ);
+			printf("using OMAP_ECC_BCH8_CODE_HW\n");
+#elif defined(CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW_DETECTION_SW)
+			nand->ecc.mode		= NAND_ECC_HW;
+			nand->ecc.layout	= &hw_bch8_nand_oob;
+			nand->ecc.size		= 512;
+			nand->ecc.bytes		= 13;
+			nand->ecc.hwctl		= omap_enable_ecc_bch;
+			nand->ecc.correct	= omap_correct_data_bch;
+			nand->ecc.calculate	= omap_calculate_ecc_bch;
+			omap_hwecc_init_bch(nand, NAND_ECC_READ);
+			printf("using OMAP_ECC_BCH8_CODE_HW_DETECTION_SW\n");
 #else
-			nand->ecc.bytes = 13;
+			printf("selected ECC not supported or not enabled\n");
 #endif
-			nand->ecc.hwctl = omap_enable_ecc_bch;
-			nand->ecc.correct = omap_correct_data_bch;
-			nand->ecc.calculate = omap_calculate_ecc_bch;
-			omap_hwecc_init_bch(nand, NAND_ECC_READ);
-			printf("8-bit BCH HW ECC selected\n");
 		}
-#endif
 	} else {
 		nand->ecc.mode = NAND_ECC_SOFT;
 		/* Use mtd default settings */
@@ -894,44 +902,44 @@ int board_nand_init(struct nand_chip *nand)
 
 	nand->chip_delay = 100;
 
-#if defined(CONFIG_AM33XX) || defined(CONFIG_NAND_OMAP_BCH8)
-#ifdef CONFIG_AM33XX
-	/* AM33xx uses the ELM */
-	/* required in case of BCH */
+#if defined(CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW)
+	printf("nand: using OMAP_ECC_BCH8_CODE_HW\n");
+	nand->ecc.mode		= NAND_ECC_HW;
+	nand->ecc.layout	= &hw_bch8_nand_oob;
+	nand->ecc.size		= CONFIG_SYS_NAND_ECCSIZE;
+	nand->ecc.bytes		= CONFIG_SYS_NAND_ECCBYTES;
+	nand->ecc.strength	= 8;
+	nand->ecc.hwctl		= omap_enable_ecc_bch;
+	nand->ecc.correct	= omap_correct_data_bch;
+	nand->ecc.calculate	= omap_calculate_ecc_bch;
+	nand->ecc.read_page	= omap_read_page_bch;
+	omap_hwecc_init_bch(nand, NAND_ECC_READ);
+	/* ELM is used for ECC error detection */
 	elm_init();
-#else
-	/*
-	 * Whereas other OMAP based SoC do not have the ELM, they use the BCH
-	 * SW library.
-	 */
-	bch_priv.control = init_bch(13, 8, 0x201b /* hw polynominal */);
+	nand->priv = &bch_priv;
+#elif defined(CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW_DETECTION_SW)
+	printf("nand: using OMAP_ECC_BCH8_CODE_HW_DETECTION_SW\n");
+	nand->ecc.mode		= NAND_ECC_HW;
+	nand->ecc.layout	= &hw_bch8_nand_oob;
+	nand->ecc.size		= CONFIG_SYS_NAND_ECCSIZE;
+	nand->ecc.bytes		= CONFIG_SYS_NAND_ECCBYTES;
+	nand->ecc.strength	= 8;
+	nand->ecc.hwctl		= omap_enable_ecc_bch;
+	nand->ecc.correct	= omap_correct_data_bch;
+	nand->ecc.calculate	= omap_calculate_ecc_bch;
+	omap_hwecc_init_bch(nand, NAND_ECC_READ);
+	/* BCH SW library is used for error detection */
+	bch_priv.control	= init_bch(13, 8, 0x201b /* hw polynominal */);
 	if (!bch_priv.control) {
 		puts("Could not init_bch()\n");
 		return -ENODEV;
 	}
-#endif
-	/* BCH info that will be correct for SPL or overridden otherwise. */
 	nand->priv = &bch_priv;
-#endif
-
-	/* Default ECC mode */
-#if defined(CONFIG_AM33XX) || defined(CONFIG_NAND_OMAP_BCH8)
-	nand->ecc.mode = NAND_ECC_HW;
-	nand->ecc.layout = &hw_bch8_nand_oob;
-	nand->ecc.size = CONFIG_SYS_NAND_ECCSIZE;
-	nand->ecc.bytes = CONFIG_SYS_NAND_ECCBYTES;
-	nand->ecc.strength = 8;
-	nand->ecc.hwctl = omap_enable_ecc_bch;
-	nand->ecc.correct = omap_correct_data_bch;
-	nand->ecc.calculate = omap_calculate_ecc_bch;
-#ifdef CONFIG_AM33XX
-	nand->ecc.read_page = omap_read_page_bch;
-#endif
-	omap_hwecc_init_bch(nand, NAND_ECC_READ);
-#else
-#if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_NAND_SOFTECC)
+#elif !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_NAND_SOFTECC)
+	printf("nand: using OMAP_ECC_HAM1_CODE_SW\n");
 	nand->ecc.mode = NAND_ECC_SOFT;
 #else
+	printf("nand: using OMAP_ECC_HAM1_CODE_HW\n");
 	nand->ecc.mode = NAND_ECC_HW;
 	nand->ecc.layout = &hw_nand_oob;
 	nand->ecc.size = CONFIG_SYS_NAND_ECCSIZE;
@@ -942,7 +950,6 @@ int board_nand_init(struct nand_chip *nand)
 	nand->ecc.strength = 1;
 	omap_hwecc_init(nand);
 #endif
-#endif
 
 #ifdef CONFIG_SPL_BUILD
 	if (nand->options & NAND_BUSWIDTH_16)
include/configs/am335x_evm.h +1 -0
index c5a6d4b..8f3bd54 100644
@@ -493,6 +493,7 @@
 #define CONFIG_NAND
 /* NAND support */
 #ifdef CONFIG_NAND
+#define CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW
 #define CONFIG_CMD_NAND
 #define CONFIG_CMD_MTDPARTS
 #define MTDIDS_DEFAULT			"nand0=omap2-nand.0"
include/configs/ti814x_evm.h +1 -1
index b6fafc7..546cc07 100644
@@ -286,7 +286,7 @@
 #define CONFIG_NAND
 /* NAND support */
 #ifdef CONFIG_NAND
-#define CONFIG_MTD_NAND_OMAP_BCH
+#define CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW
 #define CONFIG_CMD_NAND
 #define CONFIG_CMD_MTDPARTS
 #define MTDIDS_DEFAULT			"nand0=omap2-nand.0"
include/configs/tricorder.h +1 -1
index 4e2cb65..dc4f6dc 100644
@@ -109,7 +109,7 @@
 
 #define CONFIG_SYS_MAX_NAND_DEVICE	1		/* Max number of NAND */
 							/* devices */
-#define CONFIG_NAND_OMAP_BCH8
+#define CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW_DETECTION_SW
 #define CONFIG_BCH
 
 /* commands to include */
Signature · 1 line
1.8.1
#2 lore raw

PATCH 1/4 mtd: nand: omap: enable BCH ECC scheme using ELM for generic platform

Quoted 12 lines · Pekon Gupta

BCH8_ECC scheme implemented in omap_gpmc.c driver has following two favours

+-----------------------------------+-----------------+-----------------+
|ECC Scheme                         | ECC Calculation | Error Detection |
+-----------------------------------+-----------------+-----------------+
|OMAP_ECC_BCH8_CODE_HW              |GPMC             |ELM H/W engine   |
|OMAP_ECC_BCH8_CODE_HW_DETECTION_SW |GPMC             |S/W BCH library  |
+-----------------------------------+-----------------+-----------------+

Current implementation enables of BCH8_CODE_HW only for AM33xx SoC family. (using CONFIG_AM33XX). However, other SoC families (like TI81xx) also have ELM hardware module, and can support ECC error detection using ELM.

Quoted 8 lines

This patch
- replaces CONFIG_AM33xx define with generic CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW so that all device families having required h/w capability can use ELM for error detection in ECC_BCHx schemes.

- replaces CONFIG_NAND_OMAP_BCH8 with CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW_DETECTION_SW and separates out code for above mentioned BCH8_ECC implementations so that driver can be build independently using anyone of them.

Please document these CONFIG symbols in the README.

Is the choice of ECC mode dictated by the hardware, or is it software's choice? If the former, it should be CONFIG_SYS rather than just CONFIG.

Quoted 16 lines
---
 drivers/mtd/nand/omap_gpmc.c | 117 +++++++++++++++++++++++--------------------
 include/configs/am335x_evm.h |   1 +
 include/configs/ti814x_evm.h |   2 +-
 include/configs/tricorder.h  |   2 +-
 4 files changed, 65 insertions(+), 57 deletions(-)
drivers/mtd/nand/omap_gpmc.c +0 -0
index ec1787f..c6c5cec 100644
@@ -12,11 +12,12 @@
 #include <asm/arch/cpu.h>
 #include <asm/omap_gpmc.h>

drivers/mtd/nand/omap_gpmc.c line 21

Quoted 10 lines
drivers/mtd/nand/omap_gpmc.c +3 -2
 #include <linux/mtd/nand_ecc.h>
-#include <linux/bch.h>
 #include <linux/compiler.h>
 #include <nand.h>
-#ifdef CONFIG_AM33XX
+#if defined(CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW)
 #include <asm/arch/elm.h>
+#elif defined(CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW_DETECTION_SW)
+#include <linux/bch.h>
 #endif

Normally includes don't get ifdeffed... and what is the connection between a particular ECC mode and asm/arch/elm.h?

-Scott

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

PATCH 1/4 mtd: nand: omap: enable BCH ECC scheme using ELM for generic platform

Quoted 10 lines · Pekon

Hi,

Quoted 9 lines · Pekon Gupta
Quoted 2 lines

This patch
- replaces CONFIG_AM33xx define with generic

CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW

Quoted 4 lines

so that all device families having required h/w capability can use ELM for error detection in ECC_BCHx schemes.

- replaces CONFIG_NAND_OMAP_BCH8 with

Quoted 8 lines
Quoted 7 lines

CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW_DETECTION_SW

Quoted 1 line

and separates out code for above mentioned BCH8_ECC implementations

so that

Quoted 1 line

driver can be build independently using anyone of them.

Please document these CONFIG symbols in the README.

[Pekon]: should I add them to doc/README.nand ?

Yes.

Quoted 4 lines

Also, in broad sense these define suggest which flavor of ECC scheme to use BCH8_HW, BCH8_SW, BCH4_HW, BCH4_SW, etc..
So in-order to make them generic for use across all vendors I can rename them to CONFIG_SYS_NAND_ECC_xx (omitting OMAP in name).

I don't think this would be appropriate, especially with the "SYS" in the name. The generic approach is that this is configured at runtime. Whether a specific controller driver uses CONFIG symbols or other mechanisms to determine what sort of ECC to use is up to the controller driver (most controller drivers probably only support one type for any given type of NAND chip).

Plus, this way you only need to focus on the options that are relevant to OMAP.

Quoted 7 lines
Quoted 3 lines

Is the choice of ECC mode dictated by the hardware, or is it software's choice? If the former, it should be CONFIG_SYS rather than just CONFIG.

[Pekon] Some older OMAP device do not support ELM hardware. So in those CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW_DETECTION_SW is default. In newer devices, supporting ELM hardware CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW is default.

What does "DETECTION_SW" mean?

Quoted 5 lines
Quoted 5 lines

drivers/mtd/nand/omap_gpmc.c

Quoted 4 lines
drivers/mtd/nand/omap_gpmc.c +2 -1
-#ifdef CONFIG_AM33XX
+#if defined(CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW)
 #include <asm/arch/elm.h>
+#elif

defined(CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW_DETECTION_SW)

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

+#include <linux/bch.h>
#endif

Normally includes don't get ifdeffed... and what is the connection between a particular ECC mode and asm/arch/elm.h?

[Pekon] Both the Config do the same BCH8 ECC scheme, but implementation is different. One uses S/W library, while other uses ELM hardware engine.

Why can't you include both headers? They don't appear to be exposing the same interface...

Quoted 8 lines

- CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW_DETECTION_SW
Include API for S/W library (lib/bch.c) so included that here.. But this ECC scheme should be used only for older OMAP platforms where
ELM is not present

- CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW
Include declarations for ELM functions. So new OMAP platforms which have ELM hardware engine, need not include whole bch.c library in their code.

Maybe it should just be something like CONFIG_SYS_OMAP_ELM?

-Scott

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw

PATCH 1/4 mtd: nand: omap: enable BCH ECC scheme using ELM for generic platform

Quoted 12 lines · Pekon
Quoted 5 lines
Quoted 5 lines

- CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW_DETECTION_SW
Include API for S/W library (lib/bch.c) so included that here.. But this ECC scheme should be used only for older OMAP platforms where
ELM is not present

Quoted 7 lines
Quoted 2 lines

- CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW
Include declarations for ELM functions. So new OMAP platforms which

have

Quoted 1 line

ELM hardware engine, need not include whole bch.c library in their code.

Maybe it should just be something like CONFIG_SYS_OMAP_ELM?

Quoted 8 lines

Actually is not just decides between using ELM or not. CONFIGs also selects which all ECC scheme to support (multiple selection allowed).

Following ECC schemes can be supported on omap-nand driver..
[1] http://permalink.gmane.org/gmane.linux.ports.arm.omap/101028

So to keep code foot-print small, configs are used to select out some Un-needed ECC schemes on newer devices.

If the hardware doesn't dictate a specific choice, use CONFIG rather than CONFIG_SYS, even if not all hardware supports all options.

-Scott

#7 lore raw

PATCH 2/4 mtd: nand: omap: optimize chip->ecc.hwctl() for H/W ECC schemes

In reply to Pekon Gupta

chip->ecc.hwctl() is used for preparing the H/W controller before read/write NAND accesses (like assigning data-buf, enabling ECC scheme configs, etc.)

Though all ECC schemes in OMAP NAND driver use GPMC controller for generating ECC syndrome (for both Read/Write accesses). But but in current code HAM1_ECC and BCHx_ECC schemes implement individual function to achieve this. This patch
(1) removes omap_hwecc_init() and omap_hwecc_init_bch()
as chip->ecc.hwctl will re-initializeGPMC before every read/write call. omap_hwecc_init_bch() -> omap_enable_ecc_bch()

(2) merges the GPMC configuration code for all ECC schemes into single omap_enable_hwecc(), thus adding scalability for future ECC schemes. omap_enable_hwecc() + omap_enable_ecc_bch() -> omap_enable_hwecc()

---
 drivers/mtd/nand/omap_gpmc.c | 210 +++++++++++++------------------------------
 1 file changed, 61 insertions(+), 149 deletions(-)
drivers/mtd/nand/omap_gpmc.c +61 -149
index c6c5cec..f3b86e5 100644
@@ -20,6 +20,9 @@
 #include <linux/bch.h>
 #endif
 
+
+#define SECTOR_BYTES		512
+
 static uint8_t cs;
 static __maybe_unused struct nand_ecclayout hw_nand_oob =
 	GPMC_NAND_HW_ECC_LAYOUT;
@@ -63,21 +66,6 @@ int omap_spl_dev_ready(struct mtd_info *mtd)
 }
 #endif
 
-/*
- * omap_hwecc_init - Initialize the Hardware ECC for NAND flash in
- *                   GPMC controller
- * @mtd:        MTD device structure
- *
- */
-static void __maybe_unused omap_hwecc_init(struct nand_chip *chip)
-{
-	/*
-	 * Init ECC Control Register
-	 * Clear all ECC | Enable Reg1
-	 */
-	writel(ECCCLEAR | ECCRESULTREG1, &gpmc_cfg->ecc_control);
-	writel(ECCSIZE1 | ECCSIZE0 | ECCSIZE0SEL, &gpmc_cfg->ecc_size_config);
-}
 
 /*
  * gen_true_ecc - This function will generate true ECC value, which
@@ -195,38 +183,6 @@ static int __maybe_unused omap_calculate_ecc(struct mtd_info *mtd,
 }
 
 /*
- * omap_enable_ecc - This function enables the hardware ecc functionality
- * @mtd:        MTD device structure
- * @mode:       Read/Write mode
- */
-static void __maybe_unused omap_enable_hwecc(struct mtd_info *mtd, int32_t mode)
-{
-	struct nand_chip *chip = mtd->priv;
-	uint32_t val, dev_width = (chip->options & NAND_BUSWIDTH_16) >> 1;
-
-	switch (mode) {
-	case NAND_ECC_READ:
-	case NAND_ECC_WRITE:
-		/* Clear the ecc result registers, select ecc reg as 1 */
-		writel(ECCCLEAR | ECCRESULTREG1, &gpmc_cfg->ecc_control);
-
-		/*
-		 * Size 0 = 0xFF, Size1 is 0xFF - both are 512 bytes
-		 * tell all regs to generate size0 sized regs
-		 * we just have a single ECC engine for all CS
-		 */
-		writel(ECCSIZE1 | ECCSIZE0 | ECCSIZE0SEL,
-			&gpmc_cfg->ecc_size_config);
-		val = (dev_width << 7) | (cs << 1) | (0x1);
-		writel(val, &gpmc_cfg->ecc_config);
-		break;
-	default:
-		printf("Error: Unrecognized Mode[%d]!\n", mode);
-		break;
-	}
-}
-
-/*
  * Generic BCH interface
  */
 struct nand_bch_priv {
@@ -265,105 +221,64 @@ static __maybe_unused struct nand_bch_priv bch_priv = {
 };
 
 /*
- * omap_hwecc_init_bch - Initialize the BCH Hardware ECC for NAND flash in
- *				GPMC controller
+ * omap_enable_hwecc - configures GPMC as per ECC scheme before read/write
  * @mtd:	MTD device structure
  * @mode:	Read/Write mode
  */
 __maybe_unused
-static void omap_hwecc_init_bch(struct nand_chip *chip, int32_t mode)
+static void omap_enable_hwecc(struct mtd_info *mtd, int32_t mode)
 {
-	uint32_t val;
-	uint32_t dev_width = (chip->options & NAND_BUSWIDTH_16) >> 1;
-#if defined(CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW)
-	uint32_t unused_length = 0;
-#endif
-	uint32_t wr_mode = BCH_WRAPMODE_6;
-	struct nand_bch_priv *bch = chip->priv;
-
-	/* Clear the ecc result registers, select ecc reg as 1 */
-	writel(ECCCLEAR | ECCRESULTREG1, &gpmc_cfg->ecc_control);
-
-#if defined(CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW)
-	wr_mode = BCH_WRAPMODE_1;
-
-	switch (bch->nibbles) {
-	case ECC_BCH4_NIBBLES:
-		unused_length = 3;
-		break;
-	case ECC_BCH8_NIBBLES:
-		unused_length = 2;
-		break;
-	case ECC_BCH16_NIBBLES:
-		unused_length = 0;
-		break;
-	}
-
-	/*
-	 * This is ecc_size_config for ELM mode.
-	 * Here we are using different settings for read and write access and
-	 * also depending on BCH strength.
-	 */
-	switch (mode) {
-	case NAND_ECC_WRITE:
-		/* write access only setup eccsize1 config */
-		val = ((unused_length + bch->nibbles) << 22);
-		break;
-
-	case NAND_ECC_READ:
-	default:
-		/*
-		 * by default eccsize0 selected for ecc1resultsize
-		 * eccsize0 config.
-		 */
-		val  = (bch->nibbles << 12);
-		/* eccsize1 config */
-		val |= (unused_length << 22);
-		break;
-	}
+	struct nand_chip *chip = mtd->priv;
+	unsigned int dev_width = (chip->options & NAND_BUSWIDTH_16) ? 1 : 0;
+	unsigned int nsectors = (mtd->writesize / SECTOR_BYTES);
+	unsigned int ecc_algo = 0;
+	unsigned int bch_type = 0;
+	unsigned int eccsize1 = 0x00, eccsize0 = 0x00, bch_wrapmode = 0x00;
+	u32 ecc_size_config_val = 0;
+	u32 ecc_config_val = 0;
+
+	if (chip->ecc.strength == 1) {
+		ecc_algo = 0x0;
+		bch_type = 0x0;
+		bch_wrapmode = 0x00;
+		eccsize0 = 0xFF;
+		eccsize1 = 0xFF;
+#if defined(CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW) || \
+	defined(CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW_DETECTION_SW)
+	} else if (chip->ecc.strength == 8) {
+		ecc_algo = 0x1;
+		bch_type = 0x1;
+		if (mode == NAND_ECC_WRITE) {
+			bch_wrapmode = 0x01;
+			eccsize0 = 0;  /* extra bits in nibbles per sector */
+			eccsize1 = 28; /* OOB bits in nibbles per sector */
+		} else {
+			bch_wrapmode = 0x01;
+			eccsize0 = 26; /* ECC bits in nibbles per sector */
+			eccsize1 = 2;  /* non-ECC bits in nibbles per sector */
+		}
 #else
-	/*
-	 * This ecc_size_config setting is for BCH sw library.
-	 *
-	 * Note: we only support BCH8 currently with BCH sw library!
-	 * Should be really easy to adobt to BCH4, however some omap3 have
-	 * flaws with BCH4.
-	 *
-	 * Here we are using wrapping mode 6 both for reading and writing, with:
-	 *  size0 = 0  (no additional protected byte in spare area)
-	 *  size1 = 32 (skip 32 nibbles = 16 bytes per sector in spare area)
-	 */
-	val = (32 << 22) | (0 << 12);
+	} else {
+		printf("*Error: invalid driver configuration\n");
 #endif
-	/* ecc size configuration */
-	writel(val, &gpmc_cfg->ecc_size_config);
-
-	/*
-	 * Configure the ecc engine in gpmc
-	 * We assume 512 Byte sector pages for access to NAND.
-	 */
-	val  = (1 << 16);		/* enable BCH mode */
-	val |= (bch->type << 12);	/* setup BCH type */
-	val |= (wr_mode << 8);		/* setup wrapping mode */
-	val |= (dev_width << 7);	/* setup device width (16 or 8 bit) */
-	val |= (cs << 1);		/* setup chip select to work on */
-	debug("set ECC_CONFIG=0x%08x\n", val);
-	writel(val, &gpmc_cfg->ecc_config);
-}
-
-/*
- * omap_enable_ecc_bch - This function enables the bch h/w ecc functionality
- * @mtd:	MTD device structure
- * @mode:	Read/Write mode
- */
-__maybe_unused
-static void omap_enable_ecc_bch(struct mtd_info *mtd, int32_t mode)
-{
-	struct nand_chip *chip = mtd->priv;
-
-	omap_hwecc_init_bch(chip, mode);
-	/* enable ecc */
-	writel((readl(&gpmc_cfg->ecc_config) | 0x1), &gpmc_cfg->ecc_config);
+	}
+	/* Clear ecc and enable bits */
+	writel(ECCCLEAR | ECCRESULTREG1, &gpmc_cfg->ecc_control);
+	/* Configure ecc size for BCH */
+	ecc_size_config_val = (eccsize1 << 22) | (eccsize0 << 12);
+	writel(ecc_size_config_val, &gpmc_cfg->ecc_size_config);
+
+	/* Configure device details for BCH engine */
+	ecc_config_val = ((ecc_algo << 16)	| /* HAM1 | BCHx */
+			(bch_type << 12)	| /* BCH4/BCH8/BCH16 */
+			(bch_wrapmode << 8)	| /* wrap mode */
+			(dev_width << 7)	| /* bus width */
+			(((nsectors-1) & 0x7) << 4) | /* number of sectors */
+			(cs <<  1)	| /* ECC CS */
+			(0x0));			/* disable ECC */
+	writel(ecc_config_val, &gpmc_cfg->ecc_config);
+	/* enable ECC engine */
+	writel(ecc_config_val | 0x1, &gpmc_cfg->ecc_config);
 }
 
 /*
@@ -802,7 +717,7 @@ void omap_nand_switch_ecc(uint32_t hardware, uint32_t eccstrength)
 			nand->ecc.hwctl = omap_enable_hwecc;
 			nand->ecc.correct = omap_correct_data;
 			nand->ecc.calculate = omap_calculate_ecc;
-			omap_hwecc_init(nand);
+			omap_enable_hwecc(mtd, NAND_ECC_READ);
 			printf("1-bit hamming HW ECC selected\n");
 		} else if (eccstrength == 8) {
 #if defined(CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW)
@@ -811,20 +726,20 @@ void omap_nand_switch_ecc(uint32_t hardware, uint32_t eccstrength)
 			nand->ecc.size		= 512;
 			nand->ecc.bytes		= 14;
 			nand->ecc.read_page	= omap_read_page_bch;
-			nand->ecc.hwctl		= omap_enable_ecc_bch;
+			nand->ecc.hwctl		= omap_enable_hwecc;
 			nand->ecc.correct	= omap_correct_data_bch;
 			nand->ecc.calculate	= omap_calculate_ecc_bch;
-			omap_hwecc_init_bch(nand, NAND_ECC_READ);
+			omap_enable_hwecc(mtd, NAND_ECC_READ);
 			printf("using OMAP_ECC_BCH8_CODE_HW\n");
 #elif defined(CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW_DETECTION_SW)
 			nand->ecc.mode		= NAND_ECC_HW;
 			nand->ecc.layout	= &hw_bch8_nand_oob;
 			nand->ecc.size		= 512;
 			nand->ecc.bytes		= 13;
-			nand->ecc.hwctl		= omap_enable_ecc_bch;
+			nand->ecc.hwctl		= omap_enable_hwecc;
 			nand->ecc.correct	= omap_correct_data_bch;
 			nand->ecc.calculate	= omap_calculate_ecc_bch;
-			omap_hwecc_init_bch(nand, NAND_ECC_READ);
+			omap_enable_hwecc(mtd, NAND_ECC_READ);
 			printf("using OMAP_ECC_BCH8_CODE_HW_DETECTION_SW\n");
 #else
 			printf("selected ECC not supported or not enabled\n");
@@ -909,11 +824,10 @@ int board_nand_init(struct nand_chip *nand)
 	nand->ecc.size		= CONFIG_SYS_NAND_ECCSIZE;
 	nand->ecc.bytes		= CONFIG_SYS_NAND_ECCBYTES;
 	nand->ecc.strength	= 8;
-	nand->ecc.hwctl		= omap_enable_ecc_bch;
+	nand->ecc.hwctl		= omap_enable_hwecc;
 	nand->ecc.correct	= omap_correct_data_bch;
 	nand->ecc.calculate	= omap_calculate_ecc_bch;
 	nand->ecc.read_page	= omap_read_page_bch;
-	omap_hwecc_init_bch(nand, NAND_ECC_READ);
 	/* ELM is used for ECC error detection */
 	elm_init();
 	nand->priv = &bch_priv;
@@ -924,10 +838,9 @@ int board_nand_init(struct nand_chip *nand)
 	nand->ecc.size		= CONFIG_SYS_NAND_ECCSIZE;
 	nand->ecc.bytes		= CONFIG_SYS_NAND_ECCBYTES;
 	nand->ecc.strength	= 8;
-	nand->ecc.hwctl		= omap_enable_ecc_bch;
+	nand->ecc.hwctl		= omap_enable_hwecc;
 	nand->ecc.correct	= omap_correct_data_bch;
 	nand->ecc.calculate	= omap_calculate_ecc_bch;
-	omap_hwecc_init_bch(nand, NAND_ECC_READ);
 	/* BCH SW library is used for error detection */
 	bch_priv.control	= init_bch(13, 8, 0x201b /* hw polynominal */);
 	if (!bch_priv.control) {
@@ -948,7 +861,6 @@ int board_nand_init(struct nand_chip *nand)
 	nand->ecc.correct = omap_correct_data;
 	nand->ecc.calculate = omap_calculate_ecc;
 	nand->ecc.strength = 1;
-	omap_hwecc_init(nand);
 #endif
 
 #ifdef CONFIG_SPL_BUILD
Signature · 1 line
1.8.1
#8 lore raw

PATCH 3/4 mtd: nand: omap: optimize chip->ecc.calculate() for H/W ECC schemes

In reply to Pekon Gupta

chip->ecc.calculate() is used for calculating and fetching of ECC syndrome by processing the data passed during Read/Write accesses.

All H/W based ECC schemes use GPMC controller to calculate ECC syndrome. But each BCHx_ECC scheme has its own implemetation of post-processing and fetching ECC syndrome from GPMC controller.

This patch updates OMAP_ECC_BCH8_CODE_HW ECC scheme in following way:
- merges various sub-functions into single omap_calculate_ecc_bch().
- removes omap_ecc_disable() and instead uses it as inline.

---
 drivers/mtd/nand/omap_gpmc.c | 82 ++++++++++----------------------------------
 1 file changed, 18 insertions(+), 64 deletions(-)
drivers/mtd/nand/omap_gpmc.c +18 -64
index f3b86e5..40b71a7 100644
@@ -281,34 +281,26 @@ static void omap_enable_hwecc(struct mtd_info *mtd, int32_t mode)
 	writel(ecc_config_val | 0x1, &gpmc_cfg->ecc_config);
 }
 
-/*
- * omap_ecc_disable - Disable H/W ECC calculation
- *
- * @mtd:	MTD device structure
- */
-static void __maybe_unused omap_ecc_disable(struct mtd_info *mtd)
-{
-	writel((readl(&gpmc_cfg->ecc_config) & ~0x1), &gpmc_cfg->ecc_config);
-}
 
 #if defined(CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW)
 /*
- * BCH8 support (needs ELM and thus AM33xx-only)
- */
-/*
- * omap_read_bch8_result - Read BCH result for BCH8 level
+ *  omap_calculate_ecc_bch - Read BCH ECC result
  *
- * @mtd:	MTD device structure
- * @big_endian:	When set read register 3 first
- * @ecc_code:	Read syndrome from BCH result registers
+ *  @mtd:	MTD structure
+ *  @dat:	unused
+ *  @ecc_code:	ecc_code buffer
  */
-static void omap_read_bch8_result(struct mtd_info *mtd, uint8_t big_endian,
+static int omap_calculate_ecc_bch(struct mtd_info *mtd, const uint8_t *dat,
 				uint8_t *ecc_code)
 {
+	struct nand_chip *chip = mtd->priv;
+	struct nand_bch_priv *bch = chip->priv;
+	int8_t ret = 0;
 	uint32_t *ptr;
 	int8_t i = 0, j;
 
-	if (big_endian) {
+	switch (bch->type) {
+	case ECC_BCH8:
 		ptr = &gpmc_cfg->bch_result_0_3[0].bch_result_x[3];
 		ecc_code[i++] = readl(ptr) & 0xFF;
 		ptr--;
@@ -319,18 +311,13 @@ static void omap_read_bch8_result(struct mtd_info *mtd, uint8_t big_endian,
 			ecc_code[i++] = readl(ptr) & 0xFF;
 			ptr--;
 		}
-	} else {
-		ptr = &gpmc_cfg->bch_result_0_3[0].bch_result_x[0];
-		for (j = 0; j < 3; j++) {
-			ecc_code[i++] = readl(ptr) & 0xFF;
-			ecc_code[i++] = (readl(ptr) >>  8) & 0xFF;
-			ecc_code[i++] = (readl(ptr) >> 16) & 0xFF;
-			ecc_code[i++] = (readl(ptr) >> 24) & 0xFF;
-			ptr++;
-		}
-		ecc_code[i++] = readl(ptr) & 0xFF;
-		ecc_code[i++] = 0;	/* 14th byte is always zero */
+		break;
+	default:
+		ret = -1;
 	}
+	/* clear result and disable engine */
+	writel((readl(&gpmc_cfg->ecc_config) & ~0x1), &gpmc_cfg->ecc_config);
+	return ret;
 }
 
 /*
@@ -369,35 +356,6 @@ static void omap_rotate_ecc_bch(struct mtd_info *mtd, uint8_t *calc_ecc,
 }
 
 /*
- *  omap_calculate_ecc_bch - Read BCH ECC result
- *
- *  @mtd:	MTD structure
- *  @dat:	unused
- *  @ecc_code:	ecc_code buffer
- */
-static int omap_calculate_ecc_bch(struct mtd_info *mtd, const uint8_t *dat,
-				uint8_t *ecc_code)
-{
-	struct nand_chip *chip = mtd->priv;
-	struct nand_bch_priv *bch = chip->priv;
-	uint8_t big_endian = 1;
-	int8_t ret = 0;
-
-	if (bch->type == ECC_BCH8)
-		omap_read_bch8_result(mtd, big_endian, ecc_code);
-	else /* BCH4 and BCH16 currently not supported */
-		ret = -1;
-
-	/*
-	 * Stop reading anymore ECC vals and clear old results
-	 * enable will be called if more reads are required
-	 */
-	omap_ecc_disable(mtd);
-
-	return ret;
-}
-
-/*
  * omap_fix_errors_bch - Correct bch error in the data
  *
  * @mtd:	MTD device structure
@@ -594,12 +552,8 @@ static int omap_calculate_ecc_bch(struct mtd_info *mtd, const uint8_t *dat,
 		*ecc++ = 0x24 ^ ((val1 >> 8) & 0xFF);
 		*ecc++ = 0xb5 ^ (val1 & 0xFF);
 	}
-
-	/*
-	 * Stop reading anymore ECC vals and clear old results
-	 * enable will be called if more reads are required
-	 */
-	omap_ecc_disable(mtd);
+	/* Stop reading anymore ECC vals and clear old results */
+	writel((readl(&gpmc_cfg->ecc_config) & ~0x1), &gpmc_cfg->ecc_config);
 
 	return ret;
 }
Signature · 1 line
1.8.1
#9 lore raw

PATCH 4/4 mtd: nand: omap: optimized chip->ecc.correct() for H/W ECC schemes

In reply to Pekon Gupta

chip->ecc.correct() is used for detecting and correcting bit-flips during read operations. In omap-nand driver it implemented as:
(a) omap_correct_data(): for h/w based ECC_HAM1 scheme
(b) omap_correct_data_bch() + CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW_DETECTION_SW for ECC_BCH8 scheme using GPMC and software lib/bch.c
(c) omap_correct_data_bch() + CONFIG_NAND_OMAP_ECC_BCH8_CODE_HW for ECC_BCH8 scheme using GPMC and ELM

This patch updates (c)
- checks for calc_ecc[]==0x00 so that error_correction is not required for known good pages.
- adds scalability for other ECC_BCHx scheme by merging following omap_rotate_ecc_bch() + omap_fix_errors_bch() => omap_correct_data_bch()
- fixing logic for bit-flip correction based on error_loc[count]

---
 drivers/mtd/nand/omap_gpmc.c | 124 +++++++++++++++----------------------------
 1 file changed, 44 insertions(+), 80 deletions(-)
drivers/mtd/nand/omap_gpmc.c +44 -80
index 40b71a7..229af81 100644
@@ -22,6 +22,8 @@
 
 
 #define SECTOR_BYTES		512
+/* 4 bit padding to make byte aligned, 56 = 52 + 4 */
+#define BCH4_BIT_PAD		4
 
 static uint8_t cs;
 static __maybe_unused struct nand_ecclayout hw_nand_oob =
@@ -321,77 +323,6 @@ static int omap_calculate_ecc_bch(struct mtd_info *mtd, const uint8_t *dat,
 }
 
 /*
- * omap_rotate_ecc_bch - Rotate the syndrome bytes
- *
- * @mtd:	MTD device structure
- * @calc_ecc:	ECC read from ECC registers
- * @syndrome:	Rotated syndrome will be retuned in this array
- *
- */
-static void omap_rotate_ecc_bch(struct mtd_info *mtd, uint8_t *calc_ecc,
-		uint8_t *syndrome)
-{
-	struct nand_chip *chip = mtd->priv;
-	struct nand_bch_priv *bch = chip->priv;
-	uint8_t n_bytes = 0;
-	int8_t i, j;
-
-	switch (bch->type) {
-	case ECC_BCH4:
-		n_bytes = 8;
-		break;
-
-	case ECC_BCH16:
-		n_bytes = 28;
-		break;
-
-	case ECC_BCH8:
-	default:
-		n_bytes = 13;
-		break;
-	}
-
-	for (i = 0, j = (n_bytes-1); i < n_bytes; i++, j--)
-		syndrome[i] =  calc_ecc[j];
-}
-
-/*
- * omap_fix_errors_bch - Correct bch error in the data
- *
- * @mtd:	MTD device structure
- * @data:	Data read from flash
- * @error_count:Number of errors in data
- * @error_loc:	Locations of errors in the data
- *
- */
-static void omap_fix_errors_bch(struct mtd_info *mtd, uint8_t *data,
-		uint32_t error_count, uint32_t *error_loc)
-{
-	struct nand_chip *chip = mtd->priv;
-	struct nand_bch_priv *bch = chip->priv;
-	uint8_t count = 0;
-	uint32_t error_byte_pos;
-	uint32_t error_bit_mask;
-	uint32_t last_bit = (bch->nibbles * 4) - 1;
-
-	/* Flip all bits as specified by the error location array. */
-	/* FOR( each found error location flip the bit ) */
-	for (count = 0; count < error_count; count++) {
-		if (error_loc[count] > last_bit) {
-			/* Remove the ECC spare bits from correction. */
-			error_loc[count] -= (last_bit + 1);
-			/* Offset bit in data region */
-			error_byte_pos = ((512 * 8) -
-					(error_loc[count]) - 1) / 8;
-			/* Error Bit mask */
-			error_bit_mask = 0x1 << (error_loc[count] % 8);
-			/* Toggle the error bit to make the correction. */
-			data[error_byte_pos] ^= error_bit_mask;
-		}
-	}
-}
-
-/*
  * omap_correct_data_bch - Compares the ecc read from nand spare area
  * with ECC registers values and corrects one bit error if it has occured
  *
@@ -407,16 +338,26 @@ static int omap_correct_data_bch(struct mtd_info *mtd, uint8_t *dat,
 {
 	struct nand_chip *chip = mtd->priv;
 	struct nand_bch_priv *bch = chip->priv;
+	uint32_t eccbytes = chip->ecc.bytes;
 	uint8_t syndrome[28];
-	uint32_t error_count = 0;
+	uint32_t error_count = 0, error_max;
 	uint32_t error_loc[8];
-	uint32_t i, ecc_flag;
+	uint32_t i, j, ecc_flag = 0;
+	uint8_t count, ret = 0;
+	uint32_t byte_pos, bit_pos;
+
+	/* check calculated ecc */
+	for (i = 0; i < chip->ecc.bytes && !ecc_flag; i++)
+		if (calc_ecc[i] != 0x00)
+			ecc_flag = 1;
+	if (!ecc_flag)
+		return 0;
 
+	/* check for whether its a erased-page */
 	ecc_flag = 0;
-	for (i = 0; i < chip->ecc.bytes; i++)
+	for (i = 0; i < chip->ecc.bytes && !ecc_flag; i++)
 		if (read_ecc[i] != 0xff)
 			ecc_flag = 1;
-
 	if (!ecc_flag)
 		return 0;
 
@@ -427,20 +368,43 @@ static int omap_correct_data_bch(struct mtd_info *mtd, uint8_t *dat,
 	 * while reading ECC result we read it in big endian.
 	 * Hence while loading to ELM we have rotate to get the right endian.
 	 */
-	omap_rotate_ecc_bch(mtd, calc_ecc, syndrome);
+	for (i = 0, j = (eccbytes-1); i < eccbytes; i++, j--)
+		syndrome[i] =  calc_ecc[j];
 
 	/* use elm module to check for errors */
 	if (elm_check_error(syndrome, bch->nibbles, &error_count,
 				error_loc) != 0) {
-		printf("ECC: uncorrectable.\n");
+		printf("nand: uncorrectable ECC errors\n");
 		return -1;
 	}
 
 	/* correct bch error */
-	if (error_count > 0)
-		omap_fix_errors_bch(mtd, dat, error_count, error_loc);
+	for (count = 0; count < error_count; count++) {
+		switch (bch->type) {
+		case ECC_BCH4:
+			error_max = SECTOR_BYTES + (eccbytes - 1);
+			/* add 4 to take care 4 bit padding */
+			error_loc[count] += BCH4_BIT_PAD;
+			break;
+		case ECC_BCH8:
+			/* 14th byte in ECC is reserved to match ROM layout */
+			error_max = SECTOR_BYTES + (eccbytes - 1);
+			break;
+		default:
+			return -1;
+		}
+		byte_pos = error_max - ((error_loc[count] - 1) / 8);
+		bit_pos  = error_loc[count] % 8;
 
-	return 0;
+		if (byte_pos < SECTOR_BYTES)
+			dat[byte_pos] ^= 1 << bit_pos;
+		else if (byte_pos < error_max)
+			read_ecc[byte_pos - SECTOR_BYTES] = 1 << bit_pos;
+		else
+			ret = -1;
+	}
+
+	return ret;
 }
 
 /**
Signature · 1 line
1.8.1