Skip to content

Commit bdd7c43

Browse files
committed
[nrf fromtree] 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). Signed-off-by: Andrzej Głąbek <[email protected]> (cherry picked from commit ff13d40)
1 parent 79bc3aa commit bdd7c43

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
@@ -887,6 +887,77 @@ static int gpio_reset(const struct device *dev)
887887
}
888888
#endif
889889

890+
#if defined(WITH_SOFT_RESET)
891+
static int soft_reset_66_99(const struct device *dev)
892+
{
893+
int rc;
894+
895+
set_up_xfer(dev, MSPI_TX);
896+
rc = perform_xfer(dev, SPI_NOR_CMD_RESET_EN, false);
897+
if (rc < 0) {
898+
LOG_ERR("CMD_RESET_EN failed: %d", rc);
899+
return rc;
900+
}
901+
902+
set_up_xfer(dev, MSPI_TX);
903+
rc = perform_xfer(dev, SPI_NOR_CMD_RESET_MEM, false);
904+
if (rc < 0) {
905+
LOG_ERR("CMD_RESET_MEM failed: %d", rc);
906+
return rc;
907+
}
908+
909+
return 0;
910+
}
911+
912+
static int soft_reset(const struct device *dev)
913+
{
914+
const struct flash_mspi_nor_config *dev_config = dev->config;
915+
struct flash_mspi_nor_data *dev_data = dev->data;
916+
int rc;
917+
918+
/* If the flash may expect commands sent in multi-line mode,
919+
* send additionally the reset sequence this way.
920+
*/
921+
if (dev_config->multi_io_cmd) {
922+
rc = mspi_dev_config(dev_config->bus, &dev_config->mspi_id,
923+
MSPI_DEVICE_CONFIG_IO_MODE,
924+
&dev_config->mspi_nor_cfg);
925+
if (rc < 0) {
926+
LOG_ERR("%s: dev_config() failed: %d", __func__, rc);
927+
return rc;
928+
}
929+
930+
dev_data->in_target_io_mode = true;
931+
932+
rc = soft_reset_66_99(dev);
933+
if (rc < 0) {
934+
return rc;
935+
}
936+
937+
rc = mspi_dev_config(dev_config->bus, &dev_config->mspi_id,
938+
MSPI_DEVICE_CONFIG_IO_MODE,
939+
&dev_config->mspi_nor_init_cfg);
940+
if (rc < 0) {
941+
LOG_ERR("%s: dev_config() failed: %d", __func__, rc);
942+
return rc;
943+
}
944+
945+
dev_data->in_target_io_mode = false;
946+
}
947+
948+
rc = soft_reset_66_99(dev);
949+
if (rc < 0) {
950+
return rc;
951+
}
952+
953+
if (dev_config->reset_recovery_us != 0) {
954+
k_busy_wait(dev_config->reset_recovery_us);
955+
}
956+
957+
return 0;
958+
}
959+
#endif /* WITH_SOFT_RESET */
960+
890961
static int flash_chip_init(const struct device *dev)
891962
{
892963
const struct flash_mspi_nor_config *dev_config = dev->config;
@@ -938,6 +1009,15 @@ static int flash_chip_init(const struct device *dev)
9381009
}
9391010
#endif
9401011

