summaryrefslogtreecommitdiffstats
path: root/drivers/regulator/core.c
diff options
context:
space:
mode:
authorMarco Felsch <m.felsch@pengutronix.de>2021-06-25 09:25:30 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2021-06-25 10:01:00 +0200
commitcd23b6facf33cc9bdaa90ea8c0479ef6959f2860 (patch)
treeac21e99434cc129425e36ca034abc30731436f7e /drivers/regulator/core.c
parentb052703f0d141a1caf7dfaca16f905308e03487f (diff)
downloadbarebox-cd23b6facf33cc9bdaa90ea8c0479ef6959f2860.tar.gz
barebox-cd23b6facf33cc9bdaa90ea8c0479ef6959f2860.tar.xz
common: add initial barebox deep-probe support
The barebox 'deep probe' or 'probe on demand' mechanism is the answer of unwanted -EPROBE_DEFER failures. The EPROBE_DEFER error code was introduced by commit ab3da15bc14c ("base: Introduce deferred probing") and since then it causes a few problems. The error is returned if either the device is not yet present or the driver is not yet registered. This makes sense on linux systems where modules and hot-plug devices are used very often but not for barebox. The module support is rarely used and devices aren't hot pluggable. The current barebox behaviour populates all devices before the drivers are registered so all devices are present during the driver registration. So the driver probe() function gets called immediately after the driver registration and causes the -EPROBE_DEFER error if this driver depends on an other not yet registered driver. To get rid of the EPROBE_DEFER error code we need to reorder the device population and the driver registration. All drivers must be registered first. In an ideal world all driver can be registered by the same initcall level. Then devices are getting populated which causes calling the driver probe() function but this time resources/devices are created on demand if not yet available. Dependencies between devices are normally expressed as references to other device nodes. With deep probe barebox provides helper functions which take a device node and probe the device behind that node if necessary. This means instead of returning -EPROBE_DEFER, we can now make the desired resources available once we need them. If the resource can't be created we are returning -ENODEV since we are not supporting hot-plugging. Dropping EPROBE_DEFER is the long-term goal, avoid initcall shifting is the short-term goal. Call it deep-probe since the on-demand device creation can create very deep stacks. This commit adds the initial support for: spi, i2c, reset, regulator, gpio and clk resource on-demand creation. The deep-probe mechanism must be enabled for each board to avoid breaking changes using deep_probe_enable(). This can be changed later after all boards are converted to the new mechanism. Signed-off-by: Marco Felsch <m.felsch@pengutronix.de> Link: https://lore.pengutronix.de/20201021115813.31645-8-m.felsch@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Link: https://lore.barebox.org/20210625072540.32717-10-s.hauer@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/regulator/core.c')
-rw-r--r--drivers/regulator/core.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index ac3a9b048e..097f7d779b 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -175,6 +175,7 @@ int of_regulator_register(struct regulator_dev *rd, struct device_node *node)
return PTR_ERR(ri);
ri->node = node;
+ node->dev = rd->dev;
if (rd->desc->off_on_delay)
ri->enable_time_us = rd->desc->off_on_delay;
@@ -197,6 +198,7 @@ static struct regulator_internal *of_regulator_get(struct device_d *dev, const c
char *propname;
struct regulator_internal *ri;
struct device_node *node;
+ int ret;
propname = basprintf("%s-supply", supply);
@@ -228,6 +230,10 @@ static struct regulator_internal *of_regulator_get(struct device_d *dev, const c
goto out;
}
+ ret = of_device_ensure_probed(node);
+ if (ret)
+ return ERR_PTR(ret);
+
list_for_each_entry(ri, &regulator_list, list) {
if (ri->node == node) {
dev_dbg(dev, "Using %s regulator from %s\n",