Skip to content

Commit 08c5be2

Browse files
committed
[nrf fromlist] drivers: flash_mspi_nor: Add Soft Reset
Add implementation of the most common Soft Reset routine (sequence of reset enable instruction 0x66 and reset instruction 0x99). Upstream PR #: 93093 Signed-off-by: Andrzej Głąbek <[email protected]>
1 parent 5a16efa commit 08c5be2

File tree

4 files changed

+102
-4
lines changed

4 files changed

+102
-4
lines changed

drivers/flash/flash_mspi_nor.c

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,77 @@ static int gpio_reset(const struct device *dev)
849849
}
850850
#endif
851851

852+
#if defined(WITH_SOFT_RESET)
853+
static int soft_reset_66_99(const struct device *dev)
854+
{
855+
int rc;
856+
857+
set_up_xfer(dev, MSPI_TX);
858+
rc = perform_xfer(dev, SPI_NOR_CMD_RESET_EN, false);
859+
if (rc < 0) {
860+
LOG_ERR("CMD_RESET_EN failed: %d", rc);
861+
return rc;
862+
}
863+
864+
set_up_xfer(dev, MSPI_TX);
865+
rc = perform_xfer(dev, SPI_NOR_CMD_RESET_MEM, false);
866+
if (rc < 0) {
867+
LOG_ERR("CMD_RESET_MEM failed: %d", rc);
868+
return rc;
869+
}
870+
871+
return 0;
872+
}
873+
874+
static int soft_reset(const struct device *dev)
875+
{
876+
const struct flash_mspi_nor_config *dev_config = dev->config;
877+
struct flash_mspi_nor_data *dev_data = dev->data;
878+
int rc;
879+
880+
/* If the flash may expect commands sent in multi-line mode,
881+
* send additionally the reset sequence this way.
882+
*/
883+
if (dev_config->multi_io_cmd) {
884+
rc = mspi_dev_config(dev_config->bus, &dev_config->mspi_id,
885+
MSPI_DEVICE_CONFIG_IO_MODE,
886+
&dev_config->mspi_nor_cfg);
887+
if (rc < 0) {
888+
LOG_ERR("%s: dev_config() failed: %d", __func__, rc);
889+
return rc;
890+
}
891+
892+
dev_data->in_target_io_mode = true;
893+
894+
rc = soft_reset_66_99(dev);
895+
if (rc < 0) {
896+
return rc;
897+
}
898+
899+
rc = mspi_dev_config(dev_config->bus, &dev_config->mspi_id,
900+
MSPI_DEVICE_CONFIG_IO_MODE,
901+
&dev_config->mspi_nor_init_cfg);
902+
if (rc < 0) {
903+
LOG_ERR("%s: dev_config() failed: %d", __func__, rc);
904+
return rc;
905+
}
906+
907+
dev_data->in_target_io_mode = false;
908+
}
909+
910+
rc = soft_reset_66_99(dev);
911+
if (rc < 0) {
912+
return rc;
913+
}
914+
915+
if (dev_config->reset_recovery_us != 0) {
916+
k_busy_wait(dev_config->reset_recovery_us);
917+
}
918+
919+
return 0;
920+
}
921+
#endif /* WITH_SOFT_RESET */
922+
852923
static int flash_chip_init(const struct device *dev)
853924
{
854925
const struct flash_mspi_nor_config *dev_config = dev->config;
@@ -897,6 +968,15 @@ static int flash_chip_init(const struct device *dev)
897968
}
898969
#endif
899970

