[PATCH v1 3/3] mfd: max8907: Convert to use device managed poweroff handler

From: Svyatoslav Ryhel

Date: Sun Sep 27 2026 - 11:59:07 EST


Replace the legacy global 'pm_power_off' function pointer assignment with
the devm_register_sys_off_handler() helper.

Signed-off-by: Svyatoslav Ryhel <clamor95@xxxxxxxxx>
---
drivers/mfd/max8907.c | 27 ++++++++++++++++-----------
1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/drivers/mfd/max8907.c b/drivers/mfd/max8907.c
index 363ac80c0593b..0cecb53b62078 100644
--- a/drivers/mfd/max8907.c
+++ b/drivers/mfd/max8907.c
@@ -15,6 +15,7 @@
#include <linux/mfd/max8907.h>
#include <linux/module.h>
#include <linux/of.h>
+#include <linux/reboot.h>
#include <linux/regmap.h>
#include <linux/slab.h>

@@ -173,19 +174,18 @@ static const struct regmap_irq_chip max8907_rtc_irq_chip = {
.num_irqs = ARRAY_SIZE(max8907_rtc_irqs),
};

-static struct max8907 *max8907_pm_off;
-static void max8907_power_off(void)
+static int max8907_power_off(struct sys_off_data *data)
{
- regmap_update_bits(max8907_pm_off->regmap_gen, MAX8907_REG_RESET_CNFG,
- MAX8907_MASK_POWER_OFF, MAX8907_MASK_POWER_OFF);
+ struct max8907 *max8907 = data->cb_data;
+
+ return regmap_update_bits(max8907->regmap_gen, MAX8907_REG_RESET_CNFG,
+ MAX8907_MASK_POWER_OFF, MAX8907_MASK_POWER_OFF);
}

static int max8907_i2c_probe(struct i2c_client *i2c)
{
struct max8907 *max8907;
int ret;
- bool pm_off = of_property_read_bool(i2c->dev.of_node,
- "maxim,system-power-controller");

max8907 = devm_kzalloc(&i2c->dev, sizeof(struct max8907), GFP_KERNEL);
if (!max8907) {
@@ -204,6 +204,16 @@ static int max8907_i2c_probe(struct i2c_client *i2c)
goto err_regmap_gen;
}

+ if (device_property_read_bool(&i2c->dev, "system-power-controller") ||
+ device_property_read_bool(&i2c->dev, "maxim,system-power-controller")) {
+ ret = devm_register_sys_off_handler(&i2c->dev, SYS_OFF_MODE_POWER_OFF,
+ SYS_OFF_PRIO_DEFAULT,
+ &max8907_power_off, max8907);
+ if (ret)
+ return dev_err_probe(&i2c->dev, ret,
+ "failed to register poweroff handler\n");
+ }
+
max8907->i2c_rtc = i2c_new_dummy_device(i2c->adapter, MAX8907_RTC_I2C_ADDR);
if (IS_ERR(max8907->i2c_rtc)) {
ret = PTR_ERR(max8907->i2c_rtc);
@@ -250,11 +260,6 @@ static int max8907_i2c_probe(struct i2c_client *i2c)
goto err_add_devices;
}

- if (pm_off && !pm_power_off) {
- max8907_pm_off = max8907;
- pm_power_off = max8907_power_off;
- }
-
return 0;

err_add_devices:
--
2.53.0