[1/2] mtd: nand: Fix ecc in mxs_nand_spl onfi mode

Message ID 20220708141439.164394-1-michael@amarulasolutions.com
State New
Headers show
Series
  • [1/2] mtd: nand: Fix ecc in mxs_nand_spl onfi mode
Related show

Commit Message

Michael Nazzareno Trimarchi July 8, 2022, 2:14 p.m. UTC
We need to calculate the ecc parameters in a way that are the same
in uboot and spl. The parameters are connected to the onfi
computation. We need to assign all the value of chip in order
to have same ecc strength parameters before calling

mxs_nand_set_geometry that calculate the ecc layout

/* use the legacy bch setting by default */
if ((!nand_info->use_minimum_ecc && mtd->oobsize < 1024) ||
     !(chip->ecc_strength_ds > 0 && chip->ecc_step_ds > 0)) {
	dev_dbg(mtd->dev, "use legacy bch geometry\n");
	err = mxs_nand_legacy_calc_ecc_layout(geo, mtd);
	if (!err)
		return 0;
}

Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com>
---
 drivers/mtd/nand/raw/mxs_nand_spl.c | 6 ++++++
 1 file changed, 6 insertions(+)

Patch

diff --git a/drivers/mtd/nand/raw/mxs_nand_spl.c b/drivers/mtd/nand/raw/mxs_nand_spl.c
index 3daacbb330..683071c1cb 100644
--- a/drivers/mtd/nand/raw/mxs_nand_spl.c
+++ b/drivers/mtd/nand/raw/mxs_nand_spl.c
@@ -139,6 +139,10 @@  static int mxs_flash_onfi_ident(struct mtd_info *mtd)
 	mtd->writesize = le32_to_cpu(p->byte_per_page);
 	mtd->erasesize = le32_to_cpu(p->pages_per_block) * mtd->writesize;
 	mtd->oobsize = le16_to_cpu(p->spare_bytes_per_page);
+	if (p->ecc_bits != 0xff) {
+		chip->ecc_strength_ds = p->ecc_bits;
+		chip->ecc_step_ds = 512;
+	}
 	chip->chipsize = le32_to_cpu(p->blocks_per_lun);
 	chip->chipsize *= (uint64_t)mtd->erasesize * p->lun_count;
 	/* Calculate the address shift from the page size */
@@ -152,6 +156,8 @@  static int mxs_flash_onfi_ident(struct mtd_info *mtd)
 	debug("writesize=%d (>>%d)\n", mtd->writesize, chip->page_shift);
 	debug("oobsize=%d\n", mtd->oobsize);
 	debug("chipsize=%lld\n", chip->chipsize);
+	debug("ecc_strength_ds=%d\n", chip->ecc_strength_ds);
+	debug("ecc_step_ds = %d\n", chip->ecc_step_ds);
 
 	return 0;
 }