pm: device: runtime: Add API to check if it is enabled

Add a new API to check if a device has device runtime feature enabled.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
This commit is contained in:
Flavio Ceolin 2021-11-05 19:18:02 -07:00 committed by Anas Nashif
commit b2aa5feb9d
2 changed files with 31 additions and 0 deletions

View file

@ -116,12 +116,27 @@ int pm_device_runtime_put(const struct device *dev);
*/
int pm_device_runtime_put_async(const struct device *dev);
/**
* @brief Check if device runtime is enabled for a given device.
*
* @funcprops \pre_kernel_ok
*
* @param dev Device instance.
*
* @retval true If device has device runtime PM enabled.
* @retval false If the device has device runtime PM disabled.
*
* @see pm_device_runtime_enable()
*/
bool pm_device_runtime_is_enabled(const struct device *dev);
#else
static inline void pm_device_runtime_enable(const struct device *dev) { }
static inline int pm_device_runtime_disable(const struct device *dev) { return -ENOSYS; }
static inline int pm_device_runtime_get(const struct device *dev) { return -ENOSYS; }
static inline int pm_device_runtime_put(const struct device *dev) { return -ENOSYS; }
static inline int pm_device_runtime_put_async(const struct device *dev) { return -ENOSYS; }
static inline bool pm_device_runtime_is_enabled(const struct device *dev) { return false; }
#endif
/** @} */

View file

@ -241,3 +241,19 @@ unlock:
return ret;
}
bool pm_device_runtime_is_enabled(const struct device *dev)
{
bool ret = false;
struct pm_device *pm = dev->pm;
if (!k_is_pre_kernel()) {
(void)k_mutex_lock(&pm->lock, K_FOREVER);
ret = pm->enable;
(void)k_mutex_unlock(&pm->lock);
} else {
ret = pm->enable;
}
return ret;
}