[PATCH v3 3/3] mtd: spi-nor: allow overriding uniform erase

Thibaut VARÈNE hacks+kernel at slashdirt.org
Fri Jul 29 02:16:36 PDT 2022


This patch introduces a new CONFIG_MTD_SPI_NOR_USE_VARIABLE_ERASE option
which forces an SPI NOR mtd device to use non-uniform erase, enabling
(on supporting hardware) to complete erase operations using all
available erasesizes through spi_nor_erase_multi_sectors().

The majority of current SPI NOR devices support multiple erasesizes:
instead of forcing all operations to use 4K erase size for everything
(using CONFIG_MTD_SPI_NOR_USE_4K_SECTORS) when write access to a
minor-aligned partition is needed, this patch allows the kernel to use
the largest suitable erase size for a given operation, thus improving
performance.

Signed-off-by: John Thomson <git at johnthomson.fastmail.com.au>
Signed-off-by: Thibaut VARÈNE <hacks+kernel at slashdirt.org>
---
 drivers/mtd/spi-nor/Kconfig | 10 ++++++++++
 drivers/mtd/spi-nor/core.c  |  2 ++
 2 files changed, 12 insertions(+)

diff --git a/drivers/mtd/spi-nor/Kconfig b/drivers/mtd/spi-nor/Kconfig
index 24cd25de2..09df9f1a8 100644
--- a/drivers/mtd/spi-nor/Kconfig
+++ b/drivers/mtd/spi-nor/Kconfig
@@ -10,6 +10,16 @@ menuconfig MTD_SPI_NOR
 
 if MTD_SPI_NOR
 
+config MTD_SPI_NOR_USE_VARIABLE_ERASE
+	bool "Disable uniform_erase to allow use of all hardware supported erasesizes"
+	depends on !MTD_SPI_NOR_USE_4K_SECTORS
+	default n
+	help
+	  Allow mixed use of all hardware supported erasesizes,
+	  by forcing spi_nor to use the multiple eraseregions code path.
+	  For example: A 68K erase will use one 64K erase, and one 4K erase
+	  on supporting hardware.
+
 config MTD_SPI_NOR_USE_4K_SECTORS
 	bool "Use small 4096 B erase sectors"
 	default y
diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index bafd3396e..b4b539a9f 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -1048,6 +1048,8 @@ static u8 spi_nor_convert_3to4_erase(u8 opcode)
 
 static bool spi_nor_has_uniform_erase(const struct spi_nor *nor)
 {
+	if (IS_ENABLED(CONFIG_MTD_SPI_NOR_USE_VARIABLE_ERASE))
+		return false;
 	return !!nor->params->erase_map.uniform_erase_type;
 }
 
-- 
2.30.2




More information about the linux-mtd mailing list