Commit 609ca5f3 authored by Mark Brown's avatar Mark Brown

regulator: core: Use class device list for regulator_list in late init

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: default avatarMark Brown <broonie@kernel.org>
parent 29f5f486
...@@ -110,6 +110,11 @@ static struct regulator *create_regulator(struct regulator_dev *rdev, ...@@ -110,6 +110,11 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
struct device *dev, struct device *dev,
const char *supply_name); 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) static const char *rdev_get_name(struct regulator_dev *rdev)
{ {
if (rdev->constraints && rdev->constraints->name) if (rdev->constraints && rdev->constraints->name)
...@@ -4152,38 +4157,18 @@ static int __init regulator_init(void) ...@@ -4152,38 +4157,18 @@ static int __init regulator_init(void)
/* init early to allow our consumers to complete system booting */ /* init early to allow our consumers to complete system booting */
core_initcall(regulator_init); 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; struct regulator_dev *rdev = dev_to_rdev(dev);
const struct regulator_ops *ops; const struct regulator_ops *ops = rdev->desc->ops;
struct regulation_constraints *c; struct regulation_constraints *c = rdev->constraints;
int enabled, ret; int enabled, ret;
/*
* Since DT doesn't provide an idiomatic mechanism for
* enabling full constraints and since it's much more natural
* with DT to provide them just assume that a DT enabled
* system has full constraints.
*/
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) if (c && c->always_on)
continue; return 0;
if (c && !(c->valid_ops_mask & REGULATOR_CHANGE_STATUS)) if (c && !(c->valid_ops_mask & REGULATOR_CHANGE_STATUS))
continue; return 0;
mutex_lock(&rdev->mutex); mutex_lock(&rdev->mutex);
...@@ -4200,8 +4185,8 @@ static int __init regulator_init_complete(void) ...@@ -4200,8 +4185,8 @@ static int __init regulator_init_complete(void)
goto unlock; goto unlock;
if (have_full_constraints()) { if (have_full_constraints()) {
/* We log since this may kill the system if it /* We log since this may kill the system if it goes
* goes wrong. */ * wrong. */
rdev_info(rdev, "disabling\n"); rdev_info(rdev, "disabling\n");
ret = _regulator_do_disable(rdev); ret = _regulator_do_disable(rdev);
if (ret != 0) if (ret != 0)
...@@ -4217,9 +4202,28 @@ static int __init regulator_init_complete(void) ...@@ -4217,9 +4202,28 @@ static int __init regulator_init_complete(void)
unlock: unlock:
mutex_unlock(&rdev->mutex); mutex_unlock(&rdev->mutex);
}
mutex_unlock(&regulator_list_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
* with DT to provide them just assume that a DT enabled
* system has full constraints.
*/
if (of_have_populated_dt())
has_full_constraints = true;
/* 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.
*/
class_for_each_device(&regulator_class, NULL, NULL,
regulator_late_cleanup);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment