From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH v2 03/10] power: reset: reboot-mode: port syscon-reboot-mode support
Date: Mon, 28 Sep 2020 16:45:07 +0200 [thread overview]
Message-ID: <20200928144514.14398-4-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20200928144514.14398-1-a.fatoum@pengutronix.de>
Reboot modes are one-shot information that should be valid for only a
single reset. Syscons that survive a warm reset are one way to implement
this. This is used by many BootROMs to allow falling into a recovery
mode on the next boot. This ports the Linux syscon-reboot-mode support.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
Documentation/user/reboot-mode.rst | 11 +++
drivers/power/reset/Kconfig | 11 +++
drivers/power/reset/Makefile | 1 +
drivers/power/reset/syscon-reboot-mode.c | 85 ++++++++++++++++++++++++
4 files changed, 108 insertions(+)
create mode 100644 drivers/power/reset/syscon-reboot-mode.c
diff --git a/Documentation/user/reboot-mode.rst b/Documentation/user/reboot-mode.rst
index 1908da3ed2d7..9321d928f41a 100644
--- a/Documentation/user/reboot-mode.rst
+++ b/Documentation/user/reboot-mode.rst
@@ -45,6 +45,17 @@ Reboot mode providers have priorities. The provider with the highest
priority has its parameters aliased as ``$global.system.reboot_mode.prev``
and ``$global.system.reboot_mode.next``.
+Reset
+~~~~~
+
+Reboot modes can be stored on a syscon wrapping general purpose registers
+that survives warm resets. If the system instead did reset via an external
+power management IC, the registers may lose their value.
+
+If such reboot mode storage is used, users must take care to use the correct
+reset provider. In barebox, multiple reset providers may co-exist. They
+``reset`` command allows listing and choosing a specific reboot mode.
+
Disambiguation
~~~~~~~~~~~~~~
diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig
index 5554fc122d92..f65e1f67fd59 100644
--- a/drivers/power/reset/Kconfig
+++ b/drivers/power/reset/Kconfig
@@ -3,3 +3,14 @@
config REBOOT_MODE
bool
+
+config SYSCON_REBOOT_MODE
+ bool "Generic SYSCON regmap reboot mode driver"
+ depends on OFDEVICE
+ depends on MFD_SYSCON
+ select REBOOT_MODE
+ help
+ Say y here will enable reboot mode driver. This will
+ get reboot mode arguments and store it in SYSCON mapped
+ register, then the bootloader can read it to take different
+ action according to the mode.
diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile
index 68231f044a52..56feec78cf26 100644
--- a/drivers/power/reset/Makefile
+++ b/drivers/power/reset/Makefile
@@ -1,2 +1,3 @@
# SPDX-License-Identifier: GPL-2.0-only
obj-$(CONFIG_REBOOT_MODE) += reboot-mode.o
+obj-$(CONFIG_SYSCON_REBOOT_MODE) += syscon-reboot-mode.o
diff --git a/drivers/power/reset/syscon-reboot-mode.c b/drivers/power/reset/syscon-reboot-mode.c
new file mode 100644
index 000000000000..5e4aed943d5c
--- /dev/null
+++ b/drivers/power/reset/syscon-reboot-mode.c
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2016, Fuzhou Rockchip Electronics Co., Ltd
+ */
+
+#include <common.h>
+#include <init.h>
+#include <driver.h>
+#include <of.h>
+#include <regmap.h>
+#include <mfd/syscon.h>
+#include <linux/reboot-mode.h>
+
+struct syscon_reboot_mode {
+ struct regmap *map;
+ struct reboot_mode_driver reboot;
+ u32 offset;
+ u32 mask;
+};
+
+static int syscon_reboot_mode_write(struct reboot_mode_driver *reboot,
+ unsigned int magic)
+{
+ struct syscon_reboot_mode *syscon_rbm;
+ int ret;
+
+ syscon_rbm = container_of(reboot, struct syscon_reboot_mode, reboot);
+
+ ret = regmap_update_bits(syscon_rbm->map, syscon_rbm->offset,
+ syscon_rbm->mask, magic);
+ if (ret < 0)
+ dev_err(reboot->dev, "update reboot mode bits failed\n");
+
+ return ret;
+}
+
+static int syscon_reboot_mode_probe(struct device_d *dev)
+{
+ int ret;
+ struct syscon_reboot_mode *syscon_rbm;
+ struct device_node *np = dev->device_node;
+ u32 magic;
+
+ syscon_rbm = xzalloc(sizeof(*syscon_rbm));
+
+ syscon_rbm->reboot.dev = dev;
+ syscon_rbm->reboot.write = syscon_reboot_mode_write;
+ syscon_rbm->mask = 0xffffffff;
+
+ syscon_rbm->map = syscon_node_to_regmap(dev->parent->device_node);
+ if (IS_ERR(syscon_rbm->map))
+ return PTR_ERR(syscon_rbm->map);
+
+ if (of_property_read_u32(np, "offset", &syscon_rbm->offset))
+ return -EINVAL;
+
+ of_property_read_u32(np, "mask", &syscon_rbm->mask);
+
+ ret = regmap_read(syscon_rbm->map, syscon_rbm->offset, &magic);
+ if (ret) {
+ dev_err(dev, "error reading reboot mode: %s\n",
+ strerror(-ret));
+ return ret;
+ }
+
+ magic &= syscon_rbm->mask;
+
+ ret = reboot_mode_register(&syscon_rbm->reboot, magic);
+ if (ret)
+ dev_err(dev, "can't register reboot mode\n");
+
+ return ret;
+}
+
+static const struct of_device_id syscon_reboot_mode_of_match[] = {
+ { .compatible = "syscon-reboot-mode" },
+ { /* sentinel */ }
+};
+
+static struct driver_d syscon_reboot_mode_driver = {
+ .probe = syscon_reboot_mode_probe,
+ .name = "syscon-reboot-mode",
+ .of_compatible = syscon_reboot_mode_of_match,
+};
+coredevice_platform_driver(syscon_reboot_mode_driver);
--
2.28.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2020-09-28 14:45 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-28 14:45 [PATCH v2 00/10] power: reset: add support for syscon reboot Ahmad Fatoum
2020-09-28 14:45 ` [PATCH v2 01/10] usbgadget: autostart: support delayed usbgadget.autostart=1 Ahmad Fatoum
2020-09-28 14:45 ` [PATCH v2 02/10] drivers: add reboot-mode infrastructure Ahmad Fatoum
2020-09-28 14:45 ` Ahmad Fatoum [this message]
2020-09-28 14:45 ` [PATCH v2 04/10] power: reset: reboot-mode: fix up node into boot device tree Ahmad Fatoum
2020-09-28 14:45 ` [PATCH v2 05/10] defaultenv: provide defaults for generic reboot modes Ahmad Fatoum
2020-09-28 14:45 ` [PATCH v2 06/10] ARM: dts: stm32mp: setup syscon-reboot-mode on TAMP general purpose register Ahmad Fatoum
2020-09-28 14:45 ` [PATCH v2 07/10] ARM: stm32mp: remove custom reboot mode logic from arch code Ahmad Fatoum
2020-09-28 14:45 ` [PATCH v2 08/10] power: reset: reboot-mode: support multi-word magic Ahmad Fatoum
2020-09-28 14:45 ` [PATCH v2 09/10] power: reset: syscon-reboot-mode: support multi-word reboot modes Ahmad Fatoum
2020-09-28 14:45 ` [PATCH v2 10/10] ARM: dts: i.MX6qdl: define BootROM reboot-mode on top of SRC_GPR{9, 10} Ahmad Fatoum
2020-09-29 8:25 ` [PATCH v2 00/10] power: reset: add support for syscon reboot 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=20200928144514.14398-4-a.fatoum@pengutronix.de \
--to=a.fatoum@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