mtd: spi-nor: Add support for flash reset
authorSai Krishna Potthuri <sai.krishna.potthuri@amd.com>
Thu, 8 Sep 2022 06:44:28 +0000 (12:14 +0530)
committerTudor Ambarus <tudor.ambarus@microchip.com>
Tue, 25 Oct 2022 02:11:34 +0000 (05:11 +0300)
Add support for spi-nor flash reset via GPIO controller by reading the
reset-gpio property. If there is a valid GPIO specifier then reset will
be performed by asserting and deasserting the GPIO using gpiod APIs
otherwise it will not perform any operation.

Signed-off-by: Sai Krishna Potthuri <sai.krishna.potthuri@amd.com>
Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Reviewed-by: Michael Walle <michael@walle.cc>
Link: https://lore.kernel.org/r/20220908064428.2962-3-sai.krishna.potthuri@amd.com
drivers/mtd/spi-nor/core.c

index f2c6400..a78ab9b 100644 (file)
@@ -2933,6 +2933,27 @@ static void spi_nor_set_mtd_info(struct spi_nor *nor)
        mtd->_put_device = spi_nor_put_device;
 }
 
+static int spi_nor_hw_reset(struct spi_nor *nor)
+{
+       struct gpio_desc *reset;
+
+       reset = devm_gpiod_get_optional(nor->dev, "reset", GPIOD_OUT_LOW);
+       if (IS_ERR_OR_NULL(reset))
+               return PTR_ERR_OR_ZERO(reset);
+
+       /*
+        * Experimental delay values by looking at different flash device
+        * vendors datasheets.
+        */
+       usleep_range(1, 5);
+       gpiod_set_value_cansleep(reset, 1);
+       usleep_range(100, 150);
+       gpiod_set_value_cansleep(reset, 0);
+       usleep_range(1000, 1200);
+
+       return 0;
+}
+
 int spi_nor_scan(struct spi_nor *nor, const char *name,
                 const struct spi_nor_hwcaps *hwcaps)
 {
@@ -2965,6 +2986,10 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
        if (!nor->bouncebuf)
                return -ENOMEM;
 
+       ret = spi_nor_hw_reset(nor);
+       if (ret)
+               return ret;
+
        info = spi_nor_get_flash_info(nor, name);
        if (IS_ERR(info))
                return PTR_ERR(info);