Commit 939b62d8 authored by Axel Lin's avatar Axel Lin Committed by Mark Brown

regulator: Convert mc13xxx regulator drivers to set_voltage_sel

Convert mc13892_sw_regulator_ops and mc13xxx_regulator_ops to set_voltage_sel.
mc13xxx_get_best_voltage_index function is not used now, remove it.
Signed-off-by: default avatarAxel Lin <axel.lin@gmail.com>
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent a4d9f179
...@@ -428,24 +428,15 @@ static int mc13892_sw_regulator_get_voltage(struct regulator_dev *rdev) ...@@ -428,24 +428,15 @@ static int mc13892_sw_regulator_get_voltage(struct regulator_dev *rdev)
return val; return val;
} }
static int mc13892_sw_regulator_set_voltage(struct regulator_dev *rdev, static int mc13892_sw_regulator_set_voltage_sel(struct regulator_dev *rdev,
int min_uV, int max_uV, unsigned *selector) unsigned selector)
{ {
struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev); struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
int hi, value, mask, id = rdev_get_id(rdev); int hi, value, mask, id = rdev_get_id(rdev);
u32 valread; u32 valread;
int ret; int ret;
dev_dbg(rdev_get_dev(rdev), "%s id: %d min_uV: %d max_uV: %d\n", value = mc13892_regulators[id].voltages[selector];
__func__, id, min_uV, max_uV);
/* Find the best index */
value = mc13xxx_get_best_voltage_index(rdev, min_uV, max_uV);
dev_dbg(rdev_get_dev(rdev), "%s best value: %d\n", __func__, value);
if (value < 0)
return value;
value = mc13892_regulators[id].voltages[value];
mc13xxx_lock(priv->mc13xxx); mc13xxx_lock(priv->mc13xxx);
ret = mc13xxx_reg_read(priv->mc13xxx, ret = mc13xxx_reg_read(priv->mc13xxx,
...@@ -480,7 +471,7 @@ static int mc13892_sw_regulator_set_voltage(struct regulator_dev *rdev, ...@@ -480,7 +471,7 @@ static int mc13892_sw_regulator_set_voltage(struct regulator_dev *rdev,
static struct regulator_ops mc13892_sw_regulator_ops = { static struct regulator_ops mc13892_sw_regulator_ops = {
.is_enabled = mc13xxx_sw_regulator_is_enabled, .is_enabled = mc13xxx_sw_regulator_is_enabled,
.list_voltage = mc13xxx_regulator_list_voltage, .list_voltage = mc13xxx_regulator_list_voltage,
.set_voltage = mc13892_sw_regulator_set_voltage, .set_voltage_sel = mc13892_sw_regulator_set_voltage_sel,
.get_voltage = mc13892_sw_regulator_get_voltage, .get_voltage = mc13892_sw_regulator_get_voltage,
}; };
......
...@@ -94,62 +94,18 @@ int mc13xxx_regulator_list_voltage(struct regulator_dev *rdev, ...@@ -94,62 +94,18 @@ int mc13xxx_regulator_list_voltage(struct regulator_dev *rdev,
} }
EXPORT_SYMBOL_GPL(mc13xxx_regulator_list_voltage); EXPORT_SYMBOL_GPL(mc13xxx_regulator_list_voltage);
int mc13xxx_get_best_voltage_index(struct regulator_dev *rdev, static int mc13xxx_regulator_set_voltage_sel(struct regulator_dev *rdev,
int min_uV, int max_uV) unsigned selector)
{ {
struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev); struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators; struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
int reg_id = rdev_get_id(rdev); int id = rdev_get_id(rdev);
int i;
int bestmatch;
int bestindex;
/*
* Locate the minimum voltage fitting the criteria on
* this regulator. The switchable voltages are not
* in strict falling order so we need to check them
* all for the best match.
*/
bestmatch = INT_MAX;
bestindex = -1;
for (i = 0; i < mc13xxx_regulators[reg_id].desc.n_voltages; i++) {
if (mc13xxx_regulators[reg_id].voltages[i] >= min_uV &&
mc13xxx_regulators[reg_id].voltages[i] < bestmatch) {
bestmatch = mc13xxx_regulators[reg_id].voltages[i];
bestindex = i;
}
}
if (bestindex < 0 || bestmatch > max_uV) {
dev_warn(&rdev->dev, "no possible value for %d<=x<=%d uV\n",
min_uV, max_uV);
return -EINVAL;
}
return bestindex;
}
EXPORT_SYMBOL_GPL(mc13xxx_get_best_voltage_index);
static int mc13xxx_regulator_set_voltage(struct regulator_dev *rdev, int min_uV,
int max_uV, unsigned *selector)
{
struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators;
int value, id = rdev_get_id(rdev);
int ret; int ret;
dev_dbg(rdev_get_dev(rdev), "%s id: %d min_uV: %d max_uV: %d\n",
__func__, id, min_uV, max_uV);
/* Find the best index */
value = mc13xxx_get_best_voltage_index(rdev, min_uV, max_uV);
dev_dbg(rdev_get_dev(rdev), "%s best value: %d\n", __func__, value);
if (value < 0)
return value;
mc13xxx_lock(priv->mc13xxx); mc13xxx_lock(priv->mc13xxx);
ret = mc13xxx_reg_rmw(priv->mc13xxx, mc13xxx_regulators[id].vsel_reg, ret = mc13xxx_reg_rmw(priv->mc13xxx, mc13xxx_regulators[id].vsel_reg,
mc13xxx_regulators[id].vsel_mask, mc13xxx_regulators[id].vsel_mask,
value << mc13xxx_regulators[id].vsel_shift); selector << mc13xxx_regulators[id].vsel_shift);
mc13xxx_unlock(priv->mc13xxx); mc13xxx_unlock(priv->mc13xxx);
return ret; return ret;
...@@ -187,7 +143,7 @@ struct regulator_ops mc13xxx_regulator_ops = { ...@@ -187,7 +143,7 @@ struct regulator_ops mc13xxx_regulator_ops = {
.disable = mc13xxx_regulator_disable, .disable = mc13xxx_regulator_disable,
.is_enabled = mc13xxx_regulator_is_enabled, .is_enabled = mc13xxx_regulator_is_enabled,
.list_voltage = mc13xxx_regulator_list_voltage, .list_voltage = mc13xxx_regulator_list_voltage,
.set_voltage = mc13xxx_regulator_set_voltage, .set_voltage_sel = mc13xxx_regulator_set_voltage_sel,
.get_voltage = mc13xxx_regulator_get_voltage, .get_voltage = mc13xxx_regulator_get_voltage,
}; };
EXPORT_SYMBOL_GPL(mc13xxx_regulator_ops); EXPORT_SYMBOL_GPL(mc13xxx_regulator_ops);
......
...@@ -35,8 +35,6 @@ struct mc13xxx_regulator_priv { ...@@ -35,8 +35,6 @@ struct mc13xxx_regulator_priv {
extern int mc13xxx_sw_regulator(struct regulator_dev *rdev); extern int mc13xxx_sw_regulator(struct regulator_dev *rdev);
extern int mc13xxx_sw_regulator_is_enabled(struct regulator_dev *rdev); extern int mc13xxx_sw_regulator_is_enabled(struct regulator_dev *rdev);
extern int mc13xxx_get_best_voltage_index(struct regulator_dev *rdev,
int min_uV, int max_uV);
extern int mc13xxx_regulator_list_voltage(struct regulator_dev *rdev, extern int mc13xxx_regulator_list_voltage(struct regulator_dev *rdev,
unsigned selector); unsigned selector);
extern int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev, extern int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev,
......
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