summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2020-09-28 16:45:08 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2020-09-29 10:25:02 +0200
commitb28bcba8662cf0e60d35ef30c8d284f320fc9b1c (patch)
tree99e94fa90d1d26a4c7520fd4d3a5a308ec60cff3
parentb42bf25c5bd4baffac1a4f3b40ec0ba10cc13504 (diff)
downloadbarebox-b28bcba8662cf0e60d35ef30c8d284f320fc9b1c.tar.gz
barebox-b28bcba8662cf0e60d35ef30c8d284f320fc9b1c.tar.xz
power: reset: reboot-mode: fix up node into boot device tree
Instead of relying that the kernel and barebox device trees are in sync, just enforce it by having barebox fix up the device tree node it probed into the kernel device tree. We usually want that, but some reboot mode drivers might want to inhibit the fixup, e.g. because they implement a non-upstream binding or because they communicate with the BootROM, while the kernel shouldn't. For those the fixup is made optional via a struct reboot_mode_driver::no_fixup member. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--drivers/power/reset/reboot-mode.c43
-rw-r--r--include/linux/reboot-mode.h1
2 files changed, 44 insertions, 0 deletions
diff --git a/drivers/power/reset/reboot-mode.c b/drivers/power/reset/reboot-mode.c
index 5992a2acd9..bf51c00aee 100644
--- a/drivers/power/reset/reboot-mode.c
+++ b/drivers/power/reset/reboot-mode.c
@@ -52,6 +52,46 @@ static int reboot_mode_add_param(struct device_d *dev,
return PTR_ERR_OR_ZERO(param);
}
+static struct device_node *of_get_node_by_reproducible_name(struct device_node *dstroot,
+ struct device_node *srcnp)
+{
+ struct device_node *dstnp;
+ char *name;
+
+ name = of_get_reproducible_name(srcnp);
+ dstnp = of_find_node_by_reproducible_name(dstroot, name);
+ free(name);
+
+ return dstnp;
+}
+
+static int of_reboot_mode_fixup(struct device_node *root, void *ctx)
+{
+ struct reboot_mode_driver *reboot = ctx;
+ struct device_node *dstnp, *srcnp, *dstparent;
+
+ srcnp = reboot->dev->device_node;
+ dstnp = of_get_node_by_reproducible_name(root, srcnp);
+
+ /* nothing to do when called on barebox-internal tree */
+ if (srcnp == dstnp)
+ return 0;
+
+ if (dstnp) {
+ dstparent = dstnp->parent;
+ of_delete_node(dstnp);
+ } else {
+ dstparent = of_get_node_by_reproducible_name(root, srcnp->parent);
+ }
+
+ if (!dstparent)
+ return -EINVAL;
+
+ of_copy_node(dstparent, srcnp);
+
+ return 0;
+}
+
static int reboot_mode_add_globalvar(void)
{
struct reboot_mode_driver *reboot = __boot_mode;
@@ -59,6 +99,9 @@ static int reboot_mode_add_globalvar(void)
if (!reboot)
return 0;
+ if (!reboot->no_fixup)
+ of_register_fixup(of_reboot_mode_fixup, reboot);
+
return reboot_mode_add_param(&global_device, "system.reboot_mode.", reboot);
}
late_initcall(reboot_mode_add_globalvar);
diff --git a/include/linux/reboot-mode.h b/include/linux/reboot-mode.h
index 92a1da7b55..bc57f1d72d 100644
--- a/include/linux/reboot-mode.h
+++ b/include/linux/reboot-mode.h
@@ -11,6 +11,7 @@ struct reboot_mode_driver {
struct device_d *dev;
int (*write)(struct reboot_mode_driver *reboot, u32 magic);
int priority;
+ bool no_fixup;
/* filled by reboot_mode_register */
int reboot_mode_prev, reboot_mode_next;