diff --git a/drivers/display/display_st7735r.c b/drivers/display/display_st7735r.c index 1fe0948acfd..467621d7554 100644 --- a/drivers/display/display_st7735r.c +++ b/drivers/display/display_st7735r.c @@ -505,23 +505,16 @@ static int st7735r_pm_control(const struct device *dev, uint32_t ctrl_command, int ret = 0; struct st7735r_data *data = (struct st7735r_data *)dev->data; - switch (ctrl_command) { - case PM_DEVICE_STATE_SET: - if (*state == PM_DEVICE_STATE_ACTIVE) { - ret = st7735r_exit_sleep(data); - if (ret < 0) { - return ret; - } - } else { - ret = st7735r_enter_sleep(data); - if (ret < 0) { - return ret; - } + if (*state == PM_DEVICE_STATE_ACTIVE) { + ret = st7735r_exit_sleep(data); + if (ret < 0) { + return ret; + } + } else { + ret = st7735r_enter_sleep(data); + if (ret < 0) { + return ret; } - - break; - default: - ret = -EINVAL; } return ret; diff --git a/drivers/display/display_st7789v.c b/drivers/display/display_st7789v.c index 807cc38aa81..6cf6da46db0 100644 --- a/drivers/display/display_st7789v.c +++ b/drivers/display/display_st7789v.c @@ -404,24 +404,15 @@ static void st7789v_enter_sleep(struct st7789v_data *data) static int st7789v_pm_control(const struct device *dev, uint32_t ctrl_command, enum pm_device_state *state) { - int ret = 0; struct st7789v_data *data = (struct st7789v_data *)dev->data; - switch (ctrl_command) { - case DEVICE_PM_SET_POWER_STATE: - if (*state == PM_DEVICE_STATE_ACTIVE) { - st7789v_exit_sleep(data); - ret = 0; - } else { - st7789v_enter_sleep(data); - ret = 0; - } - break; - default: - ret = -EINVAL; + if (*state == PM_DEVICE_STATE_ACTIVE) { + st7789v_exit_sleep(data); + } else { + st7789v_enter_sleep(data); } - return ret; + return 0; } #endif /* CONFIG_PM_DEVICE */ diff --git a/drivers/entropy/entropy_cc13xx_cc26xx.c b/drivers/entropy/entropy_cc13xx_cc26xx.c index 68a11f8d355..4095823b1df 100644 --- a/drivers/entropy/entropy_cc13xx_cc26xx.c +++ b/drivers/entropy/entropy_cc13xx_cc26xx.c @@ -295,14 +295,11 @@ 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; - if (ctrl_command == PM_DEVICE_STATE_SET) { - 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); - } + (void)pm_device_state_get(dev, &curr_state); + if (*state != curr_state) { + ret = entropy_cc13xx_cc26xx_set_power_state(dev, *state); } return ret; diff --git a/drivers/ethernet/eth_mcux.c b/drivers/ethernet/eth_mcux.c index 814b3359ba6..b779a06d706 100644 --- a/drivers/ethernet/eth_mcux.c +++ b/drivers/ethernet/eth_mcux.c @@ -198,32 +198,28 @@ static int eth_mcux_device_pm_control(const struct device *dev, goto out; } - if (command == PM_DEVICE_STATE_SET) { - if (*state == PM_DEVICE_STATE_SUSPEND) { - LOG_DBG("Suspending"); + if (*state == PM_DEVICE_STATE_SUSPEND) { + LOG_DBG("Suspending"); - ret = net_if_suspend(eth_ctx->iface); - if (ret == -EBUSY) { - goto out; - } - - eth_mcux_phy_enter_reset(eth_ctx); - eth_mcux_phy_stop(eth_ctx); - - ENET_Reset(eth_ctx->base); - ENET_Deinit(eth_ctx->base); - clock_control_off(eth_ctx->clock_dev, - (clock_control_subsys_t)eth_ctx->clock); - } else if (*state == PM_DEVICE_STATE_ACTIVE) { - LOG_DBG("Resuming"); - - clock_control_on(eth_ctx->clock_dev, - (clock_control_subsys_t)eth_ctx->clock); - eth_mcux_init(dev); - net_if_resume(eth_ctx->iface); + ret = net_if_suspend(eth_ctx->iface); + if (ret == -EBUSY) { + goto out; } - } else { - return -EINVAL; + + eth_mcux_phy_enter_reset(eth_ctx); + eth_mcux_phy_stop(eth_ctx); + + ENET_Reset(eth_ctx->base); + ENET_Deinit(eth_ctx->base); + clock_control_off(eth_ctx->clock_dev, + (clock_control_subsys_t)eth_ctx->clock); + } else if (*state == PM_DEVICE_STATE_ACTIVE) { + LOG_DBG("Resuming"); + + clock_control_on(eth_ctx->clock_dev, + (clock_control_subsys_t)eth_ctx->clock); + eth_mcux_init(dev); + net_if_resume(eth_ctx->iface); } out: diff --git a/drivers/flash/spi_flash_at45.c b/drivers/flash/spi_flash_at45.c index 959ba098944..9dd107d7842 100644 --- a/drivers/flash/spi_flash_at45.c +++ b/drivers/flash/spi_flash_at45.c @@ -630,34 +630,31 @@ static int spi_flash_at45_pm_control(const struct device *dev, { const struct spi_flash_at45_config *dev_config = get_dev_config(dev); int err = 0; + enum pm_device_state curr_state; - if (ctrl_command == PM_DEVICE_STATE_SET) { - 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; - (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; + 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; } } diff --git a/drivers/gpio/gpio_dw.c b/drivers/gpio/gpio_dw.c index e86bd3fb485..931757d2ad0 100644 --- a/drivers/gpio/gpio_dw.c +++ b/drivers/gpio/gpio_dw.c @@ -447,12 +447,10 @@ static int gpio_dw_device_ctrl(const struct device *port, { int ret = 0; - if (ctrl_command == PM_DEVICE_STATE_SET) { - if (*state == PM_DEVICE_STATE_SUSPEND) { - ret = gpio_dw_suspend_port(port); - } else if (*state == PM_DEVICE_STATE_ACTIVE) { - ret = gpio_dw_resume_from_suspend_port(port); - } + if (*state == PM_DEVICE_STATE_SUSPEND) { + ret = gpio_dw_suspend_port(port); + } else if (*state == PM_DEVICE_STATE_ACTIVE) { + ret = gpio_dw_resume_from_suspend_port(port); } return ret; diff --git a/drivers/gpio/gpio_stm32.c b/drivers/gpio/gpio_stm32.c index 89f0f1fdf42..29f095e31af 100644 --- a/drivers/gpio/gpio_stm32.c +++ b/drivers/gpio/gpio_stm32.c @@ -599,19 +599,11 @@ 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; - switch (ctrl_command) { - case PM_DEVICE_STATE_SET: - 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); - } - break; - default: - ret = -EINVAL; - + (void)pm_device_state_get(dev, &curr_state); + if (*state != curr_state) { + ret = gpio_stm32_set_power_state(dev, *state); } return ret; diff --git a/drivers/i2c/i2c_cc13xx_cc26xx.c b/drivers/i2c/i2c_cc13xx_cc26xx.c index 0f40a5b51ca..4326bc9ba6f 100644 --- a/drivers/i2c/i2c_cc13xx_cc26xx.c +++ b/drivers/i2c/i2c_cc13xx_cc26xx.c @@ -369,15 +369,12 @@ 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; - if (ctrl_command == PM_DEVICE_STATE_SET) { - 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); - } + (void)pm_device_state_get(dev, &curr_state); + if (*state != curr_state) { + ret = i2c_cc13xx_cc26xx_set_power_state(dev, + new_state); } return ret; diff --git a/drivers/i2c/i2c_nrfx_twi.c b/drivers/i2c/i2c_nrfx_twi.c index 7194cced5fd..efa0cf1a7bb 100644 --- a/drivers/i2c/i2c_nrfx_twi.c +++ b/drivers/i2c/i2c_nrfx_twi.c @@ -221,33 +221,30 @@ static int twi_nrfx_pm_control(const struct device *dev, enum pm_device_state *state) { int ret = 0; + enum pm_device_state curr_state; - if (ctrl_command == PM_DEVICE_STATE_SET) { - 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; + (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; } } diff --git a/drivers/i2c/i2c_nrfx_twim.c b/drivers/i2c/i2c_nrfx_twim.c index 8eb06cbd5e9..dcb6b037995 100644 --- a/drivers/i2c/i2c_nrfx_twim.c +++ b/drivers/i2c/i2c_nrfx_twim.c @@ -259,34 +259,31 @@ static int twim_nrfx_pm_control(const struct device *dev, enum pm_device_state *state) { int ret = 0; + enum pm_device_state curr_state; - if (ctrl_command == PM_DEVICE_STATE_SET) { - 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; + (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; } } diff --git a/drivers/interrupt_controller/intc_arcv2_irq_unit.c b/drivers/interrupt_controller/intc_arcv2_irq_unit.c index 001a62cdba0..5df1dc73c6c 100644 --- a/drivers/interrupt_controller/intc_arcv2_irq_unit.c +++ b/drivers/interrupt_controller/intc_arcv2_irq_unit.c @@ -181,12 +181,10 @@ static int arc_v2_irq_unit_device_ctrl(const struct device *dev, int ret = 0; unsigned int key = arch_irq_lock(); - if (ctrl_command == PM_DEVICE_STATE_SET) { - if (*state == PM_DEVICE_STATE_SUSPEND) { - ret = arc_v2_irq_unit_suspend(dev); - } else if (*state == PM_DEVICE_STATE_ACTIVE) { - ret = arc_v2_irq_unit_resume(dev); - } + if (*state == PM_DEVICE_STATE_SUSPEND) { + ret = arc_v2_irq_unit_suspend(dev); + } else if (*state == PM_DEVICE_STATE_ACTIVE) { + ret = arc_v2_irq_unit_resume(dev); } arch_irq_unlock(key); diff --git a/drivers/interrupt_controller/intc_ioapic.c b/drivers/interrupt_controller/intc_ioapic.c index e9f6418be09..31cd89bd199 100644 --- a/drivers/interrupt_controller/intc_ioapic.c +++ b/drivers/interrupt_controller/intc_ioapic.c @@ -314,27 +314,24 @@ static int ioapic_device_ctrl(const struct device *dev, enum pm_device_state *state) { int ret = 0; + enum pm_device_state curr_state; - if (ctrl_command == PM_DEVICE_STATE_SET) { - 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); - } - break; - case PM_DEVICE_STATE_SUSPEND: - case PM_DEVICE_STATE_FORCE_SUSPEND: - case PM_DEVICE_STATE_OFF: - ret = ioapic_suspend(dev); - break; - default: - ret = -ENOTSUP; + (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); } + break; + case PM_DEVICE_STATE_SUSPEND: + case PM_DEVICE_STATE_FORCE_SUSPEND: + case PM_DEVICE_STATE_OFF: + ret = ioapic_suspend(dev); + break; + default: + ret = -ENOTSUP; } return ret; diff --git a/drivers/interrupt_controller/intc_loapic.c b/drivers/interrupt_controller/intc_loapic.c index 3599208588f..7809e071491 100644 --- a/drivers/interrupt_controller/intc_loapic.c +++ b/drivers/interrupt_controller/intc_loapic.c @@ -414,12 +414,10 @@ static int loapic_device_ctrl(const struct device *port, { int ret = 0; - if (ctrl_command == PM_DEVICE_STATE_SET) { - if (*state == PM_DEVICE_STATE_SUSPEND) { - ret = loapic_suspend(port); - } else if (*state == PM_DEVICE_STATE_ACTIVE) { - ret = loapic_resume(port); - } + if (*state == PM_DEVICE_STATE_SUSPEND) { + ret = loapic_suspend(port); + } else if (*state == PM_DEVICE_STATE_ACTIVE) { + ret = loapic_resume(port); } return ret; diff --git a/drivers/led/led_pwm.c b/drivers/led/led_pwm.c index 9c6d2719a5e..4fbad06146c 100644 --- a/drivers/led/led_pwm.c +++ b/drivers/led/led_pwm.c @@ -145,19 +145,7 @@ static int led_pwm_pm_set_state(const struct device *dev, static int led_pwm_pm_control(const struct device *dev, uint32_t ctrl_command, enum pm_device_state *state) { - int err; - - switch (ctrl_command) { - case PM_DEVICE_STATE_SET: - err = led_pwm_pm_set_state(dev, *state); - break; - - default: - err = -ENOTSUP; - break; - } - - return err; + return led_pwm_pm_set_state(dev, *state); } #endif /* CONFIG_PM_DEVICE */ diff --git a/drivers/pwm/pwm_nrfx.c b/drivers/pwm/pwm_nrfx.c index 139511dbd09..e8b9db0f8f3 100644 --- a/drivers/pwm/pwm_nrfx.c +++ b/drivers/pwm/pwm_nrfx.c @@ -322,15 +322,11 @@ static int pwm_nrfx_pm_control(const struct device *dev, enum pm_device_state *state) { int err = 0; + enum pm_device_state curr_state; - if (ctrl_command == PM_DEVICE_STATE_SET) { - 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); - } + (void)pm_device_state_get(dev, &curr_state); + if (*state != current_state) { + err = pwm_nrfx_set_power_state(*state, current_state, dev); } return err; diff --git a/drivers/sensor/apds9960/apds9960.c b/drivers/sensor/apds9960/apds9960.c index 4f94cb6060e..32d4d4bb8c2 100644 --- a/drivers/sensor/apds9960/apds9960.c +++ b/drivers/sensor/apds9960/apds9960.c @@ -416,29 +416,26 @@ static int apds9960_device_ctrl(const struct device *dev, struct apds9960_data *data = dev->data; int ret = 0; - if (ctrl_command == PM_DEVICE_STATE_SET) { - if (*state == PM_DEVICE_STATE_ACTIVE) { - if (i2c_reg_update_byte(data->i2c, config->i2c_address, - APDS9960_ENABLE_REG, - APDS9960_ENABLE_PON, - APDS9960_ENABLE_PON)) { - ret = -EIO; - } - - } else { - - if (i2c_reg_update_byte(data->i2c, config->i2c_address, + if (*state == PM_DEVICE_STATE_ACTIVE) { + if (i2c_reg_update_byte(data->i2c, config->i2c_address, APDS9960_ENABLE_REG, - APDS9960_ENABLE_PON, 0)) { - ret = -EIO; - } - - if (i2c_reg_write_byte(data->i2c, config->i2c_address, - APDS9960_AICLEAR_REG, 0)) { - ret = -EIO; - } + APDS9960_ENABLE_PON, + APDS9960_ENABLE_PON)) { + ret = -EIO; } + } else { + + if (i2c_reg_update_byte(data->i2c, config->i2c_address, + APDS9960_ENABLE_REG, + APDS9960_ENABLE_PON, 0)) { + ret = -EIO; + } + + if (i2c_reg_write_byte(data->i2c, config->i2c_address, + APDS9960_AICLEAR_REG, 0)) { + ret = -EIO; + } } return ret; diff --git a/drivers/sensor/bme280/bme280.c b/drivers/sensor/bme280/bme280.c index 2c1dcdc33a5..faa439f8dc9 100644 --- a/drivers/sensor/bme280/bme280.c +++ b/drivers/sensor/bme280/bme280.c @@ -414,32 +414,28 @@ int bme280_pm_ctrl(const struct device *dev, uint32_t ctrl_command, enum pm_device_state *state) { int ret = 0; + enum pm_device_state curr_state; - /* Set power state */ - if (ctrl_command == PM_DEVICE_STATE_SET) { - enum pm_device_state curr_state; + pm_device_state_get(dev, &curr_state); + if (*state != curr_state) { - pm_device_state_get(dev, &curr_state); - if (*state != curr_state) { + /* Switching from OFF to any */ + if (curr_state == PM_DEVICE_STATE_OFF) { - /* Switching from OFF to any */ - if (curr_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) { - /* 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); - /* 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); } } diff --git a/drivers/sensor/bmp388/bmp388.c b/drivers/sensor/bmp388/bmp388.c index bab5c5dcf3a..eab0041fcd8 100644 --- a/drivers/sensor/bmp388/bmp388.c +++ b/drivers/sensor/bmp388/bmp388.c @@ -588,9 +588,7 @@ static int bmp388_device_ctrl( { int ret = 0; - if (ctrl_command == PM_DEVICE_STATE_SET) { - ret = bmp388_set_power_state(dev, *state); - } + ret = bmp388_set_power_state(dev, *state); return ret; } diff --git a/drivers/sensor/bq274xx/bq274xx.c b/drivers/sensor/bq274xx/bq274xx.c index d6bcaa3f748..e3dc76acde2 100644 --- a/drivers/sensor/bq274xx/bq274xx.c +++ b/drivers/sensor/bq274xx/bq274xx.c @@ -737,25 +737,19 @@ static int bq274xx_pm_control(const struct device *dev, uint32_t ctrl_command, int ret = 0; struct bq274xx_data *data = dev->data; - switch (ctrl_command) { - case PM_DEVICE_STATE_SET: - if (*state == PM_DEVICE_STATE_OFF) { - ret = bq274xx_enter_shutdown_mode(data); - if (ret < 0) { - LOG_ERR("Unable to enter off state"); - } - } else if (*state == PM_DEVICE_STATE_ACTIVE) { - ret = bq274xx_exit_shutdown_mode(dev); - if (ret < 0) { - LOG_ERR("Unable to enter active state"); - } - } else { - LOG_ERR("State to set is not implemented"); - ret = -ENOTSUP; + if (*state == PM_DEVICE_STATE_OFF) { + ret = bq274xx_enter_shutdown_mode(data); + if (ret < 0) { + LOG_ERR("Unable to enter off state"); } - break; - default: - ret = -EINVAL; + } else if (*state == PM_DEVICE_STATE_ACTIVE) { + ret = bq274xx_exit_shutdown_mode(dev); + if (ret < 0) { + LOG_ERR("Unable to enter active state"); + } + } else { + LOG_ERR("State to set is not implemented"); + ret = -ENOTSUP; } return ret; diff --git a/drivers/sensor/fdc2x1x/fdc2x1x.c b/drivers/sensor/fdc2x1x/fdc2x1x.c index 2dea2d0c526..34eff52ef71 100644 --- a/drivers/sensor/fdc2x1x/fdc2x1x.c +++ b/drivers/sensor/fdc2x1x/fdc2x1x.c @@ -540,22 +540,20 @@ 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; - if (ctrl_command == PM_DEVICE_STATE_SET) { - enum pm_device_state curr_state; - (void)pm_device_state_get(dev, &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; - } + 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; } } diff --git a/drivers/sensor/lis2mdl/lis2mdl.c b/drivers/sensor/lis2mdl/lis2mdl.c index 96439fdfa08..64af656ef70 100644 --- a/drivers/sensor/lis2mdl/lis2mdl.c +++ b/drivers/sensor/lis2mdl/lis2mdl.c @@ -481,20 +481,11 @@ static int lis2mdl_pm_control(const struct device *dev, uint32_t ctrl_command, struct lis2mdl_data *lis2mdl = dev->data; const struct lis2mdl_config *const config = dev->config; int status = 0; + enum pm_device_state curr_state; - switch (ctrl_command) { - case PM_DEVICE_STATE_SET: - 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); - } - break; - default: - LOG_ERR("Got unknown power management control command"); - status = -EINVAL; + (void)pm_device_state_get(dev, &curr_state); + if (*state != curr_state) { + status = lis2mdl_set_power_state(lis2mdl, config, *state); } return status; diff --git a/drivers/sensor/qdec_nrfx/qdec_nrfx.c b/drivers/sensor/qdec_nrfx/qdec_nrfx.c index cb4451b39c3..01be74ede35 100644 --- a/drivers/sensor/qdec_nrfx/qdec_nrfx.c +++ b/drivers/sensor/qdec_nrfx/qdec_nrfx.c @@ -248,15 +248,7 @@ static int qdec_nrfx_pm_control(const struct device *dev, LOG_DBG(""); - switch (ctrl_command) { - case PM_DEVICE_STATE_SET: - err = qdec_nrfx_pm_set_state(data, *state); - break; - - default: - err = -ENOTSUP; - break; - } + err = qdec_nrfx_pm_set_state(data, *state); return err; } diff --git a/drivers/sensor/sgp40/sgp40.c b/drivers/sensor/sgp40/sgp40.c index d2a206c4db1..55c803c2f3a 100644 --- a/drivers/sensor/sgp40/sgp40.c +++ b/drivers/sensor/sgp40/sgp40.c @@ -222,13 +222,7 @@ static int sgp40_pm_ctrl(const struct device *dev, uint32_t ctrl_command, enum pm_device_state *state) { - int rc = 0; - - if (ctrl_command == PM_DEVICE_STATE_SET) { - rc = sgp40_set_power_state(dev, *state); - } - - return rc; + return sgp40_set_power_state(dev, *state); } #endif /* CONFIG_PM_DEVICE */ diff --git a/drivers/sensor/vcnl4040/vcnl4040.c b/drivers/sensor/vcnl4040/vcnl4040.c index 9c452fbf464..199d630d195 100644 --- a/drivers/sensor/vcnl4040/vcnl4040.c +++ b/drivers/sensor/vcnl4040/vcnl4040.c @@ -223,56 +223,52 @@ static int vcnl4040_device_ctrl(const struct device *dev, enum pm_device_state *state) { int ret = 0; + uint16_t ps_conf; - if (ctrl_command == PM_DEVICE_STATE_SET) { - uint16_t ps_conf; + ret = vcnl4040_read(dev, VCNL4040_REG_PS_CONF, &ps_conf); + if (ret < 0) + return ret; +#ifdef CONFIG_VCNL4040_ENABLE_ALS + uint16_t als_conf; - ret = vcnl4040_read(dev, VCNL4040_REG_PS_CONF, &ps_conf); + ret = vcnl4040_read(dev, VCNL4040_REG_ALS_CONF, &als_conf); + if (ret < 0) + return ret; +#endif + if (*state == PM_DEVICE_STATE_ACTIVE) { + /* Clear proximity shutdown */ + ps_conf &= ~VCNL4040_PS_SD_MASK; + + ret = vcnl4040_write(dev, VCNL4040_REG_PS_CONF, + ps_conf); if (ret < 0) return ret; #ifdef CONFIG_VCNL4040_ENABLE_ALS - uint16_t als_conf; + /* Clear als shutdown */ + als_conf &= ~VCNL4040_ALS_SD_MASK; - ret = vcnl4040_read(dev, VCNL4040_REG_ALS_CONF, &als_conf); + ret = vcnl4040_write(dev, VCNL4040_REG_ALS_CONF, + als_conf); if (ret < 0) return ret; #endif - if (*state == PM_DEVICE_STATE_ACTIVE) { - /* Clear proximity shutdown */ - ps_conf &= ~VCNL4040_PS_SD_MASK; + } else { + /* Set proximity shutdown bit 0 */ + ps_conf |= VCNL4040_PS_SD_MASK; - ret = vcnl4040_write(dev, VCNL4040_REG_PS_CONF, - ps_conf); - if (ret < 0) - return ret; + ret = vcnl4040_write(dev, VCNL4040_REG_PS_CONF, + ps_conf); + if (ret < 0) + return ret; #ifdef CONFIG_VCNL4040_ENABLE_ALS - /* Clear als shutdown */ - als_conf &= ~VCNL4040_ALS_SD_MASK; + /* Clear als shutdown bit 0 */ + als_conf |= VCNL4040_ALS_SD_MASK; - ret = vcnl4040_write(dev, VCNL4040_REG_ALS_CONF, - als_conf); - if (ret < 0) - return ret; + ret = vcnl4040_write(dev, VCNL4040_REG_ALS_CONF, + als_conf) + if (ret < 0) + return ret; #endif - } else { - /* Set proximity shutdown bit 0 */ - ps_conf |= VCNL4040_PS_SD_MASK; - - ret = vcnl4040_write(dev, VCNL4040_REG_PS_CONF, - ps_conf); - if (ret < 0) - return ret; -#ifdef CONFIG_VCNL4040_ENABLE_ALS - /* Clear als shutdown bit 0 */ - als_conf |= VCNL4040_ALS_SD_MASK; - - ret = vcnl4040_write(dev, VCNL4040_REG_ALS_CONF, - als_conf) - if (ret < 0) - return ret; -#endif - } - } return ret; diff --git a/drivers/serial/uart_cc13xx_cc26xx.c b/drivers/serial/uart_cc13xx_cc26xx.c index b71eec3a44d..c442616e803 100644 --- a/drivers/serial/uart_cc13xx_cc26xx.c +++ b/drivers/serial/uart_cc13xx_cc26xx.c @@ -445,14 +445,11 @@ 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; - if (ctrl_command == PM_DEVICE_STATE_SET) { - 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); - } + (void)pm_device_state_get(dev, &curr_state); + if (*state != curr_state) { + ret = uart_cc13xx_cc26xx_set_power_state(dev, *state); } return ret; diff --git a/drivers/serial/uart_npcx.c b/drivers/serial/uart_npcx.c index 1260aa2ac5f..e8b984991fe 100644 --- a/drivers/serial/uart_npcx.c +++ b/drivers/serial/uart_npcx.c @@ -460,17 +460,7 @@ static inline int uart_npcx_set_power_state(const struct device *dev, static int uart_npcx_pm_control(const struct device *dev, uint32_t ctrl_command, enum pm_device_state *state) { - int ret = 0; - - switch (ctrl_command) { - case PM_DEVICE_STATE_SET: - ret = uart_npcx_set_power_state(dev, *state); - break; - default: - ret = -EINVAL; - } - - return ret; + return uart_npcx_set_power_state(dev, *state); } #endif /* CONFIG_PM_DEVICE */ diff --git a/drivers/serial/uart_nrfx_uart.c b/drivers/serial/uart_nrfx_uart.c index 5317f0fafe5..150296af43b 100644 --- a/drivers/serial/uart_nrfx_uart.c +++ b/drivers/serial/uart_nrfx_uart.c @@ -1162,13 +1162,11 @@ static int uart_nrfx_pm_control(const struct device *dev, uint32_t ctrl_command, enum pm_device_state *state) { - if (ctrl_command == PM_DEVICE_STATE_SET) { - enum pm_device_state current_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); - } + (void)pm_device_state_get(dev, ¤t_state); + if (*state != current_state) { + uart_nrfx_set_power_state(dev, *state); } return 0; diff --git a/drivers/serial/uart_nrfx_uarte.c b/drivers/serial/uart_nrfx_uarte.c index e044e419f57..b9349d46f49 100644 --- a/drivers/serial/uart_nrfx_uarte.c +++ b/drivers/serial/uart_nrfx_uarte.c @@ -1927,13 +1927,9 @@ static int uarte_nrfx_pm_control(const struct device *dev, { enum pm_device_state curr_state; - if (ctrl_command == PM_DEVICE_STATE_SET) { - 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); - } + (void)pm_device_state_get(dev, &curr_state); + if (*state != curr_state) { + uarte_nrfx_set_power_state(dev, *state); } return 0; diff --git a/drivers/serial/uart_stm32.c b/drivers/serial/uart_stm32.c index b95a6c44102..02e013b1f51 100644 --- a/drivers/serial/uart_stm32.c +++ b/drivers/serial/uart_stm32.c @@ -1463,13 +1463,11 @@ static int uart_stm32_pm_control(const struct device *dev, uint32_t ctrl_command, enum pm_device_state *state) { - if (ctrl_command == PM_DEVICE_STATE_SET) { - enum pm_device_state curr_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); - } + (void)pm_device_state_get(dev, &curr_state); + if (*state != curr_state) { + uart_stm32_set_power_state(dev, *state); } return 0; diff --git a/drivers/spi/spi_cc13xx_cc26xx.c b/drivers/spi/spi_cc13xx_cc26xx.c index 1746eeb92b2..aececb716b9 100644 --- a/drivers/spi/spi_cc13xx_cc26xx.c +++ b/drivers/spi/spi_cc13xx_cc26xx.c @@ -252,14 +252,11 @@ 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; - if (ctrl_command == PM_DEVICE_STATE_SET) { - 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); - } + (void)pm_device_state_get(dev, &curr_state); + if (*state != curr_state) { + ret = spi_cc13xx_cc26xx_set_power_state(dev, *state); } return ret; diff --git a/drivers/spi/spi_nrfx_spi.c b/drivers/spi/spi_nrfx_spi.c index 6214721a5e2..07ffe2e49d9 100644 --- a/drivers/spi/spi_nrfx_spi.c +++ b/drivers/spi/spi_nrfx_spi.c @@ -284,30 +284,27 @@ 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; - if (ctrl_command == PM_DEVICE_STATE_SET) { - 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; - (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; - - 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; - - default: - ret = -ENOTSUP; + 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; + + default: + ret = -ENOTSUP; } } diff --git a/drivers/spi/spi_nrfx_spim.c b/drivers/spi/spi_nrfx_spim.c index 1389af160a1..a8f966fd744 100644 --- a/drivers/spi/spi_nrfx_spim.c +++ b/drivers/spi/spi_nrfx_spim.c @@ -331,30 +331,27 @@ 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; - if (ctrl_command == PM_DEVICE_STATE_SET) { - 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; - (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; - - 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; - - default: - ret = -ENOTSUP; + 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; + + default: + ret = -ENOTSUP; } } diff --git a/samples/subsys/pm/device_pm/src/dummy_driver.c b/samples/subsys/pm/device_pm/src/dummy_driver.c index d65dd03d4cf..16bd3fac3cc 100644 --- a/samples/subsys/pm/device_pm/src/dummy_driver.c +++ b/samples/subsys/pm/device_pm/src/dummy_driver.c @@ -90,24 +90,13 @@ static int dummy_device_pm_ctrl(const struct device *dev, uint32_t ctrl_command, enum pm_device_state *state) { - int ret = 0; - - switch (ctrl_command) { - case PM_DEVICE_STATE_SET: - if (*state == PM_DEVICE_STATE_ACTIVE) { - printk("child resuming..\n"); - return 0; - } else { - printk("child suspending..\n"); - return 0; - } - break; - default: - ret = -EINVAL; - + if (*state == PM_DEVICE_STATE_ACTIVE) { + printk("child resuming..\n"); + } else { + printk("child suspending..\n"); } - return ret; + return 0; } static const struct dummy_driver_api funcs = { diff --git a/samples/subsys/pm/device_pm/src/dummy_parent.c b/samples/subsys/pm/device_pm/src/dummy_parent.c index 45888f9aa55..16368c63360 100644 --- a/samples/subsys/pm/device_pm/src/dummy_parent.c +++ b/samples/subsys/pm/device_pm/src/dummy_parent.c @@ -28,24 +28,13 @@ static int dummy_parent_pm_ctrl(const struct device *dev, uint32_t ctrl_command, enum pm_device_state *state) { - int ret = 0; - - switch (ctrl_command) { - case PM_DEVICE_STATE_SET: - if (*state == PM_DEVICE_STATE_ACTIVE) { - printk("parent resuming..\n"); - return 0; - } else { - printk("parent suspending..\n"); - return 0; - } - break; - default: - ret = -EINVAL; - + if (*state == PM_DEVICE_STATE_ACTIVE) { + printk("parent resuming..\n"); + } else { + printk("parent suspending..\n"); } - return ret; + return 0; } static const struct dummy_parent_api funcs = { diff --git a/tests/net/pm/src/main.c b/tests/net/pm/src/main.c index aceaf3004d0..7cb46a9990e 100644 --- a/tests/net/pm/src/main.c +++ b/tests/net/pm/src/main.c @@ -27,17 +27,13 @@ static int fake_dev_pm_control(const struct device *dev, uint32_t command, struct fake_dev_context *ctx = dev->data; int ret = 0; - if (command == PM_DEVICE_STATE_SET) { - if (*state == PM_DEVICE_STATE_SUSPEND) { - ret = net_if_suspend(ctx->iface); - if (ret == -EBUSY) { - goto out; - } - } else if (*state == PM_DEVICE_STATE_ACTIVE) { - ret = net_if_resume(ctx->iface); + if (*state == PM_DEVICE_STATE_SUSPEND) { + ret = net_if_suspend(ctx->iface); + if (ret == -EBUSY) { + goto out; } - } else { - return -EINVAL; + } else if (*state == PM_DEVICE_STATE_ACTIVE) { + ret = net_if_resume(ctx->iface); } out: diff --git a/tests/subsys/pm/device_runtime/src/dummy_driver.c b/tests/subsys/pm/device_runtime/src/dummy_driver.c index b5238d77d0b..af7a8081f6a 100644 --- a/tests/subsys/pm/device_runtime/src/dummy_driver.c +++ b/tests/subsys/pm/device_runtime/src/dummy_driver.c @@ -38,18 +38,7 @@ static int dummy_device_pm_ctrl(const struct device *dev, uint32_t ctrl_command, enum pm_device_state *state) { - int ret; - - switch (ctrl_command) { - case PM_DEVICE_STATE_SET: - ret = 0; - break; - default: - ret = -EINVAL; - - } - - return ret; + return 0; } static const struct dummy_driver_api funcs = { diff --git a/tests/subsys/pm/power_mgmt/src/dummy_driver.c b/tests/subsys/pm/power_mgmt/src/dummy_driver.c index cbf5237095a..ecb36052308 100644 --- a/tests/subsys/pm/power_mgmt/src/dummy_driver.c +++ b/tests/subsys/pm/power_mgmt/src/dummy_driver.c @@ -23,18 +23,7 @@ static int dummy_device_pm_ctrl(const struct device *dev, uint32_t ctrl_command, enum pm_device_state *state) { - int ret; - - switch (ctrl_command) { - case PM_DEVICE_STATE_SET: - ret = 0; - break; - default: - ret = -EINVAL; - - } - - return ret; + return 0; } static const struct dummy_driver_api funcs = {