ALSA: usb-audio: add support for Akai MPD16
[safe/jmp/linux-2.6] / drivers / regulator / core.c
index e11c222..51cf2bb 100644 (file)
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/device.h>
+#include <linux/slab.h>
 #include <linux/err.h>
 #include <linux/mutex.h>
 #include <linux/suspend.h>
+#include <linux/delay.h>
 #include <linux/regulator/consumer.h>
 #include <linux/regulator/driver.h>
 #include <linux/regulator/machine.h>
 
+#include "dummy.h"
+
 #define REGULATOR_VERSION "0.5"
 
 static DEFINE_MUTEX(regulator_list_mutex);
@@ -66,6 +70,16 @@ static unsigned int _regulator_get_mode(struct regulator_dev *rdev);
 static void _notifier_call_chain(struct regulator_dev *rdev,
                                  unsigned long event, void *data);
 
+static const char *rdev_get_name(struct regulator_dev *rdev)
+{
+       if (rdev->constraints && rdev->constraints->name)
+               return rdev->constraints->name;
+       else if (rdev->desc->name)
+               return rdev->desc->name;
+       else
+               return "";
+}
+
 /* gets the regulator for a given consumer device */
 static struct regulator *get_device_regulator(struct device *dev)
 {
@@ -96,12 +110,12 @@ static int regulator_check_voltage(struct regulator_dev *rdev,
 
        if (!rdev->constraints) {
                printk(KERN_ERR "%s: no constraints for %s\n", __func__,
-                      rdev->desc->name);
+                      rdev_get_name(rdev));
                return -ENODEV;
        }
        if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) {
                printk(KERN_ERR "%s: operation not allowed for %s\n",
-                      __func__, rdev->desc->name);
+                      __func__, rdev_get_name(rdev));
                return -EPERM;
        }
 
@@ -124,12 +138,12 @@ static int regulator_check_current_limit(struct regulator_dev *rdev,
 
        if (!rdev->constraints) {
                printk(KERN_ERR "%s: no constraints for %s\n", __func__,
-                      rdev->desc->name);
+                      rdev_get_name(rdev));
                return -ENODEV;
        }
        if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_CURRENT)) {
                printk(KERN_ERR "%s: operation not allowed for %s\n",
-                      __func__, rdev->desc->name);
+                      __func__, rdev_get_name(rdev));
                return -EPERM;
        }
 
@@ -159,17 +173,17 @@ static int regulator_check_mode(struct regulator_dev *rdev, int mode)
 
        if (!rdev->constraints) {
                printk(KERN_ERR "%s: no constraints for %s\n", __func__,
-                      rdev->desc->name);
+                      rdev_get_name(rdev));
                return -ENODEV;
        }
        if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_MODE)) {
                printk(KERN_ERR "%s: operation not allowed for %s\n",
-                      __func__, rdev->desc->name);
+                      __func__, rdev_get_name(rdev));
                return -EPERM;
        }
        if (!(rdev->constraints->valid_modes_mask & mode)) {
                printk(KERN_ERR "%s: invalid mode %x for %s\n",
-                      __func__, mode, rdev->desc->name);
+                      __func__, mode, rdev_get_name(rdev));
                return -EINVAL;
        }
        return 0;
@@ -180,12 +194,12 @@ static int regulator_check_drms(struct regulator_dev *rdev)
 {
        if (!rdev->constraints) {
                printk(KERN_ERR "%s: no constraints for %s\n", __func__,
-                      rdev->desc->name);
+                      rdev_get_name(rdev));
                return -ENODEV;
        }
        if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS)) {
                printk(KERN_ERR "%s: operation not allowed for %s\n",
-                      __func__, rdev->desc->name);
+                      __func__, rdev_get_name(rdev));
                return -EPERM;
        }
        return 0;
@@ -230,16 +244,8 @@ static ssize_t regulator_name_show(struct device *dev,
                             struct device_attribute *attr, char *buf)
 {
        struct regulator_dev *rdev = dev_get_drvdata(dev);
-       const char *name;
 
-       if (rdev->constraints->name)
-               name = rdev->constraints->name;
-       else if (rdev->desc->name)
-               name = rdev->desc->name;
-       else
-               name = "";
-
-       return sprintf(buf, "%s\n", name);
+       return sprintf(buf, "%s\n", rdev_get_name(rdev));
 }
 
 static ssize_t regulator_print_opmode(char *buf, int mode)
