提交 e79055d6 编写于 作者: M Mark Brown 提交者: Liam Girdwood

regulator: Factor out voltage constraint setup

This allows constraints to take effect on regulators that support
voltage setting but for which the board does not specify a voltage
range (for example, because it is fixed correctly at system startup).
Signed-off-by: NMark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: NLiam Girdwood <lrg@slimlogic.co.uk>
上级 5b307627
...@@ -672,31 +672,11 @@ static void print_constraints(struct regulator_dev *rdev) ...@@ -672,31 +672,11 @@ static void print_constraints(struct regulator_dev *rdev)
printk(KERN_INFO "regulator: %s: %s\n", rdev->desc->name, buf); printk(KERN_INFO "regulator: %s: %s\n", rdev->desc->name, buf);
} }
/** static int machine_constraints_voltage(struct regulator_dev *rdev,
* set_machine_constraints - sets regulator constraints const char *name, struct regulation_constraints *constraints)
* @rdev: regulator source
* @constraints: constraints to apply
*
* Allows platform initialisation code to define and constrain
* regulator circuits e.g. valid voltage/current ranges, etc. NOTE:
* Constraints *must* be set by platform code in order for some
* regulator operations to proceed i.e. set_voltage, set_current_limit,
* set_mode.
*/
static int set_machine_constraints(struct regulator_dev *rdev,
struct regulation_constraints *constraints)
{ {
int ret = 0;
const char *name;
struct regulator_ops *ops = rdev->desc->ops; struct regulator_ops *ops = rdev->desc->ops;
if (constraints->name)
name = constraints->name;
else if (rdev->desc->name)
name = rdev->desc->name;
else
name = "regulator";
/* constrain machine-level voltage specs to fit /* constrain machine-level voltage specs to fit
* the actual range supported by this regulator. * the actual range supported by this regulator.
*/ */
...@@ -719,14 +699,13 @@ static int set_machine_constraints(struct regulator_dev *rdev, ...@@ -719,14 +699,13 @@ static int set_machine_constraints(struct regulator_dev *rdev,
/* voltage constraints are optional */ /* voltage constraints are optional */
if ((cmin == 0) && (cmax == 0)) if ((cmin == 0) && (cmax == 0))
goto out; return 0;
/* else require explicit machine-level constraints */ /* else require explicit machine-level constraints */
if (cmin <= 0 || cmax <= 0 || cmax < cmin) { if (cmin <= 0 || cmax <= 0 || cmax < cmin) {
pr_err("%s: %s '%s' voltage constraints\n", pr_err("%s: %s '%s' voltage constraints\n",
__func__, "invalid", name); __func__, "invalid", name);
ret = -EINVAL; return -EINVAL;
goto out;
} }
/* initial: [cmin..cmax] valid, [min_uV..max_uV] not */ /* initial: [cmin..cmax] valid, [min_uV..max_uV] not */
...@@ -748,8 +727,7 @@ static int set_machine_constraints(struct regulator_dev *rdev, ...@@ -748,8 +727,7 @@ static int set_machine_constraints(struct regulator_dev *rdev,
if (max_uV < min_uV) { if (max_uV < min_uV) {
pr_err("%s: %s '%s' voltage constraints\n", pr_err("%s: %s '%s' voltage constraints\n",
__func__, "unsupportable", name); __func__, "unsupportable", name);
ret = -EINVAL; return -EINVAL;
goto out;
} }
/* use regulator's subset of machine constraints */ /* use regulator's subset of machine constraints */
...@@ -767,6 +745,38 @@ static int set_machine_constraints(struct regulator_dev *rdev, ...@@ -767,6 +745,38 @@ static int set_machine_constraints(struct regulator_dev *rdev,
} }
} }
return 0;
}
/**
* set_machine_constraints - sets regulator constraints
* @rdev: regulator source
* @constraints: constraints to apply
*
* Allows platform initialisation code to define and constrain
* regulator circuits e.g. valid voltage/current ranges, etc. NOTE:
* Constraints *must* be set by platform code in order for some
* regulator operations to proceed i.e. set_voltage, set_current_limit,
* set_mode.
*/
static int set_machine_constraints(struct regulator_dev *rdev,
struct regulation_constraints *constraints)
{
int ret = 0;
const char *name;
struct regulator_ops *ops = rdev->desc->ops;
if (constraints->name)
name = constraints->name;
else if (rdev->desc->name)
name = rdev->desc->name;
else
name = "regulator";
ret = machine_constraints_voltage(rdev, name, constraints);
if (ret != 0)
goto out;
rdev->constraints = constraints; rdev->constraints = constraints;
/* do we need to apply the constraint voltage */ /* do we need to apply the constraint voltage */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册