diff options
author | Oleksij Rempel <o.rempel@pengutronix.de> | 2023-10-26 16:48:21 +0200 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2023-11-13 01:26:25 +0000 |
commit | 8156c7dd47b92fc4a70c9ea58e7a9e88c8bc32be (patch) | |
tree | 8553e19ac5241e14b020928537e4b82cd38bf746 /drivers/regulator/core.c | |
parent | 0e1c8dcbdecefea93dee19419b2f67dca591dd42 (diff) |
regulator: Introduce handling for system-critical under-voltage events
Handle under-voltage events for crucial regulators to maintain system
stability and avoid issues during power drops.
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Link: https://lore.kernel.org/r/20231026144824.4065145-3-o.rempel@pengutronix.de
Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'drivers/regulator/core.c')
-rw-r--r-- | drivers/regulator/core.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 3137e40fcd3e..a072f721f288 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> @@ -5062,6 +5063,41 @@ void regulator_bulk_free(int num_consumers, EXPORT_SYMBOL_GPL(regulator_bulk_free); /** + * regulator_handle_critical - Handle events for system-critical regulators. + * @rdev: The regulator device. + * @event: The event being handled. + * + * This function handles critical events such as under-voltage, over-current, + * and unknown errors for regulators deemed system-critical. On detecting such + * events, it triggers a hardware protection shutdown with a defined timeout. + */ +static void regulator_handle_critical(struct regulator_dev *rdev, + unsigned long event) +{ + const char *reason = NULL; + + if (!rdev->constraints->system_critical) + return; + + switch (event) { + case REGULATOR_EVENT_UNDER_VOLTAGE: + reason = "System critical regulator: voltage drop detected"; + break; + case REGULATOR_EVENT_OVER_CURRENT: + reason = "System critical regulator: over-current detected"; + break; + case REGULATOR_EVENT_FAIL: + reason = "System critical regulator: unknown error"; + } + + if (!reason) + return; + + hw_protection_shutdown(reason, + REGULATOR_DEF_UV_LESS_CRITICAL_WINDOW_MS); +} + +/** * regulator_notifier_call_chain - call regulator event notifier * @rdev: regulator source * @event: notifier block @@ -5073,6 +5109,8 @@ EXPORT_SYMBOL_GPL(regulator_bulk_free); int regulator_notifier_call_chain(struct regulator_dev *rdev, unsigned long event, void *data) { + regulator_handle_critical(rdev, event); + _notifier_call_chain(rdev, event, data); return NOTIFY_DONE; |