diff options
Diffstat (limited to 'drivers/regulator')
-rw-r--r-- | drivers/regulator/max8998.c | 29 |
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, ®, &shift, &mask); | 326 | ret = max8998_get_voltage_register(rdev, ®, &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 | ||
326 | static struct regulator_ops max8998_ldo_ops = { | 351 | static struct regulator_ops max8998_ldo_ops = { |