msm-poweroff.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* Copyright (c) 2013, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. */
  13. #include <linux/delay.h>
  14. #include <linux/err.h>
  15. #include <linux/init.h>
  16. #include <linux/kernel.h>
  17. #include <linux/io.h>
  18. #include <linux/of.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/module.h>
  21. #include <linux/reboot.h>
  22. #include <linux/pm.h>
  23. static void __iomem *msm_ps_hold;
  24. static int do_msm_restart(struct notifier_block *nb, unsigned long action,
  25. void *data)
  26. {
  27. writel(0, msm_ps_hold);
  28. mdelay(10000);
  29. return NOTIFY_DONE;
  30. }
  31. static struct notifier_block restart_nb = {
  32. .notifier_call = do_msm_restart,
  33. .priority = 128,
  34. };
  35. static void do_msm_poweroff(void)
  36. {
  37. /* TODO: Add poweroff capability */
  38. do_msm_restart(&restart_nb, 0, NULL);
  39. }
  40. static int msm_restart_probe(struct platform_device *pdev)
  41. {
  42. struct device *dev = &pdev->dev;
  43. struct resource *mem;
  44. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  45. msm_ps_hold = devm_ioremap_resource(dev, mem);
  46. if (IS_ERR(msm_ps_hold))
  47. return PTR_ERR(msm_ps_hold);
  48. register_restart_handler(&restart_nb);
  49. pm_power_off = do_msm_poweroff;
  50. return 0;
  51. }
  52. static const struct of_device_id of_msm_restart_match[] = {
  53. { .compatible = "qcom,pshold", },
  54. {},
  55. };
  56. MODULE_DEVICE_TABLE(of, of_msm_restart_match);
  57. static struct platform_driver msm_restart_driver = {
  58. .probe = msm_restart_probe,
  59. .driver = {
  60. .name = "msm-restart",
  61. .of_match_table = of_match_ptr(of_msm_restart_match),
  62. },
  63. };
  64. static int __init msm_restart_init(void)
  65. {
  66. return platform_driver_register(&msm_restart_driver);
  67. }
  68. device_initcall(msm_restart_init);