Skip to content

Commit 81ae924

Browse files
committed
[nrf fromlist] drivers: flash_mspi_nor: Add support for "supply-gpios" property
Add support for supplying power to the flash chip by activation of a GPIO specified through the "supply-gpios" property. Implementation of gpio_reset() is also slightly modified so that it is consistent with soft_reset() and the new power_supply() and so that all these functions can use a common routine that performs a reset recovery delay. Upstream PR #: 93093 Signed-off-by: Andrzej Głąbek <[email protected]>
1 parent 5c268bc commit 81ae924

File tree

3 files changed

+73
-32
lines changed

3 files changed

+73
-32
lines changed

drivers/flash/flash_mspi_nor.c

Lines changed: 65 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -810,39 +810,54 @@ static int switch_to_target_io_mode(const struct device *dev)
810810
&dev_config->mspi_nor_cfg);
811811
}
812812

813+
#if defined(WITH_SUPPLY_GPIO)
814+
static int power_supply(const struct device *dev)
815+
{
816+
const struct flash_mspi_nor_config *dev_config = dev->config;
817+
int rc;
818+
819+
if (!gpio_is_ready_dt(&dev_config->supply)) {
820+
LOG_ERR("Device %s is not ready",
821+
dev_config->supply.port->name);
822+
return -ENODEV;
823+
}
824+
825+
rc = gpio_pin_configure_dt(&dev_config->supply, GPIO_OUTPUT_ACTIVE);
826+
if (rc < 0) {
827+
LOG_ERR("Failed to activate power supply GPIO: %d", rc);
828+
return -EIO;
829+
}
830+
831+
return 0;
832+
}
833+
#endif
834+
813835
#if defined(WITH_RESET_GPIO)
814836
static int gpio_reset(const struct device *dev)
815837
{
816838
const struct flash_mspi_nor_config *dev_config = dev->config;
817839
int rc;
818840

819-
if (dev_config->reset.port) {
820-
if (!gpio_is_ready_dt(&dev_config->reset)) {
821-
LOG_ERR("Device %s is not ready",
822-
dev_config->reset.port->name);
823-
return -ENODEV;
824-
}
825-
826-
rc = gpio_pin_configure_dt(&dev_config->reset,
827-
GPIO_OUTPUT_ACTIVE);
828-
if (rc < 0) {
829-
LOG_ERR("Failed to activate RESET: %d", rc);
830-
return -EIO;
831-
}
841+
if (!gpio_is_ready_dt(&dev_config->reset)) {
842+
LOG_ERR("Device %s is not ready",
843+
dev_config->reset.port->name);
844+
return -ENODEV;
845+
}
832846

833-
if (dev_config->reset_pulse_us != 0) {
834-
k_busy_wait(dev_config->reset_pulse_us);
835-
}
847+
rc = gpio_pin_configure_dt(&dev_config->reset, GPIO_OUTPUT_ACTIVE);
848+
if (rc < 0) {
849+
LOG_ERR("Failed to activate RESET: %d", rc);
850+
return -EIO;
851+
}
836852

837-
rc = gpio_pin_set_dt(&dev_config->reset, 0);
838-
if (rc < 0) {
839-
LOG_ERR("Failed to deactivate RESET: %d", rc);
840-
return -EIO;
841-
}
853+
if (dev_config->reset_pulse_us != 0) {
854+
k_busy_wait(dev_config->reset_pulse_us);
855+
}
842856

843-
if (dev_config->reset_recovery_us != 0) {
844-
k_busy_wait(dev_config->reset_recovery_us);
845-
}
857+
rc = gpio_pin_set_dt(&dev_config->reset, 0);
858+
if (rc < 0) {
859+
LOG_ERR("Failed to deactivate RESET: %d", rc);
860+
return -EIO;
846861
}
847862

848863
return 0;
@@ -912,10 +927,6 @@ static int soft_reset(const struct device *dev)
912927
return rc;
913928
}
914929

915-
if (dev_config->reset_recovery_us != 0) {
916-
k_busy_wait(dev_config->reset_recovery_us);
917-
}
918-
919930
return 0;
920931
}
921932
#endif /* WITH_SOFT_RESET */
@@ -925,6 +936,7 @@ static int flash_chip_init(const struct device *dev)
925936
const struct flash_mspi_nor_config *dev_config = dev->config;
926937
struct flash_mspi_nor_data *dev_data = dev->data;
927938
uint8_t id[JESD216_READ_ID_LEN] = {0};
939+
bool flash_reset = false;
928940
int rc;
929941

