Skip to content

Commit

Permalink
regulator: core: do not silently ignore provided init_data
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jerome Brunet authored and Mark Brown committed Oct 22, 2024
1 parent 42f7652 commit cd7a38c
Showing 1 changed file with 34 additions and 23 deletions.
57 changes: 34 additions & 23 deletions drivers/regulator/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -5681,32 +5681,43 @@ regulator_register(struct device *dev,
goto clean;
}

init_data = regulator_of_get_init_data(dev, regulator_desc, config,
&rdev->dev.of_node);

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

/*
* We need to keep track of any GPIO descriptor coming from the
* device tree until we have handled it over to the core. If the
* config that was passed in to this function DOES NOT contain
* a descriptor, and the config after this call DOES contain
* a descriptor, we definitely got one from parsing the device
* tree.
*/
if (!cfg->ena_gpiod && config->ena_gpiod)
dangling_of_gpiod = true;
if (!init_data) {
init_data = config->init_data;
rdev->dev.of_node = of_node_get(config->of_node);

} else {
init_data = regulator_of_get_init_data(dev, regulator_desc,
config,
&rdev->dev.of_node);

/*
* Sometimes not all resources are probed already so we need to
* take that into account. This happens most the time if the
* ena_gpiod comes from a gpio extender or something else.
*/
if (PTR_ERR(init_data) == -EPROBE_DEFER) {
ret = -EPROBE_DEFER;
goto clean;
}

/*
* We need to keep track of any GPIO descriptor coming from the
* device tree until we have handled it over to the core. If the
* config that was passed in to this function DOES NOT contain a
* descriptor, and the config after this call DOES contain a
* descriptor, we definitely got one from parsing the device
* tree.
*/
if (!cfg->ena_gpiod && config->ena_gpiod)
dangling_of_gpiod = true;
}

ww_mutex_init(&rdev->mutex, &regulator_ww_class);
Expand Down

0 comments on commit cd7a38c

Please sign in to comment.