regulator: Convert rc5t583 to set_voltage
authorAxel Lin <axel.lin@gmail.com>
Thu, 5 Apr 2012 06:07:36 +0000 (14:07 +0800)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Fri, 6 Apr 2012 17:32:23 +0000 (18:32 +0100)
Not every regulator driver should implement set_voltage_sel callback.
See commit e8eef82
"regulator: Provide a selector based set_voltage_sel() operation".

For rc5t583, the regulator voltage can be mapped onto selector values with a
simple calculation, thus implement set_voltage is better than set_voltage_sel.

Signed-off-by: Axel Lin <axel.lin@gmail.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
drivers/regulator/rc5t583-regulator.c

index 7e9c14affa5ea55c1858c24ebd7766923a207cd0..fe094a6140d908f7b20bb41da3b2d43b2a659484 100644 (file)
@@ -124,19 +124,26 @@ static int rc5t583_list_voltage(struct regulator_dev *rdev, unsigned selector)
        return ri->min_uV + (ri->step_uV * selector);
 }
 
-static int rc5t583_set_voltage_sel(struct regulator_dev *rdev,
-               unsigned int selector)
+static int rc5t583_set_voltage(struct regulator_dev *rdev,
+                              int min_uV, int max_uV, unsigned *selector)
 {
        struct rc5t583_regulator *reg = rdev_get_drvdata(rdev);
        struct rc5t583_regulator_info *ri = reg->reg_info;
-       int ret;
-       if (selector >= rdev->desc->n_voltages) {
-               dev_err(&rdev->dev, "Invalid selector 0x%02x\n", selector);
+       int sel, ret;
+
+       if (min_uV < ri->min_uV)
+               min_uV = ri->min_uV;
+
+       sel = DIV_ROUND_UP(min_uV - ri->min_uV, ri->step_uV);
+
+       if (sel >= rdev->desc->n_voltages) {
+               dev_err(&rdev->dev, "Invalid selector 0x%02x\n", sel);
                return -EINVAL;
        }
 
-       ret = rc5t583_update(reg->mfd->dev, ri->vout_reg,
-                               selector, ri->vout_mask);
+       *selector = sel;
+
+       ret = rc5t583_update(reg->mfd->dev, ri->vout_reg, sel, ri->vout_mask);
        if (ret < 0)
                dev_err(&rdev->dev,
                    "Error in update voltage register 0x%02x\n", ri->vout_reg);
@@ -191,7 +198,7 @@ static struct regulator_ops rc5t583_ops = {
        .disable                = rc5t583_reg_disable,
        .enable_time            = rc5t583_regulator_enable_time,
        .get_voltage_sel        = rc5t583_get_voltage_sel,
-       .set_voltage_sel        = rc5t583_set_voltage_sel,
+       .set_voltage            = rc5t583_set_voltage,
        .list_voltage           = rc5t583_list_voltage,
        .set_voltage_time_sel   = rc5t583_set_voltage_time_sel,
 };