pm: Add API to check if a state disables a device

Add an API function that can be used by client code to check if a state
disables a device.

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
This commit is contained in:
Declan Snyder 2025-05-09 16:17:41 -05:00 committed by Benjamin Cabé
commit 6bd6e50838
2 changed files with 36 additions and 0 deletions

View file

@ -230,6 +230,21 @@ void pm_policy_device_power_lock_get(const struct device *dev);
*/
void pm_policy_device_power_lock_put(const struct device *dev);
/**
* @brief Check if a state will disable a device
*
* This function allows client code to check if a state will disable a device.
*
* @param dev Device reference.
* @param state The state to check on whether it disables the device.
* @param substate_id The substate to check on whether it disables the device.
*
* @retval true if the state disables the device
* @retval false if the state does not disable the device
*/
bool pm_policy_device_is_disabling_state(const struct device *dev,
enum pm_state state, uint8_t substate_id);
/**
* @brief Returns the ticks until the next event
*

View file

@ -1,6 +1,7 @@
/*
* Copyright (c) 2018 Intel Corporation.
* Copyright (c) 2022 Nordic Semiconductor ASA
* Copyright 2025 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -138,3 +139,23 @@ void pm_policy_device_power_lock_put(const struct device *dev)
}
#endif
}
bool pm_policy_device_is_disabling_state(const struct device *dev,
enum pm_state state, uint8_t substate_id)
{
#if DT_HAS_COMPAT_STATUS_OKAY(zephyr_power_state)
struct pm_state_device_constraint *constraints =
pm_policy_priv_device_find_device_constraints(dev);
if (constraints == NULL) {
return false;
}
for (size_t j = 0; j < constraints->pm_constraints_size; j++) {
if (constraints->constraints[j].state == state &&
constraints->constraints[j].substate_id == substate_id) {
return true;
}
}
#endif
return false;
}