<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">From 1b1305e95e85624f538ec56db9acf88e2d3d7397 Mon Sep 17 00:00:00 2001
From: Samuel Holland &lt;samuel@sholland.org&gt;
Date: Wed, 28 Dec 2022 10:27:52 -0600
Subject: [PATCH] mfd: axp20x: Switch to the sys-off handler API

This removes a layer of indirection through pm_power_off() and allows
the PMIC handler to be used as a fallback when firmware power off fails.
This happens on boards like the Clockwork DevTerm R-01 where OpenSBI
does not know how to use the PMIC to power off the board.

Move the check for AXP288 to avoid registering a dummy handler.

Signed-off-by: Samuel Holland &lt;samuel@sholland.org&gt;
[Lee: Removed superfluous new line]
Signed-off-by: Lee Jones &lt;lee@kernel.org&gt;
Link: https://lore.kernel.org/r/20221228162752.14204-1-samuel@sholland.org
---
 drivers/mfd/axp20x.c | 27 +++++++++++----------------
 1 file changed, 11 insertions(+), 16 deletions(-)

--- a/drivers/mfd/axp20x.c
+++ b/drivers/mfd/axp20x.c
@@ -23,7 +23,7 @@
 #include &lt;linux/mfd/core.h&gt;
 #include &lt;linux/module.h&gt;
 #include &lt;linux/of_device.h&gt;
-#include &lt;linux/pm_runtime.h&gt;
+#include &lt;linux/reboot.h&gt;
 #include &lt;linux/regmap.h&gt;
 #include &lt;linux/regulator/consumer.h&gt;
 
@@ -832,17 +832,16 @@ static const struct mfd_cell axp813_cell
 	},
 };
 
-static struct axp20x_dev *axp20x_pm_power_off;
-static void axp20x_power_off(void)
+static int axp20x_power_off(struct sys_off_data *data)
 {
-	if (axp20x_pm_power_off-&gt;variant == AXP288_ID)
-		return;
+	struct axp20x_dev *axp20x = data-&gt;cb_data;
 
-	regmap_write(axp20x_pm_power_off-&gt;regmap, AXP20X_OFF_CTRL,
-		     AXP20X_OFF);
+	regmap_write(axp20x-&gt;regmap, AXP20X_OFF_CTRL, AXP20X_OFF);
 
 	/* Give capacitors etc. time to drain to avoid kernel panic msg. */
 	mdelay(500);
+
+	return NOTIFY_DONE;
 }
 
 int axp20x_match_device(struct axp20x_dev *axp20x)
@@ -1009,10 +1008,11 @@ int axp20x_device_probe(struct axp20x_de
 		return ret;
 	}
 
-	if (!pm_power_off) {
-		axp20x_pm_power_off = axp20x;
-		pm_power_off = axp20x_power_off;
-	}
+	if (axp20x-&gt;variant != AXP288_ID)
+		devm_register_sys_off_handler(axp20x-&gt;dev,
+					      SYS_OFF_MODE_POWER_OFF,
+					      SYS_OFF_PRIO_DEFAULT,
+					      axp20x_power_off, axp20x);
 
 	dev_info(axp20x-&gt;dev, "AXP20X driver loaded\n");
 
@@ -1022,11 +1022,6 @@ EXPORT_SYMBOL(axp20x_device_probe);
 
 void axp20x_device_remove(struct axp20x_dev *axp20x)
 {
-	if (axp20x == axp20x_pm_power_off) {
-		axp20x_pm_power_off = NULL;
-		pm_power_off = NULL;
-	}
-
 	mfd_remove_devices(axp20x-&gt;dev);
 	regmap_del_irq_chip(axp20x-&gt;irq, axp20x-&gt;regmap_irqc);
 }
</pre></body></html>