[PATCH 7/9] mtd: spi-nor: Rewrite rem_bank_len calculation

Marek Vasut marek.vasut+renesas at mailbox.org
Sat Oct 26 22:16:24 CEST 2024


Rewrite the code to make it clear exactly where the
SNOR_F_HAS_PARALLEL flag leads to *2 and /2 operation
compared to regular code path. No functional change.

Fixes: 5d40b3d384dc ("mtd: spi-nor: Add parallel and stacked memories support")
Signed-off-by: Marek Vasut <marek.vasut+renesas at mailbox.org>
---
Cc: Andre Przywara <andre.przywara at arm.com>
Cc: Ashok Reddy Soma <ashok.reddy.soma at amd.com>
Cc: Jagan Teki <jagan at amarulasolutions.com>
Cc: Michael Walle <mwalle at kernel.org>
Cc: Michal Simek <michal.simek at amd.com>
Cc: Patrice Chotard <patrice.chotard at foss.st.com>
Cc: Patrick Delaunay <patrick.delaunay at foss.st.com>
Cc: Pratyush Yadav <p.yadav at ti.com>
Cc: Quentin Schulz <quentin.schulz at cherry.de>
Cc: Sean Anderson <seanga2 at gmail.com>
Cc: Simon Glass <sjg at chromium.org>
Cc: Takahiro Kuwano <Takahiro.Kuwano at infineon.com>
Cc: Tom Rini <trini at konsulko.com>
Cc: Tudor Ambarus <tudor.ambarus at linaro.org>
Cc: Venkatesh Yadav Abbarapu <venkatesh.abbarapu at amd.com>
Cc: u-boot at lists.denx.de
Cc: uboot-stm32 at st-md-mailman.stormreply.com
---
 drivers/mtd/spi/spi-nor-core.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c
index e49b7cad023..c1ee466bcc0 100644
--- a/drivers/mtd/spi/spi-nor-core.c
+++ b/drivers/mtd/spi/spi-nor-core.c
@@ -1593,13 +1593,14 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,
 	}
 
 	while (len) {
-		if (nor->flags & SNOR_F_HAS_PARALLEL) {
-			bank = (u32)from / (SZ_16M << 0x01);
-			rem_bank_len = ((SZ_16M << 0x01) * (bank + 1)) - from;
-		} else {
-			bank = (u32)from / SZ_16M;
-			rem_bank_len = (SZ_16M * (bank + 1)) - from;
-		}
+		bank = (u32)from / SZ_16M;
+		if (nor->flags & SNOR_F_HAS_PARALLEL)
+			bank /= 2;
+
+		rem_bank_len = SZ_16M * (bank + 1);
+		if (nor->flags & SNOR_F_HAS_PARALLEL)
+			rem_bank_len *= 2;
+		rem_bank_len -= from;
 
 		offset = from;
 
-- 
2.45.2



More information about the U-Boot mailing list