1012+
#if defined(WITH_SOFT_RESET)
1013+
if (dev_config->initial_soft_reset) {
1014+
rc = soft_reset(dev);
1015+
if (rc < 0) {
1016+
return rc;
1017+
}
1018+
}
1019+
#endif
1020+
9411021
if (dev_config->quirks != NULL &&
9421022
dev_config->quirks->pre_init != NULL) {
9431023
rc = dev_config->quirks->pre_init(dev);
@@ -1212,10 +1292,10 @@ BUILD_ASSERT((FLASH_SIZE(inst) % CONFIG_FLASH_MSPI_NOR_LAYOUT_PAGE_SIZE) == 0, \
12121292
(.xip_cfg = MSPI_XIP_CONFIG_DT_INST(inst),)) \
12131293
IF_ENABLED(WITH_RESET_GPIO, \
12141294
(.reset = GPIO_DT_SPEC_INST_GET_OR(inst, reset_gpios, {0}), \
1215-
.reset_pulse_us = DT_INST_PROP_OR(inst, t_reset_pulse, 0) \
1216-
/ 1000, \
1295+
.reset_pulse_us = DT_INST_PROP_OR(inst, t_reset_pulse, 0) \
1296+
/ 1000,)) \
12171297
.reset_recovery_us = DT_INST_PROP_OR(inst, t_reset_recovery, 0) \
1218-
/ 1000,)) \
1298+
/ 1000, \
12191299
.transfer_timeout = DT_INST_PROP(inst, transfer_timeout), \
12201300
FLASH_PAGE_LAYOUT_DEFINE(inst) \
12211301
.jedec_id = DT_INST_PROP_OR(inst, jedec_id, {0}), \
@@ -1228,6 +1308,7 @@ BUILD_ASSERT((FLASH_SIZE(inst) % CONFIG_FLASH_MSPI_NOR_LAYOUT_PAGE_SIZE) == 0, \
12281308
.multiperipheral_bus = DT_PROP(DT_INST_BUS(inst), \
12291309
software_multiperipheral), \
12301310
IO_MODE_FLAGS(DT_INST_ENUM_IDX(inst, mspi_io_mode)), \
1311+
.initial_soft_reset = DT_INST_PROP(inst, initial_soft_reset), \
12311312
}; \
12321313
FLASH_PAGE_LAYOUT_CHECK(inst) \
12331314
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
@@ -75,8 +78,8 @@ struct flash_mspi_nor_config {
7578
#if defined(WITH_RESET_GPIO)
7679
struct gpio_dt_spec reset;
7780
uint32_t reset_pulse_us;
78-
uint32_t reset_recovery_us;
7981
#endif
82+
uint32_t reset_recovery_us;
8083
uint32_t transfer_timeout;
8184
#if defined(CONFIG_FLASH_PAGE_LAYOUT)
8285
struct flash_pages_layout layout;
@@ -91,6 +94,7 @@ struct flash_mspi_nor_config {
9194
bool multiperipheral_bus : 1;
9295
bool multi_io_cmd : 1;
9396
bool single_io_addr : 1;
97+
bool initial_soft_reset : 1;
9498
};
9599

96100
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
@@ -6,6 +6,8 @@
66

77
#ifdef CONFIG_FLASH_MSPI_NOR_USE_SFDP
88

9+
#define BFP_DW16_SOFT_RESET_66_99 BIT(4)
10+
911
#define BFP_DW16_4B_ADDR_ENTER_B7 BIT(0)
1012
#define BFP_DW16_4B_ADDR_ENTER_06_B7 BIT(1)
1113
#define BFP_DW16_4B_ADDR_PER_CMD BIT(5)
@@ -359,6 +361,11 @@
359361
BFP_DW16_4B_ADDR_PER_CMD | \
360362
BFP_DW16_4B_ADDR_ALWAYS)), \
361363
"No supported method of entering 4-byte addressing mode for " \
364+
DT_NODE_FULL_NAME(DT_DRV_INST(inst))); \
365+
BUILD_ASSERT(!DT_INST_PROP(inst, initial_soft_reset) || \
366+
(SFDP_FIELD(inst, sfdp_bfp, 16, GENMASK(13, 8)) \
367+
& BFP_DW16_SOFT_RESET_66_99), \
368+
"Cannot use 66h/99h soft reset sequence for " \
362369
DT_NODE_FULL_NAME(DT_DRV_INST(inst)))
363370

364371
#else

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,9 @@ properties:
5252
codes for commands that require addresses (like Read, Page Program,
5353
or Erase) if those are supported by the flash chip, or if necessary,
5454
it will switch the chip to 4-byte addressing mode.
55+
56+
initial-soft-reset:
57+
type: boolean
58+
description: |
59+
When set, the flash driver performs software reset of the flash chip
60+
at initialization.

0 commit comments

Comments
 (0)