Browse Source

pm: device: correct state in `pm_device_driver_init`

Set the value of `pm->state` as we move through the various stages of
`pm_device_driver_init`. This ensures hat if any of the code inside the
actions callbacks runs `pm_device_state_get` they get the correct state,
instead of always getting `PM_DEVICE_STATE_ACTIVE` (0, the value at
reset).

Signed-off-by: Jordan Yates <jordan@embeint.com>
pull/88671/head
Jordan Yates 3 months ago committed by Benjamin Cabé
parent
commit
71a0f39568
  1. 22
      subsys/pm/device.c

22
subsys/pm/device.c

@ -361,10 +361,13 @@ int pm_device_driver_init(const struct device *dev, @@ -361,10 +361,13 @@ int pm_device_driver_init(const struct device *dev,
struct pm_device_base *pm = dev->pm_base;
int rc;
/* Device is currently in the OFF state */
if (pm) {
pm->state = PM_DEVICE_STATE_OFF;
}
/* Work only needs to be performed if the device is powered */
if (!pm_device_is_powered(dev)) {
/* Start in off mode */
pm_device_init_off(dev);
return 0;
}
@ -380,16 +383,21 @@ int pm_device_driver_init(const struct device *dev, @@ -380,16 +383,21 @@ int pm_device_driver_init(const struct device *dev,
return action_cb(dev, PM_DEVICE_ACTION_RESUME);
}
/* Device is currently in the SUSPENDED state */
pm->state = PM_DEVICE_STATE_SUSPENDED;
/* If device will have PM device runtime enabled */
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME) &&
atomic_test_bit(&pm->flags, PM_DEVICE_FLAG_RUNTIME_AUTO)) {
/* Init into suspend mode.
* This saves a SUSPENDED->ACTIVE->SUSPENDED cycle.
*/
pm_device_init_suspended(dev);
return 0;
}
/* Startup into active mode */
return action_cb(dev, PM_DEVICE_ACTION_RESUME);
rc = action_cb(dev, PM_DEVICE_ACTION_RESUME);
/* Device is now in the ACTIVE state */
pm->state = PM_DEVICE_STATE_ACTIVE;
/* Return the PM_DEVICE_ACTION_RESUME result */
return rc;
}

Loading…
Cancel
Save