regulator: Support voltage offsets to compensate for drops in system
authorMark Brown <broonie@opensource.wolfsonmicro.com>
Sun, 8 May 2011 21:13:37 +0000 (22:13 +0100)
committerLiam Girdwood <lrg@slimlogic.co.uk>
Fri, 27 May 2011 09:34:37 +0000 (10:34 +0100)
Some systems, particularly physically large systems used for early
prototyping, may experience substantial voltage drops between the regulator
and the consumers as a result of long traces in the system. With these
systems voltages may need to be set higher than requested in order to
ensure reliable system operation.

Allow systems to work around such hardware issues by allowing constraints
to supply an offset to be applied to any requested and reported voltages.
This is not ideal, especially since the voltage drop may be load dependant,
but is sufficient for most affected systems, it is not expected to be used
in production hardware. The offset is applied after all constraint
processing so constraints should be specified in terms of consumer values
not physically configured values.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>
drivers/regulator/core.c
include/linux/regulator/machine.h

index 432faa5cb8afaf6ff107e75a0f2bf326f6530283..58452ac0f165fa0b54025252d34eb8c206e68719 100644 (file)
@@ -724,6 +724,10 @@ static void print_constraints(struct regulator_dev *rdev)
                        count += sprintf(buf + count, "at %d mV ", ret / 1000);
        }
 
+       if (constraints->uV_offset)
+               count += sprintf(buf, "%dmV offset ",
+                                constraints->uV_offset / 1000);
+
        if (constraints->min_uA && constraints->max_uA) {
                if (constraints->min_uA == constraints->max_uA)
                        count += sprintf(buf + count, "%d mA ",
@@ -1641,6 +1645,9 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev,
 
        trace_regulator_set_voltage(rdev_get_name(rdev), min_uV, max_uV);
 
+       min_uV += rdev->constraints->uV_offset;
+       max_uV += rdev->constraints->uV_offset;
+
        if (rdev->desc->ops->set_voltage) {
                ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV,
                                                   &selector);
@@ -1865,18 +1872,20 @@ EXPORT_SYMBOL_GPL(regulator_sync_voltage);
 
 static int _regulator_get_voltage(struct regulator_dev *rdev)
 {
-       int sel;
+       int sel, ret;
 
        if (rdev->desc->ops->get_voltage_sel) {
                sel = rdev->desc->ops->get_voltage_sel(rdev);
                if (sel < 0)
                        return sel;
-               return rdev->desc->ops->list_voltage(rdev, sel);
+               ret = rdev->desc->ops->list_voltage(rdev, sel);
        }
        if (rdev->desc->ops->get_voltage)
-               return rdev->desc->ops->get_voltage(rdev);
+               ret = rdev->desc->ops->get_voltage(rdev);
        else
                return -EINVAL;
+
+       return ret - rdev->constraints->uV_offset;
 }
 
 /**
index 8f1a55d9949494d191460d068df721b9d119a872..ce3127a75c8866a27afeeb875bd5943c2dc61976 100644 (file)
@@ -68,6 +68,8 @@ struct regulator_state {
  *
  * @min_uV: Smallest voltage consumers may set.
  * @max_uV: Largest voltage consumers may set.
+ * @uV_offset: Offset applied to voltages from consumer to compensate for
+ *             voltage drops.
  *
  * @min_uA: Smallest consumers consumers may set.
  * @max_uA: Largest current consumers may set.
@@ -99,6 +101,8 @@ struct regulation_constraints {
        int min_uV;
        int max_uV;
 
+       int uV_offset;
+
        /* current output range (inclusive) - for current control */
        int min_uA;
        int max_uA;