diff options
author | Boris Brezillon <boris.brezillon@free-electrons.com> | 2016-06-08 11:04:24 -0400 |
---|---|---|
committer | Boris Brezillon <boris.brezillon@free-electrons.com> | 2016-09-23 03:35:16 -0400 |
commit | 4796d8655915b8dce265318542a40d920aad91a3 (patch) | |
tree | b63f91f3ce4e11c344bf2e0733938b7bc779ecce /drivers/mtd | |
parent | 8bbba48124f2ace8f8bf382539d7115f0f307eeb (diff) |
mtd: nand: sunxi: Support ECC maximization
Setup the maximum ECC config when NAND_ECC_MAXIMIZE is set.
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Diffstat (limited to 'drivers/mtd')
-rw-r--r-- | drivers/mtd/nand/sunxi_nand.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/drivers/mtd/nand/sunxi_nand.c b/drivers/mtd/nand/sunxi_nand.c index 2032244138c1..8b8470c4e6d0 100644 --- a/drivers/mtd/nand/sunxi_nand.c +++ b/drivers/mtd/nand/sunxi_nand.c | |||
@@ -1787,6 +1787,35 @@ static int sunxi_nand_hw_common_ecc_ctrl_init(struct mtd_info *mtd, | |||
1787 | int ret; | 1787 | int ret; |
1788 | int i; | 1788 | int i; |
1789 | 1789 | ||
1790 | if (ecc->options & NAND_ECC_MAXIMIZE) { | ||
1791 | int bytes; | ||
1792 | |||
1793 | ecc->size = 1024; | ||
1794 | nsectors = mtd->writesize / ecc->size; | ||
1795 | |||
1796 | /* Reserve 2 bytes for the BBM */ | ||
1797 | bytes = (mtd->oobsize - 2) / nsectors; | ||
1798 | |||
1799 | /* 4 non-ECC bytes are added before each ECC bytes section */ | ||
1800 | bytes -= 4; | ||
1801 | |||
1802 | /* and bytes has to be even. */ | ||
1803 | if (bytes % 2) | ||
1804 | bytes--; | ||
1805 | |||
1806 | ecc->strength = bytes * 8 / fls(8 * ecc->size); | ||
1807 | |||
1808 | for (i = 0; i < ARRAY_SIZE(strengths); i++) { | ||
1809 | if (strengths[i] > ecc->strength) | ||
1810 | break; | ||
1811 | } | ||
1812 | |||
1813 | if (!i) | ||
1814 | ecc->strength = 0; | ||
1815 | else | ||
1816 | ecc->strength = strengths[i - 1]; | ||
1817 | } | ||
1818 | |||
1790 | if (ecc->size != 512 && ecc->size != 1024) | 1819 | if (ecc->size != 512 && ecc->size != 1024) |
1791 | return -EINVAL; | 1820 | return -EINVAL; |
1792 | 1821 | ||