@@ -14,6 +14,8 @@ LOG_MODULE_REGISTER(spi_cc23x0, CONFIG_SPI_LOG_LEVEL);
14
14
#include <zephyr/drivers/pinctrl.h>
15
15
#include <zephyr/drivers/spi.h>
16
16
#include <zephyr/irq.h>
17
+ #include <zephyr/pm/device.h>
18
+ #include <zephyr/pm/policy.h>
17
19
#include <zephyr/sys/util.h>
18
20
19
21
#include <driverlib/clkctl.h>
@@ -63,6 +65,22 @@ struct spi_cc23x0_data {
63
65
#endif
64
66
};
65
67
68
+ static inline void spi_cc23x0_pm_policy_state_lock_get (void )
69
+ {
70
+ #ifdef CONFIG_PM_DEVICE
71
+ pm_policy_state_lock_get (PM_STATE_RUNTIME_IDLE , PM_ALL_SUBSTATES );
72
+ pm_policy_state_lock_get (PM_STATE_STANDBY , PM_ALL_SUBSTATES );
73
+ #endif
74
+ }
75
+
76
+ static inline void spi_cc23x0_pm_policy_state_lock_put (void )
77
+ {
78
+ #ifdef CONFIG_PM_DEVICE
79
+ pm_policy_state_lock_put (PM_STATE_STANDBY , PM_ALL_SUBSTATES );
80
+ pm_policy_state_lock_put (PM_STATE_RUNTIME_IDLE , PM_ALL_SUBSTATES );
81
+ #endif
82
+ }
83
+
66
84
static void spi_cc23x0_isr (const struct device * dev )
67
85
{
68
86
const struct spi_cc23x0_config * cfg = dev -> config ;
@@ -307,6 +325,8 @@ static int spi_cc23x0_transceive(const struct device *dev,
307
325
};
308
326
#endif
309
327
328
+ spi_cc23x0_pm_policy_state_lock_get ();
329
+
310
330
spi_context_lock (ctx , false, NULL , NULL , config );
311
331
312
332
ret = spi_cc23x0_configure (dev , config );
@@ -388,6 +408,7 @@ static int spi_cc23x0_transceive(const struct device *dev,
388
408
389
409
ctx_release :
390
410
spi_context_release (ctx , ret );
411
+ spi_cc23x0_pm_policy_state_lock_put ();
391
412
return ret ;
392
413
}
393
414
@@ -446,6 +467,29 @@ static int spi_cc23x0_init(const struct device *dev)
446
467
return 0 ;
447
468
}
448
469
470
+ #ifdef CONFIG_PM_DEVICE
471
+
472
+ static int spi_cc23x0_pm_action (const struct device * dev , enum pm_device_action action )
473
+ {
474
+ const struct spi_cc23x0_config * cfg = dev -> config ;
475
+ struct spi_cc23x0_data * data = dev -> data ;
476
+
477
+ switch (action ) {
478
+ case PM_DEVICE_ACTION_SUSPEND :
479
+ SPIDisable (cfg -> base );
480
+ CLKCTLDisable (CLKCTL_BASE , CLKCTL_SPI0 );
481
+ return 0 ;
482
+ case PM_DEVICE_ACTION_RESUME :
483
+ /* Force SPI to be reconfigured at next transfer */
484
+ data -> ctx .config = NULL ;
485
+ return 0 ;
486
+ default :
487
+ return - ENOTSUP ;
488
+ }
489
+ }
490
+
491
+ #endif /* CONFIG_PM_DEVICE */
492
+
449
493
#ifdef CONFIG_SPI_CC23X0_DMA_DRIVEN
450
494
#define SPI_CC23X0_DMA_INIT (n ) \
451
495
.dma_dev = DEVICE_DT_GET(TI_CC23X0_DT_INST_DMA_CTLR(n, tx)), \
@@ -459,6 +503,7 @@ static int spi_cc23x0_init(const struct device *dev)
459
503
460
504
#define SPI_CC23X0_INIT (n ) \
461
505
PINCTRL_DT_INST_DEFINE(n); \
506
+ PM_DEVICE_DT_INST_DEFINE(n, spi_cc23x0_pm_action); \
462
507
\
463
508
static void spi_irq_config_func_##n(void) \
464
509
{ \
@@ -484,7 +529,7 @@ static int spi_cc23x0_init(const struct device *dev)
484
529
\
485
530
DEVICE_DT_INST_DEFINE(n, \
486
531
spi_cc23x0_init, \
487
- NULL, \
532
+ PM_DEVICE_DT_INST_GET(n), \
488
533
&spi_cc23x0_data_##n, \
489
534
&spi_cc23x0_config_##n, \
490
535
POST_KERNEL, \
0 commit comments