pm: device: Add device pm state lock
Add a new API to lock a device pm state. When the device has its state locked, the kernel will no longer suspend / resume devices when the system goes to sleep and device runtime power management operations will fail. Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
This commit is contained in:
parent
f8cd20fa3e
commit
097e08c71a
2 changed files with 74 additions and 0 deletions
|
@ -39,6 +39,8 @@ enum pm_device_flag {
|
||||||
PM_DEVICE_FLAG_WS_ENABLED,
|
PM_DEVICE_FLAG_WS_ENABLED,
|
||||||
/** Indicates if device runtime is enabled */
|
/** Indicates if device runtime is enabled */
|
||||||
PM_DEVICE_FLAG_RUNTIME_ENABLED,
|
PM_DEVICE_FLAG_RUNTIME_ENABLED,
|
||||||
|
/** Indicates if the device pm is locked. */
|
||||||
|
PM_DEVICE_FLAG_STATE_LOCKED,
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @endcond */
|
/** @endcond */
|
||||||
|
@ -407,6 +409,42 @@ bool pm_device_wakeup_is_enabled(const struct device *dev);
|
||||||
* @retval false If the device is not wake up capable.
|
* @retval false If the device is not wake up capable.
|
||||||
*/
|
*/
|
||||||
bool pm_device_wakeup_is_capable(const struct device *dev);
|
bool pm_device_wakeup_is_capable(const struct device *dev);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Lock current device state.
|
||||||
|
*
|
||||||
|
* This function locks the current device power state. Once
|
||||||
|
* locked the device power state will not be changed by
|
||||||
|
* system power management or device runtime power
|
||||||
|
* management until unlocked.
|
||||||
|
*
|
||||||
|
* @see pm_device_state_unlock
|
||||||
|
*
|
||||||
|
* @param dev Device instance.
|
||||||
|
*/
|
||||||
|
void pm_device_state_lock(const struct device *dev);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Unlock the current device state.
|
||||||
|
*
|
||||||
|
* Unlocks a previously locked device pm.
|
||||||
|
*
|
||||||
|
* @see pm_device_state_lock
|
||||||
|
*
|
||||||
|
* @param dev Device instance.
|
||||||
|
*/
|
||||||
|
void pm_device_state_unlock(const struct device *dev);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check if the device pm is locked.
|
||||||
|
*
|
||||||
|
* @param dev Device instance.
|
||||||
|
*
|
||||||
|
* @retval true If device is locked.
|
||||||
|
* @retval false If device is not locked.
|
||||||
|
*/
|
||||||
|
bool pm_device_state_is_locked(const struct device *dev);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
static inline void pm_device_busy_set(const struct device *dev) {}
|
static inline void pm_device_busy_set(const struct device *dev) {}
|
||||||
static inline void pm_device_busy_clear(const struct device *dev) {}
|
static inline void pm_device_busy_clear(const struct device *dev) {}
|
||||||
|
@ -424,6 +462,12 @@ static inline bool pm_device_wakeup_is_capable(const struct device *dev)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
static inline void pm_device_state_lock(const struct device *dev) {}
|
||||||
|
static inline void pm_device_state_unlock(const struct device *dev) {}
|
||||||
|
static inline bool pm_device_state_is_locked(const struct device *dev)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
#endif /* CONFIG_PM_DEVICE */
|
#endif /* CONFIG_PM_DEVICE */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -241,3 +241,33 @@ bool pm_device_wakeup_is_capable(const struct device *dev)
|
||||||
return atomic_test_bit(&pm->flags,
|
return atomic_test_bit(&pm->flags,
|
||||||
PM_DEVICE_FLAG_WS_CAPABLE);
|
PM_DEVICE_FLAG_WS_CAPABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pm_device_state_lock(const struct device *dev)
|
||||||
|
{
|
||||||
|
struct pm_device *pm = dev->pm;
|
||||||
|
|
||||||
|
if (pm != NULL) {
|
||||||
|
atomic_set_bit(&pm->flags, PM_DEVICE_FLAG_STATE_LOCKED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void pm_device_state_unlock(const struct device *dev)
|
||||||
|
{
|
||||||
|
struct pm_device *pm = dev->pm;
|
||||||
|
|
||||||
|
if (pm != NULL) {
|
||||||
|
atomic_clear_bit(&pm->flags, PM_DEVICE_FLAG_STATE_LOCKED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pm_device_state_is_locked(const struct device *dev)
|
||||||
|
{
|
||||||
|
struct pm_device *pm = dev->pm;
|
||||||
|
|
||||||
|
if (pm == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return atomic_test_bit(&pm->flags,
|
||||||
|
PM_DEVICE_FLAG_STATE_LOCKED);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue