regulator: core: Use class device list for regulator_list in late init
authorMark Brown <broonie@kernel.org>
Mon, 10 Aug 2015 18:43:47 +0000 (19:43 +0100)
committerMark Brown <broonie@kernel.org>
Wed, 12 Aug 2015 12:21:14 +0000 (13:21 +0100)
The regulator_list has exactly the same contents as the list that the
driver core maintains of regulator_class members so is redundant. As a
first step in converting over to use the class device list convert our
iteration in late_initcall() to use the class device iterator.

Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/regulator/core.c

index 01a0a78368b80ab1e670d380fcea1938630600df..0c0e9ab94d4d7a9468bf4a2865c891e1bca1c2e6 100644 (file)
@@ -110,6 +110,11 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
                                          struct device *dev,
                                          const char *supply_name);
 
+static struct regulator_dev *dev_to_rdev(struct device *dev)
+{
+       return container_of(dev, struct regulator_dev, dev);
+}
+
 static const char *rdev_get_name(struct regulator_dev *rdev)
 {
        if (rdev->constraints && rdev->constraints->name)
@@ -4152,13 +4157,57 @@ static int __init regulator_init(void)
 /* init early to allow our consumers to complete system booting */
 core_initcall(regulator_init);
 
-static int __init regulator_init_complete(void)
+static int __init regulator_late_cleanup(struct device *dev, void *data)
 {
-       struct regulator_dev *rdev;
-       const struct regulator_ops *ops;
-       struct regulation_constraints *c;
+       struct regulator_dev *rdev = dev_to_rdev(dev);
+       const struct regulator_ops *ops = rdev->desc->ops;
+       struct regulation_constraints *c = rdev->constraints;
        int enabled, ret;
 
+       if (c && c->always_on)
+               return 0;
+
+       if (c && !(c->valid_ops_mask & REGULATOR_CHANGE_STATUS))
+               return 0;
+
+       mutex_lock(&rdev->mutex);
+
+       if (rdev->use_count)
+               goto unlock;
+
+       /* If we can't read the status assume it's on. */
+       if (ops->is_enabled)
+               enabled = ops->is_enabled(rdev);
+       else
+               enabled = 1;
+
+       if (!enabled)
+               goto unlock;
+
+       if (have_full_constraints()) {
+               /* We log since this may kill the system if it goes
+                * wrong. */
+               rdev_info(rdev, "disabling\n");
+               ret = _regulator_do_disable(rdev);
+               if (ret != 0)
+                       rdev_err(rdev, "couldn't disable: %d\n", ret);
+       } else {
+               /* The intention is that in future we will
+                * assume that full constraints are provided
+                * so warn even if we aren't going to do
+                * anything here.
+                */
+               rdev_warn(rdev, "incomplete constraints, leaving on\n");
+       }
+
+unlock:
+       mutex_unlock(&rdev->mutex);
+
+       return 0;
+}
+
+static int __init regulator_init_complete(void)
+{
        /*
         * Since DT doesn't provide an idiomatic mechanism for
         * enabling full constraints and since it's much more natural
@@ -4168,58 +4217,13 @@ static int __init regulator_init_complete(void)
        if (of_have_populated_dt())
                has_full_constraints = true;
 
-       mutex_lock(&regulator_list_mutex);
-
        /* If we have a full configuration then disable any regulators
         * we have permission to change the status for and which are
         * not in use or always_on.  This is effectively the default
         * for DT and ACPI as they have full constraints.
         */
-       list_for_each_entry(rdev, &regulator_list, list) {
-               ops = rdev->desc->ops;
-               c = rdev->constraints;
-
-               if (c && c->always_on)
-                       continue;
-
-               if (c && !(c->valid_ops_mask & REGULATOR_CHANGE_STATUS))
-                       continue;
-
-               mutex_lock(&rdev->mutex);
-
-               if (rdev->use_count)
-                       goto unlock;
-
-               /* If we can't read the status assume it's on. */
-               if (ops->is_enabled)
-                       enabled = ops->is_enabled(rdev);
-               else
-                       enabled = 1;
-
-               if (!enabled)
-                       goto unlock;
-
-               if (have_full_constraints()) {
-                       /* We log since this may kill the system if it
-                        * goes wrong. */
-                       rdev_info(rdev, "disabling\n");
-                       ret = _regulator_do_disable(rdev);
-                       if (ret != 0)
-                               rdev_err(rdev, "couldn't disable: %d\n", ret);
-               } else {
-                       /* The intention is that in future we will
-                        * assume that full constraints are provided
-                        * so warn even if we aren't going to do
-                        * anything here.
-                        */
-                       rdev_warn(rdev, "incomplete constraints, leaving on\n");
-               }
-
-unlock:
-               mutex_unlock(&rdev->mutex);
-       }
-
-       mutex_unlock(&regulator_list_mutex);
+       class_for_each_device(&regulator_class, NULL, NULL,
+                             regulator_late_cleanup);
 
        return 0;
 }