Skip to content

Commit 71a0f39

Browse files
JordanYateskartben
authored andcommitted
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>
1 parent 5721815 commit 71a0f39

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

subsys/pm/device.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,13 @@ int pm_device_driver_init(const struct device *dev,
361361
struct pm_device_base *pm = dev->pm_base;
362362
int rc;
363363

364+
/* Device is currently in the OFF state */
365+
if (pm) {
366+
pm->state = PM_DEVICE_STATE_OFF;
367+
}
368+
364369
/* Work only needs to be performed if the device is powered */
365370
if (!pm_device_is_powered(dev)) {
366-
/* Start in off mode */
367-
pm_device_init_off(dev);
368371
return 0;
369372
}
370373

@@ -380,16 +383,21 @@ int pm_device_driver_init(const struct device *dev,
380383
return action_cb(dev, PM_DEVICE_ACTION_RESUME);
381384
}
382385

386+
/* Device is currently in the SUSPENDED state */
387+
pm->state = PM_DEVICE_STATE_SUSPENDED;
388+
383389
/* If device will have PM device runtime enabled */
384390
if (IS_ENABLED(CONFIG_PM_DEVICE_RUNTIME) &&
385391
atomic_test_bit(&pm->flags, PM_DEVICE_FLAG_RUNTIME_AUTO)) {
386-
/* Init into suspend mode.
387-
* This saves a SUSPENDED->ACTIVE->SUSPENDED cycle.
388-
*/
389-
pm_device_init_suspended(dev);
390392
return 0;
391393
}
392394

393395
/* Startup into active mode */
394-
return action_cb(dev, PM_DEVICE_ACTION_RESUME);
396+
rc = action_cb(dev, PM_DEVICE_ACTION_RESUME);
397+
398+
/* Device is now in the ACTIVE state */
399+
pm->state = PM_DEVICE_STATE_ACTIVE;
400+
401+
/* Return the PM_DEVICE_ACTION_RESUME result */
402+
return rc;
395403
}

0 commit comments

Comments
 (0)