pm: cleanup pm control callback implementations

- Return -ENOTSUP if the requested state is not supported
- Remove redundant "noop style" functions.
- Use switch everywhere to handle requested state (not necessary in all
  drivers, but better take off with consistency in place after current
  changes).

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2021-07-05 10:35:15 +02:00 committed by Anas Nashif
commit 495672ab62
33 changed files with 263 additions and 334 deletions

View file

@ -494,27 +494,22 @@ static int st7735r_init(const struct device *dev)
}
#ifdef CONFIG_PM_DEVICE
static int st7735r_enter_sleep(struct st7735r_data *data)
{
return st7735r_transmit(data, ST7735R_CMD_SLEEP_IN, NULL, 0);
}
static int st7735r_pm_control(const struct device *dev,
enum pm_device_state state)
{
int ret = 0;
struct st7735r_data *data = (struct st7735r_data *)dev->data;
if (state == PM_DEVICE_STATE_ACTIVE) {
switch (state) {
case 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;
case PM_DEVICE_STATE_SUSPENDED:
ret = st7735r_transmit(data, ST7735R_CMD_SLEEP_IN, NULL, 0);
break;
default:
ret = -ENOTSUP;
break;
}
return ret;

View file

@ -396,23 +396,25 @@ static int st7789v_init(const struct device *dev)
}
#ifdef CONFIG_PM_DEVICE
static void st7789v_enter_sleep(struct st7789v_data *data)
{
st7789v_transmit(data, ST7789V_CMD_SLEEP_IN, NULL, 0);
}
static int st7789v_pm_control(const struct device *dev,
enum pm_device_state state)
{
struct st7789v_data *data = (struct st7789v_data *)dev->data;
int ret = 0;
if (state == PM_DEVICE_STATE_ACTIVE) {
switch (state) {
case PM_DEVICE_STATE_ACTIVE:
st7789v_exit_sleep(data);
} else {
st7789v_enter_sleep(data);
break;
case PM_DEVICE_STATE_SUSPENDED:
ret = st7789v_transmit(data, ST7789V_CMD_SLEEP_IN, NULL, 0);
break;
default:
ret = -ENOTSUP;
break;
}
return 0;
return ret;
}
#endif /* CONFIG_PM_DEVICE */

View file

@ -264,26 +264,25 @@ static int post_notify_fxn(unsigned int eventType, uintptr_t eventArg,
#endif
#ifdef CONFIG_PM_DEVICE
static int entropy_cc13xx_cc26xx_set_power_state(const struct device *dev,
enum pm_device_state state)
{
struct entropy_cc13xx_cc26xx_data *data = get_dev_data(dev);
if (state == PM_DEVICE_STATE_ACTIVE) {
Power_setDependency(PowerCC26XX_PERIPH_TRNG);
start_trng(data);
} else {
stop_trng(data);
Power_releaseDependency(PowerCC26XX_PERIPH_TRNG);
}
return 0;
}
static int entropy_cc13xx_cc26xx_pm_control(const struct device *dev,
enum pm_device_state state)
{
return entropy_cc13xx_cc26xx_set_power_state(dev, state);
struct entropy_cc13xx_cc26xx_data *data = get_dev_data(dev);
switch (state) {
case PM_DEVICE_STATE_ACTIVE:
Power_setDependency(PowerCC26XX_PERIPH_TRNG);
start_trng(data);
break;
case PM_DEVICE_STATE_SUSPENDED:
stop_trng(data);
Power_releaseDependency(PowerCC26XX_PERIPH_TRNG);
break;
default:
return -ENOTSUP;
}
return 0;
}
#endif /* CONFIG_PM_DEVICE */

View file

@ -197,7 +197,8 @@ static int eth_mcux_device_pm_control(const struct device *dev,
goto out;
}
if (state == PM_DEVICE_STATE_SUSPENDED) {
switch (state) {
case PM_DEVICE_STATE_SUSPENDED:
LOG_DBG("Suspending");
ret = net_if_suspend(eth_ctx->iface);
@ -212,13 +213,18 @@ static int eth_mcux_device_pm_control(const struct device *dev,
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) {
break;
case 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);
break;
default:
ret = -ENOTSUP;
break;
}
out:

View file

@ -637,6 +637,7 @@ static int spi_flash_at45_pm_control(const struct device *dev,
break;
case PM_DEVICE_STATE_SUSPENDED:
__fallthrough;
case PM_DEVICE_STATE_OFF:
acquire(dev);
power_down_op(dev,

View file

@ -425,34 +425,25 @@ static inline int gpio_dw_manage_callback(const struct device *port,
}
#ifdef CONFIG_PM_DEVICE
static inline int gpio_dw_suspend_port(const struct device *port)
{
gpio_dw_clock_off(port);
return 0;
}
static inline int gpio_dw_resume_from_suspend_port(const struct device *port)
{
gpio_dw_clock_on(port);
return 0;
}
/*
* Implements the driver control management functionality
* the *context may include IN data or/and OUT data
*/
static int gpio_dw_device_ctrl(const struct device *port,
static int gpio_dw_device_ctrl(const struct device *dev,
enum pm_device_state state)
{
int ret = 0;
if (state == PM_DEVICE_STATE_SUSPENDED) {
ret = gpio_dw_suspend_port(port);
} else if (state == PM_DEVICE_STATE_ACTIVE) {
ret = gpio_dw_resume_from_suspend_port(port);
switch (state) {
case PM_DEVICE_STATE_SUSPENDED:
gpio_dw_clock_off(dev);
break;
case PM_DEVICE_STATE_ACTIVE:
gpio_dw_clock_on(dev);
break;
default:
return -ENOTSUP;
}
return ret;
return 0;
}
#endif

View file

@ -574,28 +574,19 @@ static const struct gpio_driver_api gpio_stm32_driver = {
};
#ifdef CONFIG_PM_DEVICE
static int gpio_stm32_set_power_state(const struct device *dev,
enum pm_device_state state)
{
int ret = 0;
if (state == PM_DEVICE_STATE_ACTIVE) {
ret = gpio_stm32_clock_request(dev, true);
} else if (state == PM_DEVICE_STATE_SUSPENDED) {
ret = gpio_stm32_clock_request(dev, false);
}
if (ret < 0) {
return ret;
}
return 0;
}
static int gpio_stm32_pm_device_ctrl(const struct device *dev,
enum pm_device_state state)
{
return gpio_stm32_set_power_state(dev, state);
switch (state) {
case PM_DEVICE_STATE_ACTIVE:
return gpio_stm32_clock_request(dev, true);
case PM_DEVICE_STATE_SUSPENDED:
return gpio_stm32_clock_request(dev, false);
default:
return -ENOTSUP;
}
return 0;
}
#endif /* CONFIG_PM_DEVICE */

View file

@ -326,12 +326,13 @@ static int postNotifyFxn(unsigned int eventType, uintptr_t eventArg,
#endif
#ifdef CONFIG_PM_DEVICE
static int i2c_cc13xx_cc26xx_set_power_state(const struct device *dev,
enum pm_device_state state)
static int i2c_cc13xx_cc26xx_pm_control(const struct device *dev,
enum pm_device_state state)
{
int ret = 0;
if (state == PM_DEVICE_STATE_ACTIVE) {
switch (state) {
case PM_DEVICE_STATE_ACTIVE:
Power_setDependency(PowerCC26XX_PERIPH_I2C0);
IOCPinTypeI2c(get_dev_config(dev)->base,
get_dev_config(dev)->sda_pin,
@ -341,7 +342,8 @@ static int i2c_cc13xx_cc26xx_set_power_state(const struct device *dev,
if (ret == 0) {
I2CMasterIntEnable(get_dev_config(dev)->base);
}
} else {
break;
case PM_DEVICE_STATE_SUSPENDED:
I2CMasterIntDisable(get_dev_config(dev)->base);
I2CMasterDisable(get_dev_config(dev)->base);
/* Reset pin type to default GPIO configuration */
@ -350,16 +352,13 @@ static int i2c_cc13xx_cc26xx_set_power_state(const struct device *dev,
IOCPortConfigureSet(get_dev_config(dev)->sda_pin,
IOC_PORT_GPIO, IOC_STD_OUTPUT);
Power_releaseDependency(PowerCC26XX_PERIPH_I2C0);
break;
default:
return -ENOTSUP;
}
return ret;
}
static int i2c_cc13xx_cc26xx_pm_control(const struct device *dev,
enum pm_device_state state)
{
return i2c_cc13xx_cc26xx_set_power_state(dev, state);
}
#endif /* CONFIG_PM_DEVICE */
static int i2c_cc13xx_cc26xx_init(const struct device *dev)

View file

@ -231,6 +231,7 @@ static int twi_nrfx_pm_control(const struct device *dev,
break;
case PM_DEVICE_STATE_SUSPENDED:
__fallthrough;
case PM_DEVICE_STATE_OFF:
nrfx_twi_uninit(&get_dev_config(dev)->twi);
break;

View file

@ -269,6 +269,7 @@ static int twim_nrfx_pm_control(const struct device *dev,
break;
case PM_DEVICE_STATE_SUSPENDED:
__fallthrough;
case PM_DEVICE_STATE_OFF:
nrfx_twim_uninit(&get_dev_config(dev)->twim);
break;

View file

@ -180,10 +180,16 @@ static int arc_v2_irq_unit_device_ctrl(const struct device *dev,
int ret = 0;
unsigned int key = arch_irq_lock();
if (state == PM_DEVICE_STATE_SUSPENDED) {
switch (state) {
case PM_DEVICE_STATE_SUSPENDED:
ret = arc_v2_irq_unit_suspend(dev);
} else if (state == PM_DEVICE_STATE_ACTIVE) {
break;
case PM_DEVICE_STATE_ACTIVE:
ret = arc_v2_irq_unit_resume(dev);
break;
default:
ret = -ENOTSUP;
break;
}
arch_irq_unlock(key);

View file

@ -319,6 +319,7 @@ static int ioapic_device_ctrl(const struct device *dev,
ret = ioapic_resume_from_suspend(dev);
break;
case PM_DEVICE_STATE_SUSPENDED:
__fallthrough;
case PM_DEVICE_STATE_OFF:
ret = ioapic_suspend(dev);
break;
@ -329,7 +330,6 @@ static int ioapic_device_ctrl(const struct device *dev,
return ret;
}
#endif /*CONFIG_PM_DEVICE*/
/**

View file

@ -408,15 +408,20 @@ int loapic_resume(const struct device *port)
* the *context may include IN data or/and OUT data
*/
__pinned_func
static int loapic_device_ctrl(const struct device *port,
static int loapic_device_ctrl(const struct device *dev,
enum pm_device_state state)
{
int ret = 0;
if (state == PM_DEVICE_STATE_SUSPENDED) {
ret = loapic_suspend(port);
} else if (state == PM_DEVICE_STATE_ACTIVE) {
ret = loapic_resume(port);
switch (state) {
case PM_DEVICE_STATE_SUSPENDED:
ret = loapic_suspend(dev);
break;
case PM_DEVICE_STATE_ACTIVE:
ret = loapic_resume(dev);
break;
default:
return -ENOTSUP;
}
return ret;

View file

@ -114,9 +114,8 @@ static int led_pwm_init(const struct device *dev)
}
#ifdef CONFIG_PM_DEVICE
static int led_pwm_pm_set_state(const struct device *dev,
enum pm_device_state new_state)
static int led_pwm_pm_control(const struct device *dev,
enum pm_device_state state)
{
const struct led_pwm_config *config = DEV_CFG(dev);
@ -124,8 +123,8 @@ static int led_pwm_pm_set_state(const struct device *dev,
for (size_t i = 0; i < config->num_leds; i++) {
const struct led_pwm *led_pwm = &config->led[i];
LOG_DBG("Switching PWM %p to state %" PRIu32, led_pwm->dev, new_state);
int err = pm_device_state_set(led_pwm->dev, new_state);
LOG_DBG("Switching PWM %p to state %" PRIu32, led_pwm->dev, state);
int err = pm_device_state_set(led_pwm->dev, state);
if (err) {
LOG_ERR("Cannot switch PWM %p power state", led_pwm->dev);
@ -134,13 +133,6 @@ static int led_pwm_pm_set_state(const struct device *dev,
return 0;
}
static int led_pwm_pm_control(const struct device *dev,
enum pm_device_state state)
{
return led_pwm_pm_set_state(dev, state);
}
#endif /* CONFIG_PM_DEVICE */
static const struct led_driver_api led_pwm_api = {

View file

@ -282,7 +282,6 @@ static int pwm_nrfx_init(const struct device *dev)
}
#ifdef CONFIG_PM_DEVICE
static void pwm_nrfx_uninit(const struct device *dev)
{
const struct pwm_nrfx_config *config = dev->config;
@ -292,8 +291,8 @@ static void pwm_nrfx_uninit(const struct device *dev)
memset(dev->data, 0, sizeof(struct pwm_nrfx_data));
}
static int pwm_nrfx_set_power_state(enum pm_device_state state,
const struct device *dev)
static int pwm_nrfx_pm_control(const struct device *dev,
enum pm_device_state state)
{
int err = 0;
@ -302,32 +301,19 @@ static int pwm_nrfx_set_power_state(enum pm_device_state state,
err = pwm_nrfx_init(dev);
break;
case PM_DEVICE_STATE_SUSPENDED:
__fallthrough;
case PM_DEVICE_STATE_OFF:
pwm_nrfx_uninit(dev);
break;
default:
__ASSERT_NO_MSG(false);
break;
return -ENOTSUP;
}
return err;
}
static int pwm_nrfx_pm_control(const struct device *dev,
enum pm_device_state state)
{
return pwm_nrfx_set_power_state(state, dev);
}
#define PWM_NRFX_PM_CONTROL(idx) \
static int pwm_##idx##_nrfx_pm_control(const struct device *dev, \
enum pm_device_state state) \
{ \
return pwm_nrfx_pm_control(dev, state) \
}
#else
#define PWM_NRFX_PM_CONTROL(idx)
#define pwm_nrfx_pm_control NULL
#endif /* CONFIG_PM_DEVICE */
@ -381,9 +367,8 @@ static int pwm_nrfx_pm_control(const struct device *dev,
.seq.values.p_raw = pwm_nrfx_##idx##_data.current, \
.seq.length = NRF_PWM_CHANNEL_COUNT \
}; \
PWM_NRFX_PM_CONTROL(idx) \
DEVICE_DT_DEFINE(PWM(idx), \
pwm_nrfx_init, pwm_##idx##_nrfx_pm_control, \
pwm_nrfx_init, pwm_nrfx_pm_control, \
&pwm_nrfx_##idx##_data, \
&pwm_nrfx_##idx##config, \
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \

View file

@ -415,26 +415,29 @@ static int apds9960_device_ctrl(const struct device *dev,
struct apds9960_data *data = dev->data;
int ret = 0;
if (state == PM_DEVICE_STATE_ACTIVE) {
switch (state) {
case 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 {
break;
case PM_DEVICE_STATE_SUSPENDED:
if (i2c_reg_update_byte(data->i2c, config->i2c_address,
APDS9960_ENABLE_REG,
APDS9960_ENABLE_PON, 0)) {
APDS9960_ENABLE_REG,
APDS9960_ENABLE_PON, 0)) {
ret = -EIO;
}
if (i2c_reg_write_byte(data->i2c, config->i2c_address,
APDS9960_AICLEAR_REG, 0)) {
APDS9960_AICLEAR_REG, 0)) {
ret = -EIO;
}
break;
default:
return -ENOTSUP;
}
return ret;

View file

@ -414,21 +414,25 @@ int bme280_pm_ctrl(const struct device *dev, enum pm_device_state state)
{
int ret = 0;
/* Switching from OFF to any */
if (state != PM_DEVICE_STATE_OFF) {
switch (state) {
case PM_DEVICE_STATE_ACTIVE:
/* Re-initialize the chip */
ret = bme280_chip_init(dev);
}
/* Switching to OFF from any */
else if (state == PM_DEVICE_STATE_OFF) {
break;
case PM_DEVICE_STATE_SUSPENDED:
__fallthrough;
case PM_DEVICE_STATE_OFF:
/* Put the chip into sleep mode */
ret = bme280_reg_write(dev,
BME280_REG_CTRL_MEAS,
BME280_CTRL_MEAS_OFF_VAL);
if (ret < 0)
if (ret < 0) {
LOG_DBG("CTRL_MEAS write failed: %d", ret);
}
break;
default:
return -ENOTSUP;
}
return ret;

View file

@ -549,18 +549,22 @@ static int bmp388_get_calibration_data(const struct device *dev)
}
#ifdef CONFIG_PM_DEVICE
static int bmp388_set_power_state(const struct device *dev,
enum pm_device_state state)
static int bmp388_device_ctrl(const struct device *dev,
enum pm_device_state state)
{
uint8_t reg_val;
if (state == PM_DEVICE_STATE_ACTIVE) {
switch (state) {
case PM_DEVICE_STATE_ACTIVE:
reg_val = BMP388_PWR_CTRL_MODE_NORMAL;
} else if ((state == PM_DEVICE_STATE_SUSPENDED) ||
(state == PM_DEVICE_STATE_OFF)) {
break;
case PM_DEVICE_STATE_SUSPENDED:
__fallthrough;
case PM_DEVICE_STATE_OFF:
reg_val = BMP388_PWR_CTRL_MODE_SLEEP;
} else {
return 0;
break;
default:
return -ENOTSUP;
}
if (bmp388_reg_field_update(dev,
@ -573,17 +577,6 @@ static int bmp388_set_power_state(const struct device *dev,
return 0;
}
static int bmp388_device_ctrl(
const struct device *dev,
enum pm_device_state state)
{
int ret = 0;
ret = bmp388_set_power_state(dev, state);
return ret;
}
#endif /* CONFIG_PM_DEVICE */
static const struct sensor_driver_api bmp388_api = {

View file

@ -734,22 +734,19 @@ static int bq274xx_exit_shutdown_mode(const struct device *dev)
static int bq274xx_pm_control(const struct device *dev,
enum pm_device_state state)
{
int ret = 0;
int ret;
struct bq274xx_data *data = dev->data;
if (state == PM_DEVICE_STATE_OFF) {
switch (state) {
case 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) {
break;
case 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");
break;
default:
ret = -ENOTSUP;
break;
}
return ret;

View file

@ -481,8 +481,8 @@ static int fdc2x1x_set_shutdown(const struct device *dev, bool enable)
* @param pm_state - power management state
* @return 0 in case of success, negative error code otherwise.
*/
static int fdc2x1x_set_pm_state(const struct device *dev,
enum pm_device_state pm_state)
static int fdc2x1x_device_pm_ctrl(const struct device *dev,
enum pm_device_state state)
{
int ret;
struct fdc2x1x_data *data = dev->data;
@ -491,7 +491,7 @@ static int fdc2x1x_set_pm_state(const struct device *dev,
(void)pm_device_state_get(dev, &curr_state);
switch (pm_state) {
switch (state) {
case PM_DEVICE_STATE_ACTIVE:
if (curr_state == PM_DEVICE_STATE_OFF) {
ret = fdc2x1x_set_shutdown(dev, false);
@ -524,30 +524,11 @@ static int fdc2x1x_set_pm_state(const struct device *dev,
ret = fdc2x1x_set_shutdown(dev, true);
} else {
LOG_ERR("SD pin not defined");
ret = -EINVAL;
ret = -ENOTSUP;
}
break;
default:
return -EINVAL;
}
return ret;
}
static int fdc2x1x_device_pm_ctrl(const struct device *dev,
enum pm_device_state state)
{
struct fdc2x1x_data *data = dev->data;
int ret = 0;
switch (state) {
case PM_DEVICE_STATE_ACTIVE:
case PM_DEVICE_STATE_OFF:
ret = fdc2x1x_set_pm_state(dev, state);
break;
default:
LOG_ERR("PM state not supported");
ret = -EINVAL;
return -ENOTSUP;
}
return ret;

View file

@ -442,14 +442,15 @@ static int lis2mdl_init(const struct device *dev)
}
#ifdef CONFIG_PM_DEVICE
static int lis2mdl_set_power_state(struct lis2mdl_data *lis2mdl,
const struct lis2mdl_config *const config,
enum pm_device_state state)
static int lis2mdl_pm_control(const struct device *dev,
enum pm_device_state state)
{
const struct lis2mdl_config *config = dev->config;
stmdev_ctx_t *ctx = (stmdev_ctx_t *)&config->ctx;
int status = 0;
if (state == PM_DEVICE_STATE_ACTIVE) {
switch (state) {
case PM_DEVICE_STATE_ACTIVE:
if (config->single_mode) {
status = lis2mdl_operating_mode_set(ctx,
LIS2MDL_SINGLE_TRIGGER);
@ -461,25 +462,20 @@ static int lis2mdl_set_power_state(struct lis2mdl_data *lis2mdl,
LOG_ERR("Power up failed");
}
LOG_DBG("State changed to active");
} else {
break;
case PM_DEVICE_STATE_SUSPENDED:
status = lis2mdl_operating_mode_set(ctx, LIS2MDL_POWER_DOWN);
if (status) {
LOG_ERR("Power down failed");
}
LOG_DBG("State changed to inactive");
break;
default:
return -ENOTSUP;
}
return status;
}
static int lis2mdl_pm_control(const struct device *dev,
enum pm_device_state state)
{
struct lis2mdl_data *lis2mdl = dev->data;
const struct lis2mdl_config *const config = dev->config;
return lis2mdl_set_power_state(lis2mdl, config, state);
}
#endif /* CONFIG_PM_DEVICE */
#if DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT) == 0

View file

@ -207,38 +207,29 @@ static int qdec_nrfx_init(const struct device *dev)
}
#ifdef CONFIG_PM_DEVICE
static int qdec_nrfx_pm_set_state(struct qdec_nrfx_data *data,
enum pm_device_state state)
static int qdec_nrfx_pm_control(struct qdec_nrfx_data *data,
enum pm_device_state state)
{
if (state == PM_DEVICE_STATE_ACTIVE) {
switch (state) {
case PM_DEVICE_STATE_ACTIVE:
qdec_nrfx_gpio_ctrl(true);
nrfx_qdec_enable();
} else if (state == PM_DEVICE_STATE_OFF) {
break;
case PM_DEVICE_STATE_OFF:
/* device must be uninitialized */
nrfx_qdec_uninit();
} else {
break;
case PM_DEVICE_STATE_SUSPENDED:
/* device must be suspended */
nrfx_qdec_disable();
qdec_nrfx_gpio_ctrl(false);
break;
default:
return -ENOTSUP;
}
return 0;
}
static int qdec_nrfx_pm_control(const struct device *dev,
enum pm_device_state state)
{
struct qdec_nrfx_data *data = &qdec_nrfx_data;
int err;
LOG_DBG("");
err = qdec_nrfx_pm_set_state(data, state);
return err;
}
#endif /* CONFIG_PM_DEVICE */

View file

@ -186,34 +186,23 @@ static int sgp40_channel_get(const struct device *dev,
#ifdef CONFIG_PM_DEVICE
static int sgp40_set_power_state(const struct device *dev,
enum pm_device_state power_state)
static int sgp40_pm_ctrl(const struct device *dev, enum pm_device_state state)
{
uint16_t cmd;
int rc;
if (power_state == PM_DEVICE_STATE_ACTIVE) {
switch (state) {
case PM_DEVICE_STATE_ACTIVE:
/* activate the hotplate by sending a measure command */
cmd = SGP40_CMD_MEASURE_RAW;
} else if (power_state == PM_DEVICE_STATE_SUSPENDED) {
break;
case PM_DEVICE_STATE_SUSPENDED:
cmd = SGP40_CMD_HEATER_OFF;
} else {
LOG_DBG("Power state not implemented.");
break;
default:
return -ENOTSUP;
}
rc = sgp40_write_command(dev, cmd);
if (rc < 0) {
LOG_ERR("Failed to set power state.");
return rc;
}
return 0;
}
static int sgp40_pm_ctrl(const struct device *dev, enum pm_device_state state)
{
return sgp40_set_power_state(dev, state);
return sgp40_write_command(dev, cmd);
}
#endif /* CONFIG_PM_DEVICE */

View file

@ -234,7 +234,8 @@ static int vcnl4040_device_ctrl(const struct device *dev,
if (ret < 0)
return ret;
#endif
if (state == PM_DEVICE_STATE_ACTIVE) {
switch (state) {
case PM_DEVICE_STATE_ACTIVE:
/* Clear proximity shutdown */
ps_conf &= ~VCNL4040_PS_SD_MASK;
@ -251,7 +252,8 @@ static int vcnl4040_device_ctrl(const struct device *dev,
if (ret < 0)
return ret;
#endif
} else {
break;
case PM_DEVICE_STATE_SUSPENDED:
/* Set proximity shutdown bit 0 */
ps_conf |= VCNL4040_PS_SD_MASK;
@ -268,6 +270,9 @@ static int vcnl4040_device_ctrl(const struct device *dev,
if (ret < 0)
return ret;
#endif
break;
default:
return -ENOTSUP;
}
return ret;

View file

@ -397,12 +397,13 @@ static int postNotifyFxn(unsigned int eventType, uintptr_t eventArg,
#endif
#ifdef CONFIG_PM_DEVICE
static int uart_cc13xx_cc26xx_set_power_state(const struct device *dev,
enum pm_device_state state)
static int uart_cc13xx_cc26xx_pm_control(const struct device *dev,
enum pm_device_state state)
{
int ret = 0;
if (state == PM_DEVICE_STATE_ACTIVE) {
switch (state) {
case PM_DEVICE_STATE_ACTIVE:
if (get_dev_conf(dev)->regs == DT_INST_REG_ADDR(0)) {
Power_setDependency(PowerCC26XX_PERIPH_UART0);
} else {
@ -411,7 +412,8 @@ static int uart_cc13xx_cc26xx_set_power_state(const struct device *dev,
/* Configure and enable UART */
ret = uart_cc13xx_cc26xx_configure(dev,
&get_dev_data(dev)->uart_config);
} else {
break;
case PM_DEVICE_STATE_SUSPENDED:
UARTDisable(get_dev_conf(dev)->regs);
/*
* Release power dependency - i.e. potentially power
@ -423,16 +425,13 @@ static int uart_cc13xx_cc26xx_set_power_state(const struct device *dev,
} else {
Power_releaseDependency(PowerCC26X2_PERIPH_UART1);
}
break;
default:
return -ENOTSUP;
}
return ret;
}
static int uart_cc13xx_cc26xx_pm_control(const struct device *dev,
enum pm_device_state state)
{
return uart_cc13xx_cc26xx_set_power_state(dev, state);
}
#endif /* CONFIG_PM_DEVICE */
static const struct uart_driver_api uart_cc13xx_cc26xx_driver_api = {

View file

@ -438,11 +438,12 @@ static inline bool uart_npcx_device_is_transmitting(const struct device *dev)
return 0;
}
static inline int uart_npcx_set_power_state(const struct device *dev,
enum pm_device_state next_state)
static inline int uart_npcx_pm_control(const struct device *dev,
enum pm_device_state state)
{
/* If next device power state is LOW or SUSPEND power state */
if (next_state == PM_DEVICE_STATE_SUSPENDED) {
/* If next device power state is SUSPEND power state */
switch (state) {
case PM_DEVICE_STATE_SUSPENDED:
/*
* If uart device is busy with transmitting, the driver will
* stay in while loop and wait for the transaction is completed.
@ -450,17 +451,13 @@ static inline int uart_npcx_set_power_state(const struct device *dev,
while (uart_npcx_device_is_transmitting(dev)) {
continue;
}
break;
default:
return -ENOTSUP;
}
return 0;
}
/* Implements the device power management control functionality */
static int uart_npcx_pm_control(const struct device *dev,
enum pm_device_state state)
{
return uart_npcx_set_power_state(dev, state);
}
#endif /* CONFIG_PM_DEVICE */
#ifdef CONFIG_UART_INTERRUPT_DRIVEN

View file

@ -1139,26 +1139,25 @@ static void uart_nrfx_pins_enable(const struct device *dev, bool enable)
}
}
static void uart_nrfx_set_power_state(const struct device *dev,
enum pm_device_state state)
static int uart_nrfx_pm_control(const struct device *dev,
enum pm_device_state state)
{
if (state == PM_DEVICE_STATE_ACTIVE) {
switch (state) {
case PM_DEVICE_STATE_ACTIVE:
uart_nrfx_pins_enable(dev, true);
nrf_uart_enable(uart0_addr);
if (RX_PIN_USED) {
nrf_uart_task_trigger(uart0_addr,
NRF_UART_TASK_STARTRX);
}
} else {
break;
case PM_DEVICE_STATE_SUSPENDED:
nrf_uart_disable(uart0_addr);
uart_nrfx_pins_enable(dev, false);
break;
default:
return -ENOTSUP;
}
}
static int uart_nrfx_pm_control(const struct device *dev,
enum pm_device_state state)
{
uart_nrfx_set_power_state(dev, state);
return 0;
}

View file

@ -1831,15 +1831,16 @@ static void wait_for_tx_stopped(const struct device *dev)
}
static void uarte_nrfx_set_power_state(const struct device *dev,
enum pm_device_state state)
static int uarte_nrfx_pm_control(const struct device *dev,
enum pm_device_state state)
{
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
#if defined(CONFIG_UART_ASYNC_API) || defined(UARTE_INTERRUPT_DRIVEN)
struct uarte_nrfx_data *data = get_dev_data(dev);
#endif
if (state == PM_DEVICE_STATE_ACTIVE) {
switch (state) {
case PM_DEVICE_STATE_ACTIVE:
uarte_nrfx_pins_enable(dev, true);
nrf_uarte_enable(uarte);
@ -1848,7 +1849,7 @@ static void uarte_nrfx_set_power_state(const struct device *dev,
nrfx_timer_enable(&get_dev_config(dev)->timer);
}
if (get_dev_data(dev)->async) {
return;
return 0;
}
#endif
if (nrf_uarte_rx_pin_get(uarte) != NRF_UARTE_PSEL_DISCONNECTED) {
@ -1863,7 +1864,8 @@ static void uarte_nrfx_set_power_state(const struct device *dev,
}
#endif
}
} else {
break;
case PM_DEVICE_STATE_SUSPENDED:
/* Disabling UART requires stopping RX, but stop RX event is
* only sent after each RX if async UART API is used.
*/
@ -1904,13 +1906,10 @@ static void uarte_nrfx_set_power_state(const struct device *dev,
wait_for_tx_stopped(dev);
uart_disable(dev);
uarte_nrfx_pins_enable(dev, false);
break;
default:
return -ENOTSUP;
}
}
static int uarte_nrfx_pm_control(const struct device *dev,
enum pm_device_state state)
{
uarte_nrfx_set_power_state(dev, state);
return 0;
}

View file

@ -1422,13 +1422,14 @@ static int uart_stm32_init(const struct device *dev)
}
#ifdef CONFIG_PM_DEVICE
static int uart_stm32_set_power_state(const struct device *dev,
enum pm_device_state state)
static int uart_stm32_pm_control(const struct device *dev,
enum pm_device_state state)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
/* setting a low power mode */
if (state != PM_DEVICE_STATE_ACTIVE) {
switch (state) {
case PM_DEVICE_STATE_SUSPENDED:
#ifdef USART_ISR_BUSY
/* Make sure that no USART transfer is on-going */
while (LL_USART_IsActiveFlag_BUSY(UartInstance) == 1) {
@ -1444,28 +1445,14 @@ static int uart_stm32_set_power_state(const struct device *dev,
/* Clear OVERRUN flag */
LL_USART_ClearFlag_ORE(UartInstance);
/* Leave UartInstance unchanged */
break;
default:
return -ENOTSUP;
}
/* UartInstance returning to active mode has nothing special to do */
return 0;
}
/**
* @brief disable the UART channel
*
* This routine is called to put the device in low power mode.
*
* @param dev UART device struct
*
* @return 0
*/
static int uart_stm32_pm_control(const struct device *dev,
enum pm_device_state state)
{
uart_stm32_set_power_state(dev, state);
return 0;
}
#endif /* CONFIG_PM_DEVICE */
#ifdef CONFIG_UART_ASYNC_API

View file

@ -208,16 +208,18 @@ static int spi_cc13xx_cc26xx_release(const struct device *dev,
}
#ifdef CONFIG_PM_DEVICE
static int spi_cc13xx_cc26xx_set_power_state(const struct device *dev,
enum pm_device_state state)
static int spi_cc13xx_cc26xx_pm_control(const struct device *dev,
enum pm_device_state state)
{
if (state == PM_DEVICE_STATE_ACTIVE) {
switch (state) {
case PM_DEVICE_STATE_ACTIVE:
if (get_dev_config(dev)->base == DT_INST_REG_ADDR(0)) {
Power_setDependency(PowerCC26XX_PERIPH_SSI0);
} else {
Power_setDependency(PowerCC26XX_PERIPH_SSI1);
}
} else {
break;
case PM_DEVICE_STATE_SUSPENDED:
SSIDisable(get_dev_config(dev)->base);
/*
* Release power dependency
@ -227,16 +229,13 @@ static int spi_cc13xx_cc26xx_set_power_state(const struct device *dev,
} else {
Power_releaseDependency(PowerCC26XX_PERIPH_SSI1);
}
break;
default:
return -ENOTSUP;
}
return 0;
}
static int spi_cc13xx_cc26xx_pm_control(const struct device *dev,
enum pm_device_state state)
{
return spi_cc13xx_cc26xx_set_power_state(dev, state);
}
#endif /* CONFIG_PM_DEVICE */

View file

@ -89,10 +89,15 @@ static int dummy_close(const struct device *dev)
static int dummy_device_pm_ctrl(const struct device *dev,
enum pm_device_state state)
{
if (state == PM_DEVICE_STATE_ACTIVE) {
switch (state) {
case PM_DEVICE_STATE_ACTIVE:
printk("child resuming..\n");
} else {
break;
case PM_DEVICE_STATE_SUSPENDED:
printk("child suspending..\n");
break;
default:
return -ENOTSUP;
}
return 0;

View file

@ -27,10 +27,15 @@ 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)
{
if (state == PM_DEVICE_STATE_ACTIVE) {
switch (state) {
case PM_DEVICE_STATE_ACTIVE:
printk("parent resuming..\n");
} else {
break;
case PM_DEVICE_STATE_SUSPENDED:
printk("parent suspending..\n");
break;
default:
return -ENOTSUP;
}
return 0;

View file

@ -25,15 +25,21 @@ static int fake_dev_pm_control(const struct device *dev,
enum pm_device_state state)
{
struct fake_dev_context *ctx = dev->data;
int ret = 0;
int ret;
if (state == PM_DEVICE_STATE_SUSPENDED) {
switch (state) {
case PM_DEVICE_STATE_SUSPENDED:
ret = net_if_suspend(ctx->iface);
if (ret == -EBUSY) {
goto out;
}
} else if (state == PM_DEVICE_STATE_ACTIVE) {
break;
case PM_DEVICE_STATE_ACTIVE:
ret = net_if_resume(ctx->iface);
break;
default:
ret = -ENOTSUP;
break;
}
out: