msm-poweroff.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 = 128,
  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. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  35. msm_ps_hold = devm_ioremap_resource(dev, mem);
  36. if (IS_ERR(msm_ps_hold))
  37. return PTR_ERR(msm_ps_hold);
  38. register_restart_handler(&restart_nb);
  39. pm_power_off = do_msm_poweroff;
  40. return 0;
  41. }
  42. static const struct of_device_id of_msm_restart_match[] = {
  43. { .compatible = "qcom,pshold", },
  44. {},
  45. };
  46. MODULE_DEVICE_TABLE(of, of_msm_restart_match);
  47. static struct platform_driver msm_restart_driver = {
  48. .probe = msm_restart_probe,
  49. .driver = {
  50. .name = "msm-restart",
  51. .of_match_table = of_match_ptr(of_msm_restart_match),
  52. },
  53. };
  54. static int __init msm_restart_init(void)
  55. {
  56. return platform_driver_register(&msm_restart_driver);
  57. }
  58. device_initcall(msm_restart_init);