mtd: spi-nor: spansion: Add local function to discover page size
authorTakahiro Kuwano <Takahiro.Kuwano@infineon.com>
Mon, 25 Jul 2022 09:25:04 +0000 (12:25 +0300)
committerTudor Ambarus <tudor.ambarus@microchip.com>
Thu, 28 Jul 2022 02:18:28 +0000 (05:18 +0300)
The page size check in s28hs512t fixup can be used for s25hs/hl-t as well.
Move that to a newly created local function.

Signed-off-by: Takahiro Kuwano <Takahiro.Kuwano@infineon.com>
Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Reviewed-by: Michael Walle <michael@walle.cc>
Link: https://lore.kernel.org/r/20220725092505.446315-7-tudor.ambarus@microchip.com
drivers/mtd/spi-nor/spansion.c

index 43cd6cd..60e41e1 100644 (file)
@@ -114,6 +114,36 @@ static int cypress_nor_octal_dtr_dis(struct spi_nor *nor)
 }
 
 /**
+ * cypress_nor_set_page_size() - Set page size which corresponds to the flash
+ *                               configuration.
+ * @nor:       pointer to a 'struct spi_nor'
+ *
+ * The BFPT table advertises a 512B or 256B page size depending on part but the
+ * page size is actually configurable (with the default being 256B). Read from
+ * CFR3V[4] and set the correct size.
+ *
+ * Return: 0 on success, -errno otherwise.
+ */
+static int cypress_nor_set_page_size(struct spi_nor *nor)
+{
+       struct spi_mem_op op =
+               CYPRESS_NOR_RD_ANY_REG_OP(3, SPINOR_REG_CYPRESS_CFR3V,
+                                         nor->bouncebuf);
+       int ret;
+
+       ret = spi_nor_read_any_reg(nor, &op, nor->reg_proto);
+       if (ret)
+               return ret;
+
+       if (nor->bouncebuf[0] & SPINOR_REG_CYPRESS_CFR3V_PGSZ)
+               nor->params->page_size = 512;
+       else
+               nor->params->page_size = 256;
+
+       return 0;
+}
+
+/**
  * cypress_nor_octal_dtr_enable() - Enable octal DTR on Cypress flashes.
  * @nor:               pointer to a 'struct spi_nor'
  * @enable:              whether to enable or disable Octal DTR
@@ -167,28 +197,7 @@ static int s28hs512t_post_bfpt_fixup(struct spi_nor *nor,
                                     const struct sfdp_parameter_header *bfpt_header,
                                     const struct sfdp_bfpt *bfpt)
 {
-       /*
-        * The BFPT table advertises a 512B page size but the page size is
-        * actually configurable (with the default being 256B). Read from
-        * CFR3V[4] and set the correct size.
-        */
-       struct spi_mem_op op =
-               CYPRESS_NOR_RD_ANY_REG_OP(3, SPINOR_REG_CYPRESS_CFR3V,
-                                         nor->bouncebuf);
-       int ret;
-
-       spi_nor_spimem_setup_op(nor, &op, nor->reg_proto);
-
-       ret = spi_mem_exec_op(nor->spimem, &op);
-       if (ret)
-               return ret;
-
-       if (nor->bouncebuf[0] & SPINOR_REG_CYPRESS_CFR3V_PGSZ)
-               nor->params->page_size = 512;
-       else
-               nor->params->page_size = 256;
-
-       return 0;
+       return cypress_nor_set_page_size(nor);
 }
 
 static const struct spi_nor_fixups s28hs512t_fixups = {