power: reset: atc260x-poweroff: Use devm_register_sys_off_handler(RESTART)
authorAndrew Davis <afd@ti.com>
Mon, 12 Feb 2024 16:28:13 +0000 (10:28 -0600)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Tue, 13 Feb 2024 01:17:24 +0000 (02:17 +0100)
Use device life-cycle managed register function to simplify probe and
exit paths.

Signed-off-by: Andrew Davis <afd@ti.com>
Reviewed-by: Cristian Ciocaltea <cristian.ciocaltea@collabora.com>
Link: https://lore.kernel.org/r/20240212162831.67838-2-afd@ti.com
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/reset/atc260x-poweroff.c

index b4aa50e9685e1fbb496901a4d75bd9bce64779cb..ce2748d3282c3cf50573fc7631fcbab5ccb4c256 100644 (file)
@@ -16,7 +16,6 @@
 struct atc260x_pwrc {
        struct device *dev;
        struct regmap *regmap;
-       struct notifier_block restart_nb;
        int (*do_poweroff)(const struct atc260x_pwrc *pwrc, bool restart);
 };
 
@@ -172,11 +171,9 @@ static void atc260x_pwrc_pm_handler(void)
        WARN_ONCE(1, "Unable to power off system\n");
 }
 
-static int atc260x_pwrc_restart_handler(struct notifier_block *nb,
-                                       unsigned long mode, void *cmd)
+static int atc260x_pwrc_restart_handler(struct sys_off_data *data)
 {
-       struct atc260x_pwrc *pwrc = container_of(nb, struct atc260x_pwrc,
-                                                restart_nb);
+       struct atc260x_pwrc *pwrc = data->cb_data;
        pwrc->do_poweroff(pwrc, true);
 
        return NOTIFY_DONE;
@@ -194,8 +191,6 @@ static int atc260x_pwrc_probe(struct platform_device *pdev)
 
        priv->dev = &pdev->dev;
        priv->regmap = atc260x->regmap;
-       priv->restart_nb.notifier_call = atc260x_pwrc_restart_handler;
-       priv->restart_nb.priority = 192;
 
        switch (atc260x->ic_type) {
        case ATC2603C:
@@ -225,7 +220,11 @@ static int atc260x_pwrc_probe(struct platform_device *pdev)
                dev_warn(priv->dev, "Poweroff callback already assigned\n");
        }
 
-       ret = register_restart_handler(&priv->restart_nb);
+       ret = devm_register_sys_off_handler(priv->dev,
+                                           SYS_OFF_MODE_RESTART,
+                                           SYS_OFF_PRIO_HIGH,
+                                           atc260x_pwrc_restart_handler,
+                                           priv);
        if (ret)
                dev_err(priv->dev, "failed to register restart handler: %d\n",
                        ret);
@@ -241,8 +240,6 @@ static void atc260x_pwrc_remove(struct platform_device *pdev)
                pm_power_off = NULL;
                atc260x_pwrc_data = NULL;
        }
-
-       unregister_restart_handler(&priv->restart_nb);
 }
 
 static struct platform_driver atc260x_pwrc_driver = {