[PATCH v2 1/2] of: implement new of_device_ensure_probed_by_alias_stem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Function first goes through all the aliases which have the given stem.
It then ensures that all the devices hiding under these aliases are
probed.

User can specify one device_node which won't get probed. This is mainly
for avoiding recursion if the function will be called from device probe
function, or to specify the device which should get probed last. In the
later case the user should probe the last device manually.

Signed-off-by: Andrej Picej <andrej.picej@xxxxxxxxx>
---
Changes in v2:
 - add check for deep probe support,
 - users can now specify one device node, which won't get probed. This
   ensures that one device can be probed last and we avoid recursion, if
this device happens to have alias,
 - fix function name (ensured -> ensure).
---
 drivers/of/base.c | 40 ++++++++++++++++++++++++++++++++++++++++
 include/of.h      |  6 ++++++
 2 files changed, 46 insertions(+)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 80465d6d50..ad747e9e63 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -274,6 +274,46 @@ int of_alias_get_id_from(struct device_node *root, struct device_node *np,
 }
 EXPORT_SYMBOL_GPL(of_alias_get_id_from);
 
+/**
+ * of_device_ensured_probed_by_alias_stem - Ensure all devices with alias base name
+ * are probed
+ * @np:		Device node of a device that should be probed last, NULL if such
+ * 		device doesn't exist
+ * @stem:	Alias stem of the given device_node
+ *
+ * The function ensures all devices with the given alias stem are probed before the
+ * target device.
+ *
+ * Returns 0 on success or error code.
+ */
+int of_device_ensure_probed_by_alias_stem(struct device_node *np, const char *stem)
+{
+	struct alias_prop *app;
+	int id = -ENODEV;
+	int ret;
+
+	if (!deep_probe_is_supported())
+		return 0;
+
+	list_for_each_entry(app, &aliases_lookup, link) {
+		if (of_node_cmp(app->stem, stem) != 0)
+			continue;
+
+		/* If device node is given skip the probing of that device so we
+		 * avoid recursion.
+		 */
+		if (np != NULL && np == app->np)
+			continue;
+
+		ret = of_device_ensure_probed(app->np);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(of_device_ensure_probed_by_alias_stem);
+
 const char *of_alias_get(struct device_node *np)
 {
 	struct alias_prop *app;
diff --git a/include/of.h b/include/of.h
index 216d0ee763..0b520bb35c 100644
--- a/include/of.h
+++ b/include/of.h
@@ -261,6 +261,7 @@ extern void of_alias_scan(void);
 extern int of_alias_get_id(struct device_node *np, const char *stem);
 extern int of_alias_get_id_from(struct device_node *root, struct device_node *np,
 				const char *stem);
+extern int of_device_ensure_probed_by_alias_stem(struct device_node *np, const char *stem);
 extern const char *of_alias_get(struct device_node *np);
 extern int of_modalias_node(struct device_node *node, char *modalias, int len);
 
@@ -750,6 +751,11 @@ static inline int of_alias_get_id_from(struct device_node *root, struct device_n
 	return -ENOSYS;
 }
 
+static int of_device_ensure_probed_by_alias_stem(struct device_node *np, const char *stem)
+{
+	return -ENOSYS;
+}
+
 static inline const char *of_alias_get(struct device_node *np)
 {
 	return NULL;
-- 
2.25.1


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux