power: reset: mt6323-poweroff: Use devm_register_sys_off_handler(POWER_OFF)
authorAndrew Davis <afd@ti.com>
Mon, 12 Feb 2024 16:28:23 +0000 (10:28 -0600)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Tue, 13 Feb 2024 01:17:25 +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: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Link: https://lore.kernel.org/r/20240212162831.67838-12-afd@ti.com
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/reset/mt6323-poweroff.c

index 57a63c0..c663347 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/platform_device.h>
 #include <linux/mfd/mt6397/core.h>
 #include <linux/mfd/mt6397/rtc.h>
+#include <linux/reboot.h>
 
 struct mt6323_pwrc {
        struct device *dev;
@@ -21,11 +22,9 @@ struct mt6323_pwrc {
        u32 base;
 };
 
-static struct mt6323_pwrc *mt_pwrc;
-
-static void mt6323_do_pwroff(void)
+static int mt6323_do_pwroff(struct sys_off_data *data)
 {
-       struct mt6323_pwrc *pwrc = mt_pwrc;
+       struct mt6323_pwrc *pwrc = data->cb_data;
        unsigned int val;
        int ret;
 
@@ -44,6 +43,8 @@ static void mt6323_do_pwroff(void)
        mdelay(1000);
 
        WARN_ONCE(1, "Unable to power off system\n");
+
+       return NOTIFY_DONE;
 }
 
 static int mt6323_pwrc_probe(struct platform_device *pdev)
@@ -51,6 +52,7 @@ static int mt6323_pwrc_probe(struct platform_device *pdev)
        struct mt6397_chip *mt6397_chip = dev_get_drvdata(pdev->dev.parent);
        struct mt6323_pwrc *pwrc;
        struct resource *res;
+       int ret;
 
        pwrc = devm_kzalloc(&pdev->dev, sizeof(*pwrc), GFP_KERNEL);
        if (!pwrc)
@@ -63,19 +65,18 @@ static int mt6323_pwrc_probe(struct platform_device *pdev)
        pwrc->base = res->start;
        pwrc->regmap = mt6397_chip->regmap;
        pwrc->dev = &pdev->dev;
-       mt_pwrc = pwrc;
 
-       pm_power_off = &mt6323_do_pwroff;
+       ret = devm_register_sys_off_handler(pwrc->dev,
+                                           SYS_OFF_MODE_POWER_OFF,
+                                           SYS_OFF_PRIO_DEFAULT,
+                                           mt6323_do_pwroff,
+                                           pwrc);
+       if (ret)
+               return dev_err_probe(pwrc->dev, ret, "failed to register power-off handler\n");
 
        return 0;
 }
 
-static void mt6323_pwrc_remove(struct platform_device *pdev)
-{
-       if (pm_power_off == &mt6323_do_pwroff)
-               pm_power_off = NULL;
-}
-
 static const struct of_device_id mt6323_pwrc_dt_match[] = {
        { .compatible = "mediatek,mt6323-pwrc" },
        {},
@@ -84,7 +85,6 @@ MODULE_DEVICE_TABLE(of, mt6323_pwrc_dt_match);
 
 static struct platform_driver mt6323_pwrc_driver = {
        .probe          = mt6323_pwrc_probe,
-       .remove_new     = mt6323_pwrc_remove,
        .driver         = {
                .name   = "mt6323-pwrc",
                .of_match_table = mt6323_pwrc_dt_match,