msm-poweroff.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 deassert_pshold(struct notifier_block *nb, unsigned long action,
  16. void *data)
  17. {
  18. writel(0, msm_ps_hold);
  19. mdelay(10000);
  20. return NOTIFY_DONE;
  21. }
  22. static struct notifier_block restart_nb = {
  23. .notifier_call = deassert_pshold,
  24. .priority = 200,
  25. };
  26. static void do_msm_poweroff(void)
  27. {
  28. deassert_pshold(&restart_nb, 0, NULL);
  29. }
  30. static int msm_restart_probe(struct platform_device *pdev)
  31. {
  32. struct device *dev = &pdev->dev;
  33. struct resource *mem;
  34. int ret;
  35. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  36. msm_ps_hold = devm_ioremap_resource(dev, mem);
  37. if (IS_ERR(msm_ps_hold))
  38. return PTR_ERR(msm_ps_hold);
  39. ret = register_restart_handler(&restart_nb);
  40. if (ret)
  41. dev_err(dev, "failed to register restart handler.\n");
  42. pm_power_off = do_msm_poweroff;
  43. return 0;
  44. }
  45. static int msm_restart_remove(struct platform_device *pdev)
  46. {
  47. struct device *dev = &pdev->dev;
  48. int ret;
  49. ret = unregister_restart_handler(&restart_nb);
  50. if (ret)
  51. dev_err(dev, "failed to unregister restart handler.\n");
  52. return 0;
  53. }
  54. static const struct of_device_id of_msm_restart_match[] = {
  55. { .compatible = "qcom,pshold", },
  56. {},
  57. };
  58. MODULE_DEVICE_TABLE(of, of_msm_restart_match);
  59. static struct platform_driver msm_restart_driver = {
  60. .probe = msm_restart_probe,
  61. .remove = msm_restart_remove,
  62. .driver = {
  63. .name = "msm-restart",
  64. .of_match_table = of_match_ptr(of_msm_restart_match),
  65. },
  66. };
  67. static int __init msm_restart_init(void)
  68. {
  69. return platform_driver_register(&msm_restart_driver);
  70. }
  71. module_init(msm_restart_init);
  72. static __exit void msm_restart_exit(void)
  73. {
  74. platform_driver_unregister(&msm_restart_driver);
  75. }
  76. module_exit(msm_restart_exit);
  77. MODULE_DESCRIPTION("MSM Poweroff Driver");
  78. MODULE_LICENSE("GPL");