From 4dee9d16c01cec6f290f9ff25cda72416c8d2d3f Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Fri, 25 Sep 2020 11:09:59 +0200 Subject: of: Add common device tree register function The different architectures duplicate some code around unflattening and registering the device tree. Add common functions to reduce this duplication. Signed-off-by: Sascha Hauer --- drivers/of/base.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'drivers') diff --git a/drivers/of/base.c b/drivers/of/base.c index 0a2632f963..4e88af7b22 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -1567,6 +1567,34 @@ int of_set_root_node(struct device_node *node) return 0; } +void barebox_register_of(struct device_node *root) +{ + if (root_node) + return; + + of_fix_tree(root); + of_set_root_node(root); + + if (IS_ENABLED(CONFIG_OFDEVICE)) + of_probe(); +} + +void barebox_register_fdt(const void *dtb) +{ + struct device_node *root; + + if (root_node) + return; + + root = of_unflatten_dtb(dtb); + if (IS_ERR(root)) { + pr_err("Cannot unflatten dtb: %pe\n", root); + return; + } + + barebox_register_of(root); +} + /** * of_device_is_available - check if a device is available for use * -- cgit v1.2.3