diff options
author | Axel Lin <axel.lin@ingics.com> | 2012-12-27 19:23:16 -0500 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2013-01-08 06:07:05 -0500 |
commit | c8c14a393ba3329552147870103f2d004bbcbcac (patch) | |
tree | 364a2ccd44ea20c1166a7469a5c6c73cf36a2b52 /drivers/regulator/lp3972.c | |
parent | d1c3ed669a2d452cacfb48c2d171a1f364dae2ed (diff) |
regulator: lp3972: Convert to get_voltage_sel
regulator_list_voltage_table() returns -EINVAL if selector >= n_voltages.
Thus we don't need to check if reg is greater than LP3972_BUCK_VOL_MAX_IDX in
lp3972_[ldo|dcdc]_get_voltage_sel.
LP3972_BUCK_VOL_MIN_IDX and LP3972_BUCK_VOL_MAX_IDX are not used, remove them.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator/lp3972.c')
-rw-r--r-- | drivers/regulator/lp3972.c | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/drivers/regulator/lp3972.c b/drivers/regulator/lp3972.c index 69c42c318b87..0baabcfb578a 100644 --- a/drivers/regulator/lp3972.c +++ b/drivers/regulator/lp3972.c | |||
@@ -165,8 +165,6 @@ static const int buck_base_addr[] = { | |||
165 | #define LP3972_BUCK_VOL_ENABLE_REG(x) (buck_vol_enable_addr[x]) | 165 | #define LP3972_BUCK_VOL_ENABLE_REG(x) (buck_vol_enable_addr[x]) |
166 | #define LP3972_BUCK_VOL1_REG(x) (buck_base_addr[x]) | 166 | #define LP3972_BUCK_VOL1_REG(x) (buck_base_addr[x]) |
167 | #define LP3972_BUCK_VOL_MASK 0x1f | 167 | #define LP3972_BUCK_VOL_MASK 0x1f |
168 | #define LP3972_BUCK_VOL_MIN_IDX(x) ((x) ? 0x01 : 0x00) | ||
169 | #define LP3972_BUCK_VOL_MAX_IDX(x) ((x) ? 0x19 : 0x1f) | ||
170 | 168 | ||
171 | static int lp3972_i2c_read(struct i2c_client *i2c, char reg, int count, | 169 | static int lp3972_i2c_read(struct i2c_client *i2c, char reg, int count, |
172 | u16 *dest) | 170 | u16 *dest) |
@@ -257,7 +255,7 @@ static int lp3972_ldo_disable(struct regulator_dev *dev) | |||
257 | mask, 0); | 255 | mask, 0); |
258 | } | 256 | } |
259 | 257 | ||
260 | static int lp3972_ldo_get_voltage(struct regulator_dev *dev) | 258 | static int lp3972_ldo_get_voltage_sel(struct regulator_dev *dev) |
261 | { | 259 | { |
262 | struct lp3972 *lp3972 = rdev_get_drvdata(dev); | 260 | struct lp3972 *lp3972 = rdev_get_drvdata(dev); |
263 | int ldo = rdev_get_id(dev) - LP3972_LDO1; | 261 | int ldo = rdev_get_id(dev) - LP3972_LDO1; |
@@ -267,7 +265,7 @@ static int lp3972_ldo_get_voltage(struct regulator_dev *dev) | |||
267 | reg = lp3972_reg_read(lp3972, LP3972_LDO_VOL_CONTR_REG(ldo)); | 265 | reg = lp3972_reg_read(lp3972, LP3972_LDO_VOL_CONTR_REG(ldo)); |
268 | val = (reg >> LP3972_LDO_VOL_CONTR_SHIFT(ldo)) & mask; | 266 | val = (reg >> LP3972_LDO_VOL_CONTR_SHIFT(ldo)) & mask; |
269 | 267 | ||
270 | return dev->desc->volt_table[val]; | 268 | return val; |
271 | } | 269 | } |
272 | 270 | ||
273 | static int lp3972_ldo_set_voltage_sel(struct regulator_dev *dev, | 271 | static int lp3972_ldo_set_voltage_sel(struct regulator_dev *dev, |
@@ -314,7 +312,7 @@ static struct regulator_ops lp3972_ldo_ops = { | |||
314 | .is_enabled = lp3972_ldo_is_enabled, | 312 | .is_enabled = lp3972_ldo_is_enabled, |
315 | .enable = lp3972_ldo_enable, | 313 | .enable = lp3972_ldo_enable, |
316 | .disable = lp3972_ldo_disable, | 314 | .disable = lp3972_ldo_disable, |
317 | .get_voltage = lp3972_ldo_get_voltage, | 315 | .get_voltage_sel = lp3972_ldo_get_voltage_sel, |
318 | .set_voltage_sel = lp3972_ldo_set_voltage_sel, | 316 | .set_voltage_sel = lp3972_ldo_set_voltage_sel, |
319 | }; | 317 | }; |
320 | 318 | ||
@@ -353,24 +351,16 @@ static int lp3972_dcdc_disable(struct regulator_dev *dev) | |||
353 | return val; | 351 | return val; |
354 | } | 352 | } |
355 | 353 | ||
356 | static int lp3972_dcdc_get_voltage(struct regulator_dev *dev) | 354 | static int lp3972_dcdc_get_voltage_sel(struct regulator_dev *dev) |
357 | { | 355 | { |
358 | struct lp3972 *lp3972 = rdev_get_drvdata(dev); | 356 | struct lp3972 *lp3972 = rdev_get_drvdata(dev); |
359 | int buck = rdev_get_id(dev) - LP3972_DCDC1; | 357 | int buck = rdev_get_id(dev) - LP3972_DCDC1; |
360 | u16 reg; | 358 | u16 reg; |
361 | int val; | ||
362 | 359 | ||
363 | reg = lp3972_reg_read(lp3972, LP3972_BUCK_VOL1_REG(buck)); | 360 | reg = lp3972_reg_read(lp3972, LP3972_BUCK_VOL1_REG(buck)); |
364 | reg &= LP3972_BUCK_VOL_MASK; | 361 | reg &= LP3972_BUCK_VOL_MASK; |
365 | if (reg <= LP3972_BUCK_VOL_MAX_IDX(buck)) | ||
366 | val = dev->desc->volt_table[reg]; | ||
367 | else { | ||
368 | val = 0; | ||
369 | dev_warn(&dev->dev, "chip reported incorrect voltage value." | ||
370 | " reg = %d\n", reg); | ||
371 | } | ||
372 | 362 | ||
373 | return val; | 363 | return reg; |
374 | } | 364 | } |
375 | 365 | ||
376 | static int lp3972_dcdc_set_voltage_sel(struct regulator_dev *dev, | 366 | static int lp3972_dcdc_set_voltage_sel(struct regulator_dev *dev, |
@@ -402,7 +392,7 @@ static struct regulator_ops lp3972_dcdc_ops = { | |||
402 | .is_enabled = lp3972_dcdc_is_enabled, | 392 | .is_enabled = lp3972_dcdc_is_enabled, |
403 | .enable = lp3972_dcdc_enable, | 393 | .enable = lp3972_dcdc_enable, |
404 | .disable = lp3972_dcdc_disable, | 394 | .disable = lp3972_dcdc_disable, |
405 | .get_voltage = lp3972_dcdc_get_voltage, | 395 | .get_voltage_sel = lp3972_dcdc_get_voltage_sel, |
406 | .set_voltage_sel = lp3972_dcdc_set_voltage_sel, | 396 | .set_voltage_sel = lp3972_dcdc_set_voltage_sel, |
407 | }; | 397 | }; |
408 | 398 | ||