aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator
diff options
context:
space:
mode:
authorDavid Vrabel <david.vrabel@csr.com>2009-01-22 14:12:32 -0500
committerDavid Vrabel <david.vrabel@csr.com>2009-01-22 14:12:32 -0500
commitdff243f7cb3a2ebbb09093066c1bc4a90ff5b3a4 (patch)
tree1c63e7c2f879cd322ca785671b74b4ff796dd24c /drivers/regulator
parenta5e6ced58d423cb09c4fc0087dcfdb0b5deb5e1c (diff)
parentf3b8436ad9a8ad36b3c9fa1fe030c7f38e5d3d0b (diff)
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6 into for-upstream
Diffstat (limited to 'drivers/regulator')
-rw-r--r--drivers/regulator/Kconfig7
-rw-r--r--drivers/regulator/Makefile1
-rw-r--r--drivers/regulator/core.c474
-rw-r--r--drivers/regulator/da903x.c12
-rw-r--r--drivers/regulator/pcf50633-regulator.c329
-rw-r--r--drivers/regulator/wm8350-regulator.c91
-rw-r--r--drivers/regulator/wm8400-regulator.c2
7 files changed, 726 insertions, 190 deletions
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 39360e2a4540..e7e0cf102d6d 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -73,4 +73,11 @@ config REGULATOR_DA903X
73 Say y here to support the BUCKs and LDOs regulators found on 73 Say y here to support the BUCKs and LDOs regulators found on
74 Dialog Semiconductor DA9030/DA9034 PMIC. 74 Dialog Semiconductor DA9030/DA9034 PMIC.
75 75
76config REGULATOR_PCF50633
77 tristate "PCF50633 regulator driver"
78 depends on MFD_PCF50633
79 help
80 Say Y here to support the voltage regulators and convertors
81 on PCF50633
82
76endif 83endif
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 254d40c02ee8..61b30c6ddecc 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -11,5 +11,6 @@ obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o
11obj-$(CONFIG_REGULATOR_WM8350) += wm8350-regulator.o 11obj-$(CONFIG_REGULATOR_WM8350) += wm8350-regulator.o
12obj-$(CONFIG_REGULATOR_WM8400) += wm8400-regulator.o 12obj-$(CONFIG_REGULATOR_WM8400) += wm8400-regulator.o
13obj-$(CONFIG_REGULATOR_DA903X) += da903x.o 13obj-$(CONFIG_REGULATOR_DA903X) += da903x.o
14obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o
14 15
15ccflags-$(CONFIG_REGULATOR_DEBUG) += -DDEBUG 16ccflags-$(CONFIG_REGULATOR_DEBUG) += -DDEBUG
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 02a774424e8d..f511a406fcaa 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -29,7 +29,7 @@ static DEFINE_MUTEX(regulator_list_mutex);
29static LIST_HEAD(regulator_list); 29static LIST_HEAD(regulator_list);
30static LIST_HEAD(regulator_map_list); 30static LIST_HEAD(regulator_map_list);
31 31
32/** 32/*
33 * struct regulator_dev 33 * struct regulator_dev
34 * 34 *
35 * Voltage / Current regulator class device. One for each regulator. 35 * Voltage / Current regulator class device. One for each regulator.
@@ -56,7 +56,7 @@ struct regulator_dev {
56 void *reg_data; /* regulator_dev data */ 56 void *reg_data; /* regulator_dev data */
57}; 57};
58 58
59/** 59/*
60 * struct regulator_map 60 * struct regulator_map
61 * 61 *
62 * Used to provide symbolic supply names to devices. 62 * Used to provide symbolic supply names to devices.
@@ -79,7 +79,7 @@ struct regulator {
79 int uA_load; 79 int uA_load;
80 int min_uV; 80 int min_uV;
81 int max_uV; 81 int max_uV;
82 int enabled; /* client has called enabled */ 82 int enabled; /* count of client enables */
83 char *supply_name; 83 char *supply_name;
84 struct device_attribute dev_attr; 84 struct device_attribute dev_attr;
85 struct regulator_dev *rdev; 85 struct regulator_dev *rdev;
@@ -174,6 +174,16 @@ static int regulator_check_current_limit(struct regulator_dev *rdev,
174/* operating mode constraint check */ 174/* operating mode constraint check */
175static int regulator_check_mode(struct regulator_dev *rdev, int mode) 175static int regulator_check_mode(struct regulator_dev *rdev, int mode)
176{ 176{
177 switch (mode) {
178 case REGULATOR_MODE_FAST:
179 case REGULATOR_MODE_NORMAL:
180 case REGULATOR_MODE_IDLE:
181 case REGULATOR_MODE_STANDBY:
182 break;
183 default:
184 return -EINVAL;
185 }
186
177 if (!rdev->constraints) { 187 if (!rdev->constraints) {
178 printk(KERN_ERR "%s: no constraints for %s\n", __func__, 188 printk(KERN_ERR "%s: no constraints for %s\n", __func__,
179 rdev->desc->name); 189 rdev->desc->name);
@@ -232,6 +242,7 @@ static ssize_t regulator_uV_show(struct device *dev,
232 242
233 return ret; 243 return ret;
234} 244}
245static DEVICE_ATTR(microvolts, 0444, regulator_uV_show, NULL);
235 246
236static ssize_t regulator_uA_show(struct device *dev, 247static ssize_t regulator_uA_show(struct device *dev,
237 struct device_attribute *attr, char *buf) 248 struct device_attribute *attr, char *buf)
@@ -240,6 +251,7 @@ static ssize_t regulator_uA_show(struct device *dev,
240 251
241 return sprintf(buf, "%d\n", _regulator_get_current_limit(rdev)); 252 return sprintf(buf, "%d\n", _regulator_get_current_limit(rdev));
242} 253}
254static DEVICE_ATTR(microamps, 0444, regulator_uA_show, NULL);
243 255
244static ssize_t regulator_name_show(struct device *dev, 256static ssize_t regulator_name_show(struct device *dev,
245 struct device_attribute *attr, char *buf) 257 struct device_attribute *attr, char *buf)
@@ -257,12 +269,8 @@ static ssize_t regulator_name_show(struct device *dev,
257 return sprintf(buf, "%s\n", name); 269 return sprintf(buf, "%s\n", name);
258} 270}
259 271
260static ssize_t regulator_opmode_show(struct device *dev, 272static ssize_t regulator_print_opmode(char *buf, int mode)
261 struct device_attribute *attr, char *buf)
262{ 273{
263 struct regulator_dev *rdev = dev_get_drvdata(dev);
264 int mode = _regulator_get_mode(rdev);
265
266 switch (mode) { 274 switch (mode) {
267 case REGULATOR_MODE_FAST: 275 case REGULATOR_MODE_FAST:
268 return sprintf(buf, "fast\n"); 276 return sprintf(buf, "fast\n");
@@ -276,12 +284,17 @@ static ssize_t regulator_opmode_show(struct device *dev,
276 return sprintf(buf, "unknown\n"); 284 return sprintf(buf, "unknown\n");
277} 285}
278 286
279static ssize_t regulator_state_show(struct device *dev, 287static ssize_t regulator_opmode_show(struct device *dev,
280 struct device_attribute *attr, char *buf) 288 struct device_attribute *attr, char *buf)
281{ 289{
282 struct regulator_dev *rdev = dev_get_drvdata(dev); 290 struct regulator_dev *rdev = dev_get_drvdata(dev);
283 int state = _regulator_is_enabled(rdev);
284 291
292 return regulator_print_opmode(buf, _regulator_get_mode(rdev));
293}
294static DEVICE_ATTR(opmode, 0444, regulator_opmode_show, NULL);
295
296static ssize_t regulator_print_state(char *buf, int state)
297{
285 if (state > 0) 298 if (state > 0)
286 return sprintf(buf, "enabled\n"); 299 return sprintf(buf, "enabled\n");
287 else if (state == 0) 300 else if (state == 0)
@@ -290,6 +303,15 @@ static ssize_t regulator_state_show(struct device *dev,
290 return sprintf(buf, "unknown\n"); 303 return sprintf(buf, "unknown\n");
291} 304}
292 305
306static ssize_t regulator_state_show(struct device *dev,
307 struct device_attribute *attr, char *buf)
308{
309 struct regulator_dev *rdev = dev_get_drvdata(dev);
310
311 return regulator_print_state(buf, _regulator_is_enabled(rdev));
312}
313static DEVICE_ATTR(state, 0444, regulator_state_show, NULL);
314
293static ssize_t regulator_min_uA_show(struct device *dev, 315static ssize_t regulator_min_uA_show(struct device *dev,
294 struct device_attribute *attr, char *buf) 316 struct device_attribute *attr, char *buf)
295{ 317{
@@ -300,6 +322,7 @@ static ssize_t regulator_min_uA_show(struct device *dev,
300 322
301 return sprintf(buf, "%d\n", rdev->constraints->min_uA); 323 return sprintf(buf, "%d\n", rdev->constraints->min_uA);
302} 324}
325static DEVICE_ATTR(min_microamps, 0444, regulator_min_uA_show, NULL);
303 326
304static ssize_t regulator_max_uA_show(struct device *dev, 327static ssize_t regulator_max_uA_show(struct device *dev,
305 struct device_attribute *attr, char *buf) 328 struct device_attribute *attr, char *buf)
@@ -311,6 +334,7 @@ static ssize_t regulator_max_uA_show(struct device *dev,
311 334
312 return sprintf(buf, "%d\n", rdev->constraints->max_uA); 335 return sprintf(buf, "%d\n", rdev->constraints->max_uA);
313} 336}
337static DEVICE_ATTR(max_microamps, 0444, regulator_max_uA_show, NULL);
314 338
315static ssize_t regulator_min_uV_show(struct device *dev, 339static ssize_t regulator_min_uV_show(struct device *dev,
316 struct device_attribute *attr, char *buf) 340 struct device_attribute *attr, char *buf)
@@ -322,6 +346,7 @@ static ssize_t regulator_min_uV_show(struct device *dev,
322 346
323 return sprintf(buf, "%d\n", rdev->constraints->min_uV); 347 return sprintf(buf, "%d\n", rdev->constraints->min_uV);
324} 348}
349static DEVICE_ATTR(min_microvolts, 0444, regulator_min_uV_show, NULL);
325 350
326static ssize_t regulator_max_uV_show(struct device *dev, 351static ssize_t regulator_max_uV_show(struct device *dev,
327 struct device_attribute *attr, char *buf) 352 struct device_attribute *attr, char *buf)
@@ -333,6 +358,7 @@ static ssize_t regulator_max_uV_show(struct device *dev,
333 358
334 return sprintf(buf, "%d\n", rdev->constraints->max_uV); 359 return sprintf(buf, "%d\n", rdev->constraints->max_uV);
335} 360}
361static DEVICE_ATTR(max_microvolts, 0444, regulator_max_uV_show, NULL);
336 362
337static ssize_t regulator_total_uA_show(struct device *dev, 363static ssize_t regulator_total_uA_show(struct device *dev,
338 struct device_attribute *attr, char *buf) 364 struct device_attribute *attr, char *buf)
@@ -347,6 +373,7 @@ static ssize_t regulator_total_uA_show(struct device *dev,
347 mutex_unlock(&rdev->mutex); 373 mutex_unlock(&rdev->mutex);
348 return sprintf(buf, "%d\n", uA); 374 return sprintf(buf, "%d\n", uA);
349} 375}
376static DEVICE_ATTR(requested_microamps, 0444, regulator_total_uA_show, NULL);
350 377
351static ssize_t regulator_num_users_show(struct device *dev, 378static ssize_t regulator_num_users_show(struct device *dev,
352 struct device_attribute *attr, char *buf) 379 struct device_attribute *attr, char *buf)
@@ -374,153 +401,106 @@ static ssize_t regulator_suspend_mem_uV_show(struct device *dev,
374{ 401{
375 struct regulator_dev *rdev = dev_get_drvdata(dev); 402 struct regulator_dev *rdev = dev_get_drvdata(dev);
376 403
377 if (!rdev->constraints)
378 return sprintf(buf, "not defined\n");
379 return sprintf(buf, "%d\n", rdev->constraints->state_mem.uV); 404 return sprintf(buf, "%d\n", rdev->constraints->state_mem.uV);
380} 405}
406static DEVICE_ATTR(suspend_mem_microvolts, 0444,
407 regulator_suspend_mem_uV_show, NULL);
381 408
382static ssize_t regulator_suspend_disk_uV_show(struct device *dev, 409static ssize_t regulator_suspend_disk_uV_show(struct device *dev,
383 struct device_attribute *attr, char *buf) 410 struct device_attribute *attr, char *buf)
384{ 411{
385 struct regulator_dev *rdev = dev_get_drvdata(dev); 412 struct regulator_dev *rdev = dev_get_drvdata(dev);
386 413
387 if (!rdev->constraints)
388 return sprintf(buf, "not defined\n");
389 return sprintf(buf, "%d\n", rdev->constraints->state_disk.uV); 414 return sprintf(buf, "%d\n", rdev->constraints->state_disk.uV);
390} 415}
416static DEVICE_ATTR(suspend_disk_microvolts, 0444,
417 regulator_suspend_disk_uV_show, NULL);
391 418
392static ssize_t regulator_suspend_standby_uV_show(struct device *dev, 419static ssize_t regulator_suspend_standby_uV_show(struct device *dev,
393 struct device_attribute *attr, char *buf) 420 struct device_attribute *attr, char *buf)
394{ 421{
395 struct regulator_dev *rdev = dev_get_drvdata(dev); 422 struct regulator_dev *rdev = dev_get_drvdata(dev);
396 423
397 if (!rdev->constraints)
398 return sprintf(buf, "not defined\n");
399 return sprintf(buf, "%d\n", rdev->constraints->state_standby.uV); 424 return sprintf(buf, "%d\n", rdev->constraints->state_standby.uV);
400} 425}
401 426static DEVICE_ATTR(suspend_standby_microvolts, 0444,
402static ssize_t suspend_opmode_show(struct regulator_dev *rdev, 427 regulator_suspend_standby_uV_show, NULL);
403 unsigned int mode, char *buf)
404{
405 switch (mode) {
406 case REGULATOR_MODE_FAST:
407 return sprintf(buf, "fast\n");
408 case REGULATOR_MODE_NORMAL:
409 return sprintf(buf, "normal\n");
410 case REGULATOR_MODE_IDLE:
411 return sprintf(buf, "idle\n");
412 case REGULATOR_MODE_STANDBY:
413 return sprintf(buf, "standby\n");
414 }
415 return sprintf(buf, "unknown\n");
416}
417 428
418static ssize_t regulator_suspend_mem_mode_show(struct device *dev, 429static ssize_t regulator_suspend_mem_mode_show(struct device *dev,
419 struct device_attribute *attr, char *buf) 430 struct device_attribute *attr, char *buf)
420{ 431{
421 struct regulator_dev *rdev = dev_get_drvdata(dev); 432 struct regulator_dev *rdev = dev_get_drvdata(dev);
422 433
423 if (!rdev->constraints) 434 return regulator_print_opmode(buf,
424 return sprintf(buf, "not defined\n"); 435 rdev->constraints->state_mem.mode);
425 return suspend_opmode_show(rdev,
426 rdev->constraints->state_mem.mode, buf);
427} 436}
437static DEVICE_ATTR(suspend_mem_mode, 0444,
438 regulator_suspend_mem_mode_show, NULL);
428 439
429static ssize_t regulator_suspend_disk_mode_show(struct device *dev, 440static ssize_t regulator_suspend_disk_mode_show(struct device *dev,
430 struct device_attribute *attr, char *buf) 441 struct device_attribute *attr, char *buf)
431{ 442{
432 struct regulator_dev *rdev = dev_get_drvdata(dev); 443 struct regulator_dev *rdev = dev_get_drvdata(dev);
433 444
434 if (!rdev->constraints) 445 return regulator_print_opmode(buf,
435 return sprintf(buf, "not defined\n"); 446 rdev->constraints->state_disk.mode);
436 return suspend_opmode_show(rdev,
437 rdev->constraints->state_disk.mode, buf);
438} 447}
448static DEVICE_ATTR(suspend_disk_mode, 0444,
449 regulator_suspend_disk_mode_show, NULL);
439 450
440static ssize_t regulator_suspend_standby_mode_show(struct device *dev, 451static ssize_t regulator_suspend_standby_mode_show(struct device *dev,
441 struct device_attribute *attr, char *buf) 452 struct device_attribute *attr, char *buf)
442{ 453{
443 struct regulator_dev *rdev = dev_get_drvdata(dev); 454 struct regulator_dev *rdev = dev_get_drvdata(dev);
444 455
445 if (!rdev->constraints) 456 return regulator_print_opmode(buf,
446 return sprintf(buf, "not defined\n"); 457 rdev->constraints->state_standby.mode);
447 return suspend_opmode_show(rdev,
448 rdev->constraints->state_standby.mode, buf);
449} 458}
459static DEVICE_ATTR(suspend_standby_mode, 0444,
460 regulator_suspend_standby_mode_show, NULL);
450 461
451static ssize_t regulator_suspend_mem_state_show(struct device *dev, 462static ssize_t regulator_suspend_mem_state_show(struct device *dev,
452 struct device_attribute *attr, char *buf) 463 struct device_attribute *attr, char *buf)
453{ 464{
454 struct regulator_dev *rdev = dev_get_drvdata(dev); 465 struct regulator_dev *rdev = dev_get_drvdata(dev);
455 466
456 if (!rdev->constraints) 467 return regulator_print_state(buf,
457 return sprintf(buf, "not defined\n"); 468 rdev->constraints->state_mem.enabled);
458
459 if (rdev->constraints->state_mem.enabled)
460 return sprintf(buf, "enabled\n");
461 else
462 return sprintf(buf, "disabled\n");
463} 469}
470static DEVICE_ATTR(suspend_mem_state, 0444,
471 regulator_suspend_mem_state_show, NULL);
464 472
465static ssize_t regulator_suspend_disk_state_show(struct device *dev, 473static ssize_t regulator_suspend_disk_state_show(struct device *dev,
466 struct device_attribute *attr, char *buf) 474 struct device_attribute *attr, char *buf)
467{ 475{
468 struct regulator_dev *rdev = dev_get_drvdata(dev); 476 struct regulator_dev *rdev = dev_get_drvdata(dev);
469 477
470 if (!rdev->constraints) 478 return regulator_print_state(buf,
471 return sprintf(buf, "not defined\n"); 479 rdev->constraints->state_disk.enabled);
472
473 if (rdev->constraints->state_disk.enabled)
474 return sprintf(buf, "enabled\n");
475 else
476 return sprintf(buf, "disabled\n");
477} 480}
481static DEVICE_ATTR(suspend_disk_state, 0444,
482 regulator_suspend_disk_state_show, NULL);
478 483
479static ssize_t regulator_suspend_standby_state_show(struct device *dev, 484static ssize_t regulator_suspend_standby_state_show(struct device *dev,
480 struct device_attribute *attr, char *buf) 485 struct device_attribute *attr, char *buf)
481{ 486{
482 struct regulator_dev *rdev = dev_get_drvdata(dev); 487 struct regulator_dev *rdev = dev_get_drvdata(dev);
483 488
484 if (!rdev->constraints) 489 return regulator_print_state(buf,
485 return sprintf(buf, "not defined\n"); 490 rdev->constraints->state_standby.enabled);
486
487 if (rdev->constraints->state_standby.enabled)
488 return sprintf(buf, "enabled\n");
489 else
490 return sprintf(buf, "disabled\n");
491} 491}
492static DEVICE_ATTR(suspend_standby_state, 0444,
493 regulator_suspend_standby_state_show, NULL);
492 494
495
496/*
497 * These are the only attributes are present for all regulators.
498 * Other attributes are a function of regulator functionality.
499 */
493static struct device_attribute regulator_dev_attrs[] = { 500static struct device_attribute regulator_dev_attrs[] = {
494 __ATTR(name, 0444, regulator_name_show, NULL), 501 __ATTR(name, 0444, regulator_name_show, NULL),
495 __ATTR(microvolts, 0444, regulator_uV_show, NULL),
496 __ATTR(microamps, 0444, regulator_uA_show, NULL),
497 __ATTR(opmode, 0444, regulator_opmode_show, NULL),
498 __ATTR(state, 0444, regulator_state_show, NULL),
499 __ATTR(min_microvolts, 0444, regulator_min_uV_show, NULL),
500 __ATTR(min_microamps, 0444, regulator_min_uA_show, NULL),
501 __ATTR(max_microvolts, 0444, regulator_max_uV_show, NULL),
502 __ATTR(max_microamps, 0444, regulator_max_uA_show, NULL),
503 __ATTR(requested_microamps, 0444, regulator_total_uA_show, NULL),
504 __ATTR(num_users, 0444, regulator_num_users_show, NULL), 502 __ATTR(num_users, 0444, regulator_num_users_show, NULL),
505 __ATTR(type, 0444, regulator_type_show, NULL), 503 __ATTR(type, 0444, regulator_type_show, NULL),
506 __ATTR(suspend_mem_microvolts, 0444,
507 regulator_suspend_mem_uV_show, NULL),
508 __ATTR(suspend_disk_microvolts, 0444,
509 regulator_suspend_disk_uV_show, NULL),
510 __ATTR(suspend_standby_microvolts, 0444,
511 regulator_suspend_standby_uV_show, NULL),
512 __ATTR(suspend_mem_mode, 0444,
513 regulator_suspend_mem_mode_show, NULL),
514 __ATTR(suspend_disk_mode, 0444,
515 regulator_suspend_disk_mode_show, NULL),
516 __ATTR(suspend_standby_mode, 0444,
517 regulator_suspend_standby_mode_show, NULL),
518 __ATTR(suspend_mem_state, 0444,
519 regulator_suspend_mem_state_show, NULL),
520 __ATTR(suspend_disk_state, 0444,
521 regulator_suspend_disk_state_show, NULL),
522 __ATTR(suspend_standby_state, 0444,
523 regulator_suspend_standby_state_show, NULL),
524 __ATTR_NULL, 504 __ATTR_NULL,
525}; 505};
526 506
@@ -675,7 +655,8 @@ static void print_constraints(struct regulator_dev *rdev)
675 655
676/** 656/**
677 * set_machine_constraints - sets regulator constraints 657 * set_machine_constraints - sets regulator constraints
678 * @regulator: regulator source 658 * @rdev: regulator source
659 * @constraints: constraints to apply
679 * 660 *
680 * Allows platform initialisation code to define and constrain 661 * Allows platform initialisation code to define and constrain
681 * regulator circuits e.g. valid voltage/current ranges, etc. NOTE: 662 * regulator circuits e.g. valid voltage/current ranges, etc. NOTE:
@@ -750,8 +731,8 @@ out:
750 731
751/** 732/**
752 * set_supply - set regulator supply regulator 733 * set_supply - set regulator supply regulator
753 * @regulator: regulator name 734 * @rdev: regulator name
754 * @supply: supply regulator name 735 * @supply_rdev: supply regulator name
755 * 736 *
756 * Called by platform initialisation code to set the supply regulator for this 737 * Called by platform initialisation code to set the supply regulator for this
757 * regulator. This ensures that a regulators supply will also be enabled by the 738 * regulator. This ensures that a regulators supply will also be enabled by the
@@ -778,9 +759,9 @@ out:
778 759
779/** 760/**
780 * set_consumer_device_supply: Bind a regulator to a symbolic supply 761 * set_consumer_device_supply: Bind a regulator to a symbolic supply
781 * @regulator: regulator source 762 * @rdev: regulator source
782 * @dev: device the supply applies to 763 * @consumer_dev: device the supply applies to
783 * @supply: symbolic name for supply 764 * @supply: symbolic name for supply
784 * 765 *
785 * Allows platform initialisation code to map physical regulator 766 * Allows platform initialisation code to map physical regulator
786 * sources to symbolic names for supplies for use by devices. Devices 767 * sources to symbolic names for supplies for use by devices. Devices
@@ -795,6 +776,20 @@ static int set_consumer_device_supply(struct regulator_dev *rdev,
795 if (supply == NULL) 776 if (supply == NULL)
796 return -EINVAL; 777 return -EINVAL;
797 778
779 list_for_each_entry(node, &regulator_map_list, list) {
780 if (consumer_dev != node->dev)
781 continue;
782 if (strcmp(node->supply, supply) != 0)
783 continue;
784
785 dev_dbg(consumer_dev, "%s/%s is '%s' supply; fail %s/%s\n",
786 dev_name(&node->regulator->dev),
787 node->regulator->desc->name,
788 supply,
789 dev_name(&rdev->dev), rdev->desc->name);
790 return -EBUSY;
791 }
792
798 node = kmalloc(sizeof(struct regulator_map), GFP_KERNEL); 793 node = kmalloc(sizeof(struct regulator_map), GFP_KERNEL);
799 if (node == NULL) 794 if (node == NULL)
800 return -ENOMEM; 795 return -ENOMEM;
@@ -963,16 +958,13 @@ void regulator_put(struct regulator *regulator)
963 if (regulator == NULL || IS_ERR(regulator)) 958 if (regulator == NULL || IS_ERR(regulator))
964 return; 959 return;
965 960
966 if (regulator->enabled) {
967 printk(KERN_WARNING "Releasing supply %s while enabled\n",
968 regulator->supply_name);
969 WARN_ON(regulator->enabled);
970 regulator_disable(regulator);
971 }
972
973 mutex_lock(&regulator_list_mutex); 961 mutex_lock(&regulator_list_mutex);
974 rdev = regulator->rdev; 962 rdev = regulator->rdev;
975 963
964 if (WARN(regulator->enabled, "Releasing supply %s while enabled\n",
965 regulator->supply_name))
966 _regulator_disable(rdev);
967
976 /* remove any sysfs entries */ 968 /* remove any sysfs entries */
977 if (regulator->dev) { 969 if (regulator->dev) {
978 sysfs_remove_link(&rdev->dev.kobj, regulator->supply_name); 970 sysfs_remove_link(&rdev->dev.kobj, regulator->supply_name);
@@ -1034,29 +1026,26 @@ static int _regulator_enable(struct regulator_dev *rdev)
1034 * regulator_enable - enable regulator output 1026 * regulator_enable - enable regulator output
1035 * @regulator: regulator source 1027 * @regulator: regulator source
1036 * 1028 *
1037 * Enable the regulator output at the predefined voltage or current value. 1029 * Request that the regulator be enabled with the regulator output at
1030 * the predefined voltage or current value. Calls to regulator_enable()
1031 * must be balanced with calls to regulator_disable().
1032 *
1038 * NOTE: the output value can be set by other drivers, boot loader or may be 1033 * NOTE: the output value can be set by other drivers, boot loader or may be
1039 * hardwired in the regulator. 1034 * hardwired in the regulator.
1040 * NOTE: calls to regulator_enable() must be balanced with calls to
1041 * regulator_disable().
1042 */ 1035 */
1043int regulator_enable(struct regulator *regulator) 1036int regulator_enable(struct regulator *regulator)
1044{ 1037{
1045 int ret; 1038 struct regulator_dev *rdev = regulator->rdev;
1046 1039 int ret = 0;
1047 if (regulator->enabled) {
1048 printk(KERN_CRIT "Regulator %s already enabled\n",
1049 regulator->supply_name);
1050 WARN_ON(regulator->enabled);
1051 return 0;
1052 }
1053 1040
1054 mutex_lock(&regulator->rdev->mutex); 1041 mutex_lock(&rdev->mutex);
1055 regulator->enabled = 1; 1042 if (regulator->enabled == 0)
1056 ret = _regulator_enable(regulator->rdev); 1043 ret = _regulator_enable(rdev);
1057 if (ret != 0) 1044 else if (regulator->enabled < 0)
1058 regulator->enabled = 0; 1045 ret = -EIO;
1059 mutex_unlock(&regulator->rdev->mutex); 1046 if (ret == 0)
1047 regulator->enabled++;
1048 mutex_unlock(&rdev->mutex);
1060 return ret; 1049 return ret;
1061} 1050}
1062EXPORT_SYMBOL_GPL(regulator_enable); 1051EXPORT_SYMBOL_GPL(regulator_enable);
@@ -1100,27 +1089,31 @@ static int _regulator_disable(struct regulator_dev *rdev)
1100 * regulator_disable - disable regulator output 1089 * regulator_disable - disable regulator output
1101 * @regulator: regulator source 1090 * @regulator: regulator source
1102 * 1091 *
1103 * Disable the regulator output voltage or current. 1092 * Disable the regulator output voltage or current. Calls to
1104 * NOTE: this will only disable the regulator output if no other consumer 1093 * regulator_enable() must be balanced with calls to
1105 * devices have it enabled.
1106 * NOTE: calls to regulator_enable() must be balanced with calls to
1107 * regulator_disable(). 1094 * regulator_disable().
1095 *
1096 * NOTE: this will only disable the regulator output if no other consumer
1097 * devices have it enabled, the regulator device supports disabling and
1098 * machine constraints permit this operation.
1108 */ 1099 */
1109int regulator_disable(struct regulator *regulator) 1100int regulator_disable(struct regulator *regulator)
1110{ 1101{
1111 int ret; 1102 struct regulator_dev *rdev = regulator->rdev;
1112 1103 int ret = 0;
1113 if (!regulator->enabled) {
1114 printk(KERN_ERR "%s: not in use by this consumer\n",
1115 __func__);
1116 return 0;
1117 }
1118 1104
1119 mutex_lock(&regulator->rdev->mutex); 1105 mutex_lock(&rdev->mutex);
1120 regulator->enabled = 0; 1106 if (regulator->enabled == 1) {
1121 regulator->uA_load = 0; 1107 ret = _regulator_disable(rdev);
1122 ret = _regulator_disable(regulator->rdev); 1108 if (ret == 0)
1123 mutex_unlock(&regulator->rdev->mutex); 1109 regulator->uA_load = 0;
1110 } else if (WARN(regulator->enabled <= 0,
1111 "unbalanced disables for supply %s\n",
1112 regulator->supply_name))
1113 ret = -EIO;
1114 if (ret == 0)
1115 regulator->enabled--;
1116 mutex_unlock(&rdev->mutex);
1124 return ret; 1117 return ret;
1125} 1118}
1126EXPORT_SYMBOL_GPL(regulator_disable); 1119EXPORT_SYMBOL_GPL(regulator_disable);
@@ -1196,7 +1189,13 @@ out:
1196 * regulator_is_enabled - is the regulator output enabled 1189 * regulator_is_enabled - is the regulator output enabled
1197 * @regulator: regulator source 1190 * @regulator: regulator source
1198 * 1191 *
1199 * Returns zero for disabled otherwise return number of enable requests. 1192 * Returns positive if the regulator driver backing the source/client
1193 * has requested that the device be enabled, zero if it hasn't, else a
1194 * negative errno code.
1195 *
1196 * Note that the device backing this regulator handle can have multiple
1197 * users, so it might be enabled even if regulator_enable() was never
1198 * called for this particular source.
1200 */ 1199 */
1201int regulator_is_enabled(struct regulator *regulator) 1200int regulator_is_enabled(struct regulator *regulator)
1202{ 1201{
@@ -1219,7 +1218,7 @@ EXPORT_SYMBOL_GPL(regulator_is_enabled);
1219 * 1218 *
1220 * NOTE: If the regulator is shared between several devices then the lowest 1219 * NOTE: If the regulator is shared between several devices then the lowest
1221 * request voltage that meets the system constraints will be used. 1220 * request voltage that meets the system constraints will be used.
1222 * NOTE: Regulator system constraints must be set for this regulator before 1221 * Regulator system constraints must be set for this regulator before
1223 * calling this function otherwise this call will fail. 1222 * calling this function otherwise this call will fail.
1224 */ 1223 */
1225int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV) 1224int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV)
@@ -1493,7 +1492,8 @@ int regulator_set_optimum_mode(struct regulator *regulator, int uA_load)
1493 mode = rdev->desc->ops->get_optimum_mode(rdev, 1492 mode = rdev->desc->ops->get_optimum_mode(rdev,
1494 input_uV, output_uV, 1493 input_uV, output_uV,
1495 total_uA_load); 1494 total_uA_load);
1496 if (ret <= 0) { 1495 ret = regulator_check_mode(rdev, mode);
1496 if (ret < 0) {
1497 printk(KERN_ERR "%s: failed to get optimum mode for %s @" 1497 printk(KERN_ERR "%s: failed to get optimum mode for %s @"
1498 " %d uA %d -> %d uV\n", __func__, rdev->desc->name, 1498 " %d uA %d -> %d uV\n", __func__, rdev->desc->name,
1499 total_uA_load, input_uV, output_uV); 1499 total_uA_load, input_uV, output_uV);
@@ -1501,7 +1501,7 @@ int regulator_set_optimum_mode(struct regulator *regulator, int uA_load)
1501 } 1501 }
1502 1502
1503 ret = rdev->desc->ops->set_mode(rdev, mode); 1503 ret = rdev->desc->ops->set_mode(rdev, mode);
1504 if (ret <= 0) { 1504 if (ret < 0) {
1505 printk(KERN_ERR "%s: failed to set optimum mode %x for %s\n", 1505 printk(KERN_ERR "%s: failed to set optimum mode %x for %s\n",
1506 __func__, mode, rdev->desc->name); 1506 __func__, mode, rdev->desc->name);
1507 goto out; 1507 goto out;
@@ -1516,7 +1516,7 @@ EXPORT_SYMBOL_GPL(regulator_set_optimum_mode);
1516/** 1516/**
1517 * regulator_register_notifier - register regulator event notifier 1517 * regulator_register_notifier - register regulator event notifier
1518 * @regulator: regulator source 1518 * @regulator: regulator source
1519 * @notifier_block: notifier block 1519 * @nb: notifier block
1520 * 1520 *
1521 * Register notifier block to receive regulator events. 1521 * Register notifier block to receive regulator events.
1522 */ 1522 */
@@ -1531,7 +1531,7 @@ EXPORT_SYMBOL_GPL(regulator_register_notifier);
1531/** 1531/**
1532 * regulator_unregister_notifier - unregister regulator event notifier 1532 * regulator_unregister_notifier - unregister regulator event notifier
1533 * @regulator: regulator source 1533 * @regulator: regulator source
1534 * @notifier_block: notifier block 1534 * @nb: notifier block
1535 * 1535 *
1536 * Unregister regulator event notifier block. 1536 * Unregister regulator event notifier block.
1537 */ 1537 */
@@ -1697,9 +1697,9 @@ EXPORT_SYMBOL_GPL(regulator_bulk_free);
1697 1697
1698/** 1698/**
1699 * regulator_notifier_call_chain - call regulator event notifier 1699 * regulator_notifier_call_chain - call regulator event notifier
1700 * @regulator: regulator source 1700 * @rdev: regulator source
1701 * @event: notifier block 1701 * @event: notifier block
1702 * @data: 1702 * @data: callback-specific data.
1703 * 1703 *
1704 * Called by regulator drivers to notify clients a regulator event has 1704 * Called by regulator drivers to notify clients a regulator event has
1705 * occurred. We also notify regulator clients downstream. 1705 * occurred. We also notify regulator clients downstream.
@@ -1713,10 +1713,122 @@ int regulator_notifier_call_chain(struct regulator_dev *rdev,
1713} 1713}
1714EXPORT_SYMBOL_GPL(regulator_notifier_call_chain); 1714EXPORT_SYMBOL_GPL(regulator_notifier_call_chain);
1715 1715
1716/*
1717 * To avoid cluttering sysfs (and memory) with useless state, only
1718 * create attributes that can be meaningfully displayed.
1719 */
1720static int add_regulator_attributes(struct regulator_dev *rdev)
1721{
1722 struct device *dev = &rdev->dev;
1723 struct regulator_ops *ops = rdev->desc->ops;
1724 int status = 0;
1725
1726 /* some attributes need specific methods to be displayed */
1727 if (ops->get_voltage) {
1728 status = device_create_file(dev, &dev_attr_microvolts);
1729 if (status < 0)
1730 return status;
1731 }
1732 if (ops->get_current_limit) {
1733 status = device_create_file(dev, &dev_attr_microamps);
1734 if (status < 0)
1735 return status;
1736 }
1737 if (ops->get_mode) {
1738 status = device_create_file(dev, &dev_attr_opmode);
1739 if (status < 0)
1740 return status;
1741 }
1742 if (ops->is_enabled) {
1743 status = device_create_file(dev, &dev_attr_state);
1744 if (status < 0)
1745 return status;
1746 }
1747
1748 /* some attributes are type-specific */
1749 if (rdev->desc->type == REGULATOR_CURRENT) {
1750 status = device_create_file(dev, &dev_attr_requested_microamps);
1751 if (status < 0)
1752 return status;
1753 }
1754
1755 /* all the other attributes exist to support constraints;
1756 * don't show them if there are no constraints, or if the
1757 * relevant supporting methods are missing.
1758 */
1759 if (!rdev->constraints)
1760 return status;
1761
1762 /* constraints need specific supporting methods */
1763 if (ops->set_voltage) {
1764 status = device_create_file(dev, &dev_attr_min_microvolts);
1765 if (status < 0)
1766 return status;
1767 status = device_create_file(dev, &dev_attr_max_microvolts);
1768 if (status < 0)
1769 return status;
1770 }
1771 if (ops->set_current_limit) {
1772 status = device_create_file(dev, &dev_attr_min_microamps);
1773 if (status < 0)
1774 return status;
1775 status = device_create_file(dev, &dev_attr_max_microamps);
1776 if (status < 0)
1777 return status;
1778 }
1779
1780 /* suspend mode constraints need multiple supporting methods */
1781 if (!(ops->set_suspend_enable && ops->set_suspend_disable))
1782 return status;
1783
1784 status = device_create_file(dev, &dev_attr_suspend_standby_state);
1785 if (status < 0)
1786 return status;
1787 status = device_create_file(dev, &dev_attr_suspend_mem_state);
1788 if (status < 0)
1789 return status;
1790 status = device_create_file(dev, &dev_attr_suspend_disk_state);
1791 if (status < 0)
1792 return status;
1793
1794 if (ops->set_suspend_voltage) {
1795 status = device_create_file(dev,
1796 &dev_attr_suspend_standby_microvolts);
1797 if (status < 0)
1798 return status;
1799 status = device_create_file(dev,
1800 &dev_attr_suspend_mem_microvolts);
1801 if (status < 0)
1802 return status;
1803 status = device_create_file(dev,
1804 &dev_attr_suspend_disk_microvolts);
1805 if (status < 0)
1806 return status;
1807 }
1808
1809 if (ops->set_suspend_mode) {
1810 status = device_create_file(dev,
1811 &dev_attr_suspend_standby_mode);
1812 if (status < 0)
1813 return status;
1814 status = device_create_file(dev,
1815 &dev_attr_suspend_mem_mode);
1816 if (status < 0)
1817 return status;
1818 status = device_create_file(dev,
1819 &dev_attr_suspend_disk_mode);
1820 if (status < 0)
1821 return status;
1822 }
1823
1824 return status;
1825}
1826
1716/** 1827/**
1717 * regulator_register - register regulator 1828 * regulator_register - register regulator
1718 * @regulator: regulator source 1829 * @regulator_desc: regulator to register
1719 * @reg_data: private regulator data 1830 * @dev: struct device for the regulator
1831 * @driver_data: private regulator data
1720 * 1832 *
1721 * Called by regulator drivers to register a regulator. 1833 * Called by regulator drivers to register a regulator.
1722 * Returns 0 on success. 1834 * Returns 0 on success.
@@ -1761,45 +1873,37 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
1761 /* preform any regulator specific init */ 1873 /* preform any regulator specific init */
1762 if (init_data->regulator_init) { 1874 if (init_data->regulator_init) {
1763 ret = init_data->regulator_init(rdev->reg_data); 1875 ret = init_data->regulator_init(rdev->reg_data);
1764 if (ret < 0) { 1876 if (ret < 0)
1765 kfree(rdev); 1877 goto clean;
1766 rdev = ERR_PTR(ret);
1767 goto out;
1768 }
1769 }
1770
1771 /* set regulator constraints */
1772 ret = set_machine_constraints(rdev, &init_data->constraints);
1773 if (ret < 0) {
1774 kfree(rdev);
1775 rdev = ERR_PTR(ret);
1776 goto out;
1777 } 1878 }
1778 1879
1779 /* register with sysfs */ 1880 /* register with sysfs */
1780 rdev->dev.class = &regulator_class; 1881 rdev->dev.class = &regulator_class;
1781 rdev->dev.parent = dev; 1882 rdev->dev.parent = dev;
1782 snprintf(rdev->dev.bus_id, sizeof(rdev->dev.bus_id), 1883 dev_set_name(&rdev->dev, "regulator.%d",
1783 "regulator.%d", atomic_inc_return(&regulator_no) - 1); 1884 atomic_inc_return(&regulator_no) - 1);
1784 ret = device_register(&rdev->dev); 1885 ret = device_register(&rdev->dev);
1785 if (ret != 0) { 1886 if (ret != 0)
1786 kfree(rdev); 1887 goto clean;
1787 rdev = ERR_PTR(ret);
1788 goto out;
1789 }
1790 1888
1791 dev_set_drvdata(&rdev->dev, rdev); 1889 dev_set_drvdata(&rdev->dev, rdev);
1792 1890
1891 /* set regulator constraints */
1892 ret = set_machine_constraints(rdev, &init_data->constraints);
1893 if (ret < 0)
1894 goto scrub;
1895
1896 /* add attributes supported by this regulator */
1897 ret = add_regulator_attributes(rdev);
1898 if (ret < 0)
1899 goto scrub;
1900
1793 /* set supply regulator if it exists */ 1901 /* set supply regulator if it exists */
1794 if (init_data->supply_regulator_dev) { 1902 if (init_data->supply_regulator_dev) {
1795 ret = set_supply(rdev, 1903 ret = set_supply(rdev,
1796 dev_get_drvdata(init_data->supply_regulator_dev)); 1904 dev_get_drvdata(init_data->supply_regulator_dev));
1797 if (ret < 0) { 1905 if (ret < 0)
1798 device_unregister(&rdev->dev); 1906 goto scrub;
1799 kfree(rdev);
1800 rdev = ERR_PTR(ret);
1801 goto out;
1802 }
1803 } 1907 }
1804 1908
1805 /* add consumers devices */ 1909 /* add consumers devices */
@@ -1811,10 +1915,7 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
1811 for (--i; i >= 0; i--) 1915 for (--i; i >= 0; i--)
1812 unset_consumer_device_supply(rdev, 1916 unset_consumer_device_supply(rdev,
1813 init_data->consumer_supplies[i].dev); 1917 init_data->consumer_supplies[i].dev);
1814 device_unregister(&rdev->dev); 1918 goto scrub;
1815 kfree(rdev);
1816 rdev = ERR_PTR(ret);
1817 goto out;
1818 } 1919 }
1819 } 1920 }
1820 1921
@@ -1822,12 +1923,19 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
1822out: 1923out:
1823 mutex_unlock(&regulator_list_mutex); 1924 mutex_unlock(&regulator_list_mutex);
1824 return rdev; 1925 return rdev;
1926
1927scrub:
1928 device_unregister(&rdev->dev);
1929clean:
1930 kfree(rdev);
1931 rdev = ERR_PTR(ret);
1932 goto out;
1825} 1933}
1826EXPORT_SYMBOL_GPL(regulator_register); 1934EXPORT_SYMBOL_GPL(regulator_register);
1827 1935
1828/** 1936/**
1829 * regulator_unregister - unregister regulator 1937 * regulator_unregister - unregister regulator
1830 * @regulator: regulator source 1938 * @rdev: regulator to unregister
1831 * 1939 *
1832 * Called by regulator drivers to unregister a regulator. 1940 * Called by regulator drivers to unregister a regulator.
1833 */ 1941 */
@@ -1846,7 +1954,7 @@ void regulator_unregister(struct regulator_dev *rdev)
1846EXPORT_SYMBOL_GPL(regulator_unregister); 1954EXPORT_SYMBOL_GPL(regulator_unregister);
1847 1955
1848/** 1956/**
1849 * regulator_suspend_prepare: prepare regulators for system wide suspend 1957 * regulator_suspend_prepare - prepare regulators for system wide suspend
1850 * @state: system suspend state 1958 * @state: system suspend state
1851 * 1959 *
1852 * Configure each regulator with it's suspend operating parameters for state. 1960 * Configure each regulator with it's suspend operating parameters for state.
@@ -1882,7 +1990,7 @@ EXPORT_SYMBOL_GPL(regulator_suspend_prepare);
1882 1990
1883/** 1991/**
1884 * rdev_get_drvdata - get rdev regulator driver data 1992 * rdev_get_drvdata - get rdev regulator driver data
1885 * @regulator: regulator 1993 * @rdev: regulator
1886 * 1994 *
1887 * Get rdev regulator driver private data. This call can be used in the 1995 * Get rdev regulator driver private data. This call can be used in the
1888 * regulator driver context. 1996 * regulator driver context.
@@ -1919,7 +2027,7 @@ EXPORT_SYMBOL_GPL(regulator_set_drvdata);
1919 2027
1920/** 2028/**
1921 * regulator_get_id - get regulator ID 2029 * regulator_get_id - get regulator ID
1922 * @regulator: regulator 2030 * @rdev: regulator
1923 */ 2031 */
1924int rdev_get_id(struct regulator_dev *rdev) 2032int rdev_get_id(struct regulator_dev *rdev)
1925{ 2033{
diff --git a/drivers/regulator/da903x.c b/drivers/regulator/da903x.c
index 773b29cec8be..fe77730a7edb 100644
--- a/drivers/regulator/da903x.c
+++ b/drivers/regulator/da903x.c
@@ -102,7 +102,7 @@ static int da903x_set_ldo_voltage(struct regulator_dev *rdev,
102 uint8_t val, mask; 102 uint8_t val, mask;
103 103
104 if (check_range(info, min_uV, max_uV)) { 104 if (check_range(info, min_uV, max_uV)) {
105 pr_err("invalid voltage range (%d, %d) uV", min_uV, max_uV); 105 pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV);
106 return -EINVAL; 106 return -EINVAL;
107 } 107 }
108 108
@@ -159,7 +159,7 @@ static int da903x_is_enabled(struct regulator_dev *rdev)
159 if (ret) 159 if (ret)
160 return ret; 160 return ret;
161 161
162 return reg_val & (1 << info->enable_bit); 162 return !!(reg_val & (1 << info->enable_bit));
163} 163}
164 164
165/* DA9030 specific operations */ 165/* DA9030 specific operations */
@@ -172,7 +172,7 @@ static int da9030_set_ldo1_15_voltage(struct regulator_dev *rdev,
172 int ret; 172 int ret;
173 173
174 if (check_range(info, min_uV, max_uV)) { 174 if (check_range(info, min_uV, max_uV)) {
175 pr_err("invalid voltage range (%d, %d) uV", min_uV, max_uV); 175 pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV);
176 return -EINVAL; 176 return -EINVAL;
177 } 177 }
178 178
@@ -199,7 +199,7 @@ static int da9030_set_ldo14_voltage(struct regulator_dev *rdev,
199 int thresh; 199 int thresh;
200 200
201 if (check_range(info, min_uV, max_uV)) { 201 if (check_range(info, min_uV, max_uV)) {
202 pr_err("invalid voltage range (%d, %d) uV", min_uV, max_uV); 202 pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV);
203 return -EINVAL; 203 return -EINVAL;
204 } 204 }
205 205
@@ -248,7 +248,7 @@ static int da9034_set_dvc_voltage(struct regulator_dev *rdev,
248 int ret; 248 int ret;
249 249
250 if (check_range(info, min_uV, max_uV)) { 250 if (check_range(info, min_uV, max_uV)) {
251 pr_err("invalid voltage range (%d, %d) uV", min_uV, max_uV); 251 pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV);
252 return -EINVAL; 252 return -EINVAL;
253 } 253 }
254 254
@@ -273,7 +273,7 @@ static int da9034_set_ldo12_voltage(struct regulator_dev *rdev,
273 uint8_t val, mask; 273 uint8_t val, mask;
274 274
275 if (check_range(info, min_uV, max_uV)) { 275 if (check_range(info, min_uV, max_uV)) {
276 pr_err("invalid voltage range (%d, %d) uV", min_uV, max_uV); 276 pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV);
277 return -EINVAL; 277 return -EINVAL;
278 } 278 }
279 279
diff --git a/drivers/regulator/pcf50633-regulator.c b/drivers/regulator/pcf50633-regulator.c
new file mode 100644
index 000000000000..4cc85ec6e120
--- /dev/null
+++ b/drivers/regulator/pcf50633-regulator.c
@@ -0,0 +1,329 @@
1/* NXP PCF50633 PMIC Driver
2 *
3 * (C) 2006-2008 by Openmoko, Inc.
4 * Author: Balaji Rao <balajirrao@openmoko.org>
5 * All rights reserved.
6 *
7 * Broken down from monstrous PCF50633 driver mainly by
8 * Harald Welte and Andy Green and Werner Almesberger
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
14 *
15 */
16
17#include <linux/kernel.h>
18#include <linux/module.h>
19#include <linux/init.h>
20#include <linux/device.h>
21#include <linux/err.h>
22#include <linux/platform_device.h>
23
24#include <linux/mfd/pcf50633/core.h>
25#include <linux/mfd/pcf50633/pmic.h>
26
27#define PCF50633_REGULATOR(_name, _id) \
28 { \
29 .name = _name, \
30 .id = _id, \
31 .ops = &pcf50633_regulator_ops, \
32 .type = REGULATOR_VOLTAGE, \
33 .owner = THIS_MODULE, \
34 }
35
36static const u8 pcf50633_regulator_registers[PCF50633_NUM_REGULATORS] = {
37 [PCF50633_REGULATOR_AUTO] = PCF50633_REG_AUTOOUT,
38 [PCF50633_REGULATOR_DOWN1] = PCF50633_REG_DOWN1OUT,
39 [PCF50633_REGULATOR_DOWN2] = PCF50633_REG_DOWN2OUT,
40 [PCF50633_REGULATOR_MEMLDO] = PCF50633_REG_MEMLDOOUT,
41 [PCF50633_REGULATOR_LDO1] = PCF50633_REG_LDO1OUT,
42 [PCF50633_REGULATOR_LDO2] = PCF50633_REG_LDO2OUT,
43 [PCF50633_REGULATOR_LDO3] = PCF50633_REG_LDO3OUT,
44 [PCF50633_REGULATOR_LDO4] = PCF50633_REG_LDO4OUT,
45 [PCF50633_REGULATOR_LDO5] = PCF50633_REG_LDO5OUT,
46 [PCF50633_REGULATOR_LDO6] = PCF50633_REG_LDO6OUT,
47 [PCF50633_REGULATOR_HCLDO] = PCF50633_REG_HCLDOOUT,
48};
49
50/* Bits from voltage value */
51static u8 auto_voltage_bits(unsigned int millivolts)
52{
53 if (millivolts < 1800)
54 return 0;
55 if (millivolts > 3800)
56 return 0xff;
57
58 millivolts -= 625;
59
60 return millivolts / 25;
61}
62
63static u8 down_voltage_bits(unsigned int millivolts)
64{
65 if (millivolts < 625)
66 return 0;
67 else if (millivolts > 3000)
68 return 0xff;
69
70 millivolts -= 625;
71
72 return millivolts / 25;
73}
74
75static u8 ldo_voltage_bits(unsigned int millivolts)
76{
77 if (millivolts < 900)
78 return 0;
79 else if (millivolts > 3600)
80 return 0x1f;
81
82 millivolts -= 900;
83 return millivolts / 100;
84}
85
86/* Obtain voltage value from bits */
87static unsigned int auto_voltage_value(u8 bits)
88{
89 if (bits < 0x2f)
90 return 0;
91
92 return 625 + (bits * 25);
93}
94
95
96static unsigned int down_voltage_value(u8 bits)
97{
98 return 625 + (bits * 25);
99}
100
101
102static unsigned int ldo_voltage_value(u8 bits)
103{
104 bits &= 0x1f;
105
106 return 900 + (bits * 100);
107}
108
109static int pcf50633_regulator_set_voltage(struct regulator_dev *rdev,
110 int min_uV, int max_uV)
111{
112 struct pcf50633 *pcf;
113 int regulator_id, millivolts;
114 u8 volt_bits, regnr;
115
116 pcf = rdev_get_drvdata(rdev);
117
118 regulator_id = rdev_get_id(rdev);
119 if (regulator_id >= PCF50633_NUM_REGULATORS)
120 return -EINVAL;
121
122 millivolts = min_uV / 1000;
123
124 regnr = pcf50633_regulator_registers[regulator_id];
125
126 switch (regulator_id) {
127 case PCF50633_REGULATOR_AUTO:
128 volt_bits = auto_voltage_bits(millivolts);
129 break;
130 case PCF50633_REGULATOR_DOWN1:
131 volt_bits = down_voltage_bits(millivolts);
132 break;
133 case PCF50633_REGULATOR_DOWN2:
134 volt_bits = down_voltage_bits(millivolts);
135 break;
136 case PCF50633_REGULATOR_LDO1:
137 case PCF50633_REGULATOR_LDO2:
138 case PCF50633_REGULATOR_LDO3:
139 case PCF50633_REGULATOR_LDO4:
140 case PCF50633_REGULATOR_LDO5:
141 case PCF50633_REGULATOR_LDO6:
142 case PCF50633_REGULATOR_HCLDO:
143 volt_bits = ldo_voltage_bits(millivolts);
144 break;
145 default:
146 return -EINVAL;
147 }
148
149 return pcf50633_reg_write(pcf, regnr, volt_bits);
150}
151
152static int pcf50633_regulator_get_voltage(struct regulator_dev *rdev)
153{
154 struct pcf50633 *pcf;
155 int regulator_id, millivolts, volt_bits;
156 u8 regnr;
157
158 pcf = rdev_get_drvdata(rdev);;
159
160 regulator_id = rdev_get_id(rdev);
161 if (regulator_id >= PCF50633_NUM_REGULATORS)
162 return -EINVAL;
163
164 regnr = pcf50633_regulator_registers[regulator_id];
165
166 volt_bits = pcf50633_reg_read(pcf, regnr);
167 if (volt_bits < 0)
168 return -1;
169
170 switch (regulator_id) {
171 case PCF50633_REGULATOR_AUTO:
172 millivolts = auto_voltage_value(volt_bits);
173 break;
174 case PCF50633_REGULATOR_DOWN1:
175 millivolts = down_voltage_value(volt_bits);
176 break;
177 case PCF50633_REGULATOR_DOWN2:
178 millivolts = down_voltage_value(volt_bits);
179 break;
180 case PCF50633_REGULATOR_LDO1:
181 case PCF50633_REGULATOR_LDO2:
182 case PCF50633_REGULATOR_LDO3:
183 case PCF50633_REGULATOR_LDO4:
184 case PCF50633_REGULATOR_LDO5:
185 case PCF50633_REGULATOR_LDO6:
186 case PCF50633_REGULATOR_HCLDO:
187 millivolts = ldo_voltage_value(volt_bits);
188 break;
189 default:
190 return -EINVAL;
191 }
192
193 return millivolts * 1000;
194}
195
196static int pcf50633_regulator_enable(struct regulator_dev *rdev)
197{
198 struct pcf50633 *pcf = rdev_get_drvdata(rdev);
199 int regulator_id;
200 u8 regnr;
201
202 regulator_id = rdev_get_id(rdev);
203 if (regulator_id >= PCF50633_NUM_REGULATORS)
204 return -EINVAL;
205
206 /* The *ENA register is always one after the *OUT register */
207 regnr = pcf50633_regulator_registers[regulator_id] + 1;
208
209 return pcf50633_reg_set_bit_mask(pcf, regnr, PCF50633_REGULATOR_ON,
210 PCF50633_REGULATOR_ON);
211}
212
213static int pcf50633_regulator_disable(struct regulator_dev *rdev)
214{
215 struct pcf50633 *pcf = rdev_get_drvdata(rdev);
216 int regulator_id;
217 u8 regnr;
218
219 regulator_id = rdev_get_id(rdev);
220 if (regulator_id >= PCF50633_NUM_REGULATORS)
221 return -EINVAL;
222
223 /* the *ENA register is always one after the *OUT register */
224 regnr = pcf50633_regulator_registers[regulator_id] + 1;
225
226 return pcf50633_reg_set_bit_mask(pcf, regnr,
227 PCF50633_REGULATOR_ON, 0);
228}
229
230static int pcf50633_regulator_is_enabled(struct regulator_dev *rdev)
231{
232 struct pcf50633 *pcf = rdev_get_drvdata(rdev);
233 int regulator_id = rdev_get_id(rdev);
234 u8 regnr;
235
236 regulator_id = rdev_get_id(rdev);
237 if (regulator_id >= PCF50633_NUM_REGULATORS)
238 return -EINVAL;
239
240 /* the *ENA register is always one after the *OUT register */
241 regnr = pcf50633_regulator_registers[regulator_id] + 1;
242
243 return pcf50633_reg_read(pcf, regnr) & PCF50633_REGULATOR_ON;
244}
245
246static struct regulator_ops pcf50633_regulator_ops = {
247 .set_voltage = pcf50633_regulator_set_voltage,
248 .get_voltage = pcf50633_regulator_get_voltage,
249 .enable = pcf50633_regulator_enable,
250 .disable = pcf50633_regulator_disable,
251 .is_enabled = pcf50633_regulator_is_enabled,
252};
253
254static struct regulator_desc regulators[] = {
255 [PCF50633_REGULATOR_AUTO] =
256 PCF50633_REGULATOR("auto", PCF50633_REGULATOR_AUTO),
257 [PCF50633_REGULATOR_DOWN1] =
258 PCF50633_REGULATOR("down1", PCF50633_REGULATOR_DOWN1),
259 [PCF50633_REGULATOR_DOWN2] =
260 PCF50633_REGULATOR("down2", PCF50633_REGULATOR_DOWN2),
261 [PCF50633_REGULATOR_LDO1] =
262 PCF50633_REGULATOR("ldo1", PCF50633_REGULATOR_LDO1),
263 [PCF50633_REGULATOR_LDO2] =
264 PCF50633_REGULATOR("ldo2", PCF50633_REGULATOR_LDO2),
265 [PCF50633_REGULATOR_LDO3] =
266 PCF50633_REGULATOR("ldo3", PCF50633_REGULATOR_LDO3),
267 [PCF50633_REGULATOR_LDO4] =
268 PCF50633_REGULATOR("ldo4", PCF50633_REGULATOR_LDO4),
269 [PCF50633_REGULATOR_LDO5] =
270 PCF50633_REGULATOR("ldo5", PCF50633_REGULATOR_LDO5),
271 [PCF50633_REGULATOR_LDO6] =
272 PCF50633_REGULATOR("ldo6", PCF50633_REGULATOR_LDO6),
273 [PCF50633_REGULATOR_HCLDO] =
274 PCF50633_REGULATOR("hcldo", PCF50633_REGULATOR_HCLDO),
275 [PCF50633_REGULATOR_MEMLDO] =
276 PCF50633_REGULATOR("memldo", PCF50633_REGULATOR_MEMLDO),
277};
278
279static int __devinit pcf50633_regulator_probe(struct platform_device *pdev)
280{
281 struct regulator_dev *rdev;
282 struct pcf50633 *pcf;
283
284 /* Already set by core driver */
285 pcf = platform_get_drvdata(pdev);
286
287 rdev = regulator_register(&regulators[pdev->id], &pdev->dev, pcf);
288 if (IS_ERR(rdev))
289 return PTR_ERR(rdev);
290
291 if (pcf->pdata->regulator_registered)
292 pcf->pdata->regulator_registered(pcf, pdev->id);
293
294 return 0;
295}
296
297static int __devexit pcf50633_regulator_remove(struct platform_device *pdev)
298{
299 struct regulator_dev *rdev = platform_get_drvdata(pdev);
300
301 regulator_unregister(rdev);
302
303 return 0;
304}
305
306static struct platform_driver pcf50633_regulator_driver = {
307 .driver = {
308 .name = "pcf50633-regltr",
309 },
310 .probe = pcf50633_regulator_probe,
311 .remove = __devexit_p(pcf50633_regulator_remove),
312};
313
314static int __init pcf50633_regulator_init(void)
315{
316 return platform_driver_register(&pcf50633_regulator_driver);
317}
318module_init(pcf50633_regulator_init);
319
320static void __exit pcf50633_regulator_exit(void)
321{
322 platform_driver_unregister(&pcf50633_regulator_driver);
323}
324module_exit(pcf50633_regulator_exit);
325
326MODULE_AUTHOR("Balaji Rao <balajirrao@openmoko.org>");
327MODULE_DESCRIPTION("PCF50633 regulator driver");
328MODULE_LICENSE("GPL");
329MODULE_ALIAS("platform:pcf50633-regulator");
diff --git a/drivers/regulator/wm8350-regulator.c b/drivers/regulator/wm8350-regulator.c
index c68c496b2c49..7aa35248181b 100644
--- a/drivers/regulator/wm8350-regulator.c
+++ b/drivers/regulator/wm8350-regulator.c
@@ -1412,6 +1412,97 @@ int wm8350_register_regulator(struct wm8350 *wm8350, int reg,
1412} 1412}
1413EXPORT_SYMBOL_GPL(wm8350_register_regulator); 1413EXPORT_SYMBOL_GPL(wm8350_register_regulator);
1414 1414
1415/**
1416 * wm8350_register_led - Register a WM8350 LED output
1417 *
1418 * @param wm8350 The WM8350 device to configure.
1419 * @param lednum LED device index to create.
1420 * @param dcdc The DCDC to use for the LED.
1421 * @param isink The ISINK to use for the LED.
1422 * @param pdata Configuration for the LED.
1423 *
1424 * The WM8350 supports the use of an ISINK together with a DCDC to
1425 * provide a power-efficient LED driver. This function registers the
1426 * regulators and instantiates the platform device for a LED. The
1427 * operating modes for the LED regulators must be configured using
1428 * wm8350_isink_set_flash(), wm8350_dcdc25_set_mode() and
1429 * wm8350_dcdc_set_slot() prior to calling this function.
1430 */
1431int wm8350_register_led(struct wm8350 *wm8350, int lednum, int dcdc, int isink,
1432 struct wm8350_led_platform_data *pdata)
1433{
1434 struct wm8350_led *led;
1435 struct platform_device *pdev;
1436 int ret;
1437
1438 if (lednum > ARRAY_SIZE(wm8350->pmic.led) || lednum < 0) {
1439 dev_err(wm8350->dev, "Invalid LED index %d\n", lednum);
1440 return -ENODEV;
1441 }
1442
1443 led = &wm8350->pmic.led[lednum];
1444
1445 if (led->pdev) {
1446 dev_err(wm8350->dev, "LED %d already allocated\n", lednum);
1447 return -EINVAL;
1448 }
1449
1450 pdev = platform_device_alloc("wm8350-led", lednum);
1451 if (pdev == NULL) {
1452 dev_err(wm8350->dev, "Failed to allocate LED %d\n", lednum);
1453 return -ENOMEM;
1454 }
1455
1456 led->isink_consumer.dev = &pdev->dev;
1457 led->isink_consumer.supply = "led_isink";
1458 led->isink_init.num_consumer_supplies = 1;
1459 led->isink_init.consumer_supplies = &led->isink_consumer;
1460 led->isink_init.constraints.min_uA = 0;
1461 led->isink_init.constraints.max_uA = pdata->max_uA;
1462 led->isink_init.constraints.valid_ops_mask = REGULATOR_CHANGE_CURRENT;
1463 led->isink_init.constraints.valid_modes_mask = REGULATOR_MODE_NORMAL;
1464 ret = wm8350_register_regulator(wm8350, isink, &led->isink_init);
1465 if (ret != 0) {
1466 platform_device_put(pdev);
1467 return ret;
1468 }
1469
1470 led->dcdc_consumer.dev = &pdev->dev;
1471 led->dcdc_consumer.supply = "led_vcc";
1472 led->dcdc_init.num_consumer_supplies = 1;
1473 led->dcdc_init.consumer_supplies = &led->dcdc_consumer;
1474 led->dcdc_init.constraints.valid_modes_mask = REGULATOR_MODE_NORMAL;
1475 ret = wm8350_register_regulator(wm8350, dcdc, &led->dcdc_init);
1476 if (ret != 0) {
1477 platform_device_put(pdev);
1478 return ret;
1479 }
1480
1481 switch (isink) {
1482 case WM8350_ISINK_A:
1483 wm8350->pmic.isink_A_dcdc = dcdc;
1484 break;
1485 case WM8350_ISINK_B:
1486 wm8350->pmic.isink_B_dcdc = dcdc;
1487 break;
1488 }
1489
1490 pdev->dev.platform_data = pdata;
1491 pdev->dev.parent = wm8350->dev;
1492 ret = platform_device_add(pdev);
1493 if (ret != 0) {
1494 dev_err(wm8350->dev, "Failed to register LED %d: %d\n",
1495 lednum, ret);
1496 platform_device_put(pdev);
1497 return ret;
1498 }
1499
1500 led->pdev = pdev;
1501
1502 return 0;
1503}
1504EXPORT_SYMBOL_GPL(wm8350_register_led);
1505
1415static struct platform_driver wm8350_regulator_driver = { 1506static struct platform_driver wm8350_regulator_driver = {
1416 .probe = wm8350_regulator_probe, 1507 .probe = wm8350_regulator_probe,
1417 .remove = wm8350_regulator_remove, 1508 .remove = wm8350_regulator_remove,
diff --git a/drivers/regulator/wm8400-regulator.c b/drivers/regulator/wm8400-regulator.c
index 48b372e038a8..56e23d44ba59 100644
--- a/drivers/regulator/wm8400-regulator.c
+++ b/drivers/regulator/wm8400-regulator.c
@@ -289,7 +289,7 @@ static struct regulator_desc regulators[] = {
289 }, 289 },
290}; 290};
291 291
292static int __init wm8400_regulator_probe(struct platform_device *pdev) 292static int __devinit wm8400_regulator_probe(struct platform_device *pdev)
293{ 293{
294 struct regulator_dev *rdev; 294 struct regulator_dev *rdev;
295 295