diff --git a/drivers/display/display_st7735r.c b/drivers/display/display_st7735r.c index bfa60af4f0d..c7a596bb93e 100644 --- a/drivers/display/display_st7735r.c +++ b/drivers/display/display_st7735r.c @@ -495,16 +495,16 @@ static int st7735r_init(const struct device *dev) #ifdef CONFIG_PM_DEVICE static int st7735r_pm_control(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { int ret = 0; struct st7735r_data *data = (struct st7735r_data *)dev->data; - switch (state) { - case PM_DEVICE_STATE_ACTIVE: + switch (action) { + case PM_DEVICE_ACTION_RESUME: ret = st7735r_exit_sleep(data); break; - case PM_DEVICE_STATE_SUSPENDED: + case PM_DEVICE_ACTION_SUSPEND: ret = st7735r_transmit(data, ST7735R_CMD_SLEEP_IN, NULL, 0); break; default: diff --git a/drivers/display/display_st7789v.c b/drivers/display/display_st7789v.c index 92106bd7712..fc02cd50429 100644 --- a/drivers/display/display_st7789v.c +++ b/drivers/display/display_st7789v.c @@ -397,16 +397,16 @@ static int st7789v_init(const struct device *dev) #ifdef CONFIG_PM_DEVICE static int st7789v_pm_control(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { struct st7789v_data *data = (struct st7789v_data *)dev->data; int ret = 0; - switch (state) { - case PM_DEVICE_STATE_ACTIVE: + switch (action) { + case PM_DEVICE_ACTION_RESUME: st7789v_exit_sleep(data); break; - case PM_DEVICE_STATE_SUSPENDED: + case PM_DEVICE_ACTION_SUSPEND: ret = st7789v_transmit(data, ST7789V_CMD_SLEEP_IN, NULL, 0); break; default: diff --git a/drivers/entropy/entropy_cc13xx_cc26xx.c b/drivers/entropy/entropy_cc13xx_cc26xx.c index bdb5640509f..c8e411d8526 100644 --- a/drivers/entropy/entropy_cc13xx_cc26xx.c +++ b/drivers/entropy/entropy_cc13xx_cc26xx.c @@ -265,16 +265,16 @@ static int post_notify_fxn(unsigned int eventType, uintptr_t eventArg, #ifdef CONFIG_PM_DEVICE static int entropy_cc13xx_cc26xx_pm_control(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { struct entropy_cc13xx_cc26xx_data *data = get_dev_data(dev); - switch (state) { - case PM_DEVICE_STATE_ACTIVE: + switch (action) { + case PM_DEVICE_ACTION_RESUME: Power_setDependency(PowerCC26XX_PERIPH_TRNG); start_trng(data); break; - case PM_DEVICE_STATE_SUSPENDED: + case PM_DEVICE_ACTION_SUSPEND: stop_trng(data); Power_releaseDependency(PowerCC26XX_PERIPH_TRNG); break; diff --git a/drivers/ethernet/eth_mcux.c b/drivers/ethernet/eth_mcux.c index 188f32aa51d..4227d98e342 100644 --- a/drivers/ethernet/eth_mcux.c +++ b/drivers/ethernet/eth_mcux.c @@ -185,7 +185,7 @@ static void eth_mcux_phy_enter_reset(struct eth_context *context); void eth_mcux_phy_stop(struct eth_context *context); static int eth_mcux_device_pm_control(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { struct eth_context *eth_ctx = (struct eth_context *)dev->data; int ret = 0; @@ -197,8 +197,8 @@ static int eth_mcux_device_pm_control(const struct device *dev, goto out; } - switch (state) { - case PM_DEVICE_STATE_SUSPENDED: + switch (action) { + case PM_DEVICE_ACTION_SUSPEND: LOG_DBG("Suspending"); ret = net_if_suspend(eth_ctx->iface); @@ -214,7 +214,7 @@ static int eth_mcux_device_pm_control(const struct device *dev, clock_control_off(eth_ctx->clock_dev, (clock_control_subsys_t)eth_ctx->clock); break; - case PM_DEVICE_STATE_ACTIVE: + case PM_DEVICE_ACTION_RESUME: LOG_DBG("Resuming"); clock_control_on(eth_ctx->clock_dev, diff --git a/drivers/flash/spi_flash_at45.c b/drivers/flash/spi_flash_at45.c index cc747c91a2f..ad6afa01173 100644 --- a/drivers/flash/spi_flash_at45.c +++ b/drivers/flash/spi_flash_at45.c @@ -625,18 +625,18 @@ static int spi_flash_at45_init(const struct device *dev) #if IS_ENABLED(CONFIG_PM_DEVICE) static int spi_flash_at45_pm_control(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { const struct spi_flash_at45_config *dev_config = get_dev_config(dev); - switch (state) { - case PM_DEVICE_STATE_ACTIVE: + switch (action) { + case PM_DEVICE_ACTION_RESUME: acquire(dev); power_down_op(dev, CMD_EXIT_DPD, dev_config->t_exit_dpd); release(dev); break; - case PM_DEVICE_STATE_SUSPENDED: + case PM_DEVICE_ACTION_SUSPEND: acquire(dev); power_down_op(dev, dev_config->use_udpd ? CMD_ENTER_UDPD : CMD_ENTER_DPD, diff --git a/drivers/gpio/gpio_dw.c b/drivers/gpio/gpio_dw.c index d57834eeda3..d44ea78770f 100644 --- a/drivers/gpio/gpio_dw.c +++ b/drivers/gpio/gpio_dw.c @@ -430,13 +430,13 @@ static inline int gpio_dw_manage_callback(const struct device *port, * the *context may include IN data or/and OUT data */ static int gpio_dw_device_ctrl(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { - switch (state) { - case PM_DEVICE_STATE_SUSPENDED: + switch (action) { + case PM_DEVICE_ACTION_SUSPEND: gpio_dw_clock_off(dev); break; - case PM_DEVICE_STATE_ACTIVE: + case PM_DEVICE_ACTION_RESUME: gpio_dw_clock_on(dev); break; default: diff --git a/drivers/gpio/gpio_stm32.c b/drivers/gpio/gpio_stm32.c index fe661638fb9..8b1ff3dea53 100644 --- a/drivers/gpio/gpio_stm32.c +++ b/drivers/gpio/gpio_stm32.c @@ -575,12 +575,12 @@ static const struct gpio_driver_api gpio_stm32_driver = { #ifdef CONFIG_PM_DEVICE static int gpio_stm32_pm_device_ctrl(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { - switch (state) { - case PM_DEVICE_STATE_ACTIVE: + switch (action) { + case PM_DEVICE_ACTION_RESUME: return gpio_stm32_clock_request(dev, true); - case PM_DEVICE_STATE_SUSPENDED: + case PM_DEVICE_ACTION_SUSPEND: return gpio_stm32_clock_request(dev, false); default: return -ENOTSUP; diff --git a/drivers/i2c/i2c_cc13xx_cc26xx.c b/drivers/i2c/i2c_cc13xx_cc26xx.c index 1343c934b8a..38e7449aed8 100644 --- a/drivers/i2c/i2c_cc13xx_cc26xx.c +++ b/drivers/i2c/i2c_cc13xx_cc26xx.c @@ -327,12 +327,12 @@ static int postNotifyFxn(unsigned int eventType, uintptr_t eventArg, #ifdef CONFIG_PM_DEVICE static int i2c_cc13xx_cc26xx_pm_control(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { int ret = 0; - switch (state) { - case PM_DEVICE_STATE_ACTIVE: + switch (action) { + case PM_DEVICE_ACTION_RESUME: Power_setDependency(PowerCC26XX_PERIPH_I2C0); IOCPinTypeI2c(get_dev_config(dev)->base, get_dev_config(dev)->sda_pin, @@ -343,7 +343,7 @@ static int i2c_cc13xx_cc26xx_pm_control(const struct device *dev, I2CMasterIntEnable(get_dev_config(dev)->base); } break; - case PM_DEVICE_STATE_SUSPENDED: + case PM_DEVICE_ACTION_SUSPEND: I2CMasterIntDisable(get_dev_config(dev)->base); I2CMasterDisable(get_dev_config(dev)->base); /* Reset pin type to default GPIO configuration */ diff --git a/drivers/i2c/i2c_nrfx_twi.c b/drivers/i2c/i2c_nrfx_twi.c index 99f9fc2f660..21c1bc72f07 100644 --- a/drivers/i2c/i2c_nrfx_twi.c +++ b/drivers/i2c/i2c_nrfx_twi.c @@ -217,12 +217,12 @@ static int init_twi(const struct device *dev) #ifdef CONFIG_PM_DEVICE static int twi_nrfx_pm_control(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { int ret = 0; - switch (state) { - case PM_DEVICE_STATE_ACTIVE: + switch (action) { + case PM_DEVICE_ACTION_RESUME: init_twi(dev); if (get_dev_data(dev)->dev_config) { i2c_nrfx_twi_configure(dev, @@ -230,7 +230,7 @@ static int twi_nrfx_pm_control(const struct device *dev, } break; - case PM_DEVICE_STATE_SUSPENDED: + case PM_DEVICE_ACTION_SUSPEND: nrfx_twi_uninit(&get_dev_config(dev)->twi); break; diff --git a/drivers/i2c/i2c_nrfx_twim.c b/drivers/i2c/i2c_nrfx_twim.c index 4ee43626784..1b84412d07c 100644 --- a/drivers/i2c/i2c_nrfx_twim.c +++ b/drivers/i2c/i2c_nrfx_twim.c @@ -255,12 +255,12 @@ static int init_twim(const struct device *dev) #ifdef CONFIG_PM_DEVICE static int twim_nrfx_pm_control(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { int ret = 0; - switch (state) { - case PM_DEVICE_STATE_ACTIVE: + switch (action) { + case PM_DEVICE_ACTION_RESUME: init_twim(dev); if (get_dev_data(dev)->dev_config) { i2c_nrfx_twim_configure(dev, @@ -268,7 +268,7 @@ static int twim_nrfx_pm_control(const struct device *dev, } break; - case PM_DEVICE_STATE_SUSPENDED: + case PM_DEVICE_ACTION_SUSPEND: nrfx_twim_uninit(&get_dev_config(dev)->twim); break; diff --git a/drivers/interrupt_controller/intc_arcv2_irq_unit.c b/drivers/interrupt_controller/intc_arcv2_irq_unit.c index 7b52232ecf4..a5d9f363cba 100644 --- a/drivers/interrupt_controller/intc_arcv2_irq_unit.c +++ b/drivers/interrupt_controller/intc_arcv2_irq_unit.c @@ -175,16 +175,16 @@ static int arc_v2_irq_unit_resume(const struct device *dev) * @return operation result */ static int arc_v2_irq_unit_device_ctrl(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { int ret = 0; unsigned int key = arch_irq_lock(); - switch (state) { - case PM_DEVICE_STATE_SUSPENDED: + switch (action) { + case PM_DEVICE_ACTION_SUSPEND: ret = arc_v2_irq_unit_suspend(dev); break; - case PM_DEVICE_STATE_ACTIVE: + case PM_DEVICE_ACTION_RESUME: ret = arc_v2_irq_unit_resume(dev); break; default: diff --git a/drivers/interrupt_controller/intc_ioapic.c b/drivers/interrupt_controller/intc_ioapic.c index 36a212f8611..212be5515a7 100644 --- a/drivers/interrupt_controller/intc_ioapic.c +++ b/drivers/interrupt_controller/intc_ioapic.c @@ -310,15 +310,15 @@ int ioapic_resume_from_suspend(const struct device *port) */ __pinned_func static int ioapic_device_ctrl(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { int ret = 0; - switch (state) { - case PM_DEVICE_STATE_ACTIVE: + switch (action) { + case PM_DEVICE_ACTION_RESUME: ret = ioapic_resume_from_suspend(dev); break; - case PM_DEVICE_STATE_SUSPENDED: + case PM_DEVICE_ACTION_SUSPEND: ret = ioapic_suspend(dev); break; default: diff --git a/drivers/interrupt_controller/intc_loapic.c b/drivers/interrupt_controller/intc_loapic.c index ffaa4100854..0a8f0555c99 100644 --- a/drivers/interrupt_controller/intc_loapic.c +++ b/drivers/interrupt_controller/intc_loapic.c @@ -409,15 +409,15 @@ int loapic_resume(const struct device *port) */ __pinned_func static int loapic_device_ctrl(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { int ret = 0; - switch (state) { - case PM_DEVICE_STATE_SUSPENDED: + switch (action) { + case PM_DEVICE_ACTION_SUSPEND: ret = loapic_suspend(dev); break; - case PM_DEVICE_STATE_ACTIVE: + case PM_DEVICE_ACTION_RESUME: ret = loapic_resume(dev); break; default: diff --git a/drivers/led/led_pwm.c b/drivers/led/led_pwm.c index a886800c793..7ca6afeb16b 100644 --- a/drivers/led/led_pwm.c +++ b/drivers/led/led_pwm.c @@ -115,17 +115,31 @@ static int led_pwm_init(const struct device *dev) #ifdef CONFIG_PM_DEVICE static int led_pwm_pm_control(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { const struct led_pwm_config *config = DEV_CFG(dev); /* switch all underlying PWM devices to the new state */ for (size_t i = 0; i < config->num_leds; i++) { + int err; + enum pm_device_state state; const struct led_pwm *led_pwm = &config->led[i]; LOG_DBG("Switching PWM %p to state %" PRIu32, led_pwm->dev, state); - int err = pm_device_state_set(led_pwm->dev, state); + /* NOTE: temporary solution, deserves proper fix */ + switch (action) { + case PM_DEVICE_ACTION_RESUME: + state = PM_DEVICE_STATE_ACTIVE; + break; + case PM_DEVICE_ACTION_SUSPEND: + state = PM_DEVICE_STATE_SUSPENDED; + break; + default: + return -ENOTSUP; + } + + err = pm_device_state_set(led_pwm->dev, state); if (err) { LOG_ERR("Cannot switch PWM %p power state", led_pwm->dev); } diff --git a/drivers/pwm/pwm_nrfx.c b/drivers/pwm/pwm_nrfx.c index dee8e855967..2aa29ca0ad5 100644 --- a/drivers/pwm/pwm_nrfx.c +++ b/drivers/pwm/pwm_nrfx.c @@ -292,15 +292,15 @@ static void pwm_nrfx_uninit(const struct device *dev) } static int pwm_nrfx_pm_control(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { int err = 0; - switch (state) { - case PM_DEVICE_STATE_ACTIVE: + switch (action) { + case PM_DEVICE_ACTION_RESUME: err = pwm_nrfx_init(dev); break; - case PM_DEVICE_STATE_SUSPENDED: + case PM_DEVICE_ACTION_SUSPEND: pwm_nrfx_uninit(dev); break; default: diff --git a/drivers/sensor/apds9960/apds9960.c b/drivers/sensor/apds9960/apds9960.c index e1070e23bec..bff5e8bfe6b 100644 --- a/drivers/sensor/apds9960/apds9960.c +++ b/drivers/sensor/apds9960/apds9960.c @@ -409,14 +409,14 @@ static int apds9960_init_interrupt(const struct device *dev) #ifdef CONFIG_PM_DEVICE static int apds9960_device_ctrl(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { const struct apds9960_config *config = dev->config; struct apds9960_data *data = dev->data; int ret = 0; - switch (state) { - case PM_DEVICE_STATE_ACTIVE: + switch (action) { + case PM_DEVICE_ACTION_RESUME: if (i2c_reg_update_byte(data->i2c, config->i2c_address, APDS9960_ENABLE_REG, APDS9960_ENABLE_PON, @@ -424,7 +424,7 @@ static int apds9960_device_ctrl(const struct device *dev, ret = -EIO; } break; - case PM_DEVICE_STATE_SUSPENDED: + case PM_DEVICE_ACTION_SUSPEND: if (i2c_reg_update_byte(data->i2c, config->i2c_address, APDS9960_ENABLE_REG, APDS9960_ENABLE_PON, 0)) { diff --git a/drivers/sensor/bme280/bme280.c b/drivers/sensor/bme280/bme280.c index 3e75f02340e..9728518e15c 100644 --- a/drivers/sensor/bme280/bme280.c +++ b/drivers/sensor/bme280/bme280.c @@ -410,16 +410,16 @@ static int bme280_chip_init(const struct device *dev) } #ifdef CONFIG_PM_DEVICE -int bme280_pm_ctrl(const struct device *dev, enum pm_device_state state) +int bme280_pm_ctrl(const struct device *dev, enum pm_device_action action) { int ret = 0; - switch (state) { - case PM_DEVICE_STATE_ACTIVE: + switch (action) { + case PM_DEVICE_ACTION_RESUME: /* Re-initialize the chip */ ret = bme280_chip_init(dev); break; - case PM_DEVICE_STATE_SUSPENDED: + case PM_DEVICE_ACTION_SUSPEND: /* Put the chip into sleep mode */ ret = bme280_reg_write(dev, BME280_REG_CTRL_MEAS, diff --git a/drivers/sensor/bmp388/bmp388.c b/drivers/sensor/bmp388/bmp388.c index 0f02eee4880..a7fa11f5bbe 100644 --- a/drivers/sensor/bmp388/bmp388.c +++ b/drivers/sensor/bmp388/bmp388.c @@ -550,15 +550,15 @@ static int bmp388_get_calibration_data(const struct device *dev) #ifdef CONFIG_PM_DEVICE static int bmp388_device_ctrl(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { uint8_t reg_val; - switch (state) { - case PM_DEVICE_STATE_ACTIVE: + switch (action) { + case PM_DEVICE_ACTION_RESUME: reg_val = BMP388_PWR_CTRL_MODE_NORMAL; break; - case PM_DEVICE_STATE_SUSPENDED: + case PM_DEVICE_ACTION_SUSPEND: reg_val = BMP388_PWR_CTRL_MODE_SLEEP; break; default: diff --git a/drivers/sensor/bq274xx/bq274xx.c b/drivers/sensor/bq274xx/bq274xx.c index ca61a516b43..3d1cd71e854 100644 --- a/drivers/sensor/bq274xx/bq274xx.c +++ b/drivers/sensor/bq274xx/bq274xx.c @@ -732,16 +732,16 @@ static int bq274xx_exit_shutdown_mode(const struct device *dev) } static int bq274xx_pm_control(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { int ret; struct bq274xx_data *data = dev->data; - switch (state) { - case PM_DEVICE_STATE_OFF: + switch (action) { + case PM_DEVICE_ACTION_TURN_OFF: ret = bq274xx_enter_shutdown_mode(data); break; - case PM_DEVICE_STATE_ACTIVE: + case PM_DEVICE_ACTION_RESUME: ret = bq274xx_exit_shutdown_mode(dev); break; default: diff --git a/drivers/sensor/fdc2x1x/fdc2x1x.c b/drivers/sensor/fdc2x1x/fdc2x1x.c index 4b58e72a430..c5884434260 100644 --- a/drivers/sensor/fdc2x1x/fdc2x1x.c +++ b/drivers/sensor/fdc2x1x/fdc2x1x.c @@ -482,7 +482,7 @@ static int fdc2x1x_set_shutdown(const struct device *dev, bool enable) * @return 0 in case of success, negative error code otherwise. */ static int fdc2x1x_device_pm_ctrl(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { int ret; struct fdc2x1x_data *data = dev->data; @@ -491,8 +491,8 @@ static int fdc2x1x_device_pm_ctrl(const struct device *dev, (void)pm_device_state_get(dev, &curr_state); - switch (state) { - case PM_DEVICE_STATE_ACTIVE: + switch (action) { + case PM_DEVICE_ACTION_RESUME: if (curr_state == PM_DEVICE_STATE_OFF) { ret = fdc2x1x_set_shutdown(dev, false); if (ret) { @@ -506,7 +506,7 @@ static int fdc2x1x_device_pm_ctrl(const struct device *dev, } break; - case PM_DEVICE_STATE_SUSPENDED: + case PM_DEVICE_ACTION_SUSPEND: if (curr_state == PM_DEVICE_STATE_OFF) { ret = fdc2x1x_set_shutdown(dev, false); if (ret) { @@ -519,7 +519,7 @@ static int fdc2x1x_device_pm_ctrl(const struct device *dev, } break; - case PM_DEVICE_STATE_OFF: + case PM_DEVICE_ACTION_TURN_OFF: if (cfg->sd_gpio->name) { ret = fdc2x1x_set_shutdown(dev, true); } else { diff --git a/drivers/sensor/lis2mdl/lis2mdl.c b/drivers/sensor/lis2mdl/lis2mdl.c index 2e9eec00891..165135ce330 100644 --- a/drivers/sensor/lis2mdl/lis2mdl.c +++ b/drivers/sensor/lis2mdl/lis2mdl.c @@ -443,14 +443,14 @@ static int lis2mdl_init(const struct device *dev) #ifdef CONFIG_PM_DEVICE static int lis2mdl_pm_control(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { const struct lis2mdl_config *config = dev->config; stmdev_ctx_t *ctx = (stmdev_ctx_t *)&config->ctx; int status = 0; - switch (state) { - case PM_DEVICE_STATE_ACTIVE: + switch (action) { + case PM_DEVICE_ACTION_RESUME: if (config->single_mode) { status = lis2mdl_operating_mode_set(ctx, LIS2MDL_SINGLE_TRIGGER); @@ -463,7 +463,7 @@ static int lis2mdl_pm_control(const struct device *dev, } LOG_DBG("State changed to active"); break; - case PM_DEVICE_STATE_SUSPENDED: + case PM_DEVICE_ACTION_SUSPEND: status = lis2mdl_operating_mode_set(ctx, LIS2MDL_POWER_DOWN); if (status) { LOG_ERR("Power down failed"); diff --git a/drivers/sensor/qdec_nrfx/qdec_nrfx.c b/drivers/sensor/qdec_nrfx/qdec_nrfx.c index 336816590a7..b13f119bec4 100644 --- a/drivers/sensor/qdec_nrfx/qdec_nrfx.c +++ b/drivers/sensor/qdec_nrfx/qdec_nrfx.c @@ -208,18 +208,18 @@ static int qdec_nrfx_init(const struct device *dev) #ifdef CONFIG_PM_DEVICE static int qdec_nrfx_pm_control(struct qdec_nrfx_data *data, - enum pm_device_state state) + enum pm_device_action action) { - switch (state) { - case PM_DEVICE_STATE_ACTIVE: + switch (action) { + case PM_DEVICE_ACTION_RESUME: qdec_nrfx_gpio_ctrl(true); nrfx_qdec_enable(); break; - case PM_DEVICE_STATE_OFF: + case PM_DEVICE_ACTION_TURN_OFF: /* device must be uninitialized */ nrfx_qdec_uninit(); break; - case PM_DEVICE_STATE_SUSPENDED: + case PM_DEVICE_ACTION_SUSPEND: /* device must be suspended */ nrfx_qdec_disable(); qdec_nrfx_gpio_ctrl(false); diff --git a/drivers/sensor/sgp40/sgp40.c b/drivers/sensor/sgp40/sgp40.c index 824547c6d70..4258b645cff 100644 --- a/drivers/sensor/sgp40/sgp40.c +++ b/drivers/sensor/sgp40/sgp40.c @@ -186,16 +186,16 @@ static int sgp40_channel_get(const struct device *dev, #ifdef CONFIG_PM_DEVICE -static int sgp40_pm_ctrl(const struct device *dev, enum pm_device_state state) +static int sgp40_pm_ctrl(const struct device *dev, enum pm_device_action action) { uint16_t cmd; - switch (state) { - case PM_DEVICE_STATE_ACTIVE: + switch (action) { + case PM_DEVICE_ACTION_RESUME: /* activate the hotplate by sending a measure command */ cmd = SGP40_CMD_MEASURE_RAW; break; - case PM_DEVICE_STATE_SUSPENDED: + case PM_DEVICE_ACTION_SUSPEND: cmd = SGP40_CMD_HEATER_OFF; break; default: diff --git a/drivers/sensor/vcnl4040/vcnl4040.c b/drivers/sensor/vcnl4040/vcnl4040.c index 0191ba24603..6fa065ff60f 100644 --- a/drivers/sensor/vcnl4040/vcnl4040.c +++ b/drivers/sensor/vcnl4040/vcnl4040.c @@ -219,7 +219,7 @@ static int vcnl4040_ambient_setup(const struct device *dev) #ifdef CONFIG_PM_DEVICE static int vcnl4040_device_ctrl(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { int ret = 0; uint16_t ps_conf; @@ -234,8 +234,8 @@ static int vcnl4040_device_ctrl(const struct device *dev, if (ret < 0) return ret; #endif - switch (state) { - case PM_DEVICE_STATE_ACTIVE: + switch (action) { + case PM_DEVICE_ACTION_RESUME: /* Clear proximity shutdown */ ps_conf &= ~VCNL4040_PS_SD_MASK; @@ -253,7 +253,7 @@ static int vcnl4040_device_ctrl(const struct device *dev, return ret; #endif break; - case PM_DEVICE_STATE_SUSPENDED: + case PM_DEVICE_ACTION_SUSPEND: /* Set proximity shutdown bit 0 */ ps_conf |= VCNL4040_PS_SD_MASK; diff --git a/drivers/serial/uart_cc13xx_cc26xx.c b/drivers/serial/uart_cc13xx_cc26xx.c index 799414e7881..50e7aec6fff 100644 --- a/drivers/serial/uart_cc13xx_cc26xx.c +++ b/drivers/serial/uart_cc13xx_cc26xx.c @@ -398,12 +398,12 @@ static int postNotifyFxn(unsigned int eventType, uintptr_t eventArg, #ifdef CONFIG_PM_DEVICE static int uart_cc13xx_cc26xx_pm_control(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { int ret = 0; - switch (state) { - case PM_DEVICE_STATE_ACTIVE: + switch (action) { + case PM_DEVICE_ACTION_RESUME: if (get_dev_conf(dev)->regs == DT_INST_REG_ADDR(0)) { Power_setDependency(PowerCC26XX_PERIPH_UART0); } else { @@ -413,7 +413,7 @@ static int uart_cc13xx_cc26xx_pm_control(const struct device *dev, ret = uart_cc13xx_cc26xx_configure(dev, &get_dev_data(dev)->uart_config); break; - case PM_DEVICE_STATE_SUSPENDED: + case PM_DEVICE_ACTION_SUSPEND: UARTDisable(get_dev_conf(dev)->regs); /* * Release power dependency - i.e. potentially power diff --git a/drivers/serial/uart_npcx.c b/drivers/serial/uart_npcx.c index c95a4a570bb..7a8c4b75b4c 100644 --- a/drivers/serial/uart_npcx.c +++ b/drivers/serial/uart_npcx.c @@ -439,11 +439,11 @@ static inline bool uart_npcx_device_is_transmitting(const struct device *dev) } static inline int uart_npcx_pm_control(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { /* If next device power state is SUSPEND power state */ - switch (state) { - case PM_DEVICE_STATE_SUSPENDED: + switch (action) { + case PM_DEVICE_ACTION_SUSPEND: /* * If uart device is busy with transmitting, the driver will * stay in while loop and wait for the transaction is completed. diff --git a/drivers/serial/uart_nrfx_uart.c b/drivers/serial/uart_nrfx_uart.c index 7b1328ffbde..3a4247401c6 100644 --- a/drivers/serial/uart_nrfx_uart.c +++ b/drivers/serial/uart_nrfx_uart.c @@ -1140,10 +1140,10 @@ static void uart_nrfx_pins_enable(const struct device *dev, bool enable) } static int uart_nrfx_pm_control(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { - switch (state) { - case PM_DEVICE_STATE_ACTIVE: + switch (action) { + case PM_DEVICE_ACTION_RESUME: uart_nrfx_pins_enable(dev, true); nrf_uart_enable(uart0_addr); if (RX_PIN_USED) { @@ -1151,7 +1151,7 @@ static int uart_nrfx_pm_control(const struct device *dev, NRF_UART_TASK_STARTRX); } break; - case PM_DEVICE_STATE_SUSPENDED: + case PM_DEVICE_ACTION_SUSPEND: nrf_uart_disable(uart0_addr); uart_nrfx_pins_enable(dev, false); break; diff --git a/drivers/serial/uart_nrfx_uarte.c b/drivers/serial/uart_nrfx_uarte.c index 4ce9f1a0733..2521565f3f1 100644 --- a/drivers/serial/uart_nrfx_uarte.c +++ b/drivers/serial/uart_nrfx_uarte.c @@ -1832,15 +1832,15 @@ static void wait_for_tx_stopped(const struct device *dev) static int uarte_nrfx_pm_control(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { 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 - switch (state) { - case PM_DEVICE_STATE_ACTIVE: + switch (action) { + case PM_DEVICE_ACTION_RESUME: uarte_nrfx_pins_enable(dev, true); nrf_uarte_enable(uarte); @@ -1865,7 +1865,7 @@ static int uarte_nrfx_pm_control(const struct device *dev, #endif } break; - case PM_DEVICE_STATE_SUSPENDED: + case PM_DEVICE_ACTION_SUSPEND: /* Disabling UART requires stopping RX, but stop RX event is * only sent after each RX if async UART API is used. */ diff --git a/drivers/serial/uart_stm32.c b/drivers/serial/uart_stm32.c index c7b06bd1c2e..705e6d8fa4c 100644 --- a/drivers/serial/uart_stm32.c +++ b/drivers/serial/uart_stm32.c @@ -1423,13 +1423,13 @@ static int uart_stm32_init(const struct device *dev) #ifdef CONFIG_PM_DEVICE static int uart_stm32_pm_control(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { USART_TypeDef *UartInstance = UART_STRUCT(dev); /* setting a low power mode */ - switch (state) { - case PM_DEVICE_STATE_SUSPENDED: + switch (action) { + case PM_DEVICE_ACTION_SUSPEND: #ifdef USART_ISR_BUSY /* Make sure that no USART transfer is on-going */ while (LL_USART_IsActiveFlag_BUSY(UartInstance) == 1) { diff --git a/drivers/spi/spi_cc13xx_cc26xx.c b/drivers/spi/spi_cc13xx_cc26xx.c index dedc6ab8d84..a95bd9b5731 100644 --- a/drivers/spi/spi_cc13xx_cc26xx.c +++ b/drivers/spi/spi_cc13xx_cc26xx.c @@ -209,17 +209,17 @@ static int spi_cc13xx_cc26xx_release(const struct device *dev, #ifdef CONFIG_PM_DEVICE static int spi_cc13xx_cc26xx_pm_control(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { - switch (state) { - case PM_DEVICE_STATE_ACTIVE: + switch (action) { + case PM_DEVICE_ACTION_RESUME: if (get_dev_config(dev)->base == DT_INST_REG_ADDR(0)) { Power_setDependency(PowerCC26XX_PERIPH_SSI0); } else { Power_setDependency(PowerCC26XX_PERIPH_SSI1); } break; - case PM_DEVICE_STATE_SUSPENDED: + case PM_DEVICE_ACTION_SUSPEND: SSIDisable(get_dev_config(dev)->base); /* * Release power dependency diff --git a/drivers/spi/spi_nrfx_spi.c b/drivers/spi/spi_nrfx_spi.c index d66dc54b4e1..d70a6c5d902 100644 --- a/drivers/spi/spi_nrfx_spi.c +++ b/drivers/spi/spi_nrfx_spi.c @@ -278,20 +278,20 @@ static int init_spi(const struct device *dev) #ifdef CONFIG_PM_DEVICE static int spi_nrfx_pm_control(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { int ret = 0; struct spi_nrfx_data *data = get_dev_data(dev); const struct spi_nrfx_config *config = get_dev_config(dev); - switch (state) { - case PM_DEVICE_STATE_ACTIVE: + switch (action) { + case PM_DEVICE_ACTION_RESUME: ret = init_spi(dev); /* Force reconfiguration before next transfer */ data->ctx.config = NULL; break; - case PM_DEVICE_STATE_SUSPENDED: + case PM_DEVICE_ACTION_SUSPEND: nrfx_spi_uninit(&config->spi); break; diff --git a/drivers/spi/spi_nrfx_spim.c b/drivers/spi/spi_nrfx_spim.c index 8c759ea89ed..8765a2109e1 100644 --- a/drivers/spi/spi_nrfx_spim.c +++ b/drivers/spi/spi_nrfx_spim.c @@ -325,20 +325,20 @@ static int init_spim(const struct device *dev) #ifdef CONFIG_PM_DEVICE static int spim_nrfx_pm_control(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { int ret = 0; struct spi_nrfx_data *data = get_dev_data(dev); const struct spi_nrfx_config *config = get_dev_config(dev); - switch (state) { - case PM_DEVICE_STATE_ACTIVE: + switch (action) { + case PM_DEVICE_ACTION_RESUME: ret = init_spim(dev); /* Force reconfiguration before next transfer */ data->ctx.config = NULL; break; - case PM_DEVICE_STATE_SUSPENDED: + case PM_DEVICE_ACTION_SUSPEND: nrfx_spim_uninit(&config->spim); break; diff --git a/drivers/timer/sys_clock_init.c b/drivers/timer/sys_clock_init.c index ab55a003a88..1caaf3e02d9 100644 --- a/drivers/timer/sys_clock_init.c +++ b/drivers/timer/sys_clock_init.c @@ -31,7 +31,7 @@ int __weak sys_clock_driver_init(const struct device *dev) } int __weak sys_clock_device_ctrl(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { return -ENOSYS; } diff --git a/include/pm/device.h b/include/pm/device.h index 52c481bff6b..da52185751e 100644 --- a/include/pm/device.h +++ b/include/pm/device.h @@ -70,6 +70,16 @@ enum pm_device_flag { PM_DEVICE_FLAG_COUNT }; +/** @brief Device PM actions. */ +enum pm_device_action { + /** Suspend. */ + PM_DEVICE_ACTION_SUSPEND, + /** Resume. */ + PM_DEVICE_ACTION_RESUME, + /** Turn off. */ + PM_DEVICE_ACTION_TURN_OFF, +}; + /** * @brief Device PM info */ @@ -97,14 +107,14 @@ struct pm_device { * @brief Device power management control function callback. * * @param dev Device instance. - * @param state Requested state. + * @param action Requested action. * * @retval 0 If successful. - * @retval -ENOTSUP If the requested state is not supported. + * @retval -ENOTSUP If the requested action is not supported. * @retval Errno Other negative errno on failure. */ typedef int (*pm_device_control_callback_t)(const struct device *dev, - enum pm_device_state state); + enum pm_device_action action); /** * @brief Get name of device PM state diff --git a/samples/subsys/pm/device_pm/src/dummy_driver.c b/samples/subsys/pm/device_pm/src/dummy_driver.c index 4f0681341f1..b70b75a9231 100644 --- a/samples/subsys/pm/device_pm/src/dummy_driver.c +++ b/samples/subsys/pm/device_pm/src/dummy_driver.c @@ -87,13 +87,13 @@ static int dummy_close(const struct device *dev) } static int dummy_device_pm_ctrl(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { - switch (state) { - case PM_DEVICE_STATE_ACTIVE: + switch (action) { + case PM_DEVICE_ACTION_RESUME: printk("child resuming..\n"); break; - case PM_DEVICE_STATE_SUSPENDED: + case PM_DEVICE_ACTION_SUSPEND: printk("child suspending..\n"); break; default: diff --git a/samples/subsys/pm/device_pm/src/dummy_parent.c b/samples/subsys/pm/device_pm/src/dummy_parent.c index c9b23eaa66b..b80e4ed0fa9 100644 --- a/samples/subsys/pm/device_pm/src/dummy_parent.c +++ b/samples/subsys/pm/device_pm/src/dummy_parent.c @@ -25,13 +25,13 @@ static int dummy_transfer(const struct device *dev, uint32_t cmd, } static int dummy_parent_pm_ctrl(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { - switch (state) { - case PM_DEVICE_STATE_ACTIVE: + switch (action) { + case PM_DEVICE_ACTION_RESUME: printk("parent resuming..\n"); break; - case PM_DEVICE_STATE_SUSPENDED: + case PM_DEVICE_ACTION_SUSPEND: printk("parent suspending..\n"); break; default: diff --git a/subsys/pm/device.c b/subsys/pm/device.c index d19afbd1f3d..2ca48dc77d6 100644 --- a/subsys/pm/device.c +++ b/subsys/pm/device.c @@ -132,6 +132,7 @@ int pm_device_state_set(const struct device *dev, enum pm_device_state state) { int ret; + enum pm_device_action action; if (dev->pm_control == NULL) { return -ENOSYS; @@ -143,12 +144,16 @@ int pm_device_state_set(const struct device *dev, (dev->pm->state == PM_DEVICE_STATE_SUSPENDING)) { return -EALREADY; } + + action = PM_DEVICE_ACTION_SUSPEND; break; case PM_DEVICE_STATE_ACTIVE: if ((dev->pm->state == PM_DEVICE_STATE_ACTIVE) || (dev->pm->state == PM_DEVICE_STATE_RESUMING)) { return -EALREADY; } + + action = PM_DEVICE_ACTION_RESUME; break; case PM_DEVICE_STATE_FORCE_SUSPEND: __fallthrough; @@ -158,12 +163,14 @@ int pm_device_state_set(const struct device *dev, if (dev->pm->state == state) { return -EALREADY; } + + action = PM_DEVICE_ACTION_TURN_OFF; break; default: return -ENOTSUP; } - ret = dev->pm_control(dev, state); + ret = dev->pm_control(dev, action); if (ret < 0) { return ret; } diff --git a/tests/net/pm/src/main.c b/tests/net/pm/src/main.c index afbdb41559b..d7af22b1f21 100644 --- a/tests/net/pm/src/main.c +++ b/tests/net/pm/src/main.c @@ -22,19 +22,19 @@ struct fake_dev_context { }; static int fake_dev_pm_control(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { struct fake_dev_context *ctx = dev->data; int ret; - switch (state) { - case PM_DEVICE_STATE_SUSPENDED: + switch (action) { + case PM_DEVICE_ACTION_SUSPEND: ret = net_if_suspend(ctx->iface); if (ret == -EBUSY) { goto out; } break; - case PM_DEVICE_STATE_ACTIVE: + case PM_DEVICE_ACTION_RESUME: ret = net_if_resume(ctx->iface); break; default: diff --git a/tests/subsys/pm/device_runtime/src/dummy_driver.c b/tests/subsys/pm/device_runtime/src/dummy_driver.c index 9c597a3096d..17958e78239 100644 --- a/tests/subsys/pm/device_runtime/src/dummy_driver.c +++ b/tests/subsys/pm/device_runtime/src/dummy_driver.c @@ -35,7 +35,7 @@ static int dummy_close_sync(const struct device *dev) } static int dummy_device_pm_ctrl(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { return 0; } diff --git a/tests/subsys/pm/power_mgmt/src/dummy_driver.c b/tests/subsys/pm/power_mgmt/src/dummy_driver.c index 788851975dd..60de4d0f64b 100644 --- a/tests/subsys/pm/power_mgmt/src/dummy_driver.c +++ b/tests/subsys/pm/power_mgmt/src/dummy_driver.c @@ -20,7 +20,7 @@ static int dummy_close(const struct device *dev) } static int dummy_device_pm_ctrl(const struct device *dev, - enum pm_device_state state) + enum pm_device_action action) { return 0; }