restart-poweroff.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Power off by restarting and let u-boot keep hold of the machine
  4. * until the user presses a button for example.
  5. *
  6. * Andrew Lunn <andrew@lunn.ch>
  7. *
  8. * Copyright (C) 2012 Andrew Lunn
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/init.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/of_platform.h>
  14. #include <linux/module.h>
  15. #include <linux/reboot.h>
  16. static int restart_poweroff_do_poweroff(struct sys_off_data *data)
  17. {
  18. reboot_mode = REBOOT_HARD;
  19. machine_restart(NULL);
  20. return NOTIFY_DONE;
  21. }
  22. static int restart_poweroff_probe(struct platform_device *pdev)
  23. {
  24. /* Set this handler to low priority to not override an existing handler */
  25. return devm_register_sys_off_handler(&pdev->dev,
  26. SYS_OFF_MODE_POWER_OFF,
  27. SYS_OFF_PRIO_LOW,
  28. restart_poweroff_do_poweroff,
  29. NULL);
  30. }
  31. static const struct of_device_id of_restart_poweroff_match[] = {
  32. { .compatible = "restart-poweroff", },
  33. {},
  34. };
  35. MODULE_DEVICE_TABLE(of, of_restart_poweroff_match);
  36. static struct platform_driver restart_poweroff_driver = {
  37. .probe = restart_poweroff_probe,
  38. .driver = {
  39. .name = "poweroff-restart",
  40. .of_match_table = of_restart_poweroff_match,
  41. },
  42. };
  43. module_platform_driver(restart_poweroff_driver);
  44. MODULE_AUTHOR("Andrew Lunn <andrew@lunn.ch");
  45. MODULE_DESCRIPTION("restart poweroff driver");
  46. MODULE_ALIAS("platform:poweroff-restart");