msm-vm-poweroff.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2022-2023, Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #include <linux/io.h>
  6. #include <linux/of.h>
  7. #include <linux/platform_device.h>
  8. #include <linux/module.h>
  9. #include <linux/reboot.h>
  10. #include <linux/pm.h>
  11. #include <linux/delay.h>
  12. #include <linux/of_address.h>
  13. #include <linux/panic_notifier.h>
  14. #include <linux/cacheflush.h>
  15. #include <asm/system_misc.h>
  16. #include <soc/qcom/watchdog.h>
  17. static int in_panic;
  18. static struct notifier_block restart_nb;
  19. static int panic_prep_restart(struct notifier_block *this,
  20. unsigned long event, void *ptr)
  21. {
  22. in_panic = 1;
  23. return NOTIFY_DONE;
  24. }
  25. static struct notifier_block panic_blk = {
  26. .notifier_call = panic_prep_restart,
  27. };
  28. static int do_vm_restart(struct notifier_block *unused, unsigned long action,
  29. void *arg)
  30. {
  31. pr_notice("Going down for vm restart now\n");
  32. if (in_panic)
  33. qcom_wdt_trigger_bite();
  34. return NOTIFY_DONE;
  35. }
  36. static int vm_restart_probe(struct platform_device *pdev)
  37. {
  38. atomic_notifier_chain_register(&panic_notifier_list, &panic_blk);
  39. restart_nb.notifier_call = do_vm_restart;
  40. restart_nb.priority = 200;
  41. register_restart_handler(&restart_nb);
  42. return 0;
  43. }
  44. static const struct of_device_id of_vm_restart_match[] = {
  45. { .compatible = "qcom,vm-restart", },
  46. {},
  47. };
  48. MODULE_DEVICE_TABLE(of, of_vm_restart_match);
  49. static struct platform_driver vm_restart_driver = {
  50. .probe = vm_restart_probe,
  51. .driver = {
  52. .name = "msm-vm-restart",
  53. .of_match_table = of_match_ptr(of_vm_restart_match),
  54. },
  55. };
  56. static int __init vm_restart_init(void)
  57. {
  58. return platform_driver_register(&vm_restart_driver);
  59. }
  60. #if IS_MODULE(CONFIG_POWER_RESET_QCOM_VM)
  61. module_init(vm_restart_init);
  62. #else
  63. pure_initcall(vm_restart_init);
  64. #endif
  65. static __exit void vm_restart_exit(void)
  66. {
  67. platform_driver_unregister(&vm_restart_driver);
  68. }
  69. module_exit(vm_restart_exit);
  70. MODULE_DESCRIPTION("MSM VM Poweroff Driver");
  71. MODULE_LICENSE("GPL");