regulator: core: Add helper for allow HW access to enable/disable regulator
authorBiju Das <biju.das.jz@bp.renesas.com>
Sun, 16 Jun 2024 10:53:55 +0000 (11:53 +0100)
committerMark Brown <broonie@kernel.org>
Wed, 26 Jun 2024 17:17:05 +0000 (18:17 +0100)
Add a helper function that allow regulator consumers to allow low-level
HW access, in order to enable/disable regulator in atomic context.

The use-case for RZ/G2L SoC is to enable VBUS selection register based
on vbus detection that happens in interrupt context.

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
Link: https://patch.msgid.link/20240616105402.45211-4-biju.das.jz@bp.renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Documentation/power/regulator/consumer.rst
drivers/regulator/core.c
include/linux/regulator/consumer.h

index 85c2bf5..9d2416f 100644 (file)
@@ -227,3 +227,9 @@ directly written to the voltage selector register, use::
 
        int regulator_list_hardware_vsel(struct regulator *regulator,
                                         unsigned selector);
+
+To access the hardware for enabling/disabling the regulator, consumers must
+use regulator_get_exclusive(), as it can't work if there's more than one
+consumer. To enable/disable regulator use::
+
+       int regulator_hardware_enable(struct regulator *regulator, bool enable);
index 844e958..7674b7f 100644 (file)
@@ -3408,6 +3408,34 @@ int regulator_list_hardware_vsel(struct regulator *regulator,
 }
 EXPORT_SYMBOL_GPL(regulator_list_hardware_vsel);
 
+/**
+ * regulator_hardware_enable - access the HW for enable/disable regulator
+ * @regulator: regulator source
+ * @enable: true for enable, false for disable
+ *
+ * Request that the regulator be enabled/disabled with the regulator output at
+ * the predefined voltage or current value.
+ *
+ * On success 0 is returned, otherwise a negative errno is returned.
+ */
+int regulator_hardware_enable(struct regulator *regulator, bool enable)
+{
+       struct regulator_dev *rdev = regulator->rdev;
+       const struct regulator_ops *ops = rdev->desc->ops;
+       int ret = -EOPNOTSUPP;
+
+       if (!rdev->exclusive || !ops || !ops->enable || !ops->disable)
+               return ret;
+
+       if (enable)
+               ret = ops->enable(rdev);
+       else
+               ret = ops->disable(rdev);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(regulator_hardware_enable);
+
 /**
  * regulator_get_linear_step - return the voltage step size between VSEL values
  * @regulator: regulator source
index 59d0b9a..550a0e6 100644 (file)
@@ -250,6 +250,7 @@ int regulator_get_hardware_vsel_register(struct regulator *regulator,
                                         unsigned *vsel_mask);
 int regulator_list_hardware_vsel(struct regulator *regulator,
                                 unsigned selector);
+int regulator_hardware_enable(struct regulator *regulator, bool enable);
 
 /* regulator notifier block */
 int regulator_register_notifier(struct regulator *regulator,
@@ -571,6 +572,12 @@ static inline int regulator_list_hardware_vsel(struct regulator *regulator,
        return -EOPNOTSUPP;
 }
 
+static inline int regulator_hardware_enable(struct regulator *regulator,
+                                           bool enable)
+{
+       return -EOPNOTSUPP;
+}
+
 static inline int regulator_register_notifier(struct regulator *regulator,
                              struct notifier_block *nb)
 {