[PATCH v3 22/22] mtd: spinand: repeat reading in regular mode if continuous reading fails

Mikhail Kshevetskiy mikhail.kshevetskiy at iopsys.eu
Tue Aug 5 10:15:11 CEST 2025


Continuous reading may result in multiple flash pages reading in one
operation. Unfortunately, not all spi-nand controllers support such
large reading. They will read less data. Unfortunately, the operation
can't be continued.

In this case:
 * disable continuous reading on this (not good enough) spi controller
 * repeat reading in regular mode.

Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy at iopsys.eu>
---
 drivers/mtd/nand/spi/core.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index e9ca2b3c391..89c0738905e 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -428,7 +428,7 @@ static int spinand_read_from_cache_op(struct spinand_device *spinand,
 		 * Toggling the CS during a continuous read is forbidden.
 		 */
 		if (nbytes && req->continuous)
-			return -EIO;
+			return -E2BIG;
 	}
 
 	if (req->datalen)
@@ -887,16 +887,28 @@ static bool spinand_use_cont_read(struct mtd_info *mtd, loff_t from,
 static int spinand_mtd_read(struct mtd_info *mtd, loff_t from,
 			    struct mtd_oob_ops *ops)
 {
+	struct spinand_device *spinand = mtd_to_spinand(mtd);
 	unsigned int max_bitflips = 0;
-	int ret;
+	int ret = -E2BIG;
 
 #ifndef __UBOOT__
 	mutex_lock(&spinand->lock);
 #endif
 
-	if (spinand_use_cont_read(mtd, from, ops))
+	if (spinand_use_cont_read(mtd, from, ops)) {
 		ret = spinand_mtd_continuous_page_read(mtd, from, ops, &max_bitflips);
-	else
+		if (ret == -E2BIG) {
+			/*
+			 * Some spi controllers may not support reading up to
+			 * erase block size. They will read less data than
+			 * expected. If this happen disable continuous mode
+			 * and repeat reading in normal mode.
+			 */
+			spinand->cont_read_possible = false;
+		}
+	}
+
+	if (ret == -E2BIG)
 		ret = spinand_mtd_regular_page_read(mtd, from, ops, &max_bitflips);
 
 #ifndef __UBOOT__
-- 
2.47.2



More information about the U-Boot mailing list