diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-05-21 19:49:16 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-05-21 19:49:16 -0400 |
commit | ac1806572df55b6125ad9d117906820dacfa3145 (patch) | |
tree | 6831707507d54e20d561a6403d2ff3e8469909ce /drivers/regulator | |
parent | ae82a8282031e3c31a4f68c5381ee459e42908f8 (diff) | |
parent | 84df8c1241beb87fec73415ef4f6e627aca34835 (diff) |
Merge tag 'regulator-3.5' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator
Pull regulator updates from Mark Brown:
"The major thing here is the addition of some helpers to factor code
out of drivers, making a fair proportion of regulators much more just
data rather than code which is nice.
- Helpers in the core for regulators using regmap, providing generic
implementations of the enable and voltage selection operations which
just need data to describe them in the drivers.
- Split out voltage mapping and voltage setting, allowing many more
drivers to take advantage of the infrastructure for selectors.
- Loads and loads of cleanups from Axel Lin once again, including many
changes to take advantage of the above new framework features
- New drivers for Ricoh RC5T583, TI TPS62362, TI TPS62363, TI
TPS65913, TI TWL6035 and TI TWL6037.
Some of the registration changes to support the core refactoring
caused so many conflicts that eventually topic branches were abandoned
for this release."
* tag 'regulator-3.5' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator: (227 commits)
regulator: tps65910: use of_node of matched regulator being register
regulator: tps65910: dt: support when "regulators" node found
regulator: tps65910: add error message in case of failure
regulator: tps62360: dt: initialize of_node param for regulator register.
regulator: tps65910: use devm_* for memory allocation
regulator: tps65910: use small letter for regulator names
mfd: tpx6586x: Depend on regulator
regulator: regulator for Palmas Kconfig
regulator: regulator driver for Palmas series chips
regulator: Enable Device Tree for the db8500-prcmu regulator driver
regulator: db8500-prcmu: Separate regulator registration from probe
regulator: ab3100: Use regulator_map_voltage_iterate()
regulator: tps65217: Convert to set_voltage_sel and map_voltage
regulator: Enable the ab8500 for Device Tree
regulator: ab8500: Split up probe() into manageable pieces
regulator: max8925: Remove check_range function and max_uV from struct rc5t583_regulator_info
regulator: max8649: Remove unused check_range() function
regulator: rc5t583: Remove max_uV from struct rc5t583_regulator_info
regulator: da9052: Convert to set_voltage_sel and map_voltage
regulator: max8952: Use devm_kzalloc
...
Diffstat (limited to 'drivers/regulator')
54 files changed, 3884 insertions, 3236 deletions
diff --git a/drivers/regulator/88pm8607.c b/drivers/regulator/88pm8607.c index 28b81ae4cf7f..c3482b954cb7 100644 --- a/drivers/regulator/88pm8607.c +++ b/drivers/regulator/88pm8607.c | |||
@@ -27,13 +27,8 @@ struct pm8607_regulator_info { | |||
27 | unsigned int *vol_table; | 27 | unsigned int *vol_table; |
28 | unsigned int *vol_suspend; | 28 | unsigned int *vol_suspend; |
29 | 29 | ||
30 | int vol_reg; | ||
31 | int vol_shift; | ||
32 | int vol_nbits; | ||
33 | int update_reg; | 30 | int update_reg; |
34 | int update_bit; | 31 | int update_bit; |
35 | int enable_reg; | ||
36 | int enable_bit; | ||
37 | int slope_double; | 32 | int slope_double; |
38 | }; | 33 | }; |
39 | 34 | ||
@@ -216,7 +211,7 @@ static int pm8607_list_voltage(struct regulator_dev *rdev, unsigned index) | |||
216 | struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); | 211 | struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); |
217 | int ret = -EINVAL; | 212 | int ret = -EINVAL; |
218 | 213 | ||
219 | if (info->vol_table && (index < (1 << info->vol_nbits))) { | 214 | if (info->vol_table && (index < rdev->desc->n_voltages)) { |
220 | ret = info->vol_table[index]; | 215 | ret = info->vol_table[index]; |
221 | if (info->slope_double) | 216 | if (info->slope_double) |
222 | ret <<= 1; | 217 | ret <<= 1; |
@@ -224,51 +219,16 @@ static int pm8607_list_voltage(struct regulator_dev *rdev, unsigned index) | |||
224 | return ret; | 219 | return ret; |
225 | } | 220 | } |
226 | 221 | ||
227 | static int choose_voltage(struct regulator_dev *rdev, int min_uV, int max_uV) | 222 | static int pm8607_set_voltage_sel(struct regulator_dev *rdev, unsigned selector) |
228 | { | 223 | { |
229 | struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); | 224 | struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); |
230 | int i, ret = -ENOENT; | 225 | uint8_t val; |
231 | |||
232 | if (info->slope_double) { | ||
233 | min_uV = min_uV >> 1; | ||
234 | max_uV = max_uV >> 1; | ||
235 | } | ||
236 | if (info->vol_table) { | ||
237 | for (i = 0; i < (1 << info->vol_nbits); i++) { | ||
238 | if (!info->vol_table[i]) | ||
239 | break; | ||
240 | if ((min_uV <= info->vol_table[i]) | ||
241 | && (max_uV >= info->vol_table[i])) { | ||
242 | ret = i; | ||
243 | break; | ||
244 | } | ||
245 | } | ||
246 | } | ||
247 | if (ret < 0) | ||
248 | pr_err("invalid voltage range (%d %d) uV\n", min_uV, max_uV); | ||
249 | return ret; | ||
250 | } | ||
251 | |||
252 | static int pm8607_set_voltage(struct regulator_dev *rdev, | ||
253 | int min_uV, int max_uV, unsigned *selector) | ||
254 | { | ||
255 | struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); | ||
256 | uint8_t val, mask; | ||
257 | int ret; | 226 | int ret; |
258 | 227 | ||
259 | if (min_uV > max_uV) { | 228 | val = (uint8_t)(selector << (ffs(rdev->desc->vsel_mask) - 1)); |
260 | pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV); | ||
261 | return -EINVAL; | ||
262 | } | ||
263 | 229 | ||
264 | ret = choose_voltage(rdev, min_uV, max_uV); | 230 | ret = pm860x_set_bits(info->i2c, rdev->desc->vsel_reg, |
265 | if (ret < 0) | 231 | rdev->desc->vsel_mask, val); |
266 | return -EINVAL; | ||
267 | *selector = ret; | ||
268 | val = (uint8_t)(ret << info->vol_shift); | ||
269 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; | ||
270 | |||
271 | ret = pm860x_set_bits(info->i2c, info->vol_reg, mask, val); | ||
272 | if (ret) | 232 | if (ret) |
273 | return ret; | 233 | return ret; |
274 | switch (info->desc.id) { | 234 | switch (info->desc.id) { |
@@ -282,60 +242,16 @@ static int pm8607_set_voltage(struct regulator_dev *rdev, | |||
282 | return ret; | 242 | return ret; |
283 | } | 243 | } |
284 | 244 | ||
285 | static int pm8607_get_voltage(struct regulator_dev *rdev) | ||
286 | { | ||
287 | struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); | ||
288 | uint8_t val, mask; | ||
289 | int ret; | ||
290 | |||
291 | ret = pm860x_reg_read(info->i2c, info->vol_reg); | ||
292 | if (ret < 0) | ||
293 | return ret; | ||
294 | |||
295 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; | ||
296 | val = ((unsigned char)ret & mask) >> info->vol_shift; | ||
297 | |||
298 | return pm8607_list_voltage(rdev, val); | ||
299 | } | ||
300 | |||
301 | static int pm8607_enable(struct regulator_dev *rdev) | ||
302 | { | ||
303 | struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); | ||
304 | |||
305 | return pm860x_set_bits(info->i2c, info->enable_reg, | ||
306 | 1 << info->enable_bit, | ||
307 | 1 << info->enable_bit); | ||
308 | } | ||
309 | |||
310 | static int pm8607_disable(struct regulator_dev *rdev) | ||
311 | { | ||
312 | struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); | ||
313 | |||
314 | return pm860x_set_bits(info->i2c, info->enable_reg, | ||
315 | 1 << info->enable_bit, 0); | ||
316 | } | ||
317 | |||
318 | static int pm8607_is_enabled(struct regulator_dev *rdev) | ||
319 | { | ||
320 | struct pm8607_regulator_info *info = rdev_get_drvdata(rdev); | ||
321 | int ret; | ||
322 | |||
323 | ret = pm860x_reg_read(info->i2c, info->enable_reg); | ||
324 | if (ret < 0) | ||
325 | return ret; | ||
326 | |||
327 | return !!((unsigned char)ret & (1 << info->enable_bit)); | ||
328 | } | ||
329 | |||
330 | static struct regulator_ops pm8607_regulator_ops = { | 245 | static struct regulator_ops pm8607_regulator_ops = { |
331 | .set_voltage = pm8607_set_voltage, | 246 | .list_voltage = pm8607_list_voltage, |
332 | .get_voltage = pm8607_get_voltage, | 247 | .set_voltage_sel = pm8607_set_voltage_sel, |
333 | .enable = pm8607_enable, | 248 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
334 | .disable = pm8607_disable, | 249 | .enable = regulator_enable_regmap, |
335 | .is_enabled = pm8607_is_enabled, | 250 | .disable = regulator_disable_regmap, |
251 | .is_enabled = regulator_is_enabled_regmap, | ||
336 | }; | 252 | }; |
337 | 253 | ||
338 | #define PM8607_DVC(vreg, nbits, ureg, ubit, ereg, ebit) \ | 254 | #define PM8607_DVC(vreg, ureg, ubit, ereg, ebit) \ |
339 | { \ | 255 | { \ |
340 | .desc = { \ | 256 | .desc = { \ |
341 | .name = #vreg, \ | 257 | .name = #vreg, \ |
@@ -343,20 +259,20 @@ static struct regulator_ops pm8607_regulator_ops = { | |||
343 | .type = REGULATOR_VOLTAGE, \ | 259 | .type = REGULATOR_VOLTAGE, \ |
344 | .id = PM8607_ID_##vreg, \ | 260 | .id = PM8607_ID_##vreg, \ |
345 | .owner = THIS_MODULE, \ | 261 | .owner = THIS_MODULE, \ |
262 | .n_voltages = ARRAY_SIZE(vreg##_table), \ | ||
263 | .vsel_reg = PM8607_##vreg, \ | ||
264 | .vsel_mask = ARRAY_SIZE(vreg##_table) - 1, \ | ||
265 | .enable_reg = PM8607_##ereg, \ | ||
266 | .enable_mask = 1 << (ebit), \ | ||
346 | }, \ | 267 | }, \ |
347 | .vol_reg = PM8607_##vreg, \ | ||
348 | .vol_shift = (0), \ | ||
349 | .vol_nbits = (nbits), \ | ||
350 | .update_reg = PM8607_##ureg, \ | 268 | .update_reg = PM8607_##ureg, \ |
351 | .update_bit = (ubit), \ | 269 | .update_bit = (ubit), \ |
352 | .enable_reg = PM8607_##ereg, \ | ||
353 | .enable_bit = (ebit), \ | ||
354 | .slope_double = (0), \ | 270 | .slope_double = (0), \ |
355 | .vol_table = (unsigned int *)&vreg##_table, \ | 271 | .vol_table = (unsigned int *)&vreg##_table, \ |
356 | .vol_suspend = (unsigned int *)&vreg##_suspend_table, \ | 272 | .vol_suspend = (unsigned int *)&vreg##_suspend_table, \ |
357 | } | 273 | } |
358 | 274 | ||
359 | #define PM8607_LDO(_id, vreg, shift, nbits, ereg, ebit) \ | 275 | #define PM8607_LDO(_id, vreg, shift, ereg, ebit) \ |
360 | { \ | 276 | { \ |
361 | .desc = { \ | 277 | .desc = { \ |
362 | .name = "LDO" #_id, \ | 278 | .name = "LDO" #_id, \ |
@@ -364,35 +280,35 @@ static struct regulator_ops pm8607_regulator_ops = { | |||
364 | .type = REGULATOR_VOLTAGE, \ | 280 | .type = REGULATOR_VOLTAGE, \ |
365 | .id = PM8607_ID_LDO##_id, \ | 281 | .id = PM8607_ID_LDO##_id, \ |
366 | .owner = THIS_MODULE, \ | 282 | .owner = THIS_MODULE, \ |
283 | .n_voltages = ARRAY_SIZE(LDO##_id##_table), \ | ||
284 | .vsel_reg = PM8607_##vreg, \ | ||
285 | .vsel_mask = (ARRAY_SIZE(LDO##_id##_table) - 1) << (shift), \ | ||
286 | .enable_reg = PM8607_##ereg, \ | ||
287 | .enable_mask = 1 << (ebit), \ | ||
367 | }, \ | 288 | }, \ |
368 | .vol_reg = PM8607_##vreg, \ | ||
369 | .vol_shift = (shift), \ | ||
370 | .vol_nbits = (nbits), \ | ||
371 | .enable_reg = PM8607_##ereg, \ | ||
372 | .enable_bit = (ebit), \ | ||
373 | .slope_double = (0), \ | 289 | .slope_double = (0), \ |
374 | .vol_table = (unsigned int *)&LDO##_id##_table, \ | 290 | .vol_table = (unsigned int *)&LDO##_id##_table, \ |
375 | .vol_suspend = (unsigned int *)&LDO##_id##_suspend_table, \ | 291 | .vol_suspend = (unsigned int *)&LDO##_id##_suspend_table, \ |
376 | } | 292 | } |
377 | 293 | ||
378 | static struct pm8607_regulator_info pm8607_regulator_info[] = { | 294 | static struct pm8607_regulator_info pm8607_regulator_info[] = { |
379 | PM8607_DVC(BUCK1, 6, GO, 0, SUPPLIES_EN11, 0), | 295 | PM8607_DVC(BUCK1, GO, 0, SUPPLIES_EN11, 0), |
380 | PM8607_DVC(BUCK2, 6, GO, 1, SUPPLIES_EN11, 1), | 296 | PM8607_DVC(BUCK2, GO, 1, SUPPLIES_EN11, 1), |
381 | PM8607_DVC(BUCK3, 6, GO, 2, SUPPLIES_EN11, 2), | 297 | PM8607_DVC(BUCK3, GO, 2, SUPPLIES_EN11, 2), |
382 | 298 | ||
383 | PM8607_LDO( 1, LDO1, 0, 2, SUPPLIES_EN11, 3), | 299 | PM8607_LDO(1, LDO1, 0, SUPPLIES_EN11, 3), |
384 | PM8607_LDO( 2, LDO2, 0, 3, SUPPLIES_EN11, 4), | 300 | PM8607_LDO(2, LDO2, 0, SUPPLIES_EN11, 4), |
385 | PM8607_LDO( 3, LDO3, 0, 3, SUPPLIES_EN11, 5), | 301 | PM8607_LDO(3, LDO3, 0, SUPPLIES_EN11, 5), |
386 | PM8607_LDO( 4, LDO4, 0, 3, SUPPLIES_EN11, 6), | 302 | PM8607_LDO(4, LDO4, 0, SUPPLIES_EN11, 6), |
387 | PM8607_LDO( 5, LDO5, 0, 2, SUPPLIES_EN11, 7), | 303 | PM8607_LDO(5, LDO5, 0, SUPPLIES_EN11, 7), |
388 | PM8607_LDO( 6, LDO6, 0, 3, SUPPLIES_EN12, 0), | 304 | PM8607_LDO(6, LDO6, 0, SUPPLIES_EN12, 0), |
389 | PM8607_LDO( 7, LDO7, 0, 3, SUPPLIES_EN12, 1), | 305 | PM8607_LDO(7, LDO7, 0, SUPPLIES_EN12, 1), |
390 | PM8607_LDO( 8, LDO8, 0, 3, SUPPLIES_EN12, 2), | 306 | PM8607_LDO(8, LDO8, 0, SUPPLIES_EN12, 2), |
391 | PM8607_LDO( 9, LDO9, 0, 3, SUPPLIES_EN12, 3), | 307 | PM8607_LDO(9, LDO9, 0, SUPPLIES_EN12, 3), |
392 | PM8607_LDO(10, LDO10, 0, 4, SUPPLIES_EN12, 4), | 308 | PM8607_LDO(10, LDO10, 0, SUPPLIES_EN12, 4), |
393 | PM8607_LDO(12, LDO12, 0, 4, SUPPLIES_EN12, 5), | 309 | PM8607_LDO(12, LDO12, 0, SUPPLIES_EN12, 5), |
394 | PM8607_LDO(13, VIBRATOR_SET, 1, 3, VIBRATOR_SET, 0), | 310 | PM8607_LDO(13, VIBRATOR_SET, 1, VIBRATOR_SET, 0), |
395 | PM8607_LDO(14, LDO14, 0, 3, SUPPLIES_EN12, 6), | 311 | PM8607_LDO(14, LDO14, 0, SUPPLIES_EN12, 6), |
396 | }; | 312 | }; |
397 | 313 | ||
398 | static int __devinit pm8607_regulator_probe(struct platform_device *pdev) | 314 | static int __devinit pm8607_regulator_probe(struct platform_device *pdev) |
@@ -400,6 +316,7 @@ static int __devinit pm8607_regulator_probe(struct platform_device *pdev) | |||
400 | struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent); | 316 | struct pm860x_chip *chip = dev_get_drvdata(pdev->dev.parent); |
401 | struct pm8607_regulator_info *info = NULL; | 317 | struct pm8607_regulator_info *info = NULL; |
402 | struct regulator_init_data *pdata = pdev->dev.platform_data; | 318 | struct regulator_init_data *pdata = pdev->dev.platform_data; |
319 | struct regulator_config config = { }; | ||
403 | struct resource *res; | 320 | struct resource *res; |
404 | int i; | 321 | int i; |
405 | 322 | ||
@@ -425,9 +342,17 @@ static int __devinit pm8607_regulator_probe(struct platform_device *pdev) | |||
425 | if ((i == PM8607_ID_BUCK3) && info->chip->buck3_double) | 342 | if ((i == PM8607_ID_BUCK3) && info->chip->buck3_double) |
426 | info->slope_double = 1; | 343 | info->slope_double = 1; |
427 | 344 | ||
345 | config.dev = &pdev->dev; | ||
346 | config.init_data = pdata; | ||
347 | config.driver_data = info; | ||
348 | |||
349 | if (chip->id == CHIP_PM8607) | ||
350 | config.regmap = chip->regmap; | ||
351 | else | ||
352 | config.regmap = chip->regmap_companion; | ||
353 | |||
428 | /* replace driver_data with info */ | 354 | /* replace driver_data with info */ |
429 | info->regulator = regulator_register(&info->desc, &pdev->dev, | 355 | info->regulator = regulator_register(&info->desc, &config); |
430 | pdata, info, NULL); | ||
431 | if (IS_ERR(info->regulator)) { | 356 | if (IS_ERR(info->regulator)) { |
432 | dev_err(&pdev->dev, "failed to register regulator %s\n", | 357 | dev_err(&pdev->dev, "failed to register regulator %s\n", |
433 | info->desc.name); | 358 | info->desc.name); |
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index 36db5a441eba..c86b8864e411 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig | |||
@@ -223,6 +223,16 @@ config REGULATOR_PCF50633 | |||
223 | Say Y here to support the voltage regulators and convertors | 223 | Say Y here to support the voltage regulators and convertors |
224 | on PCF50633 | 224 | on PCF50633 |
225 | 225 | ||
226 | config REGULATOR_RC5T583 | ||
227 | tristate "RICOH RC5T583 Power regulators" | ||
228 | depends on MFD_RC5T583 | ||
229 | help | ||
230 | Select this option to enable the power regulator of RICOH | ||
231 | PMIC RC5T583. | ||
232 | This driver supports the control of different power rails of device | ||
233 | through regulator interface. The device supports multiple DCDC/LDO | ||
234 | outputs which can be controlled by i2c communication. | ||
235 | |||
226 | config REGULATOR_S5M8767 | 236 | config REGULATOR_S5M8767 |
227 | tristate "Samsung S5M8767A voltage regulator" | 237 | tristate "Samsung S5M8767A voltage regulator" |
228 | depends on MFD_S5M_CORE | 238 | depends on MFD_S5M_CORE |
@@ -258,6 +268,18 @@ config REGULATOR_DB8500_PRCMU | |||
258 | This driver supports the voltage domain regulators controlled by the | 268 | This driver supports the voltage domain regulators controlled by the |
259 | DB8500 PRCMU | 269 | DB8500 PRCMU |
260 | 270 | ||
271 | config REGULATOR_PALMAS | ||
272 | tristate "TI Palmas PMIC Regulators" | ||
273 | depends on MFD_PALMAS | ||
274 | help | ||
275 | If you wish to control the regulators on the Palmas series of | ||
276 | chips say Y here. This will enable support for all the software | ||
277 | controllable SMPS/LDO regulators. | ||
278 | |||
279 | The regulators available on Palmas series chips vary depending | ||
280 | on the muxing. This is handled automatically in the driver by | ||
281 | reading the mux info from OTP. | ||
282 | |||
261 | config REGULATOR_TPS6105X | 283 | config REGULATOR_TPS6105X |
262 | tristate "TI TPS6105X Power regulators" | 284 | tristate "TI TPS6105X Power regulators" |
263 | depends on TPS6105X | 285 | depends on TPS6105X |
@@ -268,11 +290,11 @@ config REGULATOR_TPS6105X | |||
268 | audio amplifiers. | 290 | audio amplifiers. |
269 | 291 | ||
270 | config REGULATOR_TPS62360 | 292 | config REGULATOR_TPS62360 |
271 | tristate "TI TPS62360 Power Regulator" | 293 | tristate "TI TPS6236x Power Regulator" |
272 | depends on I2C | 294 | depends on I2C |
273 | select REGMAP_I2C | 295 | select REGMAP_I2C |
274 | help | 296 | help |
275 | This driver supports TPS62360 voltage regulator chip. This | 297 | This driver supports TPS6236x voltage regulator chip. This |
276 | regulator is meant for processor core supply. This chip is | 298 | regulator is meant for processor core supply. This chip is |
277 | high-frequency synchronous step down dc-dc converter optimized | 299 | high-frequency synchronous step down dc-dc converter optimized |
278 | for battery-powered portable applications. | 300 | for battery-powered portable applications. |
@@ -294,6 +316,13 @@ config REGULATOR_TPS6507X | |||
294 | three step-down converters and two general-purpose LDO voltage regulators. | 316 | three step-down converters and two general-purpose LDO voltage regulators. |
295 | It supports TI's software based Class-2 SmartReflex implementation. | 317 | It supports TI's software based Class-2 SmartReflex implementation. |
296 | 318 | ||
319 | config REGULATOR_TPS65090 | ||
320 | tristate "TI TPS65090 Power regulator" | ||
321 | depends on MFD_TPS65090 | ||
322 | help | ||
323 | This driver provides support for the voltage regulators on the | ||
324 | TI TPS65090 PMIC. | ||
325 | |||
297 | config REGULATOR_TPS65217 | 326 | config REGULATOR_TPS65217 |
298 | tristate "TI TPS65217 Power regulators" | 327 | tristate "TI TPS65217 Power regulators" |
299 | depends on MFD_TPS65217 | 328 | depends on MFD_TPS65217 |
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 94b52745e957..977fd46909ab 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile | |||
@@ -9,7 +9,6 @@ obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o | |||
9 | obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o | 9 | obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o |
10 | obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o | 10 | obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o |
11 | 11 | ||
12 | obj-$(CONFIG_REGULATOR_GPIO) += gpio-regulator.o | ||
13 | obj-$(CONFIG_REGULATOR_88PM8607) += 88pm8607.o | 12 | obj-$(CONFIG_REGULATOR_88PM8607) += 88pm8607.o |
14 | obj-$(CONFIG_REGULATOR_AAT2870) += aat2870-regulator.o | 13 | obj-$(CONFIG_REGULATOR_AAT2870) += aat2870-regulator.o |
15 | obj-$(CONFIG_REGULATOR_AB3100) += ab3100.o | 14 | obj-$(CONFIG_REGULATOR_AB3100) += ab3100.o |
@@ -20,6 +19,7 @@ obj-$(CONFIG_REGULATOR_DA903X) += da903x.o | |||
20 | obj-$(CONFIG_REGULATOR_DA9052) += da9052-regulator.o | 19 | obj-$(CONFIG_REGULATOR_DA9052) += da9052-regulator.o |
21 | obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o | 20 | obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o |
22 | obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o | 21 | obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o |
22 | obj-$(CONFIG_REGULATOR_GPIO) += gpio-regulator.o | ||
23 | obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o | 23 | obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o |
24 | obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o | 24 | obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o |
25 | obj-$(CONFIG_REGULATOR_LP3972) += lp3972.o | 25 | obj-$(CONFIG_REGULATOR_LP3972) += lp3972.o |
@@ -33,13 +33,16 @@ obj-$(CONFIG_REGULATOR_MAX8998) += max8998.o | |||
33 | obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o | 33 | obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o |
34 | obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o | 34 | obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o |
35 | obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o | 35 | obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o |
36 | obj-$(CONFIG_REGULATOR_PALMAS) += palmas-regulator.o | ||
36 | obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o | 37 | obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o |
37 | obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o | 38 | obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o |
39 | obj-$(CONFIG_REGULATOR_RC5T583) += rc5t583-regulator.o | ||
38 | obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o | 40 | obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o |
39 | obj-$(CONFIG_REGULATOR_TPS6105X) += tps6105x-regulator.o | 41 | obj-$(CONFIG_REGULATOR_TPS6105X) += tps6105x-regulator.o |
40 | obj-$(CONFIG_REGULATOR_TPS62360) += tps62360-regulator.o | 42 | obj-$(CONFIG_REGULATOR_TPS62360) += tps62360-regulator.o |
41 | obj-$(CONFIG_REGULATOR_TPS65023) += tps65023-regulator.o | 43 | obj-$(CONFIG_REGULATOR_TPS65023) += tps65023-regulator.o |
42 | obj-$(CONFIG_REGULATOR_TPS6507X) += tps6507x-regulator.o | 44 | obj-$(CONFIG_REGULATOR_TPS6507X) += tps6507x-regulator.o |
45 | obj-$(CONFIG_REGULATOR_TPS65090) += tps65090-regulator.o | ||
43 | obj-$(CONFIG_REGULATOR_TPS65217) += tps65217-regulator.o | 46 | obj-$(CONFIG_REGULATOR_TPS65217) += tps65217-regulator.o |
44 | obj-$(CONFIG_REGULATOR_TPS6524X) += tps6524x-regulator.o | 47 | obj-$(CONFIG_REGULATOR_TPS6524X) += tps6524x-regulator.o |
45 | obj-$(CONFIG_REGULATOR_TPS6586X) += tps6586x-regulator.o | 48 | obj-$(CONFIG_REGULATOR_TPS6586X) += tps6586x-regulator.o |
diff --git a/drivers/regulator/aat2870-regulator.c b/drivers/regulator/aat2870-regulator.c index 9ed5c5d84e12..06776ca945f2 100644 --- a/drivers/regulator/aat2870-regulator.c +++ b/drivers/regulator/aat2870-regulator.c | |||
@@ -24,7 +24,6 @@ | |||
24 | #include <linux/err.h> | 24 | #include <linux/err.h> |
25 | #include <linux/module.h> | 25 | #include <linux/module.h> |
26 | #include <linux/slab.h> | 26 | #include <linux/slab.h> |
27 | #include <linux/delay.h> | ||
28 | #include <linux/platform_device.h> | 27 | #include <linux/platform_device.h> |
29 | #include <linux/regulator/driver.h> | 28 | #include <linux/regulator/driver.h> |
30 | #include <linux/regulator/machine.h> | 29 | #include <linux/regulator/machine.h> |
@@ -178,6 +177,7 @@ static struct aat2870_regulator *aat2870_get_regulator(int id) | |||
178 | static int aat2870_regulator_probe(struct platform_device *pdev) | 177 | static int aat2870_regulator_probe(struct platform_device *pdev) |
179 | { | 178 | { |
180 | struct aat2870_regulator *ri; | 179 | struct aat2870_regulator *ri; |
180 | struct regulator_config config = { 0 }; | ||
181 | struct regulator_dev *rdev; | 181 | struct regulator_dev *rdev; |
182 | 182 | ||
183 | ri = aat2870_get_regulator(pdev->id); | 183 | ri = aat2870_get_regulator(pdev->id); |
@@ -187,8 +187,11 @@ static int aat2870_regulator_probe(struct platform_device *pdev) | |||
187 | } | 187 | } |
188 | ri->aat2870 = dev_get_drvdata(pdev->dev.parent); | 188 | ri->aat2870 = dev_get_drvdata(pdev->dev.parent); |
189 | 189 | ||
190 | rdev = regulator_register(&ri->desc, &pdev->dev, | 190 | config.dev = &pdev->dev; |
191 | pdev->dev.platform_data, ri, NULL); | 191 | config.driver_data = ri; |
192 | config.init_data = pdev->dev.platform_data; | ||
193 | |||
194 | rdev = regulator_register(&ri->desc, &config); | ||
192 | if (IS_ERR(rdev)) { | 195 | if (IS_ERR(rdev)) { |
193 | dev_err(&pdev->dev, "Failed to register regulator %s\n", | 196 | dev_err(&pdev->dev, "Failed to register regulator %s\n", |
194 | ri->desc.name); | 197 | ri->desc.name); |
@@ -231,3 +234,4 @@ module_exit(aat2870_regulator_exit); | |||
231 | MODULE_DESCRIPTION("AnalogicTech AAT2870 Regulator"); | 234 | MODULE_DESCRIPTION("AnalogicTech AAT2870 Regulator"); |
232 | MODULE_LICENSE("GPL"); | 235 | MODULE_LICENSE("GPL"); |
233 | MODULE_AUTHOR("Jin Park <jinyoungp@nvidia.com>"); | 236 | MODULE_AUTHOR("Jin Park <jinyoungp@nvidia.com>"); |
237 | MODULE_ALIAS("platform:aat2870-regulator"); | ||
diff --git a/drivers/regulator/ab3100.c b/drivers/regulator/ab3100.c index 042271aace6a..03f4d9c604ec 100644 --- a/drivers/regulator/ab3100.c +++ b/drivers/regulator/ab3100.c | |||
@@ -13,7 +13,6 @@ | |||
13 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
14 | #include <linux/init.h> | 14 | #include <linux/init.h> |
15 | #include <linux/err.h> | 15 | #include <linux/err.h> |
16 | #include <linux/delay.h> | ||
17 | #include <linux/platform_device.h> | 16 | #include <linux/platform_device.h> |
18 | #include <linux/regulator/driver.h> | 17 | #include <linux/regulator/driver.h> |
19 | #include <linux/mfd/abx500.h> | 18 | #include <linux/mfd/abx500.h> |
@@ -305,53 +304,12 @@ static int ab3100_get_voltage_regulator(struct regulator_dev *reg) | |||
305 | return abreg->typ_voltages[regval]; | 304 | return abreg->typ_voltages[regval]; |
306 | } | 305 | } |
307 | 306 | ||
308 | static int ab3100_get_best_voltage_index(struct regulator_dev *reg, | 307 | static int ab3100_set_voltage_regulator_sel(struct regulator_dev *reg, |
309 | int min_uV, int max_uV) | 308 | unsigned selector) |
310 | { | ||
311 | struct ab3100_regulator *abreg = reg->reg_data; | ||
312 | int i; | ||
313 | int bestmatch; | ||
314 | int bestindex; | ||
315 | |||
316 | /* | ||
317 | * Locate the minimum voltage fitting the criteria on | ||
318 | * this regulator. The switchable voltages are not | ||
319 | * in strict falling order so we need to check them | ||
320 | * all for the best match. | ||
321 | */ | ||
322 | bestmatch = INT_MAX; | ||
323 | bestindex = -1; | ||
324 | for (i = 0; i < abreg->voltages_len; i++) { | ||
325 | if (abreg->typ_voltages[i] <= max_uV && | ||
326 | abreg->typ_voltages[i] >= min_uV && | ||
327 | abreg->typ_voltages[i] < bestmatch) { | ||
328 | bestmatch = abreg->typ_voltages[i]; | ||
329 | bestindex = i; | ||
330 | } | ||
331 | } | ||
332 | |||
333 | if (bestindex < 0) { | ||
334 | dev_warn(®->dev, "requested %d<=x<=%d uV, out of range!\n", | ||
335 | min_uV, max_uV); | ||
336 | return -EINVAL; | ||
337 | } | ||
338 | return bestindex; | ||
339 | } | ||
340 | |||
341 | static int ab3100_set_voltage_regulator(struct regulator_dev *reg, | ||
342 | int min_uV, int max_uV, | ||
343 | unsigned *selector) | ||
344 | { | 309 | { |
345 | struct ab3100_regulator *abreg = reg->reg_data; | 310 | struct ab3100_regulator *abreg = reg->reg_data; |
346 | u8 regval; | 311 | u8 regval; |
347 | int err; | 312 | int err; |
348 | int bestindex; | ||
349 | |||
350 | bestindex = ab3100_get_best_voltage_index(reg, min_uV, max_uV); | ||
351 | if (bestindex < 0) | ||
352 | return bestindex; | ||
353 | |||
354 | *selector = bestindex; | ||
355 | 313 | ||
356 | err = abx500_get_register_interruptible(abreg->dev, 0, | 314 | err = abx500_get_register_interruptible(abreg->dev, 0, |
357 | abreg->regreg, ®val); | 315 | abreg->regreg, ®val); |
@@ -364,7 +322,7 @@ static int ab3100_set_voltage_regulator(struct regulator_dev *reg, | |||
364 | 322 | ||
365 | /* The highest three bits control the variable regulators */ | 323 | /* The highest three bits control the variable regulators */ |
366 | regval &= ~0xE0; | 324 | regval &= ~0xE0; |
367 | regval |= (bestindex << 5); | 325 | regval |= (selector << 5); |
368 | 326 | ||
369 | err = abx500_set_register_interruptible(abreg->dev, 0, | 327 | err = abx500_set_register_interruptible(abreg->dev, 0, |
370 | abreg->regreg, regval); | 328 | abreg->regreg, regval); |
@@ -392,7 +350,7 @@ static int ab3100_set_suspend_voltage_regulator(struct regulator_dev *reg, | |||
392 | return -EINVAL; | 350 | return -EINVAL; |
393 | 351 | ||
394 | /* LDO E and BUCK have special suspend voltages you can set */ | 352 | /* LDO E and BUCK have special suspend voltages you can set */ |
395 | bestindex = ab3100_get_best_voltage_index(reg, uV, uV); | 353 | bestindex = regulator_map_voltage_iterate(reg, uV, uV); |
396 | 354 | ||
397 | err = abx500_get_register_interruptible(abreg->dev, 0, | 355 | err = abx500_get_register_interruptible(abreg->dev, 0, |
398 | targetreg, ®val); | 356 | targetreg, ®val); |
@@ -464,7 +422,7 @@ static struct regulator_ops regulator_ops_variable = { | |||
464 | .disable = ab3100_disable_regulator, | 422 | .disable = ab3100_disable_regulator, |
465 | .is_enabled = ab3100_is_enabled_regulator, | 423 | .is_enabled = ab3100_is_enabled_regulator, |
466 | .get_voltage = ab3100_get_voltage_regulator, | 424 | .get_voltage = ab3100_get_voltage_regulator, |
467 | .set_voltage = ab3100_set_voltage_regulator, | 425 | .set_voltage_sel = ab3100_set_voltage_regulator_sel, |
468 | .list_voltage = ab3100_list_voltage_regulator, | 426 | .list_voltage = ab3100_list_voltage_regulator, |
469 | .enable_time = ab3100_enable_time_regulator, | 427 | .enable_time = ab3100_enable_time_regulator, |
470 | }; | 428 | }; |
@@ -474,7 +432,7 @@ static struct regulator_ops regulator_ops_variable_sleepable = { | |||
474 | .disable = ab3100_disable_regulator, | 432 | .disable = ab3100_disable_regulator, |
475 | .is_enabled = ab3100_is_enabled_regulator, | 433 | .is_enabled = ab3100_is_enabled_regulator, |
476 | .get_voltage = ab3100_get_voltage_regulator, | 434 | .get_voltage = ab3100_get_voltage_regulator, |
477 | .set_voltage = ab3100_set_voltage_regulator, | 435 | .set_voltage_sel = ab3100_set_voltage_regulator_sel, |
478 | .set_suspend_voltage = ab3100_set_suspend_voltage_regulator, | 436 | .set_suspend_voltage = ab3100_set_suspend_voltage_regulator, |
479 | .list_voltage = ab3100_list_voltage_regulator, | 437 | .list_voltage = ab3100_list_voltage_regulator, |
480 | .enable_time = ab3100_enable_time_regulator, | 438 | .enable_time = ab3100_enable_time_regulator, |
@@ -582,6 +540,7 @@ ab3100_regulator_desc[AB3100_NUM_REGULATORS] = { | |||
582 | static int __devinit ab3100_regulators_probe(struct platform_device *pdev) | 540 | static int __devinit ab3100_regulators_probe(struct platform_device *pdev) |
583 | { | 541 | { |
584 | struct ab3100_platform_data *plfdata = pdev->dev.platform_data; | 542 | struct ab3100_platform_data *plfdata = pdev->dev.platform_data; |
543 | struct regulator_config config = { }; | ||
585 | int err = 0; | 544 | int err = 0; |
586 | u8 data; | 545 | u8 data; |
587 | int i; | 546 | int i; |
@@ -627,15 +586,15 @@ static int __devinit ab3100_regulators_probe(struct platform_device *pdev) | |||
627 | reg->dev = &pdev->dev; | 586 | reg->dev = &pdev->dev; |
628 | reg->plfdata = plfdata; | 587 | reg->plfdata = plfdata; |
629 | 588 | ||
589 | config.dev = &pdev->dev; | ||
590 | config.driver_data = reg; | ||
591 | config.init_data = &plfdata->reg_constraints[i]; | ||
592 | |||
630 | /* | 593 | /* |
631 | * Register the regulator, pass around | 594 | * Register the regulator, pass around |
632 | * the ab3100_regulator struct | 595 | * the ab3100_regulator struct |
633 | */ | 596 | */ |
634 | rdev = regulator_register(&ab3100_regulator_desc[i], | 597 | rdev = regulator_register(&ab3100_regulator_desc[i], &config); |
635 | &pdev->dev, | ||
636 | &plfdata->reg_constraints[i], | ||
637 | reg, NULL); | ||
638 | |||
639 | if (IS_ERR(rdev)) { | 598 | if (IS_ERR(rdev)) { |
640 | err = PTR_ERR(rdev); | 599 | err = PTR_ERR(rdev); |
641 | dev_err(&pdev->dev, | 600 | dev_err(&pdev->dev, |
diff --git a/drivers/regulator/ab8500.c b/drivers/regulator/ab8500.c index c7ee4c15d6f5..e1b8c54ace5a 100644 --- a/drivers/regulator/ab8500.c +++ b/drivers/regulator/ab8500.c | |||
@@ -18,9 +18,12 @@ | |||
18 | #include <linux/platform_device.h> | 18 | #include <linux/platform_device.h> |
19 | #include <linux/mfd/abx500.h> | 19 | #include <linux/mfd/abx500.h> |
20 | #include <linux/mfd/abx500/ab8500.h> | 20 | #include <linux/mfd/abx500/ab8500.h> |
21 | #include <linux/of.h> | ||
22 | #include <linux/regulator/of_regulator.h> | ||
21 | #include <linux/regulator/driver.h> | 23 | #include <linux/regulator/driver.h> |
22 | #include <linux/regulator/machine.h> | 24 | #include <linux/regulator/machine.h> |
23 | #include <linux/regulator/ab8500.h> | 25 | #include <linux/regulator/ab8500.h> |
26 | #include <linux/slab.h> | ||
24 | 27 | ||
25 | /** | 28 | /** |
26 | * struct ab8500_regulator_info - ab8500 regulator information | 29 | * struct ab8500_regulator_info - ab8500 regulator information |
@@ -234,25 +237,8 @@ static int ab8500_regulator_get_voltage_sel(struct regulator_dev *rdev) | |||
234 | return val; | 237 | return val; |
235 | } | 238 | } |
236 | 239 | ||
237 | static int ab8500_get_best_voltage_index(struct regulator_dev *rdev, | 240 | static int ab8500_regulator_set_voltage_sel(struct regulator_dev *rdev, |
238 | int min_uV, int max_uV) | 241 | unsigned selector) |
239 | { | ||
240 | struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); | ||
241 | int i; | ||
242 | |||
243 | /* check the supported voltage */ | ||
244 | for (i = 0; i < info->voltages_len; i++) { | ||
245 | if ((info->voltages[i] >= min_uV) && | ||
246 | (info->voltages[i] <= max_uV)) | ||
247 | return i; | ||
248 | } | ||
249 | |||
250 | return -EINVAL; | ||
251 | } | ||
252 | |||
253 | static int ab8500_regulator_set_voltage(struct regulator_dev *rdev, | ||
254 | int min_uV, int max_uV, | ||
255 | unsigned *selector) | ||
256 | { | 242 | { |
257 | int ret; | 243 | int ret; |
258 | struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); | 244 | struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); |
@@ -263,18 +249,8 @@ static int ab8500_regulator_set_voltage(struct regulator_dev *rdev, | |||
263 | return -EINVAL; | 249 | return -EINVAL; |
264 | } | 250 | } |
265 | 251 | ||
266 | /* get the appropriate voltages within the range */ | ||
267 | ret = ab8500_get_best_voltage_index(rdev, min_uV, max_uV); | ||
268 | if (ret < 0) { | ||
269 | dev_err(rdev_get_dev(rdev), | ||
270 | "couldn't get best voltage for regulator\n"); | ||
271 | return ret; | ||
272 | } | ||
273 | |||
274 | *selector = ret; | ||
275 | |||
276 | /* set the registers for the request */ | 252 | /* set the registers for the request */ |
277 | regval = (u8)ret; | 253 | regval = (u8)selector; |
278 | ret = abx500_mask_and_set_register_interruptible(info->dev, | 254 | ret = abx500_mask_and_set_register_interruptible(info->dev, |
279 | info->voltage_bank, info->voltage_reg, | 255 | info->voltage_bank, info->voltage_reg, |
280 | info->voltage_mask, regval); | 256 | info->voltage_mask, regval); |
@@ -319,7 +295,7 @@ static struct regulator_ops ab8500_regulator_ops = { | |||
319 | .disable = ab8500_regulator_disable, | 295 | .disable = ab8500_regulator_disable, |
320 | .is_enabled = ab8500_regulator_is_enabled, | 296 | .is_enabled = ab8500_regulator_is_enabled, |
321 | .get_voltage_sel = ab8500_regulator_get_voltage_sel, | 297 | .get_voltage_sel = ab8500_regulator_get_voltage_sel, |
322 | .set_voltage = ab8500_regulator_set_voltage, | 298 | .set_voltage_sel = ab8500_regulator_set_voltage_sel, |
323 | .list_voltage = ab8500_list_voltage, | 299 | .list_voltage = ab8500_list_voltage, |
324 | .enable_time = ab8500_regulator_enable_time, | 300 | .enable_time = ab8500_regulator_enable_time, |
325 | .set_voltage_time_sel = ab8500_regulator_set_voltage_time_sel, | 301 | .set_voltage_time_sel = ab8500_regulator_set_voltage_time_sel, |
@@ -735,12 +711,139 @@ static struct ab8500_reg_init ab8500_reg_init[] = { | |||
735 | REG_INIT(AB8500_REGUCTRLDISCH2, 0x04, 0x44, 0x16), | 711 | REG_INIT(AB8500_REGUCTRLDISCH2, 0x04, 0x44, 0x16), |
736 | }; | 712 | }; |
737 | 713 | ||
714 | static __devinit int | ||
715 | ab8500_regulator_init_registers(struct platform_device *pdev, int id, int value) | ||
716 | { | ||
717 | int err; | ||
718 | |||
719 | if (value & ~ab8500_reg_init[id].mask) { | ||
720 | dev_err(&pdev->dev, | ||
721 | "Configuration error: value outside mask.\n"); | ||
722 | return -EINVAL; | ||
723 | } | ||
724 | |||
725 | err = abx500_mask_and_set_register_interruptible( | ||
726 | &pdev->dev, | ||
727 | ab8500_reg_init[id].bank, | ||
728 | ab8500_reg_init[id].addr, | ||
729 | ab8500_reg_init[id].mask, | ||
730 | value); | ||
731 | if (err < 0) { | ||
732 | dev_err(&pdev->dev, | ||
733 | "Failed to initialize 0x%02x, 0x%02x.\n", | ||
734 | ab8500_reg_init[id].bank, | ||
735 | ab8500_reg_init[id].addr); | ||
736 | return err; | ||
737 | } | ||
738 | |||
739 | dev_vdbg(&pdev->dev, | ||
740 | "init: 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", | ||
741 | ab8500_reg_init[id].bank, | ||
742 | ab8500_reg_init[id].addr, | ||
743 | ab8500_reg_init[id].mask, | ||
744 | value); | ||
745 | |||
746 | return 0; | ||
747 | } | ||
748 | |||
749 | static __devinit int ab8500_regulator_register(struct platform_device *pdev, | ||
750 | struct regulator_init_data *init_data, | ||
751 | int id, | ||
752 | struct device_node *np) | ||
753 | { | ||
754 | struct ab8500_regulator_info *info = NULL; | ||
755 | struct regulator_config config = { }; | ||
756 | int err; | ||
757 | |||
758 | /* assign per-regulator data */ | ||
759 | info = &ab8500_regulator_info[id]; | ||
760 | info->dev = &pdev->dev; | ||
761 | |||
762 | config.dev = &pdev->dev; | ||
763 | config.init_data = init_data; | ||
764 | config.driver_data = info; | ||
765 | config.of_node = np; | ||
766 | |||
767 | /* fix for hardware before ab8500v2.0 */ | ||
768 | if (abx500_get_chip_id(info->dev) < 0x20) { | ||
769 | if (info->desc.id == AB8500_LDO_AUX3) { | ||
770 | info->desc.n_voltages = | ||
771 | ARRAY_SIZE(ldo_vauxn_voltages); | ||
772 | info->voltages = ldo_vauxn_voltages; | ||
773 | info->voltages_len = | ||
774 | ARRAY_SIZE(ldo_vauxn_voltages); | ||
775 | info->voltage_mask = 0xf; | ||
776 | } | ||
777 | } | ||
778 | |||
779 | /* register regulator with framework */ | ||
780 | info->regulator = regulator_register(&info->desc, &config); | ||
781 | if (IS_ERR(info->regulator)) { | ||
782 | err = PTR_ERR(info->regulator); | ||
783 | dev_err(&pdev->dev, "failed to register regulator %s\n", | ||
784 | info->desc.name); | ||
785 | /* when we fail, un-register all earlier regulators */ | ||
786 | while (--id >= 0) { | ||
787 | info = &ab8500_regulator_info[id]; | ||
788 | regulator_unregister(info->regulator); | ||
789 | } | ||
790 | return err; | ||
791 | } | ||
792 | |||
793 | return 0; | ||
794 | } | ||
795 | |||
796 | static struct of_regulator_match ab8500_regulator_matches[] = { | ||
797 | { .name = "LDO-AUX1", .driver_data = (void *) AB8500_LDO_AUX1, }, | ||
798 | { .name = "LDO-AUX2", .driver_data = (void *) AB8500_LDO_AUX2, }, | ||
799 | { .name = "LDO-AUX3", .driver_data = (void *) AB8500_LDO_AUX3, }, | ||
800 | { .name = "LDO-INTCORE", .driver_data = (void *) AB8500_LDO_INTCORE, }, | ||
801 | { .name = "LDO-TVOUT", .driver_data = (void *) AB8500_LDO_TVOUT, }, | ||
802 | { .name = "LDO-USB", .driver_data = (void *) AB8500_LDO_USB, }, | ||
803 | { .name = "LDO-AUDIO", .driver_data = (void *) AB8500_LDO_AUDIO, }, | ||
804 | { .name = "LDO-ANAMIC1", .driver_data = (void *) AB8500_LDO_ANAMIC1, }, | ||
805 | { .name = "LDO-ANAMIC2", .driver_data = (void *) AB8500_LDO_ANAMIC2, }, | ||
806 | { .name = "LDO-DMIC", .driver_data = (void *) AB8500_LDO_DMIC, }, | ||
807 | { .name = "LDO-ANA", .driver_data = (void *) AB8500_LDO_ANA, }, | ||
808 | }; | ||
809 | |||
810 | static __devinit int | ||
811 | ab8500_regulator_of_probe(struct platform_device *pdev, struct device_node *np) | ||
812 | { | ||
813 | int err, i; | ||
814 | |||
815 | for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) { | ||
816 | err = ab8500_regulator_register( | ||
817 | pdev, ab8500_regulator_matches[i].init_data, | ||
818 | i, ab8500_regulator_matches[i].of_node); | ||
819 | if (err) | ||
820 | return err; | ||
821 | } | ||
822 | |||
823 | return 0; | ||
824 | } | ||
825 | |||
738 | static __devinit int ab8500_regulator_probe(struct platform_device *pdev) | 826 | static __devinit int ab8500_regulator_probe(struct platform_device *pdev) |
739 | { | 827 | { |
740 | struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent); | 828 | struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent); |
741 | struct ab8500_platform_data *pdata; | 829 | struct ab8500_platform_data *pdata; |
830 | struct device_node *np = pdev->dev.of_node; | ||
742 | int i, err; | 831 | int i, err; |
743 | 832 | ||
833 | if (np) { | ||
834 | err = of_regulator_match(&pdev->dev, np, | ||
835 | ab8500_regulator_matches, | ||
836 | ARRAY_SIZE(ab8500_regulator_matches)); | ||
837 | if (err < 0) { | ||
838 | dev_err(&pdev->dev, | ||
839 | "Error parsing regulator init data: %d\n", err); | ||
840 | return err; | ||
841 | } | ||
842 | |||
843 | err = ab8500_regulator_of_probe(pdev, np); | ||
844 | return err; | ||
845 | } | ||
846 | |||
744 | if (!ab8500) { | 847 | if (!ab8500) { |
745 | dev_err(&pdev->dev, "null mfd parent\n"); | 848 | dev_err(&pdev->dev, "null mfd parent\n"); |
746 | return -EINVAL; | 849 | return -EINVAL; |
@@ -759,8 +862,7 @@ static __devinit int ab8500_regulator_probe(struct platform_device *pdev) | |||
759 | 862 | ||
760 | /* initialize registers */ | 863 | /* initialize registers */ |
761 | for (i = 0; i < pdata->num_regulator_reg_init; i++) { | 864 | for (i = 0; i < pdata->num_regulator_reg_init; i++) { |
762 | int id; | 865 | int id, value; |
763 | u8 value; | ||
764 | 866 | ||
765 | id = pdata->regulator_reg_init[i].id; | 867 | id = pdata->regulator_reg_init[i].id; |
766 | value = pdata->regulator_reg_init[i].value; | 868 | value = pdata->regulator_reg_init[i].value; |
@@ -771,70 +873,17 @@ static __devinit int ab8500_regulator_probe(struct platform_device *pdev) | |||
771 | "Configuration error: id outside range.\n"); | 873 | "Configuration error: id outside range.\n"); |
772 | return -EINVAL; | 874 | return -EINVAL; |
773 | } | 875 | } |
774 | if (value & ~ab8500_reg_init[id].mask) { | ||
775 | dev_err(&pdev->dev, | ||
776 | "Configuration error: value outside mask.\n"); | ||
777 | return -EINVAL; | ||
778 | } | ||
779 | 876 | ||
780 | /* initialize register */ | 877 | err = ab8500_regulator_init_registers(pdev, id, value); |
781 | err = abx500_mask_and_set_register_interruptible(&pdev->dev, | 878 | if (err < 0) |
782 | ab8500_reg_init[id].bank, | ||
783 | ab8500_reg_init[id].addr, | ||
784 | ab8500_reg_init[id].mask, | ||
785 | value); | ||
786 | if (err < 0) { | ||
787 | dev_err(&pdev->dev, | ||
788 | "Failed to initialize 0x%02x, 0x%02x.\n", | ||
789 | ab8500_reg_init[id].bank, | ||
790 | ab8500_reg_init[id].addr); | ||
791 | return err; | 879 | return err; |
792 | } | ||
793 | dev_vdbg(&pdev->dev, | ||
794 | " init: 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", | ||
795 | ab8500_reg_init[id].bank, | ||
796 | ab8500_reg_init[id].addr, | ||
797 | ab8500_reg_init[id].mask, | ||
798 | value); | ||
799 | } | 880 | } |
800 | 881 | ||
801 | /* register all regulators */ | 882 | /* register all regulators */ |
802 | for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) { | 883 | for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) { |
803 | struct ab8500_regulator_info *info = NULL; | 884 | err = ab8500_regulator_register(pdev, &pdata->regulator[i], i, NULL); |
804 | 885 | if (err < 0) | |
805 | /* assign per-regulator data */ | ||
806 | info = &ab8500_regulator_info[i]; | ||
807 | info->dev = &pdev->dev; | ||
808 | |||
809 | /* fix for hardware before ab8500v2.0 */ | ||
810 | if (abx500_get_chip_id(info->dev) < 0x20) { | ||
811 | if (info->desc.id == AB8500_LDO_AUX3) { | ||
812 | info->desc.n_voltages = | ||
813 | ARRAY_SIZE(ldo_vauxn_voltages); | ||
814 | info->voltages = ldo_vauxn_voltages; | ||
815 | info->voltages_len = | ||
816 | ARRAY_SIZE(ldo_vauxn_voltages); | ||
817 | info->voltage_mask = 0xf; | ||
818 | } | ||
819 | } | ||
820 | |||
821 | /* register regulator with framework */ | ||
822 | info->regulator = regulator_register(&info->desc, &pdev->dev, | ||
823 | &pdata->regulator[i], info, NULL); | ||
824 | if (IS_ERR(info->regulator)) { | ||
825 | err = PTR_ERR(info->regulator); | ||
826 | dev_err(&pdev->dev, "failed to register regulator %s\n", | ||
827 | info->desc.name); | ||
828 | /* when we fail, un-register all earlier regulators */ | ||
829 | while (--i >= 0) { | ||
830 | info = &ab8500_regulator_info[i]; | ||
831 | regulator_unregister(info->regulator); | ||
832 | } | ||
833 | return err; | 886 | return err; |
834 | } | ||
835 | |||
836 | dev_vdbg(rdev_get_dev(info->regulator), | ||
837 | "%s-probed\n", info->desc.name); | ||
838 | } | 887 | } |
839 | 888 | ||
840 | return 0; | 889 | return 0; |
@@ -857,12 +906,18 @@ static __devexit int ab8500_regulator_remove(struct platform_device *pdev) | |||
857 | return 0; | 906 | return 0; |
858 | } | 907 | } |
859 | 908 | ||
909 | static const struct of_device_id ab8500_regulator_match[] = { | ||
910 | { .compatible = "stericsson,ab8500-regulator", }, | ||
911 | {} | ||
912 | }; | ||
913 | |||
860 | static struct platform_driver ab8500_regulator_driver = { | 914 | static struct platform_driver ab8500_regulator_driver = { |
861 | .probe = ab8500_regulator_probe, | 915 | .probe = ab8500_regulator_probe, |
862 | .remove = __devexit_p(ab8500_regulator_remove), | 916 | .remove = __devexit_p(ab8500_regulator_remove), |
863 | .driver = { | 917 | .driver = { |
864 | .name = "ab8500-regulator", | 918 | .name = "ab8500-regulator", |
865 | .owner = THIS_MODULE, | 919 | .owner = THIS_MODULE, |
920 | .of_match_table = ab8500_regulator_match, | ||
866 | }, | 921 | }, |
867 | }; | 922 | }; |
868 | 923 | ||
diff --git a/drivers/regulator/ad5398.c b/drivers/regulator/ad5398.c index 26d23adfc66f..46d05f38baf8 100644 --- a/drivers/regulator/ad5398.c +++ b/drivers/regulator/ad5398.c | |||
@@ -99,8 +99,8 @@ static int ad5398_set_current_limit(struct regulator_dev *rdev, int min_uA, int | |||
99 | if (ad5398_calc_current(chip, selector) > max_uA) | 99 | if (ad5398_calc_current(chip, selector) > max_uA) |
100 | return -EINVAL; | 100 | return -EINVAL; |
101 | 101 | ||
102 | dev_dbg(&client->dev, "changing current %dmA\n", | 102 | dev_dbg(&client->dev, "changing current %duA\n", |
103 | ad5398_calc_current(chip, selector) / 1000); | 103 | ad5398_calc_current(chip, selector)); |
104 | 104 | ||
105 | /* read chip enable bit */ | 105 | /* read chip enable bit */ |
106 | ret = ad5398_read_reg(client, &data); | 106 | ret = ad5398_read_reg(client, &data); |
@@ -184,7 +184,7 @@ static struct regulator_ops ad5398_ops = { | |||
184 | .is_enabled = ad5398_is_enabled, | 184 | .is_enabled = ad5398_is_enabled, |
185 | }; | 185 | }; |
186 | 186 | ||
187 | static struct regulator_desc ad5398_reg = { | 187 | static const struct regulator_desc ad5398_reg = { |
188 | .name = "isink", | 188 | .name = "isink", |
189 | .id = 0, | 189 | .id = 0, |
190 | .ops = &ad5398_ops, | 190 | .ops = &ad5398_ops, |
@@ -212,6 +212,7 @@ static int __devinit ad5398_probe(struct i2c_client *client, | |||
212 | const struct i2c_device_id *id) | 212 | const struct i2c_device_id *id) |
213 | { | 213 | { |
214 | struct regulator_init_data *init_data = client->dev.platform_data; | 214 | struct regulator_init_data *init_data = client->dev.platform_data; |
215 | struct regulator_config config = { }; | ||
215 | struct ad5398_chip_info *chip; | 216 | struct ad5398_chip_info *chip; |
216 | const struct ad5398_current_data_format *df = | 217 | const struct ad5398_current_data_format *df = |
217 | (struct ad5398_current_data_format *)id->driver_data; | 218 | (struct ad5398_current_data_format *)id->driver_data; |
@@ -220,10 +221,14 @@ static int __devinit ad5398_probe(struct i2c_client *client, | |||
220 | if (!init_data) | 221 | if (!init_data) |
221 | return -EINVAL; | 222 | return -EINVAL; |
222 | 223 | ||
223 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); | 224 | chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); |
224 | if (!chip) | 225 | if (!chip) |
225 | return -ENOMEM; | 226 | return -ENOMEM; |
226 | 227 | ||
228 | config.dev = &client->dev; | ||
229 | config.init_data = init_data; | ||
230 | config.driver_data = chip; | ||
231 | |||
227 | chip->client = client; | 232 | chip->client = client; |
228 | 233 | ||
229 | chip->min_uA = df->min_uA; | 234 | chip->min_uA = df->min_uA; |
@@ -232,8 +237,7 @@ static int __devinit ad5398_probe(struct i2c_client *client, | |||
232 | chip->current_offset = df->current_offset; | 237 | chip->current_offset = df->current_offset; |
233 | chip->current_mask = (chip->current_level - 1) << chip->current_offset; | 238 | chip->current_mask = (chip->current_level - 1) << chip->current_offset; |
234 | 239 | ||
235 | chip->rdev = regulator_register(&ad5398_reg, &client->dev, | 240 | chip->rdev = regulator_register(&ad5398_reg, &config); |
236 | init_data, chip, NULL); | ||
237 | if (IS_ERR(chip->rdev)) { | 241 | if (IS_ERR(chip->rdev)) { |
238 | ret = PTR_ERR(chip->rdev); | 242 | ret = PTR_ERR(chip->rdev); |
239 | dev_err(&client->dev, "failed to register %s %s\n", | 243 | dev_err(&client->dev, "failed to register %s %s\n", |
@@ -246,7 +250,6 @@ static int __devinit ad5398_probe(struct i2c_client *client, | |||
246 | return 0; | 250 | return 0; |
247 | 251 | ||
248 | err: | 252 | err: |
249 | kfree(chip); | ||
250 | return ret; | 253 | return ret; |
251 | } | 254 | } |
252 | 255 | ||
@@ -255,8 +258,6 @@ static int __devexit ad5398_remove(struct i2c_client *client) | |||
255 | struct ad5398_chip_info *chip = i2c_get_clientdata(client); | 258 | struct ad5398_chip_info *chip = i2c_get_clientdata(client); |
256 | 259 | ||
257 | regulator_unregister(chip->rdev); | 260 | regulator_unregister(chip->rdev); |
258 | kfree(chip); | ||
259 | |||
260 | return 0; | 261 | return 0; |
261 | } | 262 | } |
262 | 263 | ||
diff --git a/drivers/regulator/anatop-regulator.c b/drivers/regulator/anatop-regulator.c index 81fd606e47bc..49b2112b0486 100644 --- a/drivers/regulator/anatop-regulator.c +++ b/drivers/regulator/anatop-regulator.c | |||
@@ -122,6 +122,7 @@ static int __devinit anatop_regulator_probe(struct platform_device *pdev) | |||
122 | struct anatop_regulator *sreg; | 122 | struct anatop_regulator *sreg; |
123 | struct regulator_init_data *initdata; | 123 | struct regulator_init_data *initdata; |
124 | struct anatop *anatopmfd = dev_get_drvdata(pdev->dev.parent); | 124 | struct anatop *anatopmfd = dev_get_drvdata(pdev->dev.parent); |
125 | struct regulator_config config = { }; | ||
125 | int ret = 0; | 126 | int ret = 0; |
126 | 127 | ||
127 | initdata = of_get_regulator_init_data(dev, np); | 128 | initdata = of_get_regulator_init_data(dev, np); |
@@ -178,9 +179,13 @@ static int __devinit anatop_regulator_probe(struct platform_device *pdev) | |||
178 | rdesc->n_voltages = (sreg->max_voltage - sreg->min_voltage) | 179 | rdesc->n_voltages = (sreg->max_voltage - sreg->min_voltage) |
179 | / 25000 + 1; | 180 | / 25000 + 1; |
180 | 181 | ||
182 | config.dev = &pdev->dev; | ||
183 | config.init_data = initdata; | ||
184 | config.driver_data = sreg; | ||
185 | config.of_node = pdev->dev.of_node; | ||
186 | |||
181 | /* register regulator */ | 187 | /* register regulator */ |
182 | rdev = regulator_register(rdesc, dev, | 188 | rdev = regulator_register(rdesc, &config); |
183 | initdata, sreg, pdev->dev.of_node); | ||
184 | if (IS_ERR(rdev)) { | 189 | if (IS_ERR(rdev)) { |
185 | dev_err(dev, "failed to register %s\n", | 190 | dev_err(dev, "failed to register %s\n", |
186 | rdesc->name); | 191 | rdesc->name); |
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 046fb1bd8619..7584a74eec8a 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <linux/suspend.h> | 24 | #include <linux/suspend.h> |
25 | #include <linux/delay.h> | 25 | #include <linux/delay.h> |
26 | #include <linux/of.h> | 26 | #include <linux/of.h> |
27 | #include <linux/regmap.h> | ||
27 | #include <linux/regulator/of_regulator.h> | 28 | #include <linux/regulator/of_regulator.h> |
28 | #include <linux/regulator/consumer.h> | 29 | #include <linux/regulator/consumer.h> |
29 | #include <linux/regulator/driver.h> | 30 | #include <linux/regulator/driver.h> |
@@ -74,6 +75,7 @@ struct regulator_map { | |||
74 | struct regulator { | 75 | struct regulator { |
75 | struct device *dev; | 76 | struct device *dev; |
76 | struct list_head list; | 77 | struct list_head list; |
78 | unsigned int always_on:1; | ||
77 | int uA_load; | 79 | int uA_load; |
78 | int min_uV; | 80 | int min_uV; |
79 | int max_uV; | 81 | int max_uV; |
@@ -155,6 +157,17 @@ static struct device_node *of_get_regulator(struct device *dev, const char *supp | |||
155 | return regnode; | 157 | return regnode; |
156 | } | 158 | } |
157 | 159 | ||
160 | static int _regulator_can_change_status(struct regulator_dev *rdev) | ||
161 | { | ||
162 | if (!rdev->constraints) | ||
163 | return 0; | ||
164 | |||
165 | if (rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_STATUS) | ||
166 | return 1; | ||
167 | else | ||
168 | return 0; | ||
169 | } | ||
170 | |||
158 | /* Platform voltage constraint check */ | 171 | /* Platform voltage constraint check */ |
159 | static int regulator_check_voltage(struct regulator_dev *rdev, | 172 | static int regulator_check_voltage(struct regulator_dev *rdev, |
160 | int *min_uV, int *max_uV) | 173 | int *min_uV, int *max_uV) |
@@ -649,7 +662,7 @@ static void drms_uA_update(struct regulator_dev *rdev) | |||
649 | /* get input voltage */ | 662 | /* get input voltage */ |
650 | input_uV = 0; | 663 | input_uV = 0; |
651 | if (rdev->supply) | 664 | if (rdev->supply) |
652 | input_uV = _regulator_get_voltage(rdev); | 665 | input_uV = regulator_get_voltage(rdev->supply); |
653 | if (input_uV <= 0) | 666 | if (input_uV <= 0) |
654 | input_uV = rdev->constraints->input_uV; | 667 | input_uV = rdev->constraints->input_uV; |
655 | if (input_uV <= 0) | 668 | if (input_uV <= 0) |
@@ -673,17 +686,14 @@ static int suspend_set_state(struct regulator_dev *rdev, | |||
673 | struct regulator_state *rstate) | 686 | struct regulator_state *rstate) |
674 | { | 687 | { |
675 | int ret = 0; | 688 | int ret = 0; |
676 | bool can_set_state; | ||
677 | |||
678 | can_set_state = rdev->desc->ops->set_suspend_enable && | ||
679 | rdev->desc->ops->set_suspend_disable; | ||
680 | 689 | ||
681 | /* If we have no suspend mode configration don't set anything; | 690 | /* If we have no suspend mode configration don't set anything; |
682 | * only warn if the driver actually makes the suspend mode | 691 | * only warn if the driver implements set_suspend_voltage or |
683 | * configurable. | 692 | * set_suspend_mode callback. |
684 | */ | 693 | */ |
685 | if (!rstate->enabled && !rstate->disabled) { | 694 | if (!rstate->enabled && !rstate->disabled) { |
686 | if (can_set_state) | 695 | if (rdev->desc->ops->set_suspend_voltage || |
696 | rdev->desc->ops->set_suspend_mode) | ||
687 | rdev_warn(rdev, "No configuration\n"); | 697 | rdev_warn(rdev, "No configuration\n"); |
688 | return 0; | 698 | return 0; |
689 | } | 699 | } |
@@ -693,15 +703,13 @@ static int suspend_set_state(struct regulator_dev *rdev, | |||
693 | return -EINVAL; | 703 | return -EINVAL; |
694 | } | 704 | } |
695 | 705 | ||
696 | if (!can_set_state) { | 706 | if (rstate->enabled && rdev->desc->ops->set_suspend_enable) |
697 | rdev_err(rdev, "no way to set suspend state\n"); | ||
698 | return -EINVAL; | ||
699 | } | ||
700 | |||
701 | if (rstate->enabled) | ||
702 | ret = rdev->desc->ops->set_suspend_enable(rdev); | 707 | ret = rdev->desc->ops->set_suspend_enable(rdev); |
703 | else | 708 | else if (rstate->disabled && rdev->desc->ops->set_suspend_disable) |
704 | ret = rdev->desc->ops->set_suspend_disable(rdev); | 709 | ret = rdev->desc->ops->set_suspend_disable(rdev); |
710 | else /* OK if set_suspend_enable or set_suspend_disable is NULL */ | ||
711 | ret = 0; | ||
712 | |||
705 | if (ret < 0) { | 713 | if (ret < 0) { |
706 | rdev_err(rdev, "failed to enabled/disable\n"); | 714 | rdev_err(rdev, "failed to enabled/disable\n"); |
707 | return ret; | 715 | return ret; |
@@ -1146,6 +1154,15 @@ static struct regulator *create_regulator(struct regulator_dev *rdev, | |||
1146 | ®ulator->max_uV); | 1154 | ®ulator->max_uV); |
1147 | } | 1155 | } |
1148 | 1156 | ||
1157 | /* | ||
1158 | * Check now if the regulator is an always on regulator - if | ||
1159 | * it is then we don't need to do nearly so much work for | ||
1160 | * enable/disable calls. | ||
1161 | */ | ||
1162 | if (!_regulator_can_change_status(rdev) && | ||
1163 | _regulator_is_enabled(rdev)) | ||
1164 | regulator->always_on = true; | ||
1165 | |||
1149 | mutex_unlock(&rdev->mutex); | 1166 | mutex_unlock(&rdev->mutex); |
1150 | return regulator; | 1167 | return regulator; |
1151 | link_name_err: | 1168 | link_name_err: |
@@ -1169,26 +1186,52 @@ static int _regulator_get_enable_time(struct regulator_dev *rdev) | |||
1169 | } | 1186 | } |
1170 | 1187 | ||
1171 | static struct regulator_dev *regulator_dev_lookup(struct device *dev, | 1188 | static struct regulator_dev *regulator_dev_lookup(struct device *dev, |
1172 | const char *supply) | 1189 | const char *supply, |
1190 | int *ret) | ||
1173 | { | 1191 | { |
1174 | struct regulator_dev *r; | 1192 | struct regulator_dev *r; |
1175 | struct device_node *node; | 1193 | struct device_node *node; |
1194 | struct regulator_map *map; | ||
1195 | const char *devname = NULL; | ||
1176 | 1196 | ||
1177 | /* first do a dt based lookup */ | 1197 | /* first do a dt based lookup */ |
1178 | if (dev && dev->of_node) { | 1198 | if (dev && dev->of_node) { |
1179 | node = of_get_regulator(dev, supply); | 1199 | node = of_get_regulator(dev, supply); |
1180 | if (node) | 1200 | if (node) { |
1181 | list_for_each_entry(r, ®ulator_list, list) | 1201 | list_for_each_entry(r, ®ulator_list, list) |
1182 | if (r->dev.parent && | 1202 | if (r->dev.parent && |
1183 | node == r->dev.of_node) | 1203 | node == r->dev.of_node) |
1184 | return r; | 1204 | return r; |
1205 | } else { | ||
1206 | /* | ||
1207 | * If we couldn't even get the node then it's | ||
1208 | * not just that the device didn't register | ||
1209 | * yet, there's no node and we'll never | ||
1210 | * succeed. | ||
1211 | */ | ||
1212 | *ret = -ENODEV; | ||
1213 | } | ||
1185 | } | 1214 | } |
1186 | 1215 | ||
1187 | /* if not found, try doing it non-dt way */ | 1216 | /* if not found, try doing it non-dt way */ |
1217 | if (dev) | ||
1218 | devname = dev_name(dev); | ||
1219 | |||
1188 | list_for_each_entry(r, ®ulator_list, list) | 1220 | list_for_each_entry(r, ®ulator_list, list) |
1189 | if (strcmp(rdev_get_name(r), supply) == 0) | 1221 | if (strcmp(rdev_get_name(r), supply) == 0) |
1190 | return r; | 1222 | return r; |
1191 | 1223 | ||
1224 | list_for_each_entry(map, ®ulator_map_list, list) { | ||
1225 | /* If the mapping has a device set up it must match */ | ||
1226 | if (map->dev_name && | ||
1227 | (!devname || strcmp(map->dev_name, devname))) | ||
1228 | continue; | ||
1229 | |||
1230 | if (strcmp(map->supply, supply) == 0) | ||
1231 | return map->regulator; | ||
1232 | } | ||
1233 | |||
1234 | |||
1192 | return NULL; | 1235 | return NULL; |
1193 | } | 1236 | } |
1194 | 1237 | ||
@@ -1197,7 +1240,6 @@ static struct regulator *_regulator_get(struct device *dev, const char *id, | |||
1197 | int exclusive) | 1240 | int exclusive) |
1198 | { | 1241 | { |
1199 | struct regulator_dev *rdev; | 1242 | struct regulator_dev *rdev; |
1200 | struct regulator_map *map; | ||
1201 | struct regulator *regulator = ERR_PTR(-EPROBE_DEFER); | 1243 | struct regulator *regulator = ERR_PTR(-EPROBE_DEFER); |
1202 | const char *devname = NULL; | 1244 | const char *devname = NULL; |
1203 | int ret; | 1245 | int ret; |
@@ -1212,22 +1254,10 @@ static struct regulator *_regulator_get(struct device *dev, const char *id, | |||
1212 | 1254 | ||
1213 | mutex_lock(®ulator_list_mutex); | 1255 | mutex_lock(®ulator_list_mutex); |
1214 | 1256 | ||
1215 | rdev = regulator_dev_lookup(dev, id); | 1257 | rdev = regulator_dev_lookup(dev, id, &ret); |
1216 | if (rdev) | 1258 | if (rdev) |
1217 | goto found; | 1259 | goto found; |
1218 | 1260 | ||
1219 | list_for_each_entry(map, ®ulator_map_list, list) { | ||
1220 | /* If the mapping has a device set up it must match */ | ||
1221 | if (map->dev_name && | ||
1222 | (!devname || strcmp(map->dev_name, devname))) | ||
1223 | continue; | ||
1224 | |||
1225 | if (strcmp(map->supply, id) == 0) { | ||
1226 | rdev = map->regulator; | ||
1227 | goto found; | ||
1228 | } | ||
1229 | } | ||
1230 | |||
1231 | if (board_wants_dummy_regulator) { | 1261 | if (board_wants_dummy_regulator) { |
1232 | rdev = dummy_regulator_rdev; | 1262 | rdev = dummy_regulator_rdev; |
1233 | goto found; | 1263 | goto found; |
@@ -1438,17 +1468,6 @@ void devm_regulator_put(struct regulator *regulator) | |||
1438 | } | 1468 | } |
1439 | EXPORT_SYMBOL_GPL(devm_regulator_put); | 1469 | EXPORT_SYMBOL_GPL(devm_regulator_put); |
1440 | 1470 | ||
1441 | static int _regulator_can_change_status(struct regulator_dev *rdev) | ||
1442 | { | ||
1443 | if (!rdev->constraints) | ||
1444 | return 0; | ||
1445 | |||
1446 | if (rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_STATUS) | ||
1447 | return 1; | ||
1448 | else | ||
1449 | return 0; | ||
1450 | } | ||
1451 | |||
1452 | /* locks held by regulator_enable() */ | 1471 | /* locks held by regulator_enable() */ |
1453 | static int _regulator_enable(struct regulator_dev *rdev) | 1472 | static int _regulator_enable(struct regulator_dev *rdev) |
1454 | { | 1473 | { |
@@ -1528,6 +1547,9 @@ int regulator_enable(struct regulator *regulator) | |||
1528 | struct regulator_dev *rdev = regulator->rdev; | 1547 | struct regulator_dev *rdev = regulator->rdev; |
1529 | int ret = 0; | 1548 | int ret = 0; |
1530 | 1549 | ||
1550 | if (regulator->always_on) | ||
1551 | return 0; | ||
1552 | |||
1531 | if (rdev->supply) { | 1553 | if (rdev->supply) { |
1532 | ret = regulator_enable(rdev->supply); | 1554 | ret = regulator_enable(rdev->supply); |
1533 | if (ret != 0) | 1555 | if (ret != 0) |
@@ -1606,6 +1628,9 @@ int regulator_disable(struct regulator *regulator) | |||
1606 | struct regulator_dev *rdev = regulator->rdev; | 1628 | struct regulator_dev *rdev = regulator->rdev; |
1607 | int ret = 0; | 1629 | int ret = 0; |
1608 | 1630 | ||
1631 | if (regulator->always_on) | ||
1632 | return 0; | ||
1633 | |||
1609 | mutex_lock(&rdev->mutex); | 1634 | mutex_lock(&rdev->mutex); |
1610 | ret = _regulator_disable(rdev); | 1635 | ret = _regulator_disable(rdev); |
1611 | mutex_unlock(&rdev->mutex); | 1636 | mutex_unlock(&rdev->mutex); |
@@ -1714,6 +1739,9 @@ int regulator_disable_deferred(struct regulator *regulator, int ms) | |||
1714 | struct regulator_dev *rdev = regulator->rdev; | 1739 | struct regulator_dev *rdev = regulator->rdev; |
1715 | int ret; | 1740 | int ret; |
1716 | 1741 | ||
1742 | if (regulator->always_on) | ||
1743 | return 0; | ||
1744 | |||
1717 | mutex_lock(&rdev->mutex); | 1745 | mutex_lock(&rdev->mutex); |
1718 | rdev->deferred_disables++; | 1746 | rdev->deferred_disables++; |
1719 | mutex_unlock(&rdev->mutex); | 1747 | mutex_unlock(&rdev->mutex); |
@@ -1727,6 +1755,61 @@ int regulator_disable_deferred(struct regulator *regulator, int ms) | |||
1727 | } | 1755 | } |
1728 | EXPORT_SYMBOL_GPL(regulator_disable_deferred); | 1756 | EXPORT_SYMBOL_GPL(regulator_disable_deferred); |
1729 | 1757 | ||
1758 | /** | ||
1759 | * regulator_is_enabled_regmap - standard is_enabled() for regmap users | ||
1760 | * | ||
1761 | * @rdev: regulator to operate on | ||
1762 | * | ||
1763 | * Regulators that use regmap for their register I/O can set the | ||
1764 | * enable_reg and enable_mask fields in their descriptor and then use | ||
1765 | * this as their is_enabled operation, saving some code. | ||
1766 | */ | ||
1767 | int regulator_is_enabled_regmap(struct regulator_dev *rdev) | ||
1768 | { | ||
1769 | unsigned int val; | ||
1770 | int ret; | ||
1771 | |||
1772 | ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val); | ||
1773 | if (ret != 0) | ||
1774 | return ret; | ||
1775 | |||
1776 | return (val & rdev->desc->enable_mask) != 0; | ||
1777 | } | ||
1778 | EXPORT_SYMBOL_GPL(regulator_is_enabled_regmap); | ||
1779 | |||
1780 | /** | ||
1781 | * regulator_enable_regmap - standard enable() for regmap users | ||
1782 | * | ||
1783 | * @rdev: regulator to operate on | ||
1784 | * | ||
1785 | * Regulators that use regmap for their register I/O can set the | ||
1786 | * enable_reg and enable_mask fields in their descriptor and then use | ||
1787 | * this as their enable() operation, saving some code. | ||
1788 | */ | ||
1789 | int regulator_enable_regmap(struct regulator_dev *rdev) | ||
1790 | { | ||
1791 | return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, | ||
1792 | rdev->desc->enable_mask, | ||
1793 | rdev->desc->enable_mask); | ||
1794 | } | ||
1795 | EXPORT_SYMBOL_GPL(regulator_enable_regmap); | ||
1796 | |||
1797 | /** | ||
1798 | * regulator_disable_regmap - standard disable() for regmap users | ||
1799 | * | ||
1800 | * @rdev: regulator to operate on | ||
1801 | * | ||
1802 | * Regulators that use regmap for their register I/O can set the | ||
1803 | * enable_reg and enable_mask fields in their descriptor and then use | ||
1804 | * this as their disable() operation, saving some code. | ||
1805 | */ | ||
1806 | int regulator_disable_regmap(struct regulator_dev *rdev) | ||
1807 | { | ||
1808 | return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, | ||
1809 | rdev->desc->enable_mask, 0); | ||
1810 | } | ||
1811 | EXPORT_SYMBOL_GPL(regulator_disable_regmap); | ||
1812 | |||
1730 | static int _regulator_is_enabled(struct regulator_dev *rdev) | 1813 | static int _regulator_is_enabled(struct regulator_dev *rdev) |
1731 | { | 1814 | { |
1732 | /* If we don't know then assume that the regulator is always on */ | 1815 | /* If we don't know then assume that the regulator is always on */ |
@@ -1752,6 +1835,9 @@ int regulator_is_enabled(struct regulator *regulator) | |||
1752 | { | 1835 | { |
1753 | int ret; | 1836 | int ret; |
1754 | 1837 | ||
1838 | if (regulator->always_on) | ||
1839 | return 1; | ||
1840 | |||
1755 | mutex_lock(®ulator->rdev->mutex); | 1841 | mutex_lock(®ulator->rdev->mutex); |
1756 | ret = _regulator_is_enabled(regulator->rdev); | 1842 | ret = _regulator_is_enabled(regulator->rdev); |
1757 | mutex_unlock(®ulator->rdev->mutex); | 1843 | mutex_unlock(®ulator->rdev->mutex); |
@@ -1777,6 +1863,26 @@ int regulator_count_voltages(struct regulator *regulator) | |||
1777 | EXPORT_SYMBOL_GPL(regulator_count_voltages); | 1863 | EXPORT_SYMBOL_GPL(regulator_count_voltages); |
1778 | 1864 | ||
1779 | /** | 1865 | /** |
1866 | * regulator_list_voltage_linear - List voltages with simple calculation | ||
1867 | * | ||
1868 | * @rdev: Regulator device | ||
1869 | * @selector: Selector to convert into a voltage | ||
1870 | * | ||
1871 | * Regulators with a simple linear mapping between voltages and | ||
1872 | * selectors can set min_uV and uV_step in the regulator descriptor | ||
1873 | * and then use this function as their list_voltage() operation, | ||
1874 | */ | ||
1875 | int regulator_list_voltage_linear(struct regulator_dev *rdev, | ||
1876 | unsigned int selector) | ||
1877 | { | ||
1878 | if (selector >= rdev->desc->n_voltages) | ||
1879 | return -EINVAL; | ||
1880 | |||
1881 | return rdev->desc->min_uV + (rdev->desc->uV_step * selector); | ||
1882 | } | ||
1883 | EXPORT_SYMBOL_GPL(regulator_list_voltage_linear); | ||
1884 | |||
1885 | /** | ||
1780 | * regulator_list_voltage - enumerate supported voltages | 1886 | * regulator_list_voltage - enumerate supported voltages |
1781 | * @regulator: regulator source | 1887 | * @regulator: regulator source |
1782 | * @selector: identify voltage to list | 1888 | * @selector: identify voltage to list |
@@ -1840,75 +1946,183 @@ int regulator_is_supported_voltage(struct regulator *regulator, | |||
1840 | } | 1946 | } |
1841 | EXPORT_SYMBOL_GPL(regulator_is_supported_voltage); | 1947 | EXPORT_SYMBOL_GPL(regulator_is_supported_voltage); |
1842 | 1948 | ||
1949 | /** | ||
1950 | * regulator_get_voltage_sel_regmap - standard get_voltage_sel for regmap users | ||
1951 | * | ||
1952 | * @rdev: regulator to operate on | ||
1953 | * | ||
1954 | * Regulators that use regmap for their register I/O can set the | ||
1955 | * vsel_reg and vsel_mask fields in their descriptor and then use this | ||
1956 | * as their get_voltage_vsel operation, saving some code. | ||
1957 | */ | ||
1958 | int regulator_get_voltage_sel_regmap(struct regulator_dev *rdev) | ||
1959 | { | ||
1960 | unsigned int val; | ||
1961 | int ret; | ||
1962 | |||
1963 | ret = regmap_read(rdev->regmap, rdev->desc->vsel_reg, &val); | ||
1964 | if (ret != 0) | ||
1965 | return ret; | ||
1966 | |||
1967 | val &= rdev->desc->vsel_mask; | ||
1968 | val >>= ffs(rdev->desc->vsel_mask) - 1; | ||
1969 | |||
1970 | return val; | ||
1971 | } | ||
1972 | EXPORT_SYMBOL_GPL(regulator_get_voltage_sel_regmap); | ||
1973 | |||
1974 | /** | ||
1975 | * regulator_set_voltage_sel_regmap - standard set_voltage_sel for regmap users | ||
1976 | * | ||
1977 | * @rdev: regulator to operate on | ||
1978 | * @sel: Selector to set | ||
1979 | * | ||
1980 | * Regulators that use regmap for their register I/O can set the | ||
1981 | * vsel_reg and vsel_mask fields in their descriptor and then use this | ||
1982 | * as their set_voltage_vsel operation, saving some code. | ||
1983 | */ | ||
1984 | int regulator_set_voltage_sel_regmap(struct regulator_dev *rdev, unsigned sel) | ||
1985 | { | ||
1986 | sel <<= ffs(rdev->desc->vsel_mask) - 1; | ||
1987 | |||
1988 | return regmap_update_bits(rdev->regmap, rdev->desc->vsel_reg, | ||
1989 | rdev->desc->vsel_mask, sel); | ||
1990 | } | ||
1991 | EXPORT_SYMBOL_GPL(regulator_set_voltage_sel_regmap); | ||
1992 | |||
1993 | /** | ||
1994 | * regulator_map_voltage_iterate - map_voltage() based on list_voltage() | ||
1995 | * | ||
1996 | * @rdev: Regulator to operate on | ||
1997 | * @min_uV: Lower bound for voltage | ||
1998 | * @max_uV: Upper bound for voltage | ||
1999 | * | ||
2000 | * Drivers implementing set_voltage_sel() and list_voltage() can use | ||
2001 | * this as their map_voltage() operation. It will find a suitable | ||
2002 | * voltage by calling list_voltage() until it gets something in bounds | ||
2003 | * for the requested voltages. | ||
2004 | */ | ||
2005 | int regulator_map_voltage_iterate(struct regulator_dev *rdev, | ||
2006 | int min_uV, int max_uV) | ||
2007 | { | ||
2008 | int best_val = INT_MAX; | ||
2009 | int selector = 0; | ||
2010 | int i, ret; | ||
2011 | |||
2012 | /* Find the smallest voltage that falls within the specified | ||
2013 | * range. | ||
2014 | */ | ||
2015 | for (i = 0; i < rdev->desc->n_voltages; i++) { | ||
2016 | ret = rdev->desc->ops->list_voltage(rdev, i); | ||
2017 | if (ret < 0) | ||
2018 | continue; | ||
2019 | |||
2020 | if (ret < best_val && ret >= min_uV && ret <= max_uV) { | ||
2021 | best_val = ret; | ||
2022 | selector = i; | ||
2023 | } | ||
2024 | } | ||
2025 | |||
2026 | if (best_val != INT_MAX) | ||
2027 | return selector; | ||
2028 | else | ||
2029 | return -EINVAL; | ||
2030 | } | ||
2031 | EXPORT_SYMBOL_GPL(regulator_map_voltage_iterate); | ||
2032 | |||
2033 | /** | ||
2034 | * regulator_map_voltage_linear - map_voltage() for simple linear mappings | ||
2035 | * | ||
2036 | * @rdev: Regulator to operate on | ||
2037 | * @min_uV: Lower bound for voltage | ||
2038 | * @max_uV: Upper bound for voltage | ||
2039 | * | ||
2040 | * Drivers providing min_uV and uV_step in their regulator_desc can | ||
2041 | * use this as their map_voltage() operation. | ||
2042 | */ | ||
2043 | int regulator_map_voltage_linear(struct regulator_dev *rdev, | ||
2044 | int min_uV, int max_uV) | ||
2045 | { | ||
2046 | int ret, voltage; | ||
2047 | |||
2048 | if (!rdev->desc->uV_step) { | ||
2049 | BUG_ON(!rdev->desc->uV_step); | ||
2050 | return -EINVAL; | ||
2051 | } | ||
2052 | |||
2053 | ret = DIV_ROUND_UP(min_uV - rdev->desc->min_uV, rdev->desc->uV_step); | ||
2054 | if (ret < 0) | ||
2055 | return ret; | ||
2056 | |||
2057 | /* Map back into a voltage to verify we're still in bounds */ | ||
2058 | voltage = rdev->desc->ops->list_voltage(rdev, ret); | ||
2059 | if (voltage < min_uV || voltage > max_uV) | ||
2060 | return -EINVAL; | ||
2061 | |||
2062 | return ret; | ||
2063 | } | ||
2064 | EXPORT_SYMBOL_GPL(regulator_map_voltage_linear); | ||
2065 | |||
1843 | static int _regulator_do_set_voltage(struct regulator_dev *rdev, | 2066 | static int _regulator_do_set_voltage(struct regulator_dev *rdev, |
1844 | int min_uV, int max_uV) | 2067 | int min_uV, int max_uV) |
1845 | { | 2068 | { |
1846 | int ret; | 2069 | int ret; |
1847 | int delay = 0; | 2070 | int delay = 0; |
2071 | int best_val; | ||
1848 | unsigned int selector; | 2072 | unsigned int selector; |
2073 | int old_selector = -1; | ||
1849 | 2074 | ||
1850 | trace_regulator_set_voltage(rdev_get_name(rdev), min_uV, max_uV); | 2075 | trace_regulator_set_voltage(rdev_get_name(rdev), min_uV, max_uV); |
1851 | 2076 | ||
1852 | min_uV += rdev->constraints->uV_offset; | 2077 | min_uV += rdev->constraints->uV_offset; |
1853 | max_uV += rdev->constraints->uV_offset; | 2078 | max_uV += rdev->constraints->uV_offset; |
1854 | 2079 | ||
2080 | /* | ||
2081 | * If we can't obtain the old selector there is not enough | ||
2082 | * info to call set_voltage_time_sel(). | ||
2083 | */ | ||
2084 | if (rdev->desc->ops->set_voltage_time_sel && | ||
2085 | rdev->desc->ops->get_voltage_sel) { | ||
2086 | old_selector = rdev->desc->ops->get_voltage_sel(rdev); | ||
2087 | if (old_selector < 0) | ||
2088 | return old_selector; | ||
2089 | } | ||
2090 | |||
1855 | if (rdev->desc->ops->set_voltage) { | 2091 | if (rdev->desc->ops->set_voltage) { |
1856 | ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV, | 2092 | ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV, |
1857 | &selector); | 2093 | &selector); |
1858 | |||
1859 | if (rdev->desc->ops->list_voltage) | ||
1860 | selector = rdev->desc->ops->list_voltage(rdev, | ||
1861 | selector); | ||
1862 | else | ||
1863 | selector = -1; | ||
1864 | } else if (rdev->desc->ops->set_voltage_sel) { | 2094 | } else if (rdev->desc->ops->set_voltage_sel) { |
1865 | int best_val = INT_MAX; | 2095 | if (rdev->desc->ops->map_voltage) |
1866 | int i; | 2096 | ret = rdev->desc->ops->map_voltage(rdev, min_uV, |
1867 | 2097 | max_uV); | |
1868 | selector = 0; | 2098 | else |
1869 | 2099 | ret = regulator_map_voltage_iterate(rdev, min_uV, | |
1870 | /* Find the smallest voltage that falls within the specified | 2100 | max_uV); |
1871 | * range. | ||
1872 | */ | ||
1873 | for (i = 0; i < rdev->desc->n_voltages; i++) { | ||
1874 | ret = rdev->desc->ops->list_voltage(rdev, i); | ||
1875 | if (ret < 0) | ||
1876 | continue; | ||
1877 | 2101 | ||
1878 | if (ret < best_val && ret >= min_uV && ret <= max_uV) { | 2102 | if (ret >= 0) { |
1879 | best_val = ret; | 2103 | selector = ret; |
1880 | selector = i; | 2104 | ret = rdev->desc->ops->set_voltage_sel(rdev, ret); |
1881 | } | ||
1882 | } | 2105 | } |
2106 | } else { | ||
2107 | ret = -EINVAL; | ||
2108 | } | ||
1883 | 2109 | ||
1884 | /* | 2110 | if (rdev->desc->ops->list_voltage) |
1885 | * If we can't obtain the old selector there is not enough | 2111 | best_val = rdev->desc->ops->list_voltage(rdev, selector); |
1886 | * info to call set_voltage_time_sel(). | 2112 | else |
1887 | */ | 2113 | best_val = -1; |
1888 | if (rdev->desc->ops->set_voltage_time_sel && | ||
1889 | rdev->desc->ops->get_voltage_sel) { | ||
1890 | unsigned int old_selector = 0; | ||
1891 | 2114 | ||
1892 | ret = rdev->desc->ops->get_voltage_sel(rdev); | 2115 | /* Call set_voltage_time_sel if successfully obtained old_selector */ |
1893 | if (ret < 0) | 2116 | if (ret == 0 && old_selector >= 0 && |
1894 | return ret; | 2117 | rdev->desc->ops->set_voltage_time_sel) { |
1895 | old_selector = ret; | ||
1896 | ret = rdev->desc->ops->set_voltage_time_sel(rdev, | ||
1897 | old_selector, selector); | ||
1898 | if (ret < 0) | ||
1899 | rdev_warn(rdev, "set_voltage_time_sel() failed: %d\n", ret); | ||
1900 | else | ||
1901 | delay = ret; | ||
1902 | } | ||
1903 | 2118 | ||
1904 | if (best_val != INT_MAX) { | 2119 | delay = rdev->desc->ops->set_voltage_time_sel(rdev, |
1905 | ret = rdev->desc->ops->set_voltage_sel(rdev, selector); | 2120 | old_selector, selector); |
1906 | selector = best_val; | 2121 | if (delay < 0) { |
1907 | } else { | 2122 | rdev_warn(rdev, "set_voltage_time_sel() failed: %d\n", |
1908 | ret = -EINVAL; | 2123 | delay); |
2124 | delay = 0; | ||
1909 | } | 2125 | } |
1910 | } else { | ||
1911 | ret = -EINVAL; | ||
1912 | } | 2126 | } |
1913 | 2127 | ||
1914 | /* Insert any necessary delays */ | 2128 | /* Insert any necessary delays */ |
@@ -1923,7 +2137,7 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev, | |||
1923 | _notifier_call_chain(rdev, REGULATOR_EVENT_VOLTAGE_CHANGE, | 2137 | _notifier_call_chain(rdev, REGULATOR_EVENT_VOLTAGE_CHANGE, |
1924 | NULL); | 2138 | NULL); |
1925 | 2139 | ||
1926 | trace_regulator_set_voltage_complete(rdev_get_name(rdev), selector); | 2140 | trace_regulator_set_voltage_complete(rdev_get_name(rdev), best_val); |
1927 | 2141 | ||
1928 | return ret; | 2142 | return ret; |
1929 | } | 2143 | } |
@@ -2327,6 +2541,9 @@ int regulator_set_optimum_mode(struct regulator *regulator, int uA_load) | |||
2327 | */ | 2541 | */ |
2328 | ret = -EINVAL; | 2542 | ret = -EINVAL; |
2329 | 2543 | ||
2544 | if (!rdev->desc->ops->set_mode) | ||
2545 | goto out; | ||
2546 | |||
2330 | /* get output voltage */ | 2547 | /* get output voltage */ |
2331 | output_uV = _regulator_get_voltage(rdev); | 2548 | output_uV = _regulator_get_voltage(rdev); |
2332 | if (output_uV <= 0) { | 2549 | if (output_uV <= 0) { |
@@ -2528,9 +2745,13 @@ int regulator_bulk_enable(int num_consumers, | |||
2528 | int i; | 2745 | int i; |
2529 | int ret = 0; | 2746 | int ret = 0; |
2530 | 2747 | ||
2531 | for (i = 0; i < num_consumers; i++) | 2748 | for (i = 0; i < num_consumers; i++) { |
2532 | async_schedule_domain(regulator_bulk_enable_async, | 2749 | if (consumers[i].consumer->always_on) |
2533 | &consumers[i], &async_domain); | 2750 | consumers[i].ret = 0; |
2751 | else | ||
2752 | async_schedule_domain(regulator_bulk_enable_async, | ||
2753 | &consumers[i], &async_domain); | ||
2754 | } | ||
2534 | 2755 | ||
2535 | async_synchronize_full_domain(&async_domain); | 2756 | async_synchronize_full_domain(&async_domain); |
2536 | 2757 | ||
@@ -2569,7 +2790,7 @@ int regulator_bulk_disable(int num_consumers, | |||
2569 | struct regulator_bulk_data *consumers) | 2790 | struct regulator_bulk_data *consumers) |
2570 | { | 2791 | { |
2571 | int i; | 2792 | int i; |
2572 | int ret; | 2793 | int ret, r; |
2573 | 2794 | ||
2574 | for (i = num_consumers - 1; i >= 0; --i) { | 2795 | for (i = num_consumers - 1; i >= 0; --i) { |
2575 | ret = regulator_disable(consumers[i].consumer); | 2796 | ret = regulator_disable(consumers[i].consumer); |
@@ -2581,8 +2802,12 @@ int regulator_bulk_disable(int num_consumers, | |||
2581 | 2802 | ||
2582 | err: | 2803 | err: |
2583 | pr_err("Failed to disable %s: %d\n", consumers[i].supply, ret); | 2804 | pr_err("Failed to disable %s: %d\n", consumers[i].supply, ret); |
2584 | for (++i; i < num_consumers; ++i) | 2805 | for (++i; i < num_consumers; ++i) { |
2585 | regulator_enable(consumers[i].consumer); | 2806 | r = regulator_enable(consumers[i].consumer); |
2807 | if (r != 0) | ||
2808 | pr_err("Failed to reename %s: %d\n", | ||
2809 | consumers[i].supply, r); | ||
2810 | } | ||
2586 | 2811 | ||
2587 | return ret; | 2812 | return ret; |
2588 | } | 2813 | } |
@@ -2759,10 +2984,6 @@ static int add_regulator_attributes(struct regulator_dev *rdev) | |||
2759 | return status; | 2984 | return status; |
2760 | } | 2985 | } |
2761 | 2986 | ||
2762 | /* suspend mode constraints need multiple supporting methods */ | ||
2763 | if (!(ops->set_suspend_enable && ops->set_suspend_disable)) | ||
2764 | return status; | ||
2765 | |||
2766 | status = device_create_file(dev, &dev_attr_suspend_standby_state); | 2987 | status = device_create_file(dev, &dev_attr_suspend_standby_state); |
2767 | if (status < 0) | 2988 | if (status < 0) |
2768 | return status; | 2989 | return status; |
@@ -2823,28 +3044,29 @@ static void rdev_init_debugfs(struct regulator_dev *rdev) | |||
2823 | /** | 3044 | /** |
2824 | * regulator_register - register regulator | 3045 | * regulator_register - register regulator |
2825 | * @regulator_desc: regulator to register | 3046 | * @regulator_desc: regulator to register |
2826 | * @dev: struct device for the regulator | 3047 | * @config: runtime configuration for regulator |
2827 | * @init_data: platform provided init data, passed through by driver | ||
2828 | * @driver_data: private regulator data | ||
2829 | * @of_node: OpenFirmware node to parse for device tree bindings (may be | ||
2830 | * NULL). | ||
2831 | * | 3048 | * |
2832 | * Called by regulator drivers to register a regulator. | 3049 | * Called by regulator drivers to register a regulator. |
2833 | * Returns 0 on success. | 3050 | * Returns 0 on success. |
2834 | */ | 3051 | */ |
2835 | struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, | 3052 | struct regulator_dev * |
2836 | struct device *dev, const struct regulator_init_data *init_data, | 3053 | regulator_register(const struct regulator_desc *regulator_desc, |
2837 | void *driver_data, struct device_node *of_node) | 3054 | const struct regulator_config *config) |
2838 | { | 3055 | { |
2839 | const struct regulation_constraints *constraints = NULL; | 3056 | const struct regulation_constraints *constraints = NULL; |
3057 | const struct regulator_init_data *init_data; | ||
2840 | static atomic_t regulator_no = ATOMIC_INIT(0); | 3058 | static atomic_t regulator_no = ATOMIC_INIT(0); |
2841 | struct regulator_dev *rdev; | 3059 | struct regulator_dev *rdev; |
3060 | struct device *dev; | ||
2842 | int ret, i; | 3061 | int ret, i; |
2843 | const char *supply = NULL; | 3062 | const char *supply = NULL; |
2844 | 3063 | ||
2845 | if (regulator_desc == NULL) | 3064 | if (regulator_desc == NULL || config == NULL) |
2846 | return ERR_PTR(-EINVAL); | 3065 | return ERR_PTR(-EINVAL); |
2847 | 3066 | ||
3067 | dev = config->dev; | ||
3068 | WARN_ON(!dev); | ||
3069 | |||
2848 | if (regulator_desc->name == NULL || regulator_desc->ops == NULL) | 3070 | if (regulator_desc->name == NULL || regulator_desc->ops == NULL) |
2849 | return ERR_PTR(-EINVAL); | 3071 | return ERR_PTR(-EINVAL); |
2850 | 3072 | ||
@@ -2868,6 +3090,8 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, | |||
2868 | return ERR_PTR(-EINVAL); | 3090 | return ERR_PTR(-EINVAL); |
2869 | } | 3091 | } |
2870 | 3092 | ||
3093 | init_data = config->init_data; | ||
3094 | |||
2871 | rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL); | 3095 | rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL); |
2872 | if (rdev == NULL) | 3096 | if (rdev == NULL) |
2873 | return ERR_PTR(-ENOMEM); | 3097 | return ERR_PTR(-ENOMEM); |
@@ -2875,9 +3099,10 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, | |||
2875 | mutex_lock(®ulator_list_mutex); | 3099 | mutex_lock(®ulator_list_mutex); |
2876 | 3100 | ||
2877 | mutex_init(&rdev->mutex); | 3101 | mutex_init(&rdev->mutex); |
2878 | rdev->reg_data = driver_data; | 3102 | rdev->reg_data = config->driver_data; |
2879 | rdev->owner = regulator_desc->owner; | 3103 | rdev->owner = regulator_desc->owner; |
2880 | rdev->desc = regulator_desc; | 3104 | rdev->desc = regulator_desc; |
3105 | rdev->regmap = config->regmap; | ||
2881 | INIT_LIST_HEAD(&rdev->consumer_list); | 3106 | INIT_LIST_HEAD(&rdev->consumer_list); |
2882 | INIT_LIST_HEAD(&rdev->list); | 3107 | INIT_LIST_HEAD(&rdev->list); |
2883 | BLOCKING_INIT_NOTIFIER_HEAD(&rdev->notifier); | 3108 | BLOCKING_INIT_NOTIFIER_HEAD(&rdev->notifier); |
@@ -2892,7 +3117,7 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, | |||
2892 | 3117 | ||
2893 | /* register with sysfs */ | 3118 | /* register with sysfs */ |
2894 | rdev->dev.class = ®ulator_class; | 3119 | rdev->dev.class = ®ulator_class; |
2895 | rdev->dev.of_node = of_node; | 3120 | rdev->dev.of_node = config->of_node; |
2896 | rdev->dev.parent = dev; | 3121 | rdev->dev.parent = dev; |
2897 | dev_set_name(&rdev->dev, "regulator.%d", | 3122 | dev_set_name(&rdev->dev, "regulator.%d", |
2898 | atomic_inc_return(®ulator_no) - 1); | 3123 | atomic_inc_return(®ulator_no) - 1); |
@@ -2925,7 +3150,7 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, | |||
2925 | if (supply) { | 3150 | if (supply) { |
2926 | struct regulator_dev *r; | 3151 | struct regulator_dev *r; |
2927 | 3152 | ||
2928 | r = regulator_dev_lookup(dev, supply); | 3153 | r = regulator_dev_lookup(dev, supply, &ret); |
2929 | 3154 | ||
2930 | if (!r) { | 3155 | if (!r) { |
2931 | dev_err(dev, "Failed to find supply %s\n", supply); | 3156 | dev_err(dev, "Failed to find supply %s\n", supply); |
@@ -2938,8 +3163,7 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, | |||
2938 | goto scrub; | 3163 | goto scrub; |
2939 | 3164 | ||
2940 | /* Enable supply if rail is enabled */ | 3165 | /* Enable supply if rail is enabled */ |
2941 | if (rdev->desc->ops->is_enabled && | 3166 | if (_regulator_is_enabled(rdev)) { |
2942 | rdev->desc->ops->is_enabled(rdev)) { | ||
2943 | ret = regulator_enable(rdev->supply); | 3167 | ret = regulator_enable(rdev->supply); |
2944 | if (ret < 0) | 3168 | if (ret < 0) |
2945 | goto scrub; | 3169 | goto scrub; |
@@ -2971,6 +3195,8 @@ unset_supplies: | |||
2971 | unset_regulator_supplies(rdev); | 3195 | unset_regulator_supplies(rdev); |
2972 | 3196 | ||
2973 | scrub: | 3197 | scrub: |
3198 | if (rdev->supply) | ||
3199 | regulator_put(rdev->supply); | ||
2974 | kfree(rdev->constraints); | 3200 | kfree(rdev->constraints); |
2975 | device_unregister(&rdev->dev); | 3201 | device_unregister(&rdev->dev); |
2976 | /* device core frees rdev */ | 3202 | /* device core frees rdev */ |
@@ -3069,7 +3295,7 @@ int regulator_suspend_finish(void) | |||
3069 | goto unlock; | 3295 | goto unlock; |
3070 | if (!ops->disable) | 3296 | if (!ops->disable) |
3071 | goto unlock; | 3297 | goto unlock; |
3072 | if (ops->is_enabled && !ops->is_enabled(rdev)) | 3298 | if (!_regulator_is_enabled(rdev)) |
3073 | goto unlock; | 3299 | goto unlock; |
3074 | 3300 | ||
3075 | error = ops->disable(rdev); | 3301 | error = ops->disable(rdev); |
diff --git a/drivers/regulator/da903x.c b/drivers/regulator/da903x.c index 1851f0929ef0..1005f5f7e603 100644 --- a/drivers/regulator/da903x.c +++ b/drivers/regulator/da903x.c | |||
@@ -76,9 +76,7 @@ | |||
76 | struct da903x_regulator_info { | 76 | struct da903x_regulator_info { |
77 | struct regulator_desc desc; | 77 | struct regulator_desc desc; |
78 | 78 | ||
79 | int min_uV; | ||
80 | int max_uV; | 79 | int max_uV; |
81 | int step_uV; | ||
82 | int vol_reg; | 80 | int vol_reg; |
83 | int vol_shift; | 81 | int vol_shift; |
84 | int vol_nbits; | 82 | int vol_nbits; |
@@ -88,10 +86,6 @@ struct da903x_regulator_info { | |||
88 | int enable_bit; | 86 | int enable_bit; |
89 | }; | 87 | }; |
90 | 88 | ||
91 | static int da9034_ldo12_data[] = { 1700, 1750, 1800, 1850, 1900, 1950, | ||
92 | 2000, 2050, 2700, 2750, 2800, 2850, | ||
93 | 2900, 2950, 3000, 3050 }; | ||
94 | |||
95 | static inline struct device *to_da903x_dev(struct regulator_dev *rdev) | 89 | static inline struct device *to_da903x_dev(struct regulator_dev *rdev) |
96 | { | 90 | { |
97 | return rdev_get_dev(rdev)->parent->parent; | 91 | return rdev_get_dev(rdev)->parent->parent; |
@@ -100,34 +94,26 @@ static inline struct device *to_da903x_dev(struct regulator_dev *rdev) | |||
100 | static inline int check_range(struct da903x_regulator_info *info, | 94 | static inline int check_range(struct da903x_regulator_info *info, |
101 | int min_uV, int max_uV) | 95 | int min_uV, int max_uV) |
102 | { | 96 | { |
103 | if (min_uV < info->min_uV || min_uV > info->max_uV) | 97 | if (min_uV < info->desc.min_uV || min_uV > info->max_uV) |
104 | return -EINVAL; | 98 | return -EINVAL; |
105 | 99 | ||
106 | return 0; | 100 | return 0; |
107 | } | 101 | } |
108 | 102 | ||
109 | /* DA9030/DA9034 common operations */ | 103 | /* DA9030/DA9034 common operations */ |
110 | static int da903x_set_ldo_voltage(struct regulator_dev *rdev, | 104 | static int da903x_set_voltage_sel(struct regulator_dev *rdev, unsigned selector) |
111 | int min_uV, int max_uV, unsigned *selector) | ||
112 | { | 105 | { |
113 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | 106 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); |
114 | struct device *da9034_dev = to_da903x_dev(rdev); | 107 | struct device *da9034_dev = to_da903x_dev(rdev); |
115 | uint8_t val, mask; | 108 | uint8_t val, mask; |
116 | 109 | ||
117 | if (check_range(info, min_uV, max_uV)) { | 110 | val = selector << info->vol_shift; |
118 | pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV); | ||
119 | return -EINVAL; | ||
120 | } | ||
121 | |||
122 | val = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV); | ||
123 | *selector = val; | ||
124 | val <<= info->vol_shift; | ||
125 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; | 111 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; |
126 | 112 | ||
127 | return da903x_update(da9034_dev, info->vol_reg, val, mask); | 113 | return da903x_update(da9034_dev, info->vol_reg, val, mask); |
128 | } | 114 | } |
129 | 115 | ||
130 | static int da903x_get_voltage(struct regulator_dev *rdev) | 116 | static int da903x_get_voltage_sel(struct regulator_dev *rdev) |
131 | { | 117 | { |
132 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | 118 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); |
133 | struct device *da9034_dev = to_da903x_dev(rdev); | 119 | struct device *da9034_dev = to_da903x_dev(rdev); |
@@ -141,7 +127,7 @@ static int da903x_get_voltage(struct regulator_dev *rdev) | |||
141 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; | 127 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; |
142 | val = (val & mask) >> info->vol_shift; | 128 | val = (val & mask) >> info->vol_shift; |
143 | 129 | ||
144 | return info->min_uV + info->step_uV * val; | 130 | return val; |
145 | } | 131 | } |
146 | 132 | ||
147 | static int da903x_enable(struct regulator_dev *rdev) | 133 | static int da903x_enable(struct regulator_dev *rdev) |
@@ -176,35 +162,16 @@ static int da903x_is_enabled(struct regulator_dev *rdev) | |||
176 | return !!(reg_val & (1 << info->enable_bit)); | 162 | return !!(reg_val & (1 << info->enable_bit)); |
177 | } | 163 | } |
178 | 164 | ||
179 | static int da903x_list_voltage(struct regulator_dev *rdev, unsigned selector) | ||
180 | { | ||
181 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | ||
182 | int ret; | ||
183 | |||
184 | ret = info->min_uV + info->step_uV * selector; | ||
185 | if (ret > info->max_uV) | ||
186 | return -EINVAL; | ||
187 | return ret; | ||
188 | } | ||
189 | |||
190 | /* DA9030 specific operations */ | 165 | /* DA9030 specific operations */ |
191 | static int da9030_set_ldo1_15_voltage(struct regulator_dev *rdev, | 166 | static int da9030_set_ldo1_15_voltage_sel(struct regulator_dev *rdev, |
192 | int min_uV, int max_uV, | 167 | unsigned selector) |
193 | unsigned *selector) | ||
194 | { | 168 | { |
195 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | 169 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); |
196 | struct device *da903x_dev = to_da903x_dev(rdev); | 170 | struct device *da903x_dev = to_da903x_dev(rdev); |
197 | uint8_t val, mask; | 171 | uint8_t val, mask; |
198 | int ret; | 172 | int ret; |
199 | 173 | ||
200 | if (check_range(info, min_uV, max_uV)) { | 174 | val = selector << info->vol_shift; |
201 | pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV); | ||
202 | return -EINVAL; | ||
203 | } | ||
204 | |||
205 | val = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV); | ||
206 | *selector = val; | ||
207 | val <<= info->vol_shift; | ||
208 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; | 175 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; |
209 | val |= DA9030_LDO_UNLOCK; /* have to set UNLOCK bits */ | 176 | val |= DA9030_LDO_UNLOCK; /* have to set UNLOCK bits */ |
210 | mask |= DA9030_LDO_UNLOCK_MASK; | 177 | mask |= DA9030_LDO_UNLOCK_MASK; |
@@ -217,73 +184,57 @@ static int da9030_set_ldo1_15_voltage(struct regulator_dev *rdev, | |||
217 | return da903x_update(da903x_dev, info->vol_reg, val, mask); | 184 | return da903x_update(da903x_dev, info->vol_reg, val, mask); |
218 | } | 185 | } |
219 | 186 | ||
220 | static int da9030_set_ldo14_voltage(struct regulator_dev *rdev, | 187 | static int da9030_map_ldo14_voltage(struct regulator_dev *rdev, |
221 | int min_uV, int max_uV, | 188 | int min_uV, int max_uV) |
222 | unsigned *selector) | ||
223 | { | 189 | { |
224 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | 190 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); |
225 | struct device *da903x_dev = to_da903x_dev(rdev); | 191 | int thresh, sel; |
226 | uint8_t val, mask; | ||
227 | int thresh; | ||
228 | 192 | ||
229 | if (check_range(info, min_uV, max_uV)) { | 193 | if (check_range(info, min_uV, max_uV)) { |
230 | pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV); | 194 | pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV); |
231 | return -EINVAL; | 195 | return -EINVAL; |
232 | } | 196 | } |
233 | 197 | ||
234 | thresh = (info->max_uV + info->min_uV) / 2; | 198 | thresh = (info->max_uV + info->desc.min_uV) / 2; |
235 | if (min_uV < thresh) { | 199 | if (min_uV < thresh) { |
236 | val = DIV_ROUND_UP(thresh - min_uV, info->step_uV); | 200 | sel = DIV_ROUND_UP(thresh - min_uV, info->desc.uV_step); |
237 | val |= 0x4; | 201 | sel |= 0x4; |
238 | } else { | 202 | } else { |
239 | val = DIV_ROUND_UP(min_uV - thresh, info->step_uV); | 203 | sel = DIV_ROUND_UP(min_uV - thresh, info->desc.uV_step); |
240 | } | 204 | } |
241 | 205 | ||
242 | *selector = val; | 206 | return sel; |
243 | val <<= info->vol_shift; | ||
244 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; | ||
245 | |||
246 | return da903x_update(da903x_dev, info->vol_reg, val, mask); | ||
247 | } | 207 | } |
248 | 208 | ||
249 | static int da9030_get_ldo14_voltage(struct regulator_dev *rdev) | 209 | static int da9030_list_ldo14_voltage(struct regulator_dev *rdev, |
210 | unsigned selector) | ||
250 | { | 211 | { |
251 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | 212 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); |
252 | struct device *da903x_dev = to_da903x_dev(rdev); | 213 | int volt; |
253 | uint8_t val, mask; | ||
254 | int ret; | ||
255 | 214 | ||
256 | ret = da903x_read(da903x_dev, info->vol_reg, &val); | 215 | if (selector & 0x4) |
257 | if (ret) | 216 | volt = rdev->desc->min_uV + |
258 | return ret; | 217 | rdev->desc->uV_step * (3 - (selector & ~0x4)); |
218 | else | ||
219 | volt = (info->max_uV + rdev->desc->min_uV) / 2 + | ||
220 | rdev->desc->uV_step * (selector & ~0x4); | ||
259 | 221 | ||
260 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; | 222 | if (volt > info->max_uV) |
261 | val = (val & mask) >> info->vol_shift; | 223 | return -EINVAL; |
262 | 224 | ||
263 | if (val & 0x4) | 225 | return volt; |
264 | return info->min_uV + info->step_uV * (3 - (val & ~0x4)); | ||
265 | else | ||
266 | return (info->max_uV + info->min_uV) / 2 + | ||
267 | info->step_uV * (val & ~0x4); | ||
268 | } | 226 | } |
269 | 227 | ||
270 | /* DA9034 specific operations */ | 228 | /* DA9034 specific operations */ |
271 | static int da9034_set_dvc_voltage(struct regulator_dev *rdev, | 229 | static int da9034_set_dvc_voltage_sel(struct regulator_dev *rdev, |
272 | int min_uV, int max_uV, unsigned *selector) | 230 | unsigned selector) |
273 | { | 231 | { |
274 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | 232 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); |
275 | struct device *da9034_dev = to_da903x_dev(rdev); | 233 | struct device *da9034_dev = to_da903x_dev(rdev); |
276 | uint8_t val, mask; | 234 | uint8_t val, mask; |
277 | int ret; | 235 | int ret; |
278 | 236 | ||
279 | if (check_range(info, min_uV, max_uV)) { | 237 | val = selector << info->vol_shift; |
280 | pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV); | ||
281 | return -EINVAL; | ||
282 | } | ||
283 | |||
284 | val = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV); | ||
285 | *selector = val; | ||
286 | val <<= info->vol_shift; | ||
287 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; | 238 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; |
288 | 239 | ||
289 | ret = da903x_update(da9034_dev, info->vol_reg, val, mask); | 240 | ret = da903x_update(da9034_dev, info->vol_reg, val, mask); |
@@ -295,59 +246,45 @@ static int da9034_set_dvc_voltage(struct regulator_dev *rdev, | |||
295 | return ret; | 246 | return ret; |
296 | } | 247 | } |
297 | 248 | ||
298 | static int da9034_set_ldo12_voltage(struct regulator_dev *rdev, | 249 | static int da9034_map_ldo12_voltage(struct regulator_dev *rdev, |
299 | int min_uV, int max_uV, unsigned *selector) | 250 | int min_uV, int max_uV) |
300 | { | 251 | { |
301 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | 252 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); |
302 | struct device *da9034_dev = to_da903x_dev(rdev); | 253 | int sel; |
303 | uint8_t val, mask; | ||
304 | 254 | ||
305 | if (check_range(info, min_uV, max_uV)) { | 255 | if (check_range(info, min_uV, max_uV)) { |
306 | pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV); | 256 | pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV); |
307 | return -EINVAL; | 257 | return -EINVAL; |
308 | } | 258 | } |
309 | 259 | ||
310 | val = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV); | 260 | sel = DIV_ROUND_UP(min_uV - info->desc.min_uV, info->desc.uV_step); |
311 | val = (val >= 20) ? val - 12 : ((val > 7) ? 8 : val); | 261 | sel = (sel >= 20) ? sel - 12 : ((sel > 7) ? 8 : sel); |
312 | *selector = val; | ||
313 | val <<= info->vol_shift; | ||
314 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; | ||
315 | 262 | ||
316 | return da903x_update(da9034_dev, info->vol_reg, val, mask); | 263 | return sel; |
317 | } | 264 | } |
318 | 265 | ||
319 | static int da9034_get_ldo12_voltage(struct regulator_dev *rdev) | 266 | static int da9034_list_ldo12_voltage(struct regulator_dev *rdev, |
267 | unsigned selector) | ||
320 | { | 268 | { |
321 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); | 269 | struct da903x_regulator_info *info = rdev_get_drvdata(rdev); |
322 | struct device *da9034_dev = to_da903x_dev(rdev); | 270 | int volt; |
323 | uint8_t val, mask; | ||
324 | int ret; | ||
325 | |||
326 | ret = da903x_read(da9034_dev, info->vol_reg, &val); | ||
327 | if (ret) | ||
328 | return ret; | ||
329 | |||
330 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; | ||
331 | val = (val & mask) >> info->vol_shift; | ||
332 | 271 | ||
333 | if (val >= 8) | 272 | if (selector >= 8) |
334 | return 2700000 + info->step_uV * (val - 8); | 273 | volt = 2700000 + rdev->desc->uV_step * (selector - 8); |
335 | 274 | else | |
336 | return info->min_uV + info->step_uV * val; | 275 | volt = rdev->desc->min_uV + rdev->desc->uV_step * selector; |
337 | } | ||
338 | 276 | ||
339 | static int da9034_list_ldo12_voltage(struct regulator_dev *rdev, | 277 | if (volt > info->max_uV) |
340 | unsigned selector) | ||
341 | { | ||
342 | if (selector >= ARRAY_SIZE(da9034_ldo12_data)) | ||
343 | return -EINVAL; | 278 | return -EINVAL; |
344 | return da9034_ldo12_data[selector] * 1000; | 279 | |
280 | return volt; | ||
345 | } | 281 | } |
346 | 282 | ||
347 | static struct regulator_ops da903x_regulator_ldo_ops = { | 283 | static struct regulator_ops da903x_regulator_ldo_ops = { |
348 | .set_voltage = da903x_set_ldo_voltage, | 284 | .set_voltage_sel = da903x_set_voltage_sel, |
349 | .get_voltage = da903x_get_voltage, | 285 | .get_voltage_sel = da903x_get_voltage_sel, |
350 | .list_voltage = da903x_list_voltage, | 286 | .list_voltage = regulator_list_voltage_linear, |
287 | .map_voltage = regulator_map_voltage_linear, | ||
351 | .enable = da903x_enable, | 288 | .enable = da903x_enable, |
352 | .disable = da903x_disable, | 289 | .disable = da903x_disable, |
353 | .is_enabled = da903x_is_enabled, | 290 | .is_enabled = da903x_is_enabled, |
@@ -355,9 +292,10 @@ static struct regulator_ops da903x_regulator_ldo_ops = { | |||
355 | 292 | ||
356 | /* NOTE: this is dedicated for the insane DA9030 LDO14 */ | 293 | /* NOTE: this is dedicated for the insane DA9030 LDO14 */ |
357 | static struct regulator_ops da9030_regulator_ldo14_ops = { | 294 | static struct regulator_ops da9030_regulator_ldo14_ops = { |
358 | .set_voltage = da9030_set_ldo14_voltage, | 295 | .set_voltage_sel = da903x_set_voltage_sel, |
359 | .get_voltage = da9030_get_ldo14_voltage, | 296 | .get_voltage_sel = da903x_get_voltage_sel, |
360 | .list_voltage = da903x_list_voltage, | 297 | .list_voltage = da9030_list_ldo14_voltage, |
298 | .map_voltage = da9030_map_ldo14_voltage, | ||
361 | .enable = da903x_enable, | 299 | .enable = da903x_enable, |
362 | .disable = da903x_disable, | 300 | .disable = da903x_disable, |
363 | .is_enabled = da903x_is_enabled, | 301 | .is_enabled = da903x_is_enabled, |
@@ -365,18 +303,20 @@ static struct regulator_ops da9030_regulator_ldo14_ops = { | |||
365 | 303 | ||
366 | /* NOTE: this is dedicated for the DA9030 LDO1 and LDO15 that have locks */ | 304 | /* NOTE: this is dedicated for the DA9030 LDO1 and LDO15 that have locks */ |
367 | static struct regulator_ops da9030_regulator_ldo1_15_ops = { | 305 | static struct regulator_ops da9030_regulator_ldo1_15_ops = { |
368 | .set_voltage = da9030_set_ldo1_15_voltage, | 306 | .set_voltage_sel = da9030_set_ldo1_15_voltage_sel, |
369 | .get_voltage = da903x_get_voltage, | 307 | .get_voltage_sel = da903x_get_voltage_sel, |
370 | .list_voltage = da903x_list_voltage, | 308 | .list_voltage = regulator_list_voltage_linear, |
309 | .map_voltage = regulator_map_voltage_linear, | ||
371 | .enable = da903x_enable, | 310 | .enable = da903x_enable, |
372 | .disable = da903x_disable, | 311 | .disable = da903x_disable, |
373 | .is_enabled = da903x_is_enabled, | 312 | .is_enabled = da903x_is_enabled, |
374 | }; | 313 | }; |
375 | 314 | ||
376 | static struct regulator_ops da9034_regulator_dvc_ops = { | 315 | static struct regulator_ops da9034_regulator_dvc_ops = { |
377 | .set_voltage = da9034_set_dvc_voltage, | 316 | .set_voltage_sel = da9034_set_dvc_voltage_sel, |
378 | .get_voltage = da903x_get_voltage, | 317 | .get_voltage_sel = da903x_get_voltage_sel, |
379 | .list_voltage = da903x_list_voltage, | 318 | .list_voltage = regulator_list_voltage_linear, |
319 | .map_voltage = regulator_map_voltage_linear, | ||
380 | .enable = da903x_enable, | 320 | .enable = da903x_enable, |
381 | .disable = da903x_disable, | 321 | .disable = da903x_disable, |
382 | .is_enabled = da903x_is_enabled, | 322 | .is_enabled = da903x_is_enabled, |
@@ -384,9 +324,10 @@ static struct regulator_ops da9034_regulator_dvc_ops = { | |||
384 | 324 | ||
385 | /* NOTE: this is dedicated for the insane LDO12 */ | 325 | /* NOTE: this is dedicated for the insane LDO12 */ |
386 | static struct regulator_ops da9034_regulator_ldo12_ops = { | 326 | static struct regulator_ops da9034_regulator_ldo12_ops = { |
387 | .set_voltage = da9034_set_ldo12_voltage, | 327 | .set_voltage_sel = da903x_set_voltage_sel, |
388 | .get_voltage = da9034_get_ldo12_voltage, | 328 | .get_voltage_sel = da903x_get_voltage_sel, |
389 | .list_voltage = da9034_list_ldo12_voltage, | 329 | .list_voltage = da9034_list_ldo12_voltage, |
330 | .map_voltage = da9034_map_ldo12_voltage, | ||
390 | .enable = da903x_enable, | 331 | .enable = da903x_enable, |
391 | .disable = da903x_disable, | 332 | .disable = da903x_disable, |
392 | .is_enabled = da903x_is_enabled, | 333 | .is_enabled = da903x_is_enabled, |
@@ -401,10 +342,10 @@ static struct regulator_ops da9034_regulator_ldo12_ops = { | |||
401 | .id = _pmic##_ID_LDO##_id, \ | 342 | .id = _pmic##_ID_LDO##_id, \ |
402 | .n_voltages = (step) ? ((max - min) / step + 1) : 1, \ | 343 | .n_voltages = (step) ? ((max - min) / step + 1) : 1, \ |
403 | .owner = THIS_MODULE, \ | 344 | .owner = THIS_MODULE, \ |
345 | .min_uV = (min) * 1000, \ | ||
346 | .uV_step = (step) * 1000, \ | ||
404 | }, \ | 347 | }, \ |
405 | .min_uV = (min) * 1000, \ | ||
406 | .max_uV = (max) * 1000, \ | 348 | .max_uV = (max) * 1000, \ |
407 | .step_uV = (step) * 1000, \ | ||
408 | .vol_reg = _pmic##_##vreg, \ | 349 | .vol_reg = _pmic##_##vreg, \ |
409 | .vol_shift = (shift), \ | 350 | .vol_shift = (shift), \ |
410 | .vol_nbits = (nbits), \ | 351 | .vol_nbits = (nbits), \ |
@@ -421,10 +362,10 @@ static struct regulator_ops da9034_regulator_ldo12_ops = { | |||
421 | .id = _pmic##_ID_##_id, \ | 362 | .id = _pmic##_ID_##_id, \ |
422 | .n_voltages = (step) ? ((max - min) / step + 1) : 1, \ | 363 | .n_voltages = (step) ? ((max - min) / step + 1) : 1, \ |
423 | .owner = THIS_MODULE, \ | 364 | .owner = THIS_MODULE, \ |
365 | .min_uV = (min) * 1000, \ | ||
366 | .uV_step = (step) * 1000, \ | ||
424 | }, \ | 367 | }, \ |
425 | .min_uV = (min) * 1000, \ | ||
426 | .max_uV = (max) * 1000, \ | 368 | .max_uV = (max) * 1000, \ |
427 | .step_uV = (step) * 1000, \ | ||
428 | .vol_reg = _pmic##_##vreg, \ | 369 | .vol_reg = _pmic##_##vreg, \ |
429 | .vol_shift = (0), \ | 370 | .vol_shift = (0), \ |
430 | .vol_nbits = (nbits), \ | 371 | .vol_nbits = (nbits), \ |
@@ -517,6 +458,7 @@ static int __devinit da903x_regulator_probe(struct platform_device *pdev) | |||
517 | { | 458 | { |
518 | struct da903x_regulator_info *ri = NULL; | 459 | struct da903x_regulator_info *ri = NULL; |
519 | struct regulator_dev *rdev; | 460 | struct regulator_dev *rdev; |
461 | struct regulator_config config = { }; | ||
520 | 462 | ||
521 | ri = find_regulator_info(pdev->id); | 463 | ri = find_regulator_info(pdev->id); |
522 | if (ri == NULL) { | 464 | if (ri == NULL) { |
@@ -527,7 +469,7 @@ static int __devinit da903x_regulator_probe(struct platform_device *pdev) | |||
527 | /* Workaround for the weird LDO12 voltage setting */ | 469 | /* Workaround for the weird LDO12 voltage setting */ |
528 | if (ri->desc.id == DA9034_ID_LDO12) { | 470 | if (ri->desc.id == DA9034_ID_LDO12) { |
529 | ri->desc.ops = &da9034_regulator_ldo12_ops; | 471 | ri->desc.ops = &da9034_regulator_ldo12_ops; |
530 | ri->desc.n_voltages = ARRAY_SIZE(da9034_ldo12_data); | 472 | ri->desc.n_voltages = 16; |
531 | } | 473 | } |
532 | 474 | ||
533 | if (ri->desc.id == DA9030_ID_LDO14) | 475 | if (ri->desc.id == DA9030_ID_LDO14) |
@@ -536,8 +478,11 @@ static int __devinit da903x_regulator_probe(struct platform_device *pdev) | |||
536 | if (ri->desc.id == DA9030_ID_LDO1 || ri->desc.id == DA9030_ID_LDO15) | 478 | if (ri->desc.id == DA9030_ID_LDO1 || ri->desc.id == DA9030_ID_LDO15) |
537 | ri->desc.ops = &da9030_regulator_ldo1_15_ops; | 479 | ri->desc.ops = &da9030_regulator_ldo1_15_ops; |
538 | 480 | ||
539 | rdev = regulator_register(&ri->desc, &pdev->dev, | 481 | config.dev = &pdev->dev; |
540 | pdev->dev.platform_data, ri, NULL); | 482 | config.init_data = pdev->dev.platform_data; |
483 | config.driver_data = ri; | ||
484 | |||
485 | rdev = regulator_register(&ri->desc, &config); | ||
541 | if (IS_ERR(rdev)) { | 486 | if (IS_ERR(rdev)) { |
542 | dev_err(&pdev->dev, "failed to register regulator %s\n", | 487 | dev_err(&pdev->dev, "failed to register regulator %s\n", |
543 | ri->desc.name); | 488 | ri->desc.name); |
diff --git a/drivers/regulator/da9052-regulator.c b/drivers/regulator/da9052-regulator.c index 09915e89705d..88976d8d44ed 100644 --- a/drivers/regulator/da9052-regulator.c +++ b/drivers/regulator/da9052-regulator.c | |||
@@ -19,6 +19,10 @@ | |||
19 | #include <linux/platform_device.h> | 19 | #include <linux/platform_device.h> |
20 | #include <linux/regulator/driver.h> | 20 | #include <linux/regulator/driver.h> |
21 | #include <linux/regulator/machine.h> | 21 | #include <linux/regulator/machine.h> |
22 | #ifdef CONFIG_OF | ||
23 | #include <linux/of.h> | ||
24 | #include <linux/regulator/of_regulator.h> | ||
25 | #endif | ||
22 | 26 | ||
23 | #include <linux/mfd/da9052/da9052.h> | 27 | #include <linux/mfd/da9052/da9052.h> |
24 | #include <linux/mfd/da9052/reg.h> | 28 | #include <linux/mfd/da9052/reg.h> |
@@ -37,6 +41,22 @@ | |||
37 | #define DA9052_BUCK_ILIM_MASK_EVEN 0x0c | 41 | #define DA9052_BUCK_ILIM_MASK_EVEN 0x0c |
38 | #define DA9052_BUCK_ILIM_MASK_ODD 0xc0 | 42 | #define DA9052_BUCK_ILIM_MASK_ODD 0xc0 |
39 | 43 | ||
44 | /* DA9052 REGULATOR IDs */ | ||
45 | #define DA9052_ID_BUCK1 0 | ||
46 | #define DA9052_ID_BUCK2 1 | ||
47 | #define DA9052_ID_BUCK3 2 | ||
48 | #define DA9052_ID_BUCK4 3 | ||
49 | #define DA9052_ID_LDO1 4 | ||
50 | #define DA9052_ID_LDO2 5 | ||
51 | #define DA9052_ID_LDO3 6 | ||
52 | #define DA9052_ID_LDO4 7 | ||
53 | #define DA9052_ID_LDO5 8 | ||
54 | #define DA9052_ID_LDO6 9 | ||
55 | #define DA9052_ID_LDO7 10 | ||
56 | #define DA9052_ID_LDO8 11 | ||
57 | #define DA9052_ID_LDO9 12 | ||
58 | #define DA9052_ID_LDO10 13 | ||
59 | |||
40 | static const u32 da9052_current_limits[3][4] = { | 60 | static const u32 da9052_current_limits[3][4] = { |
41 | {700000, 800000, 1000000, 1200000}, /* DA9052-BC BUCKs */ | 61 | {700000, 800000, 1000000, 1200000}, /* DA9052-BC BUCKs */ |
42 | {1600000, 2000000, 2400000, 3000000}, /* DA9053-AA/Bx BUCK-CORE */ | 62 | {1600000, 2000000, 2400000, 3000000}, /* DA9053-AA/Bx BUCK-CORE */ |
@@ -50,8 +70,6 @@ struct da9052_regulator_info { | |||
50 | int step_uV; | 70 | int step_uV; |
51 | int min_uV; | 71 | int min_uV; |
52 | int max_uV; | 72 | int max_uV; |
53 | unsigned char volt_shift; | ||
54 | unsigned char en_bit; | ||
55 | unsigned char activate_bit; | 73 | unsigned char activate_bit; |
56 | }; | 74 | }; |
57 | 75 | ||
@@ -70,42 +88,6 @@ static int verify_range(struct da9052_regulator_info *info, | |||
70 | return 0; | 88 | return 0; |
71 | } | 89 | } |
72 | 90 | ||
73 | static int da9052_regulator_enable(struct regulator_dev *rdev) | ||
74 | { | ||
75 | struct da9052_regulator *regulator = rdev_get_drvdata(rdev); | ||
76 | struct da9052_regulator_info *info = regulator->info; | ||
77 | int offset = rdev_get_id(rdev); | ||
78 | |||
79 | return da9052_reg_update(regulator->da9052, | ||
80 | DA9052_BUCKCORE_REG + offset, | ||
81 | 1 << info->en_bit, 1 << info->en_bit); | ||
82 | } | ||
83 | |||
84 | static int da9052_regulator_disable(struct regulator_dev *rdev) | ||
85 | { | ||
86 | struct da9052_regulator *regulator = rdev_get_drvdata(rdev); | ||
87 | struct da9052_regulator_info *info = regulator->info; | ||
88 | int offset = rdev_get_id(rdev); | ||
89 | |||
90 | return da9052_reg_update(regulator->da9052, | ||
91 | DA9052_BUCKCORE_REG + offset, | ||
92 | 1 << info->en_bit, 0); | ||
93 | } | ||
94 | |||
95 | static int da9052_regulator_is_enabled(struct regulator_dev *rdev) | ||
96 | { | ||
97 | struct da9052_regulator *regulator = rdev_get_drvdata(rdev); | ||
98 | struct da9052_regulator_info *info = regulator->info; | ||
99 | int offset = rdev_get_id(rdev); | ||
100 | int ret; | ||
101 | |||
102 | ret = da9052_reg_read(regulator->da9052, DA9052_BUCKCORE_REG + offset); | ||
103 | if (ret < 0) | ||
104 | return ret; | ||
105 | |||
106 | return ret & (1 << info->en_bit); | ||
107 | } | ||
108 | |||
109 | static int da9052_dcdc_get_current_limit(struct regulator_dev *rdev) | 91 | static int da9052_dcdc_get_current_limit(struct regulator_dev *rdev) |
110 | { | 92 | { |
111 | struct da9052_regulator *regulator = rdev_get_drvdata(rdev); | 93 | struct da9052_regulator *regulator = rdev_get_drvdata(rdev); |
@@ -173,36 +155,23 @@ static int da9052_dcdc_set_current_limit(struct regulator_dev *rdev, int min_uA, | |||
173 | reg_val << 6); | 155 | reg_val << 6); |
174 | } | 156 | } |
175 | 157 | ||
176 | static int da9052_list_buckperi_voltage(struct regulator_dev *rdev, | ||
177 | unsigned int selector) | ||
178 | { | ||
179 | struct da9052_regulator *regulator = rdev_get_drvdata(rdev); | ||
180 | struct da9052_regulator_info *info = regulator->info; | ||
181 | int volt_uV; | ||
182 | |||
183 | if ((regulator->da9052->chip_id == DA9052) && | ||
184 | (selector >= DA9052_BUCK_PERI_REG_MAP_UPTO_3uV)) { | ||
185 | volt_uV = ((DA9052_BUCK_PERI_REG_MAP_UPTO_3uV * info->step_uV) | ||
186 | + info->min_uV); | ||
187 | volt_uV += (selector - DA9052_BUCK_PERI_REG_MAP_UPTO_3uV) | ||
188 | * (DA9052_BUCK_PERI_3uV_STEP); | ||
189 | } else | ||
190 | volt_uV = (selector * info->step_uV) + info->min_uV; | ||
191 | |||
192 | if (volt_uV > info->max_uV) | ||
193 | return -EINVAL; | ||
194 | |||
195 | return volt_uV; | ||
196 | } | ||
197 | |||
198 | static int da9052_list_voltage(struct regulator_dev *rdev, | 158 | static int da9052_list_voltage(struct regulator_dev *rdev, |
199 | unsigned int selector) | 159 | unsigned int selector) |
200 | { | 160 | { |
201 | struct da9052_regulator *regulator = rdev_get_drvdata(rdev); | 161 | struct da9052_regulator *regulator = rdev_get_drvdata(rdev); |
202 | struct da9052_regulator_info *info = regulator->info; | 162 | struct da9052_regulator_info *info = regulator->info; |
163 | int id = rdev_get_id(rdev); | ||
203 | int volt_uV; | 164 | int volt_uV; |
204 | 165 | ||
205 | volt_uV = info->min_uV + info->step_uV * selector; | 166 | if ((id == DA9052_ID_BUCK4) && (regulator->da9052->chip_id == DA9052) |
167 | && (selector >= DA9052_BUCK_PERI_REG_MAP_UPTO_3uV)) { | ||
168 | volt_uV = ((DA9052_BUCK_PERI_REG_MAP_UPTO_3uV * info->step_uV) | ||
169 | + info->min_uV); | ||
170 | volt_uV += (selector - DA9052_BUCK_PERI_REG_MAP_UPTO_3uV) | ||
171 | * (DA9052_BUCK_PERI_3uV_STEP); | ||
172 | } else { | ||
173 | volt_uV = (selector * info->step_uV) + info->min_uV; | ||
174 | } | ||
206 | 175 | ||
207 | if (volt_uV > info->max_uV) | 176 | if (volt_uV > info->max_uV) |
208 | return -EINVAL; | 177 | return -EINVAL; |
@@ -210,103 +179,13 @@ static int da9052_list_voltage(struct regulator_dev *rdev, | |||
210 | return volt_uV; | 179 | return volt_uV; |
211 | } | 180 | } |
212 | 181 | ||
213 | static int da9052_regulator_set_voltage_int(struct regulator_dev *rdev, | 182 | static int da9052_map_voltage(struct regulator_dev *rdev, |
214 | int min_uV, int max_uV, | 183 | int min_uV, int max_uV) |
215 | unsigned int *selector) | ||
216 | { | ||
217 | struct da9052_regulator *regulator = rdev_get_drvdata(rdev); | ||
218 | struct da9052_regulator_info *info = regulator->info; | ||
219 | int offset = rdev_get_id(rdev); | ||
220 | int ret; | ||
221 | |||
222 | ret = verify_range(info, min_uV, max_uV); | ||
223 | if (ret < 0) | ||
224 | return ret; | ||
225 | |||
226 | if (min_uV < info->min_uV) | ||
227 | min_uV = info->min_uV; | ||
228 | |||
229 | *selector = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV); | ||
230 | |||
231 | ret = da9052_list_voltage(rdev, *selector); | ||
232 | if (ret < 0) | ||
233 | return ret; | ||
234 | |||
235 | return da9052_reg_update(regulator->da9052, | ||
236 | DA9052_BUCKCORE_REG + offset, | ||
237 | (1 << info->volt_shift) - 1, *selector); | ||
238 | } | ||
239 | |||
240 | static int da9052_set_ldo_voltage(struct regulator_dev *rdev, | ||
241 | int min_uV, int max_uV, | ||
242 | unsigned int *selector) | ||
243 | { | ||
244 | return da9052_regulator_set_voltage_int(rdev, min_uV, max_uV, selector); | ||
245 | } | ||
246 | |||
247 | static int da9052_set_ldo5_6_voltage(struct regulator_dev *rdev, | ||
248 | int min_uV, int max_uV, | ||
249 | unsigned int *selector) | ||
250 | { | ||
251 | struct da9052_regulator *regulator = rdev_get_drvdata(rdev); | ||
252 | struct da9052_regulator_info *info = regulator->info; | ||
253 | int ret; | ||
254 | |||
255 | ret = da9052_regulator_set_voltage_int(rdev, min_uV, max_uV, selector); | ||
256 | if (ret < 0) | ||
257 | return ret; | ||
258 | |||
259 | /* Some LDOs are DVC controlled which requires enabling of | ||
260 | * the LDO activate bit to implment the changes on the | ||
261 | * LDO output. | ||
262 | */ | ||
263 | return da9052_reg_update(regulator->da9052, DA9052_SUPPLY_REG, | ||
264 | info->activate_bit, info->activate_bit); | ||
265 | } | ||
266 | |||
267 | static int da9052_set_dcdc_voltage(struct regulator_dev *rdev, | ||
268 | int min_uV, int max_uV, | ||
269 | unsigned int *selector) | ||
270 | { | ||
271 | struct da9052_regulator *regulator = rdev_get_drvdata(rdev); | ||
272 | struct da9052_regulator_info *info = regulator->info; | ||
273 | int ret; | ||
274 | |||
275 | ret = da9052_regulator_set_voltage_int(rdev, min_uV, max_uV, selector); | ||
276 | if (ret < 0) | ||
277 | return ret; | ||
278 | |||
279 | /* Some DCDCs are DVC controlled which requires enabling of | ||
280 | * the DCDC activate bit to implment the changes on the | ||
281 | * DCDC output. | ||
282 | */ | ||
283 | return da9052_reg_update(regulator->da9052, DA9052_SUPPLY_REG, | ||
284 | info->activate_bit, info->activate_bit); | ||
285 | } | ||
286 | |||
287 | static int da9052_get_regulator_voltage_sel(struct regulator_dev *rdev) | ||
288 | { | ||
289 | struct da9052_regulator *regulator = rdev_get_drvdata(rdev); | ||
290 | struct da9052_regulator_info *info = regulator->info; | ||
291 | int offset = rdev_get_id(rdev); | ||
292 | int ret; | ||
293 | |||
294 | ret = da9052_reg_read(regulator->da9052, DA9052_BUCKCORE_REG + offset); | ||
295 | if (ret < 0) | ||
296 | return ret; | ||
297 | |||
298 | ret &= ((1 << info->volt_shift) - 1); | ||
299 | |||
300 | return ret; | ||
301 | } | ||
302 | |||
303 | static int da9052_set_buckperi_voltage(struct regulator_dev *rdev, int min_uV, | ||
304 | int max_uV, unsigned int *selector) | ||
305 | { | 184 | { |
306 | struct da9052_regulator *regulator = rdev_get_drvdata(rdev); | 185 | struct da9052_regulator *regulator = rdev_get_drvdata(rdev); |
307 | struct da9052_regulator_info *info = regulator->info; | 186 | struct da9052_regulator_info *info = regulator->info; |
308 | int offset = rdev_get_id(rdev); | 187 | int id = rdev_get_id(rdev); |
309 | int ret; | 188 | int ret, sel; |
310 | 189 | ||
311 | ret = verify_range(info, min_uV, max_uV); | 190 | ret = verify_range(info, min_uV, max_uV); |
312 | if (ret < 0) | 191 | if (ret < 0) |
@@ -315,192 +194,147 @@ static int da9052_set_buckperi_voltage(struct regulator_dev *rdev, int min_uV, | |||
315 | if (min_uV < info->min_uV) | 194 | if (min_uV < info->min_uV) |
316 | min_uV = info->min_uV; | 195 | min_uV = info->min_uV; |
317 | 196 | ||
318 | if ((regulator->da9052->chip_id == DA9052) && | 197 | if ((id == DA9052_ID_BUCK4) && (regulator->da9052->chip_id == DA9052) |
319 | (min_uV >= DA9052_CONST_3uV)) | 198 | && (min_uV >= DA9052_CONST_3uV)) { |
320 | *selector = DA9052_BUCK_PERI_REG_MAP_UPTO_3uV + | 199 | sel = DA9052_BUCK_PERI_REG_MAP_UPTO_3uV + |
321 | DIV_ROUND_UP(min_uV - DA9052_CONST_3uV, | 200 | DIV_ROUND_UP(min_uV - DA9052_CONST_3uV, |
322 | DA9052_BUCK_PERI_3uV_STEP); | 201 | DA9052_BUCK_PERI_3uV_STEP); |
323 | else | 202 | } else { |
324 | *selector = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV); | 203 | sel = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV); |
204 | } | ||
325 | 205 | ||
326 | ret = da9052_list_buckperi_voltage(rdev, *selector); | 206 | ret = da9052_list_voltage(rdev, sel); |
327 | if (ret < 0) | 207 | if (ret < 0) |
328 | return ret; | 208 | return ret; |
329 | 209 | ||
330 | return da9052_reg_update(regulator->da9052, | 210 | return sel; |
331 | DA9052_BUCKCORE_REG + offset, | ||
332 | (1 << info->volt_shift) - 1, *selector); | ||
333 | } | 211 | } |
334 | 212 | ||
335 | static int da9052_get_buckperi_voltage_sel(struct regulator_dev *rdev) | 213 | static int da9052_regulator_set_voltage_sel(struct regulator_dev *rdev, |
214 | unsigned int selector) | ||
336 | { | 215 | { |
337 | struct da9052_regulator *regulator = rdev_get_drvdata(rdev); | 216 | struct da9052_regulator *regulator = rdev_get_drvdata(rdev); |
338 | struct da9052_regulator_info *info = regulator->info; | 217 | struct da9052_regulator_info *info = regulator->info; |
339 | int offset = rdev_get_id(rdev); | 218 | int id = rdev_get_id(rdev); |
340 | int ret; | 219 | int ret; |
341 | 220 | ||
342 | ret = da9052_reg_read(regulator->da9052, DA9052_BUCKCORE_REG + offset); | 221 | ret = da9052_reg_update(regulator->da9052, rdev->desc->vsel_reg, |
222 | rdev->desc->vsel_mask, selector); | ||
343 | if (ret < 0) | 223 | if (ret < 0) |
344 | return ret; | 224 | return ret; |
345 | 225 | ||
346 | ret &= ((1 << info->volt_shift) - 1); | 226 | /* Some LDOs and DCDCs are DVC controlled which requires enabling of |
227 | * the activate bit to implment the changes on the output. | ||
228 | */ | ||
229 | switch (id) { | ||
230 | case DA9052_ID_BUCK1: | ||
231 | case DA9052_ID_BUCK2: | ||
232 | case DA9052_ID_BUCK3: | ||
233 | case DA9052_ID_LDO2: | ||
234 | case DA9052_ID_LDO3: | ||
235 | ret = da9052_reg_update(regulator->da9052, DA9052_SUPPLY_REG, | ||
236 | info->activate_bit, info->activate_bit); | ||
237 | break; | ||
238 | } | ||
347 | 239 | ||
348 | return ret; | 240 | return ret; |
349 | } | 241 | } |
350 | 242 | ||
351 | static struct regulator_ops da9052_buckperi_ops = { | ||
352 | .list_voltage = da9052_list_buckperi_voltage, | ||
353 | .get_voltage_sel = da9052_get_buckperi_voltage_sel, | ||
354 | .set_voltage = da9052_set_buckperi_voltage, | ||
355 | |||
356 | .get_current_limit = da9052_dcdc_get_current_limit, | ||
357 | .set_current_limit = da9052_dcdc_set_current_limit, | ||
358 | |||
359 | .is_enabled = da9052_regulator_is_enabled, | ||
360 | .enable = da9052_regulator_enable, | ||
361 | .disable = da9052_regulator_disable, | ||
362 | }; | ||
363 | |||
364 | static struct regulator_ops da9052_dcdc_ops = { | 243 | static struct regulator_ops da9052_dcdc_ops = { |
365 | .set_voltage = da9052_set_dcdc_voltage, | ||
366 | .get_current_limit = da9052_dcdc_get_current_limit, | 244 | .get_current_limit = da9052_dcdc_get_current_limit, |
367 | .set_current_limit = da9052_dcdc_set_current_limit, | 245 | .set_current_limit = da9052_dcdc_set_current_limit, |
368 | 246 | ||
369 | .list_voltage = da9052_list_voltage, | 247 | .list_voltage = da9052_list_voltage, |
370 | .get_voltage_sel = da9052_get_regulator_voltage_sel, | 248 | .map_voltage = da9052_map_voltage, |
371 | .is_enabled = da9052_regulator_is_enabled, | 249 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
372 | .enable = da9052_regulator_enable, | 250 | .set_voltage_sel = da9052_regulator_set_voltage_sel, |
373 | .disable = da9052_regulator_disable, | 251 | .is_enabled = regulator_is_enabled_regmap, |
374 | }; | 252 | .enable = regulator_enable_regmap, |
375 | 253 | .disable = regulator_disable_regmap, | |
376 | static struct regulator_ops da9052_ldo5_6_ops = { | ||
377 | .set_voltage = da9052_set_ldo5_6_voltage, | ||
378 | |||
379 | .list_voltage = da9052_list_voltage, | ||
380 | .get_voltage_sel = da9052_get_regulator_voltage_sel, | ||
381 | .is_enabled = da9052_regulator_is_enabled, | ||
382 | .enable = da9052_regulator_enable, | ||
383 | .disable = da9052_regulator_disable, | ||
384 | }; | 254 | }; |
385 | 255 | ||
386 | static struct regulator_ops da9052_ldo_ops = { | 256 | static struct regulator_ops da9052_ldo_ops = { |
387 | .set_voltage = da9052_set_ldo_voltage, | ||
388 | |||
389 | .list_voltage = da9052_list_voltage, | 257 | .list_voltage = da9052_list_voltage, |
390 | .get_voltage_sel = da9052_get_regulator_voltage_sel, | 258 | .map_voltage = da9052_map_voltage, |
391 | .is_enabled = da9052_regulator_is_enabled, | 259 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
392 | .enable = da9052_regulator_enable, | 260 | .set_voltage_sel = da9052_regulator_set_voltage_sel, |
393 | .disable = da9052_regulator_disable, | 261 | .is_enabled = regulator_is_enabled_regmap, |
262 | .enable = regulator_enable_regmap, | ||
263 | .disable = regulator_disable_regmap, | ||
394 | }; | 264 | }; |
395 | 265 | ||
396 | #define DA9052_LDO5_6(_id, step, min, max, sbits, ebits, abits) \ | ||
397 | {\ | ||
398 | .reg_desc = {\ | ||
399 | .name = "LDO" #_id,\ | ||
400 | .ops = &da9052_ldo5_6_ops,\ | ||
401 | .type = REGULATOR_VOLTAGE,\ | ||
402 | .id = _id,\ | ||
403 | .n_voltages = (max - min) / step + 1, \ | ||
404 | .owner = THIS_MODULE,\ | ||
405 | },\ | ||
406 | .min_uV = (min) * 1000,\ | ||
407 | .max_uV = (max) * 1000,\ | ||
408 | .step_uV = (step) * 1000,\ | ||
409 | .volt_shift = (sbits),\ | ||
410 | .en_bit = (ebits),\ | ||
411 | .activate_bit = (abits),\ | ||
412 | } | ||
413 | |||
414 | #define DA9052_LDO(_id, step, min, max, sbits, ebits, abits) \ | 266 | #define DA9052_LDO(_id, step, min, max, sbits, ebits, abits) \ |
415 | {\ | 267 | {\ |
416 | .reg_desc = {\ | 268 | .reg_desc = {\ |
417 | .name = "LDO" #_id,\ | 269 | .name = #_id,\ |
418 | .ops = &da9052_ldo_ops,\ | 270 | .ops = &da9052_ldo_ops,\ |
419 | .type = REGULATOR_VOLTAGE,\ | 271 | .type = REGULATOR_VOLTAGE,\ |
420 | .id = _id,\ | 272 | .id = DA9052_ID_##_id,\ |
421 | .n_voltages = (max - min) / step + 1, \ | 273 | .n_voltages = (max - min) / step + 1, \ |
422 | .owner = THIS_MODULE,\ | 274 | .owner = THIS_MODULE,\ |
275 | .vsel_reg = DA9052_BUCKCORE_REG + DA9052_ID_##_id, \ | ||
276 | .vsel_mask = (1 << (sbits)) - 1,\ | ||
277 | .enable_reg = DA9052_BUCKCORE_REG + DA9052_ID_##_id, \ | ||
278 | .enable_mask = 1 << (ebits),\ | ||
423 | },\ | 279 | },\ |
424 | .min_uV = (min) * 1000,\ | 280 | .min_uV = (min) * 1000,\ |
425 | .max_uV = (max) * 1000,\ | 281 | .max_uV = (max) * 1000,\ |
426 | .step_uV = (step) * 1000,\ | 282 | .step_uV = (step) * 1000,\ |
427 | .volt_shift = (sbits),\ | ||
428 | .en_bit = (ebits),\ | ||
429 | .activate_bit = (abits),\ | 283 | .activate_bit = (abits),\ |
430 | } | 284 | } |
431 | 285 | ||
432 | #define DA9052_DCDC(_id, step, min, max, sbits, ebits, abits) \ | 286 | #define DA9052_DCDC(_id, step, min, max, sbits, ebits, abits) \ |
433 | {\ | 287 | {\ |
434 | .reg_desc = {\ | 288 | .reg_desc = {\ |
435 | .name = "BUCK" #_id,\ | 289 | .name = #_id,\ |
436 | .ops = &da9052_dcdc_ops,\ | 290 | .ops = &da9052_dcdc_ops,\ |
437 | .type = REGULATOR_VOLTAGE,\ | 291 | .type = REGULATOR_VOLTAGE,\ |
438 | .id = _id,\ | 292 | .id = DA9052_ID_##_id,\ |
439 | .n_voltages = (max - min) / step + 1, \ | 293 | .n_voltages = (max - min) / step + 1, \ |
440 | .owner = THIS_MODULE,\ | 294 | .owner = THIS_MODULE,\ |
295 | .vsel_reg = DA9052_BUCKCORE_REG + DA9052_ID_##_id, \ | ||
296 | .vsel_mask = (1 << (sbits)) - 1,\ | ||
297 | .enable_reg = DA9052_BUCKCORE_REG + DA9052_ID_##_id, \ | ||
298 | .enable_mask = 1 << (ebits),\ | ||
441 | },\ | 299 | },\ |
442 | .min_uV = (min) * 1000,\ | 300 | .min_uV = (min) * 1000,\ |
443 | .max_uV = (max) * 1000,\ | 301 | .max_uV = (max) * 1000,\ |
444 | .step_uV = (step) * 1000,\ | 302 | .step_uV = (step) * 1000,\ |
445 | .volt_shift = (sbits),\ | ||
446 | .en_bit = (ebits),\ | ||
447 | .activate_bit = (abits),\ | ||
448 | } | ||
449 | |||
450 | #define DA9052_BUCKPERI(_id, step, min, max, sbits, ebits, abits) \ | ||
451 | {\ | ||
452 | .reg_desc = {\ | ||
453 | .name = "BUCK" #_id,\ | ||
454 | .ops = &da9052_buckperi_ops,\ | ||
455 | .type = REGULATOR_VOLTAGE,\ | ||
456 | .id = _id,\ | ||
457 | .n_voltages = (max - min) / step + 1, \ | ||
458 | .owner = THIS_MODULE,\ | ||
459 | },\ | ||
460 | .min_uV = (min) * 1000,\ | ||
461 | .max_uV = (max) * 1000,\ | ||
462 | .step_uV = (step) * 1000,\ | ||
463 | .volt_shift = (sbits),\ | ||
464 | .en_bit = (ebits),\ | ||
465 | .activate_bit = (abits),\ | 303 | .activate_bit = (abits),\ |
466 | } | 304 | } |
467 | 305 | ||
468 | static struct da9052_regulator_info da9052_regulator_info[] = { | 306 | static struct da9052_regulator_info da9052_regulator_info[] = { |
469 | /* Buck1 - 4 */ | 307 | DA9052_DCDC(BUCK1, 25, 500, 2075, 6, 6, DA9052_SUPPLY_VBCOREGO), |
470 | DA9052_DCDC(0, 25, 500, 2075, 6, 6, DA9052_SUPPLY_VBCOREGO), | 308 | DA9052_DCDC(BUCK2, 25, 500, 2075, 6, 6, DA9052_SUPPLY_VBPROGO), |
471 | DA9052_DCDC(1, 25, 500, 2075, 6, 6, DA9052_SUPPLY_VBPROGO), | 309 | DA9052_DCDC(BUCK3, 25, 925, 2500, 6, 6, DA9052_SUPPLY_VBMEMGO), |
472 | DA9052_DCDC(2, 25, 925, 2500, 6, 6, DA9052_SUPPLY_VBMEMGO), | 310 | DA9052_DCDC(BUCK4, 50, 1800, 3600, 5, 6, 0), |
473 | DA9052_BUCKPERI(3, 50, 1800, 3600, 5, 6, 0), | 311 | DA9052_LDO(LDO1, 50, 600, 1800, 5, 6, 0), |
474 | /* LD01 - LDO10 */ | 312 | DA9052_LDO(LDO2, 25, 600, 1800, 6, 6, DA9052_SUPPLY_VLDO2GO), |
475 | DA9052_LDO(4, 50, 600, 1800, 5, 6, 0), | 313 | DA9052_LDO(LDO3, 25, 1725, 3300, 6, 6, DA9052_SUPPLY_VLDO3GO), |
476 | DA9052_LDO5_6(5, 25, 600, 1800, 6, 6, DA9052_SUPPLY_VLDO2GO), | 314 | DA9052_LDO(LDO4, 25, 1725, 3300, 6, 6, 0), |
477 | DA9052_LDO5_6(6, 25, 1725, 3300, 6, 6, DA9052_SUPPLY_VLDO3GO), | 315 | DA9052_LDO(LDO5, 50, 1200, 3600, 6, 6, 0), |
478 | DA9052_LDO(7, 25, 1725, 3300, 6, 6, 0), | 316 | DA9052_LDO(LDO6, 50, 1200, 3600, 6, 6, 0), |
479 | DA9052_LDO(8, 50, 1200, 3600, 6, 6, 0), | 317 | DA9052_LDO(LDO7, 50, 1200, 3600, 6, 6, 0), |
480 | DA9052_LDO(9, 50, 1200, 3600, 6, 6, 0), | 318 | DA9052_LDO(LDO8, 50, 1200, 3600, 6, 6, 0), |
481 | DA9052_LDO(10, 50, 1200, 3600, 6, 6, 0), | 319 | DA9052_LDO(LDO9, 50, 1250, 3650, 6, 6, 0), |
482 | DA9052_LDO(11, 50, 1200, 3600, 6, 6, 0), | 320 | DA9052_LDO(LDO10, 50, 1200, 3600, 6, 6, 0), |
483 | DA9052_LDO(12, 50, 1250, 3650, 6, 6, 0), | ||
484 | DA9052_LDO(13, 50, 1200, 3600, 6, 6, 0), | ||
485 | }; | 321 | }; |
486 | 322 | ||
487 | static struct da9052_regulator_info da9053_regulator_info[] = { | 323 | static struct da9052_regulator_info da9053_regulator_info[] = { |
488 | /* Buck1 - 4 */ | 324 | DA9052_DCDC(BUCK1, 25, 500, 2075, 6, 6, DA9052_SUPPLY_VBCOREGO), |
489 | DA9052_DCDC(0, 25, 500, 2075, 6, 6, DA9052_SUPPLY_VBCOREGO), | 325 | DA9052_DCDC(BUCK2, 25, 500, 2075, 6, 6, DA9052_SUPPLY_VBPROGO), |
490 | DA9052_DCDC(1, 25, 500, 2075, 6, 6, DA9052_SUPPLY_VBPROGO), | 326 | DA9052_DCDC(BUCK3, 25, 925, 2500, 6, 6, DA9052_SUPPLY_VBMEMGO), |
491 | DA9052_DCDC(2, 25, 925, 2500, 6, 6, DA9052_SUPPLY_VBMEMGO), | 327 | DA9052_DCDC(BUCK4, 25, 925, 2500, 6, 6, 0), |
492 | DA9052_BUCKPERI(3, 25, 925, 2500, 6, 6, 0), | 328 | DA9052_LDO(LDO1, 50, 600, 1800, 5, 6, 0), |
493 | /* LD01 - LDO10 */ | 329 | DA9052_LDO(LDO2, 25, 600, 1800, 6, 6, DA9052_SUPPLY_VLDO2GO), |
494 | DA9052_LDO(4, 50, 600, 1800, 5, 6, 0), | 330 | DA9052_LDO(LDO3, 25, 1725, 3300, 6, 6, DA9052_SUPPLY_VLDO3GO), |
495 | DA9052_LDO5_6(5, 25, 600, 1800, 6, 6, DA9052_SUPPLY_VLDO2GO), | 331 | DA9052_LDO(LDO4, 25, 1725, 3300, 6, 6, 0), |
496 | DA9052_LDO5_6(6, 25, 1725, 3300, 6, 6, DA9052_SUPPLY_VLDO3GO), | 332 | DA9052_LDO(LDO5, 50, 1200, 3600, 6, 6, 0), |
497 | DA9052_LDO(7, 25, 1725, 3300, 6, 6, 0), | 333 | DA9052_LDO(LDO6, 50, 1200, 3600, 6, 6, 0), |
498 | DA9052_LDO(8, 50, 1200, 3600, 6, 6, 0), | 334 | DA9052_LDO(LDO7, 50, 1200, 3600, 6, 6, 0), |
499 | DA9052_LDO(9, 50, 1200, 3600, 6, 6, 0), | 335 | DA9052_LDO(LDO8, 50, 1200, 3600, 6, 6, 0), |
500 | DA9052_LDO(10, 50, 1200, 3600, 6, 6, 0), | 336 | DA9052_LDO(LDO9, 50, 1250, 3650, 6, 6, 0), |
501 | DA9052_LDO(11, 50, 1200, 3600, 6, 6, 0), | 337 | DA9052_LDO(LDO10, 50, 1200, 3600, 6, 6, 0), |
502 | DA9052_LDO(12, 50, 1250, 3650, 6, 6, 0), | ||
503 | DA9052_LDO(13, 50, 1200, 3600, 6, 6, 0), | ||
504 | }; | 338 | }; |
505 | 339 | ||
506 | static inline struct da9052_regulator_info *find_regulator_info(u8 chip_id, | 340 | static inline struct da9052_regulator_info *find_regulator_info(u8 chip_id, |
@@ -533,10 +367,10 @@ static inline struct da9052_regulator_info *find_regulator_info(u8 chip_id, | |||
533 | 367 | ||
534 | static int __devinit da9052_regulator_probe(struct platform_device *pdev) | 368 | static int __devinit da9052_regulator_probe(struct platform_device *pdev) |
535 | { | 369 | { |
370 | struct regulator_config config = { }; | ||
536 | struct da9052_regulator *regulator; | 371 | struct da9052_regulator *regulator; |
537 | struct da9052 *da9052; | 372 | struct da9052 *da9052; |
538 | struct da9052_pdata *pdata; | 373 | struct da9052_pdata *pdata; |
539 | int ret; | ||
540 | 374 | ||
541 | regulator = devm_kzalloc(&pdev->dev, sizeof(struct da9052_regulator), | 375 | regulator = devm_kzalloc(&pdev->dev, sizeof(struct da9052_regulator), |
542 | GFP_KERNEL); | 376 | GFP_KERNEL); |
@@ -551,26 +385,49 @@ static int __devinit da9052_regulator_probe(struct platform_device *pdev) | |||
551 | pdev->id); | 385 | pdev->id); |
552 | if (regulator->info == NULL) { | 386 | if (regulator->info == NULL) { |
553 | dev_err(&pdev->dev, "invalid regulator ID specified\n"); | 387 | dev_err(&pdev->dev, "invalid regulator ID specified\n"); |
554 | ret = -EINVAL; | 388 | return -EINVAL; |
555 | goto err; | ||
556 | } | 389 | } |
390 | |||
391 | config.dev = &pdev->dev; | ||
392 | config.driver_data = regulator; | ||
393 | config.regmap = da9052->regmap; | ||
394 | if (pdata && pdata->regulators) { | ||
395 | config.init_data = pdata->regulators[pdev->id]; | ||
396 | } else { | ||
397 | #ifdef CONFIG_OF | ||
398 | struct device_node *nproot = da9052->dev->of_node; | ||
399 | struct device_node *np; | ||
400 | |||
401 | if (!nproot) | ||
402 | return -ENODEV; | ||
403 | |||
404 | nproot = of_find_node_by_name(nproot, "regulators"); | ||
405 | if (!nproot) | ||
406 | return -ENODEV; | ||
407 | |||
408 | for (np = of_get_next_child(nproot, NULL); np; | ||
409 | np = of_get_next_child(nproot, np)) { | ||
410 | if (!of_node_cmp(np->name, | ||
411 | regulator->info->reg_desc.name)) { | ||
412 | config.init_data = of_get_regulator_init_data( | ||
413 | &pdev->dev, np); | ||
414 | break; | ||
415 | } | ||
416 | } | ||
417 | #endif | ||
418 | } | ||
419 | |||
557 | regulator->rdev = regulator_register(®ulator->info->reg_desc, | 420 | regulator->rdev = regulator_register(®ulator->info->reg_desc, |
558 | &pdev->dev, | 421 | &config); |
559 | pdata->regulators[pdev->id], | ||
560 | regulator, NULL); | ||
561 | if (IS_ERR(regulator->rdev)) { | 422 | if (IS_ERR(regulator->rdev)) { |
562 | dev_err(&pdev->dev, "failed to register regulator %s\n", | 423 | dev_err(&pdev->dev, "failed to register regulator %s\n", |
563 | regulator->info->reg_desc.name); | 424 | regulator->info->reg_desc.name); |
564 | ret = PTR_ERR(regulator->rdev); | 425 | return PTR_ERR(regulator->rdev); |
565 | goto err; | ||
566 | } | 426 | } |
567 | 427 | ||
568 | platform_set_drvdata(pdev, regulator); | 428 | platform_set_drvdata(pdev, regulator); |
569 | 429 | ||
570 | return 0; | 430 | return 0; |
571 | err: | ||
572 | devm_kfree(&pdev->dev, regulator); | ||
573 | return ret; | ||
574 | } | 431 | } |
575 | 432 | ||
576 | static int __devexit da9052_regulator_remove(struct platform_device *pdev) | 433 | static int __devexit da9052_regulator_remove(struct platform_device *pdev) |
@@ -578,8 +435,6 @@ static int __devexit da9052_regulator_remove(struct platform_device *pdev) | |||
578 | struct da9052_regulator *regulator = platform_get_drvdata(pdev); | 435 | struct da9052_regulator *regulator = platform_get_drvdata(pdev); |
579 | 436 | ||
580 | regulator_unregister(regulator->rdev); | 437 | regulator_unregister(regulator->rdev); |
581 | devm_kfree(&pdev->dev, regulator); | ||
582 | |||
583 | return 0; | 438 | return 0; |
584 | } | 439 | } |
585 | 440 | ||
diff --git a/drivers/regulator/db8500-prcmu.c b/drivers/regulator/db8500-prcmu.c index 4bd25e75efa0..968f97f3cb3d 100644 --- a/drivers/regulator/db8500-prcmu.c +++ b/drivers/regulator/db8500-prcmu.c | |||
@@ -17,6 +17,8 @@ | |||
17 | #include <linux/regulator/driver.h> | 17 | #include <linux/regulator/driver.h> |
18 | #include <linux/regulator/machine.h> | 18 | #include <linux/regulator/machine.h> |
19 | #include <linux/regulator/db8500-prcmu.h> | 19 | #include <linux/regulator/db8500-prcmu.h> |
20 | #include <linux/regulator/of_regulator.h> | ||
21 | #include <linux/of.h> | ||
20 | #include <linux/module.h> | 22 | #include <linux/module.h> |
21 | #include "dbx500-prcmu.h" | 23 | #include "dbx500-prcmu.h" |
22 | 24 | ||
@@ -410,45 +412,120 @@ dbx500_regulator_info[DB8500_NUM_REGULATORS] = { | |||
410 | }, | 412 | }, |
411 | }; | 413 | }; |
412 | 414 | ||
415 | static __devinit int db8500_regulator_register(struct platform_device *pdev, | ||
416 | struct regulator_init_data *init_data, | ||
417 | int id, | ||
418 | struct device_node *np) | ||
419 | { | ||
420 | struct dbx500_regulator_info *info; | ||
421 | struct regulator_config config = { }; | ||
422 | int err; | ||
423 | |||
424 | /* assign per-regulator data */ | ||
425 | info = &dbx500_regulator_info[id]; | ||
426 | info->dev = &pdev->dev; | ||
427 | |||
428 | config.dev = &pdev->dev; | ||
429 | config.init_data = init_data; | ||
430 | config.driver_data = info; | ||
431 | config.of_node = np; | ||
432 | |||
433 | /* register with the regulator framework */ | ||
434 | info->rdev = regulator_register(&info->desc, &config); | ||
435 | if (IS_ERR(info->rdev)) { | ||
436 | err = PTR_ERR(info->rdev); | ||
437 | dev_err(&pdev->dev, "failed to register %s: err %i\n", | ||
438 | info->desc.name, err); | ||
439 | |||
440 | /* if failing, unregister all earlier regulators */ | ||
441 | while (--id >= 0) { | ||
442 | info = &dbx500_regulator_info[id]; | ||
443 | regulator_unregister(info->rdev); | ||
444 | } | ||
445 | return err; | ||
446 | } | ||
447 | |||
448 | dev_dbg(rdev_get_dev(info->rdev), | ||
449 | "regulator-%s-probed\n", info->desc.name); | ||
450 | |||
451 | return 0; | ||
452 | } | ||
453 | |||
454 | static struct of_regulator_match db8500_regulator_matches[] = { | ||
455 | { .name = "db8500-vape", .driver_data = (void *) DB8500_REGULATOR_VAPE, }, | ||
456 | { .name = "db8500-varm", .driver_data = (void *) DB8500_REGULATOR_VARM, }, | ||
457 | { .name = "db8500-vmodem", .driver_data = (void *) DB8500_REGULATOR_VMODEM, }, | ||
458 | { .name = "db8500-vpll", .driver_data = (void *) DB8500_REGULATOR_VPLL, }, | ||
459 | { .name = "db8500-vsmps1", .driver_data = (void *) DB8500_REGULATOR_VSMPS1, }, | ||
460 | { .name = "db8500-vsmps2", .driver_data = (void *) DB8500_REGULATOR_VSMPS2, }, | ||
461 | { .name = "db8500-vsmps3", .driver_data = (void *) DB8500_REGULATOR_VSMPS3, }, | ||
462 | { .name = "db8500-vrf1", .driver_data = (void *) DB8500_REGULATOR_VRF1, }, | ||
463 | { .name = "db8500-sva-mmdsp", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SVAMMDSP, }, | ||
464 | { .name = "db8500-sva-mmdsp-ret", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SVAMMDSPRET, }, | ||
465 | { .name = "db8500-sva-pipe", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SVAPIPE, }, | ||
466 | { .name = "db8500-sia-mmdsp", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SIAMMDSP, }, | ||
467 | { .name = "db8500-sia-mmdsp-ret", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SIAMMDSPRET, }, | ||
468 | { .name = "db8500-sia-pipe", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SIAPIPE, }, | ||
469 | { .name = "db8500-sga", .driver_data = (void *) DB8500_REGULATOR_SWITCH_SGA, }, | ||
470 | { .name = "db8500-b2r2-mcde", .driver_data = (void *) DB8500_REGULATOR_SWITCH_B2R2_MCDE, }, | ||
471 | { .name = "db8500-esram12", .driver_data = (void *) DB8500_REGULATOR_SWITCH_ESRAM12, }, | ||
472 | { .name = "db8500-esram12-ret", .driver_data = (void *) DB8500_REGULATOR_SWITCH_ESRAM12RET, }, | ||
473 | { .name = "db8500-esram34", .driver_data = (void *) DB8500_REGULATOR_SWITCH_ESRAM34, }, | ||
474 | { .name = "db8500-esram34-ret", .driver_data = (void *) DB8500_REGULATOR_SWITCH_ESRAM34RET, }, | ||
475 | }; | ||
476 | |||
477 | static __devinit int | ||
478 | db8500_regulator_of_probe(struct platform_device *pdev, | ||
479 | struct device_node *np) | ||
480 | { | ||
481 | int i, err; | ||
482 | |||
483 | for (i = 0; i < ARRAY_SIZE(dbx500_regulator_info); i++) { | ||
484 | err = db8500_regulator_register( | ||
485 | pdev, db8500_regulator_matches[i].init_data, | ||
486 | i, db8500_regulator_matches[i].of_node); | ||
487 | if (err) | ||
488 | return err; | ||
489 | } | ||
490 | |||
491 | return 0; | ||
492 | } | ||
493 | |||
413 | static int __devinit db8500_regulator_probe(struct platform_device *pdev) | 494 | static int __devinit db8500_regulator_probe(struct platform_device *pdev) |
414 | { | 495 | { |
415 | struct regulator_init_data *db8500_init_data = | 496 | struct regulator_init_data *db8500_init_data = |
416 | dev_get_platdata(&pdev->dev); | 497 | dev_get_platdata(&pdev->dev); |
498 | struct device_node *np = pdev->dev.of_node; | ||
417 | int i, err; | 499 | int i, err; |
418 | 500 | ||
419 | /* register all regulators */ | 501 | /* register all regulators */ |
420 | for (i = 0; i < ARRAY_SIZE(dbx500_regulator_info); i++) { | 502 | if (np) { |
421 | struct dbx500_regulator_info *info; | 503 | err = of_regulator_match(&pdev->dev, np, |
422 | struct regulator_init_data *init_data = &db8500_init_data[i]; | 504 | db8500_regulator_matches, |
423 | 505 | ARRAY_SIZE(db8500_regulator_matches)); | |
424 | /* assign per-regulator data */ | 506 | if (err < 0) { |
425 | info = &dbx500_regulator_info[i]; | 507 | dev_err(&pdev->dev, |
426 | info->dev = &pdev->dev; | 508 | "Error parsing regulator init data: %d\n", err); |
427 | |||
428 | /* register with the regulator framework */ | ||
429 | info->rdev = regulator_register(&info->desc, &pdev->dev, | ||
430 | init_data, info, NULL); | ||
431 | if (IS_ERR(info->rdev)) { | ||
432 | err = PTR_ERR(info->rdev); | ||
433 | dev_err(&pdev->dev, "failed to register %s: err %i\n", | ||
434 | info->desc.name, err); | ||
435 | |||
436 | /* if failing, unregister all earlier regulators */ | ||
437 | while (--i >= 0) { | ||
438 | info = &dbx500_regulator_info[i]; | ||
439 | regulator_unregister(info->rdev); | ||
440 | } | ||
441 | return err; | 509 | return err; |
442 | } | 510 | } |
443 | 511 | ||
444 | dev_dbg(rdev_get_dev(info->rdev), | 512 | err = db8500_regulator_of_probe(pdev, np); |
445 | "regulator-%s-probed\n", info->desc.name); | 513 | if (err) |
514 | return err; | ||
515 | } else { | ||
516 | for (i = 0; i < ARRAY_SIZE(dbx500_regulator_info); i++) { | ||
517 | err = db8500_regulator_register(pdev, | ||
518 | &db8500_init_data[i], | ||
519 | i, NULL); | ||
520 | if (err) | ||
521 | return err; | ||
522 | } | ||
446 | } | 523 | } |
524 | |||
447 | err = ux500_regulator_debug_init(pdev, | 525 | err = ux500_regulator_debug_init(pdev, |
448 | dbx500_regulator_info, | 526 | dbx500_regulator_info, |
449 | ARRAY_SIZE(dbx500_regulator_info)); | 527 | ARRAY_SIZE(dbx500_regulator_info)); |
450 | 528 | return 0; | |
451 | return err; | ||
452 | } | 529 | } |
453 | 530 | ||
454 | static int __exit db8500_regulator_remove(struct platform_device *pdev) | 531 | static int __exit db8500_regulator_remove(struct platform_device *pdev) |
@@ -470,10 +547,16 @@ static int __exit db8500_regulator_remove(struct platform_device *pdev) | |||
470 | return 0; | 547 | return 0; |
471 | } | 548 | } |
472 | 549 | ||
550 | static const struct of_device_id db8500_prcmu_regulator_match[] = { | ||
551 | { .compatible = "stericsson,db8500-prcmu-regulator", }, | ||
552 | {} | ||
553 | }; | ||
554 | |||
473 | static struct platform_driver db8500_regulator_driver = { | 555 | static struct platform_driver db8500_regulator_driver = { |
474 | .driver = { | 556 | .driver = { |
475 | .name = "db8500-prcmu-regulators", | 557 | .name = "db8500-prcmu-regulators", |
476 | .owner = THIS_MODULE, | 558 | .owner = THIS_MODULE, |
559 | .of_match_table = db8500_prcmu_regulator_match, | ||
477 | }, | 560 | }, |
478 | .probe = db8500_regulator_probe, | 561 | .probe = db8500_regulator_probe, |
479 | .remove = __exit_p(db8500_regulator_remove), | 562 | .remove = __exit_p(db8500_regulator_remove), |
diff --git a/drivers/regulator/dummy.c b/drivers/regulator/dummy.c index 0ee00de4be72..86f655c7f7a1 100644 --- a/drivers/regulator/dummy.c +++ b/drivers/regulator/dummy.c | |||
@@ -39,10 +39,13 @@ static struct regulator_desc dummy_desc = { | |||
39 | 39 | ||
40 | static int __devinit dummy_regulator_probe(struct platform_device *pdev) | 40 | static int __devinit dummy_regulator_probe(struct platform_device *pdev) |
41 | { | 41 | { |
42 | struct regulator_config config = { }; | ||
42 | int ret; | 43 | int ret; |
43 | 44 | ||
44 | dummy_regulator_rdev = regulator_register(&dummy_desc, NULL, | 45 | config.dev = &pdev->dev; |
45 | &dummy_initdata, NULL, NULL); | 46 | config.init_data = &dummy_initdata; |
47 | |||
48 | dummy_regulator_rdev = regulator_register(&dummy_desc, &config); | ||
46 | if (IS_ERR(dummy_regulator_rdev)) { | 49 | if (IS_ERR(dummy_regulator_rdev)) { |
47 | ret = PTR_ERR(dummy_regulator_rdev); | 50 | ret = PTR_ERR(dummy_regulator_rdev); |
48 | pr_err("Failed to register regulator: %d\n", ret); | 51 | pr_err("Failed to register regulator: %d\n", ret); |
diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c index 40f38030b394..f09fe7b20e82 100644 --- a/drivers/regulator/fixed.c +++ b/drivers/regulator/fixed.c | |||
@@ -25,7 +25,6 @@ | |||
25 | #include <linux/regulator/driver.h> | 25 | #include <linux/regulator/driver.h> |
26 | #include <linux/regulator/fixed.h> | 26 | #include <linux/regulator/fixed.h> |
27 | #include <linux/gpio.h> | 27 | #include <linux/gpio.h> |
28 | #include <linux/delay.h> | ||
29 | #include <linux/slab.h> | 28 | #include <linux/slab.h> |
30 | #include <linux/of.h> | 29 | #include <linux/of.h> |
31 | #include <linux/of_gpio.h> | 30 | #include <linux/of_gpio.h> |
@@ -91,6 +90,9 @@ of_get_fixed_voltage_config(struct device *dev) | |||
91 | if (of_find_property(np, "enable-active-high", NULL)) | 90 | if (of_find_property(np, "enable-active-high", NULL)) |
92 | config->enable_high = true; | 91 | config->enable_high = true; |
93 | 92 | ||
93 | if (of_find_property(np, "gpio-open-drain", NULL)) | ||
94 | config->gpio_is_open_drain = true; | ||
95 | |||
94 | return config; | 96 | return config; |
95 | } | 97 | } |
96 | 98 | ||
@@ -105,10 +107,8 @@ static int fixed_voltage_enable(struct regulator_dev *dev) | |||
105 | { | 107 | { |
106 | struct fixed_voltage_data *data = rdev_get_drvdata(dev); | 108 | struct fixed_voltage_data *data = rdev_get_drvdata(dev); |
107 | 109 | ||
108 | if (gpio_is_valid(data->gpio)) { | 110 | gpio_set_value_cansleep(data->gpio, data->enable_high); |
109 | gpio_set_value_cansleep(data->gpio, data->enable_high); | 111 | data->is_enabled = true; |
110 | data->is_enabled = true; | ||
111 | } | ||
112 | 112 | ||
113 | return 0; | 113 | return 0; |
114 | } | 114 | } |
@@ -117,10 +117,8 @@ static int fixed_voltage_disable(struct regulator_dev *dev) | |||
117 | { | 117 | { |
118 | struct fixed_voltage_data *data = rdev_get_drvdata(dev); | 118 | struct fixed_voltage_data *data = rdev_get_drvdata(dev); |
119 | 119 | ||
120 | if (gpio_is_valid(data->gpio)) { | 120 | gpio_set_value_cansleep(data->gpio, !data->enable_high); |
121 | gpio_set_value_cansleep(data->gpio, !data->enable_high); | 121 | data->is_enabled = false; |
122 | data->is_enabled = false; | ||
123 | } | ||
124 | 122 | ||
125 | return 0; | 123 | return 0; |
126 | } | 124 | } |
@@ -153,7 +151,7 @@ static int fixed_voltage_list_voltage(struct regulator_dev *dev, | |||
153 | return data->microvolts; | 151 | return data->microvolts; |
154 | } | 152 | } |
155 | 153 | ||
156 | static struct regulator_ops fixed_voltage_ops = { | 154 | static struct regulator_ops fixed_voltage_gpio_ops = { |
157 | .is_enabled = fixed_voltage_is_enabled, | 155 | .is_enabled = fixed_voltage_is_enabled, |
158 | .enable = fixed_voltage_enable, | 156 | .enable = fixed_voltage_enable, |
159 | .disable = fixed_voltage_disable, | 157 | .disable = fixed_voltage_disable, |
@@ -162,10 +160,16 @@ static struct regulator_ops fixed_voltage_ops = { | |||
162 | .list_voltage = fixed_voltage_list_voltage, | 160 | .list_voltage = fixed_voltage_list_voltage, |
163 | }; | 161 | }; |
164 | 162 | ||
163 | static struct regulator_ops fixed_voltage_ops = { | ||
164 | .get_voltage = fixed_voltage_get_voltage, | ||
165 | .list_voltage = fixed_voltage_list_voltage, | ||
166 | }; | ||
167 | |||
165 | static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev) | 168 | static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev) |
166 | { | 169 | { |
167 | struct fixed_voltage_config *config; | 170 | struct fixed_voltage_config *config; |
168 | struct fixed_voltage_data *drvdata; | 171 | struct fixed_voltage_data *drvdata; |
172 | struct regulator_config cfg = { }; | ||
169 | int ret; | 173 | int ret; |
170 | 174 | ||
171 | if (pdev->dev.of_node) | 175 | if (pdev->dev.of_node) |
@@ -176,7 +180,8 @@ static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev) | |||
176 | if (!config) | 180 | if (!config) |
177 | return -ENOMEM; | 181 | return -ENOMEM; |
178 | 182 | ||
179 | drvdata = kzalloc(sizeof(struct fixed_voltage_data), GFP_KERNEL); | 183 | drvdata = devm_kzalloc(&pdev->dev, sizeof(struct fixed_voltage_data), |
184 | GFP_KERNEL); | ||
180 | if (drvdata == NULL) { | 185 | if (drvdata == NULL) { |
181 | dev_err(&pdev->dev, "Failed to allocate device data\n"); | 186 | dev_err(&pdev->dev, "Failed to allocate device data\n"); |
182 | ret = -ENOMEM; | 187 | ret = -ENOMEM; |
@@ -191,7 +196,6 @@ static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev) | |||
191 | } | 196 | } |
192 | drvdata->desc.type = REGULATOR_VOLTAGE; | 197 | drvdata->desc.type = REGULATOR_VOLTAGE; |
193 | drvdata->desc.owner = THIS_MODULE; | 198 | drvdata->desc.owner = THIS_MODULE; |
194 | drvdata->desc.ops = &fixed_voltage_ops; | ||
195 | 199 | ||
196 | if (config->microvolts) | 200 | if (config->microvolts) |
197 | drvdata->desc.n_voltages = 1; | 201 | drvdata->desc.n_voltages = 1; |
@@ -201,6 +205,7 @@ static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev) | |||
201 | drvdata->startup_delay = config->startup_delay; | 205 | drvdata->startup_delay = config->startup_delay; |
202 | 206 | ||
203 | if (gpio_is_valid(config->gpio)) { | 207 | if (gpio_is_valid(config->gpio)) { |
208 | int gpio_flag; | ||
204 | drvdata->enable_high = config->enable_high; | 209 | drvdata->enable_high = config->enable_high; |
205 | 210 | ||
206 | /* FIXME: Remove below print warning | 211 | /* FIXME: Remove below print warning |
@@ -218,39 +223,39 @@ static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev) | |||
218 | dev_warn(&pdev->dev, | 223 | dev_warn(&pdev->dev, |
219 | "using GPIO 0 for regulator enable control\n"); | 224 | "using GPIO 0 for regulator enable control\n"); |
220 | 225 | ||
221 | ret = gpio_request(config->gpio, config->supply_name); | 226 | /* |
222 | if (ret) { | 227 | * set output direction without changing state |
223 | dev_err(&pdev->dev, | ||
224 | "Could not obtain regulator enable GPIO %d: %d\n", | ||
225 | config->gpio, ret); | ||
226 | goto err_name; | ||
227 | } | ||
228 | |||
229 | /* set output direction without changing state | ||
230 | * to prevent glitch | 228 | * to prevent glitch |
231 | */ | 229 | */ |
232 | drvdata->is_enabled = config->enabled_at_boot; | 230 | drvdata->is_enabled = config->enabled_at_boot; |
233 | ret = drvdata->is_enabled ? | 231 | ret = drvdata->is_enabled ? |
234 | config->enable_high : !config->enable_high; | 232 | config->enable_high : !config->enable_high; |
233 | gpio_flag = ret ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW; | ||
234 | |||
235 | if (config->gpio_is_open_drain) | ||
236 | gpio_flag |= GPIOF_OPEN_DRAIN; | ||
235 | 237 | ||
236 | ret = gpio_direction_output(config->gpio, ret); | 238 | ret = gpio_request_one(config->gpio, gpio_flag, |
239 | config->supply_name); | ||
237 | if (ret) { | 240 | if (ret) { |
238 | dev_err(&pdev->dev, | 241 | dev_err(&pdev->dev, |
239 | "Could not configure regulator enable GPIO %d direction: %d\n", | 242 | "Could not obtain regulator enable GPIO %d: %d\n", |
240 | config->gpio, ret); | 243 | config->gpio, ret); |
241 | goto err_gpio; | 244 | goto err_name; |
242 | } | 245 | } |
243 | 246 | ||
247 | drvdata->desc.ops = &fixed_voltage_gpio_ops; | ||
248 | |||
244 | } else { | 249 | } else { |
245 | /* Regulator without GPIO control is considered | 250 | drvdata->desc.ops = &fixed_voltage_ops; |
246 | * always enabled | ||
247 | */ | ||
248 | drvdata->is_enabled = true; | ||
249 | } | 251 | } |
250 | 252 | ||
251 | drvdata->dev = regulator_register(&drvdata->desc, &pdev->dev, | 253 | cfg.dev = &pdev->dev; |
252 | config->init_data, drvdata, | 254 | cfg.init_data = config->init_data; |
253 | pdev->dev.of_node); | 255 | cfg.driver_data = drvdata; |
256 | cfg.of_node = pdev->dev.of_node; | ||
257 | |||
258 | drvdata->dev = regulator_register(&drvdata->desc, &cfg); | ||
254 | if (IS_ERR(drvdata->dev)) { | 259 | if (IS_ERR(drvdata->dev)) { |
255 | ret = PTR_ERR(drvdata->dev); | 260 | ret = PTR_ERR(drvdata->dev); |
256 | dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret); | 261 | dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret); |
@@ -270,7 +275,6 @@ err_gpio: | |||
270 | err_name: | 275 | err_name: |
271 | kfree(drvdata->desc.name); | 276 | kfree(drvdata->desc.name); |
272 | err: | 277 | err: |
273 | kfree(drvdata); | ||
274 | return ret; | 278 | return ret; |
275 | } | 279 | } |
276 | 280 | ||
@@ -282,7 +286,6 @@ static int __devexit reg_fixed_voltage_remove(struct platform_device *pdev) | |||
282 | if (gpio_is_valid(drvdata->gpio)) | 286 | if (gpio_is_valid(drvdata->gpio)) |
283 | gpio_free(drvdata->gpio); | 287 | gpio_free(drvdata->gpio); |
284 | kfree(drvdata->desc.name); | 288 | kfree(drvdata->desc.name); |
285 | kfree(drvdata); | ||
286 | 289 | ||
287 | return 0; | 290 | return 0; |
288 | } | 291 | } |
diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c index 42e1cb1835e5..9997d7aaca84 100644 --- a/drivers/regulator/gpio-regulator.c +++ b/drivers/regulator/gpio-regulator.c | |||
@@ -30,7 +30,6 @@ | |||
30 | #include <linux/regulator/machine.h> | 30 | #include <linux/regulator/machine.h> |
31 | #include <linux/regulator/gpio-regulator.h> | 31 | #include <linux/regulator/gpio-regulator.h> |
32 | #include <linux/gpio.h> | 32 | #include <linux/gpio.h> |
33 | #include <linux/delay.h> | ||
34 | #include <linux/slab.h> | 33 | #include <linux/slab.h> |
35 | 34 | ||
36 | struct gpio_regulator_data { | 35 | struct gpio_regulator_data { |
@@ -105,15 +104,15 @@ static int gpio_regulator_set_value(struct regulator_dev *dev, | |||
105 | int min, int max) | 104 | int min, int max) |
106 | { | 105 | { |
107 | struct gpio_regulator_data *data = rdev_get_drvdata(dev); | 106 | struct gpio_regulator_data *data = rdev_get_drvdata(dev); |
108 | int ptr, target, state; | 107 | int ptr, target, state, best_val = INT_MAX; |
109 | 108 | ||
110 | target = -1; | ||
111 | for (ptr = 0; ptr < data->nr_states; ptr++) | 109 | for (ptr = 0; ptr < data->nr_states; ptr++) |
112 | if (data->states[ptr].value >= min && | 110 | if (data->states[ptr].value < best_val && |
111 | data->states[ptr].value >= min && | ||
113 | data->states[ptr].value <= max) | 112 | data->states[ptr].value <= max) |
114 | target = data->states[ptr].gpios; | 113 | target = data->states[ptr].gpios; |
115 | 114 | ||
116 | if (target < 0) | 115 | if (best_val == INT_MAX) |
117 | return -EINVAL; | 116 | return -EINVAL; |
118 | 117 | ||
119 | for (ptr = 0; ptr < data->nr_gpios; ptr++) { | 118 | for (ptr = 0; ptr < data->nr_gpios; ptr++) { |
@@ -172,9 +171,11 @@ static int __devinit gpio_regulator_probe(struct platform_device *pdev) | |||
172 | { | 171 | { |
173 | struct gpio_regulator_config *config = pdev->dev.platform_data; | 172 | struct gpio_regulator_config *config = pdev->dev.platform_data; |
174 | struct gpio_regulator_data *drvdata; | 173 | struct gpio_regulator_data *drvdata; |
174 | struct regulator_config cfg = { }; | ||
175 | int ptr, ret, state; | 175 | int ptr, ret, state; |
176 | 176 | ||
177 | drvdata = kzalloc(sizeof(struct gpio_regulator_data), GFP_KERNEL); | 177 | drvdata = devm_kzalloc(&pdev->dev, sizeof(struct gpio_regulator_data), |
178 | GFP_KERNEL); | ||
178 | if (drvdata == NULL) { | 179 | if (drvdata == NULL) { |
179 | dev_err(&pdev->dev, "Failed to allocate device data\n"); | 180 | dev_err(&pdev->dev, "Failed to allocate device data\n"); |
180 | return -ENOMEM; | 181 | return -ENOMEM; |
@@ -283,8 +284,11 @@ static int __devinit gpio_regulator_probe(struct platform_device *pdev) | |||
283 | } | 284 | } |
284 | drvdata->state = state; | 285 | drvdata->state = state; |
285 | 286 | ||
286 | drvdata->dev = regulator_register(&drvdata->desc, &pdev->dev, | 287 | cfg.dev = &pdev->dev; |
287 | config->init_data, drvdata, NULL); | 288 | cfg.init_data = config->init_data; |
289 | cfg.driver_data = &drvdata; | ||
290 | |||
291 | drvdata->dev = regulator_register(&drvdata->desc, &cfg); | ||
288 | if (IS_ERR(drvdata->dev)) { | 292 | if (IS_ERR(drvdata->dev)) { |
289 | ret = PTR_ERR(drvdata->dev); | 293 | ret = PTR_ERR(drvdata->dev); |
290 | dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret); | 294 | dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret); |
@@ -307,7 +311,6 @@ err_memgpio: | |||
307 | err_name: | 311 | err_name: |
308 | kfree(drvdata->desc.name); | 312 | kfree(drvdata->desc.name); |
309 | err: | 313 | err: |
310 | kfree(drvdata); | ||
311 | return ret; | 314 | return ret; |
312 | } | 315 | } |
313 | 316 | ||
@@ -326,7 +329,6 @@ static int __devexit gpio_regulator_remove(struct platform_device *pdev) | |||
326 | gpio_free(drvdata->enable_gpio); | 329 | gpio_free(drvdata->enable_gpio); |
327 | 330 | ||
328 | kfree(drvdata->desc.name); | 331 | kfree(drvdata->desc.name); |
329 | kfree(drvdata); | ||
330 | 332 | ||
331 | return 0; | 333 | return 0; |
332 | } | 334 | } |
diff --git a/drivers/regulator/isl6271a-regulator.c b/drivers/regulator/isl6271a-regulator.c index 775f5fd208c3..56d273f25603 100644 --- a/drivers/regulator/isl6271a-regulator.c +++ b/drivers/regulator/isl6271a-regulator.c | |||
@@ -22,7 +22,6 @@ | |||
22 | #include <linux/platform_device.h> | 22 | #include <linux/platform_device.h> |
23 | #include <linux/regulator/driver.h> | 23 | #include <linux/regulator/driver.h> |
24 | #include <linux/i2c.h> | 24 | #include <linux/i2c.h> |
25 | #include <linux/delay.h> | ||
26 | #include <linux/slab.h> | 25 | #include <linux/slab.h> |
27 | 26 | ||
28 | #define ISL6271A_VOLTAGE_MIN 850000 | 27 | #define ISL6271A_VOLTAGE_MIN 850000 |
@@ -36,47 +35,30 @@ struct isl_pmic { | |||
36 | struct mutex mtx; | 35 | struct mutex mtx; |
37 | }; | 36 | }; |
38 | 37 | ||
39 | static int isl6271a_get_voltage(struct regulator_dev *dev) | 38 | static int isl6271a_get_voltage_sel(struct regulator_dev *dev) |
40 | { | 39 | { |
41 | struct isl_pmic *pmic = rdev_get_drvdata(dev); | 40 | struct isl_pmic *pmic = rdev_get_drvdata(dev); |
42 | int idx, data; | 41 | int idx; |
43 | 42 | ||
44 | mutex_lock(&pmic->mtx); | 43 | mutex_lock(&pmic->mtx); |
45 | 44 | ||
46 | idx = i2c_smbus_read_byte(pmic->client); | 45 | idx = i2c_smbus_read_byte(pmic->client); |
47 | if (idx < 0) { | 46 | if (idx < 0) |
48 | dev_err(&pmic->client->dev, "Error getting voltage\n"); | 47 | dev_err(&pmic->client->dev, "Error getting voltage\n"); |
49 | data = idx; | ||
50 | goto out; | ||
51 | } | ||
52 | |||
53 | /* Convert the data from chip to microvolts */ | ||
54 | data = ISL6271A_VOLTAGE_MIN + (ISL6271A_VOLTAGE_STEP * (idx & 0xf)); | ||
55 | 48 | ||
56 | out: | ||
57 | mutex_unlock(&pmic->mtx); | 49 | mutex_unlock(&pmic->mtx); |
58 | return data; | 50 | return idx; |
59 | } | 51 | } |
60 | 52 | ||
61 | static int isl6271a_set_voltage(struct regulator_dev *dev, | 53 | static int isl6271a_set_voltage_sel(struct regulator_dev *dev, |
62 | int minuV, int maxuV, | 54 | unsigned selector) |
63 | unsigned *selector) | ||
64 | { | 55 | { |
65 | struct isl_pmic *pmic = rdev_get_drvdata(dev); | 56 | struct isl_pmic *pmic = rdev_get_drvdata(dev); |
66 | int err, data; | 57 | int err; |
67 | |||
68 | if (minuV < ISL6271A_VOLTAGE_MIN || minuV > ISL6271A_VOLTAGE_MAX) | ||
69 | return -EINVAL; | ||
70 | if (maxuV < ISL6271A_VOLTAGE_MIN || maxuV > ISL6271A_VOLTAGE_MAX) | ||
71 | return -EINVAL; | ||
72 | |||
73 | data = DIV_ROUND_UP(minuV - ISL6271A_VOLTAGE_MIN, | ||
74 | ISL6271A_VOLTAGE_STEP); | ||
75 | *selector = data; | ||
76 | 58 | ||
77 | mutex_lock(&pmic->mtx); | 59 | mutex_lock(&pmic->mtx); |
78 | 60 | ||
79 | err = i2c_smbus_write_byte(pmic->client, data); | 61 | err = i2c_smbus_write_byte(pmic->client, selector); |
80 | if (err < 0) | 62 | if (err < 0) |
81 | dev_err(&pmic->client->dev, "Error setting voltage\n"); | 63 | dev_err(&pmic->client->dev, "Error setting voltage\n"); |
82 | 64 | ||
@@ -84,15 +66,11 @@ static int isl6271a_set_voltage(struct regulator_dev *dev, | |||
84 | return err; | 66 | return err; |
85 | } | 67 | } |
86 | 68 | ||
87 | static int isl6271a_list_voltage(struct regulator_dev *dev, unsigned selector) | ||
88 | { | ||
89 | return ISL6271A_VOLTAGE_MIN + (ISL6271A_VOLTAGE_STEP * selector); | ||
90 | } | ||
91 | |||
92 | static struct regulator_ops isl_core_ops = { | 69 | static struct regulator_ops isl_core_ops = { |
93 | .get_voltage = isl6271a_get_voltage, | 70 | .get_voltage_sel = isl6271a_get_voltage_sel, |
94 | .set_voltage = isl6271a_set_voltage, | 71 | .set_voltage_sel = isl6271a_set_voltage_sel, |
95 | .list_voltage = isl6271a_list_voltage, | 72 | .list_voltage = regulator_list_voltage_linear, |
73 | .map_voltage = regulator_map_voltage_linear, | ||
96 | }; | 74 | }; |
97 | 75 | ||
98 | static int isl6271a_get_fixed_voltage(struct regulator_dev *dev) | 76 | static int isl6271a_get_fixed_voltage(struct regulator_dev *dev) |
@@ -112,7 +90,7 @@ static struct regulator_ops isl_fixed_ops = { | |||
112 | .list_voltage = isl6271a_list_fixed_voltage, | 90 | .list_voltage = isl6271a_list_fixed_voltage, |
113 | }; | 91 | }; |
114 | 92 | ||
115 | static struct regulator_desc isl_rd[] = { | 93 | static const struct regulator_desc isl_rd[] = { |
116 | { | 94 | { |
117 | .name = "Core Buck", | 95 | .name = "Core Buck", |
118 | .id = 0, | 96 | .id = 0, |
@@ -120,6 +98,8 @@ static struct regulator_desc isl_rd[] = { | |||
120 | .ops = &isl_core_ops, | 98 | .ops = &isl_core_ops, |
121 | .type = REGULATOR_VOLTAGE, | 99 | .type = REGULATOR_VOLTAGE, |
122 | .owner = THIS_MODULE, | 100 | .owner = THIS_MODULE, |
101 | .min_uV = ISL6271A_VOLTAGE_MIN, | ||
102 | .uV_step = ISL6271A_VOLTAGE_STEP, | ||
123 | }, { | 103 | }, { |
124 | .name = "LDO1", | 104 | .name = "LDO1", |
125 | .id = 1, | 105 | .id = 1, |
@@ -140,6 +120,7 @@ static struct regulator_desc isl_rd[] = { | |||
140 | static int __devinit isl6271a_probe(struct i2c_client *i2c, | 120 | static int __devinit isl6271a_probe(struct i2c_client *i2c, |
141 | const struct i2c_device_id *id) | 121 | const struct i2c_device_id *id) |
142 | { | 122 | { |
123 | struct regulator_config config = { }; | ||
143 | struct regulator_init_data *init_data = i2c->dev.platform_data; | 124 | struct regulator_init_data *init_data = i2c->dev.platform_data; |
144 | struct isl_pmic *pmic; | 125 | struct isl_pmic *pmic; |
145 | int err, i; | 126 | int err, i; |
@@ -147,12 +128,7 @@ static int __devinit isl6271a_probe(struct i2c_client *i2c, | |||
147 | if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 128 | if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
148 | return -EIO; | 129 | return -EIO; |
149 | 130 | ||
150 | if (!init_data) { | 131 | pmic = devm_kzalloc(&i2c->dev, sizeof(struct isl_pmic), GFP_KERNEL); |
151 | dev_err(&i2c->dev, "no platform data supplied\n"); | ||
152 | return -EIO; | ||
153 | } | ||
154 | |||
155 | pmic = kzalloc(sizeof(struct isl_pmic), GFP_KERNEL); | ||
156 | if (!pmic) | 132 | if (!pmic) |
157 | return -ENOMEM; | 133 | return -ENOMEM; |
158 | 134 | ||
@@ -161,8 +137,14 @@ static int __devinit isl6271a_probe(struct i2c_client *i2c, | |||
161 | mutex_init(&pmic->mtx); | 137 | mutex_init(&pmic->mtx); |
162 | 138 | ||
163 | for (i = 0; i < 3; i++) { | 139 | for (i = 0; i < 3; i++) { |
164 | pmic->rdev[i] = regulator_register(&isl_rd[i], &i2c->dev, | 140 | config.dev = &i2c->dev; |
165 | init_data, pmic, NULL); | 141 | if (i == 0) |
142 | config.init_data = init_data; | ||
143 | else | ||
144 | config.init_data = 0; | ||
145 | config.driver_data = pmic; | ||
146 | |||
147 | pmic->rdev[i] = regulator_register(&isl_rd[i], &config); | ||
166 | if (IS_ERR(pmic->rdev[i])) { | 148 | if (IS_ERR(pmic->rdev[i])) { |
167 | dev_err(&i2c->dev, "failed to register %s\n", id->name); | 149 | dev_err(&i2c->dev, "failed to register %s\n", id->name); |
168 | err = PTR_ERR(pmic->rdev[i]); | 150 | err = PTR_ERR(pmic->rdev[i]); |
@@ -177,8 +159,6 @@ static int __devinit isl6271a_probe(struct i2c_client *i2c, | |||
177 | error: | 159 | error: |
178 | while (--i >= 0) | 160 | while (--i >= 0) |
179 | regulator_unregister(pmic->rdev[i]); | 161 | regulator_unregister(pmic->rdev[i]); |
180 | |||
181 | kfree(pmic); | ||
182 | return err; | 162 | return err; |
183 | } | 163 | } |
184 | 164 | ||
@@ -189,9 +169,6 @@ static int __devexit isl6271a_remove(struct i2c_client *i2c) | |||
189 | 169 | ||
190 | for (i = 0; i < 3; i++) | 170 | for (i = 0; i < 3; i++) |
191 | regulator_unregister(pmic->rdev[i]); | 171 | regulator_unregister(pmic->rdev[i]); |
192 | |||
193 | kfree(pmic); | ||
194 | |||
195 | return 0; | 172 | return 0; |
196 | } | 173 | } |
197 | 174 | ||
diff --git a/drivers/regulator/lp3971.c b/drivers/regulator/lp3971.c index 0cfabd318a59..981bea9cb9d7 100644 --- a/drivers/regulator/lp3971.c +++ b/drivers/regulator/lp3971.c | |||
@@ -124,6 +124,10 @@ static const int *ldo_voltage_map[] = { | |||
124 | static int lp3971_ldo_list_voltage(struct regulator_dev *dev, unsigned index) | 124 | static int lp3971_ldo_list_voltage(struct regulator_dev *dev, unsigned index) |
125 | { | 125 | { |
126 | int ldo = rdev_get_id(dev) - LP3971_LDO1; | 126 | int ldo = rdev_get_id(dev) - LP3971_LDO1; |
127 | |||
128 | if (index > LDO_VOL_MAX_IDX) | ||
129 | return -EINVAL; | ||
130 | |||
127 | return 1000 * LDO_VOL_VALUE_MAP(ldo)[index]; | 131 | return 1000 * LDO_VOL_VALUE_MAP(ldo)[index]; |
128 | } | 132 | } |
129 | 133 | ||
@@ -168,32 +172,15 @@ static int lp3971_ldo_get_voltage(struct regulator_dev *dev) | |||
168 | return 1000 * LDO_VOL_VALUE_MAP(ldo)[val]; | 172 | return 1000 * LDO_VOL_VALUE_MAP(ldo)[val]; |
169 | } | 173 | } |
170 | 174 | ||
171 | static int lp3971_ldo_set_voltage(struct regulator_dev *dev, | 175 | static int lp3971_ldo_set_voltage_sel(struct regulator_dev *dev, |
172 | int min_uV, int max_uV, | 176 | unsigned int selector) |
173 | unsigned int *selector) | ||
174 | { | 177 | { |
175 | struct lp3971 *lp3971 = rdev_get_drvdata(dev); | 178 | struct lp3971 *lp3971 = rdev_get_drvdata(dev); |
176 | int ldo = rdev_get_id(dev) - LP3971_LDO1; | 179 | int ldo = rdev_get_id(dev) - LP3971_LDO1; |
177 | int min_vol = min_uV / 1000, max_vol = max_uV / 1000; | ||
178 | const int *vol_map = LDO_VOL_VALUE_MAP(ldo); | ||
179 | u16 val; | ||
180 | |||
181 | if (min_vol < vol_map[LDO_VOL_MIN_IDX] || | ||
182 | min_vol > vol_map[LDO_VOL_MAX_IDX]) | ||
183 | return -EINVAL; | ||
184 | |||
185 | for (val = LDO_VOL_MIN_IDX; val <= LDO_VOL_MAX_IDX; val++) | ||
186 | if (vol_map[val] >= min_vol) | ||
187 | break; | ||
188 | |||
189 | if (val > LDO_VOL_MAX_IDX || vol_map[val] > max_vol) | ||
190 | return -EINVAL; | ||
191 | |||
192 | *selector = val; | ||
193 | 180 | ||
194 | return lp3971_set_bits(lp3971, LP3971_LDO_VOL_CONTR_REG(ldo), | 181 | return lp3971_set_bits(lp3971, LP3971_LDO_VOL_CONTR_REG(ldo), |
195 | LDO_VOL_CONTR_MASK << LDO_VOL_CONTR_SHIFT(ldo), | 182 | LDO_VOL_CONTR_MASK << LDO_VOL_CONTR_SHIFT(ldo), |
196 | val << LDO_VOL_CONTR_SHIFT(ldo)); | 183 | selector << LDO_VOL_CONTR_SHIFT(ldo)); |
197 | } | 184 | } |
198 | 185 | ||
199 | static struct regulator_ops lp3971_ldo_ops = { | 186 | static struct regulator_ops lp3971_ldo_ops = { |
@@ -202,11 +189,14 @@ static struct regulator_ops lp3971_ldo_ops = { | |||
202 | .enable = lp3971_ldo_enable, | 189 | .enable = lp3971_ldo_enable, |
203 | .disable = lp3971_ldo_disable, | 190 | .disable = lp3971_ldo_disable, |
204 | .get_voltage = lp3971_ldo_get_voltage, | 191 | .get_voltage = lp3971_ldo_get_voltage, |
205 | .set_voltage = lp3971_ldo_set_voltage, | 192 | .set_voltage_sel = lp3971_ldo_set_voltage_sel, |
206 | }; | 193 | }; |
207 | 194 | ||
208 | static int lp3971_dcdc_list_voltage(struct regulator_dev *dev, unsigned index) | 195 | static int lp3971_dcdc_list_voltage(struct regulator_dev *dev, unsigned index) |
209 | { | 196 | { |
197 | if (index < BUCK_TARGET_VOL_MIN_IDX || index > BUCK_TARGET_VOL_MAX_IDX) | ||
198 | return -EINVAL; | ||
199 | |||
210 | return 1000 * buck_voltage_map[index]; | 200 | return 1000 * buck_voltage_map[index]; |
211 | } | 201 | } |
212 | 202 | ||
@@ -259,33 +249,15 @@ static int lp3971_dcdc_get_voltage(struct regulator_dev *dev) | |||
259 | return val; | 249 | return val; |
260 | } | 250 | } |
261 | 251 | ||
262 | static int lp3971_dcdc_set_voltage(struct regulator_dev *dev, | 252 | static int lp3971_dcdc_set_voltage_sel(struct regulator_dev *dev, |
263 | int min_uV, int max_uV, | 253 | unsigned int selector) |
264 | unsigned int *selector) | ||
265 | { | 254 | { |
266 | struct lp3971 *lp3971 = rdev_get_drvdata(dev); | 255 | struct lp3971 *lp3971 = rdev_get_drvdata(dev); |
267 | int buck = rdev_get_id(dev) - LP3971_DCDC1; | 256 | int buck = rdev_get_id(dev) - LP3971_DCDC1; |
268 | int min_vol = min_uV / 1000, max_vol = max_uV / 1000; | ||
269 | const int *vol_map = buck_voltage_map; | ||
270 | u16 val; | ||
271 | int ret; | 257 | int ret; |
272 | 258 | ||
273 | if (min_vol < vol_map[BUCK_TARGET_VOL_MIN_IDX] || | ||
274 | min_vol > vol_map[BUCK_TARGET_VOL_MAX_IDX]) | ||
275 | return -EINVAL; | ||
276 | |||
277 | for (val = BUCK_TARGET_VOL_MIN_IDX; val <= BUCK_TARGET_VOL_MAX_IDX; | ||
278 | val++) | ||
279 | if (vol_map[val] >= min_vol) | ||
280 | break; | ||
281 | |||
282 | if (val > BUCK_TARGET_VOL_MAX_IDX || vol_map[val] > max_vol) | ||
283 | return -EINVAL; | ||
284 | |||
285 | *selector = val; | ||
286 | |||
287 | ret = lp3971_set_bits(lp3971, LP3971_BUCK_TARGET_VOL1_REG(buck), | 259 | ret = lp3971_set_bits(lp3971, LP3971_BUCK_TARGET_VOL1_REG(buck), |
288 | BUCK_TARGET_VOL_MASK, val); | 260 | BUCK_TARGET_VOL_MASK, selector); |
289 | if (ret) | 261 | if (ret) |
290 | return ret; | 262 | return ret; |
291 | 263 | ||
@@ -306,10 +278,10 @@ static struct regulator_ops lp3971_dcdc_ops = { | |||
306 | .enable = lp3971_dcdc_enable, | 278 | .enable = lp3971_dcdc_enable, |
307 | .disable = lp3971_dcdc_disable, | 279 | .disable = lp3971_dcdc_disable, |
308 | .get_voltage = lp3971_dcdc_get_voltage, | 280 | .get_voltage = lp3971_dcdc_get_voltage, |
309 | .set_voltage = lp3971_dcdc_set_voltage, | 281 | .set_voltage_sel = lp3971_dcdc_set_voltage_sel, |
310 | }; | 282 | }; |
311 | 283 | ||
312 | static struct regulator_desc regulators[] = { | 284 | static const struct regulator_desc regulators[] = { |
313 | { | 285 | { |
314 | .name = "LDO1", | 286 | .name = "LDO1", |
315 | .id = LP3971_LDO1, | 287 | .id = LP3971_LDO1, |
@@ -449,10 +421,15 @@ static int __devinit setup_regulators(struct lp3971 *lp3971, | |||
449 | 421 | ||
450 | /* Instantiate the regulators */ | 422 | /* Instantiate the regulators */ |
451 | for (i = 0; i < pdata->num_regulators; i++) { | 423 | for (i = 0; i < pdata->num_regulators; i++) { |
424 | struct regulator_config config = { }; | ||
452 | struct lp3971_regulator_subdev *reg = &pdata->regulators[i]; | 425 | struct lp3971_regulator_subdev *reg = &pdata->regulators[i]; |
453 | lp3971->rdev[i] = regulator_register(®ulators[reg->id], | ||
454 | lp3971->dev, reg->initdata, lp3971, NULL); | ||
455 | 426 | ||
427 | config.dev = lp3971->dev; | ||
428 | config.init_data = reg->initdata; | ||
429 | config.driver_data = lp3971; | ||
430 | |||
431 | lp3971->rdev[i] = regulator_register(®ulators[reg->id], | ||
432 | &config); | ||
456 | if (IS_ERR(lp3971->rdev[i])) { | 433 | if (IS_ERR(lp3971->rdev[i])) { |
457 | err = PTR_ERR(lp3971->rdev[i]); | 434 | err = PTR_ERR(lp3971->rdev[i]); |
458 | dev_err(lp3971->dev, "regulator init failed: %d\n", | 435 | dev_err(lp3971->dev, "regulator init failed: %d\n", |
@@ -545,23 +522,7 @@ static struct i2c_driver lp3971_i2c_driver = { | |||
545 | .id_table = lp3971_i2c_id, | 522 | .id_table = lp3971_i2c_id, |
546 | }; | 523 | }; |
547 | 524 | ||
548 | static int __init lp3971_module_init(void) | 525 | module_i2c_driver(lp3971_i2c_driver); |
549 | { | ||
550 | int ret; | ||
551 | |||
552 | ret = i2c_add_driver(&lp3971_i2c_driver); | ||
553 | if (ret != 0) | ||
554 | pr_err("Failed to register I2C driver: %d\n", ret); | ||
555 | |||
556 | return ret; | ||
557 | } | ||
558 | module_init(lp3971_module_init); | ||
559 | |||
560 | static void __exit lp3971_module_exit(void) | ||
561 | { | ||
562 | i2c_del_driver(&lp3971_i2c_driver); | ||
563 | } | ||
564 | module_exit(lp3971_module_exit); | ||
565 | 526 | ||
566 | MODULE_LICENSE("GPL"); | 527 | MODULE_LICENSE("GPL"); |
567 | MODULE_AUTHOR("Marek Szyprowski <m.szyprowski@samsung.com>"); | 528 | MODULE_AUTHOR("Marek Szyprowski <m.szyprowski@samsung.com>"); |
diff --git a/drivers/regulator/lp3972.c b/drivers/regulator/lp3972.c index 49a15eefe5fe..de073df7d344 100644 --- a/drivers/regulator/lp3972.c +++ b/drivers/regulator/lp3972.c | |||
@@ -245,6 +245,11 @@ static int lp3972_set_bits(struct lp3972 *lp3972, u8 reg, u16 mask, u16 val) | |||
245 | static int lp3972_ldo_list_voltage(struct regulator_dev *dev, unsigned index) | 245 | static int lp3972_ldo_list_voltage(struct regulator_dev *dev, unsigned index) |
246 | { | 246 | { |
247 | int ldo = rdev_get_id(dev) - LP3972_LDO1; | 247 | int ldo = rdev_get_id(dev) - LP3972_LDO1; |
248 | |||
249 | if (index < LP3972_LDO_VOL_MIN_IDX(ldo) || | ||
250 | index > LP3972_LDO_VOL_MAX_IDX(ldo)) | ||
251 | return -EINVAL; | ||
252 | |||
248 | return 1000 * LP3972_LDO_VOL_VALUE_MAP(ldo)[index]; | 253 | return 1000 * LP3972_LDO_VOL_VALUE_MAP(ldo)[index]; |
249 | } | 254 | } |
250 | 255 | ||
@@ -292,34 +297,16 @@ static int lp3972_ldo_get_voltage(struct regulator_dev *dev) | |||
292 | return 1000 * LP3972_LDO_VOL_VALUE_MAP(ldo)[val]; | 297 | return 1000 * LP3972_LDO_VOL_VALUE_MAP(ldo)[val]; |
293 | } | 298 | } |
294 | 299 | ||
295 | static int lp3972_ldo_set_voltage(struct regulator_dev *dev, | 300 | static int lp3972_ldo_set_voltage_sel(struct regulator_dev *dev, |
296 | int min_uV, int max_uV, | 301 | unsigned int selector) |
297 | unsigned int *selector) | ||
298 | { | 302 | { |
299 | struct lp3972 *lp3972 = rdev_get_drvdata(dev); | 303 | struct lp3972 *lp3972 = rdev_get_drvdata(dev); |
300 | int ldo = rdev_get_id(dev) - LP3972_LDO1; | 304 | int ldo = rdev_get_id(dev) - LP3972_LDO1; |
301 | int min_vol = min_uV / 1000, max_vol = max_uV / 1000; | ||
302 | const int *vol_map = LP3972_LDO_VOL_VALUE_MAP(ldo); | ||
303 | u16 val; | ||
304 | int shift, ret; | 305 | int shift, ret; |
305 | 306 | ||
306 | if (min_vol < vol_map[LP3972_LDO_VOL_MIN_IDX(ldo)] || | ||
307 | min_vol > vol_map[LP3972_LDO_VOL_MAX_IDX(ldo)]) | ||
308 | return -EINVAL; | ||
309 | |||
310 | for (val = LP3972_LDO_VOL_MIN_IDX(ldo); | ||
311 | val <= LP3972_LDO_VOL_MAX_IDX(ldo); val++) | ||
312 | if (vol_map[val] >= min_vol) | ||
313 | break; | ||
314 | |||
315 | if (val > LP3972_LDO_VOL_MAX_IDX(ldo) || vol_map[val] > max_vol) | ||
316 | return -EINVAL; | ||
317 | |||
318 | *selector = val; | ||
319 | |||
320 | shift = LP3972_LDO_VOL_CONTR_SHIFT(ldo); | 307 | shift = LP3972_LDO_VOL_CONTR_SHIFT(ldo); |
321 | ret = lp3972_set_bits(lp3972, LP3972_LDO_VOL_CONTR_REG(ldo), | 308 | ret = lp3972_set_bits(lp3972, LP3972_LDO_VOL_CONTR_REG(ldo), |
322 | LP3972_LDO_VOL_MASK(ldo) << shift, val << shift); | 309 | LP3972_LDO_VOL_MASK(ldo) << shift, selector << shift); |
323 | 310 | ||
324 | if (ret) | 311 | if (ret) |
325 | return ret; | 312 | return ret; |
@@ -355,12 +342,17 @@ static struct regulator_ops lp3972_ldo_ops = { | |||
355 | .enable = lp3972_ldo_enable, | 342 | .enable = lp3972_ldo_enable, |
356 | .disable = lp3972_ldo_disable, | 343 | .disable = lp3972_ldo_disable, |
357 | .get_voltage = lp3972_ldo_get_voltage, | 344 | .get_voltage = lp3972_ldo_get_voltage, |
358 | .set_voltage = lp3972_ldo_set_voltage, | 345 | .set_voltage_sel = lp3972_ldo_set_voltage_sel, |
359 | }; | 346 | }; |
360 | 347 | ||
361 | static int lp3972_dcdc_list_voltage(struct regulator_dev *dev, unsigned index) | 348 | static int lp3972_dcdc_list_voltage(struct regulator_dev *dev, unsigned index) |
362 | { | 349 | { |
363 | int buck = rdev_get_id(dev) - LP3972_DCDC1; | 350 | int buck = rdev_get_id(dev) - LP3972_DCDC1; |
351 | |||
352 | if (index < LP3972_BUCK_VOL_MIN_IDX(buck) || | ||
353 | index > LP3972_BUCK_VOL_MAX_IDX(buck)) | ||
354 | return -EINVAL; | ||
355 | |||
364 | return 1000 * buck_voltage_map[buck][index]; | 356 | return 1000 * buck_voltage_map[buck][index]; |
365 | } | 357 | } |
366 | 358 | ||
@@ -419,34 +411,15 @@ static int lp3972_dcdc_get_voltage(struct regulator_dev *dev) | |||
419 | return val; | 411 | return val; |
420 | } | 412 | } |
421 | 413 | ||
422 | static int lp3972_dcdc_set_voltage(struct regulator_dev *dev, | 414 | static int lp3972_dcdc_set_voltage_sel(struct regulator_dev *dev, |
423 | int min_uV, int max_uV, | 415 | unsigned int selector) |
424 | unsigned int *selector) | ||
425 | { | 416 | { |
426 | struct lp3972 *lp3972 = rdev_get_drvdata(dev); | 417 | struct lp3972 *lp3972 = rdev_get_drvdata(dev); |
427 | int buck = rdev_get_id(dev) - LP3972_DCDC1; | 418 | int buck = rdev_get_id(dev) - LP3972_DCDC1; |
428 | int min_vol = min_uV / 1000, max_vol = max_uV / 1000; | ||
429 | const int *vol_map = buck_voltage_map[buck]; | ||
430 | u16 val; | ||
431 | int ret; | 419 | int ret; |
432 | 420 | ||
433 | if (min_vol < vol_map[LP3972_BUCK_VOL_MIN_IDX(buck)] || | ||
434 | min_vol > vol_map[LP3972_BUCK_VOL_MAX_IDX(buck)]) | ||
435 | return -EINVAL; | ||
436 | |||
437 | for (val = LP3972_BUCK_VOL_MIN_IDX(buck); | ||
438 | val <= LP3972_BUCK_VOL_MAX_IDX(buck); val++) | ||
439 | if (vol_map[val] >= min_vol) | ||
440 | break; | ||
441 | |||
442 | if (val > LP3972_BUCK_VOL_MAX_IDX(buck) || | ||
443 | vol_map[val] > max_vol) | ||
444 | return -EINVAL; | ||
445 | |||
446 | *selector = val; | ||
447 | |||
448 | ret = lp3972_set_bits(lp3972, LP3972_BUCK_VOL1_REG(buck), | 421 | ret = lp3972_set_bits(lp3972, LP3972_BUCK_VOL1_REG(buck), |
449 | LP3972_BUCK_VOL_MASK, val); | 422 | LP3972_BUCK_VOL_MASK, selector); |
450 | if (ret) | 423 | if (ret) |
451 | return ret; | 424 | return ret; |
452 | 425 | ||
@@ -468,10 +441,10 @@ static struct regulator_ops lp3972_dcdc_ops = { | |||
468 | .enable = lp3972_dcdc_enable, | 441 | .enable = lp3972_dcdc_enable, |
469 | .disable = lp3972_dcdc_disable, | 442 | .disable = lp3972_dcdc_disable, |
470 | .get_voltage = lp3972_dcdc_get_voltage, | 443 | .get_voltage = lp3972_dcdc_get_voltage, |
471 | .set_voltage = lp3972_dcdc_set_voltage, | 444 | .set_voltage_sel = lp3972_dcdc_set_voltage_sel, |
472 | }; | 445 | }; |
473 | 446 | ||
474 | static struct regulator_desc regulators[] = { | 447 | static const struct regulator_desc regulators[] = { |
475 | { | 448 | { |
476 | .name = "LDO1", | 449 | .name = "LDO1", |
477 | .id = LP3972_LDO1, | 450 | .id = LP3972_LDO1, |
@@ -554,9 +527,14 @@ static int __devinit setup_regulators(struct lp3972 *lp3972, | |||
554 | /* Instantiate the regulators */ | 527 | /* Instantiate the regulators */ |
555 | for (i = 0; i < pdata->num_regulators; i++) { | 528 | for (i = 0; i < pdata->num_regulators; i++) { |
556 | struct lp3972_regulator_subdev *reg = &pdata->regulators[i]; | 529 | struct lp3972_regulator_subdev *reg = &pdata->regulators[i]; |
557 | lp3972->rdev[i] = regulator_register(®ulators[reg->id], | 530 | struct regulator_config config = { }; |
558 | lp3972->dev, reg->initdata, lp3972, NULL); | ||
559 | 531 | ||
532 | config.dev = lp3972->dev; | ||
533 | config.init_data = reg->initdata; | ||
534 | config.driver_data = lp3972; | ||
535 | |||
536 | lp3972->rdev[i] = regulator_register(®ulators[reg->id], | ||
537 | &config); | ||
560 | if (IS_ERR(lp3972->rdev[i])) { | 538 | if (IS_ERR(lp3972->rdev[i])) { |
561 | err = PTR_ERR(lp3972->rdev[i]); | 539 | err = PTR_ERR(lp3972->rdev[i]); |
562 | dev_err(lp3972->dev, "regulator init failed: %d\n", | 540 | dev_err(lp3972->dev, "regulator init failed: %d\n", |
diff --git a/drivers/regulator/max1586.c b/drivers/regulator/max1586.c index 282d2ee0604e..b9444ee08da9 100644 --- a/drivers/regulator/max1586.c +++ b/drivers/regulator/max1586.c | |||
@@ -161,7 +161,7 @@ static struct regulator_ops max1586_v6_ops = { | |||
161 | .list_voltage = max1586_v6_list, | 161 | .list_voltage = max1586_v6_list, |
162 | }; | 162 | }; |
163 | 163 | ||
164 | static struct regulator_desc max1586_reg[] = { | 164 | static const struct regulator_desc max1586_reg[] = { |
165 | { | 165 | { |
166 | .name = "Output_V3", | 166 | .name = "Output_V3", |
167 | .id = MAX1586_V3, | 167 | .id = MAX1586_V3, |
@@ -185,21 +185,21 @@ static int __devinit max1586_pmic_probe(struct i2c_client *client, | |||
185 | { | 185 | { |
186 | struct regulator_dev **rdev; | 186 | struct regulator_dev **rdev; |
187 | struct max1586_platform_data *pdata = client->dev.platform_data; | 187 | struct max1586_platform_data *pdata = client->dev.platform_data; |
188 | struct regulator_config config = { }; | ||
188 | struct max1586_data *max1586; | 189 | struct max1586_data *max1586; |
189 | int i, id, ret = -ENOMEM; | 190 | int i, id, ret = -ENOMEM; |
190 | 191 | ||
191 | max1586 = kzalloc(sizeof(struct max1586_data) + | 192 | max1586 = devm_kzalloc(&client->dev, sizeof(struct max1586_data) + |
192 | sizeof(struct regulator_dev *) * (MAX1586_V6 + 1), | 193 | sizeof(struct regulator_dev *) * (MAX1586_V6 + 1), |
193 | GFP_KERNEL); | 194 | GFP_KERNEL); |
194 | if (!max1586) | 195 | if (!max1586) |
195 | goto out; | 196 | return -ENOMEM; |
196 | 197 | ||
197 | max1586->client = client; | 198 | max1586->client = client; |
198 | 199 | ||
199 | if (!pdata->v3_gain) { | 200 | if (!pdata->v3_gain) |
200 | ret = -EINVAL; | 201 | return -EINVAL; |
201 | goto out_unmap; | 202 | |
202 | } | ||
203 | max1586->min_uV = MAX1586_V3_MIN_UV / 1000 * pdata->v3_gain / 1000; | 203 | max1586->min_uV = MAX1586_V3_MIN_UV / 1000 * pdata->v3_gain / 1000; |
204 | max1586->max_uV = MAX1586_V3_MAX_UV / 1000 * pdata->v3_gain / 1000; | 204 | max1586->max_uV = MAX1586_V3_MAX_UV / 1000 * pdata->v3_gain / 1000; |
205 | 205 | ||
@@ -212,9 +212,12 @@ static int __devinit max1586_pmic_probe(struct i2c_client *client, | |||
212 | dev_err(&client->dev, "invalid regulator id %d\n", id); | 212 | dev_err(&client->dev, "invalid regulator id %d\n", id); |
213 | goto err; | 213 | goto err; |
214 | } | 214 | } |
215 | rdev[i] = regulator_register(&max1586_reg[id], &client->dev, | 215 | |
216 | pdata->subdevs[i].platform_data, | 216 | config.dev = &client->dev; |
217 | max1586, NULL); | 217 | config.init_data = pdata->subdevs[i].platform_data; |
218 | config.driver_data = max1586; | ||
219 | |||
220 | rdev[i] = regulator_register(&max1586_reg[id], &config); | ||
218 | if (IS_ERR(rdev[i])) { | 221 | if (IS_ERR(rdev[i])) { |
219 | ret = PTR_ERR(rdev[i]); | 222 | ret = PTR_ERR(rdev[i]); |
220 | dev_err(&client->dev, "failed to register %s\n", | 223 | dev_err(&client->dev, "failed to register %s\n", |
@@ -230,9 +233,6 @@ static int __devinit max1586_pmic_probe(struct i2c_client *client, | |||
230 | err: | 233 | err: |
231 | while (--i >= 0) | 234 | while (--i >= 0) |
232 | regulator_unregister(rdev[i]); | 235 | regulator_unregister(rdev[i]); |
233 | out_unmap: | ||
234 | kfree(max1586); | ||
235 | out: | ||
236 | return ret; | 236 | return ret; |
237 | } | 237 | } |
238 | 238 | ||
@@ -244,8 +244,6 @@ static int __devexit max1586_pmic_remove(struct i2c_client *client) | |||
244 | for (i = 0; i <= MAX1586_V6; i++) | 244 | for (i = 0; i <= MAX1586_V6; i++) |
245 | if (max1586->rdev[i]) | 245 | if (max1586->rdev[i]) |
246 | regulator_unregister(max1586->rdev[i]); | 246 | regulator_unregister(max1586->rdev[i]); |
247 | kfree(max1586); | ||
248 | |||
249 | return 0; | 247 | return 0; |
250 | } | 248 | } |
251 | 249 | ||
diff --git a/drivers/regulator/max8649.c b/drivers/regulator/max8649.c index 824c650436ed..1f4bb80457b3 100644 --- a/drivers/regulator/max8649.c +++ b/drivers/regulator/max8649.c | |||
@@ -53,7 +53,6 @@ struct max8649_regulator_info { | |||
53 | struct device *dev; | 53 | struct device *dev; |
54 | struct regmap *regmap; | 54 | struct regmap *regmap; |
55 | 55 | ||
56 | int vol_reg; | ||
57 | unsigned mode:2; /* bit[1:0] = VID1, VID0 */ | 56 | unsigned mode:2; /* bit[1:0] = VID1, VID0 */ |
58 | unsigned extclk_freq:2; | 57 | unsigned extclk_freq:2; |
59 | unsigned extclk:1; | 58 | unsigned extclk:1; |
@@ -61,53 +60,6 @@ struct max8649_regulator_info { | |||
61 | unsigned ramp_down:1; | 60 | unsigned ramp_down:1; |
62 | }; | 61 | }; |
63 | 62 | ||
64 | /* I2C operations */ | ||
65 | |||
66 | static inline int check_range(int min_uV, int max_uV) | ||
67 | { | ||
68 | if ((min_uV < MAX8649_DCDC_VMIN) || (max_uV > MAX8649_DCDC_VMAX) | ||
69 | || (min_uV > max_uV)) | ||
70 | return -EINVAL; | ||
71 | return 0; | ||
72 | } | ||
73 | |||
74 | static int max8649_list_voltage(struct regulator_dev *rdev, unsigned index) | ||
75 | { | ||
76 | return (MAX8649_DCDC_VMIN + index * MAX8649_DCDC_STEP); | ||
77 | } | ||
78 | |||
79 | static int max8649_get_voltage(struct regulator_dev *rdev) | ||
80 | { | ||
81 | struct max8649_regulator_info *info = rdev_get_drvdata(rdev); | ||
82 | unsigned int val; | ||
83 | unsigned char data; | ||
84 | int ret; | ||
85 | |||
86 | ret = regmap_read(info->regmap, info->vol_reg, &val); | ||
87 | if (ret != 0) | ||
88 | return ret; | ||
89 | data = (unsigned char)val & MAX8649_VOL_MASK; | ||
90 | return max8649_list_voltage(rdev, data); | ||
91 | } | ||
92 | |||
93 | static int max8649_set_voltage(struct regulator_dev *rdev, | ||
94 | int min_uV, int max_uV, unsigned *selector) | ||
95 | { | ||
96 | struct max8649_regulator_info *info = rdev_get_drvdata(rdev); | ||
97 | unsigned char data, mask; | ||
98 | |||
99 | if (check_range(min_uV, max_uV)) { | ||
100 | dev_err(info->dev, "invalid voltage range (%d, %d) uV\n", | ||
101 | min_uV, max_uV); | ||
102 | return -EINVAL; | ||
103 | } | ||
104 | data = DIV_ROUND_UP(min_uV - MAX8649_DCDC_VMIN, MAX8649_DCDC_STEP); | ||
105 | mask = MAX8649_VOL_MASK; | ||
106 | *selector = data & mask; | ||
107 | |||
108 | return regmap_update_bits(info->regmap, info->vol_reg, mask, data); | ||
109 | } | ||
110 | |||
111 | /* EN_PD means pulldown on EN input */ | 63 | /* EN_PD means pulldown on EN input */ |
112 | static int max8649_enable(struct regulator_dev *rdev) | 64 | static int max8649_enable(struct regulator_dev *rdev) |
113 | { | 65 | { |
@@ -145,11 +97,11 @@ static int max8649_enable_time(struct regulator_dev *rdev) | |||
145 | unsigned int val; | 97 | unsigned int val; |
146 | 98 | ||
147 | /* get voltage */ | 99 | /* get voltage */ |
148 | ret = regmap_read(info->regmap, info->vol_reg, &val); | 100 | ret = regmap_read(info->regmap, rdev->desc->vsel_reg, &val); |
149 | if (ret != 0) | 101 | if (ret != 0) |
150 | return ret; | 102 | return ret; |
151 | val &= MAX8649_VOL_MASK; | 103 | val &= MAX8649_VOL_MASK; |
152 | voltage = max8649_list_voltage(rdev, (unsigned char)val); /* uV */ | 104 | voltage = regulator_list_voltage_linear(rdev, (unsigned char)val); |
153 | 105 | ||
154 | /* get rate */ | 106 | /* get rate */ |
155 | ret = regmap_read(info->regmap, MAX8649_RAMP, &val); | 107 | ret = regmap_read(info->regmap, MAX8649_RAMP, &val); |
@@ -167,11 +119,11 @@ static int max8649_set_mode(struct regulator_dev *rdev, unsigned int mode) | |||
167 | 119 | ||
168 | switch (mode) { | 120 | switch (mode) { |
169 | case REGULATOR_MODE_FAST: | 121 | case REGULATOR_MODE_FAST: |
170 | regmap_update_bits(info->regmap, info->vol_reg, MAX8649_FORCE_PWM, | 122 | regmap_update_bits(info->regmap, rdev->desc->vsel_reg, |
171 | MAX8649_FORCE_PWM); | 123 | MAX8649_FORCE_PWM, MAX8649_FORCE_PWM); |
172 | break; | 124 | break; |
173 | case REGULATOR_MODE_NORMAL: | 125 | case REGULATOR_MODE_NORMAL: |
174 | regmap_update_bits(info->regmap, info->vol_reg, | 126 | regmap_update_bits(info->regmap, rdev->desc->vsel_reg, |
175 | MAX8649_FORCE_PWM, 0); | 127 | MAX8649_FORCE_PWM, 0); |
176 | break; | 128 | break; |
177 | default: | 129 | default: |
@@ -186,7 +138,7 @@ static unsigned int max8649_get_mode(struct regulator_dev *rdev) | |||
186 | unsigned int val; | 138 | unsigned int val; |
187 | int ret; | 139 | int ret; |
188 | 140 | ||
189 | ret = regmap_read(info->regmap, info->vol_reg, &val); | 141 | ret = regmap_read(info->regmap, rdev->desc->vsel_reg, &val); |
190 | if (ret != 0) | 142 | if (ret != 0) |
191 | return ret; | 143 | return ret; |
192 | if (val & MAX8649_FORCE_PWM) | 144 | if (val & MAX8649_FORCE_PWM) |
@@ -195,9 +147,10 @@ static unsigned int max8649_get_mode(struct regulator_dev *rdev) | |||
195 | } | 147 | } |
196 | 148 | ||
197 | static struct regulator_ops max8649_dcdc_ops = { | 149 | static struct regulator_ops max8649_dcdc_ops = { |
198 | .set_voltage = max8649_set_voltage, | 150 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
199 | .get_voltage = max8649_get_voltage, | 151 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
200 | .list_voltage = max8649_list_voltage, | 152 | .list_voltage = regulator_list_voltage_linear, |
153 | .map_voltage = regulator_map_voltage_linear, | ||
201 | .enable = max8649_enable, | 154 | .enable = max8649_enable, |
202 | .disable = max8649_disable, | 155 | .disable = max8649_disable, |
203 | .is_enabled = max8649_is_enabled, | 156 | .is_enabled = max8649_is_enabled, |
@@ -213,6 +166,9 @@ static struct regulator_desc dcdc_desc = { | |||
213 | .type = REGULATOR_VOLTAGE, | 166 | .type = REGULATOR_VOLTAGE, |
214 | .n_voltages = 1 << 6, | 167 | .n_voltages = 1 << 6, |
215 | .owner = THIS_MODULE, | 168 | .owner = THIS_MODULE, |
169 | .vsel_mask = MAX8649_VOL_MASK, | ||
170 | .min_uV = MAX8649_DCDC_VMIN, | ||
171 | .uV_step = MAX8649_DCDC_STEP, | ||
216 | }; | 172 | }; |
217 | 173 | ||
218 | static struct regmap_config max8649_regmap_config = { | 174 | static struct regmap_config max8649_regmap_config = { |
@@ -225,21 +181,23 @@ static int __devinit max8649_regulator_probe(struct i2c_client *client, | |||
225 | { | 181 | { |
226 | struct max8649_platform_data *pdata = client->dev.platform_data; | 182 | struct max8649_platform_data *pdata = client->dev.platform_data; |
227 | struct max8649_regulator_info *info = NULL; | 183 | struct max8649_regulator_info *info = NULL; |
184 | struct regulator_config config = { }; | ||
228 | unsigned int val; | 185 | unsigned int val; |
229 | unsigned char data; | 186 | unsigned char data; |
230 | int ret; | 187 | int ret; |
231 | 188 | ||
232 | info = kzalloc(sizeof(struct max8649_regulator_info), GFP_KERNEL); | 189 | info = devm_kzalloc(&client->dev, sizeof(struct max8649_regulator_info), |
190 | GFP_KERNEL); | ||
233 | if (!info) { | 191 | if (!info) { |
234 | dev_err(&client->dev, "No enough memory\n"); | 192 | dev_err(&client->dev, "No enough memory\n"); |
235 | return -ENOMEM; | 193 | return -ENOMEM; |
236 | } | 194 | } |
237 | 195 | ||
238 | info->regmap = regmap_init_i2c(client, &max8649_regmap_config); | 196 | info->regmap = devm_regmap_init_i2c(client, &max8649_regmap_config); |
239 | if (IS_ERR(info->regmap)) { | 197 | if (IS_ERR(info->regmap)) { |
240 | ret = PTR_ERR(info->regmap); | 198 | ret = PTR_ERR(info->regmap); |
241 | dev_err(&client->dev, "Failed to allocate register map: %d\n", ret); | 199 | dev_err(&client->dev, "Failed to allocate register map: %d\n", ret); |
242 | goto fail; | 200 | return ret; |
243 | } | 201 | } |
244 | 202 | ||
245 | info->dev = &client->dev; | 203 | info->dev = &client->dev; |
@@ -248,16 +206,16 @@ static int __devinit max8649_regulator_probe(struct i2c_client *client, | |||
248 | info->mode = pdata->mode; | 206 | info->mode = pdata->mode; |
249 | switch (info->mode) { | 207 | switch (info->mode) { |
250 | case 0: | 208 | case 0: |
251 | info->vol_reg = MAX8649_MODE0; | 209 | dcdc_desc.vsel_reg = MAX8649_MODE0; |
252 | break; | 210 | break; |
253 | case 1: | 211 | case 1: |
254 | info->vol_reg = MAX8649_MODE1; | 212 | dcdc_desc.vsel_reg = MAX8649_MODE1; |
255 | break; | 213 | break; |
256 | case 2: | 214 | case 2: |
257 | info->vol_reg = MAX8649_MODE2; | 215 | dcdc_desc.vsel_reg = MAX8649_MODE2; |
258 | break; | 216 | break; |
259 | case 3: | 217 | case 3: |
260 | info->vol_reg = MAX8649_MODE3; | 218 | dcdc_desc.vsel_reg = MAX8649_MODE3; |
261 | break; | 219 | break; |
262 | default: | 220 | default: |
263 | break; | 221 | break; |
@@ -267,7 +225,7 @@ static int __devinit max8649_regulator_probe(struct i2c_client *client, | |||
267 | if (ret != 0) { | 225 | if (ret != 0) { |
268 | dev_err(info->dev, "Failed to detect ID of MAX8649:%d\n", | 226 | dev_err(info->dev, "Failed to detect ID of MAX8649:%d\n", |
269 | ret); | 227 | ret); |
270 | goto out; | 228 | return ret; |
271 | } | 229 | } |
272 | dev_info(info->dev, "Detected MAX8649 (ID:%x)\n", val); | 230 | dev_info(info->dev, "Detected MAX8649 (ID:%x)\n", val); |
273 | 231 | ||
@@ -277,7 +235,8 @@ static int __devinit max8649_regulator_probe(struct i2c_client *client, | |||
277 | /* enable/disable external clock synchronization */ | 235 | /* enable/disable external clock synchronization */ |
278 | info->extclk = pdata->extclk; | 236 | info->extclk = pdata->extclk; |
279 | data = (info->extclk) ? MAX8649_SYNC_EXTCLK : 0; | 237 | data = (info->extclk) ? MAX8649_SYNC_EXTCLK : 0; |
280 | regmap_update_bits(info->regmap, info->vol_reg, MAX8649_SYNC_EXTCLK, data); | 238 | regmap_update_bits(info->regmap, dcdc_desc.vsel_reg, |
239 | MAX8649_SYNC_EXTCLK, data); | ||
281 | if (info->extclk) { | 240 | if (info->extclk) { |
282 | /* set external clock frequency */ | 241 | /* set external clock frequency */ |
283 | info->extclk_freq = pdata->extclk_freq; | 242 | info->extclk_freq = pdata->extclk_freq; |
@@ -297,22 +256,18 @@ static int __devinit max8649_regulator_probe(struct i2c_client *client, | |||
297 | MAX8649_RAMP_DOWN); | 256 | MAX8649_RAMP_DOWN); |
298 | } | 257 | } |
299 | 258 | ||
300 | info->regulator = regulator_register(&dcdc_desc, &client->dev, | 259 | config.dev = &client->dev; |
301 | pdata->regulator, info, NULL); | 260 | config.init_data = pdata->regulator; |
261 | config.driver_data = info; | ||
262 | |||
263 | info->regulator = regulator_register(&dcdc_desc, &config); | ||
302 | if (IS_ERR(info->regulator)) { | 264 | if (IS_ERR(info->regulator)) { |
303 | dev_err(info->dev, "failed to register regulator %s\n", | 265 | dev_err(info->dev, "failed to register regulator %s\n", |
304 | dcdc_desc.name); | 266 | dcdc_desc.name); |
305 | ret = PTR_ERR(info->regulator); | 267 | return PTR_ERR(info->regulator); |
306 | goto out; | ||
307 | } | 268 | } |
308 | 269 | ||
309 | dev_info(info->dev, "Max8649 regulator device is detected.\n"); | ||
310 | return 0; | 270 | return 0; |
311 | out: | ||
312 | regmap_exit(info->regmap); | ||
313 | fail: | ||
314 | kfree(info); | ||
315 | return ret; | ||
316 | } | 271 | } |
317 | 272 | ||
318 | static int __devexit max8649_regulator_remove(struct i2c_client *client) | 273 | static int __devexit max8649_regulator_remove(struct i2c_client *client) |
@@ -322,8 +277,6 @@ static int __devexit max8649_regulator_remove(struct i2c_client *client) | |||
322 | if (info) { | 277 | if (info) { |
323 | if (info->regulator) | 278 | if (info->regulator) |
324 | regulator_unregister(info->regulator); | 279 | regulator_unregister(info->regulator); |
325 | regmap_exit(info->regmap); | ||
326 | kfree(info); | ||
327 | } | 280 | } |
328 | 281 | ||
329 | return 0; | 282 | return 0; |
@@ -360,4 +313,3 @@ module_exit(max8649_exit); | |||
360 | MODULE_DESCRIPTION("MAXIM 8649 voltage regulator driver"); | 313 | MODULE_DESCRIPTION("MAXIM 8649 voltage regulator driver"); |
361 | MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>"); | 314 | MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>"); |
362 | MODULE_LICENSE("GPL"); | 315 | MODULE_LICENSE("GPL"); |
363 | |||
diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c index 4c5b05311f47..8d531742f593 100644 --- a/drivers/regulator/max8660.c +++ b/drivers/regulator/max8660.c | |||
@@ -126,42 +126,22 @@ static int max8660_dcdc_disable(struct regulator_dev *rdev) | |||
126 | return max8660_write(max8660, MAX8660_OVER1, mask, 0); | 126 | return max8660_write(max8660, MAX8660_OVER1, mask, 0); |
127 | } | 127 | } |
128 | 128 | ||
129 | static int max8660_dcdc_list(struct regulator_dev *rdev, unsigned selector) | 129 | static int max8660_dcdc_get_voltage_sel(struct regulator_dev *rdev) |
130 | { | ||
131 | if (selector > MAX8660_DCDC_MAX_SEL) | ||
132 | return -EINVAL; | ||
133 | return MAX8660_DCDC_MIN_UV + selector * MAX8660_DCDC_STEP; | ||
134 | } | ||
135 | |||
136 | static int max8660_dcdc_get(struct regulator_dev *rdev) | ||
137 | { | 130 | { |
138 | struct max8660 *max8660 = rdev_get_drvdata(rdev); | 131 | struct max8660 *max8660 = rdev_get_drvdata(rdev); |
132 | |||
139 | u8 reg = (rdev_get_id(rdev) == MAX8660_V3) ? MAX8660_ADTV2 : MAX8660_SDTV2; | 133 | u8 reg = (rdev_get_id(rdev) == MAX8660_V3) ? MAX8660_ADTV2 : MAX8660_SDTV2; |
140 | u8 selector = max8660->shadow_regs[reg]; | 134 | u8 selector = max8660->shadow_regs[reg]; |
141 | return MAX8660_DCDC_MIN_UV + selector * MAX8660_DCDC_STEP; | 135 | return selector; |
142 | } | 136 | } |
143 | 137 | ||
144 | static int max8660_dcdc_set(struct regulator_dev *rdev, int min_uV, int max_uV, | 138 | static int max8660_dcdc_set_voltage_sel(struct regulator_dev *rdev, |
145 | unsigned int *s) | 139 | unsigned int selector) |
146 | { | 140 | { |
147 | struct max8660 *max8660 = rdev_get_drvdata(rdev); | 141 | struct max8660 *max8660 = rdev_get_drvdata(rdev); |
148 | u8 reg, selector, bits; | 142 | u8 reg, bits; |
149 | int ret; | 143 | int ret; |
150 | 144 | ||
151 | if (min_uV < MAX8660_DCDC_MIN_UV || min_uV > MAX8660_DCDC_MAX_UV) | ||
152 | return -EINVAL; | ||
153 | if (max_uV < MAX8660_DCDC_MIN_UV || max_uV > MAX8660_DCDC_MAX_UV) | ||
154 | return -EINVAL; | ||
155 | |||
156 | selector = DIV_ROUND_UP(min_uV - MAX8660_DCDC_MIN_UV, | ||
157 | MAX8660_DCDC_STEP); | ||
158 | |||
159 | ret = max8660_dcdc_list(rdev, selector); | ||
160 | if (ret < 0 || ret > max_uV) | ||
161 | return -EINVAL; | ||
162 | |||
163 | *s = selector; | ||
164 | |||
165 | reg = (rdev_get_id(rdev) == MAX8660_V3) ? MAX8660_ADTV2 : MAX8660_SDTV2; | 145 | reg = (rdev_get_id(rdev) == MAX8660_V3) ? MAX8660_ADTV2 : MAX8660_SDTV2; |
166 | ret = max8660_write(max8660, reg, 0, selector); | 146 | ret = max8660_write(max8660, reg, 0, selector); |
167 | if (ret) | 147 | if (ret) |
@@ -174,9 +154,10 @@ static int max8660_dcdc_set(struct regulator_dev *rdev, int min_uV, int max_uV, | |||
174 | 154 | ||
175 | static struct regulator_ops max8660_dcdc_ops = { | 155 | static struct regulator_ops max8660_dcdc_ops = { |
176 | .is_enabled = max8660_dcdc_is_enabled, | 156 | .is_enabled = max8660_dcdc_is_enabled, |
177 | .list_voltage = max8660_dcdc_list, | 157 | .list_voltage = regulator_list_voltage_linear, |
178 | .set_voltage = max8660_dcdc_set, | 158 | .map_voltage = regulator_map_voltage_linear, |
179 | .get_voltage = max8660_dcdc_get, | 159 | .set_voltage_sel = max8660_dcdc_set_voltage_sel, |
160 | .get_voltage_sel = max8660_dcdc_get_voltage_sel, | ||
180 | }; | 161 | }; |
181 | 162 | ||
182 | 163 | ||
@@ -184,42 +165,20 @@ static struct regulator_ops max8660_dcdc_ops = { | |||
184 | * LDO5 functions | 165 | * LDO5 functions |
185 | */ | 166 | */ |
186 | 167 | ||
187 | static int max8660_ldo5_list(struct regulator_dev *rdev, unsigned selector) | 168 | static int max8660_ldo5_get_voltage_sel(struct regulator_dev *rdev) |
188 | { | ||
189 | if (selector > MAX8660_LDO5_MAX_SEL) | ||
190 | return -EINVAL; | ||
191 | return MAX8660_LDO5_MIN_UV + selector * MAX8660_LDO5_STEP; | ||
192 | } | ||
193 | |||
194 | static int max8660_ldo5_get(struct regulator_dev *rdev) | ||
195 | { | 169 | { |
196 | struct max8660 *max8660 = rdev_get_drvdata(rdev); | 170 | struct max8660 *max8660 = rdev_get_drvdata(rdev); |
197 | u8 selector = max8660->shadow_regs[MAX8660_MDTV2]; | ||
198 | 171 | ||
199 | return MAX8660_LDO5_MIN_UV + selector * MAX8660_LDO5_STEP; | 172 | u8 selector = max8660->shadow_regs[MAX8660_MDTV2]; |
173 | return selector; | ||
200 | } | 174 | } |
201 | 175 | ||
202 | static int max8660_ldo5_set(struct regulator_dev *rdev, int min_uV, int max_uV, | 176 | static int max8660_ldo5_set_voltage_sel(struct regulator_dev *rdev, |
203 | unsigned int *s) | 177 | unsigned int selector) |
204 | { | 178 | { |
205 | struct max8660 *max8660 = rdev_get_drvdata(rdev); | 179 | struct max8660 *max8660 = rdev_get_drvdata(rdev); |
206 | u8 selector; | ||
207 | int ret; | 180 | int ret; |
208 | 181 | ||
209 | if (min_uV < MAX8660_LDO5_MIN_UV || min_uV > MAX8660_LDO5_MAX_UV) | ||
210 | return -EINVAL; | ||
211 | if (max_uV < MAX8660_LDO5_MIN_UV || max_uV > MAX8660_LDO5_MAX_UV) | ||
212 | return -EINVAL; | ||
213 | |||
214 | selector = DIV_ROUND_UP(min_uV - MAX8660_LDO5_MIN_UV, | ||
215 | MAX8660_LDO5_STEP); | ||
216 | |||
217 | ret = max8660_ldo5_list(rdev, selector); | ||
218 | if (ret < 0 || ret > max_uV) | ||
219 | return -EINVAL; | ||
220 | |||
221 | *s = selector; | ||
222 | |||
223 | ret = max8660_write(max8660, MAX8660_MDTV2, 0, selector); | 182 | ret = max8660_write(max8660, MAX8660_MDTV2, 0, selector); |
224 | if (ret) | 183 | if (ret) |
225 | return ret; | 184 | return ret; |
@@ -229,9 +188,10 @@ static int max8660_ldo5_set(struct regulator_dev *rdev, int min_uV, int max_uV, | |||
229 | } | 188 | } |
230 | 189 | ||
231 | static struct regulator_ops max8660_ldo5_ops = { | 190 | static struct regulator_ops max8660_ldo5_ops = { |
232 | .list_voltage = max8660_ldo5_list, | 191 | .list_voltage = regulator_list_voltage_linear, |
233 | .set_voltage = max8660_ldo5_set, | 192 | .map_voltage = regulator_map_voltage_linear, |
234 | .get_voltage = max8660_ldo5_get, | 193 | .set_voltage_sel = max8660_ldo5_set_voltage_sel, |
194 | .get_voltage_sel = max8660_ldo5_get_voltage_sel, | ||
235 | }; | 195 | }; |
236 | 196 | ||
237 | 197 | ||
@@ -261,59 +221,38 @@ static int max8660_ldo67_disable(struct regulator_dev *rdev) | |||
261 | return max8660_write(max8660, MAX8660_OVER2, mask, 0); | 221 | return max8660_write(max8660, MAX8660_OVER2, mask, 0); |
262 | } | 222 | } |
263 | 223 | ||
264 | static int max8660_ldo67_list(struct regulator_dev *rdev, unsigned selector) | 224 | static int max8660_ldo67_get_voltage_sel(struct regulator_dev *rdev) |
265 | { | ||
266 | if (selector > MAX8660_LDO67_MAX_SEL) | ||
267 | return -EINVAL; | ||
268 | return MAX8660_LDO67_MIN_UV + selector * MAX8660_LDO67_STEP; | ||
269 | } | ||
270 | |||
271 | static int max8660_ldo67_get(struct regulator_dev *rdev) | ||
272 | { | 225 | { |
273 | struct max8660 *max8660 = rdev_get_drvdata(rdev); | 226 | struct max8660 *max8660 = rdev_get_drvdata(rdev); |
227 | |||
274 | u8 shift = (rdev_get_id(rdev) == MAX8660_V6) ? 0 : 4; | 228 | u8 shift = (rdev_get_id(rdev) == MAX8660_V6) ? 0 : 4; |
275 | u8 selector = (max8660->shadow_regs[MAX8660_L12VCR] >> shift) & 0xf; | 229 | u8 selector = (max8660->shadow_regs[MAX8660_L12VCR] >> shift) & 0xf; |
276 | 230 | return selector; | |
277 | return MAX8660_LDO67_MIN_UV + selector * MAX8660_LDO67_STEP; | ||
278 | } | 231 | } |
279 | 232 | ||
280 | static int max8660_ldo67_set(struct regulator_dev *rdev, int min_uV, | 233 | static int max8660_ldo67_set_voltage_sel(struct regulator_dev *rdev, |
281 | int max_uV, unsigned int *s) | 234 | unsigned int selector) |
282 | { | 235 | { |
283 | struct max8660 *max8660 = rdev_get_drvdata(rdev); | 236 | struct max8660 *max8660 = rdev_get_drvdata(rdev); |
284 | u8 selector; | ||
285 | int ret; | ||
286 | |||
287 | if (min_uV < MAX8660_LDO67_MIN_UV || min_uV > MAX8660_LDO67_MAX_UV) | ||
288 | return -EINVAL; | ||
289 | if (max_uV < MAX8660_LDO67_MIN_UV || max_uV > MAX8660_LDO67_MAX_UV) | ||
290 | return -EINVAL; | ||
291 | |||
292 | selector = DIV_ROUND_UP(min_uV - MAX8660_LDO67_MIN_UV, | ||
293 | MAX8660_LDO67_STEP); | ||
294 | |||
295 | ret = max8660_ldo67_list(rdev, selector); | ||
296 | if (ret < 0 || ret > max_uV) | ||
297 | return -EINVAL; | ||
298 | |||
299 | *s = selector; | ||
300 | 237 | ||
301 | if (rdev_get_id(rdev) == MAX8660_V6) | 238 | if (rdev_get_id(rdev) == MAX8660_V6) |
302 | return max8660_write(max8660, MAX8660_L12VCR, 0xf0, selector); | 239 | return max8660_write(max8660, MAX8660_L12VCR, 0xf0, selector); |
303 | else | 240 | else |
304 | return max8660_write(max8660, MAX8660_L12VCR, 0x0f, selector << 4); | 241 | return max8660_write(max8660, MAX8660_L12VCR, 0x0f, |
242 | selector << 4); | ||
305 | } | 243 | } |
306 | 244 | ||
307 | static struct regulator_ops max8660_ldo67_ops = { | 245 | static struct regulator_ops max8660_ldo67_ops = { |
308 | .is_enabled = max8660_ldo67_is_enabled, | 246 | .is_enabled = max8660_ldo67_is_enabled, |
309 | .enable = max8660_ldo67_enable, | 247 | .enable = max8660_ldo67_enable, |
310 | .disable = max8660_ldo67_disable, | 248 | .disable = max8660_ldo67_disable, |
311 | .list_voltage = max8660_ldo67_list, | 249 | .list_voltage = regulator_list_voltage_linear, |
312 | .get_voltage = max8660_ldo67_get, | 250 | .map_voltage = regulator_map_voltage_linear, |
313 | .set_voltage = max8660_ldo67_set, | 251 | .get_voltage_sel = max8660_ldo67_get_voltage_sel, |
252 | .set_voltage_sel = max8660_ldo67_set_voltage_sel, | ||
314 | }; | 253 | }; |
315 | 254 | ||
316 | static struct regulator_desc max8660_reg[] = { | 255 | static const struct regulator_desc max8660_reg[] = { |
317 | { | 256 | { |
318 | .name = "V3(DCDC)", | 257 | .name = "V3(DCDC)", |
319 | .id = MAX8660_V3, | 258 | .id = MAX8660_V3, |
@@ -321,6 +260,8 @@ static struct regulator_desc max8660_reg[] = { | |||
321 | .type = REGULATOR_VOLTAGE, | 260 | .type = REGULATOR_VOLTAGE, |
322 | .n_voltages = MAX8660_DCDC_MAX_SEL + 1, | 261 | .n_voltages = MAX8660_DCDC_MAX_SEL + 1, |
323 | .owner = THIS_MODULE, | 262 | .owner = THIS_MODULE, |
263 | .min_uV = MAX8660_DCDC_MIN_UV, | ||
264 | .uV_step = MAX8660_DCDC_STEP, | ||
324 | }, | 265 | }, |
325 | { | 266 | { |
326 | .name = "V4(DCDC)", | 267 | .name = "V4(DCDC)", |
@@ -329,6 +270,8 @@ static struct regulator_desc max8660_reg[] = { | |||
329 | .type = REGULATOR_VOLTAGE, | 270 | .type = REGULATOR_VOLTAGE, |
330 | .n_voltages = MAX8660_DCDC_MAX_SEL + 1, | 271 | .n_voltages = MAX8660_DCDC_MAX_SEL + 1, |
331 | .owner = THIS_MODULE, | 272 | .owner = THIS_MODULE, |
273 | .min_uV = MAX8660_DCDC_MIN_UV, | ||
274 | .uV_step = MAX8660_DCDC_STEP, | ||
332 | }, | 275 | }, |
333 | { | 276 | { |
334 | .name = "V5(LDO)", | 277 | .name = "V5(LDO)", |
@@ -337,6 +280,8 @@ static struct regulator_desc max8660_reg[] = { | |||
337 | .type = REGULATOR_VOLTAGE, | 280 | .type = REGULATOR_VOLTAGE, |
338 | .n_voltages = MAX8660_LDO5_MAX_SEL + 1, | 281 | .n_voltages = MAX8660_LDO5_MAX_SEL + 1, |
339 | .owner = THIS_MODULE, | 282 | .owner = THIS_MODULE, |
283 | .min_uV = MAX8660_LDO5_MIN_UV, | ||
284 | .uV_step = MAX8660_LDO5_STEP, | ||
340 | }, | 285 | }, |
341 | { | 286 | { |
342 | .name = "V6(LDO)", | 287 | .name = "V6(LDO)", |
@@ -345,6 +290,8 @@ static struct regulator_desc max8660_reg[] = { | |||
345 | .type = REGULATOR_VOLTAGE, | 290 | .type = REGULATOR_VOLTAGE, |
346 | .n_voltages = MAX8660_LDO67_MAX_SEL + 1, | 291 | .n_voltages = MAX8660_LDO67_MAX_SEL + 1, |
347 | .owner = THIS_MODULE, | 292 | .owner = THIS_MODULE, |
293 | .min_uV = MAX8660_LDO67_MIN_UV, | ||
294 | .uV_step = MAX8660_LDO67_STEP, | ||
348 | }, | 295 | }, |
349 | { | 296 | { |
350 | .name = "V7(LDO)", | 297 | .name = "V7(LDO)", |
@@ -353,6 +300,8 @@ static struct regulator_desc max8660_reg[] = { | |||
353 | .type = REGULATOR_VOLTAGE, | 300 | .type = REGULATOR_VOLTAGE, |
354 | .n_voltages = MAX8660_LDO67_MAX_SEL + 1, | 301 | .n_voltages = MAX8660_LDO67_MAX_SEL + 1, |
355 | .owner = THIS_MODULE, | 302 | .owner = THIS_MODULE, |
303 | .min_uV = MAX8660_LDO67_MIN_UV, | ||
304 | .uV_step = MAX8660_LDO67_STEP, | ||
356 | }, | 305 | }, |
357 | }; | 306 | }; |
358 | 307 | ||
@@ -361,21 +310,20 @@ static int __devinit max8660_probe(struct i2c_client *client, | |||
361 | { | 310 | { |
362 | struct regulator_dev **rdev; | 311 | struct regulator_dev **rdev; |
363 | struct max8660_platform_data *pdata = client->dev.platform_data; | 312 | struct max8660_platform_data *pdata = client->dev.platform_data; |
313 | struct regulator_config config = { }; | ||
364 | struct max8660 *max8660; | 314 | struct max8660 *max8660; |
365 | int boot_on, i, id, ret = -EINVAL; | 315 | int boot_on, i, id, ret = -EINVAL; |
366 | 316 | ||
367 | if (pdata->num_subdevs > MAX8660_V_END) { | 317 | if (pdata->num_subdevs > MAX8660_V_END) { |
368 | dev_err(&client->dev, "Too many regulators found!\n"); | 318 | dev_err(&client->dev, "Too many regulators found!\n"); |
369 | goto out; | 319 | return -EINVAL; |
370 | } | 320 | } |
371 | 321 | ||
372 | max8660 = kzalloc(sizeof(struct max8660) + | 322 | max8660 = devm_kzalloc(&client->dev, sizeof(struct max8660) + |
373 | sizeof(struct regulator_dev *) * MAX8660_V_END, | 323 | sizeof(struct regulator_dev *) * MAX8660_V_END, |
374 | GFP_KERNEL); | 324 | GFP_KERNEL); |
375 | if (!max8660) { | 325 | if (!max8660) |
376 | ret = -ENOMEM; | 326 | return -ENOMEM; |
377 | goto out; | ||
378 | } | ||
379 | 327 | ||
380 | max8660->client = client; | 328 | max8660->client = client; |
381 | rdev = max8660->rdev; | 329 | rdev = max8660->rdev; |
@@ -404,7 +352,7 @@ static int __devinit max8660_probe(struct i2c_client *client, | |||
404 | for (i = 0; i < pdata->num_subdevs; i++) { | 352 | for (i = 0; i < pdata->num_subdevs; i++) { |
405 | 353 | ||
406 | if (!pdata->subdevs[i].platform_data) | 354 | if (!pdata->subdevs[i].platform_data) |
407 | goto err_free; | 355 | goto err_out; |
408 | 356 | ||
409 | boot_on = pdata->subdevs[i].platform_data->constraints.boot_on; | 357 | boot_on = pdata->subdevs[i].platform_data->constraints.boot_on; |
410 | 358 | ||
@@ -430,7 +378,7 @@ static int __devinit max8660_probe(struct i2c_client *client, | |||
430 | case MAX8660_V7: | 378 | case MAX8660_V7: |
431 | if (!strcmp(i2c_id->name, "max8661")) { | 379 | if (!strcmp(i2c_id->name, "max8661")) { |
432 | dev_err(&client->dev, "Regulator not on this chip!\n"); | 380 | dev_err(&client->dev, "Regulator not on this chip!\n"); |
433 | goto err_free; | 381 | goto err_out; |
434 | } | 382 | } |
435 | 383 | ||
436 | if (boot_on) | 384 | if (boot_on) |
@@ -440,7 +388,7 @@ static int __devinit max8660_probe(struct i2c_client *client, | |||
440 | default: | 388 | default: |
441 | dev_err(&client->dev, "invalid regulator %s\n", | 389 | dev_err(&client->dev, "invalid regulator %s\n", |
442 | pdata->subdevs[i].name); | 390 | pdata->subdevs[i].name); |
443 | goto err_free; | 391 | goto err_out; |
444 | } | 392 | } |
445 | } | 393 | } |
446 | 394 | ||
@@ -449,9 +397,11 @@ static int __devinit max8660_probe(struct i2c_client *client, | |||
449 | 397 | ||
450 | id = pdata->subdevs[i].id; | 398 | id = pdata->subdevs[i].id; |
451 | 399 | ||
452 | rdev[i] = regulator_register(&max8660_reg[id], &client->dev, | 400 | config.dev = &client->dev; |
453 | pdata->subdevs[i].platform_data, | 401 | config.init_data = pdata->subdevs[i].platform_data; |
454 | max8660, NULL); | 402 | config.driver_data = max8660; |
403 | |||
404 | rdev[i] = regulator_register(&max8660_reg[id], &config); | ||
455 | if (IS_ERR(rdev[i])) { | 405 | if (IS_ERR(rdev[i])) { |
456 | ret = PTR_ERR(rdev[i]); | 406 | ret = PTR_ERR(rdev[i]); |
457 | dev_err(&client->dev, "failed to register %s\n", | 407 | dev_err(&client->dev, "failed to register %s\n", |
@@ -461,15 +411,12 @@ static int __devinit max8660_probe(struct i2c_client *client, | |||
461 | } | 411 | } |
462 | 412 | ||
463 | i2c_set_clientdata(client, max8660); | 413 | i2c_set_clientdata(client, max8660); |
464 | dev_info(&client->dev, "Maxim 8660/8661 regulator driver loaded\n"); | ||
465 | return 0; | 414 | return 0; |
466 | 415 | ||
467 | err_unregister: | 416 | err_unregister: |
468 | while (--i >= 0) | 417 | while (--i >= 0) |
469 | regulator_unregister(rdev[i]); | 418 | regulator_unregister(rdev[i]); |
470 | err_free: | 419 | err_out: |
471 | kfree(max8660); | ||
472 | out: | ||
473 | return ret; | 420 | return ret; |
474 | } | 421 | } |
475 | 422 | ||
@@ -481,8 +428,6 @@ static int __devexit max8660_remove(struct i2c_client *client) | |||
481 | for (i = 0; i < MAX8660_V_END; i++) | 428 | for (i = 0; i < MAX8660_V_END; i++) |
482 | if (max8660->rdev[i]) | 429 | if (max8660->rdev[i]) |
483 | regulator_unregister(max8660->rdev[i]); | 430 | regulator_unregister(max8660->rdev[i]); |
484 | kfree(max8660); | ||
485 | |||
486 | return 0; | 431 | return 0; |
487 | } | 432 | } |
488 | 433 | ||
diff --git a/drivers/regulator/max8925-regulator.c b/drivers/regulator/max8925-regulator.c index 2f242f43096e..43dc97ec3932 100644 --- a/drivers/regulator/max8925-regulator.c +++ b/drivers/regulator/max8925-regulator.c | |||
@@ -38,50 +38,20 @@ struct max8925_regulator_info { | |||
38 | struct i2c_client *i2c; | 38 | struct i2c_client *i2c; |
39 | struct max8925_chip *chip; | 39 | struct max8925_chip *chip; |
40 | 40 | ||
41 | int min_uV; | ||
42 | int max_uV; | ||
43 | int step_uV; | ||
44 | int vol_reg; | 41 | int vol_reg; |
45 | int vol_shift; | ||
46 | int vol_nbits; | ||
47 | int enable_reg; | 42 | int enable_reg; |
48 | }; | 43 | }; |
49 | 44 | ||
50 | static inline int check_range(struct max8925_regulator_info *info, | 45 | static int max8925_set_voltage_sel(struct regulator_dev *rdev, |
51 | int min_uV, int max_uV) | 46 | unsigned int selector) |
52 | { | ||
53 | if (min_uV < info->min_uV || min_uV > info->max_uV) | ||
54 | return -EINVAL; | ||
55 | |||
56 | return 0; | ||
57 | } | ||
58 | |||
59 | static int max8925_list_voltage(struct regulator_dev *rdev, unsigned index) | ||
60 | { | ||
61 | struct max8925_regulator_info *info = rdev_get_drvdata(rdev); | ||
62 | return info->min_uV + index * info->step_uV; | ||
63 | } | ||
64 | |||
65 | static int max8925_set_voltage(struct regulator_dev *rdev, | ||
66 | int min_uV, int max_uV, unsigned int *selector) | ||
67 | { | 47 | { |
68 | struct max8925_regulator_info *info = rdev_get_drvdata(rdev); | 48 | struct max8925_regulator_info *info = rdev_get_drvdata(rdev); |
69 | unsigned char data, mask; | 49 | unsigned char mask = rdev->desc->n_voltages - 1; |
70 | |||
71 | if (check_range(info, min_uV, max_uV)) { | ||
72 | dev_err(info->chip->dev, "invalid voltage range (%d, %d) uV\n", | ||
73 | min_uV, max_uV); | ||
74 | return -EINVAL; | ||
75 | } | ||
76 | data = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV); | ||
77 | *selector = data; | ||
78 | data <<= info->vol_shift; | ||
79 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; | ||
80 | 50 | ||
81 | return max8925_set_bits(info->i2c, info->vol_reg, mask, data); | 51 | return max8925_set_bits(info->i2c, info->vol_reg, mask, selector); |
82 | } | 52 | } |
83 | 53 | ||
84 | static int max8925_get_voltage(struct regulator_dev *rdev) | 54 | static int max8925_get_voltage_sel(struct regulator_dev *rdev) |
85 | { | 55 | { |
86 | struct max8925_regulator_info *info = rdev_get_drvdata(rdev); | 56 | struct max8925_regulator_info *info = rdev_get_drvdata(rdev); |
87 | unsigned char data, mask; | 57 | unsigned char data, mask; |
@@ -90,10 +60,10 @@ static int max8925_get_voltage(struct regulator_dev *rdev) | |||
90 | ret = max8925_reg_read(info->i2c, info->vol_reg); | 60 | ret = max8925_reg_read(info->i2c, info->vol_reg); |
91 | if (ret < 0) | 61 | if (ret < 0) |
92 | return ret; | 62 | return ret; |
93 | mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; | 63 | mask = rdev->desc->n_voltages - 1; |
94 | data = (ret & mask) >> info->vol_shift; | 64 | data = ret & mask; |
95 | 65 | ||
96 | return max8925_list_voltage(rdev, data); | 66 | return data; |
97 | } | 67 | } |
98 | 68 | ||
99 | static int max8925_enable(struct regulator_dev *rdev) | 69 | static int max8925_enable(struct regulator_dev *rdev) |
@@ -163,8 +133,10 @@ static int max8925_set_dvm_disable(struct regulator_dev *rdev) | |||
163 | } | 133 | } |
164 | 134 | ||
165 | static struct regulator_ops max8925_regulator_sdv_ops = { | 135 | static struct regulator_ops max8925_regulator_sdv_ops = { |
166 | .set_voltage = max8925_set_voltage, | 136 | .map_voltage = regulator_map_voltage_linear, |
167 | .get_voltage = max8925_get_voltage, | 137 | .list_voltage = regulator_list_voltage_linear, |
138 | .set_voltage_sel = max8925_set_voltage_sel, | ||
139 | .get_voltage_sel = max8925_get_voltage_sel, | ||
168 | .enable = max8925_enable, | 140 | .enable = max8925_enable, |
169 | .disable = max8925_disable, | 141 | .disable = max8925_disable, |
170 | .is_enabled = max8925_is_enabled, | 142 | .is_enabled = max8925_is_enabled, |
@@ -174,8 +146,10 @@ static struct regulator_ops max8925_regulator_sdv_ops = { | |||
174 | }; | 146 | }; |
175 | 147 | ||
176 | static struct regulator_ops max8925_regulator_ldo_ops = { | 148 | static struct regulator_ops max8925_regulator_ldo_ops = { |
177 | .set_voltage = max8925_set_voltage, | 149 | .map_voltage = regulator_map_voltage_linear, |
178 | .get_voltage = max8925_get_voltage, | 150 | .list_voltage = regulator_list_voltage_linear, |
151 | .set_voltage_sel = max8925_set_voltage_sel, | ||
152 | .get_voltage_sel = max8925_get_voltage_sel, | ||
179 | .enable = max8925_enable, | 153 | .enable = max8925_enable, |
180 | .disable = max8925_disable, | 154 | .disable = max8925_disable, |
181 | .is_enabled = max8925_is_enabled, | 155 | .is_enabled = max8925_is_enabled, |
@@ -189,13 +163,11 @@ static struct regulator_ops max8925_regulator_ldo_ops = { | |||
189 | .type = REGULATOR_VOLTAGE, \ | 163 | .type = REGULATOR_VOLTAGE, \ |
190 | .id = MAX8925_ID_SD##_id, \ | 164 | .id = MAX8925_ID_SD##_id, \ |
191 | .owner = THIS_MODULE, \ | 165 | .owner = THIS_MODULE, \ |
166 | .n_voltages = 64, \ | ||
167 | .min_uV = min * 1000, \ | ||
168 | .uV_step = step * 1000, \ | ||
192 | }, \ | 169 | }, \ |
193 | .min_uV = min * 1000, \ | ||
194 | .max_uV = max * 1000, \ | ||
195 | .step_uV = step * 1000, \ | ||
196 | .vol_reg = MAX8925_SDV##_id, \ | 170 | .vol_reg = MAX8925_SDV##_id, \ |
197 | .vol_shift = 0, \ | ||
198 | .vol_nbits = 6, \ | ||
199 | .enable_reg = MAX8925_SDCTL##_id, \ | 171 | .enable_reg = MAX8925_SDCTL##_id, \ |
200 | } | 172 | } |
201 | 173 | ||
@@ -207,13 +179,11 @@ static struct regulator_ops max8925_regulator_ldo_ops = { | |||
207 | .type = REGULATOR_VOLTAGE, \ | 179 | .type = REGULATOR_VOLTAGE, \ |
208 | .id = MAX8925_ID_LDO##_id, \ | 180 | .id = MAX8925_ID_LDO##_id, \ |
209 | .owner = THIS_MODULE, \ | 181 | .owner = THIS_MODULE, \ |
182 | .n_voltages = 64, \ | ||
183 | .min_uV = min * 1000, \ | ||
184 | .uV_step = step * 1000, \ | ||
210 | }, \ | 185 | }, \ |
211 | .min_uV = min * 1000, \ | ||
212 | .max_uV = max * 1000, \ | ||
213 | .step_uV = step * 1000, \ | ||
214 | .vol_reg = MAX8925_LDOVOUT##_id, \ | 186 | .vol_reg = MAX8925_LDOVOUT##_id, \ |
215 | .vol_shift = 0, \ | ||
216 | .vol_nbits = 6, \ | ||
217 | .enable_reg = MAX8925_LDOCTL##_id, \ | 187 | .enable_reg = MAX8925_LDOCTL##_id, \ |
218 | } | 188 | } |
219 | 189 | ||
@@ -261,6 +231,7 @@ static int __devinit max8925_regulator_probe(struct platform_device *pdev) | |||
261 | { | 231 | { |
262 | struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent); | 232 | struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent); |
263 | struct max8925_platform_data *pdata = chip->dev->platform_data; | 233 | struct max8925_platform_data *pdata = chip->dev->platform_data; |
234 | struct regulator_config config = { }; | ||
264 | struct max8925_regulator_info *ri; | 235 | struct max8925_regulator_info *ri; |
265 | struct regulator_dev *rdev; | 236 | struct regulator_dev *rdev; |
266 | 237 | ||
@@ -272,8 +243,11 @@ static int __devinit max8925_regulator_probe(struct platform_device *pdev) | |||
272 | ri->i2c = chip->i2c; | 243 | ri->i2c = chip->i2c; |
273 | ri->chip = chip; | 244 | ri->chip = chip; |
274 | 245 | ||
275 | rdev = regulator_register(&ri->desc, &pdev->dev, | 246 | config.dev = &pdev->dev; |
276 | pdata->regulator[pdev->id], ri, NULL); | 247 | config.init_data = pdata->regulator[pdev->id]; |
248 | config.driver_data = ri; | ||
249 | |||
250 | rdev = regulator_register(&ri->desc, &config); | ||
277 | if (IS_ERR(rdev)) { | 251 | if (IS_ERR(rdev)) { |
278 | dev_err(&pdev->dev, "failed to register regulator %s\n", | 252 | dev_err(&pdev->dev, "failed to register regulator %s\n", |
279 | ri->desc.name); | 253 | ri->desc.name); |
@@ -319,4 +293,3 @@ MODULE_LICENSE("GPL"); | |||
319 | MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>"); | 293 | MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>"); |
320 | MODULE_DESCRIPTION("Regulator Driver for Maxim 8925 PMIC"); | 294 | MODULE_DESCRIPTION("Regulator Driver for Maxim 8925 PMIC"); |
321 | MODULE_ALIAS("platform:max8925-regulator"); | 295 | MODULE_ALIAS("platform:max8925-regulator"); |
322 | |||
diff --git a/drivers/regulator/max8952.c b/drivers/regulator/max8952.c index 75d89400c123..910c9b26d499 100644 --- a/drivers/regulator/max8952.c +++ b/drivers/regulator/max8952.c | |||
@@ -69,11 +69,6 @@ static int max8952_write_reg(struct max8952_data *max8952, | |||
69 | return i2c_smbus_write_byte_data(max8952->client, reg, value); | 69 | return i2c_smbus_write_byte_data(max8952->client, reg, value); |
70 | } | 70 | } |
71 | 71 | ||
72 | static int max8952_voltage(struct max8952_data *max8952, u8 mode) | ||
73 | { | ||
74 | return (max8952->pdata->dvs_mode[mode] * 10 + 770) * 1000; | ||
75 | } | ||
76 | |||
77 | static int max8952_list_voltage(struct regulator_dev *rdev, | 72 | static int max8952_list_voltage(struct regulator_dev *rdev, |
78 | unsigned int selector) | 73 | unsigned int selector) |
79 | { | 74 | { |
@@ -82,7 +77,7 @@ static int max8952_list_voltage(struct regulator_dev *rdev, | |||
82 | if (rdev_get_id(rdev) != 0) | 77 | if (rdev_get_id(rdev) != 0) |
83 | return -EINVAL; | 78 | return -EINVAL; |
84 | 79 | ||
85 | return max8952_voltage(max8952, selector); | 80 | return (max8952->pdata->dvs_mode[selector] * 10 + 770) * 1000; |
86 | } | 81 | } |
87 | 82 | ||
88 | static int max8952_is_enabled(struct regulator_dev *rdev) | 83 | static int max8952_is_enabled(struct regulator_dev *rdev) |
@@ -117,7 +112,7 @@ static int max8952_disable(struct regulator_dev *rdev) | |||
117 | return 0; | 112 | return 0; |
118 | } | 113 | } |
119 | 114 | ||
120 | static int max8952_get_voltage(struct regulator_dev *rdev) | 115 | static int max8952_get_voltage_sel(struct regulator_dev *rdev) |
121 | { | 116 | { |
122 | struct max8952_data *max8952 = rdev_get_drvdata(rdev); | 117 | struct max8952_data *max8952 = rdev_get_drvdata(rdev); |
123 | u8 vid = 0; | 118 | u8 vid = 0; |
@@ -127,14 +122,13 @@ static int max8952_get_voltage(struct regulator_dev *rdev) | |||
127 | if (max8952->vid1) | 122 | if (max8952->vid1) |
128 | vid += 2; | 123 | vid += 2; |
129 | 124 | ||
130 | return max8952_voltage(max8952, vid); | 125 | return vid; |
131 | } | 126 | } |
132 | 127 | ||
133 | static int max8952_set_voltage(struct regulator_dev *rdev, | 128 | static int max8952_set_voltage_sel(struct regulator_dev *rdev, |
134 | int min_uV, int max_uV, unsigned *selector) | 129 | unsigned selector) |
135 | { | 130 | { |
136 | struct max8952_data *max8952 = rdev_get_drvdata(rdev); | 131 | struct max8952_data *max8952 = rdev_get_drvdata(rdev); |
137 | s8 vid = -1, i; | ||
138 | 132 | ||
139 | if (!gpio_is_valid(max8952->pdata->gpio_vid0) || | 133 | if (!gpio_is_valid(max8952->pdata->gpio_vid0) || |
140 | !gpio_is_valid(max8952->pdata->gpio_vid1)) { | 134 | !gpio_is_valid(max8952->pdata->gpio_vid1)) { |
@@ -142,23 +136,10 @@ static int max8952_set_voltage(struct regulator_dev *rdev, | |||
142 | return -EPERM; | 136 | return -EPERM; |
143 | } | 137 | } |
144 | 138 | ||
145 | for (i = 0; i < MAX8952_NUM_DVS_MODE; i++) { | 139 | max8952->vid0 = selector & 0x1; |
146 | int volt = max8952_voltage(max8952, i); | 140 | max8952->vid1 = (selector >> 1) & 0x1; |
147 | 141 | gpio_set_value(max8952->pdata->gpio_vid0, max8952->vid0); | |
148 | /* Set the voltage as low as possible within the range */ | 142 | gpio_set_value(max8952->pdata->gpio_vid1, max8952->vid1); |
149 | if (volt <= max_uV && volt >= min_uV) | ||
150 | if (vid == -1 || max8952_voltage(max8952, vid) > volt) | ||
151 | vid = i; | ||
152 | } | ||
153 | |||
154 | if (vid >= 0 && vid < MAX8952_NUM_DVS_MODE) { | ||
155 | max8952->vid0 = (vid % 2 == 1); | ||
156 | max8952->vid1 = (((vid >> 1) % 2) == 1); | ||
157 | *selector = vid; | ||
158 | gpio_set_value(max8952->pdata->gpio_vid0, max8952->vid0); | ||
159 | gpio_set_value(max8952->pdata->gpio_vid1, max8952->vid1); | ||
160 | } else | ||
161 | return -EINVAL; | ||
162 | 143 | ||
163 | return 0; | 144 | return 0; |
164 | } | 145 | } |
@@ -168,12 +149,12 @@ static struct regulator_ops max8952_ops = { | |||
168 | .is_enabled = max8952_is_enabled, | 149 | .is_enabled = max8952_is_enabled, |
169 | .enable = max8952_enable, | 150 | .enable = max8952_enable, |
170 | .disable = max8952_disable, | 151 | .disable = max8952_disable, |
171 | .get_voltage = max8952_get_voltage, | 152 | .get_voltage_sel = max8952_get_voltage_sel, |
172 | .set_voltage = max8952_set_voltage, | 153 | .set_voltage_sel = max8952_set_voltage_sel, |
173 | .set_suspend_disable = max8952_disable, | 154 | .set_suspend_disable = max8952_disable, |
174 | }; | 155 | }; |
175 | 156 | ||
176 | static struct regulator_desc regulator = { | 157 | static const struct regulator_desc regulator = { |
177 | .name = "MAX8952_VOUT", | 158 | .name = "MAX8952_VOUT", |
178 | .id = 0, | 159 | .id = 0, |
179 | .n_voltages = MAX8952_NUM_DVS_MODE, | 160 | .n_voltages = MAX8952_NUM_DVS_MODE, |
@@ -187,6 +168,7 @@ static int __devinit max8952_pmic_probe(struct i2c_client *client, | |||
187 | { | 168 | { |
188 | struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); | 169 | struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); |
189 | struct max8952_platform_data *pdata = client->dev.platform_data; | 170 | struct max8952_platform_data *pdata = client->dev.platform_data; |
171 | struct regulator_config config = { }; | ||
190 | struct max8952_data *max8952; | 172 | struct max8952_data *max8952; |
191 | 173 | ||
192 | int ret = 0, err = 0; | 174 | int ret = 0, err = 0; |
@@ -199,7 +181,8 @@ static int __devinit max8952_pmic_probe(struct i2c_client *client, | |||
199 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) | 181 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) |
200 | return -EIO; | 182 | return -EIO; |
201 | 183 | ||
202 | max8952 = kzalloc(sizeof(struct max8952_data), GFP_KERNEL); | 184 | max8952 = devm_kzalloc(&client->dev, sizeof(struct max8952_data), |
185 | GFP_KERNEL); | ||
203 | if (!max8952) | 186 | if (!max8952) |
204 | return -ENOMEM; | 187 | return -ENOMEM; |
205 | 188 | ||
@@ -207,18 +190,21 @@ static int __devinit max8952_pmic_probe(struct i2c_client *client, | |||
207 | max8952->dev = &client->dev; | 190 | max8952->dev = &client->dev; |
208 | max8952->pdata = pdata; | 191 | max8952->pdata = pdata; |
209 | 192 | ||
210 | max8952->rdev = regulator_register(®ulator, max8952->dev, | 193 | config.dev = max8952->dev; |
211 | &pdata->reg_data, max8952, NULL); | 194 | config.init_data = &pdata->reg_data; |
195 | config.driver_data = max8952; | ||
196 | |||
197 | max8952->rdev = regulator_register(®ulator, &config); | ||
212 | 198 | ||
213 | if (IS_ERR(max8952->rdev)) { | 199 | if (IS_ERR(max8952->rdev)) { |
214 | ret = PTR_ERR(max8952->rdev); | 200 | ret = PTR_ERR(max8952->rdev); |
215 | dev_err(max8952->dev, "regulator init failed (%d)\n", ret); | 201 | dev_err(max8952->dev, "regulator init failed (%d)\n", ret); |
216 | goto err_reg; | 202 | return ret; |
217 | } | 203 | } |
218 | 204 | ||
219 | max8952->en = !!(pdata->reg_data.constraints.boot_on); | 205 | max8952->en = !!(pdata->reg_data.constraints.boot_on); |
220 | max8952->vid0 = (pdata->default_mode % 2) == 1; | 206 | max8952->vid0 = pdata->default_mode & 0x1; |
221 | max8952->vid1 = ((pdata->default_mode >> 1) % 2) == 1; | 207 | max8952->vid1 = (pdata->default_mode >> 1) & 0x1; |
222 | 208 | ||
223 | if (gpio_is_valid(pdata->gpio_en)) { | 209 | if (gpio_is_valid(pdata->gpio_en)) { |
224 | if (!gpio_request(pdata->gpio_en, "MAX8952 EN")) | 210 | if (!gpio_request(pdata->gpio_en, "MAX8952 EN")) |
@@ -241,13 +227,13 @@ static int __devinit max8952_pmic_probe(struct i2c_client *client, | |||
241 | gpio_is_valid(pdata->gpio_vid1)) { | 227 | gpio_is_valid(pdata->gpio_vid1)) { |
242 | if (!gpio_request(pdata->gpio_vid0, "MAX8952 VID0")) | 228 | if (!gpio_request(pdata->gpio_vid0, "MAX8952 VID0")) |
243 | gpio_direction_output(pdata->gpio_vid0, | 229 | gpio_direction_output(pdata->gpio_vid0, |
244 | (pdata->default_mode) % 2); | 230 | (pdata->default_mode) & 0x1); |
245 | else | 231 | else |
246 | err = 1; | 232 | err = 1; |
247 | 233 | ||
248 | if (!gpio_request(pdata->gpio_vid1, "MAX8952 VID1")) | 234 | if (!gpio_request(pdata->gpio_vid1, "MAX8952 VID1")) |
249 | gpio_direction_output(pdata->gpio_vid1, | 235 | gpio_direction_output(pdata->gpio_vid1, |
250 | (pdata->default_mode >> 1) % 2); | 236 | (pdata->default_mode >> 1) & 0x1); |
251 | else { | 237 | else { |
252 | if (!err) | 238 | if (!err) |
253 | gpio_free(pdata->gpio_vid0); | 239 | gpio_free(pdata->gpio_vid0); |
@@ -310,10 +296,6 @@ static int __devinit max8952_pmic_probe(struct i2c_client *client, | |||
310 | i2c_set_clientdata(client, max8952); | 296 | i2c_set_clientdata(client, max8952); |
311 | 297 | ||
312 | return 0; | 298 | return 0; |
313 | |||
314 | err_reg: | ||
315 | kfree(max8952); | ||
316 | return ret; | ||
317 | } | 299 | } |
318 | 300 | ||
319 | static int __devexit max8952_pmic_remove(struct i2c_client *client) | 301 | static int __devexit max8952_pmic_remove(struct i2c_client *client) |
@@ -327,8 +309,6 @@ static int __devexit max8952_pmic_remove(struct i2c_client *client) | |||
327 | gpio_free(pdata->gpio_vid0); | 309 | gpio_free(pdata->gpio_vid0); |
328 | gpio_free(pdata->gpio_vid1); | 310 | gpio_free(pdata->gpio_vid1); |
329 | gpio_free(pdata->gpio_en); | 311 | gpio_free(pdata->gpio_en); |
330 | |||
331 | kfree(max8952); | ||
332 | return 0; | 312 | return 0; |
333 | } | 313 | } |
334 | 314 | ||
diff --git a/drivers/regulator/max8997.c b/drivers/regulator/max8997.c index 17a58c56eebf..704cd49ef375 100644 --- a/drivers/regulator/max8997.c +++ b/drivers/regulator/max8997.c | |||
@@ -22,7 +22,6 @@ | |||
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <linux/bug.h> | 24 | #include <linux/bug.h> |
25 | #include <linux/delay.h> | ||
26 | #include <linux/err.h> | 25 | #include <linux/err.h> |
27 | #include <linux/gpio.h> | 26 | #include <linux/gpio.h> |
28 | #include <linux/slab.h> | 27 | #include <linux/slab.h> |
@@ -68,29 +67,28 @@ struct voltage_map_desc { | |||
68 | int min; | 67 | int min; |
69 | int max; | 68 | int max; |
70 | int step; | 69 | int step; |
71 | unsigned int n_bits; | ||
72 | }; | 70 | }; |
73 | 71 | ||
74 | /* Voltage maps in mV */ | 72 | /* Voltage maps in mV */ |
75 | static const struct voltage_map_desc ldo_voltage_map_desc = { | 73 | static const struct voltage_map_desc ldo_voltage_map_desc = { |
76 | .min = 800, .max = 3950, .step = 50, .n_bits = 6, | 74 | .min = 800, .max = 3950, .step = 50, |
77 | }; /* LDO1 ~ 18, 21 all */ | 75 | }; /* LDO1 ~ 18, 21 all */ |
78 | 76 | ||
79 | static const struct voltage_map_desc buck1245_voltage_map_desc = { | 77 | static const struct voltage_map_desc buck1245_voltage_map_desc = { |
80 | .min = 650, .max = 2225, .step = 25, .n_bits = 6, | 78 | .min = 650, .max = 2225, .step = 25, |
81 | }; /* Buck1, 2, 4, 5 */ | 79 | }; /* Buck1, 2, 4, 5 */ |
82 | 80 | ||
83 | static const struct voltage_map_desc buck37_voltage_map_desc = { | 81 | static const struct voltage_map_desc buck37_voltage_map_desc = { |
84 | .min = 750, .max = 3900, .step = 50, .n_bits = 6, | 82 | .min = 750, .max = 3900, .step = 50, |
85 | }; /* Buck3, 7 */ | 83 | }; /* Buck3, 7 */ |
86 | 84 | ||
87 | /* current map in mA */ | 85 | /* current map in mA */ |
88 | static const struct voltage_map_desc charger_current_map_desc = { | 86 | static const struct voltage_map_desc charger_current_map_desc = { |
89 | .min = 200, .max = 950, .step = 50, .n_bits = 4, | 87 | .min = 200, .max = 950, .step = 50, |
90 | }; | 88 | }; |
91 | 89 | ||
92 | static const struct voltage_map_desc topoff_current_map_desc = { | 90 | static const struct voltage_map_desc topoff_current_map_desc = { |
93 | .min = 50, .max = 200, .step = 10, .n_bits = 4, | 91 | .min = 50, .max = 200, .step = 10, |
94 | }; | 92 | }; |
95 | 93 | ||
96 | static const struct voltage_map_desc *reg_voltage_map[] = { | 94 | static const struct voltage_map_desc *reg_voltage_map[] = { |
@@ -279,9 +277,7 @@ static int max8997_reg_is_enabled(struct regulator_dev *rdev) | |||
279 | u8 val; | 277 | u8 val; |
280 | 278 | ||
281 | ret = max8997_get_enable_register(rdev, ®, &mask, &pattern); | 279 | ret = max8997_get_enable_register(rdev, ®, &mask, &pattern); |
282 | if (ret == -EINVAL) | 280 | if (ret) |
283 | return 1; /* "not controllable" */ | ||
284 | else if (ret) | ||
285 | return ret; | 281 | return ret; |
286 | 282 | ||
287 | ret = max8997_read_reg(i2c, reg, &val); | 283 | ret = max8997_read_reg(i2c, reg, &val); |
@@ -320,6 +316,7 @@ static int max8997_reg_disable(struct regulator_dev *rdev) | |||
320 | static int max8997_get_voltage_register(struct regulator_dev *rdev, | 316 | static int max8997_get_voltage_register(struct regulator_dev *rdev, |
321 | int *_reg, int *_shift, int *_mask) | 317 | int *_reg, int *_shift, int *_mask) |
322 | { | 318 | { |
319 | struct max8997_data *max8997 = rdev_get_drvdata(rdev); | ||
323 | int rid = rdev_get_id(rdev); | 320 | int rid = rdev_get_id(rdev); |
324 | int reg, shift = 0, mask = 0x3f; | 321 | int reg, shift = 0, mask = 0x3f; |
325 | 322 | ||
@@ -329,9 +326,13 @@ static int max8997_get_voltage_register(struct regulator_dev *rdev, | |||
329 | break; | 326 | break; |
330 | case MAX8997_BUCK1: | 327 | case MAX8997_BUCK1: |
331 | reg = MAX8997_REG_BUCK1DVS1; | 328 | reg = MAX8997_REG_BUCK1DVS1; |
329 | if (max8997->buck1_gpiodvs) | ||
330 | reg += max8997->buck125_gpioindex; | ||
332 | break; | 331 | break; |
333 | case MAX8997_BUCK2: | 332 | case MAX8997_BUCK2: |
334 | reg = MAX8997_REG_BUCK2DVS1; | 333 | reg = MAX8997_REG_BUCK2DVS1; |
334 | if (max8997->buck2_gpiodvs) | ||
335 | reg += max8997->buck125_gpioindex; | ||
335 | break; | 336 | break; |
336 | case MAX8997_BUCK3: | 337 | case MAX8997_BUCK3: |
337 | reg = MAX8997_REG_BUCK3DVS; | 338 | reg = MAX8997_REG_BUCK3DVS; |
@@ -341,6 +342,8 @@ static int max8997_get_voltage_register(struct regulator_dev *rdev, | |||
341 | break; | 342 | break; |
342 | case MAX8997_BUCK5: | 343 | case MAX8997_BUCK5: |
343 | reg = MAX8997_REG_BUCK5DVS1; | 344 | reg = MAX8997_REG_BUCK5DVS1; |
345 | if (max8997->buck5_gpiodvs) | ||
346 | reg += max8997->buck125_gpioindex; | ||
344 | break; | 347 | break; |
345 | case MAX8997_BUCK7: | 348 | case MAX8997_BUCK7: |
346 | reg = MAX8997_REG_BUCK7DVS; | 349 | reg = MAX8997_REG_BUCK7DVS; |
@@ -376,23 +379,17 @@ static int max8997_get_voltage_register(struct regulator_dev *rdev, | |||
376 | return 0; | 379 | return 0; |
377 | } | 380 | } |
378 | 381 | ||
379 | static int max8997_get_voltage(struct regulator_dev *rdev) | 382 | static int max8997_get_voltage_sel(struct regulator_dev *rdev) |
380 | { | 383 | { |
381 | struct max8997_data *max8997 = rdev_get_drvdata(rdev); | 384 | struct max8997_data *max8997 = rdev_get_drvdata(rdev); |
382 | struct i2c_client *i2c = max8997->iodev->i2c; | 385 | struct i2c_client *i2c = max8997->iodev->i2c; |
383 | int reg, shift, mask, ret; | 386 | int reg, shift, mask, ret; |
384 | int rid = rdev_get_id(rdev); | ||
385 | u8 val; | 387 | u8 val; |
386 | 388 | ||
387 | ret = max8997_get_voltage_register(rdev, ®, &shift, &mask); | 389 | ret = max8997_get_voltage_register(rdev, ®, &shift, &mask); |
388 | if (ret) | 390 | if (ret) |
389 | return ret; | 391 | return ret; |
390 | 392 | ||
391 | if ((rid == MAX8997_BUCK1 && max8997->buck1_gpiodvs) || | ||
392 | (rid == MAX8997_BUCK2 && max8997->buck2_gpiodvs) || | ||
393 | (rid == MAX8997_BUCK5 && max8997->buck5_gpiodvs)) | ||
394 | reg += max8997->buck125_gpioindex; | ||
395 | |||
396 | ret = max8997_read_reg(i2c, reg, &val); | 393 | ret = max8997_read_reg(i2c, reg, &val); |
397 | if (ret) | 394 | if (ret) |
398 | return ret; | 395 | return ret; |
@@ -400,22 +397,14 @@ static int max8997_get_voltage(struct regulator_dev *rdev) | |||
400 | val >>= shift; | 397 | val >>= shift; |
401 | val &= mask; | 398 | val &= mask; |
402 | 399 | ||
403 | if (rdev->desc && rdev->desc->ops && rdev->desc->ops->list_voltage) | 400 | return val; |
404 | return rdev->desc->ops->list_voltage(rdev, val); | ||
405 | |||
406 | /* | ||
407 | * max8997_list_voltage returns value for any rdev with voltage_map, | ||
408 | * which works for "CHARGER" and "CHARGER TOPOFF" that do not have | ||
409 | * list_voltage ops (they are current regulators). | ||
410 | */ | ||
411 | return max8997_list_voltage(rdev, val); | ||
412 | } | 401 | } |
413 | 402 | ||
414 | static inline int max8997_get_voltage_proper_val( | 403 | static inline int max8997_get_voltage_proper_val( |
415 | const struct voltage_map_desc *desc, | 404 | const struct voltage_map_desc *desc, |
416 | int min_vol, int max_vol) | 405 | int min_vol, int max_vol) |
417 | { | 406 | { |
418 | int i = 0; | 407 | int i; |
419 | 408 | ||
420 | if (desc == NULL) | 409 | if (desc == NULL) |
421 | return -EINVAL; | 410 | return -EINVAL; |
@@ -423,14 +412,12 @@ static inline int max8997_get_voltage_proper_val( | |||
423 | if (max_vol < desc->min || min_vol > desc->max) | 412 | if (max_vol < desc->min || min_vol > desc->max) |
424 | return -EINVAL; | 413 | return -EINVAL; |
425 | 414 | ||
426 | while (desc->min + desc->step * i < min_vol && | 415 | if (min_vol < desc->min) |
427 | desc->min + desc->step * i < desc->max) | 416 | min_vol = desc->min; |
428 | i++; | ||
429 | 417 | ||
430 | if (desc->min + desc->step * i > max_vol) | 418 | i = DIV_ROUND_UP(min_vol - desc->min, desc->step); |
431 | return -EINVAL; | ||
432 | 419 | ||
433 | if (i >= (1 << desc->n_bits)) | 420 | if (desc->min + desc->step * i > max_vol) |
434 | return -EINVAL; | 421 | return -EINVAL; |
435 | 422 | ||
436 | return i; | 423 | return i; |
@@ -499,9 +486,7 @@ static int max8997_set_voltage_ldobuck(struct regulator_dev *rdev, | |||
499 | int min_vol = min_uV / 1000, max_vol = max_uV / 1000; | 486 | int min_vol = min_uV / 1000, max_vol = max_uV / 1000; |
500 | const struct voltage_map_desc *desc; | 487 | const struct voltage_map_desc *desc; |
501 | int rid = rdev_get_id(rdev); | 488 | int rid = rdev_get_id(rdev); |
502 | int reg, shift = 0, mask, ret; | 489 | int i, reg, shift, mask, ret; |
503 | int i; | ||
504 | u8 org; | ||
505 | 490 | ||
506 | switch (rid) { | 491 | switch (rid) { |
507 | case MAX8997_LDO1 ... MAX8997_LDO21: | 492 | case MAX8997_LDO1 ... MAX8997_LDO21: |
@@ -530,21 +515,50 @@ static int max8997_set_voltage_ldobuck(struct regulator_dev *rdev, | |||
530 | if (ret) | 515 | if (ret) |
531 | return ret; | 516 | return ret; |
532 | 517 | ||
533 | max8997_read_reg(i2c, reg, &org); | ||
534 | org = (org & mask) >> shift; | ||
535 | |||
536 | ret = max8997_update_reg(i2c, reg, i << shift, mask << shift); | 518 | ret = max8997_update_reg(i2c, reg, i << shift, mask << shift); |
537 | *selector = i; | 519 | *selector = i; |
538 | 520 | ||
539 | if (rid == MAX8997_BUCK1 || rid == MAX8997_BUCK2 || | 521 | return ret; |
540 | rid == MAX8997_BUCK4 || rid == MAX8997_BUCK5) { | 522 | } |
541 | /* If the voltage is increasing */ | 523 | |
542 | if (org < i) | 524 | static int max8997_set_voltage_ldobuck_time_sel(struct regulator_dev *rdev, |
543 | udelay(DIV_ROUND_UP(desc->step * (i - org), | 525 | unsigned int old_selector, |
544 | max8997->ramp_delay)); | 526 | unsigned int new_selector) |
527 | { | ||
528 | struct max8997_data *max8997 = rdev_get_drvdata(rdev); | ||
529 | int rid = rdev_get_id(rdev); | ||
530 | const struct voltage_map_desc *desc = reg_voltage_map[rid]; | ||
531 | |||
532 | /* Delay is required only if the voltage is increasing */ | ||
533 | if (old_selector >= new_selector) | ||
534 | return 0; | ||
535 | |||
536 | /* No need to delay if gpio_dvs_mode */ | ||
537 | switch (rid) { | ||
538 | case MAX8997_BUCK1: | ||
539 | if (max8997->buck1_gpiodvs) | ||
540 | return 0; | ||
541 | break; | ||
542 | case MAX8997_BUCK2: | ||
543 | if (max8997->buck2_gpiodvs) | ||
544 | return 0; | ||
545 | break; | ||
546 | case MAX8997_BUCK5: | ||
547 | if (max8997->buck5_gpiodvs) | ||
548 | return 0; | ||
549 | break; | ||
545 | } | 550 | } |
546 | 551 | ||
547 | return ret; | 552 | switch (rid) { |
553 | case MAX8997_BUCK1: | ||
554 | case MAX8997_BUCK2: | ||
555 | case MAX8997_BUCK4: | ||
556 | case MAX8997_BUCK5: | ||
557 | return DIV_ROUND_UP(desc->step * (new_selector - old_selector), | ||
558 | max8997->ramp_delay); | ||
559 | } | ||
560 | |||
561 | return 0; | ||
548 | } | 562 | } |
549 | 563 | ||
550 | /* | 564 | /* |
@@ -751,11 +765,6 @@ static int max8997_set_voltage_safeout(struct regulator_dev *rdev, | |||
751 | return ret; | 765 | return ret; |
752 | } | 766 | } |
753 | 767 | ||
754 | static int max8997_reg_enable_suspend(struct regulator_dev *rdev) | ||
755 | { | ||
756 | return 0; | ||
757 | } | ||
758 | |||
759 | static int max8997_reg_disable_suspend(struct regulator_dev *rdev) | 768 | static int max8997_reg_disable_suspend(struct regulator_dev *rdev) |
760 | { | 769 | { |
761 | struct max8997_data *max8997 = rdev_get_drvdata(rdev); | 770 | struct max8997_data *max8997 = rdev_get_drvdata(rdev); |
@@ -788,9 +797,9 @@ static struct regulator_ops max8997_ldo_ops = { | |||
788 | .is_enabled = max8997_reg_is_enabled, | 797 | .is_enabled = max8997_reg_is_enabled, |
789 | .enable = max8997_reg_enable, | 798 | .enable = max8997_reg_enable, |
790 | .disable = max8997_reg_disable, | 799 | .disable = max8997_reg_disable, |
791 | .get_voltage = max8997_get_voltage, | 800 | .get_voltage_sel = max8997_get_voltage_sel, |
792 | .set_voltage = max8997_set_voltage_ldobuck, | 801 | .set_voltage = max8997_set_voltage_ldobuck, |
793 | .set_suspend_enable = max8997_reg_enable_suspend, | 802 | .set_voltage_time_sel = max8997_set_voltage_ldobuck_time_sel, |
794 | .set_suspend_disable = max8997_reg_disable_suspend, | 803 | .set_suspend_disable = max8997_reg_disable_suspend, |
795 | }; | 804 | }; |
796 | 805 | ||
@@ -799,9 +808,9 @@ static struct regulator_ops max8997_buck_ops = { | |||
799 | .is_enabled = max8997_reg_is_enabled, | 808 | .is_enabled = max8997_reg_is_enabled, |
800 | .enable = max8997_reg_enable, | 809 | .enable = max8997_reg_enable, |
801 | .disable = max8997_reg_disable, | 810 | .disable = max8997_reg_disable, |
802 | .get_voltage = max8997_get_voltage, | 811 | .get_voltage_sel = max8997_get_voltage_sel, |
803 | .set_voltage = max8997_set_voltage_buck, | 812 | .set_voltage = max8997_set_voltage_buck, |
804 | .set_suspend_enable = max8997_reg_enable_suspend, | 813 | .set_voltage_time_sel = max8997_set_voltage_ldobuck_time_sel, |
805 | .set_suspend_disable = max8997_reg_disable_suspend, | 814 | .set_suspend_disable = max8997_reg_disable_suspend, |
806 | }; | 815 | }; |
807 | 816 | ||
@@ -810,7 +819,6 @@ static struct regulator_ops max8997_fixedvolt_ops = { | |||
810 | .is_enabled = max8997_reg_is_enabled, | 819 | .is_enabled = max8997_reg_is_enabled, |
811 | .enable = max8997_reg_enable, | 820 | .enable = max8997_reg_enable, |
812 | .disable = max8997_reg_disable, | 821 | .disable = max8997_reg_disable, |
813 | .set_suspend_enable = max8997_reg_enable_suspend, | ||
814 | .set_suspend_disable = max8997_reg_disable_suspend, | 822 | .set_suspend_disable = max8997_reg_disable_suspend, |
815 | }; | 823 | }; |
816 | 824 | ||
@@ -819,144 +827,117 @@ static struct regulator_ops max8997_safeout_ops = { | |||
819 | .is_enabled = max8997_reg_is_enabled, | 827 | .is_enabled = max8997_reg_is_enabled, |
820 | .enable = max8997_reg_enable, | 828 | .enable = max8997_reg_enable, |
821 | .disable = max8997_reg_disable, | 829 | .disable = max8997_reg_disable, |
822 | .get_voltage = max8997_get_voltage, | 830 | .get_voltage_sel = max8997_get_voltage_sel, |
823 | .set_voltage = max8997_set_voltage_safeout, | 831 | .set_voltage = max8997_set_voltage_safeout, |
824 | .set_suspend_enable = max8997_reg_enable_suspend, | ||
825 | .set_suspend_disable = max8997_reg_disable_suspend, | 832 | .set_suspend_disable = max8997_reg_disable_suspend, |
826 | }; | 833 | }; |
827 | 834 | ||
828 | static struct regulator_ops max8997_fixedstate_ops = { | 835 | static struct regulator_ops max8997_fixedstate_ops = { |
829 | .list_voltage = max8997_list_voltage_charger_cv, | 836 | .list_voltage = max8997_list_voltage_charger_cv, |
830 | .get_voltage = max8997_get_voltage, | 837 | .get_voltage_sel = max8997_get_voltage_sel, |
831 | .set_voltage = max8997_set_voltage_charger_cv, | 838 | .set_voltage = max8997_set_voltage_charger_cv, |
832 | }; | 839 | }; |
833 | 840 | ||
834 | static int max8997_set_voltage_ldobuck_wrap(struct regulator_dev *rdev, | 841 | static int max8997_set_current_limit(struct regulator_dev *rdev, |
835 | int min_uV, int max_uV) | 842 | int min_uA, int max_uA) |
836 | { | 843 | { |
837 | unsigned dummy; | 844 | unsigned dummy; |
845 | int rid = rdev_get_id(rdev); | ||
846 | |||
847 | if (rid != MAX8997_CHARGER && rid != MAX8997_CHARGER_TOPOFF) | ||
848 | return -EINVAL; | ||
838 | 849 | ||
839 | return max8997_set_voltage_ldobuck(rdev, min_uV, max_uV, &dummy); | 850 | /* Reuse max8997_set_voltage_ldobuck to set current_limit. */ |
851 | return max8997_set_voltage_ldobuck(rdev, min_uA, max_uA, &dummy); | ||
840 | } | 852 | } |
841 | 853 | ||
854 | static int max8997_get_current_limit(struct regulator_dev *rdev) | ||
855 | { | ||
856 | int sel, rid = rdev_get_id(rdev); | ||
857 | |||
858 | if (rid != MAX8997_CHARGER && rid != MAX8997_CHARGER_TOPOFF) | ||
859 | return -EINVAL; | ||
860 | |||
861 | sel = max8997_get_voltage_sel(rdev); | ||
862 | if (sel < 0) | ||
863 | return sel; | ||
864 | |||
865 | /* Reuse max8997_list_voltage to get current_limit. */ | ||
866 | return max8997_list_voltage(rdev, sel); | ||
867 | } | ||
842 | 868 | ||
843 | static struct regulator_ops max8997_charger_ops = { | 869 | static struct regulator_ops max8997_charger_ops = { |
844 | .is_enabled = max8997_reg_is_enabled, | 870 | .is_enabled = max8997_reg_is_enabled, |
845 | .enable = max8997_reg_enable, | 871 | .enable = max8997_reg_enable, |
846 | .disable = max8997_reg_disable, | 872 | .disable = max8997_reg_disable, |
847 | .get_current_limit = max8997_get_voltage, | 873 | .get_current_limit = max8997_get_current_limit, |
848 | .set_current_limit = max8997_set_voltage_ldobuck_wrap, | 874 | .set_current_limit = max8997_set_current_limit, |
849 | }; | 875 | }; |
850 | 876 | ||
851 | static struct regulator_ops max8997_charger_fixedstate_ops = { | 877 | static struct regulator_ops max8997_charger_fixedstate_ops = { |
852 | .is_enabled = max8997_reg_is_enabled, | 878 | .get_current_limit = max8997_get_current_limit, |
853 | .get_current_limit = max8997_get_voltage, | 879 | .set_current_limit = max8997_set_current_limit, |
854 | .set_current_limit = max8997_set_voltage_ldobuck_wrap, | ||
855 | }; | 880 | }; |
856 | 881 | ||
857 | #define regulator_desc_ldo(num) { \ | 882 | #define MAX8997_VOLTAGE_REGULATOR(_name, _ops) {\ |
858 | .name = "LDO"#num, \ | 883 | .name = #_name, \ |
859 | .id = MAX8997_LDO##num, \ | 884 | .id = MAX8997_##_name, \ |
860 | .ops = &max8997_ldo_ops, \ | 885 | .ops = &_ops, \ |
861 | .type = REGULATOR_VOLTAGE, \ | 886 | .type = REGULATOR_VOLTAGE, \ |
862 | .owner = THIS_MODULE, \ | 887 | .owner = THIS_MODULE, \ |
863 | } | 888 | } |
864 | #define regulator_desc_buck(num) { \ | 889 | |
865 | .name = "BUCK"#num, \ | 890 | #define MAX8997_CURRENT_REGULATOR(_name, _ops) {\ |
866 | .id = MAX8997_BUCK##num, \ | 891 | .name = #_name, \ |
867 | .ops = &max8997_buck_ops, \ | 892 | .id = MAX8997_##_name, \ |
868 | .type = REGULATOR_VOLTAGE, \ | 893 | .ops = &_ops, \ |
894 | .type = REGULATOR_CURRENT, \ | ||
869 | .owner = THIS_MODULE, \ | 895 | .owner = THIS_MODULE, \ |
870 | } | 896 | } |
871 | 897 | ||
872 | static struct regulator_desc regulators[] = { | 898 | static struct regulator_desc regulators[] = { |
873 | regulator_desc_ldo(1), | 899 | MAX8997_VOLTAGE_REGULATOR(LDO1, max8997_ldo_ops), |
874 | regulator_desc_ldo(2), | 900 | MAX8997_VOLTAGE_REGULATOR(LDO2, max8997_ldo_ops), |
875 | regulator_desc_ldo(3), | 901 | MAX8997_VOLTAGE_REGULATOR(LDO3, max8997_ldo_ops), |
876 | regulator_desc_ldo(4), | 902 | MAX8997_VOLTAGE_REGULATOR(LDO4, max8997_ldo_ops), |
877 | regulator_desc_ldo(5), | 903 | MAX8997_VOLTAGE_REGULATOR(LDO5, max8997_ldo_ops), |
878 | regulator_desc_ldo(6), | 904 | MAX8997_VOLTAGE_REGULATOR(LDO6, max8997_ldo_ops), |
879 | regulator_desc_ldo(7), | 905 | MAX8997_VOLTAGE_REGULATOR(LDO7, max8997_ldo_ops), |
880 | regulator_desc_ldo(8), | 906 | MAX8997_VOLTAGE_REGULATOR(LDO8, max8997_ldo_ops), |
881 | regulator_desc_ldo(9), | 907 | MAX8997_VOLTAGE_REGULATOR(LDO9, max8997_ldo_ops), |
882 | regulator_desc_ldo(10), | 908 | MAX8997_VOLTAGE_REGULATOR(LDO10, max8997_ldo_ops), |
883 | regulator_desc_ldo(11), | 909 | MAX8997_VOLTAGE_REGULATOR(LDO11, max8997_ldo_ops), |
884 | regulator_desc_ldo(12), | 910 | MAX8997_VOLTAGE_REGULATOR(LDO12, max8997_ldo_ops), |
885 | regulator_desc_ldo(13), | 911 | MAX8997_VOLTAGE_REGULATOR(LDO13, max8997_ldo_ops), |
886 | regulator_desc_ldo(14), | 912 | MAX8997_VOLTAGE_REGULATOR(LDO14, max8997_ldo_ops), |
887 | regulator_desc_ldo(15), | 913 | MAX8997_VOLTAGE_REGULATOR(LDO15, max8997_ldo_ops), |
888 | regulator_desc_ldo(16), | 914 | MAX8997_VOLTAGE_REGULATOR(LDO16, max8997_ldo_ops), |
889 | regulator_desc_ldo(17), | 915 | MAX8997_VOLTAGE_REGULATOR(LDO17, max8997_ldo_ops), |
890 | regulator_desc_ldo(18), | 916 | MAX8997_VOLTAGE_REGULATOR(LDO18, max8997_ldo_ops), |
891 | regulator_desc_ldo(21), | 917 | MAX8997_VOLTAGE_REGULATOR(LDO21, max8997_ldo_ops), |
892 | regulator_desc_buck(1), | 918 | MAX8997_VOLTAGE_REGULATOR(BUCK1, max8997_buck_ops), |
893 | regulator_desc_buck(2), | 919 | MAX8997_VOLTAGE_REGULATOR(BUCK2, max8997_buck_ops), |
894 | regulator_desc_buck(3), | 920 | MAX8997_VOLTAGE_REGULATOR(BUCK3, max8997_buck_ops), |
895 | regulator_desc_buck(4), | 921 | MAX8997_VOLTAGE_REGULATOR(BUCK4, max8997_buck_ops), |
896 | regulator_desc_buck(5), | 922 | MAX8997_VOLTAGE_REGULATOR(BUCK5, max8997_buck_ops), |
897 | { | 923 | MAX8997_VOLTAGE_REGULATOR(BUCK6, max8997_fixedvolt_ops), |
898 | .name = "BUCK6", | 924 | MAX8997_VOLTAGE_REGULATOR(BUCK7, max8997_buck_ops), |
899 | .id = MAX8997_BUCK6, | 925 | MAX8997_VOLTAGE_REGULATOR(EN32KHZ_AP, max8997_fixedvolt_ops), |
900 | .ops = &max8997_fixedvolt_ops, | 926 | MAX8997_VOLTAGE_REGULATOR(EN32KHZ_CP, max8997_fixedvolt_ops), |
901 | .type = REGULATOR_VOLTAGE, | 927 | MAX8997_VOLTAGE_REGULATOR(ENVICHG, max8997_fixedvolt_ops), |
902 | .owner = THIS_MODULE, | 928 | MAX8997_VOLTAGE_REGULATOR(ESAFEOUT1, max8997_safeout_ops), |
903 | }, | 929 | MAX8997_VOLTAGE_REGULATOR(ESAFEOUT2, max8997_safeout_ops), |
904 | regulator_desc_buck(7), | 930 | MAX8997_VOLTAGE_REGULATOR(CHARGER_CV, max8997_fixedstate_ops), |
905 | { | 931 | MAX8997_CURRENT_REGULATOR(CHARGER, max8997_charger_ops), |
906 | .name = "EN32KHz_AP", | 932 | MAX8997_CURRENT_REGULATOR(CHARGER_TOPOFF, |
907 | .id = MAX8997_EN32KHZ_AP, | 933 | max8997_charger_fixedstate_ops), |
908 | .ops = &max8997_fixedvolt_ops, | ||
909 | .type = REGULATOR_VOLTAGE, | ||
910 | .owner = THIS_MODULE, | ||
911 | }, { | ||
912 | .name = "EN32KHz_CP", | ||
913 | .id = MAX8997_EN32KHZ_CP, | ||
914 | .ops = &max8997_fixedvolt_ops, | ||
915 | .type = REGULATOR_VOLTAGE, | ||
916 | .owner = THIS_MODULE, | ||
917 | }, { | ||
918 | .name = "ENVICHG", | ||
919 | .id = MAX8997_ENVICHG, | ||
920 | .ops = &max8997_fixedvolt_ops, | ||
921 | .type = REGULATOR_VOLTAGE, | ||
922 | .owner = THIS_MODULE, | ||
923 | }, { | ||
924 | .name = "ESAFEOUT1", | ||
925 | .id = MAX8997_ESAFEOUT1, | ||
926 | .ops = &max8997_safeout_ops, | ||
927 | .type = REGULATOR_VOLTAGE, | ||
928 | .owner = THIS_MODULE, | ||
929 | }, { | ||
930 | .name = "ESAFEOUT2", | ||
931 | .id = MAX8997_ESAFEOUT2, | ||
932 | .ops = &max8997_safeout_ops, | ||
933 | .type = REGULATOR_VOLTAGE, | ||
934 | .owner = THIS_MODULE, | ||
935 | }, { | ||
936 | .name = "CHARGER_CV", | ||
937 | .id = MAX8997_CHARGER_CV, | ||
938 | .ops = &max8997_fixedstate_ops, | ||
939 | .type = REGULATOR_VOLTAGE, | ||
940 | .owner = THIS_MODULE, | ||
941 | }, { | ||
942 | .name = "CHARGER", | ||
943 | .id = MAX8997_CHARGER, | ||
944 | .ops = &max8997_charger_ops, | ||
945 | .type = REGULATOR_CURRENT, | ||
946 | .owner = THIS_MODULE, | ||
947 | }, { | ||
948 | .name = "CHARGER_TOPOFF", | ||
949 | .id = MAX8997_CHARGER_TOPOFF, | ||
950 | .ops = &max8997_charger_fixedstate_ops, | ||
951 | .type = REGULATOR_CURRENT, | ||
952 | .owner = THIS_MODULE, | ||
953 | }, | ||
954 | }; | 934 | }; |
955 | 935 | ||
956 | static __devinit int max8997_pmic_probe(struct platform_device *pdev) | 936 | static __devinit int max8997_pmic_probe(struct platform_device *pdev) |
957 | { | 937 | { |
958 | struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent); | 938 | struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent); |
959 | struct max8997_platform_data *pdata = dev_get_platdata(iodev->dev); | 939 | struct max8997_platform_data *pdata = dev_get_platdata(iodev->dev); |
940 | struct regulator_config config = { }; | ||
960 | struct regulator_dev **rdev; | 941 | struct regulator_dev **rdev; |
961 | struct max8997_data *max8997; | 942 | struct max8997_data *max8997; |
962 | struct i2c_client *i2c; | 943 | struct i2c_client *i2c; |
@@ -968,16 +949,15 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) | |||
968 | return -ENODEV; | 949 | return -ENODEV; |
969 | } | 950 | } |
970 | 951 | ||
971 | max8997 = kzalloc(sizeof(struct max8997_data), GFP_KERNEL); | 952 | max8997 = devm_kzalloc(&pdev->dev, sizeof(struct max8997_data), |
953 | GFP_KERNEL); | ||
972 | if (!max8997) | 954 | if (!max8997) |
973 | return -ENOMEM; | 955 | return -ENOMEM; |
974 | 956 | ||
975 | size = sizeof(struct regulator_dev *) * pdata->num_regulators; | 957 | size = sizeof(struct regulator_dev *) * pdata->num_regulators; |
976 | max8997->rdev = kzalloc(size, GFP_KERNEL); | 958 | max8997->rdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); |
977 | if (!max8997->rdev) { | 959 | if (!max8997->rdev) |
978 | kfree(max8997); | ||
979 | return -ENOMEM; | 960 | return -ENOMEM; |
980 | } | ||
981 | 961 | ||
982 | rdev = max8997->rdev; | 962 | rdev = max8997->rdev; |
983 | max8997->dev = &pdev->dev; | 963 | max8997->dev = &pdev->dev; |
@@ -1001,7 +981,7 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) | |||
1001 | pdata->buck1_voltage[i] / 1000 + | 981 | pdata->buck1_voltage[i] / 1000 + |
1002 | buck1245_voltage_map_desc.step); | 982 | buck1245_voltage_map_desc.step); |
1003 | if (ret < 0) | 983 | if (ret < 0) |
1004 | goto err_alloc; | 984 | goto err_out; |
1005 | 985 | ||
1006 | max8997->buck2_vol[i] = ret = | 986 | max8997->buck2_vol[i] = ret = |
1007 | max8997_get_voltage_proper_val( | 987 | max8997_get_voltage_proper_val( |
@@ -1010,7 +990,7 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) | |||
1010 | pdata->buck2_voltage[i] / 1000 + | 990 | pdata->buck2_voltage[i] / 1000 + |
1011 | buck1245_voltage_map_desc.step); | 991 | buck1245_voltage_map_desc.step); |
1012 | if (ret < 0) | 992 | if (ret < 0) |
1013 | goto err_alloc; | 993 | goto err_out; |
1014 | 994 | ||
1015 | max8997->buck5_vol[i] = ret = | 995 | max8997->buck5_vol[i] = ret = |
1016 | max8997_get_voltage_proper_val( | 996 | max8997_get_voltage_proper_val( |
@@ -1019,7 +999,7 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) | |||
1019 | pdata->buck5_voltage[i] / 1000 + | 999 | pdata->buck5_voltage[i] / 1000 + |
1020 | buck1245_voltage_map_desc.step); | 1000 | buck1245_voltage_map_desc.step); |
1021 | if (ret < 0) | 1001 | if (ret < 0) |
1022 | goto err_alloc; | 1002 | goto err_out; |
1023 | 1003 | ||
1024 | if (max_buck1 < max8997->buck1_vol[i]) | 1004 | if (max_buck1 < max8997->buck1_vol[i]) |
1025 | max_buck1 = max8997->buck1_vol[i]; | 1005 | max_buck1 = max8997->buck1_vol[i]; |
@@ -1052,7 +1032,7 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) | |||
1052 | !gpio_is_valid(pdata->buck125_gpios[2])) { | 1032 | !gpio_is_valid(pdata->buck125_gpios[2])) { |
1053 | dev_err(&pdev->dev, "GPIO NOT VALID\n"); | 1033 | dev_err(&pdev->dev, "GPIO NOT VALID\n"); |
1054 | ret = -EINVAL; | 1034 | ret = -EINVAL; |
1055 | goto err_alloc; | 1035 | goto err_out; |
1056 | } | 1036 | } |
1057 | 1037 | ||
1058 | ret = gpio_request(pdata->buck125_gpios[0], | 1038 | ret = gpio_request(pdata->buck125_gpios[0], |
@@ -1061,7 +1041,7 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) | |||
1061 | dev_warn(&pdev->dev, "Duplicated gpio request" | 1041 | dev_warn(&pdev->dev, "Duplicated gpio request" |
1062 | " on SET1\n"); | 1042 | " on SET1\n"); |
1063 | else if (ret) | 1043 | else if (ret) |
1064 | goto err_alloc; | 1044 | goto err_out; |
1065 | else | 1045 | else |
1066 | gpio1set = true; | 1046 | gpio1set = true; |
1067 | 1047 | ||
@@ -1073,7 +1053,7 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) | |||
1073 | else if (ret) { | 1053 | else if (ret) { |
1074 | if (gpio1set) | 1054 | if (gpio1set) |
1075 | gpio_free(pdata->buck125_gpios[0]); | 1055 | gpio_free(pdata->buck125_gpios[0]); |
1076 | goto err_alloc; | 1056 | goto err_out; |
1077 | } else | 1057 | } else |
1078 | gpio2set = true; | 1058 | gpio2set = true; |
1079 | 1059 | ||
@@ -1087,7 +1067,7 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) | |||
1087 | gpio_free(pdata->buck125_gpios[0]); | 1067 | gpio_free(pdata->buck125_gpios[0]); |
1088 | if (gpio2set) | 1068 | if (gpio2set) |
1089 | gpio_free(pdata->buck125_gpios[1]); | 1069 | gpio_free(pdata->buck125_gpios[1]); |
1090 | goto err_alloc; | 1070 | goto err_out; |
1091 | } | 1071 | } |
1092 | 1072 | ||
1093 | gpio_direction_output(pdata->buck125_gpios[0], | 1073 | gpio_direction_output(pdata->buck125_gpios[0], |
@@ -1140,8 +1120,11 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) | |||
1140 | else if (id == MAX8997_CHARGER_CV) | 1120 | else if (id == MAX8997_CHARGER_CV) |
1141 | regulators[id].n_voltages = 16; | 1121 | regulators[id].n_voltages = 16; |
1142 | 1122 | ||
1143 | rdev[i] = regulator_register(®ulators[id], max8997->dev, | 1123 | config.dev = max8997->dev; |
1144 | pdata->regulators[i].initdata, max8997, NULL); | 1124 | config.init_data = pdata->regulators[i].initdata; |
1125 | config.driver_data = max8997; | ||
1126 | |||
1127 | rdev[i] = regulator_register(®ulators[id], &config); | ||
1145 | if (IS_ERR(rdev[i])) { | 1128 | if (IS_ERR(rdev[i])) { |
1146 | ret = PTR_ERR(rdev[i]); | 1129 | ret = PTR_ERR(rdev[i]); |
1147 | dev_err(max8997->dev, "regulator init failed for %d\n", | 1130 | dev_err(max8997->dev, "regulator init failed for %d\n", |
@@ -1153,13 +1136,9 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) | |||
1153 | 1136 | ||
1154 | return 0; | 1137 | return 0; |
1155 | err: | 1138 | err: |
1156 | for (i = 0; i < max8997->num_regulators; i++) | 1139 | while (--i >= 0) |
1157 | if (rdev[i]) | 1140 | regulator_unregister(rdev[i]); |
1158 | regulator_unregister(rdev[i]); | 1141 | err_out: |
1159 | err_alloc: | ||
1160 | kfree(max8997->rdev); | ||
1161 | kfree(max8997); | ||
1162 | |||
1163 | return ret; | 1142 | return ret; |
1164 | } | 1143 | } |
1165 | 1144 | ||
@@ -1170,12 +1149,7 @@ static int __devexit max8997_pmic_remove(struct platform_device *pdev) | |||
1170 | int i; | 1149 | int i; |
1171 | 1150 | ||
1172 | for (i = 0; i < max8997->num_regulators; i++) | 1151 | for (i = 0; i < max8997->num_regulators; i++) |
1173 | if (rdev[i]) | 1152 | regulator_unregister(rdev[i]); |
1174 | regulator_unregister(rdev[i]); | ||
1175 | |||
1176 | kfree(max8997->rdev); | ||
1177 | kfree(max8997); | ||
1178 | |||
1179 | return 0; | 1153 | return 0; |
1180 | } | 1154 | } |
1181 | 1155 | ||
diff --git a/drivers/regulator/max8998.c b/drivers/regulator/max8998.c index 5890265eeacc..18bb58b9b96e 100644 --- a/drivers/regulator/max8998.c +++ b/drivers/regulator/max8998.c | |||
@@ -28,7 +28,6 @@ | |||
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> | ||
32 | #include <linux/platform_device.h> | 31 | #include <linux/platform_device.h> |
33 | #include <linux/regulator/driver.h> | 32 | #include <linux/regulator/driver.h> |
34 | #include <linux/mfd/max8998.h> | 33 | #include <linux/mfd/max8998.h> |
@@ -277,7 +276,7 @@ static int max8998_get_voltage_register(struct regulator_dev *rdev, | |||
277 | return 0; | 276 | return 0; |
278 | } | 277 | } |
279 | 278 | ||
280 | static int max8998_get_voltage(struct regulator_dev *rdev) | 279 | static int max8998_get_voltage_sel(struct regulator_dev *rdev) |
281 | { | 280 | { |
282 | struct max8998_data *max8998 = rdev_get_drvdata(rdev); | 281 | struct max8998_data *max8998 = rdev_get_drvdata(rdev); |
283 | struct i2c_client *i2c = max8998->iodev->i2c; | 282 | struct i2c_client *i2c = max8998->iodev->i2c; |
@@ -295,7 +294,7 @@ static int max8998_get_voltage(struct regulator_dev *rdev) | |||
295 | val >>= shift; | 294 | val >>= shift; |
296 | val &= mask; | 295 | val &= mask; |
297 | 296 | ||
298 | return max8998_list_voltage(rdev, val); | 297 | return val; |
299 | } | 298 | } |
300 | 299 | ||
301 | static int max8998_set_voltage_ldo(struct regulator_dev *rdev, | 300 | static int max8998_set_voltage_ldo(struct regulator_dev *rdev, |
@@ -306,8 +305,7 @@ static int max8998_set_voltage_ldo(struct regulator_dev *rdev, | |||
306 | int min_vol = min_uV / 1000, max_vol = max_uV / 1000; | 305 | int min_vol = min_uV / 1000, max_vol = max_uV / 1000; |
307 | const struct voltage_map_desc *desc; | 306 | const struct voltage_map_desc *desc; |
308 | int ldo = rdev_get_id(rdev); | 307 | int ldo = rdev_get_id(rdev); |
309 | int reg, shift = 0, mask, ret; | 308 | int reg, shift = 0, mask, ret, i; |
310 | int i = 0; | ||
311 | 309 | ||
312 | if (ldo >= ARRAY_SIZE(ldo_voltage_map)) | 310 | if (ldo >= ARRAY_SIZE(ldo_voltage_map)) |
313 | return -EINVAL; | 311 | return -EINVAL; |
@@ -319,9 +317,10 @@ static int max8998_set_voltage_ldo(struct regulator_dev *rdev, | |||
319 | if (max_vol < desc->min || min_vol > desc->max) | 317 | if (max_vol < desc->min || min_vol > desc->max) |
320 | return -EINVAL; | 318 | return -EINVAL; |
321 | 319 | ||
322 | while (desc->min + desc->step*i < min_vol && | 320 | if (min_vol < desc->min) |
323 | desc->min + desc->step*i < desc->max) | 321 | min_vol = desc->min; |
324 | i++; | 322 | |
323 | i = DIV_ROUND_UP(min_vol - desc->min, desc->step); | ||
325 | 324 | ||
326 | if (desc->min + desc->step*i > max_vol) | 325 | if (desc->min + desc->step*i > max_vol) |
327 | return -EINVAL; | 326 | return -EINVAL; |
@@ -359,8 +358,7 @@ static int max8998_set_voltage_buck(struct regulator_dev *rdev, | |||
359 | const struct voltage_map_desc *desc; | 358 | const struct voltage_map_desc *desc; |
360 | int buck = rdev_get_id(rdev); | 359 | int buck = rdev_get_id(rdev); |
361 | int reg, shift = 0, mask, ret; | 360 | int reg, shift = 0, mask, ret; |
362 | int difference = 0, i = 0, j = 0, previous_vol = 0; | 361 | int i, j, previous_sel; |
363 | u8 val = 0; | ||
364 | static u8 buck1_last_val; | 362 | static u8 buck1_last_val; |
365 | 363 | ||
366 | if (buck >= ARRAY_SIZE(ldo_voltage_map)) | 364 | if (buck >= ARRAY_SIZE(ldo_voltage_map)) |
@@ -374,9 +372,10 @@ static int max8998_set_voltage_buck(struct regulator_dev *rdev, | |||
374 | if (max_vol < desc->min || min_vol > desc->max) | 372 | if (max_vol < desc->min || min_vol > desc->max) |
375 | return -EINVAL; | 373 | return -EINVAL; |
376 | 374 | ||
377 | while (desc->min + desc->step*i < min_vol && | 375 | if (min_vol < desc->min) |
378 | desc->min + desc->step*i < desc->max) | 376 | min_vol = desc->min; |
379 | i++; | 377 | |
378 | i = DIV_ROUND_UP(min_vol - desc->min, desc->step); | ||
380 | 379 | ||
381 | if (desc->min + desc->step*i > max_vol) | 380 | if (desc->min + desc->step*i > max_vol) |
382 | return -EINVAL; | 381 | return -EINVAL; |
@@ -387,13 +386,14 @@ static int max8998_set_voltage_buck(struct regulator_dev *rdev, | |||
387 | if (ret) | 386 | if (ret) |
388 | return ret; | 387 | return ret; |
389 | 388 | ||
390 | previous_vol = max8998_get_voltage(rdev); | 389 | previous_sel = max8998_get_voltage_sel(rdev); |
391 | 390 | ||
392 | /* Check if voltage needs to be changed */ | 391 | /* Check if voltage needs to be changed */ |
393 | /* if previous_voltage equal new voltage, return */ | 392 | /* if previous_voltage equal new voltage, return */ |
394 | if (previous_vol == max8998_list_voltage(rdev, i)) { | 393 | if (previous_sel == i) { |
395 | dev_dbg(max8998->dev, "No voltage change, old:%d, new:%d\n", | 394 | dev_dbg(max8998->dev, "No voltage change, old:%d, new:%d\n", |
396 | previous_vol, max8998_list_voltage(rdev, i)); | 395 | max8998_list_voltage(rdev, previous_sel), |
396 | max8998_list_voltage(rdev, i)); | ||
397 | return ret; | 397 | return ret; |
398 | } | 398 | } |
399 | 399 | ||
@@ -482,19 +482,40 @@ buck2_exit: | |||
482 | break; | 482 | break; |
483 | } | 483 | } |
484 | 484 | ||
485 | return ret; | ||
486 | } | ||
487 | |||
488 | static int max8998_set_voltage_buck_time_sel(struct regulator_dev *rdev, | ||
489 | unsigned int old_selector, | ||
490 | unsigned int new_selector) | ||
491 | { | ||
492 | struct max8998_data *max8998 = rdev_get_drvdata(rdev); | ||
493 | struct i2c_client *i2c = max8998->iodev->i2c; | ||
494 | const struct voltage_map_desc *desc; | ||
495 | int buck = rdev_get_id(rdev); | ||
496 | u8 val = 0; | ||
497 | int difference, ret; | ||
498 | |||
499 | if (buck < MAX8998_BUCK1 || buck > MAX8998_BUCK4) | ||
500 | return -EINVAL; | ||
501 | |||
502 | desc = ldo_voltage_map[buck]; | ||
503 | |||
485 | /* Voltage stabilization */ | 504 | /* Voltage stabilization */ |
486 | max8998_read_reg(i2c, MAX8998_REG_ONOFF4, &val); | 505 | ret = max8998_read_reg(i2c, MAX8998_REG_ONOFF4, &val); |
506 | if (ret) | ||
507 | return ret; | ||
487 | 508 | ||
488 | /* lp3974 hasn't got ENRAMP bit - ramp is assumed as true */ | 509 | /* lp3974 hasn't got ENRAMP bit - ramp is assumed as true */ |
489 | /* MAX8998 has ENRAMP bit implemented, so test it*/ | 510 | /* MAX8998 has ENRAMP bit implemented, so test it*/ |
490 | if (max8998->iodev->type == TYPE_MAX8998 && !(val & MAX8998_ENRAMP)) | 511 | if (max8998->iodev->type == TYPE_MAX8998 && !(val & MAX8998_ENRAMP)) |
491 | return ret; | 512 | return 0; |
492 | 513 | ||
493 | difference = desc->min + desc->step*i - previous_vol/1000; | 514 | difference = (new_selector - old_selector) * desc->step; |
494 | if (difference > 0) | 515 | if (difference > 0) |
495 | udelay(difference / ((val & 0x0f) + 1)); | 516 | return difference / ((val & 0x0f) + 1); |
496 | 517 | ||
497 | return ret; | 518 | return 0; |
498 | } | 519 | } |
499 | 520 | ||
500 | static struct regulator_ops max8998_ldo_ops = { | 521 | static struct regulator_ops max8998_ldo_ops = { |
@@ -502,7 +523,7 @@ static struct regulator_ops max8998_ldo_ops = { | |||
502 | .is_enabled = max8998_ldo_is_enabled, | 523 | .is_enabled = max8998_ldo_is_enabled, |
503 | .enable = max8998_ldo_enable, | 524 | .enable = max8998_ldo_enable, |
504 | .disable = max8998_ldo_disable, | 525 | .disable = max8998_ldo_disable, |
505 | .get_voltage = max8998_get_voltage, | 526 | .get_voltage_sel = max8998_get_voltage_sel, |
506 | .set_voltage = max8998_set_voltage_ldo, | 527 | .set_voltage = max8998_set_voltage_ldo, |
507 | .set_suspend_enable = max8998_ldo_enable, | 528 | .set_suspend_enable = max8998_ldo_enable, |
508 | .set_suspend_disable = max8998_ldo_disable, | 529 | .set_suspend_disable = max8998_ldo_disable, |
@@ -513,8 +534,9 @@ static struct regulator_ops max8998_buck_ops = { | |||
513 | .is_enabled = max8998_ldo_is_enabled, | 534 | .is_enabled = max8998_ldo_is_enabled, |
514 | .enable = max8998_ldo_enable, | 535 | .enable = max8998_ldo_enable, |
515 | .disable = max8998_ldo_disable, | 536 | .disable = max8998_ldo_disable, |
516 | .get_voltage = max8998_get_voltage, | 537 | .get_voltage_sel = max8998_get_voltage_sel, |
517 | .set_voltage = max8998_set_voltage_buck, | 538 | .set_voltage = max8998_set_voltage_buck, |
539 | .set_voltage_time_sel = max8998_set_voltage_buck_time_sel, | ||
518 | .set_suspend_enable = max8998_ldo_enable, | 540 | .set_suspend_enable = max8998_ldo_enable, |
519 | .set_suspend_disable = max8998_ldo_disable, | 541 | .set_suspend_disable = max8998_ldo_disable, |
520 | }; | 542 | }; |
@@ -685,6 +707,7 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev) | |||
685 | { | 707 | { |
686 | struct max8998_dev *iodev = dev_get_drvdata(pdev->dev.parent); | 708 | struct max8998_dev *iodev = dev_get_drvdata(pdev->dev.parent); |
687 | struct max8998_platform_data *pdata = dev_get_platdata(iodev->dev); | 709 | struct max8998_platform_data *pdata = dev_get_platdata(iodev->dev); |
710 | struct regulator_config config = { }; | ||
688 | struct regulator_dev **rdev; | 711 | struct regulator_dev **rdev; |
689 | struct max8998_data *max8998; | 712 | struct max8998_data *max8998; |
690 | struct i2c_client *i2c; | 713 | struct i2c_client *i2c; |
@@ -695,16 +718,15 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev) | |||
695 | return -ENODEV; | 718 | return -ENODEV; |
696 | } | 719 | } |
697 | 720 | ||
698 | max8998 = kzalloc(sizeof(struct max8998_data), GFP_KERNEL); | 721 | max8998 = devm_kzalloc(&pdev->dev, sizeof(struct max8998_data), |
722 | GFP_KERNEL); | ||
699 | if (!max8998) | 723 | if (!max8998) |
700 | return -ENOMEM; | 724 | return -ENOMEM; |
701 | 725 | ||
702 | size = sizeof(struct regulator_dev *) * pdata->num_regulators; | 726 | size = sizeof(struct regulator_dev *) * pdata->num_regulators; |
703 | max8998->rdev = kzalloc(size, GFP_KERNEL); | 727 | max8998->rdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); |
704 | if (!max8998->rdev) { | 728 | if (!max8998->rdev) |
705 | kfree(max8998); | ||
706 | return -ENOMEM; | 729 | return -ENOMEM; |
707 | } | ||
708 | 730 | ||
709 | rdev = max8998->rdev; | 731 | rdev = max8998->rdev; |
710 | max8998->dev = &pdev->dev; | 732 | max8998->dev = &pdev->dev; |
@@ -728,14 +750,14 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev) | |||
728 | printk(KERN_ERR "MAX8998 SET1 GPIO defined as 0 !\n"); | 750 | printk(KERN_ERR "MAX8998 SET1 GPIO defined as 0 !\n"); |
729 | WARN_ON(!pdata->buck1_set1); | 751 | WARN_ON(!pdata->buck1_set1); |
730 | ret = -EIO; | 752 | ret = -EIO; |
731 | goto err_free_mem; | 753 | goto err_out; |
732 | } | 754 | } |
733 | /* Check if SET2 is not equal to 0 */ | 755 | /* Check if SET2 is not equal to 0 */ |
734 | if (!pdata->buck1_set2) { | 756 | if (!pdata->buck1_set2) { |
735 | printk(KERN_ERR "MAX8998 SET2 GPIO defined as 0 !\n"); | 757 | printk(KERN_ERR "MAX8998 SET2 GPIO defined as 0 !\n"); |
736 | WARN_ON(!pdata->buck1_set2); | 758 | WARN_ON(!pdata->buck1_set2); |
737 | ret = -EIO; | 759 | ret = -EIO; |
738 | goto err_free_mem; | 760 | goto err_out; |
739 | } | 761 | } |
740 | 762 | ||
741 | gpio_request(pdata->buck1_set1, "MAX8998 BUCK1_SET1"); | 763 | gpio_request(pdata->buck1_set1, "MAX8998 BUCK1_SET1"); |
@@ -755,7 +777,7 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev) | |||
755 | max8998->buck1_vol[0] = i; | 777 | max8998->buck1_vol[0] = i; |
756 | ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE1, i); | 778 | ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE1, i); |
757 | if (ret) | 779 | if (ret) |
758 | goto err_free_mem; | 780 | goto err_out; |
759 | 781 | ||
760 | /* Set predefined value for BUCK1 register 2 */ | 782 | /* Set predefined value for BUCK1 register 2 */ |
761 | i = 0; | 783 | i = 0; |
@@ -767,7 +789,7 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev) | |||
767 | max8998->buck1_vol[1] = i; | 789 | max8998->buck1_vol[1] = i; |
768 | ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE2, i); | 790 | ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE2, i); |
769 | if (ret) | 791 | if (ret) |
770 | goto err_free_mem; | 792 | goto err_out; |
771 | 793 | ||
772 | /* Set predefined value for BUCK1 register 3 */ | 794 | /* Set predefined value for BUCK1 register 3 */ |
773 | i = 0; | 795 | i = 0; |
@@ -779,7 +801,7 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev) | |||
779 | max8998->buck1_vol[2] = i; | 801 | max8998->buck1_vol[2] = i; |
780 | ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE3, i); | 802 | ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE3, i); |
781 | if (ret) | 803 | if (ret) |
782 | goto err_free_mem; | 804 | goto err_out; |
783 | 805 | ||
784 | /* Set predefined value for BUCK1 register 4 */ | 806 | /* Set predefined value for BUCK1 register 4 */ |
785 | i = 0; | 807 | i = 0; |
@@ -791,7 +813,7 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev) | |||
791 | max8998->buck1_vol[3] = i; | 813 | max8998->buck1_vol[3] = i; |
792 | ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE4, i); | 814 | ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE4, i); |
793 | if (ret) | 815 | if (ret) |
794 | goto err_free_mem; | 816 | goto err_out; |
795 | 817 | ||
796 | } | 818 | } |
797 | 819 | ||
@@ -801,7 +823,7 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev) | |||
801 | printk(KERN_ERR "MAX8998 SET3 GPIO defined as 0 !\n"); | 823 | printk(KERN_ERR "MAX8998 SET3 GPIO defined as 0 !\n"); |
802 | WARN_ON(!pdata->buck2_set3); | 824 | WARN_ON(!pdata->buck2_set3); |
803 | ret = -EIO; | 825 | ret = -EIO; |
804 | goto err_free_mem; | 826 | goto err_out; |
805 | } | 827 | } |
806 | gpio_request(pdata->buck2_set3, "MAX8998 BUCK2_SET3"); | 828 | gpio_request(pdata->buck2_set3, "MAX8998 BUCK2_SET3"); |
807 | gpio_direction_output(pdata->buck2_set3, | 829 | gpio_direction_output(pdata->buck2_set3, |
@@ -816,7 +838,7 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev) | |||
816 | max8998->buck2_vol[0] = i; | 838 | max8998->buck2_vol[0] = i; |
817 | ret = max8998_write_reg(i2c, MAX8998_REG_BUCK2_VOLTAGE1, i); | 839 | ret = max8998_write_reg(i2c, MAX8998_REG_BUCK2_VOLTAGE1, i); |
818 | if (ret) | 840 | if (ret) |
819 | goto err_free_mem; | 841 | goto err_out; |
820 | 842 | ||
821 | /* BUCK2 register 2 */ | 843 | /* BUCK2 register 2 */ |
822 | i = 0; | 844 | i = 0; |
@@ -827,7 +849,7 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev) | |||
827 | max8998->buck2_vol[1] = i; | 849 | max8998->buck2_vol[1] = i; |
828 | ret = max8998_write_reg(i2c, MAX8998_REG_BUCK2_VOLTAGE2, i); | 850 | ret = max8998_write_reg(i2c, MAX8998_REG_BUCK2_VOLTAGE2, i); |
829 | if (ret) | 851 | if (ret) |
830 | goto err_free_mem; | 852 | goto err_out; |
831 | } | 853 | } |
832 | 854 | ||
833 | for (i = 0; i < pdata->num_regulators; i++) { | 855 | for (i = 0; i < pdata->num_regulators; i++) { |
@@ -840,8 +862,12 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev) | |||
840 | int count = (desc->max - desc->min) / desc->step + 1; | 862 | int count = (desc->max - desc->min) / desc->step + 1; |
841 | regulators[index].n_voltages = count; | 863 | regulators[index].n_voltages = count; |
842 | } | 864 | } |
843 | rdev[i] = regulator_register(®ulators[index], max8998->dev, | 865 | |
844 | pdata->regulators[i].initdata, max8998, NULL); | 866 | config.dev = max8998->dev; |
867 | config.init_data = pdata->regulators[i].initdata; | ||
868 | config.driver_data = max8998; | ||
869 | |||
870 | rdev[i] = regulator_register(®ulators[index], &config); | ||
845 | if (IS_ERR(rdev[i])) { | 871 | if (IS_ERR(rdev[i])) { |
846 | ret = PTR_ERR(rdev[i]); | 872 | ret = PTR_ERR(rdev[i]); |
847 | dev_err(max8998->dev, "regulator init failed\n"); | 873 | dev_err(max8998->dev, "regulator init failed\n"); |
@@ -853,14 +879,9 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev) | |||
853 | 879 | ||
854 | return 0; | 880 | return 0; |
855 | err: | 881 | err: |
856 | for (i = 0; i < max8998->num_regulators; i++) | 882 | while (--i >= 0) |
857 | if (rdev[i]) | 883 | regulator_unregister(rdev[i]); |
858 | regulator_unregister(rdev[i]); | 884 | err_out: |
859 | |||
860 | err_free_mem: | ||
861 | kfree(max8998->rdev); | ||
862 | kfree(max8998); | ||
863 | |||
864 | return ret; | 885 | return ret; |
865 | } | 886 | } |
866 | 887 | ||
@@ -871,12 +892,7 @@ static int __devexit max8998_pmic_remove(struct platform_device *pdev) | |||
871 | int i; | 892 | int i; |
872 | 893 | ||
873 | for (i = 0; i < max8998->num_regulators; i++) | 894 | for (i = 0; i < max8998->num_regulators; i++) |
874 | if (rdev[i]) | 895 | regulator_unregister(rdev[i]); |
875 | regulator_unregister(rdev[i]); | ||
876 | |||
877 | kfree(max8998->rdev); | ||
878 | kfree(max8998); | ||
879 | |||
880 | return 0; | 896 | return 0; |
881 | } | 897 | } |
882 | 898 | ||
diff --git a/drivers/regulator/mc13783-regulator.c b/drivers/regulator/mc13783-regulator.c index 6c0face87ffe..7dcdfa283e93 100644 --- a/drivers/regulator/mc13783-regulator.c +++ b/drivers/regulator/mc13783-regulator.c | |||
@@ -340,6 +340,7 @@ static int __devinit mc13783_regulator_probe(struct platform_device *pdev) | |||
340 | struct mc13xxx_regulator_platform_data *pdata = | 340 | struct mc13xxx_regulator_platform_data *pdata = |
341 | dev_get_platdata(&pdev->dev); | 341 | dev_get_platdata(&pdev->dev); |
342 | struct mc13xxx_regulator_init_data *init_data; | 342 | struct mc13xxx_regulator_init_data *init_data; |
343 | struct regulator_config config = { }; | ||
343 | int i, ret; | 344 | int i, ret; |
344 | 345 | ||
345 | dev_dbg(&pdev->dev, "%s id %d\n", __func__, pdev->id); | 346 | dev_dbg(&pdev->dev, "%s id %d\n", __func__, pdev->id); |
@@ -357,11 +358,16 @@ static int __devinit mc13783_regulator_probe(struct platform_device *pdev) | |||
357 | priv->mc13xxx = mc13783; | 358 | priv->mc13xxx = mc13783; |
358 | 359 | ||
359 | for (i = 0; i < pdata->num_regulators; i++) { | 360 | for (i = 0; i < pdata->num_regulators; i++) { |
361 | struct regulator_desc *desc; | ||
362 | |||
360 | init_data = &pdata->regulators[i]; | 363 | init_data = &pdata->regulators[i]; |
361 | priv->regulators[i] = regulator_register( | 364 | desc = &mc13783_regulators[init_data->id].desc; |
362 | &mc13783_regulators[init_data->id].desc, | 365 | |
363 | &pdev->dev, init_data->init_data, priv, NULL); | 366 | config.dev = &pdev->dev; |
367 | config.init_data = init_data->init_data; | ||
368 | config.driver_data = priv; | ||
364 | 369 | ||
370 | priv->regulators[i] = regulator_register(desc, &config); | ||
365 | if (IS_ERR(priv->regulators[i])) { | 371 | if (IS_ERR(priv->regulators[i])) { |
366 | dev_err(&pdev->dev, "failed to register regulator %s\n", | 372 | dev_err(&pdev->dev, "failed to register regulator %s\n", |
367 | mc13783_regulators[i].desc.name); | 373 | mc13783_regulators[i].desc.name); |
diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c index 845aa2263b8a..970a233dbe46 100644 --- a/drivers/regulator/mc13892-regulator.c +++ b/drivers/regulator/mc13892-regulator.c | |||
@@ -428,24 +428,15 @@ static int mc13892_sw_regulator_get_voltage(struct regulator_dev *rdev) | |||
428 | return val; | 428 | return val; |
429 | } | 429 | } |
430 | 430 | ||
431 | static int mc13892_sw_regulator_set_voltage(struct regulator_dev *rdev, | 431 | static int mc13892_sw_regulator_set_voltage_sel(struct regulator_dev *rdev, |
432 | int min_uV, int max_uV, unsigned *selector) | 432 | unsigned selector) |
433 | { | 433 | { |
434 | struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev); | 434 | struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev); |
435 | int hi, value, mask, id = rdev_get_id(rdev); | 435 | int hi, value, mask, id = rdev_get_id(rdev); |
436 | u32 valread; | 436 | u32 valread; |
437 | int ret; | 437 | int ret; |
438 | 438 | ||
439 | dev_dbg(rdev_get_dev(rdev), "%s id: %d min_uV: %d max_uV: %d\n", | 439 | value = mc13892_regulators[id].voltages[selector]; |
440 | __func__, id, min_uV, max_uV); | ||
441 | |||
442 | /* Find the best index */ | ||
443 | value = mc13xxx_get_best_voltage_index(rdev, min_uV, max_uV); | ||
444 | dev_dbg(rdev_get_dev(rdev), "%s best value: %d\n", __func__, value); | ||
445 | if (value < 0) | ||
446 | return value; | ||
447 | |||
448 | value = mc13892_regulators[id].voltages[value]; | ||
449 | 440 | ||
450 | mc13xxx_lock(priv->mc13xxx); | 441 | mc13xxx_lock(priv->mc13xxx); |
451 | ret = mc13xxx_reg_read(priv->mc13xxx, | 442 | ret = mc13xxx_reg_read(priv->mc13xxx, |
@@ -480,7 +471,7 @@ err: | |||
480 | static struct regulator_ops mc13892_sw_regulator_ops = { | 471 | static struct regulator_ops mc13892_sw_regulator_ops = { |
481 | .is_enabled = mc13xxx_sw_regulator_is_enabled, | 472 | .is_enabled = mc13xxx_sw_regulator_is_enabled, |
482 | .list_voltage = mc13xxx_regulator_list_voltage, | 473 | .list_voltage = mc13xxx_regulator_list_voltage, |
483 | .set_voltage = mc13892_sw_regulator_set_voltage, | 474 | .set_voltage_sel = mc13892_sw_regulator_set_voltage_sel, |
484 | .get_voltage = mc13892_sw_regulator_get_voltage, | 475 | .get_voltage = mc13892_sw_regulator_get_voltage, |
485 | }; | 476 | }; |
486 | 477 | ||
@@ -528,6 +519,7 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev) | |||
528 | struct mc13xxx_regulator_platform_data *pdata = | 519 | struct mc13xxx_regulator_platform_data *pdata = |
529 | dev_get_platdata(&pdev->dev); | 520 | dev_get_platdata(&pdev->dev); |
530 | struct mc13xxx_regulator_init_data *mc13xxx_data; | 521 | struct mc13xxx_regulator_init_data *mc13xxx_data; |
522 | struct regulator_config config = { }; | ||
531 | int i, ret; | 523 | int i, ret; |
532 | int num_regulators = 0; | 524 | int num_regulators = 0; |
533 | u32 val; | 525 | u32 val; |
@@ -597,9 +589,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev) | |||
597 | } | 589 | } |
598 | desc = &mc13892_regulators[id].desc; | 590 | desc = &mc13892_regulators[id].desc; |
599 | 591 | ||
600 | priv->regulators[i] = regulator_register( | 592 | config.dev = &pdev->dev; |
601 | desc, &pdev->dev, init_data, priv, node); | 593 | config.init_data = init_data; |
594 | config.driver_data = priv; | ||
595 | config.of_node = node; | ||
602 | 596 | ||
597 | priv->regulators[i] = regulator_register(desc, &config); | ||
603 | if (IS_ERR(priv->regulators[i])) { | 598 | if (IS_ERR(priv->regulators[i])) { |
604 | dev_err(&pdev->dev, "failed to register regulator %s\n", | 599 | dev_err(&pdev->dev, "failed to register regulator %s\n", |
605 | mc13892_regulators[i].desc.name); | 600 | mc13892_regulators[i].desc.name); |
diff --git a/drivers/regulator/mc13xxx-regulator-core.c b/drivers/regulator/mc13xxx-regulator-core.c index 62dcd0a432bb..4fa9704739bc 100644 --- a/drivers/regulator/mc13xxx-regulator-core.c +++ b/drivers/regulator/mc13xxx-regulator-core.c | |||
@@ -94,62 +94,18 @@ int mc13xxx_regulator_list_voltage(struct regulator_dev *rdev, | |||
94 | } | 94 | } |
95 | EXPORT_SYMBOL_GPL(mc13xxx_regulator_list_voltage); | 95 | EXPORT_SYMBOL_GPL(mc13xxx_regulator_list_voltage); |
96 | 96 | ||
97 | int mc13xxx_get_best_voltage_index(struct regulator_dev *rdev, | 97 | static int mc13xxx_regulator_set_voltage_sel(struct regulator_dev *rdev, |
98 | int min_uV, int max_uV) | 98 | unsigned selector) |
99 | { | 99 | { |
100 | struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev); | 100 | struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev); |
101 | struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators; | 101 | struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators; |
102 | int reg_id = rdev_get_id(rdev); | 102 | int id = rdev_get_id(rdev); |
103 | int i; | ||
104 | int bestmatch; | ||
105 | int bestindex; | ||
106 | |||
107 | /* | ||
108 | * Locate the minimum voltage fitting the criteria on | ||
109 | * this regulator. The switchable voltages are not | ||
110 | * in strict falling order so we need to check them | ||
111 | * all for the best match. | ||
112 | */ | ||
113 | bestmatch = INT_MAX; | ||
114 | bestindex = -1; | ||
115 | for (i = 0; i < mc13xxx_regulators[reg_id].desc.n_voltages; i++) { | ||
116 | if (mc13xxx_regulators[reg_id].voltages[i] >= min_uV && | ||
117 | mc13xxx_regulators[reg_id].voltages[i] < bestmatch) { | ||
118 | bestmatch = mc13xxx_regulators[reg_id].voltages[i]; | ||
119 | bestindex = i; | ||
120 | } | ||
121 | } | ||
122 | |||
123 | if (bestindex < 0 || bestmatch > max_uV) { | ||
124 | dev_warn(&rdev->dev, "no possible value for %d<=x<=%d uV\n", | ||
125 | min_uV, max_uV); | ||
126 | return -EINVAL; | ||
127 | } | ||
128 | return bestindex; | ||
129 | } | ||
130 | EXPORT_SYMBOL_GPL(mc13xxx_get_best_voltage_index); | ||
131 | |||
132 | static int mc13xxx_regulator_set_voltage(struct regulator_dev *rdev, int min_uV, | ||
133 | int max_uV, unsigned *selector) | ||
134 | { | ||
135 | struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev); | ||
136 | struct mc13xxx_regulator *mc13xxx_regulators = priv->mc13xxx_regulators; | ||
137 | int value, id = rdev_get_id(rdev); | ||
138 | int ret; | 103 | int ret; |
139 | 104 | ||
140 | dev_dbg(rdev_get_dev(rdev), "%s id: %d min_uV: %d max_uV: %d\n", | ||
141 | __func__, id, min_uV, max_uV); | ||
142 | |||
143 | /* Find the best index */ | ||
144 | value = mc13xxx_get_best_voltage_index(rdev, min_uV, max_uV); | ||
145 | dev_dbg(rdev_get_dev(rdev), "%s best value: %d\n", __func__, value); | ||
146 | if (value < 0) | ||
147 | return value; | ||
148 | |||
149 | mc13xxx_lock(priv->mc13xxx); | 105 | mc13xxx_lock(priv->mc13xxx); |
150 | ret = mc13xxx_reg_rmw(priv->mc13xxx, mc13xxx_regulators[id].vsel_reg, | 106 | ret = mc13xxx_reg_rmw(priv->mc13xxx, mc13xxx_regulators[id].vsel_reg, |
151 | mc13xxx_regulators[id].vsel_mask, | 107 | mc13xxx_regulators[id].vsel_mask, |
152 | value << mc13xxx_regulators[id].vsel_shift); | 108 | selector << mc13xxx_regulators[id].vsel_shift); |
153 | mc13xxx_unlock(priv->mc13xxx); | 109 | mc13xxx_unlock(priv->mc13xxx); |
154 | 110 | ||
155 | return ret; | 111 | return ret; |
@@ -187,7 +143,7 @@ struct regulator_ops mc13xxx_regulator_ops = { | |||
187 | .disable = mc13xxx_regulator_disable, | 143 | .disable = mc13xxx_regulator_disable, |
188 | .is_enabled = mc13xxx_regulator_is_enabled, | 144 | .is_enabled = mc13xxx_regulator_is_enabled, |
189 | .list_voltage = mc13xxx_regulator_list_voltage, | 145 | .list_voltage = mc13xxx_regulator_list_voltage, |
190 | .set_voltage = mc13xxx_regulator_set_voltage, | 146 | .set_voltage_sel = mc13xxx_regulator_set_voltage_sel, |
191 | .get_voltage = mc13xxx_regulator_get_voltage, | 147 | .get_voltage = mc13xxx_regulator_get_voltage, |
192 | }; | 148 | }; |
193 | EXPORT_SYMBOL_GPL(mc13xxx_regulator_ops); | 149 | EXPORT_SYMBOL_GPL(mc13xxx_regulator_ops); |
diff --git a/drivers/regulator/mc13xxx.h b/drivers/regulator/mc13xxx.h index b3961c658b05..044aba4d28ec 100644 --- a/drivers/regulator/mc13xxx.h +++ b/drivers/regulator/mc13xxx.h | |||
@@ -35,8 +35,6 @@ struct mc13xxx_regulator_priv { | |||
35 | 35 | ||
36 | extern int mc13xxx_sw_regulator(struct regulator_dev *rdev); | 36 | extern int mc13xxx_sw_regulator(struct regulator_dev *rdev); |
37 | extern int mc13xxx_sw_regulator_is_enabled(struct regulator_dev *rdev); | 37 | extern int mc13xxx_sw_regulator_is_enabled(struct regulator_dev *rdev); |
38 | extern int mc13xxx_get_best_voltage_index(struct regulator_dev *rdev, | ||
39 | int min_uV, int max_uV); | ||
40 | extern int mc13xxx_regulator_list_voltage(struct regulator_dev *rdev, | 38 | extern int mc13xxx_regulator_list_voltage(struct regulator_dev *rdev, |
41 | unsigned selector); | 39 | unsigned selector); |
42 | extern int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev, | 40 | extern int mc13xxx_fixed_regulator_set_voltage(struct regulator_dev *rdev, |
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c index 679734d26a16..56593b75168a 100644 --- a/drivers/regulator/of_regulator.c +++ b/drivers/regulator/of_regulator.c | |||
@@ -14,6 +14,7 @@ | |||
14 | #include <linux/slab.h> | 14 | #include <linux/slab.h> |
15 | #include <linux/of.h> | 15 | #include <linux/of.h> |
16 | #include <linux/regulator/machine.h> | 16 | #include <linux/regulator/machine.h> |
17 | #include <linux/regulator/of_regulator.h> | ||
17 | 18 | ||
18 | static void of_get_regulation_constraints(struct device_node *np, | 19 | static void of_get_regulation_constraints(struct device_node *np, |
19 | struct regulator_init_data **init_data) | 20 | struct regulator_init_data **init_data) |
@@ -85,3 +86,49 @@ struct regulator_init_data *of_get_regulator_init_data(struct device *dev, | |||
85 | return init_data; | 86 | return init_data; |
86 | } | 87 | } |
87 | EXPORT_SYMBOL_GPL(of_get_regulator_init_data); | 88 | EXPORT_SYMBOL_GPL(of_get_regulator_init_data); |
89 | |||
90 | /** | ||
91 | * of_regulator_match - extract regulator init data | ||
92 | * @dev: device requesting the data | ||
93 | * @node: parent device node of the regulators | ||
94 | * @matches: match table for the regulators | ||
95 | * @num_matches: number of entries in match table | ||
96 | * | ||
97 | * This function uses a match table specified by the regulator driver and | ||
98 | * looks up the corresponding init data in the device tree. Note that the | ||
99 | * match table is modified in place. | ||
100 | * | ||
101 | * Returns the number of matches found or a negative error code on failure. | ||
102 | */ | ||
103 | int of_regulator_match(struct device *dev, struct device_node *node, | ||
104 | struct of_regulator_match *matches, | ||
105 | unsigned int num_matches) | ||
106 | { | ||
107 | unsigned int count = 0; | ||
108 | unsigned int i; | ||
109 | |||
110 | if (!dev || !node) | ||
111 | return -EINVAL; | ||
112 | |||
113 | for (i = 0; i < num_matches; i++) { | ||
114 | struct of_regulator_match *match = &matches[i]; | ||
115 | struct device_node *child; | ||
116 | |||
117 | child = of_find_node_by_name(node, match->name); | ||
118 | if (!child) | ||
119 | continue; | ||
120 | |||
121 | match->init_data = of_get_regulator_init_data(dev, child); | ||
122 | if (!match->init_data) { | ||
123 | dev_err(dev, "failed to parse DT for regulator %s\n", | ||
124 | child->name); | ||
125 | return -EINVAL; | ||
126 | } | ||
127 | |||
128 | match->of_node = child; | ||
129 | count++; | ||
130 | } | ||
131 | |||
132 | return count; | ||
133 | } | ||
134 | EXPORT_SYMBOL_GPL(of_regulator_match); | ||
diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c new file mode 100644 index 000000000000..c4435f608df7 --- /dev/null +++ b/drivers/regulator/palmas-regulator.c | |||
@@ -0,0 +1,822 @@ | |||
1 | /* | ||
2 | * Driver for Regulator part of Palmas PMIC Chips | ||
3 | * | ||
4 | * Copyright 2011-2012 Texas Instruments Inc. | ||
5 | * | ||
6 | * Author: Graeme Gregory <gg@slimlogic.co.uk> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License as published by the | ||
10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
11 | * option) any later version. | ||
12 | * | ||
13 | */ | ||
14 | |||
15 | #include <linux/kernel.h> | ||
16 | #include <linux/module.h> | ||
17 | #include <linux/init.h> | ||
18 | #include <linux/err.h> | ||
19 | #include <linux/platform_device.h> | ||
20 | #include <linux/regulator/driver.h> | ||
21 | #include <linux/regulator/machine.h> | ||
22 | #include <linux/slab.h> | ||
23 | #include <linux/regmap.h> | ||
24 | #include <linux/mfd/palmas.h> | ||
25 | |||
26 | struct regs_info { | ||
27 | char *name; | ||
28 | u8 vsel_addr; | ||
29 | u8 ctrl_addr; | ||
30 | u8 tstep_addr; | ||
31 | }; | ||
32 | |||
33 | static const struct regs_info palmas_regs_info[] = { | ||
34 | { | ||
35 | .name = "SMPS12", | ||
36 | .vsel_addr = PALMAS_SMPS12_VOLTAGE, | ||
37 | .ctrl_addr = PALMAS_SMPS12_CTRL, | ||
38 | .tstep_addr = PALMAS_SMPS12_TSTEP, | ||
39 | }, | ||
40 | { | ||
41 | .name = "SMPS123", | ||
42 | .vsel_addr = PALMAS_SMPS12_VOLTAGE, | ||
43 | .ctrl_addr = PALMAS_SMPS12_CTRL, | ||
44 | .tstep_addr = PALMAS_SMPS12_TSTEP, | ||
45 | }, | ||
46 | { | ||
47 | .name = "SMPS3", | ||
48 | .vsel_addr = PALMAS_SMPS3_VOLTAGE, | ||
49 | .ctrl_addr = PALMAS_SMPS3_CTRL, | ||
50 | }, | ||
51 | { | ||
52 | .name = "SMPS45", | ||
53 | .vsel_addr = PALMAS_SMPS45_VOLTAGE, | ||
54 | .ctrl_addr = PALMAS_SMPS45_CTRL, | ||
55 | .tstep_addr = PALMAS_SMPS45_TSTEP, | ||
56 | }, | ||
57 | { | ||
58 | .name = "SMPS457", | ||
59 | .vsel_addr = PALMAS_SMPS45_VOLTAGE, | ||
60 | .ctrl_addr = PALMAS_SMPS45_CTRL, | ||
61 | .tstep_addr = PALMAS_SMPS45_TSTEP, | ||
62 | }, | ||
63 | { | ||
64 | .name = "SMPS6", | ||
65 | .vsel_addr = PALMAS_SMPS6_VOLTAGE, | ||
66 | .ctrl_addr = PALMAS_SMPS6_CTRL, | ||
67 | .tstep_addr = PALMAS_SMPS6_TSTEP, | ||
68 | }, | ||
69 | { | ||
70 | .name = "SMPS7", | ||
71 | .vsel_addr = PALMAS_SMPS7_VOLTAGE, | ||
72 | .ctrl_addr = PALMAS_SMPS7_CTRL, | ||
73 | }, | ||
74 | { | ||
75 | .name = "SMPS8", | ||
76 | .vsel_addr = PALMAS_SMPS8_VOLTAGE, | ||
77 | .ctrl_addr = PALMAS_SMPS8_CTRL, | ||
78 | .tstep_addr = PALMAS_SMPS8_TSTEP, | ||
79 | }, | ||
80 | { | ||
81 | .name = "SMPS9", | ||
82 | .vsel_addr = PALMAS_SMPS9_VOLTAGE, | ||
83 | .ctrl_addr = PALMAS_SMPS9_CTRL, | ||
84 | }, | ||
85 | { | ||
86 | .name = "SMPS10", | ||
87 | }, | ||
88 | { | ||
89 | .name = "LDO1", | ||
90 | .vsel_addr = PALMAS_LDO1_VOLTAGE, | ||
91 | .ctrl_addr = PALMAS_LDO1_CTRL, | ||
92 | }, | ||
93 | { | ||
94 | .name = "LDO2", | ||
95 | .vsel_addr = PALMAS_LDO2_VOLTAGE, | ||
96 | .ctrl_addr = PALMAS_LDO2_CTRL, | ||
97 | }, | ||
98 | { | ||
99 | .name = "LDO3", | ||
100 | .vsel_addr = PALMAS_LDO3_VOLTAGE, | ||
101 | .ctrl_addr = PALMAS_LDO3_CTRL, | ||
102 | }, | ||
103 | { | ||
104 | .name = "LDO4", | ||
105 | .vsel_addr = PALMAS_LDO4_VOLTAGE, | ||
106 | .ctrl_addr = PALMAS_LDO4_CTRL, | ||
107 | }, | ||
108 | { | ||
109 | .name = "LDO5", | ||
110 | .vsel_addr = PALMAS_LDO5_VOLTAGE, | ||
111 | .ctrl_addr = PALMAS_LDO5_CTRL, | ||
112 | }, | ||
113 | { | ||
114 | .name = "LDO6", | ||
115 | .vsel_addr = PALMAS_LDO6_VOLTAGE, | ||
116 | .ctrl_addr = PALMAS_LDO6_CTRL, | ||
117 | }, | ||
118 | { | ||
119 | .name = "LDO7", | ||
120 | .vsel_addr = PALMAS_LDO7_VOLTAGE, | ||
121 | .ctrl_addr = PALMAS_LDO7_CTRL, | ||
122 | }, | ||
123 | { | ||
124 | .name = "LDO8", | ||
125 | .vsel_addr = PALMAS_LDO8_VOLTAGE, | ||
126 | .ctrl_addr = PALMAS_LDO8_CTRL, | ||
127 | }, | ||
128 | { | ||
129 | .name = "LDO9", | ||
130 | .vsel_addr = PALMAS_LDO9_VOLTAGE, | ||
131 | .ctrl_addr = PALMAS_LDO9_CTRL, | ||
132 | }, | ||
133 | { | ||
134 | .name = "LDOLN", | ||
135 | .vsel_addr = PALMAS_LDOLN_VOLTAGE, | ||
136 | .ctrl_addr = PALMAS_LDOLN_CTRL, | ||
137 | }, | ||
138 | { | ||
139 | .name = "LDOUSB", | ||
140 | .vsel_addr = PALMAS_LDOUSB_VOLTAGE, | ||
141 | .ctrl_addr = PALMAS_LDOUSB_CTRL, | ||
142 | }, | ||
143 | }; | ||
144 | |||
145 | #define SMPS_CTRL_MODE_OFF 0x00 | ||
146 | #define SMPS_CTRL_MODE_ON 0x01 | ||
147 | #define SMPS_CTRL_MODE_ECO 0x02 | ||
148 | #define SMPS_CTRL_MODE_PWM 0x03 | ||
149 | |||
150 | /* These values are derived from the data sheet. And are the number of steps | ||
151 | * where there is a voltage change, the ranges at beginning and end of register | ||
152 | * max/min values where there are no change are ommitted. | ||
153 | * | ||
154 | * So they are basically (maxV-minV)/stepV | ||
155 | */ | ||
156 | #define PALMAS_SMPS_NUM_VOLTAGES 116 | ||
157 | #define PALMAS_SMPS10_NUM_VOLTAGES 2 | ||
158 | #define PALMAS_LDO_NUM_VOLTAGES 50 | ||
159 | |||
160 | #define SMPS10_VSEL (1<<3) | ||
161 | #define SMPS10_BOOST_EN (1<<2) | ||
162 | #define SMPS10_BYPASS_EN (1<<1) | ||
163 | #define SMPS10_SWITCH_EN (1<<0) | ||
164 | |||
165 | #define REGULATOR_SLAVE 0 | ||
166 | |||
167 | static int palmas_smps_read(struct palmas *palmas, unsigned int reg, | ||
168 | unsigned int *dest) | ||
169 | { | ||
170 | unsigned int addr; | ||
171 | |||
172 | addr = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, reg); | ||
173 | |||
174 | return regmap_read(palmas->regmap[REGULATOR_SLAVE], addr, dest); | ||
175 | } | ||
176 | |||
177 | static int palmas_smps_write(struct palmas *palmas, unsigned int reg, | ||
178 | unsigned int value) | ||
179 | { | ||
180 | unsigned int addr; | ||
181 | |||
182 | addr = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, reg); | ||
183 | |||
184 | return regmap_write(palmas->regmap[REGULATOR_SLAVE], addr, value); | ||
185 | } | ||
186 | |||
187 | static int palmas_ldo_read(struct palmas *palmas, unsigned int reg, | ||
188 | unsigned int *dest) | ||
189 | { | ||
190 | unsigned int addr; | ||
191 | |||
192 | addr = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, reg); | ||
193 | |||
194 | return regmap_read(palmas->regmap[REGULATOR_SLAVE], addr, dest); | ||
195 | } | ||
196 | |||
197 | static int palmas_ldo_write(struct palmas *palmas, unsigned int reg, | ||
198 | unsigned int value) | ||
199 | { | ||
200 | unsigned int addr; | ||
201 | |||
202 | addr = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, reg); | ||
203 | |||
204 | return regmap_write(palmas->regmap[REGULATOR_SLAVE], addr, value); | ||
205 | } | ||
206 | |||
207 | static int palmas_is_enabled_smps(struct regulator_dev *dev) | ||
208 | { | ||
209 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); | ||
210 | int id = rdev_get_id(dev); | ||
211 | unsigned int reg; | ||
212 | |||
213 | palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, ®); | ||
214 | |||
215 | reg &= PALMAS_SMPS12_CTRL_STATUS_MASK; | ||
216 | reg >>= PALMAS_SMPS12_CTRL_STATUS_SHIFT; | ||
217 | |||
218 | return !!(reg); | ||
219 | } | ||
220 | |||
221 | static int palmas_enable_smps(struct regulator_dev *dev) | ||
222 | { | ||
223 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); | ||
224 | int id = rdev_get_id(dev); | ||
225 | unsigned int reg; | ||
226 | |||
227 | palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, ®); | ||
228 | |||
229 | reg &= ~PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK; | ||
230 | reg |= SMPS_CTRL_MODE_ON; | ||
231 | |||
232 | palmas_smps_write(pmic->palmas, palmas_regs_info[id].ctrl_addr, reg); | ||
233 | |||
234 | return 0; | ||
235 | } | ||
236 | |||
237 | static int palmas_disable_smps(struct regulator_dev *dev) | ||
238 | { | ||
239 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); | ||
240 | int id = rdev_get_id(dev); | ||
241 | unsigned int reg; | ||
242 | |||
243 | palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, ®); | ||
244 | |||
245 | reg &= ~PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK; | ||
246 | |||
247 | palmas_smps_write(pmic->palmas, palmas_regs_info[id].ctrl_addr, reg); | ||
248 | |||
249 | return 0; | ||
250 | } | ||
251 | |||
252 | |||
253 | static int palmas_set_mode_smps(struct regulator_dev *dev, unsigned int mode) | ||
254 | { | ||
255 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); | ||
256 | int id = rdev_get_id(dev); | ||
257 | unsigned int reg; | ||
258 | |||
259 | palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, ®); | ||
260 | reg &= ~PALMAS_SMPS12_CTRL_STATUS_MASK; | ||
261 | reg >>= PALMAS_SMPS12_CTRL_STATUS_SHIFT; | ||
262 | |||
263 | switch (mode) { | ||
264 | case REGULATOR_MODE_NORMAL: | ||
265 | reg |= SMPS_CTRL_MODE_ON; | ||
266 | break; | ||
267 | case REGULATOR_MODE_IDLE: | ||
268 | reg |= SMPS_CTRL_MODE_ECO; | ||
269 | break; | ||
270 | case REGULATOR_MODE_FAST: | ||
271 | reg |= SMPS_CTRL_MODE_PWM; | ||
272 | break; | ||
273 | default: | ||
274 | return -EINVAL; | ||
275 | } | ||
276 | palmas_smps_write(pmic->palmas, palmas_regs_info[id].ctrl_addr, reg); | ||
277 | |||
278 | return 0; | ||
279 | } | ||
280 | |||
281 | static unsigned int palmas_get_mode_smps(struct regulator_dev *dev) | ||
282 | { | ||
283 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); | ||
284 | int id = rdev_get_id(dev); | ||
285 | unsigned int reg; | ||
286 | |||
287 | palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, ®); | ||
288 | reg &= PALMAS_SMPS12_CTRL_STATUS_MASK; | ||
289 | reg >>= PALMAS_SMPS12_CTRL_STATUS_SHIFT; | ||
290 | |||
291 | switch (reg) { | ||
292 | case SMPS_CTRL_MODE_ON: | ||
293 | return REGULATOR_MODE_NORMAL; | ||
294 | case SMPS_CTRL_MODE_ECO: | ||
295 | return REGULATOR_MODE_IDLE; | ||
296 | case SMPS_CTRL_MODE_PWM: | ||
297 | return REGULATOR_MODE_FAST; | ||
298 | } | ||
299 | |||
300 | return 0; | ||
301 | } | ||
302 | |||
303 | static int palmas_list_voltage_smps(struct regulator_dev *dev, | ||
304 | unsigned selector) | ||
305 | { | ||
306 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); | ||
307 | int id = rdev_get_id(dev); | ||
308 | int mult = 1; | ||
309 | |||
310 | if (!selector) | ||
311 | return 0; | ||
312 | |||
313 | /* Read the multiplier set in VSEL register to return | ||
314 | * the correct voltage. | ||
315 | */ | ||
316 | if (pmic->range[id]) | ||
317 | mult = 2; | ||
318 | |||
319 | /* Voltage is (0.49V + (selector * 0.01V)) * RANGE | ||
320 | * as defined in data sheet. RANGE is either x1 or x2 | ||
321 | */ | ||
322 | return (490000 + (selector * 10000)) * mult; | ||
323 | } | ||
324 | |||
325 | static int palmas_get_voltage_smps_sel(struct regulator_dev *dev) | ||
326 | { | ||
327 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); | ||
328 | int id = rdev_get_id(dev); | ||
329 | int selector; | ||
330 | unsigned int reg; | ||
331 | unsigned int addr; | ||
332 | |||
333 | addr = palmas_regs_info[id].vsel_addr; | ||
334 | |||
335 | palmas_smps_read(pmic->palmas, addr, ®); | ||
336 | |||
337 | selector = reg & PALMAS_SMPS12_VOLTAGE_VSEL_MASK; | ||
338 | |||
339 | /* Adjust selector to match list_voltage ranges */ | ||
340 | if ((selector > 0) && (selector < 6)) | ||
341 | selector = 6; | ||
342 | if (!selector) | ||
343 | selector = 5; | ||
344 | if (selector > 121) | ||
345 | selector = 121; | ||
346 | selector -= 5; | ||
347 | |||
348 | return selector; | ||
349 | } | ||
350 | |||
351 | static int palmas_set_voltage_smps_sel(struct regulator_dev *dev, | ||
352 | unsigned selector) | ||
353 | { | ||
354 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); | ||
355 | int id = rdev_get_id(dev); | ||
356 | unsigned int reg = 0; | ||
357 | unsigned int addr; | ||
358 | |||
359 | addr = palmas_regs_info[id].vsel_addr; | ||
360 | |||
361 | /* Make sure we don't change the value of RANGE */ | ||
362 | if (pmic->range[id]) | ||
363 | reg |= PALMAS_SMPS12_VOLTAGE_RANGE; | ||
364 | |||
365 | /* Adjust the linux selector into range used in VSEL register */ | ||
366 | if (selector) | ||
367 | reg |= selector + 5; | ||
368 | |||
369 | palmas_smps_write(pmic->palmas, addr, reg); | ||
370 | |||
371 | return 0; | ||
372 | } | ||
373 | |||
374 | static int palmas_map_voltage_smps(struct regulator_dev *rdev, | ||
375 | int min_uV, int max_uV) | ||
376 | { | ||
377 | int ret, voltage; | ||
378 | |||
379 | ret = ((min_uV - 500000) / 10000) + 1; | ||
380 | if (ret < 0) | ||
381 | return ret; | ||
382 | |||
383 | /* Map back into a voltage to verify we're still in bounds */ | ||
384 | voltage = palmas_list_voltage_smps(rdev, ret); | ||
385 | if (voltage < min_uV || voltage > max_uV) | ||
386 | return -EINVAL; | ||
387 | |||
388 | return ret; | ||
389 | } | ||
390 | |||
391 | static struct regulator_ops palmas_ops_smps = { | ||
392 | .is_enabled = palmas_is_enabled_smps, | ||
393 | .enable = palmas_enable_smps, | ||
394 | .disable = palmas_disable_smps, | ||
395 | .set_mode = palmas_set_mode_smps, | ||
396 | .get_mode = palmas_get_mode_smps, | ||
397 | .get_voltage_sel = palmas_get_voltage_smps_sel, | ||
398 | .set_voltage_sel = palmas_set_voltage_smps_sel, | ||
399 | .list_voltage = palmas_list_voltage_smps, | ||
400 | .map_voltage = palmas_map_voltage_smps, | ||
401 | }; | ||
402 | |||
403 | static int palmas_list_voltage_smps10(struct regulator_dev *dev, | ||
404 | unsigned selector) | ||
405 | { | ||
406 | return 3750000 + (selector * 1250000); | ||
407 | } | ||
408 | |||
409 | static struct regulator_ops palmas_ops_smps10 = { | ||
410 | .is_enabled = regulator_is_enabled_regmap, | ||
411 | .enable = regulator_enable_regmap, | ||
412 | .disable = regulator_disable_regmap, | ||
413 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | ||
414 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | ||
415 | .list_voltage = palmas_list_voltage_smps10, | ||
416 | }; | ||
417 | |||
418 | static int palmas_is_enabled_ldo(struct regulator_dev *dev) | ||
419 | { | ||
420 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); | ||
421 | int id = rdev_get_id(dev); | ||
422 | unsigned int reg; | ||
423 | |||
424 | palmas_ldo_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, ®); | ||
425 | |||
426 | reg &= PALMAS_LDO1_CTRL_STATUS; | ||
427 | |||
428 | return !!(reg); | ||
429 | } | ||
430 | |||
431 | static int palmas_list_voltage_ldo(struct regulator_dev *dev, | ||
432 | unsigned selector) | ||
433 | { | ||
434 | if (!selector) | ||
435 | return 0; | ||
436 | |||
437 | /* voltage is 0.85V + (selector * 0.05v) */ | ||
438 | return 850000 + (selector * 50000); | ||
439 | } | ||
440 | |||
441 | static int palmas_get_voltage_ldo_sel(struct regulator_dev *dev) | ||
442 | { | ||
443 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); | ||
444 | int id = rdev_get_id(dev); | ||
445 | int selector; | ||
446 | unsigned int reg; | ||
447 | unsigned int addr; | ||
448 | |||
449 | addr = palmas_regs_info[id].vsel_addr; | ||
450 | |||
451 | palmas_ldo_read(pmic->palmas, addr, ®); | ||
452 | |||
453 | selector = reg & PALMAS_LDO1_VOLTAGE_VSEL_MASK; | ||
454 | |||
455 | /* Adjust selector to match list_voltage ranges */ | ||
456 | if (selector > 49) | ||
457 | selector = 49; | ||
458 | |||
459 | return selector; | ||
460 | } | ||
461 | |||
462 | static int palmas_set_voltage_ldo_sel(struct regulator_dev *dev, | ||
463 | unsigned selector) | ||
464 | { | ||
465 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); | ||
466 | int id = rdev_get_id(dev); | ||
467 | unsigned int reg = 0; | ||
468 | unsigned int addr; | ||
469 | |||
470 | addr = palmas_regs_info[id].vsel_addr; | ||
471 | |||
472 | reg = selector; | ||
473 | |||
474 | palmas_ldo_write(pmic->palmas, addr, reg); | ||
475 | |||
476 | return 0; | ||
477 | } | ||
478 | |||
479 | static int palmas_map_voltage_ldo(struct regulator_dev *rdev, | ||
480 | int min_uV, int max_uV) | ||
481 | { | ||
482 | int ret, voltage; | ||
483 | |||
484 | ret = ((min_uV - 900000) / 50000) + 1; | ||
485 | if (ret < 0) | ||
486 | return ret; | ||
487 | |||
488 | /* Map back into a voltage to verify we're still in bounds */ | ||
489 | voltage = palmas_list_voltage_ldo(rdev, ret); | ||
490 | if (voltage < min_uV || voltage > max_uV) | ||
491 | return -EINVAL; | ||
492 | |||
493 | return ret; | ||
494 | } | ||
495 | |||
496 | static struct regulator_ops palmas_ops_ldo = { | ||
497 | .is_enabled = palmas_is_enabled_ldo, | ||
498 | .enable = regulator_enable_regmap, | ||
499 | .disable = regulator_disable_regmap, | ||
500 | .get_voltage_sel = palmas_get_voltage_ldo_sel, | ||
501 | .set_voltage_sel = palmas_set_voltage_ldo_sel, | ||
502 | .list_voltage = palmas_list_voltage_ldo, | ||
503 | .map_voltage = palmas_map_voltage_ldo, | ||
504 | }; | ||
505 | |||
506 | /* | ||
507 | * setup the hardware based sleep configuration of the SMPS/LDO regulators | ||
508 | * from the platform data. This is different to the software based control | ||
509 | * supported by the regulator framework as it is controlled by toggling | ||
510 | * pins on the PMIC such as PREQ, SYSEN, ... | ||
511 | */ | ||
512 | static int palmas_smps_init(struct palmas *palmas, int id, | ||
513 | struct palmas_reg_init *reg_init) | ||
514 | { | ||
515 | unsigned int reg; | ||
516 | unsigned int addr; | ||
517 | int ret; | ||
518 | |||
519 | addr = palmas_regs_info[id].ctrl_addr; | ||
520 | |||
521 | ret = palmas_smps_read(palmas, addr, ®); | ||
522 | if (ret) | ||
523 | return ret; | ||
524 | |||
525 | if (id != PALMAS_REG_SMPS10) { | ||
526 | if (reg_init->warm_reset) | ||
527 | reg |= PALMAS_SMPS12_CTRL_WR_S; | ||
528 | |||
529 | if (reg_init->roof_floor) | ||
530 | reg |= PALMAS_SMPS12_CTRL_ROOF_FLOOR_EN; | ||
531 | |||
532 | if (reg_init->mode_sleep) { | ||
533 | reg &= ~PALMAS_SMPS12_CTRL_MODE_SLEEP_MASK; | ||
534 | reg |= reg_init->mode_sleep << | ||
535 | PALMAS_SMPS12_CTRL_MODE_SLEEP_SHIFT; | ||
536 | } | ||
537 | } else { | ||
538 | if (reg_init->mode_sleep) { | ||
539 | reg &= ~PALMAS_SMPS10_CTRL_MODE_SLEEP_MASK; | ||
540 | reg |= reg_init->mode_sleep << | ||
541 | PALMAS_SMPS10_CTRL_MODE_SLEEP_SHIFT; | ||
542 | } | ||
543 | |||
544 | } | ||
545 | ret = palmas_smps_write(palmas, addr, reg); | ||
546 | if (ret) | ||
547 | return ret; | ||
548 | |||
549 | if (palmas_regs_info[id].tstep_addr && reg_init->tstep) { | ||
550 | addr = palmas_regs_info[id].tstep_addr; | ||
551 | |||
552 | reg = reg_init->tstep & PALMAS_SMPS12_TSTEP_TSTEP_MASK; | ||
553 | |||
554 | ret = palmas_smps_write(palmas, addr, reg); | ||
555 | if (ret) | ||
556 | return ret; | ||
557 | } | ||
558 | |||
559 | if (palmas_regs_info[id].vsel_addr && reg_init->vsel) { | ||
560 | addr = palmas_regs_info[id].vsel_addr; | ||
561 | |||
562 | reg = reg_init->vsel; | ||
563 | |||
564 | ret = palmas_smps_write(palmas, addr, reg); | ||
565 | if (ret) | ||
566 | return ret; | ||
567 | } | ||
568 | |||
569 | |||
570 | return 0; | ||
571 | } | ||
572 | |||
573 | static int palmas_ldo_init(struct palmas *palmas, int id, | ||
574 | struct palmas_reg_init *reg_init) | ||
575 | { | ||
576 | unsigned int reg; | ||
577 | unsigned int addr; | ||
578 | int ret; | ||
579 | |||
580 | addr = palmas_regs_info[id].ctrl_addr; | ||
581 | |||
582 | ret = palmas_smps_read(palmas, addr, ®); | ||
583 | if (ret) | ||
584 | return ret; | ||
585 | |||
586 | if (reg_init->warm_reset) | ||
587 | reg |= PALMAS_LDO1_CTRL_WR_S; | ||
588 | |||
589 | if (reg_init->mode_sleep) | ||
590 | reg |= PALMAS_LDO1_CTRL_MODE_SLEEP; | ||
591 | |||
592 | ret = palmas_smps_write(palmas, addr, reg); | ||
593 | if (ret) | ||
594 | return ret; | ||
595 | |||
596 | return 0; | ||
597 | } | ||
598 | |||
599 | static __devinit int palmas_probe(struct platform_device *pdev) | ||
600 | { | ||
601 | struct palmas *palmas = dev_get_drvdata(pdev->dev.parent); | ||
602 | struct palmas_pmic_platform_data *pdata = pdev->dev.platform_data; | ||
603 | struct regulator_dev *rdev; | ||
604 | struct regulator_config config = { }; | ||
605 | struct palmas_pmic *pmic; | ||
606 | struct palmas_reg_init *reg_init; | ||
607 | int id = 0, ret; | ||
608 | unsigned int addr, reg; | ||
609 | |||
610 | if (!pdata) | ||
611 | return -EINVAL; | ||
612 | if (!pdata->reg_data) | ||
613 | return -EINVAL; | ||
614 | |||
615 | pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL); | ||
616 | if (!pmic) | ||
617 | return -ENOMEM; | ||
618 | |||
619 | pmic->dev = &pdev->dev; | ||
620 | pmic->palmas = palmas; | ||
621 | palmas->pmic = pmic; | ||
622 | platform_set_drvdata(pdev, pmic); | ||
623 | |||
624 | ret = palmas_smps_read(palmas, PALMAS_SMPS_CTRL, ®); | ||
625 | if (ret) | ||
626 | goto err_unregister_regulator; | ||
627 | |||
628 | if (reg & PALMAS_SMPS_CTRL_SMPS12_SMPS123_EN) | ||
629 | pmic->smps123 = 1; | ||
630 | |||
631 | if (reg & PALMAS_SMPS_CTRL_SMPS45_SMPS457_EN) | ||
632 | pmic->smps457 = 1; | ||
633 | |||
634 | config.regmap = palmas->regmap[REGULATOR_SLAVE]; | ||
635 | config.dev = &pdev->dev; | ||
636 | config.driver_data = pmic; | ||
637 | |||
638 | for (id = 0; id < PALMAS_REG_LDO1; id++) { | ||
639 | |||
640 | /* | ||
641 | * Miss out regulators which are not available due | ||
642 | * to slaving configurations. | ||
643 | */ | ||
644 | switch (id) { | ||
645 | case PALMAS_REG_SMPS12: | ||
646 | case PALMAS_REG_SMPS3: | ||
647 | if (pmic->smps123) | ||
648 | continue; | ||
649 | break; | ||
650 | case PALMAS_REG_SMPS123: | ||
651 | if (!pmic->smps123) | ||
652 | continue; | ||
653 | break; | ||
654 | case PALMAS_REG_SMPS45: | ||
655 | case PALMAS_REG_SMPS7: | ||
656 | if (pmic->smps457) | ||
657 | continue; | ||
658 | break; | ||
659 | case PALMAS_REG_SMPS457: | ||
660 | if (!pmic->smps457) | ||
661 | continue; | ||
662 | } | ||
663 | |||
664 | /* Register the regulators */ | ||
665 | pmic->desc[id].name = palmas_regs_info[id].name; | ||
666 | pmic->desc[id].id = id; | ||
667 | |||
668 | if (id != PALMAS_REG_SMPS10) { | ||
669 | pmic->desc[id].ops = &palmas_ops_smps; | ||
670 | pmic->desc[id].n_voltages = PALMAS_SMPS_NUM_VOLTAGES; | ||
671 | } else { | ||
672 | pmic->desc[id].n_voltages = PALMAS_SMPS10_NUM_VOLTAGES; | ||
673 | pmic->desc[id].ops = &palmas_ops_smps10; | ||
674 | pmic->desc[id].vsel_reg = PALMAS_SMPS10_CTRL; | ||
675 | pmic->desc[id].vsel_mask = SMPS10_VSEL; | ||
676 | pmic->desc[id].enable_reg = PALMAS_SMPS10_STATUS; | ||
677 | pmic->desc[id].enable_mask = SMPS10_BOOST_EN; | ||
678 | } | ||
679 | |||
680 | pmic->desc[id].type = REGULATOR_VOLTAGE; | ||
681 | pmic->desc[id].owner = THIS_MODULE; | ||
682 | |||
683 | /* Initialise sleep/init values from platform data */ | ||
684 | if (pdata && pdata->reg_init) { | ||
685 | reg_init = pdata->reg_init[id]; | ||
686 | if (reg_init) { | ||
687 | ret = palmas_smps_init(palmas, id, reg_init); | ||
688 | if (ret) | ||
689 | goto err_unregister_regulator; | ||
690 | } | ||
691 | } | ||
692 | |||
693 | /* | ||
694 | * read and store the RANGE bit for later use | ||
695 | * This must be done before regulator is probed otherwise | ||
696 | * we error in probe with unsuportable ranges. | ||
697 | */ | ||
698 | if (id != PALMAS_REG_SMPS10) { | ||
699 | addr = palmas_regs_info[id].vsel_addr; | ||
700 | |||
701 | ret = palmas_smps_read(pmic->palmas, addr, ®); | ||
702 | if (ret) | ||
703 | goto err_unregister_regulator; | ||
704 | if (reg & PALMAS_SMPS12_VOLTAGE_RANGE) | ||
705 | pmic->range[id] = 1; | ||
706 | } | ||
707 | |||
708 | if (pdata && pdata->reg_data) | ||
709 | config.init_data = pdata->reg_data[id]; | ||
710 | else | ||
711 | config.init_data = NULL; | ||
712 | |||
713 | rdev = regulator_register(&pmic->desc[id], &config); | ||
714 | if (IS_ERR(rdev)) { | ||
715 | dev_err(&pdev->dev, | ||
716 | "failed to register %s regulator\n", | ||
717 | pdev->name); | ||
718 | ret = PTR_ERR(rdev); | ||
719 | goto err_unregister_regulator; | ||
720 | } | ||
721 | |||
722 | /* Save regulator for cleanup */ | ||
723 | pmic->rdev[id] = rdev; | ||
724 | } | ||
725 | |||
726 | /* Start this loop from the id left from previous loop */ | ||
727 | for (; id < PALMAS_NUM_REGS; id++) { | ||
728 | |||
729 | /* Miss out regulators which are not available due | ||
730 | * to alternate functions. | ||
731 | */ | ||
732 | |||
733 | /* Register the regulators */ | ||
734 | pmic->desc[id].name = palmas_regs_info[id].name; | ||
735 | pmic->desc[id].id = id; | ||
736 | pmic->desc[id].n_voltages = PALMAS_LDO_NUM_VOLTAGES; | ||
737 | |||
738 | pmic->desc[id].ops = &palmas_ops_ldo; | ||
739 | |||
740 | pmic->desc[id].type = REGULATOR_VOLTAGE; | ||
741 | pmic->desc[id].owner = THIS_MODULE; | ||
742 | pmic->desc[id].enable_reg = palmas_regs_info[id].ctrl_addr; | ||
743 | pmic->desc[id].enable_mask = PALMAS_LDO1_CTRL_MODE_ACTIVE; | ||
744 | |||
745 | if (pdata && pdata->reg_data) | ||
746 | config.init_data = pdata->reg_data[id]; | ||
747 | else | ||
748 | config.init_data = NULL; | ||
749 | |||
750 | rdev = regulator_register(&pmic->desc[id], &config); | ||
751 | if (IS_ERR(rdev)) { | ||
752 | dev_err(&pdev->dev, | ||
753 | "failed to register %s regulator\n", | ||
754 | pdev->name); | ||
755 | ret = PTR_ERR(rdev); | ||
756 | goto err_unregister_regulator; | ||
757 | } | ||
758 | |||
759 | /* Save regulator for cleanup */ | ||
760 | pmic->rdev[id] = rdev; | ||
761 | |||
762 | /* Initialise sleep/init values from platform data */ | ||
763 | if (pdata->reg_init) { | ||
764 | reg_init = pdata->reg_init[id]; | ||
765 | if (reg_init) { | ||
766 | ret = palmas_ldo_init(palmas, id, reg_init); | ||
767 | if (ret) | ||
768 | goto err_unregister_regulator; | ||
769 | } | ||
770 | } | ||
771 | } | ||
772 | |||
773 | return 0; | ||
774 | |||
775 | err_unregister_regulator: | ||
776 | while (--id >= 0) | ||
777 | regulator_unregister(pmic->rdev[id]); | ||
778 | kfree(pmic->rdev); | ||
779 | kfree(pmic->desc); | ||
780 | kfree(pmic); | ||
781 | return ret; | ||
782 | } | ||
783 | |||
784 | static int __devexit palmas_remove(struct platform_device *pdev) | ||
785 | { | ||
786 | struct palmas_pmic *pmic = platform_get_drvdata(pdev); | ||
787 | int id; | ||
788 | |||
789 | for (id = 0; id < PALMAS_NUM_REGS; id++) | ||
790 | regulator_unregister(pmic->rdev[id]); | ||
791 | |||
792 | kfree(pmic->rdev); | ||
793 | kfree(pmic->desc); | ||
794 | kfree(pmic); | ||
795 | return 0; | ||
796 | } | ||
797 | |||
798 | static struct platform_driver palmas_driver = { | ||
799 | .driver = { | ||
800 | .name = "palmas-pmic", | ||
801 | .owner = THIS_MODULE, | ||
802 | }, | ||
803 | .probe = palmas_probe, | ||
804 | .remove = __devexit_p(palmas_remove), | ||
805 | }; | ||
806 | |||
807 | static int __init palmas_init(void) | ||
808 | { | ||
809 | return platform_driver_register(&palmas_driver); | ||
810 | } | ||
811 | subsys_initcall(palmas_init); | ||
812 | |||
813 | static void __exit palmas_exit(void) | ||
814 | { | ||
815 | platform_driver_unregister(&palmas_driver); | ||
816 | } | ||
817 | module_exit(palmas_exit); | ||
818 | |||
819 | MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>"); | ||
820 | MODULE_DESCRIPTION("Palmas voltage regulator driver"); | ||
821 | MODULE_LICENSE("GPL"); | ||
822 | MODULE_ALIAS("platform:palmas-pmic"); | ||
diff --git a/drivers/regulator/pcap-regulator.c b/drivers/regulator/pcap-regulator.c index a5aab1b08bcf..8211101121f0 100644 --- a/drivers/regulator/pcap-regulator.c +++ b/drivers/regulator/pcap-regulator.c | |||
@@ -150,57 +150,33 @@ static struct pcap_regulator vreg_table[] = { | |||
150 | VREG_INFO(SW2S, PCAP_REG_LOWPWR, NA, 20, NA, NA), */ | 150 | VREG_INFO(SW2S, PCAP_REG_LOWPWR, NA, 20, NA, NA), */ |
151 | }; | 151 | }; |
152 | 152 | ||
153 | static int pcap_regulator_set_voltage(struct regulator_dev *rdev, | 153 | static int pcap_regulator_set_voltage_sel(struct regulator_dev *rdev, |
154 | int min_uV, int max_uV, | 154 | unsigned selector) |
155 | unsigned *selector) | ||
156 | { | 155 | { |
157 | struct pcap_regulator *vreg = &vreg_table[rdev_get_id(rdev)]; | 156 | struct pcap_regulator *vreg = &vreg_table[rdev_get_id(rdev)]; |
158 | void *pcap = rdev_get_drvdata(rdev); | 157 | void *pcap = rdev_get_drvdata(rdev); |
159 | int uV; | ||
160 | u8 i; | ||
161 | 158 | ||
162 | /* the regulator doesn't support voltage switching */ | 159 | /* the regulator doesn't support voltage switching */ |
163 | if (vreg->n_voltages == 1) | 160 | if (vreg->n_voltages == 1) |
164 | return -EINVAL; | 161 | return -EINVAL; |
165 | 162 | ||
166 | for (i = 0; i < vreg->n_voltages; i++) { | 163 | return ezx_pcap_set_bits(pcap, vreg->reg, |
167 | /* For V1 the first is not the best match */ | 164 | (vreg->n_voltages - 1) << vreg->index, |
168 | if (i == 0 && rdev_get_id(rdev) == V1) | 165 | selector << vreg->index); |
169 | i = 1; | ||
170 | else if (i + 1 == vreg->n_voltages && rdev_get_id(rdev) == V1) | ||
171 | i = 0; | ||
172 | |||
173 | uV = vreg->voltage_table[i] * 1000; | ||
174 | if (min_uV <= uV && uV <= max_uV) { | ||
175 | *selector = i; | ||
176 | return ezx_pcap_set_bits(pcap, vreg->reg, | ||
177 | (vreg->n_voltages - 1) << vreg->index, | ||
178 | i << vreg->index); | ||
179 | } | ||
180 | |||
181 | if (i == 0 && rdev_get_id(rdev) == V1) | ||
182 | i = vreg->n_voltages - 1; | ||
183 | } | ||
184 | |||
185 | /* the requested voltage range is not supported by this regulator */ | ||
186 | return -EINVAL; | ||
187 | } | 166 | } |
188 | 167 | ||
189 | static int pcap_regulator_get_voltage(struct regulator_dev *rdev) | 168 | static int pcap_regulator_get_voltage_sel(struct regulator_dev *rdev) |
190 | { | 169 | { |
191 | struct pcap_regulator *vreg = &vreg_table[rdev_get_id(rdev)]; | 170 | struct pcap_regulator *vreg = &vreg_table[rdev_get_id(rdev)]; |
192 | void *pcap = rdev_get_drvdata(rdev); | 171 | void *pcap = rdev_get_drvdata(rdev); |
193 | u32 tmp; | 172 | u32 tmp; |
194 | int mV; | ||
195 | 173 | ||
196 | if (vreg->n_voltages == 1) | 174 | if (vreg->n_voltages == 1) |
197 | return vreg->voltage_table[0] * 1000; | 175 | return 0; |
198 | 176 | ||
199 | ezx_pcap_read(pcap, vreg->reg, &tmp); | 177 | ezx_pcap_read(pcap, vreg->reg, &tmp); |
200 | tmp = ((tmp >> vreg->index) & (vreg->n_voltages - 1)); | 178 | tmp = ((tmp >> vreg->index) & (vreg->n_voltages - 1)); |
201 | mV = vreg->voltage_table[tmp]; | 179 | return tmp; |
202 | |||
203 | return mV * 1000; | ||
204 | } | 180 | } |
205 | 181 | ||
206 | static int pcap_regulator_enable(struct regulator_dev *rdev) | 182 | static int pcap_regulator_enable(struct regulator_dev *rdev) |
@@ -248,8 +224,8 @@ static int pcap_regulator_list_voltage(struct regulator_dev *rdev, | |||
248 | 224 | ||
249 | static struct regulator_ops pcap_regulator_ops = { | 225 | static struct regulator_ops pcap_regulator_ops = { |
250 | .list_voltage = pcap_regulator_list_voltage, | 226 | .list_voltage = pcap_regulator_list_voltage, |
251 | .set_voltage = pcap_regulator_set_voltage, | 227 | .set_voltage_sel = pcap_regulator_set_voltage_sel, |
252 | .get_voltage = pcap_regulator_get_voltage, | 228 | .get_voltage_sel = pcap_regulator_get_voltage_sel, |
253 | .enable = pcap_regulator_enable, | 229 | .enable = pcap_regulator_enable, |
254 | .disable = pcap_regulator_disable, | 230 | .disable = pcap_regulator_disable, |
255 | .is_enabled = pcap_regulator_is_enabled, | 231 | .is_enabled = pcap_regulator_is_enabled, |
@@ -265,7 +241,7 @@ static struct regulator_ops pcap_regulator_ops = { | |||
265 | .owner = THIS_MODULE, \ | 241 | .owner = THIS_MODULE, \ |
266 | } | 242 | } |
267 | 243 | ||
268 | static struct regulator_desc pcap_regulators[] = { | 244 | static const struct regulator_desc pcap_regulators[] = { |
269 | VREG(V1), VREG(V2), VREG(V3), VREG(V4), VREG(V5), VREG(V6), VREG(V7), | 245 | VREG(V1), VREG(V2), VREG(V3), VREG(V4), VREG(V5), VREG(V6), VREG(V7), |
270 | VREG(V8), VREG(V9), VREG(V10), VREG(VAUX1), VREG(VAUX2), VREG(VAUX3), | 246 | VREG(V8), VREG(V9), VREG(V10), VREG(VAUX1), VREG(VAUX2), VREG(VAUX3), |
271 | VREG(VAUX4), VREG(VSIM), VREG(VSIM2), VREG(VVIB), VREG(SW1), VREG(SW2), | 247 | VREG(VAUX4), VREG(VSIM), VREG(VSIM2), VREG(VVIB), VREG(SW1), VREG(SW2), |
@@ -275,9 +251,13 @@ static int __devinit pcap_regulator_probe(struct platform_device *pdev) | |||
275 | { | 251 | { |
276 | struct regulator_dev *rdev; | 252 | struct regulator_dev *rdev; |
277 | void *pcap = dev_get_drvdata(pdev->dev.parent); | 253 | void *pcap = dev_get_drvdata(pdev->dev.parent); |
254 | struct regulator_config config = { }; | ||
255 | |||
256 | config.dev = &pdev->dev; | ||
257 | config.init_data = pdev->dev.platform_data; | ||
258 | config.driver_data = pcap; | ||
278 | 259 | ||
279 | rdev = regulator_register(&pcap_regulators[pdev->id], &pdev->dev, | 260 | rdev = regulator_register(&pcap_regulators[pdev->id], &config); |
280 | pdev->dev.platform_data, pcap, NULL); | ||
281 | if (IS_ERR(rdev)) | 261 | if (IS_ERR(rdev)) |
282 | return PTR_ERR(rdev); | 262 | return PTR_ERR(rdev); |
283 | 263 | ||
diff --git a/drivers/regulator/pcf50633-regulator.c b/drivers/regulator/pcf50633-regulator.c index 6db46c632f13..3c9d14c0017b 100644 --- a/drivers/regulator/pcf50633-regulator.c +++ b/drivers/regulator/pcf50633-regulator.c | |||
@@ -24,35 +24,25 @@ | |||
24 | #include <linux/mfd/pcf50633/core.h> | 24 | #include <linux/mfd/pcf50633/core.h> |
25 | #include <linux/mfd/pcf50633/pmic.h> | 25 | #include <linux/mfd/pcf50633/pmic.h> |
26 | 26 | ||
27 | #define PCF50633_REGULATOR(_name, _id, _n) \ | 27 | #define PCF50633_REGULATOR(_name, _id, _n) \ |
28 | { \ | 28 | { \ |
29 | .name = _name, \ | 29 | .name = _name, \ |
30 | .id = _id, \ | 30 | .id = PCF50633_REGULATOR_##_id, \ |
31 | .ops = &pcf50633_regulator_ops, \ | 31 | .ops = &pcf50633_regulator_ops, \ |
32 | .n_voltages = _n, \ | 32 | .n_voltages = _n, \ |
33 | .type = REGULATOR_VOLTAGE, \ | 33 | .type = REGULATOR_VOLTAGE, \ |
34 | .owner = THIS_MODULE, \ | 34 | .owner = THIS_MODULE, \ |
35 | .vsel_reg = PCF50633_REG_##_id##OUT, \ | ||
36 | .vsel_mask = 0xff, \ | ||
37 | .enable_reg = PCF50633_REG_##_id##OUT + 1, \ | ||
38 | .enable_mask = PCF50633_REGULATOR_ON, \ | ||
35 | } | 39 | } |
36 | 40 | ||
37 | static const u8 pcf50633_regulator_registers[PCF50633_NUM_REGULATORS] = { | ||
38 | [PCF50633_REGULATOR_AUTO] = PCF50633_REG_AUTOOUT, | ||
39 | [PCF50633_REGULATOR_DOWN1] = PCF50633_REG_DOWN1OUT, | ||
40 | [PCF50633_REGULATOR_DOWN2] = PCF50633_REG_DOWN2OUT, | ||
41 | [PCF50633_REGULATOR_MEMLDO] = PCF50633_REG_MEMLDOOUT, | ||
42 | [PCF50633_REGULATOR_LDO1] = PCF50633_REG_LDO1OUT, | ||
43 | [PCF50633_REGULATOR_LDO2] = PCF50633_REG_LDO2OUT, | ||
44 | [PCF50633_REGULATOR_LDO3] = PCF50633_REG_LDO3OUT, | ||
45 | [PCF50633_REGULATOR_LDO4] = PCF50633_REG_LDO4OUT, | ||
46 | [PCF50633_REGULATOR_LDO5] = PCF50633_REG_LDO5OUT, | ||
47 | [PCF50633_REGULATOR_LDO6] = PCF50633_REG_LDO6OUT, | ||
48 | [PCF50633_REGULATOR_HCLDO] = PCF50633_REG_HCLDOOUT, | ||
49 | }; | ||
50 | |||
51 | /* Bits from voltage value */ | 41 | /* Bits from voltage value */ |
52 | static u8 auto_voltage_bits(unsigned int millivolts) | 42 | static u8 auto_voltage_bits(unsigned int millivolts) |
53 | { | 43 | { |
54 | if (millivolts < 1800) | 44 | if (millivolts < 1800) |
55 | return 0; | 45 | return 0x2f; |
56 | if (millivolts > 3800) | 46 | if (millivolts > 3800) |
57 | return 0xff; | 47 | return 0xff; |
58 | 48 | ||
@@ -87,6 +77,9 @@ static u8 ldo_voltage_bits(unsigned int millivolts) | |||
87 | /* Obtain voltage value from bits */ | 77 | /* Obtain voltage value from bits */ |
88 | static unsigned int auto_voltage_value(u8 bits) | 78 | static unsigned int auto_voltage_value(u8 bits) |
89 | { | 79 | { |
80 | /* AUTOOUT: 00000000 to 00101110 are reserved. | ||
81 | * Return 0 for bits in reserved range, which means this selector code | ||
82 | * can't be used on this system */ | ||
90 | if (bits < 0x2f) | 83 | if (bits < 0x2f) |
91 | return 0; | 84 | return 0; |
92 | 85 | ||
@@ -123,7 +116,7 @@ static int pcf50633_regulator_set_voltage(struct regulator_dev *rdev, | |||
123 | 116 | ||
124 | millivolts = min_uV / 1000; | 117 | millivolts = min_uV / 1000; |
125 | 118 | ||
126 | regnr = pcf50633_regulator_registers[regulator_id]; | 119 | regnr = rdev->desc->vsel_reg; |
127 | 120 | ||
128 | switch (regulator_id) { | 121 | switch (regulator_id) { |
129 | case PCF50633_REGULATOR_AUTO: | 122 | case PCF50633_REGULATOR_AUTO: |
@@ -154,20 +147,22 @@ static int pcf50633_regulator_set_voltage(struct regulator_dev *rdev, | |||
154 | return pcf50633_reg_write(pcf, regnr, volt_bits); | 147 | return pcf50633_reg_write(pcf, regnr, volt_bits); |
155 | } | 148 | } |
156 | 149 | ||
157 | static int pcf50633_regulator_voltage_value(enum pcf50633_regulator_id id, | 150 | static int pcf50633_regulator_list_voltage(struct regulator_dev *rdev, |
158 | u8 bits) | 151 | unsigned int index) |
159 | { | 152 | { |
153 | int regulator_id = rdev_get_id(rdev); | ||
154 | |||
160 | int millivolts; | 155 | int millivolts; |
161 | 156 | ||
162 | switch (id) { | 157 | switch (regulator_id) { |
163 | case PCF50633_REGULATOR_AUTO: | 158 | case PCF50633_REGULATOR_AUTO: |
164 | millivolts = auto_voltage_value(bits); | 159 | millivolts = auto_voltage_value(index); |
165 | break; | 160 | break; |
166 | case PCF50633_REGULATOR_DOWN1: | 161 | case PCF50633_REGULATOR_DOWN1: |
167 | millivolts = down_voltage_value(bits); | 162 | millivolts = down_voltage_value(index); |
168 | break; | 163 | break; |
169 | case PCF50633_REGULATOR_DOWN2: | 164 | case PCF50633_REGULATOR_DOWN2: |
170 | millivolts = down_voltage_value(bits); | 165 | millivolts = down_voltage_value(index); |
171 | break; | 166 | break; |
172 | case PCF50633_REGULATOR_LDO1: | 167 | case PCF50633_REGULATOR_LDO1: |
173 | case PCF50633_REGULATOR_LDO2: | 168 | case PCF50633_REGULATOR_LDO2: |
@@ -177,7 +172,7 @@ static int pcf50633_regulator_voltage_value(enum pcf50633_regulator_id id, | |||
177 | case PCF50633_REGULATOR_LDO6: | 172 | case PCF50633_REGULATOR_LDO6: |
178 | case PCF50633_REGULATOR_HCLDO: | 173 | case PCF50633_REGULATOR_HCLDO: |
179 | case PCF50633_REGULATOR_MEMLDO: | 174 | case PCF50633_REGULATOR_MEMLDO: |
180 | millivolts = ldo_voltage_value(bits); | 175 | millivolts = ldo_voltage_value(index); |
181 | break; | 176 | break; |
182 | default: | 177 | default: |
183 | return -EINVAL; | 178 | return -EINVAL; |
@@ -186,140 +181,44 @@ static int pcf50633_regulator_voltage_value(enum pcf50633_regulator_id id, | |||
186 | return millivolts * 1000; | 181 | return millivolts * 1000; |
187 | } | 182 | } |
188 | 183 | ||
189 | static int pcf50633_regulator_get_voltage(struct regulator_dev *rdev) | ||
190 | { | ||
191 | struct pcf50633 *pcf; | ||
192 | int regulator_id; | ||
193 | u8 volt_bits, regnr; | ||
194 | |||
195 | pcf = rdev_get_drvdata(rdev); | ||
196 | |||
197 | regulator_id = rdev_get_id(rdev); | ||
198 | if (regulator_id >= PCF50633_NUM_REGULATORS) | ||
199 | return -EINVAL; | ||
200 | |||
201 | regnr = pcf50633_regulator_registers[regulator_id]; | ||
202 | |||
203 | volt_bits = pcf50633_reg_read(pcf, regnr); | ||
204 | |||
205 | return pcf50633_regulator_voltage_value(regulator_id, volt_bits); | ||
206 | } | ||
207 | |||
208 | static int pcf50633_regulator_list_voltage(struct regulator_dev *rdev, | ||
209 | unsigned int index) | ||
210 | { | ||
211 | struct pcf50633 *pcf; | ||
212 | int regulator_id; | ||
213 | |||
214 | pcf = rdev_get_drvdata(rdev); | ||
215 | |||
216 | regulator_id = rdev_get_id(rdev); | ||
217 | |||
218 | switch (regulator_id) { | ||
219 | case PCF50633_REGULATOR_AUTO: | ||
220 | index += 0x2f; | ||
221 | break; | ||
222 | default: | ||
223 | break; | ||
224 | } | ||
225 | |||
226 | return pcf50633_regulator_voltage_value(regulator_id, index); | ||
227 | } | ||
228 | |||
229 | static int pcf50633_regulator_enable(struct regulator_dev *rdev) | ||
230 | { | ||
231 | struct pcf50633 *pcf = rdev_get_drvdata(rdev); | ||
232 | int regulator_id; | ||
233 | u8 regnr; | ||
234 | |||
235 | regulator_id = rdev_get_id(rdev); | ||
236 | if (regulator_id >= PCF50633_NUM_REGULATORS) | ||
237 | return -EINVAL; | ||
238 | |||
239 | /* The *ENA register is always one after the *OUT register */ | ||
240 | regnr = pcf50633_regulator_registers[regulator_id] + 1; | ||
241 | |||
242 | return pcf50633_reg_set_bit_mask(pcf, regnr, PCF50633_REGULATOR_ON, | ||
243 | PCF50633_REGULATOR_ON); | ||
244 | } | ||
245 | |||
246 | static int pcf50633_regulator_disable(struct regulator_dev *rdev) | ||
247 | { | ||
248 | struct pcf50633 *pcf = rdev_get_drvdata(rdev); | ||
249 | int regulator_id; | ||
250 | u8 regnr; | ||
251 | |||
252 | regulator_id = rdev_get_id(rdev); | ||
253 | if (regulator_id >= PCF50633_NUM_REGULATORS) | ||
254 | return -EINVAL; | ||
255 | |||
256 | /* the *ENA register is always one after the *OUT register */ | ||
257 | regnr = pcf50633_regulator_registers[regulator_id] + 1; | ||
258 | |||
259 | return pcf50633_reg_set_bit_mask(pcf, regnr, | ||
260 | PCF50633_REGULATOR_ON, 0); | ||
261 | } | ||
262 | |||
263 | static int pcf50633_regulator_is_enabled(struct regulator_dev *rdev) | ||
264 | { | ||
265 | struct pcf50633 *pcf = rdev_get_drvdata(rdev); | ||
266 | int regulator_id = rdev_get_id(rdev); | ||
267 | u8 regnr; | ||
268 | |||
269 | regulator_id = rdev_get_id(rdev); | ||
270 | if (regulator_id >= PCF50633_NUM_REGULATORS) | ||
271 | return -EINVAL; | ||
272 | |||
273 | /* the *ENA register is always one after the *OUT register */ | ||
274 | regnr = pcf50633_regulator_registers[regulator_id] + 1; | ||
275 | |||
276 | return pcf50633_reg_read(pcf, regnr) & PCF50633_REGULATOR_ON; | ||
277 | } | ||
278 | |||
279 | static struct regulator_ops pcf50633_regulator_ops = { | 184 | static struct regulator_ops pcf50633_regulator_ops = { |
280 | .set_voltage = pcf50633_regulator_set_voltage, | 185 | .set_voltage = pcf50633_regulator_set_voltage, |
281 | .get_voltage = pcf50633_regulator_get_voltage, | 186 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
282 | .list_voltage = pcf50633_regulator_list_voltage, | 187 | .list_voltage = pcf50633_regulator_list_voltage, |
283 | .enable = pcf50633_regulator_enable, | 188 | .enable = regulator_enable_regmap, |
284 | .disable = pcf50633_regulator_disable, | 189 | .disable = regulator_disable_regmap, |
285 | .is_enabled = pcf50633_regulator_is_enabled, | 190 | .is_enabled = regulator_is_enabled_regmap, |
286 | }; | 191 | }; |
287 | 192 | ||
288 | static struct regulator_desc regulators[] = { | 193 | static const struct regulator_desc regulators[] = { |
289 | [PCF50633_REGULATOR_AUTO] = | 194 | [PCF50633_REGULATOR_AUTO] = PCF50633_REGULATOR("auto", AUTO, 128), |
290 | PCF50633_REGULATOR("auto", PCF50633_REGULATOR_AUTO, 81), | 195 | [PCF50633_REGULATOR_DOWN1] = PCF50633_REGULATOR("down1", DOWN1, 96), |
291 | [PCF50633_REGULATOR_DOWN1] = | 196 | [PCF50633_REGULATOR_DOWN2] = PCF50633_REGULATOR("down2", DOWN2, 96), |
292 | PCF50633_REGULATOR("down1", PCF50633_REGULATOR_DOWN1, 96), | 197 | [PCF50633_REGULATOR_LDO1] = PCF50633_REGULATOR("ldo1", LDO1, 28), |
293 | [PCF50633_REGULATOR_DOWN2] = | 198 | [PCF50633_REGULATOR_LDO2] = PCF50633_REGULATOR("ldo2", LDO2, 28), |
294 | PCF50633_REGULATOR("down2", PCF50633_REGULATOR_DOWN2, 96), | 199 | [PCF50633_REGULATOR_LDO3] = PCF50633_REGULATOR("ldo3", LDO3, 28), |
295 | [PCF50633_REGULATOR_LDO1] = | 200 | [PCF50633_REGULATOR_LDO4] = PCF50633_REGULATOR("ldo4", LDO4, 28), |
296 | PCF50633_REGULATOR("ldo1", PCF50633_REGULATOR_LDO1, 28), | 201 | [PCF50633_REGULATOR_LDO5] = PCF50633_REGULATOR("ldo5", LDO5, 28), |
297 | [PCF50633_REGULATOR_LDO2] = | 202 | [PCF50633_REGULATOR_LDO6] = PCF50633_REGULATOR("ldo6", LDO6, 28), |
298 | PCF50633_REGULATOR("ldo2", PCF50633_REGULATOR_LDO2, 28), | 203 | [PCF50633_REGULATOR_HCLDO] = PCF50633_REGULATOR("hcldo", HCLDO, 28), |
299 | [PCF50633_REGULATOR_LDO3] = | 204 | [PCF50633_REGULATOR_MEMLDO] = PCF50633_REGULATOR("memldo", MEMLDO, 28), |
300 | PCF50633_REGULATOR("ldo3", PCF50633_REGULATOR_LDO3, 28), | ||
301 | [PCF50633_REGULATOR_LDO4] = | ||
302 | PCF50633_REGULATOR("ldo4", PCF50633_REGULATOR_LDO4, 28), | ||
303 | [PCF50633_REGULATOR_LDO5] = | ||
304 | PCF50633_REGULATOR("ldo5", PCF50633_REGULATOR_LDO5, 28), | ||
305 | [PCF50633_REGULATOR_LDO6] = | ||
306 | PCF50633_REGULATOR("ldo6", PCF50633_REGULATOR_LDO6, 28), | ||
307 | [PCF50633_REGULATOR_HCLDO] = | ||
308 | PCF50633_REGULATOR("hcldo", PCF50633_REGULATOR_HCLDO, 28), | ||
309 | [PCF50633_REGULATOR_MEMLDO] = | ||
310 | PCF50633_REGULATOR("memldo", PCF50633_REGULATOR_MEMLDO, 28), | ||
311 | }; | 205 | }; |
312 | 206 | ||
313 | static int __devinit pcf50633_regulator_probe(struct platform_device *pdev) | 207 | static int __devinit pcf50633_regulator_probe(struct platform_device *pdev) |
314 | { | 208 | { |
315 | struct regulator_dev *rdev; | 209 | struct regulator_dev *rdev; |
316 | struct pcf50633 *pcf; | 210 | struct pcf50633 *pcf; |
211 | struct regulator_config config = { }; | ||
317 | 212 | ||
318 | /* Already set by core driver */ | 213 | /* Already set by core driver */ |
319 | pcf = dev_to_pcf50633(pdev->dev.parent); | 214 | pcf = dev_to_pcf50633(pdev->dev.parent); |
320 | 215 | ||
321 | rdev = regulator_register(®ulators[pdev->id], &pdev->dev, | 216 | config.dev = &pdev->dev; |
322 | pdev->dev.platform_data, pcf, NULL); | 217 | config.init_data = pdev->dev.platform_data; |
218 | config.driver_data = pcf; | ||
219 | config.regmap = pcf->regmap; | ||
220 | |||
221 | rdev = regulator_register(®ulators[pdev->id], &config); | ||
323 | if (IS_ERR(rdev)) | 222 | if (IS_ERR(rdev)) |
324 | return PTR_ERR(rdev); | 223 | return PTR_ERR(rdev); |
325 | 224 | ||
diff --git a/drivers/regulator/rc5t583-regulator.c b/drivers/regulator/rc5t583-regulator.c new file mode 100644 index 000000000000..1d34e64a1307 --- /dev/null +++ b/drivers/regulator/rc5t583-regulator.c | |||
@@ -0,0 +1,255 @@ | |||
1 | /* | ||
2 | * Regulator driver for RICOH RC5T583 power management chip. | ||
3 | * | ||
4 | * Copyright (c) 2011-2012, NVIDIA CORPORATION. All rights reserved. | ||
5 | * Author: Laxman dewangan <ldewangan@nvidia.com> | ||
6 | * | ||
7 | * based on code | ||
8 | * Copyright (C) 2011 RICOH COMPANY,LTD | ||
9 | * | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify it | ||
12 | * under the terms and conditions of the GNU General Public License, | ||
13 | * version 2, as published by the Free Software Foundation. | ||
14 | * | ||
15 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
17 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
18 | * more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License | ||
21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
22 | * | ||
23 | */ | ||
24 | |||
25 | #include <linux/module.h> | ||
26 | #include <linux/init.h> | ||
27 | #include <linux/slab.h> | ||
28 | #include <linux/err.h> | ||
29 | #include <linux/platform_device.h> | ||
30 | #include <linux/regulator/driver.h> | ||
31 | #include <linux/regulator/machine.h> | ||
32 | #include <linux/gpio.h> | ||
33 | #include <linux/mfd/rc5t583.h> | ||
34 | |||
35 | struct rc5t583_regulator_info { | ||
36 | int deepsleep_id; | ||
37 | |||
38 | /* Regulator register address.*/ | ||
39 | uint8_t reg_disc_reg; | ||
40 | uint8_t disc_bit; | ||
41 | uint8_t deepsleep_reg; | ||
42 | |||
43 | /* Regulator specific turn-on delay and voltage settling time*/ | ||
44 | int enable_uv_per_us; | ||
45 | int change_uv_per_us; | ||
46 | |||
47 | /* Used by regulator core */ | ||
48 | struct regulator_desc desc; | ||
49 | }; | ||
50 | |||
51 | struct rc5t583_regulator { | ||
52 | struct rc5t583_regulator_info *reg_info; | ||
53 | |||
54 | /* Devices */ | ||
55 | struct device *dev; | ||
56 | struct rc5t583 *mfd; | ||
57 | struct regulator_dev *rdev; | ||
58 | }; | ||
59 | |||
60 | static int rc5t583_regulator_enable_time(struct regulator_dev *rdev) | ||
61 | { | ||
62 | struct rc5t583_regulator *reg = rdev_get_drvdata(rdev); | ||
63 | int vsel = regulator_get_voltage_sel_regmap(rdev); | ||
64 | int curr_uV = regulator_list_voltage_linear(rdev, vsel); | ||
65 | |||
66 | return DIV_ROUND_UP(curr_uV, reg->reg_info->enable_uv_per_us); | ||
67 | } | ||
68 | |||
69 | static int rc5t583_set_voltage_time_sel(struct regulator_dev *rdev, | ||
70 | unsigned int old_selector, unsigned int new_selector) | ||
71 | { | ||
72 | struct rc5t583_regulator *reg = rdev_get_drvdata(rdev); | ||
73 | int old_uV, new_uV; | ||
74 | old_uV = regulator_list_voltage_linear(rdev, old_selector); | ||
75 | |||
76 | if (old_uV < 0) | ||
77 | return old_uV; | ||
78 | |||
79 | new_uV = regulator_list_voltage_linear(rdev, new_selector); | ||
80 | if (new_uV < 0) | ||
81 | return new_uV; | ||
82 | |||
83 | return DIV_ROUND_UP(abs(old_uV - new_uV), | ||
84 | reg->reg_info->change_uv_per_us); | ||
85 | } | ||
86 | |||
87 | |||
88 | static struct regulator_ops rc5t583_ops = { | ||
89 | .is_enabled = regulator_is_enabled_regmap, | ||
90 | .enable = regulator_enable_regmap, | ||
91 | .disable = regulator_disable_regmap, | ||
92 | .enable_time = rc5t583_regulator_enable_time, | ||
93 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | ||
94 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | ||
95 | .list_voltage = regulator_list_voltage_linear, | ||
96 | .map_voltage = regulator_map_voltage_linear, | ||
97 | .set_voltage_time_sel = rc5t583_set_voltage_time_sel, | ||
98 | }; | ||
99 | |||
100 | #define RC5T583_REG(_id, _en_reg, _en_bit, _disc_reg, _disc_bit, \ | ||
101 | _vout_mask, _min_mv, _max_mv, _step_uV, _enable_mv) \ | ||
102 | { \ | ||
103 | .reg_disc_reg = RC5T583_REG_##_disc_reg, \ | ||
104 | .disc_bit = _disc_bit, \ | ||
105 | .deepsleep_reg = RC5T583_REG_##_id##DAC_DS, \ | ||
106 | .enable_uv_per_us = _enable_mv * 1000, \ | ||
107 | .change_uv_per_us = 40 * 1000, \ | ||
108 | .deepsleep_id = RC5T583_DS_##_id, \ | ||
109 | .desc = { \ | ||
110 | .name = "rc5t583-regulator-"#_id, \ | ||
111 | .id = RC5T583_REGULATOR_##_id, \ | ||
112 | .n_voltages = (_max_mv - _min_mv) * 1000 / _step_uV + 1, \ | ||
113 | .ops = &rc5t583_ops, \ | ||
114 | .type = REGULATOR_VOLTAGE, \ | ||
115 | .owner = THIS_MODULE, \ | ||
116 | .vsel_reg = RC5T583_REG_##_id##DAC, \ | ||
117 | .vsel_mask = _vout_mask, \ | ||
118 | .enable_reg = RC5T583_REG_##_en_reg, \ | ||
119 | .enable_mask = BIT(_en_bit), \ | ||
120 | .min_uV = _min_mv * 1000, \ | ||
121 | .uV_step = _step_uV, \ | ||
122 | }, \ | ||
123 | } | ||
124 | |||
125 | static struct rc5t583_regulator_info rc5t583_reg_info[RC5T583_REGULATOR_MAX] = { | ||
126 | RC5T583_REG(DC0, DC0CTL, 0, DC0CTL, 1, 0x7F, 700, 1500, 12500, 4), | ||
127 | RC5T583_REG(DC1, DC1CTL, 0, DC1CTL, 1, 0x7F, 700, 1500, 12500, 14), | ||
128 | RC5T583_REG(DC2, DC2CTL, 0, DC2CTL, 1, 0x7F, 900, 2400, 12500, 14), | ||
129 | RC5T583_REG(DC3, DC3CTL, 0, DC3CTL, 1, 0x7F, 900, 2400, 12500, 14), | ||
130 | RC5T583_REG(LDO0, LDOEN2, 0, LDODIS2, 0, 0x7F, 900, 3400, 25000, 160), | ||
131 | RC5T583_REG(LDO1, LDOEN2, 1, LDODIS2, 1, 0x7F, 900, 3400, 25000, 160), | ||
132 | RC5T583_REG(LDO2, LDOEN2, 2, LDODIS2, 2, 0x7F, 900, 3400, 25000, 160), | ||
133 | RC5T583_REG(LDO3, LDOEN2, 3, LDODIS2, 3, 0x7F, 900, 3400, 25000, 160), | ||
134 | RC5T583_REG(LDO4, LDOEN2, 4, LDODIS2, 4, 0x3F, 750, 1500, 12500, 133), | ||
135 | RC5T583_REG(LDO5, LDOEN2, 5, LDODIS2, 5, 0x7F, 900, 3400, 25000, 267), | ||
136 | RC5T583_REG(LDO6, LDOEN2, 6, LDODIS2, 6, 0x7F, 900, 3400, 25000, 133), | ||
137 | RC5T583_REG(LDO7, LDOEN2, 7, LDODIS2, 7, 0x7F, 900, 3400, 25000, 233), | ||
138 | RC5T583_REG(LDO8, LDOEN1, 0, LDODIS1, 0, 0x7F, 900, 3400, 25000, 233), | ||
139 | RC5T583_REG(LDO9, LDOEN1, 1, LDODIS1, 1, 0x7F, 900, 3400, 25000, 133), | ||
140 | }; | ||
141 | |||
142 | static int __devinit rc5t583_regulator_probe(struct platform_device *pdev) | ||
143 | { | ||
144 | struct rc5t583 *rc5t583 = dev_get_drvdata(pdev->dev.parent); | ||
145 | struct rc5t583_platform_data *pdata = dev_get_platdata(rc5t583->dev); | ||
146 | struct regulator_init_data *reg_data; | ||
147 | struct regulator_config config = { }; | ||
148 | struct rc5t583_regulator *reg = NULL; | ||
149 | struct rc5t583_regulator *regs; | ||
150 | struct regulator_dev *rdev; | ||
151 | struct rc5t583_regulator_info *ri; | ||
152 | int ret; | ||
153 | int id; | ||
154 | |||
155 | if (!pdata) { | ||
156 | dev_err(&pdev->dev, "No platform data, exiting...\n"); | ||
157 | return -ENODEV; | ||
158 | } | ||
159 | |||
160 | regs = devm_kzalloc(&pdev->dev, RC5T583_REGULATOR_MAX * | ||
161 | sizeof(struct rc5t583_regulator), GFP_KERNEL); | ||
162 | if (!regs) { | ||
163 | dev_err(&pdev->dev, "Memory allocation failed exiting..\n"); | ||
164 | return -ENOMEM; | ||
165 | } | ||
166 | |||
167 | |||
168 | for (id = 0; id < RC5T583_REGULATOR_MAX; ++id) { | ||
169 | reg_data = pdata->reg_init_data[id]; | ||
170 | |||
171 | /* No need to register if there is no regulator data */ | ||
172 | if (!reg_data) | ||
173 | continue; | ||
174 | |||
175 | reg = ®s[id]; | ||
176 | ri = &rc5t583_reg_info[id]; | ||
177 | reg->reg_info = ri; | ||
178 | reg->mfd = rc5t583; | ||
179 | reg->dev = &pdev->dev; | ||
180 | |||
181 | if (ri->deepsleep_id == RC5T583_DS_NONE) | ||
182 | goto skip_ext_pwr_config; | ||
183 | |||
184 | ret = rc5t583_ext_power_req_config(rc5t583->dev, | ||
185 | ri->deepsleep_id, | ||
186 | pdata->regulator_ext_pwr_control[id], | ||
187 | pdata->regulator_deepsleep_slot[id]); | ||
188 | /* | ||
189 | * Configuring external control is not a major issue, | ||
190 | * just give warning. | ||
191 | */ | ||
192 | if (ret < 0) | ||
193 | dev_warn(&pdev->dev, | ||
194 | "Failed to configure ext control %d\n", id); | ||
195 | |||
196 | skip_ext_pwr_config: | ||
197 | config.dev = &pdev->dev; | ||
198 | config.init_data = reg_data; | ||
199 | config.driver_data = reg; | ||
200 | config.regmap = rc5t583->regmap; | ||
201 | |||
202 | rdev = regulator_register(&ri->desc, &config); | ||
203 | if (IS_ERR(rdev)) { | ||
204 | dev_err(&pdev->dev, "Failed to register regulator %s\n", | ||
205 | ri->desc.name); | ||
206 | ret = PTR_ERR(rdev); | ||
207 | goto clean_exit; | ||
208 | } | ||
209 | reg->rdev = rdev; | ||
210 | } | ||
211 | platform_set_drvdata(pdev, regs); | ||
212 | return 0; | ||
213 | |||
214 | clean_exit: | ||
215 | while (--id >= 0) | ||
216 | regulator_unregister(regs[id].rdev); | ||
217 | |||
218 | return ret; | ||
219 | } | ||
220 | |||
221 | static int __devexit rc5t583_regulator_remove(struct platform_device *pdev) | ||
222 | { | ||
223 | struct rc5t583_regulator *regs = platform_get_drvdata(pdev); | ||
224 | int id; | ||
225 | |||
226 | for (id = 0; id < RC5T583_REGULATOR_MAX; ++id) | ||
227 | regulator_unregister(regs[id].rdev); | ||
228 | return 0; | ||
229 | } | ||
230 | |||
231 | static struct platform_driver rc5t583_regulator_driver = { | ||
232 | .driver = { | ||
233 | .name = "rc5t583-regulator", | ||
234 | .owner = THIS_MODULE, | ||
235 | }, | ||
236 | .probe = rc5t583_regulator_probe, | ||
237 | .remove = __devexit_p(rc5t583_regulator_remove), | ||
238 | }; | ||
239 | |||
240 | static int __init rc5t583_regulator_init(void) | ||
241 | { | ||
242 | return platform_driver_register(&rc5t583_regulator_driver); | ||
243 | } | ||
244 | subsys_initcall(rc5t583_regulator_init); | ||
245 | |||
246 | static void __exit rc5t583_regulator_exit(void) | ||
247 | { | ||
248 | platform_driver_unregister(&rc5t583_regulator_driver); | ||
249 | } | ||
250 | module_exit(rc5t583_regulator_exit); | ||
251 | |||
252 | MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>"); | ||
253 | MODULE_DESCRIPTION("RC5T583 regulator driver"); | ||
254 | MODULE_ALIAS("platform:rc5t583-regulator"); | ||
255 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c index 4ca2db059004..290d6fc01029 100644 --- a/drivers/regulator/s5m8767.c +++ b/drivers/regulator/s5m8767.c | |||
@@ -12,7 +12,6 @@ | |||
12 | */ | 12 | */ |
13 | 13 | ||
14 | #include <linux/bug.h> | 14 | #include <linux/bug.h> |
15 | #include <linux/delay.h> | ||
16 | #include <linux/err.h> | 15 | #include <linux/err.h> |
17 | #include <linux/gpio.h> | 16 | #include <linux/gpio.h> |
18 | #include <linux/slab.h> | 17 | #include <linux/slab.h> |
@@ -28,6 +27,7 @@ struct s5m8767_info { | |||
28 | struct s5m87xx_dev *iodev; | 27 | struct s5m87xx_dev *iodev; |
29 | int num_regulators; | 28 | int num_regulators; |
30 | struct regulator_dev **rdev; | 29 | struct regulator_dev **rdev; |
30 | struct s5m_opmode_data *opmode; | ||
31 | 31 | ||
32 | int ramp_delay; | 32 | int ramp_delay; |
33 | bool buck2_ramp; | 33 | bool buck2_ramp; |
@@ -141,9 +141,56 @@ static int s5m8767_list_voltage(struct regulator_dev *rdev, | |||
141 | return val; | 141 | return val; |
142 | } | 142 | } |
143 | 143 | ||
144 | static int s5m8767_get_register(struct regulator_dev *rdev, int *reg) | 144 | static unsigned int s5m8767_opmode_reg[][4] = { |
145 | /* {OFF, ON, LOWPOWER, SUSPEND} */ | ||
146 | /* LDO1 ... LDO28 */ | ||
147 | {0x0, 0x3, 0x2, 0x1}, /* LDO1 */ | ||
148 | {0x0, 0x3, 0x2, 0x1}, | ||
149 | {0x0, 0x3, 0x2, 0x1}, | ||
150 | {0x0, 0x0, 0x0, 0x0}, | ||
151 | {0x0, 0x3, 0x2, 0x1}, /* LDO5 */ | ||
152 | {0x0, 0x3, 0x2, 0x1}, | ||
153 | {0x0, 0x3, 0x2, 0x1}, | ||
154 | {0x0, 0x3, 0x2, 0x1}, | ||
155 | {0x0, 0x3, 0x2, 0x1}, | ||
156 | {0x0, 0x3, 0x2, 0x1}, /* LDO10 */ | ||
157 | {0x0, 0x3, 0x2, 0x1}, | ||
158 | {0x0, 0x3, 0x2, 0x1}, | ||
159 | {0x0, 0x3, 0x2, 0x1}, | ||
160 | {0x0, 0x3, 0x2, 0x1}, | ||
161 | {0x0, 0x3, 0x2, 0x1}, /* LDO15 */ | ||
162 | {0x0, 0x3, 0x2, 0x1}, | ||
163 | {0x0, 0x3, 0x2, 0x1}, | ||
164 | {0x0, 0x0, 0x0, 0x0}, | ||
165 | {0x0, 0x3, 0x2, 0x1}, | ||
166 | {0x0, 0x3, 0x2, 0x1}, /* LDO20 */ | ||
167 | {0x0, 0x3, 0x2, 0x1}, | ||
168 | {0x0, 0x3, 0x2, 0x1}, | ||
169 | {0x0, 0x0, 0x0, 0x0}, | ||
170 | {0x0, 0x3, 0x2, 0x1}, | ||
171 | {0x0, 0x3, 0x2, 0x1}, /* LDO25 */ | ||
172 | {0x0, 0x3, 0x2, 0x1}, | ||
173 | {0x0, 0x3, 0x2, 0x1}, | ||
174 | {0x0, 0x3, 0x2, 0x1}, /* LDO28 */ | ||
175 | |||
176 | /* BUCK1 ... BUCK9 */ | ||
177 | {0x0, 0x3, 0x1, 0x1}, /* BUCK1 */ | ||
178 | {0x0, 0x3, 0x1, 0x1}, | ||
179 | {0x0, 0x3, 0x1, 0x1}, | ||
180 | {0x0, 0x3, 0x1, 0x1}, | ||
181 | {0x0, 0x3, 0x2, 0x1}, /* BUCK5 */ | ||
182 | {0x0, 0x3, 0x1, 0x1}, | ||
183 | {0x0, 0x3, 0x1, 0x1}, | ||
184 | {0x0, 0x3, 0x1, 0x1}, | ||
185 | {0x0, 0x3, 0x1, 0x1}, /* BUCK9 */ | ||
186 | }; | ||
187 | |||
188 | static int s5m8767_get_register(struct regulator_dev *rdev, int *reg, | ||
189 | int *enable_ctrl) | ||
145 | { | 190 | { |
146 | int reg_id = rdev_get_id(rdev); | 191 | int reg_id = rdev_get_id(rdev); |
192 | unsigned int mode; | ||
193 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); | ||
147 | 194 | ||
148 | switch (reg_id) { | 195 | switch (reg_id) { |
149 | case S5M8767_LDO1 ... S5M8767_LDO2: | 196 | case S5M8767_LDO1 ... S5M8767_LDO2: |
@@ -168,6 +215,8 @@ static int s5m8767_get_register(struct regulator_dev *rdev, int *reg) | |||
168 | return -EINVAL; | 215 | return -EINVAL; |
169 | } | 216 | } |
170 | 217 | ||
218 | mode = s5m8767->opmode[reg_id].mode; | ||
219 | *enable_ctrl = s5m8767_opmode_reg[reg_id][mode] << S5M8767_ENCTRL_SHIFT; | ||
171 | return 0; | 220 | return 0; |
172 | } | 221 | } |
173 | 222 | ||
@@ -175,10 +224,10 @@ static int s5m8767_reg_is_enabled(struct regulator_dev *rdev) | |||
175 | { | 224 | { |
176 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); | 225 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); |
177 | int ret, reg; | 226 | int ret, reg; |
178 | int mask = 0xc0, pattern = 0xc0; | 227 | int mask = 0xc0, enable_ctrl; |
179 | u8 val; | 228 | u8 val; |
180 | 229 | ||
181 | ret = s5m8767_get_register(rdev, ®); | 230 | ret = s5m8767_get_register(rdev, ®, &enable_ctrl); |
182 | if (ret == -EINVAL) | 231 | if (ret == -EINVAL) |
183 | return 1; | 232 | return 1; |
184 | else if (ret) | 233 | else if (ret) |
@@ -188,33 +237,33 @@ static int s5m8767_reg_is_enabled(struct regulator_dev *rdev) | |||
188 | if (ret) | 237 | if (ret) |
189 | return ret; | 238 | return ret; |
190 | 239 | ||
191 | return (val & mask) == pattern; | 240 | return (val & mask) == enable_ctrl; |
192 | } | 241 | } |
193 | 242 | ||
194 | static int s5m8767_reg_enable(struct regulator_dev *rdev) | 243 | static int s5m8767_reg_enable(struct regulator_dev *rdev) |
195 | { | 244 | { |
196 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); | 245 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); |
197 | int ret, reg; | 246 | int ret, reg; |
198 | int mask = 0xc0, pattern = 0xc0; | 247 | int mask = 0xc0, enable_ctrl; |
199 | 248 | ||
200 | ret = s5m8767_get_register(rdev, ®); | 249 | ret = s5m8767_get_register(rdev, ®, &enable_ctrl); |
201 | if (ret) | 250 | if (ret) |
202 | return ret; | 251 | return ret; |
203 | 252 | ||
204 | return s5m_reg_update(s5m8767->iodev, reg, pattern, mask); | 253 | return s5m_reg_update(s5m8767->iodev, reg, enable_ctrl, mask); |
205 | } | 254 | } |
206 | 255 | ||
207 | static int s5m8767_reg_disable(struct regulator_dev *rdev) | 256 | static int s5m8767_reg_disable(struct regulator_dev *rdev) |
208 | { | 257 | { |
209 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); | 258 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); |
210 | int ret, reg; | 259 | int ret, reg; |
211 | int mask = 0xc0, pattern = 0xc0; | 260 | int mask = 0xc0, enable_ctrl; |
212 | 261 | ||
213 | ret = s5m8767_get_register(rdev, ®); | 262 | ret = s5m8767_get_register(rdev, ®, &enable_ctrl); |
214 | if (ret) | 263 | if (ret) |
215 | return ret; | 264 | return ret; |
216 | 265 | ||
217 | return s5m_reg_update(s5m8767->iodev, reg, ~pattern, mask); | 266 | return s5m_reg_update(s5m8767->iodev, reg, ~mask, mask); |
218 | } | 267 | } |
219 | 268 | ||
220 | static int s5m8767_get_voltage_register(struct regulator_dev *rdev, int *_reg) | 269 | static int s5m8767_get_voltage_register(struct regulator_dev *rdev, int *_reg) |
@@ -297,7 +346,10 @@ static int s5m8767_convert_voltage_to_sel( | |||
297 | if (max_vol < desc->min || min_vol > desc->max) | 346 | if (max_vol < desc->min || min_vol > desc->max) |
298 | return -EINVAL; | 347 | return -EINVAL; |
299 | 348 | ||
300 | selector = (min_vol - desc->min) / desc->step; | 349 | if (min_vol < desc->min) |
350 | min_vol = desc->min; | ||
351 | |||
352 | selector = DIV_ROUND_UP(min_vol - desc->min, desc->step); | ||
301 | 353 | ||
302 | if (desc->min + desc->step * selector > max_vol) | 354 | if (desc->min + desc->step * selector > max_vol) |
303 | return -EINVAL; | 355 | return -EINVAL; |
@@ -305,14 +357,33 @@ static int s5m8767_convert_voltage_to_sel( | |||
305 | return selector; | 357 | return selector; |
306 | } | 358 | } |
307 | 359 | ||
360 | static inline void s5m8767_set_high(struct s5m8767_info *s5m8767) | ||
361 | { | ||
362 | int temp_index = s5m8767->buck_gpioindex; | ||
363 | |||
364 | gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1); | ||
365 | gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1); | ||
366 | gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1); | ||
367 | } | ||
368 | |||
369 | static inline void s5m8767_set_low(struct s5m8767_info *s5m8767) | ||
370 | { | ||
371 | int temp_index = s5m8767->buck_gpioindex; | ||
372 | |||
373 | gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1); | ||
374 | gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1); | ||
375 | gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1); | ||
376 | } | ||
377 | |||
308 | static int s5m8767_set_voltage(struct regulator_dev *rdev, | 378 | static int s5m8767_set_voltage(struct regulator_dev *rdev, |
309 | int min_uV, int max_uV, unsigned *selector) | 379 | int min_uV, int max_uV, unsigned *selector) |
310 | { | 380 | { |
311 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); | 381 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); |
312 | const struct s5m_voltage_desc *desc; | 382 | const struct s5m_voltage_desc *desc; |
313 | int reg_id = rdev_get_id(rdev); | 383 | int reg_id = rdev_get_id(rdev); |
314 | int sel, reg, mask, ret; | 384 | int sel, reg, mask, ret = 0, old_index, index = 0; |
315 | u8 val; | 385 | u8 val; |
386 | u8 *buck234_vol = NULL; | ||
316 | 387 | ||
317 | switch (reg_id) { | 388 | switch (reg_id) { |
318 | case S5M8767_LDO1 ... S5M8767_LDO28: | 389 | case S5M8767_LDO1 ... S5M8767_LDO28: |
@@ -320,6 +391,12 @@ static int s5m8767_set_voltage(struct regulator_dev *rdev, | |||
320 | break; | 391 | break; |
321 | case S5M8767_BUCK1 ... S5M8767_BUCK6: | 392 | case S5M8767_BUCK1 ... S5M8767_BUCK6: |
322 | mask = 0xff; | 393 | mask = 0xff; |
394 | if (reg_id == S5M8767_BUCK2 && s5m8767->buck2_gpiodvs) | ||
395 | buck234_vol = &s5m8767->buck2_vol[0]; | ||
396 | else if (reg_id == S5M8767_BUCK3 && s5m8767->buck3_gpiodvs) | ||
397 | buck234_vol = &s5m8767->buck3_vol[0]; | ||
398 | else if (reg_id == S5M8767_BUCK4 && s5m8767->buck4_gpiodvs) | ||
399 | buck234_vol = &s5m8767->buck4_vol[0]; | ||
323 | break; | 400 | break; |
324 | case S5M8767_BUCK7 ... S5M8767_BUCK8: | 401 | case S5M8767_BUCK7 ... S5M8767_BUCK8: |
325 | return -EINVAL; | 402 | return -EINVAL; |
@@ -336,102 +413,32 @@ static int s5m8767_set_voltage(struct regulator_dev *rdev, | |||
336 | if (sel < 0) | 413 | if (sel < 0) |
337 | return sel; | 414 | return sel; |
338 | 415 | ||
339 | ret = s5m8767_get_voltage_register(rdev, ®); | 416 | /* buck234_vol != NULL means to control buck234 voltage via DVS GPIO */ |
340 | if (ret) | 417 | if (buck234_vol) { |
341 | return ret; | 418 | while (*buck234_vol != sel) { |
342 | 419 | buck234_vol++; | |
343 | s5m_reg_read(s5m8767->iodev, reg, &val); | 420 | index++; |
344 | val &= ~mask; | 421 | } |
345 | val |= sel; | 422 | old_index = s5m8767->buck_gpioindex; |
346 | 423 | s5m8767->buck_gpioindex = index; | |
347 | ret = s5m_reg_write(s5m8767->iodev, reg, val); | 424 | |
348 | *selector = sel; | 425 | if (index > old_index) |
349 | 426 | s5m8767_set_high(s5m8767); | |
350 | return ret; | 427 | else |
351 | } | 428 | s5m8767_set_low(s5m8767); |
352 | 429 | } else { | |
353 | static inline void s5m8767_set_high(struct s5m8767_info *s5m8767) | 430 | ret = s5m8767_get_voltage_register(rdev, ®); |
354 | { | 431 | if (ret) |
355 | int temp_index = s5m8767->buck_gpioindex; | 432 | return ret; |
356 | |||
357 | gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1); | ||
358 | gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1); | ||
359 | gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1); | ||
360 | } | ||
361 | |||
362 | static inline void s5m8767_set_low(struct s5m8767_info *s5m8767) | ||
363 | { | ||
364 | int temp_index = s5m8767->buck_gpioindex; | ||
365 | |||
366 | gpio_set_value(s5m8767->buck_gpios[2], temp_index & 0x1); | ||
367 | gpio_set_value(s5m8767->buck_gpios[1], (temp_index >> 1) & 0x1); | ||
368 | gpio_set_value(s5m8767->buck_gpios[0], (temp_index >> 2) & 0x1); | ||
369 | } | ||
370 | |||
371 | static int s5m8767_set_voltage_buck(struct regulator_dev *rdev, | ||
372 | int min_uV, int max_uV, unsigned *selector) | ||
373 | { | ||
374 | struct s5m8767_info *s5m8767 = rdev_get_drvdata(rdev); | ||
375 | int reg_id = rdev_get_id(rdev); | ||
376 | const struct s5m_voltage_desc *desc; | ||
377 | int new_val, old_val, i = 0; | ||
378 | |||
379 | if (reg_id < S5M8767_BUCK1 || reg_id > S5M8767_BUCK6) | ||
380 | return -EINVAL; | ||
381 | |||
382 | switch (reg_id) { | ||
383 | case S5M8767_BUCK1: | ||
384 | return s5m8767_set_voltage(rdev, min_uV, max_uV, selector); | ||
385 | case S5M8767_BUCK2 ... S5M8767_BUCK4: | ||
386 | break; | ||
387 | case S5M8767_BUCK5 ... S5M8767_BUCK6: | ||
388 | return s5m8767_set_voltage(rdev, min_uV, max_uV, selector); | ||
389 | case S5M8767_BUCK9: | ||
390 | return s5m8767_set_voltage(rdev, min_uV, max_uV, selector); | ||
391 | } | ||
392 | 433 | ||
393 | desc = reg_voltage_map[reg_id]; | 434 | s5m_reg_read(s5m8767->iodev, reg, &val); |
394 | new_val = s5m8767_convert_voltage_to_sel(desc, min_uV, max_uV); | 435 | val = (val & ~mask) | sel; |
395 | if (new_val < 0) | ||
396 | return new_val; | ||
397 | 436 | ||
398 | switch (reg_id) { | 437 | ret = s5m_reg_write(s5m8767->iodev, reg, val); |
399 | case S5M8767_BUCK2: | ||
400 | if (s5m8767->buck2_gpiodvs) { | ||
401 | while (s5m8767->buck2_vol[i] != new_val) | ||
402 | i++; | ||
403 | } else | ||
404 | return s5m8767_set_voltage(rdev, min_uV, | ||
405 | max_uV, selector); | ||
406 | break; | ||
407 | case S5M8767_BUCK3: | ||
408 | if (s5m8767->buck3_gpiodvs) { | ||
409 | while (s5m8767->buck3_vol[i] != new_val) | ||
410 | i++; | ||
411 | } else | ||
412 | return s5m8767_set_voltage(rdev, min_uV, | ||
413 | max_uV, selector); | ||
414 | break; | ||
415 | case S5M8767_BUCK4: | ||
416 | if (s5m8767->buck3_gpiodvs) { | ||
417 | while (s5m8767->buck4_vol[i] != new_val) | ||
418 | i++; | ||
419 | } else | ||
420 | return s5m8767_set_voltage(rdev, min_uV, | ||
421 | max_uV, selector); | ||
422 | break; | ||
423 | } | 438 | } |
424 | 439 | ||
425 | old_val = s5m8767->buck_gpioindex; | 440 | *selector = sel; |
426 | s5m8767->buck_gpioindex = i; | 441 | return ret; |
427 | |||
428 | if (i > old_val) | ||
429 | s5m8767_set_high(s5m8767); | ||
430 | else | ||
431 | s5m8767_set_low(s5m8767); | ||
432 | |||
433 | *selector = new_val; | ||
434 | return 0; | ||
435 | } | 442 | } |
436 | 443 | ||
437 | static int s5m8767_set_voltage_time_sel(struct regulator_dev *rdev, | 444 | static int s5m8767_set_voltage_time_sel(struct regulator_dev *rdev, |
@@ -450,7 +457,7 @@ static int s5m8767_set_voltage_time_sel(struct regulator_dev *rdev, | |||
450 | return 0; | 457 | return 0; |
451 | } | 458 | } |
452 | 459 | ||
453 | static struct regulator_ops s5m8767_ldo_ops = { | 460 | static struct regulator_ops s5m8767_ops = { |
454 | .list_voltage = s5m8767_list_voltage, | 461 | .list_voltage = s5m8767_list_voltage, |
455 | .is_enabled = s5m8767_reg_is_enabled, | 462 | .is_enabled = s5m8767_reg_is_enabled, |
456 | .enable = s5m8767_reg_enable, | 463 | .enable = s5m8767_reg_enable, |
@@ -460,75 +467,59 @@ static struct regulator_ops s5m8767_ldo_ops = { | |||
460 | .set_voltage_time_sel = s5m8767_set_voltage_time_sel, | 467 | .set_voltage_time_sel = s5m8767_set_voltage_time_sel, |
461 | }; | 468 | }; |
462 | 469 | ||
463 | static struct regulator_ops s5m8767_buck_ops = { | 470 | #define s5m8767_regulator_desc(_name) { \ |
464 | .list_voltage = s5m8767_list_voltage, | 471 | .name = #_name, \ |
465 | .is_enabled = s5m8767_reg_is_enabled, | 472 | .id = S5M8767_##_name, \ |
466 | .enable = s5m8767_reg_enable, | 473 | .ops = &s5m8767_ops, \ |
467 | .disable = s5m8767_reg_disable, | ||
468 | .get_voltage_sel = s5m8767_get_voltage_sel, | ||
469 | .set_voltage = s5m8767_set_voltage_buck, | ||
470 | .set_voltage_time_sel = s5m8767_set_voltage_time_sel, | ||
471 | }; | ||
472 | |||
473 | #define regulator_desc_ldo(num) { \ | ||
474 | .name = "LDO"#num, \ | ||
475 | .id = S5M8767_LDO##num, \ | ||
476 | .ops = &s5m8767_ldo_ops, \ | ||
477 | .type = REGULATOR_VOLTAGE, \ | ||
478 | .owner = THIS_MODULE, \ | ||
479 | } | ||
480 | #define regulator_desc_buck(num) { \ | ||
481 | .name = "BUCK"#num, \ | ||
482 | .id = S5M8767_BUCK##num, \ | ||
483 | .ops = &s5m8767_buck_ops, \ | ||
484 | .type = REGULATOR_VOLTAGE, \ | 474 | .type = REGULATOR_VOLTAGE, \ |
485 | .owner = THIS_MODULE, \ | 475 | .owner = THIS_MODULE, \ |
486 | } | 476 | } |
487 | 477 | ||
488 | static struct regulator_desc regulators[] = { | 478 | static struct regulator_desc regulators[] = { |
489 | regulator_desc_ldo(1), | 479 | s5m8767_regulator_desc(LDO1), |
490 | regulator_desc_ldo(2), | 480 | s5m8767_regulator_desc(LDO2), |
491 | regulator_desc_ldo(3), | 481 | s5m8767_regulator_desc(LDO3), |
492 | regulator_desc_ldo(4), | 482 | s5m8767_regulator_desc(LDO4), |
493 | regulator_desc_ldo(5), | 483 | s5m8767_regulator_desc(LDO5), |
494 | regulator_desc_ldo(6), | 484 | s5m8767_regulator_desc(LDO6), |
495 | regulator_desc_ldo(7), | 485 | s5m8767_regulator_desc(LDO7), |
496 | regulator_desc_ldo(8), | 486 | s5m8767_regulator_desc(LDO8), |
497 | regulator_desc_ldo(9), | 487 | s5m8767_regulator_desc(LDO9), |
498 | regulator_desc_ldo(10), | 488 | s5m8767_regulator_desc(LDO10), |
499 | regulator_desc_ldo(11), | 489 | s5m8767_regulator_desc(LDO11), |
500 | regulator_desc_ldo(12), | 490 | s5m8767_regulator_desc(LDO12), |
501 | regulator_desc_ldo(13), | 491 | s5m8767_regulator_desc(LDO13), |
502 | regulator_desc_ldo(14), | 492 | s5m8767_regulator_desc(LDO14), |
503 | regulator_desc_ldo(15), | 493 | s5m8767_regulator_desc(LDO15), |
504 | regulator_desc_ldo(16), | 494 | s5m8767_regulator_desc(LDO16), |
505 | regulator_desc_ldo(17), | 495 | s5m8767_regulator_desc(LDO17), |
506 | regulator_desc_ldo(18), | 496 | s5m8767_regulator_desc(LDO18), |
507 | regulator_desc_ldo(19), | 497 | s5m8767_regulator_desc(LDO19), |
508 | regulator_desc_ldo(20), | 498 | s5m8767_regulator_desc(LDO20), |
509 | regulator_desc_ldo(21), | 499 | s5m8767_regulator_desc(LDO21), |
510 | regulator_desc_ldo(22), | 500 | s5m8767_regulator_desc(LDO22), |
511 | regulator_desc_ldo(23), | 501 | s5m8767_regulator_desc(LDO23), |
512 | regulator_desc_ldo(24), | 502 | s5m8767_regulator_desc(LDO24), |
513 | regulator_desc_ldo(25), | 503 | s5m8767_regulator_desc(LDO25), |
514 | regulator_desc_ldo(26), | 504 | s5m8767_regulator_desc(LDO26), |
515 | regulator_desc_ldo(27), | 505 | s5m8767_regulator_desc(LDO27), |
516 | regulator_desc_ldo(28), | 506 | s5m8767_regulator_desc(LDO28), |
517 | regulator_desc_buck(1), | 507 | s5m8767_regulator_desc(BUCK1), |
518 | regulator_desc_buck(2), | 508 | s5m8767_regulator_desc(BUCK2), |
519 | regulator_desc_buck(3), | 509 | s5m8767_regulator_desc(BUCK3), |
520 | regulator_desc_buck(4), | 510 | s5m8767_regulator_desc(BUCK4), |
521 | regulator_desc_buck(5), | 511 | s5m8767_regulator_desc(BUCK5), |
522 | regulator_desc_buck(6), | 512 | s5m8767_regulator_desc(BUCK6), |
523 | regulator_desc_buck(7), | 513 | s5m8767_regulator_desc(BUCK7), |
524 | regulator_desc_buck(8), | 514 | s5m8767_regulator_desc(BUCK8), |
525 | regulator_desc_buck(9), | 515 | s5m8767_regulator_desc(BUCK9), |
526 | }; | 516 | }; |
527 | 517 | ||
528 | static __devinit int s5m8767_pmic_probe(struct platform_device *pdev) | 518 | static __devinit int s5m8767_pmic_probe(struct platform_device *pdev) |
529 | { | 519 | { |
530 | struct s5m87xx_dev *iodev = dev_get_drvdata(pdev->dev.parent); | 520 | struct s5m87xx_dev *iodev = dev_get_drvdata(pdev->dev.parent); |
531 | struct s5m_platform_data *pdata = dev_get_platdata(iodev->dev); | 521 | struct s5m_platform_data *pdata = dev_get_platdata(iodev->dev); |
522 | struct regulator_config config = { }; | ||
532 | struct regulator_dev **rdev; | 523 | struct regulator_dev **rdev; |
533 | struct s5m8767_info *s5m8767; | 524 | struct s5m8767_info *s5m8767; |
534 | int i, ret, size; | 525 | int i, ret, size; |
@@ -586,6 +577,7 @@ static __devinit int s5m8767_pmic_probe(struct platform_device *pdev) | |||
586 | s5m8767->buck2_ramp = pdata->buck2_ramp_enable; | 577 | s5m8767->buck2_ramp = pdata->buck2_ramp_enable; |
587 | s5m8767->buck3_ramp = pdata->buck3_ramp_enable; | 578 | s5m8767->buck3_ramp = pdata->buck3_ramp_enable; |
588 | s5m8767->buck4_ramp = pdata->buck4_ramp_enable; | 579 | s5m8767->buck4_ramp = pdata->buck4_ramp_enable; |
580 | s5m8767->opmode = pdata->opmode; | ||
589 | 581 | ||
590 | for (i = 0; i < 8; i++) { | 582 | for (i = 0; i < 8; i++) { |
591 | if (s5m8767->buck2_gpiodvs) { | 583 | if (s5m8767->buck2_gpiodvs) { |
@@ -723,8 +715,11 @@ static __devinit int s5m8767_pmic_probe(struct platform_device *pdev) | |||
723 | regulators[id].n_voltages = | 715 | regulators[id].n_voltages = |
724 | (desc->max - desc->min) / desc->step + 1; | 716 | (desc->max - desc->min) / desc->step + 1; |
725 | 717 | ||
726 | rdev[i] = regulator_register(®ulators[id], s5m8767->dev, | 718 | config.dev = s5m8767->dev; |
727 | pdata->regulators[i].initdata, s5m8767, NULL); | 719 | config.init_data = pdata->regulators[i].initdata; |
720 | config.driver_data = s5m8767; | ||
721 | |||
722 | rdev[i] = regulator_register(®ulators[id], &config); | ||
728 | if (IS_ERR(rdev[i])) { | 723 | if (IS_ERR(rdev[i])) { |
729 | ret = PTR_ERR(rdev[i]); | 724 | ret = PTR_ERR(rdev[i]); |
730 | dev_err(s5m8767->dev, "regulator init failed for %d\n", | 725 | dev_err(s5m8767->dev, "regulator init failed for %d\n", |
diff --git a/drivers/regulator/tps6105x-regulator.c b/drivers/regulator/tps6105x-regulator.c index d9278da18a9e..d840d8440a91 100644 --- a/drivers/regulator/tps6105x-regulator.c +++ b/drivers/regulator/tps6105x-regulator.c | |||
@@ -123,7 +123,7 @@ static struct regulator_ops tps6105x_regulator_ops = { | |||
123 | .list_voltage = tps6105x_regulator_list_voltage, | 123 | .list_voltage = tps6105x_regulator_list_voltage, |
124 | }; | 124 | }; |
125 | 125 | ||
126 | static struct regulator_desc tps6105x_regulator_desc = { | 126 | static const struct regulator_desc tps6105x_regulator_desc = { |
127 | .name = "tps6105x-boost", | 127 | .name = "tps6105x-boost", |
128 | .ops = &tps6105x_regulator_ops, | 128 | .ops = &tps6105x_regulator_ops, |
129 | .type = REGULATOR_VOLTAGE, | 129 | .type = REGULATOR_VOLTAGE, |
@@ -139,6 +139,7 @@ static int __devinit tps6105x_regulator_probe(struct platform_device *pdev) | |||
139 | { | 139 | { |
140 | struct tps6105x *tps6105x = dev_get_platdata(&pdev->dev); | 140 | struct tps6105x *tps6105x = dev_get_platdata(&pdev->dev); |
141 | struct tps6105x_platform_data *pdata = tps6105x->pdata; | 141 | struct tps6105x_platform_data *pdata = tps6105x->pdata; |
142 | struct regulator_config config = { }; | ||
142 | int ret; | 143 | int ret; |
143 | 144 | ||
144 | /* This instance is not set for regulator mode so bail out */ | 145 | /* This instance is not set for regulator mode so bail out */ |
@@ -148,11 +149,13 @@ static int __devinit tps6105x_regulator_probe(struct platform_device *pdev) | |||
148 | return 0; | 149 | return 0; |
149 | } | 150 | } |
150 | 151 | ||
152 | config.dev = &tps6105x->client->dev; | ||
153 | config.init_data = pdata->regulator_data; | ||
154 | config.driver_data = tps6105x; | ||
155 | |||
151 | /* Register regulator with framework */ | 156 | /* Register regulator with framework */ |
152 | tps6105x->regulator = regulator_register(&tps6105x_regulator_desc, | 157 | tps6105x->regulator = regulator_register(&tps6105x_regulator_desc, |
153 | &tps6105x->client->dev, | 158 | &config); |
154 | pdata->regulator_data, tps6105x, | ||
155 | NULL); | ||
156 | if (IS_ERR(tps6105x->regulator)) { | 159 | if (IS_ERR(tps6105x->regulator)) { |
157 | ret = PTR_ERR(tps6105x->regulator); | 160 | ret = PTR_ERR(tps6105x->regulator); |
158 | dev_err(&tps6105x->client->dev, | 161 | dev_err(&tps6105x->client->dev, |
diff --git a/drivers/regulator/tps62360-regulator.c b/drivers/regulator/tps62360-regulator.c index e2ec73068ee2..e534269ed44a 100644 --- a/drivers/regulator/tps62360-regulator.c +++ b/drivers/regulator/tps62360-regulator.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * tps62360.c -- TI tps62360 | 2 | * tps62360.c -- TI tps62360 |
3 | * | 3 | * |
4 | * Driver for processor core supply tps62360 and tps62361B | 4 | * Driver for processor core supply tps62360, tps62361B, tps62362 and tps62363. |
5 | * | 5 | * |
6 | * Copyright (c) 2012, NVIDIA Corporation. | 6 | * Copyright (c) 2012, NVIDIA Corporation. |
7 | * | 7 | * |
@@ -26,13 +26,16 @@ | |||
26 | #include <linux/module.h> | 26 | #include <linux/module.h> |
27 | #include <linux/init.h> | 27 | #include <linux/init.h> |
28 | #include <linux/err.h> | 28 | #include <linux/err.h> |
29 | #include <linux/of.h> | ||
30 | #include <linux/of_device.h> | ||
31 | #include <linux/of_gpio.h> | ||
32 | #include <linux/regulator/of_regulator.h> | ||
29 | #include <linux/platform_device.h> | 33 | #include <linux/platform_device.h> |
30 | #include <linux/regulator/driver.h> | 34 | #include <linux/regulator/driver.h> |
31 | #include <linux/regulator/machine.h> | 35 | #include <linux/regulator/machine.h> |
32 | #include <linux/regulator/tps62360.h> | 36 | #include <linux/regulator/tps62360.h> |
33 | #include <linux/gpio.h> | 37 | #include <linux/gpio.h> |
34 | #include <linux/i2c.h> | 38 | #include <linux/i2c.h> |
35 | #include <linux/delay.h> | ||
36 | #include <linux/slab.h> | 39 | #include <linux/slab.h> |
37 | #include <linux/regmap.h> | 40 | #include <linux/regmap.h> |
38 | 41 | ||
@@ -46,20 +49,20 @@ | |||
46 | #define REG_RAMPCTRL 6 | 49 | #define REG_RAMPCTRL 6 |
47 | #define REG_CHIPID 8 | 50 | #define REG_CHIPID 8 |
48 | 51 | ||
49 | enum chips {TPS62360, TPS62361}; | 52 | #define FORCE_PWM_ENABLE BIT(7) |
50 | 53 | ||
51 | #define TPS62360_BASE_VOLTAGE 770 | 54 | enum chips {TPS62360, TPS62361, TPS62362, TPS62363}; |
55 | |||
56 | #define TPS62360_BASE_VOLTAGE 770000 | ||
52 | #define TPS62360_N_VOLTAGES 64 | 57 | #define TPS62360_N_VOLTAGES 64 |
53 | 58 | ||
54 | #define TPS62361_BASE_VOLTAGE 500 | 59 | #define TPS62361_BASE_VOLTAGE 500000 |
55 | #define TPS62361_N_VOLTAGES 128 | 60 | #define TPS62361_N_VOLTAGES 128 |
56 | 61 | ||
57 | /* tps 62360 chip information */ | 62 | /* tps 62360 chip information */ |
58 | struct tps62360_chip { | 63 | struct tps62360_chip { |
59 | const char *name; | ||
60 | struct device *dev; | 64 | struct device *dev; |
61 | struct regulator_desc desc; | 65 | struct regulator_desc desc; |
62 | struct i2c_client *client; | ||
63 | struct regulator_dev *rdev; | 66 | struct regulator_dev *rdev; |
64 | struct regmap *regmap; | 67 | struct regmap *regmap; |
65 | int chip_id; | 68 | int chip_id; |
@@ -68,12 +71,12 @@ struct tps62360_chip { | |||
68 | int voltage_base; | 71 | int voltage_base; |
69 | u8 voltage_reg_mask; | 72 | u8 voltage_reg_mask; |
70 | bool en_internal_pulldn; | 73 | bool en_internal_pulldn; |
71 | bool en_force_pwm; | ||
72 | bool en_discharge; | 74 | bool en_discharge; |
73 | bool valid_gpios; | 75 | bool valid_gpios; |
74 | int lru_index[4]; | 76 | int lru_index[4]; |
75 | int curr_vset_vsel[4]; | 77 | int curr_vset_vsel[4]; |
76 | int curr_vset_id; | 78 | int curr_vset_id; |
79 | int change_uv_per_us; | ||
77 | }; | 80 | }; |
78 | 81 | ||
79 | /* | 82 | /* |
@@ -99,6 +102,7 @@ static bool find_voltage_set_register(struct tps62360_chip *tps, | |||
99 | bool found = false; | 102 | bool found = false; |
100 | int new_vset_reg = tps->lru_index[3]; | 103 | int new_vset_reg = tps->lru_index[3]; |
101 | int found_index = 3; | 104 | int found_index = 3; |
105 | |||
102 | for (i = 0; i < 4; ++i) { | 106 | for (i = 0; i < 4; ++i) { |
103 | if (tps->curr_vset_vsel[tps->lru_index[i]] == req_vsel) { | 107 | if (tps->curr_vset_vsel[tps->lru_index[i]] == req_vsel) { |
104 | new_vset_reg = tps->lru_index[i]; | 108 | new_vset_reg = tps->lru_index[i]; |
@@ -117,7 +121,7 @@ update_lru_index: | |||
117 | return found; | 121 | return found; |
118 | } | 122 | } |
119 | 123 | ||
120 | static int tps62360_dcdc_get_voltage(struct regulator_dev *dev) | 124 | static int tps62360_dcdc_get_voltage_sel(struct regulator_dev *dev) |
121 | { | 125 | { |
122 | struct tps62360_chip *tps = rdev_get_drvdata(dev); | 126 | struct tps62360_chip *tps = rdev_get_drvdata(dev); |
123 | int vsel; | 127 | int vsel; |
@@ -126,196 +130,312 @@ static int tps62360_dcdc_get_voltage(struct regulator_dev *dev) | |||
126 | 130 | ||
127 | ret = regmap_read(tps->regmap, REG_VSET0 + tps->curr_vset_id, &data); | 131 | ret = regmap_read(tps->regmap, REG_VSET0 + tps->curr_vset_id, &data); |
128 | if (ret < 0) { | 132 | if (ret < 0) { |
129 | dev_err(tps->dev, "%s: Error in reading register %d\n", | 133 | dev_err(tps->dev, "%s(): register %d read failed with err %d\n", |
130 | __func__, REG_VSET0 + tps->curr_vset_id); | 134 | __func__, REG_VSET0 + tps->curr_vset_id, ret); |
131 | return ret; | 135 | return ret; |
132 | } | 136 | } |
133 | vsel = (int)data & tps->voltage_reg_mask; | 137 | vsel = (int)data & tps->voltage_reg_mask; |
134 | return (tps->voltage_base + vsel * 10) * 1000; | 138 | return vsel; |
135 | } | 139 | } |
136 | 140 | ||
137 | static int tps62360_dcdc_set_voltage(struct regulator_dev *dev, | 141 | static int tps62360_dcdc_set_voltage_sel(struct regulator_dev *dev, |
138 | int min_uV, int max_uV, unsigned *selector) | 142 | unsigned selector) |
139 | { | 143 | { |
140 | struct tps62360_chip *tps = rdev_get_drvdata(dev); | 144 | struct tps62360_chip *tps = rdev_get_drvdata(dev); |
141 | int vsel; | ||
142 | int ret; | 145 | int ret; |
143 | bool found = false; | 146 | bool found = false; |
144 | int new_vset_id = tps->curr_vset_id; | 147 | int new_vset_id = tps->curr_vset_id; |
145 | 148 | ||
146 | if (max_uV < min_uV) | ||
147 | return -EINVAL; | ||
148 | |||
149 | if (min_uV > | ||
150 | ((tps->voltage_base + (tps->desc.n_voltages - 1) * 10) * 1000)) | ||
151 | return -EINVAL; | ||
152 | |||
153 | if (max_uV < tps->voltage_base * 1000) | ||
154 | return -EINVAL; | ||
155 | |||
156 | vsel = DIV_ROUND_UP(min_uV - (tps->voltage_base * 1000), 10000); | ||
157 | if (selector) | ||
158 | *selector = (vsel & tps->voltage_reg_mask); | ||
159 | |||
160 | /* | 149 | /* |
161 | * If gpios are available to select the VSET register then least | 150 | * If gpios are available to select the VSET register then least |
162 | * recently used register for new configuration. | 151 | * recently used register for new configuration. |
163 | */ | 152 | */ |
164 | if (tps->valid_gpios) | 153 | if (tps->valid_gpios) |
165 | found = find_voltage_set_register(tps, vsel, &new_vset_id); | 154 | found = find_voltage_set_register(tps, selector, &new_vset_id); |
166 | 155 | ||
167 | if (!found) { | 156 | if (!found) { |
168 | ret = regmap_update_bits(tps->regmap, REG_VSET0 + new_vset_id, | 157 | ret = regmap_update_bits(tps->regmap, REG_VSET0 + new_vset_id, |
169 | tps->voltage_reg_mask, vsel); | 158 | tps->voltage_reg_mask, selector); |
170 | if (ret < 0) { | 159 | if (ret < 0) { |
171 | dev_err(tps->dev, "%s: Error in updating register %d\n", | 160 | dev_err(tps->dev, |
172 | __func__, REG_VSET0 + new_vset_id); | 161 | "%s(): register %d update failed with err %d\n", |
162 | __func__, REG_VSET0 + new_vset_id, ret); | ||
173 | return ret; | 163 | return ret; |
174 | } | 164 | } |
175 | tps->curr_vset_id = new_vset_id; | 165 | tps->curr_vset_id = new_vset_id; |
176 | tps->curr_vset_vsel[new_vset_id] = vsel; | 166 | tps->curr_vset_vsel[new_vset_id] = selector; |
177 | } | 167 | } |
178 | 168 | ||
179 | /* Select proper VSET register vio gpios */ | 169 | /* Select proper VSET register vio gpios */ |
180 | if (tps->valid_gpios) { | 170 | if (tps->valid_gpios) { |
181 | gpio_set_value_cansleep(tps->vsel0_gpio, | 171 | gpio_set_value_cansleep(tps->vsel0_gpio, new_vset_id & 0x1); |
182 | new_vset_id & 0x1); | ||
183 | gpio_set_value_cansleep(tps->vsel1_gpio, | 172 | gpio_set_value_cansleep(tps->vsel1_gpio, |
184 | (new_vset_id >> 1) & 0x1); | 173 | (new_vset_id >> 1) & 0x1); |
185 | } | 174 | } |
186 | return 0; | 175 | return 0; |
187 | } | 176 | } |
188 | 177 | ||
189 | static int tps62360_dcdc_list_voltage(struct regulator_dev *dev, | 178 | static int tps62360_set_voltage_time_sel(struct regulator_dev *rdev, |
190 | unsigned selector) | 179 | unsigned int old_selector, unsigned int new_selector) |
191 | { | 180 | { |
192 | struct tps62360_chip *tps = rdev_get_drvdata(dev); | 181 | struct tps62360_chip *tps = rdev_get_drvdata(rdev); |
182 | int old_uV, new_uV; | ||
193 | 183 | ||
194 | if (selector >= tps->desc.n_voltages) | 184 | old_uV = regulator_list_voltage_linear(rdev, old_selector); |
195 | return -EINVAL; | 185 | if (old_uV < 0) |
196 | return (tps->voltage_base + selector * 10) * 1000; | 186 | return old_uV; |
187 | |||
188 | new_uV = regulator_list_voltage_linear(rdev, new_selector); | ||
189 | if (new_uV < 0) | ||
190 | return new_uV; | ||
191 | |||
192 | return DIV_ROUND_UP(abs(old_uV - new_uV), tps->change_uv_per_us); | ||
197 | } | 193 | } |
198 | 194 | ||
199 | static struct regulator_ops tps62360_dcdc_ops = { | 195 | static int tps62360_set_mode(struct regulator_dev *rdev, unsigned int mode) |
200 | .get_voltage = tps62360_dcdc_get_voltage, | 196 | { |
201 | .set_voltage = tps62360_dcdc_set_voltage, | 197 | struct tps62360_chip *tps = rdev_get_drvdata(rdev); |
202 | .list_voltage = tps62360_dcdc_list_voltage, | 198 | int i; |
203 | }; | 199 | int val; |
200 | int ret; | ||
201 | |||
202 | /* Enable force PWM mode in FAST mode only. */ | ||
203 | switch (mode) { | ||
204 | case REGULATOR_MODE_FAST: | ||
205 | val = FORCE_PWM_ENABLE; | ||
206 | break; | ||
207 | |||
208 | case REGULATOR_MODE_NORMAL: | ||
209 | val = 0; | ||
210 | break; | ||
204 | 211 | ||
205 | static int tps62360_init_force_pwm(struct tps62360_chip *tps, | 212 | default: |
206 | struct tps62360_regulator_platform_data *pdata, | 213 | return -EINVAL; |
207 | int vset_id) | 214 | } |
215 | |||
216 | if (!tps->valid_gpios) { | ||
217 | ret = regmap_update_bits(tps->regmap, | ||
218 | REG_VSET0 + tps->curr_vset_id, FORCE_PWM_ENABLE, val); | ||
219 | if (ret < 0) | ||
220 | dev_err(tps->dev, | ||
221 | "%s(): register %d update failed with err %d\n", | ||
222 | __func__, REG_VSET0 + tps->curr_vset_id, ret); | ||
223 | return ret; | ||
224 | } | ||
225 | |||
226 | /* If gpios are valid then all register set need to be control */ | ||
227 | for (i = 0; i < 4; ++i) { | ||
228 | ret = regmap_update_bits(tps->regmap, | ||
229 | REG_VSET0 + i, FORCE_PWM_ENABLE, val); | ||
230 | if (ret < 0) { | ||
231 | dev_err(tps->dev, | ||
232 | "%s(): register %d update failed with err %d\n", | ||
233 | __func__, REG_VSET0 + i, ret); | ||
234 | return ret; | ||
235 | } | ||
236 | } | ||
237 | return ret; | ||
238 | } | ||
239 | |||
240 | static unsigned int tps62360_get_mode(struct regulator_dev *rdev) | ||
208 | { | 241 | { |
242 | struct tps62360_chip *tps = rdev_get_drvdata(rdev); | ||
209 | unsigned int data; | 243 | unsigned int data; |
210 | int ret; | 244 | int ret; |
211 | ret = regmap_read(tps->regmap, REG_VSET0 + vset_id, &data); | 245 | |
246 | ret = regmap_read(tps->regmap, REG_VSET0 + tps->curr_vset_id, &data); | ||
212 | if (ret < 0) { | 247 | if (ret < 0) { |
213 | dev_err(tps->dev, "%s() fails in writing reg %d\n", | 248 | dev_err(tps->dev, "%s(): register %d read failed with err %d\n", |
214 | __func__, REG_VSET0 + vset_id); | 249 | __func__, REG_VSET0 + tps->curr_vset_id, ret); |
215 | return ret; | 250 | return ret; |
216 | } | 251 | } |
217 | tps->curr_vset_vsel[vset_id] = data & tps->voltage_reg_mask; | 252 | return (data & FORCE_PWM_ENABLE) ? |
218 | if (pdata->en_force_pwm) | 253 | REGULATOR_MODE_FAST : REGULATOR_MODE_NORMAL; |
219 | data |= BIT(7); | ||
220 | else | ||
221 | data &= ~BIT(7); | ||
222 | ret = regmap_write(tps->regmap, REG_VSET0 + vset_id, data); | ||
223 | if (ret < 0) | ||
224 | dev_err(tps->dev, "%s() fails in writing reg %d\n", | ||
225 | __func__, REG_VSET0 + vset_id); | ||
226 | return ret; | ||
227 | } | 254 | } |
228 | 255 | ||
229 | static int tps62360_init_dcdc(struct tps62360_chip *tps, | 256 | static struct regulator_ops tps62360_dcdc_ops = { |
257 | .get_voltage_sel = tps62360_dcdc_get_voltage_sel, | ||
258 | .set_voltage_sel = tps62360_dcdc_set_voltage_sel, | ||
259 | .list_voltage = regulator_list_voltage_linear, | ||
260 | .map_voltage = regulator_map_voltage_linear, | ||
261 | .set_voltage_time_sel = tps62360_set_voltage_time_sel, | ||
262 | .set_mode = tps62360_set_mode, | ||
263 | .get_mode = tps62360_get_mode, | ||
264 | }; | ||
265 | |||
266 | static int __devinit tps62360_init_dcdc(struct tps62360_chip *tps, | ||
230 | struct tps62360_regulator_platform_data *pdata) | 267 | struct tps62360_regulator_platform_data *pdata) |
231 | { | 268 | { |
232 | int ret; | 269 | int ret; |
233 | int i; | 270 | unsigned int ramp_ctrl; |
234 | 271 | ||
235 | /* Initailize internal pull up/down control */ | 272 | /* Initialize internal pull up/down control */ |
236 | if (tps->en_internal_pulldn) | 273 | if (tps->en_internal_pulldn) |
237 | ret = regmap_write(tps->regmap, REG_CONTROL, 0xE0); | 274 | ret = regmap_write(tps->regmap, REG_CONTROL, 0xE0); |
238 | else | 275 | else |
239 | ret = regmap_write(tps->regmap, REG_CONTROL, 0x0); | 276 | ret = regmap_write(tps->regmap, REG_CONTROL, 0x0); |
240 | if (ret < 0) { | 277 | if (ret < 0) { |
241 | dev_err(tps->dev, "%s() fails in writing reg %d\n", | 278 | dev_err(tps->dev, |
242 | __func__, REG_CONTROL); | 279 | "%s(): register %d write failed with err %d\n", |
280 | __func__, REG_CONTROL, ret); | ||
243 | return ret; | 281 | return ret; |
244 | } | 282 | } |
245 | 283 | ||
246 | /* Initailize force PWM mode */ | ||
247 | if (tps->valid_gpios) { | ||
248 | for (i = 0; i < 4; ++i) { | ||
249 | ret = tps62360_init_force_pwm(tps, pdata, i); | ||
250 | if (ret < 0) | ||
251 | return ret; | ||
252 | } | ||
253 | } else { | ||
254 | ret = tps62360_init_force_pwm(tps, pdata, tps->curr_vset_id); | ||
255 | if (ret < 0) | ||
256 | return ret; | ||
257 | } | ||
258 | |||
259 | /* Reset output discharge path to reduce power consumption */ | 284 | /* Reset output discharge path to reduce power consumption */ |
260 | ret = regmap_update_bits(tps->regmap, REG_RAMPCTRL, BIT(2), 0); | 285 | ret = regmap_update_bits(tps->regmap, REG_RAMPCTRL, BIT(2), 0); |
261 | if (ret < 0) | 286 | if (ret < 0) { |
262 | dev_err(tps->dev, "%s() fails in updating reg %d\n", | 287 | dev_err(tps->dev, |
263 | __func__, REG_RAMPCTRL); | 288 | "%s(): register %d update failed with err %d\n", |
289 | __func__, REG_RAMPCTRL, ret); | ||
290 | return ret; | ||
291 | } | ||
292 | |||
293 | /* Get ramp value from ramp control register */ | ||
294 | ret = regmap_read(tps->regmap, REG_RAMPCTRL, &ramp_ctrl); | ||
295 | if (ret < 0) { | ||
296 | dev_err(tps->dev, | ||
297 | "%s(): register %d read failed with err %d\n", | ||
298 | __func__, REG_RAMPCTRL, ret); | ||
299 | return ret; | ||
300 | } | ||
301 | ramp_ctrl = (ramp_ctrl >> 4) & 0x7; | ||
302 | |||
303 | /* ramp mV/us = 32/(2^ramp_ctrl) */ | ||
304 | tps->change_uv_per_us = DIV_ROUND_UP(32000, BIT(ramp_ctrl)); | ||
264 | return ret; | 305 | return ret; |
265 | } | 306 | } |
266 | 307 | ||
267 | static const struct regmap_config tps62360_regmap_config = { | 308 | static const struct regmap_config tps62360_regmap_config = { |
268 | .reg_bits = 8, | 309 | .reg_bits = 8, |
269 | .val_bits = 8, | 310 | .val_bits = 8, |
311 | .max_register = REG_CHIPID, | ||
312 | .cache_type = REGCACHE_RBTREE, | ||
270 | }; | 313 | }; |
271 | 314 | ||
315 | static struct tps62360_regulator_platform_data * | ||
316 | of_get_tps62360_platform_data(struct device *dev) | ||
317 | { | ||
318 | struct tps62360_regulator_platform_data *pdata; | ||
319 | struct device_node *np = dev->of_node; | ||
320 | |||
321 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); | ||
322 | if (!pdata) { | ||
323 | dev_err(dev, "Memory alloc failed for platform data\n"); | ||
324 | return NULL; | ||
325 | } | ||
326 | |||
327 | pdata->reg_init_data = of_get_regulator_init_data(dev, dev->of_node); | ||
328 | if (!pdata->reg_init_data) { | ||
329 | dev_err(dev, "Not able to get OF regulator init data\n"); | ||
330 | return NULL; | ||
331 | } | ||
332 | |||
333 | pdata->vsel0_gpio = of_get_named_gpio(np, "vsel0-gpio", 0); | ||
334 | pdata->vsel1_gpio = of_get_named_gpio(np, "vsel1-gpio", 0); | ||
335 | |||
336 | if (of_find_property(np, "ti,vsel0-state-high", NULL)) | ||
337 | pdata->vsel0_def_state = 1; | ||
338 | |||
339 | if (of_find_property(np, "ti,vsel1-state-high", NULL)) | ||
340 | pdata->vsel1_def_state = 1; | ||
341 | |||
342 | if (of_find_property(np, "ti,enable-pull-down", NULL)) | ||
343 | pdata->en_internal_pulldn = true; | ||
344 | |||
345 | if (of_find_property(np, "ti,enable-vout-discharge", NULL)) | ||
346 | pdata->en_discharge = true; | ||
347 | |||
348 | return pdata; | ||
349 | } | ||
350 | |||
351 | #if defined(CONFIG_OF) | ||
352 | static const struct of_device_id tps62360_of_match[] = { | ||
353 | { .compatible = "ti,tps62360", .data = (void *)TPS62360}, | ||
354 | { .compatible = "ti,tps62361", .data = (void *)TPS62361}, | ||
355 | { .compatible = "ti,tps62362", .data = (void *)TPS62362}, | ||
356 | { .compatible = "ti,tps62363", .data = (void *)TPS62363}, | ||
357 | {}, | ||
358 | }; | ||
359 | MODULE_DEVICE_TABLE(of, tps62360_of_match); | ||
360 | #endif | ||
361 | |||
272 | static int __devinit tps62360_probe(struct i2c_client *client, | 362 | static int __devinit tps62360_probe(struct i2c_client *client, |
273 | const struct i2c_device_id *id) | 363 | const struct i2c_device_id *id) |
274 | { | 364 | { |
365 | struct regulator_config config = { }; | ||
275 | struct tps62360_regulator_platform_data *pdata; | 366 | struct tps62360_regulator_platform_data *pdata; |
276 | struct regulator_dev *rdev; | 367 | struct regulator_dev *rdev; |
277 | struct tps62360_chip *tps; | 368 | struct tps62360_chip *tps; |
278 | int ret; | 369 | int ret; |
279 | int i; | 370 | int i; |
371 | int chip_id; | ||
280 | 372 | ||
281 | pdata = client->dev.platform_data; | 373 | pdata = client->dev.platform_data; |
374 | chip_id = id->driver_data; | ||
375 | |||
376 | if (client->dev.of_node) { | ||
377 | const struct of_device_id *match; | ||
378 | match = of_match_device(of_match_ptr(tps62360_of_match), | ||
379 | &client->dev); | ||
380 | if (!match) { | ||
381 | dev_err(&client->dev, "Error: No device match found\n"); | ||
382 | return -ENODEV; | ||
383 | } | ||
384 | chip_id = (int)match->data; | ||
385 | if (!pdata) | ||
386 | pdata = of_get_tps62360_platform_data(&client->dev); | ||
387 | } | ||
388 | |||
282 | if (!pdata) { | 389 | if (!pdata) { |
283 | dev_err(&client->dev, "%s() Err: Platform data not found\n", | 390 | dev_err(&client->dev, "%s(): Platform data not found\n", |
284 | __func__); | 391 | __func__); |
285 | return -EIO; | 392 | return -EIO; |
286 | } | 393 | } |
287 | 394 | ||
288 | tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); | 395 | tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); |
289 | if (!tps) { | 396 | if (!tps) { |
290 | dev_err(&client->dev, "%s() Err: Memory allocation fails\n", | 397 | dev_err(&client->dev, "%s(): Memory allocation failed\n", |
291 | __func__); | 398 | __func__); |
292 | return -ENOMEM; | 399 | return -ENOMEM; |
293 | } | 400 | } |
294 | 401 | ||
295 | tps->en_force_pwm = pdata->en_force_pwm; | ||
296 | tps->en_discharge = pdata->en_discharge; | 402 | tps->en_discharge = pdata->en_discharge; |
297 | tps->en_internal_pulldn = pdata->en_internal_pulldn; | 403 | tps->en_internal_pulldn = pdata->en_internal_pulldn; |
298 | tps->vsel0_gpio = pdata->vsel0_gpio; | 404 | tps->vsel0_gpio = pdata->vsel0_gpio; |
299 | tps->vsel1_gpio = pdata->vsel1_gpio; | 405 | tps->vsel1_gpio = pdata->vsel1_gpio; |
300 | tps->client = client; | ||
301 | tps->dev = &client->dev; | 406 | tps->dev = &client->dev; |
302 | tps->name = id->name; | 407 | |
303 | tps->voltage_base = (id->driver_data == TPS62360) ? | 408 | switch (chip_id) { |
304 | TPS62360_BASE_VOLTAGE : TPS62361_BASE_VOLTAGE; | 409 | case TPS62360: |
305 | tps->voltage_reg_mask = (id->driver_data == TPS62360) ? 0x3F : 0x7F; | 410 | case TPS62362: |
411 | tps->voltage_base = TPS62360_BASE_VOLTAGE; | ||
412 | tps->voltage_reg_mask = 0x3F; | ||
413 | tps->desc.n_voltages = TPS62360_N_VOLTAGES; | ||
414 | break; | ||
415 | case TPS62361: | ||
416 | case TPS62363: | ||
417 | tps->voltage_base = TPS62361_BASE_VOLTAGE; | ||
418 | tps->voltage_reg_mask = 0x7F; | ||
419 | tps->desc.n_voltages = TPS62361_N_VOLTAGES; | ||
420 | break; | ||
421 | default: | ||
422 | return -ENODEV; | ||
423 | } | ||
306 | 424 | ||
307 | tps->desc.name = id->name; | 425 | tps->desc.name = id->name; |
308 | tps->desc.id = 0; | 426 | tps->desc.id = 0; |
309 | tps->desc.n_voltages = (id->driver_data == TPS62360) ? | ||
310 | TPS62360_N_VOLTAGES : TPS62361_N_VOLTAGES; | ||
311 | tps->desc.ops = &tps62360_dcdc_ops; | 427 | tps->desc.ops = &tps62360_dcdc_ops; |
312 | tps->desc.type = REGULATOR_VOLTAGE; | 428 | tps->desc.type = REGULATOR_VOLTAGE; |
313 | tps->desc.owner = THIS_MODULE; | 429 | tps->desc.owner = THIS_MODULE; |
314 | tps->regmap = regmap_init_i2c(client, &tps62360_regmap_config); | 430 | tps->desc.min_uV = tps->voltage_base; |
431 | tps->desc.uV_step = 10000; | ||
432 | |||
433 | tps->regmap = devm_regmap_init_i2c(client, &tps62360_regmap_config); | ||
315 | if (IS_ERR(tps->regmap)) { | 434 | if (IS_ERR(tps->regmap)) { |
316 | ret = PTR_ERR(tps->regmap); | 435 | ret = PTR_ERR(tps->regmap); |
317 | dev_err(&client->dev, "%s() Err: Failed to allocate register" | 436 | dev_err(&client->dev, |
318 | "map: %d\n", __func__, ret); | 437 | "%s(): regmap allocation failed with err %d\n", |
438 | __func__, ret); | ||
319 | return ret; | 439 | return ret; |
320 | } | 440 | } |
321 | i2c_set_clientdata(client, tps); | 441 | i2c_set_clientdata(client, tps); |
@@ -326,35 +446,26 @@ static int __devinit tps62360_probe(struct i2c_client *client, | |||
326 | tps->valid_gpios = false; | 446 | tps->valid_gpios = false; |
327 | 447 | ||
328 | if (gpio_is_valid(tps->vsel0_gpio) && gpio_is_valid(tps->vsel1_gpio)) { | 448 | if (gpio_is_valid(tps->vsel0_gpio) && gpio_is_valid(tps->vsel1_gpio)) { |
329 | ret = gpio_request(tps->vsel0_gpio, "tps62360-vsel0"); | 449 | int gpio_flags; |
450 | gpio_flags = (pdata->vsel0_def_state) ? | ||
451 | GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW; | ||
452 | ret = gpio_request_one(tps->vsel0_gpio, | ||
453 | gpio_flags, "tps62360-vsel0"); | ||
330 | if (ret) { | 454 | if (ret) { |
331 | dev_err(&client->dev, | 455 | dev_err(&client->dev, |
332 | "Err: Could not obtain vsel0 GPIO %d: %d\n", | 456 | "%s(): Could not obtain vsel0 GPIO %d: %d\n", |
333 | tps->vsel0_gpio, ret); | 457 | __func__, tps->vsel0_gpio, ret); |
334 | goto err_gpio0; | ||
335 | } | ||
336 | ret = gpio_direction_output(tps->vsel0_gpio, | ||
337 | pdata->vsel0_def_state); | ||
338 | if (ret) { | ||
339 | dev_err(&client->dev, "Err: Could not set direction of" | ||
340 | "vsel0 GPIO %d: %d\n", tps->vsel0_gpio, ret); | ||
341 | gpio_free(tps->vsel0_gpio); | ||
342 | goto err_gpio0; | 458 | goto err_gpio0; |
343 | } | 459 | } |
344 | 460 | ||
345 | ret = gpio_request(tps->vsel1_gpio, "tps62360-vsel1"); | 461 | gpio_flags = (pdata->vsel1_def_state) ? |
462 | GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW; | ||
463 | ret = gpio_request_one(tps->vsel1_gpio, | ||
464 | gpio_flags, "tps62360-vsel1"); | ||
346 | if (ret) { | 465 | if (ret) { |
347 | dev_err(&client->dev, | 466 | dev_err(&client->dev, |
348 | "Err: Could not obtain vsel1 GPIO %d: %d\n", | 467 | "%s(): Could not obtain vsel1 GPIO %d: %d\n", |
349 | tps->vsel1_gpio, ret); | 468 | __func__, tps->vsel1_gpio, ret); |
350 | goto err_gpio1; | ||
351 | } | ||
352 | ret = gpio_direction_output(tps->vsel1_gpio, | ||
353 | pdata->vsel1_def_state); | ||
354 | if (ret) { | ||
355 | dev_err(&client->dev, "Err: Could not set direction of" | ||
356 | "vsel1 GPIO %d: %d\n", tps->vsel1_gpio, ret); | ||
357 | gpio_free(tps->vsel1_gpio); | ||
358 | goto err_gpio1; | 469 | goto err_gpio1; |
359 | } | 470 | } |
360 | tps->valid_gpios = true; | 471 | tps->valid_gpios = true; |
@@ -371,17 +482,22 @@ static int __devinit tps62360_probe(struct i2c_client *client, | |||
371 | 482 | ||
372 | ret = tps62360_init_dcdc(tps, pdata); | 483 | ret = tps62360_init_dcdc(tps, pdata); |
373 | if (ret < 0) { | 484 | if (ret < 0) { |
374 | dev_err(tps->dev, "%s() Err: Init fails with = %d\n", | 485 | dev_err(tps->dev, "%s(): Init failed with err = %d\n", |
375 | __func__, ret); | 486 | __func__, ret); |
376 | goto err_init; | 487 | goto err_init; |
377 | } | 488 | } |
378 | 489 | ||
490 | config.dev = &client->dev; | ||
491 | config.init_data = pdata->reg_init_data; | ||
492 | config.driver_data = tps; | ||
493 | config.of_node = client->dev.of_node; | ||
494 | |||
379 | /* Register the regulators */ | 495 | /* Register the regulators */ |
380 | rdev = regulator_register(&tps->desc, &client->dev, | 496 | rdev = regulator_register(&tps->desc, &config); |
381 | &pdata->reg_init_data, tps, NULL); | ||
382 | if (IS_ERR(rdev)) { | 497 | if (IS_ERR(rdev)) { |
383 | dev_err(tps->dev, "%s() Err: Failed to register %s\n", | 498 | dev_err(tps->dev, |
384 | __func__, id->name); | 499 | "%s(): regulator register failed with err %s\n", |
500 | __func__, id->name); | ||
385 | ret = PTR_ERR(rdev); | 501 | ret = PTR_ERR(rdev); |
386 | goto err_init; | 502 | goto err_init; |
387 | } | 503 | } |
@@ -396,7 +512,6 @@ err_gpio1: | |||
396 | if (gpio_is_valid(tps->vsel0_gpio)) | 512 | if (gpio_is_valid(tps->vsel0_gpio)) |
397 | gpio_free(tps->vsel0_gpio); | 513 | gpio_free(tps->vsel0_gpio); |
398 | err_gpio0: | 514 | err_gpio0: |
399 | regmap_exit(tps->regmap); | ||
400 | return ret; | 515 | return ret; |
401 | } | 516 | } |
402 | 517 | ||
@@ -417,7 +532,6 @@ static int __devexit tps62360_remove(struct i2c_client *client) | |||
417 | gpio_free(tps->vsel0_gpio); | 532 | gpio_free(tps->vsel0_gpio); |
418 | 533 | ||
419 | regulator_unregister(tps->rdev); | 534 | regulator_unregister(tps->rdev); |
420 | regmap_exit(tps->regmap); | ||
421 | return 0; | 535 | return 0; |
422 | } | 536 | } |
423 | 537 | ||
@@ -432,13 +546,16 @@ static void tps62360_shutdown(struct i2c_client *client) | |||
432 | /* Configure the output discharge path */ | 546 | /* Configure the output discharge path */ |
433 | st = regmap_update_bits(tps->regmap, REG_RAMPCTRL, BIT(2), BIT(2)); | 547 | st = regmap_update_bits(tps->regmap, REG_RAMPCTRL, BIT(2), BIT(2)); |
434 | if (st < 0) | 548 | if (st < 0) |
435 | dev_err(tps->dev, "%s() fails in updating reg %d\n", | 549 | dev_err(tps->dev, |
436 | __func__, REG_RAMPCTRL); | 550 | "%s(): register %d update failed with err %d\n", |
551 | __func__, REG_RAMPCTRL, st); | ||
437 | } | 552 | } |
438 | 553 | ||
439 | static const struct i2c_device_id tps62360_id[] = { | 554 | static const struct i2c_device_id tps62360_id[] = { |
440 | {.name = "tps62360", .driver_data = TPS62360}, | 555 | {.name = "tps62360", .driver_data = TPS62360}, |
441 | {.name = "tps62361", .driver_data = TPS62361}, | 556 | {.name = "tps62361", .driver_data = TPS62361}, |
557 | {.name = "tps62362", .driver_data = TPS62362}, | ||
558 | {.name = "tps62363", .driver_data = TPS62363}, | ||
442 | {}, | 559 | {}, |
443 | }; | 560 | }; |
444 | 561 | ||
@@ -448,6 +565,7 @@ static struct i2c_driver tps62360_i2c_driver = { | |||
448 | .driver = { | 565 | .driver = { |
449 | .name = "tps62360", | 566 | .name = "tps62360", |
450 | .owner = THIS_MODULE, | 567 | .owner = THIS_MODULE, |
568 | .of_match_table = of_match_ptr(tps62360_of_match), | ||
451 | }, | 569 | }, |
452 | .probe = tps62360_probe, | 570 | .probe = tps62360_probe, |
453 | .remove = __devexit_p(tps62360_remove), | 571 | .remove = __devexit_p(tps62360_remove), |
@@ -468,5 +586,5 @@ static void __exit tps62360_cleanup(void) | |||
468 | module_exit(tps62360_cleanup); | 586 | module_exit(tps62360_cleanup); |
469 | 587 | ||
470 | MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>"); | 588 | MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>"); |
471 | MODULE_DESCRIPTION("TPS62360 voltage regulator driver"); | 589 | MODULE_DESCRIPTION("TPS6236x voltage regulator driver"); |
472 | MODULE_LICENSE("GPL v2"); | 590 | MODULE_LICENSE("GPL v2"); |
diff --git a/drivers/regulator/tps65023-regulator.c b/drivers/regulator/tps65023-regulator.c index 43e4902d7af8..f841bd0db6aa 100644 --- a/drivers/regulator/tps65023-regulator.c +++ b/drivers/regulator/tps65023-regulator.c | |||
@@ -23,7 +23,6 @@ | |||
23 | #include <linux/regulator/driver.h> | 23 | #include <linux/regulator/driver.h> |
24 | #include <linux/regulator/machine.h> | 24 | #include <linux/regulator/machine.h> |
25 | #include <linux/i2c.h> | 25 | #include <linux/i2c.h> |
26 | #include <linux/delay.h> | ||
27 | #include <linux/slab.h> | 26 | #include <linux/slab.h> |
28 | #include <linux/regmap.h> | 27 | #include <linux/regmap.h> |
29 | 28 | ||
@@ -72,7 +71,7 @@ | |||
72 | 71 | ||
73 | /* LDO_CTRL bitfields */ | 72 | /* LDO_CTRL bitfields */ |
74 | #define TPS65023_LDO_CTRL_LDOx_SHIFT(ldo_id) ((ldo_id)*4) | 73 | #define TPS65023_LDO_CTRL_LDOx_SHIFT(ldo_id) ((ldo_id)*4) |
75 | #define TPS65023_LDO_CTRL_LDOx_MASK(ldo_id) (0xF0 >> ((ldo_id)*4)) | 74 | #define TPS65023_LDO_CTRL_LDOx_MASK(ldo_id) (0x0F << ((ldo_id)*4)) |
76 | 75 | ||
77 | /* Number of step-down converters available */ | 76 | /* Number of step-down converters available */ |
78 | #define TPS65023_NUM_DCDC 3 | 77 | #define TPS65023_NUM_DCDC 3 |
@@ -139,7 +138,6 @@ struct tps_info { | |||
139 | /* PMIC details */ | 138 | /* PMIC details */ |
140 | struct tps_pmic { | 139 | struct tps_pmic { |
141 | struct regulator_desc desc[TPS65023_NUM_REGULATOR]; | 140 | struct regulator_desc desc[TPS65023_NUM_REGULATOR]; |
142 | struct i2c_client *client; | ||
143 | struct regulator_dev *rdev[TPS65023_NUM_REGULATOR]; | 141 | struct regulator_dev *rdev[TPS65023_NUM_REGULATOR]; |
144 | const struct tps_info *info[TPS65023_NUM_REGULATOR]; | 142 | const struct tps_info *info[TPS65023_NUM_REGULATOR]; |
145 | struct regmap *regmap; | 143 | struct regmap *regmap; |
@@ -152,96 +150,6 @@ struct tps_driver_data { | |||
152 | u8 core_regulator; | 150 | u8 core_regulator; |
153 | }; | 151 | }; |
154 | 152 | ||
155 | static int tps65023_dcdc_is_enabled(struct regulator_dev *dev) | ||
156 | { | ||
157 | struct tps_pmic *tps = rdev_get_drvdata(dev); | ||
158 | int data, dcdc = rdev_get_id(dev); | ||
159 | int ret; | ||
160 | u8 shift; | ||
161 | |||
162 | if (dcdc < TPS65023_DCDC_1 || dcdc > TPS65023_DCDC_3) | ||
163 | return -EINVAL; | ||
164 | |||
165 | shift = TPS65023_NUM_REGULATOR - dcdc; | ||
166 | ret = regmap_read(tps->regmap, TPS65023_REG_REG_CTRL, &data); | ||
167 | |||
168 | if (ret != 0) | ||
169 | return ret; | ||
170 | else | ||
171 | return (data & 1<<shift) ? 1 : 0; | ||
172 | } | ||
173 | |||
174 | static int tps65023_ldo_is_enabled(struct regulator_dev *dev) | ||
175 | { | ||
176 | struct tps_pmic *tps = rdev_get_drvdata(dev); | ||
177 | int data, ldo = rdev_get_id(dev); | ||
178 | int ret; | ||
179 | u8 shift; | ||
180 | |||
181 | if (ldo < TPS65023_LDO_1 || ldo > TPS65023_LDO_2) | ||
182 | return -EINVAL; | ||
183 | |||
184 | shift = (ldo == TPS65023_LDO_1 ? 1 : 2); | ||
185 | ret = regmap_read(tps->regmap, TPS65023_REG_REG_CTRL, &data); | ||
186 | |||
187 | if (ret != 0) | ||
188 | return ret; | ||
189 | else | ||
190 | return (data & 1<<shift) ? 1 : 0; | ||
191 | } | ||
192 | |||
193 | static int tps65023_dcdc_enable(struct regulator_dev *dev) | ||
194 | { | ||
195 | struct tps_pmic *tps = rdev_get_drvdata(dev); | ||
196 | int dcdc = rdev_get_id(dev); | ||
197 | u8 shift; | ||
198 | |||
199 | if (dcdc < TPS65023_DCDC_1 || dcdc > TPS65023_DCDC_3) | ||
200 | return -EINVAL; | ||
201 | |||
202 | shift = TPS65023_NUM_REGULATOR - dcdc; | ||
203 | return regmap_update_bits(tps->regmap, TPS65023_REG_REG_CTRL, 1 << shift, 1 << shift); | ||
204 | } | ||
205 | |||
206 | static int tps65023_dcdc_disable(struct regulator_dev *dev) | ||
207 | { | ||
208 | struct tps_pmic *tps = rdev_get_drvdata(dev); | ||
209 | int dcdc = rdev_get_id(dev); | ||
210 | u8 shift; | ||
211 | |||
212 | if (dcdc < TPS65023_DCDC_1 || dcdc > TPS65023_DCDC_3) | ||
213 | return -EINVAL; | ||
214 | |||
215 | shift = TPS65023_NUM_REGULATOR - dcdc; | ||
216 | return regmap_update_bits(tps->regmap, TPS65023_REG_REG_CTRL, 1 << shift, 0); | ||
217 | } | ||
218 | |||
219 | static int tps65023_ldo_enable(struct regulator_dev *dev) | ||
220 | { | ||
221 | struct tps_pmic *tps = rdev_get_drvdata(dev); | ||
222 | int ldo = rdev_get_id(dev); | ||
223 | u8 shift; | ||
224 | |||
225 | if (ldo < TPS65023_LDO_1 || ldo > TPS65023_LDO_2) | ||
226 | return -EINVAL; | ||
227 | |||
228 | shift = (ldo == TPS65023_LDO_1 ? 1 : 2); | ||
229 | return regmap_update_bits(tps->regmap, TPS65023_REG_REG_CTRL, 1 << shift, 1 << shift); | ||
230 | } | ||
231 | |||
232 | static int tps65023_ldo_disable(struct regulator_dev *dev) | ||
233 | { | ||
234 | struct tps_pmic *tps = rdev_get_drvdata(dev); | ||
235 | int ldo = rdev_get_id(dev); | ||
236 | u8 shift; | ||
237 | |||
238 | if (ldo < TPS65023_LDO_1 || ldo > TPS65023_LDO_2) | ||
239 | return -EINVAL; | ||
240 | |||
241 | shift = (ldo == TPS65023_LDO_1 ? 1 : 2); | ||
242 | return regmap_update_bits(tps->regmap, TPS65023_REG_REG_CTRL, 1 << shift, 0); | ||
243 | } | ||
244 | |||
245 | static int tps65023_dcdc_get_voltage(struct regulator_dev *dev) | 153 | static int tps65023_dcdc_get_voltage(struct regulator_dev *dev) |
246 | { | 154 | { |
247 | struct tps_pmic *tps = rdev_get_drvdata(dev); | 155 | struct tps_pmic *tps = rdev_get_drvdata(dev); |
@@ -261,50 +169,28 @@ static int tps65023_dcdc_get_voltage(struct regulator_dev *dev) | |||
261 | return tps->info[dcdc]->min_uV; | 169 | return tps->info[dcdc]->min_uV; |
262 | } | 170 | } |
263 | 171 | ||
264 | static int tps65023_dcdc_set_voltage(struct regulator_dev *dev, | 172 | static int tps65023_dcdc_set_voltage_sel(struct regulator_dev *dev, |
265 | int min_uV, int max_uV, | 173 | unsigned selector) |
266 | unsigned *selector) | ||
267 | { | 174 | { |
268 | struct tps_pmic *tps = rdev_get_drvdata(dev); | 175 | struct tps_pmic *tps = rdev_get_drvdata(dev); |
269 | int dcdc = rdev_get_id(dev); | 176 | int dcdc = rdev_get_id(dev); |
270 | int vsel; | ||
271 | int ret; | 177 | int ret; |
272 | 178 | ||
273 | if (dcdc != tps->core_regulator) | 179 | if (dcdc != tps->core_regulator) |
274 | return -EINVAL; | 180 | return -EINVAL; |
275 | if (min_uV < tps->info[dcdc]->min_uV | ||
276 | || min_uV > tps->info[dcdc]->max_uV) | ||
277 | return -EINVAL; | ||
278 | if (max_uV < tps->info[dcdc]->min_uV | ||
279 | || max_uV > tps->info[dcdc]->max_uV) | ||
280 | return -EINVAL; | ||
281 | |||
282 | for (vsel = 0; vsel < tps->info[dcdc]->table_len; vsel++) { | ||
283 | int mV = tps->info[dcdc]->table[vsel]; | ||
284 | int uV = mV * 1000; | ||
285 | |||
286 | /* Break at the first in-range value */ | ||
287 | if (min_uV <= uV && uV <= max_uV) | ||
288 | break; | ||
289 | } | ||
290 | 181 | ||
291 | *selector = vsel; | 182 | ret = regmap_write(tps->regmap, TPS65023_REG_DEF_CORE, selector); |
292 | 183 | if (ret) | |
293 | if (vsel == tps->info[dcdc]->table_len) | 184 | goto out; |
294 | goto failed; | ||
295 | |||
296 | ret = regmap_write(tps->regmap, TPS65023_REG_DEF_CORE, vsel); | ||
297 | 185 | ||
298 | /* Tell the chip that we have changed the value in DEFCORE | 186 | /* Tell the chip that we have changed the value in DEFCORE |
299 | * and its time to update the core voltage | 187 | * and its time to update the core voltage |
300 | */ | 188 | */ |
301 | regmap_update_bits(tps->regmap, TPS65023_REG_CON_CTRL2, | 189 | ret = regmap_update_bits(tps->regmap, TPS65023_REG_CON_CTRL2, |
302 | TPS65023_REG_CTRL2_GO, TPS65023_REG_CTRL2_GO); | 190 | TPS65023_REG_CTRL2_GO, TPS65023_REG_CTRL2_GO); |
303 | 191 | ||
192 | out: | ||
304 | return ret; | 193 | return ret; |
305 | |||
306 | failed: | ||
307 | return -EINVAL; | ||
308 | } | 194 | } |
309 | 195 | ||
310 | static int tps65023_ldo_get_voltage(struct regulator_dev *dev) | 196 | static int tps65023_ldo_get_voltage(struct regulator_dev *dev) |
@@ -325,42 +211,15 @@ static int tps65023_ldo_get_voltage(struct regulator_dev *dev) | |||
325 | return tps->info[ldo]->table[data] * 1000; | 211 | return tps->info[ldo]->table[data] * 1000; |
326 | } | 212 | } |
327 | 213 | ||
328 | static int tps65023_ldo_set_voltage(struct regulator_dev *dev, | 214 | static int tps65023_ldo_set_voltage_sel(struct regulator_dev *dev, |
329 | int min_uV, int max_uV, unsigned *selector) | 215 | unsigned selector) |
330 | { | 216 | { |
331 | struct tps_pmic *tps = rdev_get_drvdata(dev); | 217 | struct tps_pmic *tps = rdev_get_drvdata(dev); |
332 | int data, vsel, ldo = rdev_get_id(dev); | 218 | int ldo_index = rdev_get_id(dev) - TPS65023_LDO_1; |
333 | int ret; | ||
334 | |||
335 | if (ldo < TPS65023_LDO_1 || ldo > TPS65023_LDO_2) | ||
336 | return -EINVAL; | ||
337 | 219 | ||
338 | if (min_uV < tps->info[ldo]->min_uV || min_uV > tps->info[ldo]->max_uV) | 220 | return regmap_update_bits(tps->regmap, TPS65023_REG_LDO_CTRL, |
339 | return -EINVAL; | 221 | TPS65023_LDO_CTRL_LDOx_MASK(ldo_index), |
340 | if (max_uV < tps->info[ldo]->min_uV || max_uV > tps->info[ldo]->max_uV) | 222 | selector << TPS65023_LDO_CTRL_LDOx_SHIFT(ldo_index)); |
341 | return -EINVAL; | ||
342 | |||
343 | for (vsel = 0; vsel < tps->info[ldo]->table_len; vsel++) { | ||
344 | int mV = tps->info[ldo]->table[vsel]; | ||
345 | int uV = mV * 1000; | ||
346 | |||
347 | /* Break at the first in-range value */ | ||
348 | if (min_uV <= uV && uV <= max_uV) | ||
349 | break; | ||
350 | } | ||
351 | |||
352 | if (vsel == tps->info[ldo]->table_len) | ||
353 | return -EINVAL; | ||
354 | |||
355 | *selector = vsel; | ||
356 | |||
357 | ret = regmap_read(tps->regmap, TPS65023_REG_LDO_CTRL, &data); | ||
358 | if (ret != 0) | ||
359 | return ret; | ||
360 | |||
361 | data &= TPS65023_LDO_CTRL_LDOx_MASK(ldo - TPS65023_LDO_1); | ||
362 | data |= (vsel << (TPS65023_LDO_CTRL_LDOx_SHIFT(ldo - TPS65023_LDO_1))); | ||
363 | return regmap_write(tps->regmap, TPS65023_REG_LDO_CTRL, data); | ||
364 | } | 223 | } |
365 | 224 | ||
366 | static int tps65023_dcdc_list_voltage(struct regulator_dev *dev, | 225 | static int tps65023_dcdc_list_voltage(struct regulator_dev *dev, |
@@ -398,21 +257,21 @@ static int tps65023_ldo_list_voltage(struct regulator_dev *dev, | |||
398 | 257 | ||
399 | /* Operations permitted on VDCDCx */ | 258 | /* Operations permitted on VDCDCx */ |
400 | static struct regulator_ops tps65023_dcdc_ops = { | 259 | static struct regulator_ops tps65023_dcdc_ops = { |
401 | .is_enabled = tps65023_dcdc_is_enabled, | 260 | .is_enabled = regulator_is_enabled_regmap, |
402 | .enable = tps65023_dcdc_enable, | 261 | .enable = regulator_enable_regmap, |
403 | .disable = tps65023_dcdc_disable, | 262 | .disable = regulator_disable_regmap, |
404 | .get_voltage = tps65023_dcdc_get_voltage, | 263 | .get_voltage = tps65023_dcdc_get_voltage, |
405 | .set_voltage = tps65023_dcdc_set_voltage, | 264 | .set_voltage_sel = tps65023_dcdc_set_voltage_sel, |
406 | .list_voltage = tps65023_dcdc_list_voltage, | 265 | .list_voltage = tps65023_dcdc_list_voltage, |
407 | }; | 266 | }; |
408 | 267 | ||
409 | /* Operations permitted on LDOx */ | 268 | /* Operations permitted on LDOx */ |
410 | static struct regulator_ops tps65023_ldo_ops = { | 269 | static struct regulator_ops tps65023_ldo_ops = { |
411 | .is_enabled = tps65023_ldo_is_enabled, | 270 | .is_enabled = regulator_is_enabled_regmap, |
412 | .enable = tps65023_ldo_enable, | 271 | .enable = regulator_enable_regmap, |
413 | .disable = tps65023_ldo_disable, | 272 | .disable = regulator_disable_regmap, |
414 | .get_voltage = tps65023_ldo_get_voltage, | 273 | .get_voltage = tps65023_ldo_get_voltage, |
415 | .set_voltage = tps65023_ldo_set_voltage, | 274 | .set_voltage_sel = tps65023_ldo_set_voltage_sel, |
416 | .list_voltage = tps65023_ldo_list_voltage, | 275 | .list_voltage = tps65023_ldo_list_voltage, |
417 | }; | 276 | }; |
418 | 277 | ||
@@ -426,6 +285,7 @@ static int __devinit tps_65023_probe(struct i2c_client *client, | |||
426 | { | 285 | { |
427 | const struct tps_driver_data *drv_data = (void *)id->driver_data; | 286 | const struct tps_driver_data *drv_data = (void *)id->driver_data; |
428 | const struct tps_info *info = drv_data->info; | 287 | const struct tps_info *info = drv_data->info; |
288 | struct regulator_config config = { }; | ||
429 | struct regulator_init_data *init_data; | 289 | struct regulator_init_data *init_data; |
430 | struct regulator_dev *rdev; | 290 | struct regulator_dev *rdev; |
431 | struct tps_pmic *tps; | 291 | struct tps_pmic *tps; |
@@ -443,20 +303,19 @@ static int __devinit tps_65023_probe(struct i2c_client *client, | |||
443 | if (!init_data) | 303 | if (!init_data) |
444 | return -EIO; | 304 | return -EIO; |
445 | 305 | ||
446 | tps = kzalloc(sizeof(*tps), GFP_KERNEL); | 306 | tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); |
447 | if (!tps) | 307 | if (!tps) |
448 | return -ENOMEM; | 308 | return -ENOMEM; |
449 | 309 | ||
450 | tps->regmap = regmap_init_i2c(client, &tps65023_regmap_config); | 310 | tps->regmap = devm_regmap_init_i2c(client, &tps65023_regmap_config); |
451 | if (IS_ERR(tps->regmap)) { | 311 | if (IS_ERR(tps->regmap)) { |
452 | error = PTR_ERR(tps->regmap); | 312 | error = PTR_ERR(tps->regmap); |
453 | dev_err(&client->dev, "Failed to allocate register map: %d\n", | 313 | dev_err(&client->dev, "Failed to allocate register map: %d\n", |
454 | error); | 314 | error); |
455 | goto fail_alloc; | 315 | return error; |
456 | } | 316 | } |
457 | 317 | ||
458 | /* common for all regulators */ | 318 | /* common for all regulators */ |
459 | tps->client = client; | ||
460 | tps->core_regulator = drv_data->core_regulator; | 319 | tps->core_regulator = drv_data->core_regulator; |
461 | 320 | ||
462 | for (i = 0; i < TPS65023_NUM_REGULATOR; i++, info++, init_data++) { | 321 | for (i = 0; i < TPS65023_NUM_REGULATOR; i++, info++, init_data++) { |
@@ -471,9 +330,22 @@ static int __devinit tps_65023_probe(struct i2c_client *client, | |||
471 | tps->desc[i].type = REGULATOR_VOLTAGE; | 330 | tps->desc[i].type = REGULATOR_VOLTAGE; |
472 | tps->desc[i].owner = THIS_MODULE; | 331 | tps->desc[i].owner = THIS_MODULE; |
473 | 332 | ||
333 | tps->desc[i].enable_reg = TPS65023_REG_REG_CTRL; | ||
334 | if (i == TPS65023_LDO_1) | ||
335 | tps->desc[i].enable_mask = 1 << 1; | ||
336 | else if (i == TPS65023_LDO_2) | ||
337 | tps->desc[i].enable_mask = 1 << 2; | ||
338 | else /* DCDCx */ | ||
339 | tps->desc[i].enable_mask = | ||
340 | 1 << (TPS65023_NUM_REGULATOR - i); | ||
341 | |||
342 | config.dev = &client->dev; | ||
343 | config.init_data = init_data; | ||
344 | config.driver_data = tps; | ||
345 | config.regmap = tps->regmap; | ||
346 | |||
474 | /* Register the regulators */ | 347 | /* Register the regulators */ |
475 | rdev = regulator_register(&tps->desc[i], &client->dev, | 348 | rdev = regulator_register(&tps->desc[i], &config); |
476 | init_data, tps, NULL); | ||
477 | if (IS_ERR(rdev)) { | 349 | if (IS_ERR(rdev)) { |
478 | dev_err(&client->dev, "failed to register %s\n", | 350 | dev_err(&client->dev, "failed to register %s\n", |
479 | id->name); | 351 | id->name); |
@@ -496,19 +368,9 @@ static int __devinit tps_65023_probe(struct i2c_client *client, | |||
496 | fail: | 368 | fail: |
497 | while (--i >= 0) | 369 | while (--i >= 0) |
498 | regulator_unregister(tps->rdev[i]); | 370 | regulator_unregister(tps->rdev[i]); |
499 | |||
500 | regmap_exit(tps->regmap); | ||
501 | fail_alloc: | ||
502 | kfree(tps); | ||
503 | return error; | 371 | return error; |
504 | } | 372 | } |
505 | 373 | ||
506 | /** | ||
507 | * tps_65023_remove - TPS65023 driver i2c remove handler | ||
508 | * @client: i2c driver client device structure | ||
509 | * | ||
510 | * Unregister TPS driver as an i2c client device driver | ||
511 | */ | ||
512 | static int __devexit tps_65023_remove(struct i2c_client *client) | 374 | static int __devexit tps_65023_remove(struct i2c_client *client) |
513 | { | 375 | { |
514 | struct tps_pmic *tps = i2c_get_clientdata(client); | 376 | struct tps_pmic *tps = i2c_get_clientdata(client); |
@@ -516,10 +378,6 @@ static int __devexit tps_65023_remove(struct i2c_client *client) | |||
516 | 378 | ||
517 | for (i = 0; i < TPS65023_NUM_REGULATOR; i++) | 379 | for (i = 0; i < TPS65023_NUM_REGULATOR; i++) |
518 | regulator_unregister(tps->rdev[i]); | 380 | regulator_unregister(tps->rdev[i]); |
519 | |||
520 | regmap_exit(tps->regmap); | ||
521 | kfree(tps); | ||
522 | |||
523 | return 0; | 381 | return 0; |
524 | } | 382 | } |
525 | 383 | ||
@@ -638,13 +496,13 @@ static struct tps_driver_data tps65020_drv_data = { | |||
638 | }; | 496 | }; |
639 | 497 | ||
640 | static struct tps_driver_data tps65021_drv_data = { | 498 | static struct tps_driver_data tps65021_drv_data = { |
641 | .info = tps65021_regs, | 499 | .info = tps65021_regs, |
642 | .core_regulator = TPS65023_DCDC_3, | 500 | .core_regulator = TPS65023_DCDC_3, |
643 | }; | 501 | }; |
644 | 502 | ||
645 | static struct tps_driver_data tps65023_drv_data = { | 503 | static struct tps_driver_data tps65023_drv_data = { |
646 | .info = tps65023_regs, | 504 | .info = tps65023_regs, |
647 | .core_regulator = TPS65023_DCDC_1, | 505 | .core_regulator = TPS65023_DCDC_1, |
648 | }; | 506 | }; |
649 | 507 | ||
650 | static const struct i2c_device_id tps_65023_id[] = { | 508 | static const struct i2c_device_id tps_65023_id[] = { |
@@ -669,22 +527,12 @@ static struct i2c_driver tps_65023_i2c_driver = { | |||
669 | .id_table = tps_65023_id, | 527 | .id_table = tps_65023_id, |
670 | }; | 528 | }; |
671 | 529 | ||
672 | /** | ||
673 | * tps_65023_init | ||
674 | * | ||
675 | * Module init function | ||
676 | */ | ||
677 | static int __init tps_65023_init(void) | 530 | static int __init tps_65023_init(void) |
678 | { | 531 | { |
679 | return i2c_add_driver(&tps_65023_i2c_driver); | 532 | return i2c_add_driver(&tps_65023_i2c_driver); |
680 | } | 533 | } |
681 | subsys_initcall(tps_65023_init); | 534 | subsys_initcall(tps_65023_init); |
682 | 535 | ||
683 | /** | ||
684 | * tps_65023_cleanup | ||
685 | * | ||
686 | * Module exit function | ||
687 | */ | ||
688 | static void __exit tps_65023_cleanup(void) | 536 | static void __exit tps_65023_cleanup(void) |
689 | { | 537 | { |
690 | i2c_del_driver(&tps_65023_i2c_driver); | 538 | i2c_del_driver(&tps_65023_i2c_driver); |
diff --git a/drivers/regulator/tps6507x-regulator.c b/drivers/regulator/tps6507x-regulator.c index 832833fe8aad..da38be1016aa 100644 --- a/drivers/regulator/tps6507x-regulator.c +++ b/drivers/regulator/tps6507x-regulator.c | |||
@@ -23,7 +23,6 @@ | |||
23 | #include <linux/regulator/driver.h> | 23 | #include <linux/regulator/driver.h> |
24 | #include <linux/regulator/machine.h> | 24 | #include <linux/regulator/machine.h> |
25 | #include <linux/regulator/tps6507x.h> | 25 | #include <linux/regulator/tps6507x.h> |
26 | #include <linux/delay.h> | ||
27 | #include <linux/slab.h> | 26 | #include <linux/slab.h> |
28 | #include <linux/mfd/tps6507x.h> | 27 | #include <linux/mfd/tps6507x.h> |
29 | 28 | ||
@@ -283,7 +282,7 @@ static int tps6507x_pmic_disable(struct regulator_dev *dev) | |||
283 | 1 << shift); | 282 | 1 << shift); |
284 | } | 283 | } |
285 | 284 | ||
286 | static int tps6507x_pmic_get_voltage(struct regulator_dev *dev) | 285 | static int tps6507x_pmic_get_voltage_sel(struct regulator_dev *dev) |
287 | { | 286 | { |
288 | struct tps6507x_pmic *tps = rdev_get_drvdata(dev); | 287 | struct tps6507x_pmic *tps = rdev_get_drvdata(dev); |
289 | int data, rid = rdev_get_id(dev); | 288 | int data, rid = rdev_get_id(dev); |
@@ -325,7 +324,7 @@ static int tps6507x_pmic_get_voltage(struct regulator_dev *dev) | |||
325 | return data; | 324 | return data; |
326 | 325 | ||
327 | data &= mask; | 326 | data &= mask; |
328 | return tps->info[rid]->table[data] * 1000; | 327 | return data; |
329 | } | 328 | } |
330 | 329 | ||
331 | static int tps6507x_pmic_set_voltage_sel(struct regulator_dev *dev, | 330 | static int tps6507x_pmic_set_voltage_sel(struct regulator_dev *dev, |
@@ -395,7 +394,7 @@ static struct regulator_ops tps6507x_pmic_ops = { | |||
395 | .is_enabled = tps6507x_pmic_is_enabled, | 394 | .is_enabled = tps6507x_pmic_is_enabled, |
396 | .enable = tps6507x_pmic_enable, | 395 | .enable = tps6507x_pmic_enable, |
397 | .disable = tps6507x_pmic_disable, | 396 | .disable = tps6507x_pmic_disable, |
398 | .get_voltage = tps6507x_pmic_get_voltage, | 397 | .get_voltage_sel = tps6507x_pmic_get_voltage_sel, |
399 | .set_voltage_sel = tps6507x_pmic_set_voltage_sel, | 398 | .set_voltage_sel = tps6507x_pmic_set_voltage_sel, |
400 | .list_voltage = tps6507x_pmic_list_voltage, | 399 | .list_voltage = tps6507x_pmic_list_voltage, |
401 | }; | 400 | }; |
@@ -404,6 +403,7 @@ static __devinit int tps6507x_pmic_probe(struct platform_device *pdev) | |||
404 | { | 403 | { |
405 | struct tps6507x_dev *tps6507x_dev = dev_get_drvdata(pdev->dev.parent); | 404 | struct tps6507x_dev *tps6507x_dev = dev_get_drvdata(pdev->dev.parent); |
406 | struct tps_info *info = &tps6507x_pmic_regs[0]; | 405 | struct tps_info *info = &tps6507x_pmic_regs[0]; |
406 | struct regulator_config config = { }; | ||
407 | struct regulator_init_data *init_data; | 407 | struct regulator_init_data *init_data; |
408 | struct regulator_dev *rdev; | 408 | struct regulator_dev *rdev; |
409 | struct tps6507x_pmic *tps; | 409 | struct tps6507x_pmic *tps; |
@@ -428,7 +428,7 @@ static __devinit int tps6507x_pmic_probe(struct platform_device *pdev) | |||
428 | if (!init_data) | 428 | if (!init_data) |
429 | return -EINVAL; | 429 | return -EINVAL; |
430 | 430 | ||
431 | tps = kzalloc(sizeof(*tps), GFP_KERNEL); | 431 | tps = devm_kzalloc(&pdev->dev, sizeof(*tps), GFP_KERNEL); |
432 | if (!tps) | 432 | if (!tps) |
433 | return -ENOMEM; | 433 | return -ENOMEM; |
434 | 434 | ||
@@ -453,8 +453,11 @@ static __devinit int tps6507x_pmic_probe(struct platform_device *pdev) | |||
453 | tps->desc[i].type = REGULATOR_VOLTAGE; | 453 | tps->desc[i].type = REGULATOR_VOLTAGE; |
454 | tps->desc[i].owner = THIS_MODULE; | 454 | tps->desc[i].owner = THIS_MODULE; |
455 | 455 | ||
456 | rdev = regulator_register(&tps->desc[i], | 456 | config.dev = tps6507x_dev->dev; |
457 | tps6507x_dev->dev, init_data, tps, NULL); | 457 | config.init_data = init_data; |
458 | config.driver_data = tps; | ||
459 | |||
460 | rdev = regulator_register(&tps->desc[i], &config); | ||
458 | if (IS_ERR(rdev)) { | 461 | if (IS_ERR(rdev)) { |
459 | dev_err(tps6507x_dev->dev, | 462 | dev_err(tps6507x_dev->dev, |
460 | "failed to register %s regulator\n", | 463 | "failed to register %s regulator\n", |
@@ -475,8 +478,6 @@ static __devinit int tps6507x_pmic_probe(struct platform_device *pdev) | |||
475 | fail: | 478 | fail: |
476 | while (--i >= 0) | 479 | while (--i >= 0) |
477 | regulator_unregister(tps->rdev[i]); | 480 | regulator_unregister(tps->rdev[i]); |
478 | |||
479 | kfree(tps); | ||
480 | return error; | 481 | return error; |
481 | } | 482 | } |
482 | 483 | ||
@@ -488,9 +489,6 @@ static int __devexit tps6507x_pmic_remove(struct platform_device *pdev) | |||
488 | 489 | ||
489 | for (i = 0; i < TPS6507X_NUM_REGULATOR; i++) | 490 | for (i = 0; i < TPS6507X_NUM_REGULATOR; i++) |
490 | regulator_unregister(tps->rdev[i]); | 491 | regulator_unregister(tps->rdev[i]); |
491 | |||
492 | kfree(tps); | ||
493 | |||
494 | return 0; | 492 | return 0; |
495 | } | 493 | } |
496 | 494 | ||
diff --git a/drivers/regulator/tps65090-regulator.c b/drivers/regulator/tps65090-regulator.c new file mode 100644 index 000000000000..001ad554ac62 --- /dev/null +++ b/drivers/regulator/tps65090-regulator.c | |||
@@ -0,0 +1,150 @@ | |||
1 | /* | ||
2 | * Regulator driver for tps65090 power management chip. | ||
3 | * | ||
4 | * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. | ||
5 | |||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms and conditions of the GNU General Public License, | ||
8 | * version 2, as published by the Free Software Foundation. | ||
9 | |||
10 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | * more details. | ||
14 | |||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program. If not, see <http://www.gnu.org/licenses/> | ||
17 | */ | ||
18 | |||
19 | #include <linux/module.h> | ||
20 | #include <linux/init.h> | ||
21 | #include <linux/slab.h> | ||
22 | #include <linux/err.h> | ||
23 | #include <linux/platform_device.h> | ||
24 | #include <linux/regulator/driver.h> | ||
25 | #include <linux/regulator/machine.h> | ||
26 | #include <linux/mfd/tps65090.h> | ||
27 | #include <linux/regulator/tps65090-regulator.h> | ||
28 | |||
29 | struct tps65090_regulator { | ||
30 | int id; | ||
31 | /* used by regulator core */ | ||
32 | struct regulator_desc desc; | ||
33 | |||
34 | /* Device */ | ||
35 | struct device *dev; | ||
36 | }; | ||
37 | |||
38 | static struct regulator_ops tps65090_ops = { | ||
39 | .enable = regulator_enable_regmap, | ||
40 | .disable = regulator_disable_regmap, | ||
41 | .is_enabled = regulator_is_enabled_regmap, | ||
42 | }; | ||
43 | |||
44 | #define tps65090_REG(_id) \ | ||
45 | { \ | ||
46 | .id = TPS65090_ID_##_id, \ | ||
47 | .desc = { \ | ||
48 | .name = tps65090_rails(_id), \ | ||
49 | .id = TPS65090_ID_##_id, \ | ||
50 | .ops = &tps65090_ops, \ | ||
51 | .type = REGULATOR_VOLTAGE, \ | ||
52 | .owner = THIS_MODULE, \ | ||
53 | .enable_reg = (TPS65090_ID_##_id) + 12, \ | ||
54 | .enable_mask = BIT(0), \ | ||
55 | }, \ | ||
56 | } | ||
57 | |||
58 | static struct tps65090_regulator TPS65090_regulator[] = { | ||
59 | tps65090_REG(DCDC1), | ||
60 | tps65090_REG(DCDC2), | ||
61 | tps65090_REG(DCDC3), | ||
62 | tps65090_REG(FET1), | ||
63 | tps65090_REG(FET2), | ||
64 | tps65090_REG(FET3), | ||
65 | tps65090_REG(FET4), | ||
66 | tps65090_REG(FET5), | ||
67 | tps65090_REG(FET6), | ||
68 | tps65090_REG(FET7), | ||
69 | }; | ||
70 | |||
71 | static inline struct tps65090_regulator *find_regulator_info(int id) | ||
72 | { | ||
73 | struct tps65090_regulator *ri; | ||
74 | int i; | ||
75 | |||
76 | for (i = 0; i < ARRAY_SIZE(TPS65090_regulator); i++) { | ||
77 | ri = &TPS65090_regulator[i]; | ||
78 | if (ri->desc.id == id) | ||
79 | return ri; | ||
80 | } | ||
81 | return NULL; | ||
82 | } | ||
83 | |||
84 | static int __devinit tps65090_regulator_probe(struct platform_device *pdev) | ||
85 | { | ||
86 | struct tps65090 *tps65090_mfd = dev_get_drvdata(pdev->dev.parent); | ||
87 | struct tps65090_regulator *ri = NULL; | ||
88 | struct regulator_config config = { }; | ||
89 | struct regulator_dev *rdev; | ||
90 | struct tps65090_regulator_platform_data *tps_pdata; | ||
91 | int id = pdev->id; | ||
92 | |||
93 | dev_dbg(&pdev->dev, "Probing regulator %d\n", id); | ||
94 | |||
95 | ri = find_regulator_info(id); | ||
96 | if (ri == NULL) { | ||
97 | dev_err(&pdev->dev, "invalid regulator ID specified\n"); | ||
98 | return -EINVAL; | ||
99 | } | ||
100 | tps_pdata = pdev->dev.platform_data; | ||
101 | ri->dev = &pdev->dev; | ||
102 | |||
103 | config.dev = &pdev->dev; | ||
104 | config.init_data = &tps_pdata->regulator; | ||
105 | config.driver_data = ri; | ||
106 | config.regmap = tps65090_mfd->rmap; | ||
107 | |||
108 | rdev = regulator_register(&ri->desc, &config); | ||
109 | if (IS_ERR(rdev)) { | ||
110 | dev_err(&pdev->dev, "failed to register regulator %s\n", | ||
111 | ri->desc.name); | ||
112 | return PTR_ERR(rdev); | ||
113 | } | ||
114 | |||
115 | platform_set_drvdata(pdev, rdev); | ||
116 | return 0; | ||
117 | } | ||
118 | |||
119 | static int __devexit tps65090_regulator_remove(struct platform_device *pdev) | ||
120 | { | ||
121 | struct regulator_dev *rdev = platform_get_drvdata(pdev); | ||
122 | |||
123 | regulator_unregister(rdev); | ||
124 | return 0; | ||
125 | } | ||
126 | |||
127 | static struct platform_driver tps65090_regulator_driver = { | ||
128 | .driver = { | ||
129 | .name = "tps65090-regulator", | ||
130 | .owner = THIS_MODULE, | ||
131 | }, | ||
132 | .probe = tps65090_regulator_probe, | ||
133 | .remove = __devexit_p(tps65090_regulator_remove), | ||
134 | }; | ||
135 | |||
136 | static int __init tps65090_regulator_init(void) | ||
137 | { | ||
138 | return platform_driver_register(&tps65090_regulator_driver); | ||
139 | } | ||
140 | subsys_initcall(tps65090_regulator_init); | ||
141 | |||
142 | static void __exit tps65090_regulator_exit(void) | ||
143 | { | ||
144 | platform_driver_unregister(&tps65090_regulator_driver); | ||
145 | } | ||
146 | module_exit(tps65090_regulator_exit); | ||
147 | |||
148 | MODULE_DESCRIPTION("tps65090 regulator driver"); | ||
149 | MODULE_AUTHOR("Venu Byravarasu <vbyravarasu@nvidia.com>"); | ||
150 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/regulator/tps65217-regulator.c b/drivers/regulator/tps65217-regulator.c index e39521b42772..9d371d2cbcae 100644 --- a/drivers/regulator/tps65217-regulator.c +++ b/drivers/regulator/tps65217-regulator.c | |||
@@ -213,65 +213,56 @@ static int tps65217_pmic_get_voltage_sel(struct regulator_dev *dev) | |||
213 | return selector; | 213 | return selector; |
214 | } | 214 | } |
215 | 215 | ||
216 | static int tps65217_pmic_ldo1_set_voltage_sel(struct regulator_dev *dev, | 216 | static int tps65217_pmic_set_voltage_sel(struct regulator_dev *dev, |
217 | unsigned selector) | 217 | unsigned selector) |
218 | { | 218 | { |
219 | int ret; | ||
219 | struct tps65217 *tps = rdev_get_drvdata(dev); | 220 | struct tps65217 *tps = rdev_get_drvdata(dev); |
220 | int ldo = rdev_get_id(dev); | 221 | unsigned int rid = rdev_get_id(dev); |
221 | 222 | ||
222 | if (ldo != TPS65217_LDO_1) | 223 | /* Set the voltage based on vsel value and write protect level is 2 */ |
223 | return -EINVAL; | 224 | ret = tps65217_set_bits(tps, tps->info[rid]->set_vout_reg, |
225 | tps->info[rid]->set_vout_mask, | ||
226 | selector, TPS65217_PROTECT_L2); | ||
224 | 227 | ||
225 | if (selector >= tps->info[ldo]->table_len) | 228 | /* Set GO bit for DCDCx to initiate voltage transistion */ |
226 | return -EINVAL; | 229 | switch (rid) { |
230 | case TPS65217_DCDC_1 ... TPS65217_DCDC_3: | ||
231 | ret = tps65217_set_bits(tps, TPS65217_REG_DEFSLEW, | ||
232 | TPS65217_DEFSLEW_GO, TPS65217_DEFSLEW_GO, | ||
233 | TPS65217_PROTECT_L2); | ||
234 | break; | ||
235 | } | ||
227 | 236 | ||
228 | /* Set the voltage based on vsel value and write protect level is 2 */ | 237 | return ret; |
229 | return tps65217_set_bits(tps, tps->info[ldo]->set_vout_reg, | ||
230 | tps->info[ldo]->set_vout_mask, | ||
231 | selector, TPS65217_PROTECT_L2); | ||
232 | } | 238 | } |
233 | 239 | ||
234 | static int tps65217_pmic_set_voltage(struct regulator_dev *dev, | 240 | static int tps65217_pmic_map_voltage(struct regulator_dev *dev, |
235 | int min_uV, int max_uV, unsigned *selector) | 241 | int min_uV, int max_uV) |
236 | { | 242 | { |
237 | int ret; | 243 | |
238 | struct tps65217 *tps = rdev_get_drvdata(dev); | 244 | struct tps65217 *tps = rdev_get_drvdata(dev); |
239 | unsigned int rid = rdev_get_id(dev); | 245 | unsigned int sel, rid = rdev_get_id(dev); |
246 | int ret; | ||
240 | 247 | ||
241 | /* LDO1 implements set_voltage_sel callback */ | 248 | /* LDO1 uses regulator_map_voltage_iterate() */ |
242 | if (rid == TPS65217_LDO_1) | 249 | if (rid == TPS65217_LDO_1) |
243 | return -EINVAL; | 250 | return -EINVAL; |
244 | 251 | ||
245 | if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4) | 252 | if (rid < TPS65217_DCDC_1 || rid > TPS65217_LDO_4) |
246 | return -EINVAL; | 253 | return -EINVAL; |
247 | 254 | ||
248 | if (min_uV < tps->info[rid]->min_uV | 255 | if (min_uV < tps->info[rid]->min_uV || min_uV > tps->info[rid]->max_uV) |
249 | || min_uV > tps->info[rid]->max_uV) | ||
250 | return -EINVAL; | 256 | return -EINVAL; |
251 | 257 | ||
252 | if (max_uV < tps->info[rid]->min_uV | 258 | if (max_uV < tps->info[rid]->min_uV || max_uV > tps->info[rid]->max_uV) |
253 | || max_uV > tps->info[rid]->max_uV) | ||
254 | return -EINVAL; | 259 | return -EINVAL; |
255 | 260 | ||
256 | ret = tps->info[rid]->uv_to_vsel(min_uV, selector); | 261 | ret = tps->info[rid]->uv_to_vsel(min_uV, &sel); |
257 | if (ret) | 262 | if (ret) |
258 | return ret; | 263 | return ret; |
259 | 264 | ||
260 | /* Set the voltage based on vsel value and write protect level is 2 */ | 265 | return sel; |
261 | ret = tps65217_set_bits(tps, tps->info[rid]->set_vout_reg, | ||
262 | tps->info[rid]->set_vout_mask, | ||
263 | *selector, TPS65217_PROTECT_L2); | ||
264 | |||
265 | /* Set GO bit for DCDCx to initiate voltage transistion */ | ||
266 | switch (rid) { | ||
267 | case TPS65217_DCDC_1 ... TPS65217_DCDC_3: | ||
268 | ret = tps65217_set_bits(tps, TPS65217_REG_DEFSLEW, | ||
269 | TPS65217_DEFSLEW_GO, TPS65217_DEFSLEW_GO, | ||
270 | TPS65217_PROTECT_L2); | ||
271 | break; | ||
272 | } | ||
273 | |||
274 | return ret; | ||
275 | } | 266 | } |
276 | 267 | ||
277 | static int tps65217_pmic_list_voltage(struct regulator_dev *dev, | 268 | static int tps65217_pmic_list_voltage(struct regulator_dev *dev, |
@@ -298,8 +289,9 @@ static struct regulator_ops tps65217_pmic_ops = { | |||
298 | .enable = tps65217_pmic_enable, | 289 | .enable = tps65217_pmic_enable, |
299 | .disable = tps65217_pmic_disable, | 290 | .disable = tps65217_pmic_disable, |
300 | .get_voltage_sel = tps65217_pmic_get_voltage_sel, | 291 | .get_voltage_sel = tps65217_pmic_get_voltage_sel, |
301 | .set_voltage = tps65217_pmic_set_voltage, | 292 | .set_voltage_sel = tps65217_pmic_set_voltage_sel, |
302 | .list_voltage = tps65217_pmic_list_voltage, | 293 | .list_voltage = tps65217_pmic_list_voltage, |
294 | .map_voltage = tps65217_pmic_map_voltage, | ||
303 | }; | 295 | }; |
304 | 296 | ||
305 | /* Operations permitted on LDO1 */ | 297 | /* Operations permitted on LDO1 */ |
@@ -308,11 +300,11 @@ static struct regulator_ops tps65217_pmic_ldo1_ops = { | |||
308 | .enable = tps65217_pmic_enable, | 300 | .enable = tps65217_pmic_enable, |
309 | .disable = tps65217_pmic_disable, | 301 | .disable = tps65217_pmic_disable, |
310 | .get_voltage_sel = tps65217_pmic_get_voltage_sel, | 302 | .get_voltage_sel = tps65217_pmic_get_voltage_sel, |
311 | .set_voltage_sel = tps65217_pmic_ldo1_set_voltage_sel, | 303 | .set_voltage_sel = tps65217_pmic_set_voltage_sel, |
312 | .list_voltage = tps65217_pmic_list_voltage, | 304 | .list_voltage = tps65217_pmic_list_voltage, |
313 | }; | 305 | }; |
314 | 306 | ||
315 | static struct regulator_desc regulators[] = { | 307 | static const struct regulator_desc regulators[] = { |
316 | TPS65217_REGULATOR("DCDC1", TPS65217_DCDC_1, tps65217_pmic_ops, 64), | 308 | TPS65217_REGULATOR("DCDC1", TPS65217_DCDC_1, tps65217_pmic_ops, 64), |
317 | TPS65217_REGULATOR("DCDC2", TPS65217_DCDC_2, tps65217_pmic_ops, 64), | 309 | TPS65217_REGULATOR("DCDC2", TPS65217_DCDC_2, tps65217_pmic_ops, 64), |
318 | TPS65217_REGULATOR("DCDC3", TPS65217_DCDC_3, tps65217_pmic_ops, 64), | 310 | TPS65217_REGULATOR("DCDC3", TPS65217_DCDC_3, tps65217_pmic_ops, 64), |
@@ -327,13 +319,17 @@ static int __devinit tps65217_regulator_probe(struct platform_device *pdev) | |||
327 | struct regulator_dev *rdev; | 319 | struct regulator_dev *rdev; |
328 | struct tps65217 *tps; | 320 | struct tps65217 *tps; |
329 | struct tps_info *info = &tps65217_pmic_regs[pdev->id]; | 321 | struct tps_info *info = &tps65217_pmic_regs[pdev->id]; |
322 | struct regulator_config config = { }; | ||
330 | 323 | ||
331 | /* Already set by core driver */ | 324 | /* Already set by core driver */ |
332 | tps = dev_to_tps65217(pdev->dev.parent); | 325 | tps = dev_to_tps65217(pdev->dev.parent); |
333 | tps->info[pdev->id] = info; | 326 | tps->info[pdev->id] = info; |
334 | 327 | ||
335 | rdev = regulator_register(®ulators[pdev->id], &pdev->dev, | 328 | config.dev = &pdev->dev; |
336 | pdev->dev.platform_data, tps, NULL); | 329 | config.init_data = pdev->dev.platform_data; |
330 | config.driver_data = tps; | ||
331 | |||
332 | rdev = regulator_register(®ulators[pdev->id], &config); | ||
337 | if (IS_ERR(rdev)) | 333 | if (IS_ERR(rdev)) |
338 | return PTR_ERR(rdev); | 334 | return PTR_ERR(rdev); |
339 | 335 | ||
diff --git a/drivers/regulator/tps6524x-regulator.c b/drivers/regulator/tps6524x-regulator.c index 4a421be6d4f2..b88b3df82381 100644 --- a/drivers/regulator/tps6524x-regulator.c +++ b/drivers/regulator/tps6524x-regulator.c | |||
@@ -458,12 +458,10 @@ static int list_voltage(struct regulator_dev *rdev, unsigned selector) | |||
458 | info->voltages[selector] : -EINVAL); | 458 | info->voltages[selector] : -EINVAL); |
459 | } | 459 | } |
460 | 460 | ||
461 | static int set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV, | 461 | static int set_voltage_sel(struct regulator_dev *rdev, unsigned selector) |
462 | unsigned *selector) | ||
463 | { | 462 | { |
464 | const struct supply_info *info; | 463 | const struct supply_info *info; |
465 | struct tps6524x *hw; | 464 | struct tps6524x *hw; |
466 | unsigned i; | ||
467 | 465 | ||
468 | hw = rdev_get_drvdata(rdev); | 466 | hw = rdev_get_drvdata(rdev); |
469 | info = &supply_info[rdev_get_id(rdev)]; | 467 | info = &supply_info[rdev_get_id(rdev)]; |
@@ -471,20 +469,10 @@ static int set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV, | |||
471 | if (info->flags & FIXED_VOLTAGE) | 469 | if (info->flags & FIXED_VOLTAGE) |
472 | return -EINVAL; | 470 | return -EINVAL; |
473 | 471 | ||
474 | for (i = 0; i < info->n_voltages; i++) | 472 | return write_field(hw, &info->voltage, selector); |
475 | if (min_uV <= info->voltages[i] && | ||
476 | max_uV >= info->voltages[i]) | ||
477 | break; | ||
478 | |||
479 | if (i >= info->n_voltages) | ||
480 | i = info->n_voltages - 1; | ||
481 | |||
482 | *selector = i; | ||
483 | |||
484 | return write_field(hw, &info->voltage, i); | ||
485 | } | 473 | } |
486 | 474 | ||
487 | static int get_voltage(struct regulator_dev *rdev) | 475 | static int get_voltage_sel(struct regulator_dev *rdev) |
488 | { | 476 | { |
489 | const struct supply_info *info; | 477 | const struct supply_info *info; |
490 | struct tps6524x *hw; | 478 | struct tps6524x *hw; |
@@ -502,7 +490,7 @@ static int get_voltage(struct regulator_dev *rdev) | |||
502 | if (WARN_ON(ret >= info->n_voltages)) | 490 | if (WARN_ON(ret >= info->n_voltages)) |
503 | return -EIO; | 491 | return -EIO; |
504 | 492 | ||
505 | return info->voltages[ret]; | 493 | return ret; |
506 | } | 494 | } |
507 | 495 | ||
508 | static int set_current_limit(struct regulator_dev *rdev, int min_uA, | 496 | static int set_current_limit(struct regulator_dev *rdev, int min_uA, |
@@ -587,8 +575,8 @@ static struct regulator_ops regulator_ops = { | |||
587 | .is_enabled = is_supply_enabled, | 575 | .is_enabled = is_supply_enabled, |
588 | .enable = enable_supply, | 576 | .enable = enable_supply, |
589 | .disable = disable_supply, | 577 | .disable = disable_supply, |
590 | .get_voltage = get_voltage, | 578 | .get_voltage_sel = get_voltage_sel, |
591 | .set_voltage = set_voltage, | 579 | .set_voltage_sel = set_voltage_sel, |
592 | .list_voltage = list_voltage, | 580 | .list_voltage = list_voltage, |
593 | .set_current_limit = set_current_limit, | 581 | .set_current_limit = set_current_limit, |
594 | .get_current_limit = get_current_limit, | 582 | .get_current_limit = get_current_limit, |
@@ -607,7 +595,6 @@ static int pmic_remove(struct spi_device *spi) | |||
607 | hw->rdev[i] = NULL; | 595 | hw->rdev[i] = NULL; |
608 | } | 596 | } |
609 | spi_set_drvdata(spi, NULL); | 597 | spi_set_drvdata(spi, NULL); |
610 | kfree(hw); | ||
611 | return 0; | 598 | return 0; |
612 | } | 599 | } |
613 | 600 | ||
@@ -617,6 +604,7 @@ static int __devinit pmic_probe(struct spi_device *spi) | |||
617 | struct device *dev = &spi->dev; | 604 | struct device *dev = &spi->dev; |
618 | const struct supply_info *info = supply_info; | 605 | const struct supply_info *info = supply_info; |
619 | struct regulator_init_data *init_data; | 606 | struct regulator_init_data *init_data; |
607 | struct regulator_config config = { }; | ||
620 | int ret = 0, i; | 608 | int ret = 0, i; |
621 | 609 | ||
622 | init_data = dev->platform_data; | 610 | init_data = dev->platform_data; |
@@ -625,7 +613,7 @@ static int __devinit pmic_probe(struct spi_device *spi) | |||
625 | return -EINVAL; | 613 | return -EINVAL; |
626 | } | 614 | } |
627 | 615 | ||
628 | hw = kzalloc(sizeof(struct tps6524x), GFP_KERNEL); | 616 | hw = devm_kzalloc(&spi->dev, sizeof(struct tps6524x), GFP_KERNEL); |
629 | if (!hw) { | 617 | if (!hw) { |
630 | dev_err(dev, "cannot allocate regulator private data\n"); | 618 | dev_err(dev, "cannot allocate regulator private data\n"); |
631 | return -ENOMEM; | 619 | return -ENOMEM; |
@@ -648,8 +636,11 @@ static int __devinit pmic_probe(struct spi_device *spi) | |||
648 | if (info->flags & FIXED_VOLTAGE) | 636 | if (info->flags & FIXED_VOLTAGE) |
649 | hw->desc[i].n_voltages = 1; | 637 | hw->desc[i].n_voltages = 1; |
650 | 638 | ||
651 | hw->rdev[i] = regulator_register(&hw->desc[i], dev, | 639 | config.dev = dev; |
652 | init_data, hw, NULL); | 640 | config.init_data = init_data; |
641 | config.driver_data = hw; | ||
642 | |||
643 | hw->rdev[i] = regulator_register(&hw->desc[i], &config); | ||
653 | if (IS_ERR(hw->rdev[i])) { | 644 | if (IS_ERR(hw->rdev[i])) { |
654 | ret = PTR_ERR(hw->rdev[i]); | 645 | ret = PTR_ERR(hw->rdev[i]); |
655 | hw->rdev[i] = NULL; | 646 | hw->rdev[i] = NULL; |
@@ -673,17 +664,7 @@ static struct spi_driver pmic_driver = { | |||
673 | }, | 664 | }, |
674 | }; | 665 | }; |
675 | 666 | ||
676 | static int __init pmic_driver_init(void) | 667 | module_spi_driver(pmic_driver); |
677 | { | ||
678 | return spi_register_driver(&pmic_driver); | ||
679 | } | ||
680 | module_init(pmic_driver_init); | ||
681 | |||
682 | static void __exit pmic_driver_exit(void) | ||
683 | { | ||
684 | spi_unregister_driver(&pmic_driver); | ||
685 | } | ||
686 | module_exit(pmic_driver_exit); | ||
687 | 668 | ||
688 | MODULE_DESCRIPTION("TPS6524X PMIC Driver"); | 669 | MODULE_DESCRIPTION("TPS6524X PMIC Driver"); |
689 | MODULE_AUTHOR("Cyril Chemparathy"); | 670 | MODULE_AUTHOR("Cyril Chemparathy"); |
diff --git a/drivers/regulator/tps6586x-regulator.c b/drivers/regulator/tps6586x-regulator.c index cfc1f16f7771..c0a214575380 100644 --- a/drivers/regulator/tps6586x-regulator.c +++ b/drivers/regulator/tps6586x-regulator.c | |||
@@ -75,8 +75,7 @@ static inline struct device *to_tps6586x_dev(struct regulator_dev *rdev) | |||
75 | return rdev_get_dev(rdev)->parent->parent; | 75 | return rdev_get_dev(rdev)->parent->parent; |
76 | } | 76 | } |
77 | 77 | ||
78 | static int tps6586x_ldo_list_voltage(struct regulator_dev *rdev, | 78 | static int tps6586x_list_voltage(struct regulator_dev *rdev, unsigned selector) |
79 | unsigned selector) | ||
80 | { | 79 | { |
81 | struct tps6586x_regulator *info = rdev_get_drvdata(rdev); | 80 | struct tps6586x_regulator *info = rdev_get_drvdata(rdev); |
82 | int rid = rdev_get_id(rdev); | 81 | int rid = rdev_get_id(rdev); |
@@ -89,47 +88,34 @@ static int tps6586x_ldo_list_voltage(struct regulator_dev *rdev, | |||
89 | } | 88 | } |
90 | 89 | ||
91 | 90 | ||
92 | static int __tps6586x_ldo_set_voltage(struct device *parent, | 91 | static int tps6586x_set_voltage_sel(struct regulator_dev *rdev, |
93 | struct tps6586x_regulator *ri, | 92 | unsigned selector) |
94 | int min_uV, int max_uV, | ||
95 | unsigned *selector) | ||
96 | { | 93 | { |
97 | int val, uV; | 94 | struct tps6586x_regulator *ri = rdev_get_drvdata(rdev); |
95 | struct device *parent = to_tps6586x_dev(rdev); | ||
96 | int ret, val, rid = rdev_get_id(rdev); | ||
98 | uint8_t mask; | 97 | uint8_t mask; |
99 | 98 | ||
100 | for (val = 0; val < ri->desc.n_voltages; val++) { | 99 | val = selector << ri->volt_shift; |
101 | uV = ri->voltages[val] * 1000; | 100 | mask = ((1 << ri->volt_nbits) - 1) << ri->volt_shift; |
102 | |||
103 | /* LDO0 has minimal voltage 1.2 rather than 1.25 */ | ||
104 | if (ri->desc.id == TPS6586X_ID_LDO_0 && val == 0) | ||
105 | uV -= 50 * 1000; | ||
106 | |||
107 | /* use the first in-range value */ | ||
108 | if (min_uV <= uV && uV <= max_uV) { | ||
109 | |||
110 | *selector = val; | ||
111 | 101 | ||
112 | val <<= ri->volt_shift; | 102 | ret = tps6586x_update(parent, ri->volt_reg, val, mask); |
113 | mask = ((1 << ri->volt_nbits) - 1) << ri->volt_shift; | 103 | if (ret) |
104 | return ret; | ||
114 | 105 | ||
115 | return tps6586x_update(parent, ri->volt_reg, val, mask); | 106 | /* Update go bit for DVM regulators */ |
116 | } | 107 | switch (rid) { |
108 | case TPS6586X_ID_LDO_2: | ||
109 | case TPS6586X_ID_LDO_4: | ||
110 | case TPS6586X_ID_SM_0: | ||
111 | case TPS6586X_ID_SM_1: | ||
112 | ret = tps6586x_set_bits(parent, ri->go_reg, 1 << ri->go_bit); | ||
113 | break; | ||
117 | } | 114 | } |
118 | 115 | return ret; | |
119 | return -EINVAL; | ||
120 | } | ||
121 | |||
122 | static int tps6586x_ldo_set_voltage(struct regulator_dev *rdev, | ||
123 | int min_uV, int max_uV, unsigned *selector) | ||
124 | { | ||
125 | struct tps6586x_regulator *ri = rdev_get_drvdata(rdev); | ||
126 | struct device *parent = to_tps6586x_dev(rdev); | ||
127 | |||
128 | return __tps6586x_ldo_set_voltage(parent, ri, min_uV, max_uV, | ||
129 | selector); | ||
130 | } | 116 | } |
131 | 117 | ||
132 | static int tps6586x_ldo_get_voltage(struct regulator_dev *rdev) | 118 | static int tps6586x_get_voltage_sel(struct regulator_dev *rdev) |
133 | { | 119 | { |
134 | struct tps6586x_regulator *ri = rdev_get_drvdata(rdev); | 120 | struct tps6586x_regulator *ri = rdev_get_drvdata(rdev); |
135 | struct device *parent = to_tps6586x_dev(rdev); | 121 | struct device *parent = to_tps6586x_dev(rdev); |
@@ -146,22 +132,7 @@ static int tps6586x_ldo_get_voltage(struct regulator_dev *rdev) | |||
146 | if (val >= ri->desc.n_voltages) | 132 | if (val >= ri->desc.n_voltages) |
147 | BUG(); | 133 | BUG(); |
148 | 134 | ||
149 | return ri->voltages[val] * 1000; | 135 | return val; |
150 | } | ||
151 | |||
152 | static int tps6586x_dvm_set_voltage(struct regulator_dev *rdev, | ||
153 | int min_uV, int max_uV, unsigned *selector) | ||
154 | { | ||
155 | struct tps6586x_regulator *ri = rdev_get_drvdata(rdev); | ||
156 | struct device *parent = to_tps6586x_dev(rdev); | ||
157 | int ret; | ||
158 | |||
159 | ret = __tps6586x_ldo_set_voltage(parent, ri, min_uV, max_uV, | ||
160 | selector); | ||
161 | if (ret) | ||
162 | return ret; | ||
163 | |||
164 | return tps6586x_set_bits(parent, ri->go_reg, 1 << ri->go_bit); | ||
165 | } | 136 | } |
166 | 137 | ||
167 | static int tps6586x_regulator_enable(struct regulator_dev *rdev) | 138 | static int tps6586x_regulator_enable(struct regulator_dev *rdev) |
@@ -196,20 +167,10 @@ static int tps6586x_regulator_is_enabled(struct regulator_dev *rdev) | |||
196 | return !!(reg_val & (1 << ri->enable_bit[0])); | 167 | return !!(reg_val & (1 << ri->enable_bit[0])); |
197 | } | 168 | } |
198 | 169 | ||
199 | static struct regulator_ops tps6586x_regulator_ldo_ops = { | 170 | static struct regulator_ops tps6586x_regulator_ops = { |
200 | .list_voltage = tps6586x_ldo_list_voltage, | 171 | .list_voltage = tps6586x_list_voltage, |
201 | .get_voltage = tps6586x_ldo_get_voltage, | 172 | .get_voltage_sel = tps6586x_get_voltage_sel, |
202 | .set_voltage = tps6586x_ldo_set_voltage, | 173 | .set_voltage_sel = tps6586x_set_voltage_sel, |
203 | |||
204 | .is_enabled = tps6586x_regulator_is_enabled, | ||
205 | .enable = tps6586x_regulator_enable, | ||
206 | .disable = tps6586x_regulator_disable, | ||
207 | }; | ||
208 | |||
209 | static struct regulator_ops tps6586x_regulator_dvm_ops = { | ||
210 | .list_voltage = tps6586x_ldo_list_voltage, | ||
211 | .get_voltage = tps6586x_ldo_get_voltage, | ||
212 | .set_voltage = tps6586x_dvm_set_voltage, | ||
213 | 174 | ||
214 | .is_enabled = tps6586x_regulator_is_enabled, | 175 | .is_enabled = tps6586x_regulator_is_enabled, |
215 | .enable = tps6586x_regulator_enable, | 176 | .enable = tps6586x_regulator_enable, |
@@ -241,11 +202,11 @@ static int tps6586x_dvm_voltages[] = { | |||
241 | 1325, 1350, 1375, 1400, 1425, 1450, 1475, 1500, | 202 | 1325, 1350, 1375, 1400, 1425, 1450, 1475, 1500, |
242 | }; | 203 | }; |
243 | 204 | ||
244 | #define TPS6586X_REGULATOR(_id, vdata, _ops, vreg, shift, nbits, \ | 205 | #define TPS6586X_REGULATOR(_id, vdata, vreg, shift, nbits, \ |
245 | ereg0, ebit0, ereg1, ebit1) \ | 206 | ereg0, ebit0, ereg1, ebit1) \ |
246 | .desc = { \ | 207 | .desc = { \ |
247 | .name = "REG-" #_id, \ | 208 | .name = "REG-" #_id, \ |
248 | .ops = &tps6586x_regulator_##_ops, \ | 209 | .ops = &tps6586x_regulator_ops, \ |
249 | .type = REGULATOR_VOLTAGE, \ | 210 | .type = REGULATOR_VOLTAGE, \ |
250 | .id = TPS6586X_ID_##_id, \ | 211 | .id = TPS6586X_ID_##_id, \ |
251 | .n_voltages = ARRAY_SIZE(tps6586x_##vdata##_voltages), \ | 212 | .n_voltages = ARRAY_SIZE(tps6586x_##vdata##_voltages), \ |
@@ -267,14 +228,14 @@ static int tps6586x_dvm_voltages[] = { | |||
267 | #define TPS6586X_LDO(_id, vdata, vreg, shift, nbits, \ | 228 | #define TPS6586X_LDO(_id, vdata, vreg, shift, nbits, \ |
268 | ereg0, ebit0, ereg1, ebit1) \ | 229 | ereg0, ebit0, ereg1, ebit1) \ |
269 | { \ | 230 | { \ |
270 | TPS6586X_REGULATOR(_id, vdata, ldo_ops, vreg, shift, nbits, \ | 231 | TPS6586X_REGULATOR(_id, vdata, vreg, shift, nbits, \ |
271 | ereg0, ebit0, ereg1, ebit1) \ | 232 | ereg0, ebit0, ereg1, ebit1) \ |
272 | } | 233 | } |
273 | 234 | ||
274 | #define TPS6586X_DVM(_id, vdata, vreg, shift, nbits, \ | 235 | #define TPS6586X_DVM(_id, vdata, vreg, shift, nbits, \ |
275 | ereg0, ebit0, ereg1, ebit1, goreg, gobit) \ | 236 | ereg0, ebit0, ereg1, ebit1, goreg, gobit) \ |
276 | { \ | 237 | { \ |
277 | TPS6586X_REGULATOR(_id, vdata, dvm_ops, vreg, shift, nbits, \ | 238 | TPS6586X_REGULATOR(_id, vdata, vreg, shift, nbits, \ |
278 | ereg0, ebit0, ereg1, ebit1) \ | 239 | ereg0, ebit0, ereg1, ebit1) \ |
279 | TPS6586X_REGULATOR_DVM_GOREG(goreg, gobit) \ | 240 | TPS6586X_REGULATOR_DVM_GOREG(goreg, gobit) \ |
280 | } | 241 | } |
@@ -384,6 +345,7 @@ static inline struct tps6586x_regulator *find_regulator_info(int id) | |||
384 | static int __devinit tps6586x_regulator_probe(struct platform_device *pdev) | 345 | static int __devinit tps6586x_regulator_probe(struct platform_device *pdev) |
385 | { | 346 | { |
386 | struct tps6586x_regulator *ri = NULL; | 347 | struct tps6586x_regulator *ri = NULL; |
348 | struct regulator_config config = { }; | ||
387 | struct regulator_dev *rdev; | 349 | struct regulator_dev *rdev; |
388 | int id = pdev->id; | 350 | int id = pdev->id; |
389 | int err; | 351 | int err; |
@@ -400,8 +362,12 @@ static int __devinit tps6586x_regulator_probe(struct platform_device *pdev) | |||
400 | if (err) | 362 | if (err) |
401 | return err; | 363 | return err; |
402 | 364 | ||
403 | rdev = regulator_register(&ri->desc, &pdev->dev, | 365 | config.dev = &pdev->dev; |
404 | pdev->dev.platform_data, ri, NULL); | 366 | config.of_node = pdev->dev.of_node; |
367 | config.init_data = pdev->dev.platform_data; | ||
368 | config.driver_data = ri; | ||
369 | |||
370 | rdev = regulator_register(&ri->desc, &config); | ||
405 | if (IS_ERR(rdev)) { | 371 | if (IS_ERR(rdev)) { |
406 | dev_err(&pdev->dev, "failed to register regulator %s\n", | 372 | dev_err(&pdev->dev, "failed to register regulator %s\n", |
407 | ri->desc.name); | 373 | ri->desc.name); |
diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c index 4a37c2b6367f..8dc3d9392bfa 100644 --- a/drivers/regulator/tps65910-regulator.c +++ b/drivers/regulator/tps65910-regulator.c | |||
@@ -20,10 +20,10 @@ | |||
20 | #include <linux/platform_device.h> | 20 | #include <linux/platform_device.h> |
21 | #include <linux/regulator/driver.h> | 21 | #include <linux/regulator/driver.h> |
22 | #include <linux/regulator/machine.h> | 22 | #include <linux/regulator/machine.h> |
23 | #include <linux/delay.h> | ||
24 | #include <linux/slab.h> | 23 | #include <linux/slab.h> |
25 | #include <linux/gpio.h> | 24 | #include <linux/gpio.h> |
26 | #include <linux/mfd/tps65910.h> | 25 | #include <linux/mfd/tps65910.h> |
26 | #include <linux/regulator/of_regulator.h> | ||
27 | 27 | ||
28 | #define TPS65910_SUPPLY_STATE_ENABLED 0x1 | 28 | #define TPS65910_SUPPLY_STATE_ENABLED 0x1 |
29 | #define EXT_SLEEP_CONTROL (TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1 | \ | 29 | #define EXT_SLEEP_CONTROL (TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1 | \ |
@@ -94,11 +94,11 @@ struct tps_info { | |||
94 | 94 | ||
95 | static struct tps_info tps65910_regs[] = { | 95 | static struct tps_info tps65910_regs[] = { |
96 | { | 96 | { |
97 | .name = "VRTC", | 97 | .name = "vrtc", |
98 | .enable_time_us = 2200, | 98 | .enable_time_us = 2200, |
99 | }, | 99 | }, |
100 | { | 100 | { |
101 | .name = "VIO", | 101 | .name = "vio", |
102 | .min_uV = 1500000, | 102 | .min_uV = 1500000, |
103 | .max_uV = 3300000, | 103 | .max_uV = 3300000, |
104 | .n_voltages = ARRAY_SIZE(VIO_VSEL_table), | 104 | .n_voltages = ARRAY_SIZE(VIO_VSEL_table), |
@@ -106,19 +106,19 @@ static struct tps_info tps65910_regs[] = { | |||
106 | .enable_time_us = 350, | 106 | .enable_time_us = 350, |
107 | }, | 107 | }, |
108 | { | 108 | { |
109 | .name = "VDD1", | 109 | .name = "vdd1", |
110 | .min_uV = 600000, | 110 | .min_uV = 600000, |
111 | .max_uV = 4500000, | 111 | .max_uV = 4500000, |
112 | .enable_time_us = 350, | 112 | .enable_time_us = 350, |
113 | }, | 113 | }, |
114 | { | 114 | { |
115 | .name = "VDD2", | 115 | .name = "vdd2", |
116 | .min_uV = 600000, | 116 | .min_uV = 600000, |
117 | .max_uV = 4500000, | 117 | .max_uV = 4500000, |
118 | .enable_time_us = 350, | 118 | .enable_time_us = 350, |
119 | }, | 119 | }, |
120 | { | 120 | { |
121 | .name = "VDD3", | 121 | .name = "vdd3", |
122 | .min_uV = 5000000, | 122 | .min_uV = 5000000, |
123 | .max_uV = 5000000, | 123 | .max_uV = 5000000, |
124 | .n_voltages = ARRAY_SIZE(VDD3_VSEL_table), | 124 | .n_voltages = ARRAY_SIZE(VDD3_VSEL_table), |
@@ -126,7 +126,7 @@ static struct tps_info tps65910_regs[] = { | |||
126 | .enable_time_us = 200, | 126 | .enable_time_us = 200, |
127 | }, | 127 | }, |
128 | { | 128 | { |
129 | .name = "VDIG1", | 129 | .name = "vdig1", |
130 | .min_uV = 1200000, | 130 | .min_uV = 1200000, |
131 | .max_uV = 2700000, | 131 | .max_uV = 2700000, |
132 | .n_voltages = ARRAY_SIZE(VDIG1_VSEL_table), | 132 | .n_voltages = ARRAY_SIZE(VDIG1_VSEL_table), |
@@ -134,7 +134,7 @@ static struct tps_info tps65910_regs[] = { | |||
134 | .enable_time_us = 100, | 134 | .enable_time_us = 100, |
135 | }, | 135 | }, |
136 | { | 136 | { |
137 | .name = "VDIG2", | 137 | .name = "vdig2", |
138 | .min_uV = 1000000, | 138 | .min_uV = 1000000, |
139 | .max_uV = 1800000, | 139 | .max_uV = 1800000, |
140 | .n_voltages = ARRAY_SIZE(VDIG2_VSEL_table), | 140 | .n_voltages = ARRAY_SIZE(VDIG2_VSEL_table), |
@@ -142,7 +142,7 @@ static struct tps_info tps65910_regs[] = { | |||
142 | .enable_time_us = 100, | 142 | .enable_time_us = 100, |
143 | }, | 143 | }, |
144 | { | 144 | { |
145 | .name = "VPLL", | 145 | .name = "vpll", |
146 | .min_uV = 1000000, | 146 | .min_uV = 1000000, |
147 | .max_uV = 2500000, | 147 | .max_uV = 2500000, |
148 | .n_voltages = ARRAY_SIZE(VPLL_VSEL_table), | 148 | .n_voltages = ARRAY_SIZE(VPLL_VSEL_table), |
@@ -150,7 +150,7 @@ static struct tps_info tps65910_regs[] = { | |||
150 | .enable_time_us = 100, | 150 | .enable_time_us = 100, |
151 | }, | 151 | }, |
152 | { | 152 | { |
153 | .name = "VDAC", | 153 | .name = "vdac", |
154 | .min_uV = 1800000, | 154 | .min_uV = 1800000, |
155 | .max_uV = 2850000, | 155 | .max_uV = 2850000, |
156 | .n_voltages = ARRAY_SIZE(VDAC_VSEL_table), | 156 | .n_voltages = ARRAY_SIZE(VDAC_VSEL_table), |
@@ -158,7 +158,7 @@ static struct tps_info tps65910_regs[] = { | |||
158 | .enable_time_us = 100, | 158 | .enable_time_us = 100, |
159 | }, | 159 | }, |
160 | { | 160 | { |
161 | .name = "VAUX1", | 161 | .name = "vaux1", |
162 | .min_uV = 1800000, | 162 | .min_uV = 1800000, |
163 | .max_uV = 2850000, | 163 | .max_uV = 2850000, |
164 | .n_voltages = ARRAY_SIZE(VAUX1_VSEL_table), | 164 | .n_voltages = ARRAY_SIZE(VAUX1_VSEL_table), |
@@ -166,7 +166,7 @@ static struct tps_info tps65910_regs[] = { | |||
166 | .enable_time_us = 100, | 166 | .enable_time_us = 100, |
167 | }, | 167 | }, |
168 | { | 168 | { |
169 | .name = "VAUX2", | 169 | .name = "vaux2", |
170 | .min_uV = 1800000, | 170 | .min_uV = 1800000, |
171 | .max_uV = 3300000, | 171 | .max_uV = 3300000, |
172 | .n_voltages = ARRAY_SIZE(VAUX2_VSEL_table), | 172 | .n_voltages = ARRAY_SIZE(VAUX2_VSEL_table), |
@@ -174,7 +174,7 @@ static struct tps_info tps65910_regs[] = { | |||
174 | .enable_time_us = 100, | 174 | .enable_time_us = 100, |
175 | }, | 175 | }, |
176 | { | 176 | { |
177 | .name = "VAUX33", | 177 | .name = "vaux33", |
178 | .min_uV = 1800000, | 178 | .min_uV = 1800000, |
179 | .max_uV = 3300000, | 179 | .max_uV = 3300000, |
180 | .n_voltages = ARRAY_SIZE(VAUX33_VSEL_table), | 180 | .n_voltages = ARRAY_SIZE(VAUX33_VSEL_table), |
@@ -182,7 +182,7 @@ static struct tps_info tps65910_regs[] = { | |||
182 | .enable_time_us = 100, | 182 | .enable_time_us = 100, |
183 | }, | 183 | }, |
184 | { | 184 | { |
185 | .name = "VMMC", | 185 | .name = "vmmc", |
186 | .min_uV = 1800000, | 186 | .min_uV = 1800000, |
187 | .max_uV = 3300000, | 187 | .max_uV = 3300000, |
188 | .n_voltages = ARRAY_SIZE(VMMC_VSEL_table), | 188 | .n_voltages = ARRAY_SIZE(VMMC_VSEL_table), |
@@ -193,11 +193,11 @@ static struct tps_info tps65910_regs[] = { | |||
193 | 193 | ||
194 | static struct tps_info tps65911_regs[] = { | 194 | static struct tps_info tps65911_regs[] = { |
195 | { | 195 | { |
196 | .name = "VRTC", | 196 | .name = "vrtc", |
197 | .enable_time_us = 2200, | 197 | .enable_time_us = 2200, |
198 | }, | 198 | }, |
199 | { | 199 | { |
200 | .name = "VIO", | 200 | .name = "vio", |
201 | .min_uV = 1500000, | 201 | .min_uV = 1500000, |
202 | .max_uV = 3300000, | 202 | .max_uV = 3300000, |
203 | .n_voltages = ARRAY_SIZE(VIO_VSEL_table), | 203 | .n_voltages = ARRAY_SIZE(VIO_VSEL_table), |
@@ -205,77 +205,77 @@ static struct tps_info tps65911_regs[] = { | |||
205 | .enable_time_us = 350, | 205 | .enable_time_us = 350, |
206 | }, | 206 | }, |
207 | { | 207 | { |
208 | .name = "VDD1", | 208 | .name = "vdd1", |
209 | .min_uV = 600000, | 209 | .min_uV = 600000, |
210 | .max_uV = 4500000, | 210 | .max_uV = 4500000, |
211 | .n_voltages = 73, | 211 | .n_voltages = 73, |
212 | .enable_time_us = 350, | 212 | .enable_time_us = 350, |
213 | }, | 213 | }, |
214 | { | 214 | { |
215 | .name = "VDD2", | 215 | .name = "vdd2", |
216 | .min_uV = 600000, | 216 | .min_uV = 600000, |
217 | .max_uV = 4500000, | 217 | .max_uV = 4500000, |
218 | .n_voltages = 73, | 218 | .n_voltages = 73, |
219 | .enable_time_us = 350, | 219 | .enable_time_us = 350, |
220 | }, | 220 | }, |
221 | { | 221 | { |
222 | .name = "VDDCTRL", | 222 | .name = "vddctrl", |
223 | .min_uV = 600000, | 223 | .min_uV = 600000, |
224 | .max_uV = 1400000, | 224 | .max_uV = 1400000, |
225 | .n_voltages = 65, | 225 | .n_voltages = 65, |
226 | .enable_time_us = 900, | 226 | .enable_time_us = 900, |
227 | }, | 227 | }, |
228 | { | 228 | { |
229 | .name = "LDO1", | 229 | .name = "ldo1", |
230 | .min_uV = 1000000, | 230 | .min_uV = 1000000, |
231 | .max_uV = 3300000, | 231 | .max_uV = 3300000, |
232 | .n_voltages = 47, | 232 | .n_voltages = 47, |
233 | .enable_time_us = 420, | 233 | .enable_time_us = 420, |
234 | }, | 234 | }, |
235 | { | 235 | { |
236 | .name = "LDO2", | 236 | .name = "ldo2", |
237 | .min_uV = 1000000, | 237 | .min_uV = 1000000, |
238 | .max_uV = 3300000, | 238 | .max_uV = 3300000, |
239 | .n_voltages = 47, | 239 | .n_voltages = 47, |
240 | .enable_time_us = 420, | 240 | .enable_time_us = 420, |
241 | }, | 241 | }, |
242 | { | 242 | { |
243 | .name = "LDO3", | 243 | .name = "ldo3", |
244 | .min_uV = 1000000, | 244 | .min_uV = 1000000, |
245 | .max_uV = 3300000, | 245 | .max_uV = 3300000, |
246 | .n_voltages = 24, | 246 | .n_voltages = 24, |
247 | .enable_time_us = 230, | 247 | .enable_time_us = 230, |
248 | }, | 248 | }, |
249 | { | 249 | { |
250 | .name = "LDO4", | 250 | .name = "ldo4", |
251 | .min_uV = 1000000, | 251 | .min_uV = 1000000, |
252 | .max_uV = 3300000, | 252 | .max_uV = 3300000, |
253 | .n_voltages = 47, | 253 | .n_voltages = 47, |
254 | .enable_time_us = 230, | 254 | .enable_time_us = 230, |
255 | }, | 255 | }, |
256 | { | 256 | { |
257 | .name = "LDO5", | 257 | .name = "ldo5", |
258 | .min_uV = 1000000, | 258 | .min_uV = 1000000, |
259 | .max_uV = 3300000, | 259 | .max_uV = 3300000, |
260 | .n_voltages = 24, | 260 | .n_voltages = 24, |
261 | .enable_time_us = 230, | 261 | .enable_time_us = 230, |
262 | }, | 262 | }, |
263 | { | 263 | { |
264 | .name = "LDO6", | 264 | .name = "ldo6", |
265 | .min_uV = 1000000, | 265 | .min_uV = 1000000, |
266 | .max_uV = 3300000, | 266 | .max_uV = 3300000, |
267 | .n_voltages = 24, | 267 | .n_voltages = 24, |
268 | .enable_time_us = 230, | 268 | .enable_time_us = 230, |
269 | }, | 269 | }, |
270 | { | 270 | { |
271 | .name = "LDO7", | 271 | .name = "ldo7", |
272 | .min_uV = 1000000, | 272 | .min_uV = 1000000, |
273 | .max_uV = 3300000, | 273 | .max_uV = 3300000, |
274 | .n_voltages = 24, | 274 | .n_voltages = 24, |
275 | .enable_time_us = 230, | 275 | .enable_time_us = 230, |
276 | }, | 276 | }, |
277 | { | 277 | { |
278 | .name = "LDO8", | 278 | .name = "ldo8", |
279 | .min_uV = 1000000, | 279 | .min_uV = 1000000, |
280 | .max_uV = 3300000, | 280 | .max_uV = 3300000, |
281 | .n_voltages = 24, | 281 | .n_voltages = 24, |
@@ -467,48 +467,6 @@ static int tps65911_get_ctrl_register(int id) | |||
467 | } | 467 | } |
468 | } | 468 | } |
469 | 469 | ||
470 | static int tps65910_is_enabled(struct regulator_dev *dev) | ||
471 | { | ||
472 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); | ||
473 | int reg, value, id = rdev_get_id(dev); | ||
474 | |||
475 | reg = pmic->get_ctrl_reg(id); | ||
476 | if (reg < 0) | ||
477 | return reg; | ||
478 | |||
479 | value = tps65910_reg_read(pmic, reg); | ||
480 | if (value < 0) | ||
481 | return value; | ||
482 | |||
483 | return value & TPS65910_SUPPLY_STATE_ENABLED; | ||
484 | } | ||
485 | |||
486 | static int tps65910_enable(struct regulator_dev *dev) | ||
487 | { | ||
488 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); | ||
489 | struct tps65910 *mfd = pmic->mfd; | ||
490 | int reg, id = rdev_get_id(dev); | ||
491 | |||
492 | reg = pmic->get_ctrl_reg(id); | ||
493 | if (reg < 0) | ||
494 | return reg; | ||
495 | |||
496 | return tps65910_set_bits(mfd, reg, TPS65910_SUPPLY_STATE_ENABLED); | ||
497 | } | ||
498 | |||
499 | static int tps65910_disable(struct regulator_dev *dev) | ||
500 | { | ||
501 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); | ||
502 | struct tps65910 *mfd = pmic->mfd; | ||
503 | int reg, id = rdev_get_id(dev); | ||
504 | |||
505 | reg = pmic->get_ctrl_reg(id); | ||
506 | if (reg < 0) | ||
507 | return reg; | ||
508 | |||
509 | return tps65910_clear_bits(mfd, reg, TPS65910_SUPPLY_STATE_ENABLED); | ||
510 | } | ||
511 | |||
512 | static int tps65910_enable_time(struct regulator_dev *dev) | 470 | static int tps65910_enable_time(struct regulator_dev *dev) |
513 | { | 471 | { |
514 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); | 472 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); |
@@ -621,10 +579,10 @@ static int tps65910_get_voltage_dcdc_sel(struct regulator_dev *dev) | |||
621 | return -EINVAL; | 579 | return -EINVAL; |
622 | } | 580 | } |
623 | 581 | ||
624 | static int tps65910_get_voltage(struct regulator_dev *dev) | 582 | static int tps65910_get_voltage_sel(struct regulator_dev *dev) |
625 | { | 583 | { |
626 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); | 584 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); |
627 | int reg, value, id = rdev_get_id(dev), voltage = 0; | 585 | int reg, value, id = rdev_get_id(dev); |
628 | 586 | ||
629 | reg = pmic->get_ctrl_reg(id); | 587 | reg = pmic->get_ctrl_reg(id); |
630 | if (reg < 0) | 588 | if (reg < 0) |
@@ -651,9 +609,7 @@ static int tps65910_get_voltage(struct regulator_dev *dev) | |||
651 | return -EINVAL; | 609 | return -EINVAL; |
652 | } | 610 | } |
653 | 611 | ||
654 | voltage = pmic->info[id]->voltage_table[value] * 1000; | 612 | return value; |
655 | |||
656 | return voltage; | ||
657 | } | 613 | } |
658 | 614 | ||
659 | static int tps65910_get_voltage_vdd3(struct regulator_dev *dev) | 615 | static int tps65910_get_voltage_vdd3(struct regulator_dev *dev) |
@@ -661,10 +617,10 @@ static int tps65910_get_voltage_vdd3(struct regulator_dev *dev) | |||
661 | return 5 * 1000 * 1000; | 617 | return 5 * 1000 * 1000; |
662 | } | 618 | } |
663 | 619 | ||
664 | static int tps65911_get_voltage(struct regulator_dev *dev) | 620 | static int tps65911_get_voltage_sel(struct regulator_dev *dev) |
665 | { | 621 | { |
666 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); | 622 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); |
667 | int step_mv, id = rdev_get_id(dev); | 623 | int id = rdev_get_id(dev); |
668 | u8 value, reg; | 624 | u8 value, reg; |
669 | 625 | ||
670 | reg = pmic->get_ctrl_reg(id); | 626 | reg = pmic->get_ctrl_reg(id); |
@@ -677,13 +633,6 @@ static int tps65911_get_voltage(struct regulator_dev *dev) | |||
677 | case TPS65911_REG_LDO4: | 633 | case TPS65911_REG_LDO4: |
678 | value &= LDO1_SEL_MASK; | 634 | value &= LDO1_SEL_MASK; |
679 | value >>= LDO_SEL_SHIFT; | 635 | value >>= LDO_SEL_SHIFT; |
680 | /* The first 5 values of the selector correspond to 1V */ | ||
681 | if (value < 5) | ||
682 | value = 0; | ||
683 | else | ||
684 | value -= 4; | ||
685 | |||
686 | step_mv = 50; | ||
687 | break; | 636 | break; |
688 | case TPS65911_REG_LDO3: | 637 | case TPS65911_REG_LDO3: |
689 | case TPS65911_REG_LDO5: | 638 | case TPS65911_REG_LDO5: |
@@ -692,23 +641,16 @@ static int tps65911_get_voltage(struct regulator_dev *dev) | |||
692 | case TPS65911_REG_LDO8: | 641 | case TPS65911_REG_LDO8: |
693 | value &= LDO3_SEL_MASK; | 642 | value &= LDO3_SEL_MASK; |
694 | value >>= LDO_SEL_SHIFT; | 643 | value >>= LDO_SEL_SHIFT; |
695 | /* The first 3 values of the selector correspond to 1V */ | ||
696 | if (value < 3) | ||
697 | value = 0; | ||
698 | else | ||
699 | value -= 2; | ||
700 | |||
701 | step_mv = 100; | ||
702 | break; | 644 | break; |
703 | case TPS65910_REG_VIO: | 645 | case TPS65910_REG_VIO: |
704 | value &= LDO_SEL_MASK; | 646 | value &= LDO_SEL_MASK; |
705 | value >>= LDO_SEL_SHIFT; | 647 | value >>= LDO_SEL_SHIFT; |
706 | return pmic->info[id]->voltage_table[value] * 1000; | 648 | break; |
707 | default: | 649 | default: |
708 | return -EINVAL; | 650 | return -EINVAL; |
709 | } | 651 | } |
710 | 652 | ||
711 | return (LDO_MIN_VOLT + value * step_mv) * 1000; | 653 | return value; |
712 | } | 654 | } |
713 | 655 | ||
714 | static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev, | 656 | static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev, |
@@ -914,9 +856,9 @@ static int tps65910_set_voltage_dcdc_time_sel(struct regulator_dev *dev, | |||
914 | 856 | ||
915 | /* Regulator ops (except VRTC) */ | 857 | /* Regulator ops (except VRTC) */ |
916 | static struct regulator_ops tps65910_ops_dcdc = { | 858 | static struct regulator_ops tps65910_ops_dcdc = { |
917 | .is_enabled = tps65910_is_enabled, | 859 | .is_enabled = regulator_is_enabled_regmap, |
918 | .enable = tps65910_enable, | 860 | .enable = regulator_enable_regmap, |
919 | .disable = tps65910_disable, | 861 | .disable = regulator_disable_regmap, |
920 | .enable_time = tps65910_enable_time, | 862 | .enable_time = tps65910_enable_time, |
921 | .set_mode = tps65910_set_mode, | 863 | .set_mode = tps65910_set_mode, |
922 | .get_mode = tps65910_get_mode, | 864 | .get_mode = tps65910_get_mode, |
@@ -927,9 +869,9 @@ static struct regulator_ops tps65910_ops_dcdc = { | |||
927 | }; | 869 | }; |
928 | 870 | ||
929 | static struct regulator_ops tps65910_ops_vdd3 = { | 871 | static struct regulator_ops tps65910_ops_vdd3 = { |
930 | .is_enabled = tps65910_is_enabled, | 872 | .is_enabled = regulator_is_enabled_regmap, |
931 | .enable = tps65910_enable, | 873 | .enable = regulator_enable_regmap, |
932 | .disable = tps65910_disable, | 874 | .disable = regulator_disable_regmap, |
933 | .enable_time = tps65910_enable_time, | 875 | .enable_time = tps65910_enable_time, |
934 | .set_mode = tps65910_set_mode, | 876 | .set_mode = tps65910_set_mode, |
935 | .get_mode = tps65910_get_mode, | 877 | .get_mode = tps65910_get_mode, |
@@ -938,25 +880,25 @@ static struct regulator_ops tps65910_ops_vdd3 = { | |||
938 | }; | 880 | }; |
939 | 881 | ||
940 | static struct regulator_ops tps65910_ops = { | 882 | static struct regulator_ops tps65910_ops = { |
941 | .is_enabled = tps65910_is_enabled, | 883 | .is_enabled = regulator_is_enabled_regmap, |
942 | .enable = tps65910_enable, | 884 | .enable = regulator_enable_regmap, |
943 | .disable = tps65910_disable, | 885 | .disable = regulator_disable_regmap, |
944 | .enable_time = tps65910_enable_time, | 886 | .enable_time = tps65910_enable_time, |
945 | .set_mode = tps65910_set_mode, | 887 | .set_mode = tps65910_set_mode, |
946 | .get_mode = tps65910_get_mode, | 888 | .get_mode = tps65910_get_mode, |
947 | .get_voltage = tps65910_get_voltage, | 889 | .get_voltage_sel = tps65910_get_voltage_sel, |
948 | .set_voltage_sel = tps65910_set_voltage_sel, | 890 | .set_voltage_sel = tps65910_set_voltage_sel, |
949 | .list_voltage = tps65910_list_voltage, | 891 | .list_voltage = tps65910_list_voltage, |
950 | }; | 892 | }; |
951 | 893 | ||
952 | static struct regulator_ops tps65911_ops = { | 894 | static struct regulator_ops tps65911_ops = { |
953 | .is_enabled = tps65910_is_enabled, | 895 | .is_enabled = regulator_is_enabled_regmap, |
954 | .enable = tps65910_enable, | 896 | .enable = regulator_enable_regmap, |
955 | .disable = tps65910_disable, | 897 | .disable = regulator_disable_regmap, |
956 | .enable_time = tps65910_enable_time, | 898 | .enable_time = tps65910_enable_time, |
957 | .set_mode = tps65910_set_mode, | 899 | .set_mode = tps65910_set_mode, |
958 | .get_mode = tps65910_get_mode, | 900 | .get_mode = tps65910_get_mode, |
959 | .get_voltage = tps65911_get_voltage, | 901 | .get_voltage_sel = tps65911_get_voltage_sel, |
960 | .set_voltage_sel = tps65911_set_voltage_sel, | 902 | .set_voltage_sel = tps65911_set_voltage_sel, |
961 | .list_voltage = tps65911_list_voltage, | 903 | .list_voltage = tps65911_list_voltage, |
962 | }; | 904 | }; |
@@ -1094,23 +1036,141 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic, | |||
1094 | return ret; | 1036 | return ret; |
1095 | } | 1037 | } |
1096 | 1038 | ||
1039 | #ifdef CONFIG_OF | ||
1040 | |||
1041 | static struct of_regulator_match tps65910_matches[] = { | ||
1042 | { .name = "vrtc", .driver_data = (void *) &tps65910_regs[0] }, | ||
1043 | { .name = "vio", .driver_data = (void *) &tps65910_regs[1] }, | ||
1044 | { .name = "vdd1", .driver_data = (void *) &tps65910_regs[2] }, | ||
1045 | { .name = "vdd2", .driver_data = (void *) &tps65910_regs[3] }, | ||
1046 | { .name = "vdd3", .driver_data = (void *) &tps65910_regs[4] }, | ||
1047 | { .name = "vdig1", .driver_data = (void *) &tps65910_regs[5] }, | ||
1048 | { .name = "vdig2", .driver_data = (void *) &tps65910_regs[6] }, | ||
1049 | { .name = "vpll", .driver_data = (void *) &tps65910_regs[7] }, | ||
1050 | { .name = "vdac", .driver_data = (void *) &tps65910_regs[8] }, | ||
1051 | { .name = "vaux1", .driver_data = (void *) &tps65910_regs[9] }, | ||
1052 | { .name = "vaux2", .driver_data = (void *) &tps65910_regs[10] }, | ||
1053 | { .name = "vaux33", .driver_data = (void *) &tps65910_regs[11] }, | ||
1054 | { .name = "vmmc", .driver_data = (void *) &tps65910_regs[12] }, | ||
1055 | }; | ||
1056 | |||
1057 | static struct of_regulator_match tps65911_matches[] = { | ||
1058 | { .name = "vrtc", .driver_data = (void *) &tps65911_regs[0] }, | ||
1059 | { .name = "vio", .driver_data = (void *) &tps65911_regs[1] }, | ||
1060 | { .name = "vdd1", .driver_data = (void *) &tps65911_regs[2] }, | ||
1061 | { .name = "vdd2", .driver_data = (void *) &tps65911_regs[3] }, | ||
1062 | { .name = "vddctrl", .driver_data = (void *) &tps65911_regs[4] }, | ||
1063 | { .name = "ldo1", .driver_data = (void *) &tps65911_regs[5] }, | ||
1064 | { .name = "ldo2", .driver_data = (void *) &tps65911_regs[6] }, | ||
1065 | { .name = "ldo3", .driver_data = (void *) &tps65911_regs[7] }, | ||
1066 | { .name = "ldo4", .driver_data = (void *) &tps65911_regs[8] }, | ||
1067 | { .name = "ldo5", .driver_data = (void *) &tps65911_regs[9] }, | ||
1068 | { .name = "ldo6", .driver_data = (void *) &tps65911_regs[10] }, | ||
1069 | { .name = "ldo7", .driver_data = (void *) &tps65911_regs[11] }, | ||
1070 | { .name = "ldo8", .driver_data = (void *) &tps65911_regs[12] }, | ||
1071 | }; | ||
1072 | |||
1073 | static struct tps65910_board *tps65910_parse_dt_reg_data( | ||
1074 | struct platform_device *pdev, | ||
1075 | struct of_regulator_match **tps65910_reg_matches) | ||
1076 | { | ||
1077 | struct tps65910_board *pmic_plat_data; | ||
1078 | struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent); | ||
1079 | struct device_node *np = pdev->dev.parent->of_node; | ||
1080 | struct device_node *regulators; | ||
1081 | struct of_regulator_match *matches; | ||
1082 | unsigned int prop; | ||
1083 | int idx = 0, ret, count; | ||
1084 | |||
1085 | pmic_plat_data = devm_kzalloc(&pdev->dev, sizeof(*pmic_plat_data), | ||
1086 | GFP_KERNEL); | ||
1087 | |||
1088 | if (!pmic_plat_data) { | ||
1089 | dev_err(&pdev->dev, "Failure to alloc pdata for regulators.\n"); | ||
1090 | return NULL; | ||
1091 | } | ||
1092 | |||
1093 | regulators = of_find_node_by_name(np, "regulators"); | ||
1094 | if (!regulators) { | ||
1095 | dev_err(&pdev->dev, "regulator node not found\n"); | ||
1096 | return NULL; | ||
1097 | } | ||
1098 | |||
1099 | switch (tps65910_chip_id(tps65910)) { | ||
1100 | case TPS65910: | ||
1101 | count = ARRAY_SIZE(tps65910_matches); | ||
1102 | matches = tps65910_matches; | ||
1103 | break; | ||
1104 | case TPS65911: | ||
1105 | count = ARRAY_SIZE(tps65911_matches); | ||
1106 | matches = tps65911_matches; | ||
1107 | break; | ||
1108 | default: | ||
1109 | dev_err(&pdev->dev, "Invalid tps chip version\n"); | ||
1110 | return NULL; | ||
1111 | } | ||
1112 | |||
1113 | ret = of_regulator_match(pdev->dev.parent, regulators, matches, count); | ||
1114 | if (ret < 0) { | ||
1115 | dev_err(&pdev->dev, "Error parsing regulator init data: %d\n", | ||
1116 | ret); | ||
1117 | return NULL; | ||
1118 | } | ||
1119 | |||
1120 | *tps65910_reg_matches = matches; | ||
1121 | |||
1122 | for (idx = 0; idx < count; idx++) { | ||
1123 | if (!matches[idx].init_data || !matches[idx].of_node) | ||
1124 | continue; | ||
1125 | |||
1126 | pmic_plat_data->tps65910_pmic_init_data[idx] = | ||
1127 | matches[idx].init_data; | ||
1128 | |||
1129 | ret = of_property_read_u32(matches[idx].of_node, | ||
1130 | "ti,regulator-ext-sleep-control", &prop); | ||
1131 | if (!ret) | ||
1132 | pmic_plat_data->regulator_ext_sleep_control[idx] = prop; | ||
1133 | } | ||
1134 | |||
1135 | return pmic_plat_data; | ||
1136 | } | ||
1137 | #else | ||
1138 | static inline struct tps65910_board *tps65910_parse_dt_reg_data( | ||
1139 | struct platform_device *pdev, | ||
1140 | struct of_regulator_match **tps65910_reg_matches) | ||
1141 | { | ||
1142 | *tps65910_reg_matches = NULL; | ||
1143 | return 0; | ||
1144 | } | ||
1145 | #endif | ||
1146 | |||
1097 | static __devinit int tps65910_probe(struct platform_device *pdev) | 1147 | static __devinit int tps65910_probe(struct platform_device *pdev) |
1098 | { | 1148 | { |
1099 | struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent); | 1149 | struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent); |
1150 | struct regulator_config config = { }; | ||
1100 | struct tps_info *info; | 1151 | struct tps_info *info; |
1101 | struct regulator_init_data *reg_data; | 1152 | struct regulator_init_data *reg_data; |
1102 | struct regulator_dev *rdev; | 1153 | struct regulator_dev *rdev; |
1103 | struct tps65910_reg *pmic; | 1154 | struct tps65910_reg *pmic; |
1104 | struct tps65910_board *pmic_plat_data; | 1155 | struct tps65910_board *pmic_plat_data; |
1156 | struct of_regulator_match *tps65910_reg_matches = NULL; | ||
1105 | int i, err; | 1157 | int i, err; |
1106 | 1158 | ||
1107 | pmic_plat_data = dev_get_platdata(tps65910->dev); | 1159 | pmic_plat_data = dev_get_platdata(tps65910->dev); |
1108 | if (!pmic_plat_data) | 1160 | if (!pmic_plat_data && tps65910->dev->of_node) |
1161 | pmic_plat_data = tps65910_parse_dt_reg_data(pdev, | ||
1162 | &tps65910_reg_matches); | ||
1163 | |||
1164 | if (!pmic_plat_data) { | ||
1165 | dev_err(&pdev->dev, "Platform data not found\n"); | ||
1109 | return -EINVAL; | 1166 | return -EINVAL; |
1167 | } | ||
1110 | 1168 | ||
1111 | pmic = kzalloc(sizeof(*pmic), GFP_KERNEL); | 1169 | pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL); |
1112 | if (!pmic) | 1170 | if (!pmic) { |
1171 | dev_err(&pdev->dev, "Memory allocation failed for pmic\n"); | ||
1113 | return -ENOMEM; | 1172 | return -ENOMEM; |
1173 | } | ||
1114 | 1174 | ||
1115 | mutex_init(&pmic->mutex); | 1175 | mutex_init(&pmic->mutex); |
1116 | pmic->mfd = tps65910; | 1176 | pmic->mfd = tps65910; |
@@ -1134,30 +1194,29 @@ static __devinit int tps65910_probe(struct platform_device *pdev) | |||
1134 | info = tps65911_regs; | 1194 | info = tps65911_regs; |
1135 | break; | 1195 | break; |
1136 | default: | 1196 | default: |
1137 | pr_err("Invalid tps chip version\n"); | 1197 | dev_err(&pdev->dev, "Invalid tps chip version\n"); |
1138 | kfree(pmic); | ||
1139 | return -ENODEV; | 1198 | return -ENODEV; |
1140 | } | 1199 | } |
1141 | 1200 | ||
1142 | pmic->desc = kcalloc(pmic->num_regulators, | 1201 | pmic->desc = devm_kzalloc(&pdev->dev, pmic->num_regulators * |
1143 | sizeof(struct regulator_desc), GFP_KERNEL); | 1202 | sizeof(struct regulator_desc), GFP_KERNEL); |
1144 | if (!pmic->desc) { | 1203 | if (!pmic->desc) { |
1145 | err = -ENOMEM; | 1204 | dev_err(&pdev->dev, "Memory alloc fails for desc\n"); |
1146 | goto err_free_pmic; | 1205 | return -ENOMEM; |
1147 | } | 1206 | } |
1148 | 1207 | ||
1149 | pmic->info = kcalloc(pmic->num_regulators, | 1208 | pmic->info = devm_kzalloc(&pdev->dev, pmic->num_regulators * |
1150 | sizeof(struct tps_info *), GFP_KERNEL); | 1209 | sizeof(struct tps_info *), GFP_KERNEL); |
1151 | if (!pmic->info) { | 1210 | if (!pmic->info) { |
1152 | err = -ENOMEM; | 1211 | dev_err(&pdev->dev, "Memory alloc fails for info\n"); |
1153 | goto err_free_desc; | 1212 | return -ENOMEM; |
1154 | } | 1213 | } |
1155 | 1214 | ||
1156 | pmic->rdev = kcalloc(pmic->num_regulators, | 1215 | pmic->rdev = devm_kzalloc(&pdev->dev, pmic->num_regulators * |
1157 | sizeof(struct regulator_dev *), GFP_KERNEL); | 1216 | sizeof(struct regulator_dev *), GFP_KERNEL); |
1158 | if (!pmic->rdev) { | 1217 | if (!pmic->rdev) { |
1159 | err = -ENOMEM; | 1218 | dev_err(&pdev->dev, "Memory alloc fails for rdev\n"); |
1160 | goto err_free_info; | 1219 | return -ENOMEM; |
1161 | } | 1220 | } |
1162 | 1221 | ||
1163 | for (i = 0; i < pmic->num_regulators && i < TPS65910_NUM_REGS; | 1222 | for (i = 0; i < pmic->num_regulators && i < TPS65910_NUM_REGS; |
@@ -1205,9 +1264,18 @@ static __devinit int tps65910_probe(struct platform_device *pdev) | |||
1205 | 1264 | ||
1206 | pmic->desc[i].type = REGULATOR_VOLTAGE; | 1265 | pmic->desc[i].type = REGULATOR_VOLTAGE; |
1207 | pmic->desc[i].owner = THIS_MODULE; | 1266 | pmic->desc[i].owner = THIS_MODULE; |
1267 | pmic->desc[i].enable_reg = pmic->get_ctrl_reg(i); | ||
1268 | pmic->desc[i].enable_mask = TPS65910_SUPPLY_STATE_ENABLED; | ||
1269 | |||
1270 | config.dev = tps65910->dev; | ||
1271 | config.init_data = reg_data; | ||
1272 | config.driver_data = pmic; | ||
1273 | config.regmap = tps65910->regmap; | ||
1274 | |||
1275 | if (tps65910_reg_matches) | ||
1276 | config.of_node = tps65910_reg_matches[i].of_node; | ||
1208 | 1277 | ||
1209 | rdev = regulator_register(&pmic->desc[i], | 1278 | rdev = regulator_register(&pmic->desc[i], &config); |
1210 | tps65910->dev, reg_data, pmic, NULL); | ||
1211 | if (IS_ERR(rdev)) { | 1279 | if (IS_ERR(rdev)) { |
1212 | dev_err(tps65910->dev, | 1280 | dev_err(tps65910->dev, |
1213 | "failed to register %s regulator\n", | 1281 | "failed to register %s regulator\n", |
@@ -1224,13 +1292,6 @@ static __devinit int tps65910_probe(struct platform_device *pdev) | |||
1224 | err_unregister_regulator: | 1292 | err_unregister_regulator: |
1225 | while (--i >= 0) | 1293 | while (--i >= 0) |
1226 | regulator_unregister(pmic->rdev[i]); | 1294 | regulator_unregister(pmic->rdev[i]); |
1227 | kfree(pmic->rdev); | ||
1228 | err_free_info: | ||
1229 | kfree(pmic->info); | ||
1230 | err_free_desc: | ||
1231 | kfree(pmic->desc); | ||
1232 | err_free_pmic: | ||
1233 | kfree(pmic); | ||
1234 | return err; | 1295 | return err; |
1235 | } | 1296 | } |
1236 | 1297 | ||
@@ -1242,10 +1303,6 @@ static int __devexit tps65910_remove(struct platform_device *pdev) | |||
1242 | for (i = 0; i < pmic->num_regulators; i++) | 1303 | for (i = 0; i < pmic->num_regulators; i++) |
1243 | regulator_unregister(pmic->rdev[i]); | 1304 | regulator_unregister(pmic->rdev[i]); |
1244 | 1305 | ||
1245 | kfree(pmic->rdev); | ||
1246 | kfree(pmic->info); | ||
1247 | kfree(pmic->desc); | ||
1248 | kfree(pmic); | ||
1249 | return 0; | 1306 | return 0; |
1250 | } | 1307 | } |
1251 | 1308 | ||
diff --git a/drivers/regulator/tps65912-regulator.c b/drivers/regulator/tps65912-regulator.c index b36799b1f530..18b2a1dcb4b5 100644 --- a/drivers/regulator/tps65912-regulator.c +++ b/drivers/regulator/tps65912-regulator.c | |||
@@ -20,7 +20,6 @@ | |||
20 | #include <linux/platform_device.h> | 20 | #include <linux/platform_device.h> |
21 | #include <linux/regulator/driver.h> | 21 | #include <linux/regulator/driver.h> |
22 | #include <linux/regulator/machine.h> | 22 | #include <linux/regulator/machine.h> |
23 | #include <linux/delay.h> | ||
24 | #include <linux/slab.h> | 23 | #include <linux/slab.h> |
25 | #include <linux/gpio.h> | 24 | #include <linux/gpio.h> |
26 | #include <linux/mfd/tps65912.h> | 25 | #include <linux/mfd/tps65912.h> |
@@ -372,12 +371,14 @@ static unsigned int tps65912_get_mode(struct regulator_dev *dev) | |||
372 | return mode; | 371 | return mode; |
373 | } | 372 | } |
374 | 373 | ||
375 | static int tps65912_list_voltage_dcdc(struct regulator_dev *dev, | 374 | static int tps65912_list_voltage(struct regulator_dev *dev, unsigned selector) |
376 | unsigned selector) | ||
377 | { | 375 | { |
378 | struct tps65912_reg *pmic = rdev_get_drvdata(dev); | 376 | struct tps65912_reg *pmic = rdev_get_drvdata(dev); |
379 | int range, voltage = 0, id = rdev_get_id(dev); | 377 | int range, voltage = 0, id = rdev_get_id(dev); |
380 | 378 | ||
379 | if (id >= TPS65912_REG_LDO1 && id <= TPS65912_REG_LDO10) | ||
380 | return tps65912_vsel_to_uv_ldo(selector); | ||
381 | |||
381 | if (id > TPS65912_REG_DCDC4) | 382 | if (id > TPS65912_REG_DCDC4) |
382 | return -EINVAL; | 383 | return -EINVAL; |
383 | 384 | ||
@@ -404,7 +405,7 @@ static int tps65912_list_voltage_dcdc(struct regulator_dev *dev, | |||
404 | return voltage; | 405 | return voltage; |
405 | } | 406 | } |
406 | 407 | ||
407 | static int tps65912_get_voltage_dcdc(struct regulator_dev *dev) | 408 | static int tps65912_get_voltage_sel(struct regulator_dev *dev) |
408 | { | 409 | { |
409 | struct tps65912_reg *pmic = rdev_get_drvdata(dev); | 410 | struct tps65912_reg *pmic = rdev_get_drvdata(dev); |
410 | struct tps65912 *mfd = pmic->mfd; | 411 | struct tps65912 *mfd = pmic->mfd; |
@@ -418,7 +419,7 @@ static int tps65912_get_voltage_dcdc(struct regulator_dev *dev) | |||
418 | vsel = tps65912_reg_read(mfd, reg); | 419 | vsel = tps65912_reg_read(mfd, reg); |
419 | vsel &= 0x3F; | 420 | vsel &= 0x3F; |
420 | 421 | ||
421 | return tps65912_list_voltage_dcdc(dev, vsel); | 422 | return vsel; |
422 | } | 423 | } |
423 | 424 | ||
424 | static int tps65912_set_voltage_sel(struct regulator_dev *dev, | 425 | static int tps65912_set_voltage_sel(struct regulator_dev *dev, |
@@ -436,32 +437,6 @@ static int tps65912_set_voltage_sel(struct regulator_dev *dev, | |||
436 | return tps65912_reg_write(mfd, reg, selector | value); | 437 | return tps65912_reg_write(mfd, reg, selector | value); |
437 | } | 438 | } |
438 | 439 | ||
439 | static int tps65912_get_voltage_ldo(struct regulator_dev *dev) | ||
440 | { | ||
441 | struct tps65912_reg *pmic = rdev_get_drvdata(dev); | ||
442 | struct tps65912 *mfd = pmic->mfd; | ||
443 | int id = rdev_get_id(dev); | ||
444 | int vsel = 0; | ||
445 | u8 reg; | ||
446 | |||
447 | reg = tps65912_get_sel_register(pmic, id); | ||
448 | vsel = tps65912_reg_read(mfd, reg); | ||
449 | vsel &= 0x3F; | ||
450 | |||
451 | return tps65912_vsel_to_uv_ldo(vsel); | ||
452 | } | ||
453 | |||
454 | static int tps65912_list_voltage_ldo(struct regulator_dev *dev, | ||
455 | unsigned selector) | ||
456 | { | ||
457 | int ldo = rdev_get_id(dev); | ||
458 | |||
459 | if (ldo < TPS65912_REG_LDO1 || ldo > TPS65912_REG_LDO10) | ||
460 | return -EINVAL; | ||
461 | |||
462 | return tps65912_vsel_to_uv_ldo(selector); | ||
463 | } | ||
464 | |||
465 | /* Operations permitted on DCDCx */ | 440 | /* Operations permitted on DCDCx */ |
466 | static struct regulator_ops tps65912_ops_dcdc = { | 441 | static struct regulator_ops tps65912_ops_dcdc = { |
467 | .is_enabled = tps65912_reg_is_enabled, | 442 | .is_enabled = tps65912_reg_is_enabled, |
@@ -469,9 +444,9 @@ static struct regulator_ops tps65912_ops_dcdc = { | |||
469 | .disable = tps65912_reg_disable, | 444 | .disable = tps65912_reg_disable, |
470 | .set_mode = tps65912_set_mode, | 445 | .set_mode = tps65912_set_mode, |
471 | .get_mode = tps65912_get_mode, | 446 | .get_mode = tps65912_get_mode, |
472 | .get_voltage = tps65912_get_voltage_dcdc, | 447 | .get_voltage_sel = tps65912_get_voltage_sel, |
473 | .set_voltage_sel = tps65912_set_voltage_sel, | 448 | .set_voltage_sel = tps65912_set_voltage_sel, |
474 | .list_voltage = tps65912_list_voltage_dcdc, | 449 | .list_voltage = tps65912_list_voltage, |
475 | }; | 450 | }; |
476 | 451 | ||
477 | /* Operations permitted on LDOx */ | 452 | /* Operations permitted on LDOx */ |
@@ -479,14 +454,15 @@ static struct regulator_ops tps65912_ops_ldo = { | |||
479 | .is_enabled = tps65912_reg_is_enabled, | 454 | .is_enabled = tps65912_reg_is_enabled, |
480 | .enable = tps65912_reg_enable, | 455 | .enable = tps65912_reg_enable, |
481 | .disable = tps65912_reg_disable, | 456 | .disable = tps65912_reg_disable, |
482 | .get_voltage = tps65912_get_voltage_ldo, | 457 | .get_voltage_sel = tps65912_get_voltage_sel, |
483 | .set_voltage_sel = tps65912_set_voltage_sel, | 458 | .set_voltage_sel = tps65912_set_voltage_sel, |
484 | .list_voltage = tps65912_list_voltage_ldo, | 459 | .list_voltage = tps65912_list_voltage, |
485 | }; | 460 | }; |
486 | 461 | ||
487 | static __devinit int tps65912_probe(struct platform_device *pdev) | 462 | static __devinit int tps65912_probe(struct platform_device *pdev) |
488 | { | 463 | { |
489 | struct tps65912 *tps65912 = dev_get_drvdata(pdev->dev.parent); | 464 | struct tps65912 *tps65912 = dev_get_drvdata(pdev->dev.parent); |
465 | struct regulator_config config = { }; | ||
490 | struct tps_info *info; | 466 | struct tps_info *info; |
491 | struct regulator_init_data *reg_data; | 467 | struct regulator_init_data *reg_data; |
492 | struct regulator_dev *rdev; | 468 | struct regulator_dev *rdev; |
@@ -500,7 +476,7 @@ static __devinit int tps65912_probe(struct platform_device *pdev) | |||
500 | 476 | ||
501 | reg_data = pmic_plat_data->tps65912_pmic_init_data; | 477 | reg_data = pmic_plat_data->tps65912_pmic_init_data; |
502 | 478 | ||
503 | pmic = kzalloc(sizeof(*pmic), GFP_KERNEL); | 479 | pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL); |
504 | if (!pmic) | 480 | if (!pmic) |
505 | return -ENOMEM; | 481 | return -ENOMEM; |
506 | 482 | ||
@@ -524,8 +500,12 @@ static __devinit int tps65912_probe(struct platform_device *pdev) | |||
524 | pmic->desc[i].type = REGULATOR_VOLTAGE; | 500 | pmic->desc[i].type = REGULATOR_VOLTAGE; |
525 | pmic->desc[i].owner = THIS_MODULE; | 501 | pmic->desc[i].owner = THIS_MODULE; |
526 | range = tps65912_get_range(pmic, i); | 502 | range = tps65912_get_range(pmic, i); |
527 | rdev = regulator_register(&pmic->desc[i], | 503 | |
528 | tps65912->dev, reg_data, pmic, NULL); | 504 | config.dev = tps65912->dev; |
505 | config.init_data = reg_data; | ||
506 | config.driver_data = pmic; | ||
507 | |||
508 | rdev = regulator_register(&pmic->desc[i], &config); | ||
529 | if (IS_ERR(rdev)) { | 509 | if (IS_ERR(rdev)) { |
530 | dev_err(tps65912->dev, | 510 | dev_err(tps65912->dev, |
531 | "failed to register %s regulator\n", | 511 | "failed to register %s regulator\n", |
@@ -542,8 +522,6 @@ static __devinit int tps65912_probe(struct platform_device *pdev) | |||
542 | err: | 522 | err: |
543 | while (--i >= 0) | 523 | while (--i >= 0) |
544 | regulator_unregister(pmic->rdev[i]); | 524 | regulator_unregister(pmic->rdev[i]); |
545 | |||
546 | kfree(pmic); | ||
547 | return err; | 525 | return err; |
548 | } | 526 | } |
549 | 527 | ||
@@ -554,8 +532,6 @@ static int __devexit tps65912_remove(struct platform_device *pdev) | |||
554 | 532 | ||
555 | for (i = 0; i < TPS65912_NUM_REGULATOR; i++) | 533 | for (i = 0; i < TPS65912_NUM_REGULATOR; i++) |
556 | regulator_unregister(tps65912_reg->rdev[i]); | 534 | regulator_unregister(tps65912_reg->rdev[i]); |
557 | |||
558 | kfree(tps65912_reg); | ||
559 | return 0; | 535 | return 0; |
560 | } | 536 | } |
561 | 537 | ||
diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c index 9cdfc389ca26..c7390711d954 100644 --- a/drivers/regulator/twl-regulator.c +++ b/drivers/regulator/twl-regulator.c | |||
@@ -12,7 +12,6 @@ | |||
12 | #include <linux/module.h> | 12 | #include <linux/module.h> |
13 | #include <linux/init.h> | 13 | #include <linux/init.h> |
14 | #include <linux/err.h> | 14 | #include <linux/err.h> |
15 | #include <linux/delay.h> | ||
16 | #include <linux/platform_device.h> | 15 | #include <linux/platform_device.h> |
17 | #include <linux/of.h> | 16 | #include <linux/of.h> |
18 | #include <linux/of_device.h> | 17 | #include <linux/of_device.h> |
@@ -175,15 +174,14 @@ static int twl6030reg_is_enabled(struct regulator_dev *rdev) | |||
175 | struct twlreg_info *info = rdev_get_drvdata(rdev); | 174 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
176 | int grp = 0, val; | 175 | int grp = 0, val; |
177 | 176 | ||
178 | if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS))) | 177 | if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS))) { |
179 | grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP); | 178 | grp = twlreg_grp(rdev); |
180 | if (grp < 0) | 179 | if (grp < 0) |
181 | return grp; | 180 | return grp; |
182 | |||
183 | if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS))) | ||
184 | grp &= P1_GRP_6030; | 181 | grp &= P1_GRP_6030; |
185 | else | 182 | } else { |
186 | grp = 1; | 183 | grp = 1; |
184 | } | ||
187 | 185 | ||
188 | val = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_STATE); | 186 | val = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_STATE); |
189 | val = TWL6030_CFG_STATE_APP(val); | 187 | val = TWL6030_CFG_STATE_APP(val); |
@@ -197,7 +195,7 @@ static int twl4030reg_enable(struct regulator_dev *rdev) | |||
197 | int grp; | 195 | int grp; |
198 | int ret; | 196 | int ret; |
199 | 197 | ||
200 | grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP); | 198 | grp = twlreg_grp(rdev); |
201 | if (grp < 0) | 199 | if (grp < 0) |
202 | return grp; | 200 | return grp; |
203 | 201 | ||
@@ -205,8 +203,6 @@ static int twl4030reg_enable(struct regulator_dev *rdev) | |||
205 | 203 | ||
206 | ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp); | 204 | ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp); |
207 | 205 | ||
208 | udelay(info->delay); | ||
209 | |||
210 | return ret; | 206 | return ret; |
211 | } | 207 | } |
212 | 208 | ||
@@ -217,17 +213,28 @@ static int twl6030reg_enable(struct regulator_dev *rdev) | |||
217 | int ret; | 213 | int ret; |
218 | 214 | ||
219 | if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS))) | 215 | if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS))) |
220 | grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP); | 216 | grp = twlreg_grp(rdev); |
221 | if (grp < 0) | 217 | if (grp < 0) |
222 | return grp; | 218 | return grp; |
223 | 219 | ||
224 | ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE, | 220 | ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_STATE, |
225 | grp << TWL6030_CFG_STATE_GRP_SHIFT | | 221 | grp << TWL6030_CFG_STATE_GRP_SHIFT | |
226 | TWL6030_CFG_STATE_ON); | 222 | TWL6030_CFG_STATE_ON); |
223 | return ret; | ||
224 | } | ||
227 | 225 | ||
228 | udelay(info->delay); | 226 | static int twl4030reg_enable_time(struct regulator_dev *rdev) |
227 | { | ||
228 | struct twlreg_info *info = rdev_get_drvdata(rdev); | ||
229 | 229 | ||
230 | return ret; | 230 | return info->delay; |
231 | } | ||
232 | |||
233 | static int twl6030reg_enable_time(struct regulator_dev *rdev) | ||
234 | { | ||
235 | struct twlreg_info *info = rdev_get_drvdata(rdev); | ||
236 | |||
237 | return info->delay; | ||
231 | } | 238 | } |
232 | 239 | ||
233 | static int twl4030reg_disable(struct regulator_dev *rdev) | 240 | static int twl4030reg_disable(struct regulator_dev *rdev) |
@@ -236,7 +243,7 @@ static int twl4030reg_disable(struct regulator_dev *rdev) | |||
236 | int grp; | 243 | int grp; |
237 | int ret; | 244 | int ret; |
238 | 245 | ||
239 | grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP); | 246 | grp = twlreg_grp(rdev); |
240 | if (grp < 0) | 247 | if (grp < 0) |
241 | return grp; | 248 | return grp; |
242 | 249 | ||
@@ -348,7 +355,7 @@ static int twl6030reg_set_mode(struct regulator_dev *rdev, unsigned mode) | |||
348 | int val; | 355 | int val; |
349 | 356 | ||
350 | if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS))) | 357 | if (!(twl_class_is_6030() && (info->features & TWL6025_SUBCLASS))) |
351 | grp = twlreg_read(info, TWL_MODULE_PM_RECEIVER, VREG_GRP); | 358 | grp = twlreg_grp(rdev); |
352 | 359 | ||
353 | if (grp < 0) | 360 | if (grp < 0) |
354 | return grp; | 361 | return grp; |
@@ -388,14 +395,12 @@ static int twl6030reg_set_mode(struct regulator_dev *rdev, unsigned mode) | |||
388 | * VAUX3 at 3V is incorrectly listed in some TI manuals as unsupported. | 395 | * VAUX3 at 3V is incorrectly listed in some TI manuals as unsupported. |
389 | * TI are revising the twl5030/tps659x0 specs to support that 3.0V setting. | 396 | * TI are revising the twl5030/tps659x0 specs to support that 3.0V setting. |
390 | */ | 397 | */ |
391 | #ifdef CONFIG_TWL4030_ALLOW_UNSUPPORTED | ||
392 | #define UNSUP_MASK 0x0000 | ||
393 | #else | ||
394 | #define UNSUP_MASK 0x8000 | 398 | #define UNSUP_MASK 0x8000 |
395 | #endif | ||
396 | 399 | ||
397 | #define UNSUP(x) (UNSUP_MASK | (x)) | 400 | #define UNSUP(x) (UNSUP_MASK | (x)) |
398 | #define IS_UNSUP(x) (UNSUP_MASK & (x)) | 401 | #define IS_UNSUP(info, x) \ |
402 | ((UNSUP_MASK & (x)) && \ | ||
403 | !((info)->features & TWL4030_ALLOW_UNSUPPORTED)) | ||
399 | #define LDO_MV(x) (~UNSUP_MASK & (x)) | 404 | #define LDO_MV(x) (~UNSUP_MASK & (x)) |
400 | 405 | ||
401 | 406 | ||
@@ -469,35 +474,16 @@ static int twl4030ldo_list_voltage(struct regulator_dev *rdev, unsigned index) | |||
469 | struct twlreg_info *info = rdev_get_drvdata(rdev); | 474 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
470 | int mV = info->table[index]; | 475 | int mV = info->table[index]; |
471 | 476 | ||
472 | return IS_UNSUP(mV) ? 0 : (LDO_MV(mV) * 1000); | 477 | return IS_UNSUP(info, mV) ? 0 : (LDO_MV(mV) * 1000); |
473 | } | 478 | } |
474 | 479 | ||
475 | static int | 480 | static int |
476 | twl4030ldo_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV, | 481 | twl4030ldo_set_voltage_sel(struct regulator_dev *rdev, unsigned selector) |
477 | unsigned *selector) | ||
478 | { | 482 | { |
479 | struct twlreg_info *info = rdev_get_drvdata(rdev); | 483 | struct twlreg_info *info = rdev_get_drvdata(rdev); |
480 | int vsel; | ||
481 | 484 | ||
482 | for (vsel = 0; vsel < info->table_len; vsel++) { | 485 | return twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE, |
483 | int mV = info->table[vsel]; | 486 | selector); |
484 | int uV; | ||
485 | |||
486 | if (IS_UNSUP(mV)) | ||
487 | continue; | ||
488 | uV = LDO_MV(mV) * 1000; | ||
489 | |||
490 | /* REVISIT for VAUX2, first match may not be best/lowest */ | ||
491 | |||
492 | /* use the first in-range value */ | ||
493 | if (min_uV <= uV && uV <= max_uV) { | ||
494 | *selector = vsel; | ||
495 | return twlreg_write(info, TWL_MODULE_PM_RECEIVER, | ||
496 | VREG_VOLTAGE, vsel); | ||
497 | } | ||
498 | } | ||
499 | |||
500 | return -EDOM; | ||
501 | } | 487 | } |
502 | 488 | ||
503 | static int twl4030ldo_get_voltage(struct regulator_dev *rdev) | 489 | static int twl4030ldo_get_voltage(struct regulator_dev *rdev) |
@@ -516,12 +502,13 @@ static int twl4030ldo_get_voltage(struct regulator_dev *rdev) | |||
516 | static struct regulator_ops twl4030ldo_ops = { | 502 | static struct regulator_ops twl4030ldo_ops = { |
517 | .list_voltage = twl4030ldo_list_voltage, | 503 | .list_voltage = twl4030ldo_list_voltage, |
518 | 504 | ||
519 | .set_voltage = twl4030ldo_set_voltage, | 505 | .set_voltage_sel = twl4030ldo_set_voltage_sel, |
520 | .get_voltage = twl4030ldo_get_voltage, | 506 | .get_voltage = twl4030ldo_get_voltage, |
521 | 507 | ||
522 | .enable = twl4030reg_enable, | 508 | .enable = twl4030reg_enable, |
523 | .disable = twl4030reg_disable, | 509 | .disable = twl4030reg_disable, |
524 | .is_enabled = twl4030reg_is_enabled, | 510 | .is_enabled = twl4030reg_is_enabled, |
511 | .enable_time = twl4030reg_enable_time, | ||
525 | 512 | ||
526 | .set_mode = twl4030reg_set_mode, | 513 | .set_mode = twl4030reg_set_mode, |
527 | 514 | ||
@@ -642,6 +629,7 @@ static struct regulator_ops twl6030ldo_ops = { | |||
642 | .enable = twl6030reg_enable, | 629 | .enable = twl6030reg_enable, |
643 | .disable = twl6030reg_disable, | 630 | .disable = twl6030reg_disable, |
644 | .is_enabled = twl6030reg_is_enabled, | 631 | .is_enabled = twl6030reg_is_enabled, |
632 | .enable_time = twl6030reg_enable_time, | ||
645 | 633 | ||
646 | .set_mode = twl6030reg_set_mode, | 634 | .set_mode = twl6030reg_set_mode, |
647 | 635 | ||
@@ -675,6 +663,7 @@ static struct regulator_ops twl4030fixed_ops = { | |||
675 | .enable = twl4030reg_enable, | 663 | .enable = twl4030reg_enable, |
676 | .disable = twl4030reg_disable, | 664 | .disable = twl4030reg_disable, |
677 | .is_enabled = twl4030reg_is_enabled, | 665 | .is_enabled = twl4030reg_is_enabled, |
666 | .enable_time = twl4030reg_enable_time, | ||
678 | 667 | ||
679 | .set_mode = twl4030reg_set_mode, | 668 | .set_mode = twl4030reg_set_mode, |
680 | 669 | ||
@@ -689,6 +678,7 @@ static struct regulator_ops twl6030fixed_ops = { | |||
689 | .enable = twl6030reg_enable, | 678 | .enable = twl6030reg_enable, |
690 | .disable = twl6030reg_disable, | 679 | .disable = twl6030reg_disable, |
691 | .is_enabled = twl6030reg_is_enabled, | 680 | .is_enabled = twl6030reg_is_enabled, |
681 | .enable_time = twl6030reg_enable_time, | ||
692 | 682 | ||
693 | .set_mode = twl6030reg_set_mode, | 683 | .set_mode = twl6030reg_set_mode, |
694 | 684 | ||
@@ -699,6 +689,7 @@ static struct regulator_ops twl6030_fixed_resource = { | |||
699 | .enable = twl6030reg_enable, | 689 | .enable = twl6030reg_enable, |
700 | .disable = twl6030reg_disable, | 690 | .disable = twl6030reg_disable, |
701 | .is_enabled = twl6030reg_is_enabled, | 691 | .is_enabled = twl6030reg_is_enabled, |
692 | .enable_time = twl6030reg_enable_time, | ||
702 | .get_status = twl6030reg_get_status, | 693 | .get_status = twl6030reg_get_status, |
703 | }; | 694 | }; |
704 | 695 | ||
@@ -806,10 +797,7 @@ twl6030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV, | |||
806 | vsel = 0; | 797 | vsel = 0; |
807 | else if ((min_uV >= 600000) && (min_uV <= 1300000)) { | 798 | else if ((min_uV >= 600000) && (min_uV <= 1300000)) { |
808 | int calc_uV; | 799 | int calc_uV; |
809 | vsel = (min_uV - 600000) / 125; | 800 | vsel = DIV_ROUND_UP(min_uV - 600000, 12500); |
810 | if (vsel % 100) | ||
811 | vsel += 100; | ||
812 | vsel /= 100; | ||
813 | vsel++; | 801 | vsel++; |
814 | calc_uV = twl6030smps_list_voltage(rdev, vsel); | 802 | calc_uV = twl6030smps_list_voltage(rdev, vsel); |
815 | if (calc_uV > max_uV) | 803 | if (calc_uV > max_uV) |
@@ -836,10 +824,7 @@ twl6030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV, | |||
836 | vsel = 0; | 824 | vsel = 0; |
837 | else if ((min_uV >= 700000) && (min_uV <= 1420000)) { | 825 | else if ((min_uV >= 700000) && (min_uV <= 1420000)) { |
838 | int calc_uV; | 826 | int calc_uV; |
839 | vsel = (min_uV - 700000) / 125; | 827 | vsel = DIV_ROUND_UP(min_uV - 700000, 12500); |
840 | if (vsel % 100) | ||
841 | vsel += 100; | ||
842 | vsel /= 100; | ||
843 | vsel++; | 828 | vsel++; |
844 | calc_uV = twl6030smps_list_voltage(rdev, vsel); | 829 | calc_uV = twl6030smps_list_voltage(rdev, vsel); |
845 | if (calc_uV > max_uV) | 830 | if (calc_uV > max_uV) |
@@ -862,24 +847,18 @@ twl6030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV, | |||
862 | return -EINVAL; | 847 | return -EINVAL; |
863 | break; | 848 | break; |
864 | case SMPS_EXTENDED_EN: | 849 | case SMPS_EXTENDED_EN: |
865 | if (min_uV == 0) | 850 | if (min_uV == 0) { |
866 | vsel = 0; | 851 | vsel = 0; |
867 | else if ((min_uV >= 1852000) && (max_uV <= 4013600)) { | 852 | } else if ((min_uV >= 1852000) && (max_uV <= 4013600)) { |
868 | vsel = (min_uV - 1852000) / 386; | 853 | vsel = DIV_ROUND_UP(min_uV - 1852000, 38600); |
869 | if (vsel % 100) | ||
870 | vsel += 100; | ||
871 | vsel /= 100; | ||
872 | vsel++; | 854 | vsel++; |
873 | } | 855 | } |
874 | break; | 856 | break; |
875 | case SMPS_OFFSET_EN|SMPS_EXTENDED_EN: | 857 | case SMPS_OFFSET_EN|SMPS_EXTENDED_EN: |
876 | if (min_uV == 0) | 858 | if (min_uV == 0) { |
877 | vsel = 0; | 859 | vsel = 0; |
878 | else if ((min_uV >= 2161000) && (max_uV <= 4321000)) { | 860 | } else if ((min_uV >= 2161000) && (max_uV <= 4321000)) { |
879 | vsel = (min_uV - 2161000) / 386; | 861 | vsel = DIV_ROUND_UP(min_uV - 2161000, 38600); |
880 | if (vsel % 100) | ||
881 | vsel += 100; | ||
882 | vsel /= 100; | ||
883 | vsel++; | 862 | vsel++; |
884 | } | 863 | } |
885 | break; | 864 | break; |
@@ -907,6 +886,7 @@ static struct regulator_ops twlsmps_ops = { | |||
907 | .enable = twl6030reg_enable, | 886 | .enable = twl6030reg_enable, |
908 | .disable = twl6030reg_disable, | 887 | .disable = twl6030reg_disable, |
909 | .is_enabled = twl6030reg_is_enabled, | 888 | .is_enabled = twl6030reg_is_enabled, |
889 | .enable_time = twl6030reg_enable_time, | ||
910 | 890 | ||
911 | .set_mode = twl6030reg_set_mode, | 891 | .set_mode = twl6030reg_set_mode, |
912 | 892 | ||
@@ -1194,6 +1174,7 @@ static int __devinit twlreg_probe(struct platform_device *pdev) | |||
1194 | struct regulator_dev *rdev; | 1174 | struct regulator_dev *rdev; |
1195 | struct twl_regulator_driver_data *drvdata; | 1175 | struct twl_regulator_driver_data *drvdata; |
1196 | const struct of_device_id *match; | 1176 | const struct of_device_id *match; |
1177 | struct regulator_config config = { }; | ||
1197 | 1178 | ||
1198 | match = of_match_device(twl_of_match, &pdev->dev); | 1179 | match = of_match_device(twl_of_match, &pdev->dev); |
1199 | if (match) { | 1180 | if (match) { |
@@ -1207,10 +1188,12 @@ static int __devinit twlreg_probe(struct platform_device *pdev) | |||
1207 | initdata = pdev->dev.platform_data; | 1188 | initdata = pdev->dev.platform_data; |
1208 | for (i = 0, info = NULL; i < ARRAY_SIZE(twl_of_match); i++) { | 1189 | for (i = 0, info = NULL; i < ARRAY_SIZE(twl_of_match); i++) { |
1209 | info = twl_of_match[i].data; | 1190 | info = twl_of_match[i].data; |
1210 | if (!info || info->desc.id != id) | 1191 | if (info && info->desc.id == id) |
1211 | continue; | 1192 | break; |
1212 | break; | ||
1213 | } | 1193 | } |
1194 | if (i == ARRAY_SIZE(twl_of_match)) | ||
1195 | return -ENODEV; | ||
1196 | |||
1214 | drvdata = initdata->driver_data; | 1197 | drvdata = initdata->driver_data; |
1215 | if (!drvdata) | 1198 | if (!drvdata) |
1216 | return -EINVAL; | 1199 | return -EINVAL; |
@@ -1273,8 +1256,12 @@ static int __devinit twlreg_probe(struct platform_device *pdev) | |||
1273 | break; | 1256 | break; |
1274 | } | 1257 | } |
1275 | 1258 | ||
1276 | rdev = regulator_register(&info->desc, &pdev->dev, initdata, info, | 1259 | config.dev = &pdev->dev; |
1277 | pdev->dev.of_node); | 1260 | config.init_data = initdata; |
1261 | config.driver_data = info; | ||
1262 | config.of_node = pdev->dev.of_node; | ||
1263 | |||
1264 | rdev = regulator_register(&info->desc, &config); | ||
1278 | if (IS_ERR(rdev)) { | 1265 | if (IS_ERR(rdev)) { |
1279 | dev_err(&pdev->dev, "can't register %s, %ld\n", | 1266 | dev_err(&pdev->dev, "can't register %s, %ld\n", |
1280 | info->desc.name, PTR_ERR(rdev)); | 1267 | info->desc.name, PTR_ERR(rdev)); |
diff --git a/drivers/regulator/userspace-consumer.c b/drivers/regulator/userspace-consumer.c index 518667ef9a0d..a7c8deb5f28f 100644 --- a/drivers/regulator/userspace-consumer.c +++ b/drivers/regulator/userspace-consumer.c | |||
@@ -115,7 +115,9 @@ static int regulator_userspace_consumer_probe(struct platform_device *pdev) | |||
115 | if (!pdata) | 115 | if (!pdata) |
116 | return -EINVAL; | 116 | return -EINVAL; |
117 | 117 | ||
118 | drvdata = kzalloc(sizeof(struct userspace_consumer_data), GFP_KERNEL); | 118 | drvdata = devm_kzalloc(&pdev->dev, |
119 | sizeof(struct userspace_consumer_data), | ||
120 | GFP_KERNEL); | ||
119 | if (drvdata == NULL) | 121 | if (drvdata == NULL) |
120 | return -ENOMEM; | 122 | return -ENOMEM; |
121 | 123 | ||
@@ -125,16 +127,16 @@ static int regulator_userspace_consumer_probe(struct platform_device *pdev) | |||
125 | 127 | ||
126 | mutex_init(&drvdata->lock); | 128 | mutex_init(&drvdata->lock); |
127 | 129 | ||
128 | ret = regulator_bulk_get(&pdev->dev, drvdata->num_supplies, | 130 | ret = devm_regulator_bulk_get(&pdev->dev, drvdata->num_supplies, |
129 | drvdata->supplies); | 131 | drvdata->supplies); |
130 | if (ret) { | 132 | if (ret) { |
131 | dev_err(&pdev->dev, "Failed to get supplies: %d\n", ret); | 133 | dev_err(&pdev->dev, "Failed to get supplies: %d\n", ret); |
132 | goto err_alloc_supplies; | 134 | return ret; |
133 | } | 135 | } |
134 | 136 | ||
135 | ret = sysfs_create_group(&pdev->dev.kobj, &attr_group); | 137 | ret = sysfs_create_group(&pdev->dev.kobj, &attr_group); |
136 | if (ret != 0) | 138 | if (ret != 0) |
137 | goto err_create_attrs; | 139 | return ret; |
138 | 140 | ||
139 | if (pdata->init_on) { | 141 | if (pdata->init_on) { |
140 | ret = regulator_bulk_enable(drvdata->num_supplies, | 142 | ret = regulator_bulk_enable(drvdata->num_supplies, |
@@ -154,11 +156,6 @@ static int regulator_userspace_consumer_probe(struct platform_device *pdev) | |||
154 | err_enable: | 156 | err_enable: |
155 | sysfs_remove_group(&pdev->dev.kobj, &attr_group); | 157 | sysfs_remove_group(&pdev->dev.kobj, &attr_group); |
156 | 158 | ||
157 | err_create_attrs: | ||
158 | regulator_bulk_free(drvdata->num_supplies, drvdata->supplies); | ||
159 | |||
160 | err_alloc_supplies: | ||
161 | kfree(drvdata); | ||
162 | return ret; | 159 | return ret; |
163 | } | 160 | } |
164 | 161 | ||
@@ -171,9 +168,6 @@ static int regulator_userspace_consumer_remove(struct platform_device *pdev) | |||
171 | if (data->enabled) | 168 | if (data->enabled) |
172 | regulator_bulk_disable(data->num_supplies, data->supplies); | 169 | regulator_bulk_disable(data->num_supplies, data->supplies); |
173 | 170 | ||
174 | regulator_bulk_free(data->num_supplies, data->supplies); | ||
175 | kfree(data); | ||
176 | |||
177 | return 0; | 171 | return 0; |
178 | } | 172 | } |
179 | 173 | ||
diff --git a/drivers/regulator/virtual.c b/drivers/regulator/virtual.c index ee0b161c998f..c038e7422538 100644 --- a/drivers/regulator/virtual.c +++ b/drivers/regulator/virtual.c | |||
@@ -121,7 +121,7 @@ static ssize_t set_min_uV(struct device *dev, struct device_attribute *attr, | |||
121 | struct virtual_consumer_data *data = dev_get_drvdata(dev); | 121 | struct virtual_consumer_data *data = dev_get_drvdata(dev); |
122 | long val; | 122 | long val; |
123 | 123 | ||
124 | if (strict_strtol(buf, 10, &val) != 0) | 124 | if (kstrtol(buf, 10, &val) != 0) |
125 | return count; | 125 | return count; |
126 | 126 | ||
127 | mutex_lock(&data->lock); | 127 | mutex_lock(&data->lock); |
@@ -147,7 +147,7 @@ static ssize_t set_max_uV(struct device *dev, struct device_attribute *attr, | |||
147 | struct virtual_consumer_data *data = dev_get_drvdata(dev); | 147 | struct virtual_consumer_data *data = dev_get_drvdata(dev); |
148 | long val; | 148 | long val; |
149 | 149 | ||
150 | if (strict_strtol(buf, 10, &val) != 0) | 150 | if (kstrtol(buf, 10, &val) != 0) |
151 | return count; | 151 | return count; |
152 | 152 | ||
153 | mutex_lock(&data->lock); | 153 | mutex_lock(&data->lock); |
@@ -173,7 +173,7 @@ static ssize_t set_min_uA(struct device *dev, struct device_attribute *attr, | |||
173 | struct virtual_consumer_data *data = dev_get_drvdata(dev); | 173 | struct virtual_consumer_data *data = dev_get_drvdata(dev); |
174 | long val; | 174 | long val; |
175 | 175 | ||
176 | if (strict_strtol(buf, 10, &val) != 0) | 176 | if (kstrtol(buf, 10, &val) != 0) |
177 | return count; | 177 | return count; |
178 | 178 | ||
179 | mutex_lock(&data->lock); | 179 | mutex_lock(&data->lock); |
@@ -199,7 +199,7 @@ static ssize_t set_max_uA(struct device *dev, struct device_attribute *attr, | |||
199 | struct virtual_consumer_data *data = dev_get_drvdata(dev); | 199 | struct virtual_consumer_data *data = dev_get_drvdata(dev); |
200 | long val; | 200 | long val; |
201 | 201 | ||
202 | if (strict_strtol(buf, 10, &val) != 0) | 202 | if (kstrtol(buf, 10, &val) != 0) |
203 | return count; | 203 | return count; |
204 | 204 | ||
205 | mutex_lock(&data->lock); | 205 | mutex_lock(&data->lock); |
@@ -291,18 +291,19 @@ static int __devinit regulator_virtual_probe(struct platform_device *pdev) | |||
291 | struct virtual_consumer_data *drvdata; | 291 | struct virtual_consumer_data *drvdata; |
292 | int ret; | 292 | int ret; |
293 | 293 | ||
294 | drvdata = kzalloc(sizeof(struct virtual_consumer_data), GFP_KERNEL); | 294 | drvdata = devm_kzalloc(&pdev->dev, sizeof(struct virtual_consumer_data), |
295 | GFP_KERNEL); | ||
295 | if (drvdata == NULL) | 296 | if (drvdata == NULL) |
296 | return -ENOMEM; | 297 | return -ENOMEM; |
297 | 298 | ||
298 | mutex_init(&drvdata->lock); | 299 | mutex_init(&drvdata->lock); |
299 | 300 | ||
300 | drvdata->regulator = regulator_get(&pdev->dev, reg_id); | 301 | drvdata->regulator = devm_regulator_get(&pdev->dev, reg_id); |
301 | if (IS_ERR(drvdata->regulator)) { | 302 | if (IS_ERR(drvdata->regulator)) { |
302 | ret = PTR_ERR(drvdata->regulator); | 303 | ret = PTR_ERR(drvdata->regulator); |
303 | dev_err(&pdev->dev, "Failed to obtain supply '%s': %d\n", | 304 | dev_err(&pdev->dev, "Failed to obtain supply '%s': %d\n", |
304 | reg_id, ret); | 305 | reg_id, ret); |
305 | goto err; | 306 | return ret; |
306 | } | 307 | } |
307 | 308 | ||
308 | ret = sysfs_create_group(&pdev->dev.kobj, | 309 | ret = sysfs_create_group(&pdev->dev.kobj, |
@@ -310,7 +311,7 @@ static int __devinit regulator_virtual_probe(struct platform_device *pdev) | |||
310 | if (ret != 0) { | 311 | if (ret != 0) { |
311 | dev_err(&pdev->dev, | 312 | dev_err(&pdev->dev, |
312 | "Failed to create attribute group: %d\n", ret); | 313 | "Failed to create attribute group: %d\n", ret); |
313 | goto err_regulator; | 314 | return ret; |
314 | } | 315 | } |
315 | 316 | ||
316 | drvdata->mode = regulator_get_mode(drvdata->regulator); | 317 | drvdata->mode = regulator_get_mode(drvdata->regulator); |
@@ -318,12 +319,6 @@ static int __devinit regulator_virtual_probe(struct platform_device *pdev) | |||
318 | platform_set_drvdata(pdev, drvdata); | 319 | platform_set_drvdata(pdev, drvdata); |
319 | 320 | ||
320 | return 0; | 321 | return 0; |
321 | |||
322 | err_regulator: | ||
323 | regulator_put(drvdata->regulator); | ||
324 | err: | ||
325 | kfree(drvdata); | ||
326 | return ret; | ||
327 | } | 322 | } |
328 | 323 | ||
329 | static int __devexit regulator_virtual_remove(struct platform_device *pdev) | 324 | static int __devexit regulator_virtual_remove(struct platform_device *pdev) |
@@ -334,9 +329,6 @@ static int __devexit regulator_virtual_remove(struct platform_device *pdev) | |||
334 | 329 | ||
335 | if (drvdata->enabled) | 330 | if (drvdata->enabled) |
336 | regulator_disable(drvdata->regulator); | 331 | regulator_disable(drvdata->regulator); |
337 | regulator_put(drvdata->regulator); | ||
338 | |||
339 | kfree(drvdata); | ||
340 | 332 | ||
341 | platform_set_drvdata(pdev, NULL); | 333 | platform_set_drvdata(pdev, NULL); |
342 | 334 | ||
diff --git a/drivers/regulator/wm831x-dcdc.c b/drivers/regulator/wm831x-dcdc.c index ff810e787eac..a885911bb5fc 100644 --- a/drivers/regulator/wm831x-dcdc.c +++ b/drivers/regulator/wm831x-dcdc.c | |||
@@ -35,7 +35,7 @@ | |||
35 | #define WM831X_DCDC_MODE_IDLE 2 | 35 | #define WM831X_DCDC_MODE_IDLE 2 |
36 | #define WM831X_DCDC_MODE_STANDBY 3 | 36 | #define WM831X_DCDC_MODE_STANDBY 3 |
37 | 37 | ||
38 | #define WM831X_DCDC_MAX_NAME 6 | 38 | #define WM831X_DCDC_MAX_NAME 9 |
39 | 39 | ||
40 | /* Register offsets in control block */ | 40 | /* Register offsets in control block */ |
41 | #define WM831X_DCDC_CONTROL_1 0 | 41 | #define WM831X_DCDC_CONTROL_1 0 |
@@ -50,6 +50,7 @@ | |||
50 | 50 | ||
51 | struct wm831x_dcdc { | 51 | struct wm831x_dcdc { |
52 | char name[WM831X_DCDC_MAX_NAME]; | 52 | char name[WM831X_DCDC_MAX_NAME]; |
53 | char supply_name[WM831X_DCDC_MAX_NAME]; | ||
53 | struct regulator_desc desc; | 54 | struct regulator_desc desc; |
54 | int base; | 55 | int base; |
55 | struct wm831x *wm831x; | 56 | struct wm831x *wm831x; |
@@ -60,41 +61,6 @@ struct wm831x_dcdc { | |||
60 | int dvs_vsel; | 61 | int dvs_vsel; |
61 | }; | 62 | }; |
62 | 63 | ||
63 | static int wm831x_dcdc_is_enabled(struct regulator_dev *rdev) | ||
64 | { | ||
65 | struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); | ||
66 | struct wm831x *wm831x = dcdc->wm831x; | ||
67 | int mask = 1 << rdev_get_id(rdev); | ||
68 | int reg; | ||
69 | |||
70 | reg = wm831x_reg_read(wm831x, WM831X_DCDC_ENABLE); | ||
71 | if (reg < 0) | ||
72 | return reg; | ||
73 | |||
74 | if (reg & mask) | ||
75 | return 1; | ||
76 | else | ||
77 | return 0; | ||
78 | } | ||
79 | |||
80 | static int wm831x_dcdc_enable(struct regulator_dev *rdev) | ||
81 | { | ||
82 | struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); | ||
83 | struct wm831x *wm831x = dcdc->wm831x; | ||
84 | int mask = 1 << rdev_get_id(rdev); | ||
85 | |||
86 | return wm831x_set_bits(wm831x, WM831X_DCDC_ENABLE, mask, mask); | ||
87 | } | ||
88 | |||
89 | static int wm831x_dcdc_disable(struct regulator_dev *rdev) | ||
90 | { | ||
91 | struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); | ||
92 | struct wm831x *wm831x = dcdc->wm831x; | ||
93 | int mask = 1 << rdev_get_id(rdev); | ||
94 | |||
95 | return wm831x_set_bits(wm831x, WM831X_DCDC_ENABLE, mask, 0); | ||
96 | } | ||
97 | |||
98 | static unsigned int wm831x_dcdc_get_mode(struct regulator_dev *rdev) | 64 | static unsigned int wm831x_dcdc_get_mode(struct regulator_dev *rdev) |
99 | 65 | ||
100 | { | 66 | { |
@@ -414,9 +380,9 @@ static struct regulator_ops wm831x_buckv_ops = { | |||
414 | .set_current_limit = wm831x_buckv_set_current_limit, | 380 | .set_current_limit = wm831x_buckv_set_current_limit, |
415 | .get_current_limit = wm831x_buckv_get_current_limit, | 381 | .get_current_limit = wm831x_buckv_get_current_limit, |
416 | 382 | ||
417 | .is_enabled = wm831x_dcdc_is_enabled, | 383 | .is_enabled = regulator_is_enabled_regmap, |
418 | .enable = wm831x_dcdc_enable, | 384 | .enable = regulator_enable_regmap, |
419 | .disable = wm831x_dcdc_disable, | 385 | .disable = regulator_disable_regmap, |
420 | .get_status = wm831x_dcdc_get_status, | 386 | .get_status = wm831x_dcdc_get_status, |
421 | .get_mode = wm831x_dcdc_get_mode, | 387 | .get_mode = wm831x_dcdc_get_mode, |
422 | .set_mode = wm831x_dcdc_set_mode, | 388 | .set_mode = wm831x_dcdc_set_mode, |
@@ -437,23 +403,17 @@ static __devinit void wm831x_buckv_dvs_init(struct wm831x_dcdc *dcdc, | |||
437 | if (!pdata || !pdata->dvs_gpio) | 403 | if (!pdata || !pdata->dvs_gpio) |
438 | return; | 404 | return; |
439 | 405 | ||
440 | ret = gpio_request(pdata->dvs_gpio, "DCDC DVS"); | ||
441 | if (ret < 0) { | ||
442 | dev_err(wm831x->dev, "Failed to get %s DVS GPIO: %d\n", | ||
443 | dcdc->name, ret); | ||
444 | return; | ||
445 | } | ||
446 | |||
447 | /* gpiolib won't let us read the GPIO status so pick the higher | 406 | /* gpiolib won't let us read the GPIO status so pick the higher |
448 | * of the two existing voltages so we take it as platform data. | 407 | * of the two existing voltages so we take it as platform data. |
449 | */ | 408 | */ |
450 | dcdc->dvs_gpio_state = pdata->dvs_init_state; | 409 | dcdc->dvs_gpio_state = pdata->dvs_init_state; |
451 | 410 | ||
452 | ret = gpio_direction_output(pdata->dvs_gpio, dcdc->dvs_gpio_state); | 411 | ret = gpio_request_one(pdata->dvs_gpio, |
412 | dcdc->dvs_gpio_state ? GPIOF_INIT_HIGH : 0, | ||
413 | "DCDC DVS"); | ||
453 | if (ret < 0) { | 414 | if (ret < 0) { |
454 | dev_err(wm831x->dev, "Failed to enable %s DVS GPIO: %d\n", | 415 | dev_err(wm831x->dev, "Failed to get %s DVS GPIO: %d\n", |
455 | dcdc->name, ret); | 416 | dcdc->name, ret); |
456 | gpio_free(pdata->dvs_gpio); | ||
457 | return; | 417 | return; |
458 | } | 418 | } |
459 | 419 | ||
@@ -498,6 +458,7 @@ static __devinit int wm831x_buckv_probe(struct platform_device *pdev) | |||
498 | { | 458 | { |
499 | struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); | 459 | struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); |
500 | struct wm831x_pdata *pdata = wm831x->dev->platform_data; | 460 | struct wm831x_pdata *pdata = wm831x->dev->platform_data; |
461 | struct regulator_config config = { }; | ||
501 | int id; | 462 | int id; |
502 | struct wm831x_dcdc *dcdc; | 463 | struct wm831x_dcdc *dcdc; |
503 | struct resource *res; | 464 | struct resource *res; |
@@ -511,9 +472,6 @@ static __devinit int wm831x_buckv_probe(struct platform_device *pdev) | |||
511 | 472 | ||
512 | dev_dbg(&pdev->dev, "Probing DCDC%d\n", id + 1); | 473 | dev_dbg(&pdev->dev, "Probing DCDC%d\n", id + 1); |
513 | 474 | ||
514 | if (pdata == NULL || pdata->dcdc[id] == NULL) | ||
515 | return -ENODEV; | ||
516 | |||
517 | dcdc = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_dcdc), | 475 | dcdc = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_dcdc), |
518 | GFP_KERNEL); | 476 | GFP_KERNEL); |
519 | if (dcdc == NULL) { | 477 | if (dcdc == NULL) { |
@@ -533,11 +491,18 @@ static __devinit int wm831x_buckv_probe(struct platform_device *pdev) | |||
533 | 491 | ||
534 | snprintf(dcdc->name, sizeof(dcdc->name), "DCDC%d", id + 1); | 492 | snprintf(dcdc->name, sizeof(dcdc->name), "DCDC%d", id + 1); |
535 | dcdc->desc.name = dcdc->name; | 493 | dcdc->desc.name = dcdc->name; |
494 | |||
495 | snprintf(dcdc->supply_name, sizeof(dcdc->supply_name), | ||
496 | "DC%dVDD", id + 1); | ||
497 | dcdc->desc.supply_name = dcdc->supply_name; | ||
498 | |||
536 | dcdc->desc.id = id; | 499 | dcdc->desc.id = id; |
537 | dcdc->desc.type = REGULATOR_VOLTAGE; | 500 | dcdc->desc.type = REGULATOR_VOLTAGE; |
538 | dcdc->desc.n_voltages = WM831X_BUCKV_MAX_SELECTOR + 1; | 501 | dcdc->desc.n_voltages = WM831X_BUCKV_MAX_SELECTOR + 1; |
539 | dcdc->desc.ops = &wm831x_buckv_ops; | 502 | dcdc->desc.ops = &wm831x_buckv_ops; |
540 | dcdc->desc.owner = THIS_MODULE; | 503 | dcdc->desc.owner = THIS_MODULE; |
504 | dcdc->desc.enable_reg = WM831X_DCDC_ENABLE; | ||
505 | dcdc->desc.enable_mask = 1 << id; | ||
541 | 506 | ||
542 | ret = wm831x_reg_read(wm831x, dcdc->base + WM831X_DCDC_ON_CONFIG); | 507 | ret = wm831x_reg_read(wm831x, dcdc->base + WM831X_DCDC_ON_CONFIG); |
543 | if (ret < 0) { | 508 | if (ret < 0) { |
@@ -553,11 +518,16 @@ static __devinit int wm831x_buckv_probe(struct platform_device *pdev) | |||
553 | } | 518 | } |
554 | dcdc->dvs_vsel = ret & WM831X_DC1_DVS_VSEL_MASK; | 519 | dcdc->dvs_vsel = ret & WM831X_DC1_DVS_VSEL_MASK; |
555 | 520 | ||
556 | if (pdata->dcdc[id]) | 521 | if (pdata && pdata->dcdc[id]) |
557 | wm831x_buckv_dvs_init(dcdc, pdata->dcdc[id]->driver_data); | 522 | wm831x_buckv_dvs_init(dcdc, pdata->dcdc[id]->driver_data); |
558 | 523 | ||
559 | dcdc->regulator = regulator_register(&dcdc->desc, &pdev->dev, | 524 | config.dev = pdev->dev.parent; |
560 | pdata->dcdc[id], dcdc, NULL); | 525 | if (pdata) |
526 | config.init_data = pdata->dcdc[id]; | ||
527 | config.driver_data = dcdc; | ||
528 | config.regmap = wm831x->regmap; | ||
529 | |||
530 | dcdc->regulator = regulator_register(&dcdc->desc, &config); | ||
561 | if (IS_ERR(dcdc->regulator)) { | 531 | if (IS_ERR(dcdc->regulator)) { |
562 | ret = PTR_ERR(dcdc->regulator); | 532 | ret = PTR_ERR(dcdc->regulator); |
563 | dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n", | 533 | dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n", |
@@ -675,29 +645,15 @@ static int wm831x_buckp_set_suspend_voltage(struct regulator_dev *rdev, | |||
675 | return wm831x_buckp_set_voltage_int(rdev, reg, uV, uV, &selector); | 645 | return wm831x_buckp_set_voltage_int(rdev, reg, uV, uV, &selector); |
676 | } | 646 | } |
677 | 647 | ||
678 | static int wm831x_buckp_get_voltage_sel(struct regulator_dev *rdev) | ||
679 | { | ||
680 | struct wm831x_dcdc *dcdc = rdev_get_drvdata(rdev); | ||
681 | struct wm831x *wm831x = dcdc->wm831x; | ||
682 | u16 reg = dcdc->base + WM831X_DCDC_ON_CONFIG; | ||
683 | int val; | ||
684 | |||
685 | val = wm831x_reg_read(wm831x, reg); | ||
686 | if (val < 0) | ||
687 | return val; | ||
688 | |||
689 | return val & WM831X_DC3_ON_VSEL_MASK; | ||
690 | } | ||
691 | |||
692 | static struct regulator_ops wm831x_buckp_ops = { | 648 | static struct regulator_ops wm831x_buckp_ops = { |
693 | .set_voltage = wm831x_buckp_set_voltage, | 649 | .set_voltage = wm831x_buckp_set_voltage, |
694 | .get_voltage_sel = wm831x_buckp_get_voltage_sel, | 650 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
695 | .list_voltage = wm831x_buckp_list_voltage, | 651 | .list_voltage = wm831x_buckp_list_voltage, |
696 | .set_suspend_voltage = wm831x_buckp_set_suspend_voltage, | 652 | .set_suspend_voltage = wm831x_buckp_set_suspend_voltage, |
697 | 653 | ||
698 | .is_enabled = wm831x_dcdc_is_enabled, | 654 | .is_enabled = regulator_is_enabled_regmap, |
699 | .enable = wm831x_dcdc_enable, | 655 | .enable = regulator_enable_regmap, |
700 | .disable = wm831x_dcdc_disable, | 656 | .disable = regulator_disable_regmap, |
701 | .get_status = wm831x_dcdc_get_status, | 657 | .get_status = wm831x_dcdc_get_status, |
702 | .get_mode = wm831x_dcdc_get_mode, | 658 | .get_mode = wm831x_dcdc_get_mode, |
703 | .set_mode = wm831x_dcdc_set_mode, | 659 | .set_mode = wm831x_dcdc_set_mode, |
@@ -708,6 +664,7 @@ static __devinit int wm831x_buckp_probe(struct platform_device *pdev) | |||
708 | { | 664 | { |
709 | struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); | 665 | struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); |
710 | struct wm831x_pdata *pdata = wm831x->dev->platform_data; | 666 | struct wm831x_pdata *pdata = wm831x->dev->platform_data; |
667 | struct regulator_config config = { }; | ||
711 | int id; | 668 | int id; |
712 | struct wm831x_dcdc *dcdc; | 669 | struct wm831x_dcdc *dcdc; |
713 | struct resource *res; | 670 | struct resource *res; |
@@ -721,9 +678,6 @@ static __devinit int wm831x_buckp_probe(struct platform_device *pdev) | |||
721 | 678 | ||
722 | dev_dbg(&pdev->dev, "Probing DCDC%d\n", id + 1); | 679 | dev_dbg(&pdev->dev, "Probing DCDC%d\n", id + 1); |
723 | 680 | ||
724 | if (pdata == NULL || pdata->dcdc[id] == NULL) | ||
725 | return -ENODEV; | ||
726 | |||
727 | dcdc = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_dcdc), | 681 | dcdc = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_dcdc), |
728 | GFP_KERNEL); | 682 | GFP_KERNEL); |
729 | if (dcdc == NULL) { | 683 | if (dcdc == NULL) { |
@@ -743,14 +697,28 @@ static __devinit int wm831x_buckp_probe(struct platform_device *pdev) | |||
743 | 697 | ||
744 | snprintf(dcdc->name, sizeof(dcdc->name), "DCDC%d", id + 1); | 698 | snprintf(dcdc->name, sizeof(dcdc->name), "DCDC%d", id + 1); |
745 | dcdc->desc.name = dcdc->name; | 699 | dcdc->desc.name = dcdc->name; |
700 | |||
701 | snprintf(dcdc->supply_name, sizeof(dcdc->supply_name), | ||
702 | "DC%dVDD", id + 1); | ||
703 | dcdc->desc.supply_name = dcdc->supply_name; | ||
704 | |||
746 | dcdc->desc.id = id; | 705 | dcdc->desc.id = id; |
747 | dcdc->desc.type = REGULATOR_VOLTAGE; | 706 | dcdc->desc.type = REGULATOR_VOLTAGE; |
748 | dcdc->desc.n_voltages = WM831X_BUCKP_MAX_SELECTOR + 1; | 707 | dcdc->desc.n_voltages = WM831X_BUCKP_MAX_SELECTOR + 1; |
749 | dcdc->desc.ops = &wm831x_buckp_ops; | 708 | dcdc->desc.ops = &wm831x_buckp_ops; |
750 | dcdc->desc.owner = THIS_MODULE; | 709 | dcdc->desc.owner = THIS_MODULE; |
751 | 710 | dcdc->desc.vsel_reg = dcdc->base + WM831X_DCDC_ON_CONFIG; | |
752 | dcdc->regulator = regulator_register(&dcdc->desc, &pdev->dev, | 711 | dcdc->desc.vsel_mask = WM831X_DC3_ON_VSEL_MASK; |
753 | pdata->dcdc[id], dcdc, NULL); | 712 | dcdc->desc.enable_reg = WM831X_DCDC_ENABLE; |
713 | dcdc->desc.enable_mask = 1 << id; | ||
714 | |||
715 | config.dev = pdev->dev.parent; | ||
716 | if (pdata) | ||
717 | config.init_data = pdata->dcdc[id]; | ||
718 | config.driver_data = dcdc; | ||
719 | config.regmap = wm831x->regmap; | ||
720 | |||
721 | dcdc->regulator = regulator_register(&dcdc->desc, &config); | ||
754 | if (IS_ERR(dcdc->regulator)) { | 722 | if (IS_ERR(dcdc->regulator)) { |
755 | ret = PTR_ERR(dcdc->regulator); | 723 | ret = PTR_ERR(dcdc->regulator); |
756 | dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n", | 724 | dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n", |
@@ -832,15 +800,16 @@ static int wm831x_boostp_get_status(struct regulator_dev *rdev) | |||
832 | static struct regulator_ops wm831x_boostp_ops = { | 800 | static struct regulator_ops wm831x_boostp_ops = { |
833 | .get_status = wm831x_boostp_get_status, | 801 | .get_status = wm831x_boostp_get_status, |
834 | 802 | ||
835 | .is_enabled = wm831x_dcdc_is_enabled, | 803 | .is_enabled = regulator_is_enabled_regmap, |
836 | .enable = wm831x_dcdc_enable, | 804 | .enable = regulator_enable_regmap, |
837 | .disable = wm831x_dcdc_disable, | 805 | .disable = regulator_disable_regmap, |
838 | }; | 806 | }; |
839 | 807 | ||
840 | static __devinit int wm831x_boostp_probe(struct platform_device *pdev) | 808 | static __devinit int wm831x_boostp_probe(struct platform_device *pdev) |
841 | { | 809 | { |
842 | struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); | 810 | struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); |
843 | struct wm831x_pdata *pdata = wm831x->dev->platform_data; | 811 | struct wm831x_pdata *pdata = wm831x->dev->platform_data; |
812 | struct regulator_config config = { }; | ||
844 | int id = pdev->id % ARRAY_SIZE(pdata->dcdc); | 813 | int id = pdev->id % ARRAY_SIZE(pdata->dcdc); |
845 | struct wm831x_dcdc *dcdc; | 814 | struct wm831x_dcdc *dcdc; |
846 | struct resource *res; | 815 | struct resource *res; |
@@ -851,7 +820,7 @@ static __devinit int wm831x_boostp_probe(struct platform_device *pdev) | |||
851 | if (pdata == NULL || pdata->dcdc[id] == NULL) | 820 | if (pdata == NULL || pdata->dcdc[id] == NULL) |
852 | return -ENODEV; | 821 | return -ENODEV; |
853 | 822 | ||
854 | dcdc = kzalloc(sizeof(struct wm831x_dcdc), GFP_KERNEL); | 823 | dcdc = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_dcdc), GFP_KERNEL); |
855 | if (dcdc == NULL) { | 824 | if (dcdc == NULL) { |
856 | dev_err(&pdev->dev, "Unable to allocate private data\n"); | 825 | dev_err(&pdev->dev, "Unable to allocate private data\n"); |
857 | return -ENOMEM; | 826 | return -ENOMEM; |
@@ -873,9 +842,16 @@ static __devinit int wm831x_boostp_probe(struct platform_device *pdev) | |||
873 | dcdc->desc.type = REGULATOR_VOLTAGE; | 842 | dcdc->desc.type = REGULATOR_VOLTAGE; |
874 | dcdc->desc.ops = &wm831x_boostp_ops; | 843 | dcdc->desc.ops = &wm831x_boostp_ops; |
875 | dcdc->desc.owner = THIS_MODULE; | 844 | dcdc->desc.owner = THIS_MODULE; |
845 | dcdc->desc.enable_reg = WM831X_DCDC_ENABLE; | ||
846 | dcdc->desc.enable_mask = 1 << id; | ||
876 | 847 | ||
877 | dcdc->regulator = regulator_register(&dcdc->desc, &pdev->dev, | 848 | config.dev = pdev->dev.parent; |
878 | pdata->dcdc[id], dcdc, NULL); | 849 | if (pdata) |
850 | config.init_data = pdata->dcdc[id]; | ||
851 | config.driver_data = dcdc; | ||
852 | config.regmap = wm831x->regmap; | ||
853 | |||
854 | dcdc->regulator = regulator_register(&dcdc->desc, &config); | ||
879 | if (IS_ERR(dcdc->regulator)) { | 855 | if (IS_ERR(dcdc->regulator)) { |
880 | ret = PTR_ERR(dcdc->regulator); | 856 | ret = PTR_ERR(dcdc->regulator); |
881 | dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n", | 857 | dev_err(wm831x->dev, "Failed to register DCDC%d: %d\n", |
@@ -900,7 +876,6 @@ static __devinit int wm831x_boostp_probe(struct platform_device *pdev) | |||
900 | err_regulator: | 876 | err_regulator: |
901 | regulator_unregister(dcdc->regulator); | 877 | regulator_unregister(dcdc->regulator); |
902 | err: | 878 | err: |
903 | kfree(dcdc); | ||
904 | return ret; | 879 | return ret; |
905 | } | 880 | } |
906 | 881 | ||
@@ -912,7 +887,6 @@ static __devexit int wm831x_boostp_remove(struct platform_device *pdev) | |||
912 | 887 | ||
913 | free_irq(platform_get_irq_byname(pdev, "UV"), dcdc); | 888 | free_irq(platform_get_irq_byname(pdev, "UV"), dcdc); |
914 | regulator_unregister(dcdc->regulator); | 889 | regulator_unregister(dcdc->regulator); |
915 | kfree(dcdc); | ||
916 | 890 | ||
917 | return 0; | 891 | return 0; |
918 | } | 892 | } |
@@ -936,9 +910,9 @@ static struct platform_driver wm831x_boostp_driver = { | |||
936 | #define WM831X_EPE_BASE 6 | 910 | #define WM831X_EPE_BASE 6 |
937 | 911 | ||
938 | static struct regulator_ops wm831x_epe_ops = { | 912 | static struct regulator_ops wm831x_epe_ops = { |
939 | .is_enabled = wm831x_dcdc_is_enabled, | 913 | .is_enabled = regulator_is_enabled_regmap, |
940 | .enable = wm831x_dcdc_enable, | 914 | .enable = regulator_enable_regmap, |
941 | .disable = wm831x_dcdc_disable, | 915 | .disable = regulator_disable_regmap, |
942 | .get_status = wm831x_dcdc_get_status, | 916 | .get_status = wm831x_dcdc_get_status, |
943 | }; | 917 | }; |
944 | 918 | ||
@@ -946,16 +920,14 @@ static __devinit int wm831x_epe_probe(struct platform_device *pdev) | |||
946 | { | 920 | { |
947 | struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); | 921 | struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); |
948 | struct wm831x_pdata *pdata = wm831x->dev->platform_data; | 922 | struct wm831x_pdata *pdata = wm831x->dev->platform_data; |
923 | struct regulator_config config = { }; | ||
949 | int id = pdev->id % ARRAY_SIZE(pdata->epe); | 924 | int id = pdev->id % ARRAY_SIZE(pdata->epe); |
950 | struct wm831x_dcdc *dcdc; | 925 | struct wm831x_dcdc *dcdc; |
951 | int ret; | 926 | int ret; |
952 | 927 | ||
953 | dev_dbg(&pdev->dev, "Probing EPE%d\n", id + 1); | 928 | dev_dbg(&pdev->dev, "Probing EPE%d\n", id + 1); |
954 | 929 | ||
955 | if (pdata == NULL || pdata->epe[id] == NULL) | 930 | dcdc = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_dcdc), GFP_KERNEL); |
956 | return -ENODEV; | ||
957 | |||
958 | dcdc = kzalloc(sizeof(struct wm831x_dcdc), GFP_KERNEL); | ||
959 | if (dcdc == NULL) { | 931 | if (dcdc == NULL) { |
960 | dev_err(&pdev->dev, "Unable to allocate private data\n"); | 932 | dev_err(&pdev->dev, "Unable to allocate private data\n"); |
961 | return -ENOMEM; | 933 | return -ENOMEM; |
@@ -972,9 +944,16 @@ static __devinit int wm831x_epe_probe(struct platform_device *pdev) | |||
972 | dcdc->desc.ops = &wm831x_epe_ops; | 944 | dcdc->desc.ops = &wm831x_epe_ops; |
973 | dcdc->desc.type = REGULATOR_VOLTAGE; | 945 | dcdc->desc.type = REGULATOR_VOLTAGE; |
974 | dcdc->desc.owner = THIS_MODULE; | 946 | dcdc->desc.owner = THIS_MODULE; |
947 | dcdc->desc.enable_reg = WM831X_DCDC_ENABLE; | ||
948 | dcdc->desc.enable_mask = 1 << dcdc->desc.id; | ||
949 | |||
950 | config.dev = pdev->dev.parent; | ||
951 | if (pdata) | ||
952 | config.init_data = pdata->epe[id]; | ||
953 | config.driver_data = dcdc; | ||
954 | config.regmap = wm831x->regmap; | ||
975 | 955 | ||
976 | dcdc->regulator = regulator_register(&dcdc->desc, &pdev->dev, | 956 | dcdc->regulator = regulator_register(&dcdc->desc, &config); |
977 | pdata->epe[id], dcdc, NULL); | ||
978 | if (IS_ERR(dcdc->regulator)) { | 957 | if (IS_ERR(dcdc->regulator)) { |
979 | ret = PTR_ERR(dcdc->regulator); | 958 | ret = PTR_ERR(dcdc->regulator); |
980 | dev_err(wm831x->dev, "Failed to register EPE%d: %d\n", | 959 | dev_err(wm831x->dev, "Failed to register EPE%d: %d\n", |
@@ -987,7 +966,6 @@ static __devinit int wm831x_epe_probe(struct platform_device *pdev) | |||
987 | return 0; | 966 | return 0; |
988 | 967 | ||
989 | err: | 968 | err: |
990 | kfree(dcdc); | ||
991 | return ret; | 969 | return ret; |
992 | } | 970 | } |
993 | 971 | ||
@@ -996,9 +974,7 @@ static __devexit int wm831x_epe_remove(struct platform_device *pdev) | |||
996 | struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev); | 974 | struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev); |
997 | 975 | ||
998 | platform_set_drvdata(pdev, NULL); | 976 | platform_set_drvdata(pdev, NULL); |
999 | |||
1000 | regulator_unregister(dcdc->regulator); | 977 | regulator_unregister(dcdc->regulator); |
1001 | kfree(dcdc); | ||
1002 | 978 | ||
1003 | return 0; | 979 | return 0; |
1004 | } | 980 | } |
diff --git a/drivers/regulator/wm831x-isink.c b/drivers/regulator/wm831x-isink.c index b414e09c5620..b50ab778b098 100644 --- a/drivers/regulator/wm831x-isink.c +++ b/drivers/regulator/wm831x-isink.c | |||
@@ -154,6 +154,7 @@ static __devinit int wm831x_isink_probe(struct platform_device *pdev) | |||
154 | struct wm831x_pdata *pdata = wm831x->dev->platform_data; | 154 | struct wm831x_pdata *pdata = wm831x->dev->platform_data; |
155 | struct wm831x_isink *isink; | 155 | struct wm831x_isink *isink; |
156 | int id = pdev->id % ARRAY_SIZE(pdata->isink); | 156 | int id = pdev->id % ARRAY_SIZE(pdata->isink); |
157 | struct regulator_config config = { }; | ||
157 | struct resource *res; | 158 | struct resource *res; |
158 | int ret, irq; | 159 | int ret, irq; |
159 | 160 | ||
@@ -189,8 +190,11 @@ static __devinit int wm831x_isink_probe(struct platform_device *pdev) | |||
189 | isink->desc.type = REGULATOR_CURRENT; | 190 | isink->desc.type = REGULATOR_CURRENT; |
190 | isink->desc.owner = THIS_MODULE; | 191 | isink->desc.owner = THIS_MODULE; |
191 | 192 | ||
192 | isink->regulator = regulator_register(&isink->desc, &pdev->dev, | 193 | config.dev = pdev->dev.parent; |
193 | pdata->isink[id], isink, NULL); | 194 | config.init_data = pdata->isink[id]; |
195 | config.driver_data = isink; | ||
196 | |||
197 | isink->regulator = regulator_register(&isink->desc, &config); | ||
194 | if (IS_ERR(isink->regulator)) { | 198 | if (IS_ERR(isink->regulator)) { |
195 | ret = PTR_ERR(isink->regulator); | 199 | ret = PTR_ERR(isink->regulator); |
196 | dev_err(wm831x->dev, "Failed to register ISINK%d: %d\n", | 200 | dev_err(wm831x->dev, "Failed to register ISINK%d: %d\n", |
diff --git a/drivers/regulator/wm831x-ldo.c b/drivers/regulator/wm831x-ldo.c index 641e9f6499d1..aa1f8b3fbe16 100644 --- a/drivers/regulator/wm831x-ldo.c +++ b/drivers/regulator/wm831x-ldo.c | |||
@@ -25,7 +25,7 @@ | |||
25 | #include <linux/mfd/wm831x/regulator.h> | 25 | #include <linux/mfd/wm831x/regulator.h> |
26 | #include <linux/mfd/wm831x/pdata.h> | 26 | #include <linux/mfd/wm831x/pdata.h> |
27 | 27 | ||
28 | #define WM831X_LDO_MAX_NAME 6 | 28 | #define WM831X_LDO_MAX_NAME 9 |
29 | 29 | ||
30 | #define WM831X_LDO_CONTROL 0 | 30 | #define WM831X_LDO_CONTROL 0 |
31 | #define WM831X_LDO_ON_CONTROL 1 | 31 | #define WM831X_LDO_ON_CONTROL 1 |
@@ -36,6 +36,7 @@ | |||
36 | 36 | ||
37 | struct wm831x_ldo { | 37 | struct wm831x_ldo { |
38 | char name[WM831X_LDO_MAX_NAME]; | 38 | char name[WM831X_LDO_MAX_NAME]; |
39 | char supply_name[WM831X_LDO_MAX_NAME]; | ||
39 | struct regulator_desc desc; | 40 | struct regulator_desc desc; |
40 | int base; | 41 | int base; |
41 | struct wm831x *wm831x; | 42 | struct wm831x *wm831x; |
@@ -46,41 +47,6 @@ struct wm831x_ldo { | |||
46 | * Shared | 47 | * Shared |
47 | */ | 48 | */ |
48 | 49 | ||
49 | static int wm831x_ldo_is_enabled(struct regulator_dev *rdev) | ||
50 | { | ||
51 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); | ||
52 | struct wm831x *wm831x = ldo->wm831x; | ||
53 | int mask = 1 << rdev_get_id(rdev); | ||
54 | int reg; | ||
55 | |||
56 | reg = wm831x_reg_read(wm831x, WM831X_LDO_ENABLE); | ||
57 | if (reg < 0) | ||
58 | return reg; | ||
59 | |||
60 | if (reg & mask) | ||
61 | return 1; | ||
62 | else | ||
63 | return 0; | ||
64 | } | ||
65 | |||
66 | static int wm831x_ldo_enable(struct regulator_dev *rdev) | ||
67 | { | ||
68 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); | ||
69 | struct wm831x *wm831x = ldo->wm831x; | ||
70 | int mask = 1 << rdev_get_id(rdev); | ||
71 | |||
72 | return wm831x_set_bits(wm831x, WM831X_LDO_ENABLE, mask, mask); | ||
73 | } | ||
74 | |||
75 | static int wm831x_ldo_disable(struct regulator_dev *rdev) | ||
76 | { | ||
77 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); | ||
78 | struct wm831x *wm831x = ldo->wm831x; | ||
79 | int mask = 1 << rdev_get_id(rdev); | ||
80 | |||
81 | return wm831x_set_bits(wm831x, WM831X_LDO_ENABLE, mask, 0); | ||
82 | } | ||
83 | |||
84 | static irqreturn_t wm831x_ldo_uv_irq(int irq, void *data) | 50 | static irqreturn_t wm831x_ldo_uv_irq(int irq, void *data) |
85 | { | 51 | { |
86 | struct wm831x_ldo *ldo = data; | 52 | struct wm831x_ldo *ldo = data; |
@@ -105,7 +71,7 @@ static int wm831x_gp_ldo_list_voltage(struct regulator_dev *rdev, | |||
105 | /* 0.9-1.6V in 50mV steps */ | 71 | /* 0.9-1.6V in 50mV steps */ |
106 | if (selector <= WM831X_GP_LDO_SELECTOR_LOW) | 72 | if (selector <= WM831X_GP_LDO_SELECTOR_LOW) |
107 | return 900000 + (selector * 50000); | 73 | return 900000 + (selector * 50000); |
108 | /* 1.7-3.3V in 50mV steps */ | 74 | /* 1.7-3.3V in 100mV steps */ |
109 | if (selector <= WM831X_GP_LDO_MAX_SELECTOR) | 75 | if (selector <= WM831X_GP_LDO_MAX_SELECTOR) |
110 | return 1600000 + ((selector - WM831X_GP_LDO_SELECTOR_LOW) | 76 | return 1600000 + ((selector - WM831X_GP_LDO_SELECTOR_LOW) |
111 | * 100000); | 77 | * 100000); |
@@ -160,22 +126,6 @@ static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev *rdev, | |||
160 | return wm831x_gp_ldo_set_voltage_int(rdev, reg, uV, uV, &selector); | 126 | return wm831x_gp_ldo_set_voltage_int(rdev, reg, uV, uV, &selector); |
161 | } | 127 | } |
162 | 128 | ||
163 | static int wm831x_gp_ldo_get_voltage_sel(struct regulator_dev *rdev) | ||
164 | { | ||
165 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); | ||
166 | struct wm831x *wm831x = ldo->wm831x; | ||
167 | int reg = ldo->base + WM831X_LDO_ON_CONTROL; | ||
168 | int ret; | ||
169 | |||
170 | ret = wm831x_reg_read(wm831x, reg); | ||
171 | if (ret < 0) | ||
172 | return ret; | ||
173 | |||
174 | ret &= WM831X_LDO1_ON_VSEL_MASK; | ||
175 | |||
176 | return ret; | ||
177 | } | ||
178 | |||
179 | static unsigned int wm831x_gp_ldo_get_mode(struct regulator_dev *rdev) | 129 | static unsigned int wm831x_gp_ldo_get_mode(struct regulator_dev *rdev) |
180 | { | 130 | { |
181 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); | 131 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); |
@@ -293,7 +243,7 @@ static unsigned int wm831x_gp_ldo_get_optimum_mode(struct regulator_dev *rdev, | |||
293 | 243 | ||
294 | static struct regulator_ops wm831x_gp_ldo_ops = { | 244 | static struct regulator_ops wm831x_gp_ldo_ops = { |
295 | .list_voltage = wm831x_gp_ldo_list_voltage, | 245 | .list_voltage = wm831x_gp_ldo_list_voltage, |
296 | .get_voltage_sel = wm831x_gp_ldo_get_voltage_sel, | 246 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
297 | .set_voltage = wm831x_gp_ldo_set_voltage, | 247 | .set_voltage = wm831x_gp_ldo_set_voltage, |
298 | .set_suspend_voltage = wm831x_gp_ldo_set_suspend_voltage, | 248 | .set_suspend_voltage = wm831x_gp_ldo_set_suspend_voltage, |
299 | .get_mode = wm831x_gp_ldo_get_mode, | 249 | .get_mode = wm831x_gp_ldo_get_mode, |
@@ -301,15 +251,16 @@ static struct regulator_ops wm831x_gp_ldo_ops = { | |||
301 | .get_status = wm831x_gp_ldo_get_status, | 251 | .get_status = wm831x_gp_ldo_get_status, |
302 | .get_optimum_mode = wm831x_gp_ldo_get_optimum_mode, | 252 | .get_optimum_mode = wm831x_gp_ldo_get_optimum_mode, |
303 | 253 | ||
304 | .is_enabled = wm831x_ldo_is_enabled, | 254 | .is_enabled = regulator_is_enabled_regmap, |
305 | .enable = wm831x_ldo_enable, | 255 | .enable = regulator_enable_regmap, |
306 | .disable = wm831x_ldo_disable, | 256 | .disable = regulator_disable_regmap, |
307 | }; | 257 | }; |
308 | 258 | ||
309 | static __devinit int wm831x_gp_ldo_probe(struct platform_device *pdev) | 259 | static __devinit int wm831x_gp_ldo_probe(struct platform_device *pdev) |
310 | { | 260 | { |
311 | struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); | 261 | struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); |
312 | struct wm831x_pdata *pdata = wm831x->dev->platform_data; | 262 | struct wm831x_pdata *pdata = wm831x->dev->platform_data; |
263 | struct regulator_config config = { }; | ||
313 | int id; | 264 | int id; |
314 | struct wm831x_ldo *ldo; | 265 | struct wm831x_ldo *ldo; |
315 | struct resource *res; | 266 | struct resource *res; |
@@ -323,9 +274,6 @@ static __devinit int wm831x_gp_ldo_probe(struct platform_device *pdev) | |||
323 | 274 | ||
324 | dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1); | 275 | dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1); |
325 | 276 | ||
326 | if (pdata == NULL || pdata->ldo[id] == NULL) | ||
327 | return -ENODEV; | ||
328 | |||
329 | ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL); | 277 | ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL); |
330 | if (ldo == NULL) { | 278 | if (ldo == NULL) { |
331 | dev_err(&pdev->dev, "Unable to allocate private data\n"); | 279 | dev_err(&pdev->dev, "Unable to allocate private data\n"); |
@@ -344,14 +292,28 @@ static __devinit int wm831x_gp_ldo_probe(struct platform_device *pdev) | |||
344 | 292 | ||
345 | snprintf(ldo->name, sizeof(ldo->name), "LDO%d", id + 1); | 293 | snprintf(ldo->name, sizeof(ldo->name), "LDO%d", id + 1); |
346 | ldo->desc.name = ldo->name; | 294 | ldo->desc.name = ldo->name; |
295 | |||
296 | snprintf(ldo->supply_name, sizeof(ldo->supply_name), | ||
297 | "LDO%dVDD", id + 1); | ||
298 | ldo->desc.supply_name = ldo->supply_name; | ||
299 | |||
347 | ldo->desc.id = id; | 300 | ldo->desc.id = id; |
348 | ldo->desc.type = REGULATOR_VOLTAGE; | 301 | ldo->desc.type = REGULATOR_VOLTAGE; |
349 | ldo->desc.n_voltages = WM831X_GP_LDO_MAX_SELECTOR + 1; | 302 | ldo->desc.n_voltages = WM831X_GP_LDO_MAX_SELECTOR + 1; |
350 | ldo->desc.ops = &wm831x_gp_ldo_ops; | 303 | ldo->desc.ops = &wm831x_gp_ldo_ops; |
351 | ldo->desc.owner = THIS_MODULE; | 304 | ldo->desc.owner = THIS_MODULE; |
352 | 305 | ldo->desc.vsel_reg = ldo->base + WM831X_LDO_ON_CONTROL; | |
353 | ldo->regulator = regulator_register(&ldo->desc, &pdev->dev, | 306 | ldo->desc.vsel_mask = WM831X_LDO1_ON_VSEL_MASK; |
354 | pdata->ldo[id], ldo, NULL); | 307 | ldo->desc.enable_reg = WM831X_LDO_ENABLE; |
308 | ldo->desc.enable_mask = 1 << id; | ||
309 | |||
310 | config.dev = pdev->dev.parent; | ||
311 | if (pdata) | ||
312 | config.init_data = pdata->ldo[id]; | ||
313 | config.driver_data = ldo; | ||
314 | config.regmap = wm831x->regmap; | ||
315 | |||
316 | ldo->regulator = regulator_register(&ldo->desc, &config); | ||
355 | if (IS_ERR(ldo->regulator)) { | 317 | if (IS_ERR(ldo->regulator)) { |
356 | ret = PTR_ERR(ldo->regulator); | 318 | ret = PTR_ERR(ldo->regulator); |
357 | dev_err(wm831x->dev, "Failed to register LDO%d: %d\n", | 319 | dev_err(wm831x->dev, "Failed to register LDO%d: %d\n", |
@@ -414,7 +376,7 @@ static int wm831x_aldo_list_voltage(struct regulator_dev *rdev, | |||
414 | /* 1-1.6V in 50mV steps */ | 376 | /* 1-1.6V in 50mV steps */ |
415 | if (selector <= WM831X_ALDO_SELECTOR_LOW) | 377 | if (selector <= WM831X_ALDO_SELECTOR_LOW) |
416 | return 1000000 + (selector * 50000); | 378 | return 1000000 + (selector * 50000); |
417 | /* 1.7-3.5V in 50mV steps */ | 379 | /* 1.7-3.5V in 100mV steps */ |
418 | if (selector <= WM831X_ALDO_MAX_SELECTOR) | 380 | if (selector <= WM831X_ALDO_MAX_SELECTOR) |
419 | return 1600000 + ((selector - WM831X_ALDO_SELECTOR_LOW) | 381 | return 1600000 + ((selector - WM831X_ALDO_SELECTOR_LOW) |
420 | * 100000); | 382 | * 100000); |
@@ -468,22 +430,6 @@ static int wm831x_aldo_set_suspend_voltage(struct regulator_dev *rdev, | |||
468 | return wm831x_aldo_set_voltage_int(rdev, reg, uV, uV, &selector); | 430 | return wm831x_aldo_set_voltage_int(rdev, reg, uV, uV, &selector); |
469 | } | 431 | } |
470 | 432 | ||
471 | static int wm831x_aldo_get_voltage_sel(struct regulator_dev *rdev) | ||
472 | { | ||
473 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); | ||
474 | struct wm831x *wm831x = ldo->wm831x; | ||
475 | int reg = ldo->base + WM831X_LDO_ON_CONTROL; | ||
476 | int ret; | ||
477 | |||
478 | ret = wm831x_reg_read(wm831x, reg); | ||
479 | if (ret < 0) | ||
480 | return ret; | ||
481 | |||
482 | ret &= WM831X_LDO7_ON_VSEL_MASK; | ||
483 | |||
484 | return ret; | ||
485 | } | ||
486 | |||
487 | static unsigned int wm831x_aldo_get_mode(struct regulator_dev *rdev) | 433 | static unsigned int wm831x_aldo_get_mode(struct regulator_dev *rdev) |
488 | { | 434 | { |
489 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); | 435 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); |
@@ -559,22 +505,23 @@ static int wm831x_aldo_get_status(struct regulator_dev *rdev) | |||
559 | 505 | ||
560 | static struct regulator_ops wm831x_aldo_ops = { | 506 | static struct regulator_ops wm831x_aldo_ops = { |
561 | .list_voltage = wm831x_aldo_list_voltage, | 507 | .list_voltage = wm831x_aldo_list_voltage, |
562 | .get_voltage_sel = wm831x_aldo_get_voltage_sel, | 508 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
563 | .set_voltage = wm831x_aldo_set_voltage, | 509 | .set_voltage = wm831x_aldo_set_voltage, |
564 | .set_suspend_voltage = wm831x_aldo_set_suspend_voltage, | 510 | .set_suspend_voltage = wm831x_aldo_set_suspend_voltage, |
565 | .get_mode = wm831x_aldo_get_mode, | 511 | .get_mode = wm831x_aldo_get_mode, |
566 | .set_mode = wm831x_aldo_set_mode, | 512 | .set_mode = wm831x_aldo_set_mode, |
567 | .get_status = wm831x_aldo_get_status, | 513 | .get_status = wm831x_aldo_get_status, |
568 | 514 | ||
569 | .is_enabled = wm831x_ldo_is_enabled, | 515 | .is_enabled = regulator_is_enabled_regmap, |
570 | .enable = wm831x_ldo_enable, | 516 | .enable = regulator_enable_regmap, |
571 | .disable = wm831x_ldo_disable, | 517 | .disable = regulator_disable_regmap, |
572 | }; | 518 | }; |
573 | 519 | ||
574 | static __devinit int wm831x_aldo_probe(struct platform_device *pdev) | 520 | static __devinit int wm831x_aldo_probe(struct platform_device *pdev) |
575 | { | 521 | { |
576 | struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); | 522 | struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); |
577 | struct wm831x_pdata *pdata = wm831x->dev->platform_data; | 523 | struct wm831x_pdata *pdata = wm831x->dev->platform_data; |
524 | struct regulator_config config = { }; | ||
578 | int id; | 525 | int id; |
579 | struct wm831x_ldo *ldo; | 526 | struct wm831x_ldo *ldo; |
580 | struct resource *res; | 527 | struct resource *res; |
@@ -588,9 +535,6 @@ static __devinit int wm831x_aldo_probe(struct platform_device *pdev) | |||
588 | 535 | ||
589 | dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1); | 536 | dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1); |
590 | 537 | ||
591 | if (pdata == NULL || pdata->ldo[id] == NULL) | ||
592 | return -ENODEV; | ||
593 | |||
594 | ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL); | 538 | ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL); |
595 | if (ldo == NULL) { | 539 | if (ldo == NULL) { |
596 | dev_err(&pdev->dev, "Unable to allocate private data\n"); | 540 | dev_err(&pdev->dev, "Unable to allocate private data\n"); |
@@ -609,14 +553,28 @@ static __devinit int wm831x_aldo_probe(struct platform_device *pdev) | |||
609 | 553 | ||
610 | snprintf(ldo->name, sizeof(ldo->name), "LDO%d", id + 1); | 554 | snprintf(ldo->name, sizeof(ldo->name), "LDO%d", id + 1); |
611 | ldo->desc.name = ldo->name; | 555 | ldo->desc.name = ldo->name; |
556 | |||
557 | snprintf(ldo->supply_name, sizeof(ldo->supply_name), | ||
558 | "LDO%dVDD", id + 1); | ||
559 | ldo->desc.supply_name = ldo->supply_name; | ||
560 | |||
612 | ldo->desc.id = id; | 561 | ldo->desc.id = id; |
613 | ldo->desc.type = REGULATOR_VOLTAGE; | 562 | ldo->desc.type = REGULATOR_VOLTAGE; |
614 | ldo->desc.n_voltages = WM831X_ALDO_MAX_SELECTOR + 1; | 563 | ldo->desc.n_voltages = WM831X_ALDO_MAX_SELECTOR + 1; |
615 | ldo->desc.ops = &wm831x_aldo_ops; | 564 | ldo->desc.ops = &wm831x_aldo_ops; |
616 | ldo->desc.owner = THIS_MODULE; | 565 | ldo->desc.owner = THIS_MODULE; |
617 | 566 | ldo->desc.vsel_reg = ldo->base + WM831X_LDO_ON_CONTROL; | |
618 | ldo->regulator = regulator_register(&ldo->desc, &pdev->dev, | 567 | ldo->desc.vsel_mask = WM831X_LDO7_ON_VSEL_MASK; |
619 | pdata->ldo[id], ldo, NULL); | 568 | ldo->desc.enable_reg = WM831X_LDO_ENABLE; |
569 | ldo->desc.enable_mask = 1 << id; | ||
570 | |||
571 | config.dev = pdev->dev.parent; | ||
572 | if (pdata) | ||
573 | config.init_data = pdata->ldo[id]; | ||
574 | config.driver_data = ldo; | ||
575 | config.regmap = wm831x->regmap; | ||
576 | |||
577 | ldo->regulator = regulator_register(&ldo->desc, &config); | ||
620 | if (IS_ERR(ldo->regulator)) { | 578 | if (IS_ERR(ldo->regulator)) { |
621 | ret = PTR_ERR(ldo->regulator); | 579 | ret = PTR_ERR(ldo->regulator); |
622 | dev_err(wm831x->dev, "Failed to register LDO%d: %d\n", | 580 | dev_err(wm831x->dev, "Failed to register LDO%d: %d\n", |
@@ -668,15 +626,6 @@ static struct platform_driver wm831x_aldo_driver = { | |||
668 | 626 | ||
669 | #define WM831X_ALIVE_LDO_MAX_SELECTOR 0xf | 627 | #define WM831X_ALIVE_LDO_MAX_SELECTOR 0xf |
670 | 628 | ||
671 | static int wm831x_alive_ldo_list_voltage(struct regulator_dev *rdev, | ||
672 | unsigned int selector) | ||
673 | { | ||
674 | /* 0.8-1.55V in 50mV steps */ | ||
675 | if (selector <= WM831X_ALIVE_LDO_MAX_SELECTOR) | ||
676 | return 800000 + (selector * 50000); | ||
677 | return -EINVAL; | ||
678 | } | ||
679 | |||
680 | static int wm831x_alive_ldo_set_voltage_int(struct regulator_dev *rdev, | 629 | static int wm831x_alive_ldo_set_voltage_int(struct regulator_dev *rdev, |
681 | int reg, | 630 | int reg, |
682 | int min_uV, int max_uV, | 631 | int min_uV, int max_uV, |
@@ -688,7 +637,7 @@ static int wm831x_alive_ldo_set_voltage_int(struct regulator_dev *rdev, | |||
688 | 637 | ||
689 | vsel = (min_uV - 800000) / 50000; | 638 | vsel = (min_uV - 800000) / 50000; |
690 | 639 | ||
691 | ret = wm831x_alive_ldo_list_voltage(rdev, vsel); | 640 | ret = regulator_list_voltage_linear(rdev, vsel); |
692 | if (ret < 0) | 641 | if (ret < 0) |
693 | return ret; | 642 | return ret; |
694 | if (ret < min_uV || ret > max_uV) | 643 | if (ret < min_uV || ret > max_uV) |
@@ -720,22 +669,6 @@ static int wm831x_alive_ldo_set_suspend_voltage(struct regulator_dev *rdev, | |||
720 | return wm831x_alive_ldo_set_voltage_int(rdev, reg, uV, uV, &selector); | 669 | return wm831x_alive_ldo_set_voltage_int(rdev, reg, uV, uV, &selector); |
721 | } | 670 | } |
722 | 671 | ||
723 | static int wm831x_alive_ldo_get_voltage_sel(struct regulator_dev *rdev) | ||
724 | { | ||
725 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); | ||
726 | struct wm831x *wm831x = ldo->wm831x; | ||
727 | int reg = ldo->base + WM831X_ALIVE_LDO_ON_CONTROL; | ||
728 | int ret; | ||
729 | |||
730 | ret = wm831x_reg_read(wm831x, reg); | ||
731 | if (ret < 0) | ||
732 | return ret; | ||
733 | |||
734 | ret &= WM831X_LDO11_ON_VSEL_MASK; | ||
735 | |||
736 | return ret; | ||
737 | } | ||
738 | |||
739 | static int wm831x_alive_ldo_get_status(struct regulator_dev *rdev) | 672 | static int wm831x_alive_ldo_get_status(struct regulator_dev *rdev) |
740 | { | 673 | { |
741 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); | 674 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); |
@@ -754,21 +687,22 @@ static int wm831x_alive_ldo_get_status(struct regulator_dev *rdev) | |||
754 | } | 687 | } |
755 | 688 | ||
756 | static struct regulator_ops wm831x_alive_ldo_ops = { | 689 | static struct regulator_ops wm831x_alive_ldo_ops = { |
757 | .list_voltage = wm831x_alive_ldo_list_voltage, | 690 | .list_voltage = regulator_list_voltage_linear, |
758 | .get_voltage_sel = wm831x_alive_ldo_get_voltage_sel, | 691 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
759 | .set_voltage = wm831x_alive_ldo_set_voltage, | 692 | .set_voltage = wm831x_alive_ldo_set_voltage, |
760 | .set_suspend_voltage = wm831x_alive_ldo_set_suspend_voltage, | 693 | .set_suspend_voltage = wm831x_alive_ldo_set_suspend_voltage, |
761 | .get_status = wm831x_alive_ldo_get_status, | 694 | .get_status = wm831x_alive_ldo_get_status, |
762 | 695 | ||
763 | .is_enabled = wm831x_ldo_is_enabled, | 696 | .is_enabled = regulator_is_enabled_regmap, |
764 | .enable = wm831x_ldo_enable, | 697 | .enable = regulator_enable_regmap, |
765 | .disable = wm831x_ldo_disable, | 698 | .disable = regulator_disable_regmap, |
766 | }; | 699 | }; |
767 | 700 | ||
768 | static __devinit int wm831x_alive_ldo_probe(struct platform_device *pdev) | 701 | static __devinit int wm831x_alive_ldo_probe(struct platform_device *pdev) |
769 | { | 702 | { |
770 | struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); | 703 | struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); |
771 | struct wm831x_pdata *pdata = wm831x->dev->platform_data; | 704 | struct wm831x_pdata *pdata = wm831x->dev->platform_data; |
705 | struct regulator_config config = { }; | ||
772 | int id; | 706 | int id; |
773 | struct wm831x_ldo *ldo; | 707 | struct wm831x_ldo *ldo; |
774 | struct resource *res; | 708 | struct resource *res; |
@@ -783,9 +717,6 @@ static __devinit int wm831x_alive_ldo_probe(struct platform_device *pdev) | |||
783 | 717 | ||
784 | dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1); | 718 | dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1); |
785 | 719 | ||
786 | if (pdata == NULL || pdata->ldo[id] == NULL) | ||
787 | return -ENODEV; | ||
788 | |||
789 | ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL); | 720 | ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL); |
790 | if (ldo == NULL) { | 721 | if (ldo == NULL) { |
791 | dev_err(&pdev->dev, "Unable to allocate private data\n"); | 722 | dev_err(&pdev->dev, "Unable to allocate private data\n"); |
@@ -804,14 +735,30 @@ static __devinit int wm831x_alive_ldo_probe(struct platform_device *pdev) | |||
804 | 735 | ||
805 | snprintf(ldo->name, sizeof(ldo->name), "LDO%d", id + 1); | 736 | snprintf(ldo->name, sizeof(ldo->name), "LDO%d", id + 1); |
806 | ldo->desc.name = ldo->name; | 737 | ldo->desc.name = ldo->name; |
738 | |||
739 | snprintf(ldo->supply_name, sizeof(ldo->supply_name), | ||
740 | "LDO%dVDD", id + 1); | ||
741 | ldo->desc.supply_name = ldo->supply_name; | ||
742 | |||
807 | ldo->desc.id = id; | 743 | ldo->desc.id = id; |
808 | ldo->desc.type = REGULATOR_VOLTAGE; | 744 | ldo->desc.type = REGULATOR_VOLTAGE; |
809 | ldo->desc.n_voltages = WM831X_ALIVE_LDO_MAX_SELECTOR + 1; | 745 | ldo->desc.n_voltages = WM831X_ALIVE_LDO_MAX_SELECTOR + 1; |
810 | ldo->desc.ops = &wm831x_alive_ldo_ops; | 746 | ldo->desc.ops = &wm831x_alive_ldo_ops; |
811 | ldo->desc.owner = THIS_MODULE; | 747 | ldo->desc.owner = THIS_MODULE; |
812 | 748 | ldo->desc.vsel_reg = ldo->base + WM831X_ALIVE_LDO_ON_CONTROL; | |
813 | ldo->regulator = regulator_register(&ldo->desc, &pdev->dev, | 749 | ldo->desc.vsel_mask = WM831X_LDO11_ON_VSEL_MASK; |
814 | pdata->ldo[id], ldo, NULL); | 750 | ldo->desc.enable_reg = WM831X_LDO_ENABLE; |
751 | ldo->desc.enable_mask = 1 << id; | ||
752 | ldo->desc.min_uV = 800000; | ||
753 | ldo->desc.uV_step = 50000; | ||
754 | |||
755 | config.dev = pdev->dev.parent; | ||
756 | if (pdata) | ||
757 | config.init_data = pdata->ldo[id]; | ||
758 | config.driver_data = ldo; | ||
759 | config.regmap = wm831x->regmap; | ||
760 | |||
761 | ldo->regulator = regulator_register(&ldo->desc, &config); | ||
815 | if (IS_ERR(ldo->regulator)) { | 762 | if (IS_ERR(ldo->regulator)) { |
816 | ret = PTR_ERR(ldo->regulator); | 763 | ret = PTR_ERR(ldo->regulator); |
817 | dev_err(wm831x->dev, "Failed to register LDO%d: %d\n", | 764 | dev_err(wm831x->dev, "Failed to register LDO%d: %d\n", |
diff --git a/drivers/regulator/wm8350-regulator.c b/drivers/regulator/wm8350-regulator.c index 05ecfb872319..94e550dc70b6 100644 --- a/drivers/regulator/wm8350-regulator.c +++ b/drivers/regulator/wm8350-regulator.c | |||
@@ -1269,7 +1269,7 @@ static struct regulator_ops wm8350_isink_ops = { | |||
1269 | .enable_time = wm8350_isink_enable_time, | 1269 | .enable_time = wm8350_isink_enable_time, |
1270 | }; | 1270 | }; |
1271 | 1271 | ||
1272 | static struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | 1272 | static const struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { |
1273 | { | 1273 | { |
1274 | .name = "DCDC1", | 1274 | .name = "DCDC1", |
1275 | .id = WM8350_DCDC_1, | 1275 | .id = WM8350_DCDC_1, |
@@ -1398,6 +1398,7 @@ static irqreturn_t pmic_uv_handler(int irq, void *data) | |||
1398 | static int wm8350_regulator_probe(struct platform_device *pdev) | 1398 | static int wm8350_regulator_probe(struct platform_device *pdev) |
1399 | { | 1399 | { |
1400 | struct wm8350 *wm8350 = dev_get_drvdata(&pdev->dev); | 1400 | struct wm8350 *wm8350 = dev_get_drvdata(&pdev->dev); |
1401 | struct regulator_config config = { }; | ||
1401 | struct regulator_dev *rdev; | 1402 | struct regulator_dev *rdev; |
1402 | int ret; | 1403 | int ret; |
1403 | u16 val; | 1404 | u16 val; |
@@ -1425,10 +1426,12 @@ static int wm8350_regulator_probe(struct platform_device *pdev) | |||
1425 | break; | 1426 | break; |
1426 | } | 1427 | } |
1427 | 1428 | ||
1429 | config.dev = &pdev->dev; | ||
1430 | config.init_data = pdev->dev.platform_data; | ||
1431 | config.driver_data = dev_get_drvdata(&pdev->dev); | ||
1432 | |||
1428 | /* register regulator */ | 1433 | /* register regulator */ |
1429 | rdev = regulator_register(&wm8350_reg[pdev->id], &pdev->dev, | 1434 | rdev = regulator_register(&wm8350_reg[pdev->id], &config); |
1430 | pdev->dev.platform_data, | ||
1431 | dev_get_drvdata(&pdev->dev), NULL); | ||
1432 | if (IS_ERR(rdev)) { | 1435 | if (IS_ERR(rdev)) { |
1433 | dev_err(&pdev->dev, "failed to register %s\n", | 1436 | dev_err(&pdev->dev, "failed to register %s\n", |
1434 | wm8350_reg[pdev->id].name); | 1437 | wm8350_reg[pdev->id].name); |
diff --git a/drivers/regulator/wm8400-regulator.c b/drivers/regulator/wm8400-regulator.c index 8477153780b6..69a2b7ce5e4a 100644 --- a/drivers/regulator/wm8400-regulator.c +++ b/drivers/regulator/wm8400-regulator.c | |||
@@ -19,31 +19,6 @@ | |||
19 | #include <linux/regulator/driver.h> | 19 | #include <linux/regulator/driver.h> |
20 | #include <linux/mfd/wm8400-private.h> | 20 | #include <linux/mfd/wm8400-private.h> |
21 | 21 | ||
22 | static int wm8400_ldo_is_enabled(struct regulator_dev *dev) | ||
23 | { | ||
24 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | ||
25 | u16 val; | ||
26 | |||
27 | val = wm8400_reg_read(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev)); | ||
28 | return (val & WM8400_LDO1_ENA) != 0; | ||
29 | } | ||
30 | |||
31 | static int wm8400_ldo_enable(struct regulator_dev *dev) | ||
32 | { | ||
33 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | ||
34 | |||
35 | return wm8400_set_bits(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev), | ||
36 | WM8400_LDO1_ENA, WM8400_LDO1_ENA); | ||
37 | } | ||
38 | |||
39 | static int wm8400_ldo_disable(struct regulator_dev *dev) | ||
40 | { | ||
41 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | ||
42 | |||
43 | return wm8400_set_bits(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev), | ||
44 | WM8400_LDO1_ENA, 0); | ||
45 | } | ||
46 | |||
47 | static int wm8400_ldo_list_voltage(struct regulator_dev *dev, | 22 | static int wm8400_ldo_list_voltage(struct regulator_dev *dev, |
48 | unsigned selector) | 23 | unsigned selector) |
49 | { | 24 | { |
@@ -56,21 +31,9 @@ static int wm8400_ldo_list_voltage(struct regulator_dev *dev, | |||
56 | return 1600000 + ((selector - 14) * 100000); | 31 | return 1600000 + ((selector - 14) * 100000); |
57 | } | 32 | } |
58 | 33 | ||
59 | static int wm8400_ldo_get_voltage_sel(struct regulator_dev *dev) | 34 | static int wm8400_ldo_map_voltage(struct regulator_dev *dev, |
35 | int min_uV, int max_uV) | ||
60 | { | 36 | { |
61 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | ||
62 | u16 val; | ||
63 | |||
64 | val = wm8400_reg_read(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev)); | ||
65 | val &= WM8400_LDO1_VSEL_MASK; | ||
66 | |||
67 | return val; | ||
68 | } | ||
69 | |||
70 | static int wm8400_ldo_set_voltage(struct regulator_dev *dev, | ||
71 | int min_uV, int max_uV, unsigned *selector) | ||
72 | { | ||
73 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | ||
74 | u16 val; | 37 | u16 val; |
75 | 38 | ||
76 | if (min_uV < 900000 || min_uV > 3300000) | 39 | if (min_uV < 900000 || min_uV > 3300000) |
@@ -94,92 +57,19 @@ static int wm8400_ldo_set_voltage(struct regulator_dev *dev, | |||
94 | val += 0xf; | 57 | val += 0xf; |
95 | } | 58 | } |
96 | 59 | ||
97 | *selector = val; | 60 | return val; |
98 | |||
99 | return wm8400_set_bits(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev), | ||
100 | WM8400_LDO1_VSEL_MASK, val); | ||
101 | } | 61 | } |
102 | 62 | ||
103 | static struct regulator_ops wm8400_ldo_ops = { | 63 | static struct regulator_ops wm8400_ldo_ops = { |
104 | .is_enabled = wm8400_ldo_is_enabled, | 64 | .is_enabled = regulator_is_enabled_regmap, |
105 | .enable = wm8400_ldo_enable, | 65 | .enable = regulator_enable_regmap, |
106 | .disable = wm8400_ldo_disable, | 66 | .disable = regulator_disable_regmap, |
107 | .list_voltage = wm8400_ldo_list_voltage, | 67 | .list_voltage = wm8400_ldo_list_voltage, |
108 | .get_voltage_sel = wm8400_ldo_get_voltage_sel, | 68 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
109 | .set_voltage = wm8400_ldo_set_voltage, | 69 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
70 | .map_voltage = wm8400_ldo_map_voltage, | ||
110 | }; | 71 | }; |
111 | 72 | ||
112 | static int wm8400_dcdc_is_enabled(struct regulator_dev *dev) | ||
113 | { | ||
114 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | ||
115 | int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2; | ||
116 | u16 val; | ||
117 | |||
118 | val = wm8400_reg_read(wm8400, WM8400_DCDC1_CONTROL_1 + offset); | ||
119 | return (val & WM8400_DC1_ENA) != 0; | ||
120 | } | ||
121 | |||
122 | static int wm8400_dcdc_enable(struct regulator_dev *dev) | ||
123 | { | ||
124 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | ||
125 | int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2; | ||
126 | |||
127 | return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset, | ||
128 | WM8400_DC1_ENA, WM8400_DC1_ENA); | ||
129 | } | ||
130 | |||
131 | static int wm8400_dcdc_disable(struct regulator_dev *dev) | ||
132 | { | ||
133 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | ||
134 | int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2; | ||
135 | |||
136 | return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset, | ||
137 | WM8400_DC1_ENA, 0); | ||
138 | } | ||
139 | |||
140 | static int wm8400_dcdc_list_voltage(struct regulator_dev *dev, | ||
141 | unsigned selector) | ||
142 | { | ||
143 | if (selector > WM8400_DC1_VSEL_MASK) | ||
144 | return -EINVAL; | ||
145 | |||
146 | return 850000 + (selector * 25000); | ||
147 | } | ||
148 | |||
149 | static int wm8400_dcdc_get_voltage_sel(struct regulator_dev *dev) | ||
150 | { | ||
151 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | ||
152 | u16 val; | ||
153 | int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2; | ||
154 | |||
155 | val = wm8400_reg_read(wm8400, WM8400_DCDC1_CONTROL_1 + offset); | ||
156 | val &= WM8400_DC1_VSEL_MASK; | ||
157 | |||
158 | return val; | ||
159 | } | ||
160 | |||
161 | static int wm8400_dcdc_set_voltage(struct regulator_dev *dev, | ||
162 | int min_uV, int max_uV, unsigned *selector) | ||
163 | { | ||
164 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | ||
165 | u16 val; | ||
166 | int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2; | ||
167 | |||
168 | if (min_uV < 850000) | ||
169 | return -EINVAL; | ||
170 | |||
171 | val = DIV_ROUND_UP(min_uV - 850000, 25000); | ||
172 | |||
173 | if (850000 + (25000 * val) > max_uV) | ||
174 | return -EINVAL; | ||
175 | BUG_ON(850000 + (25000 * val) < min_uV); | ||
176 | |||
177 | *selector = val; | ||
178 | |||
179 | return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset, | ||
180 | WM8400_DC1_VSEL_MASK, val); | ||
181 | } | ||
182 | |||
183 | static unsigned int wm8400_dcdc_get_mode(struct regulator_dev *dev) | 73 | static unsigned int wm8400_dcdc_get_mode(struct regulator_dev *dev) |
184 | { | 74 | { |
185 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); | 75 | struct wm8400 *wm8400 = rdev_get_drvdata(dev); |
@@ -258,12 +148,12 @@ static unsigned int wm8400_dcdc_get_optimum_mode(struct regulator_dev *dev, | |||
258 | } | 148 | } |
259 | 149 | ||
260 | static struct regulator_ops wm8400_dcdc_ops = { | 150 | static struct regulator_ops wm8400_dcdc_ops = { |
261 | .is_enabled = wm8400_dcdc_is_enabled, | 151 | .is_enabled = regulator_is_enabled_regmap, |
262 | .enable = wm8400_dcdc_enable, | 152 | .enable = regulator_enable_regmap, |
263 | .disable = wm8400_dcdc_disable, | 153 | .disable = regulator_disable_regmap, |
264 | .list_voltage = wm8400_dcdc_list_voltage, | 154 | .list_voltage = regulator_list_voltage_linear, |
265 | .get_voltage_sel = wm8400_dcdc_get_voltage_sel, | 155 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
266 | .set_voltage = wm8400_dcdc_set_voltage, | 156 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
267 | .get_mode = wm8400_dcdc_get_mode, | 157 | .get_mode = wm8400_dcdc_get_mode, |
268 | .set_mode = wm8400_dcdc_set_mode, | 158 | .set_mode = wm8400_dcdc_set_mode, |
269 | .get_optimum_mode = wm8400_dcdc_get_optimum_mode, | 159 | .get_optimum_mode = wm8400_dcdc_get_optimum_mode, |
@@ -274,7 +164,11 @@ static struct regulator_desc regulators[] = { | |||
274 | .name = "LDO1", | 164 | .name = "LDO1", |
275 | .id = WM8400_LDO1, | 165 | .id = WM8400_LDO1, |
276 | .ops = &wm8400_ldo_ops, | 166 | .ops = &wm8400_ldo_ops, |
167 | .enable_reg = WM8400_LDO1_CONTROL, | ||
168 | .enable_mask = WM8400_LDO1_ENA, | ||
277 | .n_voltages = WM8400_LDO1_VSEL_MASK + 1, | 169 | .n_voltages = WM8400_LDO1_VSEL_MASK + 1, |
170 | .vsel_reg = WM8400_LDO1_CONTROL, | ||
171 | .vsel_mask = WM8400_LDO1_VSEL_MASK, | ||
278 | .type = REGULATOR_VOLTAGE, | 172 | .type = REGULATOR_VOLTAGE, |
279 | .owner = THIS_MODULE, | 173 | .owner = THIS_MODULE, |
280 | }, | 174 | }, |
@@ -282,15 +176,23 @@ static struct regulator_desc regulators[] = { | |||
282 | .name = "LDO2", | 176 | .name = "LDO2", |
283 | .id = WM8400_LDO2, | 177 | .id = WM8400_LDO2, |
284 | .ops = &wm8400_ldo_ops, | 178 | .ops = &wm8400_ldo_ops, |
179 | .enable_reg = WM8400_LDO2_CONTROL, | ||
180 | .enable_mask = WM8400_LDO2_ENA, | ||
285 | .n_voltages = WM8400_LDO2_VSEL_MASK + 1, | 181 | .n_voltages = WM8400_LDO2_VSEL_MASK + 1, |
286 | .type = REGULATOR_VOLTAGE, | 182 | .type = REGULATOR_VOLTAGE, |
183 | .vsel_reg = WM8400_LDO2_CONTROL, | ||
184 | .vsel_mask = WM8400_LDO2_VSEL_MASK, | ||
287 | .owner = THIS_MODULE, | 185 | .owner = THIS_MODULE, |
288 | }, | 186 | }, |
289 | { | 187 | { |
290 | .name = "LDO3", | 188 | .name = "LDO3", |
291 | .id = WM8400_LDO3, | 189 | .id = WM8400_LDO3, |
292 | .ops = &wm8400_ldo_ops, | 190 | .ops = &wm8400_ldo_ops, |
191 | .enable_reg = WM8400_LDO3_CONTROL, | ||
192 | .enable_mask = WM8400_LDO3_ENA, | ||
293 | .n_voltages = WM8400_LDO3_VSEL_MASK + 1, | 193 | .n_voltages = WM8400_LDO3_VSEL_MASK + 1, |
194 | .vsel_reg = WM8400_LDO3_CONTROL, | ||
195 | .vsel_mask = WM8400_LDO3_VSEL_MASK, | ||
294 | .type = REGULATOR_VOLTAGE, | 196 | .type = REGULATOR_VOLTAGE, |
295 | .owner = THIS_MODULE, | 197 | .owner = THIS_MODULE, |
296 | }, | 198 | }, |
@@ -298,7 +200,11 @@ static struct regulator_desc regulators[] = { | |||
298 | .name = "LDO4", | 200 | .name = "LDO4", |
299 | .id = WM8400_LDO4, | 201 | .id = WM8400_LDO4, |
300 | .ops = &wm8400_ldo_ops, | 202 | .ops = &wm8400_ldo_ops, |
203 | .enable_reg = WM8400_LDO4_CONTROL, | ||
204 | .enable_mask = WM8400_LDO4_ENA, | ||
301 | .n_voltages = WM8400_LDO4_VSEL_MASK + 1, | 205 | .n_voltages = WM8400_LDO4_VSEL_MASK + 1, |
206 | .vsel_reg = WM8400_LDO4_CONTROL, | ||
207 | .vsel_mask = WM8400_LDO4_VSEL_MASK, | ||
302 | .type = REGULATOR_VOLTAGE, | 208 | .type = REGULATOR_VOLTAGE, |
303 | .owner = THIS_MODULE, | 209 | .owner = THIS_MODULE, |
304 | }, | 210 | }, |
@@ -306,7 +212,13 @@ static struct regulator_desc regulators[] = { | |||
306 | .name = "DCDC1", | 212 | .name = "DCDC1", |
307 | .id = WM8400_DCDC1, | 213 | .id = WM8400_DCDC1, |
308 | .ops = &wm8400_dcdc_ops, | 214 | .ops = &wm8400_dcdc_ops, |
215 | .enable_reg = WM8400_DCDC1_CONTROL_1, | ||
216 | .enable_mask = WM8400_DC1_ENA_MASK, | ||
309 | .n_voltages = WM8400_DC1_VSEL_MASK + 1, | 217 | .n_voltages = WM8400_DC1_VSEL_MASK + 1, |
218 | .vsel_reg = WM8400_DCDC1_CONTROL_1, | ||
219 | .vsel_mask = WM8400_DC1_VSEL_MASK, | ||
220 | .min_uV = 850000, | ||
221 | .uV_step = 25000, | ||
310 | .type = REGULATOR_VOLTAGE, | 222 | .type = REGULATOR_VOLTAGE, |
311 | .owner = THIS_MODULE, | 223 | .owner = THIS_MODULE, |
312 | }, | 224 | }, |
@@ -314,7 +226,13 @@ static struct regulator_desc regulators[] = { | |||
314 | .name = "DCDC2", | 226 | .name = "DCDC2", |
315 | .id = WM8400_DCDC2, | 227 | .id = WM8400_DCDC2, |
316 | .ops = &wm8400_dcdc_ops, | 228 | .ops = &wm8400_dcdc_ops, |
229 | .enable_reg = WM8400_DCDC2_CONTROL_1, | ||
230 | .enable_mask = WM8400_DC1_ENA_MASK, | ||
317 | .n_voltages = WM8400_DC2_VSEL_MASK + 1, | 231 | .n_voltages = WM8400_DC2_VSEL_MASK + 1, |
232 | .vsel_reg = WM8400_DCDC2_CONTROL_1, | ||
233 | .vsel_mask = WM8400_DC2_VSEL_MASK, | ||
234 | .min_uV = 850000, | ||
235 | .uV_step = 25000, | ||
318 | .type = REGULATOR_VOLTAGE, | 236 | .type = REGULATOR_VOLTAGE, |
319 | .owner = THIS_MODULE, | 237 | .owner = THIS_MODULE, |
320 | }, | 238 | }, |
@@ -323,11 +241,15 @@ static struct regulator_desc regulators[] = { | |||
323 | static int __devinit wm8400_regulator_probe(struct platform_device *pdev) | 241 | static int __devinit wm8400_regulator_probe(struct platform_device *pdev) |
324 | { | 242 | { |
325 | struct wm8400 *wm8400 = container_of(pdev, struct wm8400, regulators[pdev->id]); | 243 | struct wm8400 *wm8400 = container_of(pdev, struct wm8400, regulators[pdev->id]); |
244 | struct regulator_config config = { }; | ||
326 | struct regulator_dev *rdev; | 245 | struct regulator_dev *rdev; |
327 | 246 | ||
328 | rdev = regulator_register(®ulators[pdev->id], &pdev->dev, | 247 | config.dev = &pdev->dev; |
329 | pdev->dev.platform_data, wm8400, NULL); | 248 | config.init_data = pdev->dev.platform_data; |
249 | config.driver_data = wm8400; | ||
250 | config.regmap = wm8400->regmap; | ||
330 | 251 | ||
252 | rdev = regulator_register(®ulators[pdev->id], &config); | ||
331 | if (IS_ERR(rdev)) | 253 | if (IS_ERR(rdev)) |
332 | return PTR_ERR(rdev); | 254 | return PTR_ERR(rdev); |
333 | 255 | ||
diff --git a/drivers/regulator/wm8994-regulator.c b/drivers/regulator/wm8994-regulator.c index 75ed402d9f43..9a994316e63c 100644 --- a/drivers/regulator/wm8994-regulator.c +++ b/drivers/regulator/wm8994-regulator.c | |||
@@ -86,36 +86,6 @@ static int wm8994_ldo1_list_voltage(struct regulator_dev *rdev, | |||
86 | return (selector * 100000) + 2400000; | 86 | return (selector * 100000) + 2400000; |
87 | } | 87 | } |
88 | 88 | ||
89 | static int wm8994_ldo1_get_voltage_sel(struct regulator_dev *rdev) | ||
90 | { | ||
91 | struct wm8994_ldo *ldo = rdev_get_drvdata(rdev); | ||
92 | int val; | ||
93 | |||
94 | val = wm8994_reg_read(ldo->wm8994, WM8994_LDO_1); | ||
95 | if (val < 0) | ||
96 | return val; | ||
97 | |||
98 | return (val & WM8994_LDO1_VSEL_MASK) >> WM8994_LDO1_VSEL_SHIFT; | ||
99 | } | ||
100 | |||
101 | static int wm8994_ldo1_set_voltage(struct regulator_dev *rdev, | ||
102 | int min_uV, int max_uV, unsigned *s) | ||
103 | { | ||
104 | struct wm8994_ldo *ldo = rdev_get_drvdata(rdev); | ||
105 | int selector, v; | ||
106 | |||
107 | selector = (min_uV - 2400000) / 100000; | ||
108 | v = wm8994_ldo1_list_voltage(rdev, selector); | ||
109 | if (v < 0 || v > max_uV) | ||
110 | return -EINVAL; | ||
111 | |||
112 | *s = selector; | ||
113 | selector <<= WM8994_LDO1_VSEL_SHIFT; | ||
114 | |||
115 | return wm8994_set_bits(ldo->wm8994, WM8994_LDO_1, | ||
116 | WM8994_LDO1_VSEL_MASK, selector); | ||
117 | } | ||
118 | |||
119 | static struct regulator_ops wm8994_ldo1_ops = { | 89 | static struct regulator_ops wm8994_ldo1_ops = { |
120 | .enable = wm8994_ldo_enable, | 90 | .enable = wm8994_ldo_enable, |
121 | .disable = wm8994_ldo_disable, | 91 | .disable = wm8994_ldo_disable, |
@@ -123,8 +93,8 @@ static struct regulator_ops wm8994_ldo1_ops = { | |||
123 | .enable_time = wm8994_ldo_enable_time, | 93 | .enable_time = wm8994_ldo_enable_time, |
124 | 94 | ||
125 | .list_voltage = wm8994_ldo1_list_voltage, | 95 | .list_voltage = wm8994_ldo1_list_voltage, |
126 | .get_voltage_sel = wm8994_ldo1_get_voltage_sel, | 96 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
127 | .set_voltage = wm8994_ldo1_set_voltage, | 97 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
128 | }; | 98 | }; |
129 | 99 | ||
130 | static int wm8994_ldo2_list_voltage(struct regulator_dev *rdev, | 100 | static int wm8994_ldo2_list_voltage(struct regulator_dev *rdev, |
@@ -153,51 +123,6 @@ static int wm8994_ldo2_list_voltage(struct regulator_dev *rdev, | |||
153 | } | 123 | } |
154 | } | 124 | } |
155 | 125 | ||
156 | static int wm8994_ldo2_get_voltage_sel(struct regulator_dev *rdev) | ||
157 | { | ||
158 | struct wm8994_ldo *ldo = rdev_get_drvdata(rdev); | ||
159 | int val; | ||
160 | |||
161 | val = wm8994_reg_read(ldo->wm8994, WM8994_LDO_2); | ||
162 | if (val < 0) | ||
163 | return val; | ||
164 | |||
165 | return (val & WM8994_LDO2_VSEL_MASK) >> WM8994_LDO2_VSEL_SHIFT; | ||
166 | } | ||
167 | |||
168 | static int wm8994_ldo2_set_voltage(struct regulator_dev *rdev, | ||
169 | int min_uV, int max_uV, unsigned *s) | ||
170 | { | ||
171 | struct wm8994_ldo *ldo = rdev_get_drvdata(rdev); | ||
172 | int selector, v; | ||
173 | |||
174 | switch (ldo->wm8994->type) { | ||
175 | case WM8994: | ||
176 | selector = (min_uV - 900000) / 100000; | ||
177 | break; | ||
178 | case WM8958: | ||
179 | selector = (min_uV - 1000000) / 100000; | ||
180 | break; | ||
181 | case WM1811: | ||
182 | selector = (min_uV - 950000) / 100000; | ||
183 | if (selector == 0) | ||
184 | selector = 1; | ||
185 | break; | ||
186 | default: | ||
187 | return -EINVAL; | ||
188 | } | ||
189 | |||
190 | v = wm8994_ldo2_list_voltage(rdev, selector); | ||
191 | if (v < 0 || v > max_uV) | ||
192 | return -EINVAL; | ||
193 | |||
194 | *s = selector; | ||
195 | selector <<= WM8994_LDO2_VSEL_SHIFT; | ||
196 | |||
197 | return wm8994_set_bits(ldo->wm8994, WM8994_LDO_2, | ||
198 | WM8994_LDO2_VSEL_MASK, selector); | ||
199 | } | ||
200 | |||
201 | static struct regulator_ops wm8994_ldo2_ops = { | 126 | static struct regulator_ops wm8994_ldo2_ops = { |
202 | .enable = wm8994_ldo_enable, | 127 | .enable = wm8994_ldo_enable, |
203 | .disable = wm8994_ldo_disable, | 128 | .disable = wm8994_ldo_disable, |
@@ -205,16 +130,18 @@ static struct regulator_ops wm8994_ldo2_ops = { | |||
205 | .enable_time = wm8994_ldo_enable_time, | 130 | .enable_time = wm8994_ldo_enable_time, |
206 | 131 | ||
207 | .list_voltage = wm8994_ldo2_list_voltage, | 132 | .list_voltage = wm8994_ldo2_list_voltage, |
208 | .get_voltage_sel = wm8994_ldo2_get_voltage_sel, | 133 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
209 | .set_voltage = wm8994_ldo2_set_voltage, | 134 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
210 | }; | 135 | }; |
211 | 136 | ||
212 | static struct regulator_desc wm8994_ldo_desc[] = { | 137 | static const struct regulator_desc wm8994_ldo_desc[] = { |
213 | { | 138 | { |
214 | .name = "LDO1", | 139 | .name = "LDO1", |
215 | .id = 1, | 140 | .id = 1, |
216 | .type = REGULATOR_VOLTAGE, | 141 | .type = REGULATOR_VOLTAGE, |
217 | .n_voltages = WM8994_LDO1_MAX_SELECTOR + 1, | 142 | .n_voltages = WM8994_LDO1_MAX_SELECTOR + 1, |
143 | .vsel_reg = WM8994_LDO_1, | ||
144 | .vsel_mask = WM8994_LDO1_VSEL_MASK, | ||
218 | .ops = &wm8994_ldo1_ops, | 145 | .ops = &wm8994_ldo1_ops, |
219 | .owner = THIS_MODULE, | 146 | .owner = THIS_MODULE, |
220 | }, | 147 | }, |
@@ -223,6 +150,8 @@ static struct regulator_desc wm8994_ldo_desc[] = { | |||
223 | .id = 2, | 150 | .id = 2, |
224 | .type = REGULATOR_VOLTAGE, | 151 | .type = REGULATOR_VOLTAGE, |
225 | .n_voltages = WM8994_LDO2_MAX_SELECTOR + 1, | 152 | .n_voltages = WM8994_LDO2_MAX_SELECTOR + 1, |
153 | .vsel_reg = WM8994_LDO_2, | ||
154 | .vsel_mask = WM8994_LDO2_VSEL_MASK, | ||
226 | .ops = &wm8994_ldo2_ops, | 155 | .ops = &wm8994_ldo2_ops, |
227 | .owner = THIS_MODULE, | 156 | .owner = THIS_MODULE, |
228 | }, | 157 | }, |
@@ -233,14 +162,12 @@ static __devinit int wm8994_ldo_probe(struct platform_device *pdev) | |||
233 | struct wm8994 *wm8994 = dev_get_drvdata(pdev->dev.parent); | 162 | struct wm8994 *wm8994 = dev_get_drvdata(pdev->dev.parent); |
234 | struct wm8994_pdata *pdata = wm8994->dev->platform_data; | 163 | struct wm8994_pdata *pdata = wm8994->dev->platform_data; |
235 | int id = pdev->id % ARRAY_SIZE(pdata->ldo); | 164 | int id = pdev->id % ARRAY_SIZE(pdata->ldo); |
165 | struct regulator_config config = { }; | ||
236 | struct wm8994_ldo *ldo; | 166 | struct wm8994_ldo *ldo; |
237 | int ret; | 167 | int ret; |
238 | 168 | ||
239 | dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1); | 169 | dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1); |
240 | 170 | ||
241 | if (!pdata) | ||
242 | return -ENODEV; | ||
243 | |||
244 | ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm8994_ldo), GFP_KERNEL); | 171 | ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm8994_ldo), GFP_KERNEL); |
245 | if (ldo == NULL) { | 172 | if (ldo == NULL) { |
246 | dev_err(&pdev->dev, "Unable to allocate private data\n"); | 173 | dev_err(&pdev->dev, "Unable to allocate private data\n"); |
@@ -252,24 +179,22 @@ static __devinit int wm8994_ldo_probe(struct platform_device *pdev) | |||
252 | if (pdata->ldo[id].enable && gpio_is_valid(pdata->ldo[id].enable)) { | 179 | if (pdata->ldo[id].enable && gpio_is_valid(pdata->ldo[id].enable)) { |
253 | ldo->enable = pdata->ldo[id].enable; | 180 | ldo->enable = pdata->ldo[id].enable; |
254 | 181 | ||
255 | ret = gpio_request(ldo->enable, "WM8994 LDO enable"); | 182 | ret = gpio_request_one(ldo->enable, 0, "WM8994 LDO enable"); |
256 | if (ret < 0) { | 183 | if (ret < 0) { |
257 | dev_err(&pdev->dev, "Failed to get enable GPIO: %d\n", | 184 | dev_err(&pdev->dev, "Failed to get enable GPIO: %d\n", |
258 | ret); | 185 | ret); |
259 | goto err; | 186 | goto err; |
260 | } | 187 | } |
261 | |||
262 | ret = gpio_direction_output(ldo->enable, ldo->is_enabled); | ||
263 | if (ret < 0) { | ||
264 | dev_err(&pdev->dev, "Failed to set GPIO up: %d\n", | ||
265 | ret); | ||
266 | goto err_gpio; | ||
267 | } | ||
268 | } else | 188 | } else |
269 | ldo->is_enabled = true; | 189 | ldo->is_enabled = true; |
270 | 190 | ||
271 | ldo->regulator = regulator_register(&wm8994_ldo_desc[id], &pdev->dev, | 191 | config.dev = wm8994->dev; |
272 | pdata->ldo[id].init_data, ldo, NULL); | 192 | config.driver_data = ldo; |
193 | config.regmap = wm8994->regmap; | ||
194 | if (pdata) | ||
195 | config.init_data = pdata->ldo[id].init_data; | ||
196 | |||
197 | ldo->regulator = regulator_register(&wm8994_ldo_desc[id], &config); | ||
273 | if (IS_ERR(ldo->regulator)) { | 198 | if (IS_ERR(ldo->regulator)) { |
274 | ret = PTR_ERR(ldo->regulator); | 199 | ret = PTR_ERR(ldo->regulator); |
275 | dev_err(wm8994->dev, "Failed to register LDO%d: %d\n", | 200 | dev_err(wm8994->dev, "Failed to register LDO%d: %d\n", |