@@ -14,6 +14,8 @@ LOG_MODULE_REGISTER(adc_cc23x0, CONFIG_ADC_LOG_LEVEL);
14
14
#include <zephyr/drivers/dma.h>
15
15
#include <zephyr/drivers/pinctrl.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/adc.h>
@@ -72,8 +74,27 @@ struct adc_cc23x0_data {
72
74
uint8_t ch_count ;
73
75
uint8_t mem_index ;
74
76
uint16_t * buffer ;
77
+ #ifdef CONFIG_PM_DEVICE
78
+ bool configured ;
79
+ #endif
75
80
};
76
81
82
+ static inline void adc_cc23x0_pm_policy_state_lock_get (void )
83
+ {
84
+ #ifdef CONFIG_PM_DEVICE
85
+ pm_policy_state_lock_get (PM_STATE_RUNTIME_IDLE , PM_ALL_SUBSTATES );
86
+ pm_policy_state_lock_get (PM_STATE_STANDBY , PM_ALL_SUBSTATES );
87
+ #endif
88
+ }
89
+
90
+ static inline void adc_cc23x0_pm_policy_state_lock_put (void )
91
+ {
92
+ #ifdef CONFIG_PM_DEVICE
93
+ pm_policy_state_lock_put (PM_STATE_STANDBY , PM_ALL_SUBSTATES );
94
+ pm_policy_state_lock_put (PM_STATE_RUNTIME_IDLE , PM_ALL_SUBSTATES );
95
+ #endif
96
+ }
97
+
77
98
static void adc_context_start_sampling (struct adc_context * ctx )
78
99
{
79
100
struct adc_cc23x0_data * data = CONTAINER_OF (ctx , struct adc_cc23x0_data , ctx );
@@ -115,6 +136,8 @@ static void adc_context_start_sampling(struct adc_context *ctx)
115
136
data -> mem_index = 0 ;
116
137
#endif
117
138
139
+ adc_cc23x0_pm_policy_state_lock_get ();
140
+
118
141
ADCManualTrigger ();
119
142
}
120
143
@@ -144,6 +167,7 @@ static void adc_cc23x0_isr(const struct device *dev)
144
167
*/
145
168
ADCClearInterrupt (ADC_INT_DMADONE );
146
169
LOG_DBG ("DMA done" );
170
+ adc_cc23x0_pm_policy_state_lock_put ();
147
171
adc_context_on_sampling_done (& data -> ctx , dev );
148
172
#else
149
173
/*
@@ -174,6 +198,7 @@ static void adc_cc23x0_isr(const struct device *dev)
174
198
/* Trigger next conversion */
175
199
ADCManualTrigger ();
176
200
} else {
201
+ adc_cc23x0_pm_policy_state_lock_put ();
177
202
adc_context_on_sampling_done (& data -> ctx , dev );
178
203
}
179
204
#endif
@@ -462,6 +487,10 @@ static int adc_cc23x0_channel_setup(const struct device *dev,
462
487
return - EINVAL ;
463
488
}
464
489
490
+ #ifdef CONFIG_PM_DEVICE
491
+ data -> configured = true;
492
+ #endif
493
+
465
494
return 0 ;
466
495
}
467
496
@@ -497,6 +526,34 @@ static int adc_cc23x0_init(const struct device *dev)
497
526
return 0 ;
498
527
}
499
528
529
+ #ifdef CONFIG_PM_DEVICE
530
+
531
+ static int adc_cc23x0_pm_action (const struct device * dev , enum pm_device_action action )
532
+ {
533
+ struct adc_cc23x0_data * data = dev -> data ;
534
+
535
+ switch (action ) {
536
+ case PM_DEVICE_ACTION_SUSPEND :
537
+ CLKCTLDisable (CLKCTL_BASE , CLKCTL_ADC0 );
538
+ return 0 ;
539
+ case PM_DEVICE_ACTION_RESUME :
540
+ CLKCTLEnable (CLKCTL_BASE , CLKCTL_ADC0 );
541
+ ADCEnableInterrupt (ADC_CC23X0_INT_MASK );
542
+
543
+ /* Restore context if needed */
544
+ if (data -> configured ) {
545
+ ADCSetSampleDuration (adc_cc23x0_clkdiv_to_field (data -> clk_div ),
546
+ data -> clk_cycles );
547
+ }
548
+
549
+ return 0 ;
550
+ default :
551
+ return - ENOTSUP ;
552
+ }
553
+ }
554
+
555
+ #endif /* CONFIG_PM_DEVICE */
556
+
500
557
static const struct adc_driver_api adc_cc23x0_driver_api = {
501
558
.channel_setup = adc_cc23x0_channel_setup ,
502
559
.read = adc_cc23x0_read ,
@@ -517,6 +574,7 @@ static const struct adc_driver_api adc_cc23x0_driver_api = {
517
574
518
575
#define CC23X0_ADC_INIT (n ) \
519
576
PINCTRL_DT_INST_DEFINE(n); \
577
+ PM_DEVICE_DT_INST_DEFINE(n, adc_cc23x0_pm_action); \
520
578
\
521
579
static void adc_cc23x0_cfg_func_##n(void) \
522
580
{ \
@@ -542,7 +600,7 @@ static const struct adc_driver_api adc_cc23x0_driver_api = {
542
600
\
543
601
DEVICE_DT_INST_DEFINE(n, \
544
602
&adc_cc23x0_init, \
545
- NULL, \
603
+ PM_DEVICE_DT_INST_GET(n), \
546
604
&adc_cc23x0_data_##n, \
547
605
&adc_cc23x0_config_##n, \
548
606
POST_KERNEL, \
0 commit comments