Commit 9a2372fa authored by Mark Brown's avatar Mark Brown Committed by Liam Girdwood

regulator: regulator_enable() permission checking

The regulator_enable() code wasn't actually checking that the
machine constraints had given permission to enable the regulator.
Add code to do that, but only if the regulator is not already on
due to something like always_on or being left on at startup since
in those cases there's no physical change being introduced and the
constraint wouldn't make any sense.

Also add matching code for disable(). We need to do less there since
either regulator_enable() should have succeeded first or the board
setup makes no sense.
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: default avatarLiam Girdwood <lrg@slimlogic.co.uk>
parent 9332546f
...@@ -1191,16 +1191,21 @@ void regulator_put(struct regulator *regulator) ...@@ -1191,16 +1191,21 @@ void regulator_put(struct regulator *regulator)
} }
EXPORT_SYMBOL_GPL(regulator_put); EXPORT_SYMBOL_GPL(regulator_put);
static int _regulator_can_change_status(struct regulator_dev *rdev)
{
if (!rdev->constraints)
return 0;
if (rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_STATUS)
return 1;
else
return 0;
}
/* locks held by regulator_enable() */ /* locks held by regulator_enable() */
static int _regulator_enable(struct regulator_dev *rdev) static int _regulator_enable(struct regulator_dev *rdev)
{ {
int ret = -EINVAL; int ret;
if (!rdev->constraints) {
printk(KERN_ERR "%s: %s has no constraints\n",
__func__, rdev->desc->name);
return ret;
}
/* do we need to enable the supply regulator first */ /* do we need to enable the supply regulator first */
if (rdev->supply) { if (rdev->supply) {
...@@ -1213,24 +1218,34 @@ static int _regulator_enable(struct regulator_dev *rdev) ...@@ -1213,24 +1218,34 @@ static int _regulator_enable(struct regulator_dev *rdev)
} }
/* check voltage and requested load before enabling */ /* check voltage and requested load before enabling */
if (rdev->desc->ops->enable) { if (rdev->constraints &&
(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS))
drms_uA_update(rdev);
if (rdev->constraints && if (rdev->use_count == 0) {
(rdev->constraints->valid_ops_mask & /* The regulator may on if it's not switchable or left on */
REGULATOR_CHANGE_DRMS)) ret = _regulator_is_enabled(rdev);
drms_uA_update(rdev); if (ret == -EINVAL || ret == 0) {
if (!_regulator_can_change_status(rdev))
ret = rdev->desc->ops->enable(rdev); return -EPERM;
if (ret < 0) {
printk(KERN_ERR "%s: failed to enable %s: %d\n", if (rdev->desc->ops->enable) {
ret = rdev->desc->ops->enable(rdev);
if (ret < 0)
return ret;
} else {
return -EINVAL;
}
} else {
printk(KERN_ERR "%s: is_enabled() failed for %s: %d\n",
__func__, rdev->desc->name, ret); __func__, rdev->desc->name, ret);
return ret; return ret;
} }
rdev->use_count++;
return ret;
} }
return ret; rdev->use_count++;
return 0;
} }
/** /**
...@@ -1270,7 +1285,8 @@ static int _regulator_disable(struct regulator_dev *rdev) ...@@ -1270,7 +1285,8 @@ static int _regulator_disable(struct regulator_dev *rdev)
if (rdev->use_count == 1 && !rdev->constraints->always_on) { if (rdev->use_count == 1 && !rdev->constraints->always_on) {
/* we are last user */ /* we are last user */
if (rdev->desc->ops->disable) { if (_regulator_can_change_status(rdev) &&
rdev->desc->ops->disable) {
ret = rdev->desc->ops->disable(rdev); ret = rdev->desc->ops->disable(rdev);
if (ret < 0) { if (ret < 0) {
printk(KERN_ERR "%s: failed to disable %s\n", printk(KERN_ERR "%s: failed to disable %s\n",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment