]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - drivers/regulator/core.c
Merge remote-tracking branch 'regulator/topic/enable-invert' into v3.9-rc8
[karo-tx-linux.git] / drivers / regulator / core.c
index d887b9f5b2135e378ed76667c0a3b7970900d47c..2434e2e1afcc20b56549f239cd9253e7ad4d9724 100644 (file)
@@ -116,7 +116,7 @@ static const char *rdev_get_name(struct regulator_dev *rdev)
  * @supply: regulator supply name
  *
  * Extract the regulator device node corresponding to the supply name.
- * retruns the device node corresponding to the regulator if found, else
+ * returns the device node corresponding to the regulator if found, else
  * returns NULL.
  */
 static struct device_node *of_get_regulator(struct device *dev, const char *supply)
@@ -1229,7 +1229,7 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,
        struct regulator_dev *rdev;
        struct regulator *regulator = ERR_PTR(-EPROBE_DEFER);
        const char *devname = NULL;
-       int ret;
+       int ret = 0;
 
        if (id == NULL) {
                pr_err("get() with no identifier\n");
@@ -1245,6 +1245,15 @@ static struct regulator *_regulator_get(struct device *dev, const char *id,
        if (rdev)
                goto found;
 
+       /*
+        * If we have return value from dev_lookup fail, we do not expect to
+        * succeed, so, quit with appropriate error value
+        */
+       if (ret) {
+               regulator = ERR_PTR(ret);
+               goto out;
+       }
+
        if (board_wants_dummy_regulator) {
                rdev = dummy_regulator_rdev;
                goto found;
@@ -2153,6 +2162,37 @@ int regulator_map_voltage_iterate(struct regulator_dev *rdev,
 }
 EXPORT_SYMBOL_GPL(regulator_map_voltage_iterate);
 
+/**
+ * regulator_map_voltage_ascend - map_voltage() for ascendant voltage list
+ *
+ * @rdev: Regulator to operate on
+ * @min_uV: Lower bound for voltage
+ * @max_uV: Upper bound for voltage
+ *
+ * Drivers that have ascendant voltage list can use this as their
+ * map_voltage() operation.
+ */
+int regulator_map_voltage_ascend(struct regulator_dev *rdev,
+                                int min_uV, int max_uV)
+{
+       int i, ret;
+
+       for (i = 0; i < rdev->desc->n_voltages; i++) {
+               ret = rdev->desc->ops->list_voltage(rdev, i);
+               if (ret < 0)
+                       continue;
+
+               if (ret > max_uV)
+                       break;
+
+               if (ret >= min_uV && ret <= max_uV)
+                       return i;
+       }
+
+       return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(regulator_map_voltage_ascend);
+
 /**
  * regulator_map_voltage_linear - map_voltage() for simple linear mappings
  *
@@ -3073,9 +3113,13 @@ int regulator_bulk_enable(int num_consumers,
        return 0;
 
 err:
-       pr_err("Failed to enable %s: %d\n", consumers[i].supply, ret);
-       while (--i >= 0)
-               regulator_disable(consumers[i].consumer);
+       for (i = 0; i < num_consumers; i++) {
+               if (consumers[i].ret < 0)
+                       pr_err("Failed to enable %s: %d\n", consumers[i].supply,
+                              consumers[i].ret);
+               else
+                       regulator_disable(consumers[i].consumer);
+       }
 
        return ret;
 }
@@ -3493,7 +3537,14 @@ regulator_register(const struct regulator_desc *regulator_desc,
 
                r = regulator_dev_lookup(dev, supply, &ret);
 
-               if (!r) {
+               if (ret == -ENODEV) {
+                       /*
+                        * No supply was specified for this regulator and
+                        * there will never be one.
+                        */
+                       ret = 0;
+                       goto add_dev;
+               } else if (!r) {
                        dev_err(dev, "Failed to find supply %s\n", supply);
                        ret = -EPROBE_DEFER;
                        goto scrub;
@@ -3511,6 +3562,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
                }
        }
 
+add_dev:
        /* add consumers devices */
        if (init_data) {
                for (i = 0; i < init_data->num_consumer_supplies; i++) {