summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2025-01-14 11:43:01 -0600
committerTom Rini <trini@konsulko.com>2025-01-14 11:43:01 -0600
commite17be5a07ad6947c13c39936be812a65e694ecee (patch)
tree92f8addda6ee3a888101a736c1fb7c5e5d5f719c
parent4eb937058ffd9d413929f566246eb684efe8eab5 (diff)
parent6995f2c8be901b5f3f4183ccc4a58c209e8bce52 (diff)
Merge patch series "Adjust how autoprobe is implemented"
Simon Glass <sjg@chromium.org> says: This little series makes a minor change to how autoprobe is implemented, as discussed on the list. Link: https://lore.kernel.org/r/20240626235717.272219-1-marex@denx.de Link: https://lore.kernel.org/r/20241120153642.861633-1-sjg@chromium.org
-rw-r--r--common/board_f.c9
-rw-r--r--common/board_r.c2
-rw-r--r--common/spl/spl.c4
-rw-r--r--doc/develop/driver-model/design.rst17
-rw-r--r--drivers/core/root.c36
-rw-r--r--include/dm/root.h15
6 files changed, 69 insertions, 14 deletions
diff --git a/common/board_f.c b/common/board_f.c
index 54c48d42ee9..6c5c3bfab48 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -815,21 +815,26 @@ static int initf_bootstage(void)
static int initf_dm(void)
{
-#if defined(CONFIG_DM) && CONFIG_IS_ENABLED(SYS_MALLOC_F)
int ret;
+ if (!CONFIG_IS_ENABLED(SYS_MALLOC_F))
+ return 0;
+
bootstage_start(BOOTSTAGE_ID_ACCUM_DM_F, "dm_f");
ret = dm_init_and_scan(true);
bootstage_accum(BOOTSTAGE_ID_ACCUM_DM_F);
if (ret)
return ret;
+ ret = dm_autoprobe();
+ if (ret)
+ return ret;
+
if (IS_ENABLED(CONFIG_TIMER_EARLY)) {
ret = dm_timer_init();
if (ret)
return ret;
}
-#endif
return 0;
}
diff --git a/common/board_r.c b/common/board_r.c
index f63c6aed4d5..179259b00de 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -250,7 +250,7 @@ static int initr_dm(void)
if (ret)
return ret;
- return 0;
+ return dm_autoprobe();
}
#endif
diff --git a/common/spl/spl.c b/common/spl/spl.c
index ad31a2f8b6c..02269fff93c 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -500,6 +500,10 @@ static int spl_common_init(bool setup_malloc)
debug("dm_init_and_scan() returned error %d\n", ret);
return ret;
}
+
+ ret = dm_autoprobe();
+ if (ret)
+ return ret;
}
return 0;
diff --git a/doc/develop/driver-model/design.rst b/doc/develop/driver-model/design.rst
index 8c2c81d7ac9..92f638a0204 100644
--- a/doc/develop/driver-model/design.rst
+++ b/doc/develop/driver-model/design.rst
@@ -842,6 +842,23 @@ steps (see device_probe()):
cause the uclass to do some housekeeping to record the device as
activated and 'known' by the uclass.
+For some platforms, certain devices must be probed to get the platform into
+a working state. To help with this, drivers marked with DM_FLAG_PROBE_AFTER_BIND
+will be probed immediately after all devices are bound. For now, this happens in
+SPL, before relocation and after relocation. See the call to ``dm_autoprobe()``
+for where this is done.
+
+The auto-probe feature is tricky because it bypasses the normal ordering of
+probing. General, if device A (e.g. video) needs device B (e.g. clock), then
+A's probe() method uses ``clk_get_by_index()`` and B is probed before A. But
+A is only probed when it is used. Therefore care should be taken when using
+auto-probe, limiting it to devices which truly are essential, such as power
+domains or critical clocks.
+
+See here for more discussion of this feature:
+
+:Link: https://patchwork.ozlabs.org/project/uboot/patch/20240626235717.272219-1-marex@denx.de/
+
Running stage
^^^^^^^^^^^^^
diff --git a/drivers/core/root.c b/drivers/core/root.c
index c7fb58285ca..15b8c83fee9 100644
--- a/drivers/core/root.c
+++ b/drivers/core/root.c
@@ -288,26 +288,40 @@ void *dm_priv_to_rw(void *priv)
}
#endif
-static int dm_probe_devices(struct udevice *dev, bool pre_reloc_only)
+/**
+ * dm_probe_devices() - Check whether to probe a device and all children
+ *
+ * Probes the device if DM_FLAG_PROBE_AFTER_BIND is enabled for it. Then scans
+ * all its children recursively to do the same.
+ *
+ * @dev: Device to (maybe) probe
+ * Return 0 if OK, -ve on error
+ */
+static int dm_probe_devices(struct udevice *dev)
{
- ofnode node = dev_ofnode(dev);
struct udevice *child;
- int ret;
-
- if (pre_reloc_only &&
- (!ofnode_valid(node) || !ofnode_pre_reloc(node)) &&
- !(dev->driver->flags & DM_FLAG_PRE_RELOC))
- goto probe_children;
if (dev_get_flags(dev) & DM_FLAG_PROBE_AFTER_BIND) {
+ int ret;
+
ret = device_probe(dev);
if (ret)
return ret;
}
-probe_children:
list_for_each_entry(child, &dev->child_head, sibling_node)
- dm_probe_devices(child, pre_reloc_only);
+ dm_probe_devices(child);
+
+ return 0;
+}
+
+int dm_autoprobe(void)
+{
+ int ret;
+
+ ret = dm_probe_devices(gd->dm_root);
+ if (ret)
+ return log_msg_ret("pro", ret);
return 0;
}
@@ -344,7 +358,7 @@ static int dm_scan(bool pre_reloc_only)
if (ret)
return ret;
- return dm_probe_devices(gd->dm_root, pre_reloc_only);
+ return 0;
}
int dm_init_and_scan(bool pre_reloc_only)
diff --git a/include/dm/root.h b/include/dm/root.h
index 5651b868c8b..286bd9a2ddd 100644
--- a/include/dm/root.h
+++ b/include/dm/root.h
@@ -137,6 +137,21 @@ int dm_scan_other(bool pre_reloc_only);
int dm_init_and_scan(bool pre_reloc_only);
/**
+ * dm_autoprobe() - Probe devices which are marked for probe-after-bind
+ *
+ * This probes all devices with a DM_FLAG_PROBE_AFTER_BIND flag. It checks the
+ * entire tree, so parent nodes need not have the flag set.
+ *
+ * It recursively probes parent nodes, so they do not need to have the flag
+ * set themselves. Since parents are always probed before children, if a child
+ * has the flag set, then its parent (and any devices up the chain to the root
+ * device) will be probed too.
+ *
+ * Return: 0 if OK, -ve on error
+ */
+int dm_autoprobe(void);
+
+/**
* dm_init() - Initialise Driver Model structures
*
* This function will initialize roots of driver tree and class tree.