zephyr/subsys/pm/constraint.c
Gerard Marull-Paretas 2903680822 pm: constraint: drop __weak
No SoCs are re-implementing the constraints API. This _feature_ was
mostly put in place to cover TI platform needs, but it is no longer
needed. Refer to previous commit for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-02-28 10:18:38 +01:00

48 lines
1.1 KiB
C

/*
* Copyright (c) 2018 Intel Corporation.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr.h>
#include <string.h>
#include <device.h>
#include <sys/atomic.h>
#include <pm/state.h>
#include <logging/log.h>
LOG_MODULE_DECLARE(pm, CONFIG_PM_LOG_LEVEL);
static atomic_t power_state_disable_count[PM_STATE_COUNT];
void pm_constraint_set(enum pm_state state)
{
atomic_val_t v;
__ASSERT(state < PM_STATE_COUNT, "Invalid power state!");
v = atomic_inc(&power_state_disable_count[state]);
__ASSERT(v < UINT_MAX, "Power state disable count overflowed!");
/* Make compiler happy when assertions are disabled. */
(void)(v);
}
void pm_constraint_release(enum pm_state state)
{
atomic_val_t v;
__ASSERT(state < PM_STATE_COUNT, "Invalid power state!");
v = atomic_dec(&power_state_disable_count[state]);
__ASSERT(v > 0, "Power state disable count underflowed!");
/* Make compiler happy when assertions are disabled. */
(void)(v);
}
bool pm_constraint_get(enum pm_state state)
{
__ASSERT(state < PM_STATE_COUNT, "Invalid power state!");
return (atomic_get(&power_state_disable_count[state]) == 0);
}