]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
mtd: spinand: try a regular dirmap if creating a dirmap for continuous reading fails
authorMikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
Tue, 30 Sep 2025 00:21:08 +0000 (03:21 +0300)
committerMichael Trimarchi <michael@amarulasolutions.com>
Sun, 5 Oct 2025 18:26:35 +0000 (20:26 +0200)
Continuous reading may result in multiple flash pages reading in one
operation. Typically only one flash page has read/written (a little bit
more than 2-4 Kb), but continuous reading requires the spi controller
to read up to 512 Kb in one operation without toggling CS in beetween.

Roughly speaking spi controllers can be divided on 2 categories:
 * spi controllers without dirmap acceleration support
 * spi controllers with dirmap acceleration support

Firt of them will have issues with continuous reading if restriction on
the transfer length is implemented in the adjust_op_size() handler.
Second group often supports acceleration of single page only reading.
Thus enabling of continuous reading can break flash reading.

This patch tries to create dirmap for continuous reading first and
fallback to regular reading if spi controller refuses to create it.

Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com>
drivers/mtd/nand/spi/core.c

index 69dbdd60a6a32d9c038d7a98234189d72217dbfc..68a03ddee8b19e9c8700a5b8145bc044635afeeb 100644 (file)
@@ -1114,6 +1114,37 @@ static int spinand_mtd_block_isreserved(struct mtd_info *mtd, loff_t offs)
        return ret;
 }
 
+static struct spi_mem_dirmap_desc *spinand_create_rdesc(
+                                       struct spinand_device *spinand,
+                                       struct spi_mem_dirmap_info *info)
+{
+       struct nand_device *nand = spinand_to_nand(spinand);
+       struct spi_mem_dirmap_desc *desc = NULL;
+
+       if (spinand->cont_read_possible) {
+               /*
+                * spi controller may return an error if info->length is
+                * too large
+                */
+               info->length = nanddev_eraseblock_size(nand);
+               desc = spi_mem_dirmap_create(spinand->slave, info);
+       }
+
+       if (IS_ERR_OR_NULL(desc)) {
+               /*
+                * continuous reading is not supported by flash or
+                * its spi controller, use regular reading
+                */
+               spinand->cont_read_possible = false;
+
+               info->length = nanddev_page_size(nand) +
+                              nanddev_per_page_oobsize(nand);
+               desc = spi_mem_dirmap_create(spinand->slave, info);
+       }
+
+       return desc;
+}
+
 static int spinand_create_dirmap(struct spinand_device *spinand,
                                 unsigned int plane)
 {
@@ -1132,10 +1163,8 @@ static int spinand_create_dirmap(struct spinand_device *spinand,
 
        spinand->dirmaps[plane].wdesc = desc;
 
-       if (spinand->cont_read_possible)
-               info.length = nanddev_eraseblock_size(nand);
        info.op_tmpl = *spinand->op_templates.read_cache;
-       desc = spi_mem_dirmap_create(spinand->slave, &info);
+       desc = spinand_create_rdesc(spinand, &info);
        if (IS_ERR(desc)) {
                spi_mem_dirmap_destroy(spinand->dirmaps[plane].wdesc);
                return PTR_ERR(desc);