[U-Boot] [PATCH 2/3] power: regulator: Introduce regulator_set_enable_if_allowed api

Lokesh Vutla lokeshvutla at ti.com
Mon Jan 7 06:13:14 UTC 2019


regulator_set_enable() api throws an error in the following three cases:
- when requested to disable an always-on regulator
- when set_enable() ops not provided by regulator driver
- when enabling is actually failed.(Error returned by the regulator driver)

Sometimes consumer drivers doesn't want to track the first two scenarios
and just need to worry about the case where enabling is actually failed.
But it is also a good practice to have an error value returned in the
first two cases.

So introduce an api regulator_set_enable_if_allowed() which ignores the
first two error cases and returns an error as given by regulator driver.
Consumer drivers can use this api need not worry about the first two
error conditions.

Signed-off-by: Lokesh Vutla <lokeshvutla at ti.com>
---
 drivers/power/regulator/regulator-uclass.c | 11 +++++++++++
 include/power/regulator.h                  | 11 +++++++++++
 2 files changed, 22 insertions(+)

diff --git a/drivers/power/regulator/regulator-uclass.c b/drivers/power/regulator/regulator-uclass.c
index 4511625ff2..6f355b969a 100644
--- a/drivers/power/regulator/regulator-uclass.c
+++ b/drivers/power/regulator/regulator-uclass.c
@@ -118,6 +118,17 @@ int regulator_set_enable(struct udevice *dev, bool enable)
 	return ops->set_enable(dev, enable);
 }
 
+int regulator_set_enable_if_allowed(struct udevice *dev, bool enable)
+{
+	int ret;
+
+	ret = regulator_set_enable(dev, enable);
+	if (ret == -ENOSYS || ret == -EACCES)
+		return 0;
+
+	return ret;
+}
+
 int regulator_get_mode(struct udevice *dev)
 {
 	const struct dm_regulator_ops *ops = dev_get_driver_ops(dev);
diff --git a/include/power/regulator.h b/include/power/regulator.h
index 5318ab3ace..314160a894 100644
--- a/include/power/regulator.h
+++ b/include/power/regulator.h
@@ -303,6 +303,17 @@ int regulator_get_enable(struct udevice *dev);
  */
 int regulator_set_enable(struct udevice *dev, bool enable);
 
+/**
+ * regulator_set_enable_if_allowed: set regulator enable state if allowed by
+ *					regulator
+ *
+ * @dev    - pointer to the regulator device
+ * @enable - set true or false
+ * @return - 0 on success or if enabling is not supported
+ *	     -errno val if fails.
+ */
+int regulator_set_enable_if_allowed(struct udevice *dev, bool enable);
+
 /**
  * regulator_get_mode: get active operation mode id of a given regulator
  *
-- 
2.19.2



More information about the U-Boot mailing list