]> git.itanic.dy.fi Git - linux-stable/commitdiff
mtd: spi-nor: make sector_size optional
authorMichael Walle <mwalle@kernel.org>
Fri, 8 Sep 2023 10:16:28 +0000 (12:16 +0200)
committerTudor Ambarus <tudor.ambarus@linaro.org>
Tue, 19 Sep 2023 15:56:29 +0000 (18:56 +0300)
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>
drivers/mtd/spi-nor/core.c
drivers/mtd/spi-nor/core.h
drivers/mtd/spi-nor/spansion.c
drivers/mtd/spi-nor/swp.c

index c84be791341e6ae83b43d328fc8d929d7d64efee..368851ff9f40b5320e36b1b318d51d54b99e2957 100644 (file)
@@ -2756,7 +2756,8 @@ static void spi_nor_no_sfdp_init_params(struct spi_nor *nor)
 {
        struct spi_nor_flash_parameter *params = nor->params;
        struct spi_nor_erase_map *map = &params->erase_map;
-       const u8 no_sfdp_flags = nor->info->no_sfdp_flags;
+       const struct flash_info *info = nor->info;
+       const u8 no_sfdp_flags = info->no_sfdp_flags;
        u8 i, erase_mask;
 
        if (no_sfdp_flags & SPI_NOR_DUAL_READ) {
@@ -2810,7 +2811,8 @@ static void spi_nor_no_sfdp_init_params(struct spi_nor *nor)
                i++;
        }
        erase_mask |= BIT(i);
-       spi_nor_set_erase_type(&map->erase_type[i], nor->info->sector_size,
+       spi_nor_set_erase_type(&map->erase_type[i],
+                              info->sector_size ?: SPI_NOR_DEFAULT_SECTOR_SIZE,
                               SPINOR_OP_SE);
        spi_nor_init_uniform_erase_map(map, erase_mask, params->size);
 }
index 8627d0b95be62e6b8bb371c4965b1a79891b7911..fba3ea8536a5ac8bbeb0c67fefbc985fdb0ea4a1 100644 (file)
@@ -16,6 +16,7 @@
  */
 #define SPI_NOR_DEFAULT_PAGE_SIZE 256
 #define SPI_NOR_DEFAULT_N_BANKS 1
+#define SPI_NOR_DEFAULT_SECTOR_SIZE SZ_64K
 
 /* Standard SPI NOR flash operations. */
 #define SPI_NOR_READID_OP(naddr, ndummy, buf, len)                     \
@@ -452,8 +453,9 @@ struct spi_nor_fixups {
  *                  JEDIC ID. JEDEC ID zero means "no ID" (mostly older chips).
  * @id_len:         the number of bytes of ID.
  * @size:           the size of the flash in bytes.
- * @sector_size:    the size listed here is what works with SPINOR_OP_SE, which
- *                  isn't necessarily called a "sector" by the vendor.
+ * @sector_size:    (optional) the size listed here is what works with
+ *                  SPINOR_OP_SE, which isn't necessarily called a "sector" by
+ *                  the vendor. Defaults to 64k.
  * @n_banks:        (optional) the number of banks. Defaults to 1.
  * @page_size:      (optional) the flash's page size. Defaults to 256.
  * @addr_nbytes:    number of address bytes to send.
@@ -565,7 +567,7 @@ struct flash_info {
 
 #define SPI_NOR_GEOMETRY(_sector_size, _n_sectors, _n_banks)           \
        .size = (_sector_size) * (_n_sectors),                          \
-       .sector_size = (_sector_size),                                  \
+       .sector_size = (_sector_size == SZ_64K) ? 0 : (_sector_size),   \
        .n_banks = (_n_banks)
 
 /* Used when the "_ext_id" is two bytes at most */
index 709822fced867f82659b482c718b846261d44c02..ec3172ff5baf9c6aaa031c1e9d3a65e982929226 100644 (file)
@@ -956,7 +956,8 @@ static int spansion_nor_late_init(struct spi_nor *nor)
                nor->flags |= SNOR_F_4B_OPCODES;
                /* No small sector erase for 4-byte command set */
                nor->erase_opcode = SPINOR_OP_SE;
-               nor->mtd.erasesize = nor->info->sector_size;
+               nor->mtd.erasesize = nor->info->sector_size ?:
+                       SPI_NOR_DEFAULT_SECTOR_SIZE;
        }
 
        if (mfr_flags & (USE_CLSR | USE_CLPEF)) {
index 40bf528670950728fd16152766fa47e504415cc0..585813310ee1e0f53a7dc1690c137d2490a873f7 100644 (file)
@@ -34,7 +34,11 @@ static u8 spi_nor_get_sr_tb_mask(struct spi_nor *nor)
 static u64 spi_nor_get_min_prot_length_sr(struct spi_nor *nor)
 {
        unsigned int bp_slots, bp_slots_needed;
-       unsigned int sector_size = nor->info->sector_size;
+       /*
+        * sector_size will eventually be replaced with the max erase size of
+        * the flash. For now, we need to have that ugly default.
+        */
+       unsigned int sector_size = nor->info->sector_size ?: SPI_NOR_DEFAULT_SECTOR_SIZE;
        u64 n_sectors = div_u64(nor->params->size, sector_size);
        u8 mask = spi_nor_get_sr_bp_mask(nor);