mtd: spi-nor: Introduce spi_nor_init_fixup_flags()
authorTudor Ambarus <tudor.ambarus@microchip.com>
Tue, 7 Dec 2021 14:02:48 +0000 (16:02 +0200)
committerTudor Ambarus <tudor.ambarus@microchip.com>
Tue, 7 Dec 2021 15:05:11 +0000 (17:05 +0200)
Group NOR flags initialization. Introduce a dedicated function for
setting the fixup_flags and emphasise when those flash_info flags
should be set: when the SNOR_F_4B_OPCODES/SNOR_F_IO_MODE_EN_VOLATILE
setttings can not be discovered by SFDP for this particular flash
because the SFDP table that indicates this support is not defined
in the flash.
In case the table for his support is defined but has wrong values,
one should instead use a post_sfdp() hook to set the SNOR_F equivalent
flag.

No functional change intended in this patch.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Reviewed-by: Pratyush Yadav <p.yadav@ti.com>
Link: https://lore.kernel.org/r/20211207140254.87681-9-tudor.ambarus@microchip.com
drivers/mtd/spi-nor/core.c

index 1ac7e8de4b8eb0afbfb00d4d1edaf27c0949b672..86bbd1ca22fc10b71611cb0f61000c03d540cb41 100644 (file)
@@ -2692,6 +2692,25 @@ static void spi_nor_init_flags(struct spi_nor *nor)
                nor->flags |=  SNOR_F_READY_XSR_RDY;
 }
 
+/**
+ * spi_nor_init_fixup_flags() - Initialize NOR flags for settings that can not
+ * be discovered by SFDP for this particular flash because the SFDP table that
+ * indicates this support is not defined in the flash. In case the table for
+ * this support is defined but has wrong values, one should instead use a
+ * post_sfdp() hook to set the SNOR_F equivalent flag.
+ * @nor:       pointer to a 'struct spi_nor'
+ */
+static void spi_nor_init_fixup_flags(struct spi_nor *nor)
+{
+       const u8 fixup_flags = nor->info->fixup_flags;
+
+       if (fixup_flags & SPI_NOR_4B_OPCODES)
+               nor->flags |= SNOR_F_4B_OPCODES;
+
+       if (fixup_flags & SPI_NOR_IO_MODE_EN_VOLATILE)
+               nor->flags |= SNOR_F_IO_MODE_EN_VOLATILE;
+}
+
 /**
  * spi_nor_late_init_params() - Late initialization of default flash parameters.
  * @nor:       pointer to a 'struct spi_nor'
@@ -2710,6 +2729,7 @@ static void spi_nor_late_init_params(struct spi_nor *nor)
                nor->info->fixups->late_init(nor);
 
        spi_nor_init_flags(nor);
+       spi_nor_init_fixup_flags(nor);
 
        /*
         * NOR protection support. When locking_ops are not provided, we pick
@@ -3147,7 +3167,6 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
        struct mtd_info *mtd = &nor->mtd;
        int ret;
        int i;
-       u8 fixup_flags;
 
        ret = spi_nor_check(nor);
        if (ret)
@@ -3197,13 +3216,6 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
        if (ret)
                return ret;
 
-       fixup_flags = info->fixup_flags;
-       if (fixup_flags & SPI_NOR_4B_OPCODES)
-               nor->flags |= SNOR_F_4B_OPCODES;
-
-       if (fixup_flags & SPI_NOR_IO_MODE_EN_VOLATILE)
-               nor->flags |= SNOR_F_IO_MODE_EN_VOLATILE;
-
        ret = spi_nor_set_addr_width(nor);
        if (ret)
                return ret;