Skip to content

Commit

Permalink
pm: device: Align state names with system states
Browse files Browse the repository at this point in the history
Change device pm states to the same pattern used by system power
management.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
  • Loading branch information
Flavio Ceolin authored and nashif committed May 7, 2021
1 parent 86a8ab5 commit 0c607ad
Show file tree
Hide file tree
Showing 51 changed files with 258 additions and 258 deletions.
8 changes: 4 additions & 4 deletions doc/reference/power_management/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -215,20 +215,20 @@ registers, clocks, memory etc.

The four device power states:

:code:`PM_DEVICE_ACTIVE_STATE`
:code:`PM_DEVICE_STATE_ACTIVE`

Normal operation of the device. All device context is retained.

:code:`PM_DEVICE_LOW_POWER_STATE`
:code:`PM_DEVICE_STATE_LOW_POWER`

Device context is preserved by the HW and need not be restored by the driver.

:code:`PM_DEVICE_SUSPEND_STATE`
:code:`PM_DEVICE_STATE_SUSPEND`

Most device context is lost by the hardware. Device drivers must save and
restore or reinitialize any context lost by the hardware.

:code:`PM_DEVICE_OFF_STATE`
:code:`PM_DEVICE_STATE_OFF`

Power has been fully removed from the device. The device context is lost
when this state is entered. Need to reinitialize the device when powering
Expand Down
8 changes: 4 additions & 4 deletions drivers/display/display_st7735r.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ static int st7735r_init(const struct device *dev)
}

#ifdef CONFIG_DEVICE_POWER_MANAGEMENT
data->pm_state = PM_DEVICE_ACTIVE_STATE;
data->pm_state = PM_DEVICE_STATE_ACTIVE;
#endif

