* [PATCH v2] power: reset: hisi: Manage restart handler and MMIO mapping
@ 2026-12-06 1:46 Tian Xuechen
2026-12-06 2:20 ` Sebastian Reichel
0 siblings, 1 reply; 2+ messages in thread
From: Tian Xuechen @ 2026-12-06 1:46 UTC (permalink / raw)
To: sre; +Cc: linux-pm
The HiSilicon reboot driver leaves its restart handler registered and
its MMIO mapping in place when the device is unbound.
Keep the reboot registers and offset in per-device data and pass that
data to a managed restart handler. Map the registers before registering
the handler so devres unregisters the handler before unmapping the
registers and freeing the callback data. Keep the existing restart
priority.
Fixes: 6724534c79ea ("power/reset: hisi: Register with kernel restart handler")
Suggested-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Signed-off-by: Tian Xuechen <202300460064@mail.sdu.edu.cn>
---
v2:
- Use devm_platform_ioremap_resource() and devm_register_sys_off_handler()
as suggested by Sebastian.
- Send this patch on its own. The other three drivers already have
fixes in the maintainer's for-next branch.
v1: https://lore.kernel.org/r/20261129094744.1691778-3-202300460064@mail.sdu.edu.cn
drivers/power/reset/hisi-reboot.c | 61 +++++++++++++++----------------
1 file changed, 30 insertions(+), 31 deletions(-)
diff --git a/drivers/power/reset/hisi-reboot.c b/drivers/power/reset/hisi-reboot.c
index 344093405..0b6570964 100644
--- a/drivers/power/reset/hisi-reboot.c
+++ b/drivers/power/reset/hisi-reboot.c
@@ -8,23 +8,27 @@
* Author: Haojian Zhuang <haojian.zhuang@linaro.org>
*/
-#include <linux/delay.h>
+#include <linux/err.h>
#include <linux/io.h>
#include <linux/module.h>
#include <linux/notifier.h>
-#include <linux/of_address.h>
+#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/reboot.h>
+#include <linux/slab.h>
#include <asm/proc-fns.h>
-static void __iomem *base;
-static u32 reboot_offset;
+struct hisi_reboot {
+ void __iomem *base;
+ u32 offset;
+};
-static int hisi_restart_handler(struct notifier_block *this,
- unsigned long mode, void *cmd)
+static int hisi_restart_handler(struct sys_off_data *data)
{
- writel_relaxed(0xdeadbeef, base + reboot_offset);
+ struct hisi_reboot *reboot = data->cb_data;
+
+ writel_relaxed(0xdeadbeef, reboot->base + reboot->offset);
while (1)
cpu_do_idle();
@@ -32,36 +36,31 @@ static int hisi_restart_handler(struct notifier_block *this,
return NOTIFY_DONE;
}
-static struct notifier_block hisi_restart_nb = {
- .notifier_call = hisi_restart_handler,
- .priority = 128,
-};
-
static int hisi_reboot_probe(struct platform_device *pdev)
{
- struct device_node *np = pdev->dev.of_node;
- int err;
+ struct device *dev = &pdev->dev;
+ struct hisi_reboot *reboot;
+ int ret;
+
+ reboot = devm_kzalloc(dev, sizeof(*reboot), GFP_KERNEL);
+ if (!reboot)
+ return -ENOMEM;
- base = of_iomap(np, 0);
- if (!base) {
- WARN(1, "failed to map base address");
- return -ENODEV;
- }
+ ret = of_property_read_u32(dev->of_node, "reboot-offset",
+ &reboot->offset);
+ if (ret)
+ return dev_err_probe(dev, ret, "failed to read reboot-offset\n");
- if (of_property_read_u32(np, "reboot-offset", &reboot_offset) < 0) {
- pr_err("failed to find reboot-offset property\n");
- iounmap(base);
- return -EINVAL;
- }
+ reboot->base = devm_platform_ioremap_resource(pdev, 0);
+ if (IS_ERR(reboot->base))
+ return PTR_ERR(reboot->base);
- err = register_restart_handler(&hisi_restart_nb);
- if (err) {
- dev_err(&pdev->dev, "cannot register restart handler (err=%d)\n",
- err);
- iounmap(base);
- }
+ ret = devm_register_sys_off_handler(dev, SYS_OFF_MODE_RESTART, 128,
+ hisi_restart_handler, reboot);
+ if (ret)
+ return dev_err_probe(dev, ret, "failed to register restart handler\n");
- return err;
+ return 0;
}
static const struct of_device_id hisi_reboot_of_match[] = {
base-commit: a543e120d437eb518c9b27182eb1d219194b3c77
--
2.55.0.windows.5
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v2] power: reset: hisi: Manage restart handler and MMIO mapping
2026-12-06 1:46 [PATCH v2] power: reset: hisi: Manage restart handler and MMIO mapping Tian Xuechen
@ 2026-12-06 2:20 ` Sebastian Reichel
0 siblings, 0 replies; 2+ messages in thread
From: Sebastian Reichel @ 2026-12-06 2:20 UTC (permalink / raw)
To: sre, Tian Xuechen; +Cc: linux-pm
On Sun, 06 Dec 2026 09:46:32 +0800, Tian Xuechen wrote:
> The HiSilicon reboot driver leaves its restart handler registered and
> its MMIO mapping in place when the device is unbound.
>
> Keep the reboot registers and offset in per-device data and pass that
> data to a managed restart handler. Map the registers before registering
> the handler so devres unregisters the handler before unmapping the
> registers and freeing the callback data. Keep the existing restart
> priority.
>
> [...]
Applied, thanks!
[1/1] power: reset: hisi: Manage restart handler and MMIO mapping
commit: bc2de0ff51a59327fa2955e0605076279998b450
Best regards,
--
Sebastian Reichel <sebastian.reichel@collabora.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-06 2:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-06 1:46 [PATCH v2] power: reset: hisi: Manage restart handler and MMIO mapping Tian Xuechen
2026-12-06 2:20 ` Sebastian Reichel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox