regulator: Implement uv_survival_time for handling under-voltage events
authorOleksij Rempel <o.rempel@pengutronix.de>
Thu, 26 Oct 2023 14:48:24 +0000 (16:48 +0200)
committerMark Brown <broonie@kernel.org>
Mon, 13 Nov 2023 01:26:28 +0000 (01:26 +0000)
Add 'uv_survival_time' field to regulation_constraints for specifying
survival time post critical under-voltage event. Update the regulator
notifier call chain and Device Tree property parsing to use this new
field, allowing a configurable timeout before emergency shutdown.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Link: https://lore.kernel.org/r/20231026144824.4065145-6-o.rempel@pengutronix.de
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/regulator/core.c
drivers/regulator/of_regulator.c
include/linux/regulator/machine.h

index a072f721f288130c2a6b9375a2fb1915e2091454..a6cb84af989e009ed43fb1d1386789ad37f3a430 100644 (file)
@@ -5094,7 +5094,7 @@ static void regulator_handle_critical(struct regulator_dev *rdev,
                return;
 
        hw_protection_shutdown(reason,
-                              REGULATOR_DEF_UV_LESS_CRITICAL_WINDOW_MS);
+                              rdev->constraints->uv_less_critical_window_ms);
 }
 
 /**
index 3bdd6f1919a4c8a63fd3af695dda8705d475b416..03afc160fc72ce8728f8314a5b7f9e2c38c5c808 100644 (file)
@@ -175,6 +175,13 @@ static int of_get_regulation_constraints(struct device *dev,
        if (!ret)
                constraints->enable_time = pval;
 
+       ret = of_property_read_u32(np, "regulator-uv-survival-time-ms", &pval);
+       if (!ret)
+               constraints->uv_less_critical_window_ms = pval;
+       else
+               constraints->uv_less_critical_window_ms =
+                               REGULATOR_DEF_UV_LESS_CRITICAL_WINDOW_MS;
+
        constraints->soft_start = of_property_read_bool(np,
                                        "regulator-soft-start");
        ret = of_property_read_u32(np, "regulator-active-discharge", &pval);
index e0ddfb5593c9257b733662dfe2066c90273c4e1b..0cd76d2647274ff328ceec1c7e13551243f712d9 100644 (file)
@@ -162,6 +162,13 @@ struct notification_limit {
  *                   regulator_active_discharge values are used for
  *                   initialisation.
  * @enable_time: Turn-on time of the rails (unit: microseconds)
+ * @uv_less_critical_window_ms: Specifies the time window (in milliseconds)
+ *                              following a critical under-voltage (UV) event
+ *                              during which less critical actions can be
+ *                              safely carried out by the system (for example
+ *                              logging). After this time window more critical
+ *                              actions should be done (for example prevent
+ *                              HW damage).
  */
 struct regulation_constraints {
 
@@ -213,6 +220,7 @@ struct regulation_constraints {
        unsigned int settling_time_up;
        unsigned int settling_time_down;
        unsigned int enable_time;
+       unsigned int uv_less_critical_window_ms;
 
        unsigned int active_discharge;