971+
#if defined(WITH_SOFT_RESET)
972+
if (dev_config->initial_soft_reset) {
973+
rc = soft_reset(dev);
974+
if (rc < 0) {
975+
return rc;
976+
}
977+
}
978+
#endif
979+
900980
if (dev_config->quirks != NULL &&
901981
dev_config->quirks->pre_init != NULL) {
902982
rc = dev_config->quirks->pre_init(dev);
@@ -1117,10 +1197,10 @@ BUILD_ASSERT((FLASH_SIZE(inst) % CONFIG_FLASH_MSPI_NOR_LAYOUT_PAGE_SIZE) == 0, \
11171197
(.xip_cfg = MSPI_XIP_CONFIG_DT_INST(inst),)) \
11181198
IF_ENABLED(WITH_RESET_GPIO, \
11191199
(.reset = GPIO_DT_SPEC_INST_GET_OR(inst, reset_gpios, {0}), \
1120-
.reset_pulse_us = DT_INST_PROP_OR(inst, t_reset_pulse, 0) \
1121-
/ 1000, \
1200+
.reset_pulse_us = DT_INST_PROP_OR(inst, t_reset_pulse, 0) \
1201+
/ 1000,)) \
11221202
.reset_recovery_us = DT_INST_PROP_OR(inst, t_reset_recovery, 0) \
1123-
/ 1000,)) \
1203+
/ 1000, \
11241204
.transfer_timeout = DT_INST_PROP(inst, transfer_timeout), \
11251205
FLASH_PAGE_LAYOUT_DEFINE(inst) \
11261206
.jedec_id = DT_INST_PROP(inst, jedec_id), \
@@ -1135,6 +1215,7 @@ BUILD_ASSERT((FLASH_SIZE(inst) % CONFIG_FLASH_MSPI_NOR_LAYOUT_PAGE_SIZE) == 0, \
11351215
.multiperipheral_bus = DT_PROP(DT_INST_BUS(inst), \
11361216
software_multiperipheral), \
11371217
IO_MODE_FLAGS(DT_INST_ENUM_IDX(inst, mspi_io_mode)), \
1218+
.initial_soft_reset = DT_INST_PROP(inst, initial_soft_reset), \
11381219
}; \
11391220
FLASH_PAGE_LAYOUT_CHECK(inst) \
11401221
DEVICE_DT_INST_DEFINE(inst, \

drivers/flash/flash_mspi_nor.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ extern "C" {
1919
#if DT_ANY_INST_HAS_PROP_STATUS_OKAY(reset_gpios)
2020
#define WITH_RESET_GPIO 1
2121
#endif
22+
#if DT_ANY_INST_HAS_BOOL_STATUS_OKAY(initial_soft_reset)
23+
#define WITH_SOFT_RESET 1
24+
#endif
2225

2326
#define CMD_EXTENSION_NONE 0
2427
#define CMD_EXTENSION_SAME 1
@@ -72,8 +75,8 @@ struct flash_mspi_nor_config {
7275
#if defined(WITH_RESET_GPIO)
7376
struct gpio_dt_spec reset;
7477
uint32_t reset_pulse_us;
75-
uint32_t reset_recovery_us;
7678
#endif
79+
uint32_t reset_recovery_us;
7780
uint32_t transfer_timeout;
7881
#if defined(CONFIG_FLASH_PAGE_LAYOUT)
7982
struct flash_pages_layout layout;
@@ -89,6 +92,7 @@ struct flash_mspi_nor_config {
8992
bool multiperipheral_bus : 1;
9093
bool multi_io_cmd : 1;
9194
bool single_io_addr : 1;
95+
bool initial_soft_reset : 1;
9296
};
9397

9498
struct flash_mspi_nor_data {

drivers/flash/flash_mspi_nor_sfdp.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
#define BFP_DW16_SOFT_RESET_66_99 BIT(4)
8+
79
#define BFP_DW16_4B_ADDR_ENTER_B7 BIT(0)
810
#define BFP_DW16_4B_ADDR_ENTER_06_B7 BIT(1)
911
#define BFP_DW16_4B_ADDR_PER_CMD BIT(5)
@@ -342,4 +344,9 @@
342344
BFP_DW16_4B_ADDR_PER_CMD | \
343345
BFP_DW16_4B_ADDR_ALWAYS)), \
344346
"No supported method of entering 4-byte addressing mode for " \
347+
DT_NODE_FULL_NAME(DT_DRV_INST(inst))); \
348+
BUILD_ASSERT(!DT_INST_PROP(inst, initial_soft_reset) || \
349+
(SFDP_FIELD(inst, sfdp_bfp, 16, GENMASK(13, 8)) \
350+
& BFP_DW16_SOFT_RESET_66_99), \
351+
"Cannot use 66h/99h soft reset sequence for " \
345352
DT_NODE_FULL_NAME(DT_DRV_INST(inst)))

dts/bindings/mtd/jedec,mspi-nor.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,9 @@ properties:
3838
the flash chip. The driver will use dedicated instruction codes for
3939
commands that require addresses (like Read, Page Program, or Erase)
4040
and will switch the flash chip to 4-byte addressing mode if necessary.
41+
42+
initial-soft-reset:
43+
type: boolean
44+
description: |
45+
When set, the flash driver performs software reset of the flash chip
46+
at initialization.

0 commit comments

Comments
 (0)