Skip to content

Commit cd7a38c

Browse files
jbrun3tbroonie
authored andcommitted
regulator: core: do not silently ignore provided init_data
On DT platforms, if a regulator init_data is provided in config, it is silently ignored in favor of the DT parsing done by the framework, if of_match is set. of_match is an indication that init_data is expected to be set based on DT and the parsing should be done by the regulator framework. If the regulator provider passed init_data it must be because it is useful somehow, in such case of_match should be clear. If the driver expects the framework to initialize this data on its own, it should leave init_data clear. Warn if both init_data and of_match are set, then default to the provided init_data. Signed-off-by: Jerome Brunet <jbrunet@baylibre.com> Link: https://patch.msgid.link/20241008-regulator-ignored-data-v2-1-d1251e0ee507@baylibre.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 42f7652 commit cd7a38c

File tree

1 file changed

+34
-23
lines changed

1 file changed

+34
-23
lines changed

drivers/regulator/core.c

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5681,32 +5681,43 @@ regulator_register(struct device *dev,
56815681
goto clean;
56825682
}
56835683

5684-
init_data = regulator_of_get_init_data(dev, regulator_desc, config,
5685-
&rdev->dev.of_node);
5686-
5687-
/*
5688-
* Sometimes not all resources are probed already so we need to take
5689-
* that into account. This happens most the time if the ena_gpiod comes
5690-
* from a gpio extender or something else.
5691-
*/
5692-
if (PTR_ERR(init_data) == -EPROBE_DEFER) {
5693-
ret = -EPROBE_DEFER;
5694-
goto clean;
5695-
}
5684+
if (config->init_data) {
5685+
/*
5686+
* Providing of_match means the framework is expected to parse
5687+
* DT to get the init_data. This would conflict with provided
5688+
* init_data, if set. Warn if it happens.
5689+
*/
5690+
if (regulator_desc->of_match)
5691+
dev_warn(dev, "Using provided init data - OF match ignored\n");
56965692

5697-
/*
5698-
* We need to keep track of any GPIO descriptor coming from the
5699-
* device tree until we have handled it over to the core. If the
5700-
* config that was passed in to this function DOES NOT contain
5701-
* a descriptor, and the config after this call DOES contain
5702-
* a descriptor, we definitely got one from parsing the device
5703-
* tree.
5704-
*/
5705-
if (!cfg->ena_gpiod && config->ena_gpiod)
5706-
dangling_of_gpiod = true;
5707-
if (!init_data) {
57085693
init_data = config->init_data;
57095694
rdev->dev.of_node = of_node_get(config->of_node);
5695+
5696+
} else {
5697+
init_data = regulator_of_get_init_data(dev, regulator_desc,
5698+
config,
5699+
&rdev->dev.of_node);
5700+
5701+
/*
5702+
* Sometimes not all resources are probed already so we need to
5703+
* take that into account. This happens most the time if the
5704+
* ena_gpiod comes from a gpio extender or something else.
5705+
*/
5706+
if (PTR_ERR(init_data) == -EPROBE_DEFER) {
5707+
ret = -EPROBE_DEFER;
5708+
goto clean;
5709+
}
5710+
5711+
/*
5712+
* We need to keep track of any GPIO descriptor coming from the
5713+
* device tree until we have handled it over to the core. If the
5714+
* config that was passed in to this function DOES NOT contain a
5715+
* descriptor, and the config after this call DOES contain a
5716+
* descriptor, we definitely got one from parsing the device
5717+
* tree.
5718+
*/
5719+
if (!cfg->ena_gpiod && config->ena_gpiod)
5720+
dangling_of_gpiod = true;
57105721
}
57115722

57125723
ww_mutex_init(&rdev->mutex, &regulator_ww_class);

0 commit comments

Comments
 (0)