Re: [PATCH RFC v4 06/13] regulator: set required ops for monitoring workarounds

From: Matti Vaittinen
Date: Mon Jun 26 2023 - 09:50:01 EST


On 6/20/23 23:02, Benjamin Bara wrote:
From: Benjamin Bara <benjamin.bara@xxxxxxxxxxx>

If the core should be able to handle the monitoring workarounds, certain
regulator ops are required:
- is_enabled() to decide whether a monitor should be turned off or not.
- get_active_protections() to find out if the device-tree is missing
active protections.
- get_mode() if the regulator is in a mode where monitoring is not
supported.

Signed-off-by: Benjamin Bara <benjamin.bara@xxxxxxxxxxx>

Reviewed-by: Matti Vaittinen <mazziesaccount@xxxxxxxxx>

---
drivers/regulator/core.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index dc741ac156c3..ca5d6ba889dc 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -5540,6 +5540,40 @@ regulator_register(struct device *dev,
goto rinse;
}
+ /* monitor workaround properties require ops to ensure functionality. */
+ if (regulator_desc->mon_disable_reg_disabled ||
+ regulator_desc->mon_disable_reg_set_higher ||
+ regulator_desc->mon_disable_reg_set_lower ||
+ regulator_desc->mon_unsupported_reg_modes) {
+ /*
+ * is_enabled() to make sure the monitors aren't disabled on
+ * disabled regulators.
+ */
+ if (!regulator_desc->ops->is_enabled) {
+ ret = -EINVAL;
+ goto rinse;
+ }
+
+ /*
+ * get_active_protections() to know if a regulator is monitored
+ * without the device-tree being aware of it.
+ */
+ if (!regulator_desc->ops->get_active_protections) {
+ ret = -EINVAL;
+ goto rinse;
+ }
+
+ /*
+ * mon_unsupported_reg_modes property requires get_mode() to get
+ * the old state in case a state switch is failing.
+ */
+ if (regulator_desc->mon_unsupported_reg_modes &&
+ !regulator_desc->ops->get_mode) {
+ ret = -EINVAL;
+ goto rinse;
+ }
+ }
+
rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL);
if (rdev == NULL) {
ret = -ENOMEM;


--
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~