diff --git a/boards/arm/cc1352r1_launchxl/doc/index.rst b/boards/arm/cc1352r1_launchxl/doc/index.rst index 611ab3b74fb99..721a3547a7b92 100644 --- a/boards/arm/cc1352r1_launchxl/doc/index.rst +++ b/boards/arm/cc1352r1_launchxl/doc/index.rst @@ -216,9 +216,9 @@ disable sleep state 2 while polling: .. code-block:: c - pm_ctrl_disable_state(PM_STATE_STANDBY); + pm_constraint_set(PM_STATE_STANDBY); - pm_ctrl_enable_state(PM_STATE_STANDBY); + pm_constraint_release(PM_STATE_STANDBY); References diff --git a/boards/arm/cc1352r_sensortag/doc/index.rst b/boards/arm/cc1352r_sensortag/doc/index.rst index 2a93128feb445..172cf0d7a0a84 100644 --- a/boards/arm/cc1352r_sensortag/doc/index.rst +++ b/boards/arm/cc1352r_sensortag/doc/index.rst @@ -242,9 +242,9 @@ disable sleep state 2 while polling: .. code-block:: c - pm_ctrl_disable_state(PM_STATE_STANDBY); + pm_constraint_set(PM_STATE_STANDBY); - pm_ctrl_enable_state(PM_STATE_STANDBY); + pm_constraint_release(PM_STATE_STANDBY); References diff --git a/boards/arm/cc26x2r1_launchxl/doc/index.rst b/boards/arm/cc26x2r1_launchxl/doc/index.rst index bc01d49494ac5..4972640062588 100644 --- a/boards/arm/cc26x2r1_launchxl/doc/index.rst +++ b/boards/arm/cc26x2r1_launchxl/doc/index.rst @@ -222,9 +222,9 @@ disable sleep state 2 while polling: .. code-block:: c - pm_ctrl_disable_state(PM_STATE_STANDBY); + pm_constraint_set(PM_STATE_STANDBY); - pm_ctrl_enable_state(PM_STATE_STANDBY); + pm_constraint_release(PM_STATE_STANDBY); References diff --git a/drivers/entropy/entropy_cc13xx_cc26xx.c b/drivers/entropy/entropy_cc13xx_cc26xx.c index 2e84c0ea71c96..37ba036aa6520 100644 --- a/drivers/entropy/entropy_cc13xx_cc26xx.c +++ b/drivers/entropy/entropy_cc13xx_cc26xx.c @@ -109,7 +109,7 @@ static int entropy_cc13xx_cc26xx_get_entropy(const struct device *dev, unsigned int key = irq_lock(); if (!data->constrained) { - pm_ctrl_disable_state(PM_STATE_STANDBY); + pm_constraint_set(PM_STATE_STANDBY); data->constrained = true; } irq_unlock(key); @@ -154,7 +154,7 @@ static void entropy_cc13xx_cc26xx_isr(const void *arg) if (cnt != sizeof(num)) { #ifdef CONFIG_PM if (data->constrained) { - pm_ctrl_enable_state( + pm_constraint_release( PM_STATE_STANDBY); data->constrained = false; } @@ -333,7 +333,7 @@ static int entropy_cc13xx_cc26xx_init(const struct device *dev) #if defined(CONFIG_PM) Power_setDependency(PowerCC26XX_PERIPH_TRNG); /* Stay out of standby until buffer is filled with entropy */ - pm_ctrl_disable_state(PM_STATE_STANDBY); + pm_constraint_set(PM_STATE_STANDBY); data->constrained = true; /* Register notification function */ Power_registerNotify(&data->post_notify, diff --git a/drivers/i2c/i2c_cc13xx_cc26xx.c b/drivers/i2c/i2c_cc13xx_cc26xx.c index 70fbfe64333ee..a1d6e3e1a8399 100644 --- a/drivers/i2c/i2c_cc13xx_cc26xx.c +++ b/drivers/i2c/i2c_cc13xx_cc26xx.c @@ -208,7 +208,7 @@ static int i2c_cc13xx_cc26xx_transfer(const struct device *dev, k_sem_take(&get_dev_data(dev)->lock, K_FOREVER); #ifdef CONFIG_PM - pm_ctrl_disable_state(PM_STATE_STANDBY); + pm_constraint_set(PM_STATE_STANDBY); #endif for (int i = 0; i < num_msgs; i++) { @@ -232,7 +232,7 @@ static int i2c_cc13xx_cc26xx_transfer(const struct device *dev, } #ifdef CONFIG_PM - pm_ctrl_enable_state(PM_STATE_STANDBY); + pm_constraint_release(PM_STATE_STANDBY); #endif k_sem_give(&get_dev_data(dev)->lock); diff --git a/drivers/serial/uart_cc13xx_cc26xx.c b/drivers/serial/uart_cc13xx_cc26xx.c index 69df95e7e07d2..57ba5fd4593e3 100644 --- a/drivers/serial/uart_cc13xx_cc26xx.c +++ b/drivers/serial/uart_cc13xx_cc26xx.c @@ -243,7 +243,7 @@ static void uart_cc13xx_cc26xx_irq_tx_enable(const struct device *dev) * standby mode instead, since it is the power state that * would interfere with a transfer. */ - pm_ctrl_disable_state(PM_STATE_STANDBY); + pm_constraint_set(PM_STATE_STANDBY); get_dev_data(dev)->tx_constrained = true; } #endif @@ -257,7 +257,7 @@ static void uart_cc13xx_cc26xx_irq_tx_disable(const struct device *dev) #ifdef CONFIG_PM if (get_dev_data(dev)->tx_constrained) { - pm_ctrl_enable_state(PM_STATE_STANDBY); + pm_constraint_release(PM_STATE_STANDBY); get_dev_data(dev)->tx_constrained = false; } #endif @@ -277,7 +277,7 @@ static void uart_cc13xx_cc26xx_irq_rx_enable(const struct device *dev) * standby. */ if (!get_dev_data(dev)->rx_constrained) { - pm_ctrl_disable_state(PM_STATE_STANDBY); + pm_constraint_set(PM_STATE_STANDBY); get_dev_data(dev)->rx_constrained = true; } #endif @@ -289,7 +289,7 @@ static void uart_cc13xx_cc26xx_irq_rx_disable(const struct device *dev) { #ifdef CONFIG_PM if (get_dev_data(dev)->rx_constrained) { - pm_ctrl_enable_state(PM_STATE_STANDBY); + pm_constraint_release(PM_STATE_STANDBY); get_dev_data(dev)->rx_constrained = false; } #endif diff --git a/drivers/spi/spi_cc13xx_cc26xx.c b/drivers/spi/spi_cc13xx_cc26xx.c index 8000dd360ed46..57155810307bb 100644 --- a/drivers/spi/spi_cc13xx_cc26xx.c +++ b/drivers/spi/spi_cc13xx_cc26xx.c @@ -149,7 +149,7 @@ static int spi_cc13xx_cc26xx_transceive(const struct device *dev, spi_context_lock(ctx, false, NULL, config); #ifdef CONFIG_PM - pm_ctrl_disable_state(PM_STATE_STANDBY); + pm_constraint_set(PM_STATE_STANDBY); #endif err = spi_cc13xx_cc26xx_configure(dev, config); @@ -185,7 +185,7 @@ static int spi_cc13xx_cc26xx_transceive(const struct device *dev, done: #ifdef CONFIG_PM - pm_ctrl_enable_state(PM_STATE_STANDBY); + pm_constraint_release(PM_STATE_STANDBY); #endif spi_context_release(ctx, err); return err; diff --git a/include/power/power.h b/include/power/power.h index 1f1a0829edcf7..19eccc4037f1d 100644 --- a/include/power/power.h +++ b/include/power/power.h @@ -159,31 +159,34 @@ void pm_dump_debug_info(void); #endif /* CONFIG_PM_DEBUG */ -#ifdef CONFIG_PM_STATE_LOCK /** - * @brief Disable particular power state + * @brief Set a constraint for a power state * * @details Disabled state cannot be selected by the Zephyr power * management policies. Application defined policy should - * use the @ref pm_ctrl_is_state_enabled function to - * check if given state could is enabled and could be used. + * use the @ref pm_constraint_get function to + * check if given state is enabled and could be used. + * + * @note This API is refcount * * @param [in] state Power state to be disabled. */ -void pm_ctrl_disable_state(enum pm_state state); +void pm_constraint_set(enum pm_state state); /** - * @brief Enable particular power state + * @brief Release a constraint for a power state * * @details Enabled state can be selected by the Zephyr power * management policies. Application defined policy should - * use the @ref pm_ctrl_is_state_enabled function to - * check if given state could is enabled and could be used. + * use the @ref pm_constraint_get function to + * check if given state is enabled and could be used. * By default all power states are enabled. * + * @note This API is refcount + * * @param [in] state Power state to be enabled. */ -void pm_ctrl_enable_state(enum pm_state state); +void pm_constraint_release(enum pm_state state); /** * @brief Check if particular power state is enabled @@ -192,9 +195,8 @@ void pm_ctrl_enable_state(enum pm_state state); * * @param [in] state Power state. */ -bool pm_ctrl_is_state_enabled(enum pm_state state); +bool pm_constraint_get(enum pm_state state); -#endif /* CONFIG_PM_STATE_LOCK */ /** * @} diff --git a/samples/boards/nrf/system_off/prj.conf b/samples/boards/nrf/system_off/prj.conf index a59aeab47fcc9..134a3f5f5a22e 100644 --- a/samples/boards/nrf/system_off/prj.conf +++ b/samples/boards/nrf/system_off/prj.conf @@ -1,5 +1,4 @@ CONFIG_PM=y # Required to disable default behavior of deep sleep on timeout -CONFIG_PM_STATE_LOCK=y CONFIG_PM_DEVICE=y CONFIG_GPIO=y diff --git a/samples/boards/nrf/system_off/src/main.c b/samples/boards/nrf/system_off/src/main.c index fb692875b1fc2..ffe97641bf002 100644 --- a/samples/boards/nrf/system_off/src/main.c +++ b/samples/boards/nrf/system_off/src/main.c @@ -27,7 +27,7 @@ static int disable_ds_1(const struct device *dev) { ARG_UNUSED(dev); - pm_ctrl_disable_state(PM_STATE_SOFT_OFF); + pm_constraint_set(PM_STATE_SOFT_OFF); return 0; } diff --git a/soc/arm/ti_simplelink/cc13x2_cc26x2/Kconfig.series b/soc/arm/ti_simplelink/cc13x2_cc26x2/Kconfig.series index 31679136bd6c6..798e0dc6a659c 100644 --- a/soc/arm/ti_simplelink/cc13x2_cc26x2/Kconfig.series +++ b/soc/arm/ti_simplelink/cc13x2_cc26x2/Kconfig.series @@ -12,6 +12,5 @@ config SOC_SERIES_CC13X2_CC26X2 select SOC_FAMILY_TISIMPLELINK select HAS_CC13X2_CC26X2_SDK select HAS_TI_CCFG - select PM_STATE_LOCK if PM help Enable support for TI SimpleLink CC13x2 / CC26x2 SoCs diff --git a/subsys/power/CMakeLists.txt b/subsys/power/CMakeLists.txt index a4a17025f5bd0..ba02f41218e1d 100644 --- a/subsys/power/CMakeLists.txt +++ b/subsys/power/CMakeLists.txt @@ -1,8 +1,8 @@ # SPDX-License-Identifier: Apache-2.0 zephyr_sources_ifdef(CONFIG_PM power.c) +zephyr_sources_ifdef(CONFIG_PM pm_ctrl.c) zephyr_sources_ifdef(CONFIG_PM_DEVICE device.c) -zephyr_sources_ifdef(CONFIG_PM_STATE_LOCK pm_ctrl.c) zephyr_sources_ifdef(CONFIG_PM_DEVICE_IDLE device_pm.c) zephyr_sources_ifdef(CONFIG_REBOOT reboot.c) add_subdirectory(policy) diff --git a/subsys/power/Kconfig b/subsys/power/Kconfig index c6af5d69410fe..acdceb8d2c1cd 100644 --- a/subsys/power/Kconfig +++ b/subsys/power/Kconfig @@ -22,14 +22,6 @@ menuconfig PM if PM -config PM_STATE_LOCK - bool "Power State locking capability" - help - Enable Power Management system state locking capability - if any application wants to temporarily disable certain - Power States while doing any critical work or needs quick - response from hardware resources. - config PM_DIRECT_FORCE_MODE bool "System power management direct force trigger mode" help diff --git a/subsys/power/pm_ctrl.c b/subsys/power/pm_ctrl.c index 8ee64176377be..390c5d17258f3 100644 --- a/subsys/power/pm_ctrl.c +++ b/subsys/power/pm_ctrl.c @@ -19,7 +19,7 @@ LOG_MODULE_DECLARE(power); static atomic_t power_state_disable_count[PM_STATES_LEN]; -void pm_ctrl_disable_state(enum pm_state state) +void pm_constraint_set(enum pm_state state) { atomic_val_t v; @@ -31,7 +31,7 @@ void pm_ctrl_disable_state(enum pm_state state) (void)(v); } -void pm_ctrl_enable_state(enum pm_state state) +void pm_constraint_release(enum pm_state state) { atomic_val_t v; @@ -43,7 +43,7 @@ void pm_ctrl_enable_state(enum pm_state state) (void)(v); } -bool pm_ctrl_is_state_enabled(enum pm_state state) +bool pm_constraint_get(enum pm_state state) { __ASSERT(state < PM_STATES_LEN, "Invalid power state!"); diff --git a/subsys/power/policy/policy_dummy.c b/subsys/power/policy/policy_dummy.c index dec304fbb9c24..02c65e04a818b 100644 --- a/subsys/power/policy/policy_dummy.c +++ b/subsys/power/policy/policy_dummy.c @@ -32,12 +32,11 @@ struct pm_state_info pm_policy_next_state(int32_t ticks) do { i = (i + 1) % states_len; -#ifdef CONFIG_PM_STATE_LOCK - if (!pm_ctrl_is_state_enabled( + if (!pm_constraint_get( pm_dummy_states[i].state)) { continue; } -#endif + cur_pm_state_info = pm_dummy_states[i]; LOG_DBG("Selected power state: %u", pm_dummy_states[i].state); diff --git a/subsys/power/policy/policy_residency.c b/subsys/power/policy/policy_residency.c index 24cbbc154a1e4..096247165b4dc 100644 --- a/subsys/power/policy/policy_residency.c +++ b/subsys/power/policy/policy_residency.c @@ -20,11 +20,10 @@ struct pm_state_info pm_policy_next_state(int32_t ticks) int i; for (i = ARRAY_SIZE(pm_min_residency) - 1; i >= 0; i--) { -#ifdef CONFIG_PM_STATE_LOCK - if (!pm_ctrl_is_state_enabled(pm_min_residency[i].state)) { + if (!pm_constraint_get(pm_min_residency[i].state)) { continue; } -#endif + if ((ticks == K_TICKS_FOREVER) || (ticks >= k_us_to_ticks_ceil32( pm_min_residency[i].min_residency_us))) { diff --git a/subsys/power/policy/policy_residency_cc13x2_cc26x2.c b/subsys/power/policy/policy_residency_cc13x2_cc26x2.c index 9f153093af6db..bb474924c31ef 100644 --- a/subsys/power/policy/policy_residency_cc13x2_cc26x2.c +++ b/subsys/power/policy/policy_residency_cc13x2_cc26x2.c @@ -54,11 +54,10 @@ struct pm_state_info pm_policy_next_state(int32_t ticks) } for (i = ARRAY_SIZE(residency_info) - 1; i >= 0; i--) { -#ifdef CONFIG_PM_STATE_LOCK - if (!pm_ctrl_is_state_enabled(residency_info[i].state)) { + if (!pm_constraint_get(residency_info[i].state)) { continue; } -#endif + if ((ticks < k_us_to_ticks_ceil32(residency_info[i].min_residency_us)) && (ticks != K_TICKS_FOREVER)) {