[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231025084614.3092295-3-o.rempel@pengutronix.de>
Date: Wed, 25 Oct 2023 10:46:09 +0200
From: Oleksij Rempel <o.rempel@...gutronix.de>
To: Liam Girdwood <lgirdwood@...il.com>,
Mark Brown <broonie@...nel.org>,
Rob Herring <robh+dt@...nel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>,
Conor Dooley <conor+dt@...nel.org>
Cc: Oleksij Rempel <o.rempel@...gutronix.de>, kernel@...gutronix.de,
linux-kernel@...r.kernel.org, devicetree@...r.kernel.org
Subject: [PATCH v3 2/7] regulator: Handle system-critical under-voltage events
Introduce handling for system-critical regulators during under-voltage
events.
A new field 'system_critical' in regulation_constraints is added to mark
regulators critical to system stability or functionality. During an
under-voltage event, if the regulator is marked as system-critical, an
emergency hardware protection shutdown is triggered to prevent potential
system damage or malfunction.
Signed-off-by: Oleksij Rempel <o.rempel@...gutronix.de>
---
drivers/regulator/core.c | 6 ++++++
drivers/regulator/of_regulator.c | 2 ++
include/linux/regulator/machine.h | 6 ++++++
3 files changed, 14 insertions(+)
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index d8e1caaf207e..903c384f25e3 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -19,6 +19,7 @@
#include <linux/delay.h>
#include <linux/gpio/consumer.h>
#include <linux/of.h>
+#include <linux/reboot.h>
#include <linux/regmap.h>
#include <linux/regulator/of_regulator.h>
#include <linux/regulator/consumer.h>
@@ -5073,6 +5074,11 @@ EXPORT_SYMBOL_GPL(regulator_bulk_free);
int regulator_notifier_call_chain(struct regulator_dev *rdev,
unsigned long event, void *data)
{
+ if (rdev->constraints->system_critical &&
+ event == REGULATOR_EVENT_UNDER_VOLTAGE)
+ hw_protection_shutdown("System critical voltage drop detected",
+ REGULATOR_DEF_EMERG_SHUTDWN_TMO);
+
_notifier_call_chain(rdev, event, data);
return NOTIFY_DONE;
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index 1b65e5e4e40f..3bdd6f1919a4 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -131,6 +131,8 @@ static int of_get_regulation_constraints(struct device *dev,
constraints->valid_ops_mask |= REGULATOR_CHANGE_STATUS;
constraints->pull_down = of_property_read_bool(np, "regulator-pull-down");
+ constraints->system_critical = of_property_read_bool(np,
+ "system-critical-regulator");
if (of_property_read_bool(np, "regulator-allow-bypass"))
constraints->valid_ops_mask |= REGULATOR_CHANGE_BYPASS;
diff --git a/include/linux/regulator/machine.h b/include/linux/regulator/machine.h
index 621b7f4a3639..7332ee36e9d6 100644
--- a/include/linux/regulator/machine.h
+++ b/include/linux/regulator/machine.h
@@ -49,6 +49,9 @@ struct regulator;
#define DISABLE_IN_SUSPEND 1
#define ENABLE_IN_SUSPEND 2
+/* Default time in millisecond to wait for emergency shutdown */
+#define REGULATOR_DEF_EMERG_SHUTDWN_TMO 10
+
/* Regulator active discharge flags */
enum regulator_active_discharge {
REGULATOR_ACTIVE_DISCHARGE_DEFAULT,
@@ -127,6 +130,8 @@ struct notification_limit {
* @ramp_disable: Disable ramp delay when initialising or when setting voltage.
* @soft_start: Enable soft start so that voltage ramps slowly.
* @pull_down: Enable pull down when regulator is disabled.
+ * @system_critical: Set if the regulator is critical to system stability or
+ * functionality.
* @over_current_protection: Auto disable on over current event.
*
* @over_current_detection: Configure over current limits.
@@ -214,6 +219,7 @@ struct regulation_constraints {
unsigned ramp_disable:1; /* disable ramp delay */
unsigned soft_start:1; /* ramp voltage slowly */
unsigned pull_down:1; /* pull down resistor when regulator off */
+ unsigned system_critical:1; /* critical to system stability */
unsigned over_current_protection:1; /* auto disable on over current */
unsigned over_current_detection:1; /* notify on over current */
unsigned over_voltage_detection:1; /* notify on over voltage */
--
2.39.2
Powered by blists - more mailing lists