pm: device_runtime: init into PM_DEVICE_STATE_OFF

Add a function to tell runtime power management that the device is
starting in the off state instead of active or suspended.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
This commit is contained in:
Jordan Yates 2022-01-06 22:08:37 +10:00 committed by Anas Nashif
commit 7101899328
2 changed files with 20 additions and 1 deletions

View file

@ -156,6 +156,24 @@ static inline void pm_device_runtime_init_suspended(const struct device *dev)
pm->state = PM_DEVICE_STATE_SUSPENDED; pm->state = PM_DEVICE_STATE_SUSPENDED;
} }
/**
* @brief Initialize a device state to #PM_DEVICE_STATE_OFF.
*
* 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 be connected to a power domain, at
* which case it won't be powered at boot.
*
* @param dev Device instance.
*/
static inline void pm_device_runtime_init_off(const struct device *dev)
{
struct pm_device *pm = dev->pm;
pm->state = PM_DEVICE_STATE_OFF;
}
#else #else
static inline int pm_device_runtime_enable(const struct device *dev) { return -ENOSYS; } 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; } static inline int pm_device_runtime_disable(const struct device *dev) { return -ENOSYS; }
@ -164,6 +182,7 @@ 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 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 bool pm_device_runtime_is_enabled(const struct device *dev) { return false; }
static inline void pm_device_runtime_init_suspended(const struct device *dev) { } static inline void pm_device_runtime_init_suspended(const struct device *dev) { }
static inline void pm_device_runtime_init_off(const struct device *dev) { }
#endif #endif
/** @} */ /** @} */

View file

@ -230,9 +230,9 @@ int pm_device_runtime_enable(const struct device *dev)
if (ret < 0) { if (ret < 0) {
goto unlock; goto unlock;
} }
pm->state = PM_DEVICE_STATE_SUSPENDED;
} }
pm->state = PM_DEVICE_STATE_SUSPENDED;
pm->usage = 0U; pm->usage = 0U;
atomic_set_bit(&pm->flags, PM_DEVICE_FLAG_RUNTIME_ENABLED); atomic_set_bit(&pm->flags, PM_DEVICE_FLAG_RUNTIME_ENABLED);