data->cmd_data_dev = device_get_binding(config->cmd_data.name);
Expand Down Expand Up @@ -527,18 +527,18 @@ static int st7735r_pm_control(const struct device *dev, uint32_t ctrl_command,

switch (ctrl_command) {
case PM_DEVICE_STATE_SET:
if (*((uint32_t *)context) == PM_DEVICE_ACTIVE_STATE) {
if (*((uint32_t *)context) == PM_DEVICE_STATE_ACTIVE) {
ret = st7735r_exit_sleep(data);
if (ret < 0) {
return ret;
}
data->pm_state = PM_DEVICE_ACTIVE_STATE;
data->pm_state = PM_DEVICE_STATE_ACTIVE;
} else {
ret = st7735r_enter_sleep(data);
if (ret < 0) {
return ret;
}
data->pm_state = PM_DEVICE_LOW_POWER_STATE;
data->pm_state = PM_DEVICE_STATE_LOW_POWER;
}

break;
Expand Down
8 changes: 4 additions & 4 deletions drivers/display/display_st7789v.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ static int st7789v_init(const struct device *dev)
#endif

#ifdef CONFIG_PM_DEVICE
data->pm_state = PM_DEVICE_ACTIVE_STATE;
data->pm_state = PM_DEVICE_STATE_ACTIVE;
#endif

data->cmd_data_gpio = device_get_binding(
Expand Down Expand Up @@ -416,13 +416,13 @@ static int st7789v_pm_control(const struct device *dev, uint32_t ctrl_command,

switch (ctrl_command) {
case DEVICE_PM_SET_POWER_STATE:
if (*state == PM_DEVICE_ACTIVE_STATE) {
if (*state == PM_DEVICE_STATE_ACTIVE) {
st7789v_exit_sleep(data);
data->pm_state = PM_DEVICE_ACTIVE_STATE;
data->pm_state = PM_DEVICE_STATE_ACTIVE;
ret = 0;
} else {
st7789v_enter_sleep(data);
data->pm_state = PM_DEVICE_LOW_POWER_STATE;
data->pm_state = PM_DEVICE_STATE_LOW_POWER;
ret = 0;
}
break;
Expand Down
12 changes: 6 additions & 6 deletions drivers/entropy/entropy_cc13xx_cc26xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,16 @@ static int entropy_cc13xx_cc26xx_set_power_state(const struct device *dev,
struct entropy_cc13xx_cc26xx_data *data = get_dev_data(dev);
int ret = 0;

if ((new_state == PM_DEVICE_ACTIVE_STATE) &&
if ((new_state == PM_DEVICE_STATE_ACTIVE) &&
(new_state != data->pm_state)) {
Power_setDependency(PowerCC26XX_PERIPH_TRNG);
start_trng(data);
} else {
__ASSERT_NO_MSG(new_state == PM_DEVICE_LOW_POWER_STATE ||
new_state == PM_DEVICE_SUSPEND_STATE ||
new_state == PM_DEVICE_OFF_STATE);
__ASSERT_NO_MSG(new_state == PM_DEVICE_STATE_LOW_POWER ||
new_state == PM_DEVICE_STATE_SUSPEND ||
new_state == PM_DEVICE_STATE_OFF);

if (data->pm_state == PM_DEVICE_ACTIVE_STATE) {
if (data->pm_state == PM_DEVICE_STATE_ACTIVE) {
stop_trng(data);
Power_releaseDependency(PowerCC26XX_PERIPH_TRNG);
}
Expand Down Expand Up @@ -324,7 +324,7 @@ static int entropy_cc13xx_cc26xx_init(const struct device *dev)
struct entropy_cc13xx_cc26xx_data *data = get_dev_data(dev);

#ifdef CONFIG_PM_DEVICE
get_dev_data(dev)->pm_state = PM_DEVICE_ACTIVE_STATE;
get_dev_data(dev)->pm_state = PM_DEVICE_STATE_ACTIVE;
#endif

/* Initialize driver data */
Expand Down
4 changes: 2 additions & 2 deletions drivers/ethernet/eth_mcux.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ static int eth_mcux_device_pm_control(const struct device *dev,
}

if (command == PM_DEVICE_STATE_SET) {
if (*state == PM_DEVICE_SUSPEND_STATE) {
if (*state == PM_DEVICE_STATE_SUSPEND) {
LOG_DBG("Suspending");

ret = net_if_suspend(eth_ctx->iface);
Expand All @@ -215,7 +215,7 @@ 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_ACTIVE_STATE) {
} else if (*state == PM_DEVICE_STATE_ACTIVE) {
LOG_DBG("Resuming");

clock_control_on(eth_ctx->clock_dev,
Expand Down
10 changes: 5 additions & 5 deletions drivers/flash/spi_flash_at45.c
Original file line number Diff line number Diff line change
Expand Up @@ -641,16 +641,16 @@ static int spi_flash_at45_pm_control(const struct device *dev,

if (new_state != dev_data->pm_state) {
switch (new_state) {
case PM_DEVICE_ACTIVE_STATE:
case PM_DEVICE_STATE_ACTIVE:
acquire(dev);
power_down_op(dev, CMD_EXIT_DPD,
dev_config->t_exit_dpd);
release(dev);
break;

case PM_DEVICE_LOW_POWER_STATE:
case PM_DEVICE_SUSPEND_STATE:
case PM_DEVICE_OFF_STATE:
case PM_DEVICE_STATE_LOW_POWER:
case PM_DEVICE_STATE_SUSPEND:
case PM_DEVICE_STATE_OFF:
acquire(dev);
power_down_op(dev,
dev_config->use_udpd ? CMD_ENTER_UDPD
Expand Down Expand Up @@ -721,7 +721,7 @@ static const struct flash_driver_api spi_flash_at45_api = {
static struct spi_flash_at45_data inst_##idx##_data = { \
.lock = Z_SEM_INITIALIZER(inst_##idx##_data.lock, 1, 1), \
IF_ENABLED(CONFIG_PM_DEVICE, ( \
.pm_state = PM_DEVICE_ACTIVE_STATE)) \
.pm_state = PM_DEVICE_STATE_ACTIVE)) \
}; \
INST_RESET_GPIO_SPEC(idx) \
INST_WP_GPIO_SPEC(idx) \
Expand Down
6 changes: 3 additions & 3 deletions drivers/flash/spi_nor.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ LOG_MODULE_REGISTER(spi_nor, CONFIG_FLASH_LOG_LEVEL);
* Kconfig option.
*
* When mapped to the Zephyr Device Power Management states:
* * PM_DEVICE_ACTIVE_STATE covers both active and standby modes;
* * PM_DEVICE_LOW_POWER_STATE, PM_DEVICE_SUSPEND_STATE, and
* PM_DEVICE_OFF_STATE all correspond to deep-power-down mode.
* * PM_DEVICE_STATE_ACTIVE covers both active and standby modes;
* * PM_DEVICE_STATE_LOW_POWER, PM_DEVICE_STATE_SUSPEND, and
* PM_DEVICE_STATE_OFF all correspond to deep-power-down mode.
*/

#define SPI_NOR_MAX_ADDR_WIDTH 4
Expand Down
10 changes: 5 additions & 5 deletions drivers/gpio/gpio_dw.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,15 +443,15 @@ static uint32_t gpio_dw_get_power_state(const struct device *port)
static inline int gpio_dw_suspend_port(const struct device *port)
{
gpio_dw_clock_off(port);
gpio_dw_set_power_state(port, PM_DEVICE_SUSPEND_STATE);
gpio_dw_set_power_state(port, PM_DEVICE_STATE_SUSPEND);

return 0;
}

static inline int gpio_dw_resume_from_suspend_port(const struct device *port)
{
gpio_dw_clock_on(port);
gpio_dw_set_power_state(port, PM_DEVICE_ACTIVE_STATE);
gpio_dw_set_power_state(port, PM_DEVICE_STATE_ACTIVE);
return 0;
}

Expand All @@ -466,9 +466,9 @@ static int gpio_dw_device_ctrl(const struct device *port,
int ret = 0;

if (ctrl_command == PM_DEVICE_STATE_SET) {
if (*((uint32_t *)context) == PM_DEVICE_SUSPEND_STATE) {
if (*((uint32_t *)context) == PM_DEVICE_STATE_SUSPEND) {
ret = gpio_dw_suspend_port(port);
} else if (*((uint32_t *)context) == PM_DEVICE_ACTIVE_STATE) {
} else if (*((uint32_t *)context) == PM_DEVICE_STATE_ACTIVE) {
ret = gpio_dw_resume_from_suspend_port(port);
}
} else if (ctrl_command == PM_DEVICE_STATE_GET) {
Expand Down Expand Up @@ -544,7 +544,7 @@ static int gpio_dw_initialize(const struct device *port)
config->config_func(port);
}

gpio_dw_set_power_state(port, PM_DEVICE_ACTIVE_STATE);
gpio_dw_set_power_state(port, PM_DEVICE_STATE_ACTIVE);

return 0;
}
Expand Down
12 changes: 6 additions & 6 deletions drivers/gpio/gpio_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ static int gpio_stm32_config(const struct device *dev,

#ifdef CONFIG_PM_DEVICE_RUNTIME
/* Enable device clock before configuration (requires bank writes) */
if (data->power_state != PM_DEVICE_ACTIVE_STATE) {
if (data->power_state != PM_DEVICE_STATE_ACTIVE) {
err = pm_device_get_sync(dev);
if (err < 0) {
return err;
Expand Down Expand Up @@ -586,11 +586,11 @@ static int gpio_stm32_set_power_state(const struct device *dev,
struct gpio_stm32_data *data = dev->data;
int ret = 0;

if (new_state == PM_DEVICE_ACTIVE_STATE) {
if (new_state == PM_DEVICE_STATE_ACTIVE) {
ret = gpio_stm32_clock_request(dev, true);
} else if (new_state == PM_DEVICE_SUSPEND_STATE) {
} else if (new_state == PM_DEVICE_STATE_SUSPEND) {
ret = gpio_stm32_clock_request(dev, false);
} else if (new_state == PM_DEVICE_LOW_POWER_STATE) {
} else if (new_state == PM_DEVICE_STATE_LOW_POWER) {
ret = gpio_stm32_clock_request(dev, false);
}

Expand Down Expand Up @@ -660,13 +660,13 @@ static int gpio_stm32_init(const struct device *dev)
#endif

#ifdef CONFIG_PM_DEVICE_RUNTIME
data->power_state = PM_DEVICE_OFF_STATE;
data->power_state = PM_DEVICE_STATE_OFF;
pm_device_enable(dev);

return 0;
#else
#ifdef CONFIG_PM_DEVICE
data->power_state = PM_DEVICE_ACTIVE_STATE;
data->power_state = PM_DEVICE_STATE_ACTIVE;
#endif
return gpio_stm32_clock_request(dev, true);
#endif
Expand Down
12 changes: 6 additions & 6 deletions drivers/i2c/i2c_cc13xx_cc26xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ static int i2c_cc13xx_cc26xx_set_power_state(const struct device *dev,
{
int ret = 0;

if ((new_state == PM_DEVICE_ACTIVE_STATE) &&
if ((new_state == PM_DEVICE_STATE_ACTIVE) &&
(new_state != get_dev_data(dev)->pm_state)) {
Power_setDependency(PowerCC26XX_PERIPH_I2C0);
IOCPinTypeI2c(get_dev_config(dev)->base,
Expand All @@ -346,11 +346,11 @@ static int i2c_cc13xx_cc26xx_set_power_state(const struct device *dev,
get_dev_data(dev)->pm_state = new_state;
}
} else {
__ASSERT_NO_MSG(new_state == PM_DEVICE_LOW_POWER_STATE ||
new_state == PM_DEVICE_SUSPEND_STATE ||
new_state == PM_DEVICE_OFF_STATE);
__ASSERT_NO_MSG(new_state == PM_DEVICE_STATE_LOW_POWER ||
new_state == PM_DEVICE_STATE_SUSPEND ||
new_state == PM_DEVICE_STATE_OFF);

if (get_dev_data(dev)->pm_state == PM_DEVICE_ACTIVE_STATE) {
if (get_dev_data(dev)->pm_state == PM_DEVICE_STATE_ACTIVE) {
I2CMasterIntDisable(get_dev_config(dev)->base);
I2CMasterDisable(get_dev_config(dev)->base);
/* Reset pin type to default GPIO configuration */
Expand Down Expand Up @@ -399,7 +399,7 @@ static int i2c_cc13xx_cc26xx_init(const struct device *dev)
int err;

#ifdef CONFIG_PM_DEVICE
get_dev_data(dev)->pm_state = PM_DEVICE_ACTIVE_STATE;
get_dev_data(dev)->pm_state = PM_DEVICE_STATE_ACTIVE;
#endif

#ifdef CONFIG_PM
Expand Down
12 changes: 6 additions & 6 deletions drivers/i2c/i2c_nrfx_twi.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ static int init_twi(const struct device *dev)
return -EBUSY;
}
#ifdef CONFIG_PM_DEVICE
get_dev_data(dev)->pm_state = PM_DEVICE_ACTIVE_STATE;
get_dev_data(dev)->pm_state = PM_DEVICE_STATE_ACTIVE;
#endif

return 0;
Expand All @@ -234,7 +234,7 @@ static int twi_nrfx_pm_control(const struct device *dev,

if (new_state != pm_current_state) {
switch (new_state) {
case PM_DEVICE_ACTIVE_STATE:
case PM_DEVICE_STATE_ACTIVE:
init_twi(dev);
if (get_dev_data(dev)->dev_config) {
i2c_nrfx_twi_configure(
Expand All @@ -243,10 +243,10 @@ static int twi_nrfx_pm_control(const struct device *dev,
}
break;

case PM_DEVICE_LOW_POWER_STATE:
case PM_DEVICE_SUSPEND_STATE:
case PM_DEVICE_OFF_STATE:
if (pm_current_state == PM_DEVICE_ACTIVE_STATE) {
case PM_DEVICE_STATE_LOW_POWER:
case PM_DEVICE_STATE_SUSPEND:
case PM_DEVICE_STATE_OFF:
if (pm_current_state == PM_DEVICE_STATE_ACTIVE) {
nrfx_twi_uninit(&get_dev_config(dev)->twi);
}
break;
Expand Down
12 changes: 6 additions & 6 deletions drivers/i2c/i2c_nrfx_twim.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ static int init_twim(const struct device *dev)
}

#ifdef CONFIG_PM_DEVICE
get_dev_data(dev)->pm_state = PM_DEVICE_ACTIVE_STATE;
get_dev_data(dev)->pm_state = PM_DEVICE_STATE_ACTIVE;
#endif

return 0;
Expand All @@ -273,7 +273,7 @@ static int twim_nrfx_pm_control(const struct device *dev,

if (new_state != pm_current_state) {
switch (new_state) {
case PM_DEVICE_ACTIVE_STATE:
case PM_DEVICE_STATE_ACTIVE:
init_twim(dev);
if (get_dev_data(dev)->dev_config) {
i2c_nrfx_twim_configure(
Expand All @@ -282,10 +282,10 @@ static int twim_nrfx_pm_control(const struct device *dev,
}
break;

case PM_DEVICE_LOW_POWER_STATE:
case PM_DEVICE_SUSPEND_STATE:
case PM_DEVICE_OFF_STATE:
if (pm_current_state != PM_DEVICE_ACTIVE_STATE) {
case PM_DEVICE_STATE_LOW_POWER:
case PM_DEVICE_STATE_SUSPEND:
case PM_DEVICE_STATE_OFF:
if (pm_current_state != PM_DEVICE_STATE_ACTIVE) {
break;
}
nrfx_twim_uninit(&get_dev_config(dev)->twim);
Expand Down
10 changes: 5 additions & 5 deletions drivers/interrupt_controller/intc_arcv2_irq_unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extern void *_VectorTable;
#define _ARC_V2_IRQ_VECT_BASE _ARC_V2_IRQ_VECT_BASE_S
#endif

static uint32_t _arc_v2_irq_unit_device_power_state = PM_DEVICE_ACTIVE_STATE;
static uint32_t _arc_v2_irq_unit_device_power_state = PM_DEVICE_STATE_ACTIVE;
struct arc_v2_irq_unit_ctx {
uint32_t irq_ctrl; /* Interrupt Context Saving Control Register. */
uint32_t irq_vect_base; /* Interrupt Vector Base. */
Expand Down Expand Up @@ -120,7 +120,7 @@ static int arc_v2_irq_unit_suspend(const struct device *dev)
ctx.irq_ctrl = z_arc_v2_aux_reg_read(_ARC_V2_AUX_IRQ_CTRL);
ctx.irq_vect_base = z_arc_v2_aux_reg_read(_ARC_V2_IRQ_VECT_BASE);

_arc_v2_irq_unit_device_power_state = PM_DEVICE_SUSPEND_STATE;
_arc_v2_irq_unit_device_power_state = PM_DEVICE_STATE_SUSPEND;

return 0;
}
Expand Down Expand Up @@ -166,7 +166,7 @@ static int arc_v2_irq_unit_resume(const struct device *dev)
#endif
z_arc_v2_aux_reg_write(_ARC_V2_IRQ_VECT_BASE, ctx.irq_vect_base);

_arc_v2_irq_unit_device_power_state = PM_DEVICE_ACTIVE_STATE;
_arc_v2_irq_unit_device_power_state = PM_DEVICE_STATE_ACTIVE;

return 0;
}
Expand Down Expand Up @@ -199,9 +199,9 @@ static int arc_v2_irq_unit_device_ctrl(const struct device *dev,
unsigned int key = arch_irq_lock();

if (ctrl_command == PM_DEVICE_STATE_SET) {
if (*((uint32_t *)context) == PM_DEVICE_SUSPEND_STATE) {
if (*((uint32_t *)context) == PM_DEVICE_STATE_SUSPEND) {
ret = arc_v2_irq_unit_suspend(dev);
} else if (*((uint32_t *)context) == PM_DEVICE_ACTIVE_STATE) {
} else if (*((uint32_t *)context) == PM_DEVICE_STATE_ACTIVE) {
ret = arc_v2_irq_unit_resume(dev);
}
} else if (ctrl_command == PM_DEVICE_STATE_GET) {
Expand Down
Loading

0 comments on commit 0c607ad

Please sign in to comment.