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 <vgeneves@kalray.eu>
This commit is contained in:
Vincent Geneves 2023-05-19 16:58:41 +02:00 committed by Maureen Helm
commit 3b3528cd90

View file

@ -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)