@@ -88,6 +88,9 @@ static inline void finalize_spi_transaction(const struct device *dev, bool deact
8888 if (NRF_SPIM_IS_320MHZ_SPIM (reg ) && !(dev_data -> ctx .config -> operation & SPI_HOLD_ON_CS )) {
8989 nrfy_spim_disable (reg );
9090 }
91+ if (IS_ENABLED (CONFIG_PM_DEVICE_RUNTIME )) {
92+ pm_device_runtime_put (dev );
93+ }
9194}
9295
9396static inline uint32_t get_nrf_spim_frequency (uint32_t frequency )
@@ -478,6 +481,9 @@ static int transceive(const struct device *dev,
478481 void * reg = dev_config -> spim .p_reg ;
479482 int error ;
480483
484+ if (IS_ENABLED (CONFIG_PM_DEVICE_RUNTIME )) {
485+ pm_device_runtime_get (dev );
486+ }
481487 spi_context_lock (& dev_data -> ctx , asynchronous , cb , userdata , spi_cfg );
482488
483489 error = configure (dev , spi_cfg );
@@ -589,22 +595,23 @@ static const struct spi_driver_api spi_nrfx_driver_api = {
589595 .release = spi_nrfx_release ,
590596};
591597
592- #ifdef CONFIG_PM_DEVICE
593598static int spim_nrfx_pm_action (const struct device * dev ,
594599 enum pm_device_action action )
595600{
596- int ret = 0 ;
601+ int ret = - ENOTSUP ;
597602 struct spi_nrfx_data * dev_data = dev -> data ;
598603 const struct spi_nrfx_config * dev_config = dev -> config ;
599604
600605 switch (action ) {
606+ case PM_DEVICE_ACTION_TURN_ON :
607+ ret = 0 ;
608+ break ;
601609 case PM_DEVICE_ACTION_RESUME :
602610 ret = pinctrl_apply_state (dev_config -> pcfg ,
603611 PINCTRL_STATE_DEFAULT );
604- if (ret < 0 ) {
605- return ret ;
606- }
607- ret = spim_init (dev );
612+ /* nrfx_spim_init() will be called at configuration before
613+ * the next transfer.
614+ */
608615 break ;
609616
610617 case PM_DEVICE_ACTION_SUSPEND :
@@ -615,19 +622,14 @@ static int spim_nrfx_pm_action(const struct device *dev,
615622
616623 ret = pinctrl_apply_state (dev_config -> pcfg ,
617624 PINCTRL_STATE_SLEEP );
618- if (ret < 0 ) {
619- return ret ;
620- }
621625 break ;
622626
623627 default :
624- ret = - ENOTSUP ;
628+ break ;
625629 }
626630
627631 return ret ;
628632}
629- #endif /* CONFIG_PM_DEVICE */
630-
631633
632634static int spi_nrfx_init (const struct device * dev )
633635{
@@ -670,10 +672,12 @@ static int spi_nrfx_init(const struct device *dev)
670672#endif
671673
672674#ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58
673- return anomaly_58_workaround_init (dev );
674- #else
675- return 0 ;
675+ err = anomaly_58_workaround_init (dev );
676+ if (err < 0 ) {
677+ return err ;
678+ }
676679#endif
680+ return pm_device_driver_init (dev , spim_nrfx_pm_action );
677681}
678682/*
679683 * We use NODELABEL here because the nrfx API requires us to call
0 commit comments