Skip to content

Commit 9b6bb07

Browse files
mwalleambarus
authored andcommitted
mtd: spi-nor: push 4k SE handling into spi_nor_select_uniform_erase()
4k sector erase sizes are only a thing with uniform erase types. Push the "we want 4k erase sizes" handling into spi_nor_select_uniform_erase(). One might wonder why the former sector_size isn't used anymore. It is because we either search for the largest erase size or if selected through kconfig, the 4k erase size. Now, why is that correct? For this, we have to differentiate between (1) flashes with SFDP and (2) without SFDP. For (1), we just set one (or two if SECT_4K is set) erase types and wanted_size is exactly one of these. For (2) things are a bit more complicated. For flashes which we don't have in our flash_info database, the generic driver is used and sector_size was already 0, which in turn selected the largest erase size. For flashes which had SFDP and an entry in flash_info, sector_size was always the largest sector and thus the largest erase type. Signed-off-by: Michael Walle <mwalle@kernel.org> Link: https://lore.kernel.org/r/20230807-mtd-flash-info-db-rework-v3-9-e60548861b10@kernel.org Signed-off-by: Tudor Ambarus <tudor.ambarus@linaro.org>
1 parent e255a79 commit 9b6bb07

1 file changed

Lines changed: 9 additions & 18 deletions

File tree

drivers/mtd/spi-nor/core.c

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2512,27 +2512,23 @@ static int spi_nor_select_pp(struct spi_nor *nor,
25122512
/**
25132513
* spi_nor_select_uniform_erase() - select optimum uniform erase type
25142514
* @map: the erase map of the SPI NOR
2515-
* @wanted_size: the erase type size to search for. Contains the value of
2516-
* info->sector_size, the "small sector" size in case
2517-
* CONFIG_MTD_SPI_NOR_USE_4K_SECTORS is defined or 0 if
2518-
* there is no information about the sector size. The
2519-
* latter is the case if the flash parameters are parsed
2520-
* solely by SFDP, then the largest supported erase type
2521-
* is selected.
25222515
*
25232516
* Once the optimum uniform sector erase command is found, disable all the
25242517
* other.
25252518
*
25262519
* Return: pointer to erase type on success, NULL otherwise.
25272520
*/
25282521
static const struct spi_nor_erase_type *
2529-
spi_nor_select_uniform_erase(struct spi_nor_erase_map *map,
2530-
const u32 wanted_size)
2522+
spi_nor_select_uniform_erase(struct spi_nor_erase_map *map)
25312523
{
25322524
const struct spi_nor_erase_type *tested_erase, *erase = NULL;
25332525
int i;
25342526
u8 uniform_erase_type = map->uniform_erase_type;
25352527

2528+
/*
2529+
* Search for the biggest erase size, except for when compiled
2530+
* to use 4k erases.
2531+
*/
25362532
for (i = SNOR_ERASE_TYPE_MAX - 1; i >= 0; i--) {
25372533
if (!(uniform_erase_type & BIT(i)))
25382534
continue;
@@ -2544,10 +2540,11 @@ spi_nor_select_uniform_erase(struct spi_nor_erase_map *map,
25442540
continue;
25452541

25462542
/*
2547-
* If the current erase size is the one, stop here:
2543+
* If the current erase size is the 4k one, stop here,
25482544
* we have found the right uniform Sector Erase command.
25492545
*/
2550-
if (tested_erase->size == wanted_size) {
2546+
if (IS_ENABLED(CONFIG_MTD_SPI_NOR_USE_4K_SECTORS) &&
2547+
tested_erase->size == SZ_4K) {
25512548
erase = tested_erase;
25522549
break;
25532550
}
@@ -2575,7 +2572,6 @@ static int spi_nor_select_erase(struct spi_nor *nor)
25752572
struct spi_nor_erase_map *map = &nor->params->erase_map;
25762573
const struct spi_nor_erase_type *erase = NULL;
25772574
struct mtd_info *mtd = &nor->mtd;
2578-
u32 wanted_size = nor->info->sector_size;
25792575
int i;
25802576

25812577
/*
@@ -2586,13 +2582,8 @@ static int spi_nor_select_erase(struct spi_nor *nor)
25862582
* manage the SPI flash memory as uniform with a single erase sector
25872583
* size, when possible.
25882584
*/
2589-
#ifdef CONFIG_MTD_SPI_NOR_USE_4K_SECTORS
2590-
/* prefer "small sector" erase if possible */
2591-
wanted_size = 4096u;
2592-
#endif
2593-
25942585
if (spi_nor_has_uniform_erase(nor)) {
2595-
erase = spi_nor_select_uniform_erase(map, wanted_size);
2586+
erase = spi_nor_select_uniform_erase(map);
25962587
if (!erase)
25972588
return -EINVAL;
25982589
nor->erase_opcode = erase->opcode;

0 commit comments

Comments
 (0)