regulator: Add and use rdev_<level> macros

On Tue, 2010-11-30 at 10:52 +0000, Mark Brown wrote:
> On Mon, Nov 29, 2010 at 05:12:56PM -0800, Joe Perches wrote:
> > Just to please broonie...
> > Signed-off-by: Joe Perches <joe@perches.com>
> As usual when fixing review issues please revise your original patch
> rather than posting a fresh patch.

Here's an earlier comment:

On Thu, 2010-11-18 at 13:30 +0000, Mark Brown wrote:
> This looks reasonable, please rebase on top of Daniel's patches and
> submit it properly (with changelog and so on).

Sometimes it's simpler for an upstream maintainer to do
something like:

git am -s <patch1.mbox>
patch -p1 < patch2.mbox
git commit --amend file

instead of back and forthing.

Signed-off-by: Liam Girdwood <lrg@slimlogic.co.uk>
This commit is contained in:
Joe Perches 2010-11-30 05:53:48 -08:00 committed by Liam Girdwood
parent 6220b87bfd
commit 5da84fd99b
1 changed files with 65 additions and 81 deletions

View File

@ -32,6 +32,15 @@
#include "dummy.h" #include "dummy.h"
#define rdev_err(rdev, fmt, ...) \
pr_err("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
#define rdev_warn(rdev, fmt, ...) \
pr_warn("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
#define rdev_info(rdev, fmt, ...) \
pr_info("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
#define rdev_dbg(rdev, fmt, ...) \
pr_debug("%s: " fmt, rdev_get_name(rdev), ##__VA_ARGS__)
static DEFINE_MUTEX(regulator_list_mutex); static DEFINE_MUTEX(regulator_list_mutex);
static LIST_HEAD(regulator_list); static LIST_HEAD(regulator_list);
static LIST_HEAD(regulator_map_list); static LIST_HEAD(regulator_map_list);
@ -114,11 +123,11 @@ static int regulator_check_voltage(struct regulator_dev *rdev,
BUG_ON(*min_uV > *max_uV); BUG_ON(*min_uV > *max_uV);
if (!rdev->constraints) { if (!rdev->constraints) {
pr_err("no constraints for %s\n", rdev_get_name(rdev)); rdev_err(rdev, "no constraints\n");
return -ENODEV; return -ENODEV;
} }
if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) { if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) {
pr_err("operation not allowed for %s\n", rdev_get_name(rdev)); rdev_err(rdev, "operation not allowed\n");
return -EPERM; return -EPERM;
} }
@ -140,11 +149,11 @@ static int regulator_check_current_limit(struct regulator_dev *rdev,
BUG_ON(*min_uA > *max_uA); BUG_ON(*min_uA > *max_uA);
if (!rdev->constraints) { if (!rdev->constraints) {
pr_err("no constraints for %s\n", rdev_get_name(rdev)); rdev_err(rdev, "no constraints\n");
return -ENODEV; return -ENODEV;
} }
if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_CURRENT)) { if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_CURRENT)) {
pr_err("operation not allowed for %s\n", rdev_get_name(rdev)); rdev_err(rdev, "operation not allowed\n");
return -EPERM; return -EPERM;
} }
@ -173,15 +182,15 @@ static int regulator_check_mode(struct regulator_dev *rdev, int mode)
} }
if (!rdev->constraints) { if (!rdev->constraints) {
pr_err("no constraints for %s\n", rdev_get_name(rdev)); rdev_err(rdev, "no constraints\n");
return -ENODEV; return -ENODEV;
} }
if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_MODE)) { if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_MODE)) {
pr_err("operation not allowed for %s\n", rdev_get_name(rdev)); rdev_err(rdev, "operation not allowed\n");
return -EPERM; return -EPERM;
} }
if (!(rdev->constraints->valid_modes_mask & mode)) { if (!(rdev->constraints->valid_modes_mask & mode)) {
pr_err("invalid mode %x for %s\n", mode, rdev_get_name(rdev)); rdev_err(rdev, "invalid mode %x\n", mode);
return -EINVAL; return -EINVAL;
} }
return 0; return 0;
@ -191,11 +200,11 @@ static int regulator_check_mode(struct regulator_dev *rdev, int mode)
static int regulator_check_drms(struct regulator_dev *rdev) static int regulator_check_drms(struct regulator_dev *rdev)
{ {
if (!rdev->constraints) { if (!rdev->constraints) {
pr_err("no constraints for %s\n", rdev_get_name(rdev)); rdev_err(rdev, "no constraints\n");
return -ENODEV; return -ENODEV;
} }
if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS)) { if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS)) {
pr_err("operation not allowed for %s\n", rdev_get_name(rdev)); rdev_err(rdev, "operation not allowed\n");
return -EPERM; return -EPERM;
} }
return 0; return 0;
@ -592,18 +601,17 @@ static int suspend_set_state(struct regulator_dev *rdev,
*/ */
if (!rstate->enabled && !rstate->disabled) { if (!rstate->enabled && !rstate->disabled) {
if (can_set_state) if (can_set_state)
pr_warning("No configuration for %s\n", rdev_warn(rdev, "No configuration\n");
rdev_get_name(rdev));
return 0; return 0;
} }
if (rstate->enabled && rstate->disabled) { if (rstate->enabled && rstate->disabled) {
pr_err("invalid configuration for %s\n", rdev_get_name(rdev)); rdev_err(rdev, "invalid configuration\n");
return -EINVAL; return -EINVAL;
} }
if (!can_set_state) { if (!can_set_state) {
pr_err("no way to set suspend state\n"); rdev_err(rdev, "no way to set suspend state\n");
return -EINVAL; return -EINVAL;
} }
@ -612,14 +620,14 @@ static int suspend_set_state(struct regulator_dev *rdev,
else else
ret = rdev->desc->ops->set_suspend_disable(rdev); ret = rdev->desc->ops->set_suspend_disable(rdev);
if (ret < 0) { if (ret < 0) {
pr_err("failed to enabled/disable\n"); rdev_err(rdev, "failed to enabled/disable\n");
return ret; return ret;
} }
if (rdev->desc->ops->set_suspend_voltage && rstate->uV > 0) { if (rdev->desc->ops->set_suspend_voltage && rstate->uV > 0) {
ret = rdev->desc->ops->set_suspend_voltage(rdev, rstate->uV); ret = rdev->desc->ops->set_suspend_voltage(rdev, rstate->uV);
if (ret < 0) { if (ret < 0) {
pr_err("failed to set voltage\n"); rdev_err(rdev, "failed to set voltage\n");
return ret; return ret;
} }
} }
@ -627,7 +635,7 @@ static int suspend_set_state(struct regulator_dev *rdev,
if (rdev->desc->ops->set_suspend_mode && rstate->mode > 0) { if (rdev->desc->ops->set_suspend_mode && rstate->mode > 0) {
ret = rdev->desc->ops->set_suspend_mode(rdev, rstate->mode); ret = rdev->desc->ops->set_suspend_mode(rdev, rstate->mode);
if (ret < 0) { if (ret < 0) {
pr_err("failed to set mode\n"); rdev_err(rdev, "failed to set mode\n");
return ret; return ret;
} }
} }
@ -705,14 +713,13 @@ static void print_constraints(struct regulator_dev *rdev)
if (constraints->valid_modes_mask & REGULATOR_MODE_STANDBY) if (constraints->valid_modes_mask & REGULATOR_MODE_STANDBY)
count += sprintf(buf + count, "standby"); count += sprintf(buf + count, "standby");
printk(KERN_INFO "regulator: %s: %s\n", rdev_get_name(rdev), buf); rdev_info(rdev, "regulator: %s\n", buf);
} }
static int machine_constraints_voltage(struct regulator_dev *rdev, static int machine_constraints_voltage(struct regulator_dev *rdev,
struct regulation_constraints *constraints) struct regulation_constraints *constraints)
{ {
struct regulator_ops *ops = rdev->desc->ops; struct regulator_ops *ops = rdev->desc->ops;
const char *name = rdev_get_name(rdev);
int ret; int ret;
unsigned selector; unsigned selector;
@ -725,8 +732,8 @@ static int machine_constraints_voltage(struct regulator_dev *rdev,
rdev->constraints->max_uV, rdev->constraints->max_uV,
&selector); &selector);
if (ret < 0) { if (ret < 0) {
pr_err("failed to apply %duV constraint to %s\n", rdev_err(rdev, "failed to apply %duV constraint\n",
rdev->constraints->min_uV, name); rdev->constraints->min_uV);
rdev->constraints = NULL; rdev->constraints = NULL;
return ret; return ret;
} }
@ -758,8 +765,7 @@ static int machine_constraints_voltage(struct regulator_dev *rdev,
/* else require explicit machine-level constraints */ /* else require explicit machine-level constraints */
if (cmin <= 0 || cmax <= 0 || cmax < cmin) { if (cmin <= 0 || cmax <= 0 || cmax < cmin) {
pr_err("invalid '%s' voltage constraints\n", rdev_err(rdev, "invalid voltage constraints\n");
name);
return -EINVAL; return -EINVAL;
} }
@ -780,20 +786,19 @@ static int machine_constraints_voltage(struct regulator_dev *rdev,
/* final: [min_uV..max_uV] valid iff constraints valid */ /* final: [min_uV..max_uV] valid iff constraints valid */
if (max_uV < min_uV) { if (max_uV < min_uV) {
pr_err("unsupportable '%s' voltage constraints\n", rdev_err(rdev, "unsupportable voltage constraints\n");
name);
return -EINVAL; return -EINVAL;
} }
/* use regulator's subset of machine constraints */ /* use regulator's subset of machine constraints */
if (constraints->min_uV < min_uV) { if (constraints->min_uV < min_uV) {
pr_debug("override '%s' min_uV, %d -> %d\n", rdev_dbg(rdev, "override min_uV, %d -> %d\n",
name, constraints->min_uV, min_uV); constraints->min_uV, min_uV);
constraints->min_uV = min_uV; constraints->min_uV = min_uV;
} }
if (constraints->max_uV > max_uV) { if (constraints->max_uV > max_uV) {
pr_debug("override '%s' max_uV, %d -> %d\n", rdev_dbg(rdev, "override max_uV, %d -> %d\n",
name, constraints->max_uV, max_uV); constraints->max_uV, max_uV);
constraints->max_uV = max_uV; constraints->max_uV = max_uV;
} }
} }
@ -816,7 +821,6 @@ static int set_machine_constraints(struct regulator_dev *rdev,
const struct regulation_constraints *constraints) const struct regulation_constraints *constraints)
{ {
int ret = 0; int ret = 0;
const char *name;
struct regulator_ops *ops = rdev->desc->ops; struct regulator_ops *ops = rdev->desc->ops;
rdev->constraints = kmemdup(constraints, sizeof(*constraints), rdev->constraints = kmemdup(constraints, sizeof(*constraints),
@ -824,8 +828,6 @@ static int set_machine_constraints(struct regulator_dev *rdev,
if (!rdev->constraints) if (!rdev->constraints)
return -ENOMEM; return -ENOMEM;
name = rdev_get_name(rdev);
ret = machine_constraints_voltage(rdev, rdev->constraints); ret = machine_constraints_voltage(rdev, rdev->constraints);
if (ret != 0) if (ret != 0)
goto out; goto out;
@ -834,8 +836,7 @@ static int set_machine_constraints(struct regulator_dev *rdev,
if (constraints->initial_state) { if (constraints->initial_state) {
ret = suspend_prepare(rdev, rdev->constraints->initial_state); ret = suspend_prepare(rdev, rdev->constraints->initial_state);
if (ret < 0) { if (ret < 0) {
pr_err("failed to set suspend state for %s\n", rdev_err(rdev, "failed to set suspend state\n");
name);
rdev->constraints = NULL; rdev->constraints = NULL;
goto out; goto out;
} }
@ -843,16 +844,14 @@ static int set_machine_constraints(struct regulator_dev *rdev,
if (constraints->initial_mode) { if (constraints->initial_mode) {
if (!ops->set_mode) { if (!ops->set_mode) {
pr_err("no set_mode operation for %s\n", rdev_err(rdev, "no set_mode operation\n");
name);
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
ret = ops->set_mode(rdev, rdev->constraints->initial_mode); ret = ops->set_mode(rdev, rdev->constraints->initial_mode);
if (ret < 0) { if (ret < 0) {
pr_err("failed to set initial mode for %s: %d\n", rdev_err(rdev, "failed to set initial mode: %d\n", ret);
name, ret);
goto out; goto out;
} }
} }
@ -864,7 +863,7 @@ static int set_machine_constraints(struct regulator_dev *rdev,
ops->enable) { ops->enable) {
ret = ops->enable(rdev); ret = ops->enable(rdev);
if (ret < 0) { if (ret < 0) {
pr_err("failed to enable %s\n", name); rdev_err(rdev, "failed to enable\n");
rdev->constraints = NULL; rdev->constraints = NULL;
goto out; goto out;
} }
@ -892,8 +891,8 @@ static int set_supply(struct regulator_dev *rdev,
err = sysfs_create_link(&rdev->dev.kobj, &supply_rdev->dev.kobj, err = sysfs_create_link(&rdev->dev.kobj, &supply_rdev->dev.kobj,
"supply"); "supply");
if (err) { if (err) {
pr_err("could not add device link %s err %d\n", rdev_err(rdev, "could not add device link %s err %d\n",
supply_rdev->dev.kobj.name, err); supply_rdev->dev.kobj.name, err);
goto out; goto out;
} }
rdev->supply = supply_rdev; rdev->supply = supply_rdev;
@ -949,10 +948,10 @@ static int set_consumer_device_supply(struct regulator_dev *rdev,
continue; continue;
dev_dbg(consumer_dev, "%s/%s is '%s' supply; fail %s/%s\n", dev_dbg(consumer_dev, "%s/%s is '%s' supply; fail %s/%s\n",
dev_name(&node->regulator->dev), dev_name(&node->regulator->dev),
node->regulator->desc->name, node->regulator->desc->name,
supply, supply,
dev_name(&rdev->dev), rdev_get_name(rdev)); dev_name(&rdev->dev), rdev_get_name(rdev));
return -EBUSY; return -EBUSY;
} }
@ -1023,8 +1022,7 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
regulator->dev_attr.show = device_requested_uA_show; regulator->dev_attr.show = device_requested_uA_show;
err = device_create_file(dev, &regulator->dev_attr); err = device_create_file(dev, &regulator->dev_attr);
if (err < 0) { if (err < 0) {
pr_warning("could not add regulator_dev" rdev_warn(rdev, "could not add regulator_dev requested microamps sysfs entry\n");
" requested microamps sysfs entry\n");
goto attr_name_err; goto attr_name_err;
} }
@ -1041,8 +1039,8 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
err = sysfs_create_link(&rdev->dev.kobj, &dev->kobj, err = sysfs_create_link(&rdev->dev.kobj, &dev->kobj,
buf); buf);
if (err) { if (err) {
pr_warning("could not add device link %s err %d\n", rdev_warn(rdev, "could not add device link %s err %d\n",
dev->kobj.name, err); dev->kobj.name, err);
goto link_name_err; goto link_name_err;
} }
} }
@ -1079,7 +1077,7 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,
int ret; int ret;
if (id == NULL) { if (id == NULL) {
pr_err("regulator: get() with no identifier\n"); pr_err("get() with no identifier\n");
return regulator; return regulator;
} }
@ -1113,8 +1111,8 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,
* substitute in a dummy regulator so consumers can continue. * substitute in a dummy regulator so consumers can continue.
*/ */
if (!has_full_constraints) { if (!has_full_constraints) {
pr_warning("%s supply %s not found, using dummy regulator\n", pr_warn("%s supply %s not found, using dummy regulator\n",
devname, id); devname, id);
rdev = dummy_regulator_rdev; rdev = dummy_regulator_rdev;
goto found; goto found;
} }
@ -1265,8 +1263,7 @@ static int _regulator_enable(struct regulator_dev *rdev)
ret = _regulator_enable(rdev->supply); ret = _regulator_enable(rdev->supply);
mutex_unlock(&rdev->supply->mutex); mutex_unlock(&rdev->supply->mutex);
if (ret < 0) { if (ret < 0) {
pr_err("failed to enable %s: %d\n", rdev_err(rdev, "failed to enable: %d\n", ret);
rdev_get_name(rdev), ret);
return ret; return ret;
} }
} }
@ -1293,8 +1290,7 @@ static int _regulator_enable(struct regulator_dev *rdev)
if (ret >= 0) { if (ret >= 0) {
delay = ret; delay = ret;
} else { } else {
pr_warning("enable_time() failed for %s: %d\n", rdev_warn(rdev, "enable_time() failed: %d\n",
rdev_get_name(rdev),
ret); ret);
delay = 0; delay = 0;
} }
@ -1320,8 +1316,7 @@ static int _regulator_enable(struct regulator_dev *rdev)
trace_regulator_enable_complete(rdev_get_name(rdev)); trace_regulator_enable_complete(rdev_get_name(rdev));
} else if (ret < 0) { } else if (ret < 0) {
pr_err("is_enabled() failed for %s: %d\n", rdev_err(rdev, "is_enabled() failed: %d\n", ret);
rdev_get_name(rdev), ret);
return ret; return ret;
} }
/* Fallthrough on positive return values - already enabled */ /* Fallthrough on positive return values - already enabled */
@ -1378,8 +1373,7 @@ static int _regulator_disable(struct regulator_dev *rdev,
ret = rdev->desc->ops->disable(rdev); ret = rdev->desc->ops->disable(rdev);
if (ret < 0) { if (ret < 0) {
pr_err("failed to disable %s\n", rdev_err(rdev, "failed to disable\n");
rdev_get_name(rdev));
return ret; return ret;
} }
@ -1451,8 +1445,7 @@ static int _regulator_force_disable(struct regulator_dev *rdev,
/* ah well, who wants to live forever... */ /* ah well, who wants to live forever... */
ret = rdev->desc->ops->disable(rdev); ret = rdev->desc->ops->disable(rdev);
if (ret < 0) { if (ret < 0) {
pr_err("failed to force disable %s\n", rdev_err(rdev, "failed to force disable\n");
rdev_get_name(rdev));
return ret; return ret;
} }
/* notify other consumers that power has been forced off */ /* notify other consumers that power has been forced off */
@ -1893,8 +1886,7 @@ int regulator_set_optimum_mode(struct regulator *regulator, int uA_load)
/* get output voltage */ /* get output voltage */
output_uV = rdev->desc->ops->get_voltage(rdev); output_uV = rdev->desc->ops->get_voltage(rdev);
if (output_uV <= 0) { if (output_uV <= 0) {
pr_err("invalid output voltage found for %s\n", rdev_err(rdev, "invalid output voltage found\n");
rdev_get_name(rdev));
goto out; goto out;
} }
@ -1904,8 +1896,7 @@ int regulator_set_optimum_mode(struct regulator *regulator, int uA_load)
else else
input_uV = rdev->constraints->input_uV; input_uV = rdev->constraints->input_uV;
if (input_uV <= 0) { if (input_uV <= 0) {
pr_err("invalid input voltage found for %s\n", rdev_err(rdev, "invalid input voltage found\n");
rdev_get_name(rdev));
goto out; goto out;
} }
@ -1918,16 +1909,14 @@ int regulator_set_optimum_mode(struct regulator *regulator, int uA_load)
total_uA_load); total_uA_load);
ret = regulator_check_mode(rdev, mode); ret = regulator_check_mode(rdev, mode);
if (ret < 0) { if (ret < 0) {
pr_err("failed to get optimum mode for %s @" rdev_err(rdev, "failed to get optimum mode @ %d uA %d -> %d uV\n",
" %d uA %d -> %d uV\n", rdev_get_name(rdev), total_uA_load, input_uV, output_uV);
total_uA_load, input_uV, output_uV);
goto out; goto out;
} }
ret = rdev->desc->ops->set_mode(rdev, mode); ret = rdev->desc->ops->set_mode(rdev, mode);
if (ret < 0) { if (ret < 0) {
pr_err("failed to set optimum mode %x for %s\n", rdev_err(rdev, "failed to set optimum mode %x\n", mode);
mode, rdev_get_name(rdev));
goto out; goto out;
} }
ret = mode; ret = mode;
@ -2058,7 +2047,7 @@ int regulator_bulk_enable(int num_consumers,
return 0; return 0;
err: err:
printk(KERN_ERR "Failed to enable %s: %d\n", consumers[i].supply, ret); pr_err("Failed to enable %s: %d\n", consumers[i].supply, ret);
for (--i; i >= 0; --i) for (--i; i >= 0; --i)
regulator_disable(consumers[i].consumer); regulator_disable(consumers[i].consumer);
@ -2093,8 +2082,7 @@ int regulator_bulk_disable(int num_consumers,
return 0; return 0;
err: err:
printk(KERN_ERR "Failed to disable %s: %d\n", consumers[i].supply, pr_err("Failed to disable %s: %d\n", consumers[i].supply, ret);
ret);
for (--i; i >= 0; --i) for (--i; i >= 0; --i)
regulator_enable(consumers[i].consumer); regulator_enable(consumers[i].consumer);
@ -2477,7 +2465,7 @@ int regulator_suspend_prepare(suspend_state_t state)
mutex_unlock(&rdev->mutex); mutex_unlock(&rdev->mutex);
if (ret < 0) { if (ret < 0) {
pr_err("failed to prepare %s\n", rdev_get_name(rdev)); rdev_err(rdev, "failed to prepare\n");
goto out; goto out;
} }
} }
@ -2599,7 +2587,6 @@ static int __init regulator_init_complete(void)
struct regulator_ops *ops; struct regulator_ops *ops;
struct regulation_constraints *c; struct regulation_constraints *c;
int enabled, ret; int enabled, ret;
const char *name;
mutex_lock(&regulator_list_mutex); mutex_lock(&regulator_list_mutex);
@ -2611,8 +2598,6 @@ static int __init regulator_init_complete(void)
ops = rdev->desc->ops; ops = rdev->desc->ops;
c = rdev->constraints; c = rdev->constraints;
name = rdev_get_name(rdev);
if (!ops->disable || (c && c->always_on)) if (!ops->disable || (c && c->always_on))
continue; continue;
@ -2633,10 +2618,10 @@ static int __init regulator_init_complete(void)
if (has_full_constraints) { if (has_full_constraints) {
/* We log since this may kill the system if it /* We log since this may kill the system if it
* goes wrong. */ * goes wrong. */
pr_info("disabling %s\n", name); rdev_info(rdev, "disabling\n");
ret = ops->disable(rdev); ret = ops->disable(rdev);
if (ret != 0) { if (ret != 0) {
pr_err("couldn't disable %s: %d\n", name, ret); rdev_err(rdev, "couldn't disable: %d\n", ret);
} }
} else { } else {
/* The intention is that in future we will /* The intention is that in future we will
@ -2644,8 +2629,7 @@ static int __init regulator_init_complete(void)
* so warn even if we aren't going to do * so warn even if we aren't going to do
* anything here. * anything here.
*/ */
pr_warning("incomplete constraints, leaving %s on\n", rdev_warn(rdev, "incomplete constraints, leaving on\n");
name);
} }
unlock: unlock: