diff --git a/include/zephyr/pm/policy.h b/include/zephyr/pm/policy.h index 9a2d1d159be..0bc0ca6874f 100644 --- a/include/zephyr/pm/policy.h +++ b/include/zephyr/pm/policy.h @@ -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 * diff --git a/subsys/pm/policy/policy_device_lock.c b/subsys/pm/policy/policy_device_lock.c index 8cf4618a9c7..290a1ff5159 100644 --- a/subsys/pm/policy/policy_device_lock.c +++ b/subsys/pm/policy/policy_device_lock.c @@ -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; +}