diff options
| -rw-r--r-- | drivers/regulator/core.c | 111 |
1 files changed, 44 insertions, 67 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 686dfa990726..5109f7d4809a 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c | |||
| @@ -267,12 +267,8 @@ static ssize_t regulator_name_show(struct device *dev, | |||
| 267 | return sprintf(buf, "%s\n", name); | 267 | return sprintf(buf, "%s\n", name); |
| 268 | } | 268 | } |
| 269 | 269 | ||
| 270 | static ssize_t regulator_opmode_show(struct device *dev, | 270 | static ssize_t regulator_print_opmode(char *buf, int mode) |
| 271 | struct device_attribute *attr, char *buf) | ||
| 272 | { | 271 | { |
| 273 | struct regulator_dev *rdev = dev_get_drvdata(dev); | ||
| 274 | int mode = _regulator_get_mode(rdev); | ||
| 275 | |||
| 276 | switch (mode) { | 272 | switch (mode) { |
| 277 | case REGULATOR_MODE_FAST: | 273 | case REGULATOR_MODE_FAST: |
| 278 | return sprintf(buf, "fast\n"); | 274 | return sprintf(buf, "fast\n"); |
| @@ -286,12 +282,16 @@ static ssize_t regulator_opmode_show(struct device *dev, | |||
| 286 | return sprintf(buf, "unknown\n"); | 282 | return sprintf(buf, "unknown\n"); |
| 287 | } | 283 | } |
| 288 | 284 | ||
| 289 | static ssize_t regulator_state_show(struct device *dev, | 285 | static ssize_t regulator_opmode_show(struct device *dev, |
| 290 | struct device_attribute *attr, char *buf) | 286 | struct device_attribute *attr, char *buf) |
| 291 | { | 287 | { |
| 292 | struct regulator_dev *rdev = dev_get_drvdata(dev); | 288 | struct regulator_dev *rdev = dev_get_drvdata(dev); |
| 293 | int state = _regulator_is_enabled(rdev); | ||
| 294 | 289 | ||
| 290 | return regulator_print_opmode(buf, _regulator_get_mode(rdev)); | ||
| 291 | } | ||
| 292 | |||
| 293 | static ssize_t regulator_print_state(char *buf, int state) | ||
| 294 | { | ||
| 295 | if (state > 0) | 295 | if (state > 0) |
| 296 | return sprintf(buf, "enabled\n"); | 296 | return sprintf(buf, "enabled\n"); |
| 297 | else if (state == 0) | 297 | else if (state == 0) |
| @@ -300,6 +300,14 @@ static ssize_t regulator_state_show(struct device *dev, | |||
| 300 | return sprintf(buf, "unknown\n"); | 300 | return sprintf(buf, "unknown\n"); |
| 301 | } | 301 | } |
| 302 | 302 | ||
| 303 | static ssize_t regulator_state_show(struct device *dev, | ||
| 304 | struct device_attribute *attr, char *buf) | ||
| 305 | { | ||
| 306 | struct regulator_dev *rdev = dev_get_drvdata(dev); | ||
| 307 | |||
| 308 | return regulator_print_state(buf, _regulator_is_enabled(rdev)); | ||
| 309 | } | ||
| 310 | |||
| 303 | static ssize_t regulator_min_uA_show(struct device *dev, | 311 | static ssize_t regulator_min_uA_show(struct device *dev, |
| 304 | struct device_attribute *attr, char *buf) | 312 | struct device_attribute *attr, char *buf) |
| 305 | { | 313 | { |
| @@ -409,22 +417,6 @@ static ssize_t regulator_suspend_standby_uV_show(struct device *dev, | |||
| 409 | return sprintf(buf, "%d\n", rdev->constraints->state_standby.uV); | 417 | return sprintf(buf, "%d\n", rdev->constraints->state_standby.uV); |
| 410 | } | 418 | } |
| 411 | 419 | ||
| 412 | static ssize_t suspend_opmode_show(struct regulator_dev *rdev, | ||
| 413 | unsigned int mode, char *buf) | ||
| 414 | { | ||
| 415 | switch (mode) { | ||
| 416 | case REGULATOR_MODE_FAST: | ||
| 417 | return sprintf(buf, "fast\n"); | ||
| 418 | case REGULATOR_MODE_NORMAL: | ||
| 419 | return sprintf(buf, "normal\n"); | ||
| 420 | case REGULATOR_MODE_IDLE: | ||
| 421 | return sprintf(buf, "idle\n"); | ||
| 422 | case REGULATOR_MODE_STANDBY: | ||
| 423 | return sprintf(buf, "standby\n"); | ||
| 424 | } | ||
| 425 | return sprintf(buf, "unknown\n"); | ||
| 426 | } | ||
| 427 | |||
| 428 | static ssize_t regulator_suspend_mem_mode_show(struct device *dev, | 420 | static ssize_t regulator_suspend_mem_mode_show(struct device *dev, |
| 429 | struct device_attribute *attr, char *buf) | 421 | struct device_attribute *attr, char *buf) |
| 430 | { | 422 | { |
| @@ -432,8 +424,8 @@ static ssize_t regulator_suspend_mem_mode_show(struct device *dev, | |||
| 432 | 424 | ||
| 433 | if (!rdev->constraints) | 425 | if (!rdev->constraints) |
| 434 | return sprintf(buf, "not defined\n"); | 426 | return sprintf(buf, "not defined\n"); |
| 435 | return suspend_opmode_show(rdev, | 427 | return regulator_print_opmode(buf, |
| 436 | rdev->constraints->state_mem.mode, buf); | 428 | rdev->constraints->state_mem.mode); |
| 437 | } | 429 | } |
| 438 | 430 | ||
| 439 | static ssize_t regulator_suspend_disk_mode_show(struct device *dev, | 431 | static ssize_t regulator_suspend_disk_mode_show(struct device *dev, |
| @@ -443,8 +435,8 @@ static ssize_t regulator_suspend_disk_mode_show(struct device *dev, | |||
| 443 | 435 | ||
| 444 | if (!rdev->constraints) | 436 | if (!rdev->constraints) |
| 445 | return sprintf(buf, "not defined\n"); | 437 | return sprintf(buf, "not defined\n"); |
| 446 | return suspend_opmode_show(rdev, | 438 | return regulator_print_opmode(buf, |
| 447 | rdev->constraints->state_disk.mode, buf); | 439 | rdev->constraints->state_disk.mode); |
| 448 | } | 440 | } |
| 449 | 441 | ||
| 450 | static ssize_t regulator_suspend_standby_mode_show(struct device *dev, | 442 | static ssize_t regulator_suspend_standby_mode_show(struct device *dev, |
| @@ -454,8 +446,8 @@ static ssize_t regulator_suspend_standby_mode_show(struct device *dev, | |||
| 454 | 446 | ||
| 455 | if (!rdev->constraints) | 447 | if (!rdev->constraints) |
| 456 | return sprintf(buf, "not defined\n"); | 448 | return sprintf(buf, "not defined\n"); |
| 457 | return suspend_opmode_show(rdev, | 449 | return regulator_print_opmode(buf, |
| 458 | rdev->constraints->state_standby.mode, buf); | 450 | rdev->constraints->state_standby.mode); |
| 459 | } | 451 | } |
| 460 | 452 | ||
| 461 | static ssize_t regulator_suspend_mem_state_show(struct device *dev, | 453 | static ssize_t regulator_suspend_mem_state_show(struct device *dev, |
| @@ -466,10 +458,8 @@ static ssize_t regulator_suspend_mem_state_show(struct device *dev, | |||
| 466 | if (!rdev->constraints) | 458 | if (!rdev->constraints) |
| 467 | return sprintf(buf, "not defined\n"); | 459 | return sprintf(buf, "not defined\n"); |
| 468 | 460 | ||
| 469 | if (rdev->constraints->state_mem.enabled) | 461 | return regulator_print_state(buf, |
| 470 | return sprintf(buf, "enabled\n"); | 462 | rdev->constraints->state_mem.enabled); |
| 471 | else | ||
| 472 | return sprintf(buf, "disabled\n"); | ||
| 473 | } | 463 | } |
| 474 | 464 | ||
| 475 | static ssize_t regulator_suspend_disk_state_show(struct device *dev, | 465 | static ssize_t regulator_suspend_disk_state_show(struct device *dev, |
| @@ -480,10 +470,8 @@ static ssize_t regulator_suspend_disk_state_show(struct device *dev, | |||
| 480 | if (!rdev->constraints) | 470 | if (!rdev->constraints) |
| 481 | return sprintf(buf, "not defined\n"); | 471 | return sprintf(buf, "not defined\n"); |
| 482 | 472 | ||
| 483 | if (rdev->constraints->state_disk.enabled) | 473 | return regulator_print_state(buf, |
| 484 | return sprintf(buf, "enabled\n"); | 474 | rdev->constraints->state_disk.enabled); |
| 485 | else | ||
| 486 | return sprintf(buf, "disabled\n"); | ||
| 487 | } | 475 | } |
| 488 | 476 | ||
| 489 | static ssize_t regulator_suspend_standby_state_show(struct device *dev, | 477 | static ssize_t regulator_suspend_standby_state_show(struct device *dev, |
| @@ -494,10 +482,8 @@ static ssize_t regulator_suspend_standby_state_show(struct device *dev, | |||
| 494 | if (!rdev->constraints) | 482 | if (!rdev->constraints) |
| 495 | return sprintf(buf, "not defined\n"); | 483 | return sprintf(buf, "not defined\n"); |
| 496 | 484 | ||
| 497 | if (rdev->constraints->state_standby.enabled) | 485 | return regulator_print_state(buf, |
| 498 | return sprintf(buf, "enabled\n"); | 486 | rdev->constraints->state_standby.enabled); |
| 499 | else | ||
| 500 | return sprintf(buf, "disabled\n"); | ||
| 501 | } | 487 | } |
| 502 | 488 | ||
| 503 | static struct device_attribute regulator_dev_attrs[] = { | 489 | static struct device_attribute regulator_dev_attrs[] = { |
| @@ -1773,20 +1759,14 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, | |||
| 1773 | /* preform any regulator specific init */ | 1759 | /* preform any regulator specific init */ |
| 1774 | if (init_data->regulator_init) { | 1760 | if (init_data->regulator_init) { |
| 1775 | ret = init_data->regulator_init(rdev->reg_data); | 1761 | ret = init_data->regulator_init(rdev->reg_data); |
| 1776 | if (ret < 0) { | 1762 | if (ret < 0) |
| 1777 | kfree(rdev); | 1763 | goto clean; |
| 1778 | rdev = ERR_PTR(ret); | ||
| 1779 | goto out; | ||
| 1780 | } | ||
| 1781 | } | 1764 | } |
| 1782 | 1765 | ||
| 1783 | /* set regulator constraints */ | 1766 | /* set regulator constraints */ |
| 1784 | ret = set_machine_constraints(rdev, &init_data->constraints); | 1767 | ret = set_machine_constraints(rdev, &init_data->constraints); |
| 1785 | if (ret < 0) { | 1768 | if (ret < 0) |
| 1786 | kfree(rdev); | 1769 | goto clean; |
| 1787 | rdev = ERR_PTR(ret); | ||
| 1788 | goto out; | ||
| 1789 | } | ||
| 1790 | 1770 | ||
| 1791 | /* register with sysfs */ | 1771 | /* register with sysfs */ |
| 1792 | rdev->dev.class = ®ulator_class; | 1772 | rdev->dev.class = ®ulator_class; |
| @@ -1794,11 +1774,8 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, | |||
| 1794 | dev_set_name(&rdev->dev, "regulator.%d", | 1774 | dev_set_name(&rdev->dev, "regulator.%d", |
| 1795 | atomic_inc_return(®ulator_no) - 1); | 1775 | atomic_inc_return(®ulator_no) - 1); |
| 1796 | ret = device_register(&rdev->dev); | 1776 | ret = device_register(&rdev->dev); |
| 1797 | if (ret != 0) { | 1777 | if (ret != 0) |
| 1798 | kfree(rdev); | 1778 | goto clean; |
| 1799 | rdev = ERR_PTR(ret); | ||
| 1800 | goto out; | ||
| 1801 | } | ||
| 1802 | 1779 | ||
| 1803 | dev_set_drvdata(&rdev->dev, rdev); | 1780 | dev_set_drvdata(&rdev->dev, rdev); |
| 1804 | 1781 | ||
| @@ -1806,12 +1783,8 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, | |||
| 1806 | if (init_data->supply_regulator_dev) { | 1783 | if (init_data->supply_regulator_dev) { |
| 1807 | ret = set_supply(rdev, | 1784 | ret = set_supply(rdev, |
| 1808 | dev_get_drvdata(init_data->supply_regulator_dev)); | 1785 | dev_get_drvdata(init_data->supply_regulator_dev)); |
| 1809 | if (ret < 0) { | 1786 | if (ret < 0) |
| 1810 | device_unregister(&rdev->dev); | 1787 | goto scrub; |
| 1811 | kfree(rdev); | ||
| 1812 | rdev = ERR_PTR(ret); | ||
| 1813 | goto out; | ||
| 1814 | } | ||
| 1815 | } | 1788 | } |
| 1816 | 1789 | ||
| 1817 | /* add consumers devices */ | 1790 | /* add consumers devices */ |
| @@ -1823,10 +1796,7 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, | |||
| 1823 | for (--i; i >= 0; i--) | 1796 | for (--i; i >= 0; i--) |
| 1824 | unset_consumer_device_supply(rdev, | 1797 | unset_consumer_device_supply(rdev, |
| 1825 | init_data->consumer_supplies[i].dev); | 1798 | init_data->consumer_supplies[i].dev); |
| 1826 | device_unregister(&rdev->dev); | 1799 | goto scrub; |
| 1827 | kfree(rdev); | ||
| 1828 | rdev = ERR_PTR(ret); | ||
| 1829 | goto out; | ||
| 1830 | } | 1800 | } |
| 1831 | } | 1801 | } |
| 1832 | 1802 | ||
| @@ -1834,6 +1804,13 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, | |||
| 1834 | out: | 1804 | out: |
| 1835 | mutex_unlock(®ulator_list_mutex); | 1805 | mutex_unlock(®ulator_list_mutex); |
| 1836 | return rdev; | 1806 | return rdev; |
| 1807 | |||
| 1808 | scrub: | ||
| 1809 | device_unregister(&rdev->dev); | ||
| 1810 | clean: | ||
| 1811 | kfree(rdev); | ||
| 1812 | rdev = ERR_PTR(ret); | ||
| 1813 | goto out; | ||
| 1837 | } | 1814 | } |
| 1838 | EXPORT_SYMBOL_GPL(regulator_register); | 1815 | EXPORT_SYMBOL_GPL(regulator_register); |
| 1839 | 1816 | ||
