power: reset: atc260x-poweroff: Use devm_register_sys_off_handler(POWER_OFF)
authorAndrew Davis <afd@ti.com>
Mon, 12 Feb 2024 16:28:14 +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-3-afd@ti.com
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/reset/atc260x-poweroff.c

index ce2748d3282c3cf50573fc7631fcbab5ccb4c256..e3e4621ccb1dd2337341969fd1fce3f81c539e92 100644 (file)
@@ -19,9 +19,6 @@ struct atc260x_pwrc {
        int (*do_poweroff)(const struct atc260x_pwrc *pwrc, bool restart);
 };
 
-/* Global variable needed only for pm_power_off */
-static struct atc260x_pwrc *atc260x_pwrc_data;
-
 static int atc2603c_do_poweroff(const struct atc260x_pwrc *pwrc, bool restart)
 {
        int ret, deep_sleep = 0;
@@ -164,11 +161,15 @@ static int atc2609a_init(const struct atc260x_pwrc *pwrc)
        return ret;
 }
 
-static void atc260x_pwrc_pm_handler(void)
+static int atc260x_pwrc_pm_handler(struct sys_off_data *data)
 {
-       atc260x_pwrc_data->do_poweroff(atc260x_pwrc_data, false);
+       struct atc260x_pwrc *pwrc = data->cb_data;
+
+       pwrc->do_poweroff(pwrc, false);
 
        WARN_ONCE(1, "Unable to power off system\n");
+
+       return NOTIFY_DONE;
 }
 
 static int atc260x_pwrc_restart_handler(struct sys_off_data *data)
@@ -211,14 +212,14 @@ static int atc260x_pwrc_probe(struct platform_device *pdev)
        if (ret)
                return ret;
 
-       platform_set_drvdata(pdev, priv);
-
-       if (!pm_power_off) {
-               atc260x_pwrc_data = priv;
-               pm_power_off = atc260x_pwrc_pm_handler;
-       } else {
-               dev_warn(priv->dev, "Poweroff callback already assigned\n");
-       }
+       ret = devm_register_sys_off_handler(priv->dev,
+                                           SYS_OFF_MODE_POWER_OFF,
+                                           SYS_OFF_PRIO_DEFAULT,
+                                           atc260x_pwrc_pm_handler,
+                                           priv);
+       if (ret)
+               dev_err(priv->dev, "failed to register power-off handler: %d\n",
+                       ret);
 
        ret = devm_register_sys_off_handler(priv->dev,
                                            SYS_OFF_MODE_RESTART,
@@ -232,19 +233,8 @@ static int atc260x_pwrc_probe(struct platform_device *pdev)
        return ret;
 }
 
-static void atc260x_pwrc_remove(struct platform_device *pdev)
-{
-       struct atc260x_pwrc *priv = platform_get_drvdata(pdev);
-
-       if (atc260x_pwrc_data == priv) {
-               pm_power_off = NULL;
-               atc260x_pwrc_data = NULL;
-       }
-}
-
 static struct platform_driver atc260x_pwrc_driver = {
        .probe = atc260x_pwrc_probe,
-       .remove_new = atc260x_pwrc_remove,
        .driver = {
                .name = "atc260x-pwrc",
        },