pm: device: remove usage of ctrl_command

The callback is now invoked to set the device PM state in all cases, so
the usage of ctrl_command is redundant.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2021-06-07 18:27:39 +02:00 committed by Anas Nashif
parent c2cf1ad203
commit da0ff4ae46
37 changed files with 319 additions and 509 deletions

View file

@ -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;

View file

@ -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 */

View file

@ -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;

View file

@ -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:

View file

@ -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;
}
}

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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);

View file

@ -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;

View file

@ -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;

View file

@ -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 */

View file

@ -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;

View file

@ -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;

View file

@ -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);
}
}

View file

@ -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;
}

View file

@ -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;

View file

@ -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;
}
}

View file

@ -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;

View file

@ -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;
}

View file

@ -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 */

View file

@ -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;

View file

@ -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;

View file

@ -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 */

View file

@ -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, &current_state);
if (*state != current_state) {
uart_nrfx_set_power_state(dev, *state);
}
(void)pm_device_state_get(dev, &current_state);
if (*state != current_state) {
uart_nrfx_set_power_state(dev, *state);
}
return 0;

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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 = {

View file

@ -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 = {

View file

@ -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:

View file

@ -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 = {

View file

@ -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 = {