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

index f4d6004793d3aa0cd5af28fa05e2de5df234c812..fcd588f9ae9d3bfefb753b880e1f2c4be1784051 100644 (file)
 #include <linux/module.h>
 #include <linux/reboot.h>
 
-static void restart_poweroff_do_poweroff(void)
+static int restart_poweroff_do_poweroff(struct sys_off_data *data)
 {
        reboot_mode = REBOOT_HARD;
        machine_restart(NULL);
+       return NOTIFY_DONE;
 }
 
 static int restart_poweroff_probe(struct platform_device *pdev)
 {
-       /* If a pm_power_off function has already been added, leave it alone */
-       if (pm_power_off != NULL) {
-               dev_err(&pdev->dev,
-                       "pm_power_off function already registered");
-               return -EBUSY;
-       }
-
-       pm_power_off = &restart_poweroff_do_poweroff;
-       return 0;
-}
-
-static void restart_poweroff_remove(struct platform_device *pdev)
-{
-       if (pm_power_off == &restart_poweroff_do_poweroff)
-               pm_power_off = NULL;
+       /* Set this handler to low priority to not override an existing handler */
+       return devm_register_sys_off_handler(&pdev->dev,
+                                            SYS_OFF_MODE_POWER_OFF,
+                                            SYS_OFF_PRIO_LOW,
+                                            restart_poweroff_do_poweroff,
+                                            NULL);
 }
 
 static const struct of_device_id of_restart_poweroff_match[] = {
@@ -47,7 +39,6 @@ MODULE_DEVICE_TABLE(of, of_restart_poweroff_match);
 
 static struct platform_driver restart_poweroff_driver = {
        .probe = restart_poweroff_probe,
-       .remove_new = restart_poweroff_remove,
        .driver = {
                .name = "poweroff-restart",
                .of_match_table = of_restart_poweroff_match,