mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-26 10:49:33 +00:00
regulator: Provide a selector based set_voltage_sel() operation
Many regulator drivers implement voltage setting by looping through a table of possible values, normally because the set of available voltages can't be mapped onto selectors with simple calcuation. Factor out these loops by providing a variant of set_voltage() which takes a selector rather than a voltage range as an argument and implementing a loop through the available selectors in the core. This is not going to be suitable for use with all devices as when the regulator voltage can be mapped onto selector values with a simple calculation the linear scan through the available values will be more expensive than just doing the calculation, especially for regulators that provide fine grained voltage control. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>
This commit is contained in:
parent
7579025130
commit
e8eef82b2c
2 changed files with 38 additions and 2 deletions
|
@ -1637,6 +1637,32 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev,
|
||||||
selector);
|
selector);
|
||||||
else
|
else
|
||||||
selector = -1;
|
selector = -1;
|
||||||
|
} else if (rdev->desc->ops->set_voltage_sel) {
|
||||||
|
int best_val = INT_MAX;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
selector = 0;
|
||||||
|
|
||||||
|
/* Find the smallest voltage that falls within the specified
|
||||||
|
* range.
|
||||||
|
*/
|
||||||
|
for (i = 0; i < rdev->desc->n_voltages; i++) {
|
||||||
|
ret = rdev->desc->ops->list_voltage(rdev, i);
|
||||||
|
if (ret < 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (ret < best_val && ret >= min_uV && ret <= max_uV) {
|
||||||
|
best_val = ret;
|
||||||
|
selector = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (best_val != INT_MAX) {
|
||||||
|
ret = rdev->desc->ops->set_voltage_sel(rdev, selector);
|
||||||
|
selector = best_val;
|
||||||
|
} else {
|
||||||
|
ret = -EINVAL;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -1672,7 +1698,8 @@ int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV)
|
||||||
mutex_lock(&rdev->mutex);
|
mutex_lock(&rdev->mutex);
|
||||||
|
|
||||||
/* sanity check */
|
/* sanity check */
|
||||||
if (!rdev->desc->ops->set_voltage) {
|
if (!rdev->desc->ops->set_voltage &&
|
||||||
|
!rdev->desc->ops->set_voltage_sel) {
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -2256,7 +2283,7 @@ static int add_regulator_attributes(struct regulator_dev *rdev)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
/* constraints need specific supporting methods */
|
/* constraints need specific supporting methods */
|
||||||
if (ops->set_voltage) {
|
if (ops->set_voltage || ops->set_voltage_sel) {
|
||||||
status = device_create_file(dev, &dev_attr_min_microvolts);
|
status = device_create_file(dev, &dev_attr_min_microvolts);
|
||||||
if (status < 0)
|
if (status < 0)
|
||||||
return status;
|
return status;
|
||||||
|
@ -2354,12 +2381,18 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
|
||||||
/* Only one of each should be implemented */
|
/* Only one of each should be implemented */
|
||||||
WARN_ON(regulator_desc->ops->get_voltage &&
|
WARN_ON(regulator_desc->ops->get_voltage &&
|
||||||
regulator_desc->ops->get_voltage_sel);
|
regulator_desc->ops->get_voltage_sel);
|
||||||
|
WARN_ON(regulator_desc->ops->set_voltage &&
|
||||||
|
regulator_desc->ops->set_voltage_sel);
|
||||||
|
|
||||||
/* If we're using selectors we must implement list_voltage. */
|
/* If we're using selectors we must implement list_voltage. */
|
||||||
if (regulator_desc->ops->get_voltage_sel &&
|
if (regulator_desc->ops->get_voltage_sel &&
|
||||||
!regulator_desc->ops->list_voltage) {
|
!regulator_desc->ops->list_voltage) {
|
||||||
return ERR_PTR(-EINVAL);
|
return ERR_PTR(-EINVAL);
|
||||||
}
|
}
|
||||||
|
if (regulator_desc->ops->set_voltage_sel &&
|
||||||
|
!regulator_desc->ops->list_voltage) {
|
||||||
|
return ERR_PTR(-EINVAL);
|
||||||
|
}
|
||||||
|
|
||||||
rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL);
|
rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL);
|
||||||
if (rdev == NULL)
|
if (rdev == NULL)
|
||||||
|
|
|
@ -42,6 +42,8 @@ enum regulator_status {
|
||||||
*
|
*
|
||||||
* @set_voltage: Set the voltage for the regulator within the range specified.
|
* @set_voltage: Set the voltage for the regulator within the range specified.
|
||||||
* The driver should select the voltage closest to min_uV.
|
* The driver should select the voltage closest to min_uV.
|
||||||
|
* @set_voltage_sel: Set the voltage for the regulator using the specified
|
||||||
|
* selector.
|
||||||
* @get_voltage: Return the currently configured voltage for the regulator.
|
* @get_voltage: Return the currently configured voltage for the regulator.
|
||||||
* @get_voltage_sel: Return the currently configured voltage selector for the
|
* @get_voltage_sel: Return the currently configured voltage selector for the
|
||||||
* regulator.
|
* regulator.
|
||||||
|
@ -83,6 +85,7 @@ struct regulator_ops {
|
||||||
/* get/set regulator voltage */
|
/* get/set regulator voltage */
|
||||||
int (*set_voltage) (struct regulator_dev *, int min_uV, int max_uV,
|
int (*set_voltage) (struct regulator_dev *, int min_uV, int max_uV,
|
||||||
unsigned *selector);
|
unsigned *selector);
|
||||||
|
int (*set_voltage_sel) (struct regulator_dev *, unsigned selector);
|
||||||
int (*get_voltage) (struct regulator_dev *);
|
int (*get_voltage) (struct regulator_dev *);
|
||||||
int (*get_voltage_sel) (struct regulator_dev *);
|
int (*get_voltage_sel) (struct regulator_dev *);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue