pm: refactor pm_device_driver_init
Refactor pm_device_driver_init code to keep the normal execution path inline and the early exit branches at a single indentation, this is commonly done throughout the code base. Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
This commit is contained in:
parent
91e0a4b9ac
commit
f3a6454f93
2 changed files with 37 additions and 30 deletions
|
|
@ -718,10 +718,16 @@ static inline int pm_device_driver_init(const struct device *dev, pm_device_acti
|
||||||
|
|
||||||
/* When power management is not enabled, all drivers should initialise to active state */
|
/* When power management is not enabled, all drivers should initialise to active state */
|
||||||
rc = action_cb(dev, PM_DEVICE_ACTION_TURN_ON);
|
rc = action_cb(dev, PM_DEVICE_ACTION_TURN_ON);
|
||||||
if (rc == 0) {
|
if (rc < 0) {
|
||||||
rc = action_cb(dev, PM_DEVICE_ACTION_RESUME);
|
return rc;
|
||||||
}
|
}
|
||||||
return rc;
|
|
||||||
|
rc = action_cb(dev, PM_DEVICE_ACTION_RESUME);
|
||||||
|
if (rc < 0) {
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_PM_DEVICE */
|
#endif /* CONFIG_PM_DEVICE */
|
||||||
|
|
|
||||||
|
|
@ -359,36 +359,37 @@ int pm_device_driver_init(const struct device *dev,
|
||||||
pm_device_action_cb_t action_cb)
|
pm_device_action_cb_t action_cb)
|
||||||
{
|
{
|
||||||
struct pm_device_base *pm = dev->pm_base;
|
struct pm_device_base *pm = dev->pm_base;
|
||||||
int rc = 0;
|
int rc;
|
||||||
|
|
||||||
/* Work only needs to be performed if the device is powered */
|
/* Work only needs to be performed if the device is powered */
|
||||||
if (pm_device_is_powered(dev)) {
|
if (!pm_device_is_powered(dev)) {
|
||||||
/* Run power-up logic */
|
|
||||||
rc = action_cb(dev, PM_DEVICE_ACTION_TURN_ON);
|
|
||||||
if (rc != 0) {
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
/* If device has no PM structure */
|
|
||||||
if (pm == NULL) {
|
|
||||||
/* Device should always be active */
|
|
||||||
return action_cb(dev, PM_DEVICE_ACTION_RESUME);
|
|
||||||
}
|
|
||||||
/* 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);
|
|
||||||
}
|
|
||||||
/* No PM enabled on the device by default */
|
|
||||||
else {
|
|
||||||
/* Startup into active mode */
|
|
||||||
return action_cb(dev, PM_DEVICE_ACTION_RESUME);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* Start in off mode */
|
/* Start in off mode */
|
||||||
pm_device_init_off(dev);
|
pm_device_init_off(dev);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
return rc;
|
|
||||||
|
/* Run power-up logic */
|
||||||
|
rc = action_cb(dev, PM_DEVICE_ACTION_TURN_ON);
|
||||||
|
if (rc != 0) {
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If device has no PM structure */
|
||||||
|
if (pm == NULL) {
|
||||||
|
/* Device should always be active */
|
||||||
|
return action_cb(dev, PM_DEVICE_ACTION_RESUME);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue