pm: device: do not call device if already on the given state

If the device is already at the given state, do not call the device PM
control function. This makes sure that devices are only called to change
from one state to another.

Even though asynchronous device PM is completely broken, transitional
states are considered too.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2021-07-02 12:52:18 +02:00 committed by Anas Nashif
commit bc2990f82d
3 changed files with 30 additions and 3 deletions

View file

@ -112,7 +112,9 @@ const char *pm_device_state_str(enum pm_device_state state);
* @param state Device power state to be set.
*
* @retval 0 If successful.
* @retval Errno Negative errno code in case of failure.
* @retval -ENOTSUP If requested state is not supported.
* @retval -EALREADY If device is already at (or transitioning to) the requested
* state.
*/
int pm_device_state_set(const struct device *dev,
enum pm_device_state state);