restart-poweroff.c 1.6 KB

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