pm: simplify state change check logic
The device PM control function will only be called if the requested state is different from the current one. A significant amount of drivers were checking for state changes, now unnecessary. This patch removes all this redundant logic. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
bc2990f82d
commit
920f30cc0e
22 changed files with 176 additions and 400 deletions
|
@ -265,43 +265,25 @@ static int post_notify_fxn(unsigned int eventType, uintptr_t eventArg,
|
|||
|
||||
#ifdef CONFIG_PM_DEVICE
|
||||
static int entropy_cc13xx_cc26xx_set_power_state(const struct device *dev,
|
||||
enum pm_device_state new_state)
|
||||
enum pm_device_state state)
|
||||
{
|
||||
struct entropy_cc13xx_cc26xx_data *data = get_dev_data(dev);
|
||||
int ret = 0;
|
||||
enum pm_device_state state;
|
||||
|
||||
(void)pm_device_state_get(dev, &state);
|
||||
|
||||
if ((new_state == PM_DEVICE_STATE_ACTIVE) && (new_state != state)) {
|
||||
if (state == PM_DEVICE_STATE_ACTIVE) {
|
||||
Power_setDependency(PowerCC26XX_PERIPH_TRNG);
|
||||
start_trng(data);
|
||||
} else {
|
||||
__ASSERT_NO_MSG(new_state == PM_DEVICE_STATE_LOW_POWER ||
|
||||
new_state == PM_DEVICE_STATE_SUSPEND ||
|
||||
new_state == PM_DEVICE_STATE_OFF);
|
||||
|
||||
if (state == PM_DEVICE_STATE_ACTIVE) {
|
||||
stop_trng(data);
|
||||
Power_releaseDependency(PowerCC26XX_PERIPH_TRNG);
|
||||
}
|
||||
stop_trng(data);
|
||||
Power_releaseDependency(PowerCC26XX_PERIPH_TRNG);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int entropy_cc13xx_cc26xx_pm_control(const struct device *dev,
|
||||
enum pm_device_state state)
|
||||
{
|
||||
int ret = 0;
|
||||
enum pm_device_state curr_state;
|
||||
|
||||
(void)pm_device_state_get(dev, &curr_state);
|
||||
if (state != curr_state) {
|
||||
ret = entropy_cc13xx_cc26xx_set_power_state(dev, state);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return entropy_cc13xx_cc26xx_set_power_state(dev, state);
|
||||
}
|
||||
#endif /* CONFIG_PM_DEVICE */
|
||||
|
||||
|
|
|
@ -628,36 +628,29 @@ static int spi_flash_at45_pm_control(const struct device *dev,
|
|||
enum pm_device_state state)
|
||||
{
|
||||
const struct spi_flash_at45_config *dev_config = get_dev_config(dev);
|
||||
int err = 0;
|
||||
enum pm_device_state curr_state;
|
||||
|
||||
(void)pm_device_state_get(dev, &curr_state);
|
||||
if (state != curr_state) {
|
||||
switch (state) {
|
||||
case PM_DEVICE_STATE_ACTIVE:
|
||||
acquire(dev);
|
||||
power_down_op(dev, CMD_EXIT_DPD,
|
||||
dev_config->t_exit_dpd);
|
||||
release(dev);
|
||||
break;
|
||||
switch (state) {
|
||||
case PM_DEVICE_STATE_ACTIVE:
|
||||
acquire(dev);
|
||||
power_down_op(dev, CMD_EXIT_DPD, dev_config->t_exit_dpd);
|
||||
release(dev);
|
||||
break;
|
||||
|
||||
case PM_DEVICE_STATE_LOW_POWER:
|
||||
case PM_DEVICE_STATE_SUSPEND:
|
||||
case PM_DEVICE_STATE_OFF:
|
||||
acquire(dev);
|
||||
power_down_op(dev,
|
||||
dev_config->use_udpd ? CMD_ENTER_UDPD
|
||||
: CMD_ENTER_DPD,
|
||||
dev_config->t_enter_dpd);
|
||||
release(dev);
|
||||
break;
|
||||
case PM_DEVICE_STATE_LOW_POWER:
|
||||
case PM_DEVICE_STATE_SUSPEND:
|
||||
case PM_DEVICE_STATE_OFF:
|
||||
acquire(dev);
|
||||
power_down_op(dev,
|
||||
dev_config->use_udpd ? CMD_ENTER_UDPD : CMD_ENTER_DPD,
|
||||
dev_config->t_enter_dpd);
|
||||
release(dev);
|
||||
break;
|
||||
|
||||
default:
|
||||
return -ENOTSUP;
|
||||
}
|
||||
default:
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
return err;
|
||||
return 0;
|
||||
}
|
||||
#endif /* IS_ENABLED(CONFIG_PM_DEVICE) */
|
||||
|
||||
|
|
|
@ -575,15 +575,15 @@ static const struct gpio_driver_api gpio_stm32_driver = {
|
|||
|
||||
#ifdef CONFIG_PM_DEVICE
|
||||
static int gpio_stm32_set_power_state(const struct device *dev,
|
||||
enum pm_device_state new_state)
|
||||
enum pm_device_state state)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (new_state == PM_DEVICE_STATE_ACTIVE) {
|
||||
if (state == PM_DEVICE_STATE_ACTIVE) {
|
||||
ret = gpio_stm32_clock_request(dev, true);
|
||||
} else if (new_state == PM_DEVICE_STATE_SUSPEND) {
|
||||
} else if (state == PM_DEVICE_STATE_SUSPEND) {
|
||||
ret = gpio_stm32_clock_request(dev, false);
|
||||
} else if (new_state == PM_DEVICE_STATE_LOW_POWER) {
|
||||
} else if (state == PM_DEVICE_STATE_LOW_POWER) {
|
||||
ret = gpio_stm32_clock_request(dev, false);
|
||||
}
|
||||
|
||||
|
@ -597,15 +597,7 @@ static int gpio_stm32_set_power_state(const struct device *dev,
|
|||
static int gpio_stm32_pm_device_ctrl(const struct device *dev,
|
||||
enum pm_device_state state)
|
||||
{
|
||||
int ret = 0;
|
||||
enum pm_device_state curr_state;
|
||||
|
||||
(void)pm_device_state_get(dev, &curr_state);
|
||||
if (state != curr_state) {
|
||||
ret = gpio_stm32_set_power_state(dev, state);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return gpio_stm32_set_power_state(dev, state);
|
||||
}
|
||||
#endif /* CONFIG_PM_DEVICE */
|
||||
|
||||
|
|
|
@ -327,14 +327,11 @@ static int postNotifyFxn(unsigned int eventType, uintptr_t eventArg,
|
|||
|
||||
#ifdef CONFIG_PM_DEVICE
|
||||
static int i2c_cc13xx_cc26xx_set_power_state(const struct device *dev,
|
||||
enum pm_device_state new_state)
|
||||
enum pm_device_state state)
|
||||
{
|
||||
int ret = 0;
|
||||
enum pm_device_state state;
|
||||
|
||||
(void)pm_device_state_get(dev, &state);
|
||||
|
||||
if ((new_state == PM_DEVICE_STATE_ACTIVE) && (new_state != state) {
|
||||
if (state == PM_DEVICE_STATE_ACTIVE) {
|
||||
Power_setDependency(PowerCC26XX_PERIPH_I2C0);
|
||||
IOCPinTypeI2c(get_dev_config(dev)->base,
|
||||
get_dev_config(dev)->sda_pin,
|
||||
|
@ -345,20 +342,14 @@ static int i2c_cc13xx_cc26xx_set_power_state(const struct device *dev,
|
|||
I2CMasterIntEnable(get_dev_config(dev)->base);
|
||||
}
|
||||
} else {
|
||||
__ASSERT_NO_MSG(new_state == PM_DEVICE_STATE_LOW_POWER ||
|
||||
new_state == PM_DEVICE_STATE_SUSPEND ||
|
||||
new_state == PM_DEVICE_STATE_OFF);
|
||||
|
||||
if (state == PM_DEVICE_STATE_ACTIVE) {
|
||||
I2CMasterIntDisable(get_dev_config(dev)->base);
|
||||
I2CMasterDisable(get_dev_config(dev)->base);
|
||||
/* Reset pin type to default GPIO configuration */
|
||||
IOCPortConfigureSet(get_dev_config(dev)->scl_pin,
|
||||
IOC_PORT_GPIO, IOC_STD_OUTPUT);
|
||||
IOCPortConfigureSet(get_dev_config(dev)->sda_pin,
|
||||
IOC_PORT_GPIO, IOC_STD_OUTPUT);
|
||||
Power_releaseDependency(PowerCC26XX_PERIPH_I2C0);
|
||||
}
|
||||
I2CMasterIntDisable(get_dev_config(dev)->base);
|
||||
I2CMasterDisable(get_dev_config(dev)->base);
|
||||
/* Reset pin type to default GPIO configuration */
|
||||
IOCPortConfigureSet(get_dev_config(dev)->scl_pin,
|
||||
IOC_PORT_GPIO, IOC_STD_OUTPUT);
|
||||
IOCPortConfigureSet(get_dev_config(dev)->sda_pin,
|
||||
IOC_PORT_GPIO, IOC_STD_OUTPUT);
|
||||
Power_releaseDependency(PowerCC26XX_PERIPH_I2C0);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -367,16 +358,7 @@ static int i2c_cc13xx_cc26xx_set_power_state(const struct device *dev,
|
|||
static int i2c_cc13xx_cc26xx_pm_control(const struct device *dev,
|
||||
enum pm_device_state state)
|
||||
{
|
||||
int ret = 0;
|
||||
enum pm_device_state curr_state;
|
||||
|
||||
(void)pm_device_state_get(dev, &curr_state);
|
||||
if (state != curr_state) {
|
||||
ret = i2c_cc13xx_cc26xx_set_power_state(dev,
|
||||
new_state);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return i2c_cc13xx_cc26xx_set_power_state(dev, state);
|
||||
}
|
||||
#endif /* CONFIG_PM_DEVICE */
|
||||
|
||||
|
|
|
@ -220,31 +220,24 @@ static int twi_nrfx_pm_control(const struct device *dev,
|
|||
enum pm_device_state state)
|
||||
{
|
||||
int ret = 0;
|
||||
enum pm_device_state curr_state;
|
||||
|
||||
(void)pm_device_state_get(dev, &curr_state);
|
||||
if (state != curr_state) {
|
||||
switch (state) {
|
||||
case PM_DEVICE_STATE_ACTIVE:
|
||||
init_twi(dev);
|
||||
if (get_dev_data(dev)->dev_config) {
|
||||
i2c_nrfx_twi_configure(
|
||||
dev,
|
||||
get_dev_data(dev)->dev_config);
|
||||
}
|
||||
break;
|
||||
|
||||
case PM_DEVICE_STATE_LOW_POWER:
|
||||
case PM_DEVICE_STATE_SUSPEND:
|
||||
case PM_DEVICE_STATE_OFF:
|
||||
if (curr_state == PM_DEVICE_STATE_ACTIVE) {
|
||||
nrfx_twi_uninit(&get_dev_config(dev)->twi);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = -ENOTSUP;
|
||||
switch (state) {
|
||||
case PM_DEVICE_STATE_ACTIVE:
|
||||
init_twi(dev);
|
||||
if (get_dev_data(dev)->dev_config) {
|
||||
i2c_nrfx_twi_configure(dev,
|
||||
get_dev_data(dev)->dev_config);
|
||||
}
|
||||
break;
|
||||
|
||||
case PM_DEVICE_STATE_LOW_POWER:
|
||||
case PM_DEVICE_STATE_SUSPEND:
|
||||
case PM_DEVICE_STATE_OFF:
|
||||
nrfx_twi_uninit(&get_dev_config(dev)->twi);
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = -ENOTSUP;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -258,32 +258,24 @@ static int twim_nrfx_pm_control(const struct device *dev,
|
|||
enum pm_device_state state)
|
||||
{
|
||||
int ret = 0;
|
||||
enum pm_device_state curr_state;
|
||||
|
||||
(void)pm_device_state_get(dev, &curr_state);
|
||||
if (state != curr_state) {
|
||||
switch (state) {
|
||||
case PM_DEVICE_STATE_ACTIVE:
|
||||
init_twim(dev);
|
||||
if (get_dev_data(dev)->dev_config) {
|
||||
i2c_nrfx_twim_configure(
|
||||
dev,
|
||||
get_dev_data(dev)->dev_config);
|
||||
}
|
||||
break;
|
||||
|
||||
case PM_DEVICE_STATE_LOW_POWER:
|
||||
case PM_DEVICE_STATE_SUSPEND:
|
||||
case PM_DEVICE_STATE_OFF:
|
||||
if (curr_state != PM_DEVICE_STATE_ACTIVE) {
|
||||
break;
|
||||
}
|
||||
nrfx_twim_uninit(&get_dev_config(dev)->twim);
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = -ENOTSUP;
|
||||
switch (state) {
|
||||
case PM_DEVICE_STATE_ACTIVE:
|
||||
init_twim(dev);
|
||||
if (get_dev_data(dev)->dev_config) {
|
||||
i2c_nrfx_twim_configure(dev,
|
||||
get_dev_data(dev)->dev_config);
|
||||
}
|
||||
break;
|
||||
|
||||
case PM_DEVICE_STATE_LOW_POWER:
|
||||
case PM_DEVICE_STATE_SUSPEND:
|
||||
case PM_DEVICE_STATE_OFF:
|
||||
nrfx_twim_uninit(&get_dev_config(dev)->twim);
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = -ENOTSUP;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -313,16 +313,12 @@ static int ioapic_device_ctrl(const struct device *dev,
|
|||
enum pm_device_state state)
|
||||
{
|
||||
int ret = 0;
|
||||
enum pm_device_state curr_state;
|
||||
|
||||
(void)pm_device_state_get(dev, &curr_state);
|
||||
switch (state) {
|
||||
case PM_DEVICE_STATE_LOW_POWER:
|
||||
break;
|
||||
case PM_DEVICE_STATE_ACTIVE:
|
||||
if (curr_state != PM_DEVICE_STATE_LOW_POWER) {
|
||||
ret = ioapic_resume_from_suspend(dev);
|
||||
}
|
||||
ret = ioapic_resume_from_suspend(dev);
|
||||
break;
|
||||
case PM_DEVICE_STATE_SUSPEND:
|
||||
case PM_DEVICE_STATE_FORCE_SUSPEND:
|
||||
|
|
|
@ -119,13 +119,6 @@ static int led_pwm_pm_set_state(const struct device *dev,
|
|||
enum pm_device_state new_state)
|
||||
{
|
||||
const struct led_pwm_config *config = DEV_CFG(dev);
|
||||
enum pm_device_state curr_state;
|
||||
|
||||
(void)pm_device_state_get(dev, &curr_state);
|
||||
|
||||
if (curr_state == new_state) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* switch all underlying PWM devices to the new state */
|
||||
for (size_t i = 0; i < config->num_leds; i++) {
|
||||
|
|
|
@ -292,13 +292,12 @@ static void pwm_nrfx_uninit(const struct device *dev)
|
|||
memset(dev->data, 0, sizeof(struct pwm_nrfx_data));
|
||||
}
|
||||
|
||||
static int pwm_nrfx_set_power_state(enum pm_device_state new_state,
|
||||
enum pm_device_state current_state,
|
||||
static int pwm_nrfx_set_power_state(enum pm_device_state state,
|
||||
const struct device *dev)
|
||||
{
|
||||
int err = 0;
|
||||
|
||||
switch (new_state) {
|
||||
switch (state) {
|
||||
case PM_DEVICE_STATE_ACTIVE:
|
||||
err = pwm_nrfx_init(dev);
|
||||
break;
|
||||
|
@ -306,9 +305,7 @@ static int pwm_nrfx_set_power_state(enum pm_device_state new_state,
|
|||
case PM_DEVICE_STATE_SUSPEND:
|
||||
case PM_DEVICE_STATE_FORCE_SUSPEND:
|
||||
case PM_DEVICE_STATE_OFF:
|
||||
if (current_state == PM_DEVICE_STATE_ACTIVE) {
|
||||
pwm_nrfx_uninit(dev);
|
||||
}
|
||||
pwm_nrfx_uninit(dev);
|
||||
break;
|
||||
default:
|
||||
__ASSERT_NO_MSG(false);
|
||||
|
@ -320,15 +317,7 @@ static int pwm_nrfx_set_power_state(enum pm_device_state new_state,
|
|||
static int pwm_nrfx_pm_control(const struct device *dev,
|
||||
enum pm_device_state state)
|
||||
{
|
||||
int err = 0;
|
||||
enum pm_device_state curr_state;
|
||||
|
||||
(void)pm_device_state_get(dev, &curr_state);
|
||||
if (state != current_state) {
|
||||
err = pwm_nrfx_set_power_state(state, current_state, dev);
|
||||
}
|
||||
|
||||
return err;
|
||||
return pwm_nrfx_set_power_state(state, dev);
|
||||
}
|
||||
|
||||
#define PWM_NRFX_PM_CONTROL(idx) \
|
||||
|
|
|
@ -413,29 +413,22 @@ static int bme280_chip_init(const struct device *dev)
|
|||
int bme280_pm_ctrl(const struct device *dev, enum pm_device_state state)
|
||||
{
|
||||
int ret = 0;
|
||||
enum pm_device_state curr_state;
|
||||
|
||||
pm_device_state_get(dev, &curr_state);
|
||||
if (state != curr_state) {
|
||||
/* Switching from OFF to any */
|
||||
if (state != PM_DEVICE_STATE_OFF) {
|
||||
/* Re-initialize the chip */
|
||||
ret = bme280_chip_init(dev);
|
||||
}
|
||||
/* Switching to OFF from any */
|
||||
else if (state == PM_DEVICE_STATE_OFF) {
|
||||
|
||||
/* Switching from OFF to any */
|
||||
if (curr_state == PM_DEVICE_STATE_OFF) {
|
||||
/* Put the chip into sleep mode */
|
||||
ret = bme280_reg_write(dev,
|
||||
BME280_REG_CTRL_MEAS,
|
||||
BME280_CTRL_MEAS_OFF_VAL);
|
||||
|
||||
/* Re-initialize the chip */
|
||||
ret = bme280_chip_init(dev);
|
||||
}
|
||||
/* Switching to OFF from any */
|
||||
else if (state == PM_DEVICE_STATE_OFF) {
|
||||
|
||||
/* Put the chip into sleep mode */
|
||||
ret = bme280_reg_write(dev,
|
||||
BME280_REG_CTRL_MEAS,
|
||||
BME280_CTRL_MEAS_OFF_VAL);
|
||||
|
||||
if (ret < 0)
|
||||
LOG_DBG("CTRL_MEAS write failed: %d",
|
||||
ret);
|
||||
}
|
||||
if (ret < 0)
|
||||
LOG_DBG("CTRL_MEAS write failed: %d", ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -550,21 +550,14 @@ static int bmp388_get_calibration_data(const struct device *dev)
|
|||
|
||||
#ifdef CONFIG_PM_DEVICE
|
||||
static int bmp388_set_power_state(const struct device *dev,
|
||||
enum pm_device_state power_state)
|
||||
enum pm_device_state state)
|
||||
{
|
||||
uint8_t reg_val;
|
||||
enum pm_device_state state;
|
||||
|
||||
(void)pm_device_state_get(dev, &state);
|
||||
if (state == power_state) {
|
||||
/* We are already in the desired state. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (power_state == PM_DEVICE_STATE_ACTIVE) {
|
||||
if (state == PM_DEVICE_STATE_ACTIVE) {
|
||||
reg_val = BMP388_PWR_CTRL_MODE_NORMAL;
|
||||
} else if ((power_state == PM_DEVICE_STATE_SUSPEND) ||
|
||||
(power_state == PM_DEVICE_STATE_OFF)) {
|
||||
} else if ((state == PM_DEVICE_STATE_SUSPEND) ||
|
||||
(state == PM_DEVICE_STATE_OFF)) {
|
||||
reg_val = BMP388_PWR_CTRL_MODE_SLEEP;
|
||||
} else {
|
||||
return 0;
|
||||
|
|
|
@ -539,21 +539,16 @@ static int fdc2x1x_device_pm_ctrl(const struct device *dev,
|
|||
{
|
||||
struct fdc2x1x_data *data = dev->data;
|
||||
int ret = 0;
|
||||
enum pm_device_state curr_state;
|
||||
|
||||
(void)pm_device_state_get(dev, &curr_state);
|
||||
|
||||
if (state != curr_state) {
|
||||
switch (state) {
|
||||
case PM_DEVICE_STATE_ACTIVE:
|
||||
case PM_DEVICE_STATE_LOW_POWER:
|
||||
case PM_DEVICE_STATE_OFF:
|
||||
ret = fdc2x1x_set_pm_state(dev, state);
|
||||
break;
|
||||
default:
|
||||
LOG_ERR("PM state not supported");
|
||||
ret = -EINVAL;
|
||||
}
|
||||
switch (state) {
|
||||
case PM_DEVICE_STATE_ACTIVE:
|
||||
case PM_DEVICE_STATE_LOW_POWER:
|
||||
case PM_DEVICE_STATE_OFF:
|
||||
ret = fdc2x1x_set_pm_state(dev, state);
|
||||
break;
|
||||
default:
|
||||
LOG_ERR("PM state not supported");
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -444,12 +444,12 @@ static int lis2mdl_init(const struct device *dev)
|
|||
#ifdef CONFIG_PM_DEVICE
|
||||
static int lis2mdl_set_power_state(struct lis2mdl_data *lis2mdl,
|
||||
const struct lis2mdl_config *const config,
|
||||
enum pm_device_state new_state)
|
||||
enum pm_device_state state)
|
||||
{
|
||||
stmdev_ctx_t *ctx = (stmdev_ctx_t *)&config->ctx;
|
||||
int status = 0;
|
||||
|
||||
if (new_state == PM_DEVICE_STATE_ACTIVE) {
|
||||
if (state == PM_DEVICE_STATE_ACTIVE) {
|
||||
if (config->single_mode) {
|
||||
status = lis2mdl_operating_mode_set(ctx,
|
||||
LIS2MDL_SINGLE_TRIGGER);
|
||||
|
@ -462,9 +462,6 @@ static int lis2mdl_set_power_state(struct lis2mdl_data *lis2mdl,
|
|||
}
|
||||
LOG_DBG("State changed to active");
|
||||
} else {
|
||||
__ASSERT_NO_MSG(new_state == PM_DEVICE_STATE_LOW_POWER ||
|
||||
new_state == PM_DEVICE_STATE_SUSPEND ||
|
||||
new_state == PM_DEVICE_STATE_OFF);
|
||||
status = lis2mdl_operating_mode_set(ctx, LIS2MDL_POWER_DOWN);
|
||||
if (status) {
|
||||
LOG_ERR("Power down failed");
|
||||
|
@ -480,15 +477,8 @@ static int lis2mdl_pm_control(const struct device *dev,
|
|||
{
|
||||
struct lis2mdl_data *lis2mdl = dev->data;
|
||||
const struct lis2mdl_config *const config = dev->config;
|
||||
int status = 0;
|
||||
enum pm_device_state curr_state;
|
||||
|
||||
(void)pm_device_state_get(dev, &curr_state);
|
||||
if (state != curr_state) {
|
||||
status = lis2mdl_set_power_state(lis2mdl, config, state);
|
||||
}
|
||||
|
||||
return status;
|
||||
return lis2mdl_set_power_state(lis2mdl, config, state);
|
||||
}
|
||||
#endif /* CONFIG_PM_DEVICE */
|
||||
|
||||
|
|
|
@ -209,33 +209,20 @@ static int qdec_nrfx_init(const struct device *dev)
|
|||
#ifdef CONFIG_PM_DEVICE
|
||||
|
||||
static int qdec_nrfx_pm_set_state(struct qdec_nrfx_data *data,
|
||||
enum pm_device_state new_state)
|
||||
enum pm_device_state state)
|
||||
{
|
||||
enum pm_device_state curr_state;
|
||||
|
||||
(void)pm_device_state_get(dev, &curr_state);
|
||||
|
||||
if (curr_state == new_state) {
|
||||
/* leave unchanged */
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (curr_state == PM_DEVICE_STATE_ACTIVE) {
|
||||
if (state == PM_DEVICE_STATE_ACTIVE) {
|
||||
qdec_nrfx_gpio_ctrl(true);
|
||||
nrfx_qdec_enable();
|
||||
} else if (state == PM_DEVICE_STATE_OFF) {
|
||||
/* device must be uninitialized */
|
||||
nrfx_qdec_uninit();
|
||||
} else {
|
||||
/* device must be suspended */
|
||||
nrfx_qdec_disable();
|
||||
qdec_nrfx_gpio_ctrl(false);
|
||||
}
|
||||
|
||||
if (new_state == PM_DEVICE_STATE_OFF) {
|
||||
/* device must be uninitialized */
|
||||
nrfx_qdec_uninit();
|
||||
}
|
||||
|
||||
if (new_state == PM_DEVICE_STATE_ACTIVE) {
|
||||
qdec_nrfx_gpio_ctrl(true);
|
||||
nrfx_qdec_enable();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -191,13 +191,6 @@ static int sgp40_set_power_state(const struct device *dev,
|
|||
{
|
||||
uint16_t cmd;
|
||||
int rc;
|
||||
enum pm_device_state state;
|
||||
|
||||
(void)pm_device_state_get(dev, &state);
|
||||
if (state == power_state) {
|
||||
LOG_DBG("Device already in requested PM_STATE.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (power_state == PM_DEVICE_STATE_ACTIVE) {
|
||||
/* activate the hotplate by sending a measure command */
|
||||
|
|
|
@ -398,16 +398,12 @@ static int postNotifyFxn(unsigned int eventType, uintptr_t eventArg,
|
|||
|
||||
#ifdef CONFIG_PM_DEVICE
|
||||
static int uart_cc13xx_cc26xx_set_power_state(const struct device *dev,
|
||||
enum pm_device_state new_state)
|
||||
enum pm_device_state state)
|
||||
{
|
||||
int ret = 0;
|
||||
enum pm_device_state state;
|
||||
|
||||
(void)pm_device_state_get(dev, &state);
|
||||
|
||||
if ((new_state == PM_DEVICE_STATE_ACTIVE) && (new_state != state)) {
|
||||
if (get_dev_conf(dev)->regs ==
|
||||
DT_INST_REG_ADDR(0)) {
|
||||
if (state == PM_DEVICE_STATE_ACTIVE) {
|
||||
if (get_dev_conf(dev)->regs == DT_INST_REG_ADDR(0)) {
|
||||
Power_setDependency(PowerCC26XX_PERIPH_UART0);
|
||||
} else {
|
||||
Power_setDependency(PowerCC26X2_PERIPH_UART1);
|
||||
|
@ -416,24 +412,16 @@ static int uart_cc13xx_cc26xx_set_power_state(const struct device *dev,
|
|||
ret = uart_cc13xx_cc26xx_configure(dev,
|
||||
&get_dev_data(dev)->uart_config);
|
||||
} else {
|
||||
__ASSERT_NO_MSG(new_state == PM_DEVICE_STATE_LOW_POWER ||
|
||||
new_state == PM_DEVICE_STATE_SUSPEND ||
|
||||
new_state == PM_DEVICE_STATE_OFF);
|
||||
|
||||
if (state == PM_DEVICE_STATE_ACTIVE) {
|
||||
UARTDisable(get_dev_conf(dev)->regs);
|
||||
/*
|
||||
* Release power dependency - i.e. potentially power
|
||||
* down serial domain.
|
||||
*/
|
||||
if (get_dev_conf(dev)->regs ==
|
||||
DT_INST_REG_ADDR(0)) {
|
||||
Power_releaseDependency(
|
||||
PowerCC26XX_PERIPH_UART0);
|
||||
} else {
|
||||
Power_releaseDependency(
|
||||
PowerCC26X2_PERIPH_UART1);
|
||||
}
|
||||
UARTDisable(get_dev_conf(dev)->regs);
|
||||
/*
|
||||
* Release power dependency - i.e. potentially power
|
||||
* down serial domain.
|
||||
*/
|
||||
if (get_dev_conf(dev)->regs ==
|
||||
DT_INST_REG_ADDR(0)) {
|
||||
Power_releaseDependency(PowerCC26XX_PERIPH_UART0);
|
||||
} else {
|
||||
Power_releaseDependency(PowerCC26X2_PERIPH_UART1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -443,15 +431,7 @@ static int uart_cc13xx_cc26xx_set_power_state(const struct device *dev,
|
|||
static int uart_cc13xx_cc26xx_pm_control(const struct device *dev,
|
||||
enum pm_device_state state)
|
||||
{
|
||||
int ret = 0;
|
||||
enum pm_device_state curr_state;
|
||||
|
||||
(void)pm_device_state_get(dev, &curr_state);
|
||||
if (state != curr_state) {
|
||||
ret = uart_cc13xx_cc26xx_set_power_state(dev, state);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return uart_cc13xx_cc26xx_set_power_state(dev, state);
|
||||
}
|
||||
#endif /* CONFIG_PM_DEVICE */
|
||||
|
||||
|
|
|
@ -1140,9 +1140,9 @@ static void uart_nrfx_pins_enable(const struct device *dev, bool enable)
|
|||
}
|
||||
|
||||
static void uart_nrfx_set_power_state(const struct device *dev,
|
||||
enum pm_device_state new_state)
|
||||
enum pm_device_state state)
|
||||
{
|
||||
if (new_state == PM_DEVICE_STATE_ACTIVE) {
|
||||
if (state == PM_DEVICE_STATE_ACTIVE) {
|
||||
uart_nrfx_pins_enable(dev, true);
|
||||
nrf_uart_enable(uart0_addr);
|
||||
if (RX_PIN_USED) {
|
||||
|
@ -1150,9 +1150,6 @@ static void uart_nrfx_set_power_state(const struct device *dev,
|
|||
NRF_UART_TASK_STARTRX);
|
||||
}
|
||||
} else {
|
||||
__ASSERT_NO_MSG(new_state == PM_DEVICE_STATE_LOW_POWER ||
|
||||
new_state == PM_DEVICE_STATE_SUSPEND ||
|
||||
new_state == PM_DEVICE_STATE_OFF);
|
||||
nrf_uart_disable(uart0_addr);
|
||||
uart_nrfx_pins_enable(dev, false);
|
||||
}
|
||||
|
@ -1161,12 +1158,7 @@ static void uart_nrfx_set_power_state(const struct device *dev,
|
|||
static int uart_nrfx_pm_control(const struct device *dev,
|
||||
enum pm_device_state state)
|
||||
{
|
||||
enum pm_device_state current_state;
|
||||
|
||||
(void)pm_device_state_get(dev, ¤t_state);
|
||||
if (state != current_state) {
|
||||
uart_nrfx_set_power_state(dev, state);
|
||||
}
|
||||
uart_nrfx_set_power_state(dev, state);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1832,14 +1832,14 @@ static void wait_for_tx_stopped(const struct device *dev)
|
|||
|
||||
|
||||
static void uarte_nrfx_set_power_state(const struct device *dev,
|
||||
enum pm_device_state new_state)
|
||||
enum pm_device_state state)
|
||||
{
|
||||
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
|
||||
#if defined(CONFIG_UART_ASYNC_API) || defined(UARTE_INTERRUPT_DRIVEN)
|
||||
struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
#endif
|
||||
|
||||
if (new_state == PM_DEVICE_STATE_ACTIVE) {
|
||||
if (state == PM_DEVICE_STATE_ACTIVE) {
|
||||
uarte_nrfx_pins_enable(dev, true);
|
||||
nrf_uarte_enable(uarte);
|
||||
|
||||
|
@ -1864,20 +1864,6 @@ static void uarte_nrfx_set_power_state(const struct device *dev,
|
|||
#endif
|
||||
}
|
||||
} else {
|
||||
enum pm_device_state state;
|
||||
|
||||
__ASSERT_NO_MSG(new_state == PM_DEVICE_STATE_LOW_POWER ||
|
||||
new_state == PM_DEVICE_STATE_SUSPEND ||
|
||||
new_state == PM_DEVICE_STATE_OFF);
|
||||
|
||||
/* if pm is already not active, driver will stay indefinitely
|
||||
* in while loop waiting for event NRF_UARTE_EVENT_RXTO
|
||||
*/
|
||||
(void)pm_device_state_get(dev, &state);
|
||||
if (state != PM_DEVICE_STATE_ACTIVE) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Disabling UART requires stopping RX, but stop RX event is
|
||||
* only sent after each RX if async UART API is used.
|
||||
*/
|
||||
|
@ -1924,12 +1910,7 @@ static void uarte_nrfx_set_power_state(const struct device *dev,
|
|||
static int uarte_nrfx_pm_control(const struct device *dev,
|
||||
enum pm_device_state state)
|
||||
{
|
||||
enum pm_device_state curr_state;
|
||||
|
||||
(void)pm_device_state_get(dev, &curr_state);
|
||||
if (state != curr_state) {
|
||||
uarte_nrfx_set_power_state(dev, state);
|
||||
}
|
||||
uarte_nrfx_set_power_state(dev, state);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1423,12 +1423,12 @@ static int uart_stm32_init(const struct device *dev)
|
|||
|
||||
#ifdef CONFIG_PM_DEVICE
|
||||
static int uart_stm32_set_power_state(const struct device *dev,
|
||||
enum pm_device_state new_state)
|
||||
enum pm_device_state state)
|
||||
{
|
||||
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
||||
|
||||
/* setting a low power mode */
|
||||
if (new_state != PM_DEVICE_STATE_ACTIVE) {
|
||||
if (state != PM_DEVICE_STATE_ACTIVE) {
|
||||
#ifdef USART_ISR_BUSY
|
||||
/* Make sure that no USART transfer is on-going */
|
||||
while (LL_USART_IsActiveFlag_BUSY(UartInstance) == 1) {
|
||||
|
@ -1462,12 +1462,7 @@ static int uart_stm32_set_power_state(const struct device *dev,
|
|||
static int uart_stm32_pm_control(const struct device *dev,
|
||||
enum pm_device_state state)
|
||||
{
|
||||
enum pm_device_state curr_state;
|
||||
|
||||
(void)pm_device_state_get(dev, &curr_state);
|
||||
if (state != curr_state) {
|
||||
uart_stm32_set_power_state(dev, state);
|
||||
}
|
||||
uart_stm32_set_power_state(dev, state);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -209,56 +209,33 @@ static int spi_cc13xx_cc26xx_release(const struct device *dev,
|
|||
|
||||
#ifdef CONFIG_PM_DEVICE
|
||||
static int spi_cc13xx_cc26xx_set_power_state(const struct device *dev,
|
||||
enum pm_device_state new_state)
|
||||
enum pm_device_state state)
|
||||
{
|
||||
int ret = 0;
|
||||
enum pm_device_state state;
|
||||
|
||||
(void)pm_device_state_get(dev, &state);
|
||||
|
||||
if ((new_state == PM_DEVICE_STATE_ACTIVE) && (new_state != state)) {
|
||||
if (get_dev_config(dev)->base ==
|
||||
DT_INST_REG_ADDR(0)) {
|
||||
if (state == PM_DEVICE_STATE_ACTIVE) {
|
||||
if (get_dev_config(dev)->base == DT_INST_REG_ADDR(0)) {
|
||||
Power_setDependency(PowerCC26XX_PERIPH_SSI0);
|
||||
} else {
|
||||
Power_setDependency(PowerCC26XX_PERIPH_SSI1);
|
||||
}
|
||||
} else {
|
||||
__ASSERT_NO_MSG(new_state == PM_DEVICE_STATE_LOW_POWER ||
|
||||
new_state == PM_DEVICE_STATE_SUSPEND ||
|
||||
new_state == PM_DEVICE_STATE_OFF);
|
||||
|
||||
if (state == PM_DEVICE_STATE_ACTIVE) {
|
||||
SSIDisable(get_dev_config(dev)->base);
|
||||
/*
|
||||
* Release power dependency
|
||||
*/
|
||||
if (get_dev_config(dev)->base ==
|
||||
DT_INST_REG_ADDR(0)) {
|
||||
Power_releaseDependency(
|
||||
PowerCC26XX_PERIPH_SSI0);
|
||||
} else {
|
||||
Power_releaseDependency(
|
||||
PowerCC26XX_PERIPH_SSI1);
|
||||
}
|
||||
SSIDisable(get_dev_config(dev)->base);
|
||||
/*
|
||||
* Release power dependency
|
||||
*/
|
||||
if (get_dev_config(dev)->base == DT_INST_REG_ADDR(0)) {
|
||||
Power_releaseDependency(PowerCC26XX_PERIPH_SSI0);
|
||||
} else {
|
||||
Power_releaseDependency(PowerCC26XX_PERIPH_SSI1);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int spi_cc13xx_cc26xx_pm_control(const struct device *dev,
|
||||
enum pm_device_state state)
|
||||
{
|
||||
int ret = 0;
|
||||
enum pm_device_state curr_state;
|
||||
|
||||
(void)pm_device_state_get(dev, &curr_state);
|
||||
if (state != curr_state) {
|
||||
ret = spi_cc13xx_cc26xx_set_power_state(dev, state);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return spi_cc13xx_cc26xx_set_power_state(dev, state);
|
||||
}
|
||||
#endif /* CONFIG_PM_DEVICE */
|
||||
|
||||
|
|
|
@ -283,28 +283,22 @@ static int spi_nrfx_pm_control(const struct device *dev,
|
|||
int ret = 0;
|
||||
struct spi_nrfx_data *data = get_dev_data(dev);
|
||||
const struct spi_nrfx_config *config = get_dev_config(dev);
|
||||
enum pm_device_state curr_state;
|
||||
|
||||
(void)pm_device_state_get(dev, &curr_state);
|
||||
if (state != curr_state) {
|
||||
switch (state) {
|
||||
case PM_DEVICE_STATE_ACTIVE:
|
||||
ret = init_spi(dev);
|
||||
/* Force reconfiguration before next transfer */
|
||||
data->ctx.config = NULL;
|
||||
break;
|
||||
switch (state) {
|
||||
case PM_DEVICE_STATE_ACTIVE:
|
||||
ret = init_spi(dev);
|
||||
/* Force reconfiguration before next transfer */
|
||||
data->ctx.config = NULL;
|
||||
break;
|
||||
|
||||
case PM_DEVICE_STATE_LOW_POWER:
|
||||
case PM_DEVICE_STATE_SUSPEND:
|
||||
case PM_DEVICE_STATE_OFF:
|
||||
if (curr_state == PM_DEVICE_STATE_ACTIVE) {
|
||||
nrfx_spi_uninit(&config->spi);
|
||||
}
|
||||
break;
|
||||
case PM_DEVICE_STATE_LOW_POWER:
|
||||
case PM_DEVICE_STATE_SUSPEND:
|
||||
case PM_DEVICE_STATE_OFF:
|
||||
nrfx_spi_uninit(&config->spi);
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = -ENOTSUP;
|
||||
}
|
||||
default:
|
||||
ret = -ENOTSUP;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -330,28 +330,22 @@ static int spim_nrfx_pm_control(const struct device *dev,
|
|||
int ret = 0;
|
||||
struct spi_nrfx_data *data = get_dev_data(dev);
|
||||
const struct spi_nrfx_config *config = get_dev_config(dev);
|
||||
enum pm_device_state curr_state;
|
||||
|
||||
(void)pm_device_state_get(dev, &curr_state);
|
||||
if (state != curr_state) {
|
||||
switch (state) {
|
||||
case PM_DEVICE_STATE_ACTIVE:
|
||||
ret = init_spim(dev);
|
||||
/* Force reconfiguration before next transfer */
|
||||
data->ctx.config = NULL;
|
||||
break;
|
||||
switch (state) {
|
||||
case PM_DEVICE_STATE_ACTIVE:
|
||||
ret = init_spim(dev);
|
||||
/* Force reconfiguration before next transfer */
|
||||
data->ctx.config = NULL;
|
||||
break;
|
||||
|
||||
case PM_DEVICE_STATE_LOW_POWER:
|
||||
case PM_DEVICE_STATE_SUSPEND:
|
||||
case PM_DEVICE_STATE_OFF:
|
||||
if (curr_state == PM_DEVICE_STATE_ACTIVE) {
|
||||
nrfx_spim_uninit(&config->spim);
|
||||
}
|
||||
break;
|
||||
case PM_DEVICE_STATE_LOW_POWER:
|
||||
case PM_DEVICE_STATE_SUSPEND:
|
||||
case PM_DEVICE_STATE_OFF:
|
||||
nrfx_spim_uninit(&config->spim);
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = -ENOTSUP;
|
||||
}
|
||||
default:
|
||||
ret = -ENOTSUP;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue