pm.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 <[email protected]>
  11. #include <linux/init.h>
  12. #include <linux/suspend.h>
  13. #include <linux/syscore_ops.h>
  14. #include <linux/io.h>
  15. #include <linux/soc/samsung/s3c-pm.h>
  16. #include <asm/cacheflush.h>
  17. #include <asm/suspend.h>
  18. #include "common.h"
  19. #include "regs-clock.h"
  20. /* helper functions to save and restore register state */
  21. struct sleep_save {
  22. void __iomem *reg;
  23. unsigned long val;
  24. };
  25. #define SAVE_ITEM(x) \
  26. { .reg = (x) }
  27. /**
  28. * s3c_pm_do_save() - save a set of registers for restoration on resume.
  29. * @ptr: Pointer to an array of registers.
  30. * @count: Size of the ptr array.
  31. *
  32. * Run through the list of registers given, saving their contents in the
  33. * array for later restoration when we wakeup.
  34. */
  35. static void s3c_pm_do_save(struct sleep_save *ptr, int count)
  36. {
  37. for (; count > 0; count--, ptr++) {
  38. ptr->val = readl_relaxed(ptr->reg);
  39. S3C_PMDBG("saved %p value %08lx\n", ptr->reg, ptr->val);
  40. }
  41. }
  42. /**
  43. * s3c_pm_do_restore() - restore register values from the save list.
  44. * @ptr: Pointer to an array of registers.
  45. * @count: Size of the ptr array.
  46. *
  47. * Restore the register values saved from s3c_pm_do_save().
  48. *
  49. * WARNING: Do not put any debug in here that may effect memory or use
  50. * peripherals, as things may be changing!
  51. */
  52. static void s3c_pm_do_restore_core(const struct sleep_save *ptr, int count)
  53. {
  54. for (; count > 0; count--, ptr++)
  55. writel_relaxed(ptr->val, ptr->reg);
  56. }
  57. static struct sleep_save s5pv210_core_save[] = {
  58. /* Clock ETC */
  59. SAVE_ITEM(S5P_MDNIE_SEL),
  60. };
  61. /*
  62. * VIC wake-up support (TODO)
  63. */
  64. static u32 s5pv210_irqwake_intmask = 0xffffffff;
  65. static u32 s5pv210_read_eint_wakeup_mask(void)
  66. {
  67. return __raw_readl(S5P_EINT_WAKEUP_MASK);
  68. }
  69. /*
  70. * Suspend helpers.
  71. */
  72. static int s5pv210_cpu_suspend(unsigned long arg)
  73. {
  74. unsigned long tmp;
  75. /* issue the standby signal into the pm unit. Note, we
  76. * issue a write-buffer drain just in case */
  77. tmp = 0;
  78. asm("b 1f\n\t"
  79. ".align 5\n\t"
  80. "1:\n\t"
  81. "mcr p15, 0, %0, c7, c10, 5\n\t"
  82. "mcr p15, 0, %0, c7, c10, 4\n\t"
  83. "wfi" : : "r" (tmp));
  84. pr_info("Failed to suspend the system\n");
  85. return 1; /* Aborting suspend */
  86. }
  87. static void s5pv210_pm_prepare(void)
  88. {
  89. unsigned int tmp;
  90. /*
  91. * Set wake-up mask registers
  92. * S5P_EINT_WAKEUP_MASK is set by pinctrl driver in late suspend.
  93. */
  94. __raw_writel(s5pv210_irqwake_intmask, S5P_WAKEUP_MASK);
  95. /* ensure at least INFORM0 has the resume address */
  96. __raw_writel(__pa_symbol(s5pv210_cpu_resume), S5P_INFORM0);
  97. tmp = __raw_readl(S5P_SLEEP_CFG);
  98. tmp &= ~(S5P_SLEEP_CFG_OSC_EN | S5P_SLEEP_CFG_USBOSC_EN);
  99. __raw_writel(tmp, S5P_SLEEP_CFG);
  100. /* WFI for SLEEP mode configuration by SYSCON */
  101. tmp = __raw_readl(S5P_PWR_CFG);
  102. tmp &= S5P_CFG_WFI_CLEAN;
  103. tmp |= S5P_CFG_WFI_SLEEP;
  104. __raw_writel(tmp, S5P_PWR_CFG);
  105. /* SYSCON interrupt handling disable */
  106. tmp = __raw_readl(S5P_OTHERS);
  107. tmp |= S5P_OTHER_SYSC_INTOFF;
  108. __raw_writel(tmp, S5P_OTHERS);
  109. s3c_pm_do_save(s5pv210_core_save, ARRAY_SIZE(s5pv210_core_save));
  110. }
  111. /*
  112. * Suspend operations.
  113. */
  114. static int s5pv210_suspend_enter(suspend_state_t state)
  115. {
  116. u32 eint_wakeup_mask = s5pv210_read_eint_wakeup_mask();
  117. int ret;
  118. S3C_PMDBG("%s: suspending the system...\n", __func__);
  119. S3C_PMDBG("%s: wakeup masks: %08x,%08x\n", __func__,
  120. s5pv210_irqwake_intmask, eint_wakeup_mask);
  121. if (s5pv210_irqwake_intmask == -1U
  122. && eint_wakeup_mask == -1U) {
  123. pr_err("%s: No wake-up sources!\n", __func__);
  124. pr_err("%s: Aborting sleep\n", __func__);
  125. return -EINVAL;
  126. }
  127. s3c_pm_save_uarts(false);
  128. s5pv210_pm_prepare();
  129. flush_cache_all();
  130. s3c_pm_check_store();
  131. ret = cpu_suspend(0, s5pv210_cpu_suspend);
  132. if (ret)
  133. return ret;
  134. s3c_pm_restore_uarts(false);
  135. S3C_PMDBG("%s: wakeup stat: %08x\n", __func__,
  136. __raw_readl(S5P_WAKEUP_STAT));
  137. s3c_pm_check_restore();
  138. S3C_PMDBG("%s: resuming the system...\n", __func__);
  139. return 0;
  140. }
  141. static int s5pv210_suspend_prepare(void)
  142. {
  143. s3c_pm_check_prepare();
  144. return 0;
  145. }
  146. static void s5pv210_suspend_finish(void)
  147. {
  148. s3c_pm_check_cleanup();
  149. }
  150. static const struct platform_suspend_ops s5pv210_suspend_ops = {
  151. .enter = s5pv210_suspend_enter,
  152. .prepare = s5pv210_suspend_prepare,
  153. .finish = s5pv210_suspend_finish,
  154. .valid = suspend_valid_only_mem,
  155. };
  156. /*
  157. * Syscore operations used to delay restore of certain registers.
  158. */
  159. static void s5pv210_pm_resume(void)
  160. {
  161. s3c_pm_do_restore_core(s5pv210_core_save, ARRAY_SIZE(s5pv210_core_save));
  162. }
  163. static struct syscore_ops s5pv210_pm_syscore_ops = {
  164. .resume = s5pv210_pm_resume,
  165. };
  166. /*
  167. * Initialization entry point.
  168. */
  169. void __init s5pv210_pm_init(void)
  170. {
  171. register_syscore_ops(&s5pv210_pm_syscore_ops);
  172. suspend_set_ops(&s5pv210_suspend_ops);
  173. }