pm: Use pm_device_action_run instead of state_set
Since drivers implement a callback based on action and not the state, we should be using the API based on the action instead of the one based on the state. Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
This commit is contained in:
parent
80d26d996e
commit
6451626ce7
|
@ -122,25 +122,12 @@ static int led_pwm_pm_action(const struct device *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("PWM %p running pm action %" PRIu32, led_pwm->dev,
|
||||
action);
|
||||
|
||||
/* 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);
|
||||
err = pm_device_action_run(led_pwm->dev, action);
|
||||
if (err && (err != -EALREADY)) {
|
||||
LOG_ERR("Cannot switch PWM %p power state", led_pwm->dev);
|
||||
}
|
||||
|
|
|
@ -4364,8 +4364,8 @@ static void shutdown_uart(void)
|
|||
if (ictx.uart_on) {
|
||||
HL7800_IO_DBG_LOG("Power OFF the UART");
|
||||
uart_irq_rx_disable(ictx.mdm_ctx.uart_dev);
|
||||
rc = pm_device_state_set(ictx.mdm_ctx.uart_dev,
|
||||
PM_DEVICE_STATE_SUSPENDED);
|
||||
rc = pm_device_action_run(ictx.mdm_ctx.uart_dev,
|
||||
PM_DEVICE_ACTION_SUSPEND);
|
||||
if (rc) {
|
||||
LOG_ERR("Error disabling UART peripheral (%d)", rc);
|
||||
}
|
||||
|
@ -4381,8 +4381,8 @@ static void power_on_uart(void)
|
|||
|
||||
if (!ictx.uart_on) {
|
||||
HL7800_IO_DBG_LOG("Power ON the UART");
|
||||
rc = pm_device_state_set(ictx.mdm_ctx.uart_dev,
|
||||
PM_DEVICE_STATE_ACTIVE);
|
||||
rc = pm_device_action_run(ictx.mdm_ctx.uart_dev,
|
||||
PM_DEVICE_ACTION_RESUME);
|
||||
if (rc) {
|
||||
LOG_ERR("Error enabling UART peripheral (%d)", rc);
|
||||
}
|
||||
|
|
|
@ -199,7 +199,7 @@ int mdm_receiver_sleep(struct mdm_receiver_context *ctx)
|
|||
{
|
||||
uart_irq_rx_disable(ctx->uart_dev);
|
||||
#ifdef CONFIG_PM_DEVICE
|
||||
pm_device_state_set(ctx->uart_dev, PM_DEVICE_STATE_SUSPENDED);
|
||||
pm_device_action_run(ctx->uart_dev, PM_DEVICE_ACTION_SUSPEND);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ int mdm_receiver_sleep(struct mdm_receiver_context *ctx)
|
|||
int mdm_receiver_wake(struct mdm_receiver_context *ctx)
|
||||
{
|
||||
#ifdef CONFIG_PM_DEVICE
|
||||
pm_device_state_set(ctx->uart_dev, PM_DEVICE_STATE_ACTIVE);
|
||||
pm_device_action_run(ctx->uart_dev, PM_DEVICE_ACTION_SUSPEND);
|
||||
#endif
|
||||
uart_irq_rx_enable(ctx->uart_dev);
|
||||
|
||||
|
|
|
@ -66,17 +66,17 @@ void main(void)
|
|||
k_busy_wait(BUSY_WAIT_S * USEC_PER_SEC);
|
||||
|
||||
printk("Busy-wait %u s with UART off\n", BUSY_WAIT_S);
|
||||
rc = pm_device_state_set(cons, PM_DEVICE_STATE_SUSPENDED);
|
||||
rc = pm_device_action_run(cons, PM_DEVICE_ACTION_SUSPEND);
|
||||
k_busy_wait(BUSY_WAIT_S * USEC_PER_SEC);
|
||||
rc = pm_device_state_set(cons, PM_DEVICE_STATE_ACTIVE);
|
||||
rc = pm_device_action_run(cons, PM_DEVICE_ACTION_RESUME);
|
||||
|
||||
printk("Sleep %u s\n", SLEEP_S);
|
||||
k_sleep(K_SECONDS(SLEEP_S));
|
||||
|
||||
printk("Sleep %u s with UART off\n", SLEEP_S);
|
||||
rc = pm_device_state_set(cons, PM_DEVICE_STATE_SUSPENDED);
|
||||
rc = pm_device_action_run(cons, PM_DEVICE_ACTION_SUSPEND);
|
||||
k_sleep(K_SECONDS(SLEEP_S));
|
||||
rc = pm_device_state_set(cons, PM_DEVICE_STATE_ACTIVE);
|
||||
rc = pm_device_action_run(cons, PM_DEVICE_ACTION_RESUME);
|
||||
|
||||
printk("Entering system off; press BUTTON1 to restart\n");
|
||||
|
||||
|
|
|
@ -151,7 +151,7 @@ void main(void)
|
|||
|
||||
#if IS_ENABLED(CONFIG_PM_DEVICE)
|
||||
printk("Putting the flash device into suspended state... ");
|
||||
err = pm_device_state_set(flash_dev, PM_DEVICE_STATE_SUSPENDED);
|
||||
err = pm_device_action_run(flash_dev, PM_DEVICE_ACTION_SUSPEND);
|
||||
if (err != 0) {
|
||||
printk("FAILED\n");
|
||||
return;
|
||||
|
|
|
@ -77,14 +77,10 @@ void main(void)
|
|||
intensity.val1, pdata.val1);
|
||||
|
||||
#ifdef CONFIG_PM_DEVICE
|
||||
enum pm_device_state p_state;
|
||||
|
||||
p_state = PM_DEVICE_STATE_SUSPENDED;
|
||||
pm_device_state_set(dev, p_state);
|
||||
pm_device_action_run(dev, PM_DEVICE_ACTION_SUSPEND);
|
||||
printk("set low power state for 2s\n");
|
||||
k_sleep(K_MSEC(2000));
|
||||
p_state = PM_DEVICE_STATE_ACTIVE;
|
||||
pm_device_state_set(dev, p_state);
|
||||
pm_device_action_run(dev, PM_DEVICE_ACTION_RESUME);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,16 +34,16 @@ static void trigger_handler(const struct device *dev,
|
|||
#endif
|
||||
|
||||
#ifdef CONFIG_PM_DEVICE
|
||||
static void pm_info(enum pm_device_state state, int status)
|
||||
static void pm_info(enum pm_device_action action, int status)
|
||||
{
|
||||
switch (state) {
|
||||
case PM_DEVICE_STATE_ACTIVE:
|
||||
switch (action) {
|
||||
case PM_DEVICE_ACTION_RESUME:
|
||||
printk("Enter ACTIVE_STATE ");
|
||||
break;
|
||||
case PM_DEVICE_STATE_SUSPENDED:
|
||||
case PM_DEVICE_ACTION_SUSPEND:
|
||||
printk("Enter SUSPEND_STATE ");
|
||||
break;
|
||||
case PM_DEVICE_STATE_OFF:
|
||||
case PM_DEVICE_ACTION_TURN_OFF:
|
||||
printk("Enter OFF_STATE ");
|
||||
break;
|
||||
default:
|
||||
|
@ -91,20 +91,20 @@ void main(void)
|
|||
|
||||
#ifdef CONFIG_PM_DEVICE
|
||||
/* Testing the power modes */
|
||||
enum pm_device_state p_state;
|
||||
enum pm_device_action p_action;
|
||||
int ret;
|
||||
|
||||
p_state = PM_DEVICE_STATE_SUSPENDED;
|
||||
ret = pm_device_state_set(dev, p_state);
|
||||
pm_info(p_state, ret);
|
||||
p_action = PM_DEVICE_ACTION_SUSPEND;
|
||||
ret = pm_device_action_run(dev, p_action);
|
||||
pm_info(p_action, ret);
|
||||
|
||||
p_state = PM_DEVICE_STATE_OFF;
|
||||
ret = pm_device_state_set(dev, p_state);
|
||||
pm_info(p_state, ret);
|
||||
p_action = PM_DEVICE_ACTION_TURN_OFF;
|
||||
ret = pm_device_action_run(dev, p_action);
|
||||
pm_info(p_action, ret);
|
||||
|
||||
p_state = PM_DEVICE_STATE_ACTIVE;
|
||||
ret = pm_device_state_set(dev, p_state);
|
||||
pm_info(p_state, ret);
|
||||
p_action = PM_DEVICE_ACTION_RESUME;
|
||||
ret = pm_device_action_run(dev, p_action);
|
||||
pm_info(p_action, ret);
|
||||
#endif
|
||||
|
||||
while (1) {
|
||||
|
@ -132,13 +132,13 @@ void main(void)
|
|||
|
||||
|
||||
#ifdef CONFIG_PM_DEVICE
|
||||
p_state = PM_DEVICE_STATE_OFF;
|
||||
ret = pm_device_state_set(dev, p_state);
|
||||
pm_info(p_state, ret);
|
||||
p_action = PM_DEVICE_ACTION_TURN_OFF;
|
||||
ret = pm_device_action_run(dev, p_action);
|
||||
pm_info(p_action, ret);
|
||||
k_sleep(K_MSEC(2000));
|
||||
p_state = PM_DEVICE_STATE_ACTIVE;
|
||||
ret = pm_device_state_set(dev, p_state);
|
||||
pm_info(p_state, ret);
|
||||
p_action = PM_DEVICE_ACTION_RESUME;
|
||||
ret = pm_device_action_run(dev, p_action);
|
||||
pm_info(p_action, ret);
|
||||
#elif CONFIG_FDC2X1X_TRIGGER_NONE
|
||||
k_sleep(K_MSEC(100));
|
||||
#endif
|
||||
|
|
|
@ -5530,7 +5530,7 @@ static int cmd_net_suspend(const struct shell *shell, size_t argc,
|
|||
|
||||
dev = net_if_get_device(iface);
|
||||
|
||||
ret = pm_device_state_set(dev, PM_DEVICE_STATE_SUSPENDED);
|
||||
ret = pm_device_action_run(dev, PM_DEVICE_ACTION_SUSPEND);
|
||||
if (ret != 0) {
|
||||
PR_INFO("Iface could not be suspended: ");
|
||||
|
||||
|
@ -5574,7 +5574,7 @@ static int cmd_net_resume(const struct shell *shell, size_t argc,
|
|||
|
||||
dev = net_if_get_device(iface);
|
||||
|
||||
ret = pm_device_state_set(dev, PM_DEVICE_STATE_ACTIVE);
|
||||
ret = pm_device_action_run(dev, PM_DEVICE_ACTION_RESUME);
|
||||
if (ret != 0) {
|
||||
PR_INFO("Iface could not be resumed\n");
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ static int pm_suspend_devices(void)
|
|||
continue;
|
||||
}
|
||||
|
||||
ret = pm_device_state_set(dev, PM_DEVICE_STATE_SUSPENDED);
|
||||
ret = pm_device_action_run(dev, PM_DEVICE_ACTION_SUSPEND);
|
||||
/* ignore devices not supporting or already at the given state */
|
||||
if ((ret == -ENOSYS) || (ret == -ENOTSUP) || (ret == -EALREADY)) {
|
||||
continue;
|
||||
|
@ -84,8 +84,8 @@ static int pm_suspend_devices(void)
|
|||
static void pm_resume_devices(void)
|
||||
{
|
||||
for (int i = (num_susp - 1); i >= 0; i--) {
|
||||
pm_device_state_set(__pm_device_slots_start[i],
|
||||
PM_DEVICE_STATE_ACTIVE);
|
||||
pm_device_action_run(__pm_device_slots_start[i],
|
||||
PM_DEVICE_ACTION_RESUME);
|
||||
}
|
||||
|
||||
num_susp = 0;
|
||||
|
|
|
@ -121,19 +121,33 @@ static void communication_verify(const struct device *dev, bool active)
|
|||
zassert_equal(power_state, exp_state, NULL); \
|
||||
} while (0)
|
||||
|
||||
static void state_set(const struct device *dev, enum pm_device_state state,
|
||||
static void action_run(const struct device *dev, enum pm_device_action action,
|
||||
int exp_err)
|
||||
{
|
||||
int err;
|
||||
enum pm_device_state prev_state;
|
||||
enum pm_device_state prev_state, exp_state;
|
||||
|
||||
err = pm_device_state_get(dev, &prev_state);
|
||||
zassert_equal(err, 0, "Unexpected err: %d", err);
|
||||
|
||||
err = pm_device_state_set(dev, state);
|
||||
err = pm_device_action_run(dev, action);
|
||||
zassert_equal(err, exp_err, "Unexpected err: %d", err);
|
||||
|
||||
enum pm_device_state exp_state = err == 0 ? state : prev_state;
|
||||
if (err == 0) {
|
||||
switch (action) {
|
||||
case PM_DEVICE_ACTION_SUSPEND:
|
||||
exp_state = PM_DEVICE_STATE_SUSPENDED;
|
||||
break;
|
||||
case PM_DEVICE_ACTION_RESUME:
|
||||
exp_state = PM_DEVICE_STATE_ACTIVE;
|
||||
break;
|
||||
default:
|
||||
exp_state = prev_state;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
exp_state = prev_state;
|
||||
}
|
||||
|
||||
state_verify(dev, exp_state);
|
||||
}
|
||||
|
@ -148,16 +162,16 @@ static void test_uart_pm_in_idle(void)
|
|||
state_verify(dev, PM_DEVICE_STATE_ACTIVE);
|
||||
communication_verify(dev, true);
|
||||
|
||||
state_set(dev, PM_DEVICE_STATE_SUSPENDED, 0);
|
||||
action_run(dev, PM_DEVICE_ACTION_SUSPEND, 0);
|
||||
communication_verify(dev, false);
|
||||
|
||||
state_set(dev, PM_DEVICE_STATE_ACTIVE, 0);
|
||||
action_run(dev, PM_DEVICE_ACTION_RESUME, 0);
|
||||
communication_verify(dev, true);
|
||||
|
||||
state_set(dev, PM_DEVICE_STATE_SUSPENDED, 0);
|
||||
action_run(dev, PM_DEVICE_ACTION_SUSPEND, 0);
|
||||
communication_verify(dev, false);
|
||||
|
||||
state_set(dev, PM_DEVICE_STATE_ACTIVE, 0);
|
||||
action_run(dev, PM_DEVICE_ACTION_RESUME, 0);
|
||||
communication_verify(dev, true);
|
||||
}
|
||||
|
||||
|
@ -171,21 +185,21 @@ static void test_uart_pm_poll_tx(void)
|
|||
communication_verify(dev, true);
|
||||
|
||||
uart_poll_out(dev, 'a');
|
||||
state_set(dev, PM_DEVICE_STATE_SUSPENDED, 0);
|
||||
action_run(dev, PM_DEVICE_ACTION_SUSPEND, 0);
|
||||
|
||||
communication_verify(dev, false);
|
||||
|
||||
state_set(dev, PM_DEVICE_STATE_ACTIVE, 0);
|
||||
action_run(dev, PM_DEVICE_ACTION_RESUME, 0);
|
||||
|
||||
communication_verify(dev, true);
|
||||
|
||||
/* Now same thing but with callback */
|
||||
uart_poll_out(dev, 'a');
|
||||
state_set(dev, PM_DEVICE_STATE_SUSPENDED, 0);
|
||||
action_run(dev, PM_DEVICE_ACTION_SUSPEND, 0);
|
||||
|
||||
communication_verify(dev, false);
|
||||
|
||||
state_set(dev, PM_DEVICE_STATE_ACTIVE, 0);
|
||||
action_run(dev, PM_DEVICE_ACTION_RESUME, 0);
|
||||
|
||||
communication_verify(dev, true);
|
||||
}
|
||||
|
@ -194,7 +208,7 @@ static void timeout(struct k_timer *timer)
|
|||
{
|
||||
const struct device *uart = k_timer_user_data_get(timer);
|
||||
|
||||
state_set(uart, PM_DEVICE_STATE_SUSPENDED, 0);
|
||||
action_run(uart, PM_DEVICE_ACTION_SUSPEND, 0);
|
||||
}
|
||||
|
||||
static K_TIMER_DEFINE(pm_timer, timeout, NULL);
|
||||
|
@ -221,7 +235,7 @@ static void test_uart_pm_poll_tx_interrupted(void)
|
|||
|
||||
k_timer_status_sync(&pm_timer);
|
||||
|
||||
state_set(dev, PM_DEVICE_STATE_ACTIVE, 0);
|
||||
action_run(dev, PM_DEVICE_ACTION_RESUME, 0);
|
||||
|
||||
communication_verify(dev, true);
|
||||
}
|
||||
|
|
|
@ -287,7 +287,7 @@ static void test_enable_and_disable_automatic_runtime_pm(void)
|
|||
*
|
||||
* @see device_get_binding(), pm_device_busy_set(), pm_device_busy_clear(),
|
||||
* pm_device_is_busy(), pm_device_is_any_busy(),
|
||||
* pm_device_state_set()
|
||||
* pm_device_action_run()
|
||||
*/
|
||||
void test_dummy_device_pm(void)
|
||||
{
|
||||
|
@ -326,7 +326,7 @@ void test_dummy_device_pm(void)
|
|||
test_build_suspend_device_list();
|
||||
|
||||
/* Set device state to PM_DEVICE_STATE_ACTIVE */
|
||||
ret = pm_device_state_set(dev, PM_DEVICE_STATE_ACTIVE);
|
||||
ret = pm_device_action_run(dev, PM_DEVICE_ACTION_RESUME);
|
||||
|
||||
zassert_true((ret == 0) || (ret == -EALREADY),
|
||||
"Unable to set active state to device");
|
||||
|
@ -339,7 +339,7 @@ void test_dummy_device_pm(void)
|
|||
"Error power status");
|
||||
|
||||
/* Set device state to PM_DEVICE_STATE_SUSPENDED */
|
||||
ret = pm_device_state_set(dev, PM_DEVICE_STATE_SUSPENDED);
|
||||
ret = pm_device_action_run(dev, PM_DEVICE_ACTION_SUSPEND);
|
||||
|
||||
zassert_true((ret == 0), "Unable to force suspend device");
|
||||
|
||||
|
|
|
@ -150,13 +150,13 @@ void test_pm(void)
|
|||
*/
|
||||
k_yield();
|
||||
|
||||
ret = pm_device_state_set(dev, PM_DEVICE_STATE_SUSPENDED);
|
||||
ret = pm_device_action_run(dev, PM_DEVICE_ACTION_SUSPEND);
|
||||
zassert_true(ret == 0, "Could not set state");
|
||||
|
||||
zassert_true(net_if_is_suspended(iface), "net iface is not suspended");
|
||||
|
||||
/* Let's try to suspend it again, it should fail relevantly */
|
||||
ret = pm_device_state_set(dev, PM_DEVICE_STATE_SUSPENDED);
|
||||
ret = pm_device_action_run(dev, PM_DEVICE_ACTION_SUSPEND);
|
||||
zassert_true(ret == -EALREADY, "Could change state");
|
||||
|
||||
zassert_true(net_if_is_suspended(iface), "net iface is not suspended");
|
||||
|
@ -166,12 +166,12 @@ void test_pm(void)
|
|||
(struct sockaddr *)&addr4, sizeof(struct sockaddr_in));
|
||||
zassert_true(ret < 0, "Could send data");
|
||||
|
||||
ret = pm_device_state_set(dev, PM_DEVICE_STATE_ACTIVE);
|
||||
ret = pm_device_action_run(dev, PM_DEVICE_ACTION_RESUME);
|
||||
zassert_true(ret == 0, "Could not set state");
|
||||
|
||||
zassert_false(net_if_is_suspended(iface), "net iface is suspended");
|
||||
|
||||
ret = pm_device_state_set(dev, PM_DEVICE_STATE_ACTIVE);
|
||||
ret = pm_device_action_run(dev, PM_DEVICE_ACTION_RESUME);
|
||||
zassert_true(ret == -EALREADY, "Could change state");
|
||||
|
||||
/* Let's send some data, it should go through */
|
||||
|
|
|
@ -319,7 +319,7 @@ void test_power_state_trans(void)
|
|||
* pm_action_cb
|
||||
*
|
||||
* @see pm_device_runtime_get(), pm_device_runtime_put_async(),
|
||||
* pm_device_state_set(), pm_device_state_get()
|
||||
* pm_device_action_run(), pm_device_state_get()
|
||||
*
|
||||
* @ingroup power_tests
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue