Skip to content

Commit 0d565bb

Browse files
committed
[nrf fromtree] 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. Signed-off-by: Andrzej Głąbek <[email protected]> (cherry picked from commit 835d773)
1 parent 8b1bd67 commit 0d565bb

File tree

4 files changed

+75
-33
lines changed

4 files changed

+75
-33
lines changed

drivers/flash/Kconfig.mspi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ menuconfig FLASH_MSPI_NOR
3535
select FLASH_MSPI
3636
select FLASH_HAS_EXPLICIT_ERASE
3737
select FLASH_JESD216
38-
select GPIO if $(dt_compat_any_has_prop,$(DT_COMPAT_JEDEC_MSPI_NOR),reset-gpios)
38+
select GPIO if $(dt_compat_any_has_prop,$(DT_COMPAT_JEDEC_MSPI_NOR),reset-gpios) \
39+
|| $(dt_compat_any_has_prop,$(DT_COMPAT_JEDEC_MSPI_NOR),supply-gpios)
3940

4041
if FLASH_MSPI_NOR
4142

drivers/flash/flash_mspi_nor.c

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

851+
#if defined(WITH_SUPPLY_GPIO)
852+
static int power_supply(const struct device *dev)
853+
{
854+
const struct flash_mspi_nor_config *dev_config = dev->config;
855+
int rc;
856+
857+
if (!gpio_is_ready_dt(&dev_config->supply)) {
858+
LOG_ERR("Device %s is not ready",
859+
dev_config->supply.port->name);
860+
return -ENODEV;
861+
}
862+
863+
rc = gpio_pin_configure_dt(&dev_config->supply, GPIO_OUTPUT_ACTIVE);
864+
if (rc < 0) {
865+
LOG_ERR("Failed to activate power supply GPIO: %d", rc);
866+
return -EIO;
867+
}
868+
869+
return 0;
870+
}
871+
#endif
872+
851873
#if defined(WITH_RESET_GPIO)
852874
static int gpio_reset(const struct device *dev)
853875
{
854876
const struct flash_mspi_nor_config *dev_config = dev->config;
855877
int rc;
856878

857-
if (dev_config->reset.port) {
858-
if (!gpio_is_ready_dt(&dev_config->reset)) {
859-
LOG_ERR("Device %s is not ready",
860-
dev_config->reset.port->name);
861-
return -ENODEV;
862-
}
863-
864-
rc = gpio_pin_configure_dt(&dev_config->reset,
865-
GPIO_OUTPUT_ACTIVE);
866-
if (rc < 0) {
867-
LOG_ERR("Failed to activate RESET: %d", rc);
868-
return -EIO;
869-
}
879+
if (!gpio_is_ready_dt(&dev_config->reset)) {
880+
LOG_ERR("Device %s is not ready",
881+
dev_config->reset.port->name);
882+
return -ENODEV;
883+
}
870884

871-
if (dev_config->reset_pulse_us != 0) {
872-
k_busy_wait(dev_config->reset_pulse_us);
873-
}
885+
rc = gpio_pin_configure_dt(&dev_config->reset, GPIO_OUTPUT_ACTIVE);
886+
if (rc < 0) {
887+
LOG_ERR("Failed to activate RESET: %d", rc);
888+
return -EIO;
889+
}
874890

875-
rc = gpio_pin_set_dt(&dev_config->reset, 0);
876-
if (rc < 0) {
877-
LOG_ERR("Failed to deactivate RESET: %d", rc);
878-
return -EIO;
879-
}
891+
if (dev_config->reset_pulse_us != 0) {
892+
k_busy_wait(dev_config->reset_pulse_us);
893+
}
880894

881-
if (dev_config->reset_recovery_us != 0) {
882-
k_busy_wait(dev_config->reset_recovery_us);
883-
}
895+
rc = gpio_pin_set_dt(&dev_config->reset, 0);
896+
if (rc < 0) {
897+
LOG_ERR("Failed to deactivate RESET: %d", rc);
898+
return -EIO;
884899
}
885900

886901
return 0;
@@ -950,10 +965,6 @@ static int soft_reset(const struct device *dev)
950965
return rc;
951966
}
952967

953-
if (dev_config->reset_recovery_us != 0) {
954-
k_busy_wait(dev_config->reset_recovery_us);
955-
}
956-
957968
return 0;
958969
}
959970
#endif /* WITH_SOFT_RESET */
@@ -965,6 +976,7 @@ static int flash_chip_init(const struct device *dev)
965976
uint8_t id[JESD216_READ_ID_LEN] = {0};
966977
uint16_t dts_cmd = 0;
967978
uint32_t sfdp_signature;
979+
bool flash_reset = false;
968980
int rc;
969981

