mtd: spi-nor: slightly refactor the spi_nor_setup()
authorMichael Walle <michael@walle.cc>
Wed, 23 Feb 2022 13:43:43 +0000 (14:43 +0100)
committerTudor Ambarus <tudor.ambarus@microchip.com>
Fri, 25 Feb 2022 16:11:11 +0000 (18:11 +0200)
Instead of always using a function pointer (and initializing it to our
default), just call the default function if the flash didn't set its own
one. That will make the call flow easier to follow.

Also mark the parameter as optional now.

Signed-off-by: Michael Walle <michael@walle.cc>
Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Reviewed-by: Pratyush Yadav <p.yadav@ti.com>
Link: https://lore.kernel.org/r/20220223134358.1914798-18-michael@walle.cc
drivers/mtd/spi-nor/core.c
drivers/mtd/spi-nor/core.h

index 04ea180118e33e47d023840124927eca9f326133..4d2036cdce42fb48033d68e7d802d5247369f5d2 100644 (file)
@@ -2532,11 +2532,12 @@ static int spi_nor_setup(struct spi_nor *nor,
 {
        int ret;
 
-       if (nor->params->setup) {
+       if (nor->params->setup)
                ret = nor->params->setup(nor, hwcaps);
-               if (ret)
-                       return ret;
-       }
+       else
+               ret = spi_nor_default_setup(nor, hwcaps);
+       if (ret)
+               return ret;
 
        return spi_nor_set_addr_width(nor);
 }
@@ -2786,7 +2787,6 @@ static void spi_nor_init_default_params(struct spi_nor *nor)
 
        params->quad_enable = spi_nor_sr2_bit1_quad_enable;
        params->set_4byte_addr_mode = spansion_set_4byte_addr_mode;
-       params->setup = spi_nor_default_setup;
        params->otp.org = &info->otp_org;
 
        /* Default to 16-bit Write Status (01h) Command */
index 2afb610853a987fe6760aee3ba081aa2d48db8e5..4fe16b5aa3f5de00bfbe992891d3164596c3fc10 100644 (file)
@@ -257,10 +257,10 @@ struct spi_nor_otp {
  * @convert_addr:      converts an absolute address into something the flash
  *                      will understand. Particularly useful when pagesize is
  *                      not a power-of-2.
- * @setup:              configures the SPI NOR memory. Useful for SPI NOR
- *                      flashes that have peculiarities to the SPI NOR standard
- *                      e.g. different opcodes, specific address calculation,
- *                      page size, etc.
+ * @setup:             (optional) configures the SPI NOR memory. Useful for
+ *                     SPI NOR flashes that have peculiarities to the SPI NOR
+ *                     standard e.g. different opcodes, specific address
+ *                     calculation, page size, etc.
  * @locking_ops:       SPI NOR locking methods.
  */
 struct spi_nor_flash_parameter {