pm: device_runtime: add pm_device_runtime_init_suspended
By default device state is initialized to PM_DEVICE_STATE_ACTIVE. In general, this makes sense because the device initialization function will resume and configure a device, leaving it operational. However, when device runtime PM is enabled, the device may not be resumed and the init function will just enable device runtime PM. If that is the case, this function can be used to set the initial device state to PM_DEVICE_STATE_SUSPENDED. Documentation has been updated to comment on this case, and example code has been adjusted accordingly. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
59b455eb9c
commit
d6ebab55f3
1 changed files with 20 additions and 0 deletions
|
@ -131,6 +131,25 @@ int pm_device_runtime_put_async(const struct device *dev);
|
|||
*/
|
||||
bool pm_device_runtime_is_enabled(const struct device *dev);
|
||||
|
||||
/**
|
||||
* @brief Initialize a device state to #PM_DEVICE_STATE_SUSPENDED.
|
||||
*
|
||||
* By default device state is initialized to #PM_DEVICE_STATE_ACTIVE. In
|
||||
* general, this makes sense because the device initialization function will
|
||||
* resume and configure a device, leaving it operational. However, when device
|
||||
* runtime PM is enabled, the device may not be resumed and the init function
|
||||
* will just enable device runtime PM. If that is the case, this function can be
|
||||
* used to set the initial device state to #PM_DEVICE_STATE_SUSPENDED.
|
||||
*
|
||||
* @param dev Device instance.
|
||||
*/
|
||||
static inline void pm_device_runtime_init_suspended(const struct device *dev)
|
||||
{
|
||||
struct pm_device *pm = dev->pm;
|
||||
|
||||
pm->state = PM_DEVICE_STATE_SUSPENDED;
|
||||
}
|
||||
|
||||
#else
|
||||
static inline int pm_device_runtime_enable(const struct device *dev) { return -ENOSYS; }
|
||||
static inline int pm_device_runtime_disable(const struct device *dev) { return -ENOSYS; }
|
||||
|
@ -138,6 +157,7 @@ static inline int pm_device_runtime_get(const struct device *dev) { return 0; }
|
|||
static inline int pm_device_runtime_put(const struct device *dev) { return 0; }
|
||||
static inline int pm_device_runtime_put_async(const struct device *dev) { return 0; }
|
||||
static inline bool pm_device_runtime_is_enabled(const struct device *dev) { return false; }
|
||||
static inline void pm_device_runtime_init_suspended(const struct device *dev) { }
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue