@@ -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,10 @@ 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
+ LOG_WRN ("Function not available" );
392
+ return - ENOSYS ;
393
+ #endif /* CONFIG_PM_DEVICE_RUNTIME_ASYNC */
381
394
}
382
395
383
396
__boot_func
@@ -449,7 +462,9 @@ int pm_device_runtime_enable(const struct device *dev)
449
462
/* lazy init of PM fields */
450
463
if (pm -> dev == NULL ) {
451
464
pm -> dev = dev ;
465
+ #ifdef CONFIG_PM_DEVICE_RUNTIME_ASYNC
452
466
k_work_init_delayable (& pm -> work , runtime_suspend_work );
467
+ #endif /* CONFIG_PM_DEVICE_RUNTIME_ASYNC */
453
468
}
454
469
455
470
if (pm -> base .state == PM_DEVICE_STATE_ACTIVE ) {
@@ -522,6 +537,7 @@ int pm_device_runtime_disable(const struct device *dev)
522
537
(void )k_sem_take (& pm -> lock , K_FOREVER );
523
538
}
524
539
540
+ #ifdef CONFIG_PM_DEVICE_RUNTIME_ASYNC
525
541
if (!k_is_pre_kernel ()) {
526
542
if ((pm -> base .state == PM_DEVICE_STATE_SUSPENDING ) &&
527
543
((k_work_cancel_delayable (& pm -> work ) & K_WORK_RUNNING ) == 0 )) {
@@ -539,6 +555,7 @@ int pm_device_runtime_disable(const struct device *dev)
539
555
(void )k_sem_take (& pm -> lock , K_FOREVER );
540
556
}
541
557
}
558
+ #endif /* CONFIG_PM_DEVICE_RUNTIME_ASYNC */
542
559
543
560
/* wake up the device if suspended */
544
561
if (pm -> base .state == PM_DEVICE_STATE_SUSPENDED ) {
@@ -549,8 +566,9 @@ int pm_device_runtime_disable(const struct device *dev)
549
566
550
567
pm -> base .state = PM_DEVICE_STATE_ACTIVE ;
551
568
}
552
-
569
+ #ifdef CONFIG_PM_DEVICE_RUNTIME_ASYNC
553
570
clear_bit :
571
+ #endif
554
572
atomic_clear_bit (& pm -> base .flags , PM_DEVICE_FLAG_RUNTIME_ENABLED );
555
573
556
574
unlock :
@@ -580,6 +598,7 @@ int pm_device_runtime_usage(const struct device *dev)
580
598
return dev -> pm_base -> usage ;
581
599
}
582
600
601
+ #ifdef CONFIG_PM_DEVICE_RUNTIME_ASYNC
583
602
#ifdef CONFIG_PM_DEVICE_RUNTIME_USE_DEDICATED_WQ
584
603
585
604
static int pm_device_runtime_wq_init (void )
@@ -599,3 +618,4 @@ SYS_INIT(pm_device_runtime_wq_init, POST_KERNEL,
599
618
CONFIG_PM_DEVICE_RUNTIME_DEDICATED_WQ_INIT_PRIO );
600
619
601
620
#endif /* CONFIG_PM_DEVICE_RUNTIME_USE_DEDICATED_WQ */
621
+ #endif /* CONFIG_PM_DEVICE_RUNTIME_ASYNC */
0 commit comments