History

regulator: extract voltage balancing code to the separate function

Move the coupled regulators voltage balancing code to the separate function and allow to call it from the custom regulator couplers.

Marek Szyprowski committed 6 years ago

Commit 752db831 parent 8f3d9f32 files · +37 −20Browse files

Unified · Split

2 files
  1. drivers/regulator/core.c +29 −20
  2. include/linux/regulator/coupler.h +8 −0
drivers/regulator/core.c+29−20
@@ -3642,36 +3642,19 @@ finish: · 3641 unmodified lines
3642 return done;3642 return done;
3643}3643}
3644 3644
3645static int regulator_balance_voltage(struct regulator_dev *rdev,3645int regulator_do_balance_voltage(struct regulator_dev *rdev,
3646 suspend_state_t state)3646 suspend_state_t state, bool skip_coupled)
3647{3647{
3648 struct regulator_dev **c_rdevs;3648 struct regulator_dev **c_rdevs;
3649 struct regulator_dev *best_rdev;3649 struct regulator_dev *best_rdev;
3650 struct coupling_desc *c_desc = &rdev->coupling_desc;3650 struct coupling_desc *c_desc = &rdev->coupling_desc;
3651 struct regulator_coupler *coupler = c_desc->coupler;
3652 int i, ret, n_coupled, best_min_uV, best_max_uV, best_c_rdev;3651 int i, ret, n_coupled, best_min_uV, best_max_uV, best_c_rdev;
3653 unsigned int delta, best_delta;3652 unsigned int delta, best_delta;
3654 unsigned long c_rdev_done = 0;3653 unsigned long c_rdev_done = 0;
3655 bool best_c_rdev_done;3654 bool best_c_rdev_done;
3656 3655
3657 c_rdevs = c_desc->coupled_rdevs;3656 c_rdevs = c_desc->coupled_rdevs;
3658 n_coupled = c_desc->n_coupled;3657 n_coupled = skip_coupled ? 1 : c_desc->n_coupled;
3659
3660 /*
3661 * If system is in a state other than PM_SUSPEND_ON, don't check
3662 * other coupled regulators.
3663 */
3664 if (state != PM_SUSPEND_ON)
3665 n_coupled = 1;
3666
3667 if (c_desc->n_resolved < n_coupled) {
3668 rdev_err(rdev, "Not all coupled regulators registered\n");
3669 return -EPERM;
3670 }
3671
3672 /* Invoke custom balancer for customized couplers */
3673 if (coupler && coupler->balance_voltage)
3674 return coupler->balance_voltage(coupler, rdev, state);
3675 3658
3676 /*3659 /*
3677 * Find the best possible voltage change on each loop. Leave the loop3660 * Find the best possible voltage change on each loop. Leave the loop
@@ -3742,6 +3725,32 @@ out: · 64 unmodified lines
3742 return ret;3725 return ret;
3743}3726}
3744 3727
3728static int regulator_balance_voltage(struct regulator_dev *rdev,
3729 suspend_state_t state)
3730{
3731 struct coupling_desc *c_desc = &rdev->coupling_desc;
3732 struct regulator_coupler *coupler = c_desc->coupler;
3733 bool skip_coupled = false;
3734
3735 /*
3736 * If system is in a state other than PM_SUSPEND_ON, don't check
3737 * other coupled regulators.
3738 */
3739 if (state != PM_SUSPEND_ON)
3740 skip_coupled = true;
3741
3742 if (c_desc->n_resolved < c_desc->n_coupled) {
3743 rdev_err(rdev, "Not all coupled regulators registered\n");
3744 return -EPERM;
3745 }
3746
3747 /* Invoke custom balancer for customized couplers */
3748 if (coupler && coupler->balance_voltage)
3749 return coupler->balance_voltage(coupler, rdev, state);
3750
3751 return regulator_do_balance_voltage(rdev, state, skip_coupled);
3752}
3753
3745/**3754/**
3746 * regulator_set_voltage - set regulator output voltage3755 * regulator_set_voltage - set regulator output voltage
3747 * @regulator: regulator source3756 * @regulator: regulator source
include/linux/regulator/coupler.h+8−0
@@ -62,6 +62,8 @@ int regulator_get_voltage_rdev(struct regulator_dev *rdev); · 61 unmodified lines
62int regulator_set_voltage_rdev(struct regulator_dev *rdev,62int regulator_set_voltage_rdev(struct regulator_dev *rdev,
63 int min_uV, int max_uV,63 int min_uV, int max_uV,
64 suspend_state_t state);64 suspend_state_t state);
65int regulator_do_balance_voltage(struct regulator_dev *rdev,
66 suspend_state_t state, bool skip_coupled);
65#else67#else
66static inline int regulator_coupler_register(struct regulator_coupler *coupler)68static inline int regulator_coupler_register(struct regulator_coupler *coupler)
67{69{
@@ -92,6 +94,12 @@ static inline int regulator_set_voltage_rdev(struct regulator_dev *rdev, · 24 unmodified lines
92{94{
93 return -EINVAL;95 return -EINVAL;
94}96}
97static inline int regulator_do_balance_voltage(struct regulator_dev *rdev,
98 suspend_state_t state,
99 bool skip_coupled)
100{
101 return -EINVAL;
102}
95#endif103#endif
96 104
97#endif105#endif