Skip to content

Commit 6df1777

Browse files
[nrf fromlist] pm: device: runtime: add PM_DEVICE_RUNTIME_DEFAULT_ENABLE
Many SoCs which use PM_DEVICE_RUNTIME need every device in the system to have PM_DEVICE_RUNTIME enabled to function. Currently, this is only possible by adding zephyr,pm-device-runtime-auto; to every node in every devicetree which could potentially implement device power management. This is very error prone since its easy to miss a node, especially if users apply overlays, where users need to know and remember to apply or reapply this property. This commit adds a Kconfig, disabled by default, which automatically treats every device as if it had the zephyr,pm-device-runtime-auto property added to every node. Upstream PR #: 93720 Signed-off-by: Bjarki Arge Andreasen <[email protected]>
1 parent 81ae924 commit 6df1777

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

subsys/pm/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,15 @@ endif #PM_DEVICE_RUNTIME_USE_DEDICATED_WQ
174174
endchoice
175175

176176
endif # PM_DEVICE_RUNTIME_ASYNC
177+
178+
config PM_DEVICE_RUNTIME_DEFAULT_ENABLE
179+
bool "PM device runtime enable by default"
180+
help
181+
Enable PM device runtime by default for all devices when they are
182+
initialized. This option is identical to adding the devicetree
183+
property zephyr,pm-device-runtime-auto to all nodes in the
184+
devicetree.
185+
177186
endif # PM_DEVICE_RUNTIME
178187

179188
config PM_DEVICE_SHELL

subsys/pm/device.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,9 @@ int pm_device_driver_init(const struct device *dev,
387387
pm->state = PM_DEVICE_STATE_SUSPENDED;
388388

389389
/* If device will have PM device runtime enabled */
390-
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME) &&
391-
atomic_test_bit(&pm->flags, PM_DEVICE_FLAG_RUNTIME_AUTO)) {
390+
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME_DEFAULT_ENABLE) ||
391+
(IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME) &&
392+
atomic_test_bit(&pm->flags, PM_DEVICE_FLAG_RUNTIME_AUTO))) {
392393
return 0;
393394
}
394395

subsys/pm/device_runtime.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,15 @@ int pm_device_runtime_auto_enable(const struct device *dev)
398398
{
399399
struct pm_device_base *pm = dev->pm_base;
400400

401-
/* No action needed if PM_DEVICE_FLAG_RUNTIME_AUTO is not enabled */
402-
if (!pm || !atomic_test_bit(&pm->flags, PM_DEVICE_FLAG_RUNTIME_AUTO)) {
401+
if (!pm) {
403402
return 0;
404403
}
404+
405+
if (!IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME_DEFAULT_ENABLE) &&
406+
!atomic_test_bit(&pm->flags, PM_DEVICE_FLAG_RUNTIME_AUTO)) {
407+
return 0;
408+
}
409+
405410
return pm_device_runtime_enable(dev);
406411
}
407412

0 commit comments

Comments
 (0)