pm: policy: move constraints to policy API
The pm_constraint_* APIs were effectively used by the policy manager only. This patch renames the API to the policy namespace and makes its naming more explicit: - pm_constraint_set -> pm_policy_state_lock_get() - pm_constraint_release -> pm_policy_state_lock_put() - pm_constraint_get -> pm_policy_state_lock_is_active() The reason for these changes is that constraints can be of many types: allow/disallow states, impose latency requirements, etc. The new naming also makes explicit that the API calls will influence the PM policy behavior. All drivers and documentation have been updated accordingly. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
d158f512ac
commit
5a71eeb35c
23 changed files with 191 additions and 195 deletions
|
@ -12,7 +12,7 @@
|
|||
#include <drivers/clock_control.h>
|
||||
#include <kernel.h>
|
||||
#include <pm/device.h>
|
||||
#include <pm/pm.h>
|
||||
#include <pm/policy.h>
|
||||
#include <soc.h>
|
||||
#include "soc_miwu.h"
|
||||
#include "soc_power.h"
|
||||
|
@ -35,11 +35,11 @@ struct uart_npcx_config {
|
|||
const struct npcx_alt *alts_list;
|
||||
};
|
||||
|
||||
enum uart_pm_constraint_flag {
|
||||
UART_PM_CONSTRAINT_TX_FLAG,
|
||||
UART_PM_CONSTRAINT_RX_FLAG,
|
||||
enum uart_pm_policy_state_flag {
|
||||
UART_PM_POLICY_STATE_TX_FLAG,
|
||||
UART_PM_POLICY_STATE_RX_FLAG,
|
||||
|
||||
UART_PM_CONSTRAINT_FLAG_COUNT,
|
||||
UART_PM_POLICY_STATE_FLAG_COUNT,
|
||||
};
|
||||
|
||||
/* Driver data */
|
||||
|
@ -52,7 +52,7 @@ struct uart_npcx_data {
|
|||
void *user_data;
|
||||
#endif
|
||||
#ifdef CONFIG_PM
|
||||
ATOMIC_DEFINE(pm_constraint_flag, UART_PM_CONSTRAINT_FLAG_COUNT);
|
||||
ATOMIC_DEFINE(pm_policy_state_flag, UART_PM_POLICY_STATE_FLAG_COUNT);
|
||||
#ifdef CONFIG_UART_CONSOLE_INPUT_EXPIRED
|
||||
struct k_work_delayable rx_refresh_timeout_work;
|
||||
#endif
|
||||
|
@ -60,19 +60,19 @@ struct uart_npcx_data {
|
|||
};
|
||||
|
||||
#if defined(CONFIG_PM) && defined(CONFIG_UART_INTERRUPT_DRIVEN)
|
||||
static void uart_npcx_pm_constraint_set(struct uart_npcx_data *data,
|
||||
enum uart_pm_constraint_flag flag)
|
||||
static void uart_npcx_pm_policy_state_lock_get(struct uart_npcx_data *data,
|
||||
enum uart_pm_policy_state_flag flag)
|
||||
{
|
||||
if (atomic_test_and_set_bit(data->pm_constraint_flag, flag) == 0) {
|
||||
pm_constraint_set(PM_STATE_SUSPEND_TO_IDLE);
|
||||
if (atomic_test_and_set_bit(data->pm_policy_state_flag, flag) == 0) {
|
||||
pm_policy_state_lock_get(PM_STATE_SUSPEND_TO_IDLE);
|
||||
}
|
||||
}
|
||||
|
||||
static void uart_npcx_pm_constraint_rel(struct uart_npcx_data *data,
|
||||
enum uart_pm_constraint_flag flag)
|
||||
static void uart_npcx_pm_policy_state_lock_put(struct uart_npcx_data *data,
|
||||
enum uart_pm_policy_state_flag flag)
|
||||
{
|
||||
if (atomic_test_and_clear_bit(data->pm_constraint_flag, flag) == 1) {
|
||||
pm_constraint_release(PM_STATE_SUSPEND_TO_IDLE);
|
||||
if (atomic_test_and_clear_bit(data->pm_policy_state_flag, flag) == 1) {
|
||||
pm_policy_state_lock_put(PM_STATE_SUSPEND_TO_IDLE);
|
||||
}
|
||||
}
|
||||
#endif /* defined(CONFIG_PM) && defined(CONFIG_UART_INTERRUPT_DRIVEN) */
|
||||
|
@ -151,7 +151,7 @@ static int uart_npcx_fifo_fill(const struct device *dev, const uint8_t *tx_data,
|
|||
#ifdef CONFIG_PM
|
||||
struct uart_npcx_data *data = dev->data;
|
||||
|
||||
uart_npcx_pm_constraint_set(data, UART_PM_CONSTRAINT_TX_FLAG);
|
||||
uart_npcx_pm_policy_state_lock_get(data, UART_PM_POLICY_STATE_TX_FLAG);
|
||||
inst->UTBUF = tx_data[tx_bytes++];
|
||||
inst->UFTCTL |= BIT(NPCX_UFTCTL_NXMIP_EN);
|
||||
#else
|
||||
|
@ -277,7 +277,7 @@ static void uart_npcx_isr(const struct device *dev)
|
|||
if (uart_npcx_irq_rx_ready(dev)) {
|
||||
k_timeout_t delay = K_MSEC(CONFIG_UART_CONSOLE_INPUT_EXPIRED_TIMEOUT);
|
||||
|
||||
uart_npcx_pm_constraint_set(data, UART_PM_CONSTRAINT_RX_FLAG);
|
||||
uart_npcx_pm_policy_state_lock_get(data, UART_PM_POLICY_STATE_RX_FLAG);
|
||||
k_work_reschedule(&data->rx_refresh_timeout_work, delay);
|
||||
}
|
||||
#endif
|
||||
|
@ -291,7 +291,7 @@ static void uart_npcx_isr(const struct device *dev)
|
|||
|
||||
if (IS_BIT_SET(inst->UFTCTL, NPCX_UFTCTL_NXMIP_EN) &&
|
||||
IS_BIT_SET(inst->UFTSTS, NPCX_UFTSTS_NXMIP)) {
|
||||
uart_npcx_pm_constraint_rel(data, UART_PM_CONSTRAINT_TX_FLAG);
|
||||
uart_npcx_pm_policy_state_lock_put(data, UART_PM_POLICY_STATE_TX_FLAG);
|
||||
inst->UFTCTL &= ~BIT(NPCX_UFTCTL_NXMIP_EN);
|
||||
}
|
||||
#endif /* CONFIG_PM */
|
||||
|
@ -381,7 +381,7 @@ static __unused void uart_npcx_rx_wk_isr(const struct device *dev, struct npcx_w
|
|||
struct uart_npcx_data *data = dev->data;
|
||||
k_timeout_t delay = K_MSEC(CONFIG_UART_CONSOLE_INPUT_EXPIRED_TIMEOUT);
|
||||
|
||||
uart_npcx_pm_constraint_set(data, UART_PM_CONSTRAINT_RX_FLAG);
|
||||
uart_npcx_pm_policy_state_lock_get(data, UART_PM_POLICY_STATE_RX_FLAG);
|
||||
k_work_reschedule(&data->rx_refresh_timeout_work, delay);
|
||||
#endif
|
||||
|
||||
|
@ -398,7 +398,7 @@ static void uart_npcx_rx_refresh_timeout(struct k_work *work)
|
|||
struct uart_npcx_data *data =
|
||||
CONTAINER_OF(work, struct uart_npcx_data, rx_refresh_timeout_work);
|
||||
|
||||
uart_npcx_pm_constraint_rel(data, UART_PM_CONSTRAINT_RX_FLAG);
|
||||
uart_npcx_pm_policy_state_lock_put(data, UART_PM_POLICY_STATE_RX_FLAG);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue