From 9d92492fb753f01caa31dc502f69c189c0c22ad0 Mon Sep 17 00:00:00 2001 From: Lukasz Majewski Date: Mon, 27 Sep 2010 14:32:23 +0200 Subject: regulator: Separate set_voltage for max8998 ldo and buck Signed-off-by: Lukasz Majewski Signed-off-by: Kyungmin Park Acked-by: Mark Brown Acked-by: Liam Girdwood Signed-off-by: Samuel Ortiz --- drivers/regulator/max8998.c | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) (limited to 'drivers') diff --git a/drivers/regulator/max8998.c b/drivers/regulator/max8998.c index 7f5fe6f198cf..1e5bd504fbad 100644 --- a/drivers/regulator/max8998.c +++ b/drivers/regulator/max8998.c @@ -297,7 +297,44 @@ static int max8998_get_voltage(struct regulator_dev *rdev) return max8998_list_voltage(rdev, val); } -static int max8998_set_voltage(struct regulator_dev *rdev, +static int max8998_set_voltage_ldo(struct regulator_dev *rdev, + int min_uV, int max_uV) +{ + struct max8998_data *max8998 = rdev_get_drvdata(rdev); + struct i2c_client *i2c = max8998->iodev->i2c; + int min_vol = min_uV / 1000, max_vol = max_uV / 1000; + const struct voltage_map_desc *desc; + int ldo = max8998_get_ldo(rdev); + int reg, shift = 0, mask, ret; + int i = 0; + + if (ldo >= ARRAY_SIZE(ldo_voltage_map)) + return -EINVAL; + + desc = ldo_voltage_map[ldo]; + if (desc == NULL) + return -EINVAL; + + if (max_vol < desc->min || min_vol > desc->max) + return -EINVAL; + + while (desc->min + desc->step*i < min_vol && + desc->min + desc->step*i < desc->max) + i++; + + if (desc->min + desc->step*i > max_vol) + return -EINVAL; + + ret = max8998_get_voltage_register(rdev, ®, &shift, &mask); + if (ret) + return ret; + + ret = max8998_update_reg(i2c, reg, i<