Skip to content

Commit 9777cc1

Browse files
committed
mtd: rawnand: pl353: Ensure program page operations are successful
The NAND core complies with the ONFI specification, which itself mentions that after any program or erase operation, a status check should be performed to see whether the operation was finished *and* successful. The NAND core offers helpers to finish a page write (sending the "PAGE PROG" command, waiting for the NAND chip to be ready again, and checking the operation status). But in some cases, advanced controller drivers might want to optimize this and craft their own page write helper to leverage additional hardware capabilities, thus not always using the core facilities. Some drivers, like this one, do not use the core helper to finish a page write because the final cycles are automatically managed by the hardware. In this case, the additional care must be taken to manually perform the final status check. Let's read the NAND chip status at the end of the page write helper and return -EIO upon error. Cc: Michal Simek <[email protected]> Cc: [email protected] Fixes: 08d8c62 ("mtd: rawnand: pl353: Add support for the ARM PL353 SMC NAND controller") Signed-off-by: Miquel Raynal <[email protected]> Tested-by: Michal Simek <[email protected]> Link: https://lore.kernel.org/linux-mtd/[email protected]
1 parent 3a4a893 commit 9777cc1

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

drivers/mtd/nand/raw/pl35x-nand-controller.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ static int pl35x_nand_write_page_hwecc(struct nand_chip *chip,
511511
u32 addr1 = 0, addr2 = 0, row;
512512
u32 cmd_addr;
513513
int i, ret;
514+
u8 status;
514515

515516
ret = pl35x_smc_set_ecc_mode(nfc, chip, PL35X_SMC_ECC_CFG_MODE_APB);
516517
if (ret)
@@ -563,6 +564,14 @@ static int pl35x_nand_write_page_hwecc(struct nand_chip *chip,
563564
if (ret)
564565
goto disable_ecc_engine;
565566

567+
/* Check write status on the chip side */
568+
ret = nand_status_op(chip, &status);
569+
if (ret)
570+
goto disable_ecc_engine;
571+
572+
if (status & NAND_STATUS_FAIL)
573+
ret = -EIO;
574+
566575
disable_ecc_engine:
567576
pl35x_smc_set_ecc_mode(nfc, chip, PL35X_SMC_ECC_CFG_MODE_BYPASS);
568577

0 commit comments

Comments
 (0)