regulator: extract voltage balancing code to the separate function
authorMarek Szyprowski <m.szyprowski@samsung.com>
Fri, 29 May 2020 12:49:39 +0000 (14:49 +0200)
committerMark Brown <broonie@kernel.org>
Fri, 29 May 2020 13:36:00 +0000 (14:36 +0100)
Move the coupled regulators voltage balancing code to the separate
function and allow to call it from the custom regulator couplers.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Link: https://lore.kernel.org/r/20200529124940.10675-2-m.szyprowski@samsung.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/regulator/core.c
include/linux/regulator/coupler.h

index c340505..1eba6c2 100644 (file)
@@ -3642,36 +3642,19 @@ finish:
        return done;
 }
 
-static int regulator_balance_voltage(struct regulator_dev *rdev,
-                                    suspend_state_t state)
+int regulator_do_balance_voltage(struct regulator_dev *rdev,
+                                suspend_state_t state, bool skip_coupled)
 {
        struct regulator_dev **c_rdevs;
        struct regulator_dev *best_rdev;
        struct coupling_desc *c_desc = &rdev->coupling_desc;
-       struct regulator_coupler *coupler = c_desc->coupler;
        int i, ret, n_coupled, best_min_uV, best_max_uV, best_c_rdev;
        unsigned int delta, best_delta;
        unsigned long c_rdev_done = 0;
        bool best_c_rdev_done;
 
        c_rdevs = c_desc->coupled_rdevs;
-       n_coupled = c_desc->n_coupled;
-
-       /*
-        * If system is in a state other than PM_SUSPEND_ON, don't check
-        * other coupled regulators.
-        */
-       if (state != PM_SUSPEND_ON)
-               n_coupled = 1;
-
-       if (c_desc->n_resolved < n_coupled) {
-               rdev_err(rdev, "Not all coupled regulators registered\n");
-               return -EPERM;
-       }
-
-       /* Invoke custom balancer for customized couplers */
-       if (coupler && coupler->balance_voltage)
-               return coupler->balance_voltage(coupler, rdev, state);
+       n_coupled = skip_coupled ? 1 : c_desc->n_coupled;
 
        /*
         * Find the best possible voltage change on each loop. Leave the loop
@@ -3742,6 +3725,32 @@ out:
        return ret;
 }
 
+static int regulator_balance_voltage(struct regulator_dev *rdev,
+                                    suspend_state_t state)
+{
+       struct coupling_desc *c_desc = &rdev->coupling_desc;
+       struct regulator_coupler *coupler = c_desc->coupler;
+       bool skip_coupled = false;
+
+       /*
+        * If system is in a state other than PM_SUSPEND_ON, don't check
+        * other coupled regulators.
+        */
+       if (state != PM_SUSPEND_ON)
+               skip_coupled = true;
+
+       if (c_desc->n_resolved < c_desc->n_coupled) {
+               rdev_err(rdev, "Not all coupled regulators registered\n");
+               return -EPERM;
+       }
+
+       /* Invoke custom balancer for customized couplers */
+       if (coupler && coupler->balance_voltage)
+               return coupler->balance_voltage(coupler, rdev, state);
+
+       return regulator_do_balance_voltage(rdev, state, skip_coupled);
+}
+
 /**
  * regulator_set_voltage - set regulator output voltage
  * @regulator: regulator source
index 0212d62..5f86824 100644 (file)
@@ -62,6 +62,8 @@ int regulator_get_voltage_rdev(struct regulator_dev *rdev);
 int regulator_set_voltage_rdev(struct regulator_dev *rdev,
                               int min_uV, int max_uV,
                               suspend_state_t state);
+int regulator_do_balance_voltage(struct regulator_dev *rdev,
+                                suspend_state_t state, bool skip_coupled);
 #else
 static inline int regulator_coupler_register(struct regulator_coupler *coupler)
 {
@@ -92,6 +94,12 @@ static inline int regulator_set_voltage_rdev(struct regulator_dev *rdev,
 {
        return -EINVAL;
 }
+static inline int regulator_do_balance_voltage(struct regulator_dev *rdev,
+                                              suspend_state_t state,
+                                              bool skip_coupled)
+{
+       return -EINVAL;
+}
 #endif
 
 #endif