2018-11-05 18:06:04 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Intel Corporation.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <zephyr.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <device.h>
|
2019-06-26 00:25:32 +08:00
|
|
|
#include <sys/atomic.h>
|
2018-11-05 18:06:04 +08:00
|
|
|
#include "policy/pm_policy.h"
|
|
|
|
|
2019-02-04 22:05:23 +08:00
|
|
|
#define LOG_LEVEL CONFIG_SYS_PM_LOG_LEVEL /* From power module Kconfig */
|
2018-11-05 18:06:04 +08:00
|
|
|
#include <logging/log.h>
|
|
|
|
LOG_MODULE_DECLARE(power);
|
|
|
|
|
2019-01-11 17:53:57 +08:00
|
|
|
static atomic_t power_state_disable_count[SYS_POWER_STATE_MAX];
|
2018-11-05 18:06:04 +08:00
|
|
|
|
2019-01-11 17:53:57 +08:00
|
|
|
void sys_pm_ctrl_disable_state(enum power_states state)
|
2018-11-05 18:06:04 +08:00
|
|
|
{
|
2019-01-11 17:53:57 +08:00
|
|
|
atomic_val_t v;
|
|
|
|
|
|
|
|
__ASSERT(state < SYS_POWER_STATE_MAX, "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);
|
2018-11-05 18:06:04 +08:00
|
|
|
}
|
|
|
|
|
2019-01-11 17:53:57 +08:00
|
|
|
void sys_pm_ctrl_enable_state(enum power_states state)
|
2018-11-05 18:06:04 +08:00
|
|
|
{
|
2019-01-11 17:53:57 +08:00
|
|
|
atomic_val_t v;
|
|
|
|
|
|
|
|
__ASSERT(state < SYS_POWER_STATE_MAX, "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);
|
2018-11-05 18:06:04 +08:00
|
|
|
}
|
|
|
|
|
2019-01-11 17:53:57 +08:00
|
|
|
bool sys_pm_ctrl_is_state_enabled(enum power_states state)
|
2018-11-05 18:06:04 +08:00
|
|
|
{
|
2019-01-11 17:53:57 +08:00
|
|
|
__ASSERT(state < SYS_POWER_STATE_MAX, "Invalid power state!");
|
2018-11-05 18:06:04 +08:00
|
|
|
|
2019-01-11 17:53:57 +08:00
|
|
|
return (atomic_get(&power_state_disable_count[state]) == 0);
|
2018-11-05 18:06:04 +08:00
|
|
|
}
|