regulator: struct device - replace bus_id with dev_name(), dev_set_name()
[deliverable/linux.git] / drivers / regulator / core.c
index 84202eaace57aacfc17d90564b118315bff371cc..9a644d41b8136e7b3f133d0e91986a99e8c2ae22 100644 (file)
@@ -241,6 +241,22 @@ static ssize_t regulator_uA_show(struct device *dev,
        return sprintf(buf, "%d\n", _regulator_get_current_limit(rdev));
 }
 
+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);
+}
+
 static ssize_t regulator_opmode_show(struct device *dev,
                                    struct device_attribute *attr, char *buf)
 {
@@ -473,7 +489,9 @@ static ssize_t regulator_suspend_standby_state_show(struct device *dev,
        else
                return sprintf(buf, "disabled\n");
 }
+
 static struct device_attribute regulator_dev_attrs[] = {
+       __ATTR(name, 0444, regulator_name_show, NULL),
        __ATTR(microvolts, 0444, regulator_uV_show, NULL),
        __ATTR(microamps, 0444, regulator_uA_show, NULL),
        __ATTR(opmode, 0444, regulator_opmode_show, NULL),
@@ -669,19 +687,28 @@ 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;
+
+       if (constraints->name)
+               name = constraints->name;
+       else if (rdev->desc->name)
+               name = rdev->desc->name;
+       else
+               name = "regulator";
 
        rdev->constraints = constraints;
 
        /* do we need to apply the constraint voltage */
        if (rdev->constraints->apply_uV &&
                rdev->constraints->min_uV == rdev->constraints->max_uV &&
-               rdev->desc->ops->set_voltage) {
-               ret = rdev->desc->ops->set_voltage(rdev,
+               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\n", __func__,
-                                       rdev->constraints->min_uV);
+                               printk(KERN_ERR "%s: failed to apply %duV constraint to %s\n",
+                                      __func__,
+                                      rdev->constraints->min_uV, name);
                                rdev->constraints = NULL;
                                goto out;
                        }
@@ -692,8 +719,29 @@ static int set_machine_constraints(struct regulator_dev *rdev,
                rdev->use_count = 1;
 
        /* do we need to setup our suspend state */
-       if (constraints->initial_state)
+       if (constraints->initial_state) {
                ret = suspend_prepare(rdev, constraints->initial_state);
+               if (ret < 0) {
+                       printk(KERN_ERR "%s: failed to set suspend state for %s\n",
+                              __func__, name);
+                       rdev->constraints = NULL;
+                       goto out;
+               }
+       }
+
+       /* if always_on is set then turn the regulator on if it's not
+        * already on. */
+       if (constraints->always_on && ops->enable &&
+           ((ops->is_enabled && !ops->is_enabled(rdev)) ||
+            (!ops->is_enabled && !constraints->boot_on))) {
+               ret = ops->enable(rdev);
+               if (ret < 0) {
+                       printk(KERN_ERR "%s: failed to enable %s\n",
+                              __func__, name);
+                       rdev->constraints = NULL;
+                       goto out;
+               }
+       }
 
        print_constraints(rdev);
 out:
@@ -1691,6 +1739,9 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
            !regulator_desc->type == REGULATOR_CURRENT)
                return ERR_PTR(-EINVAL);
 
+       if (!init_data)
+               return ERR_PTR(-EINVAL);
+
        rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL);
        if (rdev == NULL)
                return ERR_PTR(-ENOMEM);
@@ -1728,8 +1779,8 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
        /* register with sysfs */
        rdev->dev.class = &regulator_class;
        rdev->dev.parent = dev;
-       snprintf(rdev->dev.bus_id, sizeof(rdev->dev.bus_id),
-                "regulator.%d", atomic_inc_return(&regulator_no) - 1);
+       dev_set_name(&rdev->dev, "regulator.%d",
+                    atomic_inc_return(&regulator_no) - 1);
        ret = device_register(&rdev->dev);
        if (ret != 0) {
                kfree(rdev);
This page took 0.027595 seconds and 5 git commands to generate.