aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator
diff options
context:
space:
mode:
authorMyungJoo Ham <myungjoo.ham@samsung.com>2010-07-20 02:07:07 -0400
committerLiam Girdwood <lrg@slimlogic.co.uk>2010-08-11 06:38:01 -0400
commitc5a4655db9e0b5e49a0b17e1bf96462e93e3c326 (patch)
treede2afadd98d171248fc0f2a2edb4760f44470b29 /drivers/regulator
parentc789ca202cae5adfab0208e7e8becbc602e5d079 (diff)
regulator: MAX8998: set_voltage bugfix. ramp_up delay and min/max voltage
Two issues are addressed for max8998_set_voltage function. 1. Min/Max Voltage. max8998_set_voltage had been using the voltage value of min ( voltage[i] >= max_vol , i ) This is corrected to use: min ( voltage[i] >= min_vol , i ) 2. Ramp Up Delay. max8998_set_voltage should provide delay for BUCK1/2 if ENRAMP is on. It reads RAMP value from ONOFF4 register to determine RAMP delay length. However, when max8998_set_voltage's new voltage is lower than the previous, we don't care because it does not deteriorate the stability. Changes since v1: - rebased onto latest regulator-for-next tree Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com> Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>
Diffstat (limited to 'drivers/regulator')
-rw-r--r--drivers/regulator/max8998.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/drivers/regulator/max8998.c b/drivers/regulator/max8998.c
index 174fd1957ae4..03e55a18a2ad 100644
--- a/drivers/regulator/max8998.c
+++ b/drivers/regulator/max8998.c
@@ -28,6 +28,7 @@
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/interrupt.h> 29#include <linux/interrupt.h>
30#include <linux/mutex.h> 30#include <linux/mutex.h>
31#include <linux/delay.h>
31#include <linux/platform_device.h> 32#include <linux/platform_device.h>
32#include <linux/regulator/driver.h> 33#include <linux/regulator/driver.h>
33#include <linux/mfd/max8998.h> 34#include <linux/mfd/max8998.h>
@@ -297,10 +298,13 @@ static int max8998_set_voltage(struct regulator_dev *rdev,
297{ 298{
298 struct max8998_data *max8998 = rdev_get_drvdata(rdev); 299 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
299 int min_vol = min_uV / 1000, max_vol = max_uV / 1000; 300 int min_vol = min_uV / 1000, max_vol = max_uV / 1000;
301 int previous_vol = 0;
300 const struct voltage_map_desc *desc; 302 const struct voltage_map_desc *desc;
301 int ldo = max8998_get_ldo(rdev); 303 int ldo = max8998_get_ldo(rdev);
302 int reg, shift = 0, mask, ret; 304 int reg, shift = 0, mask, ret;
303 int i = 0; 305 int i = 0;
306 u8 val;
307 bool en_ramp = false;
304 308
305 if (ldo > ARRAY_SIZE(ldo_voltage_map)) 309 if (ldo > ARRAY_SIZE(ldo_voltage_map))
306 return -EINVAL; 310 return -EINVAL;
@@ -312,15 +316,36 @@ static int max8998_set_voltage(struct regulator_dev *rdev,
312 if (max_vol < desc->min || min_vol > desc->max) 316 if (max_vol < desc->min || min_vol > desc->max)
313 return -EINVAL; 317 return -EINVAL;
314 318
315 while (desc->min + desc->step*i < max_vol && 319 while (desc->min + desc->step*i < min_vol &&
316 desc->min + desc->step*i < desc->max) 320 desc->min + desc->step*i < desc->max)
317 i++; 321 i++;
318 322
323 if (desc->min + desc->step*i > max_vol)
324 return -EINVAL;
325
319 ret = max8998_get_voltage_register(rdev, &reg, &shift, &mask); 326 ret = max8998_get_voltage_register(rdev, &reg, &shift, &mask);
320 if (ret) 327 if (ret)
321 return ret; 328 return ret;
322 329
323 return max8998_update_reg(max8998->iodev, reg, i<<shift, mask<<shift); 330 /* wait for RAMP_UP_DELAY if rdev is BUCK1/2 and
331 * ENRAMP is ON */
332 if (ldo == MAX8998_BUCK1 || ldo == MAX8998_BUCK2) {
333 max8998_read_reg(max8998->iodev, MAX8998_REG_ONOFF4, &val);
334 if (val & (1 << 4)) {
335 en_ramp = true;
336 previous_vol = max8998_get_voltage(rdev);
337 }
338 }
339
340 ret = max8998_update_reg(max8998->iodev, reg, i<<shift, mask<<shift);
341
342 if (en_ramp == true) {
343 int difference = desc->min + desc->step*i - previous_vol/1000;
344 if (difference > 0)
345 udelay(difference / ((val & 0x0f) + 1));
346 }
347
348 return ret;
324} 349}
325 350
326static struct regulator_ops max8998_ldo_ops = { 351static struct regulator_ops max8998_ldo_ops = {