123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
- #ifndef ZEPHYR_INCLUDE_PM_DEVICE_H_
- #define ZEPHYR_INCLUDE_PM_DEVICE_H_
- #include <kernel.h>
- #include <sys/atomic.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- struct device;
- enum pm_device_state {
-
- PM_DEVICE_STATE_ACTIVE,
-
- PM_DEVICE_STATE_LOW_POWER,
-
- PM_DEVICE_STATE_SUSPENDED,
-
- PM_DEVICE_STATE_OFF
- };
- enum pm_device_flag {
-
- PM_DEVICE_FLAG_BUSY,
-
- PM_DEVICE_FLAGS_WS_CAPABLE,
-
- PM_DEVICE_FLAGS_WS_ENABLED,
-
- PM_DEVICE_FLAG_TRANSITIONING,
-
- PM_DEVICE_FLAG_COUNT
- };
- enum pm_device_action {
-
- PM_DEVICE_ACTION_SUSPEND,
-
- PM_DEVICE_ACTION_RESUME,
-
- PM_DEVICE_ACTION_TURN_OFF,
-
- PM_DEVICE_ACTION_FORCE_SUSPEND,
-
- PM_DEVICE_ACTION_LOW_POWER,
-
- PM_DEVICE_ACTION_EARLY_SUSPEND,
-
- PM_DEVICE_ACTION_LATE_RESUME,
- };
- struct pm_device {
-
- const struct device *dev;
-
- struct k_mutex lock;
-
-
- bool enable : 1;
-
- atomic_t flags;
-
- uint32_t usage;
-
- enum pm_device_state state;
-
- struct k_work_delayable work;
-
- struct k_condvar condvar;
- };
- #define Z_PM_DEVICE_INIT(obj, node_id) \
- { \
- .usage = 0U, \
- .lock = Z_MUTEX_INITIALIZER(obj.lock), \
- .condvar = Z_CONDVAR_INITIALIZER(obj.condvar), \
- .state = PM_DEVICE_STATE_ACTIVE, \
- .flags = ATOMIC_INIT(COND_CODE_1( \
- DT_NODE_EXISTS(node_id), \
- (DT_PROP_OR(node_id, wakeup_source, 0)),\
- (0)) << PM_DEVICE_FLAGS_WS_CAPABLE), \
- }
- typedef int (*pm_device_control_callback_t)(const struct device *dev,
- enum pm_device_action action);
- const char *pm_device_state_str(enum pm_device_state state);
- int pm_device_state_set(const struct device *dev,
- enum pm_device_state state);
- int pm_device_state_get(const struct device *dev,
- enum pm_device_state *state);
- #ifdef CONFIG_PM_DEVICE
- void pm_device_busy_set(const struct device *dev);
- void pm_device_busy_clear(const struct device *dev);
- bool pm_device_is_any_busy(void);
- bool pm_device_is_busy(const struct device *dev);
- #else
- static inline void pm_device_busy_set(const struct device *dev) {}
- static inline void pm_device_busy_clear(const struct device *dev) {}
- static inline bool pm_device_is_any_busy(void) { return false; }
- static inline bool pm_device_is_busy(const struct device *dev) { return false; }
- #endif
- __deprecated static inline void device_busy_set(const struct device *dev)
- {
- pm_device_busy_set(dev);
- }
- __deprecated static inline void device_busy_clear(const struct device *dev)
- {
- pm_device_busy_clear(dev);
- }
- __deprecated static inline int device_any_busy_check(void)
- {
- return pm_device_is_any_busy() ? -EBUSY : 0;
- }
- __deprecated static inline int device_busy_check(const struct device *dev)
- {
- return pm_device_is_busy(dev) ? -EBUSY : 0;
- }
- #define device_pm_control_nop __DEPRECATED_MACRO NULL
- bool pm_device_wakeup_enable(struct device *dev, bool enable);
- bool pm_device_wakeup_is_enabled(const struct device *dev);
- bool pm_device_wakeup_is_capable(const struct device *dev);
- #ifdef __cplusplus
- }
- #endif
- #endif
|