2023-10-25 08:47:07

by Oleksij Rempel

[permalink] [raw]
Subject: [PATCH v3 0/7] regulator: add under-voltage support

This series add under-voltage and emergency shutdown for system critical
regulators

changes v3:
- add system-critical-regulator property
- add regulator-uv-survival-time-ms property
- implement default policy for system critical uv events

changes v2:
- drop event forwarding support
- use emergency shutdown directly instead of generating under-voltage
error event.
- fix devicetree patch
- drop interrupt-names support


Oleksij Rempel (7):
regulator: dt-bindings: Add system-critical-regulator property
regulator: Handle system-critical under-voltage events
regulator: dt-bindings: fixed-regulator: Add under-voltage interrupt
support
regulator: dt-bindings: whitelist system-critical-regulator property
for fixed-regulator
regulator: fixed: add support for under-voltage IRQ
regulator: dt-bindings: Add regulator-uv-survival-time-ms property
regulator: Implement uv_survival_time for handling under-voltage
events

.../bindings/regulator/fixed-regulator.yaml | 7 +++
.../bindings/regulator/regulator.yaml | 12 +++++
drivers/regulator/core.c | 6 +++
drivers/regulator/fixed.c | 50 +++++++++++++++++++
drivers/regulator/of_regulator.c | 8 +++
include/linux/regulator/machine.h | 12 +++++
6 files changed, 95 insertions(+)

--
2.39.2


2023-10-25 08:47:28

by Oleksij Rempel

[permalink] [raw]
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 <[email protected]>
---
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

2023-10-25 12:47:54

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH v3 2/7] regulator: Handle system-critical under-voltage events

On Wed, Oct 25, 2023 at 10:46:09AM +0200, Oleksij Rempel wrote:

> + if (rdev->constraints->system_critical &&
> + event == REGULATOR_EVENT_UNDER_VOLTAGE)
> + hw_protection_shutdown("System critical voltage drop detected",
> + REGULATOR_DEF_EMERG_SHUTDWN_TMO);
> +

This should probably be a switch statement for the event and also handle
REGULATOR_EVENT_FAIL, possibly other errors this would also be
appropriate handling but it's less immediately obvious and we can
always extend later.


Attachments:
(No filename) (516.00 B)
signature.asc (499.00 B)
Download all attachments

2023-10-25 17:48:20

by Mark Brown

[permalink] [raw]
Subject: Re: (subset) [PATCH v3 0/7] regulator: add under-voltage support

On Wed, 25 Oct 2023 10:46:07 +0200, Oleksij Rempel wrote:
> This series add under-voltage and emergency shutdown for system critical
> regulators
>
> changes v3:
> - add system-critical-regulator property
> - add regulator-uv-survival-time-ms property
> - implement default policy for system critical uv events
>
> [...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-next

Thanks!

[3/7] regulator: dt-bindings: fixed-regulator: Add under-voltage interrupt support
commit: 0ab1dc9c657f30434ca55a3dcc87e624af0b2116
[5/7] regulator: fixed: add support for under-voltage IRQ
commit: ecb6f1f456144e9ade5a492192287decbeef4cfe

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark