Skip to content

Commit

Permalink
mtd: nand: sunxi: Support ECC maximization
Browse files Browse the repository at this point in the history
Setup the maximum ECC config when NAND_ECC_MAXIMIZE is set.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
  • Loading branch information
Boris Brezillon committed Sep 23, 2016
1 parent 8bbba48 commit 4796d86
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions drivers/mtd/nand/sunxi_nand.c
Original file line number Diff line number Diff line change
Expand Up @@ -1787,6 +1787,35 @@ static int sunxi_nand_hw_common_ecc_ctrl_init(struct mtd_info *mtd,
int ret;
int i;

if (ecc->options & NAND_ECC_MAXIMIZE) {
int bytes;

ecc->size = 1024;
nsectors = mtd->writesize / ecc->size;

/* Reserve 2 bytes for the BBM */
bytes = (mtd->oobsize - 2) / nsectors;

/* 4 non-ECC bytes are added before each ECC bytes section */
bytes -= 4;

/* and bytes has to be even. */
if (bytes % 2)
bytes--;

ecc->strength = bytes * 8 / fls(8 * ecc->size);

for (i = 0; i < ARRAY_SIZE(strengths); i++) {
if (strengths[i] > ecc->strength)
break;
}

if (!i)
ecc->strength = 0;
else
ecc->strength = strengths[i - 1];
}

if (ecc->size != 512 && ecc->size != 1024)
return -EINVAL;

Expand Down

0 comments on commit 4796d86

Please sign in to comment.