aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2010-12-10 12:28:07 -0500
committerLiam Girdwood <lrg@slimlogic.co.uk>2011-01-12 09:33:01 -0500
commit476c2d83c7ffb2429b2a504fbdb4326fc8a9d0e8 (patch)
treecdc7b4161bef5aa90a9f375229dc3dc61900ea6c /drivers/regulator
parent1bf5a1f86a328122714680cd59951074b4f31e07 (diff)
regulator: Allow drivers to report voltages as selectors
Since drivers already have to provide an API for translating selectors into voltages they may as well just report the selector values directly to the core API rather than implement the lookup themselves. The old interface is left in place for now, but may be removed in future. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>
Diffstat (limited to 'drivers/regulator')
-rw-r--r--drivers/regulator/core.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 671eb53b5cdc..b362dbde80f7 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -577,7 +577,9 @@ static void drms_uA_update(struct regulator_dev *rdev)
577 577
578 err = regulator_check_drms(rdev); 578 err = regulator_check_drms(rdev);
579 if (err < 0 || !rdev->desc->ops->get_optimum_mode || 579 if (err < 0 || !rdev->desc->ops->get_optimum_mode ||
580 !rdev->desc->ops->get_voltage || !rdev->desc->ops->set_mode) 580 (!rdev->desc->ops->get_voltage &&
581 !rdev->desc->ops->get_voltage_sel) ||
582 !rdev->desc->ops->set_mode)
581 return; 583 return;
582 584
583 /* get output voltage */ 585 /* get output voltage */
@@ -1682,7 +1684,14 @@ EXPORT_SYMBOL_GPL(regulator_set_voltage);
1682 1684
1683static int _regulator_get_voltage(struct regulator_dev *rdev) 1685static int _regulator_get_voltage(struct regulator_dev *rdev)
1684{ 1686{
1685 /* sanity check */ 1687 int sel;
1688
1689 if (rdev->desc->ops->get_voltage_sel) {
1690 sel = rdev->desc->ops->get_voltage_sel(rdev);
1691 if (sel < 0)
1692 return sel;
1693 return rdev->desc->ops->list_voltage(rdev, sel);
1694 }
1686 if (rdev->desc->ops->get_voltage) 1695 if (rdev->desc->ops->get_voltage)
1687 return rdev->desc->ops->get_voltage(rdev); 1696 return rdev->desc->ops->get_voltage(rdev);
1688 else 1697 else
@@ -2191,7 +2200,7 @@ static int add_regulator_attributes(struct regulator_dev *rdev)
2191 int status = 0; 2200 int status = 0;
2192 2201
2193 /* some attributes need specific methods to be displayed */ 2202 /* some attributes need specific methods to be displayed */
2194 if (ops->get_voltage) { 2203 if (ops->get_voltage || ops->get_voltage_sel) {
2195 status = device_create_file(dev, &dev_attr_microvolts); 2204 status = device_create_file(dev, &dev_attr_microvolts);
2196 if (status < 0) 2205 if (status < 0)
2197 return status; 2206 return status;
@@ -2327,6 +2336,16 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
2327 if (!init_data) 2336 if (!init_data)
2328 return ERR_PTR(-EINVAL); 2337 return ERR_PTR(-EINVAL);
2329 2338
2339 /* Only one of each should be implemented */
2340 WARN_ON(regulator_desc->ops->get_voltage &&
2341 regulator_desc->ops->get_voltage_sel);
2342
2343 /* If we're using selectors we must implement list_voltage. */
2344 if (regulator_desc->ops->get_voltage_sel &&
2345 !regulator_desc->ops->list_voltage) {
2346 return ERR_PTR(-EINVAL);
2347 }
2348
2330 rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL); 2349 rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL);
2331 if (rdev == NULL) 2350 if (rdev == NULL)
2332 return ERR_PTR(-ENOMEM); 2351 return ERR_PTR(-ENOMEM);