pm.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. // SPDX-License-Identifier: GPL-2.0
  2. //
  3. // Copyright (c) 2010-2014 Samsung Electronics Co., Ltd.
  4. // http://www.samsung.com
  5. //
  6. // S5PV210 - Power Management support
  7. //
  8. // Based on arch/arm/mach-s3c2410/pm.c
  9. // Copyright (c) 2006 Simtec Electronics
  10. // Ben Dooks <ben@simtec.co.uk>
  11. #include <linux/init.h>
  12. #include <linux/suspend.h>
  13. #include <linux/syscore_ops.h>
  14. #include <linux/io.h>
  15. #include <asm/cacheflush.h>
  16. #include <asm/suspend.h>
  17. #include <plat/pm-common.h>
  18. #include "common.h"
  19. #include "regs-clock.h"
  20. static struct sleep_save s5pv210_core_save[] = {
  21. /* Clock ETC */
  22. SAVE_ITEM(S5P_MDNIE_SEL),
  23. };
  24. /*
  25. * VIC wake-up support (TODO)
  26. */
  27. static u32 s5pv210_irqwake_intmask = 0xffffffff;
  28. /*
  29. * Suspend helpers.
  30. */
  31. static int s5pv210_cpu_suspend(unsigned long arg)
  32. {
  33. unsigned long tmp;
  34. /* issue the standby signal into the pm unit. Note, we
  35. * issue a write-buffer drain just in case */
  36. tmp = 0;
  37. asm("b 1f\n\t"
  38. ".align 5\n\t"
  39. "1:\n\t"
  40. "mcr p15, 0, %0, c7, c10, 5\n\t"
  41. "mcr p15, 0, %0, c7, c10, 4\n\t"
  42. "wfi" : : "r" (tmp));
  43. pr_info("Failed to suspend the system\n");
  44. return 1; /* Aborting suspend */
  45. }
  46. static void s5pv210_pm_prepare(void)
  47. {
  48. unsigned int tmp;
  49. /* Set wake-up mask registers */
  50. __raw_writel(exynos_get_eint_wake_mask(), S5P_EINT_WAKEUP_MASK);
  51. __raw_writel(s5pv210_irqwake_intmask, S5P_WAKEUP_MASK);
  52. /* ensure at least INFORM0 has the resume address */
  53. __raw_writel(__pa_symbol(s5pv210_cpu_resume), S5P_INFORM0);
  54. tmp = __raw_readl(S5P_SLEEP_CFG);
  55. tmp &= ~(S5P_SLEEP_CFG_OSC_EN | S5P_SLEEP_CFG_USBOSC_EN);
  56. __raw_writel(tmp, S5P_SLEEP_CFG);
  57. /* WFI for SLEEP mode configuration by SYSCON */
  58. tmp = __raw_readl(S5P_PWR_CFG);
  59. tmp &= S5P_CFG_WFI_CLEAN;
  60. tmp |= S5P_CFG_WFI_SLEEP;
  61. __raw_writel(tmp, S5P_PWR_CFG);
  62. /* SYSCON interrupt handling disable */
  63. tmp = __raw_readl(S5P_OTHERS);
  64. tmp |= S5P_OTHER_SYSC_INTOFF;
  65. __raw_writel(tmp, S5P_OTHERS);
  66. s3c_pm_do_save(s5pv210_core_save, ARRAY_SIZE(s5pv210_core_save));
  67. }
  68. /*
  69. * Suspend operations.
  70. */
  71. static int s5pv210_suspend_enter(suspend_state_t state)
  72. {
  73. int ret;
  74. s3c_pm_debug_init();
  75. S3C_PMDBG("%s: suspending the system...\n", __func__);
  76. S3C_PMDBG("%s: wakeup masks: %08x,%08x\n", __func__,
  77. s5pv210_irqwake_intmask, exynos_get_eint_wake_mask());
  78. if (s5pv210_irqwake_intmask == -1U
  79. && exynos_get_eint_wake_mask() == -1U) {
  80. pr_err("%s: No wake-up sources!\n", __func__);
  81. pr_err("%s: Aborting sleep\n", __func__);
  82. return -EINVAL;
  83. }
  84. s3c_pm_save_uarts();
  85. s5pv210_pm_prepare();
  86. flush_cache_all();
  87. s3c_pm_check_store();
  88. ret = cpu_suspend(0, s5pv210_cpu_suspend);
  89. if (ret)
  90. return ret;
  91. s3c_pm_restore_uarts();
  92. S3C_PMDBG("%s: wakeup stat: %08x\n", __func__,
  93. __raw_readl(S5P_WAKEUP_STAT));
  94. s3c_pm_check_restore();
  95. S3C_PMDBG("%s: resuming the system...\n", __func__);
  96. return 0;
  97. }
  98. static int s5pv210_suspend_prepare(void)
  99. {
  100. s3c_pm_check_prepare();
  101. return 0;
  102. }
  103. static void s5pv210_suspend_finish(void)
  104. {
  105. s3c_pm_check_cleanup();
  106. }
  107. static const struct platform_suspend_ops s5pv210_suspend_ops = {
  108. .enter = s5pv210_suspend_enter,
  109. .prepare = s5pv210_suspend_prepare,
  110. .finish = s5pv210_suspend_finish,
  111. .valid = suspend_valid_only_mem,
  112. };
  113. /*
  114. * Syscore operations used to delay restore of certain registers.
  115. */
  116. static void s5pv210_pm_resume(void)
  117. {
  118. s3c_pm_do_restore_core(s5pv210_core_save, ARRAY_SIZE(s5pv210_core_save));
  119. }
  120. static struct syscore_ops s5pv210_pm_syscore_ops = {
  121. .resume = s5pv210_pm_resume,
  122. };
  123. /*
  124. * Initialization entry point.
  125. */
  126. void __init s5pv210_pm_init(void)
  127. {
  128. register_syscore_ops(&s5pv210_pm_syscore_ops);
  129. suspend_set_ops(&s5pv210_suspend_ops);
  130. }