path: root/common
diff options
authorMarco Felsch <>2021-06-25 09:25:30 +0200
committerSascha Hauer <>2021-06-25 10:01:00 +0200
commitcd23b6facf33cc9bdaa90ea8c0479ef6959f2860 (patch)
treeac21e99434cc129425e36ca034abc30731436f7e /common
parentb052703f0d141a1caf7dfaca16f905308e03487f (diff)
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 <> Link: Signed-off-by: Sascha Hauer <> Link: Signed-off-by: Sascha Hauer <>
Diffstat (limited to 'common')
2 files changed, 40 insertions, 0 deletions
diff --git a/common/Makefile b/common/Makefile
index 382a4f661f..daa022ff54 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -3,6 +3,7 @@ obj-y += memory_display.o
pbl-$(CONFIG_PBL_CONSOLE) += memory_display.o
obj-y += clock.o
obj-y += console_common.o
+obj-y += deep-probe.o
obj-y += startup.o
obj-y += misc.o
obj-pbl-y += memsize.o
diff --git a/common/deep-probe.c b/common/deep-probe.c
new file mode 100644
index 0000000000..1020ad93b7
--- /dev/null
+++ b/common/deep-probe.c
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <common.h>
+#include <deep-probe.h>
+#include <of.h>
+enum deep_probe_state {
+static enum deep_probe_state boardstate = DEEP_PROBE_UNKONWN;
+bool deep_probe_is_supported(void)
+ struct deep_probe_entry *board;
+ if (boardstate > DEEP_PROBE_UNKONWN)
+ return boardstate;
+ /* determine boardstate */
+ for (board = &__barebox_deep_probe_start;
+ board != &__barebox_deep_probe_end; board++) {
+ const struct of_device_id *matches = board->device_id;
+ for (; matches->compatible; matches++) {
+ if (of_machine_is_compatible(matches->compatible)) {
+ boardstate = DEEP_PROBE_SUPPORTED;
+ printk("Deep probe supported due to %s\n", matches->compatible);
+ return true;
+ }
+ }
+ }
+ return false;