power: Get rid of deep sleep and sleep concepts

New power states have more granularity than deep sleep and sleep
states. Just get rid of this and keep the same behavior for now.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
This commit is contained in:
Flavio Ceolin 2021-03-01 13:44:40 -08:00 committed by Anas Nashif
parent 741141e464
commit 98dbea0979
11 changed files with 30 additions and 128 deletions

View File

@ -63,52 +63,6 @@ struct pm_notifier {
void (*state_exit)(enum pm_state state);
};
/**
* @brief Check if particular power state is a sleep state.
*
* This function returns true if given power state is a sleep state.
*/
static inline bool pm_is_sleep_state(enum pm_state state)
{
bool ret = true;
switch (state) {
case PM_STATE_RUNTIME_IDLE:
__fallthrough;
case PM_STATE_SUSPEND_TO_IDLE:
__fallthrough;
case PM_STATE_STANDBY:
break;
default:
ret = false;
break;
}
return ret;
}
/**
* @brief Check if particular power state is a deep sleep state.
*
* This function returns true if given power state is a deep sleep state.
*/
static inline bool pm_is_deep_sleep_state(enum pm_state state)
{
bool ret = true;
switch (state) {
case PM_STATE_SUSPEND_TO_RAM:
__fallthrough;
case PM_STATE_SUSPEND_TO_DISK:
break;
default:
ret = false;
break;
}
return ret;
}
/**
* @brief Force usage of given power state.
*

View File

@ -118,11 +118,6 @@ void pm_power_state_exit_post_ops(struct pm_state_info info)
irq_unlock(0);
}
__weak bool pm_policy_low_power_devices(enum pm_state state)
{
return pm_is_sleep_state(state);
}
/* Initialize STM32 Power */
static int stm32_power_init(const struct device *dev)
{

View File

@ -107,8 +107,3 @@ void pm_power_state_exit_post_ops(struct pm_state_info info)
*/
irq_unlock(0);
}
__weak bool pm_policy_low_power_devices(enum pm_state state)
{
return pm_is_sleep_state(state);
}

View File

@ -43,11 +43,6 @@ void pm_resume_devices(void);
*/
struct pm_state_info pm_policy_next_state(int32_t ticks);
/**
* @brief Function to determine whether to put devices in low
* power state, given the system PM state.
*/
bool pm_policy_low_power_devices(enum pm_state state);
#ifdef __cplusplus
}

View File

@ -47,8 +47,3 @@ struct pm_state_info pm_policy_next_state(int32_t ticks)
LOG_DBG("No suitable power state found!");
return STATE_ACTIVE;
}
__weak bool pm_policy_low_power_devices(enum pm_state state)
{
return pm_is_sleep_state(state);
}

View File

@ -38,8 +38,3 @@ struct pm_state_info pm_policy_next_state(int32_t ticks)
LOG_DBG("No suitable power state found!");
return (struct pm_state_info){PM_STATE_ACTIVE, 0, 0};
}
__weak bool pm_policy_low_power_devices(enum pm_state state)
{
return pm_is_sleep_state(state);
}

View File

@ -136,8 +136,3 @@ struct pm_state_info pm_policy_next_state(int32_t ticks)
LOG_DBG("No suitable power state found!");
return STATE_ACTIVE;
}
__weak bool pm_policy_low_power_devices(enum pm_state state)
{
return state == PM_STATE_STANDBY;
}

View File

@ -134,6 +134,7 @@ void pm_power_state_force(struct pm_state_info info)
}
}
#if CONFIG_PM_DEVICE
static enum pm_state _handle_device_abort(struct pm_state_info info)
{
LOG_DBG("Some devices didn't enter suspend state!");
@ -142,46 +143,43 @@ static enum pm_state _handle_device_abort(struct pm_state_info info)
z_power_state.state = PM_STATE_ACTIVE;
return PM_STATE_ACTIVE;
}
#endif
enum pm_state pm_system_suspend(int32_t ticks)
{
bool deep_sleep;
#if CONFIG_PM_DEVICE
bool low_power = false;
#endif
z_power_state = pm_policy_next_state(ticks);
if (z_power_state.state == PM_STATE_ACTIVE) {
LOG_DBG("No PM operations done.");
return z_power_state.state;
}
deep_sleep = pm_is_deep_sleep_state(z_power_state.state);
post_ops_done = 0;
if (deep_sleep) {
/* Suspend peripherals. */
if (IS_ENABLED(CONFIG_PM_DEVICE) && pm_suspend_devices()) {
#if CONFIG_PM_DEVICE
bool should_resume_devices = true;
switch (z_power_state.state) {
case PM_STATE_RUNTIME_IDLE:
__fallthrough;
case PM_STATE_SUSPEND_TO_IDLE:
__fallthrough;
case PM_STATE_STANDBY:
/* low power peripherals. */
if (pm_low_power_devices()) {
return _handle_device_abort(z_power_state);
} break;
case PM_STATE_SUSPEND_TO_RAM:
__fallthrough;
case PM_STATE_SUSPEND_TO_DISK:
if (pm_suspend_devices()) {
return _handle_device_abort(z_power_state);
}
/*
* Disable idle exit notification as it is not needed
* in deep sleep mode.
*/
#if CONFIG_PM_DEVICE
} else {
if (pm_policy_low_power_devices(z_power_state.state)) {
/* low power peripherals. */
if (pm_low_power_devices()) {
return _handle_device_abort(z_power_state);
}
low_power = true;
}
#endif
break;
default:
should_resume_devices = false;
break;
}
#endif
pm_debug_start_timer();
/* Enter power state */
pm_state_notify(true);
@ -190,7 +188,7 @@ enum pm_state pm_system_suspend(int32_t ticks)
/* Wake up sequence starts here */
#if CONFIG_PM_DEVICE
if (deep_sleep || low_power) {
if (should_resume_devices) {
/* Turn on peripherals and restore device states as necessary */
pm_resume_devices();
}

View File

@ -54,12 +54,6 @@ struct pm_state_info pm_policy_next_state(int32_t ticks)
return (struct pm_state_info){PM_STATE_ACTIVE, 0, 0};
}
/* Our PM device policy handler */
bool pm_policy_low_power_devices(enum pm_state state)
{
return pm_is_sleep_state(state);
}
/*work handler*/
static void work_handler(struct k_work *w)
{

View File

@ -59,11 +59,6 @@ __weak void pm_power_state_exit_post_ops(struct pm_state_info info)
irq_unlock(0);
}
__weak bool pm_policy_low_power_devices(enum pm_state state)
{
return pm_is_sleep_state(state);
}
/* Our PM policy handler */
struct pm_state_info pm_policy_next_state(int ticks)
{

View File

@ -14,7 +14,7 @@
#define LOG_LEVEL LOG_LEVEL_DBG
LOG_MODULE_REGISTER(pwrmgmt_test);
#define SLP_STATES_SUPPORTED 2ul
#define SLP_STATES_SUPPORTED (PM_STATE_SOFT_OFF + 1)
/* Thread properties */
#undef TASK_STACK_SIZE
@ -78,13 +78,8 @@ static void notify_pm_state_entry(enum pm_state state)
return;
}
if (pm_is_sleep_state(state)) {
pm_counters[0].entry_cnt++;
pm_latency_check();
} else if (pm_is_deep_sleep_state(state)) {
pm_counters[1].entry_cnt++;
pm_latency_check();
}
pm_counters[(int)state].entry_cnt++;
pm_latency_check();
}
static void notify_pm_state_exit(enum pm_state state)
@ -93,11 +88,7 @@ static void notify_pm_state_exit(enum pm_state state)
return;
}
if (pm_is_sleep_state(state)) {
pm_counters[0].exit_cnt++;
} else if (pm_is_deep_sleep_state(state)) {
pm_counters[1].exit_cnt++;
}
pm_counters[(int)state].exit_cnt++;
}
static struct pm_notifier notifier = {