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 togling 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 Usually, first of them have no issues with large reading support. 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.kshevets...@iopsys.eu> --- drivers/mtd/nand/spi/core.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c index 07ea66825d5..e9ca2b3c391 100644 --- a/drivers/mtd/nand/spi/core.c +++ b/drivers/mtd/nand/spi/core.c @@ -1131,10 +1131,30 @@ static int spinand_create_dirmap(struct spinand_device *spinand, spinand->dirmaps[plane].wdesc = desc; - if (spinand->cont_read_possible) + desc = NULL; + if (spinand->cont_read_possible) { + /* + * spi-controllers may return an error if info.length is + * too large + */ info.length = nanddev_eraseblock_size(nand); - info.op_tmpl = *spinand->op_templates.read_cache; - desc = spi_mem_dirmap_create(spinand->slave, &info); + info.op_tmpl = *spinand->op_templates.read_cache; + 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, try regular reading + */ + spinand->cont_read_possible = false; + + info.length = nanddev_page_size(nand) + + nanddev_per_page_oobsize(nand); + info.op_tmpl = *spinand->op_templates.read_cache; + desc = spi_mem_dirmap_create(spinand->slave, &info); + } + if (IS_ERR(desc)) { spi_mem_dirmap_destroy(spinand->dirmaps[plane].wdesc); return PTR_ERR(desc); -- 2.47.2