Skip to content

Commit e044b8b

Browse files
committed
mtd: rawnand: lpc32xx_slc: Move the ECC initialization to ->attach_chip()
The probe function is only supposed to initialize the controller hardware but not the ECC engine. Indeed, we don't know anything about the NAND chip(s) at this stage. Let's move the logic initializing the ECC engine, even pretty simple, to the ->attach_chip() hook which gets called during nand_scan() routine, after the NAND chip discovery. As the previously mentioned logic is supposed to parse the DT for us, it is likely that the chip->ecc.* entries be overwritten. So let's avoid this by moving these lines to ->attach_chip(). Fixes: d7157ff ("mtd: rawnand: Use the ECC framework user input parsing bits") Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Cc: Vladimir Zapolskiy <vz@mleia.com> Cc: Sylvain Lemieux <slemieux.tyco@gmail.com>
1 parent 2dbd838 commit e044b8b

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

drivers/mtd/nand/raw/lpc32xx_slc.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,9 @@ static int lpc32xx_nand_attach_chip(struct nand_chip *chip)
775775
struct mtd_info *mtd = nand_to_mtd(chip);
776776
struct lpc32xx_nand_host *host = nand_get_controller_data(chip);
777777

778+
if (chip->ecc.engine_type != NAND_ECC_ENGINE_TYPE_ON_HOST)
779+
return 0;
780+
778781
/* OOB and ECC CPU and DMA work areas */
779782
host->ecc_buf = (uint32_t *)(host->data_buf + LPC32XX_DMA_DATA_SIZE);
780783

@@ -786,11 +789,22 @@ static int lpc32xx_nand_attach_chip(struct nand_chip *chip)
786789
if (mtd->writesize <= 512)
787790
mtd_set_ooblayout(mtd, &lpc32xx_ooblayout_ops);
788791

792+
chip->ecc.placement = NAND_ECC_PLACEMENT_INTERLEAVED;
789793
/* These sizes remain the same regardless of page size */
790794
chip->ecc.size = 256;
795+
chip->ecc.strength = 1;
791796
chip->ecc.bytes = LPC32XX_SLC_DEV_ECC_BYTES;
792797
chip->ecc.prepad = 0;
793798
chip->ecc.postpad = 0;
799+
chip->ecc.read_page_raw = lpc32xx_nand_read_page_raw_syndrome;
800+
chip->ecc.read_page = lpc32xx_nand_read_page_syndrome;
801+
chip->ecc.write_page_raw = lpc32xx_nand_write_page_raw_syndrome;
802+
chip->ecc.write_page = lpc32xx_nand_write_page_syndrome;
803+
chip->ecc.write_oob = lpc32xx_nand_write_oob_syndrome;
804+
chip->ecc.read_oob = lpc32xx_nand_read_oob_syndrome;
805+
chip->ecc.calculate = lpc32xx_nand_ecc_calculate;
806+
chip->ecc.correct = nand_correct_data;
807+
chip->ecc.hwctl = lpc32xx_nand_ecc_enable;
794808

795809
/*
796810
* Use a custom BBT marker setup for small page FLASH that
@@ -881,21 +895,9 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
881895
platform_set_drvdata(pdev, host);
882896

883897
/* NAND callbacks for LPC32xx SLC hardware */
884-
chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST;
885-
chip->ecc.placement = NAND_ECC_PLACEMENT_INTERLEAVED;
886898
chip->legacy.read_byte = lpc32xx_nand_read_byte;
887899
chip->legacy.read_buf = lpc32xx_nand_read_buf;
888900
chip->legacy.write_buf = lpc32xx_nand_write_buf;
889-
chip->ecc.read_page_raw = lpc32xx_nand_read_page_raw_syndrome;
890-
chip->ecc.read_page = lpc32xx_nand_read_page_syndrome;
891-
chip->ecc.write_page_raw = lpc32xx_nand_write_page_raw_syndrome;
892-
chip->ecc.write_page = lpc32xx_nand_write_page_syndrome;
893-
chip->ecc.write_oob = lpc32xx_nand_write_oob_syndrome;
894-
chip->ecc.read_oob = lpc32xx_nand_read_oob_syndrome;
895-
chip->ecc.calculate = lpc32xx_nand_ecc_calculate;
896-
chip->ecc.correct = nand_correct_data;
897-
chip->ecc.strength = 1;
898-
chip->ecc.hwctl = lpc32xx_nand_ecc_enable;
899901

900902
/*
901903
* Allocate a large enough buffer for a single huge page plus

0 commit comments

Comments
 (0)