From 6014be589e618e458a8fbbddb3d42e5ec7cd5841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Mon, 14 Mar 2022 14:36:22 +0100 Subject: [PATCH] drivers: nrf_qspi_nor: Exit DPD at driver initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It may happen that after the flash chip was previously put into the Deep Power Down mode, the system was reset but the flash chip was not. Consequently, the flash chip can be in the DPD mode when the QSPI driver is initialized. Some flash chips will just exit the DPD mode on the first CS pulse, but some need to receive the dedicated command to do it and they will not respond to any other commands including those that the driver need to perform to complete its initialization ("Read status register" and "Read JEDEC ID"). This commit adds sending of the "Release from Deep Power Down" command right after initialization of the QSPI interface to avoid the problem described above. Signed-off-by: Andrzej Głąbek --- drivers/flash/nrf_qspi_nor.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/flash/nrf_qspi_nor.c b/drivers/flash/nrf_qspi_nor.c index ca49240e192..691360a9b8e 100644 --- a/drivers/flash/nrf_qspi_nor.c +++ b/drivers/flash/nrf_qspi_nor.c @@ -180,6 +180,10 @@ struct qspi_cmd { static int qspi_nor_write_protection_set(const struct device *dev, bool write_protect); +#ifdef CONFIG_PM_DEVICE +static int exit_dpd(const struct device *const dev); +#endif + /** * @brief Test whether offset is aligned. */ @@ -580,6 +584,19 @@ static int qspi_nrfx_configure(const struct device *dev) } #endif +#ifdef CONFIG_PM_DEVICE + /* It may happen that after the flash chip was previously put into + * the DPD mode, the system was reset but the flash chip was not. + * Consequently, the flash chip can be in the DPD mode at this point. + * Some flash chips will just exit the DPD mode on the first CS pulse, + * but some need to receive the dedicated command to do it, so send it. + */ + ret = exit_dpd(dev); + if (ret < 0) { + return ret; + } +#endif + if (INST_0_QER != JESD216_DW15_QER_NONE) { /* Set QE to match transfer mode. If not using quad * it's OK to leave QE set, but doing so prevents use