pm.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. /*
  2. * Copyright (c) 2011-2012 Samsung Electronics Co., Ltd.
  3. * http://www.samsung.com
  4. *
  5. * EXYNOS - Power Management support
  6. *
  7. * Based on arch/arm/mach-s3c2410/pm.c
  8. * Copyright (c) 2006 Simtec Electronics
  9. * Ben Dooks <ben@simtec.co.uk>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. */
  15. #include <linux/init.h>
  16. #include <linux/suspend.h>
  17. #include <linux/syscore_ops.h>
  18. #include <linux/io.h>
  19. #include <linux/err.h>
  20. #include <linux/clk.h>
  21. #include <asm/cacheflush.h>
  22. #include <asm/hardware/cache-l2x0.h>
  23. #include <asm/smp_scu.h>
  24. #include <plat/cpu.h>
  25. #include <plat/pm.h>
  26. #include <plat/pll.h>
  27. #include <plat/regs-srom.h>
  28. #include <mach/regs-irq.h>
  29. #include <mach/regs-gpio.h>
  30. #include <mach/regs-clock.h>
  31. #include <mach/regs-pmu.h>
  32. #include <mach/pm-core.h>
  33. #include <mach/pmu.h>
  34. static struct sleep_save exynos4_set_clksrc[] = {
  35. { .reg = EXYNOS4_CLKSRC_MASK_TOP , .val = 0x00000001, },
  36. { .reg = EXYNOS4_CLKSRC_MASK_CAM , .val = 0x11111111, },
  37. { .reg = EXYNOS4_CLKSRC_MASK_TV , .val = 0x00000111, },
  38. { .reg = EXYNOS4_CLKSRC_MASK_LCD0 , .val = 0x00001111, },
  39. { .reg = EXYNOS4_CLKSRC_MASK_MAUDIO , .val = 0x00000001, },
  40. { .reg = EXYNOS4_CLKSRC_MASK_FSYS , .val = 0x01011111, },
  41. { .reg = EXYNOS4_CLKSRC_MASK_PERIL0 , .val = 0x01111111, },
  42. { .reg = EXYNOS4_CLKSRC_MASK_PERIL1 , .val = 0x01110111, },
  43. { .reg = EXYNOS4_CLKSRC_MASK_DMC , .val = 0x00010000, },
  44. };
  45. static struct sleep_save exynos4210_set_clksrc[] = {
  46. { .reg = EXYNOS4210_CLKSRC_MASK_LCD1 , .val = 0x00001111, },
  47. };
  48. static struct sleep_save exynos4_epll_save[] = {
  49. SAVE_ITEM(EXYNOS4_EPLL_CON0),
  50. SAVE_ITEM(EXYNOS4_EPLL_CON1),
  51. };
  52. static struct sleep_save exynos4_vpll_save[] = {
  53. SAVE_ITEM(EXYNOS4_VPLL_CON0),
  54. SAVE_ITEM(EXYNOS4_VPLL_CON1),
  55. };
  56. static struct sleep_save exynos_core_save[] = {
  57. /* SROM side */
  58. SAVE_ITEM(S5P_SROM_BW),
  59. SAVE_ITEM(S5P_SROM_BC0),
  60. SAVE_ITEM(S5P_SROM_BC1),
  61. SAVE_ITEM(S5P_SROM_BC2),
  62. SAVE_ITEM(S5P_SROM_BC3),
  63. };
  64. /* For Cortex-A9 Diagnostic and Power control register */
  65. static unsigned int save_arm_register[2];
  66. static int exynos_cpu_suspend(unsigned long arg)
  67. {
  68. #ifdef CONFIG_CACHE_L2X0
  69. outer_flush_all();
  70. #endif
  71. /* issue the standby signal into the pm unit. */
  72. cpu_do_idle();
  73. /* we should never get past here */
  74. panic("sleep resumed to originator?");
  75. }
  76. static void exynos_pm_prepare(void)
  77. {
  78. unsigned int tmp;
  79. s3c_pm_do_save(exynos_core_save, ARRAY_SIZE(exynos_core_save));
  80. if (!soc_is_exynos5250()) {
  81. s3c_pm_do_save(exynos4_epll_save, ARRAY_SIZE(exynos4_epll_save));
  82. s3c_pm_do_save(exynos4_vpll_save, ARRAY_SIZE(exynos4_vpll_save));
  83. } else {
  84. /* Disable USE_RETENTION of JPEG_MEM_OPTION */
  85. tmp = __raw_readl(EXYNOS5_JPEG_MEM_OPTION);
  86. tmp &= ~EXYNOS5_OPTION_USE_RETENTION;
  87. __raw_writel(tmp, EXYNOS5_JPEG_MEM_OPTION);
  88. }
  89. /* Set value of power down register for sleep mode */
  90. exynos_sys_powerdown_conf(SYS_SLEEP);
  91. __raw_writel(S5P_CHECK_SLEEP, S5P_INFORM1);
  92. /* ensure at least INFORM0 has the resume address */
  93. __raw_writel(virt_to_phys(s3c_cpu_resume), S5P_INFORM0);
  94. /* Before enter central sequence mode, clock src register have to set */
  95. if (!soc_is_exynos5250())
  96. s3c_pm_do_restore_core(exynos4_set_clksrc, ARRAY_SIZE(exynos4_set_clksrc));
  97. if (soc_is_exynos4210())
  98. s3c_pm_do_restore_core(exynos4210_set_clksrc, ARRAY_SIZE(exynos4210_set_clksrc));
  99. }
  100. static int exynos_pm_add(struct device *dev, struct subsys_interface *sif)
  101. {
  102. pm_cpu_prep = exynos_pm_prepare;
  103. pm_cpu_sleep = exynos_cpu_suspend;
  104. return 0;
  105. }
  106. static unsigned long pll_base_rate;
  107. static void exynos4_restore_pll(void)
  108. {
  109. unsigned long pll_con, locktime, lockcnt;
  110. unsigned long pll_in_rate;
  111. unsigned int p_div, epll_wait = 0, vpll_wait = 0;
  112. if (pll_base_rate == 0)
  113. return;
  114. pll_in_rate = pll_base_rate;
  115. /* EPLL */
  116. pll_con = exynos4_epll_save[0].val;
  117. if (pll_con & (1 << 31)) {
  118. pll_con &= (PLL46XX_PDIV_MASK << PLL46XX_PDIV_SHIFT);
  119. p_div = (pll_con >> PLL46XX_PDIV_SHIFT);
  120. pll_in_rate /= 1000000;
  121. locktime = (3000 / pll_in_rate) * p_div;
  122. lockcnt = locktime * 10000 / (10000 / pll_in_rate);
  123. __raw_writel(lockcnt, EXYNOS4_EPLL_LOCK);
  124. s3c_pm_do_restore_core(exynos4_epll_save,
  125. ARRAY_SIZE(exynos4_epll_save));
  126. epll_wait = 1;
  127. }
  128. pll_in_rate = pll_base_rate;
  129. /* VPLL */
  130. pll_con = exynos4_vpll_save[0].val;
  131. if (pll_con & (1 << 31)) {
  132. pll_in_rate /= 1000000;
  133. /* 750us */
  134. locktime = 750;
  135. lockcnt = locktime * 10000 / (10000 / pll_in_rate);
  136. __raw_writel(lockcnt, EXYNOS4_VPLL_LOCK);
  137. s3c_pm_do_restore_core(exynos4_vpll_save,
  138. ARRAY_SIZE(exynos4_vpll_save));
  139. vpll_wait = 1;
  140. }
  141. /* Wait PLL locking */
  142. do {
  143. if (epll_wait) {
  144. pll_con = __raw_readl(EXYNOS4_EPLL_CON0);
  145. if (pll_con & (1 << EXYNOS4_EPLLCON0_LOCKED_SHIFT))
  146. epll_wait = 0;
  147. }
  148. if (vpll_wait) {
  149. pll_con = __raw_readl(EXYNOS4_VPLL_CON0);
  150. if (pll_con & (1 << EXYNOS4_VPLLCON0_LOCKED_SHIFT))
  151. vpll_wait = 0;
  152. }
  153. } while (epll_wait || vpll_wait);
  154. }
  155. static struct subsys_interface exynos_pm_interface = {
  156. .name = "exynos_pm",
  157. .subsys = &exynos_subsys,
  158. .add_dev = exynos_pm_add,
  159. };
  160. static __init int exynos_pm_drvinit(void)
  161. {
  162. struct clk *pll_base;
  163. unsigned int tmp;
  164. s3c_pm_init();
  165. /* All wakeup disable */
  166. tmp = __raw_readl(S5P_WAKEUP_MASK);
  167. tmp |= ((0xFF << 8) | (0x1F << 1));
  168. __raw_writel(tmp, S5P_WAKEUP_MASK);
  169. if (!soc_is_exynos5250()) {
  170. pll_base = clk_get(NULL, "xtal");
  171. if (!IS_ERR(pll_base)) {
  172. pll_base_rate = clk_get_rate(pll_base);
  173. clk_put(pll_base);
  174. }
  175. }
  176. return subsys_interface_register(&exynos_pm_interface);
  177. }
  178. arch_initcall(exynos_pm_drvinit);
  179. static int exynos_pm_suspend(void)
  180. {
  181. unsigned long tmp;
  182. /* Setting Central Sequence Register for power down mode */
  183. tmp = __raw_readl(S5P_CENTRAL_SEQ_CONFIGURATION);
  184. tmp &= ~S5P_CENTRAL_LOWPWR_CFG;
  185. __raw_writel(tmp, S5P_CENTRAL_SEQ_CONFIGURATION);
  186. /* Setting SEQ_OPTION register */
  187. tmp = (S5P_USE_STANDBY_WFI0 | S5P_USE_STANDBY_WFE0);
  188. __raw_writel(tmp, S5P_CENTRAL_SEQ_OPTION);
  189. if (!soc_is_exynos5250()) {
  190. /* Save Power control register */
  191. asm ("mrc p15, 0, %0, c15, c0, 0"
  192. : "=r" (tmp) : : "cc");
  193. save_arm_register[0] = tmp;
  194. /* Save Diagnostic register */
  195. asm ("mrc p15, 0, %0, c15, c0, 1"
  196. : "=r" (tmp) : : "cc");
  197. save_arm_register[1] = tmp;
  198. }
  199. return 0;
  200. }
  201. static void exynos_pm_resume(void)
  202. {
  203. unsigned long tmp;
  204. /*
  205. * If PMU failed while entering sleep mode, WFI will be
  206. * ignored by PMU and then exiting cpu_do_idle().
  207. * S5P_CENTRAL_LOWPWR_CFG bit will not be set automatically
  208. * in this situation.
  209. */
  210. tmp = __raw_readl(S5P_CENTRAL_SEQ_CONFIGURATION);
  211. if (!(tmp & S5P_CENTRAL_LOWPWR_CFG)) {
  212. tmp |= S5P_CENTRAL_LOWPWR_CFG;
  213. __raw_writel(tmp, S5P_CENTRAL_SEQ_CONFIGURATION);
  214. /* No need to perform below restore code */
  215. goto early_wakeup;
  216. }
  217. if (!soc_is_exynos5250()) {
  218. /* Restore Power control register */
  219. tmp = save_arm_register[0];
  220. asm volatile ("mcr p15, 0, %0, c15, c0, 0"
  221. : : "r" (tmp)
  222. : "cc");
  223. /* Restore Diagnostic register */
  224. tmp = save_arm_register[1];
  225. asm volatile ("mcr p15, 0, %0, c15, c0, 1"
  226. : : "r" (tmp)
  227. : "cc");
  228. }
  229. /* For release retention */
  230. __raw_writel((1 << 28), S5P_PAD_RET_MAUDIO_OPTION);
  231. __raw_writel((1 << 28), S5P_PAD_RET_GPIO_OPTION);
  232. __raw_writel((1 << 28), S5P_PAD_RET_UART_OPTION);
  233. __raw_writel((1 << 28), S5P_PAD_RET_MMCA_OPTION);
  234. __raw_writel((1 << 28), S5P_PAD_RET_MMCB_OPTION);
  235. __raw_writel((1 << 28), S5P_PAD_RET_EBIA_OPTION);
  236. __raw_writel((1 << 28), S5P_PAD_RET_EBIB_OPTION);
  237. s3c_pm_do_restore_core(exynos_core_save, ARRAY_SIZE(exynos_core_save));
  238. if (!soc_is_exynos5250()) {
  239. exynos4_restore_pll();
  240. #ifdef CONFIG_SMP
  241. scu_enable(S5P_VA_SCU);
  242. #endif
  243. }
  244. early_wakeup:
  245. return;
  246. }
  247. static struct syscore_ops exynos_pm_syscore_ops = {
  248. .suspend = exynos_pm_suspend,
  249. .resume = exynos_pm_resume,
  250. };
  251. static __init int exynos_pm_syscore_init(void)
  252. {
  253. register_syscore_ops(&exynos_pm_syscore_ops);
  254. return 0;
  255. }
  256. arch_initcall(exynos_pm_syscore_init);