[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230419-dynamic-vmon-v4-6-4d3734e62ada@skidata.com>
Date:   Tue, 20 Jun 2023 22:02:59 +0200
From:   Benjamin Bara <bbara93@...il.com>
To:     Liam Girdwood <lgirdwood@...il.com>,
        Mark Brown <broonie@...nel.org>
Cc:     support.opensource@...semi.com,
        DLG-Adam.Ward.opensource@...renesas.com,
        Martin Fuzzey <martin.fuzzey@...wbird.group>,
        linux-kernel@...r.kernel.org,
        Matti Vaittinen <mazziesaccount@...il.com>,
        Benjamin Bara <benjamin.bara@...data.com>
Subject: [PATCH RFC v4 06/13] regulator: set required ops for monitoring
 workarounds
From: Benjamin Bara <benjamin.bara@...data.com>
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@...data.com>
---
 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;
-- 
2.34.1
Powered by blists - more mailing lists