aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator
diff options
context:
space:
mode:
authorDavid Brownell <dbrownell@users.sourceforge.net>2008-11-11 20:39:02 -0500
committerLiam Girdwood <lrg@slimlogic.co.uk>2009-01-08 15:10:30 -0500
commit7ad68e2f970fd84d15ad67ce3216aed05f944a9c (patch)
treeb7bb5f33e6a6a1d60cc9d2be24a7d2dee36f0f93 /drivers/regulator
parent4fca9545d17b99cdb2774716b034c62a70151bcd (diff)
regulator: sysfs attribute reduction (v2)
Clean up the sysfs interface to regulators by only exposing the attributes that can be properly displayed. For example: when a particular regulator method is needed to display the value, only create that attribute when that method exists. This cleaned-up interface is much more comprehensible. Most regulators only support a subset of the possible methods, so often more than half the attributes would be meaningless. Many "not defined" values are no longer necessary. (But handling of out-of-range values still looks a bit iffy.) Documentation is updated to reflect that few of the attributes are *always* present, and to briefly explain why a regulator may not have a given attribute. This adds object code, about a dozen bytes more than was removed by the preceding patch, but saves a bunch of per-regulator data associated with the now-removed attributes. So there's a net reduction in memory footprint. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>
Diffstat (limited to 'drivers/regulator')
-rw-r--r--drivers/regulator/core.c196
1 files changed, 148 insertions, 48 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 5109f7d4809a..9a5ff97d158d 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -242,6 +242,7 @@ static ssize_t regulator_uV_show(struct device *dev,
242 242
243 return ret; 243 return ret;
244} 244}
245static DEVICE_ATTR(microvolts, 0444, regulator_uV_show, NULL);
245 246
246static ssize_t regulator_uA_show(struct device *dev, 247static ssize_t regulator_uA_show(struct device *dev,
247 struct device_attribute *attr, char *buf) 248 struct device_attribute *attr, char *buf)
@@ -250,6 +251,7 @@ static ssize_t regulator_uA_show(struct device *dev,
250 251
251 return sprintf(buf, "%d\n", _regulator_get_current_limit(rdev)); 252 return sprintf(buf, "%d\n", _regulator_get_current_limit(rdev));
252} 253}
254static DEVICE_ATTR(microamps, 0444, regulator_uA_show, NULL);
253 255
254static ssize_t regulator_name_show(struct device *dev, 256static ssize_t regulator_name_show(struct device *dev,
255 struct device_attribute *attr, char *buf) 257 struct device_attribute *attr, char *buf)
@@ -289,6 +291,7 @@ static ssize_t regulator_opmode_show(struct device *dev,
289 291
290 return regulator_print_opmode(buf, _regulator_get_mode(rdev)); 292 return regulator_print_opmode(buf, _regulator_get_mode(rdev));
291} 293}
294static DEVICE_ATTR(opmode, 0444, regulator_opmode_show, NULL);
292 295
293static ssize_t regulator_print_state(char *buf, int state) 296static ssize_t regulator_print_state(char *buf, int state)
294{ 297{
@@ -307,6 +310,7 @@ static ssize_t regulator_state_show(struct device *dev,
307 310
308 return regulator_print_state(buf, _regulator_is_enabled(rdev)); 311 return regulator_print_state(buf, _regulator_is_enabled(rdev));
309} 312}
313static DEVICE_ATTR(state, 0444, regulator_state_show, NULL);
310 314
311static ssize_t regulator_min_uA_show(struct device *dev, 315static ssize_t regulator_min_uA_show(struct device *dev,
312 struct device_attribute *attr, char *buf) 316 struct device_attribute *attr, char *buf)
@@ -318,6 +322,7 @@ static ssize_t regulator_min_uA_show(struct device *dev,
318 322
319 return sprintf(buf, "%d\n", rdev->constraints->min_uA); 323 return sprintf(buf, "%d\n", rdev->constraints->min_uA);
320} 324}
325static DEVICE_ATTR(min_microamps, 0444, regulator_min_uA_show, NULL);
321 326
322static ssize_t regulator_max_uA_show(struct device *dev, 327static ssize_t regulator_max_uA_show(struct device *dev,
323 struct device_attribute *attr, char *buf) 328 struct device_attribute *attr, char *buf)
@@ -329,6 +334,7 @@ static ssize_t regulator_max_uA_show(struct device *dev,
329 334
330 return sprintf(buf, "%d\n", rdev->constraints->max_uA); 335 return sprintf(buf, "%d\n", rdev->constraints->max_uA);
331} 336}
337static DEVICE_ATTR(max_microamps, 0444, regulator_max_uA_show, NULL);
332 338
333static ssize_t regulator_min_uV_show(struct device *dev, 339static ssize_t regulator_min_uV_show(struct device *dev,
334 struct device_attribute *attr, char *buf) 340 struct device_attribute *attr, char *buf)
@@ -340,6 +346,7 @@ static ssize_t regulator_min_uV_show(struct device *dev,
340 346
341 return sprintf(buf, "%d\n", rdev->constraints->min_uV); 347 return sprintf(buf, "%d\n", rdev->constraints->min_uV);
342} 348}
349static DEVICE_ATTR(min_microvolts, 0444, regulator_min_uV_show, NULL);
343 350
344static ssize_t regulator_max_uV_show(struct device *dev, 351static ssize_t regulator_max_uV_show(struct device *dev,
345 struct device_attribute *attr, char *buf) 352 struct device_attribute *attr, char *buf)
@@ -351,6 +358,7 @@ static ssize_t regulator_max_uV_show(struct device *dev,
351 358
352 return sprintf(buf, "%d\n", rdev->constraints->max_uV); 359 return sprintf(buf, "%d\n", rdev->constraints->max_uV);
353} 360}
361static DEVICE_ATTR(max_microvolts, 0444, regulator_max_uV_show, NULL);
354 362
355static ssize_t regulator_total_uA_show(struct device *dev, 363static ssize_t regulator_total_uA_show(struct device *dev,
356 struct device_attribute *attr, char *buf) 364 struct device_attribute *attr, char *buf)
@@ -365,6 +373,7 @@ static ssize_t regulator_total_uA_show(struct device *dev,
365 mutex_unlock(&rdev->mutex); 373 mutex_unlock(&rdev->mutex);
366 return sprintf(buf, "%d\n", uA); 374 return sprintf(buf, "%d\n", uA);
367} 375}
376static DEVICE_ATTR(requested_microamps, 0444, regulator_total_uA_show, NULL);
368 377
369static ssize_t regulator_num_users_show(struct device *dev, 378static ssize_t regulator_num_users_show(struct device *dev,
370 struct device_attribute *attr, char *buf) 379 struct device_attribute *attr, char *buf)
@@ -392,131 +401,106 @@ static ssize_t regulator_suspend_mem_uV_show(struct device *dev,
392{ 401{
393 struct regulator_dev *rdev = dev_get_drvdata(dev); 402 struct regulator_dev *rdev = dev_get_drvdata(dev);
394 403
395 if (!rdev->constraints)
396 return sprintf(buf, "not defined\n");
397 return sprintf(buf, "%d\n", rdev->constraints->state_mem.uV); 404 return sprintf(buf, "%d\n", rdev->constraints->state_mem.uV);
398} 405}
406static DEVICE_ATTR(suspend_mem_microvolts, 0444,
407 regulator_suspend_mem_uV_show, NULL);
399 408
400static ssize_t regulator_suspend_disk_uV_show(struct device *dev, 409static ssize_t regulator_suspend_disk_uV_show(struct device *dev,
401 struct device_attribute *attr, char *buf) 410 struct device_attribute *attr, char *buf)
402{ 411{
403 struct regulator_dev *rdev = dev_get_drvdata(dev); 412 struct regulator_dev *rdev = dev_get_drvdata(dev);
404 413
405 if (!rdev->constraints)
406 return sprintf(buf, "not defined\n");
407 return sprintf(buf, "%d\n", rdev->constraints->state_disk.uV); 414 return sprintf(buf, "%d\n", rdev->constraints->state_disk.uV);
408} 415}
416static DEVICE_ATTR(suspend_disk_microvolts, 0444,
417 regulator_suspend_disk_uV_show, NULL);
409 418
410static ssize_t regulator_suspend_standby_uV_show(struct device *dev, 419static ssize_t regulator_suspend_standby_uV_show(struct device *dev,
411 struct device_attribute *attr, char *buf) 420 struct device_attribute *attr, char *buf)
412{ 421{
413 struct regulator_dev *rdev = dev_get_drvdata(dev); 422 struct regulator_dev *rdev = dev_get_drvdata(dev);
414 423
415 if (!rdev->constraints)
416 return sprintf(buf, "not defined\n");
417 return sprintf(buf, "%d\n", rdev->constraints->state_standby.uV); 424 return sprintf(buf, "%d\n", rdev->constraints->state_standby.uV);
418} 425}
426static DEVICE_ATTR(suspend_standby_microvolts, 0444,
427 regulator_suspend_standby_uV_show, NULL);
419 428
420static ssize_t regulator_suspend_mem_mode_show(struct device *dev, 429static ssize_t regulator_suspend_mem_mode_show(struct device *dev,
421 struct device_attribute *attr, char *buf) 430 struct device_attribute *attr, char *buf)
422{ 431{
423 struct regulator_dev *rdev = dev_get_drvdata(dev); 432 struct regulator_dev *rdev = dev_get_drvdata(dev);
424 433
425 if (!rdev->constraints)
426 return sprintf(buf, "not defined\n");
427 return regulator_print_opmode(buf, 434 return regulator_print_opmode(buf,
428 rdev->constraints->state_mem.mode); 435 rdev->constraints->state_mem.mode);
429} 436}
437static DEVICE_ATTR(suspend_mem_mode, 0444,
438 regulator_suspend_mem_mode_show, NULL);
430 439
431static ssize_t regulator_suspend_disk_mode_show(struct device *dev, 440static ssize_t regulator_suspend_disk_mode_show(struct device *dev,
432 struct device_attribute *attr, char *buf) 441 struct device_attribute *attr, char *buf)
433{ 442{
434 struct regulator_dev *rdev = dev_get_drvdata(dev); 443 struct regulator_dev *rdev = dev_get_drvdata(dev);
435 444
436 if (!rdev->constraints)
437 return sprintf(buf, "not defined\n");
438 return regulator_print_opmode(buf, 445 return regulator_print_opmode(buf,
439 rdev->constraints->state_disk.mode); 446 rdev->constraints->state_disk.mode);
440} 447}
448static DEVICE_ATTR(suspend_disk_mode, 0444,
449 regulator_suspend_disk_mode_show, NULL);
441 450
442static ssize_t regulator_suspend_standby_mode_show(struct device *dev, 451static ssize_t regulator_suspend_standby_mode_show(struct device *dev,
443 struct device_attribute *attr, char *buf) 452 struct device_attribute *attr, char *buf)
444{ 453{
445 struct regulator_dev *rdev = dev_get_drvdata(dev); 454 struct regulator_dev *rdev = dev_get_drvdata(dev);
446 455
447 if (!rdev->constraints)
448 return sprintf(buf, "not defined\n");
449 return regulator_print_opmode(buf, 456 return regulator_print_opmode(buf,
450 rdev->constraints->state_standby.mode); 457 rdev->constraints->state_standby.mode);
451} 458}
459static DEVICE_ATTR(suspend_standby_mode, 0444,
460 regulator_suspend_standby_mode_show, NULL);
452 461
453static ssize_t regulator_suspend_mem_state_show(struct device *dev, 462static ssize_t regulator_suspend_mem_state_show(struct device *dev,
454 struct device_attribute *attr, char *buf) 463 struct device_attribute *attr, char *buf)
455{ 464{
456 struct regulator_dev *rdev = dev_get_drvdata(dev); 465 struct regulator_dev *rdev = dev_get_drvdata(dev);
457 466
458 if (!rdev->constraints)
459 return sprintf(buf, "not defined\n");
460
461 return regulator_print_state(buf, 467 return regulator_print_state(buf,
462 rdev->constraints->state_mem.enabled); 468 rdev->constraints->state_mem.enabled);
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)
471 return sprintf(buf, "not defined\n");
472
473 return regulator_print_state(buf, 478 return regulator_print_state(buf,
474 rdev->constraints->state_disk.enabled); 479 rdev->constraints->state_disk.enabled);
475} 480}
481static DEVICE_ATTR(suspend_disk_state, 0444,
482 regulator_suspend_disk_state_show, NULL);
476 483
477static ssize_t regulator_suspend_standby_state_show(struct device *dev, 484static ssize_t regulator_suspend_standby_state_show(struct device *dev,
478 struct device_attribute *attr, char *buf) 485 struct device_attribute *attr, char *buf)
479{ 486{
480 struct regulator_dev *rdev = dev_get_drvdata(dev); 487 struct regulator_dev *rdev = dev_get_drvdata(dev);
481 488
482 if (!rdev->constraints)
483 return sprintf(buf, "not defined\n");
484
485 return regulator_print_state(buf, 489 return regulator_print_state(buf,
486 rdev->constraints->state_standby.enabled); 490 rdev->constraints->state_standby.enabled);
487} 491}
492static DEVICE_ATTR(suspend_standby_state, 0444,
493 regulator_suspend_standby_state_show, NULL);
494
488 495
496/*
497 * These are the only attributes are present for all regulators.
498 * Other attributes are a function of regulator functionality.
499 */
489static struct device_attribute regulator_dev_attrs[] = { 500static struct device_attribute regulator_dev_attrs[] = {
490 __ATTR(name, 0444, regulator_name_show, NULL), 501 __ATTR(name, 0444, regulator_name_show, NULL),
491 __ATTR(microvolts, 0444, regulator_uV_show, NULL),
492 __ATTR(microamps, 0444, regulator_uA_show, NULL),
493 __ATTR(opmode, 0444, regulator_opmode_show, NULL),
494 __ATTR(state, 0444, regulator_state_show, NULL),
495 __ATTR(min_microvolts, 0444, regulator_min_uV_show, NULL),
496 __ATTR(min_microamps, 0444, regulator_min_uA_show, NULL),
497 __ATTR(max_microvolts, 0444, regulator_max_uV_show, NULL),
498 __ATTR(max_microamps, 0444, regulator_max_uA_show, NULL),
499 __ATTR(requested_microamps, 0444, regulator_total_uA_show, NULL),
500 __ATTR(num_users, 0444, regulator_num_users_show, NULL), 502 __ATTR(num_users, 0444, regulator_num_users_show, NULL),
501 __ATTR(type, 0444, regulator_type_show, NULL), 503 __ATTR(type, 0444, regulator_type_show, NULL),
502 __ATTR(suspend_mem_microvolts, 0444,
503 regulator_suspend_mem_uV_show, NULL),
504 __ATTR(suspend_disk_microvolts, 0444,
505 regulator_suspend_disk_uV_show, NULL),
506 __ATTR(suspend_standby_microvolts, 0444,
507 regulator_suspend_standby_uV_show, NULL),
508 __ATTR(suspend_mem_mode, 0444,
509 regulator_suspend_mem_mode_show, NULL),
510 __ATTR(suspend_disk_mode, 0444,
511 regulator_suspend_disk_mode_show, NULL),
512 __ATTR(suspend_standby_mode, 0444,
513 regulator_suspend_standby_mode_show, NULL),
514 __ATTR(suspend_mem_state, 0444,
515 regulator_suspend_mem_state_show, NULL),
516 __ATTR(suspend_disk_state, 0444,
517 regulator_suspend_disk_state_show, NULL),
518 __ATTR(suspend_standby_state, 0444,
519 regulator_suspend_standby_state_show, NULL),
520 __ATTR_NULL, 504 __ATTR_NULL,
521}; 505};
522 506
@@ -1711,6 +1695,117 @@ int regulator_notifier_call_chain(struct regulator_dev *rdev,
1711} 1695}
1712EXPORT_SYMBOL_GPL(regulator_notifier_call_chain); 1696EXPORT_SYMBOL_GPL(regulator_notifier_call_chain);
1713 1697
1698/*
1699 * To avoid cluttering sysfs (and memory) with useless state, only
1700 * create attributes that can be meaningfully displayed.
1701 */
1702static int add_regulator_attributes(struct regulator_dev *rdev)
1703{
1704 struct device *dev = &rdev->dev;
1705 struct regulator_ops *ops = rdev->desc->ops;
1706 int status = 0;
1707
1708 /* some attributes need specific methods to be displayed */
1709 if (ops->get_voltage) {
1710 status = device_create_file(dev, &dev_attr_microvolts);
1711 if (status < 0)
1712 return status;
1713 }
1714 if (ops->get_current_limit) {
1715 status = device_create_file(dev, &dev_attr_microamps);
1716 if (status < 0)
1717 return status;
1718 }
1719 if (ops->get_mode) {
1720 status = device_create_file(dev, &dev_attr_opmode);
1721 if (status < 0)
1722 return status;
1723 }
1724 if (ops->is_enabled) {
1725 status = device_create_file(dev, &dev_attr_state);
1726 if (status < 0)
1727 return status;
1728 }
1729
1730 /* some attributes are type-specific */
1731 if (rdev->desc->type == REGULATOR_CURRENT) {
1732 status = device_create_file(dev, &dev_attr_requested_microamps);
1733 if (status < 0)
1734 return status;
1735 }
1736
1737 /* all the other attributes exist to support constraints;
1738 * don't show them if there are no constraints, or if the
1739 * relevant supporting methods are missing.
1740 */
1741 if (!rdev->constraints)
1742 return status;
1743
1744 /* constraints need specific supporting methods */
1745 if (ops->set_voltage) {
1746 status = device_create_file(dev, &dev_attr_min_microvolts);
1747 if (status < 0)
1748 return status;
1749 status = device_create_file(dev, &dev_attr_max_microvolts);
1750 if (status < 0)
1751 return status;
1752 }
1753 if (ops->set_current_limit) {
1754 status = device_create_file(dev, &dev_attr_min_microamps);
1755 if (status < 0)
1756 return status;
1757 status = device_create_file(dev, &dev_attr_max_microamps);
1758 if (status < 0)
1759 return status;
1760 }
1761
1762 /* suspend mode constraints need multiple supporting methods */
1763 if (!(ops->set_suspend_enable && ops->set_suspend_disable))
1764 return status;
1765
1766 status = device_create_file(dev, &dev_attr_suspend_standby_state);
1767 if (status < 0)
1768 return status;
1769 status = device_create_file(dev, &dev_attr_suspend_mem_state);
1770 if (status < 0)
1771 return status;
1772 status = device_create_file(dev, &dev_attr_suspend_disk_state);
1773 if (status < 0)
1774 return status;
1775
1776 if (ops->set_suspend_voltage) {
1777 status = device_create_file(dev,
1778 &dev_attr_suspend_standby_microvolts);
1779 if (status < 0)
1780 return status;
1781 status = device_create_file(dev,
1782 &dev_attr_suspend_mem_microvolts);
1783 if (status < 0)
1784 return status;
1785 status = device_create_file(dev,
1786 &dev_attr_suspend_disk_microvolts);
1787 if (status < 0)
1788 return status;
1789 }
1790
1791 if (ops->set_suspend_mode) {
1792 status = device_create_file(dev,
1793 &dev_attr_suspend_standby_mode);
1794 if (status < 0)
1795 return status;
1796 status = device_create_file(dev,
1797 &dev_attr_suspend_mem_mode);
1798 if (status < 0)
1799 return status;
1800 status = device_create_file(dev,
1801 &dev_attr_suspend_disk_mode);
1802 if (status < 0)
1803 return status;
1804 }
1805
1806 return status;
1807}
1808
1714/** 1809/**
1715 * regulator_register - register regulator 1810 * regulator_register - register regulator
1716 * @regulator: regulator source 1811 * @regulator: regulator source
@@ -1779,6 +1874,11 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
1779 1874
1780 dev_set_drvdata(&rdev->dev, rdev); 1875 dev_set_drvdata(&rdev->dev, rdev);
1781 1876
1877 /* add attributes supported by this regulator */
1878 ret = add_regulator_attributes(rdev);
1879 if (ret < 0)
1880 goto scrub;
1881
1782 /* set supply regulator if it exists */ 1882 /* set supply regulator if it exists */
1783 if (init_data->supply_regulator_dev) { 1883 if (init_data->supply_regulator_dev) {
1784 ret = set_supply(rdev, 1884 ret = set_supply(rdev,