regulator: core: Allow specific minimal selector for starting linear mapping
authorAxel Lin <axel.lin@ingics.com>
Tue, 27 Nov 2012 02:24:33 +0000 (10:24 +0800)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Tue, 27 Nov 2012 20:07:40 +0000 (20:07 +0000)
Some drivers (at least 3 drivers) have such variant of linear mapping that
the first few selectors are invalid and the reset are linear mapping.
Let's support this case in core.

This patch adds linear_min_sel in struct regulator_desc,
so we can allow specific minimal selector for starting linear mapping.
Then extends regulator_[map|list]_voltage_linear() to support this feature.

Note that for selectors less than min_linear_index, we need count them to
n_voltages so regulator_list_voltage() won't fail while checking the boundary
for selector before calling list_voltage callback.

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 e872c8be080ed427a2e546efffee50c12acdd9fe..02a249b024b343fd7fa9dadf8a13c36b04c89f27 100644 (file)
@@ -1897,6 +1897,10 @@ int regulator_list_voltage_linear(struct regulator_dev *rdev,
 {
        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);
 }
@@ -2120,6 +2124,8 @@ int regulator_map_voltage_linear(struct regulator_dev *rdev,
        if (ret < 0)
                return ret;
 
+       ret += rdev->desc->linear_min_sel;
+
        /* Map back into a voltage to verify we're still in bounds */
        voltage = rdev->desc->ops->list_voltage(rdev, ret);
        if (voltage < min_uV || voltage > max_uV)
index 7932a3bf21bdba89f84275b7b990bcaa3a5773b0..d9ce98a5028b35cadaa8ae391412cdc05c81ae43 100644 (file)
@@ -185,6 +185,7 @@ enum regulator_type {
  *
  * @min_uV: Voltage given by the lowest selector (if linear mapping)
  * @uV_step: Voltage increase with each selector (if linear mapping)
+ * @linear_min_sel: Minimal selector for starting linear mapping
  * @ramp_delay: Time to settle down after voltage change (unit: uV/us)
  * @volt_table: Voltage mapping table (if table based mapping)
  *
@@ -207,6 +208,7 @@ struct regulator_desc {
 
        unsigned int min_uV;
        unsigned int uV_step;
+       unsigned int linear_min_sel;
        unsigned int ramp_delay;
 
        const unsigned int *volt_table;