msm-poweroff.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* Copyright (c) 2013, The Linux Foundation. All rights reserved.
  3. */
  4. #include <linux/delay.h>
  5. #include <linux/err.h>
  6. #include <linux/init.h>
  7. #include <linux/kernel.h>
  8. #include <linux/io.h>
  9. #include <linux/of.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/module.h>
  12. #include <linux/reboot.h>
  13. #include <linux/pm.h>
  14. static void __iomem *msm_ps_hold;
  15. static int do_msm_poweroff(struct sys_off_data *data)
  16. {
  17. writel(0, msm_ps_hold);
  18. mdelay(10000);
  19. return NOTIFY_DONE;
  20. }
  21. static int msm_restart_probe(struct platform_device *pdev)
  22. {
  23. msm_ps_hold = devm_platform_ioremap_resource(pdev, 0);
  24. if (IS_ERR(msm_ps_hold))
  25. return PTR_ERR(msm_ps_hold);
  26. devm_register_sys_off_handler(&pdev->dev, SYS_OFF_MODE_RESTART,
  27. 128, do_msm_poweroff, NULL);
  28. devm_register_sys_off_handler(&pdev->dev, SYS_OFF_MODE_POWER_OFF,
  29. SYS_OFF_PRIO_DEFAULT, do_msm_poweroff,
  30. NULL);
  31. return 0;
  32. }
  33. static const struct of_device_id of_msm_restart_match[] = {
  34. { .compatible = "qcom,pshold", },
  35. {},
  36. };
  37. MODULE_DEVICE_TABLE(of, of_msm_restart_match);
  38. static struct platform_driver msm_restart_driver = {
  39. .probe = msm_restart_probe,
  40. .driver = {
  41. .name = "msm-restart",
  42. .of_match_table = of_match_ptr(of_msm_restart_match),
  43. },
  44. };
  45. builtin_platform_driver(msm_restart_driver);