8
8
#include <zephyr/drivers/spi/rtio.h>
9
9
#include <zephyr/cache.h>
10
10
#include <zephyr/pm/device.h>
11
+ #include <zephyr/pm/device_runtime.h>
11
12
#include <zephyr/drivers/pinctrl.h>
12
13
#include <zephyr/mem_mgmt/mem_attr.h>
13
14
#include <soc.h>
@@ -87,6 +88,9 @@ static inline void finalize_spi_transaction(const struct device *dev, bool deact
87
88
if (NRF_SPIM_IS_320MHZ_SPIM (reg ) && !(dev_data -> ctx .config -> operation & SPI_HOLD_ON_CS )) {
88
89
nrfy_spim_disable (reg );
89
90
}
91
+ if (IS_ENABLED (CONFIG_PM_DEVICE_RUNTIME )) {
92
+ pm_device_runtime_put (dev );
93
+ }
90
94
}
91
95
92
96
static inline uint32_t get_nrf_spim_frequency (uint32_t frequency )
@@ -457,6 +461,9 @@ static int transceive(const struct device *dev,
457
461
void * reg = dev_config -> spim .p_reg ;
458
462
int error ;
459
463
464
+ if (IS_ENABLED (CONFIG_PM_DEVICE_RUNTIME )) {
465
+ pm_device_runtime_get (dev );
466
+ }
460
467
spi_context_lock (& dev_data -> ctx , asynchronous , cb , userdata , spi_cfg );
461
468
462
469
error = configure (dev , spi_cfg );
@@ -568,21 +575,20 @@ static const struct spi_driver_api spi_nrfx_driver_api = {
568
575
.release = spi_nrfx_release ,
569
576
};
570
577
571
- #ifdef CONFIG_PM_DEVICE
572
578
static int spim_nrfx_pm_action (const struct device * dev ,
573
579
enum pm_device_action action )
574
580
{
575
- int ret = 0 ;
581
+ int ret = - ENOTSUP ;
576
582
struct spi_nrfx_data * dev_data = dev -> data ;
577
583
const struct spi_nrfx_config * dev_config = dev -> config ;
578
584
579
585
switch (action ) {
586
+ case PM_DEVICE_ACTION_TURN_ON :
587
+ ret = 0 ;
588
+ break ;
580
589
case PM_DEVICE_ACTION_RESUME :
581
590
ret = pinctrl_apply_state (dev_config -> pcfg ,
582
591
PINCTRL_STATE_DEFAULT );
583
- if (ret < 0 ) {
584
- return ret ;
585
- }
586
592
/* nrfx_spim_init() will be called at configuration before
587
593
* the next transfer.
588
594
*/
@@ -596,19 +602,14 @@ static int spim_nrfx_pm_action(const struct device *dev,
596
602
597
603
ret = pinctrl_apply_state (dev_config -> pcfg ,
598
604
PINCTRL_STATE_SLEEP );
599
- if (ret < 0 ) {
600
- return ret ;
601
- }
602
605
break ;
603
606
604
607
default :
605
- ret = - ENOTSUP ;
608
+ break ;
606
609
}
607
610
608
611
return ret ;
609
612
}
610
- #endif /* CONFIG_PM_DEVICE */
611
-
612
613
613
614
static int spi_nrfx_init (const struct device * dev )
614
615
{
@@ -643,10 +644,12 @@ static int spi_nrfx_init(const struct device *dev)
643
644
spi_context_unlock_unconditionally (& dev_data -> ctx );
644
645
645
646
#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
+ }
649
651
#endif
652
+ return pm_device_driver_init (dev , spim_nrfx_pm_action );
650
653
}
651
654
/*
652
655
* We use NODELABEL here because the nrfx API requires us to call
0 commit comments