mtd: nand: Request strength instead of bytes for soft BCH
Previously, we requested that drivers pass ecc.size and ecc.bytes when using NAND_ECC_SOFT_BCH. However, a driver is likely to only know the ECC strength required for its NAND, so each driver would need to perform a strength-to-bytes calculation. Avoid duplicating this calculation in each driver by asking drivers to pass ecc.size and ecc.strength so that the strength-to-bytes calculation need only be implemented once. This reverts/generalizes this commit: mtd: nand: Base BCH ECC bytes on required strength Signed-off-by: Aaron Sierra <asierra@xes-inc.com> Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
This commit is contained in:
parent
240181fd0f
commit
e0377cdeba
@ -4037,22 +4037,24 @@ int nand_scan_tail(struct mtd_info *mtd)
|
|||||||
ecc->read_oob = nand_read_oob_std;
|
ecc->read_oob = nand_read_oob_std;
|
||||||
ecc->write_oob = nand_write_oob_std;
|
ecc->write_oob = nand_write_oob_std;
|
||||||
/*
|
/*
|
||||||
* Board driver should supply ecc.size and ecc.bytes values to
|
* Board driver should supply ecc.size and ecc.strength values
|
||||||
* select how many bits are correctable; see nand_bch_init()
|
* to select how many bits are correctable. Otherwise, default
|
||||||
* for details. Otherwise, default to 4 bits for large page
|
* to 4 bits for large page devices.
|
||||||
* devices.
|
|
||||||
*/
|
*/
|
||||||
if (!ecc->size && (mtd->oobsize >= 64)) {
|
if (!ecc->size && (mtd->oobsize >= 64)) {
|
||||||
ecc->size = 512;
|
ecc->size = 512;
|
||||||
ecc->bytes = DIV_ROUND_UP(13 * ecc->strength, 8);
|
ecc->strength = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* See nand_bch_init() for details. */
|
||||||
|
ecc->bytes = DIV_ROUND_UP(
|
||||||
|
ecc->strength * fls(8 * ecc->size), 8);
|
||||||
ecc->priv = nand_bch_init(mtd, ecc->size, ecc->bytes,
|
ecc->priv = nand_bch_init(mtd, ecc->size, ecc->bytes,
|
||||||
&ecc->layout);
|
&ecc->layout);
|
||||||
if (!ecc->priv) {
|
if (!ecc->priv) {
|
||||||
pr_warn("BCH ECC initialization failed!\n");
|
pr_warn("BCH ECC initialization failed!\n");
|
||||||
BUG();
|
BUG();
|
||||||
}
|
}
|
||||||
ecc->strength = ecc->bytes * 8 / fls(8 * ecc->size);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NAND_ECC_NONE:
|
case NAND_ECC_NONE:
|
||||||
|
@ -2337,6 +2337,7 @@ static int __init ns_init_module(void)
|
|||||||
}
|
}
|
||||||
chip->ecc.mode = NAND_ECC_SOFT_BCH;
|
chip->ecc.mode = NAND_ECC_SOFT_BCH;
|
||||||
chip->ecc.size = 512;
|
chip->ecc.size = 512;
|
||||||
|
chip->ecc.strength = bch;
|
||||||
chip->ecc.bytes = eccbytes;
|
chip->ecc.bytes = eccbytes;
|
||||||
NS_INFO("using %u-bit/%u bytes BCH ECC\n", bch, chip->ecc.size);
|
NS_INFO("using %u-bit/%u bytes BCH ECC\n", bch, chip->ecc.size);
|
||||||
}
|
}
|
||||||
|
@ -1110,8 +1110,6 @@ static int sunxi_nand_ecc_init(struct mtd_info *mtd, struct nand_ecc_ctrl *ecc,
|
|||||||
|
|
||||||
switch (ecc->mode) {
|
switch (ecc->mode) {
|
||||||
case NAND_ECC_SOFT_BCH:
|
case NAND_ECC_SOFT_BCH:
|
||||||
ecc->bytes = DIV_ROUND_UP(ecc->strength * fls(8 * ecc->size),
|
|
||||||
8);
|
|
||||||
break;
|
break;
|
||||||
case NAND_ECC_HW:
|
case NAND_ECC_HW:
|
||||||
ret = sunxi_nand_hw_ecc_ctrl_init(mtd, ecc, np);
|
ret = sunxi_nand_hw_ecc_ctrl_init(mtd, ecc, np);
|
||||||
|
Loading…
Reference in New Issue
Block a user