[PATCH] regulator: core: Fix off-on-delay-us for always-on/boot-on regulators

From: Christian Kohlschuetter
Date: Sun Jul 17 2022 - 07:30:43 EST


Regulators marked with "regulator-always-on" or "regulator-boot-on"
as well as an "off-on-delay-us", may run into cycling issues that are
hard to detect.

This is caused by the "last_off" state not being initialized in this
case.

Fix the "last_off" initialization by setting it to the current kernel
time upon initialization, regardless of always_on/boot_on state.

Signed-off-by: Christian Kohlschütter <christian@xxxxxxxxxxxxxxxx>
---
drivers/regulator/core.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index c4d844ffad7a..48ed33ad48c8 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1522,6 +1522,9 @@ static int set_machine_constraints(struct regulator_dev *rdev)
}
}

+ if (rdev->desc->off_on_delay)
+ rdev->last_off = ktime_get();
+
/* If the constraints say the regulator should be on at this point
* and we have control then make sure it is enabled.
*/
@@ -1549,8 +1552,6 @@ static int set_machine_constraints(struct regulator_dev *rdev)

if (rdev->constraints->always_on)
rdev->use_count++;
- } else if (rdev->desc->off_on_delay) {
- rdev->last_off = ktime_get();
}

print_constraints(rdev);
--
2.36.1