970982
rc = mspi_dev_config(dev_config->bus, &dev_config->mspi_id,
@@ -977,12 +989,25 @@ static int flash_chip_init(const struct device *dev)
977989

978990
dev_data->in_target_io_mode = false;
979991

992+
#if defined(WITH_SUPPLY_GPIO)
993+
if (dev_config->supply.port) {
994+
rc = power_supply(dev);
995+
if (rc < 0) {
996+
return rc;
997+
}
998+
999+
flash_reset = true;
1000+
}
1001+
#endif
1002+
9801003
#if defined(WITH_RESET_GPIO)
981-
rc = gpio_reset(dev);
1004+
if (dev_config->reset.port) {
1005+
rc = gpio_reset(dev);
1006+
if (rc < 0) {
1007+
return rc;
1008+
}
9821009

983-
if (rc < 0) {
984-
LOG_ERR("Failed to reset with GPIO: %d", rc);
985-
return rc;
1010+
flash_reset = true;
9861011
}
9871012
#endif
9881013

@@ -992,9 +1017,15 @@ static int flash_chip_init(const struct device *dev)
9921017
if (rc < 0) {
9931018
return rc;
9941019
}
1020+
1021+
flash_reset = true;
9951022
}
9961023
#endif
9971024

1025+
if (flash_reset && dev_config->reset_recovery_us != 0) {
1026+
k_busy_wait(dev_config->reset_recovery_us);
1027+
}
1028+
9981029
if (dev_config->quirks != NULL &&
9991030
dev_config->quirks->pre_init != NULL) {
10001031
rc = dev_config->quirks->pre_init(dev);
@@ -1267,6 +1298,8 @@ BUILD_ASSERT((FLASH_SIZE(inst) % CONFIG_FLASH_MSPI_NOR_LAYOUT_PAGE_SIZE) == 0, \
12671298
.mspi_nor_init_cfg = FLASH_INITIAL_CONFIG(inst), \
12681299
IF_ENABLED(CONFIG_MSPI_XIP, \
12691300
(.xip_cfg = MSPI_XIP_CONFIG_DT_INST(inst),)) \
1301+
IF_ENABLED(WITH_SUPPLY_GPIO, \
1302+
(.supply = GPIO_DT_SPEC_INST_GET_OR(inst, supply_gpios, {0}),)) \
12701303
IF_ENABLED(WITH_RESET_GPIO, \
12711304
(.reset = GPIO_DT_SPEC_INST_GET_OR(inst, reset_gpios, {0}), \
12721305
.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
@@ -75,6 +78,9 @@ struct flash_mspi_nor_config {
7578
#if defined(CONFIG_MSPI_XIP)
7679
struct mspi_xip_cfg xip_cfg;
7780
#endif
81+
#if defined(WITH_SUPPLY_GPIO)
82+
struct gpio_dt_spec supply;
83+
#endif
7884
#if defined(WITH_RESET_GPIO)
7985
struct gpio_dt_spec reset;
8086
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
@@ -35,6 +35,8 @@ properties:
3535
type: int
3636
description: |
3737
Minimum time, in nanoseconds, the flash chip needs to recover after reset.
38+
Such delay is performed when a GPIO or software reset is done, or after
39+
power is supplied to the chip if the "supply-gpios" property is specified.
3840
3941
transfer-timeout:
4042
type: int

0 commit comments

Comments
 (0)