msm-poweroff.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 <asm/system_misc.h>
  23. static void __iomem *msm_ps_hold;
  24. static void do_msm_restart(enum reboot_mode reboot_mode, const char *cmd)
  25. {
  26. writel(0, msm_ps_hold);
  27. mdelay(10000);
  28. }
  29. static void do_msm_poweroff(void)
  30. {
  31. /* TODO: Add poweroff capability */
  32. do_msm_restart(REBOOT_HARD, NULL);
  33. }
  34. static int msm_restart_probe(struct platform_device *pdev)
  35. {
  36. struct device *dev = &pdev->dev;
  37. struct resource *mem;
  38. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  39. msm_ps_hold = devm_ioremap_resource(dev, mem);
  40. if (IS_ERR(msm_ps_hold))
  41. return PTR_ERR(msm_ps_hold);
  42. pm_power_off = do_msm_poweroff;
  43. arm_pm_restart = do_msm_restart;
  44. return 0;
  45. }
  46. static const struct of_device_id of_msm_restart_match[] = {
  47. { .compatible = "qcom,pshold", },
  48. {},
  49. };
  50. MODULE_DEVICE_TABLE(of, of_msm_restart_match);
  51. static struct platform_driver msm_restart_driver = {
  52. .probe = msm_restart_probe,
  53. .driver = {
  54. .name = "msm-restart",
  55. .of_match_table = of_match_ptr(of_msm_restart_match),
  56. },
  57. };
  58. static int __init msm_restart_init(void)
  59. {
  60. return platform_driver_register(&msm_restart_driver);
  61. }
  62. device_initcall(msm_restart_init);