88#include <zephyr/drivers/spi/rtio.h>
99#include <zephyr/cache.h>
1010#include <zephyr/pm/device.h>
11+ #include <zephyr/pm/device_runtime.h>
1112#include <zephyr/drivers/pinctrl.h>
1213#include <zephyr/mem_mgmt/mem_attr.h>
1314#include <soc.h>
@@ -87,6 +88,9 @@ static inline void finalize_spi_transaction(const struct device *dev, bool deact
8788 if (NRF_SPIM_IS_320MHZ_SPIM (reg ) && !(dev_data -> ctx .config -> operation & SPI_HOLD_ON_CS )) {
8889 nrfy_spim_disable (reg );
8990 }
91+ if (IS_ENABLED (CONFIG_PM_DEVICE_RUNTIME )) {
92+ pm_device_runtime_put (dev );
93+ }
9094}
9195
9296static inline uint32_t get_nrf_spim_frequency (uint32_t frequency )
@@ -457,6 +461,9 @@ static int transceive(const struct device *dev,
457461 void * reg = dev_config -> spim .p_reg ;
458462 int error ;
459463
464+ if (IS_ENABLED (CONFIG_PM_DEVICE_RUNTIME )) {
465+ pm_device_runtime_get (dev );
466+ }
460467 spi_context_lock (& dev_data -> ctx , asynchronous , cb , userdata , spi_cfg );
461468
462469 error = configure (dev , spi_cfg );
@@ -568,21 +575,20 @@ static const struct spi_driver_api spi_nrfx_driver_api = {
568575 .release = spi_nrfx_release ,
569576};
570577
571- #ifdef CONFIG_PM_DEVICE
572578static int spim_nrfx_pm_action (const struct device * dev ,
573579 enum pm_device_action action )
574580{
575- int ret = 0 ;
581+ int ret = - ENOTSUP ;
576582 struct spi_nrfx_data * dev_data = dev -> data ;
577583 const struct spi_nrfx_config * dev_config = dev -> config ;
578584
579585 switch (action ) {
586+ case PM_DEVICE_ACTION_TURN_ON :
587+ ret = 0 ;
588+ break ;
580589 case PM_DEVICE_ACTION_RESUME :
581590 ret = pinctrl_apply_state (dev_config -> pcfg ,
582591 PINCTRL_STATE_DEFAULT );
583- if (ret < 0 ) {
584- return ret ;
585- }
586592 /* nrfx_spim_init() will be called at configuration before
587593 * the next transfer.
588594 */
@@ -596,19 +602,14 @@ static int spim_nrfx_pm_action(const struct device *dev,
596602
597603 ret = pinctrl_apply_state (dev_config -> pcfg ,
598604 PINCTRL_STATE_SLEEP );
599- if (ret < 0 ) {
600- return ret ;
601- }
602605 break ;
603606
604607 default :
605- ret = - ENOTSUP ;
608+ break ;
606609 }
607610
608611 return ret ;
609612}
610- #endif /* CONFIG_PM_DEVICE */
611-
612613
613614static int spi_nrfx_init (const struct device * dev )
614615{
@@ -643,10 +644,12 @@ static int spi_nrfx_init(const struct device *dev)
643644 spi_context_unlock_unconditionally (& dev_data -> ctx );
644645
645646#ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58
646- return anomaly_58_workaround_init (dev );
647- #else
648- return 0 ;
647+ err = anomaly_58_workaround_init (dev );
648+ if (err < 0 ) {
649+ return err ;
650+ }
649651#endif
652+ return pm_device_driver_init (dev , spim_nrfx_pm_action );
650653}
651654/*
652655 * We use NODELABEL here because the nrfx API requires us to call
0 commit comments