-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pm: Make device pm optional per state - V2 #70623
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7c02a88
pm: Deprecate PM_DEVICE_RUNTIME_EXCLUSIVE
ec0e023
pm: Disable device pm per power state
4960602
pm: Exclude device pm path when it is not needed
4960c06
pm: device: De-couple device pm from system pm
ea206bd
tests: power_mgmt: Use DTS overlay for power state
ad03ac7
tests: device_wakeup_api: Use DTS overlay for power state
eae3fd4
doc: pm: Update system device pm
3c1a860
tests: power_mgmt: Add test for PM_DEVICE_SYSTEM_MANAGED
5a10af8
tests: pm: Replace depracated build option
4c9ab05
tests: power_mgmt: Test system-managed disabled per state
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
CONFIG_PM=y | ||
CONFIG_PM_DEVICE=y | ||
CONFIG_PM_DEVICE_RUNTIME=y | ||
CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE=n | ||
CONFIG_PM_DEVICE_SYSTEM_MANAGED=y | ||
CONFIG_ADC=y | ||
#CONFIG_DEBUG=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
CONFIG_PM=y | ||
CONFIG_PM_DEVICE=y | ||
CONFIG_PM_DEVICE_RUNTIME=y | ||
CONFIG_PM_DEVICE_RUNTIME_EXCLUSIVE=n | ||
CONFIG_PM_DEVICE_SYSTEM_MANAGED=y | ||
CONFIG_ASSERT=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright (c) 2024 Intel Corporation. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/kernel.h> | ||
#include <zephyr/pm/device.h> | ||
#include <zephyr/pm/device_runtime.h> | ||
|
||
#include <zephyr/logging/log.h> | ||
LOG_MODULE_DECLARE(pm_device, CONFIG_PM_DEVICE_LOG_LEVEL); | ||
|
||
#define DT_PM_DEVICE_ENABLED(node_id) \ | ||
COND_CODE_1(DT_PROP(node_id, zephyr_pm_device_disabled), \ | ||
(), (1 +)) | ||
|
||
#define DT_PM_DEVICE_NEEDED \ | ||
(DT_FOREACH_STATUS_OKAY(zephyr_power_state, DT_PM_DEVICE_ENABLED) 0) | ||
|
||
#if DT_PM_DEVICE_NEEDED | ||
TYPE_SECTION_START_EXTERN(const struct device *, pm_device_slots); | ||
|
||
/* Number of devices successfully suspended. */ | ||
static size_t num_susp; | ||
|
||
bool pm_suspend_devices(void) | ||
{ | ||
const struct device *devs; | ||
size_t devc; | ||
|
||
devc = z_device_get_all_static(&devs); | ||
|
||
num_susp = 0; | ||
|
||
for (const struct device *dev = devs + devc - 1; dev >= devs; dev--) { | ||
int ret; | ||
|
||
/* | ||
* Ignore uninitialized devices, busy devices, wake up sources, and | ||
* devices with runtime PM enabled. | ||
*/ | ||
if (!device_is_ready(dev) || pm_device_is_busy(dev) || | ||
pm_device_wakeup_is_enabled(dev) || | ||
pm_device_runtime_is_enabled(dev)) { | ||
continue; | ||
} | ||
|
||
ret = pm_device_action_run(dev, PM_DEVICE_ACTION_SUSPEND); | ||
/* ignore devices not supporting or already at the given state */ | ||
if ((ret == -ENOSYS) || (ret == -ENOTSUP) || (ret == -EALREADY)) { | ||
continue; | ||
} else if (ret < 0) { | ||
LOG_ERR("Device %s did not enter %s state (%d)", | ||
dev->name, | ||
pm_device_state_str(PM_DEVICE_STATE_SUSPENDED), | ||
ret); | ||
return false; | ||
} | ||
|
||
TYPE_SECTION_START(pm_device_slots)[num_susp] = dev; | ||
num_susp++; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
void pm_resume_devices(void) | ||
{ | ||
for (int i = (num_susp - 1); i >= 0; i--) { | ||
pm_device_action_run(TYPE_SECTION_START(pm_device_slots)[i], | ||
PM_DEVICE_ACTION_RESUME); | ||
} | ||
|
||
num_susp = 0; | ||
} | ||
|
||
#else /* !DT_PM_DEVICE_NEEDED */ | ||
|
||
void pm_resume_devices(void) | ||
{ | ||
} | ||
|
||
bool pm_suspend_devices(void) | ||
{ | ||
return true; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright (c) 2024 Intel Corporation. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef ZEPHYR_SUBSYS_PM_DEVICE_SYSTEM_MANAGED_H_ | ||
#define ZEPHYR_SUBSYS_PM_DEVICE_SYSTEM_MANAGED_H_ | ||
|
||
#ifdef CONFIG_PM_DEVICE_SYSTEM_MANAGED | ||
|
||
bool pm_suspend_devices(void); | ||
void pm_resume_devices(void); | ||
|
||
#else | ||
|
||
bool pm_resume_devices(void) { return true; } | ||
void pm_suspend_devices(void) {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ceolin, is this a bug? Why are the function definitions different in the #if and #else cases? |
||
|
||
#endif /* CONFIG_PM_DEVICE_SYSTEM_MANAGED */ | ||
|
||
#endif /* ZEPHYR_SUBSYS_PM_DEVICE_SYSTEM_MANAGED_H_ */ |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non blocking: We could use more detailed information on
states
here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is hard to be specific without the risk of saying something that can be incomplete or wrong for a particular device :/