From 3b3528cd90802b1275e2db10c43b23349b102067 Mon Sep 17 00:00:00 2001 From: Vincent Geneves Date: Fri, 19 May 2023 16:58:41 +0200 Subject: [PATCH] drivers: flash: spi_nor: Add reset pin Add Reset pin initialization during Spi NOR driver start-up. Toggle the pin to reset the device. Signed-off-by: Vincent Geneves --- drivers/flash/spi_nor.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/flash/spi_nor.c b/drivers/flash/spi_nor.c index 994aedd3d21..f4b74451acf 100644 --- a/drivers/flash/spi_nor.c +++ b/drivers/flash/spi_nor.c @@ -67,6 +67,10 @@ struct spi_nor_config { /* Devicetree SPI configuration */ struct spi_dt_spec spi; +#if DT_INST_NODE_HAS_PROP(0, reset_gpios) + const struct gpio_dt_spec reset; +#endif + /* Runtime SFDP stores no static configuration. */ #ifndef CONFIG_SPI_NOR_SFDP_RUNTIME @@ -1144,6 +1148,23 @@ static int spi_nor_configure(const struct device *dev) return -ENODEV; } +#if DT_INST_NODE_HAS_PROP(0, reset_gpios) + if (cfg->reset) { + if (!device_is_ready(cfg->reset->port)) { + LOG_ERR("Reset pin not ready"); + return -ENODEV; + } + if (gpio_pin_configure_dt(cfg->reset, GPIO_OUTPUT_ACTIVE)) { + LOG_ERR("Couldn't configure reset pin"); + return -ENODEV; + } + rc = gpio_pin_set_dt(cfg->reset, 0); + if (rc) { + return rc; + } + } +#endif + /* After a soft-reset the flash might be in DPD or busy writing/erasing. * Exit DPD and wait until flash is ready. */ @@ -1405,6 +1426,10 @@ BUILD_ASSERT(DT_INST_PROP(0, has_lock) == (DT_INST_PROP(0, has_lock) & 0xFF), static const struct spi_nor_config spi_nor_config_0 = { .spi = SPI_DT_SPEC_INST_GET(0, SPI_WORD_SET(8), CONFIG_SPI_NOR_CS_WAIT_DELAY), +#if DT_INST_NODE_HAS_PROP(0, reset_gpios) + .reset = GPIO_DT_SPEC_INST_GET(0, reset_gpios) +#endif + #if !defined(CONFIG_SPI_NOR_SFDP_RUNTIME) #if defined(CONFIG_FLASH_PAGE_LAYOUT)