@@ -20,10 +20,12 @@ LOG_MODULE_DECLARE(pm_device, CONFIG_PM_DEVICE_LOG_LEVEL);
20
20
#define PM_DOMAIN (_pm ) NULL
21
21
#endif
22
22
23
+ #ifdef CONFIG_PM_DEVICE_RUNTIME_ASYNC
23
24
#ifdef CONFIG_PM_DEVICE_RUNTIME_USE_DEDICATED_WQ
24
25
K_THREAD_STACK_DEFINE (pm_device_runtime_stack , CONFIG_PM_DEVICE_RUNTIME_DEDICATED_WQ_STACK_SIZE );
25
26
static struct k_work_q pm_device_runtime_wq ;
26
27
#endif /* CONFIG_PM_DEVICE_RUNTIME_USE_DEDICATED_WQ */
28
+ #endif /* CONFIG_PM_DEVICE_RUNTIME_ASYNC */
27
29
28
30
#define EVENT_STATE_ACTIVE BIT(PM_DEVICE_STATE_ACTIVE)
29
31
#define EVENT_STATE_SUSPENDED BIT(PM_DEVICE_STATE_SUSPENDED)
@@ -84,12 +86,14 @@ static int runtime_suspend(const struct device *dev, bool async,
84
86
85
87
if (async ) {
86
88
/* queue suspend */
89
+ #ifdef CONFIG_PM_DEVICE_RUNTIME_ASYNC
87
90
pm -> base .state = PM_DEVICE_STATE_SUSPENDING ;
88
91
#ifdef CONFIG_PM_DEVICE_RUNTIME_USE_SYSTEM_WQ
89
92
(void )k_work_schedule (& pm -> work , delay );
90
93
#else
91
94
(void )k_work_schedule_for_queue (& pm_device_runtime_wq , & pm -> work , delay );
92
95
#endif /* CONFIG_PM_DEVICE_RUNTIME_USE_SYSTEM_WQ */
96
+ #endif /* CONFIG_PM_DEVICE_RUNTIME_ASYNC */
93
97
} else {
94
98
/* suspend now */
95
99
ret = pm -> base .action_cb (pm -> dev , PM_DEVICE_ACTION_SUSPEND );
@@ -109,6 +113,7 @@ static int runtime_suspend(const struct device *dev, bool async,
109
113
return ret ;
110
114
}
111
115
116
+ #ifdef CONFIG_PM_DEVICE_RUNTIME_ASYNC
112
117
static void runtime_suspend_work (struct k_work * work )
113
118
{
114
119
int ret ;
@@ -138,6 +143,7 @@ static void runtime_suspend_work(struct k_work *work)
138
143
139
144
__ASSERT (ret == 0 , "Could not suspend device (%d)" , ret );
140
145
}
146
+ #endif /* CONFIG_PM_DEVICE_RUNTIME_ASYNC */
141
147
142
148
static int get_sync_locked (const struct device * dev )
143
149
{
@@ -235,6 +241,7 @@ int pm_device_runtime_get(const struct device *dev)
235
241
236
242
pm -> base .usage ++ ;
237
243
244
+ #ifdef CONFIG_PM_DEVICE_RUNTIME_ASYNC
238
245
/*
239
246
* Check if the device has a pending suspend operation (not started
240
247
* yet) and cancel it. This way we avoid unnecessary operations because
@@ -260,6 +267,7 @@ int pm_device_runtime_get(const struct device *dev)
260
267
(void )k_sem_take (& pm -> lock , K_FOREVER );
261
268
}
262
269
}
270
+ #endif /* CONFIG_PM_DEVICE_RUNTIME_ASYNC */
263
271
264
272
if (pm -> base .usage > 1U ) {
265
273
goto unlock ;
@@ -358,6 +366,7 @@ int pm_device_runtime_put(const struct device *dev)
358
366
359
367
int pm_device_runtime_put_async (const struct device * dev , k_timeout_t delay )
360
368
{
369
+ #ifdef CONFIG_PM_DEVICE_RUNTIME_ASYNC
361
370
int ret ;
362
371
363
372
if (dev -> pm_base == NULL ) {
@@ -378,6 +387,9 @@ int pm_device_runtime_put_async(const struct device *dev, k_timeout_t delay)
378
387
SYS_PORT_TRACING_FUNC_EXIT (pm , device_runtime_put_async , dev , delay , ret );
379
388
380
389
return ret ;
390
+ #else
391
+ return - ENOSYS ;
392
+ #endif /* CONFIG_PM_DEVICE_RUNTIME_ASYNC */
381
393
}
382
394
383
395
__boot_func
@@ -449,7 +461,9 @@ int pm_device_runtime_enable(const struct device *dev)
449
461
/* lazy init of PM fields */
450
462
if (pm -> dev == NULL ) {
451
463
pm -> dev = dev ;
464
+ #ifdef CONFIG_PM_DEVICE_RUNTIME_ASYNC
452
465
k_work_init_delayable (& pm -> work , runtime_suspend_work );
466
+ #endif /* CONFIG_PM_DEVICE_RUNTIME_ASYNC */
453
467
}
454
468
455
469
if (pm -> base .state == PM_DEVICE_STATE_ACTIVE ) {
@@ -522,6 +536,7 @@ int pm_device_runtime_disable(const struct device *dev)
522
536
(void )k_sem_take (& pm -> lock , K_FOREVER );
523
537
}
524
538
539
+ #ifdef CONFIG_PM_DEVICE_RUNTIME_ASYNC
525
540
if (!k_is_pre_kernel ()) {
526
541
if ((pm -> base .state == PM_DEVICE_STATE_SUSPENDING ) &&
527
542
((k_work_cancel_delayable (& pm -> work ) & K_WORK_RUNNING ) == 0 )) {
@@ -539,6 +554,7 @@ int pm_device_runtime_disable(const struct device *dev)
539
554
(void )k_sem_take (& pm -> lock , K_FOREVER );
540
555
}
541
556
}
557
+ #endif /* CONFIG_PM_DEVICE_RUNTIME_ASYNC */
542
558
543
559
/* wake up the device if suspended */
544
560
if (pm -> base .state == PM_DEVICE_STATE_SUSPENDED ) {
@@ -549,8 +565,9 @@ int pm_device_runtime_disable(const struct device *dev)
549
565
550
566
pm -> base .state = PM_DEVICE_STATE_ACTIVE ;
551
567
}
552
-
568
+ #ifdef CONFIG_PM_DEVICE_RUNTIME_ASYNC
553
569
clear_bit :
570
+ #endif
554
571
atomic_clear_bit (& pm -> base .flags , PM_DEVICE_FLAG_RUNTIME_ENABLED );
555
572
556
573
unlock :
@@ -580,6 +597,7 @@ int pm_device_runtime_usage(const struct device *dev)
580
597
return dev -> pm_base -> usage ;
581
598
}
582
599
600
+ #ifdef CONFIG_PM_DEVICE_RUNTIME_ASYNC
583
601
#ifdef CONFIG_PM_DEVICE_RUNTIME_USE_DEDICATED_WQ
584
602
585
603
static int pm_device_runtime_wq_init (void )
@@ -599,3 +617,4 @@ SYS_INIT(pm_device_runtime_wq_init, POST_KERNEL,
599
617
CONFIG_PM_DEVICE_RUNTIME_DEDICATED_WQ_INIT_PRIO );
600
618
601
619
#endif /* CONFIG_PM_DEVICE_RUNTIME_USE_DEDICATED_WQ */
620
+ #endif /* CONFIG_PM_DEVICE_RUNTIME_ASYNC */
0 commit comments