[PATCH v3 4/4] mfd: max8907: Convert to use device managed poweroff handler
From: Svyatoslav Ryhel
Date: Mon Oct 19 2026 - 06:23:00 EST
Replace the legacy global 'pm_power_off' function pointer assignment with
the devm_register_power_off_handler() helper.
Signed-off-by: Svyatoslav Ryhel <clamor95@xxxxxxxxx>
---
drivers/mfd/max8907.c | 24 +++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)
diff --git a/drivers/mfd/max8907.c b/drivers/mfd/max8907.c
index fab44be7ced57..6d5e6a1556fd5 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,11 +174,17 @@ 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;
+ int ret;
+
+ ret = regmap_update_bits(max8907->regmap_gen, MAX8907_REG_RESET_CNFG,
+ MAX8907_MASK_POWER_OFF, MAX8907_MASK_POWER_OFF);
+ if (ret)
+ dev_err(max8907->dev, "failed to power off the device!\n");
+
+ return NOTIFY_DONE;
}
static int max8907_i2c_probe(struct i2c_client *i2c)
@@ -185,8 +192,6 @@ static int max8907_i2c_probe(struct i2c_client *i2c)
struct device *dev = &i2c->dev;
struct max8907 *max8907;
int ret;
- bool pm_off = of_property_read_bool(dev->of_node,
- "maxim,system-power-controller");
max8907 = devm_kzalloc(dev, sizeof(*max8907), GFP_KERNEL);
if (!max8907)
@@ -238,9 +243,10 @@ static int max8907_i2c_probe(struct i2c_client *i2c)
if (ret)
return dev_err_probe(dev, ret, "Failed to add MFD devices\n");
- if (pm_off && !pm_power_off) {
- max8907_pm_off = max8907;
- pm_power_off = max8907_power_off;
+ if (of_device_is_system_power_controller(dev->of_node)) {
+ ret = devm_register_power_off_handler(dev, max8907_power_off, max8907);
+ if (ret)
+ return dev_err_probe(dev, ret, "failed to register power-off handler\n");
}
return 0;
--
2.53.0