From: Michael Tretter <m.tretter@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Michael Tretter <m.tretter@pengutronix.de>
Subject: [PATCH v2 4/7] of: add iterator for overlays
Date: Fri, 6 Sep 2019 15:20:05 +0200 [thread overview]
Message-ID: <20190906132008.25309-5-m.tretter@pengutronix.de> (raw)
In-Reply-To: <20190906132008.25309-1-m.tretter@pengutronix.de>
Device tree overlays (the dto files) may contain multiple fragments for
different target nodes. Each fragment contains a __overlay__ node that
is applied to target node specified in the fragment.
Add a helper to call a function for each fragment in a device tree
overlay to avoid having device tree overlay internal information in
other modules.
Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
---
Changelog:
v1->v2:
- add static inline for function stub
---
drivers/of/overlay.c | 45 ++++++++++++++++++++++++++++++++++++++++++++
include/of.h | 13 +++++++++++++
2 files changed, 58 insertions(+)
diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
index f6a0576183..abfb3df9dc 100644
--- a/drivers/of/overlay.c
+++ b/drivers/of/overlay.c
@@ -194,6 +194,51 @@ static int of_overlay_fixup(struct device_node *root, void *data)
return of_overlay_apply_tree(root, overlay);
}
+/**
+ * Iterate the overlay and call process for each fragment
+ *
+ * If process() fails for any fragment, the function will stop to process
+ * other fragments and return the error of the failed process() call.
+ */
+int of_process_overlay(struct device_node *root,
+ struct device_node *overlay,
+ int (*process)(struct device_node *target,
+ struct device_node *overlay, void *data),
+ void *data)
+{
+ struct device_node *resolved;
+ struct device_node *fragment;
+ int err = 0;
+
+ resolved = of_resolve_phandles(root, overlay);
+ if (!resolved)
+ return -EINVAL;
+
+ for_each_child_of_node(resolved, fragment) {
+ struct device_node *ovl;
+ struct device_node *target;
+
+ ovl = of_get_child_by_name(fragment, "__overlay__");
+ if (!ovl)
+ continue;
+
+ target = find_target(root, fragment);
+ if (!target)
+ continue;
+
+ err = process(target, ovl, data);
+ if (err) {
+ pr_warn("failed to process %s\n", fragment->name);
+ goto out;
+ }
+ }
+
+out:
+ of_delete_node(resolved);
+
+ return err;
+}
+
/**
* Register a devicetree overlay
*
diff --git a/include/of.h b/include/of.h
index 1483c22db1..06dc9f61a5 100644
--- a/include/of.h
+++ b/include/of.h
@@ -877,6 +877,11 @@ struct device_node *of_resolve_phandles(struct device_node *root,
int of_overlay_apply_tree(struct device_node *root,
struct device_node *overlay);
int of_register_overlay(struct device_node *overlay);
+int of_process_overlay(struct device_node *root,
+ struct device_node *overlay,
+ int (*process)(struct device_node *target,
+ struct device_node *overlay, void *data),
+ void *data);
#else
static inline struct device_node *of_resolve_phandles(struct device_node *root,
const struct device_node *overlay)
@@ -895,6 +900,14 @@ static inline int of_register_overlay(struct device_node *overlay)
return -ENOSYS;
}
+static inline int of_process_overlay(struct device_node *root,
+ struct device_node *overlay,
+ int (*process)(struct device_node *target,
+ struct device_node *overlay, void *data),
+ void *data)
+{
+ return -ENOSYS;
+}
#endif
#endif /* __OF_H */
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2019-09-06 13:20 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-06 13:20 [PATCH v2 0/7] Device Tree Overlay Support Michael Tretter
2019-09-06 13:20 ` [PATCH v2 1/7] dtc: add -@ option to enable __symbols__ Michael Tretter
2019-09-06 13:20 ` [PATCH v2 2/7] of: add support for devicetree overlays Michael Tretter
2019-09-06 13:20 ` [PATCH v2 3/7] blspec: " Michael Tretter
2019-09-06 13:20 ` Michael Tretter [this message]
2019-09-06 13:20 ` [PATCH v2 5/7] firmware: add support to load firmware from dt overlay Michael Tretter
2019-09-06 13:20 ` [PATCH v2 6/7] blspec: load firmware if specified in " Michael Tretter
2019-09-11 7:53 ` Ahmad Fatoum
2019-09-06 13:20 ` [PATCH v2 7/7] commands: add of_overlay command for device tree overlays Michael Tretter
2019-09-11 7:55 ` Ahmad Fatoum
2019-09-11 8:00 ` Ahmad Fatoum
2019-09-11 9:28 ` Michael Tretter
2019-09-11 9:33 ` Ahmad Fatoum
2019-09-09 8:57 ` [PATCH v2 0/7] Device Tree Overlay Support Sascha Hauer
2019-09-12 6:57 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190906132008.25309-5-m.tretter@pengutronix.de \
--to=m.tretter@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox