regulator: core: Mutually resolve regulators coupling
If registered regulator found a couple, then the couple can find the registered regulator too and hence coupling can be mutually resolved at the registration time. Signed-off-by: Dmitry Osipenko <digetx@gmail.com> Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
9243a195be
commit
f9503385b1
1 changed files with 20 additions and 40 deletions
|
@ -4439,7 +4439,7 @@ static int regulator_register_resolve_supply(struct device *dev, void *data)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int regulator_fill_coupling_array(struct regulator_dev *rdev)
|
static void regulator_resolve_coupling(struct regulator_dev *rdev)
|
||||||
{
|
{
|
||||||
struct coupling_desc *c_desc = &rdev->coupling_desc;
|
struct coupling_desc *c_desc = &rdev->coupling_desc;
|
||||||
int n_coupled = c_desc->n_coupled;
|
int n_coupled = c_desc->n_coupled;
|
||||||
|
@ -4453,33 +4453,21 @@ static int regulator_fill_coupling_array(struct regulator_dev *rdev)
|
||||||
|
|
||||||
c_rdev = of_parse_coupled_regulator(rdev, i - 1);
|
c_rdev = of_parse_coupled_regulator(rdev, i - 1);
|
||||||
|
|
||||||
if (c_rdev) {
|
if (!c_rdev)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
regulator_lock(c_rdev);
|
||||||
|
|
||||||
c_desc->coupled_rdevs[i] = c_rdev;
|
c_desc->coupled_rdevs[i] = c_rdev;
|
||||||
c_desc->n_resolved++;
|
c_desc->n_resolved++;
|
||||||
|
|
||||||
|
regulator_unlock(c_rdev);
|
||||||
|
|
||||||
|
regulator_resolve_coupling(c_rdev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rdev->coupling_desc.n_resolved < n_coupled)
|
static int regulator_init_coupling(struct regulator_dev *rdev)
|
||||||
return -1;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int regulator_register_fill_coupling_array(struct device *dev,
|
|
||||||
void *data)
|
|
||||||
{
|
|
||||||
struct regulator_dev *rdev = dev_to_rdev(dev);
|
|
||||||
|
|
||||||
if (!IS_ENABLED(CONFIG_OF))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (regulator_fill_coupling_array(rdev))
|
|
||||||
rdev_dbg(rdev, "unable to resolve coupling\n");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int regulator_resolve_coupling(struct regulator_dev *rdev)
|
|
||||||
{
|
{
|
||||||
int n_phandles;
|
int n_phandles;
|
||||||
|
|
||||||
|
@ -4519,13 +4507,6 @@ static int regulator_resolve_coupling(struct regulator_dev *rdev)
|
||||||
if (!of_check_coupling_data(rdev))
|
if (!of_check_coupling_data(rdev))
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
|
|
||||||
/*
|
|
||||||
* After everything has been checked, try to fill rdevs array
|
|
||||||
* with pointers to regulators parsed from device tree. If some
|
|
||||||
* regulators are not registered yet, retry in late init call
|
|
||||||
*/
|
|
||||||
regulator_fill_coupling_array(rdev);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4662,11 +4643,8 @@ regulator_register(const struct regulator_desc *regulator_desc,
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto wash;
|
goto wash;
|
||||||
|
|
||||||
mutex_lock(®ulator_list_mutex);
|
ret = regulator_init_coupling(rdev);
|
||||||
ret = regulator_resolve_coupling(rdev);
|
if (ret < 0)
|
||||||
mutex_unlock(®ulator_list_mutex);
|
|
||||||
|
|
||||||
if (ret != 0)
|
|
||||||
goto wash;
|
goto wash;
|
||||||
|
|
||||||
/* add consumers devices */
|
/* add consumers devices */
|
||||||
|
@ -4700,6 +4678,11 @@ regulator_register(const struct regulator_desc *regulator_desc,
|
||||||
|
|
||||||
rdev_init_debugfs(rdev);
|
rdev_init_debugfs(rdev);
|
||||||
|
|
||||||
|
/* try to resolve regulators coupling since a new one was registered */
|
||||||
|
mutex_lock(®ulator_list_mutex);
|
||||||
|
regulator_resolve_coupling(rdev);
|
||||||
|
mutex_unlock(®ulator_list_mutex);
|
||||||
|
|
||||||
/* try to resolve regulators supply since a new one was registered */
|
/* try to resolve regulators supply since a new one was registered */
|
||||||
class_for_each_device(®ulator_class, NULL, NULL,
|
class_for_each_device(®ulator_class, NULL, NULL,
|
||||||
regulator_register_resolve_supply);
|
regulator_register_resolve_supply);
|
||||||
|
@ -5155,9 +5138,6 @@ static int __init regulator_init_complete(void)
|
||||||
class_for_each_device(®ulator_class, NULL, NULL,
|
class_for_each_device(®ulator_class, NULL, NULL,
|
||||||
regulator_late_cleanup);
|
regulator_late_cleanup);
|
||||||
|
|
||||||
class_for_each_device(®ulator_class, NULL, NULL,
|
|
||||||
regulator_register_fill_coupling_array);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
late_initcall_sync(regulator_init_complete);
|
late_initcall_sync(regulator_init_complete);
|
||||||
|
|
Loading…
Add table
Reference in a new issue