2019-06-25 12:26:13 -04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2012-2014 Wind River Systems, Inc.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ZEPHYR_INCLUDE_POWER_POWER_H_
|
|
|
|
#define ZEPHYR_INCLUDE_POWER_POWER_H_
|
|
|
|
|
|
|
|
#include <zephyr/types.h>
|
2021-01-21 13:37:04 +01:00
|
|
|
#include <sys/slist.h>
|
2020-10-23 16:17:18 -07:00
|
|
|
#include <power/power_state.h>
|
2021-02-09 08:15:47 -06:00
|
|
|
#include <toolchain.h>
|
2019-06-25 12:26:13 -04:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @defgroup power_management_api Power Management
|
|
|
|
* @{
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2020-09-01 18:31:40 -04:00
|
|
|
#ifdef CONFIG_PM
|
2019-06-25 12:26:13 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief System Power Management API
|
|
|
|
*
|
|
|
|
* @defgroup system_power_management_api System Power Management API
|
|
|
|
* @ingroup power_management_api
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2020-10-14 21:59:51 -07:00
|
|
|
/**
|
|
|
|
* Power management notifier struct
|
|
|
|
*
|
|
|
|
* This struct contains callbacks that are called when the target enters and
|
|
|
|
* exits power states.
|
|
|
|
*
|
|
|
|
* As currently implemented the entry callback is invoked when
|
|
|
|
* transitioning from PM_STATE_ACTIVE to another state, and the exit
|
|
|
|
* callback is invoked when transitioning from a non-active state to
|
|
|
|
* PM_STATE_ACTIVE. This behavior may change in the future.
|
|
|
|
*
|
|
|
|
* @note These callbacks can be called from the ISR of the event
|
|
|
|
* that caused the kernel exit from idling.
|
2021-03-10 14:59:28 -08:00
|
|
|
*
|
|
|
|
* @note It is not allowed to call @ref pm_notifier_unregister or
|
|
|
|
* @ref pm_notifier_register from these callbacks because they are called
|
|
|
|
* with the spin locked in those functions.
|
2020-10-14 21:59:51 -07:00
|
|
|
*/
|
|
|
|
struct pm_notifier {
|
|
|
|
sys_snode_t _node;
|
|
|
|
/**
|
|
|
|
* Application defined function for doing any target specific operations
|
|
|
|
* for power state entry.
|
|
|
|
*/
|
2020-12-07 21:51:46 -08:00
|
|
|
void (*state_entry)(enum pm_state state);
|
2020-10-14 21:59:51 -07:00
|
|
|
/**
|
|
|
|
* Application defined function for doing any target specific operations
|
|
|
|
* for power state exit.
|
|
|
|
*/
|
2020-12-07 21:51:46 -08:00
|
|
|
void (*state_exit)(enum pm_state state);
|
2020-10-14 21:59:51 -07:00
|
|
|
};
|
|
|
|
|
2019-06-25 12:26:13 -04:00
|
|
|
/**
|
|
|
|
* @brief Force usage of given power state.
|
|
|
|
*
|
2020-01-22 03:29:50 -05:00
|
|
|
* This function overrides decision made by PM policy forcing
|
2021-02-23 10:31:35 -08:00
|
|
|
* usage of given power state immediately.
|
2019-06-25 12:26:13 -04:00
|
|
|
*
|
2021-02-23 10:31:35 -08:00
|
|
|
* @note This function can only run in thread context
|
2020-01-22 03:36:21 -05:00
|
|
|
*
|
2021-01-12 13:23:18 -08:00
|
|
|
* @param info Power state which should be used in the ongoing
|
|
|
|
* suspend operation.
|
2019-06-25 12:26:13 -04:00
|
|
|
*/
|
2021-01-12 13:23:18 -08:00
|
|
|
void pm_power_state_force(struct pm_state_info info);
|
2019-06-25 12:26:13 -04:00
|
|
|
|
2020-09-01 18:31:40 -04:00
|
|
|
#ifdef CONFIG_PM_DEBUG
|
2019-06-25 12:26:13 -04:00
|
|
|
/**
|
|
|
|
* @brief Dump Low Power states related debug info
|
|
|
|
*
|
|
|
|
* Dump Low Power states debug info like LPS entry count and residencies.
|
|
|
|
*/
|
2020-09-01 21:46:30 -04:00
|
|
|
void pm_dump_debug_info(void);
|
2019-06-25 12:26:13 -04:00
|
|
|
|
2020-09-01 18:31:40 -04:00
|
|
|
#endif /* CONFIG_PM_DEBUG */
|
2019-06-25 12:26:13 -04:00
|
|
|
|
2021-03-16 14:18:34 -07:00
|
|
|
/**
|
|
|
|
* @brief Register a power management notifier
|
|
|
|
*
|
|
|
|
* Register the given notifier from the power management notification
|
|
|
|
* list.
|
|
|
|
*
|
|
|
|
* @param notifier pm_notifier object to be registered.
|
|
|
|
*/
|
|
|
|
void pm_notifier_register(struct pm_notifier *notifier);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Unregister a power management notifier
|
|
|
|
*
|
|
|
|
* Remove the given notifier from the power management notification
|
|
|
|
* list. After that this object callbacks will not be called.
|
|
|
|
*
|
|
|
|
* @param notifier pm_notifier object to be unregistered.
|
|
|
|
*
|
|
|
|
* @return 0 if the notifier was successfully removed, a negative value
|
|
|
|
* otherwise.
|
|
|
|
*/
|
|
|
|
int pm_notifier_unregister(struct pm_notifier *notifier);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief System Power Management Constraint API
|
|
|
|
*
|
|
|
|
* @defgroup system_power_management_constraint_api Constraint API
|
|
|
|
* @ingroup power_management_api
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2019-06-25 12:26:13 -04:00
|
|
|
/**
|
2021-01-25 20:47:22 -08:00
|
|
|
* @brief Set a constraint for a power state
|
2019-06-25 12:26:13 -04:00
|
|
|
*
|
|
|
|
* @details Disabled state cannot be selected by the Zephyr power
|
|
|
|
* management policies. Application defined policy should
|
2021-01-25 18:03:08 -08:00
|
|
|
* use the @ref pm_constraint_get function to
|
2021-01-25 20:58:27 -08:00
|
|
|
* check if given state is enabled and could be used.
|
2019-06-25 12:26:13 -04:00
|
|
|
*
|
2021-01-25 20:47:22 -08:00
|
|
|
* @note This API is refcount
|
|
|
|
*
|
2019-06-25 12:26:13 -04:00
|
|
|
* @param [in] state Power state to be disabled.
|
|
|
|
*/
|
2021-01-25 18:03:08 -08:00
|
|
|
void pm_constraint_set(enum pm_state state);
|
2019-06-25 12:26:13 -04:00
|
|
|
|
|
|
|
/**
|
2021-01-25 20:47:22 -08:00
|
|
|
* @brief Release a constraint for a power state
|
2019-06-25 12:26:13 -04:00
|
|
|
*
|
|
|
|
* @details Enabled state can be selected by the Zephyr power
|
|
|
|
* management policies. Application defined policy should
|
2021-01-25 18:03:08 -08:00
|
|
|
* use the @ref pm_constraint_get function to
|
2021-01-25 20:58:27 -08:00
|
|
|
* check if given state is enabled and could be used.
|
2019-06-25 12:26:13 -04:00
|
|
|
* By default all power states are enabled.
|
|
|
|
*
|
2021-01-25 20:47:22 -08:00
|
|
|
* @note This API is refcount
|
|
|
|
*
|
2019-06-25 12:26:13 -04:00
|
|
|
* @param [in] state Power state to be enabled.
|
|
|
|
*/
|
2021-01-25 18:03:08 -08:00
|
|
|
void pm_constraint_release(enum pm_state state);
|
2019-06-25 12:26:13 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Check if particular power state is enabled
|
|
|
|
*
|
|
|
|
* This function returns true if given power state is enabled.
|
|
|
|
*
|
|
|
|
* @param [in] state Power state.
|
|
|
|
*/
|
2021-01-25 18:03:08 -08:00
|
|
|
bool pm_constraint_get(enum pm_state state);
|
2019-06-25 12:26:13 -04:00
|
|
|
|
2021-03-10 15:31:14 -08:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Power Management Hooks
|
|
|
|
*
|
|
|
|
* @defgroup power_management_hook_interface Power Management Hooks
|
|
|
|
* @ingroup power_management_api
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Put processor into a power state.
|
|
|
|
*
|
|
|
|
* This function implements the SoC specific details necessary
|
|
|
|
* to put the processor into available power states.
|
|
|
|
*
|
|
|
|
* @param info Power state which should be used in the ongoing
|
|
|
|
* suspend operation.
|
|
|
|
*/
|
|
|
|
void pm_power_state_set(struct pm_state_info info);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Do any SoC or architecture specific post ops after sleep state exits.
|
|
|
|
*
|
|
|
|
* This function is a place holder to do any operations that may
|
|
|
|
* be needed to be done after sleep state exits. Currently it enables
|
|
|
|
* interrupts after resuming from sleep state. In future, the enabling
|
|
|
|
* of interrupts may be moved into the kernel.
|
|
|
|
*/
|
|
|
|
void pm_power_state_exit_post_ops(struct pm_state_info info);
|
|
|
|
|
2019-06-25 12:26:13 -04:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2020-09-04 10:47:50 -04:00
|
|
|
|
|
|
|
void z_pm_save_idle_exit(int32_t ticks);
|
2020-09-01 18:31:40 -04:00
|
|
|
#endif /* CONFIG_PM */
|
2019-06-25 12:26:13 -04:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* ZEPHYR_INCLUDE_POWER_POWER_H_ */
|