Commit 8db98440 authored by Axel Lin's avatar Axel Lin Committed by Mark Brown

regulator: mc13892: Simplify implementation of mc13892_sw_regulator_set_voltage_sel()

Use mc13xxx_reg_rmw rather than a mc13xxx_reg_read and a mc13xxx_reg_write calls.

This logic to set MC13892_SWITCHERS0_SWxHI bit is pretty simple:

if (volt > 1375000)
        set MC13892_SWITCHERS0_SWxHI bit
else if (volt < 1100000)
        clear MC13892_SWITCHERS0_SWxHI bit
else
        leave MC13892_SWITCHERS0_SWxHI bit untouched

We already know the selector, so we don't need to calculate the selector again.
Signed-off-by: default avatarAxel Lin <axel.lin@gmail.com>
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent 825d1059
...@@ -426,37 +426,25 @@ static int mc13892_sw_regulator_set_voltage_sel(struct regulator_dev *rdev, ...@@ -426,37 +426,25 @@ static int mc13892_sw_regulator_set_voltage_sel(struct regulator_dev *rdev,
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 volt, mask, id = rdev_get_id(rdev);
u32 valread; u32 reg_value;
int ret; int ret;
value = rdev->desc->volt_table[selector]; volt = rdev->desc->volt_table[selector];
mask = mc13892_regulators[id].vsel_mask;
reg_value = selector << mc13892_regulators[id].vsel_shift;
mc13xxx_lock(priv->mc13xxx); if (volt > 1375000) {
ret = mc13xxx_reg_read(priv->mc13xxx, mask |= MC13892_SWITCHERS0_SWxHI;
mc13892_regulators[id].vsel_reg, &valread); reg_value |= MC13892_SWITCHERS0_SWxHI;
if (ret) } else if (volt < 1100000) {
goto err; mask |= MC13892_SWITCHERS0_SWxHI;
reg_value &= ~MC13892_SWITCHERS0_SWxHI;
}
if (value > 1375000) mc13xxx_lock(priv->mc13xxx);
hi = 1; ret = mc13xxx_reg_rmw(priv->mc13xxx, mc13892_regulators[id].reg, mask,
else if (value < 1100000) reg_value);
hi = 0;
else
hi = valread & MC13892_SWITCHERS0_SWxHI;
if (hi) {
value = (value - 1100000) / 25000;
value |= MC13892_SWITCHERS0_SWxHI;
} else
value = (value - 600000) / 25000;
mask = mc13892_regulators[id].vsel_mask | MC13892_SWITCHERS0_SWxHI;
valread = (valread & ~mask) |
(value << mc13892_regulators[id].vsel_shift);
ret = mc13xxx_reg_write(priv->mc13xxx, mc13892_regulators[id].vsel_reg,
valread);
err:
mc13xxx_unlock(priv->mc13xxx); mc13xxx_unlock(priv->mc13xxx);
return ret; return ret;
......
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