Skip to content

Commit f950338

Browse files
digetxbroonie
authored andcommitted
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 <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent 9243a19 commit f950338

File tree

1 file changed

+17
-37
lines changed

1 file changed

+17
-37
lines changed

drivers/regulator/core.c

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4439,7 +4439,7 @@ static int regulator_register_resolve_supply(struct device *dev, void *data)
44394439
return 0;
44404440
}
44414441

4442-
static int regulator_fill_coupling_array(struct regulator_dev *rdev)
4442+
static void regulator_resolve_coupling(struct regulator_dev *rdev)
44434443
{
44444444
struct coupling_desc *c_desc = &rdev->coupling_desc;
44454445
int n_coupled = c_desc->n_coupled;
@@ -4453,33 +4453,21 @@ static int regulator_fill_coupling_array(struct regulator_dev *rdev)
44534453

44544454
c_rdev = of_parse_coupled_regulator(rdev, i - 1);
44554455

4456-
if (c_rdev) {
4457-
c_desc->coupled_rdevs[i] = c_rdev;
4458-
c_desc->n_resolved++;
4459-
}
4460-
}
4461-
4462-
if (rdev->coupling_desc.n_resolved < n_coupled)
4463-
return -1;
4464-
else
4465-
return 0;
4466-
}
4456+
if (!c_rdev)
4457+
continue;
44674458

4468-
static int regulator_register_fill_coupling_array(struct device *dev,
4469-
void *data)
4470-
{
4471-
struct regulator_dev *rdev = dev_to_rdev(dev);
4459+
regulator_lock(c_rdev);
44724460

4473-
if (!IS_ENABLED(CONFIG_OF))
4474-
return 0;
4461+
c_desc->coupled_rdevs[i] = c_rdev;
4462+
c_desc->n_resolved++;
44754463

4476-
if (regulator_fill_coupling_array(rdev))
4477-
rdev_dbg(rdev, "unable to resolve coupling\n");
4464+
regulator_unlock(c_rdev);
44784465

4479-
return 0;
4466+
regulator_resolve_coupling(c_rdev);
4467+
}
44804468
}
44814469

4482-
static int regulator_resolve_coupling(struct regulator_dev *rdev)
4470+
static int regulator_init_coupling(struct regulator_dev *rdev)
44834471
{
44844472
int n_phandles;
44854473

@@ -4519,13 +4507,6 @@ static int regulator_resolve_coupling(struct regulator_dev *rdev)
45194507
if (!of_check_coupling_data(rdev))
45204508
return -EPERM;
45214509

4522-
/*
4523-
* After everything has been checked, try to fill rdevs array
4524-
* with pointers to regulators parsed from device tree. If some
4525-
* regulators are not registered yet, retry in late init call
4526-
*/
4527-
regulator_fill_coupling_array(rdev);
4528-
45294510
return 0;
45304511
}
45314512

@@ -4662,11 +4643,8 @@ regulator_register(const struct regulator_desc *regulator_desc,
46624643
if (ret < 0)
46634644
goto wash;
46644645

4665-
mutex_lock(&regulator_list_mutex);
4666-
ret = regulator_resolve_coupling(rdev);
4667-
mutex_unlock(&regulator_list_mutex);
4668-
4669-
if (ret != 0)
4646+
ret = regulator_init_coupling(rdev);
4647+
if (ret < 0)
46704648
goto wash;
46714649

46724650
/* add consumers devices */
@@ -4700,6 +4678,11 @@ regulator_register(const struct regulator_desc *regulator_desc,
47004678

47014679
rdev_init_debugfs(rdev);
47024680

4681+
/* try to resolve regulators coupling since a new one was registered */
4682+
mutex_lock(&regulator_list_mutex);
4683+
regulator_resolve_coupling(rdev);
4684+
mutex_unlock(&regulator_list_mutex);
4685+
47034686
/* try to resolve regulators supply since a new one was registered */
47044687
class_for_each_device(&regulator_class, NULL, NULL,
47054688
regulator_register_resolve_supply);
@@ -5155,9 +5138,6 @@ static int __init regulator_init_complete(void)
51555138
class_for_each_device(&regulator_class, NULL, NULL,
51565139
regulator_late_cleanup);
51575140

5158-
class_for_each_device(&regulator_class, NULL, NULL,
5159-
regulator_register_fill_coupling_array);
5160-
51615141
return 0;
51625142
}
51635143
late_initcall_sync(regulator_init_complete);

0 commit comments

Comments
 (0)