From 31e6bb6787e730ddedf5cc9b90863c5ff438ead7 Mon Sep 17 00:00:00 2001 From: Bastien Curutchet Date: Fri, 8 Mar 2024 08:46:09 +0100 Subject: [PATCH 1/2] mtd: rawnand: davinci: Add dummy read after sending command Sometimes, writes fail because the tWB_max is not correctly observed after sending PAGEPROG. It leads to the R/B pin to be read as in the "ready" state right after sending the command, thus preventing the normal tPROG delay to be actually observed. This happens because the ndelay() that waits for tWB_max starts before the command reaches the NAND chip. Add a dummy read when a delay is requested at the end of the executed instruction to make sure that the sent command is received by the NAND before starting the short ndelay() (<1us but rounded up to 1us in practice). This read is done on the control register area because doing it on the Async Data area would change the NAND's RE pin state. This is not perfect as the two areas are behind two different devm_ioremap_resource() and could possibly be located on different interconnects (I did not find more details). This means either the additional latency due to the load operation is enough impacting, or it has the expected behavior of ensuring the write has been received. This has been tested on two platforms designed off of the DAVINCI/OMAP-L138. The first uses a Toshiba NAND Flash (TC58NYG2S3EBAI5), the other a Macronix one (MX30UF4G18AC). Signed-off-by: Bastien Curutchet Signed-off-by: Miquel Raynal Link: https://lore.kernel.org/linux-mtd/20240308074609.9056-1-bastien.curutchet@bootlin.com --- drivers/mtd/nand/raw/davinci_nand.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/nand/raw/davinci_nand.c b/drivers/mtd/nand/raw/davinci_nand.c index e75d81cf8c21..051deea768db 100644 --- a/drivers/mtd/nand/raw/davinci_nand.c +++ b/drivers/mtd/nand/raw/davinci_nand.c @@ -671,8 +671,11 @@ static int davinci_nand_exec_instr(struct davinci_nand_info *info, break; } - if (instr->delay_ns) + if (instr->delay_ns) { + /* Dummy read to be sure that command is sent before ndelay starts */ + davinci_nand_readl(info, 0); ndelay(instr->delay_ns); + } return 0; } From 6819db94e1cd3ce24a432f3616cd563ed0c4eaba Mon Sep 17 00:00:00 2001 From: Maxim Korotkov Date: Wed, 13 Mar 2024 13:27:20 +0300 Subject: [PATCH 2/2] mtd: rawnand: hynix: fixed typo The function hynix_nand_rr_init() should probably return an error code. Judging by the usage, it seems that the return code is passed up the call stack. Right now, it always returns 0 and the function hynix_nand_cleanup() in hynix_nand_init() has never been called. Found by RASU JSC and Linux Verification Center (linuxtesting.org) Fixes: 626994e07480 ("mtd: nand: hynix: Add read-retry support for 1x nm MLC NANDs") Signed-off-by: Maxim Korotkov Signed-off-by: Miquel Raynal Link: https://lore.kernel.org/linux-mtd/20240313102721.1991299-1-korotkov.maxim.s@gmail.com --- drivers/mtd/nand/raw/nand_hynix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/nand/raw/nand_hynix.c b/drivers/mtd/nand/raw/nand_hynix.c index a74e64e0cfa3..c02e50608816 100644 --- a/drivers/mtd/nand/raw/nand_hynix.c +++ b/drivers/mtd/nand/raw/nand_hynix.c @@ -401,7 +401,7 @@ static int hynix_nand_rr_init(struct nand_chip *chip) if (ret) pr_warn("failed to initialize read-retry infrastructure"); - return 0; + return ret; } static void hynix_nand_extract_oobsize(struct nand_chip *chip,