@@ -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 )
814836static 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) \
0 commit comments