@@ -280,8 +286,13 @@ static ssize_t regulator_state_show(struct device *dev,
                                   struct device_attribute *attr, char *buf)
 {
        struct regulator_dev *rdev = dev_get_drvdata(dev);
+       ssize_t ret;
 
-       return regulator_print_state(buf, _regulator_is_enabled(rdev));
+       mutex_lock(&rdev->mutex);
+       ret = regulator_print_state(buf, _regulator_is_enabled(rdev));
+       mutex_unlock(&rdev->mutex);
+
+       return ret;
 }
 static DEVICE_ATTR(state, 0444, regulator_state_show, NULL);
 
@@ -383,7 +394,7 @@ static ssize_t regulator_total_uA_show(struct device *dev,
 
        mutex_lock(&rdev->mutex);
        list_for_each_entry(regulator, &rdev->consumer_list, list)
-           uA += regulator->uA_load;
+               uA += regulator->uA_load;
        mutex_unlock(&rdev->mutex);
        return sprintf(buf, "%d\n", uA);
 }
@@ -558,7 +569,7 @@ static void drms_uA_update(struct regulator_dev *rdev)
 
        /* calc total requested load */
        list_for_each_entry(sibling, &rdev->consumer_list, list)
-           current_uA += sibling->uA_load;
+               current_uA += sibling->uA_load;
 
        /* now get the optimum mode for our new total regulator load */
        mode = rdev->desc->ops->get_optimum_mode(rdev, input_uV,
@@ -574,10 +585,29 @@ static int suspend_set_state(struct regulator_dev *rdev,
        struct regulator_state *rstate)
 {
        int ret = 0;
+       bool can_set_state;
+
+       can_set_state = rdev->desc->ops->set_suspend_enable &&
+               rdev->desc->ops->set_suspend_disable;
+
+       /* If we have no suspend mode configration don't set anything;
+        * only warn if the driver actually makes the suspend mode
+        * configurable.
+        */
+       if (!rstate->enabled && !rstate->disabled) {
+               if (can_set_state)
+                       printk(KERN_WARNING "%s: No configuration for %s\n",
+                              __func__, rdev_get_name(rdev));
+               return 0;
+       }
+
+       if (rstate->enabled && rstate->disabled) {
+               printk(KERN_ERR "%s: invalid configuration for %s\n",
+                      __func__, rdev_get_name(rdev));
+               return -EINVAL;
+       }
 
-       /* enable & disable are mandatory for suspend control */
-       if (!rdev->desc->ops->set_suspend_enable ||
-               !rdev->desc->ops->set_suspend_disable) {
+       if (!can_set_state) {
                printk(KERN_ERR "%s: no way to set suspend state\n",
                        __func__);
                return -EINVAL;
@@ -635,26 +665,44 @@ static int suspend_prepare(struct regulator_dev *rdev, suspend_state_t state)
 static void print_constraints(struct regulator_dev *rdev)
 {
        struct regulation_constraints *constraints = rdev->constraints;
-       char buf[80];
-       int count;
+       char buf[80] = "";
+       int count = 0;
+       int ret;
 
-       if (rdev->desc->type == REGULATOR_VOLTAGE) {
+       if (constraints->min_uV && constraints->max_uV) {
                if (constraints->min_uV == constraints->max_uV)
-                       count = sprintf(buf, "%d mV ",
-                                       constraints->min_uV / 1000);
+                       count += sprintf(buf + count, "%d mV ",
+                                        constraints->min_uV / 1000);
                else
-                       count = sprintf(buf, "%d <--> %d mV ",
-                                       constraints->min_uV / 1000,
-                                       constraints->max_uV / 1000);
-       } else {
+                       count += sprintf(buf + count, "%d <--> %d mV ",
+                                        constraints->min_uV / 1000,
+                                        constraints->max_uV / 1000);
+       }
+
+       if (!constraints->min_uV ||
+           constraints->min_uV != constraints->max_uV) {
+               ret = _regulator_get_voltage(rdev);
+               if (ret > 0)
+                       count += sprintf(buf + count, "at %d mV ", ret / 1000);
+       }
+
+       if (constraints->min_uA && constraints->max_uA) {
                if (constraints->min_uA == constraints->max_uA)
-                       count = sprintf(buf, "%d mA ",
-                                       constraints->min_uA / 1000);
+                       count += sprintf(buf + count, "%d mA ",
+                                        constraints->min_uA / 1000);
                else
-                       count = sprintf(buf, "%d <--> %d mA ",
-                                       constraints->min_uA / 1000,
-                                       constraints->max_uA / 1000);
+                       count += sprintf(buf + count, "%d <--> %d mA ",
+                                        constraints->min_uA / 1000,
+                                        constraints->max_uA / 1000);
        }
+
+       if (!constraints->min_uA ||
+           constraints->min_uA != constraints->max_uA) {
+               ret = _regulator_get_current_limit(rdev);
+               if (ret > 0)
+                       count += sprintf(buf + count, "at %d uA ", ret / 1000);
+       }
+
        if (constraints->valid_modes_mask & REGULATOR_MODE_FAST)
                count += sprintf(buf + count, "fast ");
        if (constraints->valid_modes_mask & REGULATOR_MODE_NORMAL)
@@ -664,33 +712,30 @@ static void print_constraints(struct regulator_dev *rdev)
        if (constraints->valid_modes_mask & REGULATOR_MODE_STANDBY)
                count += sprintf(buf + count, "standby");
 
-       printk(KERN_INFO "regulator: %s: %s\n", rdev->desc->name, buf);
+       printk(KERN_INFO "regulator: %s: %s\n", rdev_get_name(rdev), buf);
 }
 
-/**
- * set_machine_constraints - sets regulator constraints
- * @rdev: regulator source
- * @constraints: constraints to apply
- *
- * Allows platform initialisation code to define and constrain
- * regulator circuits e.g. valid voltage/current ranges, etc.  NOTE:
- * Constraints *must* be set by platform code in order for some
- * regulator operations to proceed i.e. set_voltage, set_current_limit,
- * set_mode.
- */
-static int set_machine_constraints(struct regulator_dev *rdev,
+static int machine_constraints_voltage(struct regulator_dev *rdev,
        struct regulation_constraints *constraints)
 {
-       int ret = 0;
-       const char *name;
        struct regulator_ops *ops = rdev->desc->ops;
+       const char *name = rdev_get_name(rdev);
+       int ret;
 
-       if (constraints->name)
-               name = constraints->name;
-       else if (rdev->desc->name)
-               name = rdev->desc->name;
-       else
-               name = "regulator";
+       /* do we need to apply the constraint voltage */
+       if (rdev->constraints->apply_uV &&
+               rdev->constraints->min_uV == rdev->constraints->max_uV &&
+               ops->set_voltage) {
+               ret = ops->set_voltage(rdev,
+                       rdev->constraints->min_uV, rdev->constraints->max_uV);
+                       if (ret < 0) {
+                               printk(KERN_ERR "%s: failed to apply %duV constraint to %s\n",
+                                      __func__,
+                                      rdev->constraints->min_uV, name);
+                               rdev->constraints = NULL;
+                               return ret;
+                       }
+       }
 
        /* constrain machine-level voltage specs to fit
         * the actual range supported by this regulator.
@@ -714,14 +759,13 @@ static int set_machine_constraints(struct regulator_dev *rdev,
 
                /* voltage constraints are optional */
                if ((cmin == 0) && (cmax == 0))
-                       goto out;
+                       return 0;
 
                /* else require explicit machine-level constraints */
                if (cmin <= 0 || cmax <= 0 || cmax < cmin) {
                        pr_err("%s: %s '%s' voltage constraints\n",
                                       __func__, "invalid", name);
-                       ret = -EINVAL;
-                       goto out;
+                       return -EINVAL;
                }
 
                /* initial: [cmin..cmax] valid, [min_uV..max_uV] not */
@@ -743,8 +787,7 @@ static int set_machine_constraints(struct regulator_dev *rdev,
                if (max_uV < min_uV) {
                        pr_err("%s: %s '%s' voltage constraints\n",
                                       __func__, "unsupportable", name);
-                       ret = -EINVAL;
-                       goto out;
+                       return -EINVAL;
                }
 
                /* use regulator's subset of machine constraints */
@@ -762,22 +805,34 @@ static int set_machine_constraints(struct regulator_dev *rdev,
                }
        }
 
+       return 0;
+}
+
+/**
+ * set_machine_constraints - sets regulator constraints
+ * @rdev: regulator source
+ * @constraints: constraints to apply
+ *
+ * Allows platform initialisation code to define and constrain
+ * regulator circuits e.g. valid voltage/current ranges, etc.  NOTE:
+ * Constraints *must* be set by platform code in order for some
+ * regulator operations to proceed i.e. set_voltage, set_current_limit,
+ * set_mode.
+ */
+static int set_machine_constraints(struct regulator_dev *rdev,
+       struct regulation_constraints *constraints)
+{
+       int ret = 0;
+       const char *name;
+       struct regulator_ops *ops = rdev->desc->ops;
+
        rdev->constraints = constraints;
 
-       /* do we need to apply the constraint voltage */
-       if (rdev->constraints->apply_uV &&
-               rdev->constraints->min_uV == rdev->constraints->max_uV &&
-               ops->set_voltage) {
-               ret = ops->set_voltage(rdev,
-                       rdev->constraints->min_uV, rdev->constraints->max_uV);
-                       if (ret < 0) {
-                               printk(KERN_ERR "%s: failed to apply %duV constraint to %s\n",
-                                      __func__,
-                                      rdev->constraints->min_uV, name);
-                               rdev->constraints = NULL;
-                               goto out;
-                       }
-       }
+       name = rdev_get_name(rdev);
+
+       ret = machine_constraints_voltage(rdev, constraints);
+       if (ret != 0)
+               goto out;
 
        /* do we need to setup our suspend state */
        if (constraints->initial_state) {
@@ -872,6 +927,7 @@ static int set_consumer_device_supply(struct regulator_dev *rdev,
        const char *supply)
 {
        struct regulator_map *node;
+       int has_dev;
 
        if (consumer_dev && consumer_dev_name)
                return -EINVAL;
@@ -882,6 +938,11 @@ static int set_consumer_device_supply(struct regulator_dev *rdev,
        if (supply == NULL)
                return -EINVAL;
 
+       if (consumer_dev_name != NULL)
+               has_dev = 1;
+       else
+               has_dev = 0;
+
        list_for_each_entry(node, &regulator_map_list, list) {
                if (consumer_dev_name != node->dev_name)
                        continue;
@@ -892,21 +953,23 @@ static int set_consumer_device_supply(struct regulator_dev *rdev,
                                dev_name(&node->regulator->dev),
                                node->regulator->desc->name,
                                supply,
-                               dev_name(&rdev->dev), rdev->desc->name);
+                               dev_name(&rdev->dev), rdev_get_name(rdev));
                return -EBUSY;
        }
 
-       node = kmalloc(sizeof(struct regulator_map), GFP_KERNEL);
+       node = kzalloc(sizeof(struct regulator_map), GFP_KERNEL);
        if (node == NULL)
                return -ENOMEM;
 
        node->regulator = rdev;
-       node->dev_name = kstrdup(consumer_dev_name, GFP_KERNEL);
        node->supply = supply;
 
-       if (node->dev_name == NULL) {
-               kfree(node);
-               return -ENOMEM;
+       if (has_dev) {
+               node->dev_name = kstrdup(consumer_dev_name, GFP_KERNEL);
+               if (node->dev_name == NULL) {
+                       kfree(node);
+                       return -ENOMEM;
+               }
        }
 
        list_add(&node->list, &regulator_map_list);
@@ -976,6 +1039,7 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
                        goto overflow_err;
 
                regulator->dev = dev;
+               sysfs_attr_init(&regulator->dev_attr.attr);
                regulator->dev_attr.attr.name = kstrdup(buf, GFP_KERNEL);
                if (regulator->dev_attr.attr.name == NULL)
                        goto attr_name_err;
@@ -1025,6 +1089,13 @@ overflow_err:
        return NULL;
 }
 
+static int _regulator_get_enable_time(struct regulator_dev *rdev)
+{
+       if (!rdev->desc->ops->enable_time)
+               return 0;
+       return rdev->desc->ops->enable_time(rdev);
+}
+
 /* Internal regulator request function */
 static struct regulator *_regulator_get(struct device *dev, const char *id,
                                        int exclusive)
@@ -1056,6 +1127,22 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,
                        goto found;
                }
        }
+
+#ifdef CONFIG_REGULATOR_DUMMY
+       if (!devname)
+               devname = "deviceless";
+
+       /* If the board didn't flag that it was fully constrained then
+        * substitute in a dummy regulator so consumers can continue.
+        */
+       if (!has_full_constraints) {
+               pr_warning("%s supply %s not found, using dummy regulator\n",
+                          devname, id);
+               rdev = dummy_regulator_rdev;
+               goto found;
+       }
+#endif
+
        mutex_unlock(&regulator_list_mutex);
        return regulator;
 
@@ -1178,46 +1265,83 @@ void regulator_put(struct regulator *regulator)
 }
 EXPORT_SYMBOL_GPL(regulator_put);
 
+static int _regulator_can_change_status(struct regulator_dev *rdev)
+{
+       if (!rdev->constraints)
+               return 0;
+
+       if (rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_STATUS)
+               return 1;
+       else
+               return 0;
+}
+
 /* locks held by regulator_enable() */
 static int _regulator_enable(struct regulator_dev *rdev)
 {
-       int ret = -EINVAL;
-
-       if (!rdev->constraints) {
-               printk(KERN_ERR "%s: %s has no constraints\n",
-                      __func__, rdev->desc->name);
-               return ret;
-       }
+       int ret, delay;
 
        /* do we need to enable the supply regulator first */
        if (rdev->supply) {
                ret = _regulator_enable(rdev->supply);
                if (ret < 0) {
                        printk(KERN_ERR "%s: failed to enable %s: %d\n",
-                              __func__, rdev->desc->name, ret);
+                              __func__, rdev_get_name(rdev), ret);
                        return ret;
                }
        }
 
        /* check voltage and requested load before enabling */
-       if (rdev->desc->ops->enable) {
+       if (rdev->constraints &&
+           (rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS))
+               drms_uA_update(rdev);
 
-               if (rdev->constraints &&
-                       (rdev->constraints->valid_ops_mask &
-                       REGULATOR_CHANGE_DRMS))
-                       drms_uA_update(rdev);
+       if (rdev->use_count == 0) {
+               /* The regulator may on if it's not switchable or left on */
+               ret = _regulator_is_enabled(rdev);
+               if (ret == -EINVAL || ret == 0) {
+                       if (!_regulator_can_change_status(rdev))
+                               return -EPERM;
+
+                       if (!rdev->desc->ops->enable)
+                               return -EINVAL;
+
+                       /* Query before enabling in case configuration
+                        * dependant.  */
+                       ret = _regulator_get_enable_time(rdev);
+                       if (ret >= 0) {
+                               delay = ret;
+                       } else {
+                               printk(KERN_WARNING
+                                       "%s: enable_time() failed for %s: %d\n",
+                                       __func__, rdev_get_name(rdev),
+                                       ret);
+                               delay = 0;
+                       }
 
-               ret = rdev->desc->ops->enable(rdev);
-               if (ret < 0) {
-                       printk(KERN_ERR "%s: failed to enable %s: %d\n",
-                              __func__, rdev->desc->name, ret);
+                       /* Allow the regulator to ramp; it would be useful
+                        * to extend this for bulk operations so that the
+                        * regulators can ramp together.  */
+                       ret = rdev->desc->ops->enable(rdev);
+                       if (ret < 0)
+                               return ret;
+
+                       if (delay >= 1000)
+                               mdelay(delay / 1000);
+                       else if (delay)
+                               udelay(delay);
+
+               } else if (ret < 0) {
+                       printk(KERN_ERR "%s: is_enabled() failed for %s: %d\n",
+                              __func__, rdev_get_name(rdev), ret);
                        return ret;
                }
-               rdev->use_count++;
-               return ret;
+               /* Fallthrough on positive return values - already enabled */
        }
 
-       return ret;
+       rdev->use_count++;
+
+       return 0;
 }
 
 /**
@@ -1250,20 +1374,25 @@ static int _regulator_disable(struct regulator_dev *rdev)
 
        if (WARN(rdev->use_count <= 0,
                        "unbalanced disables for %s\n",
-                       rdev->desc->name))
+                       rdev_get_name(rdev)))
                return -EIO;
 
        /* are we the last user and permitted to disable ? */
-       if (rdev->use_count == 1 && !rdev->constraints->always_on) {
+       if (rdev->use_count == 1 &&
+           (rdev->constraints && !rdev->constraints->always_on)) {
 
                /* we are last user */
-               if (rdev->desc->ops->disable) {
+               if (_regulator_can_change_status(rdev) &&
+                   rdev->desc->ops->disable) {
                        ret = rdev->desc->ops->disable(rdev);
                        if (ret < 0) {
                                printk(KERN_ERR "%s: failed to disable %s\n",
-                                      __func__, rdev->desc->name);
+                                      __func__, rdev_get_name(rdev));
                                return ret;
                        }
+
+                       _notifier_call_chain(rdev, REGULATOR_EVENT_DISABLE,
+                                            NULL);
                }
 
                /* decrease our supplies ref count and disable if required */
@@ -1318,12 +1447,12 @@ static int _regulator_force_disable(struct regulator_dev *rdev)
                ret = rdev->desc->ops->disable(rdev);
                if (ret < 0) {
                        printk(KERN_ERR "%s: failed to force disable %s\n",
-                              __func__, rdev->desc->name);
+                              __func__, rdev_get_name(rdev));
                        return ret;
                }
                /* notify other consumers that power has been forced off */
-               _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE,
-                       NULL);
+               _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE |
+                       REGULATOR_EVENT_DISABLE, NULL);
        }
 
        /* decrease our supplies ref count and disable if required */
@@ -1357,20 +1486,11 @@ EXPORT_SYMBOL_GPL(regulator_force_disable);
 
 static int _regulator_is_enabled(struct regulator_dev *rdev)
 {
-       int ret;
-
-       mutex_lock(&rdev->mutex);
+       /* If we don't know then assume that the regulator is always on */
+       if (!rdev->desc->ops->is_enabled)
+               return 1;
 
-       /* sanity check */
-       if (!rdev->desc->ops->is_enabled) {
-               ret = -EINVAL;
-               goto out;
-       }
-
-       ret = rdev->desc->ops->is_enabled(rdev);
-out:
-       mutex_unlock(&rdev->mutex);
-       return ret;
+       return rdev->desc->ops->is_enabled(rdev);
 }
 
 /**
@@ -1387,7 +1507,13 @@ out:
  */
 int regulator_is_enabled(struct regulator *regulator)
 {
-       return _regulator_is_enabled(regulator->rdev);
+       int ret;
+
+       mutex_lock(&regulator->rdev->mutex);
+       ret = _regulator_is_enabled(regulator->rdev);
+       mutex_unlock(&regulator->rdev->mutex);
+
+       return ret;
 }
 EXPORT_SYMBOL_GPL(regulator_is_enabled);
 
@@ -1414,7 +1540,7 @@ EXPORT_SYMBOL_GPL(regulator_count_voltages);
  * Context: can sleep
  *
  * Returns a voltage that can be passed to @regulator_set_voltage(),
- * zero if this selector code can't be used on this sytem, or a
+ * zero if this selector code can't be used on this system, or a
  * negative errno.
  */
 int regulator_list_voltage(struct regulator *regulator, unsigned selector)
@@ -1738,7 +1864,7 @@ int regulator_set_optimum_mode(struct regulator *regulator, int uA_load)
        output_uV = rdev->desc->ops->get_voltage(rdev);
        if (output_uV <= 0) {
                printk(KERN_ERR "%s: invalid output voltage found for %s\n",
-                       __func__, rdev->desc->name);
+                       __func__, rdev_get_name(rdev));
                goto out;
        }
 
@@ -1749,13 +1875,13 @@ int regulator_set_optimum_mode(struct regulator *regulator, int uA_load)
                input_uV = rdev->constraints->input_uV;
        if (input_uV <= 0) {
                printk(KERN_ERR "%s: invalid input voltage found for %s\n",
-                       __func__, rdev->desc->name);
+                       __func__, rdev_get_name(rdev));
                goto out;
        }
 
        /* calc total requested load for this regulator */
        list_for_each_entry(consumer, &rdev->consumer_list, list)
-           total_uA_load += consumer->uA_load;
+               total_uA_load += consumer->uA_load;
 
        mode = rdev->desc->ops->get_optimum_mode(rdev,
                                                 input_uV, output_uV,
@@ -1763,7 +1889,7 @@ int regulator_set_optimum_mode(struct regulator *regulator, int uA_load)
        ret = regulator_check_mode(rdev, mode);
        if (ret < 0) {
                printk(KERN_ERR "%s: failed to get optimum mode for %s @"
-                       " %d uA %d -> %d uV\n", __func__, rdev->desc->name,
+                       " %d uA %d -> %d uV\n", __func__, rdev_get_name(rdev),
                        total_uA_load, input_uV, output_uV);
                goto out;
        }
@@ -1771,7 +1897,7 @@ int regulator_set_optimum_mode(struct regulator *regulator, int uA_load)
        ret = rdev->desc->ops->set_mode(rdev, mode);
        if (ret < 0) {
                printk(KERN_ERR "%s: failed to set optimum mode %x for %s\n",
-                       __func__, mode, rdev->desc->name);
+                       __func__, mode, rdev_get_name(rdev));
                goto out;
        }
        ret = mode;
@@ -1824,9 +1950,9 @@ static void _notifier_call_chain(struct regulator_dev *rdev,
 
        /* now notify regulator we supply */
        list_for_each_entry(_rdev, &rdev->supply_list, slist) {
-         mutex_lock(&_rdev->mutex);
-         _notifier_call_chain(_rdev, event, data);
-         mutex_unlock(&_rdev->mutex);
+               mutex_lock(&_rdev->mutex);
+               _notifier_call_chain(_rdev, event, data);
+               mutex_unlock(&_rdev->mutex);
        }
 }
 
@@ -1857,9 +1983,9 @@ int regulator_bulk_get(struct device *dev, int num_consumers,
                consumers[i].consumer = regulator_get(dev,
                                                      consumers[i].supply);
                if (IS_ERR(consumers[i].consumer)) {
-                       dev_err(dev, "Failed to get supply '%s'\n",
-                               consumers[i].supply);
                        ret = PTR_ERR(consumers[i].consumer);
+                       dev_err(dev, "Failed to get supply '%s': %d\n",
+                               consumers[i].supply, ret);
                        consumers[i].consumer = NULL;
                        goto err;
                }
@@ -1902,8 +2028,8 @@ int regulator_bulk_enable(int num_consumers,
        return 0;
 
 err:
-       printk(KERN_ERR "Failed to enable %s\n", consumers[i].supply);
-       for (i = 0; i < num_consumers; i++)
+       printk(KERN_ERR "Failed to enable %s: %d\n", consumers[i].supply, ret);
+       for (--i; i >= 0; --i)
                regulator_disable(consumers[i].consumer);
 
        return ret;
@@ -1937,8 +2063,9 @@ int regulator_bulk_disable(int num_consumers,
        return 0;
 
 err:
-       printk(KERN_ERR "Failed to disable %s\n", consumers[i].supply);
-       for (i = 0; i < num_consumers; i++)
+       printk(KERN_ERR "Failed to disable %s: %d\n", consumers[i].supply,
+              ret);
+       for (--i; i >= 0; --i)
                regulator_enable(consumers[i].consumer);
 
        return ret;
@@ -2253,6 +2380,7 @@ void regulator_unregister(struct regulator_dev *rdev)
                return;
 
        mutex_lock(&regulator_list_mutex);
+       WARN_ON(rdev->open_count);
        unset_regulator_supplies(rdev);
        list_del(&rdev->list);
        if (rdev->supply)
@@ -2287,7 +2415,7 @@ int regulator_suspend_prepare(suspend_state_t state)
 
                if (ret < 0) {
                        printk(KERN_ERR "%s: failed to prepare %s\n",
-                               __func__, rdev->desc->name);
+                               __func__, rdev_get_name(rdev));
                        goto out;
                }
        }
@@ -2375,8 +2503,15 @@ EXPORT_SYMBOL_GPL(regulator_get_init_drvdata);
 
 static int __init regulator_init(void)
 {
+       int ret;
+
        printk(KERN_INFO "regulator: core version %s\n", REGULATOR_VERSION);
-       return class_register(&regulator_class);
+
+       ret = class_register(&regulator_class);
+
+       regulator_dummy_init();
+
+       return ret;
 }
 
 /* init early to allow our consumers to complete system booting */
@@ -2400,14 +2535,9 @@ static int __init regulator_init_complete(void)
                ops = rdev->desc->ops;
                c = rdev->constraints;
 
-               if (c->name)
-                       name = c->name;
-               else if (rdev->desc->name)
-                       name = rdev->desc->name;
-               else
-                       name = "regulator";
+               name = rdev_get_name(rdev);
 
-               if (!ops->disable || c->always_on)
+               if (!ops->disable || (c && c->always_on))
                        continue;
 
                mutex_lock(&rdev->mutex);