Skip to content

Commit 6dec24b

Browse files
mwalleambarus
authored andcommitted
mtd: spi-nor: make sector_size optional
Most of the (old, non-SFDP) flashes use a sector size of 64k. Make that a default value so it can be optional in the flash_info database. As a preparation for conversion to the new database format, set the sector size to zero if the default value is used. This way, the actual change is happening with this patch ant not with a later conversion patch. Signed-off-by: Michael Walle <mwalle@kernel.org> Link: https://lore.kernel.org/r/20230807-mtd-flash-info-db-rework-v3-10-e60548861b10@kernel.org Signed-off-by: Tudor Ambarus <tudor.ambarus@linaro.org>
1 parent 9b6bb07 commit 6dec24b

4 files changed

Lines changed: 16 additions & 7 deletions

File tree

drivers/mtd/spi-nor/core.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2756,7 +2756,8 @@ static void spi_nor_no_sfdp_init_params(struct spi_nor *nor)
27562756
{
27572757
struct spi_nor_flash_parameter *params = nor->params;
27582758
struct spi_nor_erase_map *map = &params->erase_map;
2759-
const u8 no_sfdp_flags = nor->info->no_sfdp_flags;
2759+
const struct flash_info *info = nor->info;
2760+
const u8 no_sfdp_flags = info->no_sfdp_flags;
27602761
u8 i, erase_mask;
27612762

27622763
if (no_sfdp_flags & SPI_NOR_DUAL_READ) {
@@ -2810,7 +2811,8 @@ static void spi_nor_no_sfdp_init_params(struct spi_nor *nor)
28102811
i++;
28112812
}
28122813
erase_mask |= BIT(i);
2813-
spi_nor_set_erase_type(&map->erase_type[i], nor->info->sector_size,
2814+
spi_nor_set_erase_type(&map->erase_type[i],
2815+
info->sector_size ?: SPI_NOR_DEFAULT_SECTOR_SIZE,
28142816
SPINOR_OP_SE);
28152817
spi_nor_init_uniform_erase_map(map, erase_mask, params->size);
28162818
}

drivers/mtd/spi-nor/core.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
#define SPI_NOR_DEFAULT_PAGE_SIZE 256
1818
#define SPI_NOR_DEFAULT_N_BANKS 1
19+
#define SPI_NOR_DEFAULT_SECTOR_SIZE SZ_64K
1920

2021
/* Standard SPI NOR flash operations. */
2122
#define SPI_NOR_READID_OP(naddr, ndummy, buf, len) \
@@ -452,8 +453,9 @@ struct spi_nor_fixups {
452453
* JEDIC ID. JEDEC ID zero means "no ID" (mostly older chips).
453454
* @id_len: the number of bytes of ID.
454455
* @size: the size of the flash in bytes.
455-
* @sector_size: the size listed here is what works with SPINOR_OP_SE, which
456-
* isn't necessarily called a "sector" by the vendor.
456+
* @sector_size: (optional) the size listed here is what works with
457+
* SPINOR_OP_SE, which isn't necessarily called a "sector" by
458+
* the vendor. Defaults to 64k.
457459
* @n_banks: (optional) the number of banks. Defaults to 1.
458460
* @page_size: (optional) the flash's page size. Defaults to 256.
459461
* @addr_nbytes: number of address bytes to send.
@@ -565,7 +567,7 @@ struct flash_info {
565567

566568
#define SPI_NOR_GEOMETRY(_sector_size, _n_sectors, _n_banks) \
567569
.size = (_sector_size) * (_n_sectors), \
568-
.sector_size = (_sector_size), \
570+
.sector_size = (_sector_size == SZ_64K) ? 0 : (_sector_size), \
569571
.n_banks = (_n_banks)
570572

571573
/* Used when the "_ext_id" is two bytes at most */

drivers/mtd/spi-nor/spansion.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,8 @@ static int spansion_nor_late_init(struct spi_nor *nor)
956956
nor->flags |= SNOR_F_4B_OPCODES;
957957
/* No small sector erase for 4-byte command set */
958958
nor->erase_opcode = SPINOR_OP_SE;
959-
nor->mtd.erasesize = nor->info->sector_size;
959+
nor->mtd.erasesize = nor->info->sector_size ?:
960+
SPI_NOR_DEFAULT_SECTOR_SIZE;
960961
}
961962

962963
if (mfr_flags & (USE_CLSR | USE_CLPEF)) {

drivers/mtd/spi-nor/swp.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ static u8 spi_nor_get_sr_tb_mask(struct spi_nor *nor)
3434
static u64 spi_nor_get_min_prot_length_sr(struct spi_nor *nor)
3535
{
3636
unsigned int bp_slots, bp_slots_needed;
37-
unsigned int sector_size = nor->info->sector_size;
37+
/*
38+
* sector_size will eventually be replaced with the max erase size of
39+
* the flash. For now, we need to have that ugly default.
40+
*/
41+
unsigned int sector_size = nor->info->sector_size ?: SPI_NOR_DEFAULT_SECTOR_SIZE;
3842
u64 n_sectors = div_u64(nor->params->size, sector_size);
3943
u8 mask = spi_nor_get_sr_bp_mask(nor);
4044

0 commit comments

Comments
 (0)