From 740eba1341ab2456c97390ea71d4be5d9ff8bab7 Mon Sep 17 00:00:00 2001 From: Gerard Marull-Paretas Date: Mon, 23 Sep 2024 10:29:40 +0200 Subject: [PATCH] pm: device: allow optional support of TURN_ON action Some devices, e.g. SoC level devices like I2C peripheral, can never be powerd off as they are always energized. Such devices can only go from an active state or to a low power state (suspended). Allow them to simply return -ENOTSUP when called with TURN_ON (or TURN_OFF). Signed-off-by: Gerard Marull-Paretas --- include/zephyr/pm/device.h | 5 +++-- subsys/pm/device.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/zephyr/pm/device.h b/include/zephyr/pm/device.h index 26e4a803774..a6e2ef032c0 100644 --- a/include/zephyr/pm/device.h +++ b/include/zephyr/pm/device.h @@ -625,7 +625,8 @@ bool pm_device_is_powered(const struct device *dev); * This helper function is intended to be called at the end of a driver * init function to automatically setup the device into the lowest power * mode. It assumes that the device has been configured as if it is in - * @ref PM_DEVICE_STATE_OFF. + * @ref PM_DEVICE_STATE_OFF, or @ref PM_DEVICE_STATE_SUSPENDED if device can + * never be powered off. * * @param dev Device instance. * @param action_cb Device PM control callback function. @@ -718,7 +719,7 @@ 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 */ rc = action_cb(dev, PM_DEVICE_ACTION_TURN_ON); - if (rc < 0) { + if ((rc < 0) && (rc != -ENOTSUP)) { return rc; } diff --git a/subsys/pm/device.c b/subsys/pm/device.c index f272a2a8e28..518e20a8630 100644 --- a/subsys/pm/device.c +++ b/subsys/pm/device.c @@ -370,7 +370,7 @@ int pm_device_driver_init(const struct device *dev, /* Run power-up logic */ rc = action_cb(dev, PM_DEVICE_ACTION_TURN_ON); - if (rc != 0) { + if ((rc < 0) && (rc != -ENOTSUP)) { return rc; }