pm: use actions for device PM control
Instead of passing target states, use actions for device PM control. Actions represent better the meaning of the callback argument. Furthermore, they are more future proof as they can be suitable for other PM actions that have no direct mapping to a state. If we compare with Linux, we could have a multi-stage suspend/resume. Such scenario would not have a good mapping when using target states. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
8be0472ba8
commit
7ccc1a41bc
40 changed files with 176 additions and 145 deletions
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue