regulator: helpers: Export helper voltage listing
authorMatti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Mon, 29 Mar 2021 12:57:33 +0000 (15:57 +0300)
committerMark Brown <broonie@kernel.org>
Fri, 2 Apr 2021 17:33:58 +0000 (18:33 +0100)
Some drivers need to translate voltage values to selectors prior regulator
registration. Currently a regulator_desc based list_voltages helper is only
exported for regulators using the linear_ranges. Export similar helper also
for regulators using simple linear mapping.

Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Link: https://lore.kernel.org/r/1200ef7a50c84327ada019b85f6527b4fc9b5ce1.1617020713.git.matti.vaittinen@fi.rohmeurope.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/regulator/helpers.c
include/linux/regulator/driver.h

index f42b394..3e19ecb 100644 (file)
@@ -508,6 +508,33 @@ int regulator_map_voltage_pickable_linear_range(struct regulator_dev *rdev,
 }
 EXPORT_SYMBOL_GPL(regulator_map_voltage_pickable_linear_range);
 
+/**
+ * regulator_desc_list_voltage_linear - List voltages with simple calculation
+ *
+ * @desc: Regulator desc for regulator which volatges are to be listed
+ * @selector: Selector to convert into a voltage
+ *
+ * Regulators with a simple linear mapping between voltages and
+ * selectors can set min_uV and uV_step in the regulator descriptor
+ * and then use this function prior regulator registration to list
+ * the voltages. This is useful when voltages need to be listed during
+ * device-tree parsing.
+ */
+int regulator_desc_list_voltage_linear(const struct regulator_desc *desc,
+                                      unsigned int selector)
+{
+       if (selector >= desc->n_voltages)
+               return -EINVAL;
+
+       if (selector < desc->linear_min_sel)
+               return 0;
+
+       selector -= desc->linear_min_sel;
+
+       return desc->min_uV + (desc->uV_step * selector);
+}
+EXPORT_SYMBOL_GPL(regulator_desc_list_voltage_linear);
+
 /**
  * regulator_list_voltage_linear - List voltages with simple calculation
  *
@@ -521,14 +548,7 @@ EXPORT_SYMBOL_GPL(regulator_map_voltage_pickable_linear_range);
 int regulator_list_voltage_linear(struct regulator_dev *rdev,
                                  unsigned int selector)
 {
-       if (selector >= rdev->desc->n_voltages)
-               return -EINVAL;
-       if (selector < rdev->desc->linear_min_sel)
-               return 0;
-
-       selector -= rdev->desc->linear_min_sel;
-
-       return rdev->desc->min_uV + (rdev->desc->uV_step * selector);
+       return regulator_desc_list_voltage_linear(rdev->desc, selector);
 }
 EXPORT_SYMBOL_GPL(regulator_list_voltage_linear);
 
index d7c77ee..39a5401 100644 (file)
@@ -543,4 +543,6 @@ void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data);
 int regulator_desc_list_voltage_linear_range(const struct regulator_desc *desc,
                                             unsigned int selector);
 
+int regulator_desc_list_voltage_linear(const struct regulator_desc *desc,
+                                      unsigned int selector);
 #endif