restart-poweroff.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Power off by restarting and let u-boot keep hold of the machine
  3. * until the user presses a button for example.
  4. *
  5. * Andrew Lunn <andrew@lunn.ch>
  6. *
  7. * Copyright (C) 2012 Andrew Lunn
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/of_platform.h>
  17. #include <linux/module.h>
  18. #include <linux/reboot.h>
  19. #include <asm/system_misc.h>
  20. static void restart_poweroff_do_poweroff(void)
  21. {
  22. arm_pm_restart(REBOOT_HARD, NULL);
  23. }
  24. static int restart_poweroff_probe(struct platform_device *pdev)
  25. {
  26. /* If a pm_power_off function has already been added, leave it alone */
  27. if (pm_power_off != NULL) {
  28. dev_err(&pdev->dev,
  29. "pm_power_off function already registered");
  30. return -EBUSY;
  31. }
  32. pm_power_off = &restart_poweroff_do_poweroff;
  33. return 0;
  34. }
  35. static int restart_poweroff_remove(struct platform_device *pdev)
  36. {
  37. if (pm_power_off == &restart_poweroff_do_poweroff)
  38. pm_power_off = NULL;
  39. return 0;
  40. }
  41. static const struct of_device_id of_restart_poweroff_match[] = {
  42. { .compatible = "restart-poweroff", },
  43. {},
  44. };
  45. static struct platform_driver restart_poweroff_driver = {
  46. .probe = restart_poweroff_probe,
  47. .remove = restart_poweroff_remove,
  48. .driver = {
  49. .name = "poweroff-restart",
  50. .owner = THIS_MODULE,
  51. .of_match_table = of_restart_poweroff_match,
  52. },
  53. };
  54. module_platform_driver(restart_poweroff_driver);
  55. MODULE_AUTHOR("Andrew Lunn <andrew@lunn.ch");
  56. MODULE_DESCRIPTION("restart poweroff driver");
  57. MODULE_LICENSE("GPLv2");
  58. MODULE_ALIAS("platform:poweroff-restart");