1 From 1b1305e95e85624f538ec56db9acf88e2d3d7397 Mon Sep 17 00:00:00 2001
2 From: Samuel Holland <samuel@sholland.org>
3 Date: Wed, 28 Dec 2022 10:27:52 -0600
4 Subject: [PATCH] mfd: axp20x: Switch to the sys-off handler API
6 This removes a layer of indirection through pm_power_off() and allows
7 the PMIC handler to be used as a fallback when firmware power off fails.
8 This happens on boards like the Clockwork DevTerm R-01 where OpenSBI
9 does not know how to use the PMIC to power off the board.
11 Move the check for AXP288 to avoid registering a dummy handler.
13 Signed-off-by: Samuel Holland <samuel@sholland.org>
14 [Lee: Removed superfluous new line]
15 Signed-off-by: Lee Jones <lee@kernel.org>
16 Link: https://lore.kernel.org/r/20221228162752.14204-1-samuel@sholland.org
18 drivers/mfd/axp20x.c | 27 +++++++++++----------------
19 1 file changed, 11 insertions(+), 16 deletions(-)
21 --- a/drivers/mfd/axp20x.c
22 +++ b/drivers/mfd/axp20x.c
24 #include <linux/mfd/core.h>
25 #include <linux/module.h>
26 #include <linux/of_device.h>
27 -#include <linux/pm_runtime.h>
28 +#include <linux/reboot.h>
29 #include <linux/regmap.h>
30 #include <linux/regulator/consumer.h>
32 @@ -832,17 +832,16 @@ static const struct mfd_cell axp813_cell
36 -static struct axp20x_dev *axp20x_pm_power_off;
37 -static void axp20x_power_off(void)
38 +static int axp20x_power_off(struct sys_off_data *data)
40 - if (axp20x_pm_power_off->variant == AXP288_ID)
42 + struct axp20x_dev *axp20x = data->cb_data;
44 - regmap_write(axp20x_pm_power_off->regmap, AXP20X_OFF_CTRL,
46 + regmap_write(axp20x->regmap, AXP20X_OFF_CTRL, AXP20X_OFF);
48 /* Give capacitors etc. time to drain to avoid kernel panic msg. */
54 int axp20x_match_device(struct axp20x_dev *axp20x)
55 @@ -1009,10 +1008,11 @@ int axp20x_device_probe(struct axp20x_de
59 - if (!pm_power_off) {
60 - axp20x_pm_power_off = axp20x;
61 - pm_power_off = axp20x_power_off;
63 + if (axp20x->variant != AXP288_ID)
64 + devm_register_sys_off_handler(axp20x->dev,
65 + SYS_OFF_MODE_POWER_OFF,
66 + SYS_OFF_PRIO_DEFAULT,
67 + axp20x_power_off, axp20x);
69 dev_info(axp20x->dev, "AXP20X driver loaded\n");
71 @@ -1022,11 +1022,6 @@ EXPORT_SYMBOL(axp20x_device_probe);
73 void axp20x_device_remove(struct axp20x_dev *axp20x)
75 - if (axp20x == axp20x_pm_power_off) {
76 - axp20x_pm_power_off = NULL;
77 - pm_power_off = NULL;
80 mfd_remove_devices(axp20x->dev);
81 regmap_del_irq_chip(axp20x->irq, axp20x->regmap_irqc);