regulator: palma: Disable smps10 boost during suspend
[linux-2.6.git] / drivers / regulator / core.c
index d1f655f..bb4fb61 100644 (file)
@@ -307,6 +307,50 @@ static ssize_t device_requested_uA_show(struct device *dev,
        return sprintf(buf, "%d\n", regulator->uA_load);
 }
 
+static ssize_t regulator_uV_set(struct device *dev,
+       struct device_attribute *attr, const char *buf, size_t count)
+{
+       struct regulator_dev *rdev = dev_get_drvdata(dev);
+       int ret;
+       int min_uV;
+       int max_uV = rdev->constraints->max_uV;
+       char *p = (char *)buf;
+
+       min_uV = memparse(p, &p);
+       mutex_lock(&rdev->mutex);
+
+       /* sanity check */
+       if (!rdev->desc->ops->set_voltage &&
+               !rdev->desc->ops->set_voltage_sel) {
+               rdev_err(rdev, "The operation is not supported\n");
+               goto out;
+       }
+
+       /* constraints check */
+       ret = regulator_check_voltage(rdev, &min_uV, &max_uV);
+       if (ret < 0) {
+               rdev_err(rdev, "Voltage is out of range min:max= %d:%d\n",
+                       rdev->constraints->min_uV, rdev->constraints->max_uV);
+               goto out;
+       }
+
+       /* Consumer check */
+       ret = regulator_check_consumers(rdev, &min_uV, &max_uV);
+       if (ret < 0) {
+               rdev_warn(rdev, "new voltage is out-range for some consumer\n");
+               rdev_warn(rdev, "min: max = %d:%d\n", min_uV, max_uV);
+       }
+
+       rdev_info(rdev, "Setting voltage min:max = %d:%d\n", min_uV, max_uV);
+       ret = _regulator_do_set_voltage(rdev, min_uV, max_uV);
+       if (ret < 0)
+               rdev_warn(rdev, "Can not set voltage %d:%d\n",  min_uV, max_uV);
+
+out:
+       mutex_unlock(&rdev->mutex);
+       return count;
+}
+
 static ssize_t regulator_uV_show(struct device *dev,
                                struct device_attribute *attr, char *buf)
 {
@@ -319,7 +363,7 @@ static ssize_t regulator_uV_show(struct device *dev,
 
        return ret;
 }
-static DEVICE_ATTR(microvolts, 0444, regulator_uV_show, NULL);
+static DEVICE_ATTR(microvolts, 0644, regulator_uV_show, regulator_uV_set);
 
 static ssize_t regulator_uA_show(struct device *dev,
                                struct device_attribute *attr, char *buf)
@@ -1919,11 +1963,11 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev,
        min_uV += rdev->constraints->uV_offset;
        max_uV += rdev->constraints->uV_offset;
 
-       if (_regulator_is_enabled(rdev))
-               _notifier_call_chain(rdev, REGULATOR_EVENT_OUT_PRECHANGE,
-                                    NULL);
-
        if (rdev->desc->ops->set_voltage) {
+               if (_regulator_is_enabled(rdev))
+                       _notifier_call_chain(rdev,
+                       REGULATOR_EVENT_OUT_PRECHANGE, (void *)min_uV);
+
                ret = rdev->desc->ops->set_voltage(rdev, min_uV, max_uV,
                                                   &selector);
 
@@ -1973,6 +2017,10 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev,
                }
 
                if (best_val != INT_MAX) {
+                       if (_regulator_is_enabled(rdev))
+                               _notifier_call_chain(rdev,
+                               REGULATOR_EVENT_OUT_PRECHANGE, (void *)best_val);
+
                        ret = rdev->desc->ops->set_voltage_sel(rdev, selector);
                        selector = best_val;
                } else {
@@ -1994,9 +2042,12 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev,
                _notifier_call_chain(rdev, REGULATOR_EVENT_VOLTAGE_CHANGE,
                                     NULL);
 
-       if (_regulator_is_enabled(rdev))
+       if (_regulator_is_enabled(rdev)) {
+               if (selector != -1)
+                       min_uV = selector;
                _notifier_call_chain(rdev, REGULATOR_EVENT_OUT_POSTCHANGE,
-                                    NULL);
+                                    (void *)min_uV);
+       }
 
        trace_regulator_set_voltage_complete(rdev_get_name(rdev), selector);
 
@@ -2483,7 +2534,7 @@ static void _notifier_call_chain(struct regulator_dev *rdev,
                                  unsigned long event, void *data)
 {
        /* call rdev chain first */
-       blocking_notifier_call_chain(&rdev->notifier, event, NULL);
+       blocking_notifier_call_chain(&rdev->notifier, event, data);
 }
 
 /**
@@ -2994,14 +3045,15 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
 
        if (init_data && init_data->supply_regulator)
                supply = init_data->supply_regulator;
+#if 0 /* Reenable when EPROBE_DEFER is pulled. */
        else if (regulator_desc->supply_name)
                supply = regulator_desc->supply_name;
+#endif
 
        if (supply) {
                struct regulator_dev *r;
 
                r = regulator_dev_lookup(dev, supply);
-
                if (!r) {
                        dev_err(dev, "Failed to find supply %s\n", supply);
                        ret = -EPROBE_DEFER;
@@ -3046,6 +3098,8 @@ unset_supplies:
        unset_regulator_supplies(rdev);
 
 scrub:
+       if (rdev->supply)
+               regulator_put(rdev->supply);
        kfree(rdev->constraints);
        device_unregister(&rdev->dev);
        /* device core frees rdev */