pm: device_runtime: add an access function to get the usage counter
Add a pm_device_usage_get() to get the current usage counter. Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
This commit is contained in:
parent
8687304ea2
commit
df819a8609
|
@ -159,6 +159,17 @@ int pm_device_runtime_put_async(const struct device *dev, k_timeout_t delay);
|
|||
*/
|
||||
bool pm_device_runtime_is_enabled(const struct device *dev);
|
||||
|
||||
/**
|
||||
* @brief Return the current device usage counter.
|
||||
*
|
||||
* @param dev Device instance.
|
||||
*
|
||||
* @returns the current usage counter.
|
||||
* @retval -ENOTSUP If the device is not using runtime PM.
|
||||
* @retval -ENOSYS If the runtime PM is not enabled at all.
|
||||
*/
|
||||
int pm_device_runtime_usage(const struct device *dev);
|
||||
|
||||
#else
|
||||
|
||||
static inline int pm_device_runtime_auto_enable(const struct device *dev)
|
||||
|
@ -205,6 +216,12 @@ static inline bool pm_device_runtime_is_enabled(const struct device *dev)
|
|||
return false;
|
||||
}
|
||||
|
||||
static inline int pm_device_runtime_usage(const struct device *dev)
|
||||
{
|
||||
ARG_UNUSED(dev);
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
|
|
@ -560,3 +560,19 @@ bool pm_device_runtime_is_enabled(const struct device *dev)
|
|||
|
||||
return pm && atomic_test_bit(&pm->flags, PM_DEVICE_FLAG_RUNTIME_ENABLED);
|
||||
}
|
||||
|
||||
int pm_device_runtime_usage(const struct device *dev)
|
||||
{
|
||||
struct pm_device *pm = dev->pm;
|
||||
uint32_t usage;
|
||||
|
||||
if (!pm_device_runtime_is_enabled(dev)) {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
(void)k_sem_take(&pm->lock, K_FOREVER);
|
||||
usage = pm->base.usage;
|
||||
k_sem_give(&pm->lock);
|
||||
|
||||
return usage;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue