Browse Source

regulator: core: Define regulator_set_voltage_triplet()

Voltage tolerance isn't necessarily same on both sides of the target
voltage and regulator_set_voltage_tol() wouldn't be suitable in such
cases.

Add another routine regulator_set_voltage_triplet(), which accepts
target, min and max voltages as arguments.

This first tries to set the voltage between the target voltage and the
upper limit, then fall back on the full range. The idea behind this is
to set regulator's voltage as close to the target voltage, as possible.

Based on regulator_set_voltage_tol().

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
Viresh Kumar 10 năm trước cách đây
mục cha
commit
30f93ca832
1 tập tin đã thay đổi với 10 bổ sung0 xóa
  1. 10 0
      include/linux/regulator/consumer.h

+ 10 - 0
include/linux/regulator/consumer.h

@@ -552,6 +552,16 @@ static inline int regulator_count_voltages(struct regulator *regulator)
 }
 }
 #endif
 #endif
 
 
+static inline int regulator_set_voltage_triplet(struct regulator *regulator,
+						int min_uV, int target_uV,
+						int max_uV)
+{
+	if (regulator_set_voltage(regulator, target_uV, max_uV) == 0)
+		return 0;
+
+	return regulator_set_voltage(regulator, min_uV, max_uV);
+}
+
 static inline int regulator_set_voltage_tol(struct regulator *regulator,
 static inline int regulator_set_voltage_tol(struct regulator *regulator,
 					    int new_uV, int tol_uV)
 					    int new_uV, int tol_uV)
 {
 {