]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
regulator: core: Add regulator_map_voltage_ascend() API
authorAxel Lin <axel.lin@ingics.com>
Thu, 18 Apr 2013 02:34:49 +0000 (10:34 +0800)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Thu, 18 Apr 2013 11:09:32 +0000 (12:09 +0100)
A lot of regulator hardware has ascendant voltage list.
This patch adds regulator_map_voltage_ascend() and export it.

Drivers that have ascendant voltage list can use this as their map_voltage()
operation, this is more efficient than default regulator_map_voltage_iterate()
function.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
drivers/regulator/core.c
include/linux/regulator/driver.h

index e3661c20cf389fe38bcbb9406f25476aae9d4796..56f4ca0854c91212d907f6fcb590785482079804 100644 (file)
@@ -2137,6 +2137,37 @@ int regulator_map_voltage_iterate(struct regulator_dev *rdev,
 }
 EXPORT_SYMBOL_GPL(regulator_map_voltage_iterate);
 
+/**
+ * regulator_map_voltage_ascend - map_voltage() for ascendant voltage list
+ *
+ * @rdev: Regulator to operate on
+ * @min_uV: Lower bound for voltage
+ * @max_uV: Upper bound for voltage
+ *
+ * Drivers that have ascendant voltage list can use this as their
+ * map_voltage() operation.
+ */
+int regulator_map_voltage_ascend(struct regulator_dev *rdev,
+                                int min_uV, int max_uV)
+{
+       int i, ret;
+
+       for (i = 0; i < rdev->desc->n_voltages; i++) {
+               ret = rdev->desc->ops->list_voltage(rdev, i);
+               if (ret < 0)
+                       continue;
+
+               if (ret > max_uV)
+                       break;
+
+               if (ret >= min_uV && ret <= max_uV)
+                       return i;
+       }
+
+       return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(regulator_map_voltage_ascend);
+
 /**
  * regulator_map_voltage_linear - map_voltage() for simple linear mappings
  *
index 7df93f52db089afb7f65ca574e89ee4996714d08..2acdc66f8342ed722361ee86459e3707acaa399d 100644 (file)
@@ -329,6 +329,8 @@ int regulator_map_voltage_linear(struct regulator_dev *rdev,
                                  int min_uV, int max_uV);
 int regulator_map_voltage_iterate(struct regulator_dev *rdev,
                                  int min_uV, int max_uV);
+int regulator_map_voltage_ascend(struct regulator_dev *rdev,
+                                 int min_uV, int max_uV);
 int regulator_get_voltage_sel_regmap(struct regulator_dev *rdev);
 int regulator_set_voltage_sel_regmap(struct regulator_dev *rdev, unsigned sel);
 int regulator_is_enabled_regmap(struct regulator_dev *rdev);