930942
rc = mspi_dev_config(dev_config->bus, &dev_config->mspi_id,
@@ -936,12 +948,25 @@ static int flash_chip_init(const struct device *dev)
936948

937949
dev_data->in_target_io_mode = false;
938950

951+
#if defined(WITH_SUPPLY_GPIO)
952+
if (dev_config->supply.port) {
953+
rc = power_supply(dev);
954+
if (rc < 0) {
955+
return rc;
956+
}
957+
958+
flash_reset = true;
959+
}
960+
#endif
961+
939962
#if defined(WITH_RESET_GPIO)
940-
rc = gpio_reset(dev);
963+
if (dev_config->reset.port) {
964+
rc = gpio_reset(dev);
965+
if (rc < 0) {
966+
return rc;
967+
}
941968

942-
if (rc < 0) {
943-
LOG_ERR("Failed to reset with GPIO: %d", rc);
944-
return rc;
969+
flash_reset = true;
945970
}
946971
#endif
947972

@@ -951,9 +976,15 @@ static int flash_chip_init(const struct device *dev)
951976
if (rc < 0) {
952977
return rc;
953978
}
979+
980+
flash_reset = true;
954981
}
955982
#endif
956983

984+
if (flash_reset && dev_config->reset_recovery_us != 0) {
985+
k_busy_wait(dev_config->reset_recovery_us);
986+
}
987+
957988
if (dev_config->quirks != NULL &&
958989
dev_config->quirks->pre_init != NULL) {
959990
rc = dev_config->quirks->pre_init(dev);
@@ -1172,6 +1203,8 @@ BUILD_ASSERT((FLASH_SIZE(inst) % CONFIG_FLASH_MSPI_NOR_LAYOUT_PAGE_SIZE) == 0, \
11721203
.mspi_nor_init_cfg = FLASH_INITIAL_CONFIG(inst), \
11731204
IF_ENABLED(CONFIG_MSPI_XIP, \
11741205
(.xip_cfg = MSPI_XIP_CONFIG_DT_INST(inst),)) \
1206+
IF_ENABLED(WITH_SUPPLY_GPIO, \
1207+
(.supply = GPIO_DT_SPEC_INST_GET_OR(inst, supply_gpios, {0}),)) \
11751208
IF_ENABLED(WITH_RESET_GPIO, \
11761209
(.reset = GPIO_DT_SPEC_INST_GET_OR(inst, reset_gpios, {0}), \
11771210
.reset_pulse_us = DT_INST_PROP_OR(inst, t_reset_pulse, 0) \

drivers/flash/flash_mspi_nor.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ extern "C" {
1616
#include "jesd216.h"
1717
#include "spi_nor.h"
1818

19+
#if DT_ANY_INST_HAS_PROP_STATUS_OKAY(supply_gpios)
20+
#define WITH_SUPPLY_GPIO 1
21+
#endif
1922
#if DT_ANY_INST_HAS_PROP_STATUS_OKAY(reset_gpios)
2023
#define WITH_RESET_GPIO 1
2124
#endif
@@ -72,6 +75,9 @@ struct flash_mspi_nor_config {
7275
#if defined(CONFIG_MSPI_XIP)
7376
struct mspi_xip_cfg xip_cfg;
7477
#endif
78+
#if defined(WITH_SUPPLY_GPIO)
79+
struct gpio_dt_spec supply;
80+
#endif
7581
#if defined(WITH_RESET_GPIO)
7682
struct gpio_dt_spec reset;
7783
uint32_t reset_pulse_us;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ properties:
2222
type: int
2323
description: |
2424
Minimum time, in nanoseconds, the flash chip needs to recover after reset.
25+
Such delay is performed when a GPIO or software reset is done, or after
26+
power is supplied to the chip if the "supply-gpios" property is specified.
2527
2628
transfer-timeout:
2729
type: int

0 commit comments

Comments
 (0)