restart-poweroff.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 <[email protected]>
  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 void restart_poweroff_do_poweroff(void)
  17. {
  18. reboot_mode = REBOOT_HARD;
  19. machine_restart(NULL);
  20. }
  21. static int restart_poweroff_probe(struct platform_device *pdev)
  22. {
  23. /* If a pm_power_off function has already been added, leave it alone */
  24. if (pm_power_off != NULL) {
  25. dev_err(&pdev->dev,
  26. "pm_power_off function already registered");
  27. return -EBUSY;
  28. }
  29. pm_power_off = &restart_poweroff_do_poweroff;
  30. return 0;
  31. }
  32. static int restart_poweroff_remove(struct platform_device *pdev)
  33. {
  34. if (pm_power_off == &restart_poweroff_do_poweroff)
  35. pm_power_off = NULL;
  36. return 0;
  37. }
  38. static const struct of_device_id of_restart_poweroff_match[] = {
  39. { .compatible = "restart-poweroff", },
  40. {},
  41. };
  42. MODULE_DEVICE_TABLE(of, of_restart_poweroff_match);
  43. static struct platform_driver restart_poweroff_driver = {
  44. .probe = restart_poweroff_probe,
  45. .remove = restart_poweroff_remove,
  46. .driver = {
  47. .name = "poweroff-restart",
  48. .of_match_table = of_restart_poweroff_match,
  49. },
  50. };
  51. module_platform_driver(restart_poweroff_driver);
  52. MODULE_AUTHOR("Andrew Lunn <[email protected]");
  53. MODULE_DESCRIPTION("restart poweroff driver");
  54. MODULE_LICENSE("GPL v2");
  55. MODULE_ALIAS("platform:poweroff-restart");