@@ -810,39 +810,54 @@ static int switch_to_target_io_mode(const struct device *dev)
810
810
& dev_config -> mspi_nor_cfg );
811
811
}
812
812
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
+
813
835
#if defined(WITH_RESET_GPIO )
814
836
static int gpio_reset (const struct device * dev )
815
837
{
816
838
const struct flash_mspi_nor_config * dev_config = dev -> config ;
817
839
int rc ;
818
840
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
+ }
832
846
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
+ }
836
852
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
+ }
842
856
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 ;
846
861
}
847
862
848
863
return 0 ;
@@ -912,10 +927,6 @@ static int soft_reset(const struct device *dev)
912
927
return rc ;
913
928
}
914
929
915
- if (dev_config -> reset_recovery_us != 0 ) {
916
- k_busy_wait (dev_config -> reset_recovery_us );
917
- }
918
-
919
930
return 0 ;
920
931
}
921
932
#endif /* WITH_SOFT_RESET */
@@ -925,6 +936,7 @@ static int flash_chip_init(const struct device *dev)
925
936
const struct flash_mspi_nor_config * dev_config = dev -> config ;
926
937
struct flash_mspi_nor_data * dev_data = dev -> data ;
927
938
uint8_t id [JESD216_READ_ID_LEN ] = {0 };
939
+ bool flash_reset = false;
928
940
int rc ;
929
941
930
942
rc = mspi_dev_config (dev_config -> bus , & dev_config -> mspi_id ,
@@ -936,12 +948,25 @@ static int flash_chip_init(const struct device *dev)
936
948
937
949
dev_data -> in_target_io_mode = false;
938
950
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
+
939
962
#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
+ }
941
968
942
- if (rc < 0 ) {
943
- LOG_ERR ("Failed to reset with GPIO: %d" , rc );
944
- return rc ;
969
+ flash_reset = true;
945
970
}
946
971
#endif
947
972
@@ -951,9 +976,15 @@ static int flash_chip_init(const struct device *dev)
951
976
if (rc < 0 ) {
952
977
return rc ;
953
978
}
979
+
980
+ flash_reset = true;
954
981
}
955
982
#endif
956
983
984
+ if (flash_reset && dev_config -> reset_recovery_us != 0 ) {
985
+ k_busy_wait (dev_config -> reset_recovery_us );
986
+ }
987
+
957
988
if (dev_config -> quirks != NULL &&
958
989
dev_config -> quirks -> pre_init != NULL ) {
959
990
rc = dev_config -> quirks -> pre_init (dev );
@@ -1172,6 +1203,8 @@ BUILD_ASSERT((FLASH_SIZE(inst) % CONFIG_FLASH_MSPI_NOR_LAYOUT_PAGE_SIZE) == 0, \
1172
1203
.mspi_nor_init_cfg = FLASH_INITIAL_CONFIG(inst), \
1173
1204
IF_ENABLED(CONFIG_MSPI_XIP, \
1174
1205
(.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}),)) \
1175
1208
IF_ENABLED(WITH_RESET_GPIO, \
1176
1209
(.reset = GPIO_DT_SPEC_INST_GET_OR(inst, reset_gpios, {0}), \
1177
1210
.reset_pulse_us = DT_INST_PROP_OR(inst, t_reset_pulse, 0) \
0 commit comments