summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorTeresa Gámez <t.gamez@phytec.de>2015-03-30 15:51:05 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2015-03-30 19:27:21 +0200
commit394d4acb8dc3e1c32cd3ff02684628c14157de0a (patch)
treef80021d396bc344cd4027dfe74783143e837bcd2 /drivers
parent4ef5f8cf34d2ac2129f277d4a16b7a4b5f19bde0 (diff)
downloadbarebox-394d4acb8dc3e1c32cd3ff02684628c14157de0a.tar.gz
barebox-394d4acb8dc3e1c32cd3ff02684628c14157de0a.tar.xz
mtd: nand_omap_gpmc: Fix ecc check for bch8 romcode
The bch8 romcode was only checked and corrected for the first 512 bytes of a 2048 byte page. Set interation counter and eccsizes correct for the different bch types. Tested OMAP_ECC_BCH8_CODE_HW and OMAP_ECC_BCH8_CODE_HW_ROMCODE. Reported-by: Gabor Janak <g.janak@agilion.de> Signed-off-by: Teresa Gámez <t.gamez@phytec.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/mtd/nand/nand_omap_gpmc.c38
1 files changed, 23 insertions, 15 deletions
diff --git a/drivers/mtd/nand/nand_omap_gpmc.c b/drivers/mtd/nand/nand_omap_gpmc.c
index 647605b0ae..9d9d27e964 100644
--- a/drivers/mtd/nand/nand_omap_gpmc.c
+++ b/drivers/mtd/nand/nand_omap_gpmc.c
@@ -298,37 +298,45 @@ static int omap_correct_bch(struct mtd_info *mtd, uint8_t *dat,
{
struct nand_chip *nand = (struct nand_chip *)(mtd->priv);
struct gpmc_nand_info *oinfo = (struct gpmc_nand_info *)(nand->priv);
- int i, j, eccsize, eccflag, count, totalcount;
+ int i, j, eccflag, count, totalcount, actual_eccsize;
unsigned int err_loc[8];
- int blocks = 0;
int select_4_8;
- if (oinfo->ecc_mode == OMAP_ECC_BCH4_CODE_HW) {
- eccsize = 7;
+ int eccsteps = oinfo->nand.ecc.steps;
+ int eccsize = oinfo->nand.ecc.bytes;
+
+ switch (oinfo->ecc_mode) {
+ case OMAP_ECC_BCH4_CODE_HW:
+ actual_eccsize = eccsize;
select_4_8 = 0;
- } else {
- eccsize = 13;
+ break;
+ case OMAP_ECC_BCH8_CODE_HW:
+ eccsize /= eccsteps;
+ actual_eccsize = eccsize;
+ select_4_8 = 1;
+ break;
+ case OMAP_ECC_BCH8_CODE_HW_ROMCODE:
+ actual_eccsize = eccsize - 1;
select_4_8 = 1;
+ break;
+ default:
+ dev_err(oinfo->pdev, "invalid driver configuration\n");
+ return -EINVAL;
}
- if (nand->ecc.size == 2048)
- blocks = 4;
- else
- blocks = 1;
-
totalcount = 0;
- for (i = 0; i < blocks; i++) {
+ for (i = 0; i < eccsteps; i++) {
/* check if any ecc error */
eccflag = 0;
- for (j = 0; (j < eccsize) && (eccflag == 0); j++) {
+ for (j = 0; (j < actual_eccsize) && (eccflag == 0); j++) {
if (calc_ecc[j] != 0)
eccflag = 1;
}
if (eccflag == 1) {
eccflag = 0;
- for (j = 0; (j < eccsize) &&
+ for (j = 0; (j < actual_eccsize) &&
(eccflag == 0); j++)
if (read_ecc[j] != 0xFF)
eccflag = 1;
@@ -350,7 +358,7 @@ static int omap_correct_bch(struct mtd_info *mtd, uint8_t *dat,
/* else, not interested to correct ecc */
}
- calc_ecc = calc_ecc + eccsize;
+ calc_ecc = calc_ecc + actual_eccsize;
read_ecc = read_ecc + eccsize;
dat += 512;
}