@@ -20,8 +20,10 @@ 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
K_THREAD_STACK_DEFINE (pm_device_runtime_stack , CONFIG_PM_DEVICE_RUNTIME_WQ_STACK_SIZE );
24
25
static struct k_work_q pm_device_runtime_wq ;
26
+ #endif /* CONFIG_PM_DEVICE_RUNTIME_ASYNC */
25
27
26
28
#define EVENT_STATE_ACTIVE BIT(PM_DEVICE_STATE_ACTIVE)
27
29
#define EVENT_STATE_SUSPENDED BIT(PM_DEVICE_STATE_SUSPENDED)
@@ -82,8 +84,10 @@ static int runtime_suspend(const struct device *dev, bool async,
82
84
83
85
if (async ) {
84
86
/* queue suspend */
87
+ #ifdef CONFIG_PM_DEVICE_RUNTIME_ASYNC
85
88
pm -> base .state = PM_DEVICE_STATE_SUSPENDING ;
86
89
(void )k_work_schedule_for_queue (& pm_device_runtime_wq , & pm -> work , delay );
90
+ #endif /* CONFIG_PM_DEVICE_RUNTIME_ASYNC */
87
91
} else {
88
92
/* suspend now */
89
93
ret = pm -> base .action_cb (pm -> dev , PM_DEVICE_ACTION_SUSPEND );
@@ -103,6 +107,7 @@ static int runtime_suspend(const struct device *dev, bool async,
103
107
return ret ;
104
108
}
105
109
110
+ #ifdef CONFIG_PM_DEVICE_RUNTIME_ASYNC
106
111
static void runtime_suspend_work (struct k_work * work )
107
112
{
108
113
int ret ;
@@ -132,6 +137,7 @@ static void runtime_suspend_work(struct k_work *work)
132
137
133
138
__ASSERT (ret == 0 , "Could not suspend device (%d)" , ret );
134
139
}
140
+ #endif /* CONFIG_PM_DEVICE_RUNTIME_ASYNC */
135
141
136
142
static int get_sync_locked (const struct device * dev )
137
143
{
@@ -229,6 +235,7 @@ int pm_device_runtime_get(const struct device *dev)
229
235
230
236
pm -> base .usage ++ ;
231
237
238
+ #ifdef CONFIG_PM_DEVICE_RUNTIME_ASYNC
232
239
/*
233
240
* Check if the device has a pending suspend operation (not started
234
241
* yet) and cancel it. This way we avoid unnecessary operations because
@@ -254,6 +261,7 @@ int pm_device_runtime_get(const struct device *dev)
254
261
(void )k_sem_take (& pm -> lock , K_FOREVER );
255
262
}
256
263
}
264
+ #endif /* CONFIG_PM_DEVICE_RUNTIME_ASYNC */
257
265
258
266
if (pm -> base .usage > 1U ) {
259
267
goto unlock ;
@@ -352,6 +360,7 @@ int pm_device_runtime_put(const struct device *dev)
352
360
353
361
int pm_device_runtime_put_async (const struct device * dev , k_timeout_t delay )
354
362
{
363
+ #ifdef CONFIG_PM_DEVICE_RUNTIME_ASYNC
355
364
int ret ;
356
365
357
366
if (dev -> pm_base == NULL ) {
@@ -372,6 +381,9 @@ int pm_device_runtime_put_async(const struct device *dev, k_timeout_t delay)
372
381
SYS_PORT_TRACING_FUNC_EXIT (pm , device_runtime_put_async , dev , delay , ret );
373
382
374
383
return ret ;
384
+ #else
385
+ return - ENOSYS ;
386
+ #endif /* CONFIG_PM_DEVICE_RUNTIME_ASYNC */
375
387
}
376
388
377
389
__boot_func
@@ -443,7 +455,9 @@ int pm_device_runtime_enable(const struct device *dev)
443
455
/* lazy init of PM fields */
444
456
if (pm -> dev == NULL ) {
445
457
pm -> dev = dev ;
458
+ #ifdef CONFIG_PM_DEVICE_RUNTIME_ASYNC
446
459
k_work_init_delayable (& pm -> work , runtime_suspend_work );
460
+ #endif /* CONFIG_PM_DEVICE_RUNTIME_ASYNC */
447
461
}
448
462
449
463
if (pm -> base .state == PM_DEVICE_STATE_ACTIVE ) {
@@ -516,6 +530,7 @@ int pm_device_runtime_disable(const struct device *dev)
516
530
(void )k_sem_take (& pm -> lock , K_FOREVER );
517
531
}
518
532
533
+ #ifdef CONFIG_PM_DEVICE_RUNTIME_ASYNC
519
534
if (!k_is_pre_kernel ()) {
520
535
if ((pm -> base .state == PM_DEVICE_STATE_SUSPENDING ) &&
521
536
((k_work_cancel_delayable (& pm -> work ) & K_WORK_RUNNING ) == 0 )) {
@@ -533,6 +548,7 @@ int pm_device_runtime_disable(const struct device *dev)
533
548
(void )k_sem_take (& pm -> lock , K_FOREVER );
534
549
}
535
550
}
551
+ #endif /* CONFIG_PM_DEVICE_RUNTIME_ASYNC */
536
552
537
553
/* wake up the device if suspended */
538
554
if (pm -> base .state == PM_DEVICE_STATE_SUSPENDED ) {
@@ -543,8 +559,9 @@ int pm_device_runtime_disable(const struct device *dev)
543
559
544
560
pm -> base .state = PM_DEVICE_STATE_ACTIVE ;
545
561
}
546
-
562
+ #ifdef CONFIG_PM_DEVICE_RUNTIME_ASYNC
547
563
clear_bit :
564
+ #endif
548
565
atomic_clear_bit (& pm -> base .flags , PM_DEVICE_FLAG_RUNTIME_ENABLED );
549
566
550
567
unlock :
@@ -574,6 +591,8 @@ int pm_device_runtime_usage(const struct device *dev)
574
591
return dev -> pm_base -> usage ;
575
592
}
576
593
594
+ #ifdef CONFIG_PM_DEVICE_RUNTIME_ASYNC
595
+
577
596
static int pm_device_runtime_wq_init (void )
578
597
{
579
598
const struct k_work_queue_config cfg = {.name = "PM DEVICE RUNTIME WQ" };
@@ -588,3 +607,5 @@ static int pm_device_runtime_wq_init(void)
588
607
}
589
608
590
609
SYS_INIT (pm_device_runtime_wq_init , POST_KERNEL , CONFIG_PM_DEVICE_RUNTIME_WQ_INIT_PRIO );
610
+
611
+ #endif /* CONFIG_PM_DEVICE_RUNTIME_ASYNC */
